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 /* MIPS extension. */
1603 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1604 /* UPC extension. */
1605 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1607 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1608 printf (_("(implementation defined: %s)"),
1609 dwarf_vmatoa ("x", uvalue));
1611 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1616 case DW_AT_encoding:
1619 case DW_ATE_void: printf ("(void)"); break;
1620 case DW_ATE_address: printf ("(machine address)"); break;
1621 case DW_ATE_boolean: printf ("(boolean)"); break;
1622 case DW_ATE_complex_float: printf ("(complex float)"); break;
1623 case DW_ATE_float: printf ("(float)"); break;
1624 case DW_ATE_signed: printf ("(signed)"); break;
1625 case DW_ATE_signed_char: printf ("(signed char)"); break;
1626 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1627 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1628 /* DWARF 2.1 values: */
1629 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1630 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1631 /* DWARF 3 values: */
1632 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1633 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1634 case DW_ATE_edited: printf ("(edited)"); break;
1635 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1636 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1637 /* HP extensions: */
1638 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1639 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1640 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1641 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1642 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1643 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1644 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1647 if (uvalue >= DW_ATE_lo_user
1648 && uvalue <= DW_ATE_hi_user)
1649 printf (_("(user defined type)"));
1651 printf (_("(unknown type)"));
1656 case DW_AT_accessibility:
1659 case DW_ACCESS_public: printf ("(public)"); break;
1660 case DW_ACCESS_protected: printf ("(protected)"); break;
1661 case DW_ACCESS_private: printf ("(private)"); break;
1663 printf (_("(unknown accessibility)"));
1668 case DW_AT_visibility:
1671 case DW_VIS_local: printf ("(local)"); break;
1672 case DW_VIS_exported: printf ("(exported)"); break;
1673 case DW_VIS_qualified: printf ("(qualified)"); break;
1674 default: printf (_("(unknown visibility)")); break;
1678 case DW_AT_virtuality:
1681 case DW_VIRTUALITY_none: printf ("(none)"); break;
1682 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1683 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1684 default: printf (_("(unknown virtuality)")); break;
1688 case DW_AT_identifier_case:
1691 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1692 case DW_ID_up_case: printf ("(up_case)"); break;
1693 case DW_ID_down_case: printf ("(down_case)"); break;
1694 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1695 default: printf (_("(unknown case)")); break;
1699 case DW_AT_calling_convention:
1702 case DW_CC_normal: printf ("(normal)"); break;
1703 case DW_CC_program: printf ("(program)"); break;
1704 case DW_CC_nocall: printf ("(nocall)"); break;
1706 if (uvalue >= DW_CC_lo_user
1707 && uvalue <= DW_CC_hi_user)
1708 printf (_("(user defined)"));
1710 printf (_("(unknown convention)"));
1714 case DW_AT_ordering:
1717 case -1: printf (_("(undefined)")); break;
1718 case 0: printf ("(row major)"); break;
1719 case 1: printf ("(column major)"); break;
1723 case DW_AT_frame_base:
1724 have_frame_base = 1;
1725 case DW_AT_location:
1726 case DW_AT_string_length:
1727 case DW_AT_return_addr:
1728 case DW_AT_data_member_location:
1729 case DW_AT_vtable_elem_location:
1731 case DW_AT_static_link:
1732 case DW_AT_use_location:
1733 case DW_AT_GNU_call_site_value:
1734 case DW_AT_GNU_call_site_data_value:
1735 case DW_AT_GNU_call_site_target:
1736 case DW_AT_GNU_call_site_target_clobbered:
1737 if ((dwarf_version < 4
1738 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1739 || form == DW_FORM_sec_offset)
1740 printf (_("(location list)"));
1742 case DW_AT_allocated:
1743 case DW_AT_associated:
1744 case DW_AT_data_location:
1746 case DW_AT_upper_bound:
1747 case DW_AT_lower_bound:
1750 int need_frame_base;
1753 need_frame_base = decode_location_expression (block_start,
1758 cu_offset, section);
1760 if (need_frame_base && !have_frame_base)
1761 printf (_(" [without DW_AT_frame_base]"));
1767 if (form == DW_FORM_ref_sig8)
1770 if (form == DW_FORM_ref1
1771 || form == DW_FORM_ref2
1772 || form == DW_FORM_ref4)
1773 uvalue += cu_offset;
1775 if (uvalue >= section->size)
1776 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1777 dwarf_vmatoa ("x", uvalue),
1778 (unsigned long) (orig_data - section->start));
1781 unsigned long abbrev_number;
1782 abbrev_entry * entry;
1784 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1786 printf (_("[Abbrev Number: %ld"), abbrev_number);
1787 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1788 if (entry->entry == abbrev_number)
1791 printf (" (%s)", get_TAG_name (entry->tag));
1805 get_AT_name (unsigned long attribute)
1809 case DW_AT_sibling: return "DW_AT_sibling";
1810 case DW_AT_location: return "DW_AT_location";
1811 case DW_AT_name: return "DW_AT_name";
1812 case DW_AT_ordering: return "DW_AT_ordering";
1813 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1814 case DW_AT_byte_size: return "DW_AT_byte_size";
1815 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1816 case DW_AT_bit_size: return "DW_AT_bit_size";
1817 case DW_AT_element_list: return "DW_AT_element_list";
1818 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1819 case DW_AT_low_pc: return "DW_AT_low_pc";
1820 case DW_AT_high_pc: return "DW_AT_high_pc";
1821 case DW_AT_language: return "DW_AT_language";
1822 case DW_AT_member: return "DW_AT_member";
1823 case DW_AT_discr: return "DW_AT_discr";
1824 case DW_AT_discr_value: return "DW_AT_discr_value";
1825 case DW_AT_visibility: return "DW_AT_visibility";
1826 case DW_AT_import: return "DW_AT_import";
1827 case DW_AT_string_length: return "DW_AT_string_length";
1828 case DW_AT_common_reference: return "DW_AT_common_reference";
1829 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1830 case DW_AT_const_value: return "DW_AT_const_value";
1831 case DW_AT_containing_type: return "DW_AT_containing_type";
1832 case DW_AT_default_value: return "DW_AT_default_value";
1833 case DW_AT_inline: return "DW_AT_inline";
1834 case DW_AT_is_optional: return "DW_AT_is_optional";
1835 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1836 case DW_AT_producer: return "DW_AT_producer";
1837 case DW_AT_prototyped: return "DW_AT_prototyped";
1838 case DW_AT_return_addr: return "DW_AT_return_addr";
1839 case DW_AT_start_scope: return "DW_AT_start_scope";
1840 case DW_AT_stride_size: return "DW_AT_stride_size";
1841 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1842 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1843 case DW_AT_accessibility: return "DW_AT_accessibility";
1844 case DW_AT_address_class: return "DW_AT_address_class";
1845 case DW_AT_artificial: return "DW_AT_artificial";
1846 case DW_AT_base_types: return "DW_AT_base_types";
1847 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1848 case DW_AT_count: return "DW_AT_count";
1849 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1850 case DW_AT_decl_column: return "DW_AT_decl_column";
1851 case DW_AT_decl_file: return "DW_AT_decl_file";
1852 case DW_AT_decl_line: return "DW_AT_decl_line";
1853 case DW_AT_declaration: return "DW_AT_declaration";
1854 case DW_AT_discr_list: return "DW_AT_discr_list";
1855 case DW_AT_encoding: return "DW_AT_encoding";
1856 case DW_AT_external: return "DW_AT_external";
1857 case DW_AT_frame_base: return "DW_AT_frame_base";
1858 case DW_AT_friend: return "DW_AT_friend";
1859 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1860 case DW_AT_macro_info: return "DW_AT_macro_info";
1861 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1862 case DW_AT_priority: return "DW_AT_priority";
1863 case DW_AT_segment: return "DW_AT_segment";
1864 case DW_AT_specification: return "DW_AT_specification";
1865 case DW_AT_static_link: return "DW_AT_static_link";
1866 case DW_AT_type: return "DW_AT_type";
1867 case DW_AT_use_location: return "DW_AT_use_location";
1868 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1869 case DW_AT_virtuality: return "DW_AT_virtuality";
1870 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1871 /* DWARF 2.1 values. */
1872 case DW_AT_allocated: return "DW_AT_allocated";
1873 case DW_AT_associated: return "DW_AT_associated";
1874 case DW_AT_data_location: return "DW_AT_data_location";
1875 case DW_AT_stride: return "DW_AT_stride";
1876 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1877 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1878 case DW_AT_extension: return "DW_AT_extension";
1879 case DW_AT_ranges: return "DW_AT_ranges";
1880 case DW_AT_trampoline: return "DW_AT_trampoline";
1881 case DW_AT_call_column: return "DW_AT_call_column";
1882 case DW_AT_call_file: return "DW_AT_call_file";
1883 case DW_AT_call_line: return "DW_AT_call_line";
1884 case DW_AT_description: return "DW_AT_description";
1885 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1886 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1887 case DW_AT_small: return "DW_AT_small";
1888 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1889 case DW_AT_digit_count: return "DW_AT_digit_count";
1890 case DW_AT_picture_string: return "DW_AT_picture_string";
1891 case DW_AT_mutable: return "DW_AT_mutable";
1892 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1893 case DW_AT_explicit: return "DW_AT_explicit";
1894 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1895 case DW_AT_endianity: return "DW_AT_endianity";
1896 case DW_AT_elemental: return "DW_AT_elemental";
1897 case DW_AT_pure: return "DW_AT_pure";
1898 case DW_AT_recursive: return "DW_AT_recursive";
1899 /* DWARF 4 values. */
1900 case DW_AT_signature: return "DW_AT_signature";
1901 case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
1902 case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
1903 case DW_AT_const_expr: return "DW_AT_const_expr";
1904 case DW_AT_enum_class: return "DW_AT_enum_class";
1905 case DW_AT_linkage_name: return "DW_AT_linkage_name";
1907 /* HP and SGI/MIPS extensions. */
1908 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1909 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1910 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1911 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1912 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1913 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1914 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1915 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1916 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1917 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1919 /* HP Extensions. */
1920 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
1921 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1922 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1923 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1924 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1925 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1926 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1927 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1928 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1929 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1930 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1931 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1932 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1934 /* One value is shared by the MIPS and HP extensions: */
1935 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1937 /* GNU extensions. */
1938 case DW_AT_sf_names: return "DW_AT_sf_names";
1939 case DW_AT_src_info: return "DW_AT_src_info";
1940 case DW_AT_mac_info: return "DW_AT_mac_info";
1941 case DW_AT_src_coords: return "DW_AT_src_coords";
1942 case DW_AT_body_begin: return "DW_AT_body_begin";
1943 case DW_AT_body_end: return "DW_AT_body_end";
1944 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1945 case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by";
1946 case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by";
1947 case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded";
1948 case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded";
1949 case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded";
1950 case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required";
1951 case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required";
1952 case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature";
1953 case DW_AT_use_GNAT_descriptive_type: return "DW_AT_use_GNAT_descriptive_type";
1954 case DW_AT_GNAT_descriptive_type: return "DW_AT_GNAT_descriptive_type";
1955 case DW_AT_GNU_call_site_value: return "DW_AT_GNU_call_site_value";
1956 case DW_AT_GNU_call_site_data_value: return "DW_AT_GNU_call_site_data_value";
1957 case DW_AT_GNU_call_site_target: return "DW_AT_GNU_call_site_target";
1958 case DW_AT_GNU_call_site_target_clobbered: return "DW_AT_GNU_call_site_target_clobbered";
1959 case DW_AT_GNU_tail_call: return "DW_AT_GNU_tail_call";
1960 case DW_AT_GNU_all_tail_call_sites: return "DW_AT_GNU_all_tail_call_sites";
1961 case DW_AT_GNU_all_call_sites: return "DW_AT_GNU_all_call_sites";
1962 case DW_AT_GNU_all_source_call_sites: return "DW_AT_GNU_all_source_call_sites";
1963 case DW_AT_GNU_macros: return "DW_AT_GNU_macros";
1965 /* UPC extension. */
1966 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1968 /* PGI (STMicroelectronics) extensions. */
1969 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1970 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1971 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1975 static char buffer[100];
1977 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1984 static unsigned char *
1985 read_and_display_attr (unsigned long attribute,
1987 unsigned char * data,
1988 dwarf_vma cu_offset,
1989 dwarf_vma pointer_size,
1990 dwarf_vma offset_size,
1992 debug_info * debug_info_p,
1994 struct dwarf_section * section)
1997 printf (" %-18s:", get_AT_name (attribute));
1998 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1999 pointer_size, offset_size,
2000 dwarf_version, debug_info_p,
2008 /* Process the contents of a .debug_info section. If do_loc is non-zero
2009 then we are scanning for location lists and we do not want to display
2010 anything to the user. If do_types is non-zero, we are processing
2011 a .debug_types section instead of a .debug_info section. */
2014 process_debug_info (struct dwarf_section *section,
2016 enum dwarf_section_display_enum abbrev_sec,
2020 unsigned char *start = section->start;
2021 unsigned char *end = start + section->size;
2022 unsigned char *section_begin;
2024 unsigned int num_units = 0;
2026 if ((do_loc || do_debug_loc || do_debug_ranges)
2027 && num_debug_info_entries == 0
2032 /* First scan the section to get the number of comp units. */
2033 for (section_begin = start, num_units = 0; section_begin < end;
2036 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2037 will be the length. For a 64-bit DWARF section, it'll be
2038 the escape code 0xffffffff followed by an 8 byte length. */
2039 length = byte_get (section_begin, 4);
2041 if (length == 0xffffffff)
2043 length = byte_get (section_begin + 4, 8);
2044 section_begin += length + 12;
2046 else if (length >= 0xfffffff0 && length < 0xffffffff)
2048 warn (_("Reserved length value (0x%s) found in section %s\n"),
2049 dwarf_vmatoa ("x", length), section->name);
2053 section_begin += length + 4;
2055 /* Negative values are illegal, they may even cause infinite
2056 looping. This can happen if we can't accurately apply
2057 relocations to an object file. */
2058 if ((signed long) length <= 0)
2060 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2061 dwarf_vmatoa ("x", length), section->name);
2068 error (_("No comp units in %s section ?"), section->name);
2072 /* Then allocate an array to hold the information. */
2073 debug_information = (debug_info *) cmalloc (num_units,
2074 sizeof (* debug_information));
2075 if (debug_information == NULL)
2077 error (_("Not enough memory for a debug info array of %u entries"),
2085 if (dwarf_start_die == 0)
2086 printf (_("Contents of the %s section:\n\n"), section->name);
2088 load_debug_section (str, file);
2091 load_debug_section (abbrev_sec, file);
2092 if (debug_displays [abbrev_sec].section.start == NULL)
2094 warn (_("Unable to locate %s section!\n"),
2095 debug_displays [abbrev_sec].section.name);
2099 for (section_begin = start, unit = 0; start < end; unit++)
2101 DWARF2_Internal_CompUnit compunit;
2102 unsigned char *hdrptr;
2103 unsigned char *tags;
2104 int level, last_level, saved_level;
2105 dwarf_vma cu_offset;
2107 int initial_length_size;
2108 unsigned char signature[8] = { 0 };
2109 dwarf_vma type_offset = 0;
2113 compunit.cu_length = byte_get (hdrptr, 4);
2116 if (compunit.cu_length == 0xffffffff)
2118 compunit.cu_length = byte_get (hdrptr, 8);
2121 initial_length_size = 12;
2126 initial_length_size = 4;
2129 compunit.cu_version = byte_get (hdrptr, 2);
2132 cu_offset = start - section_begin;
2134 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2135 hdrptr += offset_size;
2137 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2144 for (i = 0; i < 8; i++)
2146 signature[i] = byte_get (hdrptr, 1);
2150 type_offset = byte_get (hdrptr, offset_size);
2151 hdrptr += offset_size;
2154 if ((do_loc || do_debug_loc || do_debug_ranges)
2155 && num_debug_info_entries == 0
2158 debug_information [unit].cu_offset = cu_offset;
2159 debug_information [unit].pointer_size
2160 = compunit.cu_pointer_size;
2161 debug_information [unit].offset_size = offset_size;
2162 debug_information [unit].dwarf_version = compunit.cu_version;
2163 debug_information [unit].base_address = 0;
2164 debug_information [unit].loc_offsets = NULL;
2165 debug_information [unit].have_frame_base = NULL;
2166 debug_information [unit].max_loc_offsets = 0;
2167 debug_information [unit].num_loc_offsets = 0;
2168 debug_information [unit].range_lists = NULL;
2169 debug_information [unit].max_range_lists= 0;
2170 debug_information [unit].num_range_lists = 0;
2173 if (!do_loc && dwarf_start_die == 0)
2175 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2176 dwarf_vmatoa ("x", cu_offset));
2177 printf (_(" Length: 0x%s (%s)\n"),
2178 dwarf_vmatoa ("x", compunit.cu_length),
2179 offset_size == 8 ? "64-bit" : "32-bit");
2180 printf (_(" Version: %d\n"), compunit.cu_version);
2181 printf (_(" Abbrev Offset: %s\n"),
2182 dwarf_vmatoa ("d", compunit.cu_abbrev_offset));
2183 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2187 printf (_(" Signature: "));
2188 for (i = 0; i < 8; i++)
2189 printf ("%02x", signature[i]);
2191 printf (_(" Type Offset: 0x%s\n"),
2192 dwarf_vmatoa ("x", type_offset));
2196 if (cu_offset + compunit.cu_length + initial_length_size
2199 warn (_("Debug info is corrupted, length of CU at %s"
2200 " extends beyond end of section (length = %s)\n"),
2201 dwarf_vmatoa ("x", cu_offset),
2202 dwarf_vmatoa ("x", compunit.cu_length));
2206 start += compunit.cu_length + initial_length_size;
2208 if (compunit.cu_version != 2
2209 && compunit.cu_version != 3
2210 && compunit.cu_version != 4)
2212 warn (_("CU at offset %s contains corrupt or "
2213 "unsupported version number: %d.\n"),
2214 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2220 /* Process the abbrevs used by this compilation unit. DWARF
2221 sections under Mach-O have non-zero addresses. */
2222 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2223 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2224 (unsigned long) compunit.cu_abbrev_offset,
2225 (unsigned long) debug_displays [abbrev_sec].section.size);
2227 process_abbrev_section
2228 ((unsigned char *) debug_displays [abbrev_sec].section.start
2229 + compunit.cu_abbrev_offset,
2230 (unsigned char *) debug_displays [abbrev_sec].section.start
2231 + debug_displays [abbrev_sec].section.size);
2236 while (tags < start)
2238 unsigned int bytes_read;
2239 unsigned long abbrev_number;
2240 unsigned long die_offset;
2241 abbrev_entry *entry;
2243 int do_printing = 1;
2245 die_offset = tags - section_begin;
2247 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2250 /* A null DIE marks the end of a list of siblings or it may also be
2251 a section padding. */
2252 if (abbrev_number == 0)
2254 /* Check if it can be a section padding for the last CU. */
2255 if (level == 0 && start == end)
2259 for (chk = tags; chk < start; chk++)
2269 static unsigned num_bogus_warns = 0;
2271 if (num_bogus_warns < 3)
2273 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2276 if (num_bogus_warns == 3)
2277 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2280 if (dwarf_start_die != 0 && level < saved_level)
2287 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2291 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2292 saved_level = level;
2293 do_printing = (dwarf_cutoff_level == -1
2294 || level < dwarf_cutoff_level);
2296 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2297 level, die_offset, abbrev_number);
2298 else if (dwarf_cutoff_level == -1
2299 || last_level < dwarf_cutoff_level)
2300 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2305 /* Scan through the abbreviation list until we reach the
2307 for (entry = first_abbrev;
2308 entry && entry->entry != abbrev_number;
2309 entry = entry->next)
2314 if (!do_loc && do_printing)
2319 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2320 die_offset, abbrev_number);
2324 if (!do_loc && do_printing)
2325 printf (" (%s)\n", get_TAG_name (entry->tag));
2330 need_base_address = 0;
2332 case DW_TAG_compile_unit:
2333 need_base_address = 1;
2335 case DW_TAG_entry_point:
2336 case DW_TAG_subprogram:
2337 need_base_address = 0;
2338 /* Assuming that there is no DW_AT_frame_base. */
2339 have_frame_base = 0;
2343 for (attr = entry->first_attr; attr; attr = attr->next)
2347 if (! do_loc && do_printing)
2348 /* Show the offset from where the tag was extracted. */
2349 printf (" <%lx>", (unsigned long)(tags - section_begin));
2351 arg = debug_information;
2352 if (debug_information)
2355 tags = read_and_display_attr (attr->attribute,
2358 compunit.cu_pointer_size,
2360 compunit.cu_version,
2362 do_loc || ! do_printing, section);
2365 if (entry->children)
2370 /* Set num_debug_info_entries here so that it can be used to check if
2371 we need to process .debug_loc and .debug_ranges sections. */
2372 if ((do_loc || do_debug_loc || do_debug_ranges)
2373 && num_debug_info_entries == 0
2375 num_debug_info_entries = num_units;
2383 /* Locate and scan the .debug_info section in the file and record the pointer
2384 sizes and offsets for the compilation units in it. Usually an executable
2385 will have just one pointer size, but this is not guaranteed, and so we try
2386 not to make any assumptions. Returns zero upon failure, or the number of
2387 compilation units upon success. */
2390 load_debug_info (void * file)
2392 /* Reset the last pointer size so that we can issue correct error
2393 messages if we are displaying the contents of more than one section. */
2394 last_pointer_size = 0;
2395 warned_about_missing_comp_units = FALSE;
2397 /* If we have already tried and failed to load the .debug_info
2398 section then do not bother to repear the task. */
2399 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2402 /* If we already have the information there is nothing else to do. */
2403 if (num_debug_info_entries > 0)
2404 return num_debug_info_entries;
2406 if (load_debug_section (info, file)
2407 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2408 return num_debug_info_entries;
2410 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2415 display_debug_lines_raw (struct dwarf_section *section,
2416 unsigned char *data,
2419 unsigned char *start = section->start;
2421 printf (_("Raw dump of debug contents of section %s:\n\n"),
2426 DWARF2_Internal_LineInfo linfo;
2427 unsigned char *standard_opcodes;
2428 unsigned char *end_of_sequence;
2429 unsigned char *hdrptr;
2430 unsigned long hdroff;
2431 int initial_length_size;
2436 hdroff = hdrptr - start;
2438 /* Check the length of the block. */
2439 linfo.li_length = byte_get (hdrptr, 4);
2442 if (linfo.li_length == 0xffffffff)
2444 /* This section is 64-bit DWARF 3. */
2445 linfo.li_length = byte_get (hdrptr, 8);
2448 initial_length_size = 12;
2453 initial_length_size = 4;
2456 if (linfo.li_length + initial_length_size > section->size)
2459 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2464 /* Check its version number. */
2465 linfo.li_version = byte_get (hdrptr, 2);
2467 if (linfo.li_version != 2
2468 && linfo.li_version != 3
2469 && linfo.li_version != 4)
2471 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2475 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2476 hdrptr += offset_size;
2477 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2479 if (linfo.li_version >= 4)
2481 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2483 if (linfo.li_max_ops_per_insn == 0)
2485 warn (_("Invalid maximum operations per insn.\n"));
2490 linfo.li_max_ops_per_insn = 1;
2491 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2493 linfo.li_line_base = byte_get (hdrptr, 1);
2495 linfo.li_line_range = byte_get (hdrptr, 1);
2497 linfo.li_opcode_base = byte_get (hdrptr, 1);
2500 /* Sign extend the line base field. */
2501 linfo.li_line_base <<= 24;
2502 linfo.li_line_base >>= 24;
2504 printf (_(" Offset: 0x%lx\n"), hdroff);
2505 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2506 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2507 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2508 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2509 if (linfo.li_version >= 4)
2510 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2511 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2512 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2513 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2514 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2516 end_of_sequence = data + linfo.li_length + initial_length_size;
2518 reset_state_machine (linfo.li_default_is_stmt);
2520 /* Display the contents of the Opcodes table. */
2521 standard_opcodes = hdrptr;
2523 printf (_("\n Opcodes:\n"));
2525 for (i = 1; i < linfo.li_opcode_base; i++)
2526 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2528 /* Display the contents of the Directory table. */
2529 data = standard_opcodes + linfo.li_opcode_base - 1;
2532 printf (_("\n The Directory Table is empty.\n"));
2535 printf (_("\n The Directory Table:\n"));
2539 printf (" %s\n", data);
2541 data += strlen ((char *) data) + 1;
2545 /* Skip the NUL at the end of the table. */
2548 /* Display the contents of the File Name table. */
2550 printf (_("\n The File Name Table is empty.\n"));
2553 printf (_("\n The File Name Table:\n"));
2554 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2558 unsigned char *name;
2559 unsigned int bytes_read;
2561 printf (" %d\t", ++state_machine_regs.last_file_entry);
2564 data += strlen ((char *) data) + 1;
2567 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2570 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2573 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2575 printf ("%s\n", name);
2579 /* Skip the NUL at the end of the table. */
2582 /* Now display the statements. */
2583 printf (_("\n Line Number Statements:\n"));
2585 while (data < end_of_sequence)
2587 unsigned char op_code;
2588 dwarf_signed_vma adv;
2590 unsigned int bytes_read;
2594 if (op_code >= linfo.li_opcode_base)
2596 op_code -= linfo.li_opcode_base;
2597 uladv = (op_code / linfo.li_line_range);
2598 if (linfo.li_max_ops_per_insn == 1)
2600 uladv *= linfo.li_min_insn_length;
2601 state_machine_regs.address += uladv;
2602 printf (_(" Special opcode %d: "
2603 "advance Address by %s to 0x%s"),
2604 op_code, dwarf_vmatoa ("u", uladv),
2605 dwarf_vmatoa ("x", state_machine_regs.address));
2609 state_machine_regs.address
2610 += ((state_machine_regs.op_index + uladv)
2611 / linfo.li_max_ops_per_insn)
2612 * linfo.li_min_insn_length;
2613 state_machine_regs.op_index
2614 = (state_machine_regs.op_index + uladv)
2615 % linfo.li_max_ops_per_insn;
2616 printf (_(" Special opcode %d: "
2617 "advance Address by %s to 0x%s[%d]"),
2618 op_code, dwarf_vmatoa ("u", uladv),
2619 dwarf_vmatoa ("x", state_machine_regs.address),
2620 state_machine_regs.op_index);
2622 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2623 state_machine_regs.line += adv;
2624 printf (_(" and Line by %s to %d\n"),
2625 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2627 else switch (op_code)
2629 case DW_LNS_extended_op:
2630 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2634 printf (_(" Copy\n"));
2637 case DW_LNS_advance_pc:
2638 uladv = read_leb128 (data, & bytes_read, 0);
2640 if (linfo.li_max_ops_per_insn == 1)
2642 uladv *= linfo.li_min_insn_length;
2643 state_machine_regs.address += uladv;
2644 printf (_(" Advance PC by %s to 0x%s\n"),
2645 dwarf_vmatoa ("u", uladv),
2646 dwarf_vmatoa ("x", state_machine_regs.address));
2650 state_machine_regs.address
2651 += ((state_machine_regs.op_index + uladv)
2652 / linfo.li_max_ops_per_insn)
2653 * linfo.li_min_insn_length;
2654 state_machine_regs.op_index
2655 = (state_machine_regs.op_index + uladv)
2656 % linfo.li_max_ops_per_insn;
2657 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2658 dwarf_vmatoa ("u", uladv),
2659 dwarf_vmatoa ("x", state_machine_regs.address),
2660 state_machine_regs.op_index);
2664 case DW_LNS_advance_line:
2665 adv = read_sleb128 (data, & bytes_read);
2667 state_machine_regs.line += adv;
2668 printf (_(" Advance Line by %s to %d\n"),
2669 dwarf_vmatoa ("d", adv),
2670 state_machine_regs.line);
2673 case DW_LNS_set_file:
2674 adv = read_leb128 (data, & bytes_read, 0);
2676 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2677 dwarf_vmatoa ("d", adv));
2678 state_machine_regs.file = adv;
2681 case DW_LNS_set_column:
2682 uladv = read_leb128 (data, & bytes_read, 0);
2684 printf (_(" Set column to %s\n"),
2685 dwarf_vmatoa ("u", uladv));
2686 state_machine_regs.column = uladv;
2689 case DW_LNS_negate_stmt:
2690 adv = state_machine_regs.is_stmt;
2692 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2693 state_machine_regs.is_stmt = adv;
2696 case DW_LNS_set_basic_block:
2697 printf (_(" Set basic block\n"));
2698 state_machine_regs.basic_block = 1;
2701 case DW_LNS_const_add_pc:
2702 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2703 if (linfo.li_max_ops_per_insn)
2705 uladv *= linfo.li_min_insn_length;
2706 state_machine_regs.address += uladv;
2707 printf (_(" Advance PC by constant %s to 0x%s\n"),
2708 dwarf_vmatoa ("u", uladv),
2709 dwarf_vmatoa ("x", state_machine_regs.address));
2713 state_machine_regs.address
2714 += ((state_machine_regs.op_index + uladv)
2715 / linfo.li_max_ops_per_insn)
2716 * linfo.li_min_insn_length;
2717 state_machine_regs.op_index
2718 = (state_machine_regs.op_index + uladv)
2719 % linfo.li_max_ops_per_insn;
2720 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2721 dwarf_vmatoa ("u", uladv),
2722 dwarf_vmatoa ("x", state_machine_regs.address),
2723 state_machine_regs.op_index);
2727 case DW_LNS_fixed_advance_pc:
2728 uladv = byte_get (data, 2);
2730 state_machine_regs.address += uladv;
2731 state_machine_regs.op_index = 0;
2732 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2733 dwarf_vmatoa ("u", uladv),
2734 dwarf_vmatoa ("x", state_machine_regs.address));
2737 case DW_LNS_set_prologue_end:
2738 printf (_(" Set prologue_end to true\n"));
2741 case DW_LNS_set_epilogue_begin:
2742 printf (_(" Set epilogue_begin to true\n"));
2745 case DW_LNS_set_isa:
2746 uladv = read_leb128 (data, & bytes_read, 0);
2748 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2752 printf (_(" Unknown opcode %d with operands: "), op_code);
2754 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2756 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2758 i == 1 ? "" : ", ");
2773 unsigned char *name;
2774 unsigned int directory_index;
2775 unsigned int modification_date;
2776 unsigned int length;
2779 /* Output a decoded representation of the .debug_line section. */
2782 display_debug_lines_decoded (struct dwarf_section *section,
2783 unsigned char *data,
2786 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2791 /* This loop amounts to one iteration per compilation unit. */
2792 DWARF2_Internal_LineInfo linfo;
2793 unsigned char *standard_opcodes;
2794 unsigned char *end_of_sequence;
2795 unsigned char *hdrptr;
2796 int initial_length_size;
2799 File_Entry *file_table = NULL;
2800 unsigned char **directory_table = NULL;
2804 /* Extract information from the Line Number Program Header.
2805 (section 6.2.4 in the Dwarf3 doc). */
2807 /* Get the length of this CU's line number information block. */
2808 linfo.li_length = byte_get (hdrptr, 4);
2811 if (linfo.li_length == 0xffffffff)
2813 /* This section is 64-bit DWARF 3. */
2814 linfo.li_length = byte_get (hdrptr, 8);
2817 initial_length_size = 12;
2822 initial_length_size = 4;
2825 if (linfo.li_length + initial_length_size > section->size)
2827 warn (_("The line info appears to be corrupt - "
2828 "the section is too small\n"));
2832 /* Get this CU's Line Number Block version number. */
2833 linfo.li_version = byte_get (hdrptr, 2);
2835 if (linfo.li_version != 2
2836 && linfo.li_version != 3
2837 && linfo.li_version != 4)
2839 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2844 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2845 hdrptr += offset_size;
2846 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2848 if (linfo.li_version >= 4)
2850 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2852 if (linfo.li_max_ops_per_insn == 0)
2854 warn (_("Invalid maximum operations per insn.\n"));
2859 linfo.li_max_ops_per_insn = 1;
2860 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2862 linfo.li_line_base = byte_get (hdrptr, 1);
2864 linfo.li_line_range = byte_get (hdrptr, 1);
2866 linfo.li_opcode_base = byte_get (hdrptr, 1);
2869 /* Sign extend the line base field. */
2870 linfo.li_line_base <<= 24;
2871 linfo.li_line_base >>= 24;
2873 /* Find the end of this CU's Line Number Information Block. */
2874 end_of_sequence = data + linfo.li_length + initial_length_size;
2876 reset_state_machine (linfo.li_default_is_stmt);
2878 /* Save a pointer to the contents of the Opcodes table. */
2879 standard_opcodes = hdrptr;
2881 /* Traverse the Directory table just to count entries. */
2882 data = standard_opcodes + linfo.li_opcode_base - 1;
2885 unsigned int n_directories = 0;
2886 unsigned char *ptr_directory_table = data;
2890 data += strlen ((char *) data) + 1;
2894 /* Go through the directory table again to save the directories. */
2895 directory_table = (unsigned char **)
2896 xmalloc (n_directories * sizeof (unsigned char *));
2899 while (*ptr_directory_table != 0)
2901 directory_table[i] = ptr_directory_table;
2902 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2906 /* Skip the NUL at the end of the table. */
2909 /* Traverse the File Name table just to count the entries. */
2912 unsigned int n_files = 0;
2913 unsigned char *ptr_file_name_table = data;
2917 unsigned int bytes_read;
2919 /* Skip Name, directory index, last modification time and length
2921 data += strlen ((char *) data) + 1;
2922 read_leb128 (data, & bytes_read, 0);
2924 read_leb128 (data, & bytes_read, 0);
2926 read_leb128 (data, & bytes_read, 0);
2932 /* Go through the file table again to save the strings. */
2933 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2936 while (*ptr_file_name_table != 0)
2938 unsigned int bytes_read;
2940 file_table[i].name = ptr_file_name_table;
2941 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2943 /* We are not interested in directory, time or size. */
2944 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2946 ptr_file_name_table += bytes_read;
2947 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2949 ptr_file_name_table += bytes_read;
2950 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2951 ptr_file_name_table += bytes_read;
2956 /* Print the Compilation Unit's name and a header. */
2957 if (directory_table == NULL)
2959 printf (_("CU: %s:\n"), file_table[0].name);
2960 printf (_("File name Line number Starting address\n"));
2964 unsigned int ix = file_table[0].directory_index;
2965 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
2966 if (do_wide || strlen (directory) < 76)
2967 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
2969 printf ("%s:\n", file_table[0].name);
2971 printf (_("File name Line number Starting address\n"));
2975 /* Skip the NUL at the end of the table. */
2978 /* This loop iterates through the Dwarf Line Number Program. */
2979 while (data < end_of_sequence)
2981 unsigned char op_code;
2983 unsigned long int uladv;
2984 unsigned int bytes_read;
2985 int is_special_opcode = 0;
2989 if (op_code >= linfo.li_opcode_base)
2991 op_code -= linfo.li_opcode_base;
2992 uladv = (op_code / linfo.li_line_range);
2993 if (linfo.li_max_ops_per_insn == 1)
2995 uladv *= linfo.li_min_insn_length;
2996 state_machine_regs.address += uladv;
3000 state_machine_regs.address
3001 += ((state_machine_regs.op_index + uladv)
3002 / linfo.li_max_ops_per_insn)
3003 * linfo.li_min_insn_length;
3004 state_machine_regs.op_index
3005 = (state_machine_regs.op_index + uladv)
3006 % linfo.li_max_ops_per_insn;
3009 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3010 state_machine_regs.line += adv;
3011 is_special_opcode = 1;
3013 else switch (op_code)
3015 case DW_LNS_extended_op:
3017 unsigned int ext_op_code_len;
3018 unsigned char ext_op_code;
3019 unsigned char *op_code_data = data;
3021 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
3022 op_code_data += bytes_read;
3024 if (ext_op_code_len == 0)
3026 warn (_("badly formed extended line op encountered!\n"));
3029 ext_op_code_len += bytes_read;
3030 ext_op_code = *op_code_data++;
3032 switch (ext_op_code)
3034 case DW_LNE_end_sequence:
3035 reset_state_machine (linfo.li_default_is_stmt);
3037 case DW_LNE_set_address:
3038 state_machine_regs.address =
3039 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
3040 state_machine_regs.op_index = 0;
3042 case DW_LNE_define_file:
3044 unsigned int dir_index = 0;
3046 ++state_machine_regs.last_file_entry;
3047 op_code_data += strlen ((char *) op_code_data) + 1;
3048 dir_index = read_leb128 (op_code_data, & bytes_read, 0);
3049 op_code_data += bytes_read;
3050 read_leb128 (op_code_data, & bytes_read, 0);
3051 op_code_data += bytes_read;
3052 read_leb128 (op_code_data, & bytes_read, 0);
3054 printf ("%s:\n", directory_table[dir_index]);
3058 printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
3061 data += ext_op_code_len;
3067 case DW_LNS_advance_pc:
3068 uladv = read_leb128 (data, & bytes_read, 0);
3070 if (linfo.li_max_ops_per_insn == 1)
3072 uladv *= linfo.li_min_insn_length;
3073 state_machine_regs.address += uladv;
3077 state_machine_regs.address
3078 += ((state_machine_regs.op_index + uladv)
3079 / linfo.li_max_ops_per_insn)
3080 * linfo.li_min_insn_length;
3081 state_machine_regs.op_index
3082 = (state_machine_regs.op_index + uladv)
3083 % linfo.li_max_ops_per_insn;
3087 case DW_LNS_advance_line:
3088 adv = read_sleb128 (data, & bytes_read);
3090 state_machine_regs.line += adv;
3093 case DW_LNS_set_file:
3094 adv = read_leb128 (data, & bytes_read, 0);
3096 state_machine_regs.file = adv;
3097 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3099 /* If directory index is 0, that means current directory. */
3100 printf ("\n./%s:[++]\n",
3101 file_table[state_machine_regs.file - 1].name);
3105 /* The directory index starts counting at 1. */
3106 printf ("\n%s/%s:\n",
3107 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3108 file_table[state_machine_regs.file - 1].name);
3112 case DW_LNS_set_column:
3113 uladv = read_leb128 (data, & bytes_read, 0);
3115 state_machine_regs.column = uladv;
3118 case DW_LNS_negate_stmt:
3119 adv = state_machine_regs.is_stmt;
3121 state_machine_regs.is_stmt = adv;
3124 case DW_LNS_set_basic_block:
3125 state_machine_regs.basic_block = 1;
3128 case DW_LNS_const_add_pc:
3129 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3130 if (linfo.li_max_ops_per_insn == 1)
3132 uladv *= linfo.li_min_insn_length;
3133 state_machine_regs.address += uladv;
3137 state_machine_regs.address
3138 += ((state_machine_regs.op_index + uladv)
3139 / linfo.li_max_ops_per_insn)
3140 * linfo.li_min_insn_length;
3141 state_machine_regs.op_index
3142 = (state_machine_regs.op_index + uladv)
3143 % linfo.li_max_ops_per_insn;
3147 case DW_LNS_fixed_advance_pc:
3148 uladv = byte_get (data, 2);
3150 state_machine_regs.address += uladv;
3151 state_machine_regs.op_index = 0;
3154 case DW_LNS_set_prologue_end:
3157 case DW_LNS_set_epilogue_begin:
3160 case DW_LNS_set_isa:
3161 uladv = read_leb128 (data, & bytes_read, 0);
3163 printf (_(" Set ISA to %lu\n"), uladv);
3167 printf (_(" Unknown opcode %d with operands: "), op_code);
3169 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3171 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3173 i == 1 ? "" : ", ");
3180 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3181 to the DWARF address/line matrix. */
3182 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3183 || (op_code == DW_LNS_copy))
3185 const unsigned int MAX_FILENAME_LENGTH = 35;
3186 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3187 char *newFileName = NULL;
3188 size_t fileNameLength = strlen (fileName);
3190 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3192 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3193 /* Truncate file name */
3194 strncpy (newFileName,
3195 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3196 MAX_FILENAME_LENGTH + 1);
3200 newFileName = (char *) xmalloc (fileNameLength + 1);
3201 strncpy (newFileName, fileName, fileNameLength + 1);
3204 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3206 if (linfo.li_max_ops_per_insn == 1)
3207 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3208 newFileName, state_machine_regs.line,
3209 state_machine_regs.address);
3211 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3212 newFileName, state_machine_regs.line,
3213 state_machine_regs.address,
3214 state_machine_regs.op_index);
3218 if (linfo.li_max_ops_per_insn == 1)
3219 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3220 newFileName, state_machine_regs.line,
3221 state_machine_regs.address);
3223 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3224 newFileName, state_machine_regs.line,
3225 state_machine_regs.address,
3226 state_machine_regs.op_index);
3229 if (op_code == DW_LNE_end_sequence)
3237 free (directory_table);
3238 directory_table = NULL;
3246 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3248 unsigned char *data = section->start;
3249 unsigned char *end = data + section->size;
3251 int retValDecoded = 1;
3253 if (do_debug_lines == 0)
3254 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3256 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3257 retValRaw = display_debug_lines_raw (section, data, end);
3259 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3260 retValDecoded = display_debug_lines_decoded (section, data, end);
3262 if (!retValRaw || !retValDecoded)
3269 find_debug_info_for_offset (unsigned long offset)
3273 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3276 for (i = 0; i < num_debug_info_entries; i++)
3277 if (debug_information[i].cu_offset == offset)
3278 return debug_information + i;
3284 display_debug_pubnames (struct dwarf_section *section,
3285 void *file ATTRIBUTE_UNUSED)
3287 DWARF2_Internal_PubNames names;
3288 unsigned char *start = section->start;
3289 unsigned char *end = start + section->size;
3291 /* It does not matter if this load fails,
3292 we test for that later on. */
3293 load_debug_info (file);
3295 printf (_("Contents of the %s section:\n\n"), section->name);
3299 unsigned char *data;
3300 unsigned long offset;
3301 int offset_size, initial_length_size;
3305 names.pn_length = byte_get (data, 4);
3307 if (names.pn_length == 0xffffffff)
3309 names.pn_length = byte_get (data, 8);
3312 initial_length_size = 12;
3317 initial_length_size = 4;
3320 names.pn_version = byte_get (data, 2);
3323 names.pn_offset = byte_get (data, offset_size);
3324 data += offset_size;
3326 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3327 && num_debug_info_entries > 0
3328 && find_debug_info_for_offset (names.pn_offset) == NULL)
3329 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3330 (unsigned long) names.pn_offset, section->name);
3332 names.pn_size = byte_get (data, offset_size);
3333 data += offset_size;
3335 start += names.pn_length + initial_length_size;
3337 if (names.pn_version != 2 && names.pn_version != 3)
3339 static int warned = 0;
3343 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3350 printf (_(" Length: %ld\n"),
3351 (long) names.pn_length);
3352 printf (_(" Version: %d\n"),
3354 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3355 (unsigned long) names.pn_offset);
3356 printf (_(" Size of area in .debug_info section: %ld\n"),
3357 (long) names.pn_size);
3359 printf (_("\n Offset\tName\n"));
3363 offset = byte_get (data, offset_size);
3367 data += offset_size;
3368 printf (" %-6lx\t%s\n", offset, data);
3369 data += strlen ((char *) data) + 1;
3372 while (offset != 0);
3380 display_debug_macinfo (struct dwarf_section *section,
3381 void *file ATTRIBUTE_UNUSED)
3383 unsigned char *start = section->start;
3384 unsigned char *end = start + section->size;
3385 unsigned char *curr = start;
3386 unsigned int bytes_read;
3387 enum dwarf_macinfo_record_type op;
3389 printf (_("Contents of the %s section:\n\n"), section->name);
3393 unsigned int lineno;
3396 op = (enum dwarf_macinfo_record_type) *curr;
3401 case DW_MACINFO_start_file:
3403 unsigned int filenum;
3405 lineno = read_leb128 (curr, & bytes_read, 0);
3407 filenum = read_leb128 (curr, & bytes_read, 0);
3410 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3415 case DW_MACINFO_end_file:
3416 printf (_(" DW_MACINFO_end_file\n"));
3419 case DW_MACINFO_define:
3420 lineno = read_leb128 (curr, & bytes_read, 0);
3422 string = (char *) curr;
3423 curr += strlen (string) + 1;
3424 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3428 case DW_MACINFO_undef:
3429 lineno = read_leb128 (curr, & bytes_read, 0);
3431 string = (char *) curr;
3432 curr += strlen (string) + 1;
3433 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3437 case DW_MACINFO_vendor_ext:
3439 unsigned int constant;
3441 constant = read_leb128 (curr, & bytes_read, 0);
3443 string = (char *) curr;
3444 curr += strlen (string) + 1;
3445 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3455 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3456 filename and dirname corresponding to file name table entry with index
3457 FILEIDX. Return NULL on failure. */
3459 static unsigned char *
3460 get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
3461 unsigned char **dir_name)
3463 struct dwarf_section *section = &debug_displays [line].section;
3464 unsigned char *hdrptr, *dirtable, *file_name;
3465 unsigned int offset_size, initial_length_size;
3466 unsigned int version, opcode_base, bytes_read;
3467 dwarf_vma length, diridx;
3470 if (section->start == NULL
3471 || line_offset >= section->size
3475 hdrptr = section->start + line_offset;
3476 length = byte_get (hdrptr, 4);
3478 if (length == 0xffffffff)
3480 /* This section is 64-bit DWARF 3. */
3481 length = byte_get (hdrptr, 8);
3484 initial_length_size = 12;
3489 initial_length_size = 4;
3491 if (length + initial_length_size > section->size)
3493 version = byte_get (hdrptr, 2);
3495 if (version != 2 && version != 3 && version != 4)
3497 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3499 hdrptr++; /* Skip max_ops_per_insn. */
3500 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3501 opcode_base = byte_get (hdrptr, 1);
3502 if (opcode_base == 0)
3505 hdrptr += opcode_base - 1;
3507 /* Skip over dirname table. */
3508 while (*hdrptr != '\0')
3509 hdrptr += strlen ((char *) hdrptr) + 1;
3510 hdrptr++; /* Skip the NUL at the end of the table. */
3511 /* Now skip over preceding filename table entries. */
3512 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3514 hdrptr += strlen ((char *) hdrptr) + 1;
3515 read_leb128 (hdrptr, &bytes_read, 0);
3516 hdrptr += bytes_read;
3517 read_leb128 (hdrptr, &bytes_read, 0);
3518 hdrptr += bytes_read;
3519 read_leb128 (hdrptr, &bytes_read, 0);
3520 hdrptr += bytes_read;
3522 if (*hdrptr == '\0')
3525 hdrptr += strlen ((char *) hdrptr) + 1;
3526 diridx = read_leb128 (hdrptr, &bytes_read, 0);
3529 for (; *dirtable != '\0' && diridx > 1; diridx--)
3530 dirtable += strlen ((char *) dirtable) + 1;
3531 if (*dirtable == '\0')
3533 *dir_name = dirtable;
3538 display_debug_macro (struct dwarf_section *section,
3541 unsigned char *start = section->start;
3542 unsigned char *end = start + section->size;
3543 unsigned char *curr = start;
3544 unsigned char *extended_op_buf[256];
3545 unsigned int bytes_read;
3547 load_debug_section (str, file);
3548 load_debug_section (line, file);
3550 printf (_("Contents of the %s section:\n\n"), section->name);
3554 unsigned int lineno, version, flags;
3555 unsigned int offset_size = 4;
3557 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3558 unsigned char **extended_ops = NULL;
3560 version = byte_get (curr, 2);
3565 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3570 flags = byte_get (curr++, 1);
3573 printf (_(" Offset: 0x%lx\n"),
3574 (unsigned long) sec_offset);
3575 printf (_(" Version: %d\n"), version);
3576 printf (_(" Offset size: %d\n"), offset_size);
3579 line_offset = byte_get (curr, offset_size);
3580 curr += offset_size;
3581 printf (_(" Offset into .debug_line: 0x%lx\n"),
3582 (unsigned long) line_offset);
3586 unsigned int i, count = byte_get (curr++, 1), op;
3588 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3589 extended_ops = extended_op_buf;
3592 printf (_(" Extension opcode arguments:\n"));
3593 for (i = 0; i < count; i++)
3595 op = byte_get (curr++, 1);
3596 extended_ops[op] = curr;
3597 nargs = read_leb128 (curr, &bytes_read, 0);
3600 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3603 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3604 for (n = 0; n < nargs; n++)
3606 unsigned int form = byte_get (curr++, 1);
3607 printf ("%s%s", get_FORM_name (form),
3608 n == nargs - 1 ? "\n" : ", ");
3618 case DW_FORM_block1:
3619 case DW_FORM_block2:
3620 case DW_FORM_block4:
3622 case DW_FORM_string:
3624 case DW_FORM_sec_offset:
3627 error (_("Invalid extension opcode form %s\n"),
3628 get_FORM_name (form));
3644 error (_(".debug_macro section not zero terminated\n"));
3648 op = byte_get (curr++, 1);
3654 case DW_MACRO_GNU_start_file:
3656 unsigned int filenum;
3657 unsigned char *file_name = NULL, *dir_name = NULL;
3659 lineno = read_leb128 (curr, &bytes_read, 0);
3661 filenum = read_leb128 (curr, &bytes_read, 0);
3664 if ((flags & 2) == 0)
3665 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3668 = get_line_filename_and_dirname (line_offset, filenum,
3670 if (file_name == NULL)
3671 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3674 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3676 dir_name != NULL ? (const char *) dir_name : "",
3677 dir_name != NULL ? "/" : "", file_name);
3681 case DW_MACRO_GNU_end_file:
3682 printf (_(" DW_MACRO_GNU_end_file\n"));
3685 case DW_MACRO_GNU_define:
3686 lineno = read_leb128 (curr, &bytes_read, 0);
3688 string = (char *) curr;
3689 curr += strlen (string) + 1;
3690 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3694 case DW_MACRO_GNU_undef:
3695 lineno = read_leb128 (curr, &bytes_read, 0);
3697 string = (char *) curr;
3698 curr += strlen (string) + 1;
3699 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3703 case DW_MACRO_GNU_define_indirect:
3704 lineno = read_leb128 (curr, &bytes_read, 0);
3706 offset = byte_get (curr, offset_size);
3707 curr += offset_size;
3708 string = fetch_indirect_string (offset);
3709 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3713 case DW_MACRO_GNU_undef_indirect:
3714 lineno = read_leb128 (curr, &bytes_read, 0);
3716 offset = byte_get (curr, offset_size);
3717 curr += offset_size;
3718 string = fetch_indirect_string (offset);
3719 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3723 case DW_MACRO_GNU_transparent_include:
3724 offset = byte_get (curr, offset_size);
3725 curr += offset_size;
3726 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3727 (unsigned long) offset);
3731 if (extended_ops == NULL || extended_ops[op] == NULL)
3733 error (_(" Unknown macro opcode %02x seen\n"), op);
3738 /* Skip over unhandled opcodes. */
3740 unsigned char *desc = extended_ops[op];
3741 nargs = read_leb128 (desc, &bytes_read, 0);
3745 printf (_(" DW_MACRO_GNU_%02x\n"), op);
3748 printf (_(" DW_MACRO_GNU_%02x -"), op);
3749 for (n = 0; n < nargs; n++)
3752 = read_and_display_attr_value (0, byte_get (desc++, 1),
3753 curr, 0, 0, offset_size,
3754 version, NULL, 0, NULL);
3771 display_debug_abbrev (struct dwarf_section *section,
3772 void *file ATTRIBUTE_UNUSED)
3774 abbrev_entry *entry;
3775 unsigned char *start = section->start;
3776 unsigned char *end = start + section->size;
3778 printf (_("Contents of the %s section:\n\n"), section->name);
3784 start = process_abbrev_section (start, end);
3786 if (first_abbrev == NULL)
3789 printf (_(" Number TAG\n"));
3791 for (entry = first_abbrev; entry; entry = entry->next)
3795 printf (" %ld %s [%s]\n",
3797 get_TAG_name (entry->tag),
3798 entry->children ? _("has children") : _("no children"));
3800 for (attr = entry->first_attr; attr; attr = attr->next)
3801 printf (" %-18s %s\n",
3802 get_AT_name (attr->attribute),
3803 get_FORM_name (attr->form));
3813 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3815 static dwarf_vma *loc_offsets;
3818 loc_offsets_compar (const void *ap, const void *bp)
3820 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
3821 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
3823 return (a > b) - (b > a);
3827 display_debug_loc (struct dwarf_section *section, void *file)
3829 unsigned char *start = section->start;
3830 unsigned char *section_end;
3831 unsigned long bytes;
3832 unsigned char *section_begin = start;
3833 unsigned int num_loc_list = 0;
3834 unsigned long last_offset = 0;
3835 unsigned int first = 0;
3839 int seen_first_offset = 0;
3840 int locs_sorted = 1;
3841 unsigned char *next;
3842 unsigned int *array = NULL;
3844 bytes = section->size;
3845 section_end = start + bytes;
3849 printf (_("\nThe %s section is empty.\n"), section->name);
3853 if (load_debug_info (file) == 0)
3855 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3860 /* Check the order of location list in .debug_info section. If
3861 offsets of location lists are in the ascending order, we can
3862 use `debug_information' directly. */
3863 for (i = 0; i < num_debug_info_entries; i++)
3867 num = debug_information [i].num_loc_offsets;
3868 if (num > num_loc_list)
3871 /* Check if we can use `debug_information' directly. */
3872 if (locs_sorted && num != 0)
3874 if (!seen_first_offset)
3876 /* This is the first location list. */
3877 last_offset = debug_information [i].loc_offsets [0];
3879 seen_first_offset = 1;
3885 for (; j < num; j++)
3888 debug_information [i].loc_offsets [j])
3893 last_offset = debug_information [i].loc_offsets [j];
3898 if (!seen_first_offset)
3899 error (_("No location lists in .debug_info section!\n"));
3901 /* DWARF sections under Mach-O have non-zero addresses. */
3902 if (debug_information [first].num_loc_offsets > 0
3903 && debug_information [first].loc_offsets [0] != section->address)
3904 warn (_("Location lists in %s section start at 0x%s\n"),
3906 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
3909 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
3910 printf (_("Contents of the %s section:\n\n"), section->name);
3911 printf (_(" Offset Begin End Expression\n"));
3913 seen_first_offset = 0;
3914 for (i = first; i < num_debug_info_entries; i++)
3918 unsigned short length;
3919 unsigned long offset;
3920 unsigned int pointer_size;
3921 unsigned int offset_size;
3923 unsigned long cu_offset;
3924 unsigned long base_address;
3925 int need_frame_base;
3928 pointer_size = debug_information [i].pointer_size;
3929 cu_offset = debug_information [i].cu_offset;
3930 offset_size = debug_information [i].offset_size;
3931 dwarf_version = debug_information [i].dwarf_version;
3934 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
3936 loc_offsets = debug_information [i].loc_offsets;
3937 qsort (array, debug_information [i].num_loc_offsets,
3938 sizeof (*array), loc_offsets_compar);
3941 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
3943 j = locs_sorted ? k : array[k];
3945 && debug_information [i].loc_offsets [locs_sorted
3946 ? k - 1 : array [k - 1]]
3947 == debug_information [i].loc_offsets [j])
3949 has_frame_base = debug_information [i].have_frame_base [j];
3950 /* DWARF sections under Mach-O have non-zero addresses. */
3951 offset = debug_information [i].loc_offsets [j] - section->address;
3952 next = section_begin + offset;
3953 base_address = debug_information [i].base_address;
3955 if (!seen_first_offset)
3956 seen_first_offset = 1;
3960 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3961 (unsigned long) (start - section_begin),
3962 (unsigned long) (next - section_begin));
3963 else if (start > next)
3964 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3965 (unsigned long) (start - section_begin),
3966 (unsigned long) (next - section_begin));
3970 if (offset >= bytes)
3972 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3979 if (start + 2 * pointer_size > section_end)
3981 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3986 /* Note: we use sign extension here in order to be sure that
3987 we can detect the -1 escape value. Sign extension into the
3988 top 32 bits of a 32-bit address will not affect the values
3989 that we display since we always show hex values, and always
3990 the bottom 32-bits. */
3991 begin = byte_get_signed (start, pointer_size);
3992 start += pointer_size;
3993 end = byte_get_signed (start, pointer_size);
3994 start += pointer_size;
3996 printf (" %8.8lx ", offset);
3998 if (begin == 0 && end == 0)
4000 printf (_("<End of list>\n"));
4004 /* Check base address specifiers. */
4005 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4008 print_dwarf_vma (begin, pointer_size);
4009 print_dwarf_vma (end, pointer_size);
4010 printf (_("(base address)\n"));
4014 if (start + 2 > section_end)
4016 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4021 length = byte_get (start, 2);
4024 if (start + length > section_end)
4026 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4031 print_dwarf_vma (begin + base_address, pointer_size);
4032 print_dwarf_vma (end + base_address, pointer_size);
4035 need_frame_base = decode_location_expression (start,
4040 cu_offset, section);
4043 if (need_frame_base && !has_frame_base)
4044 printf (_(" [without DW_AT_frame_base]"));
4047 fputs (_(" (start == end)"), stdout);
4048 else if (begin > end)
4049 fputs (_(" (start > end)"), stdout);
4058 if (start < section_end)
4059 warn (_("There are %ld unused bytes at the end of section %s\n"),
4060 (long) (section_end - start), section->name);
4067 display_debug_str (struct dwarf_section *section,
4068 void *file ATTRIBUTE_UNUSED)
4070 unsigned char *start = section->start;
4071 unsigned long bytes = section->size;
4072 dwarf_vma addr = section->address;
4076 printf (_("\nThe %s section is empty.\n"), section->name);
4080 printf (_("Contents of the %s section:\n\n"), section->name);
4088 lbytes = (bytes > 16 ? 16 : bytes);
4090 printf (" 0x%8.8lx ", (unsigned long) addr);
4092 for (j = 0; j < 16; j++)
4095 printf ("%2.2x", start[j]);
4103 for (j = 0; j < lbytes; j++)
4106 if (k >= ' ' && k < 0x80)
4125 display_debug_info (struct dwarf_section *section, void *file)
4127 return process_debug_info (section, file, abbrev, 0, 0);
4131 display_debug_types (struct dwarf_section *section, void *file)
4133 return process_debug_info (section, file, abbrev, 0, 1);
4137 display_trace_info (struct dwarf_section *section, void *file)
4139 return process_debug_info (section, file, trace_abbrev, 0, 0);
4143 display_debug_aranges (struct dwarf_section *section,
4144 void *file ATTRIBUTE_UNUSED)
4146 unsigned char *start = section->start;
4147 unsigned char *end = start + section->size;
4149 printf (_("Contents of the %s section:\n\n"), section->name);
4151 /* It does not matter if this load fails,
4152 we test for that later on. */
4153 load_debug_info (file);
4157 unsigned char *hdrptr;
4158 DWARF2_Internal_ARange arange;
4159 unsigned char *addr_ranges;
4162 unsigned char address_size;
4165 int initial_length_size;
4169 arange.ar_length = byte_get (hdrptr, 4);
4172 if (arange.ar_length == 0xffffffff)
4174 arange.ar_length = byte_get (hdrptr, 8);
4177 initial_length_size = 12;
4182 initial_length_size = 4;
4185 arange.ar_version = byte_get (hdrptr, 2);
4188 arange.ar_info_offset = byte_get (hdrptr, offset_size);
4189 hdrptr += offset_size;
4191 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4192 && num_debug_info_entries > 0
4193 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4194 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4195 (unsigned long) arange.ar_info_offset, section->name);
4197 arange.ar_pointer_size = byte_get (hdrptr, 1);
4200 arange.ar_segment_size = byte_get (hdrptr, 1);
4203 if (arange.ar_version != 2 && arange.ar_version != 3)
4205 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4209 printf (_(" Length: %ld\n"),
4210 (long) arange.ar_length);
4211 printf (_(" Version: %d\n"), arange.ar_version);
4212 printf (_(" Offset into .debug_info: 0x%lx\n"),
4213 (unsigned long) arange.ar_info_offset);
4214 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4215 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4217 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4219 if (address_size == 0)
4221 error (_("Invalid address size in %s section!\n"),
4226 /* The DWARF spec does not require that the address size be a power
4227 of two, but we do. This will have to change if we ever encounter
4228 an uneven architecture. */
4229 if ((address_size & (address_size - 1)) != 0)
4231 warn (_("Pointer size + Segment size is not a power of two.\n"));
4235 if (address_size > 4)
4236 printf (_("\n Address Length\n"));
4238 printf (_("\n Address Length\n"));
4240 addr_ranges = hdrptr;
4242 /* Must pad to an alignment boundary that is twice the address size. */
4243 excess = (hdrptr - start) % (2 * address_size);
4245 addr_ranges += (2 * address_size) - excess;
4247 start += arange.ar_length + initial_length_size;
4249 while (addr_ranges + 2 * address_size <= start)
4251 address = byte_get (addr_ranges, address_size);
4253 addr_ranges += address_size;
4255 length = byte_get (addr_ranges, address_size);
4257 addr_ranges += address_size;
4260 print_dwarf_vma (address, address_size);
4261 print_dwarf_vma (length, address_size);
4271 /* Each debug_information[x].range_lists[y] gets this representation for
4272 sorting purposes. */
4276 /* The debug_information[x].range_lists[y] value. */
4277 unsigned long ranges_offset;
4279 /* Original debug_information to find parameters of the data. */
4280 debug_info *debug_info_p;
4283 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4286 range_entry_compar (const void *ap, const void *bp)
4288 const struct range_entry *a_re = (const struct range_entry *) ap;
4289 const struct range_entry *b_re = (const struct range_entry *) bp;
4290 const unsigned long a = a_re->ranges_offset;
4291 const unsigned long b = b_re->ranges_offset;
4293 return (a > b) - (b > a);
4297 display_debug_ranges (struct dwarf_section *section,
4298 void *file ATTRIBUTE_UNUSED)
4300 unsigned char *start = section->start;
4301 unsigned long bytes;
4302 unsigned char *section_begin = start;
4303 unsigned int num_range_list, i;
4304 struct range_entry *range_entries, *range_entry_fill;
4306 bytes = section->size;
4310 printf (_("\nThe %s section is empty.\n"), section->name);
4314 if (load_debug_info (file) == 0)
4316 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4322 for (i = 0; i < num_debug_info_entries; i++)
4323 num_range_list += debug_information [i].num_range_lists;
4325 if (num_range_list == 0)
4326 error (_("No range lists in .debug_info section!\n"));
4328 range_entries = (struct range_entry *)
4329 xmalloc (sizeof (*range_entries) * num_range_list);
4330 range_entry_fill = range_entries;
4332 for (i = 0; i < num_debug_info_entries; i++)
4334 debug_info *debug_info_p = &debug_information[i];
4337 for (j = 0; j < debug_info_p->num_range_lists; j++)
4339 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4340 range_entry_fill->debug_info_p = debug_info_p;
4345 qsort (range_entries, num_range_list, sizeof (*range_entries),
4346 range_entry_compar);
4348 /* DWARF sections under Mach-O have non-zero addresses. */
4349 if (range_entries[0].ranges_offset != section->address)
4350 warn (_("Range lists in %s section start at 0x%lx\n"),
4351 section->name, range_entries[0].ranges_offset);
4353 printf (_("Contents of the %s section:\n\n"), section->name);
4354 printf (_(" Offset Begin End\n"));
4356 for (i = 0; i < num_range_list; i++)
4358 struct range_entry *range_entry = &range_entries[i];
4359 debug_info *debug_info_p = range_entry->debug_info_p;
4360 unsigned int pointer_size;
4361 unsigned long offset;
4362 unsigned char *next;
4363 unsigned long base_address;
4365 pointer_size = debug_info_p->pointer_size;
4367 /* DWARF sections under Mach-O have non-zero addresses. */
4368 offset = range_entry->ranges_offset - section->address;
4369 next = section_begin + offset;
4370 base_address = debug_info_p->base_address;
4375 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4376 (unsigned long) (start - section_begin),
4377 (unsigned long) (next - section_begin), section->name);
4378 else if (start > next)
4379 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4380 (unsigned long) (start - section_begin),
4381 (unsigned long) (next - section_begin), section->name);
4390 /* Note: we use sign extension here in order to be sure that
4391 we can detect the -1 escape value. Sign extension into the
4392 top 32 bits of a 32-bit address will not affect the values
4393 that we display since we always show hex values, and always
4394 the bottom 32-bits. */
4395 begin = byte_get_signed (start, pointer_size);
4396 start += pointer_size;
4397 end = byte_get_signed (start, pointer_size);
4398 start += pointer_size;
4400 printf (" %8.8lx ", offset);
4402 if (begin == 0 && end == 0)
4404 printf (_("<End of list>\n"));
4408 /* Check base address specifiers. */
4409 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4412 print_dwarf_vma (begin, pointer_size);
4413 print_dwarf_vma (end, pointer_size);
4414 printf ("(base address)\n");
4418 print_dwarf_vma (begin + base_address, pointer_size);
4419 print_dwarf_vma (end + base_address, pointer_size);
4422 fputs (_("(start == end)"), stdout);
4423 else if (begin > end)
4424 fputs (_("(start > end)"), stdout);
4431 free (range_entries);
4436 typedef struct Frame_Chunk
4438 struct Frame_Chunk *next;
4439 unsigned char *chunk_start;
4441 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4442 short int *col_type;
4445 unsigned int code_factor;
4447 unsigned long pc_begin;
4448 unsigned long pc_range;
4452 unsigned char fde_encoding;
4453 unsigned char cfa_exp;
4454 unsigned char ptr_size;
4455 unsigned char segment_size;
4459 static const char *const *dwarf_regnames;
4460 static unsigned int dwarf_regnames_count;
4462 /* A marker for a col_type that means this column was never referenced
4463 in the frame info. */
4464 #define DW_CFA_unreferenced (-1)
4466 /* Return 0 if not more space is needed, 1 if more space is needed,
4467 -1 for invalid reg. */
4470 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4472 int prev = fc->ncols;
4474 if (reg < (unsigned int) fc->ncols)
4477 if (dwarf_regnames_count
4478 && reg > dwarf_regnames_count)
4481 fc->ncols = reg + 1;
4482 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4483 sizeof (short int));
4484 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4486 while (prev < fc->ncols)
4488 fc->col_type[prev] = DW_CFA_unreferenced;
4489 fc->col_offset[prev] = 0;
4495 static const char *const dwarf_regnames_i386[] =
4497 "eax", "ecx", "edx", "ebx",
4498 "esp", "ebp", "esi", "edi",
4499 "eip", "eflags", NULL,
4500 "st0", "st1", "st2", "st3",
4501 "st4", "st5", "st6", "st7",
4503 "xmm0", "xmm1", "xmm2", "xmm3",
4504 "xmm4", "xmm5", "xmm6", "xmm7",
4505 "mm0", "mm1", "mm2", "mm3",
4506 "mm4", "mm5", "mm6", "mm7",
4507 "fcw", "fsw", "mxcsr",
4508 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4513 init_dwarf_regnames_i386 (void)
4515 dwarf_regnames = dwarf_regnames_i386;
4516 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4519 static const char *const dwarf_regnames_x86_64[] =
4521 "rax", "rdx", "rcx", "rbx",
4522 "rsi", "rdi", "rbp", "rsp",
4523 "r8", "r9", "r10", "r11",
4524 "r12", "r13", "r14", "r15",
4526 "xmm0", "xmm1", "xmm2", "xmm3",
4527 "xmm4", "xmm5", "xmm6", "xmm7",
4528 "xmm8", "xmm9", "xmm10", "xmm11",
4529 "xmm12", "xmm13", "xmm14", "xmm15",
4530 "st0", "st1", "st2", "st3",
4531 "st4", "st5", "st6", "st7",
4532 "mm0", "mm1", "mm2", "mm3",
4533 "mm4", "mm5", "mm6", "mm7",
4535 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4536 "fs.base", "gs.base", NULL, NULL,
4538 "mxcsr", "fcw", "fsw"
4542 init_dwarf_regnames_x86_64 (void)
4544 dwarf_regnames = dwarf_regnames_x86_64;
4545 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4549 init_dwarf_regnames (unsigned int e_machine)
4555 init_dwarf_regnames_i386 ();
4561 init_dwarf_regnames_x86_64 ();
4570 regname (unsigned int regno, int row)
4572 static char reg[64];
4574 && regno < dwarf_regnames_count
4575 && dwarf_regnames [regno] != NULL)
4578 return dwarf_regnames [regno];
4579 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4580 dwarf_regnames [regno]);
4583 snprintf (reg, sizeof (reg), "r%d", regno);
4588 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4593 if (*max_regs < fc->ncols)
4594 *max_regs = fc->ncols;
4596 if (*need_col_headers)
4598 static const char *sloc = " LOC";
4600 *need_col_headers = 0;
4602 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4604 for (r = 0; r < *max_regs; r++)
4605 if (fc->col_type[r] != DW_CFA_unreferenced)
4610 printf ("%-5s ", regname (r, 1));
4616 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4618 strcpy (tmp, "exp");
4620 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4621 printf ("%-8s ", tmp);
4623 for (r = 0; r < fc->ncols; r++)
4625 if (fc->col_type[r] != DW_CFA_unreferenced)
4627 switch (fc->col_type[r])
4629 case DW_CFA_undefined:
4632 case DW_CFA_same_value:
4636 sprintf (tmp, "c%+d", fc->col_offset[r]);
4638 case DW_CFA_val_offset:
4639 sprintf (tmp, "v%+d", fc->col_offset[r]);
4641 case DW_CFA_register:
4642 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4644 case DW_CFA_expression:
4645 strcpy (tmp, "exp");
4647 case DW_CFA_val_expression:
4648 strcpy (tmp, "vexp");
4651 strcpy (tmp, "n/a");
4654 printf ("%-5s ", tmp);
4660 #define GET(N) byte_get (start, N); start += N
4661 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4662 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4665 display_debug_frames (struct dwarf_section *section,
4666 void *file ATTRIBUTE_UNUSED)
4668 unsigned char *start = section->start;
4669 unsigned char *end = start + section->size;
4670 unsigned char *section_start = start;
4671 Frame_Chunk *chunks = 0;
4672 Frame_Chunk *remembered_state = 0;
4674 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4675 unsigned int length_return;
4677 const char *bad_reg = _("bad register: ");
4678 int saved_eh_addr_size = eh_addr_size;
4680 printf (_("Contents of the %s section:\n"), section->name);
4684 unsigned char *saved_start;
4685 unsigned char *block_end;
4686 unsigned long length;
4687 unsigned long cie_id;
4690 int need_col_headers = 1;
4691 unsigned char *augmentation_data = NULL;
4692 unsigned long augmentation_data_len = 0;
4693 int encoded_ptr_size = saved_eh_addr_size;
4695 int initial_length_size;
4697 saved_start = start;
4698 length = byte_get (start, 4); start += 4;
4702 printf ("\n%08lx ZERO terminator\n\n",
4703 (unsigned long)(saved_start - section_start));
4707 if (length == 0xffffffff)
4709 length = byte_get (start, 8);
4712 initial_length_size = 12;
4717 initial_length_size = 4;
4720 block_end = saved_start + length + initial_length_size;
4721 if (block_end > end)
4723 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4724 length, (unsigned long)(saved_start - section_start));
4727 cie_id = byte_get (start, offset_size); start += offset_size;
4729 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4733 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4734 memset (fc, 0, sizeof (Frame_Chunk));
4738 fc->chunk_start = saved_start;
4740 fc->col_type = (short int *) xmalloc (sizeof (short int));
4741 fc->col_offset = (int *) xmalloc (sizeof (int));
4742 frame_need_space (fc, max_regs - 1);
4746 fc->augmentation = (char *) start;
4747 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4749 if (strcmp (fc->augmentation, "eh") == 0)
4750 start += eh_addr_size;
4754 fc->ptr_size = GET (1);
4755 fc->segment_size = GET (1);
4756 eh_addr_size = fc->ptr_size;
4760 fc->ptr_size = eh_addr_size;
4761 fc->segment_size = 0;
4763 fc->code_factor = LEB ();
4764 fc->data_factor = SLEB ();
4774 if (fc->augmentation[0] == 'z')
4776 augmentation_data_len = LEB ();
4777 augmentation_data = start;
4778 start += augmentation_data_len;
4782 if (do_debug_frames_interp)
4783 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4784 (unsigned long)(saved_start - section_start), length, cie_id,
4785 fc->augmentation, fc->code_factor, fc->data_factor,
4789 printf ("\n%08lx %08lx %08lx CIE\n",
4790 (unsigned long)(saved_start - section_start), length, cie_id);
4791 printf (" Version: %d\n", version);
4792 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4795 printf (" Pointer Size: %u\n", fc->ptr_size);
4796 printf (" Segment Size: %u\n", fc->segment_size);
4798 printf (" Code alignment factor: %u\n", fc->code_factor);
4799 printf (" Data alignment factor: %d\n", fc->data_factor);
4800 printf (" Return address column: %d\n", fc->ra);
4802 if (augmentation_data_len)
4805 printf (" Augmentation data: ");
4806 for (i = 0; i < augmentation_data_len; ++i)
4807 printf (" %02x", augmentation_data[i]);
4813 if (augmentation_data_len)
4815 unsigned char *p, *q;
4816 p = (unsigned char *) fc->augmentation + 1;
4817 q = augmentation_data;
4824 q += 1 + size_of_encoded_value (*q);
4826 fc->fde_encoding = *q++;
4834 if (fc->fde_encoding)
4835 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4838 frame_need_space (fc, fc->ra);
4842 unsigned char *look_for;
4843 static Frame_Chunk fde_fc;
4844 unsigned long segment_selector;
4847 memset (fc, 0, sizeof (Frame_Chunk));
4849 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
4851 for (cie = chunks; cie ; cie = cie->next)
4852 if (cie->chunk_start == look_for)
4857 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4858 cie_id, (unsigned long)(saved_start - section_start));
4860 fc->col_type = (short int *) xmalloc (sizeof (short int));
4861 fc->col_offset = (int *) xmalloc (sizeof (int));
4862 frame_need_space (fc, max_regs - 1);
4864 fc->augmentation = "";
4865 fc->fde_encoding = 0;
4866 fc->ptr_size = eh_addr_size;
4867 fc->segment_size = 0;
4871 fc->ncols = cie->ncols;
4872 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
4873 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
4874 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
4875 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
4876 fc->augmentation = cie->augmentation;
4877 fc->ptr_size = cie->ptr_size;
4878 eh_addr_size = cie->ptr_size;
4879 fc->segment_size = cie->segment_size;
4880 fc->code_factor = cie->code_factor;
4881 fc->data_factor = cie->data_factor;
4882 fc->cfa_reg = cie->cfa_reg;
4883 fc->cfa_offset = cie->cfa_offset;
4885 frame_need_space (fc, max_regs - 1);
4886 fc->fde_encoding = cie->fde_encoding;
4889 if (fc->fde_encoding)
4890 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4892 segment_selector = 0;
4893 if (fc->segment_size)
4895 segment_selector = byte_get (start, fc->segment_size);
4896 start += fc->segment_size;
4898 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
4899 start += encoded_ptr_size;
4900 fc->pc_range = byte_get (start, encoded_ptr_size);
4901 start += encoded_ptr_size;
4903 if (cie->augmentation[0] == 'z')
4905 augmentation_data_len = LEB ();
4906 augmentation_data = start;
4907 start += augmentation_data_len;
4910 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4911 (unsigned long)(saved_start - section_start), length, cie_id,
4912 (unsigned long)(cie->chunk_start - section_start));
4913 if (fc->segment_size)
4914 printf ("%04lx:", segment_selector);
4915 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
4916 if (! do_debug_frames_interp && augmentation_data_len)
4920 printf (" Augmentation data: ");
4921 for (i = 0; i < augmentation_data_len; ++i)
4922 printf (" %02x", augmentation_data[i]);
4928 /* At this point, fc is the current chunk, cie (if any) is set, and
4929 we're about to interpret instructions for the chunk. */
4930 /* ??? At present we need to do this always, since this sizes the
4931 fc->col_type and fc->col_offset arrays, which we write into always.
4932 We should probably split the interpreted and non-interpreted bits
4933 into two different routines, since there's so much that doesn't
4934 really overlap between them. */
4935 if (1 || do_debug_frames_interp)
4937 /* Start by making a pass over the chunk, allocating storage
4938 and taking note of what registers are used. */
4939 unsigned char *tmp = start;
4941 while (start < block_end)
4944 unsigned long reg, temp;
4951 /* Warning: if you add any more cases to this switch, be
4952 sure to add them to the corresponding switch below. */
4955 case DW_CFA_advance_loc:
4959 if (frame_need_space (fc, opa) >= 0)
4960 fc->col_type[opa] = DW_CFA_undefined;
4962 case DW_CFA_restore:
4963 if (frame_need_space (fc, opa) >= 0)
4964 fc->col_type[opa] = DW_CFA_undefined;
4966 case DW_CFA_set_loc:
4967 start += encoded_ptr_size;
4969 case DW_CFA_advance_loc1:
4972 case DW_CFA_advance_loc2:
4975 case DW_CFA_advance_loc4:
4978 case DW_CFA_offset_extended:
4979 case DW_CFA_val_offset:
4980 reg = LEB (); LEB ();
4981 if (frame_need_space (fc, reg) >= 0)
4982 fc->col_type[reg] = DW_CFA_undefined;
4984 case DW_CFA_restore_extended:
4986 frame_need_space (fc, reg);
4987 if (frame_need_space (fc, reg) >= 0)
4988 fc->col_type[reg] = DW_CFA_undefined;
4990 case DW_CFA_undefined:
4992 if (frame_need_space (fc, reg) >= 0)
4993 fc->col_type[reg] = DW_CFA_undefined;
4995 case DW_CFA_same_value:
4997 if (frame_need_space (fc, reg) >= 0)
4998 fc->col_type[reg] = DW_CFA_undefined;
5000 case DW_CFA_register:
5001 reg = LEB (); LEB ();
5002 if (frame_need_space (fc, reg) >= 0)
5003 fc->col_type[reg] = DW_CFA_undefined;
5005 case DW_CFA_def_cfa:
5008 case DW_CFA_def_cfa_register:
5011 case DW_CFA_def_cfa_offset:
5014 case DW_CFA_def_cfa_expression:
5018 case DW_CFA_expression:
5019 case DW_CFA_val_expression:
5023 if (frame_need_space (fc, reg) >= 0)
5024 fc->col_type[reg] = DW_CFA_undefined;
5026 case DW_CFA_offset_extended_sf:
5027 case DW_CFA_val_offset_sf:
5028 reg = LEB (); SLEB ();
5029 if (frame_need_space (fc, reg) >= 0)
5030 fc->col_type[reg] = DW_CFA_undefined;
5032 case DW_CFA_def_cfa_sf:
5035 case DW_CFA_def_cfa_offset_sf:
5038 case DW_CFA_MIPS_advance_loc8:
5041 case DW_CFA_GNU_args_size:
5044 case DW_CFA_GNU_negative_offset_extended:
5045 reg = LEB (); LEB ();
5046 if (frame_need_space (fc, reg) >= 0)
5047 fc->col_type[reg] = DW_CFA_undefined;
5056 /* Now we know what registers are used, make a second pass over
5057 the chunk, this time actually printing out the info. */
5059 while (start < block_end)
5062 unsigned long ul, reg, roffs;
5065 const char *reg_prefix = "";
5072 /* Warning: if you add any more cases to this switch, be
5073 sure to add them to the corresponding switch above. */
5076 case DW_CFA_advance_loc:
5077 if (do_debug_frames_interp)
5078 frame_display_row (fc, &need_col_headers, &max_regs);
5080 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5081 opa * fc->code_factor,
5082 fc->pc_begin + opa * fc->code_factor);
5083 fc->pc_begin += opa * fc->code_factor;
5088 if (opa >= (unsigned int) fc->ncols)
5089 reg_prefix = bad_reg;
5090 if (! do_debug_frames_interp || *reg_prefix != '\0')
5091 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5092 reg_prefix, regname (opa, 0),
5093 roffs * fc->data_factor);
5094 if (*reg_prefix == '\0')
5096 fc->col_type[opa] = DW_CFA_offset;
5097 fc->col_offset[opa] = roffs * fc->data_factor;
5101 case DW_CFA_restore:
5102 if (opa >= (unsigned int) cie->ncols
5103 || opa >= (unsigned int) fc->ncols)
5104 reg_prefix = bad_reg;
5105 if (! do_debug_frames_interp || *reg_prefix != '\0')
5106 printf (" DW_CFA_restore: %s%s\n",
5107 reg_prefix, regname (opa, 0));
5108 if (*reg_prefix == '\0')
5110 fc->col_type[opa] = cie->col_type[opa];
5111 fc->col_offset[opa] = cie->col_offset[opa];
5115 case DW_CFA_set_loc:
5116 vma = get_encoded_value (start, fc->fde_encoding, section);
5117 start += encoded_ptr_size;
5118 if (do_debug_frames_interp)
5119 frame_display_row (fc, &need_col_headers, &max_regs);
5121 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5125 case DW_CFA_advance_loc1:
5126 ofs = byte_get (start, 1); start += 1;
5127 if (do_debug_frames_interp)
5128 frame_display_row (fc, &need_col_headers, &max_regs);
5130 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5131 ofs * fc->code_factor,
5132 fc->pc_begin + ofs * fc->code_factor);
5133 fc->pc_begin += ofs * fc->code_factor;
5136 case DW_CFA_advance_loc2:
5137 ofs = byte_get (start, 2); start += 2;
5138 if (do_debug_frames_interp)
5139 frame_display_row (fc, &need_col_headers, &max_regs);
5141 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5142 ofs * fc->code_factor,
5143 fc->pc_begin + ofs * fc->code_factor);
5144 fc->pc_begin += ofs * fc->code_factor;
5147 case DW_CFA_advance_loc4:
5148 ofs = byte_get (start, 4); start += 4;
5149 if (do_debug_frames_interp)
5150 frame_display_row (fc, &need_col_headers, &max_regs);
5152 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5153 ofs * fc->code_factor,
5154 fc->pc_begin + ofs * fc->code_factor);
5155 fc->pc_begin += ofs * fc->code_factor;
5158 case DW_CFA_offset_extended:
5161 if (reg >= (unsigned int) fc->ncols)
5162 reg_prefix = bad_reg;
5163 if (! do_debug_frames_interp || *reg_prefix != '\0')
5164 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5165 reg_prefix, regname (reg, 0),
5166 roffs * fc->data_factor);
5167 if (*reg_prefix == '\0')
5169 fc->col_type[reg] = DW_CFA_offset;
5170 fc->col_offset[reg] = roffs * fc->data_factor;
5174 case DW_CFA_val_offset:
5177 if (reg >= (unsigned int) fc->ncols)
5178 reg_prefix = bad_reg;
5179 if (! do_debug_frames_interp || *reg_prefix != '\0')
5180 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5181 reg_prefix, regname (reg, 0),
5182 roffs * fc->data_factor);
5183 if (*reg_prefix == '\0')
5185 fc->col_type[reg] = DW_CFA_val_offset;
5186 fc->col_offset[reg] = roffs * fc->data_factor;
5190 case DW_CFA_restore_extended:
5192 if (reg >= (unsigned int) cie->ncols
5193 || reg >= (unsigned int) fc->ncols)
5194 reg_prefix = bad_reg;
5195 if (! do_debug_frames_interp || *reg_prefix != '\0')
5196 printf (" DW_CFA_restore_extended: %s%s\n",
5197 reg_prefix, regname (reg, 0));
5198 if (*reg_prefix == '\0')
5200 fc->col_type[reg] = cie->col_type[reg];
5201 fc->col_offset[reg] = cie->col_offset[reg];
5205 case DW_CFA_undefined:
5207 if (reg >= (unsigned int) fc->ncols)
5208 reg_prefix = bad_reg;
5209 if (! do_debug_frames_interp || *reg_prefix != '\0')
5210 printf (" DW_CFA_undefined: %s%s\n",
5211 reg_prefix, regname (reg, 0));
5212 if (*reg_prefix == '\0')
5214 fc->col_type[reg] = DW_CFA_undefined;
5215 fc->col_offset[reg] = 0;
5219 case DW_CFA_same_value:
5221 if (reg >= (unsigned int) fc->ncols)
5222 reg_prefix = bad_reg;
5223 if (! do_debug_frames_interp || *reg_prefix != '\0')
5224 printf (" DW_CFA_same_value: %s%s\n",
5225 reg_prefix, regname (reg, 0));
5226 if (*reg_prefix == '\0')
5228 fc->col_type[reg] = DW_CFA_same_value;
5229 fc->col_offset[reg] = 0;
5233 case DW_CFA_register:
5236 if (reg >= (unsigned int) fc->ncols)
5237 reg_prefix = bad_reg;
5238 if (! do_debug_frames_interp || *reg_prefix != '\0')
5240 printf (" DW_CFA_register: %s%s in ",
5241 reg_prefix, regname (reg, 0));
5242 puts (regname (roffs, 0));
5244 if (*reg_prefix == '\0')
5246 fc->col_type[reg] = DW_CFA_register;
5247 fc->col_offset[reg] = roffs;
5251 case DW_CFA_remember_state:
5252 if (! do_debug_frames_interp)
5253 printf (" DW_CFA_remember_state\n");
5254 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5255 rs->ncols = fc->ncols;
5256 rs->col_type = (short int *) xcmalloc (rs->ncols,
5257 sizeof (short int));
5258 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
5259 memcpy (rs->col_type, fc->col_type, rs->ncols);
5260 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5261 rs->next = remembered_state;
5262 remembered_state = rs;
5265 case DW_CFA_restore_state:
5266 if (! do_debug_frames_interp)
5267 printf (" DW_CFA_restore_state\n");
5268 rs = remembered_state;
5271 remembered_state = rs->next;
5272 frame_need_space (fc, rs->ncols - 1);
5273 memcpy (fc->col_type, rs->col_type, rs->ncols);
5274 memcpy (fc->col_offset, rs->col_offset,
5275 rs->ncols * sizeof (int));
5276 free (rs->col_type);
5277 free (rs->col_offset);
5280 else if (do_debug_frames_interp)
5281 printf ("Mismatched DW_CFA_restore_state\n");
5284 case DW_CFA_def_cfa:
5285 fc->cfa_reg = LEB ();
5286 fc->cfa_offset = LEB ();
5288 if (! do_debug_frames_interp)
5289 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5290 regname (fc->cfa_reg, 0), fc->cfa_offset);
5293 case DW_CFA_def_cfa_register:
5294 fc->cfa_reg = LEB ();
5296 if (! do_debug_frames_interp)
5297 printf (" DW_CFA_def_cfa_register: %s\n",
5298 regname (fc->cfa_reg, 0));
5301 case DW_CFA_def_cfa_offset:
5302 fc->cfa_offset = LEB ();
5303 if (! do_debug_frames_interp)
5304 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5308 if (! do_debug_frames_interp)
5309 printf (" DW_CFA_nop\n");
5312 case DW_CFA_def_cfa_expression:
5314 if (! do_debug_frames_interp)
5316 printf (" DW_CFA_def_cfa_expression (");
5317 decode_location_expression (start, eh_addr_size, 0, -1,
5325 case DW_CFA_expression:
5328 if (reg >= (unsigned int) fc->ncols)
5329 reg_prefix = bad_reg;
5330 if (! do_debug_frames_interp || *reg_prefix != '\0')
5332 printf (" DW_CFA_expression: %s%s (",
5333 reg_prefix, regname (reg, 0));
5334 decode_location_expression (start, eh_addr_size, 0, -1,
5338 if (*reg_prefix == '\0')
5339 fc->col_type[reg] = DW_CFA_expression;
5343 case DW_CFA_val_expression:
5346 if (reg >= (unsigned int) fc->ncols)
5347 reg_prefix = bad_reg;
5348 if (! do_debug_frames_interp || *reg_prefix != '\0')
5350 printf (" DW_CFA_val_expression: %s%s (",
5351 reg_prefix, regname (reg, 0));
5352 decode_location_expression (start, eh_addr_size, 0, -1,
5356 if (*reg_prefix == '\0')
5357 fc->col_type[reg] = DW_CFA_val_expression;
5361 case DW_CFA_offset_extended_sf:
5364 if (frame_need_space (fc, reg) < 0)
5365 reg_prefix = bad_reg;
5366 if (! do_debug_frames_interp || *reg_prefix != '\0')
5367 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5368 reg_prefix, regname (reg, 0),
5369 l * fc->data_factor);
5370 if (*reg_prefix == '\0')
5372 fc->col_type[reg] = DW_CFA_offset;
5373 fc->col_offset[reg] = l * fc->data_factor;
5377 case DW_CFA_val_offset_sf:
5380 if (frame_need_space (fc, reg) < 0)
5381 reg_prefix = bad_reg;
5382 if (! do_debug_frames_interp || *reg_prefix != '\0')
5383 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5384 reg_prefix, regname (reg, 0),
5385 l * fc->data_factor);
5386 if (*reg_prefix == '\0')
5388 fc->col_type[reg] = DW_CFA_val_offset;
5389 fc->col_offset[reg] = l * fc->data_factor;
5393 case DW_CFA_def_cfa_sf:
5394 fc->cfa_reg = LEB ();
5395 fc->cfa_offset = SLEB ();
5396 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5398 if (! do_debug_frames_interp)
5399 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5400 regname (fc->cfa_reg, 0), fc->cfa_offset);
5403 case DW_CFA_def_cfa_offset_sf:
5404 fc->cfa_offset = SLEB ();
5405 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5406 if (! do_debug_frames_interp)
5407 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5410 case DW_CFA_MIPS_advance_loc8:
5411 ofs = byte_get (start, 8); start += 8;
5412 if (do_debug_frames_interp)
5413 frame_display_row (fc, &need_col_headers, &max_regs);
5415 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5416 ofs * fc->code_factor,
5417 fc->pc_begin + ofs * fc->code_factor);
5418 fc->pc_begin += ofs * fc->code_factor;
5421 case DW_CFA_GNU_window_save:
5422 if (! do_debug_frames_interp)
5423 printf (" DW_CFA_GNU_window_save\n");
5426 case DW_CFA_GNU_args_size:
5428 if (! do_debug_frames_interp)
5429 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5432 case DW_CFA_GNU_negative_offset_extended:
5435 if (frame_need_space (fc, reg) < 0)
5436 reg_prefix = bad_reg;
5437 if (! do_debug_frames_interp || *reg_prefix != '\0')
5438 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5439 reg_prefix, regname (reg, 0),
5440 l * fc->data_factor);
5441 if (*reg_prefix == '\0')
5443 fc->col_type[reg] = DW_CFA_offset;
5444 fc->col_offset[reg] = l * fc->data_factor;
5449 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5450 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5452 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5457 if (do_debug_frames_interp)
5458 frame_display_row (fc, &need_col_headers, &max_regs);
5461 eh_addr_size = saved_eh_addr_size;
5474 display_gdb_index (struct dwarf_section *section,
5475 void *file ATTRIBUTE_UNUSED)
5477 unsigned char *start = section->start;
5479 uint32_t cu_list_offset, tu_list_offset;
5480 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5481 unsigned int cu_list_elements, tu_list_elements;
5482 unsigned int address_table_size, symbol_table_slots;
5483 unsigned char *cu_list, *tu_list;
5484 unsigned char *address_table, *symbol_table, *constant_pool;
5487 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5489 printf (_("Contents of the %s section:\n"), section->name);
5491 if (section->size < 6 * sizeof (uint32_t))
5493 warn (_("Truncated header in the %s section.\n"), section->name);
5497 version = byte_get_little_endian (start, 4);
5498 printf (_("Version %ld\n"), (long) version);
5500 /* Prior versions are obsolete, and future versions may not be
5501 backwards compatible. */
5505 warn (_("The address table data in version 3 may be wrong.\n"));
5508 warn (_("Version 4 does not support case insensitive lookups.\n"));
5513 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5517 cu_list_offset = byte_get_little_endian (start + 4, 4);
5518 tu_list_offset = byte_get_little_endian (start + 8, 4);
5519 address_table_offset = byte_get_little_endian (start + 12, 4);
5520 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5521 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5523 if (cu_list_offset > section->size
5524 || tu_list_offset > section->size
5525 || address_table_offset > section->size
5526 || symbol_table_offset > section->size
5527 || constant_pool_offset > section->size)
5529 warn (_("Corrupt header in the %s section.\n"), section->name);
5533 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5534 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5535 address_table_size = symbol_table_offset - address_table_offset;
5536 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5538 cu_list = start + cu_list_offset;
5539 tu_list = start + tu_list_offset;
5540 address_table = start + address_table_offset;
5541 symbol_table = start + symbol_table_offset;
5542 constant_pool = start + constant_pool_offset;
5544 printf (_("\nCU table:\n"));
5545 for (i = 0; i < cu_list_elements; i += 2)
5547 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5548 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5550 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5551 (unsigned long) cu_offset,
5552 (unsigned long) (cu_offset + cu_length - 1));
5555 printf (_("\nTU table:\n"));
5556 for (i = 0; i < tu_list_elements; i += 3)
5558 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5559 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5560 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5562 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5563 (unsigned long) tu_offset,
5564 (unsigned long) type_offset);
5565 print_dwarf_vma (signature, 8);
5569 printf (_("\nAddress table:\n"));
5570 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5572 uint64_t low = byte_get_little_endian (address_table + i, 8);
5573 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5574 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5576 print_dwarf_vma (low, 8);
5577 print_dwarf_vma (high, 8);
5578 printf (_("%lu\n"), (unsigned long) cu_index);
5581 printf (_("\nSymbol table:\n"));
5582 for (i = 0; i < symbol_table_slots; ++i)
5584 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5585 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5586 uint32_t num_cus, cu;
5588 if (name_offset != 0
5589 || cu_vector_offset != 0)
5593 printf ("[%3u] %s:", i, constant_pool + name_offset);
5594 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5595 for (j = 0; j < num_cus; ++j)
5597 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5598 /* Convert to TU number if it's for a type unit. */
5599 if (cu >= cu_list_elements / 2)
5600 printf (" T%lu", (unsigned long) (cu - cu_list_elements / 2));
5602 printf (" %lu", (unsigned long) cu);
5612 display_debug_not_supported (struct dwarf_section *section,
5613 void *file ATTRIBUTE_UNUSED)
5615 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5622 cmalloc (size_t nmemb, size_t size)
5624 /* Check for overflow. */
5625 if (nmemb >= ~(size_t) 0 / size)
5628 return malloc (nmemb * size);
5632 xcmalloc (size_t nmemb, size_t size)
5634 /* Check for overflow. */
5635 if (nmemb >= ~(size_t) 0 / size)
5638 return xmalloc (nmemb * size);
5642 xcrealloc (void *ptr, size_t nmemb, size_t size)
5644 /* Check for overflow. */
5645 if (nmemb >= ~(size_t) 0 / size)
5648 return xrealloc (ptr, nmemb * size);
5652 free_debug_memory (void)
5658 for (i = 0; i < max; i++)
5659 free_debug_section ((enum dwarf_section_display_enum) i);
5661 if (debug_information != NULL)
5663 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
5665 for (i = 0; i < num_debug_info_entries; i++)
5667 if (!debug_information [i].max_loc_offsets)
5669 free (debug_information [i].loc_offsets);
5670 free (debug_information [i].have_frame_base);
5672 if (!debug_information [i].max_range_lists)
5673 free (debug_information [i].range_lists);
5677 free (debug_information);
5678 debug_information = NULL;
5679 num_debug_info_entries = 0;
5684 dwarf_select_sections_by_names (const char *names)
5688 const char * option;
5692 debug_dump_long_opts;
5694 static const debug_dump_long_opts opts_table [] =
5696 /* Please keep this table alpha- sorted. */
5697 { "Ranges", & do_debug_ranges, 1 },
5698 { "abbrev", & do_debug_abbrevs, 1 },
5699 { "aranges", & do_debug_aranges, 1 },
5700 { "frames", & do_debug_frames, 1 },
5701 { "frames-interp", & do_debug_frames_interp, 1 },
5702 { "info", & do_debug_info, 1 },
5703 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5704 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5705 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5706 { "loc", & do_debug_loc, 1 },
5707 { "macro", & do_debug_macinfo, 1 },
5708 { "pubnames", & do_debug_pubnames, 1 },
5709 { "pubtypes", & do_debug_pubtypes, 1 },
5710 /* This entry is for compatability
5711 with earlier versions of readelf. */
5712 { "ranges", & do_debug_aranges, 1 },
5713 { "str", & do_debug_str, 1 },
5714 /* The special .gdb_index section. */
5715 { "gdb_index", & do_gdb_index, 1 },
5716 /* These trace_* sections are used by Itanium VMS. */
5717 { "trace_abbrev", & do_trace_abbrevs, 1 },
5718 { "trace_aranges", & do_trace_aranges, 1 },
5719 { "trace_info", & do_trace_info, 1 },
5728 const debug_dump_long_opts * entry;
5730 for (entry = opts_table; entry->option; entry++)
5732 size_t len = strlen (entry->option);
5734 if (strncmp (p, entry->option, len) == 0
5735 && (p[len] == ',' || p[len] == '\0'))
5737 * entry->variable |= entry->val;
5739 /* The --debug-dump=frames-interp option also
5740 enables the --debug-dump=frames option. */
5741 if (do_debug_frames_interp)
5742 do_debug_frames = 1;
5749 if (entry->option == NULL)
5751 warn (_("Unrecognized debug option '%s'\n"), p);
5752 p = strchr (p, ',');
5763 dwarf_select_sections_by_letters (const char *letters)
5765 unsigned int lindex = 0;
5767 while (letters[lindex])
5768 switch (letters[lindex++])
5775 do_debug_abbrevs = 1;
5779 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
5783 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
5787 do_debug_pubnames = 1;
5791 do_debug_pubtypes = 1;
5795 do_debug_aranges = 1;
5799 do_debug_ranges = 1;
5803 do_debug_frames_interp = 1;
5805 do_debug_frames = 1;
5809 do_debug_macinfo = 1;
5821 warn (_("Unrecognized debug option '%s'\n"), optarg);
5827 dwarf_select_sections_all (void)
5830 do_debug_abbrevs = 1;
5831 do_debug_lines = FLAG_DEBUG_LINES_RAW;
5832 do_debug_pubnames = 1;
5833 do_debug_pubtypes = 1;
5834 do_debug_aranges = 1;
5835 do_debug_ranges = 1;
5836 do_debug_frames = 1;
5837 do_debug_macinfo = 1;
5842 do_trace_abbrevs = 1;
5843 do_trace_aranges = 1;
5846 struct dwarf_section_display debug_displays[] =
5848 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 },
5849 display_debug_abbrev, &do_debug_abbrevs, 0 },
5850 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 },
5851 display_debug_aranges, &do_debug_aranges, 1 },
5852 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 },
5853 display_debug_frames, &do_debug_frames, 1 },
5854 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 },
5855 display_debug_info, &do_debug_info, 1 },
5856 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 },
5857 display_debug_lines, &do_debug_lines, 1 },
5858 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 },
5859 display_debug_pubnames, &do_debug_pubnames, 0 },
5860 { { ".eh_frame", "", NULL, NULL, 0, 0 },
5861 display_debug_frames, &do_debug_frames, 1 },
5862 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 },
5863 display_debug_macinfo, &do_debug_macinfo, 0 },
5864 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0 },
5865 display_debug_macro, &do_debug_macinfo, 1 },
5866 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 },
5867 display_debug_str, &do_debug_str, 0 },
5868 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 },
5869 display_debug_loc, &do_debug_loc, 1 },
5870 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 },
5871 display_debug_pubnames, &do_debug_pubtypes, 0 },
5872 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 },
5873 display_debug_ranges, &do_debug_ranges, 1 },
5874 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 },
5875 display_debug_not_supported, NULL, 0 },
5876 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 },
5877 display_debug_not_supported, NULL, 0 },
5878 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 },
5879 display_debug_types, &do_debug_info, 1 },
5880 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 },
5881 display_debug_not_supported, NULL, 0 },
5882 { { ".gdb_index", "", NULL, NULL, 0, 0 },
5883 display_gdb_index, &do_gdb_index, 0 },
5884 { { ".trace_info", "", NULL, NULL, 0, 0 },
5885 display_trace_info, &do_trace_info, 1 },
5886 { { ".trace_abbrev", "", NULL, NULL, 0, 0 },
5887 display_debug_abbrev, &do_trace_abbrevs, 0 },
5888 { { ".trace_aranges", "", NULL, NULL, 0, 0 },
5889 display_debug_aranges, &do_trace_aranges, 0 }