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 (" UNKNOW 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 (form == DW_FORM_data4
1489 || 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 (form == DW_FORM_data4
1520 || 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++;
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 (form == DW_FORM_data4
1738 || 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";
1964 /* UPC extension. */
1965 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1967 /* PGI (STMicroelectronics) extensions. */
1968 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1969 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1970 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1974 static char buffer[100];
1976 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1983 static unsigned char *
1984 read_and_display_attr (unsigned long attribute,
1986 unsigned char * data,
1987 dwarf_vma cu_offset,
1988 dwarf_vma pointer_size,
1989 dwarf_vma offset_size,
1991 debug_info * debug_info_p,
1993 struct dwarf_section * section)
1996 printf (" %-18s:", get_AT_name (attribute));
1997 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1998 pointer_size, offset_size,
1999 dwarf_version, debug_info_p,
2007 /* Process the contents of a .debug_info section. If do_loc is non-zero
2008 then we are scanning for location lists and we do not want to display
2009 anything to the user. If do_types is non-zero, we are processing
2010 a .debug_types section instead of a .debug_info section. */
2013 process_debug_info (struct dwarf_section *section,
2015 enum dwarf_section_display_enum abbrev_sec,
2019 unsigned char *start = section->start;
2020 unsigned char *end = start + section->size;
2021 unsigned char *section_begin;
2023 unsigned int num_units = 0;
2025 if ((do_loc || do_debug_loc || do_debug_ranges)
2026 && num_debug_info_entries == 0
2031 /* First scan the section to get the number of comp units. */
2032 for (section_begin = start, num_units = 0; section_begin < end;
2035 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2036 will be the length. For a 64-bit DWARF section, it'll be
2037 the escape code 0xffffffff followed by an 8 byte length. */
2038 length = byte_get (section_begin, 4);
2040 if (length == 0xffffffff)
2042 length = byte_get (section_begin + 4, 8);
2043 section_begin += length + 12;
2045 else if (length >= 0xfffffff0 && length < 0xffffffff)
2047 warn (_("Reserved length value (0x%s) found in section %s\n"),
2048 dwarf_vmatoa ("x", length), section->name);
2052 section_begin += length + 4;
2054 /* Negative values are illegal, they may even cause infinite
2055 looping. This can happen if we can't accurately apply
2056 relocations to an object file. */
2057 if ((signed long) length <= 0)
2059 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2060 dwarf_vmatoa ("x", length), section->name);
2067 error (_("No comp units in %s section ?"), section->name);
2071 /* Then allocate an array to hold the information. */
2072 debug_information = (debug_info *) cmalloc (num_units,
2073 sizeof (* debug_information));
2074 if (debug_information == NULL)
2076 error (_("Not enough memory for a debug info array of %u entries"),
2084 if (dwarf_start_die == 0)
2085 printf (_("Contents of the %s section:\n\n"), section->name);
2087 load_debug_section (str, file);
2090 load_debug_section (abbrev_sec, file);
2091 if (debug_displays [abbrev_sec].section.start == NULL)
2093 warn (_("Unable to locate %s section!\n"),
2094 debug_displays [abbrev_sec].section.name);
2098 for (section_begin = start, unit = 0; start < end; unit++)
2100 DWARF2_Internal_CompUnit compunit;
2101 unsigned char *hdrptr;
2102 unsigned char *tags;
2103 int level, last_level, saved_level;
2104 dwarf_vma cu_offset;
2106 int initial_length_size;
2107 unsigned char signature[8] = { 0 };
2108 dwarf_vma type_offset = 0;
2112 compunit.cu_length = byte_get (hdrptr, 4);
2115 if (compunit.cu_length == 0xffffffff)
2117 compunit.cu_length = byte_get (hdrptr, 8);
2120 initial_length_size = 12;
2125 initial_length_size = 4;
2128 compunit.cu_version = byte_get (hdrptr, 2);
2131 cu_offset = start - section_begin;
2133 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2134 hdrptr += offset_size;
2136 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2143 for (i = 0; i < 8; i++)
2145 signature[i] = byte_get (hdrptr, 1);
2149 type_offset = byte_get (hdrptr, offset_size);
2150 hdrptr += offset_size;
2153 if ((do_loc || do_debug_loc || do_debug_ranges)
2154 && num_debug_info_entries == 0
2157 debug_information [unit].cu_offset = cu_offset;
2158 debug_information [unit].pointer_size
2159 = compunit.cu_pointer_size;
2160 debug_information [unit].offset_size = offset_size;
2161 debug_information [unit].dwarf_version = compunit.cu_version;
2162 debug_information [unit].base_address = 0;
2163 debug_information [unit].loc_offsets = NULL;
2164 debug_information [unit].have_frame_base = NULL;
2165 debug_information [unit].max_loc_offsets = 0;
2166 debug_information [unit].num_loc_offsets = 0;
2167 debug_information [unit].range_lists = NULL;
2168 debug_information [unit].max_range_lists= 0;
2169 debug_information [unit].num_range_lists = 0;
2172 if (!do_loc && dwarf_start_die == 0)
2174 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2175 dwarf_vmatoa ("x", cu_offset));
2176 printf (_(" Length: 0x%s (%s)\n"),
2177 dwarf_vmatoa ("x", compunit.cu_length),
2178 offset_size == 8 ? "64-bit" : "32-bit");
2179 printf (_(" Version: %d\n"), compunit.cu_version);
2180 printf (_(" Abbrev Offset: %s\n"),
2181 dwarf_vmatoa ("d", compunit.cu_abbrev_offset));
2182 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2186 printf (_(" Signature: "));
2187 for (i = 0; i < 8; i++)
2188 printf ("%02x", signature[i]);
2190 printf (_(" Type Offset: 0x%s\n"),
2191 dwarf_vmatoa ("x", type_offset));
2195 if (cu_offset + compunit.cu_length + initial_length_size
2198 warn (_("Debug info is corrupted, length of CU at %s"
2199 " extends beyond end of section (length = %s)\n"),
2200 dwarf_vmatoa ("x", cu_offset),
2201 dwarf_vmatoa ("x", compunit.cu_length));
2205 start += compunit.cu_length + initial_length_size;
2207 if (compunit.cu_version != 2
2208 && compunit.cu_version != 3
2209 && compunit.cu_version != 4)
2211 warn (_("CU at offset %s contains corrupt or "
2212 "unsupported version number: %d.\n"),
2213 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2219 /* Process the abbrevs used by this compilation unit. DWARF
2220 sections under Mach-O have non-zero addresses. */
2221 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2222 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2223 (unsigned long) compunit.cu_abbrev_offset,
2224 (unsigned long) debug_displays [abbrev_sec].section.size);
2226 process_abbrev_section
2227 ((unsigned char *) debug_displays [abbrev_sec].section.start
2228 + compunit.cu_abbrev_offset,
2229 (unsigned char *) debug_displays [abbrev_sec].section.start
2230 + debug_displays [abbrev_sec].section.size);
2235 while (tags < start)
2237 unsigned int bytes_read;
2238 unsigned long abbrev_number;
2239 unsigned long die_offset;
2240 abbrev_entry *entry;
2242 int do_printing = 1;
2244 die_offset = tags - section_begin;
2246 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2249 /* A null DIE marks the end of a list of siblings or it may also be
2250 a section padding. */
2251 if (abbrev_number == 0)
2253 /* Check if it can be a section padding for the last CU. */
2254 if (level == 0 && start == end)
2258 for (chk = tags; chk < start; chk++)
2268 static unsigned num_bogus_warns = 0;
2270 if (num_bogus_warns < 3)
2272 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2275 if (num_bogus_warns == 3)
2276 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2279 if (dwarf_start_die != 0 && level < saved_level)
2286 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2290 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2291 saved_level = level;
2292 do_printing = (dwarf_cutoff_level == -1
2293 || level < dwarf_cutoff_level);
2295 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2296 level, die_offset, abbrev_number);
2297 else if (dwarf_cutoff_level == -1
2298 || last_level < dwarf_cutoff_level)
2299 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2304 /* Scan through the abbreviation list until we reach the
2306 for (entry = first_abbrev;
2307 entry && entry->entry != abbrev_number;
2308 entry = entry->next)
2313 if (!do_loc && do_printing)
2318 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2319 die_offset, abbrev_number);
2323 if (!do_loc && do_printing)
2324 printf (" (%s)\n", get_TAG_name (entry->tag));
2329 need_base_address = 0;
2331 case DW_TAG_compile_unit:
2332 need_base_address = 1;
2334 case DW_TAG_entry_point:
2335 case DW_TAG_subprogram:
2336 need_base_address = 0;
2337 /* Assuming that there is no DW_AT_frame_base. */
2338 have_frame_base = 0;
2342 for (attr = entry->first_attr; attr; attr = attr->next)
2346 if (! do_loc && do_printing)
2347 /* Show the offset from where the tag was extracted. */
2348 printf (" <%lx>", (unsigned long)(tags - section_begin));
2350 arg = debug_information;
2351 if (debug_information)
2354 tags = read_and_display_attr (attr->attribute,
2357 compunit.cu_pointer_size,
2359 compunit.cu_version,
2361 do_loc || ! do_printing, section);
2364 if (entry->children)
2369 /* Set num_debug_info_entries here so that it can be used to check if
2370 we need to process .debug_loc and .debug_ranges sections. */
2371 if ((do_loc || do_debug_loc || do_debug_ranges)
2372 && num_debug_info_entries == 0
2374 num_debug_info_entries = num_units;
2382 /* Locate and scan the .debug_info section in the file and record the pointer
2383 sizes and offsets for the compilation units in it. Usually an executable
2384 will have just one pointer size, but this is not guaranteed, and so we try
2385 not to make any assumptions. Returns zero upon failure, or the number of
2386 compilation units upon success. */
2389 load_debug_info (void * file)
2391 /* Reset the last pointer size so that we can issue correct error
2392 messages if we are displaying the contents of more than one section. */
2393 last_pointer_size = 0;
2394 warned_about_missing_comp_units = FALSE;
2396 /* If we have already tried and failed to load the .debug_info
2397 section then do not bother to repear the task. */
2398 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2401 /* If we already have the information there is nothing else to do. */
2402 if (num_debug_info_entries > 0)
2403 return num_debug_info_entries;
2405 if (load_debug_section (info, file)
2406 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2407 return num_debug_info_entries;
2409 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2414 display_debug_lines_raw (struct dwarf_section *section,
2415 unsigned char *data,
2418 unsigned char *start = section->start;
2420 printf (_("Raw dump of debug contents of section %s:\n\n"),
2425 DWARF2_Internal_LineInfo linfo;
2426 unsigned char *standard_opcodes;
2427 unsigned char *end_of_sequence;
2428 unsigned char *hdrptr;
2429 unsigned long hdroff;
2430 int initial_length_size;
2435 hdroff = hdrptr - start;
2437 /* Check the length of the block. */
2438 linfo.li_length = byte_get (hdrptr, 4);
2441 if (linfo.li_length == 0xffffffff)
2443 /* This section is 64-bit DWARF 3. */
2444 linfo.li_length = byte_get (hdrptr, 8);
2447 initial_length_size = 12;
2452 initial_length_size = 4;
2455 if (linfo.li_length + initial_length_size > section->size)
2458 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2463 /* Check its version number. */
2464 linfo.li_version = byte_get (hdrptr, 2);
2466 if (linfo.li_version != 2
2467 && linfo.li_version != 3
2468 && linfo.li_version != 4)
2470 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2474 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2475 hdrptr += offset_size;
2476 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2478 if (linfo.li_version >= 4)
2480 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2482 if (linfo.li_max_ops_per_insn == 0)
2484 warn (_("Invalid maximum operations per insn.\n"));
2489 linfo.li_max_ops_per_insn = 1;
2490 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2492 linfo.li_line_base = byte_get (hdrptr, 1);
2494 linfo.li_line_range = byte_get (hdrptr, 1);
2496 linfo.li_opcode_base = byte_get (hdrptr, 1);
2499 /* Sign extend the line base field. */
2500 linfo.li_line_base <<= 24;
2501 linfo.li_line_base >>= 24;
2503 printf (_(" Offset: 0x%lx\n"), hdroff);
2504 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2505 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2506 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2507 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2508 if (linfo.li_version >= 4)
2509 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2510 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2511 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2512 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2513 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2515 end_of_sequence = data + linfo.li_length + initial_length_size;
2517 reset_state_machine (linfo.li_default_is_stmt);
2519 /* Display the contents of the Opcodes table. */
2520 standard_opcodes = hdrptr;
2522 printf (_("\n Opcodes:\n"));
2524 for (i = 1; i < linfo.li_opcode_base; i++)
2525 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2527 /* Display the contents of the Directory table. */
2528 data = standard_opcodes + linfo.li_opcode_base - 1;
2531 printf (_("\n The Directory Table is empty.\n"));
2534 printf (_("\n The Directory Table:\n"));
2538 printf (" %s\n", data);
2540 data += strlen ((char *) data) + 1;
2544 /* Skip the NUL at the end of the table. */
2547 /* Display the contents of the File Name table. */
2549 printf (_("\n The File Name Table is empty.\n"));
2552 printf (_("\n The File Name Table:\n"));
2553 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2557 unsigned char *name;
2558 unsigned int bytes_read;
2560 printf (" %d\t", ++state_machine_regs.last_file_entry);
2563 data += strlen ((char *) data) + 1;
2566 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2569 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2572 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2574 printf ("%s\n", name);
2578 /* Skip the NUL at the end of the table. */
2581 /* Now display the statements. */
2582 printf (_("\n Line Number Statements:\n"));
2584 while (data < end_of_sequence)
2586 unsigned char op_code;
2587 dwarf_signed_vma adv;
2589 unsigned int bytes_read;
2593 if (op_code >= linfo.li_opcode_base)
2595 op_code -= linfo.li_opcode_base;
2596 uladv = (op_code / linfo.li_line_range);
2597 if (linfo.li_max_ops_per_insn == 1)
2599 uladv *= linfo.li_min_insn_length;
2600 state_machine_regs.address += uladv;
2601 printf (_(" Special opcode %d: "
2602 "advance Address by %s to 0x%s"),
2603 op_code, dwarf_vmatoa ("u", uladv),
2604 dwarf_vmatoa ("x", state_machine_regs.address));
2608 state_machine_regs.address
2609 += ((state_machine_regs.op_index + uladv)
2610 / linfo.li_max_ops_per_insn)
2611 * linfo.li_min_insn_length;
2612 state_machine_regs.op_index
2613 = (state_machine_regs.op_index + uladv)
2614 % linfo.li_max_ops_per_insn;
2615 printf (_(" Special opcode %d: "
2616 "advance Address by %s to 0x%s[%d]"),
2617 op_code, dwarf_vmatoa ("u", uladv),
2618 dwarf_vmatoa ("x", state_machine_regs.address),
2619 state_machine_regs.op_index);
2621 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2622 state_machine_regs.line += adv;
2623 printf (_(" and Line by %s to %d\n"),
2624 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2626 else switch (op_code)
2628 case DW_LNS_extended_op:
2629 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2633 printf (_(" Copy\n"));
2636 case DW_LNS_advance_pc:
2637 uladv = read_leb128 (data, & bytes_read, 0);
2639 if (linfo.li_max_ops_per_insn == 1)
2641 uladv *= linfo.li_min_insn_length;
2642 state_machine_regs.address += uladv;
2643 printf (_(" Advance PC by %s to 0x%s\n"),
2644 dwarf_vmatoa ("u", uladv),
2645 dwarf_vmatoa ("x", state_machine_regs.address));
2649 state_machine_regs.address
2650 += ((state_machine_regs.op_index + uladv)
2651 / linfo.li_max_ops_per_insn)
2652 * linfo.li_min_insn_length;
2653 state_machine_regs.op_index
2654 = (state_machine_regs.op_index + uladv)
2655 % linfo.li_max_ops_per_insn;
2656 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2657 dwarf_vmatoa ("u", uladv),
2658 dwarf_vmatoa ("x", state_machine_regs.address),
2659 state_machine_regs.op_index);
2663 case DW_LNS_advance_line:
2664 adv = read_sleb128 (data, & bytes_read);
2666 state_machine_regs.line += adv;
2667 printf (_(" Advance Line by %s to %d\n"),
2668 dwarf_vmatoa ("d", adv),
2669 state_machine_regs.line);
2672 case DW_LNS_set_file:
2673 adv = read_leb128 (data, & bytes_read, 0);
2675 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2676 dwarf_vmatoa ("d", adv));
2677 state_machine_regs.file = adv;
2680 case DW_LNS_set_column:
2681 uladv = read_leb128 (data, & bytes_read, 0);
2683 printf (_(" Set column to %s\n"),
2684 dwarf_vmatoa ("u", uladv));
2685 state_machine_regs.column = uladv;
2688 case DW_LNS_negate_stmt:
2689 adv = state_machine_regs.is_stmt;
2691 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2692 state_machine_regs.is_stmt = adv;
2695 case DW_LNS_set_basic_block:
2696 printf (_(" Set basic block\n"));
2697 state_machine_regs.basic_block = 1;
2700 case DW_LNS_const_add_pc:
2701 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2702 if (linfo.li_max_ops_per_insn)
2704 uladv *= linfo.li_min_insn_length;
2705 state_machine_regs.address += uladv;
2706 printf (_(" Advance PC by constant %s to 0x%s\n"),
2707 dwarf_vmatoa ("u", uladv),
2708 dwarf_vmatoa ("x", state_machine_regs.address));
2712 state_machine_regs.address
2713 += ((state_machine_regs.op_index + uladv)
2714 / linfo.li_max_ops_per_insn)
2715 * linfo.li_min_insn_length;
2716 state_machine_regs.op_index
2717 = (state_machine_regs.op_index + uladv)
2718 % linfo.li_max_ops_per_insn;
2719 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2720 dwarf_vmatoa ("u", uladv),
2721 dwarf_vmatoa ("x", state_machine_regs.address),
2722 state_machine_regs.op_index);
2726 case DW_LNS_fixed_advance_pc:
2727 uladv = byte_get (data, 2);
2729 state_machine_regs.address += uladv;
2730 state_machine_regs.op_index = 0;
2731 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2732 dwarf_vmatoa ("u", uladv),
2733 dwarf_vmatoa ("x", state_machine_regs.address));
2736 case DW_LNS_set_prologue_end:
2737 printf (_(" Set prologue_end to true\n"));
2740 case DW_LNS_set_epilogue_begin:
2741 printf (_(" Set epilogue_begin to true\n"));
2744 case DW_LNS_set_isa:
2745 uladv = read_leb128 (data, & bytes_read, 0);
2747 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2751 printf (_(" Unknown opcode %d with operands: "), op_code);
2753 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2755 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2757 i == 1 ? "" : ", ");
2772 unsigned char *name;
2773 unsigned int directory_index;
2774 unsigned int modification_date;
2775 unsigned int length;
2778 /* Output a decoded representation of the .debug_line section. */
2781 display_debug_lines_decoded (struct dwarf_section *section,
2782 unsigned char *data,
2785 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2790 /* This loop amounts to one iteration per compilation unit. */
2791 DWARF2_Internal_LineInfo linfo;
2792 unsigned char *standard_opcodes;
2793 unsigned char *end_of_sequence;
2794 unsigned char *hdrptr;
2795 int initial_length_size;
2798 File_Entry *file_table = NULL;
2799 unsigned char **directory_table = NULL;
2803 /* Extract information from the Line Number Program Header.
2804 (section 6.2.4 in the Dwarf3 doc). */
2806 /* Get the length of this CU's line number information block. */
2807 linfo.li_length = byte_get (hdrptr, 4);
2810 if (linfo.li_length == 0xffffffff)
2812 /* This section is 64-bit DWARF 3. */
2813 linfo.li_length = byte_get (hdrptr, 8);
2816 initial_length_size = 12;
2821 initial_length_size = 4;
2824 if (linfo.li_length + initial_length_size > section->size)
2826 warn (_("The line info appears to be corrupt - "
2827 "the section is too small\n"));
2831 /* Get this CU's Line Number Block version number. */
2832 linfo.li_version = byte_get (hdrptr, 2);
2834 if (linfo.li_version != 2
2835 && linfo.li_version != 3
2836 && linfo.li_version != 4)
2838 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2843 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2844 hdrptr += offset_size;
2845 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2847 if (linfo.li_version >= 4)
2849 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2851 if (linfo.li_max_ops_per_insn == 0)
2853 warn (_("Invalid maximum operations per insn.\n"));
2858 linfo.li_max_ops_per_insn = 1;
2859 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2861 linfo.li_line_base = byte_get (hdrptr, 1);
2863 linfo.li_line_range = byte_get (hdrptr, 1);
2865 linfo.li_opcode_base = byte_get (hdrptr, 1);
2868 /* Sign extend the line base field. */
2869 linfo.li_line_base <<= 24;
2870 linfo.li_line_base >>= 24;
2872 /* Find the end of this CU's Line Number Information Block. */
2873 end_of_sequence = data + linfo.li_length + initial_length_size;
2875 reset_state_machine (linfo.li_default_is_stmt);
2877 /* Save a pointer to the contents of the Opcodes table. */
2878 standard_opcodes = hdrptr;
2880 /* Traverse the Directory table just to count entries. */
2881 data = standard_opcodes + linfo.li_opcode_base - 1;
2884 unsigned int n_directories = 0;
2885 unsigned char *ptr_directory_table = data;
2889 data += strlen ((char *) data) + 1;
2893 /* Go through the directory table again to save the directories. */
2894 directory_table = (unsigned char **)
2895 xmalloc (n_directories * sizeof (unsigned char *));
2898 while (*ptr_directory_table != 0)
2900 directory_table[i] = ptr_directory_table;
2901 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2905 /* Skip the NUL at the end of the table. */
2908 /* Traverse the File Name table just to count the entries. */
2911 unsigned int n_files = 0;
2912 unsigned char *ptr_file_name_table = data;
2916 unsigned int bytes_read;
2918 /* Skip Name, directory index, last modification time and length
2920 data += strlen ((char *) data) + 1;
2921 read_leb128 (data, & bytes_read, 0);
2923 read_leb128 (data, & bytes_read, 0);
2925 read_leb128 (data, & bytes_read, 0);
2931 /* Go through the file table again to save the strings. */
2932 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2935 while (*ptr_file_name_table != 0)
2937 unsigned int bytes_read;
2939 file_table[i].name = ptr_file_name_table;
2940 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2942 /* We are not interested in directory, time or size. */
2943 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2945 ptr_file_name_table += bytes_read;
2946 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2948 ptr_file_name_table += bytes_read;
2949 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2950 ptr_file_name_table += bytes_read;
2955 /* Print the Compilation Unit's name and a header. */
2956 if (directory_table == NULL)
2958 printf (_("CU: %s:\n"), file_table[0].name);
2959 printf (_("File name Line number Starting address\n"));
2963 if (do_wide || strlen ((char *) directory_table[0]) < 76)
2964 printf (_("CU: %s/%s:\n"), directory_table[0],
2965 file_table[0].name);
2967 printf ("%s:\n", file_table[0].name);
2969 printf (_("File name Line number Starting address\n"));
2973 /* Skip the NUL at the end of the table. */
2976 /* This loop iterates through the Dwarf Line Number Program. */
2977 while (data < end_of_sequence)
2979 unsigned char op_code;
2981 unsigned long int uladv;
2982 unsigned int bytes_read;
2983 int is_special_opcode = 0;
2987 if (op_code >= linfo.li_opcode_base)
2989 op_code -= linfo.li_opcode_base;
2990 uladv = (op_code / linfo.li_line_range);
2991 if (linfo.li_max_ops_per_insn == 1)
2993 uladv *= linfo.li_min_insn_length;
2994 state_machine_regs.address += uladv;
2998 state_machine_regs.address
2999 += ((state_machine_regs.op_index + uladv)
3000 / linfo.li_max_ops_per_insn)
3001 * linfo.li_min_insn_length;
3002 state_machine_regs.op_index
3003 = (state_machine_regs.op_index + uladv)
3004 % linfo.li_max_ops_per_insn;
3007 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3008 state_machine_regs.line += adv;
3009 is_special_opcode = 1;
3011 else switch (op_code)
3013 case DW_LNS_extended_op:
3015 unsigned int ext_op_code_len;
3016 unsigned char ext_op_code;
3017 unsigned char *op_code_data = data;
3019 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
3020 op_code_data += bytes_read;
3022 if (ext_op_code_len == 0)
3024 warn (_("badly formed extended line op encountered!\n"));
3027 ext_op_code_len += bytes_read;
3028 ext_op_code = *op_code_data++;
3030 switch (ext_op_code)
3032 case DW_LNE_end_sequence:
3033 reset_state_machine (linfo.li_default_is_stmt);
3035 case DW_LNE_set_address:
3036 state_machine_regs.address =
3037 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
3038 state_machine_regs.op_index = 0;
3040 case DW_LNE_define_file:
3042 unsigned int dir_index = 0;
3044 ++state_machine_regs.last_file_entry;
3045 op_code_data += strlen ((char *) op_code_data) + 1;
3046 dir_index = read_leb128 (op_code_data, & bytes_read, 0);
3047 op_code_data += bytes_read;
3048 read_leb128 (op_code_data, & bytes_read, 0);
3049 op_code_data += bytes_read;
3050 read_leb128 (op_code_data, & bytes_read, 0);
3052 printf ("%s:\n", directory_table[dir_index]);
3056 printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
3059 data += ext_op_code_len;
3065 case DW_LNS_advance_pc:
3066 uladv = read_leb128 (data, & bytes_read, 0);
3068 if (linfo.li_max_ops_per_insn == 1)
3070 uladv *= linfo.li_min_insn_length;
3071 state_machine_regs.address += uladv;
3075 state_machine_regs.address
3076 += ((state_machine_regs.op_index + uladv)
3077 / linfo.li_max_ops_per_insn)
3078 * linfo.li_min_insn_length;
3079 state_machine_regs.op_index
3080 = (state_machine_regs.op_index + uladv)
3081 % linfo.li_max_ops_per_insn;
3085 case DW_LNS_advance_line:
3086 adv = read_sleb128 (data, & bytes_read);
3088 state_machine_regs.line += adv;
3091 case DW_LNS_set_file:
3092 adv = read_leb128 (data, & bytes_read, 0);
3094 state_machine_regs.file = adv;
3095 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3097 /* If directory index is 0, that means current directory. */
3098 printf ("\n./%s:[++]\n",
3099 file_table[state_machine_regs.file - 1].name);
3103 /* The directory index starts counting at 1. */
3104 printf ("\n%s/%s:\n",
3105 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3106 file_table[state_machine_regs.file - 1].name);
3110 case DW_LNS_set_column:
3111 uladv = read_leb128 (data, & bytes_read, 0);
3113 state_machine_regs.column = uladv;
3116 case DW_LNS_negate_stmt:
3117 adv = state_machine_regs.is_stmt;
3119 state_machine_regs.is_stmt = adv;
3122 case DW_LNS_set_basic_block:
3123 state_machine_regs.basic_block = 1;
3126 case DW_LNS_const_add_pc:
3127 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3128 if (linfo.li_max_ops_per_insn == 1)
3130 uladv *= linfo.li_min_insn_length;
3131 state_machine_regs.address += uladv;
3135 state_machine_regs.address
3136 += ((state_machine_regs.op_index + uladv)
3137 / linfo.li_max_ops_per_insn)
3138 * linfo.li_min_insn_length;
3139 state_machine_regs.op_index
3140 = (state_machine_regs.op_index + uladv)
3141 % linfo.li_max_ops_per_insn;
3145 case DW_LNS_fixed_advance_pc:
3146 uladv = byte_get (data, 2);
3148 state_machine_regs.address += uladv;
3149 state_machine_regs.op_index = 0;
3152 case DW_LNS_set_prologue_end:
3155 case DW_LNS_set_epilogue_begin:
3158 case DW_LNS_set_isa:
3159 uladv = read_leb128 (data, & bytes_read, 0);
3161 printf (_(" Set ISA to %lu\n"), uladv);
3165 printf (_(" Unknown opcode %d with operands: "), op_code);
3167 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3169 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3171 i == 1 ? "" : ", ");
3178 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3179 to the DWARF address/line matrix. */
3180 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3181 || (op_code == DW_LNS_copy))
3183 const unsigned int MAX_FILENAME_LENGTH = 35;
3184 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3185 char *newFileName = NULL;
3186 size_t fileNameLength = strlen (fileName);
3188 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3190 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3191 /* Truncate file name */
3192 strncpy (newFileName,
3193 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3194 MAX_FILENAME_LENGTH + 1);
3198 newFileName = (char *) xmalloc (fileNameLength + 1);
3199 strncpy (newFileName, fileName, fileNameLength + 1);
3202 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3204 if (linfo.li_max_ops_per_insn == 1)
3205 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3206 newFileName, state_machine_regs.line,
3207 state_machine_regs.address);
3209 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3210 newFileName, state_machine_regs.line,
3211 state_machine_regs.address,
3212 state_machine_regs.op_index);
3216 if (linfo.li_max_ops_per_insn == 1)
3217 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3218 newFileName, state_machine_regs.line,
3219 state_machine_regs.address);
3221 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3222 newFileName, state_machine_regs.line,
3223 state_machine_regs.address,
3224 state_machine_regs.op_index);
3227 if (op_code == DW_LNE_end_sequence)
3235 free (directory_table);
3236 directory_table = NULL;
3244 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3246 unsigned char *data = section->start;
3247 unsigned char *end = data + section->size;
3249 int retValDecoded = 1;
3251 if (do_debug_lines == 0)
3252 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3254 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3255 retValRaw = display_debug_lines_raw (section, data, end);
3257 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3258 retValDecoded = display_debug_lines_decoded (section, data, end);
3260 if (!retValRaw || !retValDecoded)
3267 find_debug_info_for_offset (unsigned long offset)
3271 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3274 for (i = 0; i < num_debug_info_entries; i++)
3275 if (debug_information[i].cu_offset == offset)
3276 return debug_information + i;
3282 display_debug_pubnames (struct dwarf_section *section,
3283 void *file ATTRIBUTE_UNUSED)
3285 DWARF2_Internal_PubNames names;
3286 unsigned char *start = section->start;
3287 unsigned char *end = start + section->size;
3289 /* It does not matter if this load fails,
3290 we test for that later on. */
3291 load_debug_info (file);
3293 printf (_("Contents of the %s section:\n\n"), section->name);
3297 unsigned char *data;
3298 unsigned long offset;
3299 int offset_size, initial_length_size;
3303 names.pn_length = byte_get (data, 4);
3305 if (names.pn_length == 0xffffffff)
3307 names.pn_length = byte_get (data, 8);
3310 initial_length_size = 12;
3315 initial_length_size = 4;
3318 names.pn_version = byte_get (data, 2);
3321 names.pn_offset = byte_get (data, offset_size);
3322 data += offset_size;
3324 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3325 && num_debug_info_entries > 0
3326 && find_debug_info_for_offset (names.pn_offset) == NULL)
3327 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3328 (unsigned long) names.pn_offset, section->name);
3330 names.pn_size = byte_get (data, offset_size);
3331 data += offset_size;
3333 start += names.pn_length + initial_length_size;
3335 if (names.pn_version != 2 && names.pn_version != 3)
3337 static int warned = 0;
3341 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3348 printf (_(" Length: %ld\n"),
3349 (long) names.pn_length);
3350 printf (_(" Version: %d\n"),
3352 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3353 (unsigned long) names.pn_offset);
3354 printf (_(" Size of area in .debug_info section: %ld\n"),
3355 (long) names.pn_size);
3357 printf (_("\n Offset\tName\n"));
3361 offset = byte_get (data, offset_size);
3365 data += offset_size;
3366 printf (" %-6lx\t%s\n", offset, data);
3367 data += strlen ((char *) data) + 1;
3370 while (offset != 0);
3378 display_debug_macinfo (struct dwarf_section *section,
3379 void *file ATTRIBUTE_UNUSED)
3381 unsigned char *start = section->start;
3382 unsigned char *end = start + section->size;
3383 unsigned char *curr = start;
3384 unsigned int bytes_read;
3385 enum dwarf_macinfo_record_type op;
3387 printf (_("Contents of the %s section:\n\n"), section->name);
3391 unsigned int lineno;
3394 op = (enum dwarf_macinfo_record_type) *curr;
3399 case DW_MACINFO_start_file:
3401 unsigned int filenum;
3403 lineno = read_leb128 (curr, & bytes_read, 0);
3405 filenum = read_leb128 (curr, & bytes_read, 0);
3408 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3413 case DW_MACINFO_end_file:
3414 printf (_(" DW_MACINFO_end_file\n"));
3417 case DW_MACINFO_define:
3418 lineno = read_leb128 (curr, & bytes_read, 0);
3420 string = (char *) curr;
3421 curr += strlen (string) + 1;
3422 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3426 case DW_MACINFO_undef:
3427 lineno = read_leb128 (curr, & bytes_read, 0);
3429 string = (char *) curr;
3430 curr += strlen (string) + 1;
3431 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3435 case DW_MACINFO_vendor_ext:
3437 unsigned int constant;
3439 constant = read_leb128 (curr, & bytes_read, 0);
3441 string = (char *) curr;
3442 curr += strlen (string) + 1;
3443 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3454 display_debug_abbrev (struct dwarf_section *section,
3455 void *file ATTRIBUTE_UNUSED)
3457 abbrev_entry *entry;
3458 unsigned char *start = section->start;
3459 unsigned char *end = start + section->size;
3461 printf (_("Contents of the %s section:\n\n"), section->name);
3467 start = process_abbrev_section (start, end);
3469 if (first_abbrev == NULL)
3472 printf (_(" Number TAG\n"));
3474 for (entry = first_abbrev; entry; entry = entry->next)
3478 printf (" %ld %s [%s]\n",
3480 get_TAG_name (entry->tag),
3481 entry->children ? _("has children") : _("no children"));
3483 for (attr = entry->first_attr; attr; attr = attr->next)
3484 printf (" %-18s %s\n",
3485 get_AT_name (attr->attribute),
3486 get_FORM_name (attr->form));
3496 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3498 static dwarf_vma *loc_offsets;
3501 loc_offsets_compar (const void *ap, const void *bp)
3503 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
3504 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
3506 return (a > b) - (b > a);
3510 display_debug_loc (struct dwarf_section *section, void *file)
3512 unsigned char *start = section->start;
3513 unsigned char *section_end;
3514 unsigned long bytes;
3515 unsigned char *section_begin = start;
3516 unsigned int num_loc_list = 0;
3517 unsigned long last_offset = 0;
3518 unsigned int first = 0;
3522 int seen_first_offset = 0;
3523 int locs_sorted = 1;
3524 unsigned char *next;
3525 unsigned int *array = NULL;
3527 bytes = section->size;
3528 section_end = start + bytes;
3532 printf (_("\nThe %s section is empty.\n"), section->name);
3536 if (load_debug_info (file) == 0)
3538 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3543 /* Check the order of location list in .debug_info section. If
3544 offsets of location lists are in the ascending order, we can
3545 use `debug_information' directly. */
3546 for (i = 0; i < num_debug_info_entries; i++)
3550 num = debug_information [i].num_loc_offsets;
3551 if (num > num_loc_list)
3554 /* Check if we can use `debug_information' directly. */
3555 if (locs_sorted && num != 0)
3557 if (!seen_first_offset)
3559 /* This is the first location list. */
3560 last_offset = debug_information [i].loc_offsets [0];
3562 seen_first_offset = 1;
3568 for (; j < num; j++)
3571 debug_information [i].loc_offsets [j])
3576 last_offset = debug_information [i].loc_offsets [j];
3581 if (!seen_first_offset)
3582 error (_("No location lists in .debug_info section!\n"));
3584 /* DWARF sections under Mach-O have non-zero addresses. */
3585 if (debug_information [first].num_loc_offsets > 0
3586 && debug_information [first].loc_offsets [0] != section->address)
3587 warn (_("Location lists in %s section start at 0x%s\n"),
3589 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
3592 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
3593 printf (_("Contents of the %s section:\n\n"), section->name);
3594 printf (_(" Offset Begin End Expression\n"));
3596 seen_first_offset = 0;
3597 for (i = first; i < num_debug_info_entries; i++)
3601 unsigned short length;
3602 unsigned long offset;
3603 unsigned int pointer_size;
3604 unsigned int offset_size;
3606 unsigned long cu_offset;
3607 unsigned long base_address;
3608 int need_frame_base;
3611 pointer_size = debug_information [i].pointer_size;
3612 cu_offset = debug_information [i].cu_offset;
3613 offset_size = debug_information [i].offset_size;
3614 dwarf_version = debug_information [i].dwarf_version;
3617 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
3619 loc_offsets = debug_information [i].loc_offsets;
3620 qsort (array, debug_information [i].num_loc_offsets,
3621 sizeof (*array), loc_offsets_compar);
3624 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
3626 j = locs_sorted ? k : array[k];
3628 && debug_information [i].loc_offsets [locs_sorted
3629 ? k - 1 : array [k - 1]]
3630 == debug_information [i].loc_offsets [j])
3632 has_frame_base = debug_information [i].have_frame_base [j];
3633 /* DWARF sections under Mach-O have non-zero addresses. */
3634 offset = debug_information [i].loc_offsets [j] - section->address;
3635 next = section_begin + offset;
3636 base_address = debug_information [i].base_address;
3638 if (!seen_first_offset)
3639 seen_first_offset = 1;
3643 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3644 (unsigned long) (start - section_begin),
3645 (unsigned long) (next - section_begin));
3646 else if (start > next)
3647 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3648 (unsigned long) (start - section_begin),
3649 (unsigned long) (next - section_begin));
3653 if (offset >= bytes)
3655 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3662 if (start + 2 * pointer_size > section_end)
3664 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3669 /* Note: we use sign extension here in order to be sure that
3670 we can detect the -1 escape value. Sign extension into the
3671 top 32 bits of a 32-bit address will not affect the values
3672 that we display since we always show hex values, and always
3673 the bottom 32-bits. */
3674 begin = byte_get_signed (start, pointer_size);
3675 start += pointer_size;
3676 end = byte_get_signed (start, pointer_size);
3677 start += pointer_size;
3679 printf (" %8.8lx ", offset);
3681 if (begin == 0 && end == 0)
3683 printf (_("<End of list>\n"));
3687 /* Check base address specifiers. */
3688 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3691 print_dwarf_vma (begin, pointer_size);
3692 print_dwarf_vma (end, pointer_size);
3693 printf (_("(base address)\n"));
3697 if (start + 2 > section_end)
3699 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3704 length = byte_get (start, 2);
3707 if (start + length > section_end)
3709 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3714 print_dwarf_vma (begin + base_address, pointer_size);
3715 print_dwarf_vma (end + base_address, pointer_size);
3718 need_frame_base = decode_location_expression (start,
3723 cu_offset, section);
3726 if (need_frame_base && !has_frame_base)
3727 printf (_(" [without DW_AT_frame_base]"));
3730 fputs (_(" (start == end)"), stdout);
3731 else if (begin > end)
3732 fputs (_(" (start > end)"), stdout);
3741 if (start < section_end)
3742 warn (_("There are %ld unused bytes at the end of section %s\n"),
3743 (long) (section_end - start), section->name);
3750 display_debug_str (struct dwarf_section *section,
3751 void *file ATTRIBUTE_UNUSED)
3753 unsigned char *start = section->start;
3754 unsigned long bytes = section->size;
3755 dwarf_vma addr = section->address;
3759 printf (_("\nThe %s section is empty.\n"), section->name);
3763 printf (_("Contents of the %s section:\n\n"), section->name);
3771 lbytes = (bytes > 16 ? 16 : bytes);
3773 printf (" 0x%8.8lx ", (unsigned long) addr);
3775 for (j = 0; j < 16; j++)
3778 printf ("%2.2x", start[j]);
3786 for (j = 0; j < lbytes; j++)
3789 if (k >= ' ' && k < 0x80)
3808 display_debug_info (struct dwarf_section *section, void *file)
3810 return process_debug_info (section, file, abbrev, 0, 0);
3814 display_debug_types (struct dwarf_section *section, void *file)
3816 return process_debug_info (section, file, abbrev, 0, 1);
3820 display_trace_info (struct dwarf_section *section, void *file)
3822 return process_debug_info (section, file, trace_abbrev, 0, 0);
3826 display_debug_aranges (struct dwarf_section *section,
3827 void *file ATTRIBUTE_UNUSED)
3829 unsigned char *start = section->start;
3830 unsigned char *end = start + section->size;
3832 printf (_("Contents of the %s section:\n\n"), section->name);
3834 /* It does not matter if this load fails,
3835 we test for that later on. */
3836 load_debug_info (file);
3840 unsigned char *hdrptr;
3841 DWARF2_Internal_ARange arange;
3842 unsigned char *addr_ranges;
3845 unsigned char address_size;
3848 int initial_length_size;
3852 arange.ar_length = byte_get (hdrptr, 4);
3855 if (arange.ar_length == 0xffffffff)
3857 arange.ar_length = byte_get (hdrptr, 8);
3860 initial_length_size = 12;
3865 initial_length_size = 4;
3868 arange.ar_version = byte_get (hdrptr, 2);
3871 arange.ar_info_offset = byte_get (hdrptr, offset_size);
3872 hdrptr += offset_size;
3874 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3875 && num_debug_info_entries > 0
3876 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
3877 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3878 (unsigned long) arange.ar_info_offset, section->name);
3880 arange.ar_pointer_size = byte_get (hdrptr, 1);
3883 arange.ar_segment_size = byte_get (hdrptr, 1);
3886 if (arange.ar_version != 2 && arange.ar_version != 3)
3888 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3892 printf (_(" Length: %ld\n"),
3893 (long) arange.ar_length);
3894 printf (_(" Version: %d\n"), arange.ar_version);
3895 printf (_(" Offset into .debug_info: 0x%lx\n"),
3896 (unsigned long) arange.ar_info_offset);
3897 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
3898 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
3900 address_size = arange.ar_pointer_size + arange.ar_segment_size;
3902 /* The DWARF spec does not require that the address size be a power
3903 of two, but we do. This will have to change if we ever encounter
3904 an uneven architecture. */
3905 if ((address_size & (address_size - 1)) != 0)
3907 warn (_("Pointer size + Segment size is not a power of two.\n"));
3911 if (address_size > 4)
3912 printf (_("\n Address Length\n"));
3914 printf (_("\n Address Length\n"));
3916 addr_ranges = hdrptr;
3918 /* Must pad to an alignment boundary that is twice the address size. */
3919 excess = (hdrptr - start) % (2 * address_size);
3921 addr_ranges += (2 * address_size) - excess;
3923 start += arange.ar_length + initial_length_size;
3925 while (addr_ranges + 2 * address_size <= start)
3927 address = byte_get (addr_ranges, address_size);
3929 addr_ranges += address_size;
3931 length = byte_get (addr_ranges, address_size);
3933 addr_ranges += address_size;
3936 print_dwarf_vma (address, address_size);
3937 print_dwarf_vma (length, address_size);
3947 /* Each debug_information[x].range_lists[y] gets this representation for
3948 sorting purposes. */
3952 /* The debug_information[x].range_lists[y] value. */
3953 unsigned long ranges_offset;
3955 /* Original debug_information to find parameters of the data. */
3956 debug_info *debug_info_p;
3959 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3962 range_entry_compar (const void *ap, const void *bp)
3964 const struct range_entry *a_re = (const struct range_entry *) ap;
3965 const struct range_entry *b_re = (const struct range_entry *) bp;
3966 const unsigned long a = a_re->ranges_offset;
3967 const unsigned long b = b_re->ranges_offset;
3969 return (a > b) - (b > a);
3973 display_debug_ranges (struct dwarf_section *section,
3974 void *file ATTRIBUTE_UNUSED)
3976 unsigned char *start = section->start;
3977 unsigned long bytes;
3978 unsigned char *section_begin = start;
3979 unsigned int num_range_list, i;
3980 struct range_entry *range_entries, *range_entry_fill;
3982 bytes = section->size;
3986 printf (_("\nThe %s section is empty.\n"), section->name);
3990 if (load_debug_info (file) == 0)
3992 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3998 for (i = 0; i < num_debug_info_entries; i++)
3999 num_range_list += debug_information [i].num_range_lists;
4001 if (num_range_list == 0)
4002 error (_("No range lists in .debug_info section!\n"));
4004 range_entries = (struct range_entry *)
4005 xmalloc (sizeof (*range_entries) * num_range_list);
4006 range_entry_fill = range_entries;
4008 for (i = 0; i < num_debug_info_entries; i++)
4010 debug_info *debug_info_p = &debug_information[i];
4013 for (j = 0; j < debug_info_p->num_range_lists; j++)
4015 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4016 range_entry_fill->debug_info_p = debug_info_p;
4021 qsort (range_entries, num_range_list, sizeof (*range_entries),
4022 range_entry_compar);
4024 /* DWARF sections under Mach-O have non-zero addresses. */
4025 if (range_entries[0].ranges_offset != section->address)
4026 warn (_("Range lists in %s section start at 0x%lx\n"),
4027 section->name, range_entries[0].ranges_offset);
4029 printf (_("Contents of the %s section:\n\n"), section->name);
4030 printf (_(" Offset Begin End\n"));
4032 for (i = 0; i < num_range_list; i++)
4034 struct range_entry *range_entry = &range_entries[i];
4035 debug_info *debug_info_p = range_entry->debug_info_p;
4036 unsigned int pointer_size;
4037 unsigned long offset;
4038 unsigned char *next;
4039 unsigned long base_address;
4041 pointer_size = debug_info_p->pointer_size;
4043 /* DWARF sections under Mach-O have non-zero addresses. */
4044 offset = range_entry->ranges_offset - section->address;
4045 next = section_begin + offset;
4046 base_address = debug_info_p->base_address;
4051 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4052 (unsigned long) (start - section_begin),
4053 (unsigned long) (next - section_begin), section->name);
4054 else if (start > next)
4055 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4056 (unsigned long) (start - section_begin),
4057 (unsigned long) (next - section_begin), section->name);
4066 /* Note: we use sign extension here in order to be sure that
4067 we can detect the -1 escape value. Sign extension into the
4068 top 32 bits of a 32-bit address will not affect the values
4069 that we display since we always show hex values, and always
4070 the bottom 32-bits. */
4071 begin = byte_get_signed (start, pointer_size);
4072 start += pointer_size;
4073 end = byte_get_signed (start, pointer_size);
4074 start += pointer_size;
4076 printf (" %8.8lx ", offset);
4078 if (begin == 0 && end == 0)
4080 printf (_("<End of list>\n"));
4084 /* Check base address specifiers. */
4085 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4088 print_dwarf_vma (begin, pointer_size);
4089 print_dwarf_vma (end, pointer_size);
4090 printf ("(base address)\n");
4094 print_dwarf_vma (begin + base_address, pointer_size);
4095 print_dwarf_vma (end + base_address, pointer_size);
4098 fputs (_("(start == end)"), stdout);
4099 else if (begin > end)
4100 fputs (_("(start > end)"), stdout);
4107 free (range_entries);
4112 typedef struct Frame_Chunk
4114 struct Frame_Chunk *next;
4115 unsigned char *chunk_start;
4117 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4118 short int *col_type;
4121 unsigned int code_factor;
4123 unsigned long pc_begin;
4124 unsigned long pc_range;
4128 unsigned char fde_encoding;
4129 unsigned char cfa_exp;
4130 unsigned char ptr_size;
4131 unsigned char segment_size;
4135 static const char *const *dwarf_regnames;
4136 static unsigned int dwarf_regnames_count;
4138 /* A marker for a col_type that means this column was never referenced
4139 in the frame info. */
4140 #define DW_CFA_unreferenced (-1)
4142 /* Return 0 if not more space is needed, 1 if more space is needed,
4143 -1 for invalid reg. */
4146 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4148 int prev = fc->ncols;
4150 if (reg < (unsigned int) fc->ncols)
4153 if (dwarf_regnames_count
4154 && reg > dwarf_regnames_count)
4157 fc->ncols = reg + 1;
4158 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4159 sizeof (short int));
4160 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4162 while (prev < fc->ncols)
4164 fc->col_type[prev] = DW_CFA_unreferenced;
4165 fc->col_offset[prev] = 0;
4171 static const char *const dwarf_regnames_i386[] =
4173 "eax", "ecx", "edx", "ebx",
4174 "esp", "ebp", "esi", "edi",
4175 "eip", "eflags", NULL,
4176 "st0", "st1", "st2", "st3",
4177 "st4", "st5", "st6", "st7",
4179 "xmm0", "xmm1", "xmm2", "xmm3",
4180 "xmm4", "xmm5", "xmm6", "xmm7",
4181 "mm0", "mm1", "mm2", "mm3",
4182 "mm4", "mm5", "mm6", "mm7",
4183 "fcw", "fsw", "mxcsr",
4184 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4189 init_dwarf_regnames_i386 (void)
4191 dwarf_regnames = dwarf_regnames_i386;
4192 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4195 static const char *const dwarf_regnames_x86_64[] =
4197 "rax", "rdx", "rcx", "rbx",
4198 "rsi", "rdi", "rbp", "rsp",
4199 "r8", "r9", "r10", "r11",
4200 "r12", "r13", "r14", "r15",
4202 "xmm0", "xmm1", "xmm2", "xmm3",
4203 "xmm4", "xmm5", "xmm6", "xmm7",
4204 "xmm8", "xmm9", "xmm10", "xmm11",
4205 "xmm12", "xmm13", "xmm14", "xmm15",
4206 "st0", "st1", "st2", "st3",
4207 "st4", "st5", "st6", "st7",
4208 "mm0", "mm1", "mm2", "mm3",
4209 "mm4", "mm5", "mm6", "mm7",
4211 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4212 "fs.base", "gs.base", NULL, NULL,
4214 "mxcsr", "fcw", "fsw"
4218 init_dwarf_regnames_x86_64 (void)
4220 dwarf_regnames = dwarf_regnames_x86_64;
4221 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4225 init_dwarf_regnames (unsigned int e_machine)
4231 init_dwarf_regnames_i386 ();
4236 init_dwarf_regnames_x86_64 ();
4245 regname (unsigned int regno, int row)
4247 static char reg[64];
4249 && regno < dwarf_regnames_count
4250 && dwarf_regnames [regno] != NULL)
4253 return dwarf_regnames [regno];
4254 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4255 dwarf_regnames [regno]);
4258 snprintf (reg, sizeof (reg), "r%d", regno);
4263 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4268 if (*max_regs < fc->ncols)
4269 *max_regs = fc->ncols;
4271 if (*need_col_headers)
4273 static const char *sloc = " LOC";
4275 *need_col_headers = 0;
4277 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4279 for (r = 0; r < *max_regs; r++)
4280 if (fc->col_type[r] != DW_CFA_unreferenced)
4285 printf ("%-5s ", regname (r, 1));
4291 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4293 strcpy (tmp, "exp");
4295 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4296 printf ("%-8s ", tmp);
4298 for (r = 0; r < fc->ncols; r++)
4300 if (fc->col_type[r] != DW_CFA_unreferenced)
4302 switch (fc->col_type[r])
4304 case DW_CFA_undefined:
4307 case DW_CFA_same_value:
4311 sprintf (tmp, "c%+d", fc->col_offset[r]);
4313 case DW_CFA_val_offset:
4314 sprintf (tmp, "v%+d", fc->col_offset[r]);
4316 case DW_CFA_register:
4317 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4319 case DW_CFA_expression:
4320 strcpy (tmp, "exp");
4322 case DW_CFA_val_expression:
4323 strcpy (tmp, "vexp");
4326 strcpy (tmp, "n/a");
4329 printf ("%-5s ", tmp);
4335 #define GET(N) byte_get (start, N); start += N
4336 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4337 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4340 display_debug_frames (struct dwarf_section *section,
4341 void *file ATTRIBUTE_UNUSED)
4343 unsigned char *start = section->start;
4344 unsigned char *end = start + section->size;
4345 unsigned char *section_start = start;
4346 Frame_Chunk *chunks = 0;
4347 Frame_Chunk *remembered_state = 0;
4349 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4350 unsigned int length_return;
4352 const char *bad_reg = _("bad register: ");
4353 int saved_eh_addr_size = eh_addr_size;
4355 printf (_("Contents of the %s section:\n"), section->name);
4359 unsigned char *saved_start;
4360 unsigned char *block_end;
4361 unsigned long length;
4362 unsigned long cie_id;
4365 int need_col_headers = 1;
4366 unsigned char *augmentation_data = NULL;
4367 unsigned long augmentation_data_len = 0;
4368 int encoded_ptr_size = saved_eh_addr_size;
4370 int initial_length_size;
4372 saved_start = start;
4373 length = byte_get (start, 4); start += 4;
4377 printf ("\n%08lx ZERO terminator\n\n",
4378 (unsigned long)(saved_start - section_start));
4382 if (length == 0xffffffff)
4384 length = byte_get (start, 8);
4387 initial_length_size = 12;
4392 initial_length_size = 4;
4395 block_end = saved_start + length + initial_length_size;
4396 if (block_end > end)
4398 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4399 length, (unsigned long)(saved_start - section_start));
4402 cie_id = byte_get (start, offset_size); start += offset_size;
4404 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4408 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4409 memset (fc, 0, sizeof (Frame_Chunk));
4413 fc->chunk_start = saved_start;
4415 fc->col_type = (short int *) xmalloc (sizeof (short int));
4416 fc->col_offset = (int *) xmalloc (sizeof (int));
4417 frame_need_space (fc, max_regs - 1);
4421 fc->augmentation = (char *) start;
4422 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4424 if (strcmp (fc->augmentation, "eh") == 0)
4425 start += eh_addr_size;
4429 fc->ptr_size = GET (1);
4430 fc->segment_size = GET (1);
4431 eh_addr_size = fc->ptr_size;
4435 fc->ptr_size = eh_addr_size;
4436 fc->segment_size = 0;
4438 fc->code_factor = LEB ();
4439 fc->data_factor = SLEB ();
4449 if (fc->augmentation[0] == 'z')
4451 augmentation_data_len = LEB ();
4452 augmentation_data = start;
4453 start += augmentation_data_len;
4457 if (do_debug_frames_interp)
4458 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4459 (unsigned long)(saved_start - section_start), length, cie_id,
4460 fc->augmentation, fc->code_factor, fc->data_factor,
4464 printf ("\n%08lx %08lx %08lx CIE\n",
4465 (unsigned long)(saved_start - section_start), length, cie_id);
4466 printf (" Version: %d\n", version);
4467 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4470 printf (" Pointer Size: %u\n", fc->ptr_size);
4471 printf (" Segment Size: %u\n", fc->segment_size);
4473 printf (" Code alignment factor: %u\n", fc->code_factor);
4474 printf (" Data alignment factor: %d\n", fc->data_factor);
4475 printf (" Return address column: %d\n", fc->ra);
4477 if (augmentation_data_len)
4480 printf (" Augmentation data: ");
4481 for (i = 0; i < augmentation_data_len; ++i)
4482 printf (" %02x", augmentation_data[i]);
4488 if (augmentation_data_len)
4490 unsigned char *p, *q;
4491 p = (unsigned char *) fc->augmentation + 1;
4492 q = augmentation_data;
4499 q += 1 + size_of_encoded_value (*q);
4501 fc->fde_encoding = *q++;
4509 if (fc->fde_encoding)
4510 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4513 frame_need_space (fc, fc->ra);
4517 unsigned char *look_for;
4518 static Frame_Chunk fde_fc;
4519 unsigned long segment_selector;
4522 memset (fc, 0, sizeof (Frame_Chunk));
4524 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
4526 for (cie = chunks; cie ; cie = cie->next)
4527 if (cie->chunk_start == look_for)
4532 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4533 cie_id, (unsigned long)(saved_start - section_start));
4535 fc->col_type = (short int *) xmalloc (sizeof (short int));
4536 fc->col_offset = (int *) xmalloc (sizeof (int));
4537 frame_need_space (fc, max_regs - 1);
4539 fc->augmentation = "";
4540 fc->fde_encoding = 0;
4541 fc->ptr_size = eh_addr_size;
4542 fc->segment_size = 0;
4546 fc->ncols = cie->ncols;
4547 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
4548 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
4549 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
4550 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
4551 fc->augmentation = cie->augmentation;
4552 fc->ptr_size = cie->ptr_size;
4553 eh_addr_size = cie->ptr_size;
4554 fc->segment_size = cie->segment_size;
4555 fc->code_factor = cie->code_factor;
4556 fc->data_factor = cie->data_factor;
4557 fc->cfa_reg = cie->cfa_reg;
4558 fc->cfa_offset = cie->cfa_offset;
4560 frame_need_space (fc, max_regs - 1);
4561 fc->fde_encoding = cie->fde_encoding;
4564 if (fc->fde_encoding)
4565 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4567 segment_selector = 0;
4568 if (fc->segment_size)
4570 segment_selector = byte_get (start, fc->segment_size);
4571 start += fc->segment_size;
4573 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
4574 start += encoded_ptr_size;
4575 fc->pc_range = byte_get (start, encoded_ptr_size);
4576 start += encoded_ptr_size;
4578 if (cie->augmentation[0] == 'z')
4580 augmentation_data_len = LEB ();
4581 augmentation_data = start;
4582 start += augmentation_data_len;
4585 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4586 (unsigned long)(saved_start - section_start), length, cie_id,
4587 (unsigned long)(cie->chunk_start - section_start));
4588 if (fc->segment_size)
4589 printf ("%04lx:", segment_selector);
4590 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
4591 if (! do_debug_frames_interp && augmentation_data_len)
4595 printf (" Augmentation data: ");
4596 for (i = 0; i < augmentation_data_len; ++i)
4597 printf (" %02x", augmentation_data[i]);
4603 /* At this point, fc is the current chunk, cie (if any) is set, and
4604 we're about to interpret instructions for the chunk. */
4605 /* ??? At present we need to do this always, since this sizes the
4606 fc->col_type and fc->col_offset arrays, which we write into always.
4607 We should probably split the interpreted and non-interpreted bits
4608 into two different routines, since there's so much that doesn't
4609 really overlap between them. */
4610 if (1 || do_debug_frames_interp)
4612 /* Start by making a pass over the chunk, allocating storage
4613 and taking note of what registers are used. */
4614 unsigned char *tmp = start;
4616 while (start < block_end)
4619 unsigned long reg, temp;
4626 /* Warning: if you add any more cases to this switch, be
4627 sure to add them to the corresponding switch below. */
4630 case DW_CFA_advance_loc:
4634 if (frame_need_space (fc, opa) >= 0)
4635 fc->col_type[opa] = DW_CFA_undefined;
4637 case DW_CFA_restore:
4638 if (frame_need_space (fc, opa) >= 0)
4639 fc->col_type[opa] = DW_CFA_undefined;
4641 case DW_CFA_set_loc:
4642 start += encoded_ptr_size;
4644 case DW_CFA_advance_loc1:
4647 case DW_CFA_advance_loc2:
4650 case DW_CFA_advance_loc4:
4653 case DW_CFA_offset_extended:
4654 case DW_CFA_val_offset:
4655 reg = LEB (); LEB ();
4656 if (frame_need_space (fc, reg) >= 0)
4657 fc->col_type[reg] = DW_CFA_undefined;
4659 case DW_CFA_restore_extended:
4661 frame_need_space (fc, reg);
4662 if (frame_need_space (fc, reg) >= 0)
4663 fc->col_type[reg] = DW_CFA_undefined;
4665 case DW_CFA_undefined:
4667 if (frame_need_space (fc, reg) >= 0)
4668 fc->col_type[reg] = DW_CFA_undefined;
4670 case DW_CFA_same_value:
4672 if (frame_need_space (fc, reg) >= 0)
4673 fc->col_type[reg] = DW_CFA_undefined;
4675 case DW_CFA_register:
4676 reg = LEB (); LEB ();
4677 if (frame_need_space (fc, reg) >= 0)
4678 fc->col_type[reg] = DW_CFA_undefined;
4680 case DW_CFA_def_cfa:
4683 case DW_CFA_def_cfa_register:
4686 case DW_CFA_def_cfa_offset:
4689 case DW_CFA_def_cfa_expression:
4693 case DW_CFA_expression:
4694 case DW_CFA_val_expression:
4698 if (frame_need_space (fc, reg) >= 0)
4699 fc->col_type[reg] = DW_CFA_undefined;
4701 case DW_CFA_offset_extended_sf:
4702 case DW_CFA_val_offset_sf:
4703 reg = LEB (); SLEB ();
4704 if (frame_need_space (fc, reg) >= 0)
4705 fc->col_type[reg] = DW_CFA_undefined;
4707 case DW_CFA_def_cfa_sf:
4710 case DW_CFA_def_cfa_offset_sf:
4713 case DW_CFA_MIPS_advance_loc8:
4716 case DW_CFA_GNU_args_size:
4719 case DW_CFA_GNU_negative_offset_extended:
4720 reg = LEB (); LEB ();
4721 if (frame_need_space (fc, reg) >= 0)
4722 fc->col_type[reg] = DW_CFA_undefined;
4731 /* Now we know what registers are used, make a second pass over
4732 the chunk, this time actually printing out the info. */
4734 while (start < block_end)
4737 unsigned long ul, reg, roffs;
4740 const char *reg_prefix = "";
4747 /* Warning: if you add any more cases to this switch, be
4748 sure to add them to the corresponding switch above. */
4751 case DW_CFA_advance_loc:
4752 if (do_debug_frames_interp)
4753 frame_display_row (fc, &need_col_headers, &max_regs);
4755 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4756 opa * fc->code_factor,
4757 fc->pc_begin + opa * fc->code_factor);
4758 fc->pc_begin += opa * fc->code_factor;
4763 if (opa >= (unsigned int) fc->ncols)
4764 reg_prefix = bad_reg;
4765 if (! do_debug_frames_interp || *reg_prefix != '\0')
4766 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4767 reg_prefix, regname (opa, 0),
4768 roffs * fc->data_factor);
4769 if (*reg_prefix == '\0')
4771 fc->col_type[opa] = DW_CFA_offset;
4772 fc->col_offset[opa] = roffs * fc->data_factor;
4776 case DW_CFA_restore:
4777 if (opa >= (unsigned int) cie->ncols
4778 || opa >= (unsigned int) fc->ncols)
4779 reg_prefix = bad_reg;
4780 if (! do_debug_frames_interp || *reg_prefix != '\0')
4781 printf (" DW_CFA_restore: %s%s\n",
4782 reg_prefix, regname (opa, 0));
4783 if (*reg_prefix == '\0')
4785 fc->col_type[opa] = cie->col_type[opa];
4786 fc->col_offset[opa] = cie->col_offset[opa];
4790 case DW_CFA_set_loc:
4791 vma = get_encoded_value (start, fc->fde_encoding, section);
4792 start += encoded_ptr_size;
4793 if (do_debug_frames_interp)
4794 frame_display_row (fc, &need_col_headers, &max_regs);
4796 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
4800 case DW_CFA_advance_loc1:
4801 ofs = byte_get (start, 1); start += 1;
4802 if (do_debug_frames_interp)
4803 frame_display_row (fc, &need_col_headers, &max_regs);
4805 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4806 ofs * fc->code_factor,
4807 fc->pc_begin + ofs * fc->code_factor);
4808 fc->pc_begin += ofs * fc->code_factor;
4811 case DW_CFA_advance_loc2:
4812 ofs = byte_get (start, 2); start += 2;
4813 if (do_debug_frames_interp)
4814 frame_display_row (fc, &need_col_headers, &max_regs);
4816 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4817 ofs * fc->code_factor,
4818 fc->pc_begin + ofs * fc->code_factor);
4819 fc->pc_begin += ofs * fc->code_factor;
4822 case DW_CFA_advance_loc4:
4823 ofs = byte_get (start, 4); start += 4;
4824 if (do_debug_frames_interp)
4825 frame_display_row (fc, &need_col_headers, &max_regs);
4827 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4828 ofs * fc->code_factor,
4829 fc->pc_begin + ofs * fc->code_factor);
4830 fc->pc_begin += ofs * fc->code_factor;
4833 case DW_CFA_offset_extended:
4836 if (reg >= (unsigned int) fc->ncols)
4837 reg_prefix = bad_reg;
4838 if (! do_debug_frames_interp || *reg_prefix != '\0')
4839 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4840 reg_prefix, regname (reg, 0),
4841 roffs * fc->data_factor);
4842 if (*reg_prefix == '\0')
4844 fc->col_type[reg] = DW_CFA_offset;
4845 fc->col_offset[reg] = roffs * fc->data_factor;
4849 case DW_CFA_val_offset:
4852 if (reg >= (unsigned int) fc->ncols)
4853 reg_prefix = bad_reg;
4854 if (! do_debug_frames_interp || *reg_prefix != '\0')
4855 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4856 reg_prefix, regname (reg, 0),
4857 roffs * fc->data_factor);
4858 if (*reg_prefix == '\0')
4860 fc->col_type[reg] = DW_CFA_val_offset;
4861 fc->col_offset[reg] = roffs * fc->data_factor;
4865 case DW_CFA_restore_extended:
4867 if (reg >= (unsigned int) cie->ncols
4868 || reg >= (unsigned int) fc->ncols)
4869 reg_prefix = bad_reg;
4870 if (! do_debug_frames_interp || *reg_prefix != '\0')
4871 printf (" DW_CFA_restore_extended: %s%s\n",
4872 reg_prefix, regname (reg, 0));
4873 if (*reg_prefix == '\0')
4875 fc->col_type[reg] = cie->col_type[reg];
4876 fc->col_offset[reg] = cie->col_offset[reg];
4880 case DW_CFA_undefined:
4882 if (reg >= (unsigned int) fc->ncols)
4883 reg_prefix = bad_reg;
4884 if (! do_debug_frames_interp || *reg_prefix != '\0')
4885 printf (" DW_CFA_undefined: %s%s\n",
4886 reg_prefix, regname (reg, 0));
4887 if (*reg_prefix == '\0')
4889 fc->col_type[reg] = DW_CFA_undefined;
4890 fc->col_offset[reg] = 0;
4894 case DW_CFA_same_value:
4896 if (reg >= (unsigned int) fc->ncols)
4897 reg_prefix = bad_reg;
4898 if (! do_debug_frames_interp || *reg_prefix != '\0')
4899 printf (" DW_CFA_same_value: %s%s\n",
4900 reg_prefix, regname (reg, 0));
4901 if (*reg_prefix == '\0')
4903 fc->col_type[reg] = DW_CFA_same_value;
4904 fc->col_offset[reg] = 0;
4908 case DW_CFA_register:
4911 if (reg >= (unsigned int) fc->ncols)
4912 reg_prefix = bad_reg;
4913 if (! do_debug_frames_interp || *reg_prefix != '\0')
4915 printf (" DW_CFA_register: %s%s in ",
4916 reg_prefix, regname (reg, 0));
4917 puts (regname (roffs, 0));
4919 if (*reg_prefix == '\0')
4921 fc->col_type[reg] = DW_CFA_register;
4922 fc->col_offset[reg] = roffs;
4926 case DW_CFA_remember_state:
4927 if (! do_debug_frames_interp)
4928 printf (" DW_CFA_remember_state\n");
4929 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4930 rs->ncols = fc->ncols;
4931 rs->col_type = (short int *) xcmalloc (rs->ncols,
4932 sizeof (short int));
4933 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
4934 memcpy (rs->col_type, fc->col_type, rs->ncols);
4935 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
4936 rs->next = remembered_state;
4937 remembered_state = rs;
4940 case DW_CFA_restore_state:
4941 if (! do_debug_frames_interp)
4942 printf (" DW_CFA_restore_state\n");
4943 rs = remembered_state;
4946 remembered_state = rs->next;
4947 frame_need_space (fc, rs->ncols - 1);
4948 memcpy (fc->col_type, rs->col_type, rs->ncols);
4949 memcpy (fc->col_offset, rs->col_offset,
4950 rs->ncols * sizeof (int));
4951 free (rs->col_type);
4952 free (rs->col_offset);
4955 else if (do_debug_frames_interp)
4956 printf ("Mismatched DW_CFA_restore_state\n");
4959 case DW_CFA_def_cfa:
4960 fc->cfa_reg = LEB ();
4961 fc->cfa_offset = LEB ();
4963 if (! do_debug_frames_interp)
4964 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4965 regname (fc->cfa_reg, 0), fc->cfa_offset);
4968 case DW_CFA_def_cfa_register:
4969 fc->cfa_reg = LEB ();
4971 if (! do_debug_frames_interp)
4972 printf (" DW_CFA_def_cfa_register: %s\n",
4973 regname (fc->cfa_reg, 0));
4976 case DW_CFA_def_cfa_offset:
4977 fc->cfa_offset = LEB ();
4978 if (! do_debug_frames_interp)
4979 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
4983 if (! do_debug_frames_interp)
4984 printf (" DW_CFA_nop\n");
4987 case DW_CFA_def_cfa_expression:
4989 if (! do_debug_frames_interp)
4991 printf (" DW_CFA_def_cfa_expression (");
4992 decode_location_expression (start, eh_addr_size, 0, -1,
5000 case DW_CFA_expression:
5003 if (reg >= (unsigned int) fc->ncols)
5004 reg_prefix = bad_reg;
5005 if (! do_debug_frames_interp || *reg_prefix != '\0')
5007 printf (" DW_CFA_expression: %s%s (",
5008 reg_prefix, regname (reg, 0));
5009 decode_location_expression (start, eh_addr_size, 0, -1,
5013 if (*reg_prefix == '\0')
5014 fc->col_type[reg] = DW_CFA_expression;
5018 case DW_CFA_val_expression:
5021 if (reg >= (unsigned int) fc->ncols)
5022 reg_prefix = bad_reg;
5023 if (! do_debug_frames_interp || *reg_prefix != '\0')
5025 printf (" DW_CFA_val_expression: %s%s (",
5026 reg_prefix, regname (reg, 0));
5027 decode_location_expression (start, eh_addr_size, 0, -1,
5031 if (*reg_prefix == '\0')
5032 fc->col_type[reg] = DW_CFA_val_expression;
5036 case DW_CFA_offset_extended_sf:
5039 if (frame_need_space (fc, reg) < 0)
5040 reg_prefix = bad_reg;
5041 if (! do_debug_frames_interp || *reg_prefix != '\0')
5042 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5043 reg_prefix, regname (reg, 0),
5044 l * fc->data_factor);
5045 if (*reg_prefix == '\0')
5047 fc->col_type[reg] = DW_CFA_offset;
5048 fc->col_offset[reg] = l * fc->data_factor;
5052 case DW_CFA_val_offset_sf:
5055 if (frame_need_space (fc, reg) < 0)
5056 reg_prefix = bad_reg;
5057 if (! do_debug_frames_interp || *reg_prefix != '\0')
5058 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5059 reg_prefix, regname (reg, 0),
5060 l * fc->data_factor);
5061 if (*reg_prefix == '\0')
5063 fc->col_type[reg] = DW_CFA_val_offset;
5064 fc->col_offset[reg] = l * fc->data_factor;
5068 case DW_CFA_def_cfa_sf:
5069 fc->cfa_reg = LEB ();
5070 fc->cfa_offset = SLEB ();
5071 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5073 if (! do_debug_frames_interp)
5074 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5075 regname (fc->cfa_reg, 0), fc->cfa_offset);
5078 case DW_CFA_def_cfa_offset_sf:
5079 fc->cfa_offset = SLEB ();
5080 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5081 if (! do_debug_frames_interp)
5082 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5085 case DW_CFA_MIPS_advance_loc8:
5086 ofs = byte_get (start, 8); start += 8;
5087 if (do_debug_frames_interp)
5088 frame_display_row (fc, &need_col_headers, &max_regs);
5090 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5091 ofs * fc->code_factor,
5092 fc->pc_begin + ofs * fc->code_factor);
5093 fc->pc_begin += ofs * fc->code_factor;
5096 case DW_CFA_GNU_window_save:
5097 if (! do_debug_frames_interp)
5098 printf (" DW_CFA_GNU_window_save\n");
5101 case DW_CFA_GNU_args_size:
5103 if (! do_debug_frames_interp)
5104 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5107 case DW_CFA_GNU_negative_offset_extended:
5110 if (frame_need_space (fc, reg) < 0)
5111 reg_prefix = bad_reg;
5112 if (! do_debug_frames_interp || *reg_prefix != '\0')
5113 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5114 reg_prefix, regname (reg, 0),
5115 l * fc->data_factor);
5116 if (*reg_prefix == '\0')
5118 fc->col_type[reg] = DW_CFA_offset;
5119 fc->col_offset[reg] = l * fc->data_factor;
5124 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5125 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5127 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5132 if (do_debug_frames_interp)
5133 frame_display_row (fc, &need_col_headers, &max_regs);
5136 eh_addr_size = saved_eh_addr_size;
5149 display_gdb_index (struct dwarf_section *section,
5150 void *file ATTRIBUTE_UNUSED)
5152 unsigned char *start = section->start;
5154 uint32_t cu_list_offset, tu_list_offset;
5155 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5156 unsigned int cu_list_elements, tu_list_elements;
5157 unsigned int address_table_size, symbol_table_slots;
5158 unsigned char *cu_list, *tu_list;
5159 unsigned char *address_table, *symbol_table, *constant_pool;
5162 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5164 printf (_("Contents of the %s section:\n"), section->name);
5166 if (section->size < 6 * sizeof (uint32_t))
5168 warn (_("Truncated header in the %s section.\n"), section->name);
5172 version = byte_get_little_endian (start, 4);
5173 printf (_("Version %ld\n"), (long) version);
5175 /* Prior versions are obsolete, and future versions may not be
5176 backwards compatible. */
5180 warn (_("The address table data in version 3 may be wrong.\n"));
5183 warn (_("Version 4 does not support case insensitive lookups.\n"));
5188 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5192 cu_list_offset = byte_get_little_endian (start + 4, 4);
5193 tu_list_offset = byte_get_little_endian (start + 8, 4);
5194 address_table_offset = byte_get_little_endian (start + 12, 4);
5195 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5196 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5198 if (cu_list_offset > section->size
5199 || tu_list_offset > section->size
5200 || address_table_offset > section->size
5201 || symbol_table_offset > section->size
5202 || constant_pool_offset > section->size)
5204 warn (_("Corrupt header in the %s section.\n"), section->name);
5208 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5209 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5210 address_table_size = symbol_table_offset - address_table_offset;
5211 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5213 cu_list = start + cu_list_offset;
5214 tu_list = start + tu_list_offset;
5215 address_table = start + address_table_offset;
5216 symbol_table = start + symbol_table_offset;
5217 constant_pool = start + constant_pool_offset;
5219 printf (_("\nCU table:\n"));
5220 for (i = 0; i < cu_list_elements; i += 2)
5222 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5223 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5225 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5226 (unsigned long) cu_offset,
5227 (unsigned long) (cu_offset + cu_length - 1));
5230 printf (_("\nTU table:\n"));
5231 for (i = 0; i < tu_list_elements; i += 3)
5233 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5234 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5235 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5237 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5238 (unsigned long) tu_offset,
5239 (unsigned long) type_offset);
5240 print_dwarf_vma (signature, 8);
5244 printf (_("\nAddress table:\n"));
5245 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5247 uint64_t low = byte_get_little_endian (address_table + i, 8);
5248 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5249 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5251 print_dwarf_vma (low, 8);
5252 print_dwarf_vma (high, 8);
5253 printf (_("%lu\n"), (unsigned long) cu_index);
5256 printf (_("\nSymbol table:\n"));
5257 for (i = 0; i < symbol_table_slots; ++i)
5259 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5260 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5261 uint32_t num_cus, cu;
5263 if (name_offset != 0
5264 || cu_vector_offset != 0)
5268 printf ("[%3u] %s:", i, constant_pool + name_offset);
5269 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5270 for (j = 0; j < num_cus; ++j)
5272 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5273 /* Convert to TU number if it's for a type unit. */
5274 if (cu >= cu_list_elements / 2)
5275 printf (" T%lu", (unsigned long) (cu - cu_list_elements / 2));
5277 printf (" %lu", (unsigned long) cu);
5287 display_debug_not_supported (struct dwarf_section *section,
5288 void *file ATTRIBUTE_UNUSED)
5290 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5297 cmalloc (size_t nmemb, size_t size)
5299 /* Check for overflow. */
5300 if (nmemb >= ~(size_t) 0 / size)
5303 return malloc (nmemb * size);
5307 xcmalloc (size_t nmemb, size_t size)
5309 /* Check for overflow. */
5310 if (nmemb >= ~(size_t) 0 / size)
5313 return xmalloc (nmemb * size);
5317 xcrealloc (void *ptr, size_t nmemb, size_t size)
5319 /* Check for overflow. */
5320 if (nmemb >= ~(size_t) 0 / size)
5323 return xrealloc (ptr, nmemb * size);
5327 free_debug_memory (void)
5333 for (i = 0; i < max; i++)
5334 free_debug_section ((enum dwarf_section_display_enum) i);
5336 if (debug_information != NULL)
5338 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
5340 for (i = 0; i < num_debug_info_entries; i++)
5342 if (!debug_information [i].max_loc_offsets)
5344 free (debug_information [i].loc_offsets);
5345 free (debug_information [i].have_frame_base);
5347 if (!debug_information [i].max_range_lists)
5348 free (debug_information [i].range_lists);
5352 free (debug_information);
5353 debug_information = NULL;
5354 num_debug_info_entries = 0;
5359 dwarf_select_sections_by_names (const char *names)
5363 const char * option;
5367 debug_dump_long_opts;
5369 static const debug_dump_long_opts opts_table [] =
5371 /* Please keep this table alpha- sorted. */
5372 { "Ranges", & do_debug_ranges, 1 },
5373 { "abbrev", & do_debug_abbrevs, 1 },
5374 { "aranges", & do_debug_aranges, 1 },
5375 { "frames", & do_debug_frames, 1 },
5376 { "frames-interp", & do_debug_frames_interp, 1 },
5377 { "info", & do_debug_info, 1 },
5378 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5379 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5380 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5381 { "loc", & do_debug_loc, 1 },
5382 { "macro", & do_debug_macinfo, 1 },
5383 { "pubnames", & do_debug_pubnames, 1 },
5384 { "pubtypes", & do_debug_pubtypes, 1 },
5385 /* This entry is for compatability
5386 with earlier versions of readelf. */
5387 { "ranges", & do_debug_aranges, 1 },
5388 { "str", & do_debug_str, 1 },
5389 /* The special .gdb_index section. */
5390 { "gdb_index", & do_gdb_index, 1 },
5391 /* These trace_* sections are used by Itanium VMS. */
5392 { "trace_abbrev", & do_trace_abbrevs, 1 },
5393 { "trace_aranges", & do_trace_aranges, 1 },
5394 { "trace_info", & do_trace_info, 1 },
5403 const debug_dump_long_opts * entry;
5405 for (entry = opts_table; entry->option; entry++)
5407 size_t len = strlen (entry->option);
5409 if (strncmp (p, entry->option, len) == 0
5410 && (p[len] == ',' || p[len] == '\0'))
5412 * entry->variable |= entry->val;
5414 /* The --debug-dump=frames-interp option also
5415 enables the --debug-dump=frames option. */
5416 if (do_debug_frames_interp)
5417 do_debug_frames = 1;
5424 if (entry->option == NULL)
5426 warn (_("Unrecognized debug option '%s'\n"), p);
5427 p = strchr (p, ',');
5438 dwarf_select_sections_by_letters (const char *letters)
5440 unsigned int lindex = 0;
5442 while (letters[lindex])
5443 switch (letters[lindex++])
5450 do_debug_abbrevs = 1;
5454 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
5458 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
5462 do_debug_pubnames = 1;
5466 do_debug_pubtypes = 1;
5470 do_debug_aranges = 1;
5474 do_debug_ranges = 1;
5478 do_debug_frames_interp = 1;
5480 do_debug_frames = 1;
5484 do_debug_macinfo = 1;
5496 warn (_("Unrecognized debug option '%s'\n"), optarg);
5502 dwarf_select_sections_all (void)
5505 do_debug_abbrevs = 1;
5506 do_debug_lines = FLAG_DEBUG_LINES_RAW;
5507 do_debug_pubnames = 1;
5508 do_debug_pubtypes = 1;
5509 do_debug_aranges = 1;
5510 do_debug_ranges = 1;
5511 do_debug_frames = 1;
5512 do_debug_macinfo = 1;
5517 do_trace_abbrevs = 1;
5518 do_trace_aranges = 1;
5521 struct dwarf_section_display debug_displays[] =
5523 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 },
5524 display_debug_abbrev, &do_debug_abbrevs, 0 },
5525 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 },
5526 display_debug_aranges, &do_debug_aranges, 1 },
5527 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 },
5528 display_debug_frames, &do_debug_frames, 1 },
5529 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 },
5530 display_debug_info, &do_debug_info, 1 },
5531 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 },
5532 display_debug_lines, &do_debug_lines, 1 },
5533 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 },
5534 display_debug_pubnames, &do_debug_pubnames, 0 },
5535 { { ".eh_frame", "", NULL, NULL, 0, 0 },
5536 display_debug_frames, &do_debug_frames, 1 },
5537 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 },
5538 display_debug_macinfo, &do_debug_macinfo, 0 },
5539 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 },
5540 display_debug_str, &do_debug_str, 0 },
5541 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 },
5542 display_debug_loc, &do_debug_loc, 1 },
5543 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 },
5544 display_debug_pubnames, &do_debug_pubtypes, 0 },
5545 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 },
5546 display_debug_ranges, &do_debug_ranges, 1 },
5547 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 },
5548 display_debug_not_supported, NULL, 0 },
5549 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 },
5550 display_debug_not_supported, NULL, 0 },
5551 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 },
5552 display_debug_types, &do_debug_info, 1 },
5553 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 },
5554 display_debug_not_supported, NULL, 0 },
5555 { { ".gdb_index", "", NULL, NULL, 0, 0 },
5556 display_gdb_index, &do_gdb_index, 0 },
5557 { { ".trace_info", "", NULL, NULL, 0, 0 },
5558 display_trace_info, &do_trace_info, 1 },
5559 { { ".trace_abbrev", "", NULL, NULL, 0, 0 },
5560 display_debug_abbrev, &do_trace_abbrevs, 0 },
5561 { { ".trace_aranges", "", NULL, NULL, 0, 0 },
5562 display_debug_aranges, &do_trace_aranges, 0 }