1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
26 #include "elf/common.h"
30 static int have_frame_base;
31 static int need_base_address;
33 static unsigned int last_pointer_size = 0;
34 static int warned_about_missing_comp_units = FALSE;
36 static unsigned int num_debug_info_entries = 0;
37 static debug_info *debug_information = NULL;
38 /* Special value for num_debug_info_entries to indicate
39 that the .debug_info section could not be loaded/parsed. */
40 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 int do_debug_pubnames;
48 int do_debug_pubtypes;
52 int do_debug_frames_interp;
58 /* Values for do_debug_lines. */
59 #define FLAG_DEBUG_LINES_RAW 1
60 #define FLAG_DEBUG_LINES_DECODED 2
62 dwarf_vma (*byte_get) (unsigned char *, int);
65 byte_get_little_endian (unsigned char *field, int size)
73 return ((unsigned int) (field[0]))
74 | (((unsigned int) (field[1])) << 8);
77 return ((unsigned long) (field[0]))
78 | (((unsigned long) (field[1])) << 8)
79 | (((unsigned long) (field[2])) << 16);
82 return ((unsigned long) (field[0]))
83 | (((unsigned long) (field[1])) << 8)
84 | (((unsigned long) (field[2])) << 16)
85 | (((unsigned long) (field[3])) << 24);
88 if (sizeof (dwarf_vma) == 8)
89 return ((dwarf_vma) (field[0]))
90 | (((dwarf_vma) (field[1])) << 8)
91 | (((dwarf_vma) (field[2])) << 16)
92 | (((dwarf_vma) (field[3])) << 24)
93 | (((dwarf_vma) (field[4])) << 32)
94 | (((dwarf_vma) (field[5])) << 40)
95 | (((dwarf_vma) (field[6])) << 48)
96 | (((dwarf_vma) (field[7])) << 56);
97 else if (sizeof (dwarf_vma) == 4)
98 /* We want to extract data from an 8 byte wide field and
99 place it into a 4 byte wide field. Since this is a little
100 endian source we can just use the 4 byte extraction code. */
101 return ((unsigned long) (field[0]))
102 | (((unsigned long) (field[1])) << 8)
103 | (((unsigned long) (field[2])) << 16)
104 | (((unsigned long) (field[3])) << 24);
107 error (_("Unhandled data length: %d\n"), size);
113 byte_get_big_endian (unsigned char *field, int size)
121 return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
124 return ((unsigned long) (field[2]))
125 | (((unsigned long) (field[1])) << 8)
126 | (((unsigned long) (field[0])) << 16);
129 return ((unsigned long) (field[3]))
130 | (((unsigned long) (field[2])) << 8)
131 | (((unsigned long) (field[1])) << 16)
132 | (((unsigned long) (field[0])) << 24);
135 if (sizeof (dwarf_vma) == 8)
136 return ((dwarf_vma) (field[7]))
137 | (((dwarf_vma) (field[6])) << 8)
138 | (((dwarf_vma) (field[5])) << 16)
139 | (((dwarf_vma) (field[4])) << 24)
140 | (((dwarf_vma) (field[3])) << 32)
141 | (((dwarf_vma) (field[2])) << 40)
142 | (((dwarf_vma) (field[1])) << 48)
143 | (((dwarf_vma) (field[0])) << 56);
144 else if (sizeof (dwarf_vma) == 4)
146 /* Although we are extracing data from an 8 byte wide field,
147 we are returning only 4 bytes of data. */
149 return ((unsigned long) (field[3]))
150 | (((unsigned long) (field[2])) << 8)
151 | (((unsigned long) (field[1])) << 16)
152 | (((unsigned long) (field[0])) << 24);
156 error (_("Unhandled data length: %d\n"), size);
162 byte_get_signed (unsigned char *field, int size)
164 dwarf_vma x = byte_get (field, size);
169 return (x ^ 0x80) - 0x80;
171 return (x ^ 0x8000) - 0x8000;
173 return (x ^ 0x80000000) - 0x80000000;
182 size_of_encoded_value (int encoding)
184 switch (encoding & 0x7)
187 case 0: return eh_addr_size;
195 get_encoded_value (unsigned char *data, int encoding)
197 int size = size_of_encoded_value (encoding);
199 if (encoding & DW_EH_PE_signed)
200 return byte_get_signed (data, size);
202 return byte_get (data, size);
205 /* Print a dwarf_vma value (typically an address, offset or length) in
206 hexadecimal format, followed by a space. The length of the value (and
207 hence the precision displayed) is determined by the byte_size parameter. */
210 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
212 static char buff[18];
214 /* Printf does not have a way of specifiying a maximum field width for an
215 integer value, so we print the full value into a buffer and then select
216 the precision we need. */
217 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
219 snprintf (buff, sizeof (buff), "%16.16llx ", val);
221 snprintf (buff, sizeof (buff), "%016I64x ", val);
224 snprintf (buff, sizeof (buff), "%16.16lx ", val);
227 fputs (buff + (byte_size == 4 ? 8 : 0), stdout);
231 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
233 unsigned long int result = 0;
234 unsigned int num_read = 0;
235 unsigned int shift = 0;
243 result |= ((unsigned long int) (byte & 0x7f)) << shift;
250 if (length_return != NULL)
251 *length_return = num_read;
253 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
254 result |= -1L << shift;
259 typedef struct State_Machine_Registers
261 unsigned long address;
268 /* This variable hold the number of the last entry seen
269 in the File Table. */
270 unsigned int last_file_entry;
273 static SMR state_machine_regs;
276 reset_state_machine (int is_stmt)
278 state_machine_regs.address = 0;
279 state_machine_regs.file = 1;
280 state_machine_regs.line = 1;
281 state_machine_regs.column = 0;
282 state_machine_regs.is_stmt = is_stmt;
283 state_machine_regs.basic_block = 0;
284 state_machine_regs.end_sequence = 0;
285 state_machine_regs.last_file_entry = 0;
288 /* Handled an extend line op.
289 Returns the number of bytes read. */
292 process_extended_line_op (unsigned char *data, int is_stmt)
294 unsigned char op_code;
295 unsigned int bytes_read;
300 len = read_leb128 (data, & bytes_read, 0);
305 warn (_("badly formed extended line op encountered!\n"));
312 printf (_(" Extended opcode %d: "), op_code);
316 case DW_LNE_end_sequence:
317 printf (_("End of Sequence\n\n"));
318 reset_state_machine (is_stmt);
321 case DW_LNE_set_address:
322 adr = byte_get (data, len - bytes_read - 1);
323 printf (_("set Address to 0x%lx\n"), adr);
324 state_machine_regs.address = adr;
327 case DW_LNE_define_file:
328 printf (_(" define new File Table entry\n"));
329 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
331 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
333 data += strlen ((char *) data) + 1;
334 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
336 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
338 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
339 printf (_("%s\n\n"), name);
342 case DW_LNE_set_discriminator:
343 printf (_("set Discriminator to %lu\n"),
344 read_leb128 (data, & bytes_read, 0));
348 case DW_LNE_HP_negate_is_UV_update:
349 printf ("DW_LNE_HP_negate_is_UV_update\n");
351 case DW_LNE_HP_push_context:
352 printf ("DW_LNE_HP_push_context\n");
354 case DW_LNE_HP_pop_context:
355 printf ("DW_LNE_HP_pop_context\n");
357 case DW_LNE_HP_set_file_line_column:
358 printf ("DW_LNE_HP_set_file_line_column\n");
360 case DW_LNE_HP_set_routine_name:
361 printf ("DW_LNE_HP_set_routine_name\n");
363 case DW_LNE_HP_set_sequence:
364 printf ("DW_LNE_HP_set_sequence\n");
366 case DW_LNE_HP_negate_post_semantics:
367 printf ("DW_LNE_HP_negate_post_semantics\n");
369 case DW_LNE_HP_negate_function_exit:
370 printf ("DW_LNE_HP_negate_function_exit\n");
372 case DW_LNE_HP_negate_front_end_logical:
373 printf ("DW_LNE_HP_negate_front_end_logical\n");
375 case DW_LNE_HP_define_proc:
376 printf ("DW_LNE_HP_define_proc\n");
380 if (op_code >= DW_LNE_lo_user
381 /* The test against DW_LNW_hi_user is redundant due to
382 the limited range of the unsigned char data type used
384 /*&& op_code <= DW_LNE_hi_user*/)
385 printf (_("user defined: length %d\n"), len - bytes_read);
387 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
395 fetch_indirect_string (unsigned long offset)
397 struct dwarf_section *section = &debug_displays [str].section;
399 if (section->start == NULL)
400 return _("<no .debug_str section>");
402 /* DWARF sections under Mach-O have non-zero addresses. */
403 offset -= section->address;
404 if (offset > section->size)
406 warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
407 return _("<offset is too big>");
410 return (const char *) section->start + offset;
413 /* FIXME: There are better and more efficient ways to handle
414 these structures. For now though, I just want something that
415 is simple to implement. */
416 typedef struct abbrev_attr
418 unsigned long attribute;
420 struct abbrev_attr *next;
424 typedef struct abbrev_entry
429 struct abbrev_attr *first_attr;
430 struct abbrev_attr *last_attr;
431 struct abbrev_entry *next;
435 static abbrev_entry *first_abbrev = NULL;
436 static abbrev_entry *last_abbrev = NULL;
443 for (abbrv = first_abbrev; abbrv;)
445 abbrev_entry *next_abbrev = abbrv->next;
448 for (attr = abbrv->first_attr; attr;)
450 abbrev_attr *next_attr = attr->next;
460 last_abbrev = first_abbrev = NULL;
464 add_abbrev (unsigned long number, unsigned long tag, int children)
468 entry = (abbrev_entry *) malloc (sizeof (*entry));
474 entry->entry = number;
476 entry->children = children;
477 entry->first_attr = NULL;
478 entry->last_attr = NULL;
481 if (first_abbrev == NULL)
482 first_abbrev = entry;
484 last_abbrev->next = entry;
490 add_abbrev_attr (unsigned long attribute, unsigned long form)
494 attr = (abbrev_attr *) malloc (sizeof (*attr));
500 attr->attribute = attribute;
504 if (last_abbrev->first_attr == NULL)
505 last_abbrev->first_attr = attr;
507 last_abbrev->last_attr->next = attr;
509 last_abbrev->last_attr = attr;
512 /* Processes the (partial) contents of a .debug_abbrev section.
513 Returns NULL if the end of the section was encountered.
514 Returns the address after the last byte read if the end of
515 an abbreviation set was found. */
517 static unsigned char *
518 process_abbrev_section (unsigned char *start, unsigned char *end)
520 if (first_abbrev != NULL)
525 unsigned int bytes_read;
528 unsigned long attribute;
531 entry = read_leb128 (start, & bytes_read, 0);
534 /* A single zero is supposed to end the section according
535 to the standard. If there's more, then signal that to
538 return start == end ? NULL : start;
540 tag = read_leb128 (start, & bytes_read, 0);
545 add_abbrev (entry, tag, children);
551 attribute = read_leb128 (start, & bytes_read, 0);
554 form = read_leb128 (start, & bytes_read, 0);
558 add_abbrev_attr (attribute, form);
560 while (attribute != 0);
567 get_TAG_name (unsigned long tag)
571 case DW_TAG_padding: return "DW_TAG_padding";
572 case DW_TAG_array_type: return "DW_TAG_array_type";
573 case DW_TAG_class_type: return "DW_TAG_class_type";
574 case DW_TAG_entry_point: return "DW_TAG_entry_point";
575 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
576 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
577 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
578 case DW_TAG_label: return "DW_TAG_label";
579 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
580 case DW_TAG_member: return "DW_TAG_member";
581 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
582 case DW_TAG_reference_type: return "DW_TAG_reference_type";
583 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
584 case DW_TAG_string_type: return "DW_TAG_string_type";
585 case DW_TAG_structure_type: return "DW_TAG_structure_type";
586 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
587 case DW_TAG_typedef: return "DW_TAG_typedef";
588 case DW_TAG_union_type: return "DW_TAG_union_type";
589 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
590 case DW_TAG_variant: return "DW_TAG_variant";
591 case DW_TAG_common_block: return "DW_TAG_common_block";
592 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
593 case DW_TAG_inheritance: return "DW_TAG_inheritance";
594 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
595 case DW_TAG_module: return "DW_TAG_module";
596 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
597 case DW_TAG_set_type: return "DW_TAG_set_type";
598 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
599 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
600 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
601 case DW_TAG_base_type: return "DW_TAG_base_type";
602 case DW_TAG_catch_block: return "DW_TAG_catch_block";
603 case DW_TAG_const_type: return "DW_TAG_const_type";
604 case DW_TAG_constant: return "DW_TAG_constant";
605 case DW_TAG_enumerator: return "DW_TAG_enumerator";
606 case DW_TAG_file_type: return "DW_TAG_file_type";
607 case DW_TAG_friend: return "DW_TAG_friend";
608 case DW_TAG_namelist: return "DW_TAG_namelist";
609 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
610 case DW_TAG_packed_type: return "DW_TAG_packed_type";
611 case DW_TAG_subprogram: return "DW_TAG_subprogram";
612 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
613 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
614 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
615 case DW_TAG_try_block: return "DW_TAG_try_block";
616 case DW_TAG_variant_part: return "DW_TAG_variant_part";
617 case DW_TAG_variable: return "DW_TAG_variable";
618 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
619 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
620 case DW_TAG_format_label: return "DW_TAG_format_label";
621 case DW_TAG_function_template: return "DW_TAG_function_template";
622 case DW_TAG_class_template: return "DW_TAG_class_template";
623 /* DWARF 2.1 values. */
624 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
625 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
626 case DW_TAG_interface_type: return "DW_TAG_interface_type";
627 case DW_TAG_namespace: return "DW_TAG_namespace";
628 case DW_TAG_imported_module: return "DW_TAG_imported_module";
629 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
630 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
631 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
632 case DW_TAG_condition: return "DW_TAG_condition";
633 case DW_TAG_shared_type: return "DW_TAG_shared_type";
634 /* DWARF 4 values. */
635 case DW_TAG_type_unit: return "DW_TAG_type_unit";
636 case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type";
637 case DW_TAG_template_alias: return "DW_TAG_template_alias";
639 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
640 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
641 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
644 static char buffer[100];
646 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
653 get_FORM_name (unsigned long form)
657 case DW_FORM_addr: return "DW_FORM_addr";
658 case DW_FORM_block2: return "DW_FORM_block2";
659 case DW_FORM_block4: return "DW_FORM_block4";
660 case DW_FORM_data2: return "DW_FORM_data2";
661 case DW_FORM_data4: return "DW_FORM_data4";
662 case DW_FORM_data8: return "DW_FORM_data8";
663 case DW_FORM_string: return "DW_FORM_string";
664 case DW_FORM_block: return "DW_FORM_block";
665 case DW_FORM_block1: return "DW_FORM_block1";
666 case DW_FORM_data1: return "DW_FORM_data1";
667 case DW_FORM_flag: return "DW_FORM_flag";
668 case DW_FORM_sdata: return "DW_FORM_sdata";
669 case DW_FORM_strp: return "DW_FORM_strp";
670 case DW_FORM_udata: return "DW_FORM_udata";
671 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
672 case DW_FORM_ref1: return "DW_FORM_ref1";
673 case DW_FORM_ref2: return "DW_FORM_ref2";
674 case DW_FORM_ref4: return "DW_FORM_ref4";
675 case DW_FORM_ref8: return "DW_FORM_ref8";
676 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
677 case DW_FORM_indirect: return "DW_FORM_indirect";
678 /* DWARF 4 values. */
679 case DW_FORM_sec_offset: return "DW_FORM_sec_offset";
680 case DW_FORM_exprloc: return "DW_FORM_exprloc";
681 case DW_FORM_flag_present: return "DW_FORM_flag_present";
682 case DW_FORM_ref_sig8: return "DW_FORM_ref_sig8";
685 static char buffer[100];
687 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
693 static unsigned char *
694 display_block (unsigned char *data, unsigned long length)
696 printf (_(" %lu byte block: "), length);
699 printf ("%lx ", (unsigned long) byte_get (data++, 1));
705 decode_location_expression (unsigned char * data,
706 unsigned int pointer_size,
707 unsigned long length,
708 unsigned long cu_offset,
709 struct dwarf_section * section)
712 unsigned int bytes_read;
713 unsigned long uvalue;
714 unsigned char *end = data + length;
715 int need_frame_base = 0;
724 printf ("DW_OP_addr: %lx",
725 (unsigned long) byte_get (data, pointer_size));
726 data += pointer_size;
729 printf ("DW_OP_deref");
732 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
735 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
738 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
742 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
746 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
750 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
754 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
755 (unsigned long) byte_get (data + 4, 4));
759 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
760 (long) byte_get (data + 4, 4));
764 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
768 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
772 printf ("DW_OP_dup");
775 printf ("DW_OP_drop");
778 printf ("DW_OP_over");
781 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
784 printf ("DW_OP_swap");
787 printf ("DW_OP_rot");
790 printf ("DW_OP_xderef");
793 printf ("DW_OP_abs");
796 printf ("DW_OP_and");
799 printf ("DW_OP_div");
802 printf ("DW_OP_minus");
805 printf ("DW_OP_mod");
808 printf ("DW_OP_mul");
811 printf ("DW_OP_neg");
814 printf ("DW_OP_not");
820 printf ("DW_OP_plus");
822 case DW_OP_plus_uconst:
823 printf ("DW_OP_plus_uconst: %lu",
824 read_leb128 (data, &bytes_read, 0));
828 printf ("DW_OP_shl");
831 printf ("DW_OP_shr");
834 printf ("DW_OP_shra");
837 printf ("DW_OP_xor");
840 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
862 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
898 printf ("DW_OP_lit%d", op - DW_OP_lit0);
933 printf ("DW_OP_reg%d", op - DW_OP_reg0);
968 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
969 read_leb128 (data, &bytes_read, 1));
974 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
979 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
983 uvalue = read_leb128 (data, &bytes_read, 0);
985 printf ("DW_OP_bregx: %lu %ld", uvalue,
986 read_leb128 (data, &bytes_read, 1));
990 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
993 case DW_OP_deref_size:
994 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
996 case DW_OP_xderef_size:
997 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
1000 printf ("DW_OP_nop");
1003 /* DWARF 3 extensions. */
1004 case DW_OP_push_object_address:
1005 printf ("DW_OP_push_object_address");
1008 /* XXX: Strictly speaking for 64-bit DWARF3 files
1009 this ought to be an 8-byte wide computation. */
1010 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset);
1014 /* XXX: Strictly speaking for 64-bit DWARF3 files
1015 this ought to be an 8-byte wide computation. */
1016 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset);
1019 case DW_OP_call_ref:
1020 /* XXX: Strictly speaking for 64-bit DWARF3 files
1021 this ought to be an 8-byte wide computation. */
1022 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data, 4) + cu_offset);
1025 case DW_OP_form_tls_address:
1026 printf ("DW_OP_form_tls_address");
1028 case DW_OP_call_frame_cfa:
1029 printf ("DW_OP_call_frame_cfa");
1031 case DW_OP_bit_piece:
1032 printf ("DW_OP_bit_piece: ");
1033 printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
1035 printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
1039 /* DWARF 4 extensions. */
1040 case DW_OP_stack_value:
1041 printf ("DW_OP_stack_value");
1044 case DW_OP_implicit_value:
1045 printf ("DW_OP_implicit_value");
1046 uvalue = read_leb128 (data, &bytes_read, 0);
1048 display_block (data, uvalue);
1052 /* GNU extensions. */
1053 case DW_OP_GNU_push_tls_address:
1054 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1056 case DW_OP_GNU_uninit:
1057 printf ("DW_OP_GNU_uninit");
1058 /* FIXME: Is there data associated with this OP ? */
1060 case DW_OP_GNU_encoded_addr:
1066 addr = get_encoded_value (data, encoding);
1067 if ((encoding & 0x70) == DW_EH_PE_pcrel)
1068 addr += section->address + (data - section->start);
1069 data += size_of_encoded_value (encoding);
1071 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1072 print_dwarf_vma (addr, pointer_size);
1076 /* HP extensions. */
1077 case DW_OP_HP_is_value:
1078 printf ("DW_OP_HP_is_value");
1079 /* FIXME: Is there data associated with this OP ? */
1081 case DW_OP_HP_fltconst4:
1082 printf ("DW_OP_HP_fltconst4");
1083 /* FIXME: Is there data associated with this OP ? */
1085 case DW_OP_HP_fltconst8:
1086 printf ("DW_OP_HP_fltconst8");
1087 /* FIXME: Is there data associated with this OP ? */
1089 case DW_OP_HP_mod_range:
1090 printf ("DW_OP_HP_mod_range");
1091 /* FIXME: Is there data associated with this OP ? */
1093 case DW_OP_HP_unmod_range:
1094 printf ("DW_OP_HP_unmod_range");
1095 /* FIXME: Is there data associated with this OP ? */
1098 printf ("DW_OP_HP_tls");
1099 /* FIXME: Is there data associated with this OP ? */
1102 /* PGI (STMicroelectronics) extensions. */
1103 case DW_OP_PGI_omp_thread_num:
1104 /* Pushes the thread number for the current thread as it would be
1105 returned by the standard OpenMP library function:
1106 omp_get_thread_num(). The "current thread" is the thread for
1107 which the expression is being evaluated. */
1108 printf ("DW_OP_PGI_omp_thread_num");
1112 if (op >= DW_OP_lo_user
1113 && op <= DW_OP_hi_user)
1114 printf (_("(User defined location op)"));
1116 printf (_("(Unknown location op)"));
1117 /* No way to tell where the next op is, so just bail. */
1118 return need_frame_base;
1121 /* Separate the ops. */
1126 return need_frame_base;
1129 static unsigned char *
1130 read_and_display_attr_value (unsigned long attribute,
1132 unsigned char * data,
1133 unsigned long cu_offset,
1134 unsigned long pointer_size,
1135 unsigned long offset_size,
1137 debug_info * debug_info_p,
1139 struct dwarf_section * section)
1141 unsigned long uvalue = 0;
1142 unsigned char *block_start = NULL;
1143 unsigned char * orig_data = data;
1144 unsigned int bytes_read;
1151 case DW_FORM_ref_addr:
1152 if (dwarf_version == 2)
1154 uvalue = byte_get (data, pointer_size);
1155 data += pointer_size;
1157 else if (dwarf_version == 3 || dwarf_version == 4)
1159 uvalue = byte_get (data, offset_size);
1160 data += offset_size;
1164 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1169 uvalue = byte_get (data, pointer_size);
1170 data += pointer_size;
1174 case DW_FORM_sec_offset:
1175 uvalue = byte_get (data, offset_size);
1176 data += offset_size;
1179 case DW_FORM_flag_present:
1186 uvalue = byte_get (data++, 1);
1191 uvalue = byte_get (data, 2);
1197 uvalue = byte_get (data, 4);
1202 uvalue = read_leb128 (data, & bytes_read, 1);
1206 case DW_FORM_ref_udata:
1208 uvalue = read_leb128 (data, & bytes_read, 0);
1212 case DW_FORM_indirect:
1213 form = read_leb128 (data, & bytes_read, 0);
1216 printf (" %s", get_FORM_name (form));
1217 return read_and_display_attr_value (attribute, form, data,
1218 cu_offset, pointer_size,
1219 offset_size, dwarf_version,
1220 debug_info_p, do_loc,
1226 case DW_FORM_ref_addr:
1228 printf (" <0x%lx>", uvalue);
1234 case DW_FORM_ref_udata:
1236 printf (" <0x%lx>", uvalue + cu_offset);
1241 case DW_FORM_sec_offset:
1243 printf (" 0x%lx", uvalue);
1246 case DW_FORM_flag_present:
1253 printf (" %ld", uvalue);
1260 uvalue = byte_get (data, 4);
1261 printf (" 0x%lx", uvalue);
1262 printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
1264 if ((do_loc || do_debug_loc || do_debug_ranges)
1265 && num_debug_info_entries == 0)
1267 if (sizeof (uvalue) == 8)
1268 uvalue = byte_get (data, 8);
1270 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1275 case DW_FORM_string:
1277 printf (" %s", data);
1278 data += strlen ((char *) data) + 1;
1282 case DW_FORM_exprloc:
1283 uvalue = read_leb128 (data, & bytes_read, 0);
1284 block_start = data + bytes_read;
1286 data = block_start + uvalue;
1288 data = display_block (block_start, uvalue);
1291 case DW_FORM_block1:
1292 uvalue = byte_get (data, 1);
1293 block_start = data + 1;
1295 data = block_start + uvalue;
1297 data = display_block (block_start, uvalue);
1300 case DW_FORM_block2:
1301 uvalue = byte_get (data, 2);
1302 block_start = data + 2;
1304 data = block_start + uvalue;
1306 data = display_block (block_start, uvalue);
1309 case DW_FORM_block4:
1310 uvalue = byte_get (data, 4);
1311 block_start = data + 4;
1313 data = block_start + uvalue;
1315 data = display_block (block_start, uvalue);
1320 printf (_(" (indirect string, offset: 0x%lx): %s"),
1321 uvalue, fetch_indirect_string (uvalue));
1324 case DW_FORM_indirect:
1325 /* Handled above. */
1328 case DW_FORM_ref_sig8:
1332 printf (" signature: ");
1333 for (i = 0; i < 8; i++)
1335 printf ("%02x", (unsigned) byte_get (data, 1));
1344 warn (_("Unrecognized form: %lu\n"), form);
1348 if ((do_loc || do_debug_loc || do_debug_ranges)
1349 && num_debug_info_entries == 0)
1353 case DW_AT_frame_base:
1354 have_frame_base = 1;
1355 case DW_AT_location:
1356 case DW_AT_string_length:
1357 case DW_AT_return_addr:
1358 case DW_AT_data_member_location:
1359 case DW_AT_vtable_elem_location:
1361 case DW_AT_static_link:
1362 case DW_AT_use_location:
1363 if (form == DW_FORM_data4
1364 || form == DW_FORM_data8
1365 || form == DW_FORM_sec_offset)
1367 /* Process location list. */
1368 unsigned int lmax = debug_info_p->max_loc_offsets;
1369 unsigned int num = debug_info_p->num_loc_offsets;
1371 if (lmax == 0 || num >= lmax)
1374 debug_info_p->loc_offsets = (long unsigned int *)
1375 xcrealloc (debug_info_p->loc_offsets,
1376 lmax, sizeof (*debug_info_p->loc_offsets));
1377 debug_info_p->have_frame_base = (int *)
1378 xcrealloc (debug_info_p->have_frame_base,
1379 lmax, sizeof (*debug_info_p->have_frame_base));
1380 debug_info_p->max_loc_offsets = lmax;
1382 debug_info_p->loc_offsets [num] = uvalue;
1383 debug_info_p->have_frame_base [num] = have_frame_base;
1384 debug_info_p->num_loc_offsets++;
1389 if (need_base_address)
1390 debug_info_p->base_address = uvalue;
1394 if (form == DW_FORM_data4
1395 || form == DW_FORM_data8
1396 || form == DW_FORM_sec_offset)
1398 /* Process range list. */
1399 unsigned int lmax = debug_info_p->max_range_lists;
1400 unsigned int num = debug_info_p->num_range_lists;
1402 if (lmax == 0 || num >= lmax)
1405 debug_info_p->range_lists = (long unsigned int *)
1406 xcrealloc (debug_info_p->range_lists,
1407 lmax, sizeof (*debug_info_p->range_lists));
1408 debug_info_p->max_range_lists = lmax;
1410 debug_info_p->range_lists [num] = uvalue;
1411 debug_info_p->num_range_lists++;
1423 /* For some attributes we can display further information. */
1431 case DW_INL_not_inlined:
1432 printf (_("(not inlined)"));
1434 case DW_INL_inlined:
1435 printf (_("(inlined)"));
1437 case DW_INL_declared_not_inlined:
1438 printf (_("(declared as inline but ignored)"));
1440 case DW_INL_declared_inlined:
1441 printf (_("(declared as inline and inlined)"));
1444 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
1449 case DW_AT_language:
1452 /* Ordered by the numeric value of these constants. */
1453 case DW_LANG_C89: printf ("(ANSI C)"); break;
1454 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1455 case DW_LANG_Ada83: printf ("(Ada)"); break;
1456 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1457 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1458 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1459 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1460 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1461 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1462 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1463 /* DWARF 2.1 values. */
1464 case DW_LANG_Java: printf ("(Java)"); break;
1465 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1466 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1467 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1468 /* DWARF 3 values. */
1469 case DW_LANG_PLI: printf ("(PLI)"); break;
1470 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1471 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1472 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1473 case DW_LANG_D: printf ("(D)"); break;
1474 /* DWARF 4 values. */
1475 case DW_LANG_Python: printf ("(Python)"); break;
1476 /* MIPS extension. */
1477 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1478 /* UPC extension. */
1479 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1481 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1482 printf ("(implementation defined: %lx)", uvalue);
1484 printf ("(Unknown: %lx)", uvalue);
1489 case DW_AT_encoding:
1492 case DW_ATE_void: printf ("(void)"); break;
1493 case DW_ATE_address: printf ("(machine address)"); break;
1494 case DW_ATE_boolean: printf ("(boolean)"); break;
1495 case DW_ATE_complex_float: printf ("(complex float)"); break;
1496 case DW_ATE_float: printf ("(float)"); break;
1497 case DW_ATE_signed: printf ("(signed)"); break;
1498 case DW_ATE_signed_char: printf ("(signed char)"); break;
1499 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1500 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1501 /* DWARF 2.1 values: */
1502 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1503 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1504 /* DWARF 3 values: */
1505 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1506 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1507 case DW_ATE_edited: printf ("(edited)"); break;
1508 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1509 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1510 /* HP extensions: */
1511 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1512 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1513 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1514 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1515 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1516 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1517 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1520 if (uvalue >= DW_ATE_lo_user
1521 && uvalue <= DW_ATE_hi_user)
1522 printf ("(user defined type)");
1524 printf ("(unknown type)");
1529 case DW_AT_accessibility:
1532 case DW_ACCESS_public: printf ("(public)"); break;
1533 case DW_ACCESS_protected: printf ("(protected)"); break;
1534 case DW_ACCESS_private: printf ("(private)"); break;
1536 printf ("(unknown accessibility)");
1541 case DW_AT_visibility:
1544 case DW_VIS_local: printf ("(local)"); break;
1545 case DW_VIS_exported: printf ("(exported)"); break;
1546 case DW_VIS_qualified: printf ("(qualified)"); break;
1547 default: printf ("(unknown visibility)"); break;
1551 case DW_AT_virtuality:
1554 case DW_VIRTUALITY_none: printf ("(none)"); break;
1555 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1556 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1557 default: printf ("(unknown virtuality)"); break;
1561 case DW_AT_identifier_case:
1564 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1565 case DW_ID_up_case: printf ("(up_case)"); break;
1566 case DW_ID_down_case: printf ("(down_case)"); break;
1567 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1568 default: printf ("(unknown case)"); break;
1572 case DW_AT_calling_convention:
1575 case DW_CC_normal: printf ("(normal)"); break;
1576 case DW_CC_program: printf ("(program)"); break;
1577 case DW_CC_nocall: printf ("(nocall)"); break;
1579 if (uvalue >= DW_CC_lo_user
1580 && uvalue <= DW_CC_hi_user)
1581 printf ("(user defined)");
1583 printf ("(unknown convention)");
1587 case DW_AT_ordering:
1590 case -1: printf ("(undefined)"); break;
1591 case 0: printf ("(row major)"); break;
1592 case 1: printf ("(column major)"); break;
1596 case DW_AT_frame_base:
1597 have_frame_base = 1;
1598 case DW_AT_location:
1599 case DW_AT_string_length:
1600 case DW_AT_return_addr:
1601 case DW_AT_data_member_location:
1602 case DW_AT_vtable_elem_location:
1604 case DW_AT_static_link:
1605 case DW_AT_use_location:
1606 if (form == DW_FORM_data4
1607 || form == DW_FORM_data8
1608 || form == DW_FORM_sec_offset)
1609 printf (_("(location list)"));
1611 case DW_AT_allocated:
1612 case DW_AT_associated:
1613 case DW_AT_data_location:
1615 case DW_AT_upper_bound:
1616 case DW_AT_lower_bound:
1619 int need_frame_base;
1622 need_frame_base = decode_location_expression (block_start,
1625 cu_offset, section);
1627 if (need_frame_base && !have_frame_base)
1628 printf (_(" [without DW_AT_frame_base]"));
1634 if (form == DW_FORM_ref_sig8)
1637 if (form == DW_FORM_ref1
1638 || form == DW_FORM_ref2
1639 || form == DW_FORM_ref4)
1640 uvalue += cu_offset;
1642 if (uvalue >= section->size)
1643 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1644 uvalue, (unsigned long) (orig_data - section->start));
1647 unsigned long abbrev_number;
1648 abbrev_entry * entry;
1650 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1652 printf ("[Abbrev Number: %ld", abbrev_number);
1653 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1654 if (entry->entry == abbrev_number)
1657 printf (" (%s)", get_TAG_name (entry->tag));
1671 get_AT_name (unsigned long attribute)
1675 case DW_AT_sibling: return "DW_AT_sibling";
1676 case DW_AT_location: return "DW_AT_location";
1677 case DW_AT_name: return "DW_AT_name";
1678 case DW_AT_ordering: return "DW_AT_ordering";
1679 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1680 case DW_AT_byte_size: return "DW_AT_byte_size";
1681 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1682 case DW_AT_bit_size: return "DW_AT_bit_size";
1683 case DW_AT_element_list: return "DW_AT_element_list";
1684 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1685 case DW_AT_low_pc: return "DW_AT_low_pc";
1686 case DW_AT_high_pc: return "DW_AT_high_pc";
1687 case DW_AT_language: return "DW_AT_language";
1688 case DW_AT_member: return "DW_AT_member";
1689 case DW_AT_discr: return "DW_AT_discr";
1690 case DW_AT_discr_value: return "DW_AT_discr_value";
1691 case DW_AT_visibility: return "DW_AT_visibility";
1692 case DW_AT_import: return "DW_AT_import";
1693 case DW_AT_string_length: return "DW_AT_string_length";
1694 case DW_AT_common_reference: return "DW_AT_common_reference";
1695 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1696 case DW_AT_const_value: return "DW_AT_const_value";
1697 case DW_AT_containing_type: return "DW_AT_containing_type";
1698 case DW_AT_default_value: return "DW_AT_default_value";
1699 case DW_AT_inline: return "DW_AT_inline";
1700 case DW_AT_is_optional: return "DW_AT_is_optional";
1701 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1702 case DW_AT_producer: return "DW_AT_producer";
1703 case DW_AT_prototyped: return "DW_AT_prototyped";
1704 case DW_AT_return_addr: return "DW_AT_return_addr";
1705 case DW_AT_start_scope: return "DW_AT_start_scope";
1706 case DW_AT_stride_size: return "DW_AT_stride_size";
1707 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1708 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1709 case DW_AT_accessibility: return "DW_AT_accessibility";
1710 case DW_AT_address_class: return "DW_AT_address_class";
1711 case DW_AT_artificial: return "DW_AT_artificial";
1712 case DW_AT_base_types: return "DW_AT_base_types";
1713 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1714 case DW_AT_count: return "DW_AT_count";
1715 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1716 case DW_AT_decl_column: return "DW_AT_decl_column";
1717 case DW_AT_decl_file: return "DW_AT_decl_file";
1718 case DW_AT_decl_line: return "DW_AT_decl_line";
1719 case DW_AT_declaration: return "DW_AT_declaration";
1720 case DW_AT_discr_list: return "DW_AT_discr_list";
1721 case DW_AT_encoding: return "DW_AT_encoding";
1722 case DW_AT_external: return "DW_AT_external";
1723 case DW_AT_frame_base: return "DW_AT_frame_base";
1724 case DW_AT_friend: return "DW_AT_friend";
1725 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1726 case DW_AT_macro_info: return "DW_AT_macro_info";
1727 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1728 case DW_AT_priority: return "DW_AT_priority";
1729 case DW_AT_segment: return "DW_AT_segment";
1730 case DW_AT_specification: return "DW_AT_specification";
1731 case DW_AT_static_link: return "DW_AT_static_link";
1732 case DW_AT_type: return "DW_AT_type";
1733 case DW_AT_use_location: return "DW_AT_use_location";
1734 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1735 case DW_AT_virtuality: return "DW_AT_virtuality";
1736 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1737 /* DWARF 2.1 values. */
1738 case DW_AT_allocated: return "DW_AT_allocated";
1739 case DW_AT_associated: return "DW_AT_associated";
1740 case DW_AT_data_location: return "DW_AT_data_location";
1741 case DW_AT_stride: return "DW_AT_stride";
1742 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1743 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1744 case DW_AT_extension: return "DW_AT_extension";
1745 case DW_AT_ranges: return "DW_AT_ranges";
1746 case DW_AT_trampoline: return "DW_AT_trampoline";
1747 case DW_AT_call_column: return "DW_AT_call_column";
1748 case DW_AT_call_file: return "DW_AT_call_file";
1749 case DW_AT_call_line: return "DW_AT_call_line";
1750 case DW_AT_description: return "DW_AT_description";
1751 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1752 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1753 case DW_AT_small: return "DW_AT_small";
1754 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1755 case DW_AT_digit_count: return "DW_AT_digit_count";
1756 case DW_AT_picture_string: return "DW_AT_picture_string";
1757 case DW_AT_mutable: return "DW_AT_mutable";
1758 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1759 case DW_AT_explicit: return "DW_AT_explicit";
1760 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1761 case DW_AT_endianity: return "DW_AT_endianity";
1762 case DW_AT_elemental: return "DW_AT_elemental";
1763 case DW_AT_pure: return "DW_AT_pure";
1764 case DW_AT_recursive: return "DW_AT_recursive";
1765 /* DWARF 4 values. */
1766 case DW_AT_signature: return "DW_AT_signature";
1767 case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
1768 case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
1769 case DW_AT_const_expr: return "DW_AT_const_expr";
1770 case DW_AT_enum_class: return "DW_AT_enum_class";
1771 case DW_AT_linkage_name: return "DW_AT_linkage_name";
1773 /* HP and SGI/MIPS extensions. */
1774 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1775 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1776 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1777 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1778 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1779 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1780 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1781 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1782 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1783 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1785 /* HP Extensions. */
1786 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
1787 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1788 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1789 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1790 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1791 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1792 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1793 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1794 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1795 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1796 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1797 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1798 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1800 /* One value is shared by the MIPS and HP extensions: */
1801 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1803 /* GNU extensions. */
1804 case DW_AT_sf_names: return "DW_AT_sf_names";
1805 case DW_AT_src_info: return "DW_AT_src_info";
1806 case DW_AT_mac_info: return "DW_AT_mac_info";
1807 case DW_AT_src_coords: return "DW_AT_src_coords";
1808 case DW_AT_body_begin: return "DW_AT_body_begin";
1809 case DW_AT_body_end: return "DW_AT_body_end";
1810 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1811 case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by";
1812 case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by";
1813 case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded";
1814 case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded";
1815 case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded";
1816 case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required";
1817 case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required";
1818 case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature";
1819 case DW_AT_use_GNAT_descriptive_type: return "DW_AT_use_GNAT_descriptive_type";
1820 case DW_AT_GNAT_descriptive_type: return "DW_AT_GNAT_descriptive_type";
1822 /* UPC extension. */
1823 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1825 /* PGI (STMicroelectronics) extensions. */
1826 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1827 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1828 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1832 static char buffer[100];
1834 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1841 static unsigned char *
1842 read_and_display_attr (unsigned long attribute,
1844 unsigned char * data,
1845 unsigned long cu_offset,
1846 unsigned long pointer_size,
1847 unsigned long offset_size,
1849 debug_info * debug_info_p,
1851 struct dwarf_section * section)
1854 printf (" %-18s:", get_AT_name (attribute));
1855 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1856 pointer_size, offset_size,
1857 dwarf_version, debug_info_p,
1865 /* Process the contents of a .debug_info section. If do_loc is non-zero
1866 then we are scanning for location lists and we do not want to display
1867 anything to the user. If do_types is non-zero, we are processing
1868 a .debug_types section instead of a .debug_info section. */
1871 process_debug_info (struct dwarf_section *section,
1876 unsigned char *start = section->start;
1877 unsigned char *end = start + section->size;
1878 unsigned char *section_begin;
1880 unsigned int num_units = 0;
1882 if ((do_loc || do_debug_loc || do_debug_ranges)
1883 && num_debug_info_entries == 0
1886 unsigned long length;
1888 /* First scan the section to get the number of comp units. */
1889 for (section_begin = start, num_units = 0; section_begin < end;
1892 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1893 will be the length. For a 64-bit DWARF section, it'll be
1894 the escape code 0xffffffff followed by an 8 byte length. */
1895 length = byte_get (section_begin, 4);
1897 if (length == 0xffffffff)
1899 length = byte_get (section_begin + 4, 8);
1900 section_begin += length + 12;
1902 else if (length >= 0xfffffff0 && length < 0xffffffff)
1904 warn (_("Reserved length value (%lx) found in section %s\n"), length, section->name);
1908 section_begin += length + 4;
1910 /* Negative values are illegal, they may even cause infinite
1911 looping. This can happen if we can't accurately apply
1912 relocations to an object file. */
1913 if ((signed long) length <= 0)
1915 warn (_("Corrupt unit length (%lx) found in section %s\n"), length, section->name);
1922 error (_("No comp units in %s section ?"), section->name);
1926 /* Then allocate an array to hold the information. */
1927 debug_information = (debug_info *) cmalloc (num_units,
1928 sizeof (* debug_information));
1929 if (debug_information == NULL)
1931 error (_("Not enough memory for a debug info array of %u entries"),
1939 printf (_("Contents of the %s section:\n\n"), section->name);
1941 load_debug_section (str, file);
1944 load_debug_section (abbrev, file);
1945 if (debug_displays [abbrev].section.start == NULL)
1947 warn (_("Unable to locate %s section!\n"),
1948 debug_displays [abbrev].section.name);
1952 for (section_begin = start, unit = 0; start < end; unit++)
1954 DWARF2_Internal_CompUnit compunit;
1955 unsigned char *hdrptr;
1956 unsigned char *cu_abbrev_offset_ptr;
1957 unsigned char *tags;
1959 unsigned long cu_offset;
1961 int initial_length_size;
1962 unsigned char signature[8];
1963 unsigned long type_offset = 0;
1967 compunit.cu_length = byte_get (hdrptr, 4);
1970 if (compunit.cu_length == 0xffffffff)
1972 compunit.cu_length = byte_get (hdrptr, 8);
1975 initial_length_size = 12;
1980 initial_length_size = 4;
1983 compunit.cu_version = byte_get (hdrptr, 2);
1986 cu_offset = start - section_begin;
1988 cu_abbrev_offset_ptr = hdrptr;
1989 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
1990 hdrptr += offset_size;
1992 compunit.cu_pointer_size = byte_get (hdrptr, 1);
1999 for (i = 0; i < 8; i++)
2001 signature[i] = byte_get (hdrptr, 1);
2005 type_offset = byte_get (hdrptr, offset_size);
2006 hdrptr += offset_size;
2009 if ((do_loc || do_debug_loc || do_debug_ranges)
2010 && num_debug_info_entries == 0
2013 debug_information [unit].cu_offset = cu_offset;
2014 debug_information [unit].pointer_size
2015 = compunit.cu_pointer_size;
2016 debug_information [unit].base_address = 0;
2017 debug_information [unit].loc_offsets = NULL;
2018 debug_information [unit].have_frame_base = NULL;
2019 debug_information [unit].max_loc_offsets = 0;
2020 debug_information [unit].num_loc_offsets = 0;
2021 debug_information [unit].range_lists = NULL;
2022 debug_information [unit].max_range_lists= 0;
2023 debug_information [unit].num_range_lists = 0;
2028 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset);
2029 printf (_(" Length: 0x%lx (%s)\n"), compunit.cu_length,
2030 initial_length_size == 8 ? "64-bit" : "32-bit");
2031 printf (_(" Version: %d\n"), compunit.cu_version);
2032 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
2033 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2037 printf (_(" Signature: "));
2038 for (i = 0; i < 8; i++)
2039 printf ("%02x", signature[i]);
2041 printf (_(" Type Offset: 0x%lx\n"), type_offset);
2045 if (cu_offset + compunit.cu_length + initial_length_size
2048 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
2049 cu_offset, compunit.cu_length);
2053 start += compunit.cu_length + initial_length_size;
2055 if (compunit.cu_version != 2
2056 && compunit.cu_version != 3
2057 && compunit.cu_version != 4)
2059 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
2060 cu_offset, compunit.cu_version);
2066 /* Process the abbrevs used by this compilation unit. DWARF
2067 sections under Mach-O have non-zero addresses. */
2068 if (compunit.cu_abbrev_offset >= debug_displays [abbrev].section.size)
2069 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2070 (unsigned long) compunit.cu_abbrev_offset,
2071 (unsigned long) debug_displays [abbrev].section.size);
2073 process_abbrev_section
2074 ((unsigned char *) debug_displays [abbrev].section.start
2075 + compunit.cu_abbrev_offset - debug_displays [abbrev].section.address,
2076 (unsigned char *) debug_displays [abbrev].section.start
2077 + debug_displays [abbrev].section.size);
2080 while (tags < start)
2082 unsigned int bytes_read;
2083 unsigned long abbrev_number;
2084 unsigned long die_offset;
2085 abbrev_entry *entry;
2088 die_offset = tags - section_begin;
2090 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2093 /* A null DIE marks the end of a list of siblings or it may also be
2094 a section padding. */
2095 if (abbrev_number == 0)
2097 /* Check if it can be a section padding for the last CU. */
2098 if (level == 0 && start == end)
2102 for (chk = tags; chk < start; chk++)
2112 static unsigned num_bogus_warns = 0;
2114 if (num_bogus_warns < 3)
2116 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2119 if (num_bogus_warns == 3)
2120 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2127 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2128 level, die_offset, abbrev_number);
2130 /* Scan through the abbreviation list until we reach the
2132 for (entry = first_abbrev;
2133 entry && entry->entry != abbrev_number;
2134 entry = entry->next)
2144 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2145 die_offset, abbrev_number);
2150 printf (_(" (%s)\n"), get_TAG_name (entry->tag));
2155 need_base_address = 0;
2157 case DW_TAG_compile_unit:
2158 need_base_address = 1;
2160 case DW_TAG_entry_point:
2161 case DW_TAG_subprogram:
2162 need_base_address = 0;
2163 /* Assuming that there is no DW_AT_frame_base. */
2164 have_frame_base = 0;
2168 for (attr = entry->first_attr; attr; attr = attr->next)
2171 /* Show the offset from where the tag was extracted. */
2172 printf (" <%2lx>", (unsigned long)(tags - section_begin));
2174 tags = read_and_display_attr (attr->attribute,
2177 compunit.cu_pointer_size,
2179 compunit.cu_version,
2180 debug_information + unit,
2184 if (entry->children)
2189 /* Set num_debug_info_entries here so that it can be used to check if
2190 we need to process .debug_loc and .debug_ranges sections. */
2191 if ((do_loc || do_debug_loc || do_debug_ranges)
2192 && num_debug_info_entries == 0
2194 num_debug_info_entries = num_units;
2204 /* Locate and scan the .debug_info section in the file and record the pointer
2205 sizes and offsets for the compilation units in it. Usually an executable
2206 will have just one pointer size, but this is not guaranteed, and so we try
2207 not to make any assumptions. Returns zero upon failure, or the number of
2208 compilation units upon success. */
2211 load_debug_info (void * file)
2213 /* Reset the last pointer size so that we can issue correct error
2214 messages if we are displaying the contents of more than one section. */
2215 last_pointer_size = 0;
2216 warned_about_missing_comp_units = FALSE;
2218 /* If we have already tried and failed to load the .debug_info
2219 section then do not bother to repear the task. */
2220 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2223 /* If we already have the information there is nothing else to do. */
2224 if (num_debug_info_entries > 0)
2225 return num_debug_info_entries;
2227 if (load_debug_section (info, file)
2228 && process_debug_info (&debug_displays [info].section, file, 1, 0))
2229 return num_debug_info_entries;
2231 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2236 display_debug_lines_raw (struct dwarf_section *section,
2237 unsigned char *data,
2240 unsigned char *start = section->start;
2242 printf (_("Raw dump of debug contents of section %s:\n\n"),
2247 DWARF2_Internal_LineInfo linfo;
2248 unsigned char *standard_opcodes;
2249 unsigned char *end_of_sequence;
2250 unsigned char *hdrptr;
2251 unsigned long hdroff;
2252 int initial_length_size;
2257 hdroff = hdrptr - start;
2259 /* Check the length of the block. */
2260 linfo.li_length = byte_get (hdrptr, 4);
2263 if (linfo.li_length == 0xffffffff)
2265 /* This section is 64-bit DWARF 3. */
2266 linfo.li_length = byte_get (hdrptr, 8);
2269 initial_length_size = 12;
2274 initial_length_size = 4;
2277 if (linfo.li_length + initial_length_size > section->size)
2280 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2285 /* Check its version number. */
2286 linfo.li_version = byte_get (hdrptr, 2);
2288 if (linfo.li_version != 2
2289 && linfo.li_version != 3
2290 && linfo.li_version != 4)
2292 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2296 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2297 hdrptr += offset_size;
2298 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2300 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2302 linfo.li_line_base = byte_get (hdrptr, 1);
2304 linfo.li_line_range = byte_get (hdrptr, 1);
2306 linfo.li_opcode_base = byte_get (hdrptr, 1);
2309 /* Sign extend the line base field. */
2310 linfo.li_line_base <<= 24;
2311 linfo.li_line_base >>= 24;
2313 printf (_(" Offset: 0x%lx\n"), hdroff);
2314 printf (_(" Length: %ld\n"), linfo.li_length);
2315 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2316 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2317 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2318 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2319 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2320 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2321 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2323 end_of_sequence = data + linfo.li_length + initial_length_size;
2325 reset_state_machine (linfo.li_default_is_stmt);
2327 /* Display the contents of the Opcodes table. */
2328 standard_opcodes = hdrptr;
2330 printf (_("\n Opcodes:\n"));
2332 for (i = 1; i < linfo.li_opcode_base; i++)
2333 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2335 /* Display the contents of the Directory table. */
2336 data = standard_opcodes + linfo.li_opcode_base - 1;
2339 printf (_("\n The Directory Table is empty.\n"));
2342 printf (_("\n The Directory Table:\n"));
2346 printf (_(" %s\n"), data);
2348 data += strlen ((char *) data) + 1;
2352 /* Skip the NUL at the end of the table. */
2355 /* Display the contents of the File Name table. */
2357 printf (_("\n The File Name Table is empty.\n"));
2360 printf (_("\n The File Name Table:\n"));
2361 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2365 unsigned char *name;
2366 unsigned int bytes_read;
2368 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
2371 data += strlen ((char *) data) + 1;
2373 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2375 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2377 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2379 printf (_("%s\n"), name);
2383 /* Skip the NUL at the end of the table. */
2386 /* Now display the statements. */
2387 printf (_("\n Line Number Statements:\n"));
2389 while (data < end_of_sequence)
2391 unsigned char op_code;
2393 unsigned long int uladv;
2394 unsigned int bytes_read;
2398 if (op_code >= linfo.li_opcode_base)
2400 op_code -= linfo.li_opcode_base;
2401 uladv = (op_code / linfo.li_line_range) * linfo.li_min_insn_length;
2402 state_machine_regs.address += uladv;
2403 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2404 op_code, uladv, state_machine_regs.address);
2405 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2406 state_machine_regs.line += adv;
2407 printf (_(" and Line by %d to %d\n"),
2408 adv, state_machine_regs.line);
2410 else switch (op_code)
2412 case DW_LNS_extended_op:
2413 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2417 printf (_(" Copy\n"));
2420 case DW_LNS_advance_pc:
2421 uladv = read_leb128 (data, & bytes_read, 0);
2422 uladv *= linfo.li_min_insn_length;
2424 state_machine_regs.address += uladv;
2425 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv,
2426 state_machine_regs.address);
2429 case DW_LNS_advance_line:
2430 adv = read_leb128 (data, & bytes_read, 1);
2432 state_machine_regs.line += adv;
2433 printf (_(" Advance Line by %d to %d\n"), adv,
2434 state_machine_regs.line);
2437 case DW_LNS_set_file:
2438 adv = read_leb128 (data, & bytes_read, 0);
2440 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2442 state_machine_regs.file = adv;
2445 case DW_LNS_set_column:
2446 uladv = read_leb128 (data, & bytes_read, 0);
2448 printf (_(" Set column to %lu\n"), uladv);
2449 state_machine_regs.column = uladv;
2452 case DW_LNS_negate_stmt:
2453 adv = state_machine_regs.is_stmt;
2455 printf (_(" Set is_stmt to %d\n"), adv);
2456 state_machine_regs.is_stmt = adv;
2459 case DW_LNS_set_basic_block:
2460 printf (_(" Set basic block\n"));
2461 state_machine_regs.basic_block = 1;
2464 case DW_LNS_const_add_pc:
2465 uladv = (((255 - linfo.li_opcode_base) / linfo.li_line_range)
2466 * linfo.li_min_insn_length);
2467 state_machine_regs.address += uladv;
2468 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv,
2469 state_machine_regs.address);
2472 case DW_LNS_fixed_advance_pc:
2473 uladv = byte_get (data, 2);
2475 state_machine_regs.address += uladv;
2476 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2477 uladv, state_machine_regs.address);
2480 case DW_LNS_set_prologue_end:
2481 printf (_(" Set prologue_end to true\n"));
2484 case DW_LNS_set_epilogue_begin:
2485 printf (_(" Set epilogue_begin to true\n"));
2488 case DW_LNS_set_isa:
2489 uladv = read_leb128 (data, & bytes_read, 0);
2491 printf (_(" Set ISA to %lu\n"), uladv);
2495 printf (_(" Unknown opcode %d with operands: "), op_code);
2497 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2499 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
2500 i == 1 ? "" : ", ");
2515 unsigned char *name;
2516 unsigned int directory_index;
2517 unsigned int modification_date;
2518 unsigned int length;
2521 /* Output a decoded representation of the .debug_line section. */
2524 display_debug_lines_decoded (struct dwarf_section *section,
2525 unsigned char *data,
2528 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2533 /* This loop amounts to one iteration per compilation unit. */
2534 DWARF2_Internal_LineInfo linfo;
2535 unsigned char *standard_opcodes;
2536 unsigned char *end_of_sequence;
2537 unsigned char *hdrptr;
2538 int initial_length_size;
2541 File_Entry *file_table = NULL;
2542 unsigned char **directory_table = NULL;
2543 unsigned int prev_line = 0;
2547 /* Extract information from the Line Number Program Header.
2548 (section 6.2.4 in the Dwarf3 doc). */
2550 /* Get the length of this CU's line number information block. */
2551 linfo.li_length = byte_get (hdrptr, 4);
2554 if (linfo.li_length == 0xffffffff)
2556 /* This section is 64-bit DWARF 3. */
2557 linfo.li_length = byte_get (hdrptr, 8);
2560 initial_length_size = 12;
2565 initial_length_size = 4;
2568 if (linfo.li_length + initial_length_size > section->size)
2570 warn (_("The line info appears to be corrupt - "
2571 "the section is too small\n"));
2575 /* Get this CU's Line Number Block version number. */
2576 linfo.li_version = byte_get (hdrptr, 2);
2578 if (linfo.li_version != 2
2579 && linfo.li_version != 3
2580 && linfo.li_version != 4)
2582 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2587 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2588 hdrptr += offset_size;
2589 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2591 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2593 linfo.li_line_base = byte_get (hdrptr, 1);
2595 linfo.li_line_range = byte_get (hdrptr, 1);
2597 linfo.li_opcode_base = byte_get (hdrptr, 1);
2600 /* Sign extend the line base field. */
2601 linfo.li_line_base <<= 24;
2602 linfo.li_line_base >>= 24;
2604 /* Find the end of this CU's Line Number Information Block. */
2605 end_of_sequence = data + linfo.li_length + initial_length_size;
2607 reset_state_machine (linfo.li_default_is_stmt);
2609 /* Save a pointer to the contents of the Opcodes table. */
2610 standard_opcodes = hdrptr;
2612 /* Traverse the Directory table just to count entries. */
2613 data = standard_opcodes + linfo.li_opcode_base - 1;
2616 unsigned int n_directories = 0;
2617 unsigned char *ptr_directory_table = data;
2621 data += strlen ((char *) data) + 1;
2625 /* Go through the directory table again to save the directories. */
2626 directory_table = (unsigned char **)
2627 xmalloc (n_directories * sizeof (unsigned char *));
2630 while (*ptr_directory_table != 0)
2632 directory_table[i] = ptr_directory_table;
2633 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2637 /* Skip the NUL at the end of the table. */
2640 /* Traverse the File Name table just to count the entries. */
2643 unsigned int n_files = 0;
2644 unsigned char *ptr_file_name_table = data;
2648 unsigned int bytes_read;
2650 /* Skip Name, directory index, last modification time and length
2652 data += strlen ((char *) data) + 1;
2653 read_leb128 (data, & bytes_read, 0);
2655 read_leb128 (data, & bytes_read, 0);
2657 read_leb128 (data, & bytes_read, 0);
2663 /* Go through the file table again to save the strings. */
2664 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2667 while (*ptr_file_name_table != 0)
2669 unsigned int bytes_read;
2671 file_table[i].name = ptr_file_name_table;
2672 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2674 /* We are not interested in directory, time or size. */
2675 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2677 ptr_file_name_table += bytes_read;
2678 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2680 ptr_file_name_table += bytes_read;
2681 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2682 ptr_file_name_table += bytes_read;
2687 /* Print the Compilation Unit's name and a header. */
2688 if (directory_table == NULL)
2690 printf (_("CU: %s:\n"), file_table[0].name);
2691 printf (_("File name Line number Starting address\n"));
2695 if (do_wide || strlen ((char *) directory_table[0]) < 76)
2697 printf (_("CU: %s/%s:\n"), directory_table[0],
2698 file_table[0].name);
2702 printf (_("%s:\n"), file_table[0].name);
2704 printf (_("File name Line number Starting address\n"));
2708 /* Skip the NUL at the end of the table. */
2711 /* This loop iterates through the Dwarf Line Number Program. */
2712 while (data < end_of_sequence)
2714 unsigned char op_code;
2716 unsigned long int uladv;
2717 unsigned int bytes_read;
2718 int is_special_opcode = 0;
2721 prev_line = state_machine_regs.line;
2723 if (op_code >= linfo.li_opcode_base)
2725 op_code -= linfo.li_opcode_base;
2726 uladv = (op_code / linfo.li_line_range) * linfo.li_min_insn_length;
2727 state_machine_regs.address += uladv;
2729 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2730 state_machine_regs.line += adv;
2731 is_special_opcode = 1;
2733 else switch (op_code)
2735 case DW_LNS_extended_op:
2737 unsigned int ext_op_code_len;
2738 unsigned char ext_op_code;
2739 unsigned char *op_code_data = data;
2741 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
2742 op_code_data += bytes_read;
2744 if (ext_op_code_len == 0)
2746 warn (_("badly formed extended line op encountered!\n"));
2749 ext_op_code_len += bytes_read;
2750 ext_op_code = *op_code_data++;
2752 switch (ext_op_code)
2754 case DW_LNE_end_sequence:
2755 reset_state_machine (linfo.li_default_is_stmt);
2757 case DW_LNE_set_address:
2758 state_machine_regs.address =
2759 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
2761 case DW_LNE_define_file:
2763 unsigned int dir_index = 0;
2765 ++state_machine_regs.last_file_entry;
2766 op_code_data += strlen ((char *) op_code_data) + 1;
2767 dir_index = read_leb128 (op_code_data, & bytes_read, 0);
2768 op_code_data += bytes_read;
2769 read_leb128 (op_code_data, & bytes_read, 0);
2770 op_code_data += bytes_read;
2771 read_leb128 (op_code_data, & bytes_read, 0);
2773 printf (_("%s:\n"), directory_table[dir_index]);
2777 printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
2780 data += ext_op_code_len;
2786 case DW_LNS_advance_pc:
2787 uladv = read_leb128 (data, & bytes_read, 0);
2788 uladv *= linfo.li_min_insn_length;
2790 state_machine_regs.address += uladv;
2793 case DW_LNS_advance_line:
2794 adv = read_leb128 (data, & bytes_read, 1);
2796 state_machine_regs.line += adv;
2799 case DW_LNS_set_file:
2800 adv = read_leb128 (data, & bytes_read, 0);
2802 state_machine_regs.file = adv;
2803 if (file_table[state_machine_regs.file - 1].directory_index == 0)
2805 /* If directory index is 0, that means current directory. */
2806 printf (_("\n./%s:[++]\n"),
2807 file_table[state_machine_regs.file - 1].name);
2811 /* The directory index starts counting at 1. */
2812 printf (_("\n%s/%s:\n"),
2813 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
2814 file_table[state_machine_regs.file - 1].name);
2818 case DW_LNS_set_column:
2819 uladv = read_leb128 (data, & bytes_read, 0);
2821 state_machine_regs.column = uladv;
2824 case DW_LNS_negate_stmt:
2825 adv = state_machine_regs.is_stmt;
2827 state_machine_regs.is_stmt = adv;
2830 case DW_LNS_set_basic_block:
2831 state_machine_regs.basic_block = 1;
2834 case DW_LNS_const_add_pc:
2835 uladv = (((255 - linfo.li_opcode_base) / linfo.li_line_range)
2836 * linfo.li_min_insn_length);
2837 state_machine_regs.address += uladv;
2840 case DW_LNS_fixed_advance_pc:
2841 uladv = byte_get (data, 2);
2843 state_machine_regs.address += uladv;
2846 case DW_LNS_set_prologue_end:
2849 case DW_LNS_set_epilogue_begin:
2852 case DW_LNS_set_isa:
2853 uladv = read_leb128 (data, & bytes_read, 0);
2855 printf (_(" Set ISA to %lu\n"), uladv);
2859 printf (_(" Unknown opcode %d with operands: "), op_code);
2861 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2863 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
2864 i == 1 ? "" : ", ");
2871 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2872 to the DWARF address/line matrix. */
2873 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
2874 || (op_code == DW_LNS_copy))
2876 const unsigned int MAX_FILENAME_LENGTH = 35;
2877 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
2878 char *newFileName = NULL;
2879 size_t fileNameLength = strlen (fileName);
2881 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
2883 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
2884 /* Truncate file name */
2885 strncpy (newFileName,
2886 fileName + fileNameLength - MAX_FILENAME_LENGTH,
2887 MAX_FILENAME_LENGTH + 1);
2891 newFileName = (char *) xmalloc (fileNameLength + 1);
2892 strncpy (newFileName, fileName, fileNameLength + 1);
2895 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
2897 printf (_("%-35s %11d %#18lx\n"), newFileName,
2898 state_machine_regs.line, state_machine_regs.address);
2902 printf (_("%s %11d %#18lx\n"), newFileName,
2903 state_machine_regs.line, state_machine_regs.address);
2906 if (op_code == DW_LNE_end_sequence)
2914 free (directory_table);
2915 directory_table = NULL;
2923 display_debug_lines (struct dwarf_section *section, void *file)
2925 unsigned char *data = section->start;
2926 unsigned char *end = data + section->size;
2928 int retValDecoded = 1;
2930 if (load_debug_info (file) == 0)
2932 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2937 if (do_debug_lines == 0)
2938 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
2940 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
2941 retValRaw = display_debug_lines_raw (section, data, end);
2943 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
2944 retValDecoded = display_debug_lines_decoded (section, data, end);
2946 if (!retValRaw || !retValDecoded)
2953 find_debug_info_for_offset (unsigned long offset)
2957 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2960 for (i = 0; i < num_debug_info_entries; i++)
2961 if (debug_information[i].cu_offset == offset)
2962 return debug_information + i;
2968 display_debug_pubnames (struct dwarf_section *section,
2969 void *file ATTRIBUTE_UNUSED)
2971 DWARF2_Internal_PubNames names;
2972 unsigned char *start = section->start;
2973 unsigned char *end = start + section->size;
2975 /* It does not matter if this load fails,
2976 we test for that later on. */
2977 load_debug_info (file);
2979 printf (_("Contents of the %s section:\n\n"), section->name);
2983 unsigned char *data;
2984 unsigned long offset;
2985 int offset_size, initial_length_size;
2989 names.pn_length = byte_get (data, 4);
2991 if (names.pn_length == 0xffffffff)
2993 names.pn_length = byte_get (data, 8);
2996 initial_length_size = 12;
3001 initial_length_size = 4;
3004 names.pn_version = byte_get (data, 2);
3007 names.pn_offset = byte_get (data, offset_size);
3008 data += offset_size;
3010 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3011 && num_debug_info_entries > 0
3012 && find_debug_info_for_offset (names.pn_offset) == NULL)
3013 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3014 names.pn_offset, section->name);
3016 names.pn_size = byte_get (data, offset_size);
3017 data += offset_size;
3019 start += names.pn_length + initial_length_size;
3021 if (names.pn_version != 2 && names.pn_version != 3)
3023 static int warned = 0;
3027 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3034 printf (_(" Length: %ld\n"),
3036 printf (_(" Version: %d\n"),
3038 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3040 printf (_(" Size of area in .debug_info section: %ld\n"),
3043 printf (_("\n Offset\tName\n"));
3047 offset = byte_get (data, offset_size);
3051 data += offset_size;
3052 printf (" %-6lx\t%s\n", offset, data);
3053 data += strlen ((char *) data) + 1;
3056 while (offset != 0);
3064 display_debug_macinfo (struct dwarf_section *section,
3065 void *file ATTRIBUTE_UNUSED)
3067 unsigned char *start = section->start;
3068 unsigned char *end = start + section->size;
3069 unsigned char *curr = start;
3070 unsigned int bytes_read;
3071 enum dwarf_macinfo_record_type op;
3073 printf (_("Contents of the %s section:\n\n"), section->name);
3077 unsigned int lineno;
3080 op = (enum dwarf_macinfo_record_type) *curr;
3085 case DW_MACINFO_start_file:
3087 unsigned int filenum;
3089 lineno = read_leb128 (curr, & bytes_read, 0);
3091 filenum = read_leb128 (curr, & bytes_read, 0);
3094 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3099 case DW_MACINFO_end_file:
3100 printf (_(" DW_MACINFO_end_file\n"));
3103 case DW_MACINFO_define:
3104 lineno = read_leb128 (curr, & bytes_read, 0);
3106 string = (char *) curr;
3107 curr += strlen (string) + 1;
3108 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3112 case DW_MACINFO_undef:
3113 lineno = read_leb128 (curr, & bytes_read, 0);
3115 string = (char *) curr;
3116 curr += strlen (string) + 1;
3117 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3121 case DW_MACINFO_vendor_ext:
3123 unsigned int constant;
3125 constant = read_leb128 (curr, & bytes_read, 0);
3127 string = (char *) curr;
3128 curr += strlen (string) + 1;
3129 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3140 display_debug_abbrev (struct dwarf_section *section,
3141 void *file ATTRIBUTE_UNUSED)
3143 abbrev_entry *entry;
3144 unsigned char *start = section->start;
3145 unsigned char *end = start + section->size;
3147 printf (_("Contents of the %s section:\n\n"), section->name);
3153 start = process_abbrev_section (start, end);
3155 if (first_abbrev == NULL)
3158 printf (_(" Number TAG\n"));
3160 for (entry = first_abbrev; entry; entry = entry->next)
3164 printf (_(" %ld %s [%s]\n"),
3166 get_TAG_name (entry->tag),
3167 entry->children ? _("has children") : _("no children"));
3169 for (attr = entry->first_attr; attr; attr = attr->next)
3170 printf (_(" %-18s %s\n"),
3171 get_AT_name (attr->attribute),
3172 get_FORM_name (attr->form));
3183 display_debug_loc (struct dwarf_section *section, void *file)
3185 unsigned char *start = section->start;
3186 unsigned char *section_end;
3187 unsigned long bytes;
3188 unsigned char *section_begin = start;
3189 unsigned int num_loc_list = 0;
3190 unsigned long last_offset = 0;
3191 unsigned int first = 0;
3194 int seen_first_offset = 0;
3195 int use_debug_info = 1;
3196 unsigned char *next;
3198 bytes = section->size;
3199 section_end = start + bytes;
3203 printf (_("\nThe %s section is empty.\n"), section->name);
3207 if (load_debug_info (file) == 0)
3209 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3214 /* Check the order of location list in .debug_info section. If
3215 offsets of location lists are in the ascending order, we can
3216 use `debug_information' directly. */
3217 for (i = 0; i < num_debug_info_entries; i++)
3221 num = debug_information [i].num_loc_offsets;
3222 num_loc_list += num;
3224 /* Check if we can use `debug_information' directly. */
3225 if (use_debug_info && num != 0)
3227 if (!seen_first_offset)
3229 /* This is the first location list. */
3230 last_offset = debug_information [i].loc_offsets [0];
3232 seen_first_offset = 1;
3238 for (; j < num; j++)
3241 debug_information [i].loc_offsets [j])
3246 last_offset = debug_information [i].loc_offsets [j];
3251 if (!use_debug_info)
3252 /* FIXME: Should we handle this case? */
3253 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3255 if (!seen_first_offset)
3256 error (_("No location lists in .debug_info section!\n"));
3258 /* DWARF sections under Mach-O have non-zero addresses. */
3259 if (debug_information [first].num_loc_offsets > 0
3260 && debug_information [first].loc_offsets [0] != section->address)
3261 warn (_("Location lists in %s section start at 0x%lx\n"),
3262 section->name, debug_information [first].loc_offsets [0]);
3264 printf (_("Contents of the %s section:\n\n"), section->name);
3265 printf (_(" Offset Begin End Expression\n"));
3267 seen_first_offset = 0;
3268 for (i = first; i < num_debug_info_entries; i++)
3272 unsigned short length;
3273 unsigned long offset;
3274 unsigned int pointer_size;
3275 unsigned long cu_offset;
3276 unsigned long base_address;
3277 int need_frame_base;
3280 pointer_size = debug_information [i].pointer_size;
3281 cu_offset = debug_information [i].cu_offset;
3283 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
3285 has_frame_base = debug_information [i].have_frame_base [j];
3286 /* DWARF sections under Mach-O have non-zero addresses. */
3287 offset = debug_information [i].loc_offsets [j] - section->address;
3288 next = section_begin + offset;
3289 base_address = debug_information [i].base_address;
3291 if (!seen_first_offset)
3292 seen_first_offset = 1;
3296 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3297 (unsigned long) (start - section_begin),
3298 (unsigned long) (next - section_begin));
3299 else if (start > next)
3300 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3301 (unsigned long) (start - section_begin),
3302 (unsigned long) (next - section_begin));
3306 if (offset >= bytes)
3308 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3315 if (start + 2 * pointer_size > section_end)
3317 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3322 /* Note: we use sign extension here in order to be sure that
3323 we can detect the -1 escape value. Sign extension into the
3324 top 32 bits of a 32-bit address will not affect the values
3325 that we display since we always show hex values, and always
3326 the bottom 32-bits. */
3327 begin = byte_get_signed (start, pointer_size);
3328 start += pointer_size;
3329 end = byte_get_signed (start, pointer_size);
3330 start += pointer_size;
3332 printf (" %8.8lx ", offset);
3334 if (begin == 0 && end == 0)
3336 printf (_("<End of list>\n"));
3340 /* Check base address specifiers. */
3341 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3344 print_dwarf_vma (begin, pointer_size);
3345 print_dwarf_vma (end, pointer_size);
3346 printf (_("(base address)\n"));
3350 if (start + 2 > section_end)
3352 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3357 length = byte_get (start, 2);
3360 if (start + length > section_end)
3362 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3367 print_dwarf_vma (begin + base_address, pointer_size);
3368 print_dwarf_vma (end + base_address, pointer_size);
3371 need_frame_base = decode_location_expression (start,
3374 cu_offset, section);
3377 if (need_frame_base && !has_frame_base)
3378 printf (_(" [without DW_AT_frame_base]"));
3381 fputs (_(" (start == end)"), stdout);
3382 else if (begin > end)
3383 fputs (_(" (start > end)"), stdout);
3392 if (start < section_end)
3393 warn (_("There are %ld unused bytes at the end of section %s\n"),
3394 (long) (section_end - start), section->name);
3400 display_debug_str (struct dwarf_section *section,
3401 void *file ATTRIBUTE_UNUSED)
3403 unsigned char *start = section->start;
3404 unsigned long bytes = section->size;
3405 dwarf_vma addr = section->address;
3409 printf (_("\nThe %s section is empty.\n"), section->name);
3413 printf (_("Contents of the %s section:\n\n"), section->name);
3421 lbytes = (bytes > 16 ? 16 : bytes);
3423 printf (" 0x%8.8lx ", (unsigned long) addr);
3425 for (j = 0; j < 16; j++)
3428 printf ("%2.2x", start[j]);
3436 for (j = 0; j < lbytes; j++)
3439 if (k >= ' ' && k < 0x80)
3458 display_debug_info (struct dwarf_section *section, void *file)
3460 return process_debug_info (section, file, 0, 0);
3464 display_debug_types (struct dwarf_section *section, void *file)
3466 return process_debug_info (section, file, 0, 1);
3470 display_debug_aranges (struct dwarf_section *section,
3471 void *file ATTRIBUTE_UNUSED)
3473 unsigned char *start = section->start;
3474 unsigned char *end = start + section->size;
3476 printf (_("Contents of the %s section:\n\n"), section->name);
3478 /* It does not matter if this load fails,
3479 we test for that later on. */
3480 load_debug_info (file);
3484 unsigned char *hdrptr;
3485 DWARF2_Internal_ARange arange;
3486 unsigned char *addr_ranges;
3489 unsigned char address_size;
3492 int initial_length_size;
3496 arange.ar_length = byte_get (hdrptr, 4);
3499 if (arange.ar_length == 0xffffffff)
3501 arange.ar_length = byte_get (hdrptr, 8);
3504 initial_length_size = 12;
3509 initial_length_size = 4;
3512 arange.ar_version = byte_get (hdrptr, 2);
3515 arange.ar_info_offset = byte_get (hdrptr, offset_size);
3516 hdrptr += offset_size;
3518 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3519 && num_debug_info_entries > 0
3520 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
3521 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3522 arange.ar_info_offset, section->name);
3524 arange.ar_pointer_size = byte_get (hdrptr, 1);
3527 arange.ar_segment_size = byte_get (hdrptr, 1);
3530 if (arange.ar_version != 2 && arange.ar_version != 3)
3532 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3536 printf (_(" Length: %ld\n"), arange.ar_length);
3537 printf (_(" Version: %d\n"), arange.ar_version);
3538 printf (_(" Offset into .debug_info: 0x%lx\n"), arange.ar_info_offset);
3539 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
3540 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
3542 address_size = arange.ar_pointer_size + arange.ar_segment_size;
3544 /* The DWARF spec does not require that the address size be a power
3545 of two, but we do. This will have to change if we ever encounter
3546 an uneven architecture. */
3547 if ((address_size & (address_size - 1)) != 0)
3549 warn (_("Pointer size + Segment size is not a power of two.\n"));
3553 if (address_size > 4)
3554 printf (_("\n Address Length\n"));
3556 printf (_("\n Address Length\n"));
3558 addr_ranges = hdrptr;
3560 /* Must pad to an alignment boundary that is twice the address size. */
3561 excess = (hdrptr - start) % (2 * address_size);
3563 addr_ranges += (2 * address_size) - excess;
3565 start += arange.ar_length + initial_length_size;
3567 while (addr_ranges + 2 * address_size <= start)
3569 address = byte_get (addr_ranges, address_size);
3571 addr_ranges += address_size;
3573 length = byte_get (addr_ranges, address_size);
3575 addr_ranges += address_size;
3578 print_dwarf_vma (address, address_size);
3579 print_dwarf_vma (length, address_size);
3589 /* Each debug_information[x].range_lists[y] gets this representation for
3590 sorting purposes. */
3594 /* The debug_information[x].range_lists[y] value. */
3595 unsigned long ranges_offset;
3597 /* Original debug_information to find parameters of the data. */
3598 debug_info *debug_info_p;
3601 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3604 range_entry_compar (const void *ap, const void *bp)
3606 const struct range_entry *a_re = (const struct range_entry *) ap;
3607 const struct range_entry *b_re = (const struct range_entry *) bp;
3608 const unsigned long a = a_re->ranges_offset;
3609 const unsigned long b = b_re->ranges_offset;
3611 return (a > b) - (b > a);
3615 display_debug_ranges (struct dwarf_section *section,
3616 void *file ATTRIBUTE_UNUSED)
3618 unsigned char *start = section->start;
3619 unsigned char *section_end;
3620 unsigned long bytes;
3621 unsigned char *section_begin = start;
3622 unsigned int num_range_list, i;
3623 struct range_entry *range_entries, *range_entry_fill;
3625 bytes = section->size;
3626 section_end = start + bytes;
3630 printf (_("\nThe %s section is empty.\n"), section->name);
3634 if (load_debug_info (file) == 0)
3636 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3642 for (i = 0; i < num_debug_info_entries; i++)
3643 num_range_list += debug_information [i].num_range_lists;
3645 if (num_range_list == 0)
3646 error (_("No range lists in .debug_info section!\n"));
3648 range_entries = (struct range_entry *)
3649 xmalloc (sizeof (*range_entries) * num_range_list);
3650 range_entry_fill = range_entries;
3652 for (i = 0; i < num_debug_info_entries; i++)
3654 debug_info *debug_info_p = &debug_information[i];
3657 for (j = 0; j < debug_info_p->num_range_lists; j++)
3659 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
3660 range_entry_fill->debug_info_p = debug_info_p;
3665 qsort (range_entries, num_range_list, sizeof (*range_entries),
3666 range_entry_compar);
3668 /* DWARF sections under Mach-O have non-zero addresses. */
3669 if (range_entries[0].ranges_offset != section->address)
3670 warn (_("Range lists in %s section start at 0x%lx\n"),
3671 section->name, range_entries[0].ranges_offset);
3673 printf (_("Contents of the %s section:\n\n"), section->name);
3674 printf (_(" Offset Begin End\n"));
3676 for (i = 0; i < num_range_list; i++)
3678 struct range_entry *range_entry = &range_entries[i];
3679 debug_info *debug_info_p = range_entry->debug_info_p;
3680 unsigned int pointer_size;
3681 unsigned long offset;
3682 unsigned char *next;
3683 unsigned long base_address;
3685 pointer_size = debug_info_p->pointer_size;
3687 /* DWARF sections under Mach-O have non-zero addresses. */
3688 offset = range_entry->ranges_offset - section->address;
3689 next = section_begin + offset;
3690 base_address = debug_info_p->base_address;
3695 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3696 (unsigned long) (start - section_begin),
3697 (unsigned long) (next - section_begin), section->name);
3698 else if (start > next)
3699 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3700 (unsigned long) (start - section_begin),
3701 (unsigned long) (next - section_begin), section->name);
3710 /* Note: we use sign extension here in order to be sure that
3711 we can detect the -1 escape value. Sign extension into the
3712 top 32 bits of a 32-bit address will not affect the values
3713 that we display since we always show hex values, and always
3714 the bottom 32-bits. */
3715 begin = byte_get_signed (start, pointer_size);
3716 start += pointer_size;
3717 end = byte_get_signed (start, pointer_size);
3718 start += pointer_size;
3720 printf (" %8.8lx ", offset);
3722 if (begin == 0 && end == 0)
3724 printf (_("<End of list>\n"));
3728 /* Check base address specifiers. */
3729 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3732 print_dwarf_vma (begin, pointer_size);
3733 print_dwarf_vma (end, pointer_size);
3734 printf ("(base address)\n");
3738 print_dwarf_vma (begin + base_address, pointer_size);
3739 print_dwarf_vma (end + base_address, pointer_size);
3742 fputs (_("(start == end)"), stdout);
3743 else if (begin > end)
3744 fputs (_("(start > end)"), stdout);
3751 free (range_entries);
3756 typedef struct Frame_Chunk
3758 struct Frame_Chunk *next;
3759 unsigned char *chunk_start;
3761 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3762 short int *col_type;
3765 unsigned int code_factor;
3767 unsigned long pc_begin;
3768 unsigned long pc_range;
3772 unsigned char fde_encoding;
3773 unsigned char cfa_exp;
3777 static const char *const *dwarf_regnames;
3778 static unsigned int dwarf_regnames_count;
3780 /* A marker for a col_type that means this column was never referenced
3781 in the frame info. */
3782 #define DW_CFA_unreferenced (-1)
3784 /* Return 0 if not more space is needed, 1 if more space is needed,
3785 -1 for invalid reg. */
3788 frame_need_space (Frame_Chunk *fc, unsigned int reg)
3790 int prev = fc->ncols;
3792 if (reg < (unsigned int) fc->ncols)
3795 if (dwarf_regnames_count
3796 && reg > dwarf_regnames_count)
3799 fc->ncols = reg + 1;
3800 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
3801 sizeof (short int));
3802 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
3804 while (prev < fc->ncols)
3806 fc->col_type[prev] = DW_CFA_unreferenced;
3807 fc->col_offset[prev] = 0;
3813 static const char *const dwarf_regnames_i386[] =
3815 "eax", "ecx", "edx", "ebx",
3816 "esp", "ebp", "esi", "edi",
3817 "eip", "eflags", NULL,
3818 "st0", "st1", "st2", "st3",
3819 "st4", "st5", "st6", "st7",
3821 "xmm0", "xmm1", "xmm2", "xmm3",
3822 "xmm4", "xmm5", "xmm6", "xmm7",
3823 "mm0", "mm1", "mm2", "mm3",
3824 "mm4", "mm5", "mm6", "mm7",
3825 "fcw", "fsw", "mxcsr",
3826 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3830 static const char *const dwarf_regnames_x86_64[] =
3832 "rax", "rdx", "rcx", "rbx",
3833 "rsi", "rdi", "rbp", "rsp",
3834 "r8", "r9", "r10", "r11",
3835 "r12", "r13", "r14", "r15",
3837 "xmm0", "xmm1", "xmm2", "xmm3",
3838 "xmm4", "xmm5", "xmm6", "xmm7",
3839 "xmm8", "xmm9", "xmm10", "xmm11",
3840 "xmm12", "xmm13", "xmm14", "xmm15",
3841 "st0", "st1", "st2", "st3",
3842 "st4", "st5", "st6", "st7",
3843 "mm0", "mm1", "mm2", "mm3",
3844 "mm4", "mm5", "mm6", "mm7",
3846 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3847 "fs.base", "gs.base", NULL, NULL,
3849 "mxcsr", "fcw", "fsw"
3853 init_dwarf_regnames (unsigned int e_machine)
3859 dwarf_regnames = dwarf_regnames_i386;
3860 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
3864 dwarf_regnames = dwarf_regnames_x86_64;
3865 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
3874 regname (unsigned int regno, int row)
3876 static char reg[64];
3878 && regno < dwarf_regnames_count
3879 && dwarf_regnames [regno] != NULL)
3882 return dwarf_regnames [regno];
3883 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
3884 dwarf_regnames [regno]);
3887 snprintf (reg, sizeof (reg), "r%d", regno);
3892 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
3897 if (*max_regs < fc->ncols)
3898 *max_regs = fc->ncols;
3900 if (*need_col_headers)
3902 static const char *sloc = " LOC";
3904 *need_col_headers = 0;
3906 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
3908 for (r = 0; r < *max_regs; r++)
3909 if (fc->col_type[r] != DW_CFA_unreferenced)
3914 printf ("%-5s ", regname (r, 1));
3920 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
3922 strcpy (tmp, "exp");
3924 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
3925 printf ("%-8s ", tmp);
3927 for (r = 0; r < fc->ncols; r++)
3929 if (fc->col_type[r] != DW_CFA_unreferenced)
3931 switch (fc->col_type[r])
3933 case DW_CFA_undefined:
3936 case DW_CFA_same_value:
3940 sprintf (tmp, "c%+d", fc->col_offset[r]);
3942 case DW_CFA_val_offset:
3943 sprintf (tmp, "v%+d", fc->col_offset[r]);
3945 case DW_CFA_register:
3946 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
3948 case DW_CFA_expression:
3949 strcpy (tmp, "exp");
3951 case DW_CFA_val_expression:
3952 strcpy (tmp, "vexp");
3955 strcpy (tmp, "n/a");
3958 printf ("%-5s ", tmp);
3964 #define GET(N) byte_get (start, N); start += N
3965 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3966 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3969 display_debug_frames (struct dwarf_section *section,
3970 void *file ATTRIBUTE_UNUSED)
3972 unsigned char *start = section->start;
3973 unsigned char *end = start + section->size;
3974 unsigned char *section_start = start;
3975 Frame_Chunk *chunks = 0;
3976 Frame_Chunk *remembered_state = 0;
3978 int is_eh = strcmp (section->name, ".eh_frame") == 0;
3979 unsigned int length_return;
3981 const char *bad_reg = _("bad register: ");
3983 printf (_("Contents of the %s section:\n"), section->name);
3987 unsigned char *saved_start;
3988 unsigned char *block_end;
3989 unsigned long length;
3990 unsigned long cie_id;
3993 int need_col_headers = 1;
3994 unsigned char *augmentation_data = NULL;
3995 unsigned long augmentation_data_len = 0;
3996 int encoded_ptr_size = eh_addr_size;
3998 int initial_length_size;
4000 saved_start = start;
4001 length = byte_get (start, 4); start += 4;
4005 printf ("\n%08lx ZERO terminator\n\n",
4006 (unsigned long)(saved_start - section_start));
4010 if (length == 0xffffffff)
4012 length = byte_get (start, 8);
4015 initial_length_size = 12;
4020 initial_length_size = 4;
4023 block_end = saved_start + length + initial_length_size;
4024 if (block_end > end)
4026 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4027 length, (unsigned long)(saved_start - section_start));
4030 cie_id = byte_get (start, offset_size); start += offset_size;
4032 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4036 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4037 memset (fc, 0, sizeof (Frame_Chunk));
4041 fc->chunk_start = saved_start;
4043 fc->col_type = (short int *) xmalloc (sizeof (short int));
4044 fc->col_offset = (int *) xmalloc (sizeof (int));
4045 frame_need_space (fc, max_regs - 1);
4049 fc->augmentation = (char *) start;
4050 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4052 if (fc->augmentation[0] == 'z')
4054 fc->code_factor = LEB ();
4055 fc->data_factor = SLEB ();
4064 augmentation_data_len = LEB ();
4065 augmentation_data = start;
4066 start += augmentation_data_len;
4068 else if (strcmp (fc->augmentation, "eh") == 0)
4070 start += eh_addr_size;
4071 fc->code_factor = LEB ();
4072 fc->data_factor = SLEB ();
4084 fc->code_factor = LEB ();
4085 fc->data_factor = SLEB ();
4097 if (do_debug_frames_interp)
4098 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4099 (unsigned long)(saved_start - section_start), length, cie_id,
4100 fc->augmentation, fc->code_factor, fc->data_factor,
4104 printf ("\n%08lx %08lx %08lx CIE\n",
4105 (unsigned long)(saved_start - section_start), length, cie_id);
4106 printf (" Version: %d\n", version);
4107 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4108 printf (" Code alignment factor: %u\n", fc->code_factor);
4109 printf (" Data alignment factor: %d\n", fc->data_factor);
4110 printf (" Return address column: %d\n", fc->ra);
4112 if (augmentation_data_len)
4115 printf (" Augmentation data: ");
4116 for (i = 0; i < augmentation_data_len; ++i)
4117 printf (" %02x", augmentation_data[i]);
4123 if (augmentation_data_len)
4125 unsigned char *p, *q;
4126 p = (unsigned char *) fc->augmentation + 1;
4127 q = augmentation_data;
4134 q += 1 + size_of_encoded_value (*q);
4136 fc->fde_encoding = *q++;
4144 if (fc->fde_encoding)
4145 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4148 frame_need_space (fc, fc->ra);
4152 unsigned char *look_for;
4153 static Frame_Chunk fde_fc;
4156 memset (fc, 0, sizeof (Frame_Chunk));
4158 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
4160 for (cie = chunks; cie ; cie = cie->next)
4161 if (cie->chunk_start == look_for)
4166 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4167 cie_id, (unsigned long)(saved_start - section_start));
4169 fc->col_type = (short int *) xmalloc (sizeof (short int));
4170 fc->col_offset = (int *) xmalloc (sizeof (int));
4171 frame_need_space (fc, max_regs - 1);
4173 fc->augmentation = "";
4174 fc->fde_encoding = 0;
4178 fc->ncols = cie->ncols;
4179 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
4180 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
4181 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
4182 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
4183 fc->augmentation = cie->augmentation;
4184 fc->code_factor = cie->code_factor;
4185 fc->data_factor = cie->data_factor;
4186 fc->cfa_reg = cie->cfa_reg;
4187 fc->cfa_offset = cie->cfa_offset;
4189 frame_need_space (fc, max_regs - 1);
4190 fc->fde_encoding = cie->fde_encoding;
4193 if (fc->fde_encoding)
4194 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4196 fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
4197 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
4198 fc->pc_begin += section->address + (start - section_start);
4199 start += encoded_ptr_size;
4200 fc->pc_range = byte_get (start, encoded_ptr_size);
4201 start += encoded_ptr_size;
4203 if (cie->augmentation[0] == 'z')
4205 augmentation_data_len = LEB ();
4206 augmentation_data = start;
4207 start += augmentation_data_len;
4210 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
4211 (unsigned long)(saved_start - section_start), length, cie_id,
4212 (unsigned long)(cie->chunk_start - section_start),
4213 fc->pc_begin, fc->pc_begin + fc->pc_range);
4214 if (! do_debug_frames_interp && augmentation_data_len)
4218 printf (" Augmentation data: ");
4219 for (i = 0; i < augmentation_data_len; ++i)
4220 printf (" %02x", augmentation_data[i]);
4226 /* At this point, fc is the current chunk, cie (if any) is set, and
4227 we're about to interpret instructions for the chunk. */
4228 /* ??? At present we need to do this always, since this sizes the
4229 fc->col_type and fc->col_offset arrays, which we write into always.
4230 We should probably split the interpreted and non-interpreted bits
4231 into two different routines, since there's so much that doesn't
4232 really overlap between them. */
4233 if (1 || do_debug_frames_interp)
4235 /* Start by making a pass over the chunk, allocating storage
4236 and taking note of what registers are used. */
4237 unsigned char *tmp = start;
4239 while (start < block_end)
4242 unsigned long reg, temp;
4249 /* Warning: if you add any more cases to this switch, be
4250 sure to add them to the corresponding switch below. */
4253 case DW_CFA_advance_loc:
4257 if (frame_need_space (fc, opa) >= 0)
4258 fc->col_type[opa] = DW_CFA_undefined;
4260 case DW_CFA_restore:
4261 if (frame_need_space (fc, opa) >= 0)
4262 fc->col_type[opa] = DW_CFA_undefined;
4264 case DW_CFA_set_loc:
4265 start += encoded_ptr_size;
4267 case DW_CFA_advance_loc1:
4270 case DW_CFA_advance_loc2:
4273 case DW_CFA_advance_loc4:
4276 case DW_CFA_offset_extended:
4277 case DW_CFA_val_offset:
4278 reg = LEB (); LEB ();
4279 if (frame_need_space (fc, reg) >= 0)
4280 fc->col_type[reg] = DW_CFA_undefined;
4282 case DW_CFA_restore_extended:
4284 frame_need_space (fc, reg);
4285 if (frame_need_space (fc, reg) >= 0)
4286 fc->col_type[reg] = DW_CFA_undefined;
4288 case DW_CFA_undefined:
4290 if (frame_need_space (fc, reg) >= 0)
4291 fc->col_type[reg] = DW_CFA_undefined;
4293 case DW_CFA_same_value:
4295 if (frame_need_space (fc, reg) >= 0)
4296 fc->col_type[reg] = DW_CFA_undefined;
4298 case DW_CFA_register:
4299 reg = LEB (); LEB ();
4300 if (frame_need_space (fc, reg) >= 0)
4301 fc->col_type[reg] = DW_CFA_undefined;
4303 case DW_CFA_def_cfa:
4306 case DW_CFA_def_cfa_register:
4309 case DW_CFA_def_cfa_offset:
4312 case DW_CFA_def_cfa_expression:
4316 case DW_CFA_expression:
4317 case DW_CFA_val_expression:
4321 if (frame_need_space (fc, reg) >= 0)
4322 fc->col_type[reg] = DW_CFA_undefined;
4324 case DW_CFA_offset_extended_sf:
4325 case DW_CFA_val_offset_sf:
4326 reg = LEB (); SLEB ();
4327 if (frame_need_space (fc, reg) >= 0)
4328 fc->col_type[reg] = DW_CFA_undefined;
4330 case DW_CFA_def_cfa_sf:
4333 case DW_CFA_def_cfa_offset_sf:
4336 case DW_CFA_MIPS_advance_loc8:
4339 case DW_CFA_GNU_args_size:
4342 case DW_CFA_GNU_negative_offset_extended:
4343 reg = LEB (); LEB ();
4344 if (frame_need_space (fc, reg) >= 0)
4345 fc->col_type[reg] = DW_CFA_undefined;
4354 /* Now we know what registers are used, make a second pass over
4355 the chunk, this time actually printing out the info. */
4357 while (start < block_end)
4360 unsigned long ul, reg, roffs;
4363 const char *reg_prefix = "";
4370 /* Warning: if you add any more cases to this switch, be
4371 sure to add them to the corresponding switch above. */
4374 case DW_CFA_advance_loc:
4375 if (do_debug_frames_interp)
4376 frame_display_row (fc, &need_col_headers, &max_regs);
4378 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4379 opa * fc->code_factor,
4380 fc->pc_begin + opa * fc->code_factor);
4381 fc->pc_begin += opa * fc->code_factor;
4386 if (opa >= (unsigned int) fc->ncols)
4387 reg_prefix = bad_reg;
4388 if (! do_debug_frames_interp || *reg_prefix != '\0')
4389 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4390 reg_prefix, regname (opa, 0),
4391 roffs * fc->data_factor);
4392 if (*reg_prefix == '\0')
4394 fc->col_type[opa] = DW_CFA_offset;
4395 fc->col_offset[opa] = roffs * fc->data_factor;
4399 case DW_CFA_restore:
4400 if (opa >= (unsigned int) cie->ncols
4401 || opa >= (unsigned int) fc->ncols)
4402 reg_prefix = bad_reg;
4403 if (! do_debug_frames_interp || *reg_prefix != '\0')
4404 printf (" DW_CFA_restore: %s%s\n",
4405 reg_prefix, regname (opa, 0));
4406 if (*reg_prefix == '\0')
4408 fc->col_type[opa] = cie->col_type[opa];
4409 fc->col_offset[opa] = cie->col_offset[opa];
4413 case DW_CFA_set_loc:
4414 vma = get_encoded_value (start, fc->fde_encoding);
4415 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
4416 vma += section->address + (start - section_start);
4417 start += encoded_ptr_size;
4418 if (do_debug_frames_interp)
4419 frame_display_row (fc, &need_col_headers, &max_regs);
4421 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
4425 case DW_CFA_advance_loc1:
4426 ofs = byte_get (start, 1); start += 1;
4427 if (do_debug_frames_interp)
4428 frame_display_row (fc, &need_col_headers, &max_regs);
4430 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4431 ofs * fc->code_factor,
4432 fc->pc_begin + ofs * fc->code_factor);
4433 fc->pc_begin += ofs * fc->code_factor;
4436 case DW_CFA_advance_loc2:
4437 ofs = byte_get (start, 2); start += 2;
4438 if (do_debug_frames_interp)
4439 frame_display_row (fc, &need_col_headers, &max_regs);
4441 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4442 ofs * fc->code_factor,
4443 fc->pc_begin + ofs * fc->code_factor);
4444 fc->pc_begin += ofs * fc->code_factor;
4447 case DW_CFA_advance_loc4:
4448 ofs = byte_get (start, 4); start += 4;
4449 if (do_debug_frames_interp)
4450 frame_display_row (fc, &need_col_headers, &max_regs);
4452 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4453 ofs * fc->code_factor,
4454 fc->pc_begin + ofs * fc->code_factor);
4455 fc->pc_begin += ofs * fc->code_factor;
4458 case DW_CFA_offset_extended:
4461 if (reg >= (unsigned int) fc->ncols)
4462 reg_prefix = bad_reg;
4463 if (! do_debug_frames_interp || *reg_prefix != '\0')
4464 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4465 reg_prefix, regname (reg, 0),
4466 roffs * fc->data_factor);
4467 if (*reg_prefix == '\0')
4469 fc->col_type[reg] = DW_CFA_offset;
4470 fc->col_offset[reg] = roffs * fc->data_factor;
4474 case DW_CFA_val_offset:
4477 if (reg >= (unsigned int) fc->ncols)
4478 reg_prefix = bad_reg;
4479 if (! do_debug_frames_interp || *reg_prefix != '\0')
4480 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4481 reg_prefix, regname (reg, 0),
4482 roffs * fc->data_factor);
4483 if (*reg_prefix == '\0')
4485 fc->col_type[reg] = DW_CFA_val_offset;
4486 fc->col_offset[reg] = roffs * fc->data_factor;
4490 case DW_CFA_restore_extended:
4492 if (reg >= (unsigned int) cie->ncols
4493 || reg >= (unsigned int) fc->ncols)
4494 reg_prefix = bad_reg;
4495 if (! do_debug_frames_interp || *reg_prefix != '\0')
4496 printf (" DW_CFA_restore_extended: %s%s\n",
4497 reg_prefix, regname (reg, 0));
4498 if (*reg_prefix == '\0')
4500 fc->col_type[reg] = cie->col_type[reg];
4501 fc->col_offset[reg] = cie->col_offset[reg];
4505 case DW_CFA_undefined:
4507 if (reg >= (unsigned int) fc->ncols)
4508 reg_prefix = bad_reg;
4509 if (! do_debug_frames_interp || *reg_prefix != '\0')
4510 printf (" DW_CFA_undefined: %s%s\n",
4511 reg_prefix, regname (reg, 0));
4512 if (*reg_prefix == '\0')
4514 fc->col_type[reg] = DW_CFA_undefined;
4515 fc->col_offset[reg] = 0;
4519 case DW_CFA_same_value:
4521 if (reg >= (unsigned int) fc->ncols)
4522 reg_prefix = bad_reg;
4523 if (! do_debug_frames_interp || *reg_prefix != '\0')
4524 printf (" DW_CFA_same_value: %s%s\n",
4525 reg_prefix, regname (reg, 0));
4526 if (*reg_prefix == '\0')
4528 fc->col_type[reg] = DW_CFA_same_value;
4529 fc->col_offset[reg] = 0;
4533 case DW_CFA_register:
4536 if (reg >= (unsigned int) fc->ncols)
4537 reg_prefix = bad_reg;
4538 if (! do_debug_frames_interp || *reg_prefix != '\0')
4540 printf (" DW_CFA_register: %s%s in ",
4541 reg_prefix, regname (reg, 0));
4542 puts (regname (roffs, 0));
4544 if (*reg_prefix == '\0')
4546 fc->col_type[reg] = DW_CFA_register;
4547 fc->col_offset[reg] = roffs;
4551 case DW_CFA_remember_state:
4552 if (! do_debug_frames_interp)
4553 printf (" DW_CFA_remember_state\n");
4554 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4555 rs->ncols = fc->ncols;
4556 rs->col_type = (short int *) xcmalloc (rs->ncols,
4557 sizeof (short int));
4558 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
4559 memcpy (rs->col_type, fc->col_type, rs->ncols);
4560 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
4561 rs->next = remembered_state;
4562 remembered_state = rs;
4565 case DW_CFA_restore_state:
4566 if (! do_debug_frames_interp)
4567 printf (" DW_CFA_restore_state\n");
4568 rs = remembered_state;
4571 remembered_state = rs->next;
4572 frame_need_space (fc, rs->ncols - 1);
4573 memcpy (fc->col_type, rs->col_type, rs->ncols);
4574 memcpy (fc->col_offset, rs->col_offset,
4575 rs->ncols * sizeof (int));
4576 free (rs->col_type);
4577 free (rs->col_offset);
4580 else if (do_debug_frames_interp)
4581 printf ("Mismatched DW_CFA_restore_state\n");
4584 case DW_CFA_def_cfa:
4585 fc->cfa_reg = LEB ();
4586 fc->cfa_offset = LEB ();
4588 if (! do_debug_frames_interp)
4589 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4590 regname (fc->cfa_reg, 0), fc->cfa_offset);
4593 case DW_CFA_def_cfa_register:
4594 fc->cfa_reg = LEB ();
4596 if (! do_debug_frames_interp)
4597 printf (" DW_CFA_def_cfa_register: %s\n",
4598 regname (fc->cfa_reg, 0));
4601 case DW_CFA_def_cfa_offset:
4602 fc->cfa_offset = LEB ();
4603 if (! do_debug_frames_interp)
4604 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
4608 if (! do_debug_frames_interp)
4609 printf (" DW_CFA_nop\n");
4612 case DW_CFA_def_cfa_expression:
4614 if (! do_debug_frames_interp)
4616 printf (" DW_CFA_def_cfa_expression (");
4617 decode_location_expression (start, eh_addr_size, ul, 0,
4625 case DW_CFA_expression:
4628 if (reg >= (unsigned int) fc->ncols)
4629 reg_prefix = bad_reg;
4630 if (! do_debug_frames_interp || *reg_prefix != '\0')
4632 printf (" DW_CFA_expression: %s%s (",
4633 reg_prefix, regname (reg, 0));
4634 decode_location_expression (start, eh_addr_size,
4638 if (*reg_prefix == '\0')
4639 fc->col_type[reg] = DW_CFA_expression;
4643 case DW_CFA_val_expression:
4646 if (reg >= (unsigned int) fc->ncols)
4647 reg_prefix = bad_reg;
4648 if (! do_debug_frames_interp || *reg_prefix != '\0')
4650 printf (" DW_CFA_val_expression: %s%s (",
4651 reg_prefix, regname (reg, 0));
4652 decode_location_expression (start, eh_addr_size, ul, 0,
4656 if (*reg_prefix == '\0')
4657 fc->col_type[reg] = DW_CFA_val_expression;
4661 case DW_CFA_offset_extended_sf:
4664 if (frame_need_space (fc, reg) < 0)
4665 reg_prefix = bad_reg;
4666 if (! do_debug_frames_interp || *reg_prefix != '\0')
4667 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4668 reg_prefix, regname (reg, 0),
4669 l * fc->data_factor);
4670 if (*reg_prefix == '\0')
4672 fc->col_type[reg] = DW_CFA_offset;
4673 fc->col_offset[reg] = l * fc->data_factor;
4677 case DW_CFA_val_offset_sf:
4680 if (frame_need_space (fc, reg) < 0)
4681 reg_prefix = bad_reg;
4682 if (! do_debug_frames_interp || *reg_prefix != '\0')
4683 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4684 reg_prefix, regname (reg, 0),
4685 l * fc->data_factor);
4686 if (*reg_prefix == '\0')
4688 fc->col_type[reg] = DW_CFA_val_offset;
4689 fc->col_offset[reg] = l * fc->data_factor;
4693 case DW_CFA_def_cfa_sf:
4694 fc->cfa_reg = LEB ();
4695 fc->cfa_offset = SLEB ();
4696 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
4698 if (! do_debug_frames_interp)
4699 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4700 regname (fc->cfa_reg, 0), fc->cfa_offset);
4703 case DW_CFA_def_cfa_offset_sf:
4704 fc->cfa_offset = SLEB ();
4705 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
4706 if (! do_debug_frames_interp)
4707 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
4710 case DW_CFA_MIPS_advance_loc8:
4711 ofs = byte_get (start, 8); start += 8;
4712 if (do_debug_frames_interp)
4713 frame_display_row (fc, &need_col_headers, &max_regs);
4715 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4716 ofs * fc->code_factor,
4717 fc->pc_begin + ofs * fc->code_factor);
4718 fc->pc_begin += ofs * fc->code_factor;
4721 case DW_CFA_GNU_window_save:
4722 if (! do_debug_frames_interp)
4723 printf (" DW_CFA_GNU_window_save\n");
4726 case DW_CFA_GNU_args_size:
4728 if (! do_debug_frames_interp)
4729 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
4732 case DW_CFA_GNU_negative_offset_extended:
4735 if (frame_need_space (fc, reg) < 0)
4736 reg_prefix = bad_reg;
4737 if (! do_debug_frames_interp || *reg_prefix != '\0')
4738 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4739 reg_prefix, regname (reg, 0),
4740 l * fc->data_factor);
4741 if (*reg_prefix == '\0')
4743 fc->col_type[reg] = DW_CFA_offset;
4744 fc->col_offset[reg] = l * fc->data_factor;
4749 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
4750 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
4752 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
4757 if (do_debug_frames_interp)
4758 frame_display_row (fc, &need_col_headers, &max_regs);
4773 display_debug_not_supported (struct dwarf_section *section,
4774 void *file ATTRIBUTE_UNUSED)
4776 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4783 cmalloc (size_t nmemb, size_t size)
4785 /* Check for overflow. */
4786 if (nmemb >= ~(size_t) 0 / size)
4789 return malloc (nmemb * size);
4793 xcmalloc (size_t nmemb, size_t size)
4795 /* Check for overflow. */
4796 if (nmemb >= ~(size_t) 0 / size)
4799 return xmalloc (nmemb * size);
4803 xcrealloc (void *ptr, size_t nmemb, size_t size)
4805 /* Check for overflow. */
4806 if (nmemb >= ~(size_t) 0 / size)
4809 return xrealloc (ptr, nmemb * size);
4813 error (const char *message, ...)
4817 va_start (args, message);
4818 fprintf (stderr, _("%s: Error: "), program_name);
4819 vfprintf (stderr, message, args);
4824 warn (const char *message, ...)
4828 va_start (args, message);
4829 fprintf (stderr, _("%s: Warning: "), program_name);
4830 vfprintf (stderr, message, args);
4835 free_debug_memory (void)
4841 for (i = 0; i < max; i++)
4842 free_debug_section ((enum dwarf_section_display_enum) i);
4844 if (debug_information != NULL)
4846 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
4848 for (i = 0; i < num_debug_info_entries; i++)
4850 if (!debug_information [i].max_loc_offsets)
4852 free (debug_information [i].loc_offsets);
4853 free (debug_information [i].have_frame_base);
4855 if (!debug_information [i].max_range_lists)
4856 free (debug_information [i].range_lists);
4860 free (debug_information);
4861 debug_information = NULL;
4862 num_debug_info_entries = 0;
4867 dwarf_select_sections_by_names (const char *names)
4871 const char * option;
4875 debug_dump_long_opts;
4877 static const debug_dump_long_opts opts_table [] =
4879 /* Please keep this table alpha- sorted. */
4880 { "Ranges", & do_debug_ranges, 1 },
4881 { "abbrev", & do_debug_abbrevs, 1 },
4882 { "aranges", & do_debug_aranges, 1 },
4883 { "frames", & do_debug_frames, 1 },
4884 { "frames-interp", & do_debug_frames_interp, 1 },
4885 { "info", & do_debug_info, 1 },
4886 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
4887 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
4888 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
4889 { "loc", & do_debug_loc, 1 },
4890 { "macro", & do_debug_macinfo, 1 },
4891 { "pubnames", & do_debug_pubnames, 1 },
4892 { "pubtypes", & do_debug_pubtypes, 1 },
4893 /* This entry is for compatability
4894 with earlier versions of readelf. */
4895 { "ranges", & do_debug_aranges, 1 },
4896 { "str", & do_debug_str, 1 },
4905 const debug_dump_long_opts * entry;
4907 for (entry = opts_table; entry->option; entry++)
4909 size_t len = strlen (entry->option);
4911 if (strncmp (p, entry->option, len) == 0
4912 && (p[len] == ',' || p[len] == '\0'))
4914 * entry->variable |= entry->val;
4916 /* The --debug-dump=frames-interp option also
4917 enables the --debug-dump=frames option. */
4918 if (do_debug_frames_interp)
4919 do_debug_frames = 1;
4926 if (entry->option == NULL)
4928 warn (_("Unrecognized debug option '%s'\n"), p);
4929 p = strchr (p, ',');
4940 dwarf_select_sections_by_letters (const char *letters)
4942 unsigned int lindex = 0;
4944 while (letters[lindex])
4945 switch (letters[lindex++])
4952 do_debug_abbrevs = 1;
4956 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
4960 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
4964 do_debug_pubnames = 1;
4968 do_debug_pubtypes = 1;
4972 do_debug_aranges = 1;
4976 do_debug_ranges = 1;
4980 do_debug_frames_interp = 1;
4982 do_debug_frames = 1;
4986 do_debug_macinfo = 1;
4998 warn (_("Unrecognized debug option '%s'\n"), optarg);
5004 dwarf_select_sections_all (void)
5007 do_debug_abbrevs = 1;
5008 do_debug_lines = FLAG_DEBUG_LINES_RAW;
5009 do_debug_pubnames = 1;
5010 do_debug_pubtypes = 1;
5011 do_debug_aranges = 1;
5012 do_debug_ranges = 1;
5013 do_debug_frames = 1;
5014 do_debug_macinfo = 1;
5019 struct dwarf_section_display debug_displays[] =
5021 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 },
5022 display_debug_abbrev, &do_debug_abbrevs, 0 },
5023 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 },
5024 display_debug_aranges, &do_debug_aranges, 1 },
5025 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 },
5026 display_debug_frames, &do_debug_frames, 1 },
5027 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 },
5028 display_debug_info, &do_debug_info, 1 },
5029 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 },
5030 display_debug_lines, &do_debug_lines, 1 },
5031 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 },
5032 display_debug_pubnames, &do_debug_pubnames, 0 },
5033 { { ".eh_frame", "", NULL, NULL, 0, 0 },
5034 display_debug_frames, &do_debug_frames, 1 },
5035 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 },
5036 display_debug_macinfo, &do_debug_macinfo, 0 },
5037 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 },
5038 display_debug_str, &do_debug_str, 0 },
5039 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 },
5040 display_debug_loc, &do_debug_loc, 1 },
5041 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 },
5042 display_debug_pubnames, &do_debug_pubtypes, 0 },
5043 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 },
5044 display_debug_ranges, &do_debug_ranges, 1 },
5045 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 },
5046 display_debug_not_supported, NULL, 0 },
5047 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 },
5048 display_debug_not_supported, NULL, 0 },
5049 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 },
5050 display_debug_types, &do_debug_info, 1 },
5051 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 },
5052 display_debug_not_supported, NULL, 0 }