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 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
129 unsigned long int result
= 0;
130 unsigned int num_read
= 0;
131 unsigned int shift
= 0;
139 result
|= ((unsigned long int) (byte
& 0x7f)) << shift
;
146 if (length_return
!= NULL
)
147 *length_return
= num_read
;
149 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
150 result
|= -1L << shift
;
155 typedef struct State_Machine_Registers
157 unsigned long address
;
163 unsigned char op_index
;
164 unsigned char end_sequence
;
165 /* This variable hold the number of the last entry seen
166 in the File Table. */
167 unsigned int last_file_entry
;
170 static SMR state_machine_regs
;
173 reset_state_machine (int is_stmt
)
175 state_machine_regs
.address
= 0;
176 state_machine_regs
.op_index
= 0;
177 state_machine_regs
.file
= 1;
178 state_machine_regs
.line
= 1;
179 state_machine_regs
.column
= 0;
180 state_machine_regs
.is_stmt
= is_stmt
;
181 state_machine_regs
.basic_block
= 0;
182 state_machine_regs
.end_sequence
= 0;
183 state_machine_regs
.last_file_entry
= 0;
186 /* Handled an extend line op.
187 Returns the number of bytes read. */
190 process_extended_line_op (unsigned char *data
, int is_stmt
)
192 unsigned char op_code
;
193 unsigned int bytes_read
;
198 len
= read_leb128 (data
, & bytes_read
, 0);
203 warn (_("badly formed extended line op encountered!\n"));
210 printf (_(" Extended opcode %d: "), op_code
);
214 case DW_LNE_end_sequence
:
215 printf (_("End of Sequence\n\n"));
216 reset_state_machine (is_stmt
);
219 case DW_LNE_set_address
:
220 adr
= byte_get (data
, len
- bytes_read
- 1);
221 printf (_("set Address to 0x%lx\n"), adr
);
222 state_machine_regs
.address
= adr
;
223 state_machine_regs
.op_index
= 0;
226 case DW_LNE_define_file
:
227 printf (_(" define new File Table entry\n"));
228 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
230 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
232 data
+= strlen ((char *) data
) + 1;
233 printf ("%lu\t", read_leb128 (data
, & bytes_read
, 0));
235 printf ("%lu\t", read_leb128 (data
, & bytes_read
, 0));
237 printf ("%lu\t", read_leb128 (data
, & bytes_read
, 0));
238 printf ("%s\n\n", name
);
241 case DW_LNE_set_discriminator
:
242 printf (_("set Discriminator to %lu\n"),
243 read_leb128 (data
, & bytes_read
, 0));
247 case DW_LNE_HP_negate_is_UV_update
:
248 printf ("DW_LNE_HP_negate_is_UV_update\n");
250 case DW_LNE_HP_push_context
:
251 printf ("DW_LNE_HP_push_context\n");
253 case DW_LNE_HP_pop_context
:
254 printf ("DW_LNE_HP_pop_context\n");
256 case DW_LNE_HP_set_file_line_column
:
257 printf ("DW_LNE_HP_set_file_line_column\n");
259 case DW_LNE_HP_set_routine_name
:
260 printf ("DW_LNE_HP_set_routine_name\n");
262 case DW_LNE_HP_set_sequence
:
263 printf ("DW_LNE_HP_set_sequence\n");
265 case DW_LNE_HP_negate_post_semantics
:
266 printf ("DW_LNE_HP_negate_post_semantics\n");
268 case DW_LNE_HP_negate_function_exit
:
269 printf ("DW_LNE_HP_negate_function_exit\n");
271 case DW_LNE_HP_negate_front_end_logical
:
272 printf ("DW_LNE_HP_negate_front_end_logical\n");
274 case DW_LNE_HP_define_proc
:
275 printf ("DW_LNE_HP_define_proc\n");
279 if (op_code
>= DW_LNE_lo_user
280 /* The test against DW_LNW_hi_user is redundant due to
281 the limited range of the unsigned char data type used
283 /*&& op_code <= DW_LNE_hi_user*/)
284 printf (_("user defined: length %d\n"), len
- bytes_read
);
286 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
294 fetch_indirect_string (unsigned long offset
)
296 struct dwarf_section
*section
= &debug_displays
[str
].section
;
298 if (section
->start
== NULL
)
299 return _("<no .debug_str section>");
301 /* DWARF sections under Mach-O have non-zero addresses. */
302 offset
-= section
->address
;
303 if (offset
> section
->size
)
305 warn (_("DW_FORM_strp offset too big: %lx\n"), offset
);
306 return _("<offset is too big>");
309 return (const char *) section
->start
+ offset
;
312 /* FIXME: There are better and more efficient ways to handle
313 these structures. For now though, I just want something that
314 is simple to implement. */
315 typedef struct abbrev_attr
317 unsigned long attribute
;
319 struct abbrev_attr
*next
;
323 typedef struct abbrev_entry
328 struct abbrev_attr
*first_attr
;
329 struct abbrev_attr
*last_attr
;
330 struct abbrev_entry
*next
;
334 static abbrev_entry
*first_abbrev
= NULL
;
335 static abbrev_entry
*last_abbrev
= NULL
;
342 for (abbrv
= first_abbrev
; abbrv
;)
344 abbrev_entry
*next_abbrev
= abbrv
->next
;
347 for (attr
= abbrv
->first_attr
; attr
;)
349 abbrev_attr
*next_attr
= attr
->next
;
359 last_abbrev
= first_abbrev
= NULL
;
363 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
367 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
373 entry
->entry
= number
;
375 entry
->children
= children
;
376 entry
->first_attr
= NULL
;
377 entry
->last_attr
= NULL
;
380 if (first_abbrev
== NULL
)
381 first_abbrev
= entry
;
383 last_abbrev
->next
= entry
;
389 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
393 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
399 attr
->attribute
= attribute
;
403 if (last_abbrev
->first_attr
== NULL
)
404 last_abbrev
->first_attr
= attr
;
406 last_abbrev
->last_attr
->next
= attr
;
408 last_abbrev
->last_attr
= attr
;
411 /* Processes the (partial) contents of a .debug_abbrev section.
412 Returns NULL if the end of the section was encountered.
413 Returns the address after the last byte read if the end of
414 an abbreviation set was found. */
416 static unsigned char *
417 process_abbrev_section (unsigned char *start
, unsigned char *end
)
419 if (first_abbrev
!= NULL
)
424 unsigned int bytes_read
;
427 unsigned long attribute
;
430 entry
= read_leb128 (start
, & bytes_read
, 0);
433 /* A single zero is supposed to end the section according
434 to the standard. If there's more, then signal that to
437 return start
== end
? NULL
: start
;
439 tag
= read_leb128 (start
, & bytes_read
, 0);
444 add_abbrev (entry
, tag
, children
);
450 attribute
= read_leb128 (start
, & bytes_read
, 0);
453 form
= read_leb128 (start
, & bytes_read
, 0);
457 add_abbrev_attr (attribute
, form
);
459 while (attribute
!= 0);
466 get_TAG_name (unsigned long tag
)
470 case DW_TAG_padding
: return "DW_TAG_padding";
471 case DW_TAG_array_type
: return "DW_TAG_array_type";
472 case DW_TAG_class_type
: return "DW_TAG_class_type";
473 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
474 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
475 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
476 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
477 case DW_TAG_label
: return "DW_TAG_label";
478 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
479 case DW_TAG_member
: return "DW_TAG_member";
480 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
481 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
482 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
483 case DW_TAG_string_type
: return "DW_TAG_string_type";
484 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
485 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
486 case DW_TAG_typedef
: return "DW_TAG_typedef";
487 case DW_TAG_union_type
: return "DW_TAG_union_type";
488 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
489 case DW_TAG_variant
: return "DW_TAG_variant";
490 case DW_TAG_common_block
: return "DW_TAG_common_block";
491 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
492 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
493 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
494 case DW_TAG_module
: return "DW_TAG_module";
495 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
496 case DW_TAG_set_type
: return "DW_TAG_set_type";
497 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
498 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
499 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
500 case DW_TAG_base_type
: return "DW_TAG_base_type";
501 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
502 case DW_TAG_const_type
: return "DW_TAG_const_type";
503 case DW_TAG_constant
: return "DW_TAG_constant";
504 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
505 case DW_TAG_file_type
: return "DW_TAG_file_type";
506 case DW_TAG_friend
: return "DW_TAG_friend";
507 case DW_TAG_namelist
: return "DW_TAG_namelist";
508 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
509 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
510 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
511 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
512 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
513 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
514 case DW_TAG_try_block
: return "DW_TAG_try_block";
515 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
516 case DW_TAG_variable
: return "DW_TAG_variable";
517 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
518 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
519 case DW_TAG_format_label
: return "DW_TAG_format_label";
520 case DW_TAG_function_template
: return "DW_TAG_function_template";
521 case DW_TAG_class_template
: return "DW_TAG_class_template";
522 /* DWARF 2.1 values. */
523 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
524 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
525 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
526 case DW_TAG_namespace
: return "DW_TAG_namespace";
527 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
528 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
529 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
530 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
531 case DW_TAG_condition
: return "DW_TAG_condition";
532 case DW_TAG_shared_type
: return "DW_TAG_shared_type";
533 /* DWARF 4 values. */
534 case DW_TAG_type_unit
: return "DW_TAG_type_unit";
535 case DW_TAG_rvalue_reference_type
: return "DW_TAG_rvalue_reference_type";
536 case DW_TAG_template_alias
: return "DW_TAG_template_alias";
538 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
539 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
540 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
543 static char buffer
[100];
545 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
552 get_FORM_name (unsigned long form
)
556 case DW_FORM_addr
: return "DW_FORM_addr";
557 case DW_FORM_block2
: return "DW_FORM_block2";
558 case DW_FORM_block4
: return "DW_FORM_block4";
559 case DW_FORM_data2
: return "DW_FORM_data2";
560 case DW_FORM_data4
: return "DW_FORM_data4";
561 case DW_FORM_data8
: return "DW_FORM_data8";
562 case DW_FORM_string
: return "DW_FORM_string";
563 case DW_FORM_block
: return "DW_FORM_block";
564 case DW_FORM_block1
: return "DW_FORM_block1";
565 case DW_FORM_data1
: return "DW_FORM_data1";
566 case DW_FORM_flag
: return "DW_FORM_flag";
567 case DW_FORM_sdata
: return "DW_FORM_sdata";
568 case DW_FORM_strp
: return "DW_FORM_strp";
569 case DW_FORM_udata
: return "DW_FORM_udata";
570 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
571 case DW_FORM_ref1
: return "DW_FORM_ref1";
572 case DW_FORM_ref2
: return "DW_FORM_ref2";
573 case DW_FORM_ref4
: return "DW_FORM_ref4";
574 case DW_FORM_ref8
: return "DW_FORM_ref8";
575 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
576 case DW_FORM_indirect
: return "DW_FORM_indirect";
577 /* DWARF 4 values. */
578 case DW_FORM_sec_offset
: return "DW_FORM_sec_offset";
579 case DW_FORM_exprloc
: return "DW_FORM_exprloc";
580 case DW_FORM_flag_present
: return "DW_FORM_flag_present";
581 case DW_FORM_ref_sig8
: return "DW_FORM_ref_sig8";
584 static char buffer
[100];
586 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
592 static unsigned char *
593 display_block (unsigned char *data
, unsigned long length
)
595 printf (_(" %lu byte block: "), length
);
598 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
604 decode_location_expression (unsigned char * data
,
605 unsigned int pointer_size
,
606 unsigned int offset_size
,
608 unsigned long length
,
609 unsigned long cu_offset
,
610 struct dwarf_section
* section
)
613 unsigned int bytes_read
;
614 unsigned long uvalue
;
615 unsigned char *end
= data
+ length
;
616 int need_frame_base
= 0;
625 printf ("DW_OP_addr: %lx",
626 (unsigned long) byte_get (data
, pointer_size
));
627 data
+= pointer_size
;
630 printf ("DW_OP_deref");
633 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
636 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
639 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
643 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
647 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
651 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
655 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
656 (unsigned long) byte_get (data
+ 4, 4));
660 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
661 (long) byte_get (data
+ 4, 4));
665 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
669 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
673 printf ("DW_OP_dup");
676 printf ("DW_OP_drop");
679 printf ("DW_OP_over");
682 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
685 printf ("DW_OP_swap");
688 printf ("DW_OP_rot");
691 printf ("DW_OP_xderef");
694 printf ("DW_OP_abs");
697 printf ("DW_OP_and");
700 printf ("DW_OP_div");
703 printf ("DW_OP_minus");
706 printf ("DW_OP_mod");
709 printf ("DW_OP_mul");
712 printf ("DW_OP_neg");
715 printf ("DW_OP_not");
721 printf ("DW_OP_plus");
723 case DW_OP_plus_uconst
:
724 printf ("DW_OP_plus_uconst: %lu",
725 read_leb128 (data
, &bytes_read
, 0));
729 printf ("DW_OP_shl");
732 printf ("DW_OP_shr");
735 printf ("DW_OP_shra");
738 printf ("DW_OP_xor");
741 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
763 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
799 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
834 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
835 regname (op
- DW_OP_reg0
, 1));
870 printf ("DW_OP_breg%d (%s): %ld", op
- DW_OP_breg0
,
871 regname (op
- DW_OP_breg0
, 1),
872 read_leb128 (data
, &bytes_read
, 1));
877 uvalue
= read_leb128 (data
, &bytes_read
, 0);
879 printf ("DW_OP_regx: %lu (%s)", uvalue
, regname (uvalue
, 1));
883 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
887 uvalue
= read_leb128 (data
, &bytes_read
, 0);
889 printf ("DW_OP_bregx: %lu (%s) %ld", uvalue
, regname (uvalue
, 1),
890 read_leb128 (data
, &bytes_read
, 1));
894 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
897 case DW_OP_deref_size
:
898 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
900 case DW_OP_xderef_size
:
901 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
904 printf ("DW_OP_nop");
907 /* DWARF 3 extensions. */
908 case DW_OP_push_object_address
:
909 printf ("DW_OP_push_object_address");
912 /* XXX: Strictly speaking for 64-bit DWARF3 files
913 this ought to be an 8-byte wide computation. */
914 printf ("DW_OP_call2: <0x%lx>", (long) byte_get (data
, 2) + cu_offset
);
918 /* XXX: Strictly speaking for 64-bit DWARF3 files
919 this ought to be an 8-byte wide computation. */
920 printf ("DW_OP_call4: <0x%lx>", (long) byte_get (data
, 4) + cu_offset
);
924 /* XXX: Strictly speaking for 64-bit DWARF3 files
925 this ought to be an 8-byte wide computation. */
926 if (dwarf_version
== -1)
928 printf (_("(DW_OP_call_ref in frame info)"));
929 /* No way to tell where the next op is, so just bail. */
930 return need_frame_base
;
932 if (dwarf_version
== 2)
934 printf ("DW_OP_call_ref: <0x%lx>",
935 (long) byte_get (data
, pointer_size
));
936 data
+= pointer_size
;
940 printf ("DW_OP_call_ref: <0x%lx>",
941 (long) byte_get (data
, offset_size
));
945 case DW_OP_form_tls_address
:
946 printf ("DW_OP_form_tls_address");
948 case DW_OP_call_frame_cfa
:
949 printf ("DW_OP_call_frame_cfa");
951 case DW_OP_bit_piece
:
952 printf ("DW_OP_bit_piece: ");
953 printf ("size: %lu ", read_leb128 (data
, &bytes_read
, 0));
955 printf ("offset: %lu ", read_leb128 (data
, &bytes_read
, 0));
959 /* DWARF 4 extensions. */
960 case DW_OP_stack_value
:
961 printf ("DW_OP_stack_value");
964 case DW_OP_implicit_value
:
965 printf ("DW_OP_implicit_value");
966 uvalue
= read_leb128 (data
, &bytes_read
, 0);
968 display_block (data
, uvalue
);
972 /* GNU extensions. */
973 case DW_OP_GNU_push_tls_address
:
974 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
976 case DW_OP_GNU_uninit
:
977 printf ("DW_OP_GNU_uninit");
978 /* FIXME: Is there data associated with this OP ? */
980 case DW_OP_GNU_encoded_addr
:
986 addr
= get_encoded_value (data
, encoding
, section
);
987 data
+= size_of_encoded_value (encoding
);
989 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
990 print_dwarf_vma (addr
, pointer_size
);
993 case DW_OP_GNU_implicit_pointer
:
994 /* XXX: Strictly speaking for 64-bit DWARF3 files
995 this ought to be an 8-byte wide computation. */
996 if (dwarf_version
== -1)
998 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
999 /* No way to tell where the next op is, so just bail. */
1000 return need_frame_base
;
1002 if (dwarf_version
== 2)
1004 printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
1005 (long) byte_get (data
, pointer_size
),
1006 read_leb128 (data
+ pointer_size
, &bytes_read
, 1));
1007 data
+= pointer_size
+ bytes_read
;
1011 printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
1012 (long) byte_get (data
, offset_size
),
1013 read_leb128 (data
+ offset_size
, &bytes_read
, 1));
1014 data
+= offset_size
+ bytes_read
;
1018 /* HP extensions. */
1019 case DW_OP_HP_is_value
:
1020 printf ("DW_OP_HP_is_value");
1021 /* FIXME: Is there data associated with this OP ? */
1023 case DW_OP_HP_fltconst4
:
1024 printf ("DW_OP_HP_fltconst4");
1025 /* FIXME: Is there data associated with this OP ? */
1027 case DW_OP_HP_fltconst8
:
1028 printf ("DW_OP_HP_fltconst8");
1029 /* FIXME: Is there data associated with this OP ? */
1031 case DW_OP_HP_mod_range
:
1032 printf ("DW_OP_HP_mod_range");
1033 /* FIXME: Is there data associated with this OP ? */
1035 case DW_OP_HP_unmod_range
:
1036 printf ("DW_OP_HP_unmod_range");
1037 /* FIXME: Is there data associated with this OP ? */
1040 printf ("DW_OP_HP_tls");
1041 /* FIXME: Is there data associated with this OP ? */
1044 /* PGI (STMicroelectronics) extensions. */
1045 case DW_OP_PGI_omp_thread_num
:
1046 /* Pushes the thread number for the current thread as it would be
1047 returned by the standard OpenMP library function:
1048 omp_get_thread_num(). The "current thread" is the thread for
1049 which the expression is being evaluated. */
1050 printf ("DW_OP_PGI_omp_thread_num");
1054 if (op
>= DW_OP_lo_user
1055 && op
<= DW_OP_hi_user
)
1056 printf (_("(User defined location op)"));
1058 printf (_("(Unknown location op)"));
1059 /* No way to tell where the next op is, so just bail. */
1060 return need_frame_base
;
1063 /* Separate the ops. */
1068 return need_frame_base
;
1071 static unsigned char *
1072 read_and_display_attr_value (unsigned long attribute
,
1074 unsigned char * data
,
1075 unsigned long cu_offset
,
1076 unsigned long pointer_size
,
1077 unsigned long offset_size
,
1079 debug_info
* debug_info_p
,
1081 struct dwarf_section
* section
)
1083 unsigned long uvalue
= 0;
1084 unsigned char *block_start
= NULL
;
1085 unsigned char * orig_data
= data
;
1086 unsigned int bytes_read
;
1093 case DW_FORM_ref_addr
:
1094 if (dwarf_version
== 2)
1096 uvalue
= byte_get (data
, pointer_size
);
1097 data
+= pointer_size
;
1099 else if (dwarf_version
== 3 || dwarf_version
== 4)
1101 uvalue
= byte_get (data
, offset_size
);
1102 data
+= offset_size
;
1106 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1111 uvalue
= byte_get (data
, pointer_size
);
1112 data
+= pointer_size
;
1116 case DW_FORM_sec_offset
:
1117 uvalue
= byte_get (data
, offset_size
);
1118 data
+= offset_size
;
1121 case DW_FORM_flag_present
:
1128 uvalue
= byte_get (data
++, 1);
1133 uvalue
= byte_get (data
, 2);
1139 uvalue
= byte_get (data
, 4);
1144 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1148 case DW_FORM_ref_udata
:
1150 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1154 case DW_FORM_indirect
:
1155 form
= read_leb128 (data
, & bytes_read
, 0);
1158 printf (" %s", get_FORM_name (form
));
1159 return read_and_display_attr_value (attribute
, form
, data
,
1160 cu_offset
, pointer_size
,
1161 offset_size
, dwarf_version
,
1162 debug_info_p
, do_loc
,
1168 case DW_FORM_ref_addr
:
1170 printf (" <0x%lx>", uvalue
);
1176 case DW_FORM_ref_udata
:
1178 printf (" <0x%lx>", uvalue
+ cu_offset
);
1183 case DW_FORM_sec_offset
:
1185 printf (" 0x%lx", uvalue
);
1188 case DW_FORM_flag_present
:
1195 printf (" %ld", uvalue
);
1202 uvalue
= byte_get (data
, 4);
1203 printf (" 0x%lx", uvalue
);
1204 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1206 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1207 && num_debug_info_entries
== 0)
1209 if (sizeof (uvalue
) == 8)
1210 uvalue
= byte_get (data
, 8);
1212 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1217 case DW_FORM_string
:
1219 printf (" %s", data
);
1220 data
+= strlen ((char *) data
) + 1;
1224 case DW_FORM_exprloc
:
1225 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1226 block_start
= data
+ bytes_read
;
1228 data
= block_start
+ uvalue
;
1230 data
= display_block (block_start
, uvalue
);
1233 case DW_FORM_block1
:
1234 uvalue
= byte_get (data
, 1);
1235 block_start
= data
+ 1;
1237 data
= block_start
+ uvalue
;
1239 data
= display_block (block_start
, uvalue
);
1242 case DW_FORM_block2
:
1243 uvalue
= byte_get (data
, 2);
1244 block_start
= data
+ 2;
1246 data
= block_start
+ uvalue
;
1248 data
= display_block (block_start
, uvalue
);
1251 case DW_FORM_block4
:
1252 uvalue
= byte_get (data
, 4);
1253 block_start
= data
+ 4;
1255 data
= block_start
+ uvalue
;
1257 data
= display_block (block_start
, uvalue
);
1262 printf (_(" (indirect string, offset: 0x%lx): %s"),
1263 uvalue
, fetch_indirect_string (uvalue
));
1266 case DW_FORM_indirect
:
1267 /* Handled above. */
1270 case DW_FORM_ref_sig8
:
1274 printf (" signature: ");
1275 for (i
= 0; i
< 8; i
++)
1277 printf ("%02x", (unsigned) byte_get (data
, 1));
1286 warn (_("Unrecognized form: %lu\n"), form
);
1290 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1291 && num_debug_info_entries
== 0)
1295 case DW_AT_frame_base
:
1296 have_frame_base
= 1;
1297 case DW_AT_location
:
1298 case DW_AT_string_length
:
1299 case DW_AT_return_addr
:
1300 case DW_AT_data_member_location
:
1301 case DW_AT_vtable_elem_location
:
1303 case DW_AT_static_link
:
1304 case DW_AT_use_location
:
1305 if (form
== DW_FORM_data4
1306 || form
== DW_FORM_data8
1307 || form
== DW_FORM_sec_offset
)
1309 /* Process location list. */
1310 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1311 unsigned int num
= debug_info_p
->num_loc_offsets
;
1313 if (lmax
== 0 || num
>= lmax
)
1316 debug_info_p
->loc_offsets
= (long unsigned int *)
1317 xcrealloc (debug_info_p
->loc_offsets
,
1318 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1319 debug_info_p
->have_frame_base
= (int *)
1320 xcrealloc (debug_info_p
->have_frame_base
,
1321 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1322 debug_info_p
->max_loc_offsets
= lmax
;
1324 debug_info_p
->loc_offsets
[num
] = uvalue
;
1325 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1326 debug_info_p
->num_loc_offsets
++;
1331 if (need_base_address
)
1332 debug_info_p
->base_address
= uvalue
;
1336 if (form
== DW_FORM_data4
1337 || form
== DW_FORM_data8
1338 || form
== DW_FORM_sec_offset
)
1340 /* Process range list. */
1341 unsigned int lmax
= debug_info_p
->max_range_lists
;
1342 unsigned int num
= debug_info_p
->num_range_lists
;
1344 if (lmax
== 0 || num
>= lmax
)
1347 debug_info_p
->range_lists
= (long unsigned int *)
1348 xcrealloc (debug_info_p
->range_lists
,
1349 lmax
, sizeof (*debug_info_p
->range_lists
));
1350 debug_info_p
->max_range_lists
= lmax
;
1352 debug_info_p
->range_lists
[num
] = uvalue
;
1353 debug_info_p
->num_range_lists
++;
1365 /* For some attributes we can display further information. */
1373 case DW_INL_not_inlined
:
1374 printf (_("(not inlined)"));
1376 case DW_INL_inlined
:
1377 printf (_("(inlined)"));
1379 case DW_INL_declared_not_inlined
:
1380 printf (_("(declared as inline but ignored)"));
1382 case DW_INL_declared_inlined
:
1383 printf (_("(declared as inline and inlined)"));
1386 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1391 case DW_AT_language
:
1394 /* Ordered by the numeric value of these constants. */
1395 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1396 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1397 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1398 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1399 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1400 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1401 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1402 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1403 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1404 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1405 /* DWARF 2.1 values. */
1406 case DW_LANG_Java
: printf ("(Java)"); break;
1407 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1408 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1409 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1410 /* DWARF 3 values. */
1411 case DW_LANG_PLI
: printf ("(PLI)"); break;
1412 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1413 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1414 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1415 case DW_LANG_D
: printf ("(D)"); break;
1416 /* DWARF 4 values. */
1417 case DW_LANG_Python
: printf ("(Python)"); break;
1418 /* MIPS extension. */
1419 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1420 /* UPC extension. */
1421 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1423 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1424 printf ("(implementation defined: %lx)", uvalue
);
1426 printf ("(Unknown: %lx)", uvalue
);
1431 case DW_AT_encoding
:
1434 case DW_ATE_void
: printf ("(void)"); break;
1435 case DW_ATE_address
: printf ("(machine address)"); break;
1436 case DW_ATE_boolean
: printf ("(boolean)"); break;
1437 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1438 case DW_ATE_float
: printf ("(float)"); break;
1439 case DW_ATE_signed
: printf ("(signed)"); break;
1440 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1441 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1442 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1443 /* DWARF 2.1 values: */
1444 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1445 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1446 /* DWARF 3 values: */
1447 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1448 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1449 case DW_ATE_edited
: printf ("(edited)"); break;
1450 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1451 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1452 /* HP extensions: */
1453 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1454 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1455 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1456 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1457 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1458 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1459 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1462 if (uvalue
>= DW_ATE_lo_user
1463 && uvalue
<= DW_ATE_hi_user
)
1464 printf ("(user defined type)");
1466 printf ("(unknown type)");
1471 case DW_AT_accessibility
:
1474 case DW_ACCESS_public
: printf ("(public)"); break;
1475 case DW_ACCESS_protected
: printf ("(protected)"); break;
1476 case DW_ACCESS_private
: printf ("(private)"); break;
1478 printf ("(unknown accessibility)");
1483 case DW_AT_visibility
:
1486 case DW_VIS_local
: printf ("(local)"); break;
1487 case DW_VIS_exported
: printf ("(exported)"); break;
1488 case DW_VIS_qualified
: printf ("(qualified)"); break;
1489 default: printf ("(unknown visibility)"); break;
1493 case DW_AT_virtuality
:
1496 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1497 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1498 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1499 default: printf ("(unknown virtuality)"); break;
1503 case DW_AT_identifier_case
:
1506 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1507 case DW_ID_up_case
: printf ("(up_case)"); break;
1508 case DW_ID_down_case
: printf ("(down_case)"); break;
1509 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1510 default: printf ("(unknown case)"); break;
1514 case DW_AT_calling_convention
:
1517 case DW_CC_normal
: printf ("(normal)"); break;
1518 case DW_CC_program
: printf ("(program)"); break;
1519 case DW_CC_nocall
: printf ("(nocall)"); break;
1521 if (uvalue
>= DW_CC_lo_user
1522 && uvalue
<= DW_CC_hi_user
)
1523 printf ("(user defined)");
1525 printf ("(unknown convention)");
1529 case DW_AT_ordering
:
1532 case -1: printf ("(undefined)"); break;
1533 case 0: printf ("(row major)"); break;
1534 case 1: printf ("(column major)"); break;
1538 case DW_AT_frame_base
:
1539 have_frame_base
= 1;
1540 case DW_AT_location
:
1541 case DW_AT_string_length
:
1542 case DW_AT_return_addr
:
1543 case DW_AT_data_member_location
:
1544 case DW_AT_vtable_elem_location
:
1546 case DW_AT_static_link
:
1547 case DW_AT_use_location
:
1548 if (form
== DW_FORM_data4
1549 || form
== DW_FORM_data8
1550 || form
== DW_FORM_sec_offset
)
1551 printf (_("(location list)"));
1553 case DW_AT_allocated
:
1554 case DW_AT_associated
:
1555 case DW_AT_data_location
:
1557 case DW_AT_upper_bound
:
1558 case DW_AT_lower_bound
:
1561 int need_frame_base
;
1564 need_frame_base
= decode_location_expression (block_start
,
1569 cu_offset
, section
);
1571 if (need_frame_base
&& !have_frame_base
)
1572 printf (_(" [without DW_AT_frame_base]"));
1578 if (form
== DW_FORM_ref_sig8
)
1581 if (form
== DW_FORM_ref1
1582 || form
== DW_FORM_ref2
1583 || form
== DW_FORM_ref4
)
1584 uvalue
+= cu_offset
;
1586 if (uvalue
>= section
->size
)
1587 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1588 uvalue
, (unsigned long) (orig_data
- section
->start
));
1591 unsigned long abbrev_number
;
1592 abbrev_entry
* entry
;
1594 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1596 printf ("[Abbrev Number: %ld", abbrev_number
);
1597 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1598 if (entry
->entry
== abbrev_number
)
1601 printf (" (%s)", get_TAG_name (entry
->tag
));
1615 get_AT_name (unsigned long attribute
)
1619 case DW_AT_sibling
: return "DW_AT_sibling";
1620 case DW_AT_location
: return "DW_AT_location";
1621 case DW_AT_name
: return "DW_AT_name";
1622 case DW_AT_ordering
: return "DW_AT_ordering";
1623 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1624 case DW_AT_byte_size
: return "DW_AT_byte_size";
1625 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1626 case DW_AT_bit_size
: return "DW_AT_bit_size";
1627 case DW_AT_element_list
: return "DW_AT_element_list";
1628 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1629 case DW_AT_low_pc
: return "DW_AT_low_pc";
1630 case DW_AT_high_pc
: return "DW_AT_high_pc";
1631 case DW_AT_language
: return "DW_AT_language";
1632 case DW_AT_member
: return "DW_AT_member";
1633 case DW_AT_discr
: return "DW_AT_discr";
1634 case DW_AT_discr_value
: return "DW_AT_discr_value";
1635 case DW_AT_visibility
: return "DW_AT_visibility";
1636 case DW_AT_import
: return "DW_AT_import";
1637 case DW_AT_string_length
: return "DW_AT_string_length";
1638 case DW_AT_common_reference
: return "DW_AT_common_reference";
1639 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1640 case DW_AT_const_value
: return "DW_AT_const_value";
1641 case DW_AT_containing_type
: return "DW_AT_containing_type";
1642 case DW_AT_default_value
: return "DW_AT_default_value";
1643 case DW_AT_inline
: return "DW_AT_inline";
1644 case DW_AT_is_optional
: return "DW_AT_is_optional";
1645 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1646 case DW_AT_producer
: return "DW_AT_producer";
1647 case DW_AT_prototyped
: return "DW_AT_prototyped";
1648 case DW_AT_return_addr
: return "DW_AT_return_addr";
1649 case DW_AT_start_scope
: return "DW_AT_start_scope";
1650 case DW_AT_stride_size
: return "DW_AT_stride_size";
1651 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1652 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1653 case DW_AT_accessibility
: return "DW_AT_accessibility";
1654 case DW_AT_address_class
: return "DW_AT_address_class";
1655 case DW_AT_artificial
: return "DW_AT_artificial";
1656 case DW_AT_base_types
: return "DW_AT_base_types";
1657 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1658 case DW_AT_count
: return "DW_AT_count";
1659 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1660 case DW_AT_decl_column
: return "DW_AT_decl_column";
1661 case DW_AT_decl_file
: return "DW_AT_decl_file";
1662 case DW_AT_decl_line
: return "DW_AT_decl_line";
1663 case DW_AT_declaration
: return "DW_AT_declaration";
1664 case DW_AT_discr_list
: return "DW_AT_discr_list";
1665 case DW_AT_encoding
: return "DW_AT_encoding";
1666 case DW_AT_external
: return "DW_AT_external";
1667 case DW_AT_frame_base
: return "DW_AT_frame_base";
1668 case DW_AT_friend
: return "DW_AT_friend";
1669 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1670 case DW_AT_macro_info
: return "DW_AT_macro_info";
1671 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1672 case DW_AT_priority
: return "DW_AT_priority";
1673 case DW_AT_segment
: return "DW_AT_segment";
1674 case DW_AT_specification
: return "DW_AT_specification";
1675 case DW_AT_static_link
: return "DW_AT_static_link";
1676 case DW_AT_type
: return "DW_AT_type";
1677 case DW_AT_use_location
: return "DW_AT_use_location";
1678 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1679 case DW_AT_virtuality
: return "DW_AT_virtuality";
1680 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1681 /* DWARF 2.1 values. */
1682 case DW_AT_allocated
: return "DW_AT_allocated";
1683 case DW_AT_associated
: return "DW_AT_associated";
1684 case DW_AT_data_location
: return "DW_AT_data_location";
1685 case DW_AT_stride
: return "DW_AT_stride";
1686 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1687 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1688 case DW_AT_extension
: return "DW_AT_extension";
1689 case DW_AT_ranges
: return "DW_AT_ranges";
1690 case DW_AT_trampoline
: return "DW_AT_trampoline";
1691 case DW_AT_call_column
: return "DW_AT_call_column";
1692 case DW_AT_call_file
: return "DW_AT_call_file";
1693 case DW_AT_call_line
: return "DW_AT_call_line";
1694 case DW_AT_description
: return "DW_AT_description";
1695 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1696 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1697 case DW_AT_small
: return "DW_AT_small";
1698 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1699 case DW_AT_digit_count
: return "DW_AT_digit_count";
1700 case DW_AT_picture_string
: return "DW_AT_picture_string";
1701 case DW_AT_mutable
: return "DW_AT_mutable";
1702 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1703 case DW_AT_explicit
: return "DW_AT_explicit";
1704 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1705 case DW_AT_endianity
: return "DW_AT_endianity";
1706 case DW_AT_elemental
: return "DW_AT_elemental";
1707 case DW_AT_pure
: return "DW_AT_pure";
1708 case DW_AT_recursive
: return "DW_AT_recursive";
1709 /* DWARF 4 values. */
1710 case DW_AT_signature
: return "DW_AT_signature";
1711 case DW_AT_main_subprogram
: return "DW_AT_main_subprogram";
1712 case DW_AT_data_bit_offset
: return "DW_AT_data_bit_offset";
1713 case DW_AT_const_expr
: return "DW_AT_const_expr";
1714 case DW_AT_enum_class
: return "DW_AT_enum_class";
1715 case DW_AT_linkage_name
: return "DW_AT_linkage_name";
1717 /* HP and SGI/MIPS extensions. */
1718 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1719 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1720 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1721 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1722 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1723 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1724 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1725 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1726 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1727 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1729 /* HP Extensions. */
1730 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1731 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1732 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1733 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1734 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1735 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1736 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1737 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1738 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1739 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1740 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1741 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1742 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1744 /* One value is shared by the MIPS and HP extensions: */
1745 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1747 /* GNU extensions. */
1748 case DW_AT_sf_names
: return "DW_AT_sf_names";
1749 case DW_AT_src_info
: return "DW_AT_src_info";
1750 case DW_AT_mac_info
: return "DW_AT_mac_info";
1751 case DW_AT_src_coords
: return "DW_AT_src_coords";
1752 case DW_AT_body_begin
: return "DW_AT_body_begin";
1753 case DW_AT_body_end
: return "DW_AT_body_end";
1754 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1755 case DW_AT_GNU_guarded_by
: return "DW_AT_GNU_guarded_by";
1756 case DW_AT_GNU_pt_guarded_by
: return "DW_AT_GNU_pt_guarded_by";
1757 case DW_AT_GNU_guarded
: return "DW_AT_GNU_guarded";
1758 case DW_AT_GNU_pt_guarded
: return "DW_AT_GNU_pt_guarded";
1759 case DW_AT_GNU_locks_excluded
: return "DW_AT_GNU_locks_excluded";
1760 case DW_AT_GNU_exclusive_locks_required
: return "DW_AT_GNU_exclusive_locks_required";
1761 case DW_AT_GNU_shared_locks_required
: return "DW_AT_GNU_shared_locks_required";
1762 case DW_AT_GNU_odr_signature
: return "DW_AT_GNU_odr_signature";
1763 case DW_AT_use_GNAT_descriptive_type
: return "DW_AT_use_GNAT_descriptive_type";
1764 case DW_AT_GNAT_descriptive_type
: return "DW_AT_GNAT_descriptive_type";
1766 /* UPC extension. */
1767 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1769 /* PGI (STMicroelectronics) extensions. */
1770 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1771 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1772 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1776 static char buffer
[100];
1778 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1785 static unsigned char *
1786 read_and_display_attr (unsigned long attribute
,
1788 unsigned char * data
,
1789 unsigned long cu_offset
,
1790 unsigned long pointer_size
,
1791 unsigned long offset_size
,
1793 debug_info
* debug_info_p
,
1795 struct dwarf_section
* section
)
1798 printf (" %-18s:", get_AT_name (attribute
));
1799 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1800 pointer_size
, offset_size
,
1801 dwarf_version
, debug_info_p
,
1809 /* Process the contents of a .debug_info section. If do_loc is non-zero
1810 then we are scanning for location lists and we do not want to display
1811 anything to the user. If do_types is non-zero, we are processing
1812 a .debug_types section instead of a .debug_info section. */
1815 process_debug_info (struct dwarf_section
*section
,
1817 enum dwarf_section_display_enum abbrev_sec
,
1821 unsigned char *start
= section
->start
;
1822 unsigned char *end
= start
+ section
->size
;
1823 unsigned char *section_begin
;
1825 unsigned int num_units
= 0;
1827 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1828 && num_debug_info_entries
== 0
1831 unsigned long length
;
1833 /* First scan the section to get the number of comp units. */
1834 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1837 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1838 will be the length. For a 64-bit DWARF section, it'll be
1839 the escape code 0xffffffff followed by an 8 byte length. */
1840 length
= byte_get (section_begin
, 4);
1842 if (length
== 0xffffffff)
1844 length
= byte_get (section_begin
+ 4, 8);
1845 section_begin
+= length
+ 12;
1847 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1849 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1853 section_begin
+= length
+ 4;
1855 /* Negative values are illegal, they may even cause infinite
1856 looping. This can happen if we can't accurately apply
1857 relocations to an object file. */
1858 if ((signed long) length
<= 0)
1860 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1867 error (_("No comp units in %s section ?"), section
->name
);
1871 /* Then allocate an array to hold the information. */
1872 debug_information
= (debug_info
*) cmalloc (num_units
,
1873 sizeof (* debug_information
));
1874 if (debug_information
== NULL
)
1876 error (_("Not enough memory for a debug info array of %u entries"),
1884 printf (_("Contents of the %s section:\n\n"), section
->name
);
1886 load_debug_section (str
, file
);
1889 load_debug_section (abbrev_sec
, file
);
1890 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
1892 warn (_("Unable to locate %s section!\n"),
1893 debug_displays
[abbrev_sec
].section
.name
);
1897 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1899 DWARF2_Internal_CompUnit compunit
;
1900 unsigned char *hdrptr
;
1901 unsigned char *tags
;
1903 unsigned long cu_offset
;
1905 int initial_length_size
;
1906 unsigned char signature
[8] = { 0 };
1907 unsigned long type_offset
= 0;
1911 compunit
.cu_length
= byte_get (hdrptr
, 4);
1914 if (compunit
.cu_length
== 0xffffffff)
1916 compunit
.cu_length
= byte_get (hdrptr
, 8);
1919 initial_length_size
= 12;
1924 initial_length_size
= 4;
1927 compunit
.cu_version
= byte_get (hdrptr
, 2);
1930 cu_offset
= start
- section_begin
;
1932 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1933 hdrptr
+= offset_size
;
1935 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1942 for (i
= 0; i
< 8; i
++)
1944 signature
[i
] = byte_get (hdrptr
, 1);
1948 type_offset
= byte_get (hdrptr
, offset_size
);
1949 hdrptr
+= offset_size
;
1952 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1953 && num_debug_info_entries
== 0
1956 debug_information
[unit
].cu_offset
= cu_offset
;
1957 debug_information
[unit
].pointer_size
1958 = compunit
.cu_pointer_size
;
1959 debug_information
[unit
].offset_size
= offset_size
;
1960 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
1961 debug_information
[unit
].base_address
= 0;
1962 debug_information
[unit
].loc_offsets
= NULL
;
1963 debug_information
[unit
].have_frame_base
= NULL
;
1964 debug_information
[unit
].max_loc_offsets
= 0;
1965 debug_information
[unit
].num_loc_offsets
= 0;
1966 debug_information
[unit
].range_lists
= NULL
;
1967 debug_information
[unit
].max_range_lists
= 0;
1968 debug_information
[unit
].num_range_lists
= 0;
1973 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
1974 printf (_(" Length: 0x%lx (%s)\n"), compunit
.cu_length
,
1975 initial_length_size
== 8 ? "64-bit" : "32-bit");
1976 printf (_(" Version: %d\n"), compunit
.cu_version
);
1977 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
1978 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1982 printf (_(" Signature: "));
1983 for (i
= 0; i
< 8; i
++)
1984 printf ("%02x", signature
[i
]);
1986 printf (_(" Type Offset: 0x%lx\n"), type_offset
);
1990 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1993 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1994 cu_offset
, compunit
.cu_length
);
1998 start
+= compunit
.cu_length
+ initial_length_size
;
2000 if (compunit
.cu_version
!= 2
2001 && compunit
.cu_version
!= 3
2002 && compunit
.cu_version
!= 4)
2004 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
2005 cu_offset
, compunit
.cu_version
);
2011 /* Process the abbrevs used by this compilation unit. DWARF
2012 sections under Mach-O have non-zero addresses. */
2013 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
2014 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2015 (unsigned long) compunit
.cu_abbrev_offset
,
2016 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2018 process_abbrev_section
2019 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2020 + compunit
.cu_abbrev_offset
,
2021 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2022 + debug_displays
[abbrev_sec
].section
.size
);
2025 while (tags
< start
)
2027 unsigned int bytes_read
;
2028 unsigned long abbrev_number
;
2029 unsigned long die_offset
;
2030 abbrev_entry
*entry
;
2033 die_offset
= tags
- section_begin
;
2035 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2038 /* A null DIE marks the end of a list of siblings or it may also be
2039 a section padding. */
2040 if (abbrev_number
== 0)
2042 /* Check if it can be a section padding for the last CU. */
2043 if (level
== 0 && start
== end
)
2047 for (chk
= tags
; chk
< start
; chk
++)
2057 static unsigned num_bogus_warns
= 0;
2059 if (num_bogus_warns
< 3)
2061 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2064 if (num_bogus_warns
== 3)
2065 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2072 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2073 level
, die_offset
, abbrev_number
);
2075 /* Scan through the abbreviation list until we reach the
2077 for (entry
= first_abbrev
;
2078 entry
&& entry
->entry
!= abbrev_number
;
2079 entry
= entry
->next
)
2089 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2090 die_offset
, abbrev_number
);
2095 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2100 need_base_address
= 0;
2102 case DW_TAG_compile_unit
:
2103 need_base_address
= 1;
2105 case DW_TAG_entry_point
:
2106 case DW_TAG_subprogram
:
2107 need_base_address
= 0;
2108 /* Assuming that there is no DW_AT_frame_base. */
2109 have_frame_base
= 0;
2113 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2116 /* Show the offset from where the tag was extracted. */
2117 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2119 tags
= read_and_display_attr (attr
->attribute
,
2122 compunit
.cu_pointer_size
,
2124 compunit
.cu_version
,
2125 debug_information
+ unit
,
2129 if (entry
->children
)
2134 /* Set num_debug_info_entries here so that it can be used to check if
2135 we need to process .debug_loc and .debug_ranges sections. */
2136 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2137 && num_debug_info_entries
== 0
2139 num_debug_info_entries
= num_units
;
2149 /* Locate and scan the .debug_info section in the file and record the pointer
2150 sizes and offsets for the compilation units in it. Usually an executable
2151 will have just one pointer size, but this is not guaranteed, and so we try
2152 not to make any assumptions. Returns zero upon failure, or the number of
2153 compilation units upon success. */
2156 load_debug_info (void * file
)
2158 /* Reset the last pointer size so that we can issue correct error
2159 messages if we are displaying the contents of more than one section. */
2160 last_pointer_size
= 0;
2161 warned_about_missing_comp_units
= FALSE
;
2163 /* If we have already tried and failed to load the .debug_info
2164 section then do not bother to repear the task. */
2165 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2168 /* If we already have the information there is nothing else to do. */
2169 if (num_debug_info_entries
> 0)
2170 return num_debug_info_entries
;
2172 if (load_debug_section (info
, file
)
2173 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2174 return num_debug_info_entries
;
2176 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2181 display_debug_lines_raw (struct dwarf_section
*section
,
2182 unsigned char *data
,
2185 unsigned char *start
= section
->start
;
2187 printf (_("Raw dump of debug contents of section %s:\n\n"),
2192 DWARF2_Internal_LineInfo linfo
;
2193 unsigned char *standard_opcodes
;
2194 unsigned char *end_of_sequence
;
2195 unsigned char *hdrptr
;
2196 unsigned long hdroff
;
2197 int initial_length_size
;
2202 hdroff
= hdrptr
- start
;
2204 /* Check the length of the block. */
2205 linfo
.li_length
= byte_get (hdrptr
, 4);
2208 if (linfo
.li_length
== 0xffffffff)
2210 /* This section is 64-bit DWARF 3. */
2211 linfo
.li_length
= byte_get (hdrptr
, 8);
2214 initial_length_size
= 12;
2219 initial_length_size
= 4;
2222 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2225 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2230 /* Check its version number. */
2231 linfo
.li_version
= byte_get (hdrptr
, 2);
2233 if (linfo
.li_version
!= 2
2234 && linfo
.li_version
!= 3
2235 && linfo
.li_version
!= 4)
2237 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2241 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2242 hdrptr
+= offset_size
;
2243 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2245 if (linfo
.li_version
>= 4)
2247 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2249 if (linfo
.li_max_ops_per_insn
== 0)
2251 warn (_("Invalid maximum operations per insn.\n"));
2256 linfo
.li_max_ops_per_insn
= 1;
2257 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2259 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2261 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2263 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2266 /* Sign extend the line base field. */
2267 linfo
.li_line_base
<<= 24;
2268 linfo
.li_line_base
>>= 24;
2270 printf (_(" Offset: 0x%lx\n"), hdroff
);
2271 printf (_(" Length: %ld\n"), linfo
.li_length
);
2272 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2273 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2274 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2275 if (linfo
.li_version
>= 4)
2276 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2277 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2278 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2279 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2280 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2282 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2284 reset_state_machine (linfo
.li_default_is_stmt
);
2286 /* Display the contents of the Opcodes table. */
2287 standard_opcodes
= hdrptr
;
2289 printf (_("\n Opcodes:\n"));
2291 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2292 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2294 /* Display the contents of the Directory table. */
2295 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2298 printf (_("\n The Directory Table is empty.\n"));
2301 printf (_("\n The Directory Table:\n"));
2305 printf (" %s\n", data
);
2307 data
+= strlen ((char *) data
) + 1;
2311 /* Skip the NUL at the end of the table. */
2314 /* Display the contents of the File Name table. */
2316 printf (_("\n The File Name Table is empty.\n"));
2319 printf (_("\n The File Name Table:\n"));
2320 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2324 unsigned char *name
;
2325 unsigned int bytes_read
;
2327 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2330 data
+= strlen ((char *) data
) + 1;
2332 printf ("%lu\t", read_leb128 (data
, & bytes_read
, 0));
2334 printf ("%lu\t", read_leb128 (data
, & bytes_read
, 0));
2336 printf ("%lu\t", read_leb128 (data
, & bytes_read
, 0));
2338 printf ("%s\n", name
);
2342 /* Skip the NUL at the end of the table. */
2345 /* Now display the statements. */
2346 printf (_("\n Line Number Statements:\n"));
2348 while (data
< end_of_sequence
)
2350 unsigned char op_code
;
2352 unsigned long int uladv
;
2353 unsigned int bytes_read
;
2357 if (op_code
>= linfo
.li_opcode_base
)
2359 op_code
-= linfo
.li_opcode_base
;
2360 uladv
= (op_code
/ linfo
.li_line_range
);
2361 if (linfo
.li_max_ops_per_insn
== 1)
2363 uladv
*= linfo
.li_min_insn_length
;
2364 state_machine_regs
.address
+= uladv
;
2365 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2366 op_code
, uladv
, state_machine_regs
.address
);
2370 state_machine_regs
.address
2371 += ((state_machine_regs
.op_index
+ uladv
)
2372 / linfo
.li_max_ops_per_insn
)
2373 * linfo
.li_min_insn_length
;
2374 state_machine_regs
.op_index
2375 = (state_machine_regs
.op_index
+ uladv
)
2376 % linfo
.li_max_ops_per_insn
;
2377 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx[%d]"),
2378 op_code
, uladv
, state_machine_regs
.address
,
2379 state_machine_regs
.op_index
);
2381 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2382 state_machine_regs
.line
+= adv
;
2383 printf (_(" and Line by %d to %d\n"),
2384 adv
, state_machine_regs
.line
);
2386 else switch (op_code
)
2388 case DW_LNS_extended_op
:
2389 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2393 printf (_(" Copy\n"));
2396 case DW_LNS_advance_pc
:
2397 uladv
= read_leb128 (data
, & bytes_read
, 0);
2399 if (linfo
.li_max_ops_per_insn
== 1)
2401 uladv
*= linfo
.li_min_insn_length
;
2402 state_machine_regs
.address
+= uladv
;
2403 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2404 state_machine_regs
.address
);
2408 state_machine_regs
.address
2409 += ((state_machine_regs
.op_index
+ uladv
)
2410 / linfo
.li_max_ops_per_insn
)
2411 * linfo
.li_min_insn_length
;
2412 state_machine_regs
.op_index
2413 = (state_machine_regs
.op_index
+ uladv
)
2414 % linfo
.li_max_ops_per_insn
;
2415 printf (_(" Advance PC by %lu to 0x%lx[%d]\n"), uladv
,
2416 state_machine_regs
.address
,
2417 state_machine_regs
.op_index
);
2421 case DW_LNS_advance_line
:
2422 adv
= read_leb128 (data
, & bytes_read
, 1);
2424 state_machine_regs
.line
+= adv
;
2425 printf (_(" Advance Line by %d to %d\n"), adv
,
2426 state_machine_regs
.line
);
2429 case DW_LNS_set_file
:
2430 adv
= read_leb128 (data
, & bytes_read
, 0);
2432 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2434 state_machine_regs
.file
= adv
;
2437 case DW_LNS_set_column
:
2438 uladv
= read_leb128 (data
, & bytes_read
, 0);
2440 printf (_(" Set column to %lu\n"), uladv
);
2441 state_machine_regs
.column
= uladv
;
2444 case DW_LNS_negate_stmt
:
2445 adv
= state_machine_regs
.is_stmt
;
2447 printf (_(" Set is_stmt to %d\n"), adv
);
2448 state_machine_regs
.is_stmt
= adv
;
2451 case DW_LNS_set_basic_block
:
2452 printf (_(" Set basic block\n"));
2453 state_machine_regs
.basic_block
= 1;
2456 case DW_LNS_const_add_pc
:
2457 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2458 if (linfo
.li_max_ops_per_insn
)
2460 uladv
*= linfo
.li_min_insn_length
;
2461 state_machine_regs
.address
+= uladv
;
2462 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2463 state_machine_regs
.address
);
2467 state_machine_regs
.address
2468 += ((state_machine_regs
.op_index
+ uladv
)
2469 / linfo
.li_max_ops_per_insn
)
2470 * linfo
.li_min_insn_length
;
2471 state_machine_regs
.op_index
2472 = (state_machine_regs
.op_index
+ uladv
)
2473 % linfo
.li_max_ops_per_insn
;
2474 printf (_(" Advance PC by constant %lu to 0x%lx[%d]\n"),
2475 uladv
, state_machine_regs
.address
,
2476 state_machine_regs
.op_index
);
2480 case DW_LNS_fixed_advance_pc
:
2481 uladv
= byte_get (data
, 2);
2483 state_machine_regs
.address
+= uladv
;
2484 state_machine_regs
.op_index
= 0;
2485 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2486 uladv
, state_machine_regs
.address
);
2489 case DW_LNS_set_prologue_end
:
2490 printf (_(" Set prologue_end to true\n"));
2493 case DW_LNS_set_epilogue_begin
:
2494 printf (_(" Set epilogue_begin to true\n"));
2497 case DW_LNS_set_isa
:
2498 uladv
= read_leb128 (data
, & bytes_read
, 0);
2500 printf (_(" Set ISA to %lu\n"), uladv
);
2504 printf (_(" Unknown opcode %d with operands: "), op_code
);
2506 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2508 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2509 i
== 1 ? "" : ", ");
2524 unsigned char *name
;
2525 unsigned int directory_index
;
2526 unsigned int modification_date
;
2527 unsigned int length
;
2530 /* Output a decoded representation of the .debug_line section. */
2533 display_debug_lines_decoded (struct dwarf_section
*section
,
2534 unsigned char *data
,
2537 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2542 /* This loop amounts to one iteration per compilation unit. */
2543 DWARF2_Internal_LineInfo linfo
;
2544 unsigned char *standard_opcodes
;
2545 unsigned char *end_of_sequence
;
2546 unsigned char *hdrptr
;
2547 int initial_length_size
;
2550 File_Entry
*file_table
= NULL
;
2551 unsigned char **directory_table
= NULL
;
2555 /* Extract information from the Line Number Program Header.
2556 (section 6.2.4 in the Dwarf3 doc). */
2558 /* Get the length of this CU's line number information block. */
2559 linfo
.li_length
= byte_get (hdrptr
, 4);
2562 if (linfo
.li_length
== 0xffffffff)
2564 /* This section is 64-bit DWARF 3. */
2565 linfo
.li_length
= byte_get (hdrptr
, 8);
2568 initial_length_size
= 12;
2573 initial_length_size
= 4;
2576 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2578 warn (_("The line info appears to be corrupt - "
2579 "the section is too small\n"));
2583 /* Get this CU's Line Number Block version number. */
2584 linfo
.li_version
= byte_get (hdrptr
, 2);
2586 if (linfo
.li_version
!= 2
2587 && linfo
.li_version
!= 3
2588 && linfo
.li_version
!= 4)
2590 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2595 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2596 hdrptr
+= offset_size
;
2597 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2599 if (linfo
.li_version
>= 4)
2601 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2603 if (linfo
.li_max_ops_per_insn
== 0)
2605 warn (_("Invalid maximum operations per insn.\n"));
2610 linfo
.li_max_ops_per_insn
= 1;
2611 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2613 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2615 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2617 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2620 /* Sign extend the line base field. */
2621 linfo
.li_line_base
<<= 24;
2622 linfo
.li_line_base
>>= 24;
2624 /* Find the end of this CU's Line Number Information Block. */
2625 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2627 reset_state_machine (linfo
.li_default_is_stmt
);
2629 /* Save a pointer to the contents of the Opcodes table. */
2630 standard_opcodes
= hdrptr
;
2632 /* Traverse the Directory table just to count entries. */
2633 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2636 unsigned int n_directories
= 0;
2637 unsigned char *ptr_directory_table
= data
;
2641 data
+= strlen ((char *) data
) + 1;
2645 /* Go through the directory table again to save the directories. */
2646 directory_table
= (unsigned char **)
2647 xmalloc (n_directories
* sizeof (unsigned char *));
2650 while (*ptr_directory_table
!= 0)
2652 directory_table
[i
] = ptr_directory_table
;
2653 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2657 /* Skip the NUL at the end of the table. */
2660 /* Traverse the File Name table just to count the entries. */
2663 unsigned int n_files
= 0;
2664 unsigned char *ptr_file_name_table
= data
;
2668 unsigned int bytes_read
;
2670 /* Skip Name, directory index, last modification time and length
2672 data
+= strlen ((char *) data
) + 1;
2673 read_leb128 (data
, & bytes_read
, 0);
2675 read_leb128 (data
, & bytes_read
, 0);
2677 read_leb128 (data
, & bytes_read
, 0);
2683 /* Go through the file table again to save the strings. */
2684 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2687 while (*ptr_file_name_table
!= 0)
2689 unsigned int bytes_read
;
2691 file_table
[i
].name
= ptr_file_name_table
;
2692 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2694 /* We are not interested in directory, time or size. */
2695 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2697 ptr_file_name_table
+= bytes_read
;
2698 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2700 ptr_file_name_table
+= bytes_read
;
2701 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2702 ptr_file_name_table
+= bytes_read
;
2707 /* Print the Compilation Unit's name and a header. */
2708 if (directory_table
== NULL
)
2710 printf (_("CU: %s:\n"), file_table
[0].name
);
2711 printf (_("File name Line number Starting address\n"));
2715 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2716 printf (_("CU: %s/%s:\n"), directory_table
[0],
2717 file_table
[0].name
);
2719 printf ("%s:\n", file_table
[0].name
);
2721 printf (_("File name Line number Starting address\n"));
2725 /* Skip the NUL at the end of the table. */
2728 /* This loop iterates through the Dwarf Line Number Program. */
2729 while (data
< end_of_sequence
)
2731 unsigned char op_code
;
2733 unsigned long int uladv
;
2734 unsigned int bytes_read
;
2735 int is_special_opcode
= 0;
2739 if (op_code
>= linfo
.li_opcode_base
)
2741 op_code
-= linfo
.li_opcode_base
;
2742 uladv
= (op_code
/ linfo
.li_line_range
);
2743 if (linfo
.li_max_ops_per_insn
== 1)
2745 uladv
*= linfo
.li_min_insn_length
;
2746 state_machine_regs
.address
+= uladv
;
2750 state_machine_regs
.address
2751 += ((state_machine_regs
.op_index
+ uladv
)
2752 / linfo
.li_max_ops_per_insn
)
2753 * linfo
.li_min_insn_length
;
2754 state_machine_regs
.op_index
2755 = (state_machine_regs
.op_index
+ uladv
)
2756 % linfo
.li_max_ops_per_insn
;
2759 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2760 state_machine_regs
.line
+= adv
;
2761 is_special_opcode
= 1;
2763 else switch (op_code
)
2765 case DW_LNS_extended_op
:
2767 unsigned int ext_op_code_len
;
2768 unsigned char ext_op_code
;
2769 unsigned char *op_code_data
= data
;
2771 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2772 op_code_data
+= bytes_read
;
2774 if (ext_op_code_len
== 0)
2776 warn (_("badly formed extended line op encountered!\n"));
2779 ext_op_code_len
+= bytes_read
;
2780 ext_op_code
= *op_code_data
++;
2782 switch (ext_op_code
)
2784 case DW_LNE_end_sequence
:
2785 reset_state_machine (linfo
.li_default_is_stmt
);
2787 case DW_LNE_set_address
:
2788 state_machine_regs
.address
=
2789 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2790 state_machine_regs
.op_index
= 0;
2792 case DW_LNE_define_file
:
2794 unsigned int dir_index
= 0;
2796 ++state_machine_regs
.last_file_entry
;
2797 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2798 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2799 op_code_data
+= bytes_read
;
2800 read_leb128 (op_code_data
, & bytes_read
, 0);
2801 op_code_data
+= bytes_read
;
2802 read_leb128 (op_code_data
, & bytes_read
, 0);
2804 printf ("%s:\n", directory_table
[dir_index
]);
2808 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2811 data
+= ext_op_code_len
;
2817 case DW_LNS_advance_pc
:
2818 uladv
= read_leb128 (data
, & bytes_read
, 0);
2820 if (linfo
.li_max_ops_per_insn
== 1)
2822 uladv
*= linfo
.li_min_insn_length
;
2823 state_machine_regs
.address
+= uladv
;
2827 state_machine_regs
.address
2828 += ((state_machine_regs
.op_index
+ uladv
)
2829 / linfo
.li_max_ops_per_insn
)
2830 * linfo
.li_min_insn_length
;
2831 state_machine_regs
.op_index
2832 = (state_machine_regs
.op_index
+ uladv
)
2833 % linfo
.li_max_ops_per_insn
;
2837 case DW_LNS_advance_line
:
2838 adv
= read_leb128 (data
, & bytes_read
, 1);
2840 state_machine_regs
.line
+= adv
;
2843 case DW_LNS_set_file
:
2844 adv
= read_leb128 (data
, & bytes_read
, 0);
2846 state_machine_regs
.file
= adv
;
2847 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2849 /* If directory index is 0, that means current directory. */
2850 printf ("\n./%s:[++]\n",
2851 file_table
[state_machine_regs
.file
- 1].name
);
2855 /* The directory index starts counting at 1. */
2856 printf ("\n%s/%s:\n",
2857 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2858 file_table
[state_machine_regs
.file
- 1].name
);
2862 case DW_LNS_set_column
:
2863 uladv
= read_leb128 (data
, & bytes_read
, 0);
2865 state_machine_regs
.column
= uladv
;
2868 case DW_LNS_negate_stmt
:
2869 adv
= state_machine_regs
.is_stmt
;
2871 state_machine_regs
.is_stmt
= adv
;
2874 case DW_LNS_set_basic_block
:
2875 state_machine_regs
.basic_block
= 1;
2878 case DW_LNS_const_add_pc
:
2879 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2880 if (linfo
.li_max_ops_per_insn
== 1)
2882 uladv
*= linfo
.li_min_insn_length
;
2883 state_machine_regs
.address
+= uladv
;
2887 state_machine_regs
.address
2888 += ((state_machine_regs
.op_index
+ uladv
)
2889 / linfo
.li_max_ops_per_insn
)
2890 * linfo
.li_min_insn_length
;
2891 state_machine_regs
.op_index
2892 = (state_machine_regs
.op_index
+ uladv
)
2893 % linfo
.li_max_ops_per_insn
;
2897 case DW_LNS_fixed_advance_pc
:
2898 uladv
= byte_get (data
, 2);
2900 state_machine_regs
.address
+= uladv
;
2901 state_machine_regs
.op_index
= 0;
2904 case DW_LNS_set_prologue_end
:
2907 case DW_LNS_set_epilogue_begin
:
2910 case DW_LNS_set_isa
:
2911 uladv
= read_leb128 (data
, & bytes_read
, 0);
2913 printf (_(" Set ISA to %lu\n"), uladv
);
2917 printf (_(" Unknown opcode %d with operands: "), op_code
);
2919 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2921 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2922 i
== 1 ? "" : ", ");
2929 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2930 to the DWARF address/line matrix. */
2931 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
2932 || (op_code
== DW_LNS_copy
))
2934 const unsigned int MAX_FILENAME_LENGTH
= 35;
2935 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
2936 char *newFileName
= NULL
;
2937 size_t fileNameLength
= strlen (fileName
);
2939 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
2941 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
2942 /* Truncate file name */
2943 strncpy (newFileName
,
2944 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
2945 MAX_FILENAME_LENGTH
+ 1);
2949 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
2950 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
2953 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
2955 if (linfo
.li_max_ops_per_insn
== 1)
2956 printf ("%-35s %11d %#18lx\n", newFileName
,
2957 state_machine_regs
.line
,
2958 state_machine_regs
.address
);
2960 printf ("%-35s %11d %#18lx[%d]\n", newFileName
,
2961 state_machine_regs
.line
,
2962 state_machine_regs
.address
,
2963 state_machine_regs
.op_index
);
2967 if (linfo
.li_max_ops_per_insn
== 1)
2968 printf ("%s %11d %#18lx\n", newFileName
,
2969 state_machine_regs
.line
,
2970 state_machine_regs
.address
);
2972 printf ("%s %11d %#18lx[%d]\n", newFileName
,
2973 state_machine_regs
.line
,
2974 state_machine_regs
.address
,
2975 state_machine_regs
.op_index
);
2978 if (op_code
== DW_LNE_end_sequence
)
2986 free (directory_table
);
2987 directory_table
= NULL
;
2995 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
2997 unsigned char *data
= section
->start
;
2998 unsigned char *end
= data
+ section
->size
;
3000 int retValDecoded
= 1;
3002 if (do_debug_lines
== 0)
3003 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3005 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3006 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3008 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3009 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3011 if (!retValRaw
|| !retValDecoded
)
3018 find_debug_info_for_offset (unsigned long offset
)
3022 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3025 for (i
= 0; i
< num_debug_info_entries
; i
++)
3026 if (debug_information
[i
].cu_offset
== offset
)
3027 return debug_information
+ i
;
3033 display_debug_pubnames (struct dwarf_section
*section
,
3034 void *file ATTRIBUTE_UNUSED
)
3036 DWARF2_Internal_PubNames names
;
3037 unsigned char *start
= section
->start
;
3038 unsigned char *end
= start
+ section
->size
;
3040 /* It does not matter if this load fails,
3041 we test for that later on. */
3042 load_debug_info (file
);
3044 printf (_("Contents of the %s section:\n\n"), section
->name
);
3048 unsigned char *data
;
3049 unsigned long offset
;
3050 int offset_size
, initial_length_size
;
3054 names
.pn_length
= byte_get (data
, 4);
3056 if (names
.pn_length
== 0xffffffff)
3058 names
.pn_length
= byte_get (data
, 8);
3061 initial_length_size
= 12;
3066 initial_length_size
= 4;
3069 names
.pn_version
= byte_get (data
, 2);
3072 names
.pn_offset
= byte_get (data
, offset_size
);
3073 data
+= offset_size
;
3075 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3076 && num_debug_info_entries
> 0
3077 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3078 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3079 names
.pn_offset
, section
->name
);
3081 names
.pn_size
= byte_get (data
, offset_size
);
3082 data
+= offset_size
;
3084 start
+= names
.pn_length
+ initial_length_size
;
3086 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3088 static int warned
= 0;
3092 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3099 printf (_(" Length: %ld\n"),
3101 printf (_(" Version: %d\n"),
3103 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3105 printf (_(" Size of area in .debug_info section: %ld\n"),
3108 printf (_("\n Offset\tName\n"));
3112 offset
= byte_get (data
, offset_size
);
3116 data
+= offset_size
;
3117 printf (" %-6lx\t%s\n", offset
, data
);
3118 data
+= strlen ((char *) data
) + 1;
3121 while (offset
!= 0);
3129 display_debug_macinfo (struct dwarf_section
*section
,
3130 void *file ATTRIBUTE_UNUSED
)
3132 unsigned char *start
= section
->start
;
3133 unsigned char *end
= start
+ section
->size
;
3134 unsigned char *curr
= start
;
3135 unsigned int bytes_read
;
3136 enum dwarf_macinfo_record_type op
;
3138 printf (_("Contents of the %s section:\n\n"), section
->name
);
3142 unsigned int lineno
;
3145 op
= (enum dwarf_macinfo_record_type
) *curr
;
3150 case DW_MACINFO_start_file
:
3152 unsigned int filenum
;
3154 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3156 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3159 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3164 case DW_MACINFO_end_file
:
3165 printf (_(" DW_MACINFO_end_file\n"));
3168 case DW_MACINFO_define
:
3169 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3171 string
= (char *) curr
;
3172 curr
+= strlen (string
) + 1;
3173 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3177 case DW_MACINFO_undef
:
3178 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3180 string
= (char *) curr
;
3181 curr
+= strlen (string
) + 1;
3182 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3186 case DW_MACINFO_vendor_ext
:
3188 unsigned int constant
;
3190 constant
= read_leb128 (curr
, & bytes_read
, 0);
3192 string
= (char *) curr
;
3193 curr
+= strlen (string
) + 1;
3194 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3205 display_debug_abbrev (struct dwarf_section
*section
,
3206 void *file ATTRIBUTE_UNUSED
)
3208 abbrev_entry
*entry
;
3209 unsigned char *start
= section
->start
;
3210 unsigned char *end
= start
+ section
->size
;
3212 printf (_("Contents of the %s section:\n\n"), section
->name
);
3218 start
= process_abbrev_section (start
, end
);
3220 if (first_abbrev
== NULL
)
3223 printf (_(" Number TAG\n"));
3225 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3229 printf (" %ld %s [%s]\n",
3231 get_TAG_name (entry
->tag
),
3232 entry
->children
? _("has children") : _("no children"));
3234 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3235 printf (" %-18s %s\n",
3236 get_AT_name (attr
->attribute
),
3237 get_FORM_name (attr
->form
));
3248 display_debug_loc (struct dwarf_section
*section
, void *file
)
3250 unsigned char *start
= section
->start
;
3251 unsigned char *section_end
;
3252 unsigned long bytes
;
3253 unsigned char *section_begin
= start
;
3254 unsigned int num_loc_list
= 0;
3255 unsigned long last_offset
= 0;
3256 unsigned int first
= 0;
3259 int seen_first_offset
= 0;
3260 int use_debug_info
= 1;
3261 unsigned char *next
;
3263 bytes
= section
->size
;
3264 section_end
= start
+ bytes
;
3268 printf (_("\nThe %s section is empty.\n"), section
->name
);
3272 if (load_debug_info (file
) == 0)
3274 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3279 /* Check the order of location list in .debug_info section. If
3280 offsets of location lists are in the ascending order, we can
3281 use `debug_information' directly. */
3282 for (i
= 0; i
< num_debug_info_entries
; i
++)
3286 num
= debug_information
[i
].num_loc_offsets
;
3287 num_loc_list
+= num
;
3289 /* Check if we can use `debug_information' directly. */
3290 if (use_debug_info
&& num
!= 0)
3292 if (!seen_first_offset
)
3294 /* This is the first location list. */
3295 last_offset
= debug_information
[i
].loc_offsets
[0];
3297 seen_first_offset
= 1;
3303 for (; j
< num
; j
++)
3306 debug_information
[i
].loc_offsets
[j
])
3311 last_offset
= debug_information
[i
].loc_offsets
[j
];
3316 if (!use_debug_info
)
3317 /* FIXME: Should we handle this case? */
3318 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3320 if (!seen_first_offset
)
3321 error (_("No location lists in .debug_info section!\n"));
3323 /* DWARF sections under Mach-O have non-zero addresses. */
3324 if (debug_information
[first
].num_loc_offsets
> 0
3325 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3326 warn (_("Location lists in %s section start at 0x%lx\n"),
3327 section
->name
, debug_information
[first
].loc_offsets
[0]);
3329 printf (_("Contents of the %s section:\n\n"), section
->name
);
3330 printf (_(" Offset Begin End Expression\n"));
3332 seen_first_offset
= 0;
3333 for (i
= first
; i
< num_debug_info_entries
; i
++)
3337 unsigned short length
;
3338 unsigned long offset
;
3339 unsigned int pointer_size
;
3340 unsigned int offset_size
;
3342 unsigned long cu_offset
;
3343 unsigned long base_address
;
3344 int need_frame_base
;
3347 pointer_size
= debug_information
[i
].pointer_size
;
3348 cu_offset
= debug_information
[i
].cu_offset
;
3349 offset_size
= debug_information
[i
].offset_size
;
3350 dwarf_version
= debug_information
[i
].dwarf_version
;
3352 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3354 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3355 /* DWARF sections under Mach-O have non-zero addresses. */
3356 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3357 next
= section_begin
+ offset
;
3358 base_address
= debug_information
[i
].base_address
;
3360 if (!seen_first_offset
)
3361 seen_first_offset
= 1;
3365 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3366 (unsigned long) (start
- section_begin
),
3367 (unsigned long) (next
- section_begin
));
3368 else if (start
> next
)
3369 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3370 (unsigned long) (start
- section_begin
),
3371 (unsigned long) (next
- section_begin
));
3375 if (offset
>= bytes
)
3377 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3384 if (start
+ 2 * pointer_size
> section_end
)
3386 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3391 /* Note: we use sign extension here in order to be sure that
3392 we can detect the -1 escape value. Sign extension into the
3393 top 32 bits of a 32-bit address will not affect the values
3394 that we display since we always show hex values, and always
3395 the bottom 32-bits. */
3396 begin
= byte_get_signed (start
, pointer_size
);
3397 start
+= pointer_size
;
3398 end
= byte_get_signed (start
, pointer_size
);
3399 start
+= pointer_size
;
3401 printf (" %8.8lx ", offset
);
3403 if (begin
== 0 && end
== 0)
3405 printf (_("<End of list>\n"));
3409 /* Check base address specifiers. */
3410 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3413 print_dwarf_vma (begin
, pointer_size
);
3414 print_dwarf_vma (end
, pointer_size
);
3415 printf (_("(base address)\n"));
3419 if (start
+ 2 > section_end
)
3421 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3426 length
= byte_get (start
, 2);
3429 if (start
+ length
> section_end
)
3431 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3436 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3437 print_dwarf_vma (end
+ base_address
, pointer_size
);
3440 need_frame_base
= decode_location_expression (start
,
3445 cu_offset
, section
);
3448 if (need_frame_base
&& !has_frame_base
)
3449 printf (_(" [without DW_AT_frame_base]"));
3452 fputs (_(" (start == end)"), stdout
);
3453 else if (begin
> end
)
3454 fputs (_(" (start > end)"), stdout
);
3463 if (start
< section_end
)
3464 warn (_("There are %ld unused bytes at the end of section %s\n"),
3465 (long) (section_end
- start
), section
->name
);
3471 display_debug_str (struct dwarf_section
*section
,
3472 void *file ATTRIBUTE_UNUSED
)
3474 unsigned char *start
= section
->start
;
3475 unsigned long bytes
= section
->size
;
3476 dwarf_vma addr
= section
->address
;
3480 printf (_("\nThe %s section is empty.\n"), section
->name
);
3484 printf (_("Contents of the %s section:\n\n"), section
->name
);
3492 lbytes
= (bytes
> 16 ? 16 : bytes
);
3494 printf (" 0x%8.8lx ", (unsigned long) addr
);
3496 for (j
= 0; j
< 16; j
++)
3499 printf ("%2.2x", start
[j
]);
3507 for (j
= 0; j
< lbytes
; j
++)
3510 if (k
>= ' ' && k
< 0x80)
3529 display_debug_info (struct dwarf_section
*section
, void *file
)
3531 return process_debug_info (section
, file
, abbrev
, 0, 0);
3535 display_debug_types (struct dwarf_section
*section
, void *file
)
3537 return process_debug_info (section
, file
, abbrev
, 0, 1);
3541 display_trace_info (struct dwarf_section
*section
, void *file
)
3543 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
3547 display_debug_aranges (struct dwarf_section
*section
,
3548 void *file ATTRIBUTE_UNUSED
)
3550 unsigned char *start
= section
->start
;
3551 unsigned char *end
= start
+ section
->size
;
3553 printf (_("Contents of the %s section:\n\n"), section
->name
);
3555 /* It does not matter if this load fails,
3556 we test for that later on. */
3557 load_debug_info (file
);
3561 unsigned char *hdrptr
;
3562 DWARF2_Internal_ARange arange
;
3563 unsigned char *addr_ranges
;
3566 unsigned char address_size
;
3569 int initial_length_size
;
3573 arange
.ar_length
= byte_get (hdrptr
, 4);
3576 if (arange
.ar_length
== 0xffffffff)
3578 arange
.ar_length
= byte_get (hdrptr
, 8);
3581 initial_length_size
= 12;
3586 initial_length_size
= 4;
3589 arange
.ar_version
= byte_get (hdrptr
, 2);
3592 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3593 hdrptr
+= offset_size
;
3595 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3596 && num_debug_info_entries
> 0
3597 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3598 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3599 arange
.ar_info_offset
, section
->name
);
3601 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3604 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3607 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3609 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3613 printf (_(" Length: %ld\n"), arange
.ar_length
);
3614 printf (_(" Version: %d\n"), arange
.ar_version
);
3615 printf (_(" Offset into .debug_info: 0x%lx\n"), arange
.ar_info_offset
);
3616 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3617 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3619 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3621 /* The DWARF spec does not require that the address size be a power
3622 of two, but we do. This will have to change if we ever encounter
3623 an uneven architecture. */
3624 if ((address_size
& (address_size
- 1)) != 0)
3626 warn (_("Pointer size + Segment size is not a power of two.\n"));
3630 if (address_size
> 4)
3631 printf (_("\n Address Length\n"));
3633 printf (_("\n Address Length\n"));
3635 addr_ranges
= hdrptr
;
3637 /* Must pad to an alignment boundary that is twice the address size. */
3638 excess
= (hdrptr
- start
) % (2 * address_size
);
3640 addr_ranges
+= (2 * address_size
) - excess
;
3642 start
+= arange
.ar_length
+ initial_length_size
;
3644 while (addr_ranges
+ 2 * address_size
<= start
)
3646 address
= byte_get (addr_ranges
, address_size
);
3648 addr_ranges
+= address_size
;
3650 length
= byte_get (addr_ranges
, address_size
);
3652 addr_ranges
+= address_size
;
3655 print_dwarf_vma (address
, address_size
);
3656 print_dwarf_vma (length
, address_size
);
3666 /* Each debug_information[x].range_lists[y] gets this representation for
3667 sorting purposes. */
3671 /* The debug_information[x].range_lists[y] value. */
3672 unsigned long ranges_offset
;
3674 /* Original debug_information to find parameters of the data. */
3675 debug_info
*debug_info_p
;
3678 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3681 range_entry_compar (const void *ap
, const void *bp
)
3683 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
3684 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
3685 const unsigned long a
= a_re
->ranges_offset
;
3686 const unsigned long b
= b_re
->ranges_offset
;
3688 return (a
> b
) - (b
> a
);
3692 display_debug_ranges (struct dwarf_section
*section
,
3693 void *file ATTRIBUTE_UNUSED
)
3695 unsigned char *start
= section
->start
;
3696 unsigned long bytes
;
3697 unsigned char *section_begin
= start
;
3698 unsigned int num_range_list
, i
;
3699 struct range_entry
*range_entries
, *range_entry_fill
;
3701 bytes
= section
->size
;
3705 printf (_("\nThe %s section is empty.\n"), section
->name
);
3709 if (load_debug_info (file
) == 0)
3711 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3717 for (i
= 0; i
< num_debug_info_entries
; i
++)
3718 num_range_list
+= debug_information
[i
].num_range_lists
;
3720 if (num_range_list
== 0)
3721 error (_("No range lists in .debug_info section!\n"));
3723 range_entries
= (struct range_entry
*)
3724 xmalloc (sizeof (*range_entries
) * num_range_list
);
3725 range_entry_fill
= range_entries
;
3727 for (i
= 0; i
< num_debug_info_entries
; i
++)
3729 debug_info
*debug_info_p
= &debug_information
[i
];
3732 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
3734 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
3735 range_entry_fill
->debug_info_p
= debug_info_p
;
3740 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
3741 range_entry_compar
);
3743 /* DWARF sections under Mach-O have non-zero addresses. */
3744 if (range_entries
[0].ranges_offset
!= section
->address
)
3745 warn (_("Range lists in %s section start at 0x%lx\n"),
3746 section
->name
, range_entries
[0].ranges_offset
);
3748 printf (_("Contents of the %s section:\n\n"), section
->name
);
3749 printf (_(" Offset Begin End\n"));
3751 for (i
= 0; i
< num_range_list
; i
++)
3753 struct range_entry
*range_entry
= &range_entries
[i
];
3754 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
3755 unsigned int pointer_size
;
3756 unsigned long offset
;
3757 unsigned char *next
;
3758 unsigned long base_address
;
3760 pointer_size
= debug_info_p
->pointer_size
;
3762 /* DWARF sections under Mach-O have non-zero addresses. */
3763 offset
= range_entry
->ranges_offset
- section
->address
;
3764 next
= section_begin
+ offset
;
3765 base_address
= debug_info_p
->base_address
;
3770 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3771 (unsigned long) (start
- section_begin
),
3772 (unsigned long) (next
- section_begin
), section
->name
);
3773 else if (start
> next
)
3774 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3775 (unsigned long) (start
- section_begin
),
3776 (unsigned long) (next
- section_begin
), section
->name
);
3785 /* Note: we use sign extension here in order to be sure that
3786 we can detect the -1 escape value. Sign extension into the
3787 top 32 bits of a 32-bit address will not affect the values
3788 that we display since we always show hex values, and always
3789 the bottom 32-bits. */
3790 begin
= byte_get_signed (start
, pointer_size
);
3791 start
+= pointer_size
;
3792 end
= byte_get_signed (start
, pointer_size
);
3793 start
+= pointer_size
;
3795 printf (" %8.8lx ", offset
);
3797 if (begin
== 0 && end
== 0)
3799 printf (_("<End of list>\n"));
3803 /* Check base address specifiers. */
3804 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3807 print_dwarf_vma (begin
, pointer_size
);
3808 print_dwarf_vma (end
, pointer_size
);
3809 printf ("(base address)\n");
3813 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3814 print_dwarf_vma (end
+ base_address
, pointer_size
);
3817 fputs (_("(start == end)"), stdout
);
3818 else if (begin
> end
)
3819 fputs (_("(start > end)"), stdout
);
3826 free (range_entries
);
3831 typedef struct Frame_Chunk
3833 struct Frame_Chunk
*next
;
3834 unsigned char *chunk_start
;
3836 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3837 short int *col_type
;
3840 unsigned int code_factor
;
3842 unsigned long pc_begin
;
3843 unsigned long pc_range
;
3847 unsigned char fde_encoding
;
3848 unsigned char cfa_exp
;
3849 unsigned char ptr_size
;
3850 unsigned char segment_size
;
3854 static const char *const *dwarf_regnames
;
3855 static unsigned int dwarf_regnames_count
;
3857 /* A marker for a col_type that means this column was never referenced
3858 in the frame info. */
3859 #define DW_CFA_unreferenced (-1)
3861 /* Return 0 if not more space is needed, 1 if more space is needed,
3862 -1 for invalid reg. */
3865 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
3867 int prev
= fc
->ncols
;
3869 if (reg
< (unsigned int) fc
->ncols
)
3872 if (dwarf_regnames_count
3873 && reg
> dwarf_regnames_count
)
3876 fc
->ncols
= reg
+ 1;
3877 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
3878 sizeof (short int));
3879 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3881 while (prev
< fc
->ncols
)
3883 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3884 fc
->col_offset
[prev
] = 0;
3890 static const char *const dwarf_regnames_i386
[] =
3892 "eax", "ecx", "edx", "ebx",
3893 "esp", "ebp", "esi", "edi",
3894 "eip", "eflags", NULL
,
3895 "st0", "st1", "st2", "st3",
3896 "st4", "st5", "st6", "st7",
3898 "xmm0", "xmm1", "xmm2", "xmm3",
3899 "xmm4", "xmm5", "xmm6", "xmm7",
3900 "mm0", "mm1", "mm2", "mm3",
3901 "mm4", "mm5", "mm6", "mm7",
3902 "fcw", "fsw", "mxcsr",
3903 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3908 init_dwarf_regnames_i386 (void)
3910 dwarf_regnames
= dwarf_regnames_i386
;
3911 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3914 static const char *const dwarf_regnames_x86_64
[] =
3916 "rax", "rdx", "rcx", "rbx",
3917 "rsi", "rdi", "rbp", "rsp",
3918 "r8", "r9", "r10", "r11",
3919 "r12", "r13", "r14", "r15",
3921 "xmm0", "xmm1", "xmm2", "xmm3",
3922 "xmm4", "xmm5", "xmm6", "xmm7",
3923 "xmm8", "xmm9", "xmm10", "xmm11",
3924 "xmm12", "xmm13", "xmm14", "xmm15",
3925 "st0", "st1", "st2", "st3",
3926 "st4", "st5", "st6", "st7",
3927 "mm0", "mm1", "mm2", "mm3",
3928 "mm4", "mm5", "mm6", "mm7",
3930 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3931 "fs.base", "gs.base", NULL
, NULL
,
3933 "mxcsr", "fcw", "fsw"
3937 init_dwarf_regnames_x86_64 (void)
3939 dwarf_regnames
= dwarf_regnames_x86_64
;
3940 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
3944 init_dwarf_regnames (unsigned int e_machine
)
3950 init_dwarf_regnames_i386 ();
3955 init_dwarf_regnames_x86_64 ();
3964 regname (unsigned int regno
, int row
)
3966 static char reg
[64];
3968 && regno
< dwarf_regnames_count
3969 && dwarf_regnames
[regno
] != NULL
)
3972 return dwarf_regnames
[regno
];
3973 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
3974 dwarf_regnames
[regno
]);
3977 snprintf (reg
, sizeof (reg
), "r%d", regno
);
3982 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
3987 if (*max_regs
< fc
->ncols
)
3988 *max_regs
= fc
->ncols
;
3990 if (*need_col_headers
)
3992 static const char *sloc
= " LOC";
3994 *need_col_headers
= 0;
3996 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
3998 for (r
= 0; r
< *max_regs
; r
++)
3999 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4004 printf ("%-5s ", regname (r
, 1));
4010 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4012 strcpy (tmp
, "exp");
4014 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4015 printf ("%-8s ", tmp
);
4017 for (r
= 0; r
< fc
->ncols
; r
++)
4019 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4021 switch (fc
->col_type
[r
])
4023 case DW_CFA_undefined
:
4026 case DW_CFA_same_value
:
4030 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4032 case DW_CFA_val_offset
:
4033 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4035 case DW_CFA_register
:
4036 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4038 case DW_CFA_expression
:
4039 strcpy (tmp
, "exp");
4041 case DW_CFA_val_expression
:
4042 strcpy (tmp
, "vexp");
4045 strcpy (tmp
, "n/a");
4048 printf ("%-5s ", tmp
);
4054 #define GET(N) byte_get (start, N); start += N
4055 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4056 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
4059 display_debug_frames (struct dwarf_section
*section
,
4060 void *file ATTRIBUTE_UNUSED
)
4062 unsigned char *start
= section
->start
;
4063 unsigned char *end
= start
+ section
->size
;
4064 unsigned char *section_start
= start
;
4065 Frame_Chunk
*chunks
= 0;
4066 Frame_Chunk
*remembered_state
= 0;
4068 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4069 unsigned int length_return
;
4071 const char *bad_reg
= _("bad register: ");
4072 int saved_eh_addr_size
= eh_addr_size
;
4074 printf (_("Contents of the %s section:\n"), section
->name
);
4078 unsigned char *saved_start
;
4079 unsigned char *block_end
;
4080 unsigned long length
;
4081 unsigned long cie_id
;
4084 int need_col_headers
= 1;
4085 unsigned char *augmentation_data
= NULL
;
4086 unsigned long augmentation_data_len
= 0;
4087 int encoded_ptr_size
= saved_eh_addr_size
;
4089 int initial_length_size
;
4091 saved_start
= start
;
4092 length
= byte_get (start
, 4); start
+= 4;
4096 printf ("\n%08lx ZERO terminator\n\n",
4097 (unsigned long)(saved_start
- section_start
));
4101 if (length
== 0xffffffff)
4103 length
= byte_get (start
, 8);
4106 initial_length_size
= 12;
4111 initial_length_size
= 4;
4114 block_end
= saved_start
+ length
+ initial_length_size
;
4115 if (block_end
> end
)
4117 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4118 length
, (unsigned long)(saved_start
- section_start
));
4121 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4123 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4127 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4128 memset (fc
, 0, sizeof (Frame_Chunk
));
4132 fc
->chunk_start
= saved_start
;
4134 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4135 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4136 frame_need_space (fc
, max_regs
- 1);
4140 fc
->augmentation
= (char *) start
;
4141 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4143 if (strcmp (fc
->augmentation
, "eh") == 0)
4144 start
+= eh_addr_size
;
4148 fc
->ptr_size
= GET (1);
4149 fc
->segment_size
= GET (1);
4150 eh_addr_size
= fc
->ptr_size
;
4154 fc
->ptr_size
= eh_addr_size
;
4155 fc
->segment_size
= 0;
4157 fc
->code_factor
= LEB ();
4158 fc
->data_factor
= SLEB ();
4168 if (fc
->augmentation
[0] == 'z')
4170 augmentation_data_len
= LEB ();
4171 augmentation_data
= start
;
4172 start
+= augmentation_data_len
;
4176 if (do_debug_frames_interp
)
4177 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4178 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4179 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4183 printf ("\n%08lx %08lx %08lx CIE\n",
4184 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4185 printf (" Version: %d\n", version
);
4186 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4189 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4190 printf (" Segment Size: %u\n", fc
->segment_size
);
4192 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4193 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4194 printf (" Return address column: %d\n", fc
->ra
);
4196 if (augmentation_data_len
)
4199 printf (" Augmentation data: ");
4200 for (i
= 0; i
< augmentation_data_len
; ++i
)
4201 printf (" %02x", augmentation_data
[i
]);
4207 if (augmentation_data_len
)
4209 unsigned char *p
, *q
;
4210 p
= (unsigned char *) fc
->augmentation
+ 1;
4211 q
= augmentation_data
;
4218 q
+= 1 + size_of_encoded_value (*q
);
4220 fc
->fde_encoding
= *q
++;
4228 if (fc
->fde_encoding
)
4229 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4232 frame_need_space (fc
, fc
->ra
);
4236 unsigned char *look_for
;
4237 static Frame_Chunk fde_fc
;
4238 unsigned long segment_selector
;
4241 memset (fc
, 0, sizeof (Frame_Chunk
));
4243 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4245 for (cie
= chunks
; cie
; cie
= cie
->next
)
4246 if (cie
->chunk_start
== look_for
)
4251 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4252 cie_id
, (unsigned long)(saved_start
- section_start
));
4254 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4255 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4256 frame_need_space (fc
, max_regs
- 1);
4258 fc
->augmentation
= "";
4259 fc
->fde_encoding
= 0;
4260 fc
->ptr_size
= eh_addr_size
;
4261 fc
->segment_size
= 0;
4265 fc
->ncols
= cie
->ncols
;
4266 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4267 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4268 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4269 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4270 fc
->augmentation
= cie
->augmentation
;
4271 fc
->ptr_size
= cie
->ptr_size
;
4272 eh_addr_size
= cie
->ptr_size
;
4273 fc
->segment_size
= cie
->segment_size
;
4274 fc
->code_factor
= cie
->code_factor
;
4275 fc
->data_factor
= cie
->data_factor
;
4276 fc
->cfa_reg
= cie
->cfa_reg
;
4277 fc
->cfa_offset
= cie
->cfa_offset
;
4279 frame_need_space (fc
, max_regs
- 1);
4280 fc
->fde_encoding
= cie
->fde_encoding
;
4283 if (fc
->fde_encoding
)
4284 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4286 segment_selector
= 0;
4287 if (fc
->segment_size
)
4289 segment_selector
= byte_get (start
, fc
->segment_size
);
4290 start
+= fc
->segment_size
;
4292 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4293 start
+= encoded_ptr_size
;
4294 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4295 start
+= encoded_ptr_size
;
4297 if (cie
->augmentation
[0] == 'z')
4299 augmentation_data_len
= LEB ();
4300 augmentation_data
= start
;
4301 start
+= augmentation_data_len
;
4304 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4305 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4306 (unsigned long)(cie
->chunk_start
- section_start
));
4307 if (fc
->segment_size
)
4308 printf ("%04lx:", segment_selector
);
4309 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4310 if (! do_debug_frames_interp
&& augmentation_data_len
)
4314 printf (" Augmentation data: ");
4315 for (i
= 0; i
< augmentation_data_len
; ++i
)
4316 printf (" %02x", augmentation_data
[i
]);
4322 /* At this point, fc is the current chunk, cie (if any) is set, and
4323 we're about to interpret instructions for the chunk. */
4324 /* ??? At present we need to do this always, since this sizes the
4325 fc->col_type and fc->col_offset arrays, which we write into always.
4326 We should probably split the interpreted and non-interpreted bits
4327 into two different routines, since there's so much that doesn't
4328 really overlap between them. */
4329 if (1 || do_debug_frames_interp
)
4331 /* Start by making a pass over the chunk, allocating storage
4332 and taking note of what registers are used. */
4333 unsigned char *tmp
= start
;
4335 while (start
< block_end
)
4338 unsigned long reg
, temp
;
4345 /* Warning: if you add any more cases to this switch, be
4346 sure to add them to the corresponding switch below. */
4349 case DW_CFA_advance_loc
:
4353 if (frame_need_space (fc
, opa
) >= 0)
4354 fc
->col_type
[opa
] = DW_CFA_undefined
;
4356 case DW_CFA_restore
:
4357 if (frame_need_space (fc
, opa
) >= 0)
4358 fc
->col_type
[opa
] = DW_CFA_undefined
;
4360 case DW_CFA_set_loc
:
4361 start
+= encoded_ptr_size
;
4363 case DW_CFA_advance_loc1
:
4366 case DW_CFA_advance_loc2
:
4369 case DW_CFA_advance_loc4
:
4372 case DW_CFA_offset_extended
:
4373 case DW_CFA_val_offset
:
4374 reg
= LEB (); LEB ();
4375 if (frame_need_space (fc
, reg
) >= 0)
4376 fc
->col_type
[reg
] = DW_CFA_undefined
;
4378 case DW_CFA_restore_extended
:
4380 frame_need_space (fc
, reg
);
4381 if (frame_need_space (fc
, reg
) >= 0)
4382 fc
->col_type
[reg
] = DW_CFA_undefined
;
4384 case DW_CFA_undefined
:
4386 if (frame_need_space (fc
, reg
) >= 0)
4387 fc
->col_type
[reg
] = DW_CFA_undefined
;
4389 case DW_CFA_same_value
:
4391 if (frame_need_space (fc
, reg
) >= 0)
4392 fc
->col_type
[reg
] = DW_CFA_undefined
;
4394 case DW_CFA_register
:
4395 reg
= LEB (); LEB ();
4396 if (frame_need_space (fc
, reg
) >= 0)
4397 fc
->col_type
[reg
] = DW_CFA_undefined
;
4399 case DW_CFA_def_cfa
:
4402 case DW_CFA_def_cfa_register
:
4405 case DW_CFA_def_cfa_offset
:
4408 case DW_CFA_def_cfa_expression
:
4412 case DW_CFA_expression
:
4413 case DW_CFA_val_expression
:
4417 if (frame_need_space (fc
, reg
) >= 0)
4418 fc
->col_type
[reg
] = DW_CFA_undefined
;
4420 case DW_CFA_offset_extended_sf
:
4421 case DW_CFA_val_offset_sf
:
4422 reg
= LEB (); SLEB ();
4423 if (frame_need_space (fc
, reg
) >= 0)
4424 fc
->col_type
[reg
] = DW_CFA_undefined
;
4426 case DW_CFA_def_cfa_sf
:
4429 case DW_CFA_def_cfa_offset_sf
:
4432 case DW_CFA_MIPS_advance_loc8
:
4435 case DW_CFA_GNU_args_size
:
4438 case DW_CFA_GNU_negative_offset_extended
:
4439 reg
= LEB (); LEB ();
4440 if (frame_need_space (fc
, reg
) >= 0)
4441 fc
->col_type
[reg
] = DW_CFA_undefined
;
4450 /* Now we know what registers are used, make a second pass over
4451 the chunk, this time actually printing out the info. */
4453 while (start
< block_end
)
4456 unsigned long ul
, reg
, roffs
;
4459 const char *reg_prefix
= "";
4466 /* Warning: if you add any more cases to this switch, be
4467 sure to add them to the corresponding switch above. */
4470 case DW_CFA_advance_loc
:
4471 if (do_debug_frames_interp
)
4472 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4474 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4475 opa
* fc
->code_factor
,
4476 fc
->pc_begin
+ opa
* fc
->code_factor
);
4477 fc
->pc_begin
+= opa
* fc
->code_factor
;
4482 if (opa
>= (unsigned int) fc
->ncols
)
4483 reg_prefix
= bad_reg
;
4484 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4485 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4486 reg_prefix
, regname (opa
, 0),
4487 roffs
* fc
->data_factor
);
4488 if (*reg_prefix
== '\0')
4490 fc
->col_type
[opa
] = DW_CFA_offset
;
4491 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4495 case DW_CFA_restore
:
4496 if (opa
>= (unsigned int) cie
->ncols
4497 || opa
>= (unsigned int) fc
->ncols
)
4498 reg_prefix
= bad_reg
;
4499 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4500 printf (" DW_CFA_restore: %s%s\n",
4501 reg_prefix
, regname (opa
, 0));
4502 if (*reg_prefix
== '\0')
4504 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4505 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4509 case DW_CFA_set_loc
:
4510 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4511 start
+= encoded_ptr_size
;
4512 if (do_debug_frames_interp
)
4513 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4515 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4519 case DW_CFA_advance_loc1
:
4520 ofs
= byte_get (start
, 1); start
+= 1;
4521 if (do_debug_frames_interp
)
4522 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4524 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4525 ofs
* fc
->code_factor
,
4526 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4527 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4530 case DW_CFA_advance_loc2
:
4531 ofs
= byte_get (start
, 2); start
+= 2;
4532 if (do_debug_frames_interp
)
4533 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4535 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4536 ofs
* fc
->code_factor
,
4537 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4538 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4541 case DW_CFA_advance_loc4
:
4542 ofs
= byte_get (start
, 4); start
+= 4;
4543 if (do_debug_frames_interp
)
4544 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4546 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4547 ofs
* fc
->code_factor
,
4548 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4549 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4552 case DW_CFA_offset_extended
:
4555 if (reg
>= (unsigned int) fc
->ncols
)
4556 reg_prefix
= bad_reg
;
4557 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4558 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4559 reg_prefix
, regname (reg
, 0),
4560 roffs
* fc
->data_factor
);
4561 if (*reg_prefix
== '\0')
4563 fc
->col_type
[reg
] = DW_CFA_offset
;
4564 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4568 case DW_CFA_val_offset
:
4571 if (reg
>= (unsigned int) fc
->ncols
)
4572 reg_prefix
= bad_reg
;
4573 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4574 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4575 reg_prefix
, regname (reg
, 0),
4576 roffs
* fc
->data_factor
);
4577 if (*reg_prefix
== '\0')
4579 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4580 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4584 case DW_CFA_restore_extended
:
4586 if (reg
>= (unsigned int) cie
->ncols
4587 || reg
>= (unsigned int) fc
->ncols
)
4588 reg_prefix
= bad_reg
;
4589 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4590 printf (" DW_CFA_restore_extended: %s%s\n",
4591 reg_prefix
, regname (reg
, 0));
4592 if (*reg_prefix
== '\0')
4594 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4595 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4599 case DW_CFA_undefined
:
4601 if (reg
>= (unsigned int) fc
->ncols
)
4602 reg_prefix
= bad_reg
;
4603 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4604 printf (" DW_CFA_undefined: %s%s\n",
4605 reg_prefix
, regname (reg
, 0));
4606 if (*reg_prefix
== '\0')
4608 fc
->col_type
[reg
] = DW_CFA_undefined
;
4609 fc
->col_offset
[reg
] = 0;
4613 case DW_CFA_same_value
:
4615 if (reg
>= (unsigned int) fc
->ncols
)
4616 reg_prefix
= bad_reg
;
4617 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4618 printf (" DW_CFA_same_value: %s%s\n",
4619 reg_prefix
, regname (reg
, 0));
4620 if (*reg_prefix
== '\0')
4622 fc
->col_type
[reg
] = DW_CFA_same_value
;
4623 fc
->col_offset
[reg
] = 0;
4627 case DW_CFA_register
:
4630 if (reg
>= (unsigned int) fc
->ncols
)
4631 reg_prefix
= bad_reg
;
4632 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4634 printf (" DW_CFA_register: %s%s in ",
4635 reg_prefix
, regname (reg
, 0));
4636 puts (regname (roffs
, 0));
4638 if (*reg_prefix
== '\0')
4640 fc
->col_type
[reg
] = DW_CFA_register
;
4641 fc
->col_offset
[reg
] = roffs
;
4645 case DW_CFA_remember_state
:
4646 if (! do_debug_frames_interp
)
4647 printf (" DW_CFA_remember_state\n");
4648 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4649 rs
->ncols
= fc
->ncols
;
4650 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
4651 sizeof (short int));
4652 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
4653 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4654 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4655 rs
->next
= remembered_state
;
4656 remembered_state
= rs
;
4659 case DW_CFA_restore_state
:
4660 if (! do_debug_frames_interp
)
4661 printf (" DW_CFA_restore_state\n");
4662 rs
= remembered_state
;
4665 remembered_state
= rs
->next
;
4666 frame_need_space (fc
, rs
->ncols
- 1);
4667 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4668 memcpy (fc
->col_offset
, rs
->col_offset
,
4669 rs
->ncols
* sizeof (int));
4670 free (rs
->col_type
);
4671 free (rs
->col_offset
);
4674 else if (do_debug_frames_interp
)
4675 printf ("Mismatched DW_CFA_restore_state\n");
4678 case DW_CFA_def_cfa
:
4679 fc
->cfa_reg
= LEB ();
4680 fc
->cfa_offset
= LEB ();
4682 if (! do_debug_frames_interp
)
4683 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4684 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4687 case DW_CFA_def_cfa_register
:
4688 fc
->cfa_reg
= LEB ();
4690 if (! do_debug_frames_interp
)
4691 printf (" DW_CFA_def_cfa_register: %s\n",
4692 regname (fc
->cfa_reg
, 0));
4695 case DW_CFA_def_cfa_offset
:
4696 fc
->cfa_offset
= LEB ();
4697 if (! do_debug_frames_interp
)
4698 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4702 if (! do_debug_frames_interp
)
4703 printf (" DW_CFA_nop\n");
4706 case DW_CFA_def_cfa_expression
:
4708 if (! do_debug_frames_interp
)
4710 printf (" DW_CFA_def_cfa_expression (");
4711 decode_location_expression (start
, eh_addr_size
, 0, -1,
4719 case DW_CFA_expression
:
4722 if (reg
>= (unsigned int) fc
->ncols
)
4723 reg_prefix
= bad_reg
;
4724 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4726 printf (" DW_CFA_expression: %s%s (",
4727 reg_prefix
, regname (reg
, 0));
4728 decode_location_expression (start
, eh_addr_size
, 0, -1,
4732 if (*reg_prefix
== '\0')
4733 fc
->col_type
[reg
] = DW_CFA_expression
;
4737 case DW_CFA_val_expression
:
4740 if (reg
>= (unsigned int) fc
->ncols
)
4741 reg_prefix
= bad_reg
;
4742 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4744 printf (" DW_CFA_val_expression: %s%s (",
4745 reg_prefix
, regname (reg
, 0));
4746 decode_location_expression (start
, eh_addr_size
, 0, -1,
4750 if (*reg_prefix
== '\0')
4751 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4755 case DW_CFA_offset_extended_sf
:
4758 if (frame_need_space (fc
, reg
) < 0)
4759 reg_prefix
= bad_reg
;
4760 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4761 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4762 reg_prefix
, regname (reg
, 0),
4763 l
* fc
->data_factor
);
4764 if (*reg_prefix
== '\0')
4766 fc
->col_type
[reg
] = DW_CFA_offset
;
4767 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4771 case DW_CFA_val_offset_sf
:
4774 if (frame_need_space (fc
, reg
) < 0)
4775 reg_prefix
= bad_reg
;
4776 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4777 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4778 reg_prefix
, regname (reg
, 0),
4779 l
* fc
->data_factor
);
4780 if (*reg_prefix
== '\0')
4782 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4783 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4787 case DW_CFA_def_cfa_sf
:
4788 fc
->cfa_reg
= LEB ();
4789 fc
->cfa_offset
= SLEB ();
4790 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4792 if (! do_debug_frames_interp
)
4793 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4794 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4797 case DW_CFA_def_cfa_offset_sf
:
4798 fc
->cfa_offset
= SLEB ();
4799 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4800 if (! do_debug_frames_interp
)
4801 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4804 case DW_CFA_MIPS_advance_loc8
:
4805 ofs
= byte_get (start
, 8); start
+= 8;
4806 if (do_debug_frames_interp
)
4807 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4809 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4810 ofs
* fc
->code_factor
,
4811 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4812 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4815 case DW_CFA_GNU_window_save
:
4816 if (! do_debug_frames_interp
)
4817 printf (" DW_CFA_GNU_window_save\n");
4820 case DW_CFA_GNU_args_size
:
4822 if (! do_debug_frames_interp
)
4823 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4826 case DW_CFA_GNU_negative_offset_extended
:
4829 if (frame_need_space (fc
, reg
) < 0)
4830 reg_prefix
= bad_reg
;
4831 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4832 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4833 reg_prefix
, regname (reg
, 0),
4834 l
* fc
->data_factor
);
4835 if (*reg_prefix
== '\0')
4837 fc
->col_type
[reg
] = DW_CFA_offset
;
4838 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4843 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4844 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4846 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4851 if (do_debug_frames_interp
)
4852 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4855 eh_addr_size
= saved_eh_addr_size
;
4868 display_gdb_index (struct dwarf_section
*section
,
4869 void *file ATTRIBUTE_UNUSED
)
4871 unsigned char *start
= section
->start
;
4873 uint32_t cu_list_offset
, tu_list_offset
;
4874 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
4875 unsigned int cu_list_elements
, tu_list_elements
;
4876 unsigned int address_table_size
, symbol_table_slots
;
4877 unsigned char *cu_list
, *tu_list
;
4878 unsigned char *address_table
, *symbol_table
, *constant_pool
;
4881 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
4883 printf (_("Contents of the %s section:\n"), section
->name
);
4885 if (section
->size
< 6 * sizeof (uint32_t))
4887 warn (_("Truncated header in the %s section.\n"), section
->name
);
4891 version
= byte_get_little_endian (start
, 4);
4892 printf (_("Version %ld\n"), (long) version
);
4894 /* Prior versions are obsolete, and future versions may not be
4895 backwards compatible. */
4899 warn (_("The address table data in version 3 may be wrong.\n"));
4904 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
4908 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
4909 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
4910 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
4911 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
4912 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
4914 if (cu_list_offset
> section
->size
4915 || tu_list_offset
> section
->size
4916 || address_table_offset
> section
->size
4917 || symbol_table_offset
> section
->size
4918 || constant_pool_offset
> section
->size
)
4920 warn (_("Corrupt header in the %s section.\n"), section
->name
);
4924 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
4925 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
4926 address_table_size
= symbol_table_offset
- address_table_offset
;
4927 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
4929 cu_list
= start
+ cu_list_offset
;
4930 tu_list
= start
+ tu_list_offset
;
4931 address_table
= start
+ address_table_offset
;
4932 symbol_table
= start
+ symbol_table_offset
;
4933 constant_pool
= start
+ constant_pool_offset
;
4935 printf (_("\nCU table:\n"));
4936 for (i
= 0; i
< cu_list_elements
; i
+= 2)
4938 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
4939 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
4941 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
4942 (unsigned long) cu_offset
,
4943 (unsigned long) (cu_offset
+ cu_length
- 1));
4946 printf (_("\nTU table:\n"));
4947 for (i
= 0; i
< tu_list_elements
; i
+= 3)
4949 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
4950 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
4951 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
4953 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
4954 (unsigned long) tu_offset
,
4955 (unsigned long) type_offset
);
4956 print_dwarf_vma (signature
, 8);
4960 printf (_("\nAddress table:\n"));
4961 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
4963 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
4964 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
4965 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
4967 print_dwarf_vma (low
, 8);
4968 print_dwarf_vma (high
, 8);
4969 printf (_("%lu\n"), (unsigned long) cu_index
);
4972 printf (_("\nSymbol table:\n"));
4973 for (i
= 0; i
< symbol_table_slots
; ++i
)
4975 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
4976 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
4977 uint32_t num_cus
, cu
;
4979 if (name_offset
!= 0
4980 || cu_vector_offset
!= 0)
4984 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
4985 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
4986 for (j
= 0; j
< num_cus
; ++j
)
4988 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
4989 /* Convert to TU number if it's for a type unit. */
4990 if (cu
>= cu_list_elements
)
4991 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
));
4993 printf (" %lu", (unsigned long) cu
);
5003 display_debug_not_supported (struct dwarf_section
*section
,
5004 void *file ATTRIBUTE_UNUSED
)
5006 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5013 cmalloc (size_t nmemb
, size_t size
)
5015 /* Check for overflow. */
5016 if (nmemb
>= ~(size_t) 0 / size
)
5019 return malloc (nmemb
* size
);
5023 xcmalloc (size_t nmemb
, size_t size
)
5025 /* Check for overflow. */
5026 if (nmemb
>= ~(size_t) 0 / size
)
5029 return xmalloc (nmemb
* size
);
5033 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5035 /* Check for overflow. */
5036 if (nmemb
>= ~(size_t) 0 / size
)
5039 return xrealloc (ptr
, nmemb
* size
);
5043 free_debug_memory (void)
5049 for (i
= 0; i
< max
; i
++)
5050 free_debug_section ((enum dwarf_section_display_enum
) i
);
5052 if (debug_information
!= NULL
)
5054 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5056 for (i
= 0; i
< num_debug_info_entries
; i
++)
5058 if (!debug_information
[i
].max_loc_offsets
)
5060 free (debug_information
[i
].loc_offsets
);
5061 free (debug_information
[i
].have_frame_base
);
5063 if (!debug_information
[i
].max_range_lists
)
5064 free (debug_information
[i
].range_lists
);
5068 free (debug_information
);
5069 debug_information
= NULL
;
5070 num_debug_info_entries
= 0;
5075 dwarf_select_sections_by_names (const char *names
)
5079 const char * option
;
5083 debug_dump_long_opts
;
5085 static const debug_dump_long_opts opts_table
[] =
5087 /* Please keep this table alpha- sorted. */
5088 { "Ranges", & do_debug_ranges
, 1 },
5089 { "abbrev", & do_debug_abbrevs
, 1 },
5090 { "aranges", & do_debug_aranges
, 1 },
5091 { "frames", & do_debug_frames
, 1 },
5092 { "frames-interp", & do_debug_frames_interp
, 1 },
5093 { "info", & do_debug_info
, 1 },
5094 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5095 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5096 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5097 { "loc", & do_debug_loc
, 1 },
5098 { "macro", & do_debug_macinfo
, 1 },
5099 { "pubnames", & do_debug_pubnames
, 1 },
5100 { "pubtypes", & do_debug_pubtypes
, 1 },
5101 /* This entry is for compatability
5102 with earlier versions of readelf. */
5103 { "ranges", & do_debug_aranges
, 1 },
5104 { "str", & do_debug_str
, 1 },
5105 /* The special .gdb_index section. */
5106 { "gdb_index", & do_gdb_index
, 1 },
5107 /* These trace_* sections are used by Itanium VMS. */
5108 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5109 { "trace_aranges", & do_trace_aranges
, 1 },
5110 { "trace_info", & do_trace_info
, 1 },
5119 const debug_dump_long_opts
* entry
;
5121 for (entry
= opts_table
; entry
->option
; entry
++)
5123 size_t len
= strlen (entry
->option
);
5125 if (strncmp (p
, entry
->option
, len
) == 0
5126 && (p
[len
] == ',' || p
[len
] == '\0'))
5128 * entry
->variable
|= entry
->val
;
5130 /* The --debug-dump=frames-interp option also
5131 enables the --debug-dump=frames option. */
5132 if (do_debug_frames_interp
)
5133 do_debug_frames
= 1;
5140 if (entry
->option
== NULL
)
5142 warn (_("Unrecognized debug option '%s'\n"), p
);
5143 p
= strchr (p
, ',');
5154 dwarf_select_sections_by_letters (const char *letters
)
5156 unsigned int lindex
= 0;
5158 while (letters
[lindex
])
5159 switch (letters
[lindex
++])
5166 do_debug_abbrevs
= 1;
5170 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5174 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5178 do_debug_pubnames
= 1;
5182 do_debug_pubtypes
= 1;
5186 do_debug_aranges
= 1;
5190 do_debug_ranges
= 1;
5194 do_debug_frames_interp
= 1;
5196 do_debug_frames
= 1;
5200 do_debug_macinfo
= 1;
5212 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5218 dwarf_select_sections_all (void)
5221 do_debug_abbrevs
= 1;
5222 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5223 do_debug_pubnames
= 1;
5224 do_debug_pubtypes
= 1;
5225 do_debug_aranges
= 1;
5226 do_debug_ranges
= 1;
5227 do_debug_frames
= 1;
5228 do_debug_macinfo
= 1;
5233 do_trace_abbrevs
= 1;
5234 do_trace_aranges
= 1;
5237 struct dwarf_section_display debug_displays
[] =
5239 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5240 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5241 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5242 display_debug_aranges
, &do_debug_aranges
, 1 },
5243 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5244 display_debug_frames
, &do_debug_frames
, 1 },
5245 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5246 display_debug_info
, &do_debug_info
, 1 },
5247 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5248 display_debug_lines
, &do_debug_lines
, 1 },
5249 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5250 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5251 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5252 display_debug_frames
, &do_debug_frames
, 1 },
5253 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5254 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5255 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5256 display_debug_str
, &do_debug_str
, 0 },
5257 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5258 display_debug_loc
, &do_debug_loc
, 1 },
5259 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5260 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5261 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5262 display_debug_ranges
, &do_debug_ranges
, 1 },
5263 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5264 display_debug_not_supported
, NULL
, 0 },
5265 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5266 display_debug_not_supported
, NULL
, 0 },
5267 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5268 display_debug_types
, &do_debug_info
, 1 },
5269 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5270 display_debug_not_supported
, NULL
, 0 },
5271 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5272 display_gdb_index
, &do_gdb_index
, 0 },
5273 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5274 display_trace_info
, &do_trace_info
, 1 },
5275 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5276 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5277 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5278 display_debug_aranges
, &do_trace_aranges
, 0 }