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"
26 #include "elf/common.h"
30 static int have_frame_base
;
31 static int need_base_address
;
33 static unsigned int last_pointer_size
= 0;
34 static int warned_about_missing_comp_units
= FALSE
;
36 static unsigned int num_debug_info_entries
= 0;
37 static debug_info
*debug_information
= NULL
;
38 /* Special value for num_debug_info_entries to indicate
39 that the .debug_info section could not be loaded/parsed. */
40 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 int do_debug_pubnames
;
48 int do_debug_pubtypes
;
52 int do_debug_frames_interp
;
58 /* Values for do_debug_lines. */
59 #define FLAG_DEBUG_LINES_RAW 1
60 #define FLAG_DEBUG_LINES_DECODED 2
62 dwarf_vma (*byte_get
) (unsigned char *, int);
65 byte_get_little_endian (unsigned char *field
, int size
)
73 return ((unsigned int) (field
[0]))
74 | (((unsigned int) (field
[1])) << 8);
77 return ((unsigned long) (field
[0]))
78 | (((unsigned long) (field
[1])) << 8)
79 | (((unsigned long) (field
[2])) << 16);
82 return ((unsigned long) (field
[0]))
83 | (((unsigned long) (field
[1])) << 8)
84 | (((unsigned long) (field
[2])) << 16)
85 | (((unsigned long) (field
[3])) << 24);
88 if (sizeof (dwarf_vma
) == 8)
89 return ((dwarf_vma
) (field
[0]))
90 | (((dwarf_vma
) (field
[1])) << 8)
91 | (((dwarf_vma
) (field
[2])) << 16)
92 | (((dwarf_vma
) (field
[3])) << 24)
93 | (((dwarf_vma
) (field
[4])) << 32)
94 | (((dwarf_vma
) (field
[5])) << 40)
95 | (((dwarf_vma
) (field
[6])) << 48)
96 | (((dwarf_vma
) (field
[7])) << 56);
97 else if (sizeof (dwarf_vma
) == 4)
98 /* We want to extract data from an 8 byte wide field and
99 place it into a 4 byte wide field. Since this is a little
100 endian source we can just use the 4 byte extraction code. */
101 return ((unsigned long) (field
[0]))
102 | (((unsigned long) (field
[1])) << 8)
103 | (((unsigned long) (field
[2])) << 16)
104 | (((unsigned long) (field
[3])) << 24);
107 error (_("Unhandled data length: %d\n"), size
);
113 byte_get_big_endian (unsigned char *field
, int size
)
121 return ((unsigned int) (field
[1])) | (((int) (field
[0])) << 8);
124 return ((unsigned long) (field
[2]))
125 | (((unsigned long) (field
[1])) << 8)
126 | (((unsigned long) (field
[0])) << 16);
129 return ((unsigned long) (field
[3]))
130 | (((unsigned long) (field
[2])) << 8)
131 | (((unsigned long) (field
[1])) << 16)
132 | (((unsigned long) (field
[0])) << 24);
135 if (sizeof (dwarf_vma
) == 8)
136 return ((dwarf_vma
) (field
[7]))
137 | (((dwarf_vma
) (field
[6])) << 8)
138 | (((dwarf_vma
) (field
[5])) << 16)
139 | (((dwarf_vma
) (field
[4])) << 24)
140 | (((dwarf_vma
) (field
[3])) << 32)
141 | (((dwarf_vma
) (field
[2])) << 40)
142 | (((dwarf_vma
) (field
[1])) << 48)
143 | (((dwarf_vma
) (field
[0])) << 56);
144 else if (sizeof (dwarf_vma
) == 4)
146 /* Although we are extracing data from an 8 byte wide field,
147 we are returning only 4 bytes of data. */
149 return ((unsigned long) (field
[3]))
150 | (((unsigned long) (field
[2])) << 8)
151 | (((unsigned long) (field
[1])) << 16)
152 | (((unsigned long) (field
[0])) << 24);
156 error (_("Unhandled data length: %d\n"), size
);
162 byte_get_signed (unsigned char *field
, int size
)
164 dwarf_vma x
= byte_get (field
, size
);
169 return (x
^ 0x80) - 0x80;
171 return (x
^ 0x8000) - 0x8000;
173 return (x
^ 0x80000000) - 0x80000000;
182 size_of_encoded_value (int encoding
)
184 switch (encoding
& 0x7)
187 case 0: return eh_addr_size
;
195 get_encoded_value (unsigned char *data
, int encoding
)
197 int size
= size_of_encoded_value (encoding
);
199 if (encoding
& DW_EH_PE_signed
)
200 return byte_get_signed (data
, size
);
202 return byte_get (data
, size
);
205 /* Print a dwarf_vma value (typically an address, offset or length) in
206 hexadecimal format, followed by a space. The length of the value (and
207 hence the precision displayed) is determined by the byte_size parameter. */
210 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
212 static char buff
[18];
214 /* Printf does not have a way of specifiying a maximum field width for an
215 integer value, so we print the full value into a buffer and then select
216 the precision we need. */
217 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
219 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
221 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
224 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
227 fputs (buff
+ (byte_size
== 4 ? 8 : 0), stdout
);
231 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
233 unsigned long int result
= 0;
234 unsigned int num_read
= 0;
235 unsigned int shift
= 0;
243 result
|= ((unsigned long int) (byte
& 0x7f)) << shift
;
250 if (length_return
!= NULL
)
251 *length_return
= num_read
;
253 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
254 result
|= -1L << shift
;
259 typedef struct State_Machine_Registers
261 unsigned long address
;
267 unsigned char op_index
;
268 unsigned char end_sequence
;
269 /* This variable hold the number of the last entry seen
270 in the File Table. */
271 unsigned int last_file_entry
;
274 static SMR state_machine_regs
;
277 reset_state_machine (int is_stmt
)
279 state_machine_regs
.address
= 0;
280 state_machine_regs
.op_index
= 0;
281 state_machine_regs
.file
= 1;
282 state_machine_regs
.line
= 1;
283 state_machine_regs
.column
= 0;
284 state_machine_regs
.is_stmt
= is_stmt
;
285 state_machine_regs
.basic_block
= 0;
286 state_machine_regs
.end_sequence
= 0;
287 state_machine_regs
.last_file_entry
= 0;
290 /* Handled an extend line op.
291 Returns the number of bytes read. */
294 process_extended_line_op (unsigned char *data
, int is_stmt
)
296 unsigned char op_code
;
297 unsigned int bytes_read
;
302 len
= read_leb128 (data
, & bytes_read
, 0);
307 warn (_("badly formed extended line op encountered!\n"));
314 printf (_(" Extended opcode %d: "), op_code
);
318 case DW_LNE_end_sequence
:
319 printf (_("End of Sequence\n\n"));
320 reset_state_machine (is_stmt
);
323 case DW_LNE_set_address
:
324 adr
= byte_get (data
, len
- bytes_read
- 1);
325 printf (_("set Address to 0x%lx\n"), adr
);
326 state_machine_regs
.address
= adr
;
327 state_machine_regs
.op_index
= 0;
330 case DW_LNE_define_file
:
331 printf (_(" define new File Table entry\n"));
332 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
334 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
336 data
+= strlen ((char *) data
) + 1;
337 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
339 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
341 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
342 printf (_("%s\n\n"), name
);
345 case DW_LNE_set_discriminator
:
346 printf (_("set Discriminator to %lu\n"),
347 read_leb128 (data
, & bytes_read
, 0));
351 case DW_LNE_HP_negate_is_UV_update
:
352 printf ("DW_LNE_HP_negate_is_UV_update\n");
354 case DW_LNE_HP_push_context
:
355 printf ("DW_LNE_HP_push_context\n");
357 case DW_LNE_HP_pop_context
:
358 printf ("DW_LNE_HP_pop_context\n");
360 case DW_LNE_HP_set_file_line_column
:
361 printf ("DW_LNE_HP_set_file_line_column\n");
363 case DW_LNE_HP_set_routine_name
:
364 printf ("DW_LNE_HP_set_routine_name\n");
366 case DW_LNE_HP_set_sequence
:
367 printf ("DW_LNE_HP_set_sequence\n");
369 case DW_LNE_HP_negate_post_semantics
:
370 printf ("DW_LNE_HP_negate_post_semantics\n");
372 case DW_LNE_HP_negate_function_exit
:
373 printf ("DW_LNE_HP_negate_function_exit\n");
375 case DW_LNE_HP_negate_front_end_logical
:
376 printf ("DW_LNE_HP_negate_front_end_logical\n");
378 case DW_LNE_HP_define_proc
:
379 printf ("DW_LNE_HP_define_proc\n");
383 if (op_code
>= DW_LNE_lo_user
384 /* The test against DW_LNW_hi_user is redundant due to
385 the limited range of the unsigned char data type used
387 /*&& op_code <= DW_LNE_hi_user*/)
388 printf (_("user defined: length %d\n"), len
- bytes_read
);
390 printf (_("UNKNOWN: length %d\n"), len
- bytes_read
);
398 fetch_indirect_string (unsigned long offset
)
400 struct dwarf_section
*section
= &debug_displays
[str
].section
;
402 if (section
->start
== NULL
)
403 return _("<no .debug_str section>");
405 /* DWARF sections under Mach-O have non-zero addresses. */
406 offset
-= section
->address
;
407 if (offset
> section
->size
)
409 warn (_("DW_FORM_strp offset too big: %lx\n"), offset
);
410 return _("<offset is too big>");
413 return (const char *) section
->start
+ offset
;
416 /* FIXME: There are better and more efficient ways to handle
417 these structures. For now though, I just want something that
418 is simple to implement. */
419 typedef struct abbrev_attr
421 unsigned long attribute
;
423 struct abbrev_attr
*next
;
427 typedef struct abbrev_entry
432 struct abbrev_attr
*first_attr
;
433 struct abbrev_attr
*last_attr
;
434 struct abbrev_entry
*next
;
438 static abbrev_entry
*first_abbrev
= NULL
;
439 static abbrev_entry
*last_abbrev
= NULL
;
446 for (abbrv
= first_abbrev
; abbrv
;)
448 abbrev_entry
*next_abbrev
= abbrv
->next
;
451 for (attr
= abbrv
->first_attr
; attr
;)
453 abbrev_attr
*next_attr
= attr
->next
;
463 last_abbrev
= first_abbrev
= NULL
;
467 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
471 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
477 entry
->entry
= number
;
479 entry
->children
= children
;
480 entry
->first_attr
= NULL
;
481 entry
->last_attr
= NULL
;
484 if (first_abbrev
== NULL
)
485 first_abbrev
= entry
;
487 last_abbrev
->next
= entry
;
493 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
497 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
503 attr
->attribute
= attribute
;
507 if (last_abbrev
->first_attr
== NULL
)
508 last_abbrev
->first_attr
= attr
;
510 last_abbrev
->last_attr
->next
= attr
;
512 last_abbrev
->last_attr
= attr
;
515 /* Processes the (partial) contents of a .debug_abbrev section.
516 Returns NULL if the end of the section was encountered.
517 Returns the address after the last byte read if the end of
518 an abbreviation set was found. */
520 static unsigned char *
521 process_abbrev_section (unsigned char *start
, unsigned char *end
)
523 if (first_abbrev
!= NULL
)
528 unsigned int bytes_read
;
531 unsigned long attribute
;
534 entry
= read_leb128 (start
, & bytes_read
, 0);
537 /* A single zero is supposed to end the section according
538 to the standard. If there's more, then signal that to
541 return start
== end
? NULL
: start
;
543 tag
= read_leb128 (start
, & bytes_read
, 0);
548 add_abbrev (entry
, tag
, children
);
554 attribute
= read_leb128 (start
, & bytes_read
, 0);
557 form
= read_leb128 (start
, & bytes_read
, 0);
561 add_abbrev_attr (attribute
, form
);
563 while (attribute
!= 0);
570 get_TAG_name (unsigned long tag
)
574 case DW_TAG_padding
: return "DW_TAG_padding";
575 case DW_TAG_array_type
: return "DW_TAG_array_type";
576 case DW_TAG_class_type
: return "DW_TAG_class_type";
577 case DW_TAG_entry_point
: return "DW_TAG_entry_point";
578 case DW_TAG_enumeration_type
: return "DW_TAG_enumeration_type";
579 case DW_TAG_formal_parameter
: return "DW_TAG_formal_parameter";
580 case DW_TAG_imported_declaration
: return "DW_TAG_imported_declaration";
581 case DW_TAG_label
: return "DW_TAG_label";
582 case DW_TAG_lexical_block
: return "DW_TAG_lexical_block";
583 case DW_TAG_member
: return "DW_TAG_member";
584 case DW_TAG_pointer_type
: return "DW_TAG_pointer_type";
585 case DW_TAG_reference_type
: return "DW_TAG_reference_type";
586 case DW_TAG_compile_unit
: return "DW_TAG_compile_unit";
587 case DW_TAG_string_type
: return "DW_TAG_string_type";
588 case DW_TAG_structure_type
: return "DW_TAG_structure_type";
589 case DW_TAG_subroutine_type
: return "DW_TAG_subroutine_type";
590 case DW_TAG_typedef
: return "DW_TAG_typedef";
591 case DW_TAG_union_type
: return "DW_TAG_union_type";
592 case DW_TAG_unspecified_parameters
: return "DW_TAG_unspecified_parameters";
593 case DW_TAG_variant
: return "DW_TAG_variant";
594 case DW_TAG_common_block
: return "DW_TAG_common_block";
595 case DW_TAG_common_inclusion
: return "DW_TAG_common_inclusion";
596 case DW_TAG_inheritance
: return "DW_TAG_inheritance";
597 case DW_TAG_inlined_subroutine
: return "DW_TAG_inlined_subroutine";
598 case DW_TAG_module
: return "DW_TAG_module";
599 case DW_TAG_ptr_to_member_type
: return "DW_TAG_ptr_to_member_type";
600 case DW_TAG_set_type
: return "DW_TAG_set_type";
601 case DW_TAG_subrange_type
: return "DW_TAG_subrange_type";
602 case DW_TAG_with_stmt
: return "DW_TAG_with_stmt";
603 case DW_TAG_access_declaration
: return "DW_TAG_access_declaration";
604 case DW_TAG_base_type
: return "DW_TAG_base_type";
605 case DW_TAG_catch_block
: return "DW_TAG_catch_block";
606 case DW_TAG_const_type
: return "DW_TAG_const_type";
607 case DW_TAG_constant
: return "DW_TAG_constant";
608 case DW_TAG_enumerator
: return "DW_TAG_enumerator";
609 case DW_TAG_file_type
: return "DW_TAG_file_type";
610 case DW_TAG_friend
: return "DW_TAG_friend";
611 case DW_TAG_namelist
: return "DW_TAG_namelist";
612 case DW_TAG_namelist_item
: return "DW_TAG_namelist_item";
613 case DW_TAG_packed_type
: return "DW_TAG_packed_type";
614 case DW_TAG_subprogram
: return "DW_TAG_subprogram";
615 case DW_TAG_template_type_param
: return "DW_TAG_template_type_param";
616 case DW_TAG_template_value_param
: return "DW_TAG_template_value_param";
617 case DW_TAG_thrown_type
: return "DW_TAG_thrown_type";
618 case DW_TAG_try_block
: return "DW_TAG_try_block";
619 case DW_TAG_variant_part
: return "DW_TAG_variant_part";
620 case DW_TAG_variable
: return "DW_TAG_variable";
621 case DW_TAG_volatile_type
: return "DW_TAG_volatile_type";
622 case DW_TAG_MIPS_loop
: return "DW_TAG_MIPS_loop";
623 case DW_TAG_format_label
: return "DW_TAG_format_label";
624 case DW_TAG_function_template
: return "DW_TAG_function_template";
625 case DW_TAG_class_template
: return "DW_TAG_class_template";
626 /* DWARF 2.1 values. */
627 case DW_TAG_dwarf_procedure
: return "DW_TAG_dwarf_procedure";
628 case DW_TAG_restrict_type
: return "DW_TAG_restrict_type";
629 case DW_TAG_interface_type
: return "DW_TAG_interface_type";
630 case DW_TAG_namespace
: return "DW_TAG_namespace";
631 case DW_TAG_imported_module
: return "DW_TAG_imported_module";
632 case DW_TAG_unspecified_type
: return "DW_TAG_unspecified_type";
633 case DW_TAG_partial_unit
: return "DW_TAG_partial_unit";
634 case DW_TAG_imported_unit
: return "DW_TAG_imported_unit";
635 case DW_TAG_condition
: return "DW_TAG_condition";
636 case DW_TAG_shared_type
: return "DW_TAG_shared_type";
637 /* DWARF 4 values. */
638 case DW_TAG_type_unit
: return "DW_TAG_type_unit";
639 case DW_TAG_rvalue_reference_type
: return "DW_TAG_rvalue_reference_type";
640 case DW_TAG_template_alias
: return "DW_TAG_template_alias";
642 case DW_TAG_upc_shared_type
: return "DW_TAG_upc_shared_type";
643 case DW_TAG_upc_strict_type
: return "DW_TAG_upc_strict_type";
644 case DW_TAG_upc_relaxed_type
: return "DW_TAG_upc_relaxed_type";
647 static char buffer
[100];
649 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
656 get_FORM_name (unsigned long form
)
660 case DW_FORM_addr
: return "DW_FORM_addr";
661 case DW_FORM_block2
: return "DW_FORM_block2";
662 case DW_FORM_block4
: return "DW_FORM_block4";
663 case DW_FORM_data2
: return "DW_FORM_data2";
664 case DW_FORM_data4
: return "DW_FORM_data4";
665 case DW_FORM_data8
: return "DW_FORM_data8";
666 case DW_FORM_string
: return "DW_FORM_string";
667 case DW_FORM_block
: return "DW_FORM_block";
668 case DW_FORM_block1
: return "DW_FORM_block1";
669 case DW_FORM_data1
: return "DW_FORM_data1";
670 case DW_FORM_flag
: return "DW_FORM_flag";
671 case DW_FORM_sdata
: return "DW_FORM_sdata";
672 case DW_FORM_strp
: return "DW_FORM_strp";
673 case DW_FORM_udata
: return "DW_FORM_udata";
674 case DW_FORM_ref_addr
: return "DW_FORM_ref_addr";
675 case DW_FORM_ref1
: return "DW_FORM_ref1";
676 case DW_FORM_ref2
: return "DW_FORM_ref2";
677 case DW_FORM_ref4
: return "DW_FORM_ref4";
678 case DW_FORM_ref8
: return "DW_FORM_ref8";
679 case DW_FORM_ref_udata
: return "DW_FORM_ref_udata";
680 case DW_FORM_indirect
: return "DW_FORM_indirect";
681 /* DWARF 4 values. */
682 case DW_FORM_sec_offset
: return "DW_FORM_sec_offset";
683 case DW_FORM_exprloc
: return "DW_FORM_exprloc";
684 case DW_FORM_flag_present
: return "DW_FORM_flag_present";
685 case DW_FORM_ref_sig8
: return "DW_FORM_ref_sig8";
688 static char buffer
[100];
690 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
696 static unsigned char *
697 display_block (unsigned char *data
, unsigned long length
)
699 printf (_(" %lu byte block: "), length
);
702 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
708 decode_location_expression (unsigned char * data
,
709 unsigned int pointer_size
,
710 unsigned long length
,
711 unsigned long cu_offset
,
712 struct dwarf_section
* section
)
715 unsigned int bytes_read
;
716 unsigned long uvalue
;
717 unsigned char *end
= data
+ length
;
718 int need_frame_base
= 0;
727 printf ("DW_OP_addr: %lx",
728 (unsigned long) byte_get (data
, pointer_size
));
729 data
+= pointer_size
;
732 printf ("DW_OP_deref");
735 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
738 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
741 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
745 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
749 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
753 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
757 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
758 (unsigned long) byte_get (data
+ 4, 4));
762 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
763 (long) byte_get (data
+ 4, 4));
767 printf ("DW_OP_constu: %lu", read_leb128 (data
, &bytes_read
, 0));
771 printf ("DW_OP_consts: %ld", read_leb128 (data
, &bytes_read
, 1));
775 printf ("DW_OP_dup");
778 printf ("DW_OP_drop");
781 printf ("DW_OP_over");
784 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
787 printf ("DW_OP_swap");
790 printf ("DW_OP_rot");
793 printf ("DW_OP_xderef");
796 printf ("DW_OP_abs");
799 printf ("DW_OP_and");
802 printf ("DW_OP_div");
805 printf ("DW_OP_minus");
808 printf ("DW_OP_mod");
811 printf ("DW_OP_mul");
814 printf ("DW_OP_neg");
817 printf ("DW_OP_not");
823 printf ("DW_OP_plus");
825 case DW_OP_plus_uconst
:
826 printf ("DW_OP_plus_uconst: %lu",
827 read_leb128 (data
, &bytes_read
, 0));
831 printf ("DW_OP_shl");
834 printf ("DW_OP_shr");
837 printf ("DW_OP_shra");
840 printf ("DW_OP_xor");
843 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
865 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
901 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
936 printf ("DW_OP_reg%d", op
- DW_OP_reg0
);
971 printf ("DW_OP_breg%d: %ld", op
- DW_OP_breg0
,
972 read_leb128 (data
, &bytes_read
, 1));
977 printf ("DW_OP_regx: %lu", read_leb128 (data
, &bytes_read
, 0));
982 printf ("DW_OP_fbreg: %ld", read_leb128 (data
, &bytes_read
, 1));
986 uvalue
= read_leb128 (data
, &bytes_read
, 0);
988 printf ("DW_OP_bregx: %lu %ld", uvalue
,
989 read_leb128 (data
, &bytes_read
, 1));
993 printf ("DW_OP_piece: %lu", read_leb128 (data
, &bytes_read
, 0));
996 case DW_OP_deref_size
:
997 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
999 case DW_OP_xderef_size
:
1000 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
1003 printf ("DW_OP_nop");
1006 /* DWARF 3 extensions. */
1007 case DW_OP_push_object_address
:
1008 printf ("DW_OP_push_object_address");
1011 /* XXX: Strictly speaking for 64-bit DWARF3 files
1012 this ought to be an 8-byte wide computation. */
1013 printf ("DW_OP_call2: <%lx>", (long) byte_get (data
, 2) + cu_offset
);
1017 /* XXX: Strictly speaking for 64-bit DWARF3 files
1018 this ought to be an 8-byte wide computation. */
1019 printf ("DW_OP_call4: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
1022 case DW_OP_call_ref
:
1023 /* XXX: Strictly speaking for 64-bit DWARF3 files
1024 this ought to be an 8-byte wide computation. */
1025 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data
, 4) + cu_offset
);
1028 case DW_OP_form_tls_address
:
1029 printf ("DW_OP_form_tls_address");
1031 case DW_OP_call_frame_cfa
:
1032 printf ("DW_OP_call_frame_cfa");
1034 case DW_OP_bit_piece
:
1035 printf ("DW_OP_bit_piece: ");
1036 printf ("size: %lu ", read_leb128 (data
, &bytes_read
, 0));
1038 printf ("offset: %lu ", read_leb128 (data
, &bytes_read
, 0));
1042 /* DWARF 4 extensions. */
1043 case DW_OP_stack_value
:
1044 printf ("DW_OP_stack_value");
1047 case DW_OP_implicit_value
:
1048 printf ("DW_OP_implicit_value");
1049 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1051 display_block (data
, uvalue
);
1055 /* GNU extensions. */
1056 case DW_OP_GNU_push_tls_address
:
1057 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1059 case DW_OP_GNU_uninit
:
1060 printf ("DW_OP_GNU_uninit");
1061 /* FIXME: Is there data associated with this OP ? */
1063 case DW_OP_GNU_encoded_addr
:
1069 addr
= get_encoded_value (data
, encoding
);
1070 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
1071 addr
+= section
->address
+ (data
- section
->start
);
1072 data
+= size_of_encoded_value (encoding
);
1074 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1075 print_dwarf_vma (addr
, pointer_size
);
1079 /* HP extensions. */
1080 case DW_OP_HP_is_value
:
1081 printf ("DW_OP_HP_is_value");
1082 /* FIXME: Is there data associated with this OP ? */
1084 case DW_OP_HP_fltconst4
:
1085 printf ("DW_OP_HP_fltconst4");
1086 /* FIXME: Is there data associated with this OP ? */
1088 case DW_OP_HP_fltconst8
:
1089 printf ("DW_OP_HP_fltconst8");
1090 /* FIXME: Is there data associated with this OP ? */
1092 case DW_OP_HP_mod_range
:
1093 printf ("DW_OP_HP_mod_range");
1094 /* FIXME: Is there data associated with this OP ? */
1096 case DW_OP_HP_unmod_range
:
1097 printf ("DW_OP_HP_unmod_range");
1098 /* FIXME: Is there data associated with this OP ? */
1101 printf ("DW_OP_HP_tls");
1102 /* FIXME: Is there data associated with this OP ? */
1105 /* PGI (STMicroelectronics) extensions. */
1106 case DW_OP_PGI_omp_thread_num
:
1107 /* Pushes the thread number for the current thread as it would be
1108 returned by the standard OpenMP library function:
1109 omp_get_thread_num(). The "current thread" is the thread for
1110 which the expression is being evaluated. */
1111 printf ("DW_OP_PGI_omp_thread_num");
1115 if (op
>= DW_OP_lo_user
1116 && op
<= DW_OP_hi_user
)
1117 printf (_("(User defined location op)"));
1119 printf (_("(Unknown location op)"));
1120 /* No way to tell where the next op is, so just bail. */
1121 return need_frame_base
;
1124 /* Separate the ops. */
1129 return need_frame_base
;
1132 static unsigned char *
1133 read_and_display_attr_value (unsigned long attribute
,
1135 unsigned char * data
,
1136 unsigned long cu_offset
,
1137 unsigned long pointer_size
,
1138 unsigned long offset_size
,
1140 debug_info
* debug_info_p
,
1142 struct dwarf_section
* section
)
1144 unsigned long uvalue
= 0;
1145 unsigned char *block_start
= NULL
;
1146 unsigned char * orig_data
= data
;
1147 unsigned int bytes_read
;
1154 case DW_FORM_ref_addr
:
1155 if (dwarf_version
== 2)
1157 uvalue
= byte_get (data
, pointer_size
);
1158 data
+= pointer_size
;
1160 else if (dwarf_version
== 3 || dwarf_version
== 4)
1162 uvalue
= byte_get (data
, offset_size
);
1163 data
+= offset_size
;
1167 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1172 uvalue
= byte_get (data
, pointer_size
);
1173 data
+= pointer_size
;
1177 case DW_FORM_sec_offset
:
1178 uvalue
= byte_get (data
, offset_size
);
1179 data
+= offset_size
;
1182 case DW_FORM_flag_present
:
1189 uvalue
= byte_get (data
++, 1);
1194 uvalue
= byte_get (data
, 2);
1200 uvalue
= byte_get (data
, 4);
1205 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1209 case DW_FORM_ref_udata
:
1211 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1215 case DW_FORM_indirect
:
1216 form
= read_leb128 (data
, & bytes_read
, 0);
1219 printf (" %s", get_FORM_name (form
));
1220 return read_and_display_attr_value (attribute
, form
, data
,
1221 cu_offset
, pointer_size
,
1222 offset_size
, dwarf_version
,
1223 debug_info_p
, do_loc
,
1229 case DW_FORM_ref_addr
:
1231 printf (" <0x%lx>", uvalue
);
1237 case DW_FORM_ref_udata
:
1239 printf (" <0x%lx>", uvalue
+ cu_offset
);
1244 case DW_FORM_sec_offset
:
1246 printf (" 0x%lx", uvalue
);
1249 case DW_FORM_flag_present
:
1256 printf (" %ld", uvalue
);
1263 uvalue
= byte_get (data
, 4);
1264 printf (" 0x%lx", uvalue
);
1265 printf (" 0x%lx", (unsigned long) byte_get (data
+ 4, 4));
1267 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1268 && num_debug_info_entries
== 0)
1270 if (sizeof (uvalue
) == 8)
1271 uvalue
= byte_get (data
, 8);
1273 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1278 case DW_FORM_string
:
1280 printf (" %s", data
);
1281 data
+= strlen ((char *) data
) + 1;
1285 case DW_FORM_exprloc
:
1286 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1287 block_start
= data
+ bytes_read
;
1289 data
= block_start
+ uvalue
;
1291 data
= display_block (block_start
, uvalue
);
1294 case DW_FORM_block1
:
1295 uvalue
= byte_get (data
, 1);
1296 block_start
= data
+ 1;
1298 data
= block_start
+ uvalue
;
1300 data
= display_block (block_start
, uvalue
);
1303 case DW_FORM_block2
:
1304 uvalue
= byte_get (data
, 2);
1305 block_start
= data
+ 2;
1307 data
= block_start
+ uvalue
;
1309 data
= display_block (block_start
, uvalue
);
1312 case DW_FORM_block4
:
1313 uvalue
= byte_get (data
, 4);
1314 block_start
= data
+ 4;
1316 data
= block_start
+ uvalue
;
1318 data
= display_block (block_start
, uvalue
);
1323 printf (_(" (indirect string, offset: 0x%lx): %s"),
1324 uvalue
, fetch_indirect_string (uvalue
));
1327 case DW_FORM_indirect
:
1328 /* Handled above. */
1331 case DW_FORM_ref_sig8
:
1335 printf (" signature: ");
1336 for (i
= 0; i
< 8; i
++)
1338 printf ("%02x", (unsigned) byte_get (data
, 1));
1347 warn (_("Unrecognized form: %lu\n"), form
);
1351 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1352 && num_debug_info_entries
== 0)
1356 case DW_AT_frame_base
:
1357 have_frame_base
= 1;
1358 case DW_AT_location
:
1359 case DW_AT_string_length
:
1360 case DW_AT_return_addr
:
1361 case DW_AT_data_member_location
:
1362 case DW_AT_vtable_elem_location
:
1364 case DW_AT_static_link
:
1365 case DW_AT_use_location
:
1366 if (form
== DW_FORM_data4
1367 || form
== DW_FORM_data8
1368 || form
== DW_FORM_sec_offset
)
1370 /* Process location list. */
1371 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1372 unsigned int num
= debug_info_p
->num_loc_offsets
;
1374 if (lmax
== 0 || num
>= lmax
)
1377 debug_info_p
->loc_offsets
= (long unsigned int *)
1378 xcrealloc (debug_info_p
->loc_offsets
,
1379 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1380 debug_info_p
->have_frame_base
= (int *)
1381 xcrealloc (debug_info_p
->have_frame_base
,
1382 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1383 debug_info_p
->max_loc_offsets
= lmax
;
1385 debug_info_p
->loc_offsets
[num
] = uvalue
;
1386 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1387 debug_info_p
->num_loc_offsets
++;
1392 if (need_base_address
)
1393 debug_info_p
->base_address
= uvalue
;
1397 if (form
== DW_FORM_data4
1398 || form
== DW_FORM_data8
1399 || form
== DW_FORM_sec_offset
)
1401 /* Process range list. */
1402 unsigned int lmax
= debug_info_p
->max_range_lists
;
1403 unsigned int num
= debug_info_p
->num_range_lists
;
1405 if (lmax
== 0 || num
>= lmax
)
1408 debug_info_p
->range_lists
= (long unsigned int *)
1409 xcrealloc (debug_info_p
->range_lists
,
1410 lmax
, sizeof (*debug_info_p
->range_lists
));
1411 debug_info_p
->max_range_lists
= lmax
;
1413 debug_info_p
->range_lists
[num
] = uvalue
;
1414 debug_info_p
->num_range_lists
++;
1426 /* For some attributes we can display further information. */
1434 case DW_INL_not_inlined
:
1435 printf (_("(not inlined)"));
1437 case DW_INL_inlined
:
1438 printf (_("(inlined)"));
1440 case DW_INL_declared_not_inlined
:
1441 printf (_("(declared as inline but ignored)"));
1443 case DW_INL_declared_inlined
:
1444 printf (_("(declared as inline and inlined)"));
1447 printf (_(" (Unknown inline attribute value: %lx)"), uvalue
);
1452 case DW_AT_language
:
1455 /* Ordered by the numeric value of these constants. */
1456 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1457 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1458 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1459 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1460 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1461 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1462 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1463 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1464 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1465 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1466 /* DWARF 2.1 values. */
1467 case DW_LANG_Java
: printf ("(Java)"); break;
1468 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1469 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1470 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1471 /* DWARF 3 values. */
1472 case DW_LANG_PLI
: printf ("(PLI)"); break;
1473 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1474 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1475 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1476 case DW_LANG_D
: printf ("(D)"); break;
1477 /* DWARF 4 values. */
1478 case DW_LANG_Python
: printf ("(Python)"); break;
1479 /* MIPS extension. */
1480 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1481 /* UPC extension. */
1482 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1484 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1485 printf ("(implementation defined: %lx)", uvalue
);
1487 printf ("(Unknown: %lx)", uvalue
);
1492 case DW_AT_encoding
:
1495 case DW_ATE_void
: printf ("(void)"); break;
1496 case DW_ATE_address
: printf ("(machine address)"); break;
1497 case DW_ATE_boolean
: printf ("(boolean)"); break;
1498 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1499 case DW_ATE_float
: printf ("(float)"); break;
1500 case DW_ATE_signed
: printf ("(signed)"); break;
1501 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1502 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1503 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1504 /* DWARF 2.1 values: */
1505 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1506 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1507 /* DWARF 3 values: */
1508 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1509 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1510 case DW_ATE_edited
: printf ("(edited)"); break;
1511 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1512 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1513 /* HP extensions: */
1514 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1515 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1516 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1517 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1518 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1519 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1520 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1523 if (uvalue
>= DW_ATE_lo_user
1524 && uvalue
<= DW_ATE_hi_user
)
1525 printf ("(user defined type)");
1527 printf ("(unknown type)");
1532 case DW_AT_accessibility
:
1535 case DW_ACCESS_public
: printf ("(public)"); break;
1536 case DW_ACCESS_protected
: printf ("(protected)"); break;
1537 case DW_ACCESS_private
: printf ("(private)"); break;
1539 printf ("(unknown accessibility)");
1544 case DW_AT_visibility
:
1547 case DW_VIS_local
: printf ("(local)"); break;
1548 case DW_VIS_exported
: printf ("(exported)"); break;
1549 case DW_VIS_qualified
: printf ("(qualified)"); break;
1550 default: printf ("(unknown visibility)"); break;
1554 case DW_AT_virtuality
:
1557 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1558 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1559 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1560 default: printf ("(unknown virtuality)"); break;
1564 case DW_AT_identifier_case
:
1567 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1568 case DW_ID_up_case
: printf ("(up_case)"); break;
1569 case DW_ID_down_case
: printf ("(down_case)"); break;
1570 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1571 default: printf ("(unknown case)"); break;
1575 case DW_AT_calling_convention
:
1578 case DW_CC_normal
: printf ("(normal)"); break;
1579 case DW_CC_program
: printf ("(program)"); break;
1580 case DW_CC_nocall
: printf ("(nocall)"); break;
1582 if (uvalue
>= DW_CC_lo_user
1583 && uvalue
<= DW_CC_hi_user
)
1584 printf ("(user defined)");
1586 printf ("(unknown convention)");
1590 case DW_AT_ordering
:
1593 case -1: printf ("(undefined)"); break;
1594 case 0: printf ("(row major)"); break;
1595 case 1: printf ("(column major)"); break;
1599 case DW_AT_frame_base
:
1600 have_frame_base
= 1;
1601 case DW_AT_location
:
1602 case DW_AT_string_length
:
1603 case DW_AT_return_addr
:
1604 case DW_AT_data_member_location
:
1605 case DW_AT_vtable_elem_location
:
1607 case DW_AT_static_link
:
1608 case DW_AT_use_location
:
1609 if (form
== DW_FORM_data4
1610 || form
== DW_FORM_data8
1611 || form
== DW_FORM_sec_offset
)
1612 printf (_("(location list)"));
1614 case DW_AT_allocated
:
1615 case DW_AT_associated
:
1616 case DW_AT_data_location
:
1618 case DW_AT_upper_bound
:
1619 case DW_AT_lower_bound
:
1622 int need_frame_base
;
1625 need_frame_base
= decode_location_expression (block_start
,
1628 cu_offset
, section
);
1630 if (need_frame_base
&& !have_frame_base
)
1631 printf (_(" [without DW_AT_frame_base]"));
1637 if (form
== DW_FORM_ref_sig8
)
1640 if (form
== DW_FORM_ref1
1641 || form
== DW_FORM_ref2
1642 || form
== DW_FORM_ref4
)
1643 uvalue
+= cu_offset
;
1645 if (uvalue
>= section
->size
)
1646 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1647 uvalue
, (unsigned long) (orig_data
- section
->start
));
1650 unsigned long abbrev_number
;
1651 abbrev_entry
* entry
;
1653 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1655 printf ("[Abbrev Number: %ld", abbrev_number
);
1656 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1657 if (entry
->entry
== abbrev_number
)
1660 printf (" (%s)", get_TAG_name (entry
->tag
));
1674 get_AT_name (unsigned long attribute
)
1678 case DW_AT_sibling
: return "DW_AT_sibling";
1679 case DW_AT_location
: return "DW_AT_location";
1680 case DW_AT_name
: return "DW_AT_name";
1681 case DW_AT_ordering
: return "DW_AT_ordering";
1682 case DW_AT_subscr_data
: return "DW_AT_subscr_data";
1683 case DW_AT_byte_size
: return "DW_AT_byte_size";
1684 case DW_AT_bit_offset
: return "DW_AT_bit_offset";
1685 case DW_AT_bit_size
: return "DW_AT_bit_size";
1686 case DW_AT_element_list
: return "DW_AT_element_list";
1687 case DW_AT_stmt_list
: return "DW_AT_stmt_list";
1688 case DW_AT_low_pc
: return "DW_AT_low_pc";
1689 case DW_AT_high_pc
: return "DW_AT_high_pc";
1690 case DW_AT_language
: return "DW_AT_language";
1691 case DW_AT_member
: return "DW_AT_member";
1692 case DW_AT_discr
: return "DW_AT_discr";
1693 case DW_AT_discr_value
: return "DW_AT_discr_value";
1694 case DW_AT_visibility
: return "DW_AT_visibility";
1695 case DW_AT_import
: return "DW_AT_import";
1696 case DW_AT_string_length
: return "DW_AT_string_length";
1697 case DW_AT_common_reference
: return "DW_AT_common_reference";
1698 case DW_AT_comp_dir
: return "DW_AT_comp_dir";
1699 case DW_AT_const_value
: return "DW_AT_const_value";
1700 case DW_AT_containing_type
: return "DW_AT_containing_type";
1701 case DW_AT_default_value
: return "DW_AT_default_value";
1702 case DW_AT_inline
: return "DW_AT_inline";
1703 case DW_AT_is_optional
: return "DW_AT_is_optional";
1704 case DW_AT_lower_bound
: return "DW_AT_lower_bound";
1705 case DW_AT_producer
: return "DW_AT_producer";
1706 case DW_AT_prototyped
: return "DW_AT_prototyped";
1707 case DW_AT_return_addr
: return "DW_AT_return_addr";
1708 case DW_AT_start_scope
: return "DW_AT_start_scope";
1709 case DW_AT_stride_size
: return "DW_AT_stride_size";
1710 case DW_AT_upper_bound
: return "DW_AT_upper_bound";
1711 case DW_AT_abstract_origin
: return "DW_AT_abstract_origin";
1712 case DW_AT_accessibility
: return "DW_AT_accessibility";
1713 case DW_AT_address_class
: return "DW_AT_address_class";
1714 case DW_AT_artificial
: return "DW_AT_artificial";
1715 case DW_AT_base_types
: return "DW_AT_base_types";
1716 case DW_AT_calling_convention
: return "DW_AT_calling_convention";
1717 case DW_AT_count
: return "DW_AT_count";
1718 case DW_AT_data_member_location
: return "DW_AT_data_member_location";
1719 case DW_AT_decl_column
: return "DW_AT_decl_column";
1720 case DW_AT_decl_file
: return "DW_AT_decl_file";
1721 case DW_AT_decl_line
: return "DW_AT_decl_line";
1722 case DW_AT_declaration
: return "DW_AT_declaration";
1723 case DW_AT_discr_list
: return "DW_AT_discr_list";
1724 case DW_AT_encoding
: return "DW_AT_encoding";
1725 case DW_AT_external
: return "DW_AT_external";
1726 case DW_AT_frame_base
: return "DW_AT_frame_base";
1727 case DW_AT_friend
: return "DW_AT_friend";
1728 case DW_AT_identifier_case
: return "DW_AT_identifier_case";
1729 case DW_AT_macro_info
: return "DW_AT_macro_info";
1730 case DW_AT_namelist_items
: return "DW_AT_namelist_items";
1731 case DW_AT_priority
: return "DW_AT_priority";
1732 case DW_AT_segment
: return "DW_AT_segment";
1733 case DW_AT_specification
: return "DW_AT_specification";
1734 case DW_AT_static_link
: return "DW_AT_static_link";
1735 case DW_AT_type
: return "DW_AT_type";
1736 case DW_AT_use_location
: return "DW_AT_use_location";
1737 case DW_AT_variable_parameter
: return "DW_AT_variable_parameter";
1738 case DW_AT_virtuality
: return "DW_AT_virtuality";
1739 case DW_AT_vtable_elem_location
: return "DW_AT_vtable_elem_location";
1740 /* DWARF 2.1 values. */
1741 case DW_AT_allocated
: return "DW_AT_allocated";
1742 case DW_AT_associated
: return "DW_AT_associated";
1743 case DW_AT_data_location
: return "DW_AT_data_location";
1744 case DW_AT_stride
: return "DW_AT_stride";
1745 case DW_AT_entry_pc
: return "DW_AT_entry_pc";
1746 case DW_AT_use_UTF8
: return "DW_AT_use_UTF8";
1747 case DW_AT_extension
: return "DW_AT_extension";
1748 case DW_AT_ranges
: return "DW_AT_ranges";
1749 case DW_AT_trampoline
: return "DW_AT_trampoline";
1750 case DW_AT_call_column
: return "DW_AT_call_column";
1751 case DW_AT_call_file
: return "DW_AT_call_file";
1752 case DW_AT_call_line
: return "DW_AT_call_line";
1753 case DW_AT_description
: return "DW_AT_description";
1754 case DW_AT_binary_scale
: return "DW_AT_binary_scale";
1755 case DW_AT_decimal_scale
: return "DW_AT_decimal_scale";
1756 case DW_AT_small
: return "DW_AT_small";
1757 case DW_AT_decimal_sign
: return "DW_AT_decimal_sign";
1758 case DW_AT_digit_count
: return "DW_AT_digit_count";
1759 case DW_AT_picture_string
: return "DW_AT_picture_string";
1760 case DW_AT_mutable
: return "DW_AT_mutable";
1761 case DW_AT_threads_scaled
: return "DW_AT_threads_scaled";
1762 case DW_AT_explicit
: return "DW_AT_explicit";
1763 case DW_AT_object_pointer
: return "DW_AT_object_pointer";
1764 case DW_AT_endianity
: return "DW_AT_endianity";
1765 case DW_AT_elemental
: return "DW_AT_elemental";
1766 case DW_AT_pure
: return "DW_AT_pure";
1767 case DW_AT_recursive
: return "DW_AT_recursive";
1768 /* DWARF 4 values. */
1769 case DW_AT_signature
: return "DW_AT_signature";
1770 case DW_AT_main_subprogram
: return "DW_AT_main_subprogram";
1771 case DW_AT_data_bit_offset
: return "DW_AT_data_bit_offset";
1772 case DW_AT_const_expr
: return "DW_AT_const_expr";
1773 case DW_AT_enum_class
: return "DW_AT_enum_class";
1774 case DW_AT_linkage_name
: return "DW_AT_linkage_name";
1776 /* HP and SGI/MIPS extensions. */
1777 case DW_AT_MIPS_loop_begin
: return "DW_AT_MIPS_loop_begin";
1778 case DW_AT_MIPS_tail_loop_begin
: return "DW_AT_MIPS_tail_loop_begin";
1779 case DW_AT_MIPS_epilog_begin
: return "DW_AT_MIPS_epilog_begin";
1780 case DW_AT_MIPS_loop_unroll_factor
: return "DW_AT_MIPS_loop_unroll_factor";
1781 case DW_AT_MIPS_software_pipeline_depth
: return "DW_AT_MIPS_software_pipeline_depth";
1782 case DW_AT_MIPS_linkage_name
: return "DW_AT_MIPS_linkage_name";
1783 case DW_AT_MIPS_stride
: return "DW_AT_MIPS_stride";
1784 case DW_AT_MIPS_abstract_name
: return "DW_AT_MIPS_abstract_name";
1785 case DW_AT_MIPS_clone_origin
: return "DW_AT_MIPS_clone_origin";
1786 case DW_AT_MIPS_has_inlines
: return "DW_AT_MIPS_has_inlines";
1788 /* HP Extensions. */
1789 case DW_AT_HP_block_index
: return "DW_AT_HP_block_index";
1790 case DW_AT_HP_actuals_stmt_list
: return "DW_AT_HP_actuals_stmt_list";
1791 case DW_AT_HP_proc_per_section
: return "DW_AT_HP_proc_per_section";
1792 case DW_AT_HP_raw_data_ptr
: return "DW_AT_HP_raw_data_ptr";
1793 case DW_AT_HP_pass_by_reference
: return "DW_AT_HP_pass_by_reference";
1794 case DW_AT_HP_opt_level
: return "DW_AT_HP_opt_level";
1795 case DW_AT_HP_prof_version_id
: return "DW_AT_HP_prof_version_id";
1796 case DW_AT_HP_opt_flags
: return "DW_AT_HP_opt_flags";
1797 case DW_AT_HP_cold_region_low_pc
: return "DW_AT_HP_cold_region_low_pc";
1798 case DW_AT_HP_cold_region_high_pc
: return "DW_AT_HP_cold_region_high_pc";
1799 case DW_AT_HP_all_variables_modifiable
: return "DW_AT_HP_all_variables_modifiable";
1800 case DW_AT_HP_linkage_name
: return "DW_AT_HP_linkage_name";
1801 case DW_AT_HP_prof_flags
: return "DW_AT_HP_prof_flags";
1803 /* One value is shared by the MIPS and HP extensions: */
1804 case DW_AT_MIPS_fde
: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1806 /* GNU extensions. */
1807 case DW_AT_sf_names
: return "DW_AT_sf_names";
1808 case DW_AT_src_info
: return "DW_AT_src_info";
1809 case DW_AT_mac_info
: return "DW_AT_mac_info";
1810 case DW_AT_src_coords
: return "DW_AT_src_coords";
1811 case DW_AT_body_begin
: return "DW_AT_body_begin";
1812 case DW_AT_body_end
: return "DW_AT_body_end";
1813 case DW_AT_GNU_vector
: return "DW_AT_GNU_vector";
1814 case DW_AT_GNU_guarded_by
: return "DW_AT_GNU_guarded_by";
1815 case DW_AT_GNU_pt_guarded_by
: return "DW_AT_GNU_pt_guarded_by";
1816 case DW_AT_GNU_guarded
: return "DW_AT_GNU_guarded";
1817 case DW_AT_GNU_pt_guarded
: return "DW_AT_GNU_pt_guarded";
1818 case DW_AT_GNU_locks_excluded
: return "DW_AT_GNU_locks_excluded";
1819 case DW_AT_GNU_exclusive_locks_required
: return "DW_AT_GNU_exclusive_locks_required";
1820 case DW_AT_GNU_shared_locks_required
: return "DW_AT_GNU_shared_locks_required";
1821 case DW_AT_GNU_odr_signature
: return "DW_AT_GNU_odr_signature";
1822 case DW_AT_use_GNAT_descriptive_type
: return "DW_AT_use_GNAT_descriptive_type";
1823 case DW_AT_GNAT_descriptive_type
: return "DW_AT_GNAT_descriptive_type";
1825 /* UPC extension. */
1826 case DW_AT_upc_threads_scaled
: return "DW_AT_upc_threads_scaled";
1828 /* PGI (STMicroelectronics) extensions. */
1829 case DW_AT_PGI_lbase
: return "DW_AT_PGI_lbase";
1830 case DW_AT_PGI_soffset
: return "DW_AT_PGI_soffset";
1831 case DW_AT_PGI_lstride
: return "DW_AT_PGI_lstride";
1835 static char buffer
[100];
1837 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1844 static unsigned char *
1845 read_and_display_attr (unsigned long attribute
,
1847 unsigned char * data
,
1848 unsigned long cu_offset
,
1849 unsigned long pointer_size
,
1850 unsigned long offset_size
,
1852 debug_info
* debug_info_p
,
1854 struct dwarf_section
* section
)
1857 printf (" %-18s:", get_AT_name (attribute
));
1858 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1859 pointer_size
, offset_size
,
1860 dwarf_version
, debug_info_p
,
1868 /* Process the contents of a .debug_info section. If do_loc is non-zero
1869 then we are scanning for location lists and we do not want to display
1870 anything to the user. If do_types is non-zero, we are processing
1871 a .debug_types section instead of a .debug_info section. */
1874 process_debug_info (struct dwarf_section
*section
,
1879 unsigned char *start
= section
->start
;
1880 unsigned char *end
= start
+ section
->size
;
1881 unsigned char *section_begin
;
1883 unsigned int num_units
= 0;
1885 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1886 && num_debug_info_entries
== 0
1889 unsigned long length
;
1891 /* First scan the section to get the number of comp units. */
1892 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1895 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1896 will be the length. For a 64-bit DWARF section, it'll be
1897 the escape code 0xffffffff followed by an 8 byte length. */
1898 length
= byte_get (section_begin
, 4);
1900 if (length
== 0xffffffff)
1902 length
= byte_get (section_begin
+ 4, 8);
1903 section_begin
+= length
+ 12;
1905 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1907 warn (_("Reserved length value (%lx) found in section %s\n"), length
, section
->name
);
1911 section_begin
+= length
+ 4;
1913 /* Negative values are illegal, they may even cause infinite
1914 looping. This can happen if we can't accurately apply
1915 relocations to an object file. */
1916 if ((signed long) length
<= 0)
1918 warn (_("Corrupt unit length (%lx) found in section %s\n"), length
, section
->name
);
1925 error (_("No comp units in %s section ?"), section
->name
);
1929 /* Then allocate an array to hold the information. */
1930 debug_information
= (debug_info
*) cmalloc (num_units
,
1931 sizeof (* debug_information
));
1932 if (debug_information
== NULL
)
1934 error (_("Not enough memory for a debug info array of %u entries"),
1942 printf (_("Contents of the %s section:\n\n"), section
->name
);
1944 load_debug_section (str
, file
);
1947 load_debug_section (abbrev
, file
);
1948 if (debug_displays
[abbrev
].section
.start
== NULL
)
1950 warn (_("Unable to locate %s section!\n"),
1951 debug_displays
[abbrev
].section
.name
);
1955 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1957 DWARF2_Internal_CompUnit compunit
;
1958 unsigned char *hdrptr
;
1959 unsigned char *tags
;
1961 unsigned long cu_offset
;
1963 int initial_length_size
;
1964 unsigned char signature
[8] = { 0 };
1965 unsigned long type_offset
= 0;
1969 compunit
.cu_length
= byte_get (hdrptr
, 4);
1972 if (compunit
.cu_length
== 0xffffffff)
1974 compunit
.cu_length
= byte_get (hdrptr
, 8);
1977 initial_length_size
= 12;
1982 initial_length_size
= 4;
1985 compunit
.cu_version
= byte_get (hdrptr
, 2);
1988 cu_offset
= start
- section_begin
;
1990 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1991 hdrptr
+= offset_size
;
1993 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
2000 for (i
= 0; i
< 8; i
++)
2002 signature
[i
] = byte_get (hdrptr
, 1);
2006 type_offset
= byte_get (hdrptr
, offset_size
);
2007 hdrptr
+= offset_size
;
2010 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2011 && num_debug_info_entries
== 0
2014 debug_information
[unit
].cu_offset
= cu_offset
;
2015 debug_information
[unit
].pointer_size
2016 = compunit
.cu_pointer_size
;
2017 debug_information
[unit
].base_address
= 0;
2018 debug_information
[unit
].loc_offsets
= NULL
;
2019 debug_information
[unit
].have_frame_base
= NULL
;
2020 debug_information
[unit
].max_loc_offsets
= 0;
2021 debug_information
[unit
].num_loc_offsets
= 0;
2022 debug_information
[unit
].range_lists
= NULL
;
2023 debug_information
[unit
].max_range_lists
= 0;
2024 debug_information
[unit
].num_range_lists
= 0;
2029 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset
);
2030 printf (_(" Length: 0x%lx (%s)\n"), compunit
.cu_length
,
2031 initial_length_size
== 8 ? "64-bit" : "32-bit");
2032 printf (_(" Version: %d\n"), compunit
.cu_version
);
2033 printf (_(" Abbrev Offset: %ld\n"), compunit
.cu_abbrev_offset
);
2034 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2038 printf (_(" Signature: "));
2039 for (i
= 0; i
< 8; i
++)
2040 printf ("%02x", signature
[i
]);
2042 printf (_(" Type Offset: 0x%lx\n"), type_offset
);
2046 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2049 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
2050 cu_offset
, compunit
.cu_length
);
2054 start
+= compunit
.cu_length
+ initial_length_size
;
2056 if (compunit
.cu_version
!= 2
2057 && compunit
.cu_version
!= 3
2058 && compunit
.cu_version
!= 4)
2060 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
2061 cu_offset
, compunit
.cu_version
);
2067 /* Process the abbrevs used by this compilation unit. DWARF
2068 sections under Mach-O have non-zero addresses. */
2069 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev
].section
.size
)
2070 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2071 (unsigned long) compunit
.cu_abbrev_offset
,
2072 (unsigned long) debug_displays
[abbrev
].section
.size
);
2074 process_abbrev_section
2075 ((unsigned char *) debug_displays
[abbrev
].section
.start
2076 + compunit
.cu_abbrev_offset
- debug_displays
[abbrev
].section
.address
,
2077 (unsigned char *) debug_displays
[abbrev
].section
.start
2078 + debug_displays
[abbrev
].section
.size
);
2081 while (tags
< start
)
2083 unsigned int bytes_read
;
2084 unsigned long abbrev_number
;
2085 unsigned long die_offset
;
2086 abbrev_entry
*entry
;
2089 die_offset
= tags
- section_begin
;
2091 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2094 /* A null DIE marks the end of a list of siblings or it may also be
2095 a section padding. */
2096 if (abbrev_number
== 0)
2098 /* Check if it can be a section padding for the last CU. */
2099 if (level
== 0 && start
== end
)
2103 for (chk
= tags
; chk
< start
; chk
++)
2113 static unsigned num_bogus_warns
= 0;
2115 if (num_bogus_warns
< 3)
2117 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2120 if (num_bogus_warns
== 3)
2121 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2128 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2129 level
, die_offset
, abbrev_number
);
2131 /* Scan through the abbreviation list until we reach the
2133 for (entry
= first_abbrev
;
2134 entry
&& entry
->entry
!= abbrev_number
;
2135 entry
= entry
->next
)
2145 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2146 die_offset
, abbrev_number
);
2151 printf (_(" (%s)\n"), get_TAG_name (entry
->tag
));
2156 need_base_address
= 0;
2158 case DW_TAG_compile_unit
:
2159 need_base_address
= 1;
2161 case DW_TAG_entry_point
:
2162 case DW_TAG_subprogram
:
2163 need_base_address
= 0;
2164 /* Assuming that there is no DW_AT_frame_base. */
2165 have_frame_base
= 0;
2169 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2172 /* Show the offset from where the tag was extracted. */
2173 printf (" <%2lx>", (unsigned long)(tags
- section_begin
));
2175 tags
= read_and_display_attr (attr
->attribute
,
2178 compunit
.cu_pointer_size
,
2180 compunit
.cu_version
,
2181 debug_information
+ unit
,
2185 if (entry
->children
)
2190 /* Set num_debug_info_entries here so that it can be used to check if
2191 we need to process .debug_loc and .debug_ranges sections. */
2192 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2193 && num_debug_info_entries
== 0
2195 num_debug_info_entries
= num_units
;
2205 /* Locate and scan the .debug_info section in the file and record the pointer
2206 sizes and offsets for the compilation units in it. Usually an executable
2207 will have just one pointer size, but this is not guaranteed, and so we try
2208 not to make any assumptions. Returns zero upon failure, or the number of
2209 compilation units upon success. */
2212 load_debug_info (void * file
)
2214 /* Reset the last pointer size so that we can issue correct error
2215 messages if we are displaying the contents of more than one section. */
2216 last_pointer_size
= 0;
2217 warned_about_missing_comp_units
= FALSE
;
2219 /* If we have already tried and failed to load the .debug_info
2220 section then do not bother to repear the task. */
2221 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2224 /* If we already have the information there is nothing else to do. */
2225 if (num_debug_info_entries
> 0)
2226 return num_debug_info_entries
;
2228 if (load_debug_section (info
, file
)
2229 && process_debug_info (&debug_displays
[info
].section
, file
, 1, 0))
2230 return num_debug_info_entries
;
2232 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2237 display_debug_lines_raw (struct dwarf_section
*section
,
2238 unsigned char *data
,
2241 unsigned char *start
= section
->start
;
2243 printf (_("Raw dump of debug contents of section %s:\n\n"),
2248 DWARF2_Internal_LineInfo linfo
;
2249 unsigned char *standard_opcodes
;
2250 unsigned char *end_of_sequence
;
2251 unsigned char *hdrptr
;
2252 unsigned long hdroff
;
2253 int initial_length_size
;
2258 hdroff
= hdrptr
- start
;
2260 /* Check the length of the block. */
2261 linfo
.li_length
= byte_get (hdrptr
, 4);
2264 if (linfo
.li_length
== 0xffffffff)
2266 /* This section is 64-bit DWARF 3. */
2267 linfo
.li_length
= byte_get (hdrptr
, 8);
2270 initial_length_size
= 12;
2275 initial_length_size
= 4;
2278 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2281 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2286 /* Check its version number. */
2287 linfo
.li_version
= byte_get (hdrptr
, 2);
2289 if (linfo
.li_version
!= 2
2290 && linfo
.li_version
!= 3
2291 && linfo
.li_version
!= 4)
2293 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2297 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2298 hdrptr
+= offset_size
;
2299 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2301 if (linfo
.li_version
>= 4)
2303 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2305 if (linfo
.li_max_ops_per_insn
== 0)
2307 warn (_("Invalid maximum operations per insn.\n"));
2312 linfo
.li_max_ops_per_insn
= 1;
2313 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2315 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2317 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2319 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2322 /* Sign extend the line base field. */
2323 linfo
.li_line_base
<<= 24;
2324 linfo
.li_line_base
>>= 24;
2326 printf (_(" Offset: 0x%lx\n"), hdroff
);
2327 printf (_(" Length: %ld\n"), linfo
.li_length
);
2328 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2329 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2330 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2331 if (linfo
.li_version
>= 4)
2332 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2333 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2334 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2335 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2336 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2338 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2340 reset_state_machine (linfo
.li_default_is_stmt
);
2342 /* Display the contents of the Opcodes table. */
2343 standard_opcodes
= hdrptr
;
2345 printf (_("\n Opcodes:\n"));
2347 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2348 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2350 /* Display the contents of the Directory table. */
2351 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2354 printf (_("\n The Directory Table is empty.\n"));
2357 printf (_("\n The Directory Table:\n"));
2361 printf (_(" %s\n"), data
);
2363 data
+= strlen ((char *) data
) + 1;
2367 /* Skip the NUL at the end of the table. */
2370 /* Display the contents of the File Name table. */
2372 printf (_("\n The File Name Table is empty.\n"));
2375 printf (_("\n The File Name Table:\n"));
2376 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2380 unsigned char *name
;
2381 unsigned int bytes_read
;
2383 printf (_(" %d\t"), ++state_machine_regs
.last_file_entry
);
2386 data
+= strlen ((char *) data
) + 1;
2388 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2390 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2392 printf (_("%lu\t"), read_leb128 (data
, & bytes_read
, 0));
2394 printf (_("%s\n"), name
);
2398 /* Skip the NUL at the end of the table. */
2401 /* Now display the statements. */
2402 printf (_("\n Line Number Statements:\n"));
2404 while (data
< end_of_sequence
)
2406 unsigned char op_code
;
2408 unsigned long int uladv
;
2409 unsigned int bytes_read
;
2413 if (op_code
>= linfo
.li_opcode_base
)
2415 op_code
-= linfo
.li_opcode_base
;
2416 uladv
= (op_code
/ linfo
.li_line_range
);
2417 if (linfo
.li_max_ops_per_insn
== 1)
2419 uladv
*= linfo
.li_min_insn_length
;
2420 state_machine_regs
.address
+= uladv
;
2421 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2422 op_code
, uladv
, state_machine_regs
.address
);
2426 state_machine_regs
.address
2427 += ((state_machine_regs
.op_index
+ uladv
)
2428 / linfo
.li_max_ops_per_insn
)
2429 * linfo
.li_min_insn_length
;
2430 state_machine_regs
.op_index
2431 = (state_machine_regs
.op_index
+ uladv
)
2432 % linfo
.li_max_ops_per_insn
;
2433 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx[%d]"),
2434 op_code
, uladv
, state_machine_regs
.address
,
2435 state_machine_regs
.op_index
);
2437 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2438 state_machine_regs
.line
+= adv
;
2439 printf (_(" and Line by %d to %d\n"),
2440 adv
, state_machine_regs
.line
);
2442 else switch (op_code
)
2444 case DW_LNS_extended_op
:
2445 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2449 printf (_(" Copy\n"));
2452 case DW_LNS_advance_pc
:
2453 uladv
= read_leb128 (data
, & bytes_read
, 0);
2455 if (linfo
.li_max_ops_per_insn
== 1)
2457 uladv
*= linfo
.li_min_insn_length
;
2458 state_machine_regs
.address
+= uladv
;
2459 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv
,
2460 state_machine_regs
.address
);
2464 state_machine_regs
.address
2465 += ((state_machine_regs
.op_index
+ uladv
)
2466 / linfo
.li_max_ops_per_insn
)
2467 * linfo
.li_min_insn_length
;
2468 state_machine_regs
.op_index
2469 = (state_machine_regs
.op_index
+ uladv
)
2470 % linfo
.li_max_ops_per_insn
;
2471 printf (_(" Advance PC by %lu to 0x%lx[%d]\n"), uladv
,
2472 state_machine_regs
.address
,
2473 state_machine_regs
.op_index
);
2477 case DW_LNS_advance_line
:
2478 adv
= read_leb128 (data
, & bytes_read
, 1);
2480 state_machine_regs
.line
+= adv
;
2481 printf (_(" Advance Line by %d to %d\n"), adv
,
2482 state_machine_regs
.line
);
2485 case DW_LNS_set_file
:
2486 adv
= read_leb128 (data
, & bytes_read
, 0);
2488 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2490 state_machine_regs
.file
= adv
;
2493 case DW_LNS_set_column
:
2494 uladv
= read_leb128 (data
, & bytes_read
, 0);
2496 printf (_(" Set column to %lu\n"), uladv
);
2497 state_machine_regs
.column
= uladv
;
2500 case DW_LNS_negate_stmt
:
2501 adv
= state_machine_regs
.is_stmt
;
2503 printf (_(" Set is_stmt to %d\n"), adv
);
2504 state_machine_regs
.is_stmt
= adv
;
2507 case DW_LNS_set_basic_block
:
2508 printf (_(" Set basic block\n"));
2509 state_machine_regs
.basic_block
= 1;
2512 case DW_LNS_const_add_pc
:
2513 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2514 if (linfo
.li_max_ops_per_insn
)
2516 uladv
*= linfo
.li_min_insn_length
;
2517 state_machine_regs
.address
+= uladv
;
2518 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv
,
2519 state_machine_regs
.address
);
2523 state_machine_regs
.address
2524 += ((state_machine_regs
.op_index
+ uladv
)
2525 / linfo
.li_max_ops_per_insn
)
2526 * linfo
.li_min_insn_length
;
2527 state_machine_regs
.op_index
2528 = (state_machine_regs
.op_index
+ uladv
)
2529 % linfo
.li_max_ops_per_insn
;
2530 printf (_(" Advance PC by constant %lu to 0x%lx[%d]\n"),
2531 uladv
, state_machine_regs
.address
,
2532 state_machine_regs
.op_index
);
2536 case DW_LNS_fixed_advance_pc
:
2537 uladv
= byte_get (data
, 2);
2539 state_machine_regs
.address
+= uladv
;
2540 state_machine_regs
.op_index
= 0;
2541 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2542 uladv
, state_machine_regs
.address
);
2545 case DW_LNS_set_prologue_end
:
2546 printf (_(" Set prologue_end to true\n"));
2549 case DW_LNS_set_epilogue_begin
:
2550 printf (_(" Set epilogue_begin to true\n"));
2553 case DW_LNS_set_isa
:
2554 uladv
= read_leb128 (data
, & bytes_read
, 0);
2556 printf (_(" Set ISA to %lu\n"), uladv
);
2560 printf (_(" Unknown opcode %d with operands: "), op_code
);
2562 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2564 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2565 i
== 1 ? "" : ", ");
2580 unsigned char *name
;
2581 unsigned int directory_index
;
2582 unsigned int modification_date
;
2583 unsigned int length
;
2586 /* Output a decoded representation of the .debug_line section. */
2589 display_debug_lines_decoded (struct dwarf_section
*section
,
2590 unsigned char *data
,
2593 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2598 /* This loop amounts to one iteration per compilation unit. */
2599 DWARF2_Internal_LineInfo linfo
;
2600 unsigned char *standard_opcodes
;
2601 unsigned char *end_of_sequence
;
2602 unsigned char *hdrptr
;
2603 int initial_length_size
;
2606 File_Entry
*file_table
= NULL
;
2607 unsigned char **directory_table
= NULL
;
2611 /* Extract information from the Line Number Program Header.
2612 (section 6.2.4 in the Dwarf3 doc). */
2614 /* Get the length of this CU's line number information block. */
2615 linfo
.li_length
= byte_get (hdrptr
, 4);
2618 if (linfo
.li_length
== 0xffffffff)
2620 /* This section is 64-bit DWARF 3. */
2621 linfo
.li_length
= byte_get (hdrptr
, 8);
2624 initial_length_size
= 12;
2629 initial_length_size
= 4;
2632 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2634 warn (_("The line info appears to be corrupt - "
2635 "the section is too small\n"));
2639 /* Get this CU's Line Number Block version number. */
2640 linfo
.li_version
= byte_get (hdrptr
, 2);
2642 if (linfo
.li_version
!= 2
2643 && linfo
.li_version
!= 3
2644 && linfo
.li_version
!= 4)
2646 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2651 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2652 hdrptr
+= offset_size
;
2653 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2655 if (linfo
.li_version
>= 4)
2657 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2659 if (linfo
.li_max_ops_per_insn
== 0)
2661 warn (_("Invalid maximum operations per insn.\n"));
2666 linfo
.li_max_ops_per_insn
= 1;
2667 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2669 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2671 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2673 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2676 /* Sign extend the line base field. */
2677 linfo
.li_line_base
<<= 24;
2678 linfo
.li_line_base
>>= 24;
2680 /* Find the end of this CU's Line Number Information Block. */
2681 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2683 reset_state_machine (linfo
.li_default_is_stmt
);
2685 /* Save a pointer to the contents of the Opcodes table. */
2686 standard_opcodes
= hdrptr
;
2688 /* Traverse the Directory table just to count entries. */
2689 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2692 unsigned int n_directories
= 0;
2693 unsigned char *ptr_directory_table
= data
;
2697 data
+= strlen ((char *) data
) + 1;
2701 /* Go through the directory table again to save the directories. */
2702 directory_table
= (unsigned char **)
2703 xmalloc (n_directories
* sizeof (unsigned char *));
2706 while (*ptr_directory_table
!= 0)
2708 directory_table
[i
] = ptr_directory_table
;
2709 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2713 /* Skip the NUL at the end of the table. */
2716 /* Traverse the File Name table just to count the entries. */
2719 unsigned int n_files
= 0;
2720 unsigned char *ptr_file_name_table
= data
;
2724 unsigned int bytes_read
;
2726 /* Skip Name, directory index, last modification time and length
2728 data
+= strlen ((char *) data
) + 1;
2729 read_leb128 (data
, & bytes_read
, 0);
2731 read_leb128 (data
, & bytes_read
, 0);
2733 read_leb128 (data
, & bytes_read
, 0);
2739 /* Go through the file table again to save the strings. */
2740 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2743 while (*ptr_file_name_table
!= 0)
2745 unsigned int bytes_read
;
2747 file_table
[i
].name
= ptr_file_name_table
;
2748 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2750 /* We are not interested in directory, time or size. */
2751 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2753 ptr_file_name_table
+= bytes_read
;
2754 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2756 ptr_file_name_table
+= bytes_read
;
2757 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2758 ptr_file_name_table
+= bytes_read
;
2763 /* Print the Compilation Unit's name and a header. */
2764 if (directory_table
== NULL
)
2766 printf (_("CU: %s:\n"), file_table
[0].name
);
2767 printf (_("File name Line number Starting address\n"));
2771 if (do_wide
|| strlen ((char *) directory_table
[0]) < 76)
2773 printf (_("CU: %s/%s:\n"), directory_table
[0],
2774 file_table
[0].name
);
2778 printf (_("%s:\n"), file_table
[0].name
);
2780 printf (_("File name Line number Starting address\n"));
2784 /* Skip the NUL at the end of the table. */
2787 /* This loop iterates through the Dwarf Line Number Program. */
2788 while (data
< end_of_sequence
)
2790 unsigned char op_code
;
2792 unsigned long int uladv
;
2793 unsigned int bytes_read
;
2794 int is_special_opcode
= 0;
2798 if (op_code
>= linfo
.li_opcode_base
)
2800 op_code
-= linfo
.li_opcode_base
;
2801 uladv
= (op_code
/ linfo
.li_line_range
);
2802 if (linfo
.li_max_ops_per_insn
== 1)
2804 uladv
*= linfo
.li_min_insn_length
;
2805 state_machine_regs
.address
+= uladv
;
2809 state_machine_regs
.address
2810 += ((state_machine_regs
.op_index
+ uladv
)
2811 / linfo
.li_max_ops_per_insn
)
2812 * linfo
.li_min_insn_length
;
2813 state_machine_regs
.op_index
2814 = (state_machine_regs
.op_index
+ uladv
)
2815 % linfo
.li_max_ops_per_insn
;
2818 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2819 state_machine_regs
.line
+= adv
;
2820 is_special_opcode
= 1;
2822 else switch (op_code
)
2824 case DW_LNS_extended_op
:
2826 unsigned int ext_op_code_len
;
2827 unsigned char ext_op_code
;
2828 unsigned char *op_code_data
= data
;
2830 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2831 op_code_data
+= bytes_read
;
2833 if (ext_op_code_len
== 0)
2835 warn (_("badly formed extended line op encountered!\n"));
2838 ext_op_code_len
+= bytes_read
;
2839 ext_op_code
= *op_code_data
++;
2841 switch (ext_op_code
)
2843 case DW_LNE_end_sequence
:
2844 reset_state_machine (linfo
.li_default_is_stmt
);
2846 case DW_LNE_set_address
:
2847 state_machine_regs
.address
=
2848 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2849 state_machine_regs
.op_index
= 0;
2851 case DW_LNE_define_file
:
2853 unsigned int dir_index
= 0;
2855 ++state_machine_regs
.last_file_entry
;
2856 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2857 dir_index
= read_leb128 (op_code_data
, & bytes_read
, 0);
2858 op_code_data
+= bytes_read
;
2859 read_leb128 (op_code_data
, & bytes_read
, 0);
2860 op_code_data
+= bytes_read
;
2861 read_leb128 (op_code_data
, & bytes_read
, 0);
2863 printf (_("%s:\n"), directory_table
[dir_index
]);
2867 printf (_("UNKNOWN: length %d\n"), ext_op_code_len
- bytes_read
);
2870 data
+= ext_op_code_len
;
2876 case DW_LNS_advance_pc
:
2877 uladv
= read_leb128 (data
, & bytes_read
, 0);
2879 if (linfo
.li_max_ops_per_insn
== 1)
2881 uladv
*= linfo
.li_min_insn_length
;
2882 state_machine_regs
.address
+= uladv
;
2886 state_machine_regs
.address
2887 += ((state_machine_regs
.op_index
+ uladv
)
2888 / linfo
.li_max_ops_per_insn
)
2889 * linfo
.li_min_insn_length
;
2890 state_machine_regs
.op_index
2891 = (state_machine_regs
.op_index
+ uladv
)
2892 % linfo
.li_max_ops_per_insn
;
2896 case DW_LNS_advance_line
:
2897 adv
= read_leb128 (data
, & bytes_read
, 1);
2899 state_machine_regs
.line
+= adv
;
2902 case DW_LNS_set_file
:
2903 adv
= read_leb128 (data
, & bytes_read
, 0);
2905 state_machine_regs
.file
= adv
;
2906 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2908 /* If directory index is 0, that means current directory. */
2909 printf (_("\n./%s:[++]\n"),
2910 file_table
[state_machine_regs
.file
- 1].name
);
2914 /* The directory index starts counting at 1. */
2915 printf (_("\n%s/%s:\n"),
2916 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2917 file_table
[state_machine_regs
.file
- 1].name
);
2921 case DW_LNS_set_column
:
2922 uladv
= read_leb128 (data
, & bytes_read
, 0);
2924 state_machine_regs
.column
= uladv
;
2927 case DW_LNS_negate_stmt
:
2928 adv
= state_machine_regs
.is_stmt
;
2930 state_machine_regs
.is_stmt
= adv
;
2933 case DW_LNS_set_basic_block
:
2934 state_machine_regs
.basic_block
= 1;
2937 case DW_LNS_const_add_pc
:
2938 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2939 if (linfo
.li_max_ops_per_insn
== 1)
2941 uladv
*= linfo
.li_min_insn_length
;
2942 state_machine_regs
.address
+= uladv
;
2946 state_machine_regs
.address
2947 += ((state_machine_regs
.op_index
+ uladv
)
2948 / linfo
.li_max_ops_per_insn
)
2949 * linfo
.li_min_insn_length
;
2950 state_machine_regs
.op_index
2951 = (state_machine_regs
.op_index
+ uladv
)
2952 % linfo
.li_max_ops_per_insn
;
2956 case DW_LNS_fixed_advance_pc
:
2957 uladv
= byte_get (data
, 2);
2959 state_machine_regs
.address
+= uladv
;
2960 state_machine_regs
.op_index
= 0;
2963 case DW_LNS_set_prologue_end
:
2966 case DW_LNS_set_epilogue_begin
:
2969 case DW_LNS_set_isa
:
2970 uladv
= read_leb128 (data
, & bytes_read
, 0);
2972 printf (_(" Set ISA to %lu\n"), uladv
);
2976 printf (_(" Unknown opcode %d with operands: "), op_code
);
2978 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2980 printf ("0x%lx%s", read_leb128 (data
, &bytes_read
, 0),
2981 i
== 1 ? "" : ", ");
2988 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2989 to the DWARF address/line matrix. */
2990 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
2991 || (op_code
== DW_LNS_copy
))
2993 const unsigned int MAX_FILENAME_LENGTH
= 35;
2994 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
2995 char *newFileName
= NULL
;
2996 size_t fileNameLength
= strlen (fileName
);
2998 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3000 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3001 /* Truncate file name */
3002 strncpy (newFileName
,
3003 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3004 MAX_FILENAME_LENGTH
+ 1);
3008 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3009 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3012 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3014 if (linfo
.li_max_ops_per_insn
== 1)
3015 printf (_("%-35s %11d %#18lx\n"), newFileName
,
3016 state_machine_regs
.line
,
3017 state_machine_regs
.address
);
3019 printf (_("%-35s %11d %#18lx[%d]\n"), newFileName
,
3020 state_machine_regs
.line
,
3021 state_machine_regs
.address
,
3022 state_machine_regs
.op_index
);
3026 if (linfo
.li_max_ops_per_insn
== 1)
3027 printf (_("%s %11d %#18lx\n"), newFileName
,
3028 state_machine_regs
.line
,
3029 state_machine_regs
.address
);
3031 printf (_("%s %11d %#18lx[%d]\n"), newFileName
,
3032 state_machine_regs
.line
,
3033 state_machine_regs
.address
,
3034 state_machine_regs
.op_index
);
3037 if (op_code
== DW_LNE_end_sequence
)
3045 free (directory_table
);
3046 directory_table
= NULL
;
3054 display_debug_lines (struct dwarf_section
*section
, void *file
)
3056 unsigned char *data
= section
->start
;
3057 unsigned char *end
= data
+ section
->size
;
3059 int retValDecoded
= 1;
3061 if (load_debug_info (file
) == 0)
3063 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3068 if (do_debug_lines
== 0)
3069 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3071 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3072 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3074 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3075 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3077 if (!retValRaw
|| !retValDecoded
)
3084 find_debug_info_for_offset (unsigned long offset
)
3088 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3091 for (i
= 0; i
< num_debug_info_entries
; i
++)
3092 if (debug_information
[i
].cu_offset
== offset
)
3093 return debug_information
+ i
;
3099 display_debug_pubnames (struct dwarf_section
*section
,
3100 void *file ATTRIBUTE_UNUSED
)
3102 DWARF2_Internal_PubNames names
;
3103 unsigned char *start
= section
->start
;
3104 unsigned char *end
= start
+ section
->size
;
3106 /* It does not matter if this load fails,
3107 we test for that later on. */
3108 load_debug_info (file
);
3110 printf (_("Contents of the %s section:\n\n"), section
->name
);
3114 unsigned char *data
;
3115 unsigned long offset
;
3116 int offset_size
, initial_length_size
;
3120 names
.pn_length
= byte_get (data
, 4);
3122 if (names
.pn_length
== 0xffffffff)
3124 names
.pn_length
= byte_get (data
, 8);
3127 initial_length_size
= 12;
3132 initial_length_size
= 4;
3135 names
.pn_version
= byte_get (data
, 2);
3138 names
.pn_offset
= byte_get (data
, offset_size
);
3139 data
+= offset_size
;
3141 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3142 && num_debug_info_entries
> 0
3143 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3144 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3145 names
.pn_offset
, section
->name
);
3147 names
.pn_size
= byte_get (data
, offset_size
);
3148 data
+= offset_size
;
3150 start
+= names
.pn_length
+ initial_length_size
;
3152 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3154 static int warned
= 0;
3158 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3165 printf (_(" Length: %ld\n"),
3167 printf (_(" Version: %d\n"),
3169 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3171 printf (_(" Size of area in .debug_info section: %ld\n"),
3174 printf (_("\n Offset\tName\n"));
3178 offset
= byte_get (data
, offset_size
);
3182 data
+= offset_size
;
3183 printf (" %-6lx\t%s\n", offset
, data
);
3184 data
+= strlen ((char *) data
) + 1;
3187 while (offset
!= 0);
3195 display_debug_macinfo (struct dwarf_section
*section
,
3196 void *file ATTRIBUTE_UNUSED
)
3198 unsigned char *start
= section
->start
;
3199 unsigned char *end
= start
+ section
->size
;
3200 unsigned char *curr
= start
;
3201 unsigned int bytes_read
;
3202 enum dwarf_macinfo_record_type op
;
3204 printf (_("Contents of the %s section:\n\n"), section
->name
);
3208 unsigned int lineno
;
3211 op
= (enum dwarf_macinfo_record_type
) *curr
;
3216 case DW_MACINFO_start_file
:
3218 unsigned int filenum
;
3220 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3222 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3225 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3230 case DW_MACINFO_end_file
:
3231 printf (_(" DW_MACINFO_end_file\n"));
3234 case DW_MACINFO_define
:
3235 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3237 string
= (char *) curr
;
3238 curr
+= strlen (string
) + 1;
3239 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3243 case DW_MACINFO_undef
:
3244 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3246 string
= (char *) curr
;
3247 curr
+= strlen (string
) + 1;
3248 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3252 case DW_MACINFO_vendor_ext
:
3254 unsigned int constant
;
3256 constant
= read_leb128 (curr
, & bytes_read
, 0);
3258 string
= (char *) curr
;
3259 curr
+= strlen (string
) + 1;
3260 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3271 display_debug_abbrev (struct dwarf_section
*section
,
3272 void *file ATTRIBUTE_UNUSED
)
3274 abbrev_entry
*entry
;
3275 unsigned char *start
= section
->start
;
3276 unsigned char *end
= start
+ section
->size
;
3278 printf (_("Contents of the %s section:\n\n"), section
->name
);
3284 start
= process_abbrev_section (start
, end
);
3286 if (first_abbrev
== NULL
)
3289 printf (_(" Number TAG\n"));
3291 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3295 printf (_(" %ld %s [%s]\n"),
3297 get_TAG_name (entry
->tag
),
3298 entry
->children
? _("has children") : _("no children"));
3300 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3301 printf (_(" %-18s %s\n"),
3302 get_AT_name (attr
->attribute
),
3303 get_FORM_name (attr
->form
));
3314 display_debug_loc (struct dwarf_section
*section
, void *file
)
3316 unsigned char *start
= section
->start
;
3317 unsigned char *section_end
;
3318 unsigned long bytes
;
3319 unsigned char *section_begin
= start
;
3320 unsigned int num_loc_list
= 0;
3321 unsigned long last_offset
= 0;
3322 unsigned int first
= 0;
3325 int seen_first_offset
= 0;
3326 int use_debug_info
= 1;
3327 unsigned char *next
;
3329 bytes
= section
->size
;
3330 section_end
= start
+ bytes
;
3334 printf (_("\nThe %s section is empty.\n"), section
->name
);
3338 if (load_debug_info (file
) == 0)
3340 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3345 /* Check the order of location list in .debug_info section. If
3346 offsets of location lists are in the ascending order, we can
3347 use `debug_information' directly. */
3348 for (i
= 0; i
< num_debug_info_entries
; i
++)
3352 num
= debug_information
[i
].num_loc_offsets
;
3353 num_loc_list
+= num
;
3355 /* Check if we can use `debug_information' directly. */
3356 if (use_debug_info
&& num
!= 0)
3358 if (!seen_first_offset
)
3360 /* This is the first location list. */
3361 last_offset
= debug_information
[i
].loc_offsets
[0];
3363 seen_first_offset
= 1;
3369 for (; j
< num
; j
++)
3372 debug_information
[i
].loc_offsets
[j
])
3377 last_offset
= debug_information
[i
].loc_offsets
[j
];
3382 if (!use_debug_info
)
3383 /* FIXME: Should we handle this case? */
3384 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3386 if (!seen_first_offset
)
3387 error (_("No location lists in .debug_info section!\n"));
3389 /* DWARF sections under Mach-O have non-zero addresses. */
3390 if (debug_information
[first
].num_loc_offsets
> 0
3391 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3392 warn (_("Location lists in %s section start at 0x%lx\n"),
3393 section
->name
, debug_information
[first
].loc_offsets
[0]);
3395 printf (_("Contents of the %s section:\n\n"), section
->name
);
3396 printf (_(" Offset Begin End Expression\n"));
3398 seen_first_offset
= 0;
3399 for (i
= first
; i
< num_debug_info_entries
; i
++)
3403 unsigned short length
;
3404 unsigned long offset
;
3405 unsigned int pointer_size
;
3406 unsigned long cu_offset
;
3407 unsigned long base_address
;
3408 int need_frame_base
;
3411 pointer_size
= debug_information
[i
].pointer_size
;
3412 cu_offset
= debug_information
[i
].cu_offset
;
3414 for (j
= 0; j
< debug_information
[i
].num_loc_offsets
; j
++)
3416 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3417 /* DWARF sections under Mach-O have non-zero addresses. */
3418 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3419 next
= section_begin
+ offset
;
3420 base_address
= debug_information
[i
].base_address
;
3422 if (!seen_first_offset
)
3423 seen_first_offset
= 1;
3427 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3428 (unsigned long) (start
- section_begin
),
3429 (unsigned long) (next
- section_begin
));
3430 else if (start
> next
)
3431 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3432 (unsigned long) (start
- section_begin
),
3433 (unsigned long) (next
- section_begin
));
3437 if (offset
>= bytes
)
3439 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3446 if (start
+ 2 * pointer_size
> section_end
)
3448 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3453 /* Note: we use sign extension here in order to be sure that
3454 we can detect the -1 escape value. Sign extension into the
3455 top 32 bits of a 32-bit address will not affect the values
3456 that we display since we always show hex values, and always
3457 the bottom 32-bits. */
3458 begin
= byte_get_signed (start
, pointer_size
);
3459 start
+= pointer_size
;
3460 end
= byte_get_signed (start
, pointer_size
);
3461 start
+= pointer_size
;
3463 printf (" %8.8lx ", offset
);
3465 if (begin
== 0 && end
== 0)
3467 printf (_("<End of list>\n"));
3471 /* Check base address specifiers. */
3472 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3475 print_dwarf_vma (begin
, pointer_size
);
3476 print_dwarf_vma (end
, pointer_size
);
3477 printf (_("(base address)\n"));
3481 if (start
+ 2 > section_end
)
3483 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3488 length
= byte_get (start
, 2);
3491 if (start
+ length
> section_end
)
3493 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3498 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3499 print_dwarf_vma (end
+ base_address
, pointer_size
);
3502 need_frame_base
= decode_location_expression (start
,
3505 cu_offset
, section
);
3508 if (need_frame_base
&& !has_frame_base
)
3509 printf (_(" [without DW_AT_frame_base]"));
3512 fputs (_(" (start == end)"), stdout
);
3513 else if (begin
> end
)
3514 fputs (_(" (start > end)"), stdout
);
3523 if (start
< section_end
)
3524 warn (_("There are %ld unused bytes at the end of section %s\n"),
3525 (long) (section_end
- start
), section
->name
);
3531 display_debug_str (struct dwarf_section
*section
,
3532 void *file ATTRIBUTE_UNUSED
)
3534 unsigned char *start
= section
->start
;
3535 unsigned long bytes
= section
->size
;
3536 dwarf_vma addr
= section
->address
;
3540 printf (_("\nThe %s section is empty.\n"), section
->name
);
3544 printf (_("Contents of the %s section:\n\n"), section
->name
);
3552 lbytes
= (bytes
> 16 ? 16 : bytes
);
3554 printf (" 0x%8.8lx ", (unsigned long) addr
);
3556 for (j
= 0; j
< 16; j
++)
3559 printf ("%2.2x", start
[j
]);
3567 for (j
= 0; j
< lbytes
; j
++)
3570 if (k
>= ' ' && k
< 0x80)
3589 display_debug_info (struct dwarf_section
*section
, void *file
)
3591 return process_debug_info (section
, file
, 0, 0);
3595 display_debug_types (struct dwarf_section
*section
, void *file
)
3597 return process_debug_info (section
, file
, 0, 1);
3601 display_debug_aranges (struct dwarf_section
*section
,
3602 void *file ATTRIBUTE_UNUSED
)
3604 unsigned char *start
= section
->start
;
3605 unsigned char *end
= start
+ section
->size
;
3607 printf (_("Contents of the %s section:\n\n"), section
->name
);
3609 /* It does not matter if this load fails,
3610 we test for that later on. */
3611 load_debug_info (file
);
3615 unsigned char *hdrptr
;
3616 DWARF2_Internal_ARange arange
;
3617 unsigned char *addr_ranges
;
3620 unsigned char address_size
;
3623 int initial_length_size
;
3627 arange
.ar_length
= byte_get (hdrptr
, 4);
3630 if (arange
.ar_length
== 0xffffffff)
3632 arange
.ar_length
= byte_get (hdrptr
, 8);
3635 initial_length_size
= 12;
3640 initial_length_size
= 4;
3643 arange
.ar_version
= byte_get (hdrptr
, 2);
3646 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3647 hdrptr
+= offset_size
;
3649 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3650 && num_debug_info_entries
> 0
3651 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3652 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3653 arange
.ar_info_offset
, section
->name
);
3655 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3658 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3661 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3663 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3667 printf (_(" Length: %ld\n"), arange
.ar_length
);
3668 printf (_(" Version: %d\n"), arange
.ar_version
);
3669 printf (_(" Offset into .debug_info: 0x%lx\n"), arange
.ar_info_offset
);
3670 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
3671 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
3673 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
3675 /* The DWARF spec does not require that the address size be a power
3676 of two, but we do. This will have to change if we ever encounter
3677 an uneven architecture. */
3678 if ((address_size
& (address_size
- 1)) != 0)
3680 warn (_("Pointer size + Segment size is not a power of two.\n"));
3684 if (address_size
> 4)
3685 printf (_("\n Address Length\n"));
3687 printf (_("\n Address Length\n"));
3689 addr_ranges
= hdrptr
;
3691 /* Must pad to an alignment boundary that is twice the address size. */
3692 excess
= (hdrptr
- start
) % (2 * address_size
);
3694 addr_ranges
+= (2 * address_size
) - excess
;
3696 start
+= arange
.ar_length
+ initial_length_size
;
3698 while (addr_ranges
+ 2 * address_size
<= start
)
3700 address
= byte_get (addr_ranges
, address_size
);
3702 addr_ranges
+= address_size
;
3704 length
= byte_get (addr_ranges
, address_size
);
3706 addr_ranges
+= address_size
;
3709 print_dwarf_vma (address
, address_size
);
3710 print_dwarf_vma (length
, address_size
);
3720 /* Each debug_information[x].range_lists[y] gets this representation for
3721 sorting purposes. */
3725 /* The debug_information[x].range_lists[y] value. */
3726 unsigned long ranges_offset
;
3728 /* Original debug_information to find parameters of the data. */
3729 debug_info
*debug_info_p
;
3732 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3735 range_entry_compar (const void *ap
, const void *bp
)
3737 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
3738 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
3739 const unsigned long a
= a_re
->ranges_offset
;
3740 const unsigned long b
= b_re
->ranges_offset
;
3742 return (a
> b
) - (b
> a
);
3746 display_debug_ranges (struct dwarf_section
*section
,
3747 void *file ATTRIBUTE_UNUSED
)
3749 unsigned char *start
= section
->start
;
3750 unsigned long bytes
;
3751 unsigned char *section_begin
= start
;
3752 unsigned int num_range_list
, i
;
3753 struct range_entry
*range_entries
, *range_entry_fill
;
3755 bytes
= section
->size
;
3759 printf (_("\nThe %s section is empty.\n"), section
->name
);
3763 if (load_debug_info (file
) == 0)
3765 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3771 for (i
= 0; i
< num_debug_info_entries
; i
++)
3772 num_range_list
+= debug_information
[i
].num_range_lists
;
3774 if (num_range_list
== 0)
3775 error (_("No range lists in .debug_info section!\n"));
3777 range_entries
= (struct range_entry
*)
3778 xmalloc (sizeof (*range_entries
) * num_range_list
);
3779 range_entry_fill
= range_entries
;
3781 for (i
= 0; i
< num_debug_info_entries
; i
++)
3783 debug_info
*debug_info_p
= &debug_information
[i
];
3786 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
3788 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
3789 range_entry_fill
->debug_info_p
= debug_info_p
;
3794 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
3795 range_entry_compar
);
3797 /* DWARF sections under Mach-O have non-zero addresses. */
3798 if (range_entries
[0].ranges_offset
!= section
->address
)
3799 warn (_("Range lists in %s section start at 0x%lx\n"),
3800 section
->name
, range_entries
[0].ranges_offset
);
3802 printf (_("Contents of the %s section:\n\n"), section
->name
);
3803 printf (_(" Offset Begin End\n"));
3805 for (i
= 0; i
< num_range_list
; i
++)
3807 struct range_entry
*range_entry
= &range_entries
[i
];
3808 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
3809 unsigned int pointer_size
;
3810 unsigned long offset
;
3811 unsigned char *next
;
3812 unsigned long base_address
;
3814 pointer_size
= debug_info_p
->pointer_size
;
3816 /* DWARF sections under Mach-O have non-zero addresses. */
3817 offset
= range_entry
->ranges_offset
- section
->address
;
3818 next
= section_begin
+ offset
;
3819 base_address
= debug_info_p
->base_address
;
3824 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3825 (unsigned long) (start
- section_begin
),
3826 (unsigned long) (next
- section_begin
), section
->name
);
3827 else if (start
> next
)
3828 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3829 (unsigned long) (start
- section_begin
),
3830 (unsigned long) (next
- section_begin
), section
->name
);
3839 /* Note: we use sign extension here in order to be sure that
3840 we can detect the -1 escape value. Sign extension into the
3841 top 32 bits of a 32-bit address will not affect the values
3842 that we display since we always show hex values, and always
3843 the bottom 32-bits. */
3844 begin
= byte_get_signed (start
, pointer_size
);
3845 start
+= pointer_size
;
3846 end
= byte_get_signed (start
, pointer_size
);
3847 start
+= pointer_size
;
3849 printf (" %8.8lx ", offset
);
3851 if (begin
== 0 && end
== 0)
3853 printf (_("<End of list>\n"));
3857 /* Check base address specifiers. */
3858 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3861 print_dwarf_vma (begin
, pointer_size
);
3862 print_dwarf_vma (end
, pointer_size
);
3863 printf ("(base address)\n");
3867 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3868 print_dwarf_vma (end
+ base_address
, pointer_size
);
3871 fputs (_("(start == end)"), stdout
);
3872 else if (begin
> end
)
3873 fputs (_("(start > end)"), stdout
);
3880 free (range_entries
);
3885 typedef struct Frame_Chunk
3887 struct Frame_Chunk
*next
;
3888 unsigned char *chunk_start
;
3890 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3891 short int *col_type
;
3894 unsigned int code_factor
;
3896 unsigned long pc_begin
;
3897 unsigned long pc_range
;
3901 unsigned char fde_encoding
;
3902 unsigned char cfa_exp
;
3903 unsigned char ptr_size
;
3904 unsigned char segment_size
;
3908 static const char *const *dwarf_regnames
;
3909 static unsigned int dwarf_regnames_count
;
3911 /* A marker for a col_type that means this column was never referenced
3912 in the frame info. */
3913 #define DW_CFA_unreferenced (-1)
3915 /* Return 0 if not more space is needed, 1 if more space is needed,
3916 -1 for invalid reg. */
3919 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
3921 int prev
= fc
->ncols
;
3923 if (reg
< (unsigned int) fc
->ncols
)
3926 if (dwarf_regnames_count
3927 && reg
> dwarf_regnames_count
)
3930 fc
->ncols
= reg
+ 1;
3931 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
3932 sizeof (short int));
3933 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
3935 while (prev
< fc
->ncols
)
3937 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
3938 fc
->col_offset
[prev
] = 0;
3944 static const char *const dwarf_regnames_i386
[] =
3946 "eax", "ecx", "edx", "ebx",
3947 "esp", "ebp", "esi", "edi",
3948 "eip", "eflags", NULL
,
3949 "st0", "st1", "st2", "st3",
3950 "st4", "st5", "st6", "st7",
3952 "xmm0", "xmm1", "xmm2", "xmm3",
3953 "xmm4", "xmm5", "xmm6", "xmm7",
3954 "mm0", "mm1", "mm2", "mm3",
3955 "mm4", "mm5", "mm6", "mm7",
3956 "fcw", "fsw", "mxcsr",
3957 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3961 static const char *const dwarf_regnames_x86_64
[] =
3963 "rax", "rdx", "rcx", "rbx",
3964 "rsi", "rdi", "rbp", "rsp",
3965 "r8", "r9", "r10", "r11",
3966 "r12", "r13", "r14", "r15",
3968 "xmm0", "xmm1", "xmm2", "xmm3",
3969 "xmm4", "xmm5", "xmm6", "xmm7",
3970 "xmm8", "xmm9", "xmm10", "xmm11",
3971 "xmm12", "xmm13", "xmm14", "xmm15",
3972 "st0", "st1", "st2", "st3",
3973 "st4", "st5", "st6", "st7",
3974 "mm0", "mm1", "mm2", "mm3",
3975 "mm4", "mm5", "mm6", "mm7",
3977 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
3978 "fs.base", "gs.base", NULL
, NULL
,
3980 "mxcsr", "fcw", "fsw"
3984 init_dwarf_regnames (unsigned int e_machine
)
3990 dwarf_regnames
= dwarf_regnames_i386
;
3991 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
3996 dwarf_regnames
= dwarf_regnames_x86_64
;
3997 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4006 regname (unsigned int regno
, int row
)
4008 static char reg
[64];
4010 && regno
< dwarf_regnames_count
4011 && dwarf_regnames
[regno
] != NULL
)
4014 return dwarf_regnames
[regno
];
4015 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4016 dwarf_regnames
[regno
]);
4019 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4024 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4029 if (*max_regs
< fc
->ncols
)
4030 *max_regs
= fc
->ncols
;
4032 if (*need_col_headers
)
4034 static const char *sloc
= " LOC";
4036 *need_col_headers
= 0;
4038 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4040 for (r
= 0; r
< *max_regs
; r
++)
4041 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4046 printf ("%-5s ", regname (r
, 1));
4052 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4054 strcpy (tmp
, "exp");
4056 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4057 printf ("%-8s ", tmp
);
4059 for (r
= 0; r
< fc
->ncols
; r
++)
4061 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4063 switch (fc
->col_type
[r
])
4065 case DW_CFA_undefined
:
4068 case DW_CFA_same_value
:
4072 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4074 case DW_CFA_val_offset
:
4075 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4077 case DW_CFA_register
:
4078 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4080 case DW_CFA_expression
:
4081 strcpy (tmp
, "exp");
4083 case DW_CFA_val_expression
:
4084 strcpy (tmp
, "vexp");
4087 strcpy (tmp
, "n/a");
4090 printf ("%-5s ", tmp
);
4096 #define GET(N) byte_get (start, N); start += N
4097 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4098 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
4101 display_debug_frames (struct dwarf_section
*section
,
4102 void *file ATTRIBUTE_UNUSED
)
4104 unsigned char *start
= section
->start
;
4105 unsigned char *end
= start
+ section
->size
;
4106 unsigned char *section_start
= start
;
4107 Frame_Chunk
*chunks
= 0;
4108 Frame_Chunk
*remembered_state
= 0;
4110 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4111 unsigned int length_return
;
4113 const char *bad_reg
= _("bad register: ");
4114 int saved_eh_addr_size
= eh_addr_size
;
4116 printf (_("Contents of the %s section:\n"), section
->name
);
4120 unsigned char *saved_start
;
4121 unsigned char *block_end
;
4122 unsigned long length
;
4123 unsigned long cie_id
;
4126 int need_col_headers
= 1;
4127 unsigned char *augmentation_data
= NULL
;
4128 unsigned long augmentation_data_len
= 0;
4129 int encoded_ptr_size
= saved_eh_addr_size
;
4131 int initial_length_size
;
4133 saved_start
= start
;
4134 length
= byte_get (start
, 4); start
+= 4;
4138 printf ("\n%08lx ZERO terminator\n\n",
4139 (unsigned long)(saved_start
- section_start
));
4143 if (length
== 0xffffffff)
4145 length
= byte_get (start
, 8);
4148 initial_length_size
= 12;
4153 initial_length_size
= 4;
4156 block_end
= saved_start
+ length
+ initial_length_size
;
4157 if (block_end
> end
)
4159 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4160 length
, (unsigned long)(saved_start
- section_start
));
4163 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4165 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4169 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4170 memset (fc
, 0, sizeof (Frame_Chunk
));
4174 fc
->chunk_start
= saved_start
;
4176 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4177 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4178 frame_need_space (fc
, max_regs
- 1);
4182 fc
->augmentation
= (char *) start
;
4183 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4185 if (strcmp (fc
->augmentation
, "eh") == 0)
4186 start
+= eh_addr_size
;
4190 fc
->ptr_size
= GET (1);
4191 fc
->segment_size
= GET (1);
4192 eh_addr_size
= fc
->ptr_size
;
4196 fc
->ptr_size
= eh_addr_size
;
4197 fc
->segment_size
= 0;
4199 fc
->code_factor
= LEB ();
4200 fc
->data_factor
= SLEB ();
4210 if (fc
->augmentation
[0] == 'z')
4212 augmentation_data_len
= LEB ();
4213 augmentation_data
= start
;
4214 start
+= augmentation_data_len
;
4218 if (do_debug_frames_interp
)
4219 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4220 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4221 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4225 printf ("\n%08lx %08lx %08lx CIE\n",
4226 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4227 printf (" Version: %d\n", version
);
4228 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4231 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4232 printf (" Segment Size: %u\n", fc
->segment_size
);
4234 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4235 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4236 printf (" Return address column: %d\n", fc
->ra
);
4238 if (augmentation_data_len
)
4241 printf (" Augmentation data: ");
4242 for (i
= 0; i
< augmentation_data_len
; ++i
)
4243 printf (" %02x", augmentation_data
[i
]);
4249 if (augmentation_data_len
)
4251 unsigned char *p
, *q
;
4252 p
= (unsigned char *) fc
->augmentation
+ 1;
4253 q
= augmentation_data
;
4260 q
+= 1 + size_of_encoded_value (*q
);
4262 fc
->fde_encoding
= *q
++;
4270 if (fc
->fde_encoding
)
4271 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4274 frame_need_space (fc
, fc
->ra
);
4278 unsigned char *look_for
;
4279 static Frame_Chunk fde_fc
;
4280 unsigned long segment_selector
;
4283 memset (fc
, 0, sizeof (Frame_Chunk
));
4285 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4287 for (cie
= chunks
; cie
; cie
= cie
->next
)
4288 if (cie
->chunk_start
== look_for
)
4293 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4294 cie_id
, (unsigned long)(saved_start
- section_start
));
4296 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4297 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4298 frame_need_space (fc
, max_regs
- 1);
4300 fc
->augmentation
= "";
4301 fc
->fde_encoding
= 0;
4302 fc
->ptr_size
= eh_addr_size
;
4303 fc
->segment_size
= 0;
4307 fc
->ncols
= cie
->ncols
;
4308 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4309 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4310 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4311 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4312 fc
->augmentation
= cie
->augmentation
;
4313 fc
->ptr_size
= cie
->ptr_size
;
4314 eh_addr_size
= cie
->ptr_size
;
4315 fc
->segment_size
= cie
->segment_size
;
4316 fc
->code_factor
= cie
->code_factor
;
4317 fc
->data_factor
= cie
->data_factor
;
4318 fc
->cfa_reg
= cie
->cfa_reg
;
4319 fc
->cfa_offset
= cie
->cfa_offset
;
4321 frame_need_space (fc
, max_regs
- 1);
4322 fc
->fde_encoding
= cie
->fde_encoding
;
4325 if (fc
->fde_encoding
)
4326 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4328 segment_selector
= 0;
4329 if (fc
->segment_size
)
4331 segment_selector
= byte_get (start
, fc
->segment_size
);
4332 start
+= fc
->segment_size
;
4334 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
);
4335 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4336 fc
->pc_begin
+= section
->address
+ (start
- section_start
);
4337 start
+= encoded_ptr_size
;
4338 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4339 start
+= encoded_ptr_size
;
4341 if (cie
->augmentation
[0] == 'z')
4343 augmentation_data_len
= LEB ();
4344 augmentation_data
= start
;
4345 start
+= augmentation_data_len
;
4348 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4349 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4350 (unsigned long)(cie
->chunk_start
- section_start
));
4351 if (fc
->segment_size
)
4352 printf ("%04lx:", segment_selector
);
4353 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4354 if (! do_debug_frames_interp
&& augmentation_data_len
)
4358 printf (" Augmentation data: ");
4359 for (i
= 0; i
< augmentation_data_len
; ++i
)
4360 printf (" %02x", augmentation_data
[i
]);
4366 /* At this point, fc is the current chunk, cie (if any) is set, and
4367 we're about to interpret instructions for the chunk. */
4368 /* ??? At present we need to do this always, since this sizes the
4369 fc->col_type and fc->col_offset arrays, which we write into always.
4370 We should probably split the interpreted and non-interpreted bits
4371 into two different routines, since there's so much that doesn't
4372 really overlap between them. */
4373 if (1 || do_debug_frames_interp
)
4375 /* Start by making a pass over the chunk, allocating storage
4376 and taking note of what registers are used. */
4377 unsigned char *tmp
= start
;
4379 while (start
< block_end
)
4382 unsigned long reg
, temp
;
4389 /* Warning: if you add any more cases to this switch, be
4390 sure to add them to the corresponding switch below. */
4393 case DW_CFA_advance_loc
:
4397 if (frame_need_space (fc
, opa
) >= 0)
4398 fc
->col_type
[opa
] = DW_CFA_undefined
;
4400 case DW_CFA_restore
:
4401 if (frame_need_space (fc
, opa
) >= 0)
4402 fc
->col_type
[opa
] = DW_CFA_undefined
;
4404 case DW_CFA_set_loc
:
4405 start
+= encoded_ptr_size
;
4407 case DW_CFA_advance_loc1
:
4410 case DW_CFA_advance_loc2
:
4413 case DW_CFA_advance_loc4
:
4416 case DW_CFA_offset_extended
:
4417 case DW_CFA_val_offset
:
4418 reg
= LEB (); LEB ();
4419 if (frame_need_space (fc
, reg
) >= 0)
4420 fc
->col_type
[reg
] = DW_CFA_undefined
;
4422 case DW_CFA_restore_extended
:
4424 frame_need_space (fc
, reg
);
4425 if (frame_need_space (fc
, reg
) >= 0)
4426 fc
->col_type
[reg
] = DW_CFA_undefined
;
4428 case DW_CFA_undefined
:
4430 if (frame_need_space (fc
, reg
) >= 0)
4431 fc
->col_type
[reg
] = DW_CFA_undefined
;
4433 case DW_CFA_same_value
:
4435 if (frame_need_space (fc
, reg
) >= 0)
4436 fc
->col_type
[reg
] = DW_CFA_undefined
;
4438 case DW_CFA_register
:
4439 reg
= LEB (); LEB ();
4440 if (frame_need_space (fc
, reg
) >= 0)
4441 fc
->col_type
[reg
] = DW_CFA_undefined
;
4443 case DW_CFA_def_cfa
:
4446 case DW_CFA_def_cfa_register
:
4449 case DW_CFA_def_cfa_offset
:
4452 case DW_CFA_def_cfa_expression
:
4456 case DW_CFA_expression
:
4457 case DW_CFA_val_expression
:
4461 if (frame_need_space (fc
, reg
) >= 0)
4462 fc
->col_type
[reg
] = DW_CFA_undefined
;
4464 case DW_CFA_offset_extended_sf
:
4465 case DW_CFA_val_offset_sf
:
4466 reg
= LEB (); SLEB ();
4467 if (frame_need_space (fc
, reg
) >= 0)
4468 fc
->col_type
[reg
] = DW_CFA_undefined
;
4470 case DW_CFA_def_cfa_sf
:
4473 case DW_CFA_def_cfa_offset_sf
:
4476 case DW_CFA_MIPS_advance_loc8
:
4479 case DW_CFA_GNU_args_size
:
4482 case DW_CFA_GNU_negative_offset_extended
:
4483 reg
= LEB (); LEB ();
4484 if (frame_need_space (fc
, reg
) >= 0)
4485 fc
->col_type
[reg
] = DW_CFA_undefined
;
4494 /* Now we know what registers are used, make a second pass over
4495 the chunk, this time actually printing out the info. */
4497 while (start
< block_end
)
4500 unsigned long ul
, reg
, roffs
;
4503 const char *reg_prefix
= "";
4510 /* Warning: if you add any more cases to this switch, be
4511 sure to add them to the corresponding switch above. */
4514 case DW_CFA_advance_loc
:
4515 if (do_debug_frames_interp
)
4516 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4518 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4519 opa
* fc
->code_factor
,
4520 fc
->pc_begin
+ opa
* fc
->code_factor
);
4521 fc
->pc_begin
+= opa
* fc
->code_factor
;
4526 if (opa
>= (unsigned int) fc
->ncols
)
4527 reg_prefix
= bad_reg
;
4528 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4529 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4530 reg_prefix
, regname (opa
, 0),
4531 roffs
* fc
->data_factor
);
4532 if (*reg_prefix
== '\0')
4534 fc
->col_type
[opa
] = DW_CFA_offset
;
4535 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4539 case DW_CFA_restore
:
4540 if (opa
>= (unsigned int) cie
->ncols
4541 || opa
>= (unsigned int) fc
->ncols
)
4542 reg_prefix
= bad_reg
;
4543 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4544 printf (" DW_CFA_restore: %s%s\n",
4545 reg_prefix
, regname (opa
, 0));
4546 if (*reg_prefix
== '\0')
4548 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4549 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4553 case DW_CFA_set_loc
:
4554 vma
= get_encoded_value (start
, fc
->fde_encoding
);
4555 if ((fc
->fde_encoding
& 0x70) == DW_EH_PE_pcrel
)
4556 vma
+= section
->address
+ (start
- section_start
);
4557 start
+= encoded_ptr_size
;
4558 if (do_debug_frames_interp
)
4559 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4561 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4565 case DW_CFA_advance_loc1
:
4566 ofs
= byte_get (start
, 1); start
+= 1;
4567 if (do_debug_frames_interp
)
4568 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4570 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4571 ofs
* fc
->code_factor
,
4572 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4573 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4576 case DW_CFA_advance_loc2
:
4577 ofs
= byte_get (start
, 2); start
+= 2;
4578 if (do_debug_frames_interp
)
4579 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4581 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4582 ofs
* fc
->code_factor
,
4583 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4584 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4587 case DW_CFA_advance_loc4
:
4588 ofs
= byte_get (start
, 4); start
+= 4;
4589 if (do_debug_frames_interp
)
4590 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4592 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4593 ofs
* fc
->code_factor
,
4594 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4595 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4598 case DW_CFA_offset_extended
:
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_offset_extended: %s%s at cfa%+ld\n",
4605 reg_prefix
, regname (reg
, 0),
4606 roffs
* fc
->data_factor
);
4607 if (*reg_prefix
== '\0')
4609 fc
->col_type
[reg
] = DW_CFA_offset
;
4610 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4614 case DW_CFA_val_offset
:
4617 if (reg
>= (unsigned int) fc
->ncols
)
4618 reg_prefix
= bad_reg
;
4619 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4620 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4621 reg_prefix
, regname (reg
, 0),
4622 roffs
* fc
->data_factor
);
4623 if (*reg_prefix
== '\0')
4625 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4626 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4630 case DW_CFA_restore_extended
:
4632 if (reg
>= (unsigned int) cie
->ncols
4633 || reg
>= (unsigned int) fc
->ncols
)
4634 reg_prefix
= bad_reg
;
4635 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4636 printf (" DW_CFA_restore_extended: %s%s\n",
4637 reg_prefix
, regname (reg
, 0));
4638 if (*reg_prefix
== '\0')
4640 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4641 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4645 case DW_CFA_undefined
:
4647 if (reg
>= (unsigned int) fc
->ncols
)
4648 reg_prefix
= bad_reg
;
4649 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4650 printf (" DW_CFA_undefined: %s%s\n",
4651 reg_prefix
, regname (reg
, 0));
4652 if (*reg_prefix
== '\0')
4654 fc
->col_type
[reg
] = DW_CFA_undefined
;
4655 fc
->col_offset
[reg
] = 0;
4659 case DW_CFA_same_value
:
4661 if (reg
>= (unsigned int) fc
->ncols
)
4662 reg_prefix
= bad_reg
;
4663 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4664 printf (" DW_CFA_same_value: %s%s\n",
4665 reg_prefix
, regname (reg
, 0));
4666 if (*reg_prefix
== '\0')
4668 fc
->col_type
[reg
] = DW_CFA_same_value
;
4669 fc
->col_offset
[reg
] = 0;
4673 case DW_CFA_register
:
4676 if (reg
>= (unsigned int) fc
->ncols
)
4677 reg_prefix
= bad_reg
;
4678 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4680 printf (" DW_CFA_register: %s%s in ",
4681 reg_prefix
, regname (reg
, 0));
4682 puts (regname (roffs
, 0));
4684 if (*reg_prefix
== '\0')
4686 fc
->col_type
[reg
] = DW_CFA_register
;
4687 fc
->col_offset
[reg
] = roffs
;
4691 case DW_CFA_remember_state
:
4692 if (! do_debug_frames_interp
)
4693 printf (" DW_CFA_remember_state\n");
4694 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4695 rs
->ncols
= fc
->ncols
;
4696 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
4697 sizeof (short int));
4698 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
4699 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
4700 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
4701 rs
->next
= remembered_state
;
4702 remembered_state
= rs
;
4705 case DW_CFA_restore_state
:
4706 if (! do_debug_frames_interp
)
4707 printf (" DW_CFA_restore_state\n");
4708 rs
= remembered_state
;
4711 remembered_state
= rs
->next
;
4712 frame_need_space (fc
, rs
->ncols
- 1);
4713 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
4714 memcpy (fc
->col_offset
, rs
->col_offset
,
4715 rs
->ncols
* sizeof (int));
4716 free (rs
->col_type
);
4717 free (rs
->col_offset
);
4720 else if (do_debug_frames_interp
)
4721 printf ("Mismatched DW_CFA_restore_state\n");
4724 case DW_CFA_def_cfa
:
4725 fc
->cfa_reg
= LEB ();
4726 fc
->cfa_offset
= LEB ();
4728 if (! do_debug_frames_interp
)
4729 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4730 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4733 case DW_CFA_def_cfa_register
:
4734 fc
->cfa_reg
= LEB ();
4736 if (! do_debug_frames_interp
)
4737 printf (" DW_CFA_def_cfa_register: %s\n",
4738 regname (fc
->cfa_reg
, 0));
4741 case DW_CFA_def_cfa_offset
:
4742 fc
->cfa_offset
= LEB ();
4743 if (! do_debug_frames_interp
)
4744 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
4748 if (! do_debug_frames_interp
)
4749 printf (" DW_CFA_nop\n");
4752 case DW_CFA_def_cfa_expression
:
4754 if (! do_debug_frames_interp
)
4756 printf (" DW_CFA_def_cfa_expression (");
4757 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4765 case DW_CFA_expression
:
4768 if (reg
>= (unsigned int) fc
->ncols
)
4769 reg_prefix
= bad_reg
;
4770 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4772 printf (" DW_CFA_expression: %s%s (",
4773 reg_prefix
, regname (reg
, 0));
4774 decode_location_expression (start
, eh_addr_size
,
4778 if (*reg_prefix
== '\0')
4779 fc
->col_type
[reg
] = DW_CFA_expression
;
4783 case DW_CFA_val_expression
:
4786 if (reg
>= (unsigned int) fc
->ncols
)
4787 reg_prefix
= bad_reg
;
4788 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4790 printf (" DW_CFA_val_expression: %s%s (",
4791 reg_prefix
, regname (reg
, 0));
4792 decode_location_expression (start
, eh_addr_size
, ul
, 0,
4796 if (*reg_prefix
== '\0')
4797 fc
->col_type
[reg
] = DW_CFA_val_expression
;
4801 case DW_CFA_offset_extended_sf
:
4804 if (frame_need_space (fc
, reg
) < 0)
4805 reg_prefix
= bad_reg
;
4806 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4807 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4808 reg_prefix
, regname (reg
, 0),
4809 l
* fc
->data_factor
);
4810 if (*reg_prefix
== '\0')
4812 fc
->col_type
[reg
] = DW_CFA_offset
;
4813 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4817 case DW_CFA_val_offset_sf
:
4820 if (frame_need_space (fc
, reg
) < 0)
4821 reg_prefix
= bad_reg
;
4822 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4823 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4824 reg_prefix
, regname (reg
, 0),
4825 l
* fc
->data_factor
);
4826 if (*reg_prefix
== '\0')
4828 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4829 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4833 case DW_CFA_def_cfa_sf
:
4834 fc
->cfa_reg
= LEB ();
4835 fc
->cfa_offset
= SLEB ();
4836 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4838 if (! do_debug_frames_interp
)
4839 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4840 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
4843 case DW_CFA_def_cfa_offset_sf
:
4844 fc
->cfa_offset
= SLEB ();
4845 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
4846 if (! do_debug_frames_interp
)
4847 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
4850 case DW_CFA_MIPS_advance_loc8
:
4851 ofs
= byte_get (start
, 8); start
+= 8;
4852 if (do_debug_frames_interp
)
4853 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4855 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4856 ofs
* fc
->code_factor
,
4857 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4858 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4861 case DW_CFA_GNU_window_save
:
4862 if (! do_debug_frames_interp
)
4863 printf (" DW_CFA_GNU_window_save\n");
4866 case DW_CFA_GNU_args_size
:
4868 if (! do_debug_frames_interp
)
4869 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
4872 case DW_CFA_GNU_negative_offset_extended
:
4875 if (frame_need_space (fc
, reg
) < 0)
4876 reg_prefix
= bad_reg
;
4877 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4878 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4879 reg_prefix
, regname (reg
, 0),
4880 l
* fc
->data_factor
);
4881 if (*reg_prefix
== '\0')
4883 fc
->col_type
[reg
] = DW_CFA_offset
;
4884 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
4889 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
4890 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
4892 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
4897 if (do_debug_frames_interp
)
4898 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4901 eh_addr_size
= saved_eh_addr_size
;
4914 display_debug_not_supported (struct dwarf_section
*section
,
4915 void *file ATTRIBUTE_UNUSED
)
4917 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4924 cmalloc (size_t nmemb
, size_t size
)
4926 /* Check for overflow. */
4927 if (nmemb
>= ~(size_t) 0 / size
)
4930 return malloc (nmemb
* size
);
4934 xcmalloc (size_t nmemb
, size_t size
)
4936 /* Check for overflow. */
4937 if (nmemb
>= ~(size_t) 0 / size
)
4940 return xmalloc (nmemb
* size
);
4944 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
4946 /* Check for overflow. */
4947 if (nmemb
>= ~(size_t) 0 / size
)
4950 return xrealloc (ptr
, nmemb
* size
);
4954 error (const char *message
, ...)
4958 va_start (args
, message
);
4959 fprintf (stderr
, _("%s: Error: "), program_name
);
4960 vfprintf (stderr
, message
, args
);
4965 warn (const char *message
, ...)
4969 va_start (args
, message
);
4970 fprintf (stderr
, _("%s: Warning: "), program_name
);
4971 vfprintf (stderr
, message
, args
);
4976 free_debug_memory (void)
4982 for (i
= 0; i
< max
; i
++)
4983 free_debug_section ((enum dwarf_section_display_enum
) i
);
4985 if (debug_information
!= NULL
)
4987 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
4989 for (i
= 0; i
< num_debug_info_entries
; i
++)
4991 if (!debug_information
[i
].max_loc_offsets
)
4993 free (debug_information
[i
].loc_offsets
);
4994 free (debug_information
[i
].have_frame_base
);
4996 if (!debug_information
[i
].max_range_lists
)
4997 free (debug_information
[i
].range_lists
);
5001 free (debug_information
);
5002 debug_information
= NULL
;
5003 num_debug_info_entries
= 0;
5008 dwarf_select_sections_by_names (const char *names
)
5012 const char * option
;
5016 debug_dump_long_opts
;
5018 static const debug_dump_long_opts opts_table
[] =
5020 /* Please keep this table alpha- sorted. */
5021 { "Ranges", & do_debug_ranges
, 1 },
5022 { "abbrev", & do_debug_abbrevs
, 1 },
5023 { "aranges", & do_debug_aranges
, 1 },
5024 { "frames", & do_debug_frames
, 1 },
5025 { "frames-interp", & do_debug_frames_interp
, 1 },
5026 { "info", & do_debug_info
, 1 },
5027 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5028 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5029 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5030 { "loc", & do_debug_loc
, 1 },
5031 { "macro", & do_debug_macinfo
, 1 },
5032 { "pubnames", & do_debug_pubnames
, 1 },
5033 { "pubtypes", & do_debug_pubtypes
, 1 },
5034 /* This entry is for compatability
5035 with earlier versions of readelf. */
5036 { "ranges", & do_debug_aranges
, 1 },
5037 { "str", & do_debug_str
, 1 },
5046 const debug_dump_long_opts
* entry
;
5048 for (entry
= opts_table
; entry
->option
; entry
++)
5050 size_t len
= strlen (entry
->option
);
5052 if (strncmp (p
, entry
->option
, len
) == 0
5053 && (p
[len
] == ',' || p
[len
] == '\0'))
5055 * entry
->variable
|= entry
->val
;
5057 /* The --debug-dump=frames-interp option also
5058 enables the --debug-dump=frames option. */
5059 if (do_debug_frames_interp
)
5060 do_debug_frames
= 1;
5067 if (entry
->option
== NULL
)
5069 warn (_("Unrecognized debug option '%s'\n"), p
);
5070 p
= strchr (p
, ',');
5081 dwarf_select_sections_by_letters (const char *letters
)
5083 unsigned int lindex
= 0;
5085 while (letters
[lindex
])
5086 switch (letters
[lindex
++])
5093 do_debug_abbrevs
= 1;
5097 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5101 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5105 do_debug_pubnames
= 1;
5109 do_debug_pubtypes
= 1;
5113 do_debug_aranges
= 1;
5117 do_debug_ranges
= 1;
5121 do_debug_frames_interp
= 1;
5123 do_debug_frames
= 1;
5127 do_debug_macinfo
= 1;
5139 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5145 dwarf_select_sections_all (void)
5148 do_debug_abbrevs
= 1;
5149 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5150 do_debug_pubnames
= 1;
5151 do_debug_pubtypes
= 1;
5152 do_debug_aranges
= 1;
5153 do_debug_ranges
= 1;
5154 do_debug_frames
= 1;
5155 do_debug_macinfo
= 1;
5160 struct dwarf_section_display debug_displays
[] =
5162 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5163 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5164 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5165 display_debug_aranges
, &do_debug_aranges
, 1 },
5166 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5167 display_debug_frames
, &do_debug_frames
, 1 },
5168 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5169 display_debug_info
, &do_debug_info
, 1 },
5170 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5171 display_debug_lines
, &do_debug_lines
, 1 },
5172 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5173 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5174 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5175 display_debug_frames
, &do_debug_frames
, 1 },
5176 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5177 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5178 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5179 display_debug_str
, &do_debug_str
, 0 },
5180 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5181 display_debug_loc
, &do_debug_loc
, 1 },
5182 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5183 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5184 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5185 display_debug_ranges
, &do_debug_ranges
, 1 },
5186 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5187 display_debug_not_supported
, NULL
, 0 },
5188 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5189 display_debug_not_supported
, NULL
, 0 },
5190 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5191 display_debug_types
, &do_debug_info
, 1 },
5192 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5193 display_debug_not_supported
, NULL
, 0 }