1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
25 #include "bfd_stdint.h"
28 #include "elf/common.h"
32 static const char *regname (unsigned int regno
, int row
);
34 static int have_frame_base
;
35 static int need_base_address
;
37 static unsigned int last_pointer_size
= 0;
38 static int warned_about_missing_comp_units
= FALSE
;
40 static unsigned int num_debug_info_entries
= 0;
41 static debug_info
*debug_information
= NULL
;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 int do_debug_pubnames
;
52 int do_debug_pubtypes
;
56 int do_debug_frames_interp
;
66 int dwarf_cutoff_level
= -1;
67 unsigned long dwarf_start_die
;
69 /* Values for do_debug_lines. */
70 #define FLAG_DEBUG_LINES_RAW 1
71 #define FLAG_DEBUG_LINES_DECODED 2
74 size_of_encoded_value (int encoding
)
76 switch (encoding
& 0x7)
79 case 0: return eh_addr_size
;
87 get_encoded_value (unsigned char *data
,
89 struct dwarf_section
*section
)
91 int size
= size_of_encoded_value (encoding
);
94 if (encoding
& DW_EH_PE_signed
)
95 val
= byte_get_signed (data
, size
);
97 val
= byte_get (data
, size
);
99 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
100 val
+= section
->address
+ (data
- section
->start
);
104 /* Print a dwarf_vma value (typically an address, offset or length) in
105 hexadecimal format, followed by a space. The length of the value (and
106 hence the precision displayed) is determined by the byte_size parameter. */
109 print_dwarf_vma (dwarf_vma val
, unsigned byte_size
)
111 static char buff
[18];
114 /* Printf does not have a way of specifiying a maximum field width for an
115 integer value, so we print the full value into a buffer and then select
116 the precision we need. */
117 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
119 snprintf (buff
, sizeof (buff
), "%16.16llx ", val
);
121 snprintf (buff
, sizeof (buff
), "%016I64x ", val
);
124 snprintf (buff
, sizeof (buff
), "%16.16lx ", val
);
129 if (byte_size
> 0 && byte_size
<= 8)
130 offset
= 16 - 2 * byte_size
;
132 error (_("Wrong size in print_dwarf_vma"));
135 fputs (buff
+ offset
, stdout
);
138 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
140 #define DWARF_VMA_FMT "ll"
142 #define DWARF_VMA_FMT "I64"
145 #define DWARF_VMA_FMT "l"
149 dwarf_vmatoa (const char *fmtch
, dwarf_vma value
)
151 /* As dwarf_vmatoa is used more then once in a printf call
152 for output, we are cycling through an fixed array of pointers
153 for return address. */
154 static int buf_pos
= 0;
155 static struct dwarf_vmatoa_buf
162 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
164 ret
= buf
[buf_pos
++].place
;
165 buf_pos
%= ARRAY_SIZE (buf
);
167 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
172 /* Format a 64-bit value, given as two 32-bit values, in hex.
173 For reentrancy, this uses a buffer provided by the caller. */
176 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
177 unsigned int buf_len
)
182 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
185 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
186 snprintf (buf
+ len
, buf_len
- len
,
187 "%08" DWARF_VMA_FMT
"x", lvalue
);
194 read_leb128 (unsigned char *data
, unsigned int *length_return
, int sign
)
196 dwarf_vma result
= 0;
197 unsigned int num_read
= 0;
198 unsigned int shift
= 0;
206 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
213 if (length_return
!= NULL
)
214 *length_return
= num_read
;
216 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
217 result
|= -1L << shift
;
222 /* Create a signed version to avoid painful typecasts. */
223 static dwarf_signed_vma
224 read_sleb128 (unsigned char *data
, unsigned int *length_return
)
226 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, 1);
229 typedef struct State_Machine_Registers
237 unsigned char op_index
;
238 unsigned char end_sequence
;
239 /* This variable hold the number of the last entry seen
240 in the File Table. */
241 unsigned int last_file_entry
;
244 static SMR state_machine_regs
;
247 reset_state_machine (int is_stmt
)
249 state_machine_regs
.address
= 0;
250 state_machine_regs
.op_index
= 0;
251 state_machine_regs
.file
= 1;
252 state_machine_regs
.line
= 1;
253 state_machine_regs
.column
= 0;
254 state_machine_regs
.is_stmt
= is_stmt
;
255 state_machine_regs
.basic_block
= 0;
256 state_machine_regs
.end_sequence
= 0;
257 state_machine_regs
.last_file_entry
= 0;
260 /* Handled an extend line op.
261 Returns the number of bytes read. */
264 process_extended_line_op (unsigned char *data
, int is_stmt
)
266 unsigned char op_code
;
267 unsigned int bytes_read
;
271 unsigned char *orig_data
= data
;
273 len
= read_leb128 (data
, & bytes_read
, 0);
278 warn (_("badly formed extended line op encountered!\n"));
285 printf (_(" Extended opcode %d: "), op_code
);
289 case DW_LNE_end_sequence
:
290 printf (_("End of Sequence\n\n"));
291 reset_state_machine (is_stmt
);
294 case DW_LNE_set_address
:
295 adr
= byte_get (data
, len
- bytes_read
- 1);
296 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
297 state_machine_regs
.address
= adr
;
298 state_machine_regs
.op_index
= 0;
301 case DW_LNE_define_file
:
302 printf (_("define new File Table entry\n"));
303 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
305 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
307 data
+= strlen ((char *) data
) + 1;
308 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
310 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
312 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
315 if ((unsigned int) (data
- orig_data
) != len
)
316 printf (_(" [Bad opcode length]"));
320 case DW_LNE_set_discriminator
:
321 printf (_("set Discriminator to %s\n"),
322 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
326 case DW_LNE_HP_negate_is_UV_update
:
327 printf ("DW_LNE_HP_negate_is_UV_update\n");
329 case DW_LNE_HP_push_context
:
330 printf ("DW_LNE_HP_push_context\n");
332 case DW_LNE_HP_pop_context
:
333 printf ("DW_LNE_HP_pop_context\n");
335 case DW_LNE_HP_set_file_line_column
:
336 printf ("DW_LNE_HP_set_file_line_column\n");
338 case DW_LNE_HP_set_routine_name
:
339 printf ("DW_LNE_HP_set_routine_name\n");
341 case DW_LNE_HP_set_sequence
:
342 printf ("DW_LNE_HP_set_sequence\n");
344 case DW_LNE_HP_negate_post_semantics
:
345 printf ("DW_LNE_HP_negate_post_semantics\n");
347 case DW_LNE_HP_negate_function_exit
:
348 printf ("DW_LNE_HP_negate_function_exit\n");
350 case DW_LNE_HP_negate_front_end_logical
:
351 printf ("DW_LNE_HP_negate_front_end_logical\n");
353 case DW_LNE_HP_define_proc
:
354 printf ("DW_LNE_HP_define_proc\n");
356 case DW_LNE_HP_source_file_correlation
:
358 unsigned char *edata
= data
+ len
- bytes_read
- 1;
360 printf ("DW_LNE_HP_source_file_correlation\n");
366 opc
= read_leb128 (data
, & bytes_read
, 0);
371 case DW_LNE_HP_SFC_formfeed
:
372 printf (" DW_LNE_HP_SFC_formfeed\n");
374 case DW_LNE_HP_SFC_set_listing_line
:
375 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
377 read_leb128 (data
, & bytes_read
, 0)));
380 case DW_LNE_HP_SFC_associate
:
381 printf (" DW_LNE_HP_SFC_associate ");
384 read_leb128 (data
, & bytes_read
, 0)));
388 read_leb128 (data
, & bytes_read
, 0)));
392 read_leb128 (data
, & bytes_read
, 0)));
396 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
406 unsigned int rlen
= len
- bytes_read
- 1;
408 if (op_code
>= DW_LNE_lo_user
409 /* The test against DW_LNW_hi_user is redundant due to
410 the limited range of the unsigned char data type used
412 /*&& op_code <= DW_LNE_hi_user*/)
413 printf (_("user defined: "));
415 printf (_("UNKNOWN: "));
416 printf (_("length %d ["), rlen
);
418 printf (" %02x", *data
++);
428 fetch_indirect_string (dwarf_vma offset
)
430 struct dwarf_section
*section
= &debug_displays
[str
].section
;
432 if (section
->start
== NULL
)
433 return _("<no .debug_str section>");
435 /* DWARF sections under Mach-O have non-zero addresses. */
436 offset
-= section
->address
;
437 if (offset
> section
->size
)
439 warn (_("DW_FORM_strp offset too big: %s\n"),
440 dwarf_vmatoa ("x", offset
));
441 return _("<offset is too big>");
444 return (const char *) section
->start
+ offset
;
447 /* FIXME: There are better and more efficient ways to handle
448 these structures. For now though, I just want something that
449 is simple to implement. */
450 typedef struct abbrev_attr
452 unsigned long attribute
;
454 struct abbrev_attr
*next
;
458 typedef struct abbrev_entry
463 struct abbrev_attr
*first_attr
;
464 struct abbrev_attr
*last_attr
;
465 struct abbrev_entry
*next
;
469 static abbrev_entry
*first_abbrev
= NULL
;
470 static abbrev_entry
*last_abbrev
= NULL
;
477 for (abbrv
= first_abbrev
; abbrv
;)
479 abbrev_entry
*next_abbrev
= abbrv
->next
;
482 for (attr
= abbrv
->first_attr
; attr
;)
484 abbrev_attr
*next_attr
= attr
->next
;
494 last_abbrev
= first_abbrev
= NULL
;
498 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
502 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
507 entry
->entry
= number
;
509 entry
->children
= children
;
510 entry
->first_attr
= NULL
;
511 entry
->last_attr
= NULL
;
514 if (first_abbrev
== NULL
)
515 first_abbrev
= entry
;
517 last_abbrev
->next
= entry
;
523 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
527 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
532 attr
->attribute
= attribute
;
536 if (last_abbrev
->first_attr
== NULL
)
537 last_abbrev
->first_attr
= attr
;
539 last_abbrev
->last_attr
->next
= attr
;
541 last_abbrev
->last_attr
= attr
;
544 /* Processes the (partial) contents of a .debug_abbrev section.
545 Returns NULL if the end of the section was encountered.
546 Returns the address after the last byte read if the end of
547 an abbreviation set was found. */
549 static unsigned char *
550 process_abbrev_section (unsigned char *start
, unsigned char *end
)
552 if (first_abbrev
!= NULL
)
557 unsigned int bytes_read
;
560 unsigned long attribute
;
563 entry
= read_leb128 (start
, & bytes_read
, 0);
566 /* A single zero is supposed to end the section according
567 to the standard. If there's more, then signal that to
570 return start
== end
? NULL
: start
;
572 tag
= read_leb128 (start
, & bytes_read
, 0);
577 add_abbrev (entry
, tag
, children
);
583 attribute
= read_leb128 (start
, & bytes_read
, 0);
586 form
= read_leb128 (start
, & bytes_read
, 0);
590 add_abbrev_attr (attribute
, form
);
592 while (attribute
!= 0);
599 get_TAG_name (unsigned long tag
)
601 const char *name
= get_DW_TAG_name (tag
);
605 static char buffer
[100];
607 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
615 get_FORM_name (unsigned long form
)
617 const char *name
= get_DW_FORM_name (form
);
621 static char buffer
[100];
623 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
630 static unsigned char *
631 display_block (unsigned char *data
, dwarf_vma length
)
633 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
636 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
642 decode_location_expression (unsigned char * data
,
643 unsigned int pointer_size
,
644 unsigned int offset_size
,
648 struct dwarf_section
* section
)
651 unsigned int bytes_read
;
653 unsigned char *end
= data
+ length
;
654 int need_frame_base
= 0;
663 printf ("DW_OP_addr: %s",
664 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
665 data
+= pointer_size
;
668 printf ("DW_OP_deref");
671 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data
++, 1));
674 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data
++, 1));
677 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data
, 2));
681 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data
, 2));
685 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data
, 4));
689 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data
, 4));
693 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data
, 4),
694 (unsigned long) byte_get (data
+ 4, 4));
698 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data
, 4),
699 (long) byte_get (data
+ 4, 4));
703 printf ("DW_OP_constu: %s",
704 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
708 printf ("DW_OP_consts: %s",
709 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
713 printf ("DW_OP_dup");
716 printf ("DW_OP_drop");
719 printf ("DW_OP_over");
722 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data
++, 1));
725 printf ("DW_OP_swap");
728 printf ("DW_OP_rot");
731 printf ("DW_OP_xderef");
734 printf ("DW_OP_abs");
737 printf ("DW_OP_and");
740 printf ("DW_OP_div");
743 printf ("DW_OP_minus");
746 printf ("DW_OP_mod");
749 printf ("DW_OP_mul");
752 printf ("DW_OP_neg");
755 printf ("DW_OP_not");
761 printf ("DW_OP_plus");
763 case DW_OP_plus_uconst
:
764 printf ("DW_OP_plus_uconst: %s",
765 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
769 printf ("DW_OP_shl");
772 printf ("DW_OP_shr");
775 printf ("DW_OP_shra");
778 printf ("DW_OP_xor");
781 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data
, 2));
803 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data
, 2));
839 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
874 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
875 regname (op
- DW_OP_reg0
, 1));
910 printf ("DW_OP_breg%d (%s): %s",
912 regname (op
- DW_OP_breg0
, 1),
913 dwarf_vmatoa ("d", (dwarf_signed_vma
)
914 read_leb128 (data
, &bytes_read
, 1)));
919 uvalue
= read_leb128 (data
, &bytes_read
, 0);
921 printf ("DW_OP_regx: %s (%s)",
922 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
926 printf ("DW_OP_fbreg: %s",
927 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
931 uvalue
= read_leb128 (data
, &bytes_read
, 0);
933 printf ("DW_OP_bregx: %s (%s) %s",
934 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
935 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
)));
939 printf ("DW_OP_piece: %s",
940 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
943 case DW_OP_deref_size
:
944 printf ("DW_OP_deref_size: %ld", (long) byte_get (data
++, 1));
946 case DW_OP_xderef_size
:
947 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data
++, 1));
950 printf ("DW_OP_nop");
953 /* DWARF 3 extensions. */
954 case DW_OP_push_object_address
:
955 printf ("DW_OP_push_object_address");
958 /* XXX: Strictly speaking for 64-bit DWARF3 files
959 this ought to be an 8-byte wide computation. */
960 printf ("DW_OP_call2: <0x%s>",
961 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 2)
966 /* XXX: Strictly speaking for 64-bit DWARF3 files
967 this ought to be an 8-byte wide computation. */
968 printf ("DW_OP_call4: <0x%s>",
969 dwarf_vmatoa ("x", (dwarf_signed_vma
) byte_get (data
, 4)
974 /* XXX: Strictly speaking for 64-bit DWARF3 files
975 this ought to be an 8-byte wide computation. */
976 if (dwarf_version
== -1)
978 printf (_("(DW_OP_call_ref in frame info)"));
979 /* No way to tell where the next op is, so just bail. */
980 return need_frame_base
;
982 if (dwarf_version
== 2)
984 printf ("DW_OP_call_ref: <0x%s>",
985 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)));
986 data
+= pointer_size
;
990 printf ("DW_OP_call_ref: <0x%s>",
991 dwarf_vmatoa ("x", byte_get (data
, offset_size
)));
995 case DW_OP_form_tls_address
:
996 printf ("DW_OP_form_tls_address");
998 case DW_OP_call_frame_cfa
:
999 printf ("DW_OP_call_frame_cfa");
1001 case DW_OP_bit_piece
:
1002 printf ("DW_OP_bit_piece: ");
1003 printf (_("size: %s "),
1004 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1006 printf (_("offset: %s "),
1007 dwarf_vmatoa ("u", read_leb128 (data
, &bytes_read
, 0)));
1011 /* DWARF 4 extensions. */
1012 case DW_OP_stack_value
:
1013 printf ("DW_OP_stack_value");
1016 case DW_OP_implicit_value
:
1017 printf ("DW_OP_implicit_value");
1018 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1020 display_block (data
, uvalue
);
1024 /* GNU extensions. */
1025 case DW_OP_GNU_push_tls_address
:
1026 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1028 case DW_OP_GNU_uninit
:
1029 printf ("DW_OP_GNU_uninit");
1030 /* FIXME: Is there data associated with this OP ? */
1032 case DW_OP_GNU_encoded_addr
:
1038 addr
= get_encoded_value (data
, encoding
, section
);
1039 data
+= size_of_encoded_value (encoding
);
1041 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1042 print_dwarf_vma (addr
, pointer_size
);
1045 case DW_OP_GNU_implicit_pointer
:
1046 /* XXX: Strictly speaking for 64-bit DWARF3 files
1047 this ought to be an 8-byte wide computation. */
1048 if (dwarf_version
== -1)
1050 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1051 /* No way to tell where the next op is, so just bail. */
1052 return need_frame_base
;
1054 if (dwarf_version
== 2)
1056 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1057 dwarf_vmatoa ("x", byte_get (data
, pointer_size
)),
1058 dwarf_vmatoa ("d", read_sleb128 (data
+ pointer_size
,
1060 data
+= pointer_size
+ bytes_read
;
1064 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1065 dwarf_vmatoa ("x", byte_get (data
, offset_size
)),
1066 dwarf_vmatoa ("d", read_sleb128 (data
+ offset_size
,
1068 data
+= offset_size
+ bytes_read
;
1071 case DW_OP_GNU_entry_value
:
1072 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1074 printf ("DW_OP_GNU_entry_value: (");
1075 if (decode_location_expression (data
, pointer_size
, offset_size
,
1076 dwarf_version
, uvalue
,
1077 cu_offset
, section
))
1078 need_frame_base
= 1;
1082 case DW_OP_GNU_const_type
:
1083 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1085 printf ("DW_OP_GNU_const_type: <0x%s> ",
1086 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1087 uvalue
= byte_get (data
++, 1);
1088 display_block (data
, uvalue
);
1091 case DW_OP_GNU_regval_type
:
1092 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1094 printf ("DW_OP_GNU_regval_type: %s (%s)",
1095 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1096 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1098 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1100 case DW_OP_GNU_deref_type
:
1101 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data
++, 1));
1102 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1104 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1106 case DW_OP_GNU_convert
:
1107 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1109 printf ("DW_OP_GNU_convert <0x%s>",
1110 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1112 case DW_OP_GNU_reinterpret
:
1113 uvalue
= read_leb128 (data
, &bytes_read
, 0);
1115 printf ("DW_OP_GNU_reinterpret <0x%s>",
1116 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1118 case DW_OP_GNU_parameter_ref
:
1119 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1120 dwarf_vmatoa ("x", cu_offset
+ byte_get (data
, 4)));
1124 /* HP extensions. */
1125 case DW_OP_HP_is_value
:
1126 printf ("DW_OP_HP_is_value");
1127 /* FIXME: Is there data associated with this OP ? */
1129 case DW_OP_HP_fltconst4
:
1130 printf ("DW_OP_HP_fltconst4");
1131 /* FIXME: Is there data associated with this OP ? */
1133 case DW_OP_HP_fltconst8
:
1134 printf ("DW_OP_HP_fltconst8");
1135 /* FIXME: Is there data associated with this OP ? */
1137 case DW_OP_HP_mod_range
:
1138 printf ("DW_OP_HP_mod_range");
1139 /* FIXME: Is there data associated with this OP ? */
1141 case DW_OP_HP_unmod_range
:
1142 printf ("DW_OP_HP_unmod_range");
1143 /* FIXME: Is there data associated with this OP ? */
1146 printf ("DW_OP_HP_tls");
1147 /* FIXME: Is there data associated with this OP ? */
1150 /* PGI (STMicroelectronics) extensions. */
1151 case DW_OP_PGI_omp_thread_num
:
1152 /* Pushes the thread number for the current thread as it would be
1153 returned by the standard OpenMP library function:
1154 omp_get_thread_num(). The "current thread" is the thread for
1155 which the expression is being evaluated. */
1156 printf ("DW_OP_PGI_omp_thread_num");
1160 if (op
>= DW_OP_lo_user
1161 && op
<= DW_OP_hi_user
)
1162 printf (_("(User defined location op)"));
1164 printf (_("(Unknown location op)"));
1165 /* No way to tell where the next op is, so just bail. */
1166 return need_frame_base
;
1169 /* Separate the ops. */
1174 return need_frame_base
;
1177 static unsigned char *
1178 read_and_display_attr_value (unsigned long attribute
,
1180 unsigned char * data
,
1181 dwarf_vma cu_offset
,
1182 dwarf_vma pointer_size
,
1183 dwarf_vma offset_size
,
1185 debug_info
* debug_info_p
,
1187 struct dwarf_section
* section
)
1189 dwarf_vma uvalue
= 0;
1190 unsigned char *block_start
= NULL
;
1191 unsigned char * orig_data
= data
;
1192 unsigned int bytes_read
;
1199 case DW_FORM_ref_addr
:
1200 if (dwarf_version
== 2)
1202 uvalue
= byte_get (data
, pointer_size
);
1203 data
+= pointer_size
;
1205 else if (dwarf_version
== 3 || dwarf_version
== 4)
1207 uvalue
= byte_get (data
, offset_size
);
1208 data
+= offset_size
;
1211 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1216 uvalue
= byte_get (data
, pointer_size
);
1217 data
+= pointer_size
;
1221 case DW_FORM_sec_offset
:
1222 uvalue
= byte_get (data
, offset_size
);
1223 data
+= offset_size
;
1226 case DW_FORM_flag_present
:
1233 uvalue
= byte_get (data
++, 1);
1238 uvalue
= byte_get (data
, 2);
1244 uvalue
= byte_get (data
, 4);
1249 uvalue
= read_leb128 (data
, & bytes_read
, 1);
1253 case DW_FORM_ref_udata
:
1255 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1259 case DW_FORM_indirect
:
1260 form
= read_leb128 (data
, & bytes_read
, 0);
1263 printf (" %s", get_FORM_name (form
));
1264 return read_and_display_attr_value (attribute
, form
, data
,
1265 cu_offset
, pointer_size
,
1266 offset_size
, dwarf_version
,
1267 debug_info_p
, do_loc
,
1273 case DW_FORM_ref_addr
:
1275 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1281 case DW_FORM_ref_udata
:
1283 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1288 case DW_FORM_sec_offset
:
1290 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1293 case DW_FORM_flag_present
:
1300 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1307 dwarf_vma high_bits
;
1310 byte_get_64 (data
, &high_bits
, &uvalue
);
1312 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1314 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1315 && num_debug_info_entries
== 0)
1317 if (sizeof (uvalue
) == 8)
1318 uvalue
= byte_get (data
, 8);
1320 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1325 case DW_FORM_string
:
1327 printf (" %s", data
);
1328 data
+= strlen ((char *) data
) + 1;
1332 case DW_FORM_exprloc
:
1333 uvalue
= read_leb128 (data
, & bytes_read
, 0);
1334 block_start
= data
+ bytes_read
;
1336 data
= block_start
+ uvalue
;
1338 data
= display_block (block_start
, uvalue
);
1341 case DW_FORM_block1
:
1342 uvalue
= byte_get (data
, 1);
1343 block_start
= data
+ 1;
1345 data
= block_start
+ uvalue
;
1347 data
= display_block (block_start
, uvalue
);
1350 case DW_FORM_block2
:
1351 uvalue
= byte_get (data
, 2);
1352 block_start
= data
+ 2;
1354 data
= block_start
+ uvalue
;
1356 data
= display_block (block_start
, uvalue
);
1359 case DW_FORM_block4
:
1360 uvalue
= byte_get (data
, 4);
1361 block_start
= data
+ 4;
1363 data
= block_start
+ uvalue
;
1365 data
= display_block (block_start
, uvalue
);
1370 printf (_(" (indirect string, offset: 0x%s): %s"),
1371 dwarf_vmatoa ("x", uvalue
),
1372 fetch_indirect_string (uvalue
));
1375 case DW_FORM_indirect
:
1376 /* Handled above. */
1379 case DW_FORM_ref_sig8
:
1382 dwarf_vma high_bits
;
1385 byte_get_64 (data
, &high_bits
, &uvalue
);
1386 printf (" signature: 0x%s",
1387 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1393 warn (_("Unrecognized form: %lu\n"), form
);
1397 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1398 && num_debug_info_entries
== 0
1399 && debug_info_p
!= NULL
)
1403 case DW_AT_frame_base
:
1404 have_frame_base
= 1;
1405 case DW_AT_location
:
1406 case DW_AT_string_length
:
1407 case DW_AT_return_addr
:
1408 case DW_AT_data_member_location
:
1409 case DW_AT_vtable_elem_location
:
1411 case DW_AT_static_link
:
1412 case DW_AT_use_location
:
1413 case DW_AT_GNU_call_site_value
:
1414 case DW_AT_GNU_call_site_data_value
:
1415 case DW_AT_GNU_call_site_target
:
1416 case DW_AT_GNU_call_site_target_clobbered
:
1417 if ((dwarf_version
< 4
1418 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1419 || form
== DW_FORM_sec_offset
)
1421 /* Process location list. */
1422 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1423 unsigned int num
= debug_info_p
->num_loc_offsets
;
1425 if (lmax
== 0 || num
>= lmax
)
1428 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1429 xcrealloc (debug_info_p
->loc_offsets
,
1430 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1431 debug_info_p
->have_frame_base
= (int *)
1432 xcrealloc (debug_info_p
->have_frame_base
,
1433 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1434 debug_info_p
->max_loc_offsets
= lmax
;
1436 debug_info_p
->loc_offsets
[num
] = uvalue
;
1437 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1438 debug_info_p
->num_loc_offsets
++;
1443 if (need_base_address
)
1444 debug_info_p
->base_address
= uvalue
;
1448 if ((dwarf_version
< 4
1449 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1450 || form
== DW_FORM_sec_offset
)
1452 /* Process range list. */
1453 unsigned int lmax
= debug_info_p
->max_range_lists
;
1454 unsigned int num
= debug_info_p
->num_range_lists
;
1456 if (lmax
== 0 || num
>= lmax
)
1459 debug_info_p
->range_lists
= (dwarf_vma
*)
1460 xcrealloc (debug_info_p
->range_lists
,
1461 lmax
, sizeof (*debug_info_p
->range_lists
));
1462 debug_info_p
->max_range_lists
= lmax
;
1464 debug_info_p
->range_lists
[num
] = uvalue
;
1465 debug_info_p
->num_range_lists
++;
1474 if (do_loc
|| attribute
== 0)
1477 /* For some attributes we can display further information. */
1485 case DW_INL_not_inlined
:
1486 printf (_("(not inlined)"));
1488 case DW_INL_inlined
:
1489 printf (_("(inlined)"));
1491 case DW_INL_declared_not_inlined
:
1492 printf (_("(declared as inline but ignored)"));
1494 case DW_INL_declared_inlined
:
1495 printf (_("(declared as inline and inlined)"));
1498 printf (_(" (Unknown inline attribute value: %s)"),
1499 dwarf_vmatoa ("x", uvalue
));
1504 case DW_AT_language
:
1507 /* Ordered by the numeric value of these constants. */
1508 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1509 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1510 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1511 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1512 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1513 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1514 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1515 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1516 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1517 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1518 /* DWARF 2.1 values. */
1519 case DW_LANG_Java
: printf ("(Java)"); break;
1520 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1521 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1522 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1523 /* DWARF 3 values. */
1524 case DW_LANG_PLI
: printf ("(PLI)"); break;
1525 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1526 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1527 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1528 case DW_LANG_D
: printf ("(D)"); break;
1529 /* DWARF 4 values. */
1530 case DW_LANG_Python
: printf ("(Python)"); break;
1531 /* DWARF 5 values. */
1532 case DW_LANG_Go
: printf ("(Go)"); break;
1533 /* MIPS extension. */
1534 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1535 /* UPC extension. */
1536 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1538 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1539 printf (_("(implementation defined: %s)"),
1540 dwarf_vmatoa ("x", uvalue
));
1542 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
1547 case DW_AT_encoding
:
1550 case DW_ATE_void
: printf ("(void)"); break;
1551 case DW_ATE_address
: printf ("(machine address)"); break;
1552 case DW_ATE_boolean
: printf ("(boolean)"); break;
1553 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1554 case DW_ATE_float
: printf ("(float)"); break;
1555 case DW_ATE_signed
: printf ("(signed)"); break;
1556 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1557 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1558 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1559 /* DWARF 2.1 values: */
1560 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1561 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1562 /* DWARF 3 values: */
1563 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1564 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1565 case DW_ATE_edited
: printf ("(edited)"); break;
1566 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
1567 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
1568 /* HP extensions: */
1569 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
1570 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
1571 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
1572 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
1573 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
1574 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
1575 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
1578 if (uvalue
>= DW_ATE_lo_user
1579 && uvalue
<= DW_ATE_hi_user
)
1580 printf (_("(user defined type)"));
1582 printf (_("(unknown type)"));
1587 case DW_AT_accessibility
:
1590 case DW_ACCESS_public
: printf ("(public)"); break;
1591 case DW_ACCESS_protected
: printf ("(protected)"); break;
1592 case DW_ACCESS_private
: printf ("(private)"); break;
1594 printf (_("(unknown accessibility)"));
1599 case DW_AT_visibility
:
1602 case DW_VIS_local
: printf ("(local)"); break;
1603 case DW_VIS_exported
: printf ("(exported)"); break;
1604 case DW_VIS_qualified
: printf ("(qualified)"); break;
1605 default: printf (_("(unknown visibility)")); break;
1609 case DW_AT_virtuality
:
1612 case DW_VIRTUALITY_none
: printf ("(none)"); break;
1613 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
1614 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
1615 default: printf (_("(unknown virtuality)")); break;
1619 case DW_AT_identifier_case
:
1622 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
1623 case DW_ID_up_case
: printf ("(up_case)"); break;
1624 case DW_ID_down_case
: printf ("(down_case)"); break;
1625 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
1626 default: printf (_("(unknown case)")); break;
1630 case DW_AT_calling_convention
:
1633 case DW_CC_normal
: printf ("(normal)"); break;
1634 case DW_CC_program
: printf ("(program)"); break;
1635 case DW_CC_nocall
: printf ("(nocall)"); break;
1637 if (uvalue
>= DW_CC_lo_user
1638 && uvalue
<= DW_CC_hi_user
)
1639 printf (_("(user defined)"));
1641 printf (_("(unknown convention)"));
1645 case DW_AT_ordering
:
1648 case -1: printf (_("(undefined)")); break;
1649 case 0: printf ("(row major)"); break;
1650 case 1: printf ("(column major)"); break;
1654 case DW_AT_frame_base
:
1655 have_frame_base
= 1;
1656 case DW_AT_location
:
1657 case DW_AT_string_length
:
1658 case DW_AT_return_addr
:
1659 case DW_AT_data_member_location
:
1660 case DW_AT_vtable_elem_location
:
1662 case DW_AT_static_link
:
1663 case DW_AT_use_location
:
1664 case DW_AT_GNU_call_site_value
:
1665 case DW_AT_GNU_call_site_data_value
:
1666 case DW_AT_GNU_call_site_target
:
1667 case DW_AT_GNU_call_site_target_clobbered
:
1668 if ((dwarf_version
< 4
1669 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1670 || form
== DW_FORM_sec_offset
)
1671 printf (_("(location list)"));
1673 case DW_AT_allocated
:
1674 case DW_AT_associated
:
1675 case DW_AT_data_location
:
1677 case DW_AT_upper_bound
:
1678 case DW_AT_lower_bound
:
1681 int need_frame_base
;
1684 need_frame_base
= decode_location_expression (block_start
,
1689 cu_offset
, section
);
1691 if (need_frame_base
&& !have_frame_base
)
1692 printf (_(" [without DW_AT_frame_base]"));
1698 if (form
== DW_FORM_ref_sig8
)
1701 if (form
== DW_FORM_ref1
1702 || form
== DW_FORM_ref2
1703 || form
== DW_FORM_ref4
1704 || form
== DW_FORM_ref_udata
)
1705 uvalue
+= cu_offset
;
1707 if (uvalue
>= section
->size
)
1708 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1709 dwarf_vmatoa ("x", uvalue
),
1710 (unsigned long) (orig_data
- section
->start
));
1713 unsigned long abbrev_number
;
1714 abbrev_entry
* entry
;
1716 abbrev_number
= read_leb128 (section
->start
+ uvalue
, NULL
, 0);
1718 printf (_("[Abbrev Number: %ld"), abbrev_number
);
1719 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
1720 use different abbrev table, and we don't track .debug_info chunks
1722 if (form
!= DW_FORM_ref_addr
)
1724 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
1725 if (entry
->entry
== abbrev_number
)
1728 printf (" (%s)", get_TAG_name (entry
->tag
));
1743 get_AT_name (unsigned long attribute
)
1747 /* One value is shared by the MIPS and HP extensions: */
1748 if (attribute
== DW_AT_MIPS_fde
)
1749 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1751 name
= get_DW_AT_name (attribute
);
1755 static char buffer
[100];
1757 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1765 static unsigned char *
1766 read_and_display_attr (unsigned long attribute
,
1768 unsigned char * data
,
1769 dwarf_vma cu_offset
,
1770 dwarf_vma pointer_size
,
1771 dwarf_vma offset_size
,
1773 debug_info
* debug_info_p
,
1775 struct dwarf_section
* section
)
1778 printf (" %-18s:", get_AT_name (attribute
));
1779 data
= read_and_display_attr_value (attribute
, form
, data
, cu_offset
,
1780 pointer_size
, offset_size
,
1781 dwarf_version
, debug_info_p
,
1789 /* Process the contents of a .debug_info section. If do_loc is non-zero
1790 then we are scanning for location lists and we do not want to display
1791 anything to the user. If do_types is non-zero, we are processing
1792 a .debug_types section instead of a .debug_info section. */
1795 process_debug_info (struct dwarf_section
*section
,
1797 enum dwarf_section_display_enum abbrev_sec
,
1801 unsigned char *start
= section
->start
;
1802 unsigned char *end
= start
+ section
->size
;
1803 unsigned char *section_begin
;
1805 unsigned int num_units
= 0;
1807 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1808 && num_debug_info_entries
== 0
1813 /* First scan the section to get the number of comp units. */
1814 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
1817 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1818 will be the length. For a 64-bit DWARF section, it'll be
1819 the escape code 0xffffffff followed by an 8 byte length. */
1820 length
= byte_get (section_begin
, 4);
1822 if (length
== 0xffffffff)
1824 length
= byte_get (section_begin
+ 4, 8);
1825 section_begin
+= length
+ 12;
1827 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
1829 warn (_("Reserved length value (0x%s) found in section %s\n"),
1830 dwarf_vmatoa ("x", length
), section
->name
);
1834 section_begin
+= length
+ 4;
1836 /* Negative values are illegal, they may even cause infinite
1837 looping. This can happen if we can't accurately apply
1838 relocations to an object file. */
1839 if ((signed long) length
<= 0)
1841 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
1842 dwarf_vmatoa ("x", length
), section
->name
);
1849 error (_("No comp units in %s section ?"), section
->name
);
1853 /* Then allocate an array to hold the information. */
1854 debug_information
= (debug_info
*) cmalloc (num_units
,
1855 sizeof (* debug_information
));
1856 if (debug_information
== NULL
)
1858 error (_("Not enough memory for a debug info array of %u entries"),
1866 if (dwarf_start_die
== 0)
1867 printf (_("Contents of the %s section:\n\n"), section
->name
);
1869 load_debug_section (str
, file
);
1872 load_debug_section (abbrev_sec
, file
);
1873 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
1875 warn (_("Unable to locate %s section!\n"),
1876 debug_displays
[abbrev_sec
].section
.name
);
1880 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
1882 DWARF2_Internal_CompUnit compunit
;
1883 unsigned char *hdrptr
;
1884 unsigned char *tags
;
1885 int level
, last_level
, saved_level
;
1886 dwarf_vma cu_offset
;
1888 int initial_length_size
;
1889 dwarf_vma signature_high
= 0;
1890 dwarf_vma signature_low
= 0;
1891 dwarf_vma type_offset
= 0;
1895 compunit
.cu_length
= byte_get (hdrptr
, 4);
1898 if (compunit
.cu_length
== 0xffffffff)
1900 compunit
.cu_length
= byte_get (hdrptr
, 8);
1903 initial_length_size
= 12;
1908 initial_length_size
= 4;
1911 compunit
.cu_version
= byte_get (hdrptr
, 2);
1914 cu_offset
= start
- section_begin
;
1916 compunit
.cu_abbrev_offset
= byte_get (hdrptr
, offset_size
);
1917 hdrptr
+= offset_size
;
1919 compunit
.cu_pointer_size
= byte_get (hdrptr
, 1);
1924 byte_get_64 (hdrptr
, &signature_high
, &signature_low
);
1926 type_offset
= byte_get (hdrptr
, offset_size
);
1927 hdrptr
+= offset_size
;
1930 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1931 && num_debug_info_entries
== 0
1934 debug_information
[unit
].cu_offset
= cu_offset
;
1935 debug_information
[unit
].pointer_size
1936 = compunit
.cu_pointer_size
;
1937 debug_information
[unit
].offset_size
= offset_size
;
1938 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
1939 debug_information
[unit
].base_address
= 0;
1940 debug_information
[unit
].loc_offsets
= NULL
;
1941 debug_information
[unit
].have_frame_base
= NULL
;
1942 debug_information
[unit
].max_loc_offsets
= 0;
1943 debug_information
[unit
].num_loc_offsets
= 0;
1944 debug_information
[unit
].range_lists
= NULL
;
1945 debug_information
[unit
].max_range_lists
= 0;
1946 debug_information
[unit
].num_range_lists
= 0;
1949 if (!do_loc
&& dwarf_start_die
== 0)
1951 printf (_(" Compilation Unit @ offset 0x%s:\n"),
1952 dwarf_vmatoa ("x", cu_offset
));
1953 printf (_(" Length: 0x%s (%s)\n"),
1954 dwarf_vmatoa ("x", compunit
.cu_length
),
1955 offset_size
== 8 ? "64-bit" : "32-bit");
1956 printf (_(" Version: %d\n"), compunit
.cu_version
);
1957 printf (_(" Abbrev Offset: %s\n"),
1958 dwarf_vmatoa ("d", compunit
.cu_abbrev_offset
));
1959 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
1964 printf (_(" Signature: 0x%s\n"),
1965 dwarf_vmatoa64 (signature_high
, signature_low
,
1966 buf
, sizeof (buf
)));
1967 printf (_(" Type Offset: 0x%s\n"),
1968 dwarf_vmatoa ("x", type_offset
));
1972 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
1975 warn (_("Debug info is corrupted, length of CU at %s"
1976 " extends beyond end of section (length = %s)\n"),
1977 dwarf_vmatoa ("x", cu_offset
),
1978 dwarf_vmatoa ("x", compunit
.cu_length
));
1982 start
+= compunit
.cu_length
+ initial_length_size
;
1984 if (compunit
.cu_version
!= 2
1985 && compunit
.cu_version
!= 3
1986 && compunit
.cu_version
!= 4)
1988 warn (_("CU at offset %s contains corrupt or "
1989 "unsupported version number: %d.\n"),
1990 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
1996 /* Process the abbrevs used by this compilation unit. DWARF
1997 sections under Mach-O have non-zero addresses. */
1998 if (compunit
.cu_abbrev_offset
>= debug_displays
[abbrev_sec
].section
.size
)
1999 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2000 (unsigned long) compunit
.cu_abbrev_offset
,
2001 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2003 process_abbrev_section
2004 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2005 + compunit
.cu_abbrev_offset
,
2006 (unsigned char *) debug_displays
[abbrev_sec
].section
.start
2007 + debug_displays
[abbrev_sec
].section
.size
);
2012 while (tags
< start
)
2014 unsigned int bytes_read
;
2015 unsigned long abbrev_number
;
2016 unsigned long die_offset
;
2017 abbrev_entry
*entry
;
2019 int do_printing
= 1;
2021 die_offset
= tags
- section_begin
;
2023 abbrev_number
= read_leb128 (tags
, & bytes_read
, 0);
2026 /* A null DIE marks the end of a list of siblings or it may also be
2027 a section padding. */
2028 if (abbrev_number
== 0)
2030 /* Check if it can be a section padding for the last CU. */
2031 if (level
== 0 && start
== end
)
2035 for (chk
= tags
; chk
< start
; chk
++)
2045 static unsigned num_bogus_warns
= 0;
2047 if (num_bogus_warns
< 3)
2049 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2052 if (num_bogus_warns
== 3)
2053 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2056 if (dwarf_start_die
!= 0 && level
< saved_level
)
2063 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2067 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2068 saved_level
= level
;
2069 do_printing
= (dwarf_cutoff_level
== -1
2070 || level
< dwarf_cutoff_level
);
2072 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2073 level
, die_offset
, abbrev_number
);
2074 else if (dwarf_cutoff_level
== -1
2075 || last_level
< dwarf_cutoff_level
)
2076 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2081 /* Scan through the abbreviation list until we reach the
2083 for (entry
= first_abbrev
;
2084 entry
&& entry
->entry
!= abbrev_number
;
2085 entry
= entry
->next
)
2090 if (!do_loc
&& do_printing
)
2095 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2096 die_offset
, abbrev_number
);
2100 if (!do_loc
&& do_printing
)
2101 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2106 need_base_address
= 0;
2108 case DW_TAG_compile_unit
:
2109 need_base_address
= 1;
2111 case DW_TAG_entry_point
:
2112 case DW_TAG_subprogram
:
2113 need_base_address
= 0;
2114 /* Assuming that there is no DW_AT_frame_base. */
2115 have_frame_base
= 0;
2119 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
2123 if (! do_loc
&& do_printing
)
2124 /* Show the offset from where the tag was extracted. */
2125 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2127 arg
= debug_information
;
2128 if (debug_information
)
2131 tags
= read_and_display_attr (attr
->attribute
,
2134 compunit
.cu_pointer_size
,
2136 compunit
.cu_version
,
2138 do_loc
|| ! do_printing
, section
);
2141 if (entry
->children
)
2146 /* Set num_debug_info_entries here so that it can be used to check if
2147 we need to process .debug_loc and .debug_ranges sections. */
2148 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2149 && num_debug_info_entries
== 0
2151 num_debug_info_entries
= num_units
;
2159 /* Locate and scan the .debug_info section in the file and record the pointer
2160 sizes and offsets for the compilation units in it. Usually an executable
2161 will have just one pointer size, but this is not guaranteed, and so we try
2162 not to make any assumptions. Returns zero upon failure, or the number of
2163 compilation units upon success. */
2166 load_debug_info (void * file
)
2168 /* Reset the last pointer size so that we can issue correct error
2169 messages if we are displaying the contents of more than one section. */
2170 last_pointer_size
= 0;
2171 warned_about_missing_comp_units
= FALSE
;
2173 /* If we have already tried and failed to load the .debug_info
2174 section then do not bother to repear the task. */
2175 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2178 /* If we already have the information there is nothing else to do. */
2179 if (num_debug_info_entries
> 0)
2180 return num_debug_info_entries
;
2182 if (load_debug_section (info
, file
)
2183 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2184 return num_debug_info_entries
;
2186 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2191 display_debug_lines_raw (struct dwarf_section
*section
,
2192 unsigned char *data
,
2195 unsigned char *start
= section
->start
;
2197 printf (_("Raw dump of debug contents of section %s:\n\n"),
2202 DWARF2_Internal_LineInfo linfo
;
2203 unsigned char *standard_opcodes
;
2204 unsigned char *end_of_sequence
;
2205 unsigned char *hdrptr
;
2206 unsigned long hdroff
;
2207 int initial_length_size
;
2212 hdroff
= hdrptr
- start
;
2214 /* Check the length of the block. */
2215 linfo
.li_length
= byte_get (hdrptr
, 4);
2218 if (linfo
.li_length
== 0xffffffff)
2220 /* This section is 64-bit DWARF 3. */
2221 linfo
.li_length
= byte_get (hdrptr
, 8);
2224 initial_length_size
= 12;
2229 initial_length_size
= 4;
2232 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2235 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2240 /* Check its version number. */
2241 linfo
.li_version
= byte_get (hdrptr
, 2);
2243 if (linfo
.li_version
!= 2
2244 && linfo
.li_version
!= 3
2245 && linfo
.li_version
!= 4)
2247 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2251 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2252 hdrptr
+= offset_size
;
2253 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2255 if (linfo
.li_version
>= 4)
2257 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2259 if (linfo
.li_max_ops_per_insn
== 0)
2261 warn (_("Invalid maximum operations per insn.\n"));
2266 linfo
.li_max_ops_per_insn
= 1;
2267 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2269 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2271 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2273 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2276 /* Sign extend the line base field. */
2277 linfo
.li_line_base
<<= 24;
2278 linfo
.li_line_base
>>= 24;
2280 printf (_(" Offset: 0x%lx\n"), hdroff
);
2281 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2282 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2283 printf (_(" Prologue Length: %d\n"), linfo
.li_prologue_length
);
2284 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2285 if (linfo
.li_version
>= 4)
2286 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2287 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2288 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2289 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2290 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2292 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2294 reset_state_machine (linfo
.li_default_is_stmt
);
2296 /* Display the contents of the Opcodes table. */
2297 standard_opcodes
= hdrptr
;
2299 printf (_("\n Opcodes:\n"));
2301 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2302 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2304 /* Display the contents of the Directory table. */
2305 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2308 printf (_("\n The Directory Table is empty.\n"));
2311 printf (_("\n The Directory Table:\n"));
2315 printf (" %s\n", data
);
2317 data
+= strlen ((char *) data
) + 1;
2321 /* Skip the NUL at the end of the table. */
2324 /* Display the contents of the File Name table. */
2326 printf (_("\n The File Name Table is empty.\n"));
2329 printf (_("\n The File Name Table:\n"));
2330 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2334 unsigned char *name
;
2335 unsigned int bytes_read
;
2337 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2340 data
+= strlen ((char *) data
) + 1;
2343 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2346 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2349 dwarf_vmatoa ("u", read_leb128 (data
, & bytes_read
, 0)));
2351 printf ("%s\n", name
);
2355 /* Skip the NUL at the end of the table. */
2358 /* Now display the statements. */
2359 printf (_("\n Line Number Statements:\n"));
2361 while (data
< end_of_sequence
)
2363 unsigned char op_code
;
2364 dwarf_signed_vma adv
;
2366 unsigned int bytes_read
;
2370 if (op_code
>= linfo
.li_opcode_base
)
2372 op_code
-= linfo
.li_opcode_base
;
2373 uladv
= (op_code
/ linfo
.li_line_range
);
2374 if (linfo
.li_max_ops_per_insn
== 1)
2376 uladv
*= linfo
.li_min_insn_length
;
2377 state_machine_regs
.address
+= uladv
;
2378 printf (_(" Special opcode %d: "
2379 "advance Address by %s to 0x%s"),
2380 op_code
, dwarf_vmatoa ("u", uladv
),
2381 dwarf_vmatoa ("x", state_machine_regs
.address
));
2385 state_machine_regs
.address
2386 += ((state_machine_regs
.op_index
+ uladv
)
2387 / linfo
.li_max_ops_per_insn
)
2388 * linfo
.li_min_insn_length
;
2389 state_machine_regs
.op_index
2390 = (state_machine_regs
.op_index
+ uladv
)
2391 % linfo
.li_max_ops_per_insn
;
2392 printf (_(" Special opcode %d: "
2393 "advance Address by %s to 0x%s[%d]"),
2394 op_code
, dwarf_vmatoa ("u", uladv
),
2395 dwarf_vmatoa ("x", state_machine_regs
.address
),
2396 state_machine_regs
.op_index
);
2398 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2399 state_machine_regs
.line
+= adv
;
2400 printf (_(" and Line by %s to %d\n"),
2401 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
2403 else switch (op_code
)
2405 case DW_LNS_extended_op
:
2406 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
);
2410 printf (_(" Copy\n"));
2413 case DW_LNS_advance_pc
:
2414 uladv
= read_leb128 (data
, & bytes_read
, 0);
2416 if (linfo
.li_max_ops_per_insn
== 1)
2418 uladv
*= linfo
.li_min_insn_length
;
2419 state_machine_regs
.address
+= uladv
;
2420 printf (_(" Advance PC by %s to 0x%s\n"),
2421 dwarf_vmatoa ("u", uladv
),
2422 dwarf_vmatoa ("x", 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 (_(" Advance PC by %s to 0x%s[%d]\n"),
2434 dwarf_vmatoa ("u", uladv
),
2435 dwarf_vmatoa ("x", state_machine_regs
.address
),
2436 state_machine_regs
.op_index
);
2440 case DW_LNS_advance_line
:
2441 adv
= read_sleb128 (data
, & bytes_read
);
2443 state_machine_regs
.line
+= adv
;
2444 printf (_(" Advance Line by %s to %d\n"),
2445 dwarf_vmatoa ("d", adv
),
2446 state_machine_regs
.line
);
2449 case DW_LNS_set_file
:
2450 adv
= read_leb128 (data
, & bytes_read
, 0);
2452 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2453 dwarf_vmatoa ("d", adv
));
2454 state_machine_regs
.file
= adv
;
2457 case DW_LNS_set_column
:
2458 uladv
= read_leb128 (data
, & bytes_read
, 0);
2460 printf (_(" Set column to %s\n"),
2461 dwarf_vmatoa ("u", uladv
));
2462 state_machine_regs
.column
= uladv
;
2465 case DW_LNS_negate_stmt
:
2466 adv
= state_machine_regs
.is_stmt
;
2468 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
2469 state_machine_regs
.is_stmt
= adv
;
2472 case DW_LNS_set_basic_block
:
2473 printf (_(" Set basic block\n"));
2474 state_machine_regs
.basic_block
= 1;
2477 case DW_LNS_const_add_pc
:
2478 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2479 if (linfo
.li_max_ops_per_insn
)
2481 uladv
*= linfo
.li_min_insn_length
;
2482 state_machine_regs
.address
+= uladv
;
2483 printf (_(" Advance PC by constant %s to 0x%s\n"),
2484 dwarf_vmatoa ("u", uladv
),
2485 dwarf_vmatoa ("x", state_machine_regs
.address
));
2489 state_machine_regs
.address
2490 += ((state_machine_regs
.op_index
+ uladv
)
2491 / linfo
.li_max_ops_per_insn
)
2492 * linfo
.li_min_insn_length
;
2493 state_machine_regs
.op_index
2494 = (state_machine_regs
.op_index
+ uladv
)
2495 % linfo
.li_max_ops_per_insn
;
2496 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2497 dwarf_vmatoa ("u", uladv
),
2498 dwarf_vmatoa ("x", state_machine_regs
.address
),
2499 state_machine_regs
.op_index
);
2503 case DW_LNS_fixed_advance_pc
:
2504 uladv
= byte_get (data
, 2);
2506 state_machine_regs
.address
+= uladv
;
2507 state_machine_regs
.op_index
= 0;
2508 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2509 dwarf_vmatoa ("u", uladv
),
2510 dwarf_vmatoa ("x", state_machine_regs
.address
));
2513 case DW_LNS_set_prologue_end
:
2514 printf (_(" Set prologue_end to true\n"));
2517 case DW_LNS_set_epilogue_begin
:
2518 printf (_(" Set epilogue_begin to true\n"));
2521 case DW_LNS_set_isa
:
2522 uladv
= read_leb128 (data
, & bytes_read
, 0);
2524 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
2528 printf (_(" Unknown opcode %d with operands: "), op_code
);
2530 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2532 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
2534 i
== 1 ? "" : ", ");
2549 unsigned char *name
;
2550 unsigned int directory_index
;
2551 unsigned int modification_date
;
2552 unsigned int length
;
2555 /* Output a decoded representation of the .debug_line section. */
2558 display_debug_lines_decoded (struct dwarf_section
*section
,
2559 unsigned char *data
,
2562 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2567 /* This loop amounts to one iteration per compilation unit. */
2568 DWARF2_Internal_LineInfo linfo
;
2569 unsigned char *standard_opcodes
;
2570 unsigned char *end_of_sequence
;
2571 unsigned char *hdrptr
;
2572 int initial_length_size
;
2575 File_Entry
*file_table
= NULL
;
2576 unsigned int n_files
= 0;
2577 unsigned char **directory_table
= NULL
;
2578 unsigned int n_directories
= 0;
2582 /* Extract information from the Line Number Program Header.
2583 (section 6.2.4 in the Dwarf3 doc). */
2585 /* Get the length of this CU's line number information block. */
2586 linfo
.li_length
= byte_get (hdrptr
, 4);
2589 if (linfo
.li_length
== 0xffffffff)
2591 /* This section is 64-bit DWARF 3. */
2592 linfo
.li_length
= byte_get (hdrptr
, 8);
2595 initial_length_size
= 12;
2600 initial_length_size
= 4;
2603 if (linfo
.li_length
+ initial_length_size
> section
->size
)
2605 warn (_("The line info appears to be corrupt - "
2606 "the section is too small\n"));
2610 /* Get this CU's Line Number Block version number. */
2611 linfo
.li_version
= byte_get (hdrptr
, 2);
2613 if (linfo
.li_version
!= 2
2614 && linfo
.li_version
!= 3
2615 && linfo
.li_version
!= 4)
2617 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2622 linfo
.li_prologue_length
= byte_get (hdrptr
, offset_size
);
2623 hdrptr
+= offset_size
;
2624 linfo
.li_min_insn_length
= byte_get (hdrptr
, 1);
2626 if (linfo
.li_version
>= 4)
2628 linfo
.li_max_ops_per_insn
= byte_get (hdrptr
, 1);
2630 if (linfo
.li_max_ops_per_insn
== 0)
2632 warn (_("Invalid maximum operations per insn.\n"));
2637 linfo
.li_max_ops_per_insn
= 1;
2638 linfo
.li_default_is_stmt
= byte_get (hdrptr
, 1);
2640 linfo
.li_line_base
= byte_get (hdrptr
, 1);
2642 linfo
.li_line_range
= byte_get (hdrptr
, 1);
2644 linfo
.li_opcode_base
= byte_get (hdrptr
, 1);
2647 /* Sign extend the line base field. */
2648 linfo
.li_line_base
<<= 24;
2649 linfo
.li_line_base
>>= 24;
2651 /* Find the end of this CU's Line Number Information Block. */
2652 end_of_sequence
= data
+ linfo
.li_length
+ initial_length_size
;
2654 reset_state_machine (linfo
.li_default_is_stmt
);
2656 /* Save a pointer to the contents of the Opcodes table. */
2657 standard_opcodes
= hdrptr
;
2659 /* Traverse the Directory table just to count entries. */
2660 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2663 unsigned char *ptr_directory_table
= data
;
2667 data
+= strlen ((char *) data
) + 1;
2671 /* Go through the directory table again to save the directories. */
2672 directory_table
= (unsigned char **)
2673 xmalloc (n_directories
* sizeof (unsigned char *));
2676 while (*ptr_directory_table
!= 0)
2678 directory_table
[i
] = ptr_directory_table
;
2679 ptr_directory_table
+= strlen ((char *) ptr_directory_table
) + 1;
2683 /* Skip the NUL at the end of the table. */
2686 /* Traverse the File Name table just to count the entries. */
2689 unsigned char *ptr_file_name_table
= data
;
2693 unsigned int bytes_read
;
2695 /* Skip Name, directory index, last modification time and length
2697 data
+= strlen ((char *) data
) + 1;
2698 read_leb128 (data
, & bytes_read
, 0);
2700 read_leb128 (data
, & bytes_read
, 0);
2702 read_leb128 (data
, & bytes_read
, 0);
2708 /* Go through the file table again to save the strings. */
2709 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
2712 while (*ptr_file_name_table
!= 0)
2714 unsigned int bytes_read
;
2716 file_table
[i
].name
= ptr_file_name_table
;
2717 ptr_file_name_table
+= strlen ((char *) ptr_file_name_table
) + 1;
2719 /* We are not interested in directory, time or size. */
2720 file_table
[i
].directory_index
= read_leb128 (ptr_file_name_table
,
2722 ptr_file_name_table
+= bytes_read
;
2723 file_table
[i
].modification_date
= read_leb128 (ptr_file_name_table
,
2725 ptr_file_name_table
+= bytes_read
;
2726 file_table
[i
].length
= read_leb128 (ptr_file_name_table
, & bytes_read
, 0);
2727 ptr_file_name_table
+= bytes_read
;
2732 /* Print the Compilation Unit's name and a header. */
2733 if (directory_table
== NULL
)
2735 printf (_("CU: %s:\n"), file_table
[0].name
);
2736 printf (_("File name Line number Starting address\n"));
2740 unsigned int ix
= file_table
[0].directory_index
;
2741 const char *directory
= ix
? (char *)directory_table
[ix
- 1] : ".";
2742 if (do_wide
|| strlen (directory
) < 76)
2743 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
2745 printf ("%s:\n", file_table
[0].name
);
2747 printf (_("File name Line number Starting address\n"));
2751 /* Skip the NUL at the end of the table. */
2754 /* This loop iterates through the Dwarf Line Number Program. */
2755 while (data
< end_of_sequence
)
2757 unsigned char op_code
;
2759 unsigned long int uladv
;
2760 unsigned int bytes_read
;
2761 int is_special_opcode
= 0;
2765 if (op_code
>= linfo
.li_opcode_base
)
2767 op_code
-= linfo
.li_opcode_base
;
2768 uladv
= (op_code
/ linfo
.li_line_range
);
2769 if (linfo
.li_max_ops_per_insn
== 1)
2771 uladv
*= linfo
.li_min_insn_length
;
2772 state_machine_regs
.address
+= uladv
;
2776 state_machine_regs
.address
2777 += ((state_machine_regs
.op_index
+ uladv
)
2778 / linfo
.li_max_ops_per_insn
)
2779 * linfo
.li_min_insn_length
;
2780 state_machine_regs
.op_index
2781 = (state_machine_regs
.op_index
+ uladv
)
2782 % linfo
.li_max_ops_per_insn
;
2785 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
2786 state_machine_regs
.line
+= adv
;
2787 is_special_opcode
= 1;
2789 else switch (op_code
)
2791 case DW_LNS_extended_op
:
2793 unsigned int ext_op_code_len
;
2794 unsigned char ext_op_code
;
2795 unsigned char *op_code_data
= data
;
2797 ext_op_code_len
= read_leb128 (op_code_data
, &bytes_read
, 0);
2798 op_code_data
+= bytes_read
;
2800 if (ext_op_code_len
== 0)
2802 warn (_("badly formed extended line op encountered!\n"));
2805 ext_op_code_len
+= bytes_read
;
2806 ext_op_code
= *op_code_data
++;
2808 switch (ext_op_code
)
2810 case DW_LNE_end_sequence
:
2811 reset_state_machine (linfo
.li_default_is_stmt
);
2813 case DW_LNE_set_address
:
2814 state_machine_regs
.address
=
2815 byte_get (op_code_data
, ext_op_code_len
- bytes_read
- 1);
2816 state_machine_regs
.op_index
= 0;
2818 case DW_LNE_define_file
:
2820 file_table
= (File_Entry
*) xrealloc
2821 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
2823 ++state_machine_regs
.last_file_entry
;
2824 /* Source file name. */
2825 file_table
[n_files
].name
= op_code_data
;
2826 op_code_data
+= strlen ((char *) op_code_data
) + 1;
2827 /* Directory index. */
2828 file_table
[n_files
].directory_index
=
2829 read_leb128 (op_code_data
, & bytes_read
, 0);
2830 op_code_data
+= bytes_read
;
2831 /* Last modification time. */
2832 file_table
[n_files
].modification_date
=
2833 read_leb128 (op_code_data
, & bytes_read
, 0);
2834 op_code_data
+= bytes_read
;
2836 file_table
[n_files
].length
=
2837 read_leb128 (op_code_data
, & bytes_read
, 0);
2842 case DW_LNE_set_discriminator
:
2843 case DW_LNE_HP_set_sequence
:
2844 /* Simply ignored. */
2848 printf (_("UNKNOWN (%u): length %d\n"),
2849 ext_op_code
, ext_op_code_len
- bytes_read
);
2852 data
+= ext_op_code_len
;
2858 case DW_LNS_advance_pc
:
2859 uladv
= read_leb128 (data
, & bytes_read
, 0);
2861 if (linfo
.li_max_ops_per_insn
== 1)
2863 uladv
*= linfo
.li_min_insn_length
;
2864 state_machine_regs
.address
+= uladv
;
2868 state_machine_regs
.address
2869 += ((state_machine_regs
.op_index
+ uladv
)
2870 / linfo
.li_max_ops_per_insn
)
2871 * linfo
.li_min_insn_length
;
2872 state_machine_regs
.op_index
2873 = (state_machine_regs
.op_index
+ uladv
)
2874 % linfo
.li_max_ops_per_insn
;
2878 case DW_LNS_advance_line
:
2879 adv
= read_sleb128 (data
, & bytes_read
);
2881 state_machine_regs
.line
+= adv
;
2884 case DW_LNS_set_file
:
2885 adv
= read_leb128 (data
, & bytes_read
, 0);
2887 state_machine_regs
.file
= adv
;
2888 if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
2890 /* If directory index is 0, that means current directory. */
2891 printf ("\n./%s:[++]\n",
2892 file_table
[state_machine_regs
.file
- 1].name
);
2896 /* The directory index starts counting at 1. */
2897 printf ("\n%s/%s:\n",
2898 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
2899 file_table
[state_machine_regs
.file
- 1].name
);
2903 case DW_LNS_set_column
:
2904 uladv
= read_leb128 (data
, & bytes_read
, 0);
2906 state_machine_regs
.column
= uladv
;
2909 case DW_LNS_negate_stmt
:
2910 adv
= state_machine_regs
.is_stmt
;
2912 state_machine_regs
.is_stmt
= adv
;
2915 case DW_LNS_set_basic_block
:
2916 state_machine_regs
.basic_block
= 1;
2919 case DW_LNS_const_add_pc
:
2920 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
2921 if (linfo
.li_max_ops_per_insn
== 1)
2923 uladv
*= linfo
.li_min_insn_length
;
2924 state_machine_regs
.address
+= uladv
;
2928 state_machine_regs
.address
2929 += ((state_machine_regs
.op_index
+ uladv
)
2930 / linfo
.li_max_ops_per_insn
)
2931 * linfo
.li_min_insn_length
;
2932 state_machine_regs
.op_index
2933 = (state_machine_regs
.op_index
+ uladv
)
2934 % linfo
.li_max_ops_per_insn
;
2938 case DW_LNS_fixed_advance_pc
:
2939 uladv
= byte_get (data
, 2);
2941 state_machine_regs
.address
+= uladv
;
2942 state_machine_regs
.op_index
= 0;
2945 case DW_LNS_set_prologue_end
:
2948 case DW_LNS_set_epilogue_begin
:
2951 case DW_LNS_set_isa
:
2952 uladv
= read_leb128 (data
, & bytes_read
, 0);
2954 printf (_(" Set ISA to %lu\n"), uladv
);
2958 printf (_(" Unknown opcode %d with operands: "), op_code
);
2960 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
2962 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data
,
2964 i
== 1 ? "" : ", ");
2971 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2972 to the DWARF address/line matrix. */
2973 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
2974 || (op_code
== DW_LNS_copy
))
2976 const unsigned int MAX_FILENAME_LENGTH
= 35;
2977 char *fileName
= (char *)file_table
[state_machine_regs
.file
- 1].name
;
2978 char *newFileName
= NULL
;
2979 size_t fileNameLength
= strlen (fileName
);
2981 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
2983 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
2984 /* Truncate file name */
2985 strncpy (newFileName
,
2986 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
2987 MAX_FILENAME_LENGTH
+ 1);
2991 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
2992 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
2995 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
2997 if (linfo
.li_max_ops_per_insn
== 1)
2998 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
2999 newFileName
, state_machine_regs
.line
,
3000 state_machine_regs
.address
);
3002 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3003 newFileName
, state_machine_regs
.line
,
3004 state_machine_regs
.address
,
3005 state_machine_regs
.op_index
);
3009 if (linfo
.li_max_ops_per_insn
== 1)
3010 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3011 newFileName
, state_machine_regs
.line
,
3012 state_machine_regs
.address
);
3014 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3015 newFileName
, state_machine_regs
.line
,
3016 state_machine_regs
.address
,
3017 state_machine_regs
.op_index
);
3020 if (op_code
== DW_LNE_end_sequence
)
3028 free (directory_table
);
3029 directory_table
= NULL
;
3037 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3039 unsigned char *data
= section
->start
;
3040 unsigned char *end
= data
+ section
->size
;
3042 int retValDecoded
= 1;
3044 if (do_debug_lines
== 0)
3045 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3047 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3048 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3050 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3051 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3053 if (!retValRaw
|| !retValDecoded
)
3060 find_debug_info_for_offset (unsigned long offset
)
3064 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3067 for (i
= 0; i
< num_debug_info_entries
; i
++)
3068 if (debug_information
[i
].cu_offset
== offset
)
3069 return debug_information
+ i
;
3075 display_debug_pubnames (struct dwarf_section
*section
,
3076 void *file ATTRIBUTE_UNUSED
)
3078 DWARF2_Internal_PubNames names
;
3079 unsigned char *start
= section
->start
;
3080 unsigned char *end
= start
+ section
->size
;
3082 /* It does not matter if this load fails,
3083 we test for that later on. */
3084 load_debug_info (file
);
3086 printf (_("Contents of the %s section:\n\n"), section
->name
);
3090 unsigned char *data
;
3091 unsigned long offset
;
3092 int offset_size
, initial_length_size
;
3096 names
.pn_length
= byte_get (data
, 4);
3098 if (names
.pn_length
== 0xffffffff)
3100 names
.pn_length
= byte_get (data
, 8);
3103 initial_length_size
= 12;
3108 initial_length_size
= 4;
3111 names
.pn_version
= byte_get (data
, 2);
3114 names
.pn_offset
= byte_get (data
, offset_size
);
3115 data
+= offset_size
;
3117 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3118 && num_debug_info_entries
> 0
3119 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3120 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3121 (unsigned long) names
.pn_offset
, section
->name
);
3123 names
.pn_size
= byte_get (data
, offset_size
);
3124 data
+= offset_size
;
3126 start
+= names
.pn_length
+ initial_length_size
;
3128 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3130 static int warned
= 0;
3134 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3141 printf (_(" Length: %ld\n"),
3142 (long) names
.pn_length
);
3143 printf (_(" Version: %d\n"),
3145 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3146 (unsigned long) names
.pn_offset
);
3147 printf (_(" Size of area in .debug_info section: %ld\n"),
3148 (long) names
.pn_size
);
3150 printf (_("\n Offset\tName\n"));
3154 offset
= byte_get (data
, offset_size
);
3158 data
+= offset_size
;
3159 printf (" %-6lx\t%s\n", offset
, data
);
3160 data
+= strlen ((char *) data
) + 1;
3163 while (offset
!= 0);
3171 display_debug_macinfo (struct dwarf_section
*section
,
3172 void *file ATTRIBUTE_UNUSED
)
3174 unsigned char *start
= section
->start
;
3175 unsigned char *end
= start
+ section
->size
;
3176 unsigned char *curr
= start
;
3177 unsigned int bytes_read
;
3178 enum dwarf_macinfo_record_type op
;
3180 printf (_("Contents of the %s section:\n\n"), section
->name
);
3184 unsigned int lineno
;
3187 op
= (enum dwarf_macinfo_record_type
) *curr
;
3192 case DW_MACINFO_start_file
:
3194 unsigned int filenum
;
3196 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3198 filenum
= read_leb128 (curr
, & bytes_read
, 0);
3201 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3206 case DW_MACINFO_end_file
:
3207 printf (_(" DW_MACINFO_end_file\n"));
3210 case DW_MACINFO_define
:
3211 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3213 string
= (char *) curr
;
3214 curr
+= strlen (string
) + 1;
3215 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3219 case DW_MACINFO_undef
:
3220 lineno
= read_leb128 (curr
, & bytes_read
, 0);
3222 string
= (char *) curr
;
3223 curr
+= strlen (string
) + 1;
3224 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3228 case DW_MACINFO_vendor_ext
:
3230 unsigned int constant
;
3232 constant
= read_leb128 (curr
, & bytes_read
, 0);
3234 string
= (char *) curr
;
3235 curr
+= strlen (string
) + 1;
3236 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3246 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3247 filename and dirname corresponding to file name table entry with index
3248 FILEIDX. Return NULL on failure. */
3250 static unsigned char *
3251 get_line_filename_and_dirname (dwarf_vma line_offset
, dwarf_vma fileidx
,
3252 unsigned char **dir_name
)
3254 struct dwarf_section
*section
= &debug_displays
[line
].section
;
3255 unsigned char *hdrptr
, *dirtable
, *file_name
;
3256 unsigned int offset_size
, initial_length_size
;
3257 unsigned int version
, opcode_base
, bytes_read
;
3258 dwarf_vma length
, diridx
;
3261 if (section
->start
== NULL
3262 || line_offset
>= section
->size
3266 hdrptr
= section
->start
+ line_offset
;
3267 length
= byte_get (hdrptr
, 4);
3269 if (length
== 0xffffffff)
3271 /* This section is 64-bit DWARF 3. */
3272 length
= byte_get (hdrptr
, 8);
3275 initial_length_size
= 12;
3280 initial_length_size
= 4;
3282 if (length
+ initial_length_size
> section
->size
)
3284 version
= byte_get (hdrptr
, 2);
3286 if (version
!= 2 && version
!= 3 && version
!= 4)
3288 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
3290 hdrptr
++; /* Skip max_ops_per_insn. */
3291 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
3292 opcode_base
= byte_get (hdrptr
, 1);
3293 if (opcode_base
== 0)
3296 hdrptr
+= opcode_base
- 1;
3298 /* Skip over dirname table. */
3299 while (*hdrptr
!= '\0')
3300 hdrptr
+= strlen ((char *) hdrptr
) + 1;
3301 hdrptr
++; /* Skip the NUL at the end of the table. */
3302 /* Now skip over preceding filename table entries. */
3303 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
3305 hdrptr
+= strlen ((char *) hdrptr
) + 1;
3306 read_leb128 (hdrptr
, &bytes_read
, 0);
3307 hdrptr
+= bytes_read
;
3308 read_leb128 (hdrptr
, &bytes_read
, 0);
3309 hdrptr
+= bytes_read
;
3310 read_leb128 (hdrptr
, &bytes_read
, 0);
3311 hdrptr
+= bytes_read
;
3313 if (*hdrptr
== '\0')
3316 hdrptr
+= strlen ((char *) hdrptr
) + 1;
3317 diridx
= read_leb128 (hdrptr
, &bytes_read
, 0);
3320 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
3321 dirtable
+= strlen ((char *) dirtable
) + 1;
3322 if (*dirtable
== '\0')
3324 *dir_name
= dirtable
;
3329 display_debug_macro (struct dwarf_section
*section
,
3332 unsigned char *start
= section
->start
;
3333 unsigned char *end
= start
+ section
->size
;
3334 unsigned char *curr
= start
;
3335 unsigned char *extended_op_buf
[256];
3336 unsigned int bytes_read
;
3338 load_debug_section (str
, file
);
3339 load_debug_section (line
, file
);
3341 printf (_("Contents of the %s section:\n\n"), section
->name
);
3345 unsigned int lineno
, version
, flags
;
3346 unsigned int offset_size
= 4;
3348 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
3349 unsigned char **extended_ops
= NULL
;
3351 version
= byte_get (curr
, 2);
3356 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3361 flags
= byte_get (curr
++, 1);
3364 printf (_(" Offset: 0x%lx\n"),
3365 (unsigned long) sec_offset
);
3366 printf (_(" Version: %d\n"), version
);
3367 printf (_(" Offset size: %d\n"), offset_size
);
3370 line_offset
= byte_get (curr
, offset_size
);
3371 curr
+= offset_size
;
3372 printf (_(" Offset into .debug_line: 0x%lx\n"),
3373 (unsigned long) line_offset
);
3377 unsigned int i
, count
= byte_get (curr
++, 1), op
;
3379 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
3380 extended_ops
= extended_op_buf
;
3383 printf (_(" Extension opcode arguments:\n"));
3384 for (i
= 0; i
< count
; i
++)
3386 op
= byte_get (curr
++, 1);
3387 extended_ops
[op
] = curr
;
3388 nargs
= read_leb128 (curr
, &bytes_read
, 0);
3391 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op
);
3394 printf (_(" DW_MACRO_GNU_%02x arguments: "), op
);
3395 for (n
= 0; n
< nargs
; n
++)
3397 unsigned int form
= byte_get (curr
++, 1);
3398 printf ("%s%s", get_FORM_name (form
),
3399 n
== nargs
- 1 ? "\n" : ", ");
3409 case DW_FORM_block1
:
3410 case DW_FORM_block2
:
3411 case DW_FORM_block4
:
3413 case DW_FORM_string
:
3415 case DW_FORM_sec_offset
:
3418 error (_("Invalid extension opcode form %s\n"),
3419 get_FORM_name (form
));
3435 error (_(".debug_macro section not zero terminated\n"));
3439 op
= byte_get (curr
++, 1);
3445 case DW_MACRO_GNU_start_file
:
3447 unsigned int filenum
;
3448 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
3450 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3452 filenum
= read_leb128 (curr
, &bytes_read
, 0);
3455 if ((flags
& 2) == 0)
3456 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3459 = get_line_filename_and_dirname (line_offset
, filenum
,
3461 if (file_name
== NULL
)
3462 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3465 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3467 dir_name
!= NULL
? (const char *) dir_name
: "",
3468 dir_name
!= NULL
? "/" : "", file_name
);
3472 case DW_MACRO_GNU_end_file
:
3473 printf (_(" DW_MACRO_GNU_end_file\n"));
3476 case DW_MACRO_GNU_define
:
3477 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3479 string
= (char *) curr
;
3480 curr
+= strlen (string
) + 1;
3481 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3485 case DW_MACRO_GNU_undef
:
3486 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3488 string
= (char *) curr
;
3489 curr
+= strlen (string
) + 1;
3490 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3494 case DW_MACRO_GNU_define_indirect
:
3495 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3497 offset
= byte_get (curr
, offset_size
);
3498 curr
+= offset_size
;
3499 string
= fetch_indirect_string (offset
);
3500 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3504 case DW_MACRO_GNU_undef_indirect
:
3505 lineno
= read_leb128 (curr
, &bytes_read
, 0);
3507 offset
= byte_get (curr
, offset_size
);
3508 curr
+= offset_size
;
3509 string
= fetch_indirect_string (offset
);
3510 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3514 case DW_MACRO_GNU_transparent_include
:
3515 offset
= byte_get (curr
, offset_size
);
3516 curr
+= offset_size
;
3517 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3518 (unsigned long) offset
);
3522 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
3524 error (_(" Unknown macro opcode %02x seen\n"), op
);
3529 /* Skip over unhandled opcodes. */
3531 unsigned char *desc
= extended_ops
[op
];
3532 nargs
= read_leb128 (desc
, &bytes_read
, 0);
3536 printf (_(" DW_MACRO_GNU_%02x\n"), op
);
3539 printf (_(" DW_MACRO_GNU_%02x -"), op
);
3540 for (n
= 0; n
< nargs
; n
++)
3543 = read_and_display_attr_value (0, byte_get (desc
++, 1),
3544 curr
, 0, 0, offset_size
,
3545 version
, NULL
, 0, NULL
);
3562 display_debug_abbrev (struct dwarf_section
*section
,
3563 void *file ATTRIBUTE_UNUSED
)
3565 abbrev_entry
*entry
;
3566 unsigned char *start
= section
->start
;
3567 unsigned char *end
= start
+ section
->size
;
3569 printf (_("Contents of the %s section:\n\n"), section
->name
);
3575 start
= process_abbrev_section (start
, end
);
3577 if (first_abbrev
== NULL
)
3580 printf (_(" Number TAG\n"));
3582 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
3586 printf (" %ld %s [%s]\n",
3588 get_TAG_name (entry
->tag
),
3589 entry
->children
? _("has children") : _("no children"));
3591 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
3592 printf (" %-18s %s\n",
3593 get_AT_name (attr
->attribute
),
3594 get_FORM_name (attr
->form
));
3604 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3606 static dwarf_vma
*loc_offsets
;
3609 loc_offsets_compar (const void *ap
, const void *bp
)
3611 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
3612 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
3614 return (a
> b
) - (b
> a
);
3618 display_debug_loc (struct dwarf_section
*section
, void *file
)
3620 unsigned char *start
= section
->start
;
3621 unsigned char *section_end
;
3622 unsigned long bytes
;
3623 unsigned char *section_begin
= start
;
3624 unsigned int num_loc_list
= 0;
3625 unsigned long last_offset
= 0;
3626 unsigned int first
= 0;
3630 int seen_first_offset
= 0;
3631 int locs_sorted
= 1;
3632 unsigned char *next
;
3633 unsigned int *array
= NULL
;
3635 bytes
= section
->size
;
3636 section_end
= start
+ bytes
;
3640 printf (_("\nThe %s section is empty.\n"), section
->name
);
3644 if (load_debug_info (file
) == 0)
3646 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3651 /* Check the order of location list in .debug_info section. If
3652 offsets of location lists are in the ascending order, we can
3653 use `debug_information' directly. */
3654 for (i
= 0; i
< num_debug_info_entries
; i
++)
3658 num
= debug_information
[i
].num_loc_offsets
;
3659 if (num
> num_loc_list
)
3662 /* Check if we can use `debug_information' directly. */
3663 if (locs_sorted
&& num
!= 0)
3665 if (!seen_first_offset
)
3667 /* This is the first location list. */
3668 last_offset
= debug_information
[i
].loc_offsets
[0];
3670 seen_first_offset
= 1;
3676 for (; j
< num
; j
++)
3679 debug_information
[i
].loc_offsets
[j
])
3684 last_offset
= debug_information
[i
].loc_offsets
[j
];
3689 if (!seen_first_offset
)
3690 error (_("No location lists in .debug_info section!\n"));
3692 /* DWARF sections under Mach-O have non-zero addresses. */
3693 if (debug_information
[first
].num_loc_offsets
> 0
3694 && debug_information
[first
].loc_offsets
[0] != section
->address
)
3695 warn (_("Location lists in %s section start at 0x%s\n"),
3697 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
3700 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
3701 printf (_("Contents of the %s section:\n\n"), section
->name
);
3702 printf (_(" Offset Begin End Expression\n"));
3704 seen_first_offset
= 0;
3705 for (i
= first
; i
< num_debug_info_entries
; i
++)
3709 unsigned short length
;
3710 unsigned long offset
;
3711 unsigned int pointer_size
;
3712 unsigned int offset_size
;
3714 unsigned long cu_offset
;
3715 unsigned long base_address
;
3716 int need_frame_base
;
3719 pointer_size
= debug_information
[i
].pointer_size
;
3720 cu_offset
= debug_information
[i
].cu_offset
;
3721 offset_size
= debug_information
[i
].offset_size
;
3722 dwarf_version
= debug_information
[i
].dwarf_version
;
3725 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
3727 loc_offsets
= debug_information
[i
].loc_offsets
;
3728 qsort (array
, debug_information
[i
].num_loc_offsets
,
3729 sizeof (*array
), loc_offsets_compar
);
3732 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
3734 j
= locs_sorted
? k
: array
[k
];
3736 && debug_information
[i
].loc_offsets
[locs_sorted
3737 ? k
- 1 : array
[k
- 1]]
3738 == debug_information
[i
].loc_offsets
[j
])
3740 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
3741 /* DWARF sections under Mach-O have non-zero addresses. */
3742 offset
= debug_information
[i
].loc_offsets
[j
] - section
->address
;
3743 next
= section_begin
+ offset
;
3744 base_address
= debug_information
[i
].base_address
;
3746 if (!seen_first_offset
)
3747 seen_first_offset
= 1;
3751 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3752 (unsigned long) (start
- section_begin
),
3753 (unsigned long) (next
- section_begin
));
3754 else if (start
> next
)
3755 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3756 (unsigned long) (start
- section_begin
),
3757 (unsigned long) (next
- section_begin
));
3761 if (offset
>= bytes
)
3763 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3770 if (start
+ 2 * pointer_size
> section_end
)
3772 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3777 /* Note: we use sign extension here in order to be sure that
3778 we can detect the -1 escape value. Sign extension into the
3779 top 32 bits of a 32-bit address will not affect the values
3780 that we display since we always show hex values, and always
3781 the bottom 32-bits. */
3782 begin
= byte_get_signed (start
, pointer_size
);
3783 start
+= pointer_size
;
3784 end
= byte_get_signed (start
, pointer_size
);
3785 start
+= pointer_size
;
3787 printf (" %8.8lx ", offset
);
3789 if (begin
== 0 && end
== 0)
3791 printf (_("<End of list>\n"));
3795 /* Check base address specifiers. */
3796 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
3799 print_dwarf_vma (begin
, pointer_size
);
3800 print_dwarf_vma (end
, pointer_size
);
3801 printf (_("(base address)\n"));
3805 if (start
+ 2 > section_end
)
3807 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3812 length
= byte_get (start
, 2);
3815 if (start
+ length
> section_end
)
3817 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3822 print_dwarf_vma (begin
+ base_address
, pointer_size
);
3823 print_dwarf_vma (end
+ base_address
, pointer_size
);
3826 need_frame_base
= decode_location_expression (start
,
3831 cu_offset
, section
);
3834 if (need_frame_base
&& !has_frame_base
)
3835 printf (_(" [without DW_AT_frame_base]"));
3838 fputs (_(" (start == end)"), stdout
);
3839 else if (begin
> end
)
3840 fputs (_(" (start > end)"), stdout
);
3849 if (start
< section_end
)
3850 warn (_("There are %ld unused bytes at the end of section %s\n"),
3851 (long) (section_end
- start
), section
->name
);
3858 display_debug_str (struct dwarf_section
*section
,
3859 void *file ATTRIBUTE_UNUSED
)
3861 unsigned char *start
= section
->start
;
3862 unsigned long bytes
= section
->size
;
3863 dwarf_vma addr
= section
->address
;
3867 printf (_("\nThe %s section is empty.\n"), section
->name
);
3871 printf (_("Contents of the %s section:\n\n"), section
->name
);
3879 lbytes
= (bytes
> 16 ? 16 : bytes
);
3881 printf (" 0x%8.8lx ", (unsigned long) addr
);
3883 for (j
= 0; j
< 16; j
++)
3886 printf ("%2.2x", start
[j
]);
3894 for (j
= 0; j
< lbytes
; j
++)
3897 if (k
>= ' ' && k
< 0x80)
3916 display_debug_info (struct dwarf_section
*section
, void *file
)
3918 return process_debug_info (section
, file
, abbrev
, 0, 0);
3922 display_debug_types (struct dwarf_section
*section
, void *file
)
3924 return process_debug_info (section
, file
, abbrev
, 0, 1);
3928 display_trace_info (struct dwarf_section
*section
, void *file
)
3930 return process_debug_info (section
, file
, trace_abbrev
, 0, 0);
3934 display_debug_aranges (struct dwarf_section
*section
,
3935 void *file ATTRIBUTE_UNUSED
)
3937 unsigned char *start
= section
->start
;
3938 unsigned char *end
= start
+ section
->size
;
3940 printf (_("Contents of the %s section:\n\n"), section
->name
);
3942 /* It does not matter if this load fails,
3943 we test for that later on. */
3944 load_debug_info (file
);
3948 unsigned char *hdrptr
;
3949 DWARF2_Internal_ARange arange
;
3950 unsigned char *addr_ranges
;
3953 unsigned char address_size
;
3956 int initial_length_size
;
3960 arange
.ar_length
= byte_get (hdrptr
, 4);
3963 if (arange
.ar_length
== 0xffffffff)
3965 arange
.ar_length
= byte_get (hdrptr
, 8);
3968 initial_length_size
= 12;
3973 initial_length_size
= 4;
3976 arange
.ar_version
= byte_get (hdrptr
, 2);
3979 arange
.ar_info_offset
= byte_get (hdrptr
, offset_size
);
3980 hdrptr
+= offset_size
;
3982 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3983 && num_debug_info_entries
> 0
3984 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
3985 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3986 (unsigned long) arange
.ar_info_offset
, section
->name
);
3988 arange
.ar_pointer_size
= byte_get (hdrptr
, 1);
3991 arange
.ar_segment_size
= byte_get (hdrptr
, 1);
3994 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
3996 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4000 printf (_(" Length: %ld\n"),
4001 (long) arange
.ar_length
);
4002 printf (_(" Version: %d\n"), arange
.ar_version
);
4003 printf (_(" Offset into .debug_info: 0x%lx\n"),
4004 (unsigned long) arange
.ar_info_offset
);
4005 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
4006 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
4008 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
4010 if (address_size
== 0)
4012 error (_("Invalid address size in %s section!\n"),
4017 /* The DWARF spec does not require that the address size be a power
4018 of two, but we do. This will have to change if we ever encounter
4019 an uneven architecture. */
4020 if ((address_size
& (address_size
- 1)) != 0)
4022 warn (_("Pointer size + Segment size is not a power of two.\n"));
4026 if (address_size
> 4)
4027 printf (_("\n Address Length\n"));
4029 printf (_("\n Address Length\n"));
4031 addr_ranges
= hdrptr
;
4033 /* Must pad to an alignment boundary that is twice the address size. */
4034 excess
= (hdrptr
- start
) % (2 * address_size
);
4036 addr_ranges
+= (2 * address_size
) - excess
;
4038 start
+= arange
.ar_length
+ initial_length_size
;
4040 while (addr_ranges
+ 2 * address_size
<= start
)
4042 address
= byte_get (addr_ranges
, address_size
);
4044 addr_ranges
+= address_size
;
4046 length
= byte_get (addr_ranges
, address_size
);
4048 addr_ranges
+= address_size
;
4051 print_dwarf_vma (address
, address_size
);
4052 print_dwarf_vma (length
, address_size
);
4062 /* Each debug_information[x].range_lists[y] gets this representation for
4063 sorting purposes. */
4067 /* The debug_information[x].range_lists[y] value. */
4068 unsigned long ranges_offset
;
4070 /* Original debug_information to find parameters of the data. */
4071 debug_info
*debug_info_p
;
4074 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4077 range_entry_compar (const void *ap
, const void *bp
)
4079 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
4080 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
4081 const unsigned long a
= a_re
->ranges_offset
;
4082 const unsigned long b
= b_re
->ranges_offset
;
4084 return (a
> b
) - (b
> a
);
4088 display_debug_ranges (struct dwarf_section
*section
,
4089 void *file ATTRIBUTE_UNUSED
)
4091 unsigned char *start
= section
->start
;
4092 unsigned long bytes
;
4093 unsigned char *section_begin
= start
;
4094 unsigned int num_range_list
, i
;
4095 struct range_entry
*range_entries
, *range_entry_fill
;
4097 bytes
= section
->size
;
4101 printf (_("\nThe %s section is empty.\n"), section
->name
);
4105 if (load_debug_info (file
) == 0)
4107 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4113 for (i
= 0; i
< num_debug_info_entries
; i
++)
4114 num_range_list
+= debug_information
[i
].num_range_lists
;
4116 if (num_range_list
== 0)
4117 error (_("No range lists in .debug_info section!\n"));
4119 range_entries
= (struct range_entry
*)
4120 xmalloc (sizeof (*range_entries
) * num_range_list
);
4121 range_entry_fill
= range_entries
;
4123 for (i
= 0; i
< num_debug_info_entries
; i
++)
4125 debug_info
*debug_info_p
= &debug_information
[i
];
4128 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
4130 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
4131 range_entry_fill
->debug_info_p
= debug_info_p
;
4136 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
4137 range_entry_compar
);
4139 /* DWARF sections under Mach-O have non-zero addresses. */
4140 if (range_entries
[0].ranges_offset
!= section
->address
)
4141 warn (_("Range lists in %s section start at 0x%lx\n"),
4142 section
->name
, range_entries
[0].ranges_offset
);
4144 printf (_("Contents of the %s section:\n\n"), section
->name
);
4145 printf (_(" Offset Begin End\n"));
4147 for (i
= 0; i
< num_range_list
; i
++)
4149 struct range_entry
*range_entry
= &range_entries
[i
];
4150 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
4151 unsigned int pointer_size
;
4152 unsigned long offset
;
4153 unsigned char *next
;
4154 unsigned long base_address
;
4156 pointer_size
= debug_info_p
->pointer_size
;
4158 /* DWARF sections under Mach-O have non-zero addresses. */
4159 offset
= range_entry
->ranges_offset
- section
->address
;
4160 next
= section_begin
+ offset
;
4161 base_address
= debug_info_p
->base_address
;
4166 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4167 (unsigned long) (start
- section_begin
),
4168 (unsigned long) (next
- section_begin
), section
->name
);
4169 else if (start
> next
)
4170 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4171 (unsigned long) (start
- section_begin
),
4172 (unsigned long) (next
- section_begin
), section
->name
);
4181 /* Note: we use sign extension here in order to be sure that
4182 we can detect the -1 escape value. Sign extension into the
4183 top 32 bits of a 32-bit address will not affect the values
4184 that we display since we always show hex values, and always
4185 the bottom 32-bits. */
4186 begin
= byte_get_signed (start
, pointer_size
);
4187 start
+= pointer_size
;
4188 end
= byte_get_signed (start
, pointer_size
);
4189 start
+= pointer_size
;
4191 printf (" %8.8lx ", offset
);
4193 if (begin
== 0 && end
== 0)
4195 printf (_("<End of list>\n"));
4199 /* Check base address specifiers. */
4200 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4203 print_dwarf_vma (begin
, pointer_size
);
4204 print_dwarf_vma (end
, pointer_size
);
4205 printf ("(base address)\n");
4209 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4210 print_dwarf_vma (end
+ base_address
, pointer_size
);
4213 fputs (_("(start == end)"), stdout
);
4214 else if (begin
> end
)
4215 fputs (_("(start > end)"), stdout
);
4222 free (range_entries
);
4227 typedef struct Frame_Chunk
4229 struct Frame_Chunk
*next
;
4230 unsigned char *chunk_start
;
4232 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4233 short int *col_type
;
4236 unsigned int code_factor
;
4238 unsigned long pc_begin
;
4239 unsigned long pc_range
;
4243 unsigned char fde_encoding
;
4244 unsigned char cfa_exp
;
4245 unsigned char ptr_size
;
4246 unsigned char segment_size
;
4250 static const char *const *dwarf_regnames
;
4251 static unsigned int dwarf_regnames_count
;
4253 /* A marker for a col_type that means this column was never referenced
4254 in the frame info. */
4255 #define DW_CFA_unreferenced (-1)
4257 /* Return 0 if not more space is needed, 1 if more space is needed,
4258 -1 for invalid reg. */
4261 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
4263 int prev
= fc
->ncols
;
4265 if (reg
< (unsigned int) fc
->ncols
)
4268 if (dwarf_regnames_count
4269 && reg
> dwarf_regnames_count
)
4272 fc
->ncols
= reg
+ 1;
4273 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
4274 sizeof (short int));
4275 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
4277 while (prev
< fc
->ncols
)
4279 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
4280 fc
->col_offset
[prev
] = 0;
4286 static const char *const dwarf_regnames_i386
[] =
4288 "eax", "ecx", "edx", "ebx",
4289 "esp", "ebp", "esi", "edi",
4290 "eip", "eflags", NULL
,
4291 "st0", "st1", "st2", "st3",
4292 "st4", "st5", "st6", "st7",
4294 "xmm0", "xmm1", "xmm2", "xmm3",
4295 "xmm4", "xmm5", "xmm6", "xmm7",
4296 "mm0", "mm1", "mm2", "mm3",
4297 "mm4", "mm5", "mm6", "mm7",
4298 "fcw", "fsw", "mxcsr",
4299 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4304 init_dwarf_regnames_i386 (void)
4306 dwarf_regnames
= dwarf_regnames_i386
;
4307 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
4310 static const char *const dwarf_regnames_x86_64
[] =
4312 "rax", "rdx", "rcx", "rbx",
4313 "rsi", "rdi", "rbp", "rsp",
4314 "r8", "r9", "r10", "r11",
4315 "r12", "r13", "r14", "r15",
4317 "xmm0", "xmm1", "xmm2", "xmm3",
4318 "xmm4", "xmm5", "xmm6", "xmm7",
4319 "xmm8", "xmm9", "xmm10", "xmm11",
4320 "xmm12", "xmm13", "xmm14", "xmm15",
4321 "st0", "st1", "st2", "st3",
4322 "st4", "st5", "st6", "st7",
4323 "mm0", "mm1", "mm2", "mm3",
4324 "mm4", "mm5", "mm6", "mm7",
4326 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
4327 "fs.base", "gs.base", NULL
, NULL
,
4329 "mxcsr", "fcw", "fsw"
4333 init_dwarf_regnames_x86_64 (void)
4335 dwarf_regnames
= dwarf_regnames_x86_64
;
4336 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
4340 init_dwarf_regnames (unsigned int e_machine
)
4346 init_dwarf_regnames_i386 ();
4352 init_dwarf_regnames_x86_64 ();
4361 regname (unsigned int regno
, int row
)
4363 static char reg
[64];
4365 && regno
< dwarf_regnames_count
4366 && dwarf_regnames
[regno
] != NULL
)
4369 return dwarf_regnames
[regno
];
4370 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
4371 dwarf_regnames
[regno
]);
4374 snprintf (reg
, sizeof (reg
), "r%d", regno
);
4379 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, int *max_regs
)
4384 if (*max_regs
< fc
->ncols
)
4385 *max_regs
= fc
->ncols
;
4387 if (*need_col_headers
)
4389 static const char *sloc
= " LOC";
4391 *need_col_headers
= 0;
4393 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
4395 for (r
= 0; r
< *max_regs
; r
++)
4396 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4401 printf ("%-5s ", regname (r
, 1));
4407 printf ("%0*lx ", eh_addr_size
* 2, fc
->pc_begin
);
4409 strcpy (tmp
, "exp");
4411 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), fc
->cfa_offset
);
4412 printf ("%-8s ", tmp
);
4414 for (r
= 0; r
< fc
->ncols
; r
++)
4416 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
4418 switch (fc
->col_type
[r
])
4420 case DW_CFA_undefined
:
4423 case DW_CFA_same_value
:
4427 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
4429 case DW_CFA_val_offset
:
4430 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
4432 case DW_CFA_register
:
4433 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
4435 case DW_CFA_expression
:
4436 strcpy (tmp
, "exp");
4438 case DW_CFA_val_expression
:
4439 strcpy (tmp
, "vexp");
4442 strcpy (tmp
, "n/a");
4445 printf ("%-5s ", tmp
);
4451 #define GET(N) byte_get (start, N); start += N
4452 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4453 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4456 display_debug_frames (struct dwarf_section
*section
,
4457 void *file ATTRIBUTE_UNUSED
)
4459 unsigned char *start
= section
->start
;
4460 unsigned char *end
= start
+ section
->size
;
4461 unsigned char *section_start
= start
;
4462 Frame_Chunk
*chunks
= 0;
4463 Frame_Chunk
*remembered_state
= 0;
4465 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
4466 unsigned int length_return
;
4468 const char *bad_reg
= _("bad register: ");
4469 int saved_eh_addr_size
= eh_addr_size
;
4471 printf (_("Contents of the %s section:\n"), section
->name
);
4475 unsigned char *saved_start
;
4476 unsigned char *block_end
;
4477 unsigned long length
;
4478 unsigned long cie_id
;
4481 int need_col_headers
= 1;
4482 unsigned char *augmentation_data
= NULL
;
4483 unsigned long augmentation_data_len
= 0;
4484 int encoded_ptr_size
= saved_eh_addr_size
;
4486 int initial_length_size
;
4488 saved_start
= start
;
4489 length
= byte_get (start
, 4); start
+= 4;
4493 printf ("\n%08lx ZERO terminator\n\n",
4494 (unsigned long)(saved_start
- section_start
));
4498 if (length
== 0xffffffff)
4500 length
= byte_get (start
, 8);
4503 initial_length_size
= 12;
4508 initial_length_size
= 4;
4511 block_end
= saved_start
+ length
+ initial_length_size
;
4512 if (block_end
> end
)
4514 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4515 length
, (unsigned long)(saved_start
- section_start
));
4518 cie_id
= byte_get (start
, offset_size
); start
+= offset_size
;
4520 if (is_eh
? (cie_id
== 0) : (cie_id
== DW_CIE_ID
))
4524 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
4525 memset (fc
, 0, sizeof (Frame_Chunk
));
4529 fc
->chunk_start
= saved_start
;
4531 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4532 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4533 frame_need_space (fc
, max_regs
- 1);
4537 fc
->augmentation
= (char *) start
;
4538 start
= (unsigned char *) strchr ((char *) start
, '\0') + 1;
4540 if (strcmp (fc
->augmentation
, "eh") == 0)
4541 start
+= eh_addr_size
;
4545 fc
->ptr_size
= GET (1);
4546 fc
->segment_size
= GET (1);
4547 eh_addr_size
= fc
->ptr_size
;
4551 fc
->ptr_size
= eh_addr_size
;
4552 fc
->segment_size
= 0;
4554 fc
->code_factor
= LEB ();
4555 fc
->data_factor
= SLEB ();
4565 if (fc
->augmentation
[0] == 'z')
4567 augmentation_data_len
= LEB ();
4568 augmentation_data
= start
;
4569 start
+= augmentation_data_len
;
4573 if (do_debug_frames_interp
)
4574 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4575 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4576 fc
->augmentation
, fc
->code_factor
, fc
->data_factor
,
4580 printf ("\n%08lx %08lx %08lx CIE\n",
4581 (unsigned long)(saved_start
- section_start
), length
, cie_id
);
4582 printf (" Version: %d\n", version
);
4583 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
4586 printf (" Pointer Size: %u\n", fc
->ptr_size
);
4587 printf (" Segment Size: %u\n", fc
->segment_size
);
4589 printf (" Code alignment factor: %u\n", fc
->code_factor
);
4590 printf (" Data alignment factor: %d\n", fc
->data_factor
);
4591 printf (" Return address column: %d\n", fc
->ra
);
4593 if (augmentation_data_len
)
4596 printf (" Augmentation data: ");
4597 for (i
= 0; i
< augmentation_data_len
; ++i
)
4598 printf (" %02x", augmentation_data
[i
]);
4604 if (augmentation_data_len
)
4606 unsigned char *p
, *q
;
4607 p
= (unsigned char *) fc
->augmentation
+ 1;
4608 q
= augmentation_data
;
4615 q
+= 1 + size_of_encoded_value (*q
);
4617 fc
->fde_encoding
= *q
++;
4625 if (fc
->fde_encoding
)
4626 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4629 frame_need_space (fc
, fc
->ra
);
4633 unsigned char *look_for
;
4634 static Frame_Chunk fde_fc
;
4635 unsigned long segment_selector
;
4638 memset (fc
, 0, sizeof (Frame_Chunk
));
4640 look_for
= is_eh
? start
- 4 - cie_id
: section_start
+ cie_id
;
4642 for (cie
= chunks
; cie
; cie
= cie
->next
)
4643 if (cie
->chunk_start
== look_for
)
4648 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4649 cie_id
, (unsigned long)(saved_start
- section_start
));
4651 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
4652 fc
->col_offset
= (int *) xmalloc (sizeof (int));
4653 frame_need_space (fc
, max_regs
- 1);
4655 fc
->augmentation
= "";
4656 fc
->fde_encoding
= 0;
4657 fc
->ptr_size
= eh_addr_size
;
4658 fc
->segment_size
= 0;
4662 fc
->ncols
= cie
->ncols
;
4663 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
4664 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
4665 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
4666 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
4667 fc
->augmentation
= cie
->augmentation
;
4668 fc
->ptr_size
= cie
->ptr_size
;
4669 eh_addr_size
= cie
->ptr_size
;
4670 fc
->segment_size
= cie
->segment_size
;
4671 fc
->code_factor
= cie
->code_factor
;
4672 fc
->data_factor
= cie
->data_factor
;
4673 fc
->cfa_reg
= cie
->cfa_reg
;
4674 fc
->cfa_offset
= cie
->cfa_offset
;
4676 frame_need_space (fc
, max_regs
- 1);
4677 fc
->fde_encoding
= cie
->fde_encoding
;
4680 if (fc
->fde_encoding
)
4681 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
4683 segment_selector
= 0;
4684 if (fc
->segment_size
)
4686 segment_selector
= byte_get (start
, fc
->segment_size
);
4687 start
+= fc
->segment_size
;
4689 fc
->pc_begin
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4690 start
+= encoded_ptr_size
;
4691 fc
->pc_range
= byte_get (start
, encoded_ptr_size
);
4692 start
+= encoded_ptr_size
;
4694 if (cie
->augmentation
[0] == 'z')
4696 augmentation_data_len
= LEB ();
4697 augmentation_data
= start
;
4698 start
+= augmentation_data_len
;
4701 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4702 (unsigned long)(saved_start
- section_start
), length
, cie_id
,
4703 (unsigned long)(cie
->chunk_start
- section_start
));
4704 if (fc
->segment_size
)
4705 printf ("%04lx:", segment_selector
);
4706 printf ("%08lx..%08lx\n", fc
->pc_begin
, fc
->pc_begin
+ fc
->pc_range
);
4707 if (! do_debug_frames_interp
&& augmentation_data_len
)
4711 printf (" Augmentation data: ");
4712 for (i
= 0; i
< augmentation_data_len
; ++i
)
4713 printf (" %02x", augmentation_data
[i
]);
4719 /* At this point, fc is the current chunk, cie (if any) is set, and
4720 we're about to interpret instructions for the chunk. */
4721 /* ??? At present we need to do this always, since this sizes the
4722 fc->col_type and fc->col_offset arrays, which we write into always.
4723 We should probably split the interpreted and non-interpreted bits
4724 into two different routines, since there's so much that doesn't
4725 really overlap between them. */
4726 if (1 || do_debug_frames_interp
)
4728 /* Start by making a pass over the chunk, allocating storage
4729 and taking note of what registers are used. */
4730 unsigned char *tmp
= start
;
4732 while (start
< block_end
)
4735 unsigned long reg
, temp
;
4742 /* Warning: if you add any more cases to this switch, be
4743 sure to add them to the corresponding switch below. */
4746 case DW_CFA_advance_loc
:
4750 if (frame_need_space (fc
, opa
) >= 0)
4751 fc
->col_type
[opa
] = DW_CFA_undefined
;
4753 case DW_CFA_restore
:
4754 if (frame_need_space (fc
, opa
) >= 0)
4755 fc
->col_type
[opa
] = DW_CFA_undefined
;
4757 case DW_CFA_set_loc
:
4758 start
+= encoded_ptr_size
;
4760 case DW_CFA_advance_loc1
:
4763 case DW_CFA_advance_loc2
:
4766 case DW_CFA_advance_loc4
:
4769 case DW_CFA_offset_extended
:
4770 case DW_CFA_val_offset
:
4771 reg
= LEB (); LEB ();
4772 if (frame_need_space (fc
, reg
) >= 0)
4773 fc
->col_type
[reg
] = DW_CFA_undefined
;
4775 case DW_CFA_restore_extended
:
4777 frame_need_space (fc
, reg
);
4778 if (frame_need_space (fc
, reg
) >= 0)
4779 fc
->col_type
[reg
] = DW_CFA_undefined
;
4781 case DW_CFA_undefined
:
4783 if (frame_need_space (fc
, reg
) >= 0)
4784 fc
->col_type
[reg
] = DW_CFA_undefined
;
4786 case DW_CFA_same_value
:
4788 if (frame_need_space (fc
, reg
) >= 0)
4789 fc
->col_type
[reg
] = DW_CFA_undefined
;
4791 case DW_CFA_register
:
4792 reg
= LEB (); LEB ();
4793 if (frame_need_space (fc
, reg
) >= 0)
4794 fc
->col_type
[reg
] = DW_CFA_undefined
;
4796 case DW_CFA_def_cfa
:
4799 case DW_CFA_def_cfa_register
:
4802 case DW_CFA_def_cfa_offset
:
4805 case DW_CFA_def_cfa_expression
:
4809 case DW_CFA_expression
:
4810 case DW_CFA_val_expression
:
4814 if (frame_need_space (fc
, reg
) >= 0)
4815 fc
->col_type
[reg
] = DW_CFA_undefined
;
4817 case DW_CFA_offset_extended_sf
:
4818 case DW_CFA_val_offset_sf
:
4819 reg
= LEB (); SLEB ();
4820 if (frame_need_space (fc
, reg
) >= 0)
4821 fc
->col_type
[reg
] = DW_CFA_undefined
;
4823 case DW_CFA_def_cfa_sf
:
4826 case DW_CFA_def_cfa_offset_sf
:
4829 case DW_CFA_MIPS_advance_loc8
:
4832 case DW_CFA_GNU_args_size
:
4835 case DW_CFA_GNU_negative_offset_extended
:
4836 reg
= LEB (); LEB ();
4837 if (frame_need_space (fc
, reg
) >= 0)
4838 fc
->col_type
[reg
] = DW_CFA_undefined
;
4847 /* Now we know what registers are used, make a second pass over
4848 the chunk, this time actually printing out the info. */
4850 while (start
< block_end
)
4853 unsigned long ul
, reg
, roffs
;
4856 const char *reg_prefix
= "";
4863 /* Warning: if you add any more cases to this switch, be
4864 sure to add them to the corresponding switch above. */
4867 case DW_CFA_advance_loc
:
4868 if (do_debug_frames_interp
)
4869 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4871 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4872 opa
* fc
->code_factor
,
4873 fc
->pc_begin
+ opa
* fc
->code_factor
);
4874 fc
->pc_begin
+= opa
* fc
->code_factor
;
4879 if (opa
>= (unsigned int) fc
->ncols
)
4880 reg_prefix
= bad_reg
;
4881 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4882 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4883 reg_prefix
, regname (opa
, 0),
4884 roffs
* fc
->data_factor
);
4885 if (*reg_prefix
== '\0')
4887 fc
->col_type
[opa
] = DW_CFA_offset
;
4888 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
4892 case DW_CFA_restore
:
4893 if (opa
>= (unsigned int) cie
->ncols
4894 || opa
>= (unsigned int) fc
->ncols
)
4895 reg_prefix
= bad_reg
;
4896 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4897 printf (" DW_CFA_restore: %s%s\n",
4898 reg_prefix
, regname (opa
, 0));
4899 if (*reg_prefix
== '\0')
4901 fc
->col_type
[opa
] = cie
->col_type
[opa
];
4902 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
4903 if (do_debug_frames_interp
4904 && fc
->col_type
[opa
] == DW_CFA_unreferenced
)
4905 fc
->col_type
[opa
] = DW_CFA_undefined
;
4909 case DW_CFA_set_loc
:
4910 vma
= get_encoded_value (start
, fc
->fde_encoding
, section
);
4911 start
+= encoded_ptr_size
;
4912 if (do_debug_frames_interp
)
4913 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4915 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma
);
4919 case DW_CFA_advance_loc1
:
4920 ofs
= byte_get (start
, 1); start
+= 1;
4921 if (do_debug_frames_interp
)
4922 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4924 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4925 ofs
* fc
->code_factor
,
4926 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4927 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4930 case DW_CFA_advance_loc2
:
4931 ofs
= byte_get (start
, 2); start
+= 2;
4932 if (do_debug_frames_interp
)
4933 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4935 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4936 ofs
* fc
->code_factor
,
4937 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4938 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4941 case DW_CFA_advance_loc4
:
4942 ofs
= byte_get (start
, 4); start
+= 4;
4943 if (do_debug_frames_interp
)
4944 frame_display_row (fc
, &need_col_headers
, &max_regs
);
4946 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4947 ofs
* fc
->code_factor
,
4948 fc
->pc_begin
+ ofs
* fc
->code_factor
);
4949 fc
->pc_begin
+= ofs
* fc
->code_factor
;
4952 case DW_CFA_offset_extended
:
4955 if (reg
>= (unsigned int) fc
->ncols
)
4956 reg_prefix
= bad_reg
;
4957 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4958 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4959 reg_prefix
, regname (reg
, 0),
4960 roffs
* fc
->data_factor
);
4961 if (*reg_prefix
== '\0')
4963 fc
->col_type
[reg
] = DW_CFA_offset
;
4964 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4968 case DW_CFA_val_offset
:
4971 if (reg
>= (unsigned int) fc
->ncols
)
4972 reg_prefix
= bad_reg
;
4973 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4974 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4975 reg_prefix
, regname (reg
, 0),
4976 roffs
* fc
->data_factor
);
4977 if (*reg_prefix
== '\0')
4979 fc
->col_type
[reg
] = DW_CFA_val_offset
;
4980 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
4984 case DW_CFA_restore_extended
:
4986 if (reg
>= (unsigned int) cie
->ncols
4987 || reg
>= (unsigned int) fc
->ncols
)
4988 reg_prefix
= bad_reg
;
4989 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
4990 printf (" DW_CFA_restore_extended: %s%s\n",
4991 reg_prefix
, regname (reg
, 0));
4992 if (*reg_prefix
== '\0')
4994 fc
->col_type
[reg
] = cie
->col_type
[reg
];
4995 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
4999 case DW_CFA_undefined
:
5001 if (reg
>= (unsigned int) fc
->ncols
)
5002 reg_prefix
= bad_reg
;
5003 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5004 printf (" DW_CFA_undefined: %s%s\n",
5005 reg_prefix
, regname (reg
, 0));
5006 if (*reg_prefix
== '\0')
5008 fc
->col_type
[reg
] = DW_CFA_undefined
;
5009 fc
->col_offset
[reg
] = 0;
5013 case DW_CFA_same_value
:
5015 if (reg
>= (unsigned int) fc
->ncols
)
5016 reg_prefix
= bad_reg
;
5017 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5018 printf (" DW_CFA_same_value: %s%s\n",
5019 reg_prefix
, regname (reg
, 0));
5020 if (*reg_prefix
== '\0')
5022 fc
->col_type
[reg
] = DW_CFA_same_value
;
5023 fc
->col_offset
[reg
] = 0;
5027 case DW_CFA_register
:
5030 if (reg
>= (unsigned int) fc
->ncols
)
5031 reg_prefix
= bad_reg
;
5032 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5034 printf (" DW_CFA_register: %s%s in ",
5035 reg_prefix
, regname (reg
, 0));
5036 puts (regname (roffs
, 0));
5038 if (*reg_prefix
== '\0')
5040 fc
->col_type
[reg
] = DW_CFA_register
;
5041 fc
->col_offset
[reg
] = roffs
;
5045 case DW_CFA_remember_state
:
5046 if (! do_debug_frames_interp
)
5047 printf (" DW_CFA_remember_state\n");
5048 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
5049 rs
->ncols
= fc
->ncols
;
5050 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
5051 sizeof (short int));
5052 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (int));
5053 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
);
5054 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (int));
5055 rs
->next
= remembered_state
;
5056 remembered_state
= rs
;
5059 case DW_CFA_restore_state
:
5060 if (! do_debug_frames_interp
)
5061 printf (" DW_CFA_restore_state\n");
5062 rs
= remembered_state
;
5065 remembered_state
= rs
->next
;
5066 frame_need_space (fc
, rs
->ncols
- 1);
5067 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
);
5068 memcpy (fc
->col_offset
, rs
->col_offset
,
5069 rs
->ncols
* sizeof (int));
5070 free (rs
->col_type
);
5071 free (rs
->col_offset
);
5074 else if (do_debug_frames_interp
)
5075 printf ("Mismatched DW_CFA_restore_state\n");
5078 case DW_CFA_def_cfa
:
5079 fc
->cfa_reg
= LEB ();
5080 fc
->cfa_offset
= LEB ();
5082 if (! do_debug_frames_interp
)
5083 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5084 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5087 case DW_CFA_def_cfa_register
:
5088 fc
->cfa_reg
= LEB ();
5090 if (! do_debug_frames_interp
)
5091 printf (" DW_CFA_def_cfa_register: %s\n",
5092 regname (fc
->cfa_reg
, 0));
5095 case DW_CFA_def_cfa_offset
:
5096 fc
->cfa_offset
= LEB ();
5097 if (! do_debug_frames_interp
)
5098 printf (" DW_CFA_def_cfa_offset: %d\n", fc
->cfa_offset
);
5102 if (! do_debug_frames_interp
)
5103 printf (" DW_CFA_nop\n");
5106 case DW_CFA_def_cfa_expression
:
5108 if (! do_debug_frames_interp
)
5110 printf (" DW_CFA_def_cfa_expression (");
5111 decode_location_expression (start
, eh_addr_size
, 0, -1,
5119 case DW_CFA_expression
:
5122 if (reg
>= (unsigned int) fc
->ncols
)
5123 reg_prefix
= bad_reg
;
5124 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5126 printf (" DW_CFA_expression: %s%s (",
5127 reg_prefix
, regname (reg
, 0));
5128 decode_location_expression (start
, eh_addr_size
, 0, -1,
5132 if (*reg_prefix
== '\0')
5133 fc
->col_type
[reg
] = DW_CFA_expression
;
5137 case DW_CFA_val_expression
:
5140 if (reg
>= (unsigned int) fc
->ncols
)
5141 reg_prefix
= bad_reg
;
5142 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5144 printf (" DW_CFA_val_expression: %s%s (",
5145 reg_prefix
, regname (reg
, 0));
5146 decode_location_expression (start
, eh_addr_size
, 0, -1,
5150 if (*reg_prefix
== '\0')
5151 fc
->col_type
[reg
] = DW_CFA_val_expression
;
5155 case DW_CFA_offset_extended_sf
:
5158 if (frame_need_space (fc
, reg
) < 0)
5159 reg_prefix
= bad_reg
;
5160 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5161 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5162 reg_prefix
, regname (reg
, 0),
5163 l
* fc
->data_factor
);
5164 if (*reg_prefix
== '\0')
5166 fc
->col_type
[reg
] = DW_CFA_offset
;
5167 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5171 case DW_CFA_val_offset_sf
:
5174 if (frame_need_space (fc
, reg
) < 0)
5175 reg_prefix
= bad_reg
;
5176 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5177 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5178 reg_prefix
, regname (reg
, 0),
5179 l
* fc
->data_factor
);
5180 if (*reg_prefix
== '\0')
5182 fc
->col_type
[reg
] = DW_CFA_val_offset
;
5183 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5187 case DW_CFA_def_cfa_sf
:
5188 fc
->cfa_reg
= LEB ();
5189 fc
->cfa_offset
= SLEB ();
5190 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5192 if (! do_debug_frames_interp
)
5193 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5194 regname (fc
->cfa_reg
, 0), fc
->cfa_offset
);
5197 case DW_CFA_def_cfa_offset_sf
:
5198 fc
->cfa_offset
= SLEB ();
5199 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
5200 if (! do_debug_frames_interp
)
5201 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc
->cfa_offset
);
5204 case DW_CFA_MIPS_advance_loc8
:
5205 ofs
= byte_get (start
, 8); start
+= 8;
5206 if (do_debug_frames_interp
)
5207 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5209 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5210 ofs
* fc
->code_factor
,
5211 fc
->pc_begin
+ ofs
* fc
->code_factor
);
5212 fc
->pc_begin
+= ofs
* fc
->code_factor
;
5215 case DW_CFA_GNU_window_save
:
5216 if (! do_debug_frames_interp
)
5217 printf (" DW_CFA_GNU_window_save\n");
5220 case DW_CFA_GNU_args_size
:
5222 if (! do_debug_frames_interp
)
5223 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
5226 case DW_CFA_GNU_negative_offset_extended
:
5229 if (frame_need_space (fc
, reg
) < 0)
5230 reg_prefix
= bad_reg
;
5231 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
5232 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5233 reg_prefix
, regname (reg
, 0),
5234 l
* fc
->data_factor
);
5235 if (*reg_prefix
== '\0')
5237 fc
->col_type
[reg
] = DW_CFA_offset
;
5238 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
5243 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
5244 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
5246 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
5251 if (do_debug_frames_interp
)
5252 frame_display_row (fc
, &need_col_headers
, &max_regs
);
5255 eh_addr_size
= saved_eh_addr_size
;
5268 display_gdb_index (struct dwarf_section
*section
,
5269 void *file ATTRIBUTE_UNUSED
)
5271 unsigned char *start
= section
->start
;
5273 uint32_t cu_list_offset
, tu_list_offset
;
5274 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
5275 unsigned int cu_list_elements
, tu_list_elements
;
5276 unsigned int address_table_size
, symbol_table_slots
;
5277 unsigned char *cu_list
, *tu_list
;
5278 unsigned char *address_table
, *symbol_table
, *constant_pool
;
5281 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5283 printf (_("Contents of the %s section:\n"), section
->name
);
5285 if (section
->size
< 6 * sizeof (uint32_t))
5287 warn (_("Truncated header in the %s section.\n"), section
->name
);
5291 version
= byte_get_little_endian (start
, 4);
5292 printf (_("Version %ld\n"), (long) version
);
5294 /* Prior versions are obsolete, and future versions may not be
5295 backwards compatible. */
5299 warn (_("The address table data in version 3 may be wrong.\n"));
5302 warn (_("Version 4 does not support case insensitive lookups.\n"));
5305 warn (_("Version 5 does not include inlined functions.\n"));
5310 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
5314 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
5315 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
5316 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
5317 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
5318 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
5320 if (cu_list_offset
> section
->size
5321 || tu_list_offset
> section
->size
5322 || address_table_offset
> section
->size
5323 || symbol_table_offset
> section
->size
5324 || constant_pool_offset
> section
->size
)
5326 warn (_("Corrupt header in the %s section.\n"), section
->name
);
5330 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
5331 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
5332 address_table_size
= symbol_table_offset
- address_table_offset
;
5333 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
5335 cu_list
= start
+ cu_list_offset
;
5336 tu_list
= start
+ tu_list_offset
;
5337 address_table
= start
+ address_table_offset
;
5338 symbol_table
= start
+ symbol_table_offset
;
5339 constant_pool
= start
+ constant_pool_offset
;
5341 printf (_("\nCU table:\n"));
5342 for (i
= 0; i
< cu_list_elements
; i
+= 2)
5344 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
5345 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
5347 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
5348 (unsigned long) cu_offset
,
5349 (unsigned long) (cu_offset
+ cu_length
- 1));
5352 printf (_("\nTU table:\n"));
5353 for (i
= 0; i
< tu_list_elements
; i
+= 3)
5355 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
5356 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
5357 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
5359 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
5360 (unsigned long) tu_offset
,
5361 (unsigned long) type_offset
);
5362 print_dwarf_vma (signature
, 8);
5366 printf (_("\nAddress table:\n"));
5367 for (i
= 0; i
< address_table_size
; i
+= 2 * 8 + 4)
5369 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
5370 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
5371 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
5373 print_dwarf_vma (low
, 8);
5374 print_dwarf_vma (high
, 8);
5375 printf (_("%lu\n"), (unsigned long) cu_index
);
5378 printf (_("\nSymbol table:\n"));
5379 for (i
= 0; i
< symbol_table_slots
; ++i
)
5381 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
5382 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
5383 uint32_t num_cus
, cu
;
5385 if (name_offset
!= 0
5386 || cu_vector_offset
!= 0)
5390 printf ("[%3u] %s:", i
, constant_pool
+ name_offset
);
5391 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
5392 for (j
= 0; j
< num_cus
; ++j
)
5394 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
5395 /* Convert to TU number if it's for a type unit. */
5396 if (cu
>= cu_list_elements
/ 2)
5397 printf (" T%lu", (unsigned long) (cu
- cu_list_elements
/ 2));
5399 printf (" %lu", (unsigned long) cu
);
5409 display_debug_not_supported (struct dwarf_section
*section
,
5410 void *file ATTRIBUTE_UNUSED
)
5412 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5419 cmalloc (size_t nmemb
, size_t size
)
5421 /* Check for overflow. */
5422 if (nmemb
>= ~(size_t) 0 / size
)
5425 return malloc (nmemb
* size
);
5429 xcmalloc (size_t nmemb
, size_t size
)
5431 /* Check for overflow. */
5432 if (nmemb
>= ~(size_t) 0 / size
)
5435 return xmalloc (nmemb
* size
);
5439 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
5441 /* Check for overflow. */
5442 if (nmemb
>= ~(size_t) 0 / size
)
5445 return xrealloc (ptr
, nmemb
* size
);
5449 free_debug_memory (void)
5455 for (i
= 0; i
< max
; i
++)
5456 free_debug_section ((enum dwarf_section_display_enum
) i
);
5458 if (debug_information
!= NULL
)
5460 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
5462 for (i
= 0; i
< num_debug_info_entries
; i
++)
5464 if (!debug_information
[i
].max_loc_offsets
)
5466 free (debug_information
[i
].loc_offsets
);
5467 free (debug_information
[i
].have_frame_base
);
5469 if (!debug_information
[i
].max_range_lists
)
5470 free (debug_information
[i
].range_lists
);
5474 free (debug_information
);
5475 debug_information
= NULL
;
5476 num_debug_info_entries
= 0;
5481 dwarf_select_sections_by_names (const char *names
)
5485 const char * option
;
5489 debug_dump_long_opts
;
5491 static const debug_dump_long_opts opts_table
[] =
5493 /* Please keep this table alpha- sorted. */
5494 { "Ranges", & do_debug_ranges
, 1 },
5495 { "abbrev", & do_debug_abbrevs
, 1 },
5496 { "aranges", & do_debug_aranges
, 1 },
5497 { "frames", & do_debug_frames
, 1 },
5498 { "frames-interp", & do_debug_frames_interp
, 1 },
5499 { "info", & do_debug_info
, 1 },
5500 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
5501 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
5502 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
5503 { "loc", & do_debug_loc
, 1 },
5504 { "macro", & do_debug_macinfo
, 1 },
5505 { "pubnames", & do_debug_pubnames
, 1 },
5506 { "pubtypes", & do_debug_pubtypes
, 1 },
5507 /* This entry is for compatability
5508 with earlier versions of readelf. */
5509 { "ranges", & do_debug_aranges
, 1 },
5510 { "str", & do_debug_str
, 1 },
5511 /* The special .gdb_index section. */
5512 { "gdb_index", & do_gdb_index
, 1 },
5513 /* These trace_* sections are used by Itanium VMS. */
5514 { "trace_abbrev", & do_trace_abbrevs
, 1 },
5515 { "trace_aranges", & do_trace_aranges
, 1 },
5516 { "trace_info", & do_trace_info
, 1 },
5525 const debug_dump_long_opts
* entry
;
5527 for (entry
= opts_table
; entry
->option
; entry
++)
5529 size_t len
= strlen (entry
->option
);
5531 if (strncmp (p
, entry
->option
, len
) == 0
5532 && (p
[len
] == ',' || p
[len
] == '\0'))
5534 * entry
->variable
|= entry
->val
;
5536 /* The --debug-dump=frames-interp option also
5537 enables the --debug-dump=frames option. */
5538 if (do_debug_frames_interp
)
5539 do_debug_frames
= 1;
5546 if (entry
->option
== NULL
)
5548 warn (_("Unrecognized debug option '%s'\n"), p
);
5549 p
= strchr (p
, ',');
5560 dwarf_select_sections_by_letters (const char *letters
)
5562 unsigned int lindex
= 0;
5564 while (letters
[lindex
])
5565 switch (letters
[lindex
++])
5572 do_debug_abbrevs
= 1;
5576 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5580 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
5584 do_debug_pubnames
= 1;
5588 do_debug_pubtypes
= 1;
5592 do_debug_aranges
= 1;
5596 do_debug_ranges
= 1;
5600 do_debug_frames_interp
= 1;
5602 do_debug_frames
= 1;
5606 do_debug_macinfo
= 1;
5618 warn (_("Unrecognized debug option '%s'\n"), optarg
);
5624 dwarf_select_sections_all (void)
5627 do_debug_abbrevs
= 1;
5628 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
5629 do_debug_pubnames
= 1;
5630 do_debug_pubtypes
= 1;
5631 do_debug_aranges
= 1;
5632 do_debug_ranges
= 1;
5633 do_debug_frames
= 1;
5634 do_debug_macinfo
= 1;
5639 do_trace_abbrevs
= 1;
5640 do_trace_aranges
= 1;
5643 struct dwarf_section_display debug_displays
[] =
5645 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0 },
5646 display_debug_abbrev
, &do_debug_abbrevs
, 0 },
5647 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0 },
5648 display_debug_aranges
, &do_debug_aranges
, 1 },
5649 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0 },
5650 display_debug_frames
, &do_debug_frames
, 1 },
5651 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0 },
5652 display_debug_info
, &do_debug_info
, 1 },
5653 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0 },
5654 display_debug_lines
, &do_debug_lines
, 1 },
5655 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0 },
5656 display_debug_pubnames
, &do_debug_pubnames
, 0 },
5657 { { ".eh_frame", "", NULL
, NULL
, 0, 0 },
5658 display_debug_frames
, &do_debug_frames
, 1 },
5659 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0 },
5660 display_debug_macinfo
, &do_debug_macinfo
, 0 },
5661 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0 },
5662 display_debug_macro
, &do_debug_macinfo
, 1 },
5663 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0 },
5664 display_debug_str
, &do_debug_str
, 0 },
5665 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0 },
5666 display_debug_loc
, &do_debug_loc
, 1 },
5667 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0 },
5668 display_debug_pubnames
, &do_debug_pubtypes
, 0 },
5669 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0 },
5670 display_debug_ranges
, &do_debug_ranges
, 1 },
5671 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0 },
5672 display_debug_not_supported
, NULL
, 0 },
5673 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0 },
5674 display_debug_not_supported
, NULL
, 0 },
5675 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0 },
5676 display_debug_types
, &do_debug_info
, 1 },
5677 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0 },
5678 display_debug_not_supported
, NULL
, 0 },
5679 { { ".gdb_index", "", NULL
, NULL
, 0, 0 },
5680 display_gdb_index
, &do_gdb_index
, 0 },
5681 { { ".trace_info", "", NULL
, NULL
, 0, 0 },
5682 display_trace_info
, &do_trace_info
, 1 },
5683 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0 },
5684 display_debug_abbrev
, &do_trace_abbrevs
, 0 },
5685 { { ".trace_aranges", "", NULL
, NULL
, 0, 0 },
5686 display_debug_aranges
, &do_trace_aranges
, 0 }