1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
25 #include "bfd_stdint.h"
28 #include "elf/common.h"
32 static const char *regname (unsigned int regno, int row);
34 static int have_frame_base;
35 static int need_base_address;
37 static unsigned int last_pointer_size = 0;
38 static int warned_about_missing_comp_units = FALSE;
40 static unsigned int num_debug_info_entries = 0;
41 static debug_info *debug_information = NULL;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 int do_debug_pubnames;
52 int do_debug_pubtypes;
56 int do_debug_frames_interp;
66 int dwarf_cutoff_level = -1;
67 unsigned long dwarf_start_die;
69 /* Values for do_debug_lines. */
70 #define FLAG_DEBUG_LINES_RAW 1
71 #define FLAG_DEBUG_LINES_DECODED 2
74 size_of_encoded_value (int encoding)
76 switch (encoding & 0x7)
79 case 0: return eh_addr_size;
87 get_encoded_value (unsigned char *data,
89 struct dwarf_section *section)
91 int size = size_of_encoded_value (encoding);
94 if (encoding & DW_EH_PE_signed)
95 val = byte_get_signed (data, size);
97 val = byte_get (data, size);
99 if ((encoding & 0x70) == DW_EH_PE_pcrel)
100 val += section->address + (data - section->start);
104 /* Print a dwarf_vma value (typically an address, offset or length) in
105 hexadecimal format, followed by a space. The length of the value (and
106 hence the precision displayed) is determined by the byte_size parameter. */
109 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
111 static char buff[18];
114 /* Printf does not have a way of specifiying a maximum field width for an
115 integer value, so we print the full value into a buffer and then select
116 the precision we need. */
117 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
119 snprintf (buff, sizeof (buff), "%16.16llx ", val);
121 snprintf (buff, sizeof (buff), "%016I64x ", val);
124 snprintf (buff, sizeof (buff), "%16.16lx ", val);
129 if (byte_size > 0 && byte_size <= 8)
130 offset = 16 - 2 * byte_size;
132 error (_("Wrong size in print_dwarf_vma"));
135 fputs (buff + offset, stdout);
138 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
140 #define DWARF_VMA_FMT "ll"
142 #define DWARF_VMA_FMT "I64"
145 #define DWARF_VMA_FMT "l"
149 dwarf_vmatoa (const char *fmtch, dwarf_vma value)
151 /* As dwarf_vmatoa is used more then once in a printf call
152 for output, we are cycling through an fixed array of pointers
153 for return address. */
154 static int buf_pos = 0;
155 static struct dwarf_vmatoa_buf
162 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
164 ret = buf[buf_pos++].place;
165 buf_pos %= ARRAY_SIZE (buf);
167 snprintf (ret, sizeof (buf[0].place), fmt, value);
173 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
175 dwarf_vma result = 0;
176 unsigned int num_read = 0;
177 unsigned int shift = 0;
185 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
192 if (length_return != NULL)
193 *length_return = num_read;
195 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
196 result |= -1L << shift;
201 /* Create a signed version to avoid painful typecasts. */
202 static dwarf_signed_vma
203 read_sleb128 (unsigned char *data, unsigned int *length_return)
205 return (dwarf_signed_vma) read_leb128 (data, length_return, 1);
208 typedef struct State_Machine_Registers
216 unsigned char op_index;
217 unsigned char end_sequence;
218 /* This variable hold the number of the last entry seen
219 in the File Table. */
220 unsigned int last_file_entry;
223 static SMR state_machine_regs;
226 reset_state_machine (int is_stmt)
228 state_machine_regs.address = 0;
229 state_machine_regs.op_index = 0;
230 state_machine_regs.file = 1;
231 state_machine_regs.line = 1;
232 state_machine_regs.column = 0;
233 state_machine_regs.is_stmt = is_stmt;
234 state_machine_regs.basic_block = 0;
235 state_machine_regs.end_sequence = 0;
236 state_machine_regs.last_file_entry = 0;
239 /* Handled an extend line op.
240 Returns the number of bytes read. */
243 process_extended_line_op (unsigned char *data, int is_stmt)
245 unsigned char op_code;
246 unsigned int bytes_read;
251 len = read_leb128 (data, & bytes_read, 0);
256 warn (_("badly formed extended line op encountered!\n"));
263 printf (_(" Extended opcode %d: "), op_code);
267 case DW_LNE_end_sequence:
268 printf (_("End of Sequence\n\n"));
269 reset_state_machine (is_stmt);
272 case DW_LNE_set_address:
273 adr = byte_get (data, len - bytes_read - 1);
274 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
275 state_machine_regs.address = adr;
276 state_machine_regs.op_index = 0;
279 case DW_LNE_define_file:
280 printf (_(" define new File Table entry\n"));
281 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
283 printf (" %d\t", ++state_machine_regs.last_file_entry);
285 data += strlen ((char *) data) + 1;
286 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
288 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
290 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
291 printf ("%s\n\n", name);
294 case DW_LNE_set_discriminator:
295 printf (_("set Discriminator to %s\n"),
296 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
300 case DW_LNE_HP_negate_is_UV_update:
301 printf ("DW_LNE_HP_negate_is_UV_update\n");
303 case DW_LNE_HP_push_context:
304 printf ("DW_LNE_HP_push_context\n");
306 case DW_LNE_HP_pop_context:
307 printf ("DW_LNE_HP_pop_context\n");
309 case DW_LNE_HP_set_file_line_column:
310 printf ("DW_LNE_HP_set_file_line_column\n");
312 case DW_LNE_HP_set_routine_name:
313 printf ("DW_LNE_HP_set_routine_name\n");
315 case DW_LNE_HP_set_sequence:
316 printf ("DW_LNE_HP_set_sequence\n");
318 case DW_LNE_HP_negate_post_semantics:
319 printf ("DW_LNE_HP_negate_post_semantics\n");
321 case DW_LNE_HP_negate_function_exit:
322 printf ("DW_LNE_HP_negate_function_exit\n");
324 case DW_LNE_HP_negate_front_end_logical:
325 printf ("DW_LNE_HP_negate_front_end_logical\n");
327 case DW_LNE_HP_define_proc:
328 printf ("DW_LNE_HP_define_proc\n");
330 case DW_LNE_HP_source_file_correlation:
332 unsigned char *edata = data + len - bytes_read - 1;
334 printf ("DW_LNE_HP_source_file_correlation\n");
340 opc = read_leb128 (data, & bytes_read, 0);
345 case DW_LNE_HP_SFC_formfeed:
346 printf (" DW_LNE_HP_SFC_formfeed\n");
348 case DW_LNE_HP_SFC_set_listing_line:
349 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
351 read_leb128 (data, & bytes_read, 0)));
354 case DW_LNE_HP_SFC_associate:
355 printf (" DW_LNE_HP_SFC_associate ");
358 read_leb128 (data, & bytes_read, 0)));
362 read_leb128 (data, & bytes_read, 0)));
366 read_leb128 (data, & bytes_read, 0)));
370 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
380 unsigned int rlen = len - bytes_read - 1;
382 if (op_code >= DW_LNE_lo_user
383 /* The test against DW_LNW_hi_user is redundant due to
384 the limited range of the unsigned char data type used
386 /*&& op_code <= DW_LNE_hi_user*/)
387 printf (_("user defined: "));
389 printf (_("UNKNOWN: "));
390 printf (_("length %d ["), rlen);
392 printf (" %02x", *data++);
402 fetch_indirect_string (dwarf_vma offset)
404 struct dwarf_section *section = &debug_displays [str].section;
406 if (section->start == NULL)
407 return _("<no .debug_str section>");
409 /* DWARF sections under Mach-O have non-zero addresses. */
410 offset -= section->address;
411 if (offset > section->size)
413 warn (_("DW_FORM_strp offset too big: %s\n"),
414 dwarf_vmatoa ("x", offset));
415 return _("<offset is too big>");
418 return (const char *) section->start + offset;
421 /* FIXME: There are better and more efficient ways to handle
422 these structures. For now though, I just want something that
423 is simple to implement. */
424 typedef struct abbrev_attr
426 unsigned long attribute;
428 struct abbrev_attr *next;
432 typedef struct abbrev_entry
437 struct abbrev_attr *first_attr;
438 struct abbrev_attr *last_attr;
439 struct abbrev_entry *next;
443 static abbrev_entry *first_abbrev = NULL;
444 static abbrev_entry *last_abbrev = NULL;
451 for (abbrv = first_abbrev; abbrv;)
453 abbrev_entry *next_abbrev = abbrv->next;
456 for (attr = abbrv->first_attr; attr;)
458 abbrev_attr *next_attr = attr->next;
468 last_abbrev = first_abbrev = NULL;
472 add_abbrev (unsigned long number, unsigned long tag, int children)
476 entry = (abbrev_entry *) malloc (sizeof (*entry));
481 entry->entry = number;
483 entry->children = children;
484 entry->first_attr = NULL;
485 entry->last_attr = NULL;
488 if (first_abbrev == NULL)
489 first_abbrev = entry;
491 last_abbrev->next = entry;
497 add_abbrev_attr (unsigned long attribute, unsigned long form)
501 attr = (abbrev_attr *) malloc (sizeof (*attr));
506 attr->attribute = attribute;
510 if (last_abbrev->first_attr == NULL)
511 last_abbrev->first_attr = attr;
513 last_abbrev->last_attr->next = attr;
515 last_abbrev->last_attr = attr;
518 /* Processes the (partial) contents of a .debug_abbrev section.
519 Returns NULL if the end of the section was encountered.
520 Returns the address after the last byte read if the end of
521 an abbreviation set was found. */
523 static unsigned char *
524 process_abbrev_section (unsigned char *start, unsigned char *end)
526 if (first_abbrev != NULL)
531 unsigned int bytes_read;
534 unsigned long attribute;
537 entry = read_leb128 (start, & bytes_read, 0);
540 /* A single zero is supposed to end the section according
541 to the standard. If there's more, then signal that to
544 return start == end ? NULL : start;
546 tag = read_leb128 (start, & bytes_read, 0);
551 add_abbrev (entry, tag, children);
557 attribute = read_leb128 (start, & bytes_read, 0);
560 form = read_leb128 (start, & bytes_read, 0);
564 add_abbrev_attr (attribute, form);
566 while (attribute != 0);
573 get_TAG_name (unsigned long tag)
577 case DW_TAG_padding: return "DW_TAG_padding";
578 case DW_TAG_array_type: return "DW_TAG_array_type";
579 case DW_TAG_class_type: return "DW_TAG_class_type";
580 case DW_TAG_entry_point: return "DW_TAG_entry_point";
581 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
582 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
583 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
584 case DW_TAG_label: return "DW_TAG_label";
585 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
586 case DW_TAG_member: return "DW_TAG_member";
587 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
588 case DW_TAG_reference_type: return "DW_TAG_reference_type";
589 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
590 case DW_TAG_string_type: return "DW_TAG_string_type";
591 case DW_TAG_structure_type: return "DW_TAG_structure_type";
592 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
593 case DW_TAG_typedef: return "DW_TAG_typedef";
594 case DW_TAG_union_type: return "DW_TAG_union_type";
595 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
596 case DW_TAG_variant: return "DW_TAG_variant";
597 case DW_TAG_common_block: return "DW_TAG_common_block";
598 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
599 case DW_TAG_inheritance: return "DW_TAG_inheritance";
600 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
601 case DW_TAG_module: return "DW_TAG_module";
602 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
603 case DW_TAG_set_type: return "DW_TAG_set_type";
604 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
605 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
606 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
607 case DW_TAG_base_type: return "DW_TAG_base_type";
608 case DW_TAG_catch_block: return "DW_TAG_catch_block";
609 case DW_TAG_const_type: return "DW_TAG_const_type";
610 case DW_TAG_constant: return "DW_TAG_constant";
611 case DW_TAG_enumerator: return "DW_TAG_enumerator";
612 case DW_TAG_file_type: return "DW_TAG_file_type";
613 case DW_TAG_friend: return "DW_TAG_friend";
614 case DW_TAG_namelist: return "DW_TAG_namelist";
615 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
616 case DW_TAG_packed_type: return "DW_TAG_packed_type";
617 case DW_TAG_subprogram: return "DW_TAG_subprogram";
618 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
619 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
620 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
621 case DW_TAG_try_block: return "DW_TAG_try_block";
622 case DW_TAG_variant_part: return "DW_TAG_variant_part";
623 case DW_TAG_variable: return "DW_TAG_variable";
624 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
625 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
626 case DW_TAG_format_label: return "DW_TAG_format_label";
627 case DW_TAG_function_template: return "DW_TAG_function_template";
628 case DW_TAG_class_template: return "DW_TAG_class_template";
629 /* DWARF 2.1 values. */
630 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
631 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
632 case DW_TAG_interface_type: return "DW_TAG_interface_type";
633 case DW_TAG_namespace: return "DW_TAG_namespace";
634 case DW_TAG_imported_module: return "DW_TAG_imported_module";
635 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
636 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
637 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
638 case DW_TAG_condition: return "DW_TAG_condition";
639 case DW_TAG_shared_type: return "DW_TAG_shared_type";
640 /* DWARF 4 values. */
641 case DW_TAG_type_unit: return "DW_TAG_type_unit";
642 case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type";
643 case DW_TAG_template_alias: return "DW_TAG_template_alias";
645 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
646 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
647 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
649 case DW_TAG_GNU_call_site: return "DW_TAG_GNU_call_site";
650 case DW_TAG_GNU_call_site_parameter:return "DW_TAG_GNU_call_site_parameter";
653 static char buffer[100];
655 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
662 get_FORM_name (unsigned long form)
666 case DW_FORM_addr: return "DW_FORM_addr";
667 case DW_FORM_block2: return "DW_FORM_block2";
668 case DW_FORM_block4: return "DW_FORM_block4";
669 case DW_FORM_data2: return "DW_FORM_data2";
670 case DW_FORM_data4: return "DW_FORM_data4";
671 case DW_FORM_data8: return "DW_FORM_data8";
672 case DW_FORM_string: return "DW_FORM_string";
673 case DW_FORM_block: return "DW_FORM_block";
674 case DW_FORM_block1: return "DW_FORM_block1";
675 case DW_FORM_data1: return "DW_FORM_data1";
676 case DW_FORM_flag: return "DW_FORM_flag";
677 case DW_FORM_sdata: return "DW_FORM_sdata";
678 case DW_FORM_strp: return "DW_FORM_strp";
679 case DW_FORM_udata: return "DW_FORM_udata";
680 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
681 case DW_FORM_ref1: return "DW_FORM_ref1";
682 case DW_FORM_ref2: return "DW_FORM_ref2";
683 case DW_FORM_ref4: return "DW_FORM_ref4";
684 case DW_FORM_ref8: return "DW_FORM_ref8";
685 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
686 case DW_FORM_indirect: return "DW_FORM_indirect";
687 /* DWARF 4 values. */
688 case DW_FORM_sec_offset: return "DW_FORM_sec_offset";
689 case DW_FORM_exprloc: return "DW_FORM_exprloc";
690 case DW_FORM_flag_present: return "DW_FORM_flag_present";
691 case DW_FORM_ref_sig8: return "DW_FORM_ref_sig8";
694 static char buffer[100];
696 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
702 static unsigned char *
703 display_block (unsigned char *data, dwarf_vma length)
705 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
708 printf ("%lx ", (unsigned long) byte_get (data++, 1));
714 decode_location_expression (unsigned char * data,
715 unsigned int pointer_size,
716 unsigned int offset_size,
720 struct dwarf_section * section)
723 unsigned int bytes_read;
725 unsigned char *end = data + length;
726 int need_frame_base = 0;
735 printf ("DW_OP_addr: %s",
736 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
737 data += pointer_size;
740 printf ("DW_OP_deref");
743 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
746 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
749 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
753 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
757 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
761 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
765 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
766 (unsigned long) byte_get (data + 4, 4));
770 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
771 (long) byte_get (data + 4, 4));
775 printf ("DW_OP_constu: %s",
776 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
780 printf ("DW_OP_consts: %s",
781 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
785 printf ("DW_OP_dup");
788 printf ("DW_OP_drop");
791 printf ("DW_OP_over");
794 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
797 printf ("DW_OP_swap");
800 printf ("DW_OP_rot");
803 printf ("DW_OP_xderef");
806 printf ("DW_OP_abs");
809 printf ("DW_OP_and");
812 printf ("DW_OP_div");
815 printf ("DW_OP_minus");
818 printf ("DW_OP_mod");
821 printf ("DW_OP_mul");
824 printf ("DW_OP_neg");
827 printf ("DW_OP_not");
833 printf ("DW_OP_plus");
835 case DW_OP_plus_uconst:
836 printf ("DW_OP_plus_uconst: %s",
837 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
841 printf ("DW_OP_shl");
844 printf ("DW_OP_shr");
847 printf ("DW_OP_shra");
850 printf ("DW_OP_xor");
853 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
875 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
911 printf ("DW_OP_lit%d", op - DW_OP_lit0);
946 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
947 regname (op - DW_OP_reg0, 1));
982 printf ("DW_OP_breg%d (%s): %s",
984 regname (op - DW_OP_breg0, 1),
985 dwarf_vmatoa ("d", (dwarf_signed_vma)
986 read_leb128 (data, &bytes_read, 1)));
991 uvalue = read_leb128 (data, &bytes_read, 0);
993 printf ("DW_OP_regx: %s (%s)",
994 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
998 printf ("DW_OP_fbreg: %s",
999 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1003 uvalue = read_leb128 (data, &bytes_read, 0);
1005 printf ("DW_OP_bregx: %s (%s) %s",
1006 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1007 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1011 printf ("DW_OP_piece: %s",
1012 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1015 case DW_OP_deref_size:
1016 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
1018 case DW_OP_xderef_size:
1019 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
1022 printf ("DW_OP_nop");
1025 /* DWARF 3 extensions. */
1026 case DW_OP_push_object_address:
1027 printf ("DW_OP_push_object_address");
1030 /* XXX: Strictly speaking for 64-bit DWARF3 files
1031 this ought to be an 8-byte wide computation. */
1032 printf ("DW_OP_call2: <0x%s>",
1033 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2)
1038 /* XXX: Strictly speaking for 64-bit DWARF3 files
1039 this ought to be an 8-byte wide computation. */
1040 printf ("DW_OP_call4: <0x%s>",
1041 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4)
1045 case DW_OP_call_ref:
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_call_ref 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_call_ref: <0x%s>",
1057 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
1058 data += pointer_size;
1062 printf ("DW_OP_call_ref: <0x%s>",
1063 dwarf_vmatoa ("x", byte_get (data, offset_size)));
1064 data += offset_size;
1067 case DW_OP_form_tls_address:
1068 printf ("DW_OP_form_tls_address");
1070 case DW_OP_call_frame_cfa:
1071 printf ("DW_OP_call_frame_cfa");
1073 case DW_OP_bit_piece:
1074 printf ("DW_OP_bit_piece: ");
1075 printf (_("size: %s "),
1076 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1078 printf (_("offset: %s "),
1079 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1083 /* DWARF 4 extensions. */
1084 case DW_OP_stack_value:
1085 printf ("DW_OP_stack_value");
1088 case DW_OP_implicit_value:
1089 printf ("DW_OP_implicit_value");
1090 uvalue = read_leb128 (data, &bytes_read, 0);
1092 display_block (data, uvalue);
1096 /* GNU extensions. */
1097 case DW_OP_GNU_push_tls_address:
1098 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1100 case DW_OP_GNU_uninit:
1101 printf ("DW_OP_GNU_uninit");
1102 /* FIXME: Is there data associated with this OP ? */
1104 case DW_OP_GNU_encoded_addr:
1110 addr = get_encoded_value (data, encoding, section);
1111 data += size_of_encoded_value (encoding);
1113 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1114 print_dwarf_vma (addr, pointer_size);
1117 case DW_OP_GNU_implicit_pointer:
1118 /* XXX: Strictly speaking for 64-bit DWARF3 files
1119 this ought to be an 8-byte wide computation. */
1120 if (dwarf_version == -1)
1122 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1123 /* No way to tell where the next op is, so just bail. */
1124 return need_frame_base;
1126 if (dwarf_version == 2)
1128 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1129 dwarf_vmatoa ("x", byte_get (data, pointer_size)),
1130 dwarf_vmatoa ("d", read_sleb128 (data + pointer_size,
1132 data += pointer_size + bytes_read;
1136 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1137 dwarf_vmatoa ("x", byte_get (data, offset_size)),
1138 dwarf_vmatoa ("d", read_sleb128 (data + offset_size,
1140 data += offset_size + bytes_read;
1143 case DW_OP_GNU_entry_value:
1144 uvalue = read_leb128 (data, &bytes_read, 0);
1146 printf ("DW_OP_GNU_entry_value: (");
1147 if (decode_location_expression (data, pointer_size, offset_size,
1148 dwarf_version, uvalue,
1149 cu_offset, section))
1150 need_frame_base = 1;
1154 case DW_OP_GNU_const_type:
1155 uvalue = read_leb128 (data, &bytes_read, 0);
1157 printf ("DW_OP_GNU_const_type: <0x%s> ",
1158 dwarf_vmatoa ("x", cu_offset + uvalue));
1159 uvalue = byte_get (data++, 1);
1160 display_block (data, uvalue);
1163 case DW_OP_GNU_regval_type:
1164 uvalue = read_leb128 (data, &bytes_read, 0);
1166 printf ("DW_OP_GNU_regval_type: %s (%s)",
1167 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1168 uvalue = read_leb128 (data, &bytes_read, 0);
1170 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1172 case DW_OP_GNU_deref_type:
1173 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data++, 1));
1174 uvalue = read_leb128 (data, &bytes_read, 0);
1176 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1178 case DW_OP_GNU_convert:
1179 uvalue = read_leb128 (data, &bytes_read, 0);
1181 printf ("DW_OP_GNU_convert <0x%s>",
1182 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1184 case DW_OP_GNU_reinterpret:
1185 uvalue = read_leb128 (data, &bytes_read, 0);
1187 printf ("DW_OP_GNU_reinterpret <0x%s>",
1188 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1190 case DW_OP_GNU_parameter_ref:
1191 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1192 dwarf_vmatoa ("x", cu_offset + byte_get (data, 4)));
1196 /* HP extensions. */
1197 case DW_OP_HP_is_value:
1198 printf ("DW_OP_HP_is_value");
1199 /* FIXME: Is there data associated with this OP ? */
1201 case DW_OP_HP_fltconst4:
1202 printf ("DW_OP_HP_fltconst4");
1203 /* FIXME: Is there data associated with this OP ? */
1205 case DW_OP_HP_fltconst8:
1206 printf ("DW_OP_HP_fltconst8");
1207 /* FIXME: Is there data associated with this OP ? */
1209 case DW_OP_HP_mod_range:
1210 printf ("DW_OP_HP_mod_range");
1211 /* FIXME: Is there data associated with this OP ? */
1213 case DW_OP_HP_unmod_range:
1214 printf ("DW_OP_HP_unmod_range");
1215 /* FIXME: Is there data associated with this OP ? */
1218 printf ("DW_OP_HP_tls");
1219 /* FIXME: Is there data associated with this OP ? */
1222 /* PGI (STMicroelectronics) extensions. */
1223 case DW_OP_PGI_omp_thread_num:
1224 /* Pushes the thread number for the current thread as it would be
1225 returned by the standard OpenMP library function:
1226 omp_get_thread_num(). The "current thread" is the thread for
1227 which the expression is being evaluated. */
1228 printf ("DW_OP_PGI_omp_thread_num");
1232 if (op >= DW_OP_lo_user
1233 && op <= DW_OP_hi_user)
1234 printf (_("(User defined location op)"));
1236 printf (_("(Unknown location op)"));
1237 /* No way to tell where the next op is, so just bail. */
1238 return need_frame_base;
1241 /* Separate the ops. */
1246 return need_frame_base;
1249 static unsigned char *
1250 read_and_display_attr_value (unsigned long attribute,
1252 unsigned char * data,
1253 dwarf_vma cu_offset,
1254 dwarf_vma pointer_size,
1255 dwarf_vma offset_size,
1257 debug_info * debug_info_p,
1259 struct dwarf_section * section)
1261 dwarf_vma uvalue = 0;
1262 unsigned char *block_start = NULL;
1263 unsigned char * orig_data = data;
1264 unsigned int bytes_read;
1271 case DW_FORM_ref_addr:
1272 if (dwarf_version == 2)
1274 uvalue = byte_get (data, pointer_size);
1275 data += pointer_size;
1277 else if (dwarf_version == 3 || dwarf_version == 4)
1279 uvalue = byte_get (data, offset_size);
1280 data += offset_size;
1283 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1288 uvalue = byte_get (data, pointer_size);
1289 data += pointer_size;
1293 case DW_FORM_sec_offset:
1294 uvalue = byte_get (data, offset_size);
1295 data += offset_size;
1298 case DW_FORM_flag_present:
1305 uvalue = byte_get (data++, 1);
1310 uvalue = byte_get (data, 2);
1316 uvalue = byte_get (data, 4);
1321 uvalue = read_leb128 (data, & bytes_read, 1);
1325 case DW_FORM_ref_udata:
1327 uvalue = read_leb128 (data, & bytes_read, 0);
1331 case DW_FORM_indirect:
1332 form = read_leb128 (data, & bytes_read, 0);
1335 printf (" %s", get_FORM_name (form));
1336 return read_and_display_attr_value (attribute, form, data,
1337 cu_offset, pointer_size,
1338 offset_size, dwarf_version,
1339 debug_info_p, do_loc,
1345 case DW_FORM_ref_addr:
1347 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1353 case DW_FORM_ref_udata:
1355 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1360 case DW_FORM_sec_offset:
1362 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1365 case DW_FORM_flag_present:
1372 printf (" %s", dwarf_vmatoa ("d", uvalue));
1379 uvalue = byte_get (data, 4);
1380 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1381 printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
1383 if ((do_loc || do_debug_loc || do_debug_ranges)
1384 && num_debug_info_entries == 0)
1386 if (sizeof (uvalue) == 8)
1387 uvalue = byte_get (data, 8);
1389 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1394 case DW_FORM_string:
1396 printf (" %s", data);
1397 data += strlen ((char *) data) + 1;
1401 case DW_FORM_exprloc:
1402 uvalue = read_leb128 (data, & bytes_read, 0);
1403 block_start = data + bytes_read;
1405 data = block_start + uvalue;
1407 data = display_block (block_start, uvalue);
1410 case DW_FORM_block1:
1411 uvalue = byte_get (data, 1);
1412 block_start = data + 1;
1414 data = block_start + uvalue;
1416 data = display_block (block_start, uvalue);
1419 case DW_FORM_block2:
1420 uvalue = byte_get (data, 2);
1421 block_start = data + 2;
1423 data = block_start + uvalue;
1425 data = display_block (block_start, uvalue);
1428 case DW_FORM_block4:
1429 uvalue = byte_get (data, 4);
1430 block_start = data + 4;
1432 data = block_start + uvalue;
1434 data = display_block (block_start, uvalue);
1439 printf (_(" (indirect string, offset: 0x%s): %s"),
1440 dwarf_vmatoa ("x", uvalue),
1441 fetch_indirect_string (uvalue));
1444 case DW_FORM_indirect:
1445 /* Handled above. */
1448 case DW_FORM_ref_sig8:
1452 printf (" signature: ");
1453 for (i = 0; i < 8; i++)
1455 printf ("%02x", (unsigned) byte_get (data, 1));
1464 warn (_("Unrecognized form: %lu\n"), form);
1468 if ((do_loc || do_debug_loc || do_debug_ranges)
1469 && num_debug_info_entries == 0
1470 && debug_info_p != NULL)
1474 case DW_AT_frame_base:
1475 have_frame_base = 1;
1476 case DW_AT_location:
1477 case DW_AT_string_length:
1478 case DW_AT_return_addr:
1479 case DW_AT_data_member_location:
1480 case DW_AT_vtable_elem_location:
1482 case DW_AT_static_link:
1483 case DW_AT_use_location:
1484 case DW_AT_GNU_call_site_value:
1485 case DW_AT_GNU_call_site_data_value:
1486 case DW_AT_GNU_call_site_target:
1487 case DW_AT_GNU_call_site_target_clobbered:
1488 if ((dwarf_version < 4
1489 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1490 || form == DW_FORM_sec_offset)
1492 /* Process location list. */
1493 unsigned int lmax = debug_info_p->max_loc_offsets;
1494 unsigned int num = debug_info_p->num_loc_offsets;
1496 if (lmax == 0 || num >= lmax)
1499 debug_info_p->loc_offsets = (dwarf_vma *)
1500 xcrealloc (debug_info_p->loc_offsets,
1501 lmax, sizeof (*debug_info_p->loc_offsets));
1502 debug_info_p->have_frame_base = (int *)
1503 xcrealloc (debug_info_p->have_frame_base,
1504 lmax, sizeof (*debug_info_p->have_frame_base));
1505 debug_info_p->max_loc_offsets = lmax;
1507 debug_info_p->loc_offsets [num] = uvalue;
1508 debug_info_p->have_frame_base [num] = have_frame_base;
1509 debug_info_p->num_loc_offsets++;
1514 if (need_base_address)
1515 debug_info_p->base_address = uvalue;
1519 if ((dwarf_version < 4
1520 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1521 || form == DW_FORM_sec_offset)
1523 /* Process range list. */
1524 unsigned int lmax = debug_info_p->max_range_lists;
1525 unsigned int num = debug_info_p->num_range_lists;
1527 if (lmax == 0 || num >= lmax)
1530 debug_info_p->range_lists = (dwarf_vma *)
1531 xcrealloc (debug_info_p->range_lists,
1532 lmax, sizeof (*debug_info_p->range_lists));
1533 debug_info_p->max_range_lists = lmax;
1535 debug_info_p->range_lists [num] = uvalue;
1536 debug_info_p->num_range_lists++;
1545 if (do_loc || attribute == 0)
1548 /* For some attributes we can display further information. */
1556 case DW_INL_not_inlined:
1557 printf (_("(not inlined)"));
1559 case DW_INL_inlined:
1560 printf (_("(inlined)"));
1562 case DW_INL_declared_not_inlined:
1563 printf (_("(declared as inline but ignored)"));
1565 case DW_INL_declared_inlined:
1566 printf (_("(declared as inline and inlined)"));
1569 printf (_(" (Unknown inline attribute value: %s)"),
1570 dwarf_vmatoa ("x", uvalue));
1575 case DW_AT_language:
1578 /* Ordered by the numeric value of these constants. */
1579 case DW_LANG_C89: printf ("(ANSI C)"); break;
1580 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1581 case DW_LANG_Ada83: printf ("(Ada)"); break;
1582 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1583 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1584 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1585 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1586 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1587 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1588 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1589 /* DWARF 2.1 values. */
1590 case DW_LANG_Java: printf ("(Java)"); break;
1591 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1592 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1593 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1594 /* DWARF 3 values. */
1595 case DW_LANG_PLI: printf ("(PLI)"); break;
1596 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1597 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1598 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1599 case DW_LANG_D: printf ("(D)"); break;
1600 /* DWARF 4 values. */
1601 case DW_LANG_Python: printf ("(Python)"); break;
1602 /* DWARF 5 values. */
1603 case DW_LANG_Go: printf ("(Go)"); break;
1604 /* MIPS extension. */
1605 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1606 /* UPC extension. */
1607 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1609 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1610 printf (_("(implementation defined: %s)"),
1611 dwarf_vmatoa ("x", uvalue));
1613 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1618 case DW_AT_encoding:
1621 case DW_ATE_void: printf ("(void)"); break;
1622 case DW_ATE_address: printf ("(machine address)"); break;
1623 case DW_ATE_boolean: printf ("(boolean)"); break;
1624 case DW_ATE_complex_float: printf ("(complex float)"); break;
1625 case DW_ATE_float: printf ("(float)"); break;
1626 case DW_ATE_signed: printf ("(signed)"); break;
1627 case DW_ATE_signed_char: printf ("(signed char)"); break;
1628 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1629 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1630 /* DWARF 2.1 values: */
1631 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1632 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1633 /* DWARF 3 values: */
1634 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1635 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1636 case DW_ATE_edited: printf ("(edited)"); break;
1637 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1638 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1639 /* HP extensions: */
1640 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1641 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1642 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1643 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1644 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1645 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1646 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1649 if (uvalue >= DW_ATE_lo_user
1650 && uvalue <= DW_ATE_hi_user)
1651 printf (_("(user defined type)"));
1653 printf (_("(unknown type)"));
1658 case DW_AT_accessibility:
1661 case DW_ACCESS_public: printf ("(public)"); break;
1662 case DW_ACCESS_protected: printf ("(protected)"); break;
1663 case DW_ACCESS_private: printf ("(private)"); break;
1665 printf (_("(unknown accessibility)"));
1670 case DW_AT_visibility:
1673 case DW_VIS_local: printf ("(local)"); break;
1674 case DW_VIS_exported: printf ("(exported)"); break;
1675 case DW_VIS_qualified: printf ("(qualified)"); break;
1676 default: printf (_("(unknown visibility)")); break;
1680 case DW_AT_virtuality:
1683 case DW_VIRTUALITY_none: printf ("(none)"); break;
1684 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1685 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1686 default: printf (_("(unknown virtuality)")); break;
1690 case DW_AT_identifier_case:
1693 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1694 case DW_ID_up_case: printf ("(up_case)"); break;
1695 case DW_ID_down_case: printf ("(down_case)"); break;
1696 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1697 default: printf (_("(unknown case)")); break;
1701 case DW_AT_calling_convention:
1704 case DW_CC_normal: printf ("(normal)"); break;
1705 case DW_CC_program: printf ("(program)"); break;
1706 case DW_CC_nocall: printf ("(nocall)"); break;
1708 if (uvalue >= DW_CC_lo_user
1709 && uvalue <= DW_CC_hi_user)
1710 printf (_("(user defined)"));
1712 printf (_("(unknown convention)"));
1716 case DW_AT_ordering:
1719 case -1: printf (_("(undefined)")); break;
1720 case 0: printf ("(row major)"); break;
1721 case 1: printf ("(column major)"); break;
1725 case DW_AT_frame_base:
1726 have_frame_base = 1;
1727 case DW_AT_location:
1728 case DW_AT_string_length:
1729 case DW_AT_return_addr:
1730 case DW_AT_data_member_location:
1731 case DW_AT_vtable_elem_location:
1733 case DW_AT_static_link:
1734 case DW_AT_use_location:
1735 case DW_AT_GNU_call_site_value:
1736 case DW_AT_GNU_call_site_data_value:
1737 case DW_AT_GNU_call_site_target:
1738 case DW_AT_GNU_call_site_target_clobbered:
1739 if ((dwarf_version < 4
1740 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1741 || form == DW_FORM_sec_offset)
1742 printf (_("(location list)"));
1744 case DW_AT_allocated:
1745 case DW_AT_associated:
1746 case DW_AT_data_location:
1748 case DW_AT_upper_bound:
1749 case DW_AT_lower_bound:
1752 int need_frame_base;
1755 need_frame_base = decode_location_expression (block_start,
1760 cu_offset, section);
1762 if (need_frame_base && !have_frame_base)
1763 printf (_(" [without DW_AT_frame_base]"));
1769 if (form == DW_FORM_ref_sig8)
1772 if (form == DW_FORM_ref1
1773 || form == DW_FORM_ref2
1774 || form == DW_FORM_ref4
1775 || form == DW_FORM_ref_udata)
1776 uvalue += cu_offset;
1778 if (uvalue >= section->size)
1779 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1780 dwarf_vmatoa ("x", uvalue),
1781 (unsigned long) (orig_data - section->start));
1784 unsigned long abbrev_number;
1785 abbrev_entry * entry;
1787 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1789 printf (_("[Abbrev Number: %ld"), abbrev_number);
1790 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1791 if (entry->entry == abbrev_number)
1794 printf (" (%s)", get_TAG_name (entry->tag));
1808 get_AT_name (unsigned long attribute)
1812 case DW_AT_sibling: return "DW_AT_sibling";
1813 case DW_AT_location: return "DW_AT_location";
1814 case DW_AT_name: return "DW_AT_name";
1815 case DW_AT_ordering: return "DW_AT_ordering";
1816 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1817 case DW_AT_byte_size: return "DW_AT_byte_size";
1818 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1819 case DW_AT_bit_size: return "DW_AT_bit_size";
1820 case DW_AT_element_list: return "DW_AT_element_list";
1821 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1822 case DW_AT_low_pc: return "DW_AT_low_pc";
1823 case DW_AT_high_pc: return "DW_AT_high_pc";
1824 case DW_AT_language: return "DW_AT_language";
1825 case DW_AT_member: return "DW_AT_member";
1826 case DW_AT_discr: return "DW_AT_discr";
1827 case DW_AT_discr_value: return "DW_AT_discr_value";
1828 case DW_AT_visibility: return "DW_AT_visibility";
1829 case DW_AT_import: return "DW_AT_import";
1830 case DW_AT_string_length: return "DW_AT_string_length";
1831 case DW_AT_common_reference: return "DW_AT_common_reference";
1832 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1833 case DW_AT_const_value: return "DW_AT_const_value";
1834 case DW_AT_containing_type: return "DW_AT_containing_type";
1835 case DW_AT_default_value: return "DW_AT_default_value";
1836 case DW_AT_inline: return "DW_AT_inline";
1837 case DW_AT_is_optional: return "DW_AT_is_optional";
1838 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1839 case DW_AT_producer: return "DW_AT_producer";
1840 case DW_AT_prototyped: return "DW_AT_prototyped";
1841 case DW_AT_return_addr: return "DW_AT_return_addr";
1842 case DW_AT_start_scope: return "DW_AT_start_scope";
1843 case DW_AT_stride_size: return "DW_AT_stride_size";
1844 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1845 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1846 case DW_AT_accessibility: return "DW_AT_accessibility";
1847 case DW_AT_address_class: return "DW_AT_address_class";
1848 case DW_AT_artificial: return "DW_AT_artificial";
1849 case DW_AT_base_types: return "DW_AT_base_types";
1850 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1851 case DW_AT_count: return "DW_AT_count";
1852 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1853 case DW_AT_decl_column: return "DW_AT_decl_column";
1854 case DW_AT_decl_file: return "DW_AT_decl_file";
1855 case DW_AT_decl_line: return "DW_AT_decl_line";
1856 case DW_AT_declaration: return "DW_AT_declaration";
1857 case DW_AT_discr_list: return "DW_AT_discr_list";
1858 case DW_AT_encoding: return "DW_AT_encoding";
1859 case DW_AT_external: return "DW_AT_external";
1860 case DW_AT_frame_base: return "DW_AT_frame_base";
1861 case DW_AT_friend: return "DW_AT_friend";
1862 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1863 case DW_AT_macro_info: return "DW_AT_macro_info";
1864 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1865 case DW_AT_priority: return "DW_AT_priority";
1866 case DW_AT_segment: return "DW_AT_segment";
1867 case DW_AT_specification: return "DW_AT_specification";
1868 case DW_AT_static_link: return "DW_AT_static_link";
1869 case DW_AT_type: return "DW_AT_type";
1870 case DW_AT_use_location: return "DW_AT_use_location";
1871 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1872 case DW_AT_virtuality: return "DW_AT_virtuality";
1873 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1874 /* DWARF 2.1 values. */
1875 case DW_AT_allocated: return "DW_AT_allocated";
1876 case DW_AT_associated: return "DW_AT_associated";
1877 case DW_AT_data_location: return "DW_AT_data_location";
1878 case DW_AT_stride: return "DW_AT_stride";
1879 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1880 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1881 case DW_AT_extension: return "DW_AT_extension";
1882 case DW_AT_ranges: return "DW_AT_ranges";
1883 case DW_AT_trampoline: return "DW_AT_trampoline";
1884 case DW_AT_call_column: return "DW_AT_call_column";
1885 case DW_AT_call_file: return "DW_AT_call_file";
1886 case DW_AT_call_line: return "DW_AT_call_line";
1887 case DW_AT_description: return "DW_AT_description";
1888 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1889 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1890 case DW_AT_small: return "DW_AT_small";
1891 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1892 case DW_AT_digit_count: return "DW_AT_digit_count";
1893 case DW_AT_picture_string: return "DW_AT_picture_string";
1894 case DW_AT_mutable: return "DW_AT_mutable";
1895 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1896 case DW_AT_explicit: return "DW_AT_explicit";
1897 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1898 case DW_AT_endianity: return "DW_AT_endianity";
1899 case DW_AT_elemental: return "DW_AT_elemental";
1900 case DW_AT_pure: return "DW_AT_pure";
1901 case DW_AT_recursive: return "DW_AT_recursive";
1902 /* DWARF 4 values. */
1903 case DW_AT_signature: return "DW_AT_signature";
1904 case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
1905 case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
1906 case DW_AT_const_expr: return "DW_AT_const_expr";
1907 case DW_AT_enum_class: return "DW_AT_enum_class";
1908 case DW_AT_linkage_name: return "DW_AT_linkage_name";
1910 /* HP and SGI/MIPS extensions. */
1911 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1912 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1913 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1914 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1915 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1916 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1917 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1918 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1919 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1920 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1922 /* HP Extensions. */
1923 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
1924 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1925 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1926 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1927 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1928 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1929 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1930 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1931 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1932 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1933 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1934 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1935 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1937 /* One value is shared by the MIPS and HP extensions: */
1938 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1940 /* GNU extensions. */
1941 case DW_AT_sf_names: return "DW_AT_sf_names";
1942 case DW_AT_src_info: return "DW_AT_src_info";
1943 case DW_AT_mac_info: return "DW_AT_mac_info";
1944 case DW_AT_src_coords: return "DW_AT_src_coords";
1945 case DW_AT_body_begin: return "DW_AT_body_begin";
1946 case DW_AT_body_end: return "DW_AT_body_end";
1947 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1948 case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by";
1949 case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by";
1950 case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded";
1951 case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded";
1952 case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded";
1953 case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required";
1954 case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required";
1955 case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature";
1956 case DW_AT_use_GNAT_descriptive_type: return "DW_AT_use_GNAT_descriptive_type";
1957 case DW_AT_GNAT_descriptive_type: return "DW_AT_GNAT_descriptive_type";
1958 case DW_AT_GNU_call_site_value: return "DW_AT_GNU_call_site_value";
1959 case DW_AT_GNU_call_site_data_value: return "DW_AT_GNU_call_site_data_value";
1960 case DW_AT_GNU_call_site_target: return "DW_AT_GNU_call_site_target";
1961 case DW_AT_GNU_call_site_target_clobbered: return "DW_AT_GNU_call_site_target_clobbered";
1962 case DW_AT_GNU_tail_call: return "DW_AT_GNU_tail_call";
1963 case DW_AT_GNU_all_tail_call_sites: return "DW_AT_GNU_all_tail_call_sites";
1964 case DW_AT_GNU_all_call_sites: return "DW_AT_GNU_all_call_sites";
1965 case DW_AT_GNU_all_source_call_sites: return "DW_AT_GNU_all_source_call_sites";
1966 case DW_AT_GNU_macros: return "DW_AT_GNU_macros";
1968 /* UPC extension. */
1969 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1971 /* PGI (STMicroelectronics) extensions. */
1972 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1973 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1974 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1978 static char buffer[100];
1980 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1987 static unsigned char *
1988 read_and_display_attr (unsigned long attribute,
1990 unsigned char * data,
1991 dwarf_vma cu_offset,
1992 dwarf_vma pointer_size,
1993 dwarf_vma offset_size,
1995 debug_info * debug_info_p,
1997 struct dwarf_section * section)
2000 printf (" %-18s:", get_AT_name (attribute));
2001 data = read_and_display_attr_value (attribute, form, data, cu_offset,
2002 pointer_size, offset_size,
2003 dwarf_version, debug_info_p,
2011 /* Process the contents of a .debug_info section. If do_loc is non-zero
2012 then we are scanning for location lists and we do not want to display
2013 anything to the user. If do_types is non-zero, we are processing
2014 a .debug_types section instead of a .debug_info section. */
2017 process_debug_info (struct dwarf_section *section,
2019 enum dwarf_section_display_enum abbrev_sec,
2023 unsigned char *start = section->start;
2024 unsigned char *end = start + section->size;
2025 unsigned char *section_begin;
2027 unsigned int num_units = 0;
2029 if ((do_loc || do_debug_loc || do_debug_ranges)
2030 && num_debug_info_entries == 0
2035 /* First scan the section to get the number of comp units. */
2036 for (section_begin = start, num_units = 0; section_begin < end;
2039 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2040 will be the length. For a 64-bit DWARF section, it'll be
2041 the escape code 0xffffffff followed by an 8 byte length. */
2042 length = byte_get (section_begin, 4);
2044 if (length == 0xffffffff)
2046 length = byte_get (section_begin + 4, 8);
2047 section_begin += length + 12;
2049 else if (length >= 0xfffffff0 && length < 0xffffffff)
2051 warn (_("Reserved length value (0x%s) found in section %s\n"),
2052 dwarf_vmatoa ("x", length), section->name);
2056 section_begin += length + 4;
2058 /* Negative values are illegal, they may even cause infinite
2059 looping. This can happen if we can't accurately apply
2060 relocations to an object file. */
2061 if ((signed long) length <= 0)
2063 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2064 dwarf_vmatoa ("x", length), section->name);
2071 error (_("No comp units in %s section ?"), section->name);
2075 /* Then allocate an array to hold the information. */
2076 debug_information = (debug_info *) cmalloc (num_units,
2077 sizeof (* debug_information));
2078 if (debug_information == NULL)
2080 error (_("Not enough memory for a debug info array of %u entries"),
2088 if (dwarf_start_die == 0)
2089 printf (_("Contents of the %s section:\n\n"), section->name);
2091 load_debug_section (str, file);
2094 load_debug_section (abbrev_sec, file);
2095 if (debug_displays [abbrev_sec].section.start == NULL)
2097 warn (_("Unable to locate %s section!\n"),
2098 debug_displays [abbrev_sec].section.name);
2102 for (section_begin = start, unit = 0; start < end; unit++)
2104 DWARF2_Internal_CompUnit compunit;
2105 unsigned char *hdrptr;
2106 unsigned char *tags;
2107 int level, last_level, saved_level;
2108 dwarf_vma cu_offset;
2110 int initial_length_size;
2111 unsigned char signature[8] = { 0 };
2112 dwarf_vma type_offset = 0;
2116 compunit.cu_length = byte_get (hdrptr, 4);
2119 if (compunit.cu_length == 0xffffffff)
2121 compunit.cu_length = byte_get (hdrptr, 8);
2124 initial_length_size = 12;
2129 initial_length_size = 4;
2132 compunit.cu_version = byte_get (hdrptr, 2);
2135 cu_offset = start - section_begin;
2137 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2138 hdrptr += offset_size;
2140 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2147 for (i = 0; i < 8; i++)
2149 signature[i] = byte_get (hdrptr, 1);
2153 type_offset = byte_get (hdrptr, offset_size);
2154 hdrptr += offset_size;
2157 if ((do_loc || do_debug_loc || do_debug_ranges)
2158 && num_debug_info_entries == 0
2161 debug_information [unit].cu_offset = cu_offset;
2162 debug_information [unit].pointer_size
2163 = compunit.cu_pointer_size;
2164 debug_information [unit].offset_size = offset_size;
2165 debug_information [unit].dwarf_version = compunit.cu_version;
2166 debug_information [unit].base_address = 0;
2167 debug_information [unit].loc_offsets = NULL;
2168 debug_information [unit].have_frame_base = NULL;
2169 debug_information [unit].max_loc_offsets = 0;
2170 debug_information [unit].num_loc_offsets = 0;
2171 debug_information [unit].range_lists = NULL;
2172 debug_information [unit].max_range_lists= 0;
2173 debug_information [unit].num_range_lists = 0;
2176 if (!do_loc && dwarf_start_die == 0)
2178 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2179 dwarf_vmatoa ("x", cu_offset));
2180 printf (_(" Length: 0x%s (%s)\n"),
2181 dwarf_vmatoa ("x", compunit.cu_length),
2182 offset_size == 8 ? "64-bit" : "32-bit");
2183 printf (_(" Version: %d\n"), compunit.cu_version);
2184 printf (_(" Abbrev Offset: %s\n"),
2185 dwarf_vmatoa ("d", compunit.cu_abbrev_offset));
2186 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2190 printf (_(" Signature: "));
2191 for (i = 0; i < 8; i++)
2192 printf ("%02x", signature[i]);
2194 printf (_(" Type Offset: 0x%s\n"),
2195 dwarf_vmatoa ("x", type_offset));
2199 if (cu_offset + compunit.cu_length + initial_length_size
2202 warn (_("Debug info is corrupted, length of CU at %s"
2203 " extends beyond end of section (length = %s)\n"),
2204 dwarf_vmatoa ("x", cu_offset),
2205 dwarf_vmatoa ("x", compunit.cu_length));
2209 start += compunit.cu_length + initial_length_size;
2211 if (compunit.cu_version != 2
2212 && compunit.cu_version != 3
2213 && compunit.cu_version != 4)
2215 warn (_("CU at offset %s contains corrupt or "
2216 "unsupported version number: %d.\n"),
2217 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2223 /* Process the abbrevs used by this compilation unit. DWARF
2224 sections under Mach-O have non-zero addresses. */
2225 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2226 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2227 (unsigned long) compunit.cu_abbrev_offset,
2228 (unsigned long) debug_displays [abbrev_sec].section.size);
2230 process_abbrev_section
2231 ((unsigned char *) debug_displays [abbrev_sec].section.start
2232 + compunit.cu_abbrev_offset,
2233 (unsigned char *) debug_displays [abbrev_sec].section.start
2234 + debug_displays [abbrev_sec].section.size);
2239 while (tags < start)
2241 unsigned int bytes_read;
2242 unsigned long abbrev_number;
2243 unsigned long die_offset;
2244 abbrev_entry *entry;
2246 int do_printing = 1;
2248 die_offset = tags - section_begin;
2250 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2253 /* A null DIE marks the end of a list of siblings or it may also be
2254 a section padding. */
2255 if (abbrev_number == 0)
2257 /* Check if it can be a section padding for the last CU. */
2258 if (level == 0 && start == end)
2262 for (chk = tags; chk < start; chk++)
2272 static unsigned num_bogus_warns = 0;
2274 if (num_bogus_warns < 3)
2276 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2279 if (num_bogus_warns == 3)
2280 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2283 if (dwarf_start_die != 0 && level < saved_level)
2290 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2294 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2295 saved_level = level;
2296 do_printing = (dwarf_cutoff_level == -1
2297 || level < dwarf_cutoff_level);
2299 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2300 level, die_offset, abbrev_number);
2301 else if (dwarf_cutoff_level == -1
2302 || last_level < dwarf_cutoff_level)
2303 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2308 /* Scan through the abbreviation list until we reach the
2310 for (entry = first_abbrev;
2311 entry && entry->entry != abbrev_number;
2312 entry = entry->next)
2317 if (!do_loc && do_printing)
2322 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2323 die_offset, abbrev_number);
2327 if (!do_loc && do_printing)
2328 printf (" (%s)\n", get_TAG_name (entry->tag));
2333 need_base_address = 0;
2335 case DW_TAG_compile_unit:
2336 need_base_address = 1;
2338 case DW_TAG_entry_point:
2339 case DW_TAG_subprogram:
2340 need_base_address = 0;
2341 /* Assuming that there is no DW_AT_frame_base. */
2342 have_frame_base = 0;
2346 for (attr = entry->first_attr; attr; attr = attr->next)
2350 if (! do_loc && do_printing)
2351 /* Show the offset from where the tag was extracted. */
2352 printf (" <%lx>", (unsigned long)(tags - section_begin));
2354 arg = debug_information;
2355 if (debug_information)
2358 tags = read_and_display_attr (attr->attribute,
2361 compunit.cu_pointer_size,
2363 compunit.cu_version,
2365 do_loc || ! do_printing, section);
2368 if (entry->children)
2373 /* Set num_debug_info_entries here so that it can be used to check if
2374 we need to process .debug_loc and .debug_ranges sections. */
2375 if ((do_loc || do_debug_loc || do_debug_ranges)
2376 && num_debug_info_entries == 0
2378 num_debug_info_entries = num_units;
2386 /* Locate and scan the .debug_info section in the file and record the pointer
2387 sizes and offsets for the compilation units in it. Usually an executable
2388 will have just one pointer size, but this is not guaranteed, and so we try
2389 not to make any assumptions. Returns zero upon failure, or the number of
2390 compilation units upon success. */
2393 load_debug_info (void * file)
2395 /* Reset the last pointer size so that we can issue correct error
2396 messages if we are displaying the contents of more than one section. */
2397 last_pointer_size = 0;
2398 warned_about_missing_comp_units = FALSE;
2400 /* If we have already tried and failed to load the .debug_info
2401 section then do not bother to repear the task. */
2402 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2405 /* If we already have the information there is nothing else to do. */
2406 if (num_debug_info_entries > 0)
2407 return num_debug_info_entries;
2409 if (load_debug_section (info, file)
2410 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2411 return num_debug_info_entries;
2413 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2418 display_debug_lines_raw (struct dwarf_section *section,
2419 unsigned char *data,
2422 unsigned char *start = section->start;
2424 printf (_("Raw dump of debug contents of section %s:\n\n"),
2429 DWARF2_Internal_LineInfo linfo;
2430 unsigned char *standard_opcodes;
2431 unsigned char *end_of_sequence;
2432 unsigned char *hdrptr;
2433 unsigned long hdroff;
2434 int initial_length_size;
2439 hdroff = hdrptr - start;
2441 /* Check the length of the block. */
2442 linfo.li_length = byte_get (hdrptr, 4);
2445 if (linfo.li_length == 0xffffffff)
2447 /* This section is 64-bit DWARF 3. */
2448 linfo.li_length = byte_get (hdrptr, 8);
2451 initial_length_size = 12;
2456 initial_length_size = 4;
2459 if (linfo.li_length + initial_length_size > section->size)
2462 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2467 /* Check its version number. */
2468 linfo.li_version = byte_get (hdrptr, 2);
2470 if (linfo.li_version != 2
2471 && linfo.li_version != 3
2472 && linfo.li_version != 4)
2474 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2478 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2479 hdrptr += offset_size;
2480 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2482 if (linfo.li_version >= 4)
2484 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2486 if (linfo.li_max_ops_per_insn == 0)
2488 warn (_("Invalid maximum operations per insn.\n"));
2493 linfo.li_max_ops_per_insn = 1;
2494 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2496 linfo.li_line_base = byte_get (hdrptr, 1);
2498 linfo.li_line_range = byte_get (hdrptr, 1);
2500 linfo.li_opcode_base = byte_get (hdrptr, 1);
2503 /* Sign extend the line base field. */
2504 linfo.li_line_base <<= 24;
2505 linfo.li_line_base >>= 24;
2507 printf (_(" Offset: 0x%lx\n"), hdroff);
2508 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2509 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2510 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2511 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2512 if (linfo.li_version >= 4)
2513 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2514 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2515 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2516 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2517 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2519 end_of_sequence = data + linfo.li_length + initial_length_size;
2521 reset_state_machine (linfo.li_default_is_stmt);
2523 /* Display the contents of the Opcodes table. */
2524 standard_opcodes = hdrptr;
2526 printf (_("\n Opcodes:\n"));
2528 for (i = 1; i < linfo.li_opcode_base; i++)
2529 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2531 /* Display the contents of the Directory table. */
2532 data = standard_opcodes + linfo.li_opcode_base - 1;
2535 printf (_("\n The Directory Table is empty.\n"));
2538 printf (_("\n The Directory Table:\n"));
2542 printf (" %s\n", data);
2544 data += strlen ((char *) data) + 1;
2548 /* Skip the NUL at the end of the table. */
2551 /* Display the contents of the File Name table. */
2553 printf (_("\n The File Name Table is empty.\n"));
2556 printf (_("\n The File Name Table:\n"));
2557 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2561 unsigned char *name;
2562 unsigned int bytes_read;
2564 printf (" %d\t", ++state_machine_regs.last_file_entry);
2567 data += strlen ((char *) data) + 1;
2570 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2573 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2576 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2578 printf ("%s\n", name);
2582 /* Skip the NUL at the end of the table. */
2585 /* Now display the statements. */
2586 printf (_("\n Line Number Statements:\n"));
2588 while (data < end_of_sequence)
2590 unsigned char op_code;
2591 dwarf_signed_vma adv;
2593 unsigned int bytes_read;
2597 if (op_code >= linfo.li_opcode_base)
2599 op_code -= linfo.li_opcode_base;
2600 uladv = (op_code / linfo.li_line_range);
2601 if (linfo.li_max_ops_per_insn == 1)
2603 uladv *= linfo.li_min_insn_length;
2604 state_machine_regs.address += uladv;
2605 printf (_(" Special opcode %d: "
2606 "advance Address by %s to 0x%s"),
2607 op_code, dwarf_vmatoa ("u", uladv),
2608 dwarf_vmatoa ("x", state_machine_regs.address));
2612 state_machine_regs.address
2613 += ((state_machine_regs.op_index + uladv)
2614 / linfo.li_max_ops_per_insn)
2615 * linfo.li_min_insn_length;
2616 state_machine_regs.op_index
2617 = (state_machine_regs.op_index + uladv)
2618 % linfo.li_max_ops_per_insn;
2619 printf (_(" Special opcode %d: "
2620 "advance Address by %s to 0x%s[%d]"),
2621 op_code, dwarf_vmatoa ("u", uladv),
2622 dwarf_vmatoa ("x", state_machine_regs.address),
2623 state_machine_regs.op_index);
2625 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2626 state_machine_regs.line += adv;
2627 printf (_(" and Line by %s to %d\n"),
2628 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2630 else switch (op_code)
2632 case DW_LNS_extended_op:
2633 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2637 printf (_(" Copy\n"));
2640 case DW_LNS_advance_pc:
2641 uladv = read_leb128 (data, & bytes_read, 0);
2643 if (linfo.li_max_ops_per_insn == 1)
2645 uladv *= linfo.li_min_insn_length;
2646 state_machine_regs.address += uladv;
2647 printf (_(" Advance PC by %s to 0x%s\n"),
2648 dwarf_vmatoa ("u", uladv),
2649 dwarf_vmatoa ("x", state_machine_regs.address));
2653 state_machine_regs.address
2654 += ((state_machine_regs.op_index + uladv)
2655 / linfo.li_max_ops_per_insn)
2656 * linfo.li_min_insn_length;
2657 state_machine_regs.op_index
2658 = (state_machine_regs.op_index + uladv)
2659 % linfo.li_max_ops_per_insn;
2660 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2661 dwarf_vmatoa ("u", uladv),
2662 dwarf_vmatoa ("x", state_machine_regs.address),
2663 state_machine_regs.op_index);
2667 case DW_LNS_advance_line:
2668 adv = read_sleb128 (data, & bytes_read);
2670 state_machine_regs.line += adv;
2671 printf (_(" Advance Line by %s to %d\n"),
2672 dwarf_vmatoa ("d", adv),
2673 state_machine_regs.line);
2676 case DW_LNS_set_file:
2677 adv = read_leb128 (data, & bytes_read, 0);
2679 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2680 dwarf_vmatoa ("d", adv));
2681 state_machine_regs.file = adv;
2684 case DW_LNS_set_column:
2685 uladv = read_leb128 (data, & bytes_read, 0);
2687 printf (_(" Set column to %s\n"),
2688 dwarf_vmatoa ("u", uladv));
2689 state_machine_regs.column = uladv;
2692 case DW_LNS_negate_stmt:
2693 adv = state_machine_regs.is_stmt;
2695 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2696 state_machine_regs.is_stmt = adv;
2699 case DW_LNS_set_basic_block:
2700 printf (_(" Set basic block\n"));
2701 state_machine_regs.basic_block = 1;
2704 case DW_LNS_const_add_pc:
2705 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2706 if (linfo.li_max_ops_per_insn)
2708 uladv *= linfo.li_min_insn_length;
2709 state_machine_regs.address += uladv;
2710 printf (_(" Advance PC by constant %s to 0x%s\n"),
2711 dwarf_vmatoa ("u", uladv),
2712 dwarf_vmatoa ("x", state_machine_regs.address));
2716 state_machine_regs.address
2717 += ((state_machine_regs.op_index + uladv)
2718 / linfo.li_max_ops_per_insn)
2719 * linfo.li_min_insn_length;
2720 state_machine_regs.op_index
2721 = (state_machine_regs.op_index + uladv)
2722 % linfo.li_max_ops_per_insn;
2723 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2724 dwarf_vmatoa ("u", uladv),
2725 dwarf_vmatoa ("x", state_machine_regs.address),
2726 state_machine_regs.op_index);
2730 case DW_LNS_fixed_advance_pc:
2731 uladv = byte_get (data, 2);
2733 state_machine_regs.address += uladv;
2734 state_machine_regs.op_index = 0;
2735 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2736 dwarf_vmatoa ("u", uladv),
2737 dwarf_vmatoa ("x", state_machine_regs.address));
2740 case DW_LNS_set_prologue_end:
2741 printf (_(" Set prologue_end to true\n"));
2744 case DW_LNS_set_epilogue_begin:
2745 printf (_(" Set epilogue_begin to true\n"));
2748 case DW_LNS_set_isa:
2749 uladv = read_leb128 (data, & bytes_read, 0);
2751 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2755 printf (_(" Unknown opcode %d with operands: "), op_code);
2757 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2759 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2761 i == 1 ? "" : ", ");
2776 unsigned char *name;
2777 unsigned int directory_index;
2778 unsigned int modification_date;
2779 unsigned int length;
2782 /* Output a decoded representation of the .debug_line section. */
2785 display_debug_lines_decoded (struct dwarf_section *section,
2786 unsigned char *data,
2789 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2794 /* This loop amounts to one iteration per compilation unit. */
2795 DWARF2_Internal_LineInfo linfo;
2796 unsigned char *standard_opcodes;
2797 unsigned char *end_of_sequence;
2798 unsigned char *hdrptr;
2799 int initial_length_size;
2802 File_Entry *file_table = NULL;
2803 unsigned char **directory_table = NULL;
2807 /* Extract information from the Line Number Program Header.
2808 (section 6.2.4 in the Dwarf3 doc). */
2810 /* Get the length of this CU's line number information block. */
2811 linfo.li_length = byte_get (hdrptr, 4);
2814 if (linfo.li_length == 0xffffffff)
2816 /* This section is 64-bit DWARF 3. */
2817 linfo.li_length = byte_get (hdrptr, 8);
2820 initial_length_size = 12;
2825 initial_length_size = 4;
2828 if (linfo.li_length + initial_length_size > section->size)
2830 warn (_("The line info appears to be corrupt - "
2831 "the section is too small\n"));
2835 /* Get this CU's Line Number Block version number. */
2836 linfo.li_version = byte_get (hdrptr, 2);
2838 if (linfo.li_version != 2
2839 && linfo.li_version != 3
2840 && linfo.li_version != 4)
2842 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2847 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2848 hdrptr += offset_size;
2849 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2851 if (linfo.li_version >= 4)
2853 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2855 if (linfo.li_max_ops_per_insn == 0)
2857 warn (_("Invalid maximum operations per insn.\n"));
2862 linfo.li_max_ops_per_insn = 1;
2863 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2865 linfo.li_line_base = byte_get (hdrptr, 1);
2867 linfo.li_line_range = byte_get (hdrptr, 1);
2869 linfo.li_opcode_base = byte_get (hdrptr, 1);
2872 /* Sign extend the line base field. */
2873 linfo.li_line_base <<= 24;
2874 linfo.li_line_base >>= 24;
2876 /* Find the end of this CU's Line Number Information Block. */
2877 end_of_sequence = data + linfo.li_length + initial_length_size;
2879 reset_state_machine (linfo.li_default_is_stmt);
2881 /* Save a pointer to the contents of the Opcodes table. */
2882 standard_opcodes = hdrptr;
2884 /* Traverse the Directory table just to count entries. */
2885 data = standard_opcodes + linfo.li_opcode_base - 1;
2888 unsigned int n_directories = 0;
2889 unsigned char *ptr_directory_table = data;
2893 data += strlen ((char *) data) + 1;
2897 /* Go through the directory table again to save the directories. */
2898 directory_table = (unsigned char **)
2899 xmalloc (n_directories * sizeof (unsigned char *));
2902 while (*ptr_directory_table != 0)
2904 directory_table[i] = ptr_directory_table;
2905 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2909 /* Skip the NUL at the end of the table. */
2912 /* Traverse the File Name table just to count the entries. */
2915 unsigned int n_files = 0;
2916 unsigned char *ptr_file_name_table = data;
2920 unsigned int bytes_read;
2922 /* Skip Name, directory index, last modification time and length
2924 data += strlen ((char *) data) + 1;
2925 read_leb128 (data, & bytes_read, 0);
2927 read_leb128 (data, & bytes_read, 0);
2929 read_leb128 (data, & bytes_read, 0);
2935 /* Go through the file table again to save the strings. */
2936 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2939 while (*ptr_file_name_table != 0)
2941 unsigned int bytes_read;
2943 file_table[i].name = ptr_file_name_table;
2944 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2946 /* We are not interested in directory, time or size. */
2947 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2949 ptr_file_name_table += bytes_read;
2950 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2952 ptr_file_name_table += bytes_read;
2953 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2954 ptr_file_name_table += bytes_read;
2959 /* Print the Compilation Unit's name and a header. */
2960 if (directory_table == NULL)
2962 printf (_("CU: %s:\n"), file_table[0].name);
2963 printf (_("File name Line number Starting address\n"));
2967 unsigned int ix = file_table[0].directory_index;
2968 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
2969 if (do_wide || strlen (directory) < 76)
2970 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
2972 printf ("%s:\n", file_table[0].name);
2974 printf (_("File name Line number Starting address\n"));
2978 /* Skip the NUL at the end of the table. */
2981 /* This loop iterates through the Dwarf Line Number Program. */
2982 while (data < end_of_sequence)
2984 unsigned char op_code;
2986 unsigned long int uladv;
2987 unsigned int bytes_read;
2988 int is_special_opcode = 0;
2992 if (op_code >= linfo.li_opcode_base)
2994 op_code -= linfo.li_opcode_base;
2995 uladv = (op_code / linfo.li_line_range);
2996 if (linfo.li_max_ops_per_insn == 1)
2998 uladv *= linfo.li_min_insn_length;
2999 state_machine_regs.address += uladv;
3003 state_machine_regs.address
3004 += ((state_machine_regs.op_index + uladv)
3005 / linfo.li_max_ops_per_insn)
3006 * linfo.li_min_insn_length;
3007 state_machine_regs.op_index
3008 = (state_machine_regs.op_index + uladv)
3009 % linfo.li_max_ops_per_insn;
3012 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3013 state_machine_regs.line += adv;
3014 is_special_opcode = 1;
3016 else switch (op_code)
3018 case DW_LNS_extended_op:
3020 unsigned int ext_op_code_len;
3021 unsigned char ext_op_code;
3022 unsigned char *op_code_data = data;
3024 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
3025 op_code_data += bytes_read;
3027 if (ext_op_code_len == 0)
3029 warn (_("badly formed extended line op encountered!\n"));
3032 ext_op_code_len += bytes_read;
3033 ext_op_code = *op_code_data++;
3035 switch (ext_op_code)
3037 case DW_LNE_end_sequence:
3038 reset_state_machine (linfo.li_default_is_stmt);
3040 case DW_LNE_set_address:
3041 state_machine_regs.address =
3042 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
3043 state_machine_regs.op_index = 0;
3045 case DW_LNE_define_file:
3047 unsigned int dir_index = 0;
3049 ++state_machine_regs.last_file_entry;
3050 op_code_data += strlen ((char *) op_code_data) + 1;
3051 dir_index = read_leb128 (op_code_data, & bytes_read, 0);
3052 op_code_data += bytes_read;
3053 read_leb128 (op_code_data, & bytes_read, 0);
3054 op_code_data += bytes_read;
3055 read_leb128 (op_code_data, & bytes_read, 0);
3057 printf ("%s:\n", directory_table[dir_index]);
3061 printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
3064 data += ext_op_code_len;
3070 case DW_LNS_advance_pc:
3071 uladv = read_leb128 (data, & bytes_read, 0);
3073 if (linfo.li_max_ops_per_insn == 1)
3075 uladv *= linfo.li_min_insn_length;
3076 state_machine_regs.address += uladv;
3080 state_machine_regs.address
3081 += ((state_machine_regs.op_index + uladv)
3082 / linfo.li_max_ops_per_insn)
3083 * linfo.li_min_insn_length;
3084 state_machine_regs.op_index
3085 = (state_machine_regs.op_index + uladv)
3086 % linfo.li_max_ops_per_insn;
3090 case DW_LNS_advance_line:
3091 adv = read_sleb128 (data, & bytes_read);
3093 state_machine_regs.line += adv;
3096 case DW_LNS_set_file:
3097 adv = read_leb128 (data, & bytes_read, 0);
3099 state_machine_regs.file = adv;
3100 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3102 /* If directory index is 0, that means current directory. */
3103 printf ("\n./%s:[++]\n",
3104 file_table[state_machine_regs.file - 1].name);
3108 /* The directory index starts counting at 1. */
3109 printf ("\n%s/%s:\n",
3110 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3111 file_table[state_machine_regs.file - 1].name);
3115 case DW_LNS_set_column:
3116 uladv = read_leb128 (data, & bytes_read, 0);
3118 state_machine_regs.column = uladv;
3121 case DW_LNS_negate_stmt:
3122 adv = state_machine_regs.is_stmt;
3124 state_machine_regs.is_stmt = adv;
3127 case DW_LNS_set_basic_block:
3128 state_machine_regs.basic_block = 1;
3131 case DW_LNS_const_add_pc:
3132 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3133 if (linfo.li_max_ops_per_insn == 1)
3135 uladv *= linfo.li_min_insn_length;
3136 state_machine_regs.address += uladv;
3140 state_machine_regs.address
3141 += ((state_machine_regs.op_index + uladv)
3142 / linfo.li_max_ops_per_insn)
3143 * linfo.li_min_insn_length;
3144 state_machine_regs.op_index
3145 = (state_machine_regs.op_index + uladv)
3146 % linfo.li_max_ops_per_insn;
3150 case DW_LNS_fixed_advance_pc:
3151 uladv = byte_get (data, 2);
3153 state_machine_regs.address += uladv;
3154 state_machine_regs.op_index = 0;
3157 case DW_LNS_set_prologue_end:
3160 case DW_LNS_set_epilogue_begin:
3163 case DW_LNS_set_isa:
3164 uladv = read_leb128 (data, & bytes_read, 0);
3166 printf (_(" Set ISA to %lu\n"), uladv);
3170 printf (_(" Unknown opcode %d with operands: "), op_code);
3172 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3174 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3176 i == 1 ? "" : ", ");
3183 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3184 to the DWARF address/line matrix. */
3185 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3186 || (op_code == DW_LNS_copy))
3188 const unsigned int MAX_FILENAME_LENGTH = 35;
3189 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3190 char *newFileName = NULL;
3191 size_t fileNameLength = strlen (fileName);
3193 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3195 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3196 /* Truncate file name */
3197 strncpy (newFileName,
3198 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3199 MAX_FILENAME_LENGTH + 1);
3203 newFileName = (char *) xmalloc (fileNameLength + 1);
3204 strncpy (newFileName, fileName, fileNameLength + 1);
3207 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3209 if (linfo.li_max_ops_per_insn == 1)
3210 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3211 newFileName, state_machine_regs.line,
3212 state_machine_regs.address);
3214 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3215 newFileName, state_machine_regs.line,
3216 state_machine_regs.address,
3217 state_machine_regs.op_index);
3221 if (linfo.li_max_ops_per_insn == 1)
3222 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3223 newFileName, state_machine_regs.line,
3224 state_machine_regs.address);
3226 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3227 newFileName, state_machine_regs.line,
3228 state_machine_regs.address,
3229 state_machine_regs.op_index);
3232 if (op_code == DW_LNE_end_sequence)
3240 free (directory_table);
3241 directory_table = NULL;
3249 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3251 unsigned char *data = section->start;
3252 unsigned char *end = data + section->size;
3254 int retValDecoded = 1;
3256 if (do_debug_lines == 0)
3257 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3259 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3260 retValRaw = display_debug_lines_raw (section, data, end);
3262 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3263 retValDecoded = display_debug_lines_decoded (section, data, end);
3265 if (!retValRaw || !retValDecoded)
3272 find_debug_info_for_offset (unsigned long offset)
3276 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3279 for (i = 0; i < num_debug_info_entries; i++)
3280 if (debug_information[i].cu_offset == offset)
3281 return debug_information + i;
3287 display_debug_pubnames (struct dwarf_section *section,
3288 void *file ATTRIBUTE_UNUSED)
3290 DWARF2_Internal_PubNames names;
3291 unsigned char *start = section->start;
3292 unsigned char *end = start + section->size;
3294 /* It does not matter if this load fails,
3295 we test for that later on. */
3296 load_debug_info (file);
3298 printf (_("Contents of the %s section:\n\n"), section->name);
3302 unsigned char *data;
3303 unsigned long offset;
3304 int offset_size, initial_length_size;
3308 names.pn_length = byte_get (data, 4);
3310 if (names.pn_length == 0xffffffff)
3312 names.pn_length = byte_get (data, 8);
3315 initial_length_size = 12;
3320 initial_length_size = 4;
3323 names.pn_version = byte_get (data, 2);
3326 names.pn_offset = byte_get (data, offset_size);
3327 data += offset_size;
3329 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3330 && num_debug_info_entries > 0
3331 && find_debug_info_for_offset (names.pn_offset) == NULL)
3332 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3333 (unsigned long) names.pn_offset, section->name);
3335 names.pn_size = byte_get (data, offset_size);
3336 data += offset_size;
3338 start += names.pn_length + initial_length_size;
3340 if (names.pn_version != 2 && names.pn_version != 3)
3342 static int warned = 0;
3346 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3353 printf (_(" Length: %ld\n"),
3354 (long) names.pn_length);
3355 printf (_(" Version: %d\n"),
3357 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3358 (unsigned long) names.pn_offset);
3359 printf (_(" Size of area in .debug_info section: %ld\n"),
3360 (long) names.pn_size);
3362 printf (_("\n Offset\tName\n"));
3366 offset = byte_get (data, offset_size);
3370 data += offset_size;
3371 printf (" %-6lx\t%s\n", offset, data);
3372 data += strlen ((char *) data) + 1;
3375 while (offset != 0);
3383 display_debug_macinfo (struct dwarf_section *section,
3384 void *file ATTRIBUTE_UNUSED)
3386 unsigned char *start = section->start;
3387 unsigned char *end = start + section->size;
3388 unsigned char *curr = start;
3389 unsigned int bytes_read;
3390 enum dwarf_macinfo_record_type op;
3392 printf (_("Contents of the %s section:\n\n"), section->name);
3396 unsigned int lineno;
3399 op = (enum dwarf_macinfo_record_type) *curr;
3404 case DW_MACINFO_start_file:
3406 unsigned int filenum;
3408 lineno = read_leb128 (curr, & bytes_read, 0);
3410 filenum = read_leb128 (curr, & bytes_read, 0);
3413 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3418 case DW_MACINFO_end_file:
3419 printf (_(" DW_MACINFO_end_file\n"));
3422 case DW_MACINFO_define:
3423 lineno = read_leb128 (curr, & bytes_read, 0);
3425 string = (char *) curr;
3426 curr += strlen (string) + 1;
3427 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3431 case DW_MACINFO_undef:
3432 lineno = read_leb128 (curr, & bytes_read, 0);
3434 string = (char *) curr;
3435 curr += strlen (string) + 1;
3436 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3440 case DW_MACINFO_vendor_ext:
3442 unsigned int constant;
3444 constant = read_leb128 (curr, & bytes_read, 0);
3446 string = (char *) curr;
3447 curr += strlen (string) + 1;
3448 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3458 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3459 filename and dirname corresponding to file name table entry with index
3460 FILEIDX. Return NULL on failure. */
3462 static unsigned char *
3463 get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
3464 unsigned char **dir_name)
3466 struct dwarf_section *section = &debug_displays [line].section;
3467 unsigned char *hdrptr, *dirtable, *file_name;
3468 unsigned int offset_size, initial_length_size;
3469 unsigned int version, opcode_base, bytes_read;
3470 dwarf_vma length, diridx;
3473 if (section->start == NULL
3474 || line_offset >= section->size
3478 hdrptr = section->start + line_offset;
3479 length = byte_get (hdrptr, 4);
3481 if (length == 0xffffffff)
3483 /* This section is 64-bit DWARF 3. */
3484 length = byte_get (hdrptr, 8);
3487 initial_length_size = 12;
3492 initial_length_size = 4;
3494 if (length + initial_length_size > section->size)
3496 version = byte_get (hdrptr, 2);
3498 if (version != 2 && version != 3 && version != 4)
3500 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3502 hdrptr++; /* Skip max_ops_per_insn. */
3503 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3504 opcode_base = byte_get (hdrptr, 1);
3505 if (opcode_base == 0)
3508 hdrptr += opcode_base - 1;
3510 /* Skip over dirname table. */
3511 while (*hdrptr != '\0')
3512 hdrptr += strlen ((char *) hdrptr) + 1;
3513 hdrptr++; /* Skip the NUL at the end of the table. */
3514 /* Now skip over preceding filename table entries. */
3515 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3517 hdrptr += strlen ((char *) hdrptr) + 1;
3518 read_leb128 (hdrptr, &bytes_read, 0);
3519 hdrptr += bytes_read;
3520 read_leb128 (hdrptr, &bytes_read, 0);
3521 hdrptr += bytes_read;
3522 read_leb128 (hdrptr, &bytes_read, 0);
3523 hdrptr += bytes_read;
3525 if (*hdrptr == '\0')
3528 hdrptr += strlen ((char *) hdrptr) + 1;
3529 diridx = read_leb128 (hdrptr, &bytes_read, 0);
3532 for (; *dirtable != '\0' && diridx > 1; diridx--)
3533 dirtable += strlen ((char *) dirtable) + 1;
3534 if (*dirtable == '\0')
3536 *dir_name = dirtable;
3541 display_debug_macro (struct dwarf_section *section,
3544 unsigned char *start = section->start;
3545 unsigned char *end = start + section->size;
3546 unsigned char *curr = start;
3547 unsigned char *extended_op_buf[256];
3548 unsigned int bytes_read;
3550 load_debug_section (str, file);
3551 load_debug_section (line, file);
3553 printf (_("Contents of the %s section:\n\n"), section->name);
3557 unsigned int lineno, version, flags;
3558 unsigned int offset_size = 4;
3560 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3561 unsigned char **extended_ops = NULL;
3563 version = byte_get (curr, 2);
3568 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3573 flags = byte_get (curr++, 1);
3576 printf (_(" Offset: 0x%lx\n"),
3577 (unsigned long) sec_offset);
3578 printf (_(" Version: %d\n"), version);
3579 printf (_(" Offset size: %d\n"), offset_size);
3582 line_offset = byte_get (curr, offset_size);
3583 curr += offset_size;
3584 printf (_(" Offset into .debug_line: 0x%lx\n"),
3585 (unsigned long) line_offset);
3589 unsigned int i, count = byte_get (curr++, 1), op;
3591 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3592 extended_ops = extended_op_buf;
3595 printf (_(" Extension opcode arguments:\n"));
3596 for (i = 0; i < count; i++)
3598 op = byte_get (curr++, 1);
3599 extended_ops[op] = curr;
3600 nargs = read_leb128 (curr, &bytes_read, 0);
3603 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3606 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3607 for (n = 0; n < nargs; n++)
3609 unsigned int form = byte_get (curr++, 1);
3610 printf ("%s%s", get_FORM_name (form),
3611 n == nargs - 1 ? "\n" : ", ");
3621 case DW_FORM_block1:
3622 case DW_FORM_block2:
3623 case DW_FORM_block4:
3625 case DW_FORM_string:
3627 case DW_FORM_sec_offset:
3630 error (_("Invalid extension opcode form %s\n"),
3631 get_FORM_name (form));
3647 error (_(".debug_macro section not zero terminated\n"));
3651 op = byte_get (curr++, 1);
3657 case DW_MACRO_GNU_start_file:
3659 unsigned int filenum;
3660 unsigned char *file_name = NULL, *dir_name = NULL;
3662 lineno = read_leb128 (curr, &bytes_read, 0);
3664 filenum = read_leb128 (curr, &bytes_read, 0);
3667 if ((flags & 2) == 0)
3668 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3671 = get_line_filename_and_dirname (line_offset, filenum,
3673 if (file_name == NULL)
3674 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3677 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3679 dir_name != NULL ? (const char *) dir_name : "",
3680 dir_name != NULL ? "/" : "", file_name);
3684 case DW_MACRO_GNU_end_file:
3685 printf (_(" DW_MACRO_GNU_end_file\n"));
3688 case DW_MACRO_GNU_define:
3689 lineno = read_leb128 (curr, &bytes_read, 0);
3691 string = (char *) curr;
3692 curr += strlen (string) + 1;
3693 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3697 case DW_MACRO_GNU_undef:
3698 lineno = read_leb128 (curr, &bytes_read, 0);
3700 string = (char *) curr;
3701 curr += strlen (string) + 1;
3702 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3706 case DW_MACRO_GNU_define_indirect:
3707 lineno = read_leb128 (curr, &bytes_read, 0);
3709 offset = byte_get (curr, offset_size);
3710 curr += offset_size;
3711 string = fetch_indirect_string (offset);
3712 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3716 case DW_MACRO_GNU_undef_indirect:
3717 lineno = read_leb128 (curr, &bytes_read, 0);
3719 offset = byte_get (curr, offset_size);
3720 curr += offset_size;
3721 string = fetch_indirect_string (offset);
3722 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3726 case DW_MACRO_GNU_transparent_include:
3727 offset = byte_get (curr, offset_size);
3728 curr += offset_size;
3729 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3730 (unsigned long) offset);
3734 if (extended_ops == NULL || extended_ops[op] == NULL)
3736 error (_(" Unknown macro opcode %02x seen\n"), op);
3741 /* Skip over unhandled opcodes. */
3743 unsigned char *desc = extended_ops[op];
3744 nargs = read_leb128 (desc, &bytes_read, 0);
3748 printf (_(" DW_MACRO_GNU_%02x\n"), op);
3751 printf (_(" DW_MACRO_GNU_%02x -"), op);
3752 for (n = 0; n < nargs; n++)
3755 = read_and_display_attr_value (0, byte_get (desc++, 1),
3756 curr, 0, 0, offset_size,
3757 version, NULL, 0, NULL);
3774 display_debug_abbrev (struct dwarf_section *section,
3775 void *file ATTRIBUTE_UNUSED)
3777 abbrev_entry *entry;
3778 unsigned char *start = section->start;
3779 unsigned char *end = start + section->size;
3781 printf (_("Contents of the %s section:\n\n"), section->name);
3787 start = process_abbrev_section (start, end);
3789 if (first_abbrev == NULL)
3792 printf (_(" Number TAG\n"));
3794 for (entry = first_abbrev; entry; entry = entry->next)
3798 printf (" %ld %s [%s]\n",
3800 get_TAG_name (entry->tag),
3801 entry->children ? _("has children") : _("no children"));
3803 for (attr = entry->first_attr; attr; attr = attr->next)
3804 printf (" %-18s %s\n",
3805 get_AT_name (attr->attribute),
3806 get_FORM_name (attr->form));
3816 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3818 static dwarf_vma *loc_offsets;
3821 loc_offsets_compar (const void *ap, const void *bp)
3823 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
3824 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
3826 return (a > b) - (b > a);
3830 display_debug_loc (struct dwarf_section *section, void *file)
3832 unsigned char *start = section->start;
3833 unsigned char *section_end;
3834 unsigned long bytes;
3835 unsigned char *section_begin = start;
3836 unsigned int num_loc_list = 0;
3837 unsigned long last_offset = 0;
3838 unsigned int first = 0;
3842 int seen_first_offset = 0;
3843 int locs_sorted = 1;
3844 unsigned char *next;
3845 unsigned int *array = NULL;
3847 bytes = section->size;
3848 section_end = start + bytes;
3852 printf (_("\nThe %s section is empty.\n"), section->name);
3856 if (load_debug_info (file) == 0)
3858 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3863 /* Check the order of location list in .debug_info section. If
3864 offsets of location lists are in the ascending order, we can
3865 use `debug_information' directly. */
3866 for (i = 0; i < num_debug_info_entries; i++)
3870 num = debug_information [i].num_loc_offsets;
3871 if (num > num_loc_list)
3874 /* Check if we can use `debug_information' directly. */
3875 if (locs_sorted && num != 0)
3877 if (!seen_first_offset)
3879 /* This is the first location list. */
3880 last_offset = debug_information [i].loc_offsets [0];
3882 seen_first_offset = 1;
3888 for (; j < num; j++)
3891 debug_information [i].loc_offsets [j])
3896 last_offset = debug_information [i].loc_offsets [j];
3901 if (!seen_first_offset)
3902 error (_("No location lists in .debug_info section!\n"));
3904 /* DWARF sections under Mach-O have non-zero addresses. */
3905 if (debug_information [first].num_loc_offsets > 0
3906 && debug_information [first].loc_offsets [0] != section->address)
3907 warn (_("Location lists in %s section start at 0x%s\n"),
3909 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
3912 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
3913 printf (_("Contents of the %s section:\n\n"), section->name);
3914 printf (_(" Offset Begin End Expression\n"));
3916 seen_first_offset = 0;
3917 for (i = first; i < num_debug_info_entries; i++)
3921 unsigned short length;
3922 unsigned long offset;
3923 unsigned int pointer_size;
3924 unsigned int offset_size;
3926 unsigned long cu_offset;
3927 unsigned long base_address;
3928 int need_frame_base;
3931 pointer_size = debug_information [i].pointer_size;
3932 cu_offset = debug_information [i].cu_offset;
3933 offset_size = debug_information [i].offset_size;
3934 dwarf_version = debug_information [i].dwarf_version;
3937 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
3939 loc_offsets = debug_information [i].loc_offsets;
3940 qsort (array, debug_information [i].num_loc_offsets,
3941 sizeof (*array), loc_offsets_compar);
3944 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
3946 j = locs_sorted ? k : array[k];
3948 && debug_information [i].loc_offsets [locs_sorted
3949 ? k - 1 : array [k - 1]]
3950 == debug_information [i].loc_offsets [j])
3952 has_frame_base = debug_information [i].have_frame_base [j];
3953 /* DWARF sections under Mach-O have non-zero addresses. */
3954 offset = debug_information [i].loc_offsets [j] - section->address;
3955 next = section_begin + offset;
3956 base_address = debug_information [i].base_address;
3958 if (!seen_first_offset)
3959 seen_first_offset = 1;
3963 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3964 (unsigned long) (start - section_begin),
3965 (unsigned long) (next - section_begin));
3966 else if (start > next)
3967 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3968 (unsigned long) (start - section_begin),
3969 (unsigned long) (next - section_begin));
3973 if (offset >= bytes)
3975 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3982 if (start + 2 * pointer_size > section_end)
3984 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3989 /* Note: we use sign extension here in order to be sure that
3990 we can detect the -1 escape value. Sign extension into the
3991 top 32 bits of a 32-bit address will not affect the values
3992 that we display since we always show hex values, and always
3993 the bottom 32-bits. */
3994 begin = byte_get_signed (start, pointer_size);
3995 start += pointer_size;
3996 end = byte_get_signed (start, pointer_size);
3997 start += pointer_size;
3999 printf (" %8.8lx ", offset);
4001 if (begin == 0 && end == 0)
4003 printf (_("<End of list>\n"));
4007 /* Check base address specifiers. */
4008 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4011 print_dwarf_vma (begin, pointer_size);
4012 print_dwarf_vma (end, pointer_size);
4013 printf (_("(base address)\n"));
4017 if (start + 2 > section_end)
4019 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4024 length = byte_get (start, 2);
4027 if (start + length > section_end)
4029 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4034 print_dwarf_vma (begin + base_address, pointer_size);
4035 print_dwarf_vma (end + base_address, pointer_size);
4038 need_frame_base = decode_location_expression (start,
4043 cu_offset, section);
4046 if (need_frame_base && !has_frame_base)
4047 printf (_(" [without DW_AT_frame_base]"));
4050 fputs (_(" (start == end)"), stdout);
4051 else if (begin > end)
4052 fputs (_(" (start > end)"), stdout);
4061 if (start < section_end)
4062 warn (_("There are %ld unused bytes at the end of section %s\n"),
4063 (long) (section_end - start), section->name);
4070 display_debug_str (struct dwarf_section *section,
4071 void *file ATTRIBUTE_UNUSED)
4073 unsigned char *start = section->start;
4074 unsigned long bytes = section->size;
4075 dwarf_vma addr = section->address;
4079 printf (_("\nThe %s section is empty.\n"), section->name);
4083 printf (_("Contents of the %s section:\n\n"), section->name);
4091 lbytes = (bytes > 16 ? 16 : bytes);
4093 printf (" 0x%8.8lx ", (unsigned long) addr);
4095 for (j = 0; j < 16; j++)
4098 printf ("%2.2x", start[j]);
4106 for (j = 0; j < lbytes; j++)
4109 if (k >= ' ' && k < 0x80)
4128 display_debug_info (struct dwarf_section *section, void *file)
4130 return process_debug_info (section, file, abbrev, 0, 0);
4134 display_debug_types (struct dwarf_section *section, void *file)
4136 return process_debug_info (section, file, abbrev, 0, 1);
4140 display_trace_info (struct dwarf_section *section, void *file)
4142 return process_debug_info (section, file, trace_abbrev, 0, 0);
4146 display_debug_aranges (struct dwarf_section *section,
4147 void *file ATTRIBUTE_UNUSED)
4149 unsigned char *start = section->start;
4150 unsigned char *end = start + section->size;
4152 printf (_("Contents of the %s section:\n\n"), section->name);
4154 /* It does not matter if this load fails,
4155 we test for that later on. */
4156 load_debug_info (file);
4160 unsigned char *hdrptr;
4161 DWARF2_Internal_ARange arange;
4162 unsigned char *addr_ranges;
4165 unsigned char address_size;
4168 int initial_length_size;
4172 arange.ar_length = byte_get (hdrptr, 4);
4175 if (arange.ar_length == 0xffffffff)
4177 arange.ar_length = byte_get (hdrptr, 8);
4180 initial_length_size = 12;
4185 initial_length_size = 4;
4188 arange.ar_version = byte_get (hdrptr, 2);
4191 arange.ar_info_offset = byte_get (hdrptr, offset_size);
4192 hdrptr += offset_size;
4194 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4195 && num_debug_info_entries > 0
4196 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4197 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4198 (unsigned long) arange.ar_info_offset, section->name);
4200 arange.ar_pointer_size = byte_get (hdrptr, 1);
4203 arange.ar_segment_size = byte_get (hdrptr, 1);
4206 if (arange.ar_version != 2 && arange.ar_version != 3)
4208 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4212 printf (_(" Length: %ld\n"),
4213 (long) arange.ar_length);
4214 printf (_(" Version: %d\n"), arange.ar_version);
4215 printf (_(" Offset into .debug_info: 0x%lx\n"),
4216 (unsigned long) arange.ar_info_offset);
4217 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4218 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4220 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4222 if (address_size == 0)
4224 error (_("Invalid address size in %s section!\n"),
4229 /* The DWARF spec does not require that the address size be a power
4230 of two, but we do. This will have to change if we ever encounter
4231 an uneven architecture. */
4232 if ((address_size & (address_size - 1)) != 0)
4234 warn (_("Pointer size + Segment size is not a power of two.\n"));
4238 if (address_size > 4)
4239 printf (_("\n Address Length\n"));
4241 printf (_("\n Address Length\n"));
4243 addr_ranges = hdrptr;
4245 /* Must pad to an alignment boundary that is twice the address size. */
4246 excess = (hdrptr - start) % (2 * address_size);
4248 addr_ranges += (2 * address_size) - excess;
4250 start += arange.ar_length + initial_length_size;
4252 while (addr_ranges + 2 * address_size <= start)
4254 address = byte_get (addr_ranges, address_size);
4256 addr_ranges += address_size;
4258 length = byte_get (addr_ranges, address_size);
4260 addr_ranges += address_size;
4263 print_dwarf_vma (address, address_size);
4264 print_dwarf_vma (length, address_size);
4274 /* Each debug_information[x].range_lists[y] gets this representation for
4275 sorting purposes. */
4279 /* The debug_information[x].range_lists[y] value. */
4280 unsigned long ranges_offset;
4282 /* Original debug_information to find parameters of the data. */
4283 debug_info *debug_info_p;
4286 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4289 range_entry_compar (const void *ap, const void *bp)
4291 const struct range_entry *a_re = (const struct range_entry *) ap;
4292 const struct range_entry *b_re = (const struct range_entry *) bp;
4293 const unsigned long a = a_re->ranges_offset;
4294 const unsigned long b = b_re->ranges_offset;
4296 return (a > b) - (b > a);
4300 display_debug_ranges (struct dwarf_section *section,
4301 void *file ATTRIBUTE_UNUSED)
4303 unsigned char *start = section->start;
4304 unsigned long bytes;
4305 unsigned char *section_begin = start;
4306 unsigned int num_range_list, i;
4307 struct range_entry *range_entries, *range_entry_fill;
4309 bytes = section->size;
4313 printf (_("\nThe %s section is empty.\n"), section->name);
4317 if (load_debug_info (file) == 0)
4319 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4325 for (i = 0; i < num_debug_info_entries; i++)
4326 num_range_list += debug_information [i].num_range_lists;
4328 if (num_range_list == 0)
4329 error (_("No range lists in .debug_info section!\n"));
4331 range_entries = (struct range_entry *)
4332 xmalloc (sizeof (*range_entries) * num_range_list);
4333 range_entry_fill = range_entries;
4335 for (i = 0; i < num_debug_info_entries; i++)
4337 debug_info *debug_info_p = &debug_information[i];
4340 for (j = 0; j < debug_info_p->num_range_lists; j++)
4342 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4343 range_entry_fill->debug_info_p = debug_info_p;
4348 qsort (range_entries, num_range_list, sizeof (*range_entries),
4349 range_entry_compar);
4351 /* DWARF sections under Mach-O have non-zero addresses. */
4352 if (range_entries[0].ranges_offset != section->address)
4353 warn (_("Range lists in %s section start at 0x%lx\n"),
4354 section->name, range_entries[0].ranges_offset);
4356 printf (_("Contents of the %s section:\n\n"), section->name);
4357 printf (_(" Offset Begin End\n"));
4359 for (i = 0; i < num_range_list; i++)
4361 struct range_entry *range_entry = &range_entries[i];
4362 debug_info *debug_info_p = range_entry->debug_info_p;
4363 unsigned int pointer_size;
4364 unsigned long offset;
4365 unsigned char *next;
4366 unsigned long base_address;
4368 pointer_size = debug_info_p->pointer_size;
4370 /* DWARF sections under Mach-O have non-zero addresses. */
4371 offset = range_entry->ranges_offset - section->address;
4372 next = section_begin + offset;
4373 base_address = debug_info_p->base_address;
4378 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4379 (unsigned long) (start - section_begin),
4380 (unsigned long) (next - section_begin), section->name);
4381 else if (start > next)
4382 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4383 (unsigned long) (start - section_begin),
4384 (unsigned long) (next - section_begin), section->name);
4393 /* Note: we use sign extension here in order to be sure that
4394 we can detect the -1 escape value. Sign extension into the
4395 top 32 bits of a 32-bit address will not affect the values
4396 that we display since we always show hex values, and always
4397 the bottom 32-bits. */
4398 begin = byte_get_signed (start, pointer_size);
4399 start += pointer_size;
4400 end = byte_get_signed (start, pointer_size);
4401 start += pointer_size;
4403 printf (" %8.8lx ", offset);
4405 if (begin == 0 && end == 0)
4407 printf (_("<End of list>\n"));
4411 /* Check base address specifiers. */
4412 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4415 print_dwarf_vma (begin, pointer_size);
4416 print_dwarf_vma (end, pointer_size);
4417 printf ("(base address)\n");
4421 print_dwarf_vma (begin + base_address, pointer_size);
4422 print_dwarf_vma (end + base_address, pointer_size);
4425 fputs (_("(start == end)"), stdout);
4426 else if (begin > end)
4427 fputs (_("(start > end)"), stdout);
4434 free (range_entries);
4439 typedef struct Frame_Chunk
4441 struct Frame_Chunk *next;
4442 unsigned char *chunk_start;
4444 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4445 short int *col_type;
4448 unsigned int code_factor;
4450 unsigned long pc_begin;
4451 unsigned long pc_range;
4455 unsigned char fde_encoding;
4456 unsigned char cfa_exp;
4457 unsigned char ptr_size;
4458 unsigned char segment_size;
4462 static const char *const *dwarf_regnames;
4463 static unsigned int dwarf_regnames_count;
4465 /* A marker for a col_type that means this column was never referenced
4466 in the frame info. */
4467 #define DW_CFA_unreferenced (-1)
4469 /* Return 0 if not more space is needed, 1 if more space is needed,
4470 -1 for invalid reg. */
4473 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4475 int prev = fc->ncols;
4477 if (reg < (unsigned int) fc->ncols)
4480 if (dwarf_regnames_count
4481 && reg > dwarf_regnames_count)
4484 fc->ncols = reg + 1;
4485 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4486 sizeof (short int));
4487 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4489 while (prev < fc->ncols)
4491 fc->col_type[prev] = DW_CFA_unreferenced;
4492 fc->col_offset[prev] = 0;
4498 static const char *const dwarf_regnames_i386[] =
4500 "eax", "ecx", "edx", "ebx",
4501 "esp", "ebp", "esi", "edi",
4502 "eip", "eflags", NULL,
4503 "st0", "st1", "st2", "st3",
4504 "st4", "st5", "st6", "st7",
4506 "xmm0", "xmm1", "xmm2", "xmm3",
4507 "xmm4", "xmm5", "xmm6", "xmm7",
4508 "mm0", "mm1", "mm2", "mm3",
4509 "mm4", "mm5", "mm6", "mm7",
4510 "fcw", "fsw", "mxcsr",
4511 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4516 init_dwarf_regnames_i386 (void)
4518 dwarf_regnames = dwarf_regnames_i386;
4519 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4522 static const char *const dwarf_regnames_x86_64[] =
4524 "rax", "rdx", "rcx", "rbx",
4525 "rsi", "rdi", "rbp", "rsp",
4526 "r8", "r9", "r10", "r11",
4527 "r12", "r13", "r14", "r15",
4529 "xmm0", "xmm1", "xmm2", "xmm3",
4530 "xmm4", "xmm5", "xmm6", "xmm7",
4531 "xmm8", "xmm9", "xmm10", "xmm11",
4532 "xmm12", "xmm13", "xmm14", "xmm15",
4533 "st0", "st1", "st2", "st3",
4534 "st4", "st5", "st6", "st7",
4535 "mm0", "mm1", "mm2", "mm3",
4536 "mm4", "mm5", "mm6", "mm7",
4538 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4539 "fs.base", "gs.base", NULL, NULL,
4541 "mxcsr", "fcw", "fsw"
4545 init_dwarf_regnames_x86_64 (void)
4547 dwarf_regnames = dwarf_regnames_x86_64;
4548 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4552 init_dwarf_regnames (unsigned int e_machine)
4558 init_dwarf_regnames_i386 ();
4564 init_dwarf_regnames_x86_64 ();
4573 regname (unsigned int regno, int row)
4575 static char reg[64];
4577 && regno < dwarf_regnames_count
4578 && dwarf_regnames [regno] != NULL)
4581 return dwarf_regnames [regno];
4582 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4583 dwarf_regnames [regno]);
4586 snprintf (reg, sizeof (reg), "r%d", regno);
4591 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4596 if (*max_regs < fc->ncols)
4597 *max_regs = fc->ncols;
4599 if (*need_col_headers)
4601 static const char *sloc = " LOC";
4603 *need_col_headers = 0;
4605 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4607 for (r = 0; r < *max_regs; r++)
4608 if (fc->col_type[r] != DW_CFA_unreferenced)
4613 printf ("%-5s ", regname (r, 1));
4619 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4621 strcpy (tmp, "exp");
4623 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4624 printf ("%-8s ", tmp);
4626 for (r = 0; r < fc->ncols; r++)
4628 if (fc->col_type[r] != DW_CFA_unreferenced)
4630 switch (fc->col_type[r])
4632 case DW_CFA_undefined:
4635 case DW_CFA_same_value:
4639 sprintf (tmp, "c%+d", fc->col_offset[r]);
4641 case DW_CFA_val_offset:
4642 sprintf (tmp, "v%+d", fc->col_offset[r]);
4644 case DW_CFA_register:
4645 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4647 case DW_CFA_expression:
4648 strcpy (tmp, "exp");
4650 case DW_CFA_val_expression:
4651 strcpy (tmp, "vexp");
4654 strcpy (tmp, "n/a");
4657 printf ("%-5s ", tmp);
4663 #define GET(N) byte_get (start, N); start += N
4664 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4665 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4668 display_debug_frames (struct dwarf_section *section,
4669 void *file ATTRIBUTE_UNUSED)
4671 unsigned char *start = section->start;
4672 unsigned char *end = start + section->size;
4673 unsigned char *section_start = start;
4674 Frame_Chunk *chunks = 0;
4675 Frame_Chunk *remembered_state = 0;
4677 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4678 unsigned int length_return;
4680 const char *bad_reg = _("bad register: ");
4681 int saved_eh_addr_size = eh_addr_size;
4683 printf (_("Contents of the %s section:\n"), section->name);
4687 unsigned char *saved_start;
4688 unsigned char *block_end;
4689 unsigned long length;
4690 unsigned long cie_id;
4693 int need_col_headers = 1;
4694 unsigned char *augmentation_data = NULL;
4695 unsigned long augmentation_data_len = 0;
4696 int encoded_ptr_size = saved_eh_addr_size;
4698 int initial_length_size;
4700 saved_start = start;
4701 length = byte_get (start, 4); start += 4;
4705 printf ("\n%08lx ZERO terminator\n\n",
4706 (unsigned long)(saved_start - section_start));
4710 if (length == 0xffffffff)
4712 length = byte_get (start, 8);
4715 initial_length_size = 12;
4720 initial_length_size = 4;
4723 block_end = saved_start + length + initial_length_size;
4724 if (block_end > end)
4726 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4727 length, (unsigned long)(saved_start - section_start));
4730 cie_id = byte_get (start, offset_size); start += offset_size;
4732 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4736 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4737 memset (fc, 0, sizeof (Frame_Chunk));
4741 fc->chunk_start = saved_start;
4743 fc->col_type = (short int *) xmalloc (sizeof (short int));
4744 fc->col_offset = (int *) xmalloc (sizeof (int));
4745 frame_need_space (fc, max_regs - 1);
4749 fc->augmentation = (char *) start;
4750 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4752 if (strcmp (fc->augmentation, "eh") == 0)
4753 start += eh_addr_size;
4757 fc->ptr_size = GET (1);
4758 fc->segment_size = GET (1);
4759 eh_addr_size = fc->ptr_size;
4763 fc->ptr_size = eh_addr_size;
4764 fc->segment_size = 0;
4766 fc->code_factor = LEB ();
4767 fc->data_factor = SLEB ();
4777 if (fc->augmentation[0] == 'z')
4779 augmentation_data_len = LEB ();
4780 augmentation_data = start;
4781 start += augmentation_data_len;
4785 if (do_debug_frames_interp)
4786 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4787 (unsigned long)(saved_start - section_start), length, cie_id,
4788 fc->augmentation, fc->code_factor, fc->data_factor,
4792 printf ("\n%08lx %08lx %08lx CIE\n",
4793 (unsigned long)(saved_start - section_start), length, cie_id);
4794 printf (" Version: %d\n", version);
4795 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4798 printf (" Pointer Size: %u\n", fc->ptr_size);
4799 printf (" Segment Size: %u\n", fc->segment_size);
4801 printf (" Code alignment factor: %u\n", fc->code_factor);
4802 printf (" Data alignment factor: %d\n", fc->data_factor);
4803 printf (" Return address column: %d\n", fc->ra);
4805 if (augmentation_data_len)
4808 printf (" Augmentation data: ");
4809 for (i = 0; i < augmentation_data_len; ++i)
4810 printf (" %02x", augmentation_data[i]);
4816 if (augmentation_data_len)
4818 unsigned char *p, *q;
4819 p = (unsigned char *) fc->augmentation + 1;
4820 q = augmentation_data;
4827 q += 1 + size_of_encoded_value (*q);
4829 fc->fde_encoding = *q++;
4837 if (fc->fde_encoding)
4838 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4841 frame_need_space (fc, fc->ra);
4845 unsigned char *look_for;
4846 static Frame_Chunk fde_fc;
4847 unsigned long segment_selector;
4850 memset (fc, 0, sizeof (Frame_Chunk));
4852 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
4854 for (cie = chunks; cie ; cie = cie->next)
4855 if (cie->chunk_start == look_for)
4860 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4861 cie_id, (unsigned long)(saved_start - section_start));
4863 fc->col_type = (short int *) xmalloc (sizeof (short int));
4864 fc->col_offset = (int *) xmalloc (sizeof (int));
4865 frame_need_space (fc, max_regs - 1);
4867 fc->augmentation = "";
4868 fc->fde_encoding = 0;
4869 fc->ptr_size = eh_addr_size;
4870 fc->segment_size = 0;
4874 fc->ncols = cie->ncols;
4875 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
4876 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
4877 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
4878 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
4879 fc->augmentation = cie->augmentation;
4880 fc->ptr_size = cie->ptr_size;
4881 eh_addr_size = cie->ptr_size;
4882 fc->segment_size = cie->segment_size;
4883 fc->code_factor = cie->code_factor;
4884 fc->data_factor = cie->data_factor;
4885 fc->cfa_reg = cie->cfa_reg;
4886 fc->cfa_offset = cie->cfa_offset;
4888 frame_need_space (fc, max_regs - 1);
4889 fc->fde_encoding = cie->fde_encoding;
4892 if (fc->fde_encoding)
4893 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4895 segment_selector = 0;
4896 if (fc->segment_size)
4898 segment_selector = byte_get (start, fc->segment_size);
4899 start += fc->segment_size;
4901 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
4902 start += encoded_ptr_size;
4903 fc->pc_range = byte_get (start, encoded_ptr_size);
4904 start += encoded_ptr_size;
4906 if (cie->augmentation[0] == 'z')
4908 augmentation_data_len = LEB ();
4909 augmentation_data = start;
4910 start += augmentation_data_len;
4913 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4914 (unsigned long)(saved_start - section_start), length, cie_id,
4915 (unsigned long)(cie->chunk_start - section_start));
4916 if (fc->segment_size)
4917 printf ("%04lx:", segment_selector);
4918 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
4919 if (! do_debug_frames_interp && augmentation_data_len)
4923 printf (" Augmentation data: ");
4924 for (i = 0; i < augmentation_data_len; ++i)
4925 printf (" %02x", augmentation_data[i]);
4931 /* At this point, fc is the current chunk, cie (if any) is set, and
4932 we're about to interpret instructions for the chunk. */
4933 /* ??? At present we need to do this always, since this sizes the
4934 fc->col_type and fc->col_offset arrays, which we write into always.
4935 We should probably split the interpreted and non-interpreted bits
4936 into two different routines, since there's so much that doesn't
4937 really overlap between them. */
4938 if (1 || do_debug_frames_interp)
4940 /* Start by making a pass over the chunk, allocating storage
4941 and taking note of what registers are used. */
4942 unsigned char *tmp = start;
4944 while (start < block_end)
4947 unsigned long reg, temp;
4954 /* Warning: if you add any more cases to this switch, be
4955 sure to add them to the corresponding switch below. */
4958 case DW_CFA_advance_loc:
4962 if (frame_need_space (fc, opa) >= 0)
4963 fc->col_type[opa] = DW_CFA_undefined;
4965 case DW_CFA_restore:
4966 if (frame_need_space (fc, opa) >= 0)
4967 fc->col_type[opa] = DW_CFA_undefined;
4969 case DW_CFA_set_loc:
4970 start += encoded_ptr_size;
4972 case DW_CFA_advance_loc1:
4975 case DW_CFA_advance_loc2:
4978 case DW_CFA_advance_loc4:
4981 case DW_CFA_offset_extended:
4982 case DW_CFA_val_offset:
4983 reg = LEB (); LEB ();
4984 if (frame_need_space (fc, reg) >= 0)
4985 fc->col_type[reg] = DW_CFA_undefined;
4987 case DW_CFA_restore_extended:
4989 frame_need_space (fc, reg);
4990 if (frame_need_space (fc, reg) >= 0)
4991 fc->col_type[reg] = DW_CFA_undefined;
4993 case DW_CFA_undefined:
4995 if (frame_need_space (fc, reg) >= 0)
4996 fc->col_type[reg] = DW_CFA_undefined;
4998 case DW_CFA_same_value:
5000 if (frame_need_space (fc, reg) >= 0)
5001 fc->col_type[reg] = DW_CFA_undefined;
5003 case DW_CFA_register:
5004 reg = LEB (); LEB ();
5005 if (frame_need_space (fc, reg) >= 0)
5006 fc->col_type[reg] = DW_CFA_undefined;
5008 case DW_CFA_def_cfa:
5011 case DW_CFA_def_cfa_register:
5014 case DW_CFA_def_cfa_offset:
5017 case DW_CFA_def_cfa_expression:
5021 case DW_CFA_expression:
5022 case DW_CFA_val_expression:
5026 if (frame_need_space (fc, reg) >= 0)
5027 fc->col_type[reg] = DW_CFA_undefined;
5029 case DW_CFA_offset_extended_sf:
5030 case DW_CFA_val_offset_sf:
5031 reg = LEB (); SLEB ();
5032 if (frame_need_space (fc, reg) >= 0)
5033 fc->col_type[reg] = DW_CFA_undefined;
5035 case DW_CFA_def_cfa_sf:
5038 case DW_CFA_def_cfa_offset_sf:
5041 case DW_CFA_MIPS_advance_loc8:
5044 case DW_CFA_GNU_args_size:
5047 case DW_CFA_GNU_negative_offset_extended:
5048 reg = LEB (); LEB ();
5049 if (frame_need_space (fc, reg) >= 0)
5050 fc->col_type[reg] = DW_CFA_undefined;
5059 /* Now we know what registers are used, make a second pass over
5060 the chunk, this time actually printing out the info. */
5062 while (start < block_end)
5065 unsigned long ul, reg, roffs;
5068 const char *reg_prefix = "";
5075 /* Warning: if you add any more cases to this switch, be
5076 sure to add them to the corresponding switch above. */
5079 case DW_CFA_advance_loc:
5080 if (do_debug_frames_interp)
5081 frame_display_row (fc, &need_col_headers, &max_regs);
5083 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5084 opa * fc->code_factor,
5085 fc->pc_begin + opa * fc->code_factor);
5086 fc->pc_begin += opa * fc->code_factor;
5091 if (opa >= (unsigned int) fc->ncols)
5092 reg_prefix = bad_reg;
5093 if (! do_debug_frames_interp || *reg_prefix != '\0')
5094 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5095 reg_prefix, regname (opa, 0),
5096 roffs * fc->data_factor);
5097 if (*reg_prefix == '\0')
5099 fc->col_type[opa] = DW_CFA_offset;
5100 fc->col_offset[opa] = roffs * fc->data_factor;
5104 case DW_CFA_restore:
5105 if (opa >= (unsigned int) cie->ncols
5106 || opa >= (unsigned int) fc->ncols)
5107 reg_prefix = bad_reg;
5108 if (! do_debug_frames_interp || *reg_prefix != '\0')
5109 printf (" DW_CFA_restore: %s%s\n",
5110 reg_prefix, regname (opa, 0));
5111 if (*reg_prefix == '\0')
5113 fc->col_type[opa] = cie->col_type[opa];
5114 fc->col_offset[opa] = cie->col_offset[opa];
5115 if (do_debug_frames_interp
5116 && fc->col_type[opa] == DW_CFA_unreferenced)
5117 fc->col_type[opa] = DW_CFA_undefined;
5121 case DW_CFA_set_loc:
5122 vma = get_encoded_value (start, fc->fde_encoding, section);
5123 start += encoded_ptr_size;
5124 if (do_debug_frames_interp)
5125 frame_display_row (fc, &need_col_headers, &max_regs);
5127 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5131 case DW_CFA_advance_loc1:
5132 ofs = byte_get (start, 1); start += 1;
5133 if (do_debug_frames_interp)
5134 frame_display_row (fc, &need_col_headers, &max_regs);
5136 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5137 ofs * fc->code_factor,
5138 fc->pc_begin + ofs * fc->code_factor);
5139 fc->pc_begin += ofs * fc->code_factor;
5142 case DW_CFA_advance_loc2:
5143 ofs = byte_get (start, 2); start += 2;
5144 if (do_debug_frames_interp)
5145 frame_display_row (fc, &need_col_headers, &max_regs);
5147 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5148 ofs * fc->code_factor,
5149 fc->pc_begin + ofs * fc->code_factor);
5150 fc->pc_begin += ofs * fc->code_factor;
5153 case DW_CFA_advance_loc4:
5154 ofs = byte_get (start, 4); start += 4;
5155 if (do_debug_frames_interp)
5156 frame_display_row (fc, &need_col_headers, &max_regs);
5158 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5159 ofs * fc->code_factor,
5160 fc->pc_begin + ofs * fc->code_factor);
5161 fc->pc_begin += ofs * fc->code_factor;
5164 case DW_CFA_offset_extended:
5167 if (reg >= (unsigned int) fc->ncols)
5168 reg_prefix = bad_reg;
5169 if (! do_debug_frames_interp || *reg_prefix != '\0')
5170 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5171 reg_prefix, regname (reg, 0),
5172 roffs * fc->data_factor);
5173 if (*reg_prefix == '\0')
5175 fc->col_type[reg] = DW_CFA_offset;
5176 fc->col_offset[reg] = roffs * fc->data_factor;
5180 case DW_CFA_val_offset:
5183 if (reg >= (unsigned int) fc->ncols)
5184 reg_prefix = bad_reg;
5185 if (! do_debug_frames_interp || *reg_prefix != '\0')
5186 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5187 reg_prefix, regname (reg, 0),
5188 roffs * fc->data_factor);
5189 if (*reg_prefix == '\0')
5191 fc->col_type[reg] = DW_CFA_val_offset;
5192 fc->col_offset[reg] = roffs * fc->data_factor;
5196 case DW_CFA_restore_extended:
5198 if (reg >= (unsigned int) cie->ncols
5199 || reg >= (unsigned int) fc->ncols)
5200 reg_prefix = bad_reg;
5201 if (! do_debug_frames_interp || *reg_prefix != '\0')
5202 printf (" DW_CFA_restore_extended: %s%s\n",
5203 reg_prefix, regname (reg, 0));
5204 if (*reg_prefix == '\0')
5206 fc->col_type[reg] = cie->col_type[reg];
5207 fc->col_offset[reg] = cie->col_offset[reg];
5211 case DW_CFA_undefined:
5213 if (reg >= (unsigned int) fc->ncols)
5214 reg_prefix = bad_reg;
5215 if (! do_debug_frames_interp || *reg_prefix != '\0')
5216 printf (" DW_CFA_undefined: %s%s\n",
5217 reg_prefix, regname (reg, 0));
5218 if (*reg_prefix == '\0')
5220 fc->col_type[reg] = DW_CFA_undefined;
5221 fc->col_offset[reg] = 0;
5225 case DW_CFA_same_value:
5227 if (reg >= (unsigned int) fc->ncols)
5228 reg_prefix = bad_reg;
5229 if (! do_debug_frames_interp || *reg_prefix != '\0')
5230 printf (" DW_CFA_same_value: %s%s\n",
5231 reg_prefix, regname (reg, 0));
5232 if (*reg_prefix == '\0')
5234 fc->col_type[reg] = DW_CFA_same_value;
5235 fc->col_offset[reg] = 0;
5239 case DW_CFA_register:
5242 if (reg >= (unsigned int) fc->ncols)
5243 reg_prefix = bad_reg;
5244 if (! do_debug_frames_interp || *reg_prefix != '\0')
5246 printf (" DW_CFA_register: %s%s in ",
5247 reg_prefix, regname (reg, 0));
5248 puts (regname (roffs, 0));
5250 if (*reg_prefix == '\0')
5252 fc->col_type[reg] = DW_CFA_register;
5253 fc->col_offset[reg] = roffs;
5257 case DW_CFA_remember_state:
5258 if (! do_debug_frames_interp)
5259 printf (" DW_CFA_remember_state\n");
5260 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5261 rs->ncols = fc->ncols;
5262 rs->col_type = (short int *) xcmalloc (rs->ncols,
5263 sizeof (short int));
5264 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
5265 memcpy (rs->col_type, fc->col_type, rs->ncols);
5266 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5267 rs->next = remembered_state;
5268 remembered_state = rs;
5271 case DW_CFA_restore_state:
5272 if (! do_debug_frames_interp)
5273 printf (" DW_CFA_restore_state\n");
5274 rs = remembered_state;
5277 remembered_state = rs->next;
5278 frame_need_space (fc, rs->ncols - 1);
5279 memcpy (fc->col_type, rs->col_type, rs->ncols);
5280 memcpy (fc->col_offset, rs->col_offset,
5281 rs->ncols * sizeof (int));
5282 free (rs->col_type);
5283 free (rs->col_offset);
5286 else if (do_debug_frames_interp)
5287 printf ("Mismatched DW_CFA_restore_state\n");
5290 case DW_CFA_def_cfa:
5291 fc->cfa_reg = LEB ();
5292 fc->cfa_offset = LEB ();
5294 if (! do_debug_frames_interp)
5295 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5296 regname (fc->cfa_reg, 0), fc->cfa_offset);
5299 case DW_CFA_def_cfa_register:
5300 fc->cfa_reg = LEB ();
5302 if (! do_debug_frames_interp)
5303 printf (" DW_CFA_def_cfa_register: %s\n",
5304 regname (fc->cfa_reg, 0));
5307 case DW_CFA_def_cfa_offset:
5308 fc->cfa_offset = LEB ();
5309 if (! do_debug_frames_interp)
5310 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5314 if (! do_debug_frames_interp)
5315 printf (" DW_CFA_nop\n");
5318 case DW_CFA_def_cfa_expression:
5320 if (! do_debug_frames_interp)
5322 printf (" DW_CFA_def_cfa_expression (");
5323 decode_location_expression (start, eh_addr_size, 0, -1,
5331 case DW_CFA_expression:
5334 if (reg >= (unsigned int) fc->ncols)
5335 reg_prefix = bad_reg;
5336 if (! do_debug_frames_interp || *reg_prefix != '\0')
5338 printf (" DW_CFA_expression: %s%s (",
5339 reg_prefix, regname (reg, 0));
5340 decode_location_expression (start, eh_addr_size, 0, -1,
5344 if (*reg_prefix == '\0')
5345 fc->col_type[reg] = DW_CFA_expression;
5349 case DW_CFA_val_expression:
5352 if (reg >= (unsigned int) fc->ncols)
5353 reg_prefix = bad_reg;
5354 if (! do_debug_frames_interp || *reg_prefix != '\0')
5356 printf (" DW_CFA_val_expression: %s%s (",
5357 reg_prefix, regname (reg, 0));
5358 decode_location_expression (start, eh_addr_size, 0, -1,
5362 if (*reg_prefix == '\0')
5363 fc->col_type[reg] = DW_CFA_val_expression;
5367 case DW_CFA_offset_extended_sf:
5370 if (frame_need_space (fc, reg) < 0)
5371 reg_prefix = bad_reg;
5372 if (! do_debug_frames_interp || *reg_prefix != '\0')
5373 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5374 reg_prefix, regname (reg, 0),
5375 l * fc->data_factor);
5376 if (*reg_prefix == '\0')
5378 fc->col_type[reg] = DW_CFA_offset;
5379 fc->col_offset[reg] = l * fc->data_factor;
5383 case DW_CFA_val_offset_sf:
5386 if (frame_need_space (fc, reg) < 0)
5387 reg_prefix = bad_reg;
5388 if (! do_debug_frames_interp || *reg_prefix != '\0')
5389 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5390 reg_prefix, regname (reg, 0),
5391 l * fc->data_factor);
5392 if (*reg_prefix == '\0')
5394 fc->col_type[reg] = DW_CFA_val_offset;
5395 fc->col_offset[reg] = l * fc->data_factor;
5399 case DW_CFA_def_cfa_sf:
5400 fc->cfa_reg = LEB ();
5401 fc->cfa_offset = SLEB ();
5402 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5404 if (! do_debug_frames_interp)
5405 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5406 regname (fc->cfa_reg, 0), fc->cfa_offset);
5409 case DW_CFA_def_cfa_offset_sf:
5410 fc->cfa_offset = SLEB ();
5411 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5412 if (! do_debug_frames_interp)
5413 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5416 case DW_CFA_MIPS_advance_loc8:
5417 ofs = byte_get (start, 8); start += 8;
5418 if (do_debug_frames_interp)
5419 frame_display_row (fc, &need_col_headers, &max_regs);
5421 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5422 ofs * fc->code_factor,
5423 fc->pc_begin + ofs * fc->code_factor);
5424 fc->pc_begin += ofs * fc->code_factor;
5427 case DW_CFA_GNU_window_save:
5428 if (! do_debug_frames_interp)
5429 printf (" DW_CFA_GNU_window_save\n");
5432 case DW_CFA_GNU_args_size:
5434 if (! do_debug_frames_interp)
5435 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5438 case DW_CFA_GNU_negative_offset_extended:
5441 if (frame_need_space (fc, reg) < 0)
5442 reg_prefix = bad_reg;
5443 if (! do_debug_frames_interp || *reg_prefix != '\0')
5444 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5445 reg_prefix, regname (reg, 0),
5446 l * fc->data_factor);
5447 if (*reg_prefix == '\0')
5449 fc->col_type[reg] = DW_CFA_offset;
5450 fc->col_offset[reg] = l * fc->data_factor;
5455 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5456 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5458 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5463 if (do_debug_frames_interp)
5464 frame_display_row (fc, &need_col_headers, &max_regs);
5467 eh_addr_size = saved_eh_addr_size;
5480 display_gdb_index (struct dwarf_section *section,
5481 void *file ATTRIBUTE_UNUSED)
5483 unsigned char *start = section->start;
5485 uint32_t cu_list_offset, tu_list_offset;
5486 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5487 unsigned int cu_list_elements, tu_list_elements;
5488 unsigned int address_table_size, symbol_table_slots;
5489 unsigned char *cu_list, *tu_list;
5490 unsigned char *address_table, *symbol_table, *constant_pool;
5493 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5495 printf (_("Contents of the %s section:\n"), section->name);
5497 if (section->size < 6 * sizeof (uint32_t))
5499 warn (_("Truncated header in the %s section.\n"), section->name);
5503 version = byte_get_little_endian (start, 4);
5504 printf (_("Version %ld\n"), (long) version);
5506 /* Prior versions are obsolete, and future versions may not be
5507 backwards compatible. */
5511 warn (_("The address table data in version 3 may be wrong.\n"));
5514 warn (_("Version 4 does not support case insensitive lookups.\n"));
5519 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5523 cu_list_offset = byte_get_little_endian (start + 4, 4);
5524 tu_list_offset = byte_get_little_endian (start + 8, 4);
5525 address_table_offset = byte_get_little_endian (start + 12, 4);
5526 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5527 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5529 if (cu_list_offset > section->size
5530 || tu_list_offset > section->size
5531 || address_table_offset > section->size
5532 || symbol_table_offset > section->size
5533 || constant_pool_offset > section->size)
5535 warn (_("Corrupt header in the %s section.\n"), section->name);
5539 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5540 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5541 address_table_size = symbol_table_offset - address_table_offset;
5542 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5544 cu_list = start + cu_list_offset;
5545 tu_list = start + tu_list_offset;
5546 address_table = start + address_table_offset;
5547 symbol_table = start + symbol_table_offset;
5548 constant_pool = start + constant_pool_offset;
5550 printf (_("\nCU table:\n"));
5551 for (i = 0; i < cu_list_elements; i += 2)
5553 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5554 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5556 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5557 (unsigned long) cu_offset,
5558 (unsigned long) (cu_offset + cu_length - 1));
5561 printf (_("\nTU table:\n"));
5562 for (i = 0; i < tu_list_elements; i += 3)
5564 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5565 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5566 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5568 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5569 (unsigned long) tu_offset,
5570 (unsigned long) type_offset);
5571 print_dwarf_vma (signature, 8);
5575 printf (_("\nAddress table:\n"));
5576 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5578 uint64_t low = byte_get_little_endian (address_table + i, 8);
5579 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5580 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5582 print_dwarf_vma (low, 8);
5583 print_dwarf_vma (high, 8);
5584 printf (_("%lu\n"), (unsigned long) cu_index);
5587 printf (_("\nSymbol table:\n"));
5588 for (i = 0; i < symbol_table_slots; ++i)
5590 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5591 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5592 uint32_t num_cus, cu;
5594 if (name_offset != 0
5595 || cu_vector_offset != 0)
5599 printf ("[%3u] %s:", i, constant_pool + name_offset);
5600 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5601 for (j = 0; j < num_cus; ++j)
5603 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5604 /* Convert to TU number if it's for a type unit. */
5605 if (cu >= cu_list_elements / 2)
5606 printf (" T%lu", (unsigned long) (cu - cu_list_elements / 2));
5608 printf (" %lu", (unsigned long) cu);
5618 display_debug_not_supported (struct dwarf_section *section,
5619 void *file ATTRIBUTE_UNUSED)
5621 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5628 cmalloc (size_t nmemb, size_t size)
5630 /* Check for overflow. */
5631 if (nmemb >= ~(size_t) 0 / size)
5634 return malloc (nmemb * size);
5638 xcmalloc (size_t nmemb, size_t size)
5640 /* Check for overflow. */
5641 if (nmemb >= ~(size_t) 0 / size)
5644 return xmalloc (nmemb * size);
5648 xcrealloc (void *ptr, size_t nmemb, size_t size)
5650 /* Check for overflow. */
5651 if (nmemb >= ~(size_t) 0 / size)
5654 return xrealloc (ptr, nmemb * size);
5658 free_debug_memory (void)
5664 for (i = 0; i < max; i++)
5665 free_debug_section ((enum dwarf_section_display_enum) i);
5667 if (debug_information != NULL)
5669 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
5671 for (i = 0; i < num_debug_info_entries; i++)
5673 if (!debug_information [i].max_loc_offsets)
5675 free (debug_information [i].loc_offsets);
5676 free (debug_information [i].have_frame_base);
5678 if (!debug_information [i].max_range_lists)
5679 free (debug_information [i].range_lists);
5683 free (debug_information);
5684 debug_information = NULL;
5685 num_debug_info_entries = 0;
5690 dwarf_select_sections_by_names (const char *names)
5694 const char * option;
5698 debug_dump_long_opts;
5700 static const debug_dump_long_opts opts_table [] =
5702 /* Please keep this table alpha- sorted. */
5703 { "Ranges", & do_debug_ranges, 1 },
5704 { "abbrev", & do_debug_abbrevs, 1 },
5705 { "aranges", & do_debug_aranges, 1 },
5706 { "frames", & do_debug_frames, 1 },
5707 { "frames-interp", & do_debug_frames_interp, 1 },
5708 { "info", & do_debug_info, 1 },
5709 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5710 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5711 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5712 { "loc", & do_debug_loc, 1 },
5713 { "macro", & do_debug_macinfo, 1 },
5714 { "pubnames", & do_debug_pubnames, 1 },
5715 { "pubtypes", & do_debug_pubtypes, 1 },
5716 /* This entry is for compatability
5717 with earlier versions of readelf. */
5718 { "ranges", & do_debug_aranges, 1 },
5719 { "str", & do_debug_str, 1 },
5720 /* The special .gdb_index section. */
5721 { "gdb_index", & do_gdb_index, 1 },
5722 /* These trace_* sections are used by Itanium VMS. */
5723 { "trace_abbrev", & do_trace_abbrevs, 1 },
5724 { "trace_aranges", & do_trace_aranges, 1 },
5725 { "trace_info", & do_trace_info, 1 },
5734 const debug_dump_long_opts * entry;
5736 for (entry = opts_table; entry->option; entry++)
5738 size_t len = strlen (entry->option);
5740 if (strncmp (p, entry->option, len) == 0
5741 && (p[len] == ',' || p[len] == '\0'))
5743 * entry->variable |= entry->val;
5745 /* The --debug-dump=frames-interp option also
5746 enables the --debug-dump=frames option. */
5747 if (do_debug_frames_interp)
5748 do_debug_frames = 1;
5755 if (entry->option == NULL)
5757 warn (_("Unrecognized debug option '%s'\n"), p);
5758 p = strchr (p, ',');
5769 dwarf_select_sections_by_letters (const char *letters)
5771 unsigned int lindex = 0;
5773 while (letters[lindex])
5774 switch (letters[lindex++])
5781 do_debug_abbrevs = 1;
5785 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
5789 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
5793 do_debug_pubnames = 1;
5797 do_debug_pubtypes = 1;
5801 do_debug_aranges = 1;
5805 do_debug_ranges = 1;
5809 do_debug_frames_interp = 1;
5811 do_debug_frames = 1;
5815 do_debug_macinfo = 1;
5827 warn (_("Unrecognized debug option '%s'\n"), optarg);
5833 dwarf_select_sections_all (void)
5836 do_debug_abbrevs = 1;
5837 do_debug_lines = FLAG_DEBUG_LINES_RAW;
5838 do_debug_pubnames = 1;
5839 do_debug_pubtypes = 1;
5840 do_debug_aranges = 1;
5841 do_debug_ranges = 1;
5842 do_debug_frames = 1;
5843 do_debug_macinfo = 1;
5848 do_trace_abbrevs = 1;
5849 do_trace_aranges = 1;
5852 struct dwarf_section_display debug_displays[] =
5854 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 },
5855 display_debug_abbrev, &do_debug_abbrevs, 0 },
5856 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 },
5857 display_debug_aranges, &do_debug_aranges, 1 },
5858 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 },
5859 display_debug_frames, &do_debug_frames, 1 },
5860 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 },
5861 display_debug_info, &do_debug_info, 1 },
5862 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 },
5863 display_debug_lines, &do_debug_lines, 1 },
5864 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 },
5865 display_debug_pubnames, &do_debug_pubnames, 0 },
5866 { { ".eh_frame", "", NULL, NULL, 0, 0 },
5867 display_debug_frames, &do_debug_frames, 1 },
5868 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 },
5869 display_debug_macinfo, &do_debug_macinfo, 0 },
5870 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0 },
5871 display_debug_macro, &do_debug_macinfo, 1 },
5872 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 },
5873 display_debug_str, &do_debug_str, 0 },
5874 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 },
5875 display_debug_loc, &do_debug_loc, 1 },
5876 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 },
5877 display_debug_pubnames, &do_debug_pubtypes, 0 },
5878 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 },
5879 display_debug_ranges, &do_debug_ranges, 1 },
5880 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 },
5881 display_debug_not_supported, NULL, 0 },
5882 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 },
5883 display_debug_not_supported, NULL, 0 },
5884 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 },
5885 display_debug_types, &do_debug_info, 1 },
5886 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 },
5887 display_debug_not_supported, NULL, 0 },
5888 { { ".gdb_index", "", NULL, NULL, 0, 0 },
5889 display_gdb_index, &do_gdb_index, 0 },
5890 { { ".trace_info", "", NULL, NULL, 0, 0 },
5891 display_trace_info, &do_trace_info, 1 },
5892 { { ".trace_abbrev", "", NULL, NULL, 0, 0 },
5893 display_debug_abbrev, &do_trace_abbrevs, 0 },
5894 { { ".trace_aranges", "", NULL, NULL, 0, 0 },
5895 display_debug_aranges, &do_trace_aranges, 0 }