1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010
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 /* Values for do_debug_lines. */
67 #define FLAG_DEBUG_LINES_RAW 1
68 #define FLAG_DEBUG_LINES_DECODED 2
71 size_of_encoded_value (int encoding
)
73 switch (encoding
& 0x7)
76 case 0: return eh_addr_size
;
84 get_encoded_value (unsigned char *data
,
86 struct dwarf_section
*section
)
88 int size
= size_of_encoded_value (encoding
);
91 if (encoding
& DW_EH_PE_signed
)
92 val
= byte_get_signed (data
, size
);
94 val
= byte_get (data
, size
);
96 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
97 val
+= section
->address
+ (data
- section
->start
);
101 /* Print a dwarf_vma value (typically an address, offset or length) in
102 hexadecimal format, followed by a space. The length of the value (and
103 hence the precision displayed) is determined by the byte_size parameter. */
106 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
108 static char buff
[18];
110 /* Printf does not have a way of specifiying a maximum field width for an
111 integer value, so we print the full value into a buffer and then select
112 the precision we need. */
113 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
115 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
117 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
120 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
123 fputs (buff
+ (byte_size
== 4 ? 8 : 0), stdout
);
127 dwarf_vmatoa (const char *fmtch
, bfd_vma value
)
129 /* As dwarf_vmatoa is used more then once in a printf call
130 for output, we are cycling through an fixed array of pointers
131 for return address. */
132 static int buf_pos
= 0;
133 static struct dwarf_vmatoa_buf
{
139 sprintf (fmt
, "%%%s%s", BFD_VMA_FMT
, fmtch
);
141 ret
= buf
[buf_pos
++].place
;
142 buf_pos
%= ARRAY_SIZE(buf
);
144 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
150 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
153 unsigned int num_read
= 0;
154 unsigned int shift
= 0;
162 result
|= ((bfd_vma
) (byte
& 0x7f)) << shift
;
169 if (length_return
!= NULL
)
170 *length_return
= num_read
;
172 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
173 result
|= -1L << shift
;
178 typedef struct State_Machine_Registers
180 unsigned long address
;
186 unsigned char op_index
;
187 unsigned char end_sequence
;
188 /* This variable hold the number of the last entry seen
189 in the File Table. */
190 unsigned int last_file_entry
;
193 static SMR state_machine_regs
;
196 reset_state_machine (int is_stmt
)
198 state_machine_regs
.address
= 0;
199 state_machine_regs
.op_index
= 0;
200 state_machine_regs
.file
= 1;
201 state_machine_regs
.line
= 1;
202 state_machine_regs
.column
= 0;
203 state_machine_regs
.is_stmt
= is_stmt
;
204 state_machine_regs
.basic_block
= 0;
205 state_machine_regs
.end_sequence
= 0;
206 state_machine_regs
.last_file_entry
= 0;
209 /* Handled an extend line op.
210 Returns the number of bytes read. */
213 process_extended_line_op (unsigned char *data
, int is_stmt
)
215 unsigned char op_code
;
216 unsigned int bytes_read
;
221 len
= read_leb128 (data
, & bytes_read
, 0);
226 warn (_("badly formed extended line op encountered!\n"));
233 printf (_(" Extended opcode %d: "), op_code
);
237 case DW_LNE_end_sequence
:
238 printf (_("End of Sequence\n\n"));
239 reset_state_machine (is_stmt
);
242 case DW_LNE_set_address
:
243 adr
= byte_get (data
, len
- bytes_read
- 1);
244 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
245 state_machine_regs
.address
= adr
;
246 state_machine_regs
.op_index
= 0;
249 case DW_LNE_define_file
:
250 printf (_(" define new File Table entry\n"));
251 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
253 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
255 data
+= strlen ((char *) data
) + 1;
256 printf ("%" BFD_VMA_FMT
"u\t", read_leb128 (data
, & bytes_read
, 0));
258 printf ("%" BFD_VMA_FMT
"u\t",
259 read_leb128 (data
, & bytes_read
, 0));
261 printf ("%" BFD_VMA_FMT
"u\t", read_leb128 (data
, & bytes_read
, 0));
262 printf ("%s\n\n", name
);
265 case DW_LNE_set_discriminator
:
266 printf (_("set Discriminator to %s\n"),
268 read_leb128 (data
, & bytes_read
, 0)));
272 case DW_LNE_HP_negate_is_UV_update
:
273 printf ("DW_LNE_HP_negate_is_UV_update\n");
275 case DW_LNE_HP_push_context
:
276 printf ("DW_LNE_HP_push_context\n");
278 case DW_LNE_HP_pop_context
:
279 printf ("DW_LNE_HP_pop_context\n");
281 case DW_LNE_HP_set_file_line_column
:
282 printf ("DW_LNE_HP_set_file_line_column\n");
284 case DW_LNE_HP_set_routine_name
:
285 printf ("DW_LNE_HP_set_routine_name\n");
287 case DW_LNE_HP_set_sequence
:
288 printf ("DW_LNE_HP_set_sequence\n");
290 case DW_LNE_HP_negate_post_semantics
:
291 printf ("DW_LNE_HP_negate_post_semantics\n");
293 case DW_LNE_HP_negate_function_exit
:
294 printf ("DW_LNE_HP_negate_function_exit\n");
296 case DW_LNE_HP_negate_front_end_logical
:
297 printf ("DW_LNE_HP_negate_front_end_logical\n");
299 case DW_LNE_HP_define_proc
:
300 printf ("DW_LNE_HP_define_proc\n");
304 if (op_code
>= DW_LNE_lo_user
305 /* The test against DW_LNW_hi_user is redundant due to
306 the limited range of the unsigned char data type used
308 /*&& op_code <= DW_LNE_hi_user*/)
309 printf (_("user defined: length %d\n"), len
- bytes_read
);
311 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
319 fetch_indirect_string (bfd_vma offset
)
321 struct dwarf_section
*section
= &debug_displays
[str
].section
;
323 if (section
->start
== NULL
)
324 return _("<no .debug_str section>");
326 /* DWARF sections under Mach-O have non-zero addresses. */
327 offset
-= section
->address
;
328 if (offset
> section
->size
)
330 warn (_("DW_FORM_strp offset too big: %lx\n"), (long) offset
);
331 return _("<offset is too big>");
334 return (const char *) section
->start
+ offset
;
337 /* FIXME: There are better and more efficient ways to handle
338 these structures. For now though, I just want something that
339 is simple to implement. */
340 typedef struct abbrev_attr
342 unsigned long attribute
;
344 struct abbrev_attr
*next
;
348 typedef struct abbrev_entry
353 struct abbrev_attr
*first_attr
;
354 struct abbrev_attr
*last_attr
;
355 struct abbrev_entry
*next
;
359 static abbrev_entry
*first_abbrev
= NULL
;
360 static abbrev_entry
*last_abbrev
= NULL
;
367 for (abbrv
= first_abbrev
; abbrv
;)
369 abbrev_entry
*next_abbrev
= abbrv
->next
;
372 for (attr
= abbrv
->first_attr
; attr
;)
374 abbrev_attr
*next_attr
= attr
->next
;
384 last_abbrev
= first_abbrev
= NULL
;
388 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
392 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
398 entry
->entry
= number
;
400 entry
->children
= children
;
401 entry
->first_attr
= NULL
;
402 entry
->last_attr
= NULL
;
405 if (first_abbrev
== NULL
)
406 first_abbrev
= entry
;
408 last_abbrev
->next
= entry
;
414 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
418 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
424 attr
->attribute
= attribute
;
428 if (last_abbrev
->first_attr
== NULL
)
429 last_abbrev
->first_attr
= attr
;
431 last_abbrev
->last_attr
->next
= attr
;
433 last_abbrev
->last_attr
= attr
;
436 /* Processes the (partial) contents of a .debug_abbrev section.
437 Returns NULL if the end of the section was encountered.
438 Returns the address after the last byte read if the end of
439 an abbreviation set was found. */
441 static unsigned char *
442 process_abbrev_section (unsigned char *start
, unsigned char *end
)
444 if (first_abbrev
!= NULL
)
449 unsigned int bytes_read
;
452 unsigned long attribute
;
455 entry
= read_leb128 (start
, & bytes_read
, 0);
458 /* A single zero is supposed to end the section according
459 to the standard. If there's more, then signal that to
462 return start
== end
? NULL
: start
;
464 tag
= read_leb128 (start
, & bytes_read
, 0);
469 add_abbrev (entry
, tag
, children
);
475 attribute
= read_leb128 (start
, & bytes_read
, 0);
478 form
= read_leb128 (start
, & bytes_read
, 0);
482 add_abbrev_attr (attribute
, form
);
484 while (attribute
!= 0);
491 get_TAG_name (unsigned long tag
)
495 case DW_TAG_padding
: return "DW_TAG_padding";
496 case DW_TAG_array_type
: return "DW_TAG_array_type";
497 case DW_TAG_class_type
: return "DW_TAG_class_type";
498 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
499 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
500 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
501 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
502 case DW_TAG_label
: return "DW_TAG_label";
503 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
504 case DW_TAG_member
: return "DW_TAG_member";
505 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
506 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
507 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
508 case DW_TAG_string_type
: return "DW_TAG_string_type";
509 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
510 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
511 case DW_TAG_typedef
: return "DW_TAG_typedef";
512 case DW_TAG_union_type
: return "DW_TAG_union_type";
513 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
514 case DW_TAG_variant
: return "DW_TAG_variant";
515 case DW_TAG_common_block
: return "DW_TAG_common_block";
516 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
517 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
518 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
519 case DW_TAG_module
: return "DW_TAG_module";
520 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
521 case DW_TAG_set_type
: return "DW_TAG_set_type";
522 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
523 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
524 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
525 case DW_TAG_base_type
: return "DW_TAG_base_type";
526 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
527 case DW_TAG_const_type
: return "DW_TAG_const_type";
528 case DW_TAG_constant
: return "DW_TAG_constant";
529 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
530 case DW_TAG_file_type
: return "DW_TAG_file_type";
531 case DW_TAG_friend
: return "DW_TAG_friend";
532 case DW_TAG_namelist
: return "DW_TAG_namelist";
533 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
534 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
535 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
536 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
537 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
538 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
539 case DW_TAG_try_block
: return "DW_TAG_try_block";
540 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
541 case DW_TAG_variable
: return "DW_TAG_variable";
542 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
543 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
544 case DW_TAG_format_label
: return "DW_TAG_format_label";
545 case DW_TAG_function_template
: return "DW_TAG_function_template";
546 case DW_TAG_class_template
: return "DW_TAG_class_template";
547 /* DWARF 2.1 values. */
548 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
549 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
550 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
551 case DW_TAG_namespace
: return "DW_TAG_namespace";
552 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
553 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
554 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
555 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
556 case DW_TAG_condition
: return "DW_TAG_condition";
557 case DW_TAG_shared_type
: return "DW_TAG_shared_type";
558 /* DWARF 4 values. */
559 case DW_TAG_type_unit
: return "DW_TAG_type_unit";
560 case DW_TAG_rvalue_reference_type
: return "DW_TAG_rvalue_reference_type";
561 case DW_TAG_template_alias
: return "DW_TAG_template_alias";
563 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
564 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
565 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
568 static char buffer
[100];
570 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
577 get_FORM_name (unsigned long form
)
581 case DW_FORM_addr
: return "DW_FORM_addr";
582 case DW_FORM_block2
: return "DW_FORM_block2";
583 case DW_FORM_block4
: return "DW_FORM_block4";
584 case DW_FORM_data2
: return "DW_FORM_data2";
585 case DW_FORM_data4
: return "DW_FORM_data4";
586 case DW_FORM_data8
: return "DW_FORM_data8";
587 case DW_FORM_string
: return "DW_FORM_string";
588 case DW_FORM_block
: return "DW_FORM_block";
589 case DW_FORM_block1
: return "DW_FORM_block1";
590 case DW_FORM_data1
: return "DW_FORM_data1";
591 case DW_FORM_flag
: return "DW_FORM_flag";
592 case DW_FORM_sdata
: return "DW_FORM_sdata";
593 case DW_FORM_strp
: return "DW_FORM_strp";
594 case DW_FORM_udata
: return "DW_FORM_udata";
595 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
596 case DW_FORM_ref1
: return "DW_FORM_ref1";
597 case DW_FORM_ref2
: return "DW_FORM_ref2";
598 case DW_FORM_ref4
: return "DW_FORM_ref4";
599 case DW_FORM_ref8
: return "DW_FORM_ref8";
600 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
601 case DW_FORM_indirect
: return "DW_FORM_indirect";
602 /* DWARF 4 values. */
603 case DW_FORM_sec_offset
: return "DW_FORM_sec_offset";
604 case DW_FORM_exprloc
: return "DW_FORM_exprloc";
605 case DW_FORM_flag_present
: return "DW_FORM_flag_present";
606 case DW_FORM_ref_sig8
: return "DW_FORM_ref_sig8";
609 static char buffer
[100];
611 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
617 static unsigned char *
618 display_block (unsigned char *data
, unsigned long length
)
620 printf (_(" %lu byte block: "), length
);
623 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
629 decode_location_expression (unsigned char * data
,
630 unsigned int pointer_size
,
631 unsigned int offset_size
,
635 struct dwarf_section
* section
)
638 unsigned int bytes_read
;
640 unsigned char *end
= data
+ length
;
641 int need_frame_base
= 0;
650 printf ("DW_OP_addr: %lx",
651 (unsigned long) byte_get (data
, pointer_size
));
652 data
+= pointer_size
;
655 printf ("DW_OP_deref");
658 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
661 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
664 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
668 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
672 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
676 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
680 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
681 (unsigned long) byte_get (data
+ 4, 4));
685 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
686 (long) byte_get (data
+ 4, 4));
690 printf ("DW_OP_constu: %" BFD_VMA_FMT
"u",
691 read_leb128 (data
, &bytes_read
, 0));
695 printf ("DW_OP_consts: %" BFD_VMA_FMT
"d",
696 read_leb128 (data
, &bytes_read
, 1));
700 printf ("DW_OP_dup");
703 printf ("DW_OP_drop");
706 printf ("DW_OP_over");
709 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
712 printf ("DW_OP_swap");
715 printf ("DW_OP_rot");
718 printf ("DW_OP_xderef");
721 printf ("DW_OP_abs");
724 printf ("DW_OP_and");
727 printf ("DW_OP_div");
730 printf ("DW_OP_minus");
733 printf ("DW_OP_mod");
736 printf ("DW_OP_mul");
739 printf ("DW_OP_neg");
742 printf ("DW_OP_not");
748 printf ("DW_OP_plus");
750 case DW_OP_plus_uconst
:
751 printf ("DW_OP_plus_uconst: %" BFD_VMA_FMT
"u",
752 read_leb128 (data
, &bytes_read
, 0));
756 printf ("DW_OP_shl");
759 printf ("DW_OP_shr");
762 printf ("DW_OP_shra");
765 printf ("DW_OP_xor");
768 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
790 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
826 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
861 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
862 regname (op
- DW_OP_reg0
, 1));
897 printf ("DW_OP_breg%d (%s): %" BFD_VMA_FMT
"d",
899 regname (op
- DW_OP_breg0
, 1),
900 read_leb128 (data
, &bytes_read
, 1));
905 uvalue
= read_leb128 (data
, &bytes_read
, 0);
907 printf ("DW_OP_regx: %" BFD_VMA_FMT
"u (%s)",
908 uvalue
, regname (uvalue
, 1));
912 printf ("DW_OP_fbreg: %" BFD_VMA_FMT
"d",
913 read_leb128 (data
, &bytes_read
, 1));
917 uvalue
= read_leb128 (data
, &bytes_read
, 0);
919 printf ("DW_OP_bregx: %" BFD_VMA_FMT
"u (%s) %" BFD_VMA_FMT
"d",
920 uvalue
, regname (uvalue
, 1),
921 read_leb128 (data
, &bytes_read
, 1));
925 printf ("DW_OP_piece: %" BFD_VMA_FMT
"u",
926 read_leb128 (data
, &bytes_read
, 0));
929 case DW_OP_deref_size
:
930 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
932 case DW_OP_xderef_size
:
933 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
936 printf ("DW_OP_nop");
939 /* DWARF 3 extensions. */
940 case DW_OP_push_object_address
:
941 printf ("DW_OP_push_object_address");
944 /* XXX: Strictly speaking for 64-bit DWARF3 files
945 this ought to be an 8-byte wide computation. */
946 printf ("DW_OP_call2: <0x%" BFD_VMA_FMT
"x>",
947 (bfd_signed_vma
) byte_get (data
, 2) + cu_offset
);
951 /* XXX: Strictly speaking for 64-bit DWARF3 files
952 this ought to be an 8-byte wide computation. */
953 printf ("DW_OP_call4: <0x%" BFD_VMA_FMT
"x>",
954 (bfd_signed_vma
) byte_get (data
, 4) + cu_offset
);
958 /* XXX: Strictly speaking for 64-bit DWARF3 files
959 this ought to be an 8-byte wide computation. */
960 if (dwarf_version
== -1)
962 printf (_("(DW_OP_call_ref in frame info)"));
963 /* No way to tell where the next op is, so just bail. */
964 return need_frame_base
;
966 if (dwarf_version
== 2)
968 printf ("DW_OP_call_ref: <0x%lx>",
969 (long) byte_get (data
, pointer_size
));
970 data
+= pointer_size
;
974 printf ("DW_OP_call_ref: <0x%lx>",
975 (long) byte_get (data
, offset_size
));
979 case DW_OP_form_tls_address
:
980 printf ("DW_OP_form_tls_address");
982 case DW_OP_call_frame_cfa
:
983 printf ("DW_OP_call_frame_cfa");
985 case DW_OP_bit_piece
:
986 printf ("DW_OP_bit_piece: ");
987 printf ("size: %" BFD_VMA_FMT
"u ",
988 read_leb128 (data
, &bytes_read
, 0));
990 printf ("offset: %" BFD_VMA_FMT
"u ",
991 read_leb128 (data
, &bytes_read
, 0));
995 /* DWARF 4 extensions. */
996 case DW_OP_stack_value
:
997 printf ("DW_OP_stack_value");
1000 case DW_OP_implicit_value
:
1001 printf ("DW_OP_implicit_value");
1002 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1004 display_block (data
, uvalue
);
1008 /* GNU extensions. */
1009 case DW_OP_GNU_push_tls_address
:
1010 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1012 case DW_OP_GNU_uninit
:
1013 printf ("DW_OP_GNU_uninit");
1014 /* FIXME: Is there data associated with this OP ? */
1016 case DW_OP_GNU_encoded_addr
:
1022 addr
= get_encoded_value (data
, encoding
, section
);
1023 data
+= size_of_encoded_value (encoding
);
1025 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1026 print_dwarf_vma (addr
, pointer_size
);
1029 case DW_OP_GNU_implicit_pointer
:
1030 /* XXX: Strictly speaking for 64-bit DWARF3 files
1031 this ought to be an 8-byte wide computation. */
1032 if (dwarf_version
== -1)
1034 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1035 /* No way to tell where the next op is, so just bail. */
1036 return need_frame_base
;
1038 if (dwarf_version
== 2)
1040 printf ("DW_OP_GNU_implicit_pointer: "
1041 "<0x%" BFD_VMA_FMT
"x> %" BFD_VMA_FMT
"d",
1042 (bfd_vma
) byte_get (data
, pointer_size
),
1043 (bfd_signed_vma
) read_leb128 (data
+ pointer_size
,
1045 data
+= pointer_size
+ bytes_read
;
1049 printf ("DW_OP_GNU_implicit_pointer: "
1050 "<0x%" BFD_VMA_FMT
"x> %" BFD_VMA_FMT
"d",
1051 (bfd_vma
) byte_get (data
, offset_size
),
1052 (bfd_signed_vma
) read_leb128 (data
+ offset_size
,
1054 data
+= offset_size
+ bytes_read
;
1058 /* HP extensions. */
1059 case DW_OP_HP_is_value
:
1060 printf ("DW_OP_HP_is_value");
1061 /* FIXME: Is there data associated with this OP ? */
1063 case DW_OP_HP_fltconst4
:
1064 printf ("DW_OP_HP_fltconst4");
1065 /* FIXME: Is there data associated with this OP ? */
1067 case DW_OP_HP_fltconst8
:
1068 printf ("DW_OP_HP_fltconst8");
1069 /* FIXME: Is there data associated with this OP ? */
1071 case DW_OP_HP_mod_range
:
1072 printf ("DW_OP_HP_mod_range");
1073 /* FIXME: Is there data associated with this OP ? */
1075 case DW_OP_HP_unmod_range
:
1076 printf ("DW_OP_HP_unmod_range");
1077 /* FIXME: Is there data associated with this OP ? */
1080 printf ("DW_OP_HP_tls");
1081 /* FIXME: Is there data associated with this OP ? */
1084 /* PGI (STMicroelectronics) extensions. */
1085 case DW_OP_PGI_omp_thread_num
:
1086 /* Pushes the thread number for the current thread as it would be
1087 returned by the standard OpenMP library function:
1088 omp_get_thread_num(). The "current thread" is the thread for
1089 which the expression is being evaluated. */
1090 printf ("DW_OP_PGI_omp_thread_num");
1094 if (op
>= DW_OP_lo_user
1095 && op
<= DW_OP_hi_user
)
1096 printf (_("(User defined location op)"));
1098 printf (_("(Unknown location op)"));
1099 /* No way to tell where the next op is, so just bail. */
1100 return need_frame_base
;
1103 /* Separate the ops. */
1108 return need_frame_base
;
1111 static unsigned char *
1112 read_and_display_attr_value (unsigned long attribute
,
1114 unsigned char * data
,
1116 bfd_vma pointer_size
,
1117 bfd_vma offset_size
,
1119 debug_info
* debug_info_p
,
1121 struct dwarf_section
* section
)
1124 unsigned char *block_start
= NULL
;
1125 unsigned char * orig_data
= data
;
1126 unsigned int bytes_read
;
1133 case DW_FORM_ref_addr
:
1134 if (dwarf_version
== 2)
1136 uvalue
= byte_get (data
, pointer_size
);
1137 data
+= pointer_size
;
1139 else if (dwarf_version
== 3 || dwarf_version
== 4)
1141 uvalue
= byte_get (data
, offset_size
);
1142 data
+= offset_size
;
1146 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1151 uvalue
= byte_get (data
, pointer_size
);
1152 data
+= pointer_size
;
1156 case DW_FORM_sec_offset
:
1157 uvalue
= byte_get (data
, offset_size
);
1158 data
+= offset_size
;
1161 case DW_FORM_flag_present
:
1168 uvalue
= byte_get (data
++, 1);
1173 uvalue
= byte_get (data
, 2);
1179 uvalue
= byte_get (data
, 4);
1184 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1188 case DW_FORM_ref_udata
:
1190 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1194 case DW_FORM_indirect
:
1195 form
= read_leb128 (data
, & bytes_read
, 0);
1198 printf (" %s", get_FORM_name (form
));
1199 return read_and_display_attr_value (attribute
, form
, data
,
1200 cu_offset
, pointer_size
,
1201 offset_size
, dwarf_version
,
1202 debug_info_p
, do_loc
,
1208 case DW_FORM_ref_addr
:
1210 printf (" <0x%" BFD_VMA_FMT
"x>", uvalue
);
1216 case DW_FORM_ref_udata
:
1218 printf (" <0x%" BFD_VMA_FMT
"x>", uvalue
+ cu_offset
);
1223 case DW_FORM_sec_offset
:
1225 printf (" 0x%" BFD_VMA_FMT
"x", uvalue
);
1228 case DW_FORM_flag_present
:
1235 printf (" %" BFD_VMA_FMT
"d", uvalue
);
1242 uvalue
= byte_get (data
, 4);
1243 printf (" 0x%" BFD_VMA_FMT
"x", uvalue
);
1244 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1246 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1247 && num_debug_info_entries
== 0)
1249 if (sizeof (uvalue
) == 8)
1250 uvalue
= byte_get (data
, 8);
1252 error (_("DW_FORM_data8 is unsupported when sizeof (bfd_vma) != 8\n"));
1257 case DW_FORM_string
:
1259 printf (" %s", data
);
1260 data
+= strlen ((char *) data
) + 1;
1264 case DW_FORM_exprloc
:
1265 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1266 block_start
= data
+ bytes_read
;
1268 data
= block_start
+ uvalue
;
1270 data
= display_block (block_start
, uvalue
);
1273 case DW_FORM_block1
:
1274 uvalue
= byte_get (data
, 1);
1275 block_start
= data
+ 1;
1277 data
= block_start
+ uvalue
;
1279 data
= display_block (block_start
, uvalue
);
1282 case DW_FORM_block2
:
1283 uvalue
= byte_get (data
, 2);
1284 block_start
= data
+ 2;
1286 data
= block_start
+ uvalue
;
1288 data
= display_block (block_start
, uvalue
);
1291 case DW_FORM_block4
:
1292 uvalue
= byte_get (data
, 4);
1293 block_start
= data
+ 4;
1295 data
= block_start
+ uvalue
;
1297 data
= display_block (block_start
, uvalue
);
1302 printf (_(" (indirect string, offset: 0x%s): %s"),
1303 dwarf_vmatoa ("x", uvalue
),
1304 fetch_indirect_string (uvalue
));
1307 case DW_FORM_indirect
:
1308 /* Handled above. */
1311 case DW_FORM_ref_sig8
:
1315 printf (" signature: ");
1316 for (i
= 0; i
< 8; i
++)
1318 printf ("%02x", (unsigned) byte_get (data
, 1));
1327 warn (_("Unrecognized form: %lu\n"), form
);
1331 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1332 && num_debug_info_entries
== 0)
1336 case DW_AT_frame_base
:
1337 have_frame_base
= 1;
1338 case DW_AT_location
:
1339 case DW_AT_string_length
:
1340 case DW_AT_return_addr
:
1341 case DW_AT_data_member_location
:
1342 case DW_AT_vtable_elem_location
:
1344 case DW_AT_static_link
:
1345 case DW_AT_use_location
:
1346 if (form
== DW_FORM_data4
1347 || form
== DW_FORM_data8
1348 || form
== DW_FORM_sec_offset
)
1350 /* Process location list. */
1351 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1352 unsigned int num
= debug_info_p
->num_loc_offsets
;
1354 if (lmax
== 0 || num
>= lmax
)
1357 debug_info_p
->loc_offsets
= (bfd_vma
*)
1358 xcrealloc (debug_info_p
->loc_offsets
,
1359 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1360 debug_info_p
->have_frame_base
= (int *)
1361 xcrealloc (debug_info_p
->have_frame_base
,
1362 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1363 debug_info_p
->max_loc_offsets
= lmax
;
1365 debug_info_p
->loc_offsets
[num
] = uvalue
;
1366 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1367 debug_info_p
->num_loc_offsets
++;
1372 if (need_base_address
)
1373 debug_info_p
->base_address
= uvalue
;
1377 if (form
== DW_FORM_data4
1378 || form
== DW_FORM_data8
1379 || form
== DW_FORM_sec_offset
)
1381 /* Process range list. */
1382 unsigned int lmax
= debug_info_p
->max_range_lists
;
1383 unsigned int num
= debug_info_p
->num_range_lists
;
1385 if (lmax
== 0 || num
>= lmax
)
1388 debug_info_p
->range_lists
= (bfd_vma
*)
1389 xcrealloc (debug_info_p
->range_lists
,
1390 lmax
, sizeof (*debug_info_p
->range_lists
));
1391 debug_info_p
->max_range_lists
= lmax
;
1393 debug_info_p
->range_lists
[num
] = uvalue
;
1394 debug_info_p
->num_range_lists
++;
1406 /* For some attributes we can display further information. */
1414 case DW_INL_not_inlined
:
1415 printf (_("(not inlined)"));
1417 case DW_INL_inlined
:
1418 printf (_("(inlined)"));
1420 case DW_INL_declared_not_inlined
:
1421 printf (_("(declared as inline but ignored)"));
1423 case DW_INL_declared_inlined
:
1424 printf (_("(declared as inline and inlined)"));
1427 printf (_(" (Unknown inline attribute value: %s)"),
1428 dwarf_vmatoa ("x", uvalue
));
1433 case DW_AT_language
:
1436 /* Ordered by the numeric value of these constants. */
1437 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1438 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1439 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1440 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1441 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1442 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1443 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1444 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1445 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1446 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1447 /* DWARF 2.1 values. */
1448 case DW_LANG_Java
: printf ("(Java)"); break;
1449 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1450 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1451 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1452 /* DWARF 3 values. */
1453 case DW_LANG_PLI
: printf ("(PLI)"); break;
1454 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1455 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1456 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1457 case DW_LANG_D
: printf ("(D)"); break;
1458 /* DWARF 4 values. */
1459 case DW_LANG_Python
: printf ("(Python)"); break;
1460 /* MIPS extension. */
1461 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1462 /* UPC extension. */
1463 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1465 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1466 printf ("(implementation defined: %" BFD_VMA_FMT
"x)", uvalue
);
1468 printf ("(Unknown: %" BFD_VMA_FMT
"x)", uvalue
);
1473 case DW_AT_encoding
:
1476 case DW_ATE_void
: printf ("(void)"); break;
1477 case DW_ATE_address
: printf ("(machine address)"); break;
1478 case DW_ATE_boolean
: printf ("(boolean)"); break;
1479 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1480 case DW_ATE_float
: printf ("(float)"); break;
1481 case DW_ATE_signed
: printf ("(signed)"); break;
1482 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1483 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1484 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1485 /* DWARF 2.1 values: */
1486 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1487 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1488 /* DWARF 3 values: */
1489 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1490 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1491 case DW_ATE_edited
: printf ("(edited)"); break;
1492 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1493 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1494 /* HP extensions: */
1495 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1496 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1497 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1498 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1499 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1500 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1501 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1504 if (uvalue
>= DW_ATE_lo_user
1505 && uvalue
<= DW_ATE_hi_user
)
1506 printf ("(user defined type)");
1508 printf ("(unknown type)");
1513 case DW_AT_accessibility
:
1516 case DW_ACCESS_public
: printf ("(public)"); break;
1517 case DW_ACCESS_protected
: printf ("(protected)"); break;
1518 case DW_ACCESS_private
: printf ("(private)"); break;
1520 printf ("(unknown accessibility)");
1525 case DW_AT_visibility
:
1528 case DW_VIS_local
: printf ("(local)"); break;
1529 case DW_VIS_exported
: printf ("(exported)"); break;
1530 case DW_VIS_qualified
: printf ("(qualified)"); break;
1531 default: printf ("(unknown visibility)"); break;
1535 case DW_AT_virtuality
:
1538 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1539 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1540 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1541 default: printf ("(unknown virtuality)"); break;
1545 case DW_AT_identifier_case
:
1548 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1549 case DW_ID_up_case
: printf ("(up_case)"); break;
1550 case DW_ID_down_case
: printf ("(down_case)"); break;
1551 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1552 default: printf ("(unknown case)"); break;
1556 case DW_AT_calling_convention
:
1559 case DW_CC_normal
: printf ("(normal)"); break;
1560 case DW_CC_program
: printf ("(program)"); break;
1561 case DW_CC_nocall
: printf ("(nocall)"); break;
1563 if (uvalue
>= DW_CC_lo_user
1564 && uvalue
<= DW_CC_hi_user
)
1565 printf ("(user defined)");
1567 printf ("(unknown convention)");
1571 case DW_AT_ordering
:
1574 case -1: printf ("(undefined)"); break;
1575 case 0: printf ("(row major)"); break;
1576 case 1: printf ("(column major)"); break;
1580 case DW_AT_frame_base
:
1581 have_frame_base
= 1;
1582 case DW_AT_location
:
1583 case DW_AT_string_length
:
1584 case DW_AT_return_addr
:
1585 case DW_AT_data_member_location
:
1586 case DW_AT_vtable_elem_location
:
1588 case DW_AT_static_link
:
1589 case DW_AT_use_location
:
1590 if (form
== DW_FORM_data4
1591 || form
== DW_FORM_data8
1592 || form
== DW_FORM_sec_offset
)
1593 printf (_("(location list)"));
1595 case DW_AT_allocated
:
1596 case DW_AT_associated
:
1597 case DW_AT_data_location
:
1599 case DW_AT_upper_bound
:
1600 case DW_AT_lower_bound
:
1603 int need_frame_base
;
1606 need_frame_base
= decode_location_expression (block_start
,
1611 cu_offset
, section
);
1613 if (need_frame_base
&& !have_frame_base
)
1614 printf (_(" [without DW_AT_frame_base]"));
1620 if (form
== DW_FORM_ref_sig8
)
1623 if (form
== DW_FORM_ref1
1624 || form
== DW_FORM_ref2
1625 || form
== DW_FORM_ref4
)
1626 uvalue
+= cu_offset
;
1628 if (uvalue
>= section
->size
)
1629 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1630 dwarf_vmatoa ("x", uvalue
),
1631 (unsigned long) (orig_data
- section
->start
));
1634 unsigned long abbrev_number
;
1635 abbrev_entry
* entry
;
1637 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1639 printf ("[Abbrev Number: %ld", abbrev_number
);
1640 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1641 if (entry
->entry
== abbrev_number
)
1644 printf (" (%s)", get_TAG_name (entry
->tag
));
1658 get_AT_name (unsigned long attribute
)
1662 case DW_AT_sibling
: return "DW_AT_sibling";
1663 case DW_AT_location
: return "DW_AT_location";
1664 case DW_AT_name
: return "DW_AT_name";
1665 case DW_AT_ordering
: return "DW_AT_ordering";
1666 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1667 case DW_AT_byte_size
: return "DW_AT_byte_size";
1668 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1669 case DW_AT_bit_size
: return "DW_AT_bit_size";
1670 case DW_AT_element_list
: return "DW_AT_element_list";
1671 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1672 case DW_AT_low_pc
: return "DW_AT_low_pc";
1673 case DW_AT_high_pc
: return "DW_AT_high_pc";
1674 case DW_AT_language
: return "DW_AT_language";
1675 case DW_AT_member
: return "DW_AT_member";
1676 case DW_AT_discr
: return "DW_AT_discr";
1677 case DW_AT_discr_value
: return "DW_AT_discr_value";
1678 case DW_AT_visibility
: return "DW_AT_visibility";
1679 case DW_AT_import
: return "DW_AT_import";
1680 case DW_AT_string_length
: return "DW_AT_string_length";
1681 case DW_AT_common_reference
: return "DW_AT_common_reference";
1682 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1683 case DW_AT_const_value
: return "DW_AT_const_value";
1684 case DW_AT_containing_type
: return "DW_AT_containing_type";
1685 case DW_AT_default_value
: return "DW_AT_default_value";
1686 case DW_AT_inline
: return "DW_AT_inline";
1687 case DW_AT_is_optional
: return "DW_AT_is_optional";
1688 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1689 case DW_AT_producer
: return "DW_AT_producer";
1690 case DW_AT_prototyped
: return "DW_AT_prototyped";
1691 case DW_AT_return_addr
: return "DW_AT_return_addr";
1692 case DW_AT_start_scope
: return "DW_AT_start_scope";
1693 case DW_AT_stride_size
: return "DW_AT_stride_size";
1694 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1695 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1696 case DW_AT_accessibility
: return "DW_AT_accessibility";
1697 case DW_AT_address_class
: return "DW_AT_address_class";
1698 case DW_AT_artificial
: return "DW_AT_artificial";
1699 case DW_AT_base_types
: return "DW_AT_base_types";
1700 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1701 case DW_AT_count
: return "DW_AT_count";
1702 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1703 case DW_AT_decl_column
: return "DW_AT_decl_column";
1704 case DW_AT_decl_file
: return "DW_AT_decl_file";
1705 case DW_AT_decl_line
: return "DW_AT_decl_line";
1706 case DW_AT_declaration
: return "DW_AT_declaration";
1707 case DW_AT_discr_list
: return "DW_AT_discr_list";
1708 case DW_AT_encoding
: return "DW_AT_encoding";
1709 case DW_AT_external
: return "DW_AT_external";
1710 case DW_AT_frame_base
: return "DW_AT_frame_base";
1711 case DW_AT_friend
: return "DW_AT_friend";
1712 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1713 case DW_AT_macro_info
: return "DW_AT_macro_info";
1714 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1715 case DW_AT_priority
: return "DW_AT_priority";
1716 case DW_AT_segment
: return "DW_AT_segment";
1717 case DW_AT_specification
: return "DW_AT_specification";
1718 case DW_AT_static_link
: return "DW_AT_static_link";
1719 case DW_AT_type
: return "DW_AT_type";
1720 case DW_AT_use_location
: return "DW_AT_use_location";
1721 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1722 case DW_AT_virtuality
: return "DW_AT_virtuality";
1723 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1724 /* DWARF 2.1 values. */
1725 case DW_AT_allocated
: return "DW_AT_allocated";
1726 case DW_AT_associated
: return "DW_AT_associated";
1727 case DW_AT_data_location
: return "DW_AT_data_location";
1728 case DW_AT_stride
: return "DW_AT_stride";
1729 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1730 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1731 case DW_AT_extension
: return "DW_AT_extension";
1732 case DW_AT_ranges
: return "DW_AT_ranges";
1733 case DW_AT_trampoline
: return "DW_AT_trampoline";
1734 case DW_AT_call_column
: return "DW_AT_call_column";
1735 case DW_AT_call_file
: return "DW_AT_call_file";
1736 case DW_AT_call_line
: return "DW_AT_call_line";
1737 case DW_AT_description
: return "DW_AT_description";
1738 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1739 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1740 case DW_AT_small
: return "DW_AT_small";
1741 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1742 case DW_AT_digit_count
: return "DW_AT_digit_count";
1743 case DW_AT_picture_string
: return "DW_AT_picture_string";
1744 case DW_AT_mutable
: return "DW_AT_mutable";
1745 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1746 case DW_AT_explicit
: return "DW_AT_explicit";
1747 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1748 case DW_AT_endianity
: return "DW_AT_endianity";
1749 case DW_AT_elemental
: return "DW_AT_elemental";
1750 case DW_AT_pure
: return "DW_AT_pure";
1751 case DW_AT_recursive
: return "DW_AT_recursive";
1752 /* DWARF 4 values. */
1753 case DW_AT_signature
: return "DW_AT_signature";
1754 case DW_AT_main_subprogram
: return "DW_AT_main_subprogram";
1755 case DW_AT_data_bit_offset
: return "DW_AT_data_bit_offset";
1756 case DW_AT_const_expr
: return "DW_AT_const_expr";
1757 case DW_AT_enum_class
: return "DW_AT_enum_class";
1758 case DW_AT_linkage_name
: return "DW_AT_linkage_name";
1760 /* HP and SGI/MIPS extensions. */
1761 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1762 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1763 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1764 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1765 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1766 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1767 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1768 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1769 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1770 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1772 /* HP Extensions. */
1773 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1774 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1775 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1776 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1777 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1778 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1779 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1780 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1781 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1782 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1783 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1784 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1785 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1787 /* One value is shared by the MIPS and HP extensions: */
1788 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1790 /* GNU extensions. */
1791 case DW_AT_sf_names
: return "DW_AT_sf_names";
1792 case DW_AT_src_info
: return "DW_AT_src_info";
1793 case DW_AT_mac_info
: return "DW_AT_mac_info";
1794 case DW_AT_src_coords
: return "DW_AT_src_coords";
1795 case DW_AT_body_begin
: return "DW_AT_body_begin";
1796 case DW_AT_body_end
: return "DW_AT_body_end";
1797 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1798 case DW_AT_GNU_guarded_by
: return "DW_AT_GNU_guarded_by";
1799 case DW_AT_GNU_pt_guarded_by
: return "DW_AT_GNU_pt_guarded_by";
1800 case DW_AT_GNU_guarded
: return "DW_AT_GNU_guarded";
1801 case DW_AT_GNU_pt_guarded
: return "DW_AT_GNU_pt_guarded";
1802 case DW_AT_GNU_locks_excluded
: return "DW_AT_GNU_locks_excluded";
1803 case DW_AT_GNU_exclusive_locks_required
: return "DW_AT_GNU_exclusive_locks_required";
1804 case DW_AT_GNU_shared_locks_required
: return "DW_AT_GNU_shared_locks_required";
1805 case DW_AT_GNU_odr_signature
: return "DW_AT_GNU_odr_signature";
1806 case DW_AT_use_GNAT_descriptive_type
: return "DW_AT_use_GNAT_descriptive_type";
1807 case DW_AT_GNAT_descriptive_type
: return "DW_AT_GNAT_descriptive_type";
1809 /* UPC extension. */
1810 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1812 /* PGI (STMicroelectronics) extensions. */
1813 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1814 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1815 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1819 static char buffer
[100];
1821 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1828 static unsigned char *
1829 read_and_display_attr (unsigned long attribute
,
1831 unsigned char * data
,
1833 bfd_vma pointer_size
,
1834 bfd_vma offset_size
,
1836 debug_info
* debug_info_p
,
1838 struct dwarf_section
* section
)
1841 printf (" %-18s:", get_AT_name (attribute
));
1842 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1843 pointer_size
, offset_size
,
1844 dwarf_version
, debug_info_p
,
1852 /* Process the contents of a .debug_info section. If do_loc is non-zero
1853 then we are scanning for location lists and we do not want to display
1854 anything to the user. If do_types is non-zero, we are processing
1855 a .debug_types section instead of a .debug_info section. */
1858 process_debug_info (struct dwarf_section
*section
,
1860 enum dwarf_section_display_enum abbrev_sec
,
1864 unsigned char *start
= section
->start
;
1865 unsigned char *end
= start
+ section
->size
;
1866 unsigned char *section_begin
;
1868 unsigned int num_units
= 0;
1870 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1871 && num_debug_info_entries
== 0
1874 unsigned long length
;
1876 /* First scan the section to get the number of comp units. */
1877 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1880 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1881 will be the length. For a 64-bit DWARF section, it'll be
1882 the escape code 0xffffffff followed by an 8 byte length. */
1883 length
= byte_get (section_begin
, 4);
1885 if (length
== 0xffffffff)
1887 length
= byte_get (section_begin
+ 4, 8);
1888 section_begin
+= length
+ 12;
1890 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1892 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1896 section_begin
+= length
+ 4;
1898 /* Negative values are illegal, they may even cause infinite
1899 looping. This can happen if we can't accurately apply
1900 relocations to an object file. */
1901 if ((signed long) length
<= 0)
1903 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1910 error (_("No comp units in %s section ?"), section
->name
);
1914 /* Then allocate an array to hold the information. */
1915 debug_information
= (debug_info
*) cmalloc (num_units
,
1916 sizeof (* debug_information
));
1917 if (debug_information
== NULL
)
1919 error (_("Not enough memory for a debug info array of %u entries"),
1927 printf (_("Contents of the %s section:\n\n"), section
->name
);
1929 load_debug_section (str
, file
);
1932 load_debug_section (abbrev_sec
, file
);
1933 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
1935 warn (_("Unable to locate %s section!\n"),
1936 debug_displays
[abbrev_sec
].section
.name
);
1940 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1942 DWARF2_Internal_CompUnit compunit
;
1943 unsigned char *hdrptr
;
1944 unsigned char *tags
;
1948 int initial_length_size
;
1949 unsigned char signature
[8] = { 0 };
1950 unsigned long type_offset
= 0;
1954 compunit
.cu_length
= byte_get (hdrptr
, 4);
1957 if (compunit
.cu_length
== 0xffffffff)
1959 compunit
.cu_length
= byte_get (hdrptr
, 8);
1962 initial_length_size
= 12;
1967 initial_length_size
= 4;
1970 compunit
.cu_version
= byte_get (hdrptr
, 2);
1973 cu_offset
= start
- section_begin
;
1975 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1976 hdrptr
+= offset_size
;
1978 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1985 for (i
= 0; i
< 8; i
++)
1987 signature
[i
] = byte_get (hdrptr
, 1);
1991 type_offset
= byte_get (hdrptr
, offset_size
);
1992 hdrptr
+= offset_size
;
1995 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1996 && num_debug_info_entries
== 0
1999 debug_information
[unit
].cu_offset
= cu_offset
;
2000 debug_information
[unit
].pointer_size
2001 = compunit
.cu_pointer_size
;
2002 debug_information
[unit
].offset_size
= offset_size
;
2003 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2004 debug_information
[unit
].base_address
= 0;
2005 debug_information
[unit
].loc_offsets
= NULL
;
2006 debug_information
[unit
].have_frame_base
= NULL
;
2007 debug_information
[unit
].max_loc_offsets
= 0;
2008 debug_information
[unit
].num_loc_offsets
= 0;
2009 debug_information
[unit
].range_lists
= NULL
;
2010 debug_information
[unit
].max_range_lists
= 0;
2011 debug_information
[unit
].num_range_lists
= 0;
2016 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2017 dwarf_vmatoa ("x", cu_offset
));
2018 printf (_(" Length: 0x%s (%s)\n"),
2019 dwarf_vmatoa ("x", compunit
.cu_length
),
2020 initial_length_size
== 8 ? "64-bit" : "32-bit");
2021 printf (_(" Version: %d\n"), compunit
.cu_version
);
2022 printf (_(" Abbrev Offset: %s\n"),
2023 dwarf_vmatoa ("d", compunit
.cu_abbrev_offset
));
2024 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2028 printf (_(" Signature: "));
2029 for (i
= 0; i
< 8; i
++)
2030 printf ("%02x", signature
[i
]);
2032 printf (_(" Type Offset: 0x%lx\n"), type_offset
);
2036 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2039 warn (_("Debug info is corrupted, length of CU at %s"
2040 " extends beyond end of section (length = %s)\n"),
2041 dwarf_vmatoa ("x", cu_offset
),
2042 dwarf_vmatoa ("x", compunit
.cu_length
));
2046 start
+= compunit
.cu_length
+ initial_length_size
;
2048 if (compunit
.cu_version
!= 2
2049 && compunit
.cu_version
!= 3
2050 && compunit
.cu_version
!= 4)
2052 warn (_("CU at offset %s contains corrupt or "
2053 "unsupported version number: %d.\n"),
2054 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2060 /* Process the abbrevs used by this compilation unit. DWARF
2061 sections under Mach-O have non-zero addresses. */
2062 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
2063 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2064 (unsigned long) compunit
.cu_abbrev_offset
,
2065 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2067 process_abbrev_section
2068 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2069 + compunit
.cu_abbrev_offset
,
2070 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2071 + debug_displays
[abbrev_sec
].section
.size
);
2074 while (tags
< start
)
2076 unsigned int bytes_read
;
2077 unsigned long abbrev_number
;
2078 unsigned long die_offset
;
2079 abbrev_entry
*entry
;
2082 die_offset
= tags
- section_begin
;
2084 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2087 /* A null DIE marks the end of a list of siblings or it may also be
2088 a section padding. */
2089 if (abbrev_number
== 0)
2091 /* Check if it can be a section padding for the last CU. */
2092 if (level
== 0 && start
== end
)
2096 for (chk
= tags
; chk
< start
; chk
++)
2106 static unsigned num_bogus_warns
= 0;
2108 if (num_bogus_warns
< 3)
2110 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2113 if (num_bogus_warns
== 3)
2114 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2121 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2122 level
, die_offset
, abbrev_number
);
2124 /* Scan through the abbreviation list until we reach the
2126 for (entry
= first_abbrev
;
2127 entry
&& entry
->entry
!= abbrev_number
;
2128 entry
= entry
->next
)
2138 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2139 die_offset
, abbrev_number
);
2144 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2149 need_base_address
= 0;
2151 case DW_TAG_compile_unit
:
2152 need_base_address
= 1;
2154 case DW_TAG_entry_point
:
2155 case DW_TAG_subprogram
:
2156 need_base_address
= 0;
2157 /* Assuming that there is no DW_AT_frame_base. */
2158 have_frame_base
= 0;
2162 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2165 /* Show the offset from where the tag was extracted. */
2166 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2168 tags
= read_and_display_attr (attr
->attribute
,
2171 compunit
.cu_pointer_size
,
2173 compunit
.cu_version
,
2174 debug_information
+ unit
,
2178 if (entry
->children
)
2183 /* Set num_debug_info_entries here so that it can be used to check if
2184 we need to process .debug_loc and .debug_ranges sections. */
2185 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2186 && num_debug_info_entries
== 0
2188 num_debug_info_entries
= num_units
;
2198 /* Locate and scan the .debug_info section in the file and record the pointer
2199 sizes and offsets for the compilation units in it. Usually an executable
2200 will have just one pointer size, but this is not guaranteed, and so we try
2201 not to make any assumptions. Returns zero upon failure, or the number of
2202 compilation units upon success. */
2205 load_debug_info (void * file
)
2207 /* Reset the last pointer size so that we can issue correct error
2208 messages if we are displaying the contents of more than one section. */
2209 last_pointer_size
= 0;
2210 warned_about_missing_comp_units
= FALSE
;
2212 /* If we have already tried and failed to load the .debug_info
2213 section then do not bother to repear the task. */
2214 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2217 /* If we already have the information there is nothing else to do. */
2218 if (num_debug_info_entries
> 0)
2219 return num_debug_info_entries
;
2221 if (load_debug_section (info
, file
)
2222 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2223 return num_debug_info_entries
;
2225 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2230 display_debug_lines_raw (struct dwarf_section
*section
,
2231 unsigned char *data
,
2234 unsigned char *start
= section
->start
;
2236 printf (_("Raw dump of debug contents of section %s:\n\n"),
2241 DWARF2_Internal_LineInfo linfo
;
2242 unsigned char *standard_opcodes
;
2243 unsigned char *end_of_sequence
;
2244 unsigned char *hdrptr
;
2245 unsigned long hdroff
;
2246 int initial_length_size
;
2251 hdroff
= hdrptr
- start
;
2253 /* Check the length of the block. */
2254 linfo
.li_length
= byte_get (hdrptr
, 4);
2257 if (linfo
.li_length
== 0xffffffff)
2259 /* This section is 64-bit DWARF 3. */
2260 linfo
.li_length
= byte_get (hdrptr
, 8);
2263 initial_length_size
= 12;
2268 initial_length_size
= 4;
2271 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2274 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2279 /* Check its version number. */
2280 linfo
.li_version
= byte_get (hdrptr
, 2);
2282 if (linfo
.li_version
!= 2
2283 && linfo
.li_version
!= 3
2284 && linfo
.li_version
!= 4)
2286 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2290 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2291 hdrptr
+= offset_size
;
2292 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2294 if (linfo
.li_version
>= 4)
2296 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2298 if (linfo
.li_max_ops_per_insn
== 0)
2300 warn (_("Invalid maximum operations per insn.\n"));
2305 linfo
.li_max_ops_per_insn
= 1;
2306 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2308 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2310 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2312 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2315 /* Sign extend the line base field. */
2316 linfo
.li_line_base
<<= 24;
2317 linfo
.li_line_base
>>= 24;
2319 printf (_(" Offset: 0x%lx\n"), hdroff
);
2320 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2321 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2322 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2323 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2324 if (linfo
.li_version
>= 4)
2325 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2326 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2327 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2328 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2329 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2331 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2333 reset_state_machine (linfo
.li_default_is_stmt
);
2335 /* Display the contents of the Opcodes table. */
2336 standard_opcodes
= hdrptr
;
2338 printf (_("\n Opcodes:\n"));
2340 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2341 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2343 /* Display the contents of the Directory table. */
2344 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2347 printf (_("\n The Directory Table is empty.\n"));
2350 printf (_("\n The Directory Table:\n"));
2354 printf (" %s\n", data
);
2356 data
+= strlen ((char *) data
) + 1;
2360 /* Skip the NUL at the end of the table. */
2363 /* Display the contents of the File Name table. */
2365 printf (_("\n The File Name Table is empty.\n"));
2368 printf (_("\n The File Name Table:\n"));
2369 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2373 unsigned char *name
;
2374 unsigned int bytes_read
;
2376 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2379 data
+= strlen ((char *) data
) + 1;
2381 printf ("%" BFD_VMA_FMT
"u\t",
2382 read_leb128 (data
, & bytes_read
, 0));
2384 printf ("%" BFD_VMA_FMT
"u\t",
2385 read_leb128 (data
, & bytes_read
, 0));
2387 printf ("%" BFD_VMA_FMT
"u\t",
2388 read_leb128 (data
, & bytes_read
, 0));
2390 printf ("%s\n", name
);
2394 /* Skip the NUL at the end of the table. */
2397 /* Now display the statements. */
2398 printf (_("\n Line Number Statements:\n"));
2400 while (data
< end_of_sequence
)
2402 unsigned char op_code
;
2404 unsigned long int uladv
;
2405 unsigned int bytes_read
;
2409 if (op_code
>= linfo
.li_opcode_base
)
2411 op_code
-= linfo
.li_opcode_base
;
2412 uladv
= (op_code
/ linfo
.li_line_range
);
2413 if (linfo
.li_max_ops_per_insn
== 1)
2415 uladv
*= linfo
.li_min_insn_length
;
2416 state_machine_regs
.address
+= uladv
;
2417 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2418 op_code
, uladv
, state_machine_regs
.address
);
2422 state_machine_regs
.address
2423 += ((state_machine_regs
.op_index
+ uladv
)
2424 / linfo
.li_max_ops_per_insn
)
2425 * linfo
.li_min_insn_length
;
2426 state_machine_regs
.op_index
2427 = (state_machine_regs
.op_index
+ uladv
)
2428 % linfo
.li_max_ops_per_insn
;
2429 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx[%d]"),
2430 op_code
, uladv
, state_machine_regs
.address
,
2431 state_machine_regs
.op_index
);
2433 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2434 state_machine_regs
.line
+= adv
;
2435 printf (_(" and Line by %d to %d\n"),
2436 adv
, state_machine_regs
.line
);
2438 else switch (op_code
)
2440 case DW_LNS_extended_op
:
2441 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2445 printf (_(" Copy\n"));
2448 case DW_LNS_advance_pc
:
2449 uladv
= read_leb128 (data
, & bytes_read
, 0);
2451 if (linfo
.li_max_ops_per_insn
== 1)
2453 uladv
*= linfo
.li_min_insn_length
;
2454 state_machine_regs
.address
+= uladv
;
2455 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2456 state_machine_regs
.address
);
2460 state_machine_regs
.address
2461 += ((state_machine_regs
.op_index
+ uladv
)
2462 / linfo
.li_max_ops_per_insn
)
2463 * linfo
.li_min_insn_length
;
2464 state_machine_regs
.op_index
2465 = (state_machine_regs
.op_index
+ uladv
)
2466 % linfo
.li_max_ops_per_insn
;
2467 printf (_(" Advance PC by %lu to 0x%lx[%d]\n"), uladv
,
2468 state_machine_regs
.address
,
2469 state_machine_regs
.op_index
);
2473 case DW_LNS_advance_line
:
2474 adv
= read_leb128 (data
, & bytes_read
, 1);
2476 state_machine_regs
.line
+= adv
;
2477 printf (_(" Advance Line by %d to %d\n"), adv
,
2478 state_machine_regs
.line
);
2481 case DW_LNS_set_file
:
2482 adv
= read_leb128 (data
, & bytes_read
, 0);
2484 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2486 state_machine_regs
.file
= adv
;
2489 case DW_LNS_set_column
:
2490 uladv
= read_leb128 (data
, & bytes_read
, 0);
2492 printf (_(" Set column to %lu\n"), uladv
);
2493 state_machine_regs
.column
= uladv
;
2496 case DW_LNS_negate_stmt
:
2497 adv
= state_machine_regs
.is_stmt
;
2499 printf (_(" Set is_stmt to %d\n"), adv
);
2500 state_machine_regs
.is_stmt
= adv
;
2503 case DW_LNS_set_basic_block
:
2504 printf (_(" Set basic block\n"));
2505 state_machine_regs
.basic_block
= 1;
2508 case DW_LNS_const_add_pc
:
2509 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2510 if (linfo
.li_max_ops_per_insn
)
2512 uladv
*= linfo
.li_min_insn_length
;
2513 state_machine_regs
.address
+= uladv
;
2514 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2515 state_machine_regs
.address
);
2519 state_machine_regs
.address
2520 += ((state_machine_regs
.op_index
+ uladv
)
2521 / linfo
.li_max_ops_per_insn
)
2522 * linfo
.li_min_insn_length
;
2523 state_machine_regs
.op_index
2524 = (state_machine_regs
.op_index
+ uladv
)
2525 % linfo
.li_max_ops_per_insn
;
2526 printf (_(" Advance PC by constant %lu to 0x%lx[%d]\n"),
2527 uladv
, state_machine_regs
.address
,
2528 state_machine_regs
.op_index
);
2532 case DW_LNS_fixed_advance_pc
:
2533 uladv
= byte_get (data
, 2);
2535 state_machine_regs
.address
+= uladv
;
2536 state_machine_regs
.op_index
= 0;
2537 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2538 uladv
, state_machine_regs
.address
);
2541 case DW_LNS_set_prologue_end
:
2542 printf (_(" Set prologue_end to true\n"));
2545 case DW_LNS_set_epilogue_begin
:
2546 printf (_(" Set epilogue_begin to true\n"));
2549 case DW_LNS_set_isa
:
2550 uladv
= read_leb128 (data
, & bytes_read
, 0);
2552 printf (_(" Set ISA to %lu\n"), uladv
);
2556 printf (_(" Unknown opcode %d with operands: "), op_code
);
2558 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2560 printf ("0x%" BFD_VMA_FMT
"x%s",
2561 read_leb128 (data
, &bytes_read
, 0),
2562 i
== 1 ? "" : ", ");
2577 unsigned char *name
;
2578 unsigned int directory_index
;
2579 unsigned int modification_date
;
2580 unsigned int length
;
2583 /* Output a decoded representation of the .debug_line section. */
2586 display_debug_lines_decoded (struct dwarf_section
*section
,
2587 unsigned char *data
,
2590 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2595 /* This loop amounts to one iteration per compilation unit. */
2596 DWARF2_Internal_LineInfo linfo
;
2597 unsigned char *standard_opcodes
;
2598 unsigned char *end_of_sequence
;
2599 unsigned char *hdrptr
;
2600 int initial_length_size
;
2603 File_Entry
*file_table
= NULL
;
2604 unsigned char **directory_table
= NULL
;
2608 /* Extract information from the Line Number Program Header.
2609 (section 6.2.4 in the Dwarf3 doc). */
2611 /* Get the length of this CU's line number information block. */
2612 linfo
.li_length
= byte_get (hdrptr
, 4);
2615 if (linfo
.li_length
== 0xffffffff)
2617 /* This section is 64-bit DWARF 3. */
2618 linfo
.li_length
= byte_get (hdrptr
, 8);
2621 initial_length_size
= 12;
2626 initial_length_size
= 4;
2629 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2631 warn (_("The line info appears to be corrupt - "
2632 "the section is too small\n"));
2636 /* Get this CU's Line Number Block version number. */
2637 linfo
.li_version
= byte_get (hdrptr
, 2);
2639 if (linfo
.li_version
!= 2
2640 && linfo
.li_version
!= 3
2641 && linfo
.li_version
!= 4)
2643 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2648 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2649 hdrptr
+= offset_size
;
2650 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2652 if (linfo
.li_version
>= 4)
2654 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2656 if (linfo
.li_max_ops_per_insn
== 0)
2658 warn (_("Invalid maximum operations per insn.\n"));
2663 linfo
.li_max_ops_per_insn
= 1;
2664 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2666 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2668 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2670 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2673 /* Sign extend the line base field. */
2674 linfo
.li_line_base
<<= 24;
2675 linfo
.li_line_base
>>= 24;
2677 /* Find the end of this CU's Line Number Information Block. */
2678 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2680 reset_state_machine (linfo
.li_default_is_stmt
);
2682 /* Save a pointer to the contents of the Opcodes table. */
2683 standard_opcodes
= hdrptr
;
2685 /* Traverse the Directory table just to count entries. */
2686 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2689 unsigned int n_directories
= 0;
2690 unsigned char *ptr_directory_table
= data
;
2694 data
+= strlen ((char *) data
) + 1;
2698 /* Go through the directory table again to save the directories. */
2699 directory_table
= (unsigned char **)
2700 xmalloc (n_directories
* sizeof (unsigned char *));
2703 while (*ptr_directory_table
!= 0)
2705 directory_table
[i
] = ptr_directory_table
;
2706 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2710 /* Skip the NUL at the end of the table. */
2713 /* Traverse the File Name table just to count the entries. */
2716 unsigned int n_files
= 0;
2717 unsigned char *ptr_file_name_table
= data
;
2721 unsigned int bytes_read
;
2723 /* Skip Name, directory index, last modification time and length
2725 data
+= strlen ((char *) data
) + 1;
2726 read_leb128 (data
, & bytes_read
, 0);
2728 read_leb128 (data
, & bytes_read
, 0);
2730 read_leb128 (data
, & bytes_read
, 0);
2736 /* Go through the file table again to save the strings. */
2737 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2740 while (*ptr_file_name_table
!= 0)
2742 unsigned int bytes_read
;
2744 file_table
[i
].name
= ptr_file_name_table
;
2745 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2747 /* We are not interested in directory, time or size. */
2748 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2750 ptr_file_name_table
+= bytes_read
;
2751 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2753 ptr_file_name_table
+= bytes_read
;
2754 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2755 ptr_file_name_table
+= bytes_read
;
2760 /* Print the Compilation Unit's name and a header. */
2761 if (directory_table
== NULL
)
2763 printf (_("CU: %s:\n"), file_table
[0].name
);
2764 printf (_("File name Line number Starting address\n"));
2768 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2769 printf (_("CU: %s/%s:\n"), directory_table
[0],
2770 file_table
[0].name
);
2772 printf ("%s:\n", file_table
[0].name
);
2774 printf (_("File name Line number Starting address\n"));
2778 /* Skip the NUL at the end of the table. */
2781 /* This loop iterates through the Dwarf Line Number Program. */
2782 while (data
< end_of_sequence
)
2784 unsigned char op_code
;
2786 unsigned long int uladv
;
2787 unsigned int bytes_read
;
2788 int is_special_opcode
= 0;
2792 if (op_code
>= linfo
.li_opcode_base
)
2794 op_code
-= linfo
.li_opcode_base
;
2795 uladv
= (op_code
/ linfo
.li_line_range
);
2796 if (linfo
.li_max_ops_per_insn
== 1)
2798 uladv
*= linfo
.li_min_insn_length
;
2799 state_machine_regs
.address
+= uladv
;
2803 state_machine_regs
.address
2804 += ((state_machine_regs
.op_index
+ uladv
)
2805 / linfo
.li_max_ops_per_insn
)
2806 * linfo
.li_min_insn_length
;
2807 state_machine_regs
.op_index
2808 = (state_machine_regs
.op_index
+ uladv
)
2809 % linfo
.li_max_ops_per_insn
;
2812 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2813 state_machine_regs
.line
+= adv
;
2814 is_special_opcode
= 1;
2816 else switch (op_code
)
2818 case DW_LNS_extended_op
:
2820 unsigned int ext_op_code_len
;
2821 unsigned char ext_op_code
;
2822 unsigned char *op_code_data
= data
;
2824 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2825 op_code_data
+= bytes_read
;
2827 if (ext_op_code_len
== 0)
2829 warn (_("badly formed extended line op encountered!\n"));
2832 ext_op_code_len
+= bytes_read
;
2833 ext_op_code
= *op_code_data
++;
2835 switch (ext_op_code
)
2837 case DW_LNE_end_sequence
:
2838 reset_state_machine (linfo
.li_default_is_stmt
);
2840 case DW_LNE_set_address
:
2841 state_machine_regs
.address
=
2842 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2843 state_machine_regs
.op_index
= 0;
2845 case DW_LNE_define_file
:
2847 unsigned int dir_index
= 0;
2849 ++state_machine_regs
.last_file_entry
;
2850 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2851 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2852 op_code_data
+= bytes_read
;
2853 read_leb128 (op_code_data
, & bytes_read
, 0);
2854 op_code_data
+= bytes_read
;
2855 read_leb128 (op_code_data
, & bytes_read
, 0);
2857 printf ("%s:\n", directory_table
[dir_index
]);
2861 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2864 data
+= ext_op_code_len
;
2870 case DW_LNS_advance_pc
:
2871 uladv
= read_leb128 (data
, & bytes_read
, 0);
2873 if (linfo
.li_max_ops_per_insn
== 1)
2875 uladv
*= linfo
.li_min_insn_length
;
2876 state_machine_regs
.address
+= uladv
;
2880 state_machine_regs
.address
2881 += ((state_machine_regs
.op_index
+ uladv
)
2882 / linfo
.li_max_ops_per_insn
)
2883 * linfo
.li_min_insn_length
;
2884 state_machine_regs
.op_index
2885 = (state_machine_regs
.op_index
+ uladv
)
2886 % linfo
.li_max_ops_per_insn
;
2890 case DW_LNS_advance_line
:
2891 adv
= read_leb128 (data
, & bytes_read
, 1);
2893 state_machine_regs
.line
+= adv
;
2896 case DW_LNS_set_file
:
2897 adv
= read_leb128 (data
, & bytes_read
, 0);
2899 state_machine_regs
.file
= adv
;
2900 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2902 /* If directory index is 0, that means current directory. */
2903 printf ("\n./%s:[++]\n",
2904 file_table
[state_machine_regs
.file
- 1].name
);
2908 /* The directory index starts counting at 1. */
2909 printf ("\n%s/%s:\n",
2910 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2911 file_table
[state_machine_regs
.file
- 1].name
);
2915 case DW_LNS_set_column
:
2916 uladv
= read_leb128 (data
, & bytes_read
, 0);
2918 state_machine_regs
.column
= uladv
;
2921 case DW_LNS_negate_stmt
:
2922 adv
= state_machine_regs
.is_stmt
;
2924 state_machine_regs
.is_stmt
= adv
;
2927 case DW_LNS_set_basic_block
:
2928 state_machine_regs
.basic_block
= 1;
2931 case DW_LNS_const_add_pc
:
2932 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2933 if (linfo
.li_max_ops_per_insn
== 1)
2935 uladv
*= linfo
.li_min_insn_length
;
2936 state_machine_regs
.address
+= uladv
;
2940 state_machine_regs
.address
2941 += ((state_machine_regs
.op_index
+ uladv
)
2942 / linfo
.li_max_ops_per_insn
)
2943 * linfo
.li_min_insn_length
;
2944 state_machine_regs
.op_index
2945 = (state_machine_regs
.op_index
+ uladv
)
2946 % linfo
.li_max_ops_per_insn
;
2950 case DW_LNS_fixed_advance_pc
:
2951 uladv
= byte_get (data
, 2);
2953 state_machine_regs
.address
+= uladv
;
2954 state_machine_regs
.op_index
= 0;
2957 case DW_LNS_set_prologue_end
:
2960 case DW_LNS_set_epilogue_begin
:
2963 case DW_LNS_set_isa
:
2964 uladv
= read_leb128 (data
, & bytes_read
, 0);
2966 printf (_(" Set ISA to %lu\n"), uladv
);
2970 printf (_(" Unknown opcode %d with operands: "), op_code
);
2972 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2974 printf ("0x%" BFD_VMA_FMT
"x%s",
2975 read_leb128 (data
, &bytes_read
, 0),
2976 i
== 1 ? "" : ", ");
2983 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2984 to the DWARF address/line matrix. */
2985 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
2986 || (op_code
== DW_LNS_copy
))
2988 const unsigned int MAX_FILENAME_LENGTH
= 35;
2989 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
2990 char *newFileName
= NULL
;
2991 size_t fileNameLength
= strlen (fileName
);
2993 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
2995 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
2996 /* Truncate file name */
2997 strncpy (newFileName
,
2998 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
2999 MAX_FILENAME_LENGTH
+ 1);
3003 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3004 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3007 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3009 if (linfo
.li_max_ops_per_insn
== 1)
3010 printf ("%-35s %11d %#18lx\n", newFileName
,
3011 state_machine_regs
.line
,
3012 state_machine_regs
.address
);
3014 printf ("%-35s %11d %#18lx[%d]\n", newFileName
,
3015 state_machine_regs
.line
,
3016 state_machine_regs
.address
,
3017 state_machine_regs
.op_index
);
3021 if (linfo
.li_max_ops_per_insn
== 1)
3022 printf ("%s %11d %#18lx\n", newFileName
,
3023 state_machine_regs
.line
,
3024 state_machine_regs
.address
);
3026 printf ("%s %11d %#18lx[%d]\n", newFileName
,
3027 state_machine_regs
.line
,
3028 state_machine_regs
.address
,
3029 state_machine_regs
.op_index
);
3032 if (op_code
== DW_LNE_end_sequence
)
3040 free (directory_table
);
3041 directory_table
= NULL
;
3049 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3051 unsigned char *data
= section
->start
;
3052 unsigned char *end
= data
+ section
->size
;
3054 int retValDecoded
= 1;
3056 if (do_debug_lines
== 0)
3057 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3059 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3060 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3062 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3063 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3065 if (!retValRaw
|| !retValDecoded
)
3072 find_debug_info_for_offset (unsigned long offset
)
3076 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3079 for (i
= 0; i
< num_debug_info_entries
; i
++)
3080 if (debug_information
[i
].cu_offset
== offset
)
3081 return debug_information
+ i
;
3087 display_debug_pubnames (struct dwarf_section
*section
,
3088 void *file ATTRIBUTE_UNUSED
)
3090 DWARF2_Internal_PubNames names
;
3091 unsigned char *start
= section
->start
;
3092 unsigned char *end
= start
+ section
->size
;
3094 /* It does not matter if this load fails,
3095 we test for that later on. */
3096 load_debug_info (file
);
3098 printf (_("Contents of the %s section:\n\n"), section
->name
);
3102 unsigned char *data
;
3103 unsigned long offset
;
3104 int offset_size
, initial_length_size
;
3108 names
.pn_length
= byte_get (data
, 4);
3110 if (names
.pn_length
== 0xffffffff)
3112 names
.pn_length
= byte_get (data
, 8);
3115 initial_length_size
= 12;
3120 initial_length_size
= 4;
3123 names
.pn_version
= byte_get (data
, 2);
3126 names
.pn_offset
= byte_get (data
, offset_size
);
3127 data
+= offset_size
;
3129 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3130 && num_debug_info_entries
> 0
3131 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3132 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3133 (unsigned long) names
.pn_offset
, section
->name
);
3135 names
.pn_size
= byte_get (data
, offset_size
);
3136 data
+= offset_size
;
3138 start
+= names
.pn_length
+ initial_length_size
;
3140 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3142 static int warned
= 0;
3146 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3153 printf (_(" Length: %ld\n"),
3154 (long) names
.pn_length
);
3155 printf (_(" Version: %d\n"),
3157 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3158 (unsigned long) names
.pn_offset
);
3159 printf (_(" Size of area in .debug_info section: %ld\n"),
3160 (long) names
.pn_size
);
3162 printf (_("\n Offset\tName\n"));
3166 offset
= byte_get (data
, offset_size
);
3170 data
+= offset_size
;
3171 printf (" %-6lx\t%s\n", offset
, data
);
3172 data
+= strlen ((char *) data
) + 1;
3175 while (offset
!= 0);
3183 display_debug_macinfo (struct dwarf_section
*section
,
3184 void *file ATTRIBUTE_UNUSED
)
3186 unsigned char *start
= section
->start
;
3187 unsigned char *end
= start
+ section
->size
;
3188 unsigned char *curr
= start
;
3189 unsigned int bytes_read
;
3190 enum dwarf_macinfo_record_type op
;
3192 printf (_("Contents of the %s section:\n\n"), section
->name
);
3196 unsigned int lineno
;
3199 op
= (enum dwarf_macinfo_record_type
) *curr
;
3204 case DW_MACINFO_start_file
:
3206 unsigned int filenum
;
3208 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3210 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3213 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3218 case DW_MACINFO_end_file
:
3219 printf (_(" DW_MACINFO_end_file\n"));
3222 case DW_MACINFO_define
:
3223 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3225 string
= (char *) curr
;
3226 curr
+= strlen (string
) + 1;
3227 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3231 case DW_MACINFO_undef
:
3232 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3234 string
= (char *) curr
;
3235 curr
+= strlen (string
) + 1;
3236 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3240 case DW_MACINFO_vendor_ext
:
3242 unsigned int constant
;
3244 constant
= read_leb128 (curr
, & bytes_read
, 0);
3246 string
= (char *) curr
;
3247 curr
+= strlen (string
) + 1;
3248 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3259 display_debug_abbrev (struct dwarf_section
*section
,
3260 void *file ATTRIBUTE_UNUSED
)
3262 abbrev_entry
*entry
;
3263 unsigned char *start
= section
->start
;
3264 unsigned char *end
= start
+ section
->size
;
3266 printf (_("Contents of the %s section:\n\n"), section
->name
);
3272 start
= process_abbrev_section (start
, end
);
3274 if (first_abbrev
== NULL
)
3277 printf (_(" Number TAG\n"));
3279 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3283 printf (" %ld %s [%s]\n",
3285 get_TAG_name (entry
->tag
),
3286 entry
->children
? _("has children") : _("no children"));
3288 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3289 printf (" %-18s %s\n",
3290 get_AT_name (attr
->attribute
),
3291 get_FORM_name (attr
->form
));
3302 display_debug_loc (struct dwarf_section
*section
, void *file
)
3304 unsigned char *start
= section
->start
;
3305 unsigned char *section_end
;
3306 unsigned long bytes
;
3307 unsigned char *section_begin
= start
;
3308 unsigned int num_loc_list
= 0;
3309 unsigned long last_offset
= 0;
3310 unsigned int first
= 0;
3313 int seen_first_offset
= 0;
3314 int use_debug_info
= 1;
3315 unsigned char *next
;
3317 bytes
= section
->size
;
3318 section_end
= start
+ bytes
;
3322 printf (_("\nThe %s section is empty.\n"), section
->name
);
3326 if (load_debug_info (file
) == 0)
3328 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3333 /* Check the order of location list in .debug_info section. If
3334 offsets of location lists are in the ascending order, we can
3335 use `debug_information' directly. */
3336 for (i
= 0; i
< num_debug_info_entries
; i
++)
3340 num
= debug_information
[i
].num_loc_offsets
;
3341 num_loc_list
+= num
;
3343 /* Check if we can use `debug_information' directly. */
3344 if (use_debug_info
&& num
!= 0)
3346 if (!seen_first_offset
)
3348 /* This is the first location list. */
3349 last_offset
= debug_information
[i
].loc_offsets
[0];
3351 seen_first_offset
= 1;
3357 for (; j
< num
; j
++)
3360 debug_information
[i
].loc_offsets
[j
])
3365 last_offset
= debug_information
[i
].loc_offsets
[j
];
3370 if (!use_debug_info
)
3371 /* FIXME: Should we handle this case? */
3372 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3374 if (!seen_first_offset
)
3375 error (_("No location lists in .debug_info section!\n"));
3377 /* DWARF sections under Mach-O have non-zero addresses. */
3378 if (debug_information
[first
].num_loc_offsets
> 0
3379 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3380 warn (_("Location lists in %s section start at 0x%s\n"),
3382 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
3384 printf (_("Contents of the %s section:\n\n"), section
->name
);
3385 printf (_(" Offset Begin End Expression\n"));
3387 seen_first_offset
= 0;
3388 for (i
= first
; i
< num_debug_info_entries
; i
++)
3392 unsigned short length
;
3393 unsigned long offset
;
3394 unsigned int pointer_size
;
3395 unsigned int offset_size
;
3397 unsigned long cu_offset
;
3398 unsigned long base_address
;
3399 int need_frame_base
;
3402 pointer_size
= debug_information
[i
].pointer_size
;
3403 cu_offset
= debug_information
[i
].cu_offset
;
3404 offset_size
= debug_information
[i
].offset_size
;
3405 dwarf_version
= debug_information
[i
].dwarf_version
;
3407 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3409 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3410 /* DWARF sections under Mach-O have non-zero addresses. */
3411 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3412 next
= section_begin
+ offset
;
3413 base_address
= debug_information
[i
].base_address
;
3415 if (!seen_first_offset
)
3416 seen_first_offset
= 1;
3420 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3421 (unsigned long) (start
- section_begin
),
3422 (unsigned long) (next
- section_begin
));
3423 else if (start
> next
)
3424 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3425 (unsigned long) (start
- section_begin
),
3426 (unsigned long) (next
- section_begin
));
3430 if (offset
>= bytes
)
3432 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3439 if (start
+ 2 * pointer_size
> section_end
)
3441 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3446 /* Note: we use sign extension here in order to be sure that
3447 we can detect the -1 escape value. Sign extension into the
3448 top 32 bits of a 32-bit address will not affect the values
3449 that we display since we always show hex values, and always
3450 the bottom 32-bits. */
3451 begin
= byte_get_signed (start
, pointer_size
);
3452 start
+= pointer_size
;
3453 end
= byte_get_signed (start
, pointer_size
);
3454 start
+= pointer_size
;
3456 printf (" %8.8lx ", offset
);
3458 if (begin
== 0 && end
== 0)
3460 printf (_("<End of list>\n"));
3464 /* Check base address specifiers. */
3465 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3468 print_dwarf_vma (begin
, pointer_size
);
3469 print_dwarf_vma (end
, pointer_size
);
3470 printf (_("(base address)\n"));
3474 if (start
+ 2 > section_end
)
3476 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3481 length
= byte_get (start
, 2);
3484 if (start
+ length
> section_end
)
3486 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3491 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3492 print_dwarf_vma (end
+ base_address
, pointer_size
);
3495 need_frame_base
= decode_location_expression (start
,
3500 cu_offset
, section
);
3503 if (need_frame_base
&& !has_frame_base
)
3504 printf (_(" [without DW_AT_frame_base]"));
3507 fputs (_(" (start == end)"), stdout
);
3508 else if (begin
> end
)
3509 fputs (_(" (start > end)"), stdout
);
3518 if (start
< section_end
)
3519 warn (_("There are %ld unused bytes at the end of section %s\n"),
3520 (long) (section_end
- start
), section
->name
);
3526 display_debug_str (struct dwarf_section
*section
,
3527 void *file ATTRIBUTE_UNUSED
)
3529 unsigned char *start
= section
->start
;
3530 unsigned long bytes
= section
->size
;
3531 dwarf_vma addr
= section
->address
;
3535 printf (_("\nThe %s section is empty.\n"), section
->name
);
3539 printf (_("Contents of the %s section:\n\n"), section
->name
);
3547 lbytes
= (bytes
> 16 ? 16 : bytes
);
3549 printf (" 0x%8.8lx ", (unsigned long) addr
);
3551 for (j
= 0; j
< 16; j
++)
3554 printf ("%2.2x", start
[j
]);
3562 for (j
= 0; j
< lbytes
; j
++)
3565 if (k
>= ' ' && k
< 0x80)
3584 display_debug_info (struct dwarf_section
*section
, void *file
)
3586 return process_debug_info (section
, file
, abbrev
, 0, 0);
3590 display_debug_types (struct dwarf_section
*section
, void *file
)
3592 return process_debug_info (section
, file
, abbrev
, 0, 1);
3596 display_trace_info (struct dwarf_section
*section
, void *file
)
3598 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
3602 display_debug_aranges (struct dwarf_section
*section
,
3603 void *file ATTRIBUTE_UNUSED
)
3605 unsigned char *start
= section
->start
;
3606 unsigned char *end
= start
+ section
->size
;
3608 printf (_("Contents of the %s section:\n\n"), section
->name
);
3610 /* It does not matter if this load fails,
3611 we test for that later on. */
3612 load_debug_info (file
);
3616 unsigned char *hdrptr
;
3617 DWARF2_Internal_ARange arange
;
3618 unsigned char *addr_ranges
;
3621 unsigned char address_size
;
3624 int initial_length_size
;
3628 arange
.ar_length
= byte_get (hdrptr
, 4);
3631 if (arange
.ar_length
== 0xffffffff)
3633 arange
.ar_length
= byte_get (hdrptr
, 8);
3636 initial_length_size
= 12;
3641 initial_length_size
= 4;
3644 arange
.ar_version
= byte_get (hdrptr
, 2);
3647 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3648 hdrptr
+= offset_size
;
3650 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3651 && num_debug_info_entries
> 0
3652 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3653 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3654 (unsigned long) arange
.ar_info_offset
, section
->name
);
3656 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3659 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3662 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3664 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3668 printf (_(" Length: %ld\n"),
3669 (long) arange
.ar_length
);
3670 printf (_(" Version: %d\n"), arange
.ar_version
);
3671 printf (_(" Offset into .debug_info: 0x%lx\n"),
3672 (unsigned long) arange
.ar_info_offset
);
3673 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3674 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3676 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3678 /* The DWARF spec does not require that the address size be a power
3679 of two, but we do. This will have to change if we ever encounter
3680 an uneven architecture. */
3681 if ((address_size
& (address_size
- 1)) != 0)
3683 warn (_("Pointer size + Segment size is not a power of two.\n"));
3687 if (address_size
> 4)
3688 printf (_("\n Address Length\n"));
3690 printf (_("\n Address Length\n"));
3692 addr_ranges
= hdrptr
;
3694 /* Must pad to an alignment boundary that is twice the address size. */
3695 excess
= (hdrptr
- start
) % (2 * address_size
);
3697 addr_ranges
+= (2 * address_size
) - excess
;
3699 start
+= arange
.ar_length
+ initial_length_size
;
3701 while (addr_ranges
+ 2 * address_size
<= start
)
3703 address
= byte_get (addr_ranges
, address_size
);
3705 addr_ranges
+= address_size
;
3707 length
= byte_get (addr_ranges
, address_size
);
3709 addr_ranges
+= address_size
;
3712 print_dwarf_vma (address
, address_size
);
3713 print_dwarf_vma (length
, address_size
);
3723 /* Each debug_information[x].range_lists[y] gets this representation for
3724 sorting purposes. */
3728 /* The debug_information[x].range_lists[y] value. */
3729 unsigned long ranges_offset
;
3731 /* Original debug_information to find parameters of the data. */
3732 debug_info
*debug_info_p
;
3735 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3738 range_entry_compar (const void *ap
, const void *bp
)
3740 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
3741 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
3742 const unsigned long a
= a_re
->ranges_offset
;
3743 const unsigned long b
= b_re
->ranges_offset
;
3745 return (a
> b
) - (b
> a
);
3749 display_debug_ranges (struct dwarf_section
*section
,
3750 void *file ATTRIBUTE_UNUSED
)
3752 unsigned char *start
= section
->start
;
3753 unsigned long bytes
;
3754 unsigned char *section_begin
= start
;
3755 unsigned int num_range_list
, i
;
3756 struct range_entry
*range_entries
, *range_entry_fill
;
3758 bytes
= section
->size
;
3762 printf (_("\nThe %s section is empty.\n"), section
->name
);
3766 if (load_debug_info (file
) == 0)
3768 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3774 for (i
= 0; i
< num_debug_info_entries
; i
++)
3775 num_range_list
+= debug_information
[i
].num_range_lists
;
3777 if (num_range_list
== 0)
3778 error (_("No range lists in .debug_info section!\n"));
3780 range_entries
= (struct range_entry
*)
3781 xmalloc (sizeof (*range_entries
) * num_range_list
);
3782 range_entry_fill
= range_entries
;
3784 for (i
= 0; i
< num_debug_info_entries
; i
++)
3786 debug_info
*debug_info_p
= &debug_information
[i
];
3789 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
3791 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
3792 range_entry_fill
->debug_info_p
= debug_info_p
;
3797 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
3798 range_entry_compar
);
3800 /* DWARF sections under Mach-O have non-zero addresses. */
3801 if (range_entries
[0].ranges_offset
!= section
->address
)
3802 warn (_("Range lists in %s section start at 0x%lx\n"),
3803 section
->name
, range_entries
[0].ranges_offset
);
3805 printf (_("Contents of the %s section:\n\n"), section
->name
);
3806 printf (_(" Offset Begin End\n"));
3808 for (i
= 0; i
< num_range_list
; i
++)
3810 struct range_entry
*range_entry
= &range_entries
[i
];
3811 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
3812 unsigned int pointer_size
;
3813 unsigned long offset
;
3814 unsigned char *next
;
3815 unsigned long base_address
;
3817 pointer_size
= debug_info_p
->pointer_size
;
3819 /* DWARF sections under Mach-O have non-zero addresses. */
3820 offset
= range_entry
->ranges_offset
- section
->address
;
3821 next
= section_begin
+ offset
;
3822 base_address
= debug_info_p
->base_address
;
3827 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3828 (unsigned long) (start
- section_begin
),
3829 (unsigned long) (next
- section_begin
), section
->name
);
3830 else if (start
> next
)
3831 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3832 (unsigned long) (start
- section_begin
),
3833 (unsigned long) (next
- section_begin
), section
->name
);
3842 /* Note: we use sign extension here in order to be sure that
3843 we can detect the -1 escape value. Sign extension into the
3844 top 32 bits of a 32-bit address will not affect the values
3845 that we display since we always show hex values, and always
3846 the bottom 32-bits. */
3847 begin
= byte_get_signed (start
, pointer_size
);
3848 start
+= pointer_size
;
3849 end
= byte_get_signed (start
, pointer_size
);
3850 start
+= pointer_size
;
3852 printf (" %8.8lx ", offset
);
3854 if (begin
== 0 && end
== 0)
3856 printf (_("<End of list>\n"));
3860 /* Check base address specifiers. */
3861 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3864 print_dwarf_vma (begin
, pointer_size
);
3865 print_dwarf_vma (end
, pointer_size
);
3866 printf ("(base address)\n");
3870 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3871 print_dwarf_vma (end
+ base_address
, pointer_size
);
3874 fputs (_("(start == end)"), stdout
);
3875 else if (begin
> end
)
3876 fputs (_("(start > end)"), stdout
);
3883 free (range_entries
);
3888 typedef struct Frame_Chunk
3890 struct Frame_Chunk
*next
;
3891 unsigned char *chunk_start
;
3893 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3894 short int *col_type
;
3897 unsigned int code_factor
;
3899 unsigned long pc_begin
;
3900 unsigned long pc_range
;
3904 unsigned char fde_encoding
;
3905 unsigned char cfa_exp
;
3906 unsigned char ptr_size
;
3907 unsigned char segment_size
;
3911 static const char *const *dwarf_regnames
;
3912 static unsigned int dwarf_regnames_count
;
3914 /* A marker for a col_type that means this column was never referenced
3915 in the frame info. */
3916 #define DW_CFA_unreferenced (-1)
3918 /* Return 0 if not more space is needed, 1 if more space is needed,
3919 -1 for invalid reg. */
3922 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
3924 int prev
= fc
->ncols
;
3926 if (reg
< (unsigned int) fc
->ncols
)
3929 if (dwarf_regnames_count
3930 && reg
> dwarf_regnames_count
)
3933 fc
->ncols
= reg
+ 1;
3934 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
3935 sizeof (short int));
3936 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3938 while (prev
< fc
->ncols
)
3940 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3941 fc
->col_offset
[prev
] = 0;
3947 static const char *const dwarf_regnames_i386
[] =
3949 "eax", "ecx", "edx", "ebx",
3950 "esp", "ebp", "esi", "edi",
3951 "eip", "eflags", NULL
,
3952 "st0", "st1", "st2", "st3",
3953 "st4", "st5", "st6", "st7",
3955 "xmm0", "xmm1", "xmm2", "xmm3",
3956 "xmm4", "xmm5", "xmm6", "xmm7",
3957 "mm0", "mm1", "mm2", "mm3",
3958 "mm4", "mm5", "mm6", "mm7",
3959 "fcw", "fsw", "mxcsr",
3960 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3965 init_dwarf_regnames_i386 (void)
3967 dwarf_regnames
= dwarf_regnames_i386
;
3968 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3971 static const char *const dwarf_regnames_x86_64
[] =
3973 "rax", "rdx", "rcx", "rbx",
3974 "rsi", "rdi", "rbp", "rsp",
3975 "r8", "r9", "r10", "r11",
3976 "r12", "r13", "r14", "r15",
3978 "xmm0", "xmm1", "xmm2", "xmm3",
3979 "xmm4", "xmm5", "xmm6", "xmm7",
3980 "xmm8", "xmm9", "xmm10", "xmm11",
3981 "xmm12", "xmm13", "xmm14", "xmm15",
3982 "st0", "st1", "st2", "st3",
3983 "st4", "st5", "st6", "st7",
3984 "mm0", "mm1", "mm2", "mm3",
3985 "mm4", "mm5", "mm6", "mm7",
3987 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3988 "fs.base", "gs.base", NULL
, NULL
,
3990 "mxcsr", "fcw", "fsw"
3994 init_dwarf_regnames_x86_64 (void)
3996 dwarf_regnames
= dwarf_regnames_x86_64
;
3997 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4001 init_dwarf_regnames (unsigned int e_machine
)
4007 init_dwarf_regnames_i386 ();
4012 init_dwarf_regnames_x86_64 ();
4021 regname (unsigned int regno
, int row
)
4023 static char reg
[64];
4025 && regno
< dwarf_regnames_count
4026 && dwarf_regnames
[regno
] != NULL
)
4029 return dwarf_regnames
[regno
];
4030 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4031 dwarf_regnames
[regno
]);
4034 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4039 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4044 if (*max_regs
< fc
->ncols
)
4045 *max_regs
= fc
->ncols
;
4047 if (*need_col_headers
)
4049 static const char *sloc
= " LOC";
4051 *need_col_headers
= 0;
4053 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4055 for (r
= 0; r
< *max_regs
; r
++)
4056 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4061 printf ("%-5s ", regname (r
, 1));
4067 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4069 strcpy (tmp
, "exp");
4071 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4072 printf ("%-8s ", tmp
);
4074 for (r
= 0; r
< fc
->ncols
; r
++)
4076 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4078 switch (fc
->col_type
[r
])
4080 case DW_CFA_undefined
:
4083 case DW_CFA_same_value
:
4087 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4089 case DW_CFA_val_offset
:
4090 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4092 case DW_CFA_register
:
4093 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4095 case DW_CFA_expression
:
4096 strcpy (tmp
, "exp");
4098 case DW_CFA_val_expression
:
4099 strcpy (tmp
, "vexp");
4102 strcpy (tmp
, "n/a");
4105 printf ("%-5s ", tmp
);
4111 #define GET(N) byte_get (start, N); start += N
4112 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4113 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
4116 display_debug_frames (struct dwarf_section
*section
,
4117 void *file ATTRIBUTE_UNUSED
)
4119 unsigned char *start
= section
->start
;
4120 unsigned char *end
= start
+ section
->size
;
4121 unsigned char *section_start
= start
;
4122 Frame_Chunk
*chunks
= 0;
4123 Frame_Chunk
*remembered_state
= 0;
4125 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4126 unsigned int length_return
;
4128 const char *bad_reg
= _("bad register: ");
4129 int saved_eh_addr_size
= eh_addr_size
;
4131 printf (_("Contents of the %s section:\n"), section
->name
);
4135 unsigned char *saved_start
;
4136 unsigned char *block_end
;
4137 unsigned long length
;
4138 unsigned long cie_id
;
4141 int need_col_headers
= 1;
4142 unsigned char *augmentation_data
= NULL
;
4143 unsigned long augmentation_data_len
= 0;
4144 int encoded_ptr_size
= saved_eh_addr_size
;
4146 int initial_length_size
;
4148 saved_start
= start
;
4149 length
= byte_get (start
, 4); start
+= 4;
4153 printf ("\n%08lx ZERO terminator\n\n",
4154 (unsigned long)(saved_start
- section_start
));
4158 if (length
== 0xffffffff)
4160 length
= byte_get (start
, 8);
4163 initial_length_size
= 12;
4168 initial_length_size
= 4;
4171 block_end
= saved_start
+ length
+ initial_length_size
;
4172 if (block_end
> end
)
4174 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4175 length
, (unsigned long)(saved_start
- section_start
));
4178 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4180 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4184 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4185 memset (fc
, 0, sizeof (Frame_Chunk
));
4189 fc
->chunk_start
= saved_start
;
4191 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4192 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4193 frame_need_space (fc
, max_regs
- 1);
4197 fc
->augmentation
= (char *) start
;
4198 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4200 if (strcmp (fc
->augmentation
, "eh") == 0)
4201 start
+= eh_addr_size
;
4205 fc
->ptr_size
= GET (1);
4206 fc
->segment_size
= GET (1);
4207 eh_addr_size
= fc
->ptr_size
;
4211 fc
->ptr_size
= eh_addr_size
;
4212 fc
->segment_size
= 0;
4214 fc
->code_factor
= LEB ();
4215 fc
->data_factor
= SLEB ();
4225 if (fc
->augmentation
[0] == 'z')
4227 augmentation_data_len
= LEB ();
4228 augmentation_data
= start
;
4229 start
+= augmentation_data_len
;
4233 if (do_debug_frames_interp
)
4234 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4235 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4236 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4240 printf ("\n%08lx %08lx %08lx CIE\n",
4241 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4242 printf (" Version: %d\n", version
);
4243 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4246 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4247 printf (" Segment Size: %u\n", fc
->segment_size
);
4249 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4250 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4251 printf (" Return address column: %d\n", fc
->ra
);
4253 if (augmentation_data_len
)
4256 printf (" Augmentation data: ");
4257 for (i
= 0; i
< augmentation_data_len
; ++i
)
4258 printf (" %02x", augmentation_data
[i
]);
4264 if (augmentation_data_len
)
4266 unsigned char *p
, *q
;
4267 p
= (unsigned char *) fc
->augmentation
+ 1;
4268 q
= augmentation_data
;
4275 q
+= 1 + size_of_encoded_value (*q
);
4277 fc
->fde_encoding
= *q
++;
4285 if (fc
->fde_encoding
)
4286 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4289 frame_need_space (fc
, fc
->ra
);
4293 unsigned char *look_for
;
4294 static Frame_Chunk fde_fc
;
4295 unsigned long segment_selector
;
4298 memset (fc
, 0, sizeof (Frame_Chunk
));
4300 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4302 for (cie
= chunks
; cie
; cie
= cie
->next
)
4303 if (cie
->chunk_start
== look_for
)
4308 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4309 cie_id
, (unsigned long)(saved_start
- section_start
));
4311 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4312 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4313 frame_need_space (fc
, max_regs
- 1);
4315 fc
->augmentation
= "";
4316 fc
->fde_encoding
= 0;
4317 fc
->ptr_size
= eh_addr_size
;
4318 fc
->segment_size
= 0;
4322 fc
->ncols
= cie
->ncols
;
4323 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4324 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4325 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4326 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4327 fc
->augmentation
= cie
->augmentation
;
4328 fc
->ptr_size
= cie
->ptr_size
;
4329 eh_addr_size
= cie
->ptr_size
;
4330 fc
->segment_size
= cie
->segment_size
;
4331 fc
->code_factor
= cie
->code_factor
;
4332 fc
->data_factor
= cie
->data_factor
;
4333 fc
->cfa_reg
= cie
->cfa_reg
;
4334 fc
->cfa_offset
= cie
->cfa_offset
;
4336 frame_need_space (fc
, max_regs
- 1);
4337 fc
->fde_encoding
= cie
->fde_encoding
;
4340 if (fc
->fde_encoding
)
4341 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4343 segment_selector
= 0;
4344 if (fc
->segment_size
)
4346 segment_selector
= byte_get (start
, fc
->segment_size
);
4347 start
+= fc
->segment_size
;
4349 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4350 start
+= encoded_ptr_size
;
4351 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4352 start
+= encoded_ptr_size
;
4354 if (cie
->augmentation
[0] == 'z')
4356 augmentation_data_len
= LEB ();
4357 augmentation_data
= start
;
4358 start
+= augmentation_data_len
;
4361 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4362 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4363 (unsigned long)(cie
->chunk_start
- section_start
));
4364 if (fc
->segment_size
)
4365 printf ("%04lx:", segment_selector
);
4366 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4367 if (! do_debug_frames_interp
&& augmentation_data_len
)
4371 printf (" Augmentation data: ");
4372 for (i
= 0; i
< augmentation_data_len
; ++i
)
4373 printf (" %02x", augmentation_data
[i
]);
4379 /* At this point, fc is the current chunk, cie (if any) is set, and
4380 we're about to interpret instructions for the chunk. */
4381 /* ??? At present we need to do this always, since this sizes the
4382 fc->col_type and fc->col_offset arrays, which we write into always.
4383 We should probably split the interpreted and non-interpreted bits
4384 into two different routines, since there's so much that doesn't
4385 really overlap between them. */
4386 if (1 || do_debug_frames_interp
)
4388 /* Start by making a pass over the chunk, allocating storage
4389 and taking note of what registers are used. */
4390 unsigned char *tmp
= start
;
4392 while (start
< block_end
)
4395 unsigned long reg
, temp
;
4402 /* Warning: if you add any more cases to this switch, be
4403 sure to add them to the corresponding switch below. */
4406 case DW_CFA_advance_loc
:
4410 if (frame_need_space (fc
, opa
) >= 0)
4411 fc
->col_type
[opa
] = DW_CFA_undefined
;
4413 case DW_CFA_restore
:
4414 if (frame_need_space (fc
, opa
) >= 0)
4415 fc
->col_type
[opa
] = DW_CFA_undefined
;
4417 case DW_CFA_set_loc
:
4418 start
+= encoded_ptr_size
;
4420 case DW_CFA_advance_loc1
:
4423 case DW_CFA_advance_loc2
:
4426 case DW_CFA_advance_loc4
:
4429 case DW_CFA_offset_extended
:
4430 case DW_CFA_val_offset
:
4431 reg
= LEB (); LEB ();
4432 if (frame_need_space (fc
, reg
) >= 0)
4433 fc
->col_type
[reg
] = DW_CFA_undefined
;
4435 case DW_CFA_restore_extended
:
4437 frame_need_space (fc
, reg
);
4438 if (frame_need_space (fc
, reg
) >= 0)
4439 fc
->col_type
[reg
] = DW_CFA_undefined
;
4441 case DW_CFA_undefined
:
4443 if (frame_need_space (fc
, reg
) >= 0)
4444 fc
->col_type
[reg
] = DW_CFA_undefined
;
4446 case DW_CFA_same_value
:
4448 if (frame_need_space (fc
, reg
) >= 0)
4449 fc
->col_type
[reg
] = DW_CFA_undefined
;
4451 case DW_CFA_register
:
4452 reg
= LEB (); LEB ();
4453 if (frame_need_space (fc
, reg
) >= 0)
4454 fc
->col_type
[reg
] = DW_CFA_undefined
;
4456 case DW_CFA_def_cfa
:
4459 case DW_CFA_def_cfa_register
:
4462 case DW_CFA_def_cfa_offset
:
4465 case DW_CFA_def_cfa_expression
:
4469 case DW_CFA_expression
:
4470 case DW_CFA_val_expression
:
4474 if (frame_need_space (fc
, reg
) >= 0)
4475 fc
->col_type
[reg
] = DW_CFA_undefined
;
4477 case DW_CFA_offset_extended_sf
:
4478 case DW_CFA_val_offset_sf
:
4479 reg
= LEB (); SLEB ();
4480 if (frame_need_space (fc
, reg
) >= 0)
4481 fc
->col_type
[reg
] = DW_CFA_undefined
;
4483 case DW_CFA_def_cfa_sf
:
4486 case DW_CFA_def_cfa_offset_sf
:
4489 case DW_CFA_MIPS_advance_loc8
:
4492 case DW_CFA_GNU_args_size
:
4495 case DW_CFA_GNU_negative_offset_extended
:
4496 reg
= LEB (); LEB ();
4497 if (frame_need_space (fc
, reg
) >= 0)
4498 fc
->col_type
[reg
] = DW_CFA_undefined
;
4507 /* Now we know what registers are used, make a second pass over
4508 the chunk, this time actually printing out the info. */
4510 while (start
< block_end
)
4513 unsigned long ul
, reg
, roffs
;
4516 const char *reg_prefix
= "";
4523 /* Warning: if you add any more cases to this switch, be
4524 sure to add them to the corresponding switch above. */
4527 case DW_CFA_advance_loc
:
4528 if (do_debug_frames_interp
)
4529 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4531 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4532 opa
* fc
->code_factor
,
4533 fc
->pc_begin
+ opa
* fc
->code_factor
);
4534 fc
->pc_begin
+= opa
* fc
->code_factor
;
4539 if (opa
>= (unsigned int) fc
->ncols
)
4540 reg_prefix
= bad_reg
;
4541 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4542 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4543 reg_prefix
, regname (opa
, 0),
4544 roffs
* fc
->data_factor
);
4545 if (*reg_prefix
== '\0')
4547 fc
->col_type
[opa
] = DW_CFA_offset
;
4548 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4552 case DW_CFA_restore
:
4553 if (opa
>= (unsigned int) cie
->ncols
4554 || opa
>= (unsigned int) fc
->ncols
)
4555 reg_prefix
= bad_reg
;
4556 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4557 printf (" DW_CFA_restore: %s%s\n",
4558 reg_prefix
, regname (opa
, 0));
4559 if (*reg_prefix
== '\0')
4561 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4562 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4566 case DW_CFA_set_loc
:
4567 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4568 start
+= encoded_ptr_size
;
4569 if (do_debug_frames_interp
)
4570 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4572 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4576 case DW_CFA_advance_loc1
:
4577 ofs
= byte_get (start
, 1); start
+= 1;
4578 if (do_debug_frames_interp
)
4579 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4581 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4582 ofs
* fc
->code_factor
,
4583 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4584 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4587 case DW_CFA_advance_loc2
:
4588 ofs
= byte_get (start
, 2); start
+= 2;
4589 if (do_debug_frames_interp
)
4590 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4592 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4593 ofs
* fc
->code_factor
,
4594 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4595 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4598 case DW_CFA_advance_loc4
:
4599 ofs
= byte_get (start
, 4); start
+= 4;
4600 if (do_debug_frames_interp
)
4601 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4603 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4604 ofs
* fc
->code_factor
,
4605 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4606 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4609 case DW_CFA_offset_extended
:
4612 if (reg
>= (unsigned int) fc
->ncols
)
4613 reg_prefix
= bad_reg
;
4614 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4615 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4616 reg_prefix
, regname (reg
, 0),
4617 roffs
* fc
->data_factor
);
4618 if (*reg_prefix
== '\0')
4620 fc
->col_type
[reg
] = DW_CFA_offset
;
4621 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4625 case DW_CFA_val_offset
:
4628 if (reg
>= (unsigned int) fc
->ncols
)
4629 reg_prefix
= bad_reg
;
4630 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4631 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4632 reg_prefix
, regname (reg
, 0),
4633 roffs
* fc
->data_factor
);
4634 if (*reg_prefix
== '\0')
4636 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4637 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4641 case DW_CFA_restore_extended
:
4643 if (reg
>= (unsigned int) cie
->ncols
4644 || reg
>= (unsigned int) fc
->ncols
)
4645 reg_prefix
= bad_reg
;
4646 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4647 printf (" DW_CFA_restore_extended: %s%s\n",
4648 reg_prefix
, regname (reg
, 0));
4649 if (*reg_prefix
== '\0')
4651 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4652 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4656 case DW_CFA_undefined
:
4658 if (reg
>= (unsigned int) fc
->ncols
)
4659 reg_prefix
= bad_reg
;
4660 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4661 printf (" DW_CFA_undefined: %s%s\n",
4662 reg_prefix
, regname (reg
, 0));
4663 if (*reg_prefix
== '\0')
4665 fc
->col_type
[reg
] = DW_CFA_undefined
;
4666 fc
->col_offset
[reg
] = 0;
4670 case DW_CFA_same_value
:
4672 if (reg
>= (unsigned int) fc
->ncols
)
4673 reg_prefix
= bad_reg
;
4674 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4675 printf (" DW_CFA_same_value: %s%s\n",
4676 reg_prefix
, regname (reg
, 0));
4677 if (*reg_prefix
== '\0')
4679 fc
->col_type
[reg
] = DW_CFA_same_value
;
4680 fc
->col_offset
[reg
] = 0;
4684 case DW_CFA_register
:
4687 if (reg
>= (unsigned int) fc
->ncols
)
4688 reg_prefix
= bad_reg
;
4689 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4691 printf (" DW_CFA_register: %s%s in ",
4692 reg_prefix
, regname (reg
, 0));
4693 puts (regname (roffs
, 0));
4695 if (*reg_prefix
== '\0')
4697 fc
->col_type
[reg
] = DW_CFA_register
;
4698 fc
->col_offset
[reg
] = roffs
;
4702 case DW_CFA_remember_state
:
4703 if (! do_debug_frames_interp
)
4704 printf (" DW_CFA_remember_state\n");
4705 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4706 rs
->ncols
= fc
->ncols
;
4707 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
4708 sizeof (short int));
4709 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
4710 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4711 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4712 rs
->next
= remembered_state
;
4713 remembered_state
= rs
;
4716 case DW_CFA_restore_state
:
4717 if (! do_debug_frames_interp
)
4718 printf (" DW_CFA_restore_state\n");
4719 rs
= remembered_state
;
4722 remembered_state
= rs
->next
;
4723 frame_need_space (fc
, rs
->ncols
- 1);
4724 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4725 memcpy (fc
->col_offset
, rs
->col_offset
,
4726 rs
->ncols
* sizeof (int));
4727 free (rs
->col_type
);
4728 free (rs
->col_offset
);
4731 else if (do_debug_frames_interp
)
4732 printf ("Mismatched DW_CFA_restore_state\n");
4735 case DW_CFA_def_cfa
:
4736 fc
->cfa_reg
= LEB ();
4737 fc
->cfa_offset
= LEB ();
4739 if (! do_debug_frames_interp
)
4740 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4741 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4744 case DW_CFA_def_cfa_register
:
4745 fc
->cfa_reg
= LEB ();
4747 if (! do_debug_frames_interp
)
4748 printf (" DW_CFA_def_cfa_register: %s\n",
4749 regname (fc
->cfa_reg
, 0));
4752 case DW_CFA_def_cfa_offset
:
4753 fc
->cfa_offset
= LEB ();
4754 if (! do_debug_frames_interp
)
4755 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4759 if (! do_debug_frames_interp
)
4760 printf (" DW_CFA_nop\n");
4763 case DW_CFA_def_cfa_expression
:
4765 if (! do_debug_frames_interp
)
4767 printf (" DW_CFA_def_cfa_expression (");
4768 decode_location_expression (start
, eh_addr_size
, 0, -1,
4776 case DW_CFA_expression
:
4779 if (reg
>= (unsigned int) fc
->ncols
)
4780 reg_prefix
= bad_reg
;
4781 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4783 printf (" DW_CFA_expression: %s%s (",
4784 reg_prefix
, regname (reg
, 0));
4785 decode_location_expression (start
, eh_addr_size
, 0, -1,
4789 if (*reg_prefix
== '\0')
4790 fc
->col_type
[reg
] = DW_CFA_expression
;
4794 case DW_CFA_val_expression
:
4797 if (reg
>= (unsigned int) fc
->ncols
)
4798 reg_prefix
= bad_reg
;
4799 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4801 printf (" DW_CFA_val_expression: %s%s (",
4802 reg_prefix
, regname (reg
, 0));
4803 decode_location_expression (start
, eh_addr_size
, 0, -1,
4807 if (*reg_prefix
== '\0')
4808 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4812 case DW_CFA_offset_extended_sf
:
4815 if (frame_need_space (fc
, reg
) < 0)
4816 reg_prefix
= bad_reg
;
4817 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4818 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4819 reg_prefix
, regname (reg
, 0),
4820 l
* fc
->data_factor
);
4821 if (*reg_prefix
== '\0')
4823 fc
->col_type
[reg
] = DW_CFA_offset
;
4824 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4828 case DW_CFA_val_offset_sf
:
4831 if (frame_need_space (fc
, reg
) < 0)
4832 reg_prefix
= bad_reg
;
4833 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4834 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4835 reg_prefix
, regname (reg
, 0),
4836 l
* fc
->data_factor
);
4837 if (*reg_prefix
== '\0')
4839 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4840 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4844 case DW_CFA_def_cfa_sf
:
4845 fc
->cfa_reg
= LEB ();
4846 fc
->cfa_offset
= SLEB ();
4847 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4849 if (! do_debug_frames_interp
)
4850 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4851 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4854 case DW_CFA_def_cfa_offset_sf
:
4855 fc
->cfa_offset
= SLEB ();
4856 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4857 if (! do_debug_frames_interp
)
4858 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4861 case DW_CFA_MIPS_advance_loc8
:
4862 ofs
= byte_get (start
, 8); start
+= 8;
4863 if (do_debug_frames_interp
)
4864 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4866 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4867 ofs
* fc
->code_factor
,
4868 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4869 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4872 case DW_CFA_GNU_window_save
:
4873 if (! do_debug_frames_interp
)
4874 printf (" DW_CFA_GNU_window_save\n");
4877 case DW_CFA_GNU_args_size
:
4879 if (! do_debug_frames_interp
)
4880 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4883 case DW_CFA_GNU_negative_offset_extended
:
4886 if (frame_need_space (fc
, reg
) < 0)
4887 reg_prefix
= bad_reg
;
4888 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4889 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4890 reg_prefix
, regname (reg
, 0),
4891 l
* fc
->data_factor
);
4892 if (*reg_prefix
== '\0')
4894 fc
->col_type
[reg
] = DW_CFA_offset
;
4895 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4900 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4901 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4903 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4908 if (do_debug_frames_interp
)
4909 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4912 eh_addr_size
= saved_eh_addr_size
;
4925 display_gdb_index (struct dwarf_section
*section
,
4926 void *file ATTRIBUTE_UNUSED
)
4928 unsigned char *start
= section
->start
;
4930 uint32_t cu_list_offset
, tu_list_offset
;
4931 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
4932 unsigned int cu_list_elements
, tu_list_elements
;
4933 unsigned int address_table_size
, symbol_table_slots
;
4934 unsigned char *cu_list
, *tu_list
;
4935 unsigned char *address_table
, *symbol_table
, *constant_pool
;
4938 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
4940 printf (_("Contents of the %s section:\n"), section
->name
);
4942 if (section
->size
< 6 * sizeof (uint32_t))
4944 warn (_("Truncated header in the %s section.\n"), section
->name
);
4948 version
= byte_get_little_endian (start
, 4);
4949 printf (_("Version %ld\n"), (long) version
);
4951 /* Prior versions are obsolete, and future versions may not be
4952 backwards compatible. */
4956 warn (_("The address table data in version 3 may be wrong.\n"));
4961 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
4965 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
4966 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
4967 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
4968 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
4969 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
4971 if (cu_list_offset
> section
->size
4972 || tu_list_offset
> section
->size
4973 || address_table_offset
> section
->size
4974 || symbol_table_offset
> section
->size
4975 || constant_pool_offset
> section
->size
)
4977 warn (_("Corrupt header in the %s section.\n"), section
->name
);
4981 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
4982 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
4983 address_table_size
= symbol_table_offset
- address_table_offset
;
4984 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
4986 cu_list
= start
+ cu_list_offset
;
4987 tu_list
= start
+ tu_list_offset
;
4988 address_table
= start
+ address_table_offset
;
4989 symbol_table
= start
+ symbol_table_offset
;
4990 constant_pool
= start
+ constant_pool_offset
;
4992 printf (_("\nCU table:\n"));
4993 for (i
= 0; i
< cu_list_elements
; i
+= 2)
4995 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
4996 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
4998 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
4999 (unsigned long) cu_offset
,
5000 (unsigned long) (cu_offset
+ cu_length
- 1));
5003 printf (_("\nTU table:\n"));
5004 for (i
= 0; i
< tu_list_elements
; i
+= 3)
5006 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
5007 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
5008 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
5010 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
5011 (unsigned long) tu_offset
,
5012 (unsigned long) type_offset
);
5013 print_dwarf_vma (signature
, 8);
5017 printf (_("\nAddress table:\n"));
5018 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
5020 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
5021 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
5022 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
5024 print_dwarf_vma (low
, 8);
5025 print_dwarf_vma (high
, 8);
5026 printf (_("%lu\n"), (unsigned long) cu_index
);
5029 printf (_("\nSymbol table:\n"));
5030 for (i
= 0; i
< symbol_table_slots
; ++i
)
5032 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
5033 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
5034 uint32_t num_cus
, cu
;
5036 if (name_offset
!= 0
5037 || cu_vector_offset
!= 0)
5041 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
5042 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
5043 for (j
= 0; j
< num_cus
; ++j
)
5045 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
5046 /* Convert to TU number if it's for a type unit. */
5047 if (cu
>= cu_list_elements
)
5048 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
));
5050 printf (" %lu", (unsigned long) cu
);
5060 display_debug_not_supported (struct dwarf_section
*section
,
5061 void *file ATTRIBUTE_UNUSED
)
5063 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5070 cmalloc (size_t nmemb
, size_t size
)
5072 /* Check for overflow. */
5073 if (nmemb
>= ~(size_t) 0 / size
)
5076 return malloc (nmemb
* size
);
5080 xcmalloc (size_t nmemb
, size_t size
)
5082 /* Check for overflow. */
5083 if (nmemb
>= ~(size_t) 0 / size
)
5086 return xmalloc (nmemb
* size
);
5090 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5092 /* Check for overflow. */
5093 if (nmemb
>= ~(size_t) 0 / size
)
5096 return xrealloc (ptr
, nmemb
* size
);
5100 free_debug_memory (void)
5106 for (i
= 0; i
< max
; i
++)
5107 free_debug_section ((enum dwarf_section_display_enum
) i
);
5109 if (debug_information
!= NULL
)
5111 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5113 for (i
= 0; i
< num_debug_info_entries
; i
++)
5115 if (!debug_information
[i
].max_loc_offsets
)
5117 free (debug_information
[i
].loc_offsets
);
5118 free (debug_information
[i
].have_frame_base
);
5120 if (!debug_information
[i
].max_range_lists
)
5121 free (debug_information
[i
].range_lists
);
5125 free (debug_information
);
5126 debug_information
= NULL
;
5127 num_debug_info_entries
= 0;
5132 dwarf_select_sections_by_names (const char *names
)
5136 const char * option
;
5140 debug_dump_long_opts
;
5142 static const debug_dump_long_opts opts_table
[] =
5144 /* Please keep this table alpha- sorted. */
5145 { "Ranges", & do_debug_ranges
, 1 },
5146 { "abbrev", & do_debug_abbrevs
, 1 },
5147 { "aranges", & do_debug_aranges
, 1 },
5148 { "frames", & do_debug_frames
, 1 },
5149 { "frames-interp", & do_debug_frames_interp
, 1 },
5150 { "info", & do_debug_info
, 1 },
5151 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5152 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5153 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5154 { "loc", & do_debug_loc
, 1 },
5155 { "macro", & do_debug_macinfo
, 1 },
5156 { "pubnames", & do_debug_pubnames
, 1 },
5157 { "pubtypes", & do_debug_pubtypes
, 1 },
5158 /* This entry is for compatability
5159 with earlier versions of readelf. */
5160 { "ranges", & do_debug_aranges
, 1 },
5161 { "str", & do_debug_str
, 1 },
5162 /* The special .gdb_index section. */
5163 { "gdb_index", & do_gdb_index
, 1 },
5164 /* These trace_* sections are used by Itanium VMS. */
5165 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5166 { "trace_aranges", & do_trace_aranges
, 1 },
5167 { "trace_info", & do_trace_info
, 1 },
5176 const debug_dump_long_opts
* entry
;
5178 for (entry
= opts_table
; entry
->option
; entry
++)
5180 size_t len
= strlen (entry
->option
);
5182 if (strncmp (p
, entry
->option
, len
) == 0
5183 && (p
[len
] == ',' || p
[len
] == '\0'))
5185 * entry
->variable
|= entry
->val
;
5187 /* The --debug-dump=frames-interp option also
5188 enables the --debug-dump=frames option. */
5189 if (do_debug_frames_interp
)
5190 do_debug_frames
= 1;
5197 if (entry
->option
== NULL
)
5199 warn (_("Unrecognized debug option '%s'\n"), p
);
5200 p
= strchr (p
, ',');
5211 dwarf_select_sections_by_letters (const char *letters
)
5213 unsigned int lindex
= 0;
5215 while (letters
[lindex
])
5216 switch (letters
[lindex
++])
5223 do_debug_abbrevs
= 1;
5227 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5231 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5235 do_debug_pubnames
= 1;
5239 do_debug_pubtypes
= 1;
5243 do_debug_aranges
= 1;
5247 do_debug_ranges
= 1;
5251 do_debug_frames_interp
= 1;
5253 do_debug_frames
= 1;
5257 do_debug_macinfo
= 1;
5269 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5275 dwarf_select_sections_all (void)
5278 do_debug_abbrevs
= 1;
5279 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5280 do_debug_pubnames
= 1;
5281 do_debug_pubtypes
= 1;
5282 do_debug_aranges
= 1;
5283 do_debug_ranges
= 1;
5284 do_debug_frames
= 1;
5285 do_debug_macinfo
= 1;
5290 do_trace_abbrevs
= 1;
5291 do_trace_aranges
= 1;
5294 struct dwarf_section_display debug_displays
[] =
5296 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5297 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5298 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5299 display_debug_aranges
, &do_debug_aranges
, 1 },
5300 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5301 display_debug_frames
, &do_debug_frames
, 1 },
5302 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5303 display_debug_info
, &do_debug_info
, 1 },
5304 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5305 display_debug_lines
, &do_debug_lines
, 1 },
5306 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5307 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5308 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5309 display_debug_frames
, &do_debug_frames
, 1 },
5310 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5311 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5312 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5313 display_debug_str
, &do_debug_str
, 0 },
5314 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5315 display_debug_loc
, &do_debug_loc
, 1 },
5316 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5317 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5318 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5319 display_debug_ranges
, &do_debug_ranges
, 1 },
5320 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5321 display_debug_not_supported
, NULL
, 0 },
5322 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5323 display_debug_not_supported
, NULL
, 0 },
5324 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5325 display_debug_types
, &do_debug_info
, 1 },
5326 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5327 display_debug_not_supported
, NULL
, 0 },
5328 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5329 display_gdb_index
, &do_gdb_index
, 0 },
5330 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5331 display_trace_info
, &do_trace_info
, 1 },
5332 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5333 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5334 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5335 display_debug_aranges
, &do_trace_aranges
, 0 }