1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007
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/dwarf2.h"
29 static int have_frame_base;
30 static int need_base_address;
32 static unsigned int last_pointer_size = 0;
33 static int warned_about_missing_comp_units = FALSE;
35 static unsigned int num_debug_info_entries = 0;
36 static debug_info *debug_information = NULL;
38 dwarf_vma eh_addr_size;
44 int do_debug_pubnames;
48 int do_debug_frames_interp;
53 dwarf_vma (*byte_get) (unsigned char *, int);
56 byte_get_little_endian (unsigned char *field, int size)
64 return ((unsigned int) (field[0]))
65 | (((unsigned int) (field[1])) << 8);
68 return ((unsigned long) (field[0]))
69 | (((unsigned long) (field[1])) << 8)
70 | (((unsigned long) (field[2])) << 16)
71 | (((unsigned long) (field[3])) << 24);
74 if (sizeof (dwarf_vma) == 8)
75 return ((dwarf_vma) (field[0]))
76 | (((dwarf_vma) (field[1])) << 8)
77 | (((dwarf_vma) (field[2])) << 16)
78 | (((dwarf_vma) (field[3])) << 24)
79 | (((dwarf_vma) (field[4])) << 32)
80 | (((dwarf_vma) (field[5])) << 40)
81 | (((dwarf_vma) (field[6])) << 48)
82 | (((dwarf_vma) (field[7])) << 56);
83 else if (sizeof (dwarf_vma) == 4)
84 /* We want to extract data from an 8 byte wide field and
85 place it into a 4 byte wide field. Since this is a little
86 endian source we can just use the 4 byte extraction code. */
87 return ((unsigned long) (field[0]))
88 | (((unsigned long) (field[1])) << 8)
89 | (((unsigned long) (field[2])) << 16)
90 | (((unsigned long) (field[3])) << 24);
93 error (_("Unhandled data length: %d\n"), size);
99 byte_get_big_endian (unsigned char *field, int size)
107 return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
110 return ((unsigned long) (field[3]))
111 | (((unsigned long) (field[2])) << 8)
112 | (((unsigned long) (field[1])) << 16)
113 | (((unsigned long) (field[0])) << 24);
116 if (sizeof (dwarf_vma) == 8)
117 return ((dwarf_vma) (field[7]))
118 | (((dwarf_vma) (field[6])) << 8)
119 | (((dwarf_vma) (field[5])) << 16)
120 | (((dwarf_vma) (field[4])) << 24)
121 | (((dwarf_vma) (field[3])) << 32)
122 | (((dwarf_vma) (field[2])) << 40)
123 | (((dwarf_vma) (field[1])) << 48)
124 | (((dwarf_vma) (field[0])) << 56);
125 else if (sizeof (dwarf_vma) == 4)
127 /* Although we are extracing data from an 8 byte wide field,
128 we are returning only 4 bytes of data. */
130 return ((unsigned long) (field[3]))
131 | (((unsigned long) (field[2])) << 8)
132 | (((unsigned long) (field[1])) << 16)
133 | (((unsigned long) (field[0])) << 24);
137 error (_("Unhandled data length: %d\n"), size);
143 byte_get_signed (unsigned char *field, int size)
145 dwarf_vma x = byte_get (field, size);
150 return (x ^ 0x80) - 0x80;
152 return (x ^ 0x8000) - 0x8000;
154 return (x ^ 0x80000000) - 0x80000000;
162 static unsigned long int
163 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
165 unsigned long int result = 0;
166 unsigned int num_read = 0;
167 unsigned int shift = 0;
175 result |= ((unsigned long int) (byte & 0x7f)) << shift;
182 if (length_return != NULL)
183 *length_return = num_read;
185 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
186 result |= -1L << shift;
191 typedef struct State_Machine_Registers
193 unsigned long address;
200 /* This variable hold the number of the last entry seen
201 in the File Table. */
202 unsigned int last_file_entry;
205 static SMR state_machine_regs;
208 reset_state_machine (int is_stmt)
210 state_machine_regs.address = 0;
211 state_machine_regs.file = 1;
212 state_machine_regs.line = 1;
213 state_machine_regs.column = 0;
214 state_machine_regs.is_stmt = is_stmt;
215 state_machine_regs.basic_block = 0;
216 state_machine_regs.end_sequence = 0;
217 state_machine_regs.last_file_entry = 0;
220 /* Handled an extend line op.
221 Returns the number of bytes read. */
224 process_extended_line_op (unsigned char *data, int is_stmt)
226 unsigned char op_code;
227 unsigned int bytes_read;
232 len = read_leb128 (data, & bytes_read, 0);
237 warn (_("badly formed extended line op encountered!\n"));
244 printf (_(" Extended opcode %d: "), op_code);
248 case DW_LNE_end_sequence:
249 printf (_("End of Sequence\n\n"));
250 reset_state_machine (is_stmt);
253 case DW_LNE_set_address:
254 adr = byte_get (data, len - bytes_read - 1);
255 printf (_("set Address to 0x%lx\n"), adr);
256 state_machine_regs.address = adr;
259 case DW_LNE_define_file:
260 printf (_(" define new File Table entry\n"));
261 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
263 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
265 data += strlen ((char *) data) + 1;
266 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
268 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
270 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
271 printf (_("%s\n\n"), name);
275 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
283 fetch_indirect_string (unsigned long offset)
285 struct dwarf_section *section = &debug_displays [str].section;
287 if (section->start == NULL)
288 return _("<no .debug_str section>");
290 /* DWARF sections under Mach-O have non-zero addresses. */
291 offset -= section->address;
292 if (offset > section->size)
294 warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
295 return _("<offset is too big>");
298 return (const char *) section->start + offset;
301 /* FIXME: There are better and more efficient ways to handle
302 these structures. For now though, I just want something that
303 is simple to implement. */
304 typedef struct abbrev_attr
306 unsigned long attribute;
308 struct abbrev_attr *next;
312 typedef struct abbrev_entry
317 struct abbrev_attr *first_attr;
318 struct abbrev_attr *last_attr;
319 struct abbrev_entry *next;
323 static abbrev_entry *first_abbrev = NULL;
324 static abbrev_entry *last_abbrev = NULL;
329 abbrev_entry *abbrev;
331 for (abbrev = first_abbrev; abbrev;)
333 abbrev_entry *next = abbrev->next;
336 for (attr = abbrev->first_attr; attr;)
338 abbrev_attr *next = attr->next;
348 last_abbrev = first_abbrev = NULL;
352 add_abbrev (unsigned long number, unsigned long tag, int children)
356 entry = malloc (sizeof (*entry));
362 entry->entry = number;
364 entry->children = children;
365 entry->first_attr = NULL;
366 entry->last_attr = NULL;
369 if (first_abbrev == NULL)
370 first_abbrev = entry;
372 last_abbrev->next = entry;
378 add_abbrev_attr (unsigned long attribute, unsigned long form)
382 attr = malloc (sizeof (*attr));
388 attr->attribute = attribute;
392 if (last_abbrev->first_attr == NULL)
393 last_abbrev->first_attr = attr;
395 last_abbrev->last_attr->next = attr;
397 last_abbrev->last_attr = attr;
400 /* Processes the (partial) contents of a .debug_abbrev section.
401 Returns NULL if the end of the section was encountered.
402 Returns the address after the last byte read if the end of
403 an abbreviation set was found. */
405 static unsigned char *
406 process_abbrev_section (unsigned char *start, unsigned char *end)
408 if (first_abbrev != NULL)
413 unsigned int bytes_read;
416 unsigned long attribute;
419 entry = read_leb128 (start, & bytes_read, 0);
422 /* A single zero is supposed to end the section according
423 to the standard. If there's more, then signal that to
426 return start == end ? NULL : start;
428 tag = read_leb128 (start, & bytes_read, 0);
433 add_abbrev (entry, tag, children);
439 attribute = read_leb128 (start, & bytes_read, 0);
442 form = read_leb128 (start, & bytes_read, 0);
446 add_abbrev_attr (attribute, form);
448 while (attribute != 0);
455 get_TAG_name (unsigned long tag)
459 case DW_TAG_padding: return "DW_TAG_padding";
460 case DW_TAG_array_type: return "DW_TAG_array_type";
461 case DW_TAG_class_type: return "DW_TAG_class_type";
462 case DW_TAG_entry_point: return "DW_TAG_entry_point";
463 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
464 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
465 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
466 case DW_TAG_label: return "DW_TAG_label";
467 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
468 case DW_TAG_member: return "DW_TAG_member";
469 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
470 case DW_TAG_reference_type: return "DW_TAG_reference_type";
471 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
472 case DW_TAG_string_type: return "DW_TAG_string_type";
473 case DW_TAG_structure_type: return "DW_TAG_structure_type";
474 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
475 case DW_TAG_typedef: return "DW_TAG_typedef";
476 case DW_TAG_union_type: return "DW_TAG_union_type";
477 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
478 case DW_TAG_variant: return "DW_TAG_variant";
479 case DW_TAG_common_block: return "DW_TAG_common_block";
480 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
481 case DW_TAG_inheritance: return "DW_TAG_inheritance";
482 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
483 case DW_TAG_module: return "DW_TAG_module";
484 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
485 case DW_TAG_set_type: return "DW_TAG_set_type";
486 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
487 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
488 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
489 case DW_TAG_base_type: return "DW_TAG_base_type";
490 case DW_TAG_catch_block: return "DW_TAG_catch_block";
491 case DW_TAG_const_type: return "DW_TAG_const_type";
492 case DW_TAG_constant: return "DW_TAG_constant";
493 case DW_TAG_enumerator: return "DW_TAG_enumerator";
494 case DW_TAG_file_type: return "DW_TAG_file_type";
495 case DW_TAG_friend: return "DW_TAG_friend";
496 case DW_TAG_namelist: return "DW_TAG_namelist";
497 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
498 case DW_TAG_packed_type: return "DW_TAG_packed_type";
499 case DW_TAG_subprogram: return "DW_TAG_subprogram";
500 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
501 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
502 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
503 case DW_TAG_try_block: return "DW_TAG_try_block";
504 case DW_TAG_variant_part: return "DW_TAG_variant_part";
505 case DW_TAG_variable: return "DW_TAG_variable";
506 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
507 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
508 case DW_TAG_format_label: return "DW_TAG_format_label";
509 case DW_TAG_function_template: return "DW_TAG_function_template";
510 case DW_TAG_class_template: return "DW_TAG_class_template";
511 /* DWARF 2.1 values. */
512 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
513 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
514 case DW_TAG_interface_type: return "DW_TAG_interface_type";
515 case DW_TAG_namespace: return "DW_TAG_namespace";
516 case DW_TAG_imported_module: return "DW_TAG_imported_module";
517 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
518 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
519 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
521 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
522 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
523 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
526 static char buffer[100];
528 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
535 get_FORM_name (unsigned long form)
539 case DW_FORM_addr: return "DW_FORM_addr";
540 case DW_FORM_block2: return "DW_FORM_block2";
541 case DW_FORM_block4: return "DW_FORM_block4";
542 case DW_FORM_data2: return "DW_FORM_data2";
543 case DW_FORM_data4: return "DW_FORM_data4";
544 case DW_FORM_data8: return "DW_FORM_data8";
545 case DW_FORM_string: return "DW_FORM_string";
546 case DW_FORM_block: return "DW_FORM_block";
547 case DW_FORM_block1: return "DW_FORM_block1";
548 case DW_FORM_data1: return "DW_FORM_data1";
549 case DW_FORM_flag: return "DW_FORM_flag";
550 case DW_FORM_sdata: return "DW_FORM_sdata";
551 case DW_FORM_strp: return "DW_FORM_strp";
552 case DW_FORM_udata: return "DW_FORM_udata";
553 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
554 case DW_FORM_ref1: return "DW_FORM_ref1";
555 case DW_FORM_ref2: return "DW_FORM_ref2";
556 case DW_FORM_ref4: return "DW_FORM_ref4";
557 case DW_FORM_ref8: return "DW_FORM_ref8";
558 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
559 case DW_FORM_indirect: return "DW_FORM_indirect";
562 static char buffer[100];
564 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
570 static unsigned char *
571 display_block (unsigned char *data, unsigned long length)
573 printf (_(" %lu byte block: "), length);
576 printf ("%lx ", (unsigned long) byte_get (data++, 1));
582 decode_location_expression (unsigned char * data,
583 unsigned int pointer_size,
584 unsigned long length,
585 unsigned long cu_offset)
588 unsigned int bytes_read;
589 unsigned long uvalue;
590 unsigned char *end = data + length;
591 int need_frame_base = 0;
600 printf ("DW_OP_addr: %lx",
601 (unsigned long) byte_get (data, pointer_size));
602 data += pointer_size;
605 printf ("DW_OP_deref");
608 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
611 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
614 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
618 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
622 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
626 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
630 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
631 (unsigned long) byte_get (data + 4, 4));
635 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
636 (long) byte_get (data + 4, 4));
640 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
644 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
648 printf ("DW_OP_dup");
651 printf ("DW_OP_drop");
654 printf ("DW_OP_over");
657 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
660 printf ("DW_OP_swap");
663 printf ("DW_OP_rot");
666 printf ("DW_OP_xderef");
669 printf ("DW_OP_abs");
672 printf ("DW_OP_and");
675 printf ("DW_OP_div");
678 printf ("DW_OP_minus");
681 printf ("DW_OP_mod");
684 printf ("DW_OP_mul");
687 printf ("DW_OP_neg");
690 printf ("DW_OP_not");
696 printf ("DW_OP_plus");
698 case DW_OP_plus_uconst:
699 printf ("DW_OP_plus_uconst: %lu",
700 read_leb128 (data, &bytes_read, 0));
704 printf ("DW_OP_shl");
707 printf ("DW_OP_shr");
710 printf ("DW_OP_shra");
713 printf ("DW_OP_xor");
716 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
738 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
774 printf ("DW_OP_lit%d", op - DW_OP_lit0);
809 printf ("DW_OP_reg%d", op - DW_OP_reg0);
844 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
845 read_leb128 (data, &bytes_read, 1));
850 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
855 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
859 uvalue = read_leb128 (data, &bytes_read, 0);
861 printf ("DW_OP_bregx: %lu %ld", uvalue,
862 read_leb128 (data, &bytes_read, 1));
866 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
869 case DW_OP_deref_size:
870 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
872 case DW_OP_xderef_size:
873 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
876 printf ("DW_OP_nop");
879 /* DWARF 3 extensions. */
880 case DW_OP_push_object_address:
881 printf ("DW_OP_push_object_address");
884 /* XXX: Strictly speaking for 64-bit DWARF3 files
885 this ought to be an 8-byte wide computation. */
886 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset);
890 /* XXX: Strictly speaking for 64-bit DWARF3 files
891 this ought to be an 8-byte wide computation. */
892 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset);
896 printf ("DW_OP_call_ref");
898 case DW_OP_form_tls_address:
899 printf ("DW_OP_form_tls_address");
902 /* GNU extensions. */
903 case DW_OP_GNU_push_tls_address:
904 printf ("DW_OP_GNU_push_tls_address");
908 if (op >= DW_OP_lo_user
909 && op <= DW_OP_hi_user)
910 printf (_("(User defined location op)"));
912 printf (_("(Unknown location op)"));
913 /* No way to tell where the next op is, so just bail. */
914 return need_frame_base;
917 /* Separate the ops. */
922 return need_frame_base;
925 static unsigned char *
926 read_and_display_attr_value (unsigned long attribute,
929 unsigned long cu_offset,
930 unsigned long pointer_size,
931 unsigned long offset_size,
933 debug_info *debug_info_p,
936 unsigned long uvalue = 0;
937 unsigned char *block_start = NULL;
938 unsigned int bytes_read;
945 case DW_FORM_ref_addr:
946 if (dwarf_version == 2)
948 uvalue = byte_get (data, pointer_size);
949 data += pointer_size;
951 else if (dwarf_version == 3)
953 uvalue = byte_get (data, offset_size);
958 error (_("Internal error: DWARF version is not 2 or 3.\n"));
963 uvalue = byte_get (data, pointer_size);
964 data += pointer_size;
968 uvalue = byte_get (data, offset_size);
975 uvalue = byte_get (data++, 1);
980 uvalue = byte_get (data, 2);
986 uvalue = byte_get (data, 4);
991 uvalue = read_leb128 (data, & bytes_read, 1);
995 case DW_FORM_ref_udata:
997 uvalue = read_leb128 (data, & bytes_read, 0);
1001 case DW_FORM_indirect:
1002 form = read_leb128 (data, & bytes_read, 0);
1005 printf (" %s", get_FORM_name (form));
1006 return read_and_display_attr_value (attribute, form, data,
1007 cu_offset, pointer_size,
1008 offset_size, dwarf_version,
1009 debug_info_p, do_loc);
1014 case DW_FORM_ref_addr:
1016 printf (" <#%lx>", uvalue);
1022 case DW_FORM_ref_udata:
1024 printf (" <%lx>", uvalue + cu_offset);
1030 printf (" %#lx", uvalue);
1039 printf (" %ld", uvalue);
1046 uvalue = byte_get (data, 4);
1047 printf (" %lx", uvalue);
1048 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
1050 if ((do_loc || do_debug_loc || do_debug_ranges)
1051 && num_debug_info_entries == 0)
1053 if (sizeof (uvalue) == 8)
1054 uvalue = byte_get (data, 8);
1056 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1061 case DW_FORM_string:
1063 printf (" %s", data);
1064 data += strlen ((char *) data) + 1;
1068 uvalue = read_leb128 (data, & bytes_read, 0);
1069 block_start = data + bytes_read;
1071 data = block_start + uvalue;
1073 data = display_block (block_start, uvalue);
1076 case DW_FORM_block1:
1077 uvalue = byte_get (data, 1);
1078 block_start = data + 1;
1080 data = block_start + uvalue;
1082 data = display_block (block_start, uvalue);
1085 case DW_FORM_block2:
1086 uvalue = byte_get (data, 2);
1087 block_start = data + 2;
1089 data = block_start + uvalue;
1091 data = display_block (block_start, uvalue);
1094 case DW_FORM_block4:
1095 uvalue = byte_get (data, 4);
1096 block_start = data + 4;
1098 data = block_start + uvalue;
1100 data = display_block (block_start, uvalue);
1105 printf (_(" (indirect string, offset: 0x%lx): %s"),
1106 uvalue, fetch_indirect_string (uvalue));
1109 case DW_FORM_indirect:
1110 /* Handled above. */
1114 warn (_("Unrecognized form: %lu\n"), form);
1118 /* For some attributes we can display further information. */
1119 if ((do_loc || do_debug_loc || do_debug_ranges)
1120 && num_debug_info_entries == 0)
1124 case DW_AT_frame_base:
1125 have_frame_base = 1;
1126 case DW_AT_location:
1127 case DW_AT_data_member_location:
1128 case DW_AT_vtable_elem_location:
1129 case DW_AT_allocated:
1130 case DW_AT_associated:
1131 case DW_AT_data_location:
1133 case DW_AT_upper_bound:
1134 case DW_AT_lower_bound:
1135 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1137 /* Process location list. */
1138 unsigned int max = debug_info_p->max_loc_offsets;
1139 unsigned int num = debug_info_p->num_loc_offsets;
1141 if (max == 0 || num >= max)
1144 debug_info_p->loc_offsets
1145 = xcrealloc (debug_info_p->loc_offsets,
1146 max, sizeof (*debug_info_p->loc_offsets));
1147 debug_info_p->have_frame_base
1148 = xcrealloc (debug_info_p->have_frame_base,
1149 max, sizeof (*debug_info_p->have_frame_base));
1150 debug_info_p->max_loc_offsets = max;
1152 debug_info_p->loc_offsets [num] = uvalue;
1153 debug_info_p->have_frame_base [num] = have_frame_base;
1154 debug_info_p->num_loc_offsets++;
1159 if (need_base_address)
1160 debug_info_p->base_address = uvalue;
1164 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1166 /* Process range list. */
1167 unsigned int max = debug_info_p->max_range_lists;
1168 unsigned int num = debug_info_p->num_range_lists;
1170 if (max == 0 || num >= max)
1173 debug_info_p->range_lists
1174 = xcrealloc (debug_info_p->range_lists,
1175 max, sizeof (*debug_info_p->range_lists));
1176 debug_info_p->max_range_lists = max;
1178 debug_info_p->range_lists [num] = uvalue;
1179 debug_info_p->num_range_lists++;
1198 case DW_INL_not_inlined:
1199 printf (_("(not inlined)"));
1201 case DW_INL_inlined:
1202 printf (_("(inlined)"));
1204 case DW_INL_declared_not_inlined:
1205 printf (_("(declared as inline but ignored)"));
1207 case DW_INL_declared_inlined:
1208 printf (_("(declared as inline and inlined)"));
1211 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
1216 case DW_AT_language:
1219 /* Ordered by the numeric value of these constants. */
1220 case DW_LANG_C89: printf ("(ANSI C)"); break;
1221 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1222 case DW_LANG_Ada83: printf ("(Ada)"); break;
1223 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1224 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1225 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1226 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1227 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1228 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1229 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1230 /* DWARF 2.1 values. */
1231 case DW_LANG_Java: printf ("(Java)"); break;
1232 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1233 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1234 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1235 /* DWARF 3 values. */
1236 case DW_LANG_PLI: printf ("(PLI)"); break;
1237 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1238 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1239 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1240 case DW_LANG_D: printf ("(D)"); break;
1241 /* MIPS extension. */
1242 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1243 /* UPC extension. */
1244 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1246 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1247 printf ("(implementation defined: %lx)", uvalue);
1249 printf ("(Unknown: %lx)", uvalue);
1254 case DW_AT_encoding:
1257 case DW_ATE_void: printf ("(void)"); break;
1258 case DW_ATE_address: printf ("(machine address)"); break;
1259 case DW_ATE_boolean: printf ("(boolean)"); break;
1260 case DW_ATE_complex_float: printf ("(complex float)"); break;
1261 case DW_ATE_float: printf ("(float)"); break;
1262 case DW_ATE_signed: printf ("(signed)"); break;
1263 case DW_ATE_signed_char: printf ("(signed char)"); break;
1264 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1265 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1266 /* DWARF 2.1 value. */
1267 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1268 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1270 if (uvalue >= DW_ATE_lo_user
1271 && uvalue <= DW_ATE_hi_user)
1272 printf ("(user defined type)");
1274 printf ("(unknown type)");
1279 case DW_AT_accessibility:
1282 case DW_ACCESS_public: printf ("(public)"); break;
1283 case DW_ACCESS_protected: printf ("(protected)"); break;
1284 case DW_ACCESS_private: printf ("(private)"); break;
1286 printf ("(unknown accessibility)");
1291 case DW_AT_visibility:
1294 case DW_VIS_local: printf ("(local)"); break;
1295 case DW_VIS_exported: printf ("(exported)"); break;
1296 case DW_VIS_qualified: printf ("(qualified)"); break;
1297 default: printf ("(unknown visibility)"); break;
1301 case DW_AT_virtuality:
1304 case DW_VIRTUALITY_none: printf ("(none)"); break;
1305 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1306 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1307 default: printf ("(unknown virtuality)"); break;
1311 case DW_AT_identifier_case:
1314 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1315 case DW_ID_up_case: printf ("(up_case)"); break;
1316 case DW_ID_down_case: printf ("(down_case)"); break;
1317 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1318 default: printf ("(unknown case)"); break;
1322 case DW_AT_calling_convention:
1325 case DW_CC_normal: printf ("(normal)"); break;
1326 case DW_CC_program: printf ("(program)"); break;
1327 case DW_CC_nocall: printf ("(nocall)"); break;
1329 if (uvalue >= DW_CC_lo_user
1330 && uvalue <= DW_CC_hi_user)
1331 printf ("(user defined)");
1333 printf ("(unknown convention)");
1337 case DW_AT_ordering:
1340 case -1: printf ("(undefined)"); break;
1341 case 0: printf ("(row major)"); break;
1342 case 1: printf ("(column major)"); break;
1346 case DW_AT_frame_base:
1347 have_frame_base = 1;
1348 case DW_AT_location:
1349 case DW_AT_data_member_location:
1350 case DW_AT_vtable_elem_location:
1351 case DW_AT_allocated:
1352 case DW_AT_associated:
1353 case DW_AT_data_location:
1355 case DW_AT_upper_bound:
1356 case DW_AT_lower_bound:
1359 int need_frame_base;
1362 need_frame_base = decode_location_expression (block_start,
1367 if (need_frame_base && !have_frame_base)
1368 printf (_(" [without DW_AT_frame_base]"));
1370 else if (form == DW_FORM_data4 || form == DW_FORM_data8)
1371 printf (_("(location list)"));
1383 get_AT_name (unsigned long attribute)
1387 case DW_AT_sibling: return "DW_AT_sibling";
1388 case DW_AT_location: return "DW_AT_location";
1389 case DW_AT_name: return "DW_AT_name";
1390 case DW_AT_ordering: return "DW_AT_ordering";
1391 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1392 case DW_AT_byte_size: return "DW_AT_byte_size";
1393 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1394 case DW_AT_bit_size: return "DW_AT_bit_size";
1395 case DW_AT_element_list: return "DW_AT_element_list";
1396 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1397 case DW_AT_low_pc: return "DW_AT_low_pc";
1398 case DW_AT_high_pc: return "DW_AT_high_pc";
1399 case DW_AT_language: return "DW_AT_language";
1400 case DW_AT_member: return "DW_AT_member";
1401 case DW_AT_discr: return "DW_AT_discr";
1402 case DW_AT_discr_value: return "DW_AT_discr_value";
1403 case DW_AT_visibility: return "DW_AT_visibility";
1404 case DW_AT_import: return "DW_AT_import";
1405 case DW_AT_string_length: return "DW_AT_string_length";
1406 case DW_AT_common_reference: return "DW_AT_common_reference";
1407 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1408 case DW_AT_const_value: return "DW_AT_const_value";
1409 case DW_AT_containing_type: return "DW_AT_containing_type";
1410 case DW_AT_default_value: return "DW_AT_default_value";
1411 case DW_AT_inline: return "DW_AT_inline";
1412 case DW_AT_is_optional: return "DW_AT_is_optional";
1413 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1414 case DW_AT_producer: return "DW_AT_producer";
1415 case DW_AT_prototyped: return "DW_AT_prototyped";
1416 case DW_AT_return_addr: return "DW_AT_return_addr";
1417 case DW_AT_start_scope: return "DW_AT_start_scope";
1418 case DW_AT_stride_size: return "DW_AT_stride_size";
1419 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1420 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1421 case DW_AT_accessibility: return "DW_AT_accessibility";
1422 case DW_AT_address_class: return "DW_AT_address_class";
1423 case DW_AT_artificial: return "DW_AT_artificial";
1424 case DW_AT_base_types: return "DW_AT_base_types";
1425 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1426 case DW_AT_count: return "DW_AT_count";
1427 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1428 case DW_AT_decl_column: return "DW_AT_decl_column";
1429 case DW_AT_decl_file: return "DW_AT_decl_file";
1430 case DW_AT_decl_line: return "DW_AT_decl_line";
1431 case DW_AT_declaration: return "DW_AT_declaration";
1432 case DW_AT_discr_list: return "DW_AT_discr_list";
1433 case DW_AT_encoding: return "DW_AT_encoding";
1434 case DW_AT_external: return "DW_AT_external";
1435 case DW_AT_frame_base: return "DW_AT_frame_base";
1436 case DW_AT_friend: return "DW_AT_friend";
1437 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1438 case DW_AT_macro_info: return "DW_AT_macro_info";
1439 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1440 case DW_AT_priority: return "DW_AT_priority";
1441 case DW_AT_segment: return "DW_AT_segment";
1442 case DW_AT_specification: return "DW_AT_specification";
1443 case DW_AT_static_link: return "DW_AT_static_link";
1444 case DW_AT_type: return "DW_AT_type";
1445 case DW_AT_use_location: return "DW_AT_use_location";
1446 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1447 case DW_AT_virtuality: return "DW_AT_virtuality";
1448 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1449 /* DWARF 2.1 values. */
1450 case DW_AT_allocated: return "DW_AT_allocated";
1451 case DW_AT_associated: return "DW_AT_associated";
1452 case DW_AT_data_location: return "DW_AT_data_location";
1453 case DW_AT_stride: return "DW_AT_stride";
1454 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1455 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1456 case DW_AT_extension: return "DW_AT_extension";
1457 case DW_AT_ranges: return "DW_AT_ranges";
1458 case DW_AT_trampoline: return "DW_AT_trampoline";
1459 case DW_AT_call_column: return "DW_AT_call_column";
1460 case DW_AT_call_file: return "DW_AT_call_file";
1461 case DW_AT_call_line: return "DW_AT_call_line";
1462 /* SGI/MIPS extensions. */
1463 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
1464 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1465 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1466 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1467 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1468 case DW_AT_MIPS_software_pipeline_depth:
1469 return "DW_AT_MIPS_software_pipeline_depth";
1470 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1471 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1472 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1473 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1474 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1475 /* GNU extensions. */
1476 case DW_AT_sf_names: return "DW_AT_sf_names";
1477 case DW_AT_src_info: return "DW_AT_src_info";
1478 case DW_AT_mac_info: return "DW_AT_mac_info";
1479 case DW_AT_src_coords: return "DW_AT_src_coords";
1480 case DW_AT_body_begin: return "DW_AT_body_begin";
1481 case DW_AT_body_end: return "DW_AT_body_end";
1482 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1483 /* UPC extension. */
1484 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1487 static char buffer[100];
1489 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1496 static unsigned char *
1497 read_and_display_attr (unsigned long attribute,
1499 unsigned char *data,
1500 unsigned long cu_offset,
1501 unsigned long pointer_size,
1502 unsigned long offset_size,
1504 debug_info *debug_info_p,
1508 printf (" %-18s:", get_AT_name (attribute));
1509 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1510 pointer_size, offset_size,
1511 dwarf_version, debug_info_p,
1519 /* Process the contents of a .debug_info section. If do_loc is non-zero
1520 then we are scanning for location lists and we do not want to display
1521 anything to the user. */
1524 process_debug_info (struct dwarf_section *section, void *file,
1527 unsigned char *start = section->start;
1528 unsigned char *end = start + section->size;
1529 unsigned char *section_begin;
1531 unsigned int num_units = 0;
1533 if ((do_loc || do_debug_loc || do_debug_ranges)
1534 && num_debug_info_entries == 0)
1536 unsigned long length;
1538 /* First scan the section to get the number of comp units. */
1539 for (section_begin = start, num_units = 0; section_begin < end;
1542 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1543 will be the length. For a 64-bit DWARF section, it'll be
1544 the escape code 0xffffffff followed by an 8 byte length. */
1545 length = byte_get (section_begin, 4);
1547 if (length == 0xffffffff)
1549 length = byte_get (section_begin + 4, 8);
1550 section_begin += length + 12;
1553 section_begin += length + 4;
1558 error (_("No comp units in %s section ?"), section->name);
1562 /* Then allocate an array to hold the information. */
1563 debug_information = cmalloc (num_units,
1564 sizeof (* debug_information));
1565 if (debug_information == NULL)
1567 error (_("Not enough memory for a debug info array of %u entries"),
1575 printf (_("The section %s contains:\n\n"), section->name);
1577 load_debug_section (str, file);
1580 load_debug_section (abbrev, file);
1581 if (debug_displays [abbrev].section.start == NULL)
1583 warn (_("Unable to locate %s section!\n"),
1584 debug_displays [abbrev].section.name);
1588 for (section_begin = start, unit = 0; start < end; unit++)
1590 DWARF2_Internal_CompUnit compunit;
1591 unsigned char *hdrptr;
1592 unsigned char *cu_abbrev_offset_ptr;
1593 unsigned char *tags;
1595 unsigned long cu_offset;
1597 int initial_length_size;
1601 compunit.cu_length = byte_get (hdrptr, 4);
1604 if (compunit.cu_length == 0xffffffff)
1606 compunit.cu_length = byte_get (hdrptr, 8);
1609 initial_length_size = 12;
1614 initial_length_size = 4;
1617 compunit.cu_version = byte_get (hdrptr, 2);
1620 cu_offset = start - section_begin;
1622 cu_abbrev_offset_ptr = hdrptr;
1623 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
1624 hdrptr += offset_size;
1626 compunit.cu_pointer_size = byte_get (hdrptr, 1);
1628 if ((do_loc || do_debug_loc || do_debug_ranges)
1629 && num_debug_info_entries == 0)
1631 debug_information [unit].cu_offset = cu_offset;
1632 debug_information [unit].pointer_size
1633 = compunit.cu_pointer_size;
1634 debug_information [unit].base_address = 0;
1635 debug_information [unit].loc_offsets = NULL;
1636 debug_information [unit].have_frame_base = NULL;
1637 debug_information [unit].max_loc_offsets = 0;
1638 debug_information [unit].num_loc_offsets = 0;
1639 debug_information [unit].range_lists = NULL;
1640 debug_information [unit].max_range_lists= 0;
1641 debug_information [unit].num_range_lists = 0;
1646 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset);
1647 printf (_(" Length: %ld\n"), compunit.cu_length);
1648 printf (_(" Version: %d\n"), compunit.cu_version);
1649 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
1650 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
1653 if (cu_offset + compunit.cu_length + initial_length_size
1656 warn (_("Debug info is corrupted, length is invalid (section is %lu bytes)\n"),
1657 (unsigned long)section->size);
1661 start += compunit.cu_length + initial_length_size;
1663 if (compunit.cu_version != 2 && compunit.cu_version != 3)
1665 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
1671 /* Process the abbrevs used by this compilation unit. DWARF
1672 sections under Mach-O have non-zero addresses. */
1673 if (compunit.cu_abbrev_offset >= debug_displays [abbrev].section.size)
1674 warn (_("Debug info is corrupted, abbrev offset is invalid (section is %lu bytes)\n"),
1675 (unsigned long)debug_displays [abbrev].section.size);
1677 process_abbrev_section
1678 ((unsigned char *) debug_displays [abbrev].section.start
1679 + compunit.cu_abbrev_offset - debug_displays [abbrev].section.address,
1680 (unsigned char *) debug_displays [abbrev].section.start
1681 + debug_displays [abbrev].section.size);
1684 while (tags < start)
1686 unsigned int bytes_read;
1687 unsigned long abbrev_number;
1688 abbrev_entry *entry;
1691 abbrev_number = read_leb128 (tags, & bytes_read, 0);
1694 /* A null DIE marks the end of a list of children. */
1695 if (abbrev_number == 0)
1702 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
1704 (unsigned long) (tags - section_begin
1708 /* Scan through the abbreviation list until we reach the
1710 for (entry = first_abbrev;
1711 entry && entry->entry != abbrev_number;
1712 entry = entry->next)
1722 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
1728 printf (_(" (%s)\n"), get_TAG_name (entry->tag));
1733 need_base_address = 0;
1735 case DW_TAG_compile_unit:
1736 need_base_address = 1;
1738 case DW_TAG_entry_point:
1739 case DW_TAG_subprogram:
1740 need_base_address = 0;
1741 /* Assuming that there is no DW_AT_frame_base. */
1742 have_frame_base = 0;
1746 for (attr = entry->first_attr; attr; attr = attr->next)
1749 /* Show the offset from where the tag was extracted. */
1750 printf (" <%2lx>", (unsigned long)(tags - section_begin));
1752 tags = read_and_display_attr (attr->attribute,
1755 compunit.cu_pointer_size,
1757 compunit.cu_version,
1758 &debug_information [unit],
1762 if (entry->children)
1767 /* Set num_debug_info_entries here so that it can be used to check if
1768 we need to process .debug_loc and .debug_ranges sections. */
1769 if ((do_loc || do_debug_loc || do_debug_ranges)
1770 && num_debug_info_entries == 0)
1771 num_debug_info_entries = num_units;
1781 /* Locate and scan the .debug_info section in the file and record the pointer
1782 sizes and offsets for the compilation units in it. Usually an executable
1783 will have just one pointer size, but this is not guaranteed, and so we try
1784 not to make any assumptions. Returns zero upon failure, or the number of
1785 compilation units upon success. */
1788 load_debug_info (void * file)
1790 /* Reset the last pointer size so that we can issue correct error
1791 messages if we are displaying the contents of more than one section. */
1792 last_pointer_size = 0;
1793 warned_about_missing_comp_units = FALSE;
1795 /* If we already have the information there is nothing else to do. */
1796 if (num_debug_info_entries > 0)
1797 return num_debug_info_entries;
1799 if (load_debug_section (info, file)
1800 && process_debug_info (&debug_displays [info].section, file, 1))
1801 return num_debug_info_entries;
1807 display_debug_lines (struct dwarf_section *section, void *file)
1809 unsigned char *start = section->start;
1810 unsigned char *data = start;
1811 unsigned char *end = start + section->size;
1813 printf (_("\nDump of debug contents of section %s:\n\n"),
1816 load_debug_info (file);
1820 DWARF2_Internal_LineInfo info;
1821 unsigned char *standard_opcodes;
1822 unsigned char *end_of_sequence;
1823 unsigned char *hdrptr;
1824 unsigned long hdroff;
1825 int initial_length_size;
1830 hdroff = hdrptr - start;
1832 /* Check the length of the block. */
1833 info.li_length = byte_get (hdrptr, 4);
1836 if (info.li_length == 0xffffffff)
1838 /* This section is 64-bit DWARF 3. */
1839 info.li_length = byte_get (hdrptr, 8);
1842 initial_length_size = 12;
1847 initial_length_size = 4;
1850 if (info.li_length + initial_length_size > section->size)
1853 (_("The line info appears to be corrupt - the section is too small\n"));
1857 /* Check its version number. */
1858 info.li_version = byte_get (hdrptr, 2);
1860 if (info.li_version != 2 && info.li_version != 3)
1862 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
1866 info.li_prologue_length = byte_get (hdrptr, offset_size);
1867 hdrptr += offset_size;
1868 info.li_min_insn_length = byte_get (hdrptr, 1);
1870 info.li_default_is_stmt = byte_get (hdrptr, 1);
1872 info.li_line_base = byte_get (hdrptr, 1);
1874 info.li_line_range = byte_get (hdrptr, 1);
1876 info.li_opcode_base = byte_get (hdrptr, 1);
1879 /* Sign extend the line base field. */
1880 info.li_line_base <<= 24;
1881 info.li_line_base >>= 24;
1883 printf (_(" Offset: 0x%lx\n"), hdroff);
1884 printf (_(" Length: %ld\n"), info.li_length);
1885 printf (_(" DWARF Version: %d\n"), info.li_version);
1886 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
1887 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
1888 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
1889 printf (_(" Line Base: %d\n"), info.li_line_base);
1890 printf (_(" Line Range: %d\n"), info.li_line_range);
1891 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
1893 end_of_sequence = data + info.li_length + initial_length_size;
1895 reset_state_machine (info.li_default_is_stmt);
1897 /* Display the contents of the Opcodes table. */
1898 standard_opcodes = hdrptr;
1900 printf (_("\n Opcodes:\n"));
1902 for (i = 1; i < info.li_opcode_base; i++)
1903 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
1905 /* Display the contents of the Directory table. */
1906 data = standard_opcodes + info.li_opcode_base - 1;
1909 printf (_("\n The Directory Table is empty.\n"));
1912 printf (_("\n The Directory Table:\n"));
1916 printf (_(" %s\n"), data);
1918 data += strlen ((char *) data) + 1;
1922 /* Skip the NUL at the end of the table. */
1925 /* Display the contents of the File Name table. */
1927 printf (_("\n The File Name Table is empty.\n"));
1930 printf (_("\n The File Name Table:\n"));
1931 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
1935 unsigned char *name;
1936 unsigned int bytes_read;
1938 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
1941 data += strlen ((char *) data) + 1;
1943 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
1945 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
1947 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
1949 printf (_("%s\n"), name);
1953 /* Skip the NUL at the end of the table. */
1956 /* Now display the statements. */
1957 printf (_("\n Line Number Statements:\n"));
1959 while (data < end_of_sequence)
1961 unsigned char op_code;
1963 unsigned long int uladv;
1964 unsigned int bytes_read;
1968 if (op_code >= info.li_opcode_base)
1970 op_code -= info.li_opcode_base;
1971 uladv = (op_code / info.li_line_range) * info.li_min_insn_length;
1972 state_machine_regs.address += uladv;
1973 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
1974 op_code, uladv, state_machine_regs.address);
1975 adv = (op_code % info.li_line_range) + info.li_line_base;
1976 state_machine_regs.line += adv;
1977 printf (_(" and Line by %d to %d\n"),
1978 adv, state_machine_regs.line);
1980 else switch (op_code)
1982 case DW_LNS_extended_op:
1983 data += process_extended_line_op (data, info.li_default_is_stmt);
1987 printf (_(" Copy\n"));
1990 case DW_LNS_advance_pc:
1991 uladv = read_leb128 (data, & bytes_read, 0);
1992 uladv *= info.li_min_insn_length;
1994 state_machine_regs.address += uladv;
1995 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv,
1996 state_machine_regs.address);
1999 case DW_LNS_advance_line:
2000 adv = read_leb128 (data, & bytes_read, 1);
2002 state_machine_regs.line += adv;
2003 printf (_(" Advance Line by %d to %d\n"), adv,
2004 state_machine_regs.line);
2007 case DW_LNS_set_file:
2008 adv = read_leb128 (data, & bytes_read, 0);
2010 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2012 state_machine_regs.file = adv;
2015 case DW_LNS_set_column:
2016 uladv = read_leb128 (data, & bytes_read, 0);
2018 printf (_(" Set column to %lu\n"), uladv);
2019 state_machine_regs.column = uladv;
2022 case DW_LNS_negate_stmt:
2023 adv = state_machine_regs.is_stmt;
2025 printf (_(" Set is_stmt to %d\n"), adv);
2026 state_machine_regs.is_stmt = adv;
2029 case DW_LNS_set_basic_block:
2030 printf (_(" Set basic block\n"));
2031 state_machine_regs.basic_block = 1;
2034 case DW_LNS_const_add_pc:
2035 uladv = (((255 - info.li_opcode_base) / info.li_line_range)
2036 * info.li_min_insn_length);
2037 state_machine_regs.address += uladv;
2038 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv,
2039 state_machine_regs.address);
2042 case DW_LNS_fixed_advance_pc:
2043 uladv = byte_get (data, 2);
2045 state_machine_regs.address += uladv;
2046 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2047 uladv, state_machine_regs.address);
2050 case DW_LNS_set_prologue_end:
2051 printf (_(" Set prologue_end to true\n"));
2054 case DW_LNS_set_epilogue_begin:
2055 printf (_(" Set epilogue_begin to true\n"));
2058 case DW_LNS_set_isa:
2059 uladv = read_leb128 (data, & bytes_read, 0);
2061 printf (_(" Set ISA to %lu\n"), uladv);
2065 printf (_(" Unknown opcode %d with operands: "), op_code);
2067 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2069 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
2070 i == 1 ? "" : ", ");
2084 display_debug_pubnames (struct dwarf_section *section,
2085 void *file ATTRIBUTE_UNUSED)
2087 DWARF2_Internal_PubNames pubnames;
2088 unsigned char *start = section->start;
2089 unsigned char *end = start + section->size;
2091 printf (_("Contents of the %s section:\n\n"), section->name);
2095 unsigned char *data;
2096 unsigned long offset;
2097 int offset_size, initial_length_size;
2101 pubnames.pn_length = byte_get (data, 4);
2103 if (pubnames.pn_length == 0xffffffff)
2105 pubnames.pn_length = byte_get (data, 8);
2108 initial_length_size = 12;
2113 initial_length_size = 4;
2116 pubnames.pn_version = byte_get (data, 2);
2118 pubnames.pn_offset = byte_get (data, offset_size);
2119 data += offset_size;
2120 pubnames.pn_size = byte_get (data, offset_size);
2121 data += offset_size;
2123 start += pubnames.pn_length + initial_length_size;
2125 if (pubnames.pn_version != 2 && pubnames.pn_version != 3)
2127 static int warned = 0;
2131 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2138 printf (_(" Length: %ld\n"),
2139 pubnames.pn_length);
2140 printf (_(" Version: %d\n"),
2141 pubnames.pn_version);
2142 printf (_(" Offset into .debug_info section: %ld\n"),
2143 pubnames.pn_offset);
2144 printf (_(" Size of area in .debug_info section: %ld\n"),
2147 printf (_("\n Offset\tName\n"));
2151 offset = byte_get (data, offset_size);
2155 data += offset_size;
2156 printf (" %-6ld\t\t%s\n", offset, data);
2157 data += strlen ((char *) data) + 1;
2160 while (offset != 0);
2168 display_debug_macinfo (struct dwarf_section *section,
2169 void *file ATTRIBUTE_UNUSED)
2171 unsigned char *start = section->start;
2172 unsigned char *end = start + section->size;
2173 unsigned char *curr = start;
2174 unsigned int bytes_read;
2175 enum dwarf_macinfo_record_type op;
2177 printf (_("Contents of the %s section:\n\n"), section->name);
2181 unsigned int lineno;
2189 case DW_MACINFO_start_file:
2191 unsigned int filenum;
2193 lineno = read_leb128 (curr, & bytes_read, 0);
2195 filenum = read_leb128 (curr, & bytes_read, 0);
2198 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2203 case DW_MACINFO_end_file:
2204 printf (_(" DW_MACINFO_end_file\n"));
2207 case DW_MACINFO_define:
2208 lineno = read_leb128 (curr, & bytes_read, 0);
2210 string = (char *) curr;
2211 curr += strlen (string) + 1;
2212 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2216 case DW_MACINFO_undef:
2217 lineno = read_leb128 (curr, & bytes_read, 0);
2219 string = (char *) curr;
2220 curr += strlen (string) + 1;
2221 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2225 case DW_MACINFO_vendor_ext:
2227 unsigned int constant;
2229 constant = read_leb128 (curr, & bytes_read, 0);
2231 string = (char *) curr;
2232 curr += strlen (string) + 1;
2233 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2244 display_debug_abbrev (struct dwarf_section *section,
2245 void *file ATTRIBUTE_UNUSED)
2247 abbrev_entry *entry;
2248 unsigned char *start = section->start;
2249 unsigned char *end = start + section->size;
2251 printf (_("Contents of the %s section:\n\n"), section->name);
2257 start = process_abbrev_section (start, end);
2259 if (first_abbrev == NULL)
2262 printf (_(" Number TAG\n"));
2264 for (entry = first_abbrev; entry; entry = entry->next)
2268 printf (_(" %ld %s [%s]\n"),
2270 get_TAG_name (entry->tag),
2271 entry->children ? _("has children") : _("no children"));
2273 for (attr = entry->first_attr; attr; attr = attr->next)
2274 printf (_(" %-18s %s\n"),
2275 get_AT_name (attr->attribute),
2276 get_FORM_name (attr->form));
2287 display_debug_loc (struct dwarf_section *section, void *file)
2289 unsigned char *start = section->start;
2290 unsigned char *section_end;
2291 unsigned long bytes;
2292 unsigned char *section_begin = start;
2293 unsigned int num_loc_list = 0;
2294 unsigned long last_offset = 0;
2295 unsigned int first = 0;
2298 int seen_first_offset = 0;
2299 int use_debug_info = 1;
2300 unsigned char *next;
2302 bytes = section->size;
2303 section_end = start + bytes;
2307 printf (_("\nThe %s section is empty.\n"), section->name);
2311 load_debug_info (file);
2313 /* Check the order of location list in .debug_info section. If
2314 offsets of location lists are in the ascending order, we can
2315 use `debug_information' directly. */
2316 for (i = 0; i < num_debug_info_entries; i++)
2320 num = debug_information [i].num_loc_offsets;
2321 num_loc_list += num;
2323 /* Check if we can use `debug_information' directly. */
2324 if (use_debug_info && num != 0)
2326 if (!seen_first_offset)
2328 /* This is the first location list. */
2329 last_offset = debug_information [i].loc_offsets [0];
2331 seen_first_offset = 1;
2337 for (; j < num; j++)
2340 debug_information [i].loc_offsets [j])
2345 last_offset = debug_information [i].loc_offsets [j];
2350 if (!use_debug_info)
2351 /* FIXME: Should we handle this case? */
2352 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
2354 if (!seen_first_offset)
2355 error (_("No location lists in .debug_info section!\n"));
2357 /* DWARF sections under Mach-O have non-zero addresses. */
2358 if (debug_information [first].num_loc_offsets > 0
2359 && debug_information [first].loc_offsets [0] != section->address)
2360 warn (_("Location lists in %s section start at 0x%lx\n"),
2361 section->name, debug_information [first].loc_offsets [0]);
2363 printf (_("Contents of the %s section:\n\n"), section->name);
2364 printf (_(" Offset Begin End Expression\n"));
2366 seen_first_offset = 0;
2367 for (i = first; i < num_debug_info_entries; i++)
2369 unsigned long begin;
2371 unsigned short length;
2372 unsigned long offset;
2373 unsigned int pointer_size;
2374 unsigned long cu_offset;
2375 unsigned long base_address;
2376 int need_frame_base;
2379 pointer_size = debug_information [i].pointer_size;
2380 cu_offset = debug_information [i].cu_offset;
2382 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
2384 has_frame_base = debug_information [i].have_frame_base [j];
2385 /* DWARF sections under Mach-O have non-zero addresses. */
2386 offset = debug_information [i].loc_offsets [j] - section->address;
2387 next = section_begin + offset;
2388 base_address = debug_information [i].base_address;
2390 if (!seen_first_offset)
2391 seen_first_offset = 1;
2395 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
2396 (long)(start - section_begin), (long)(next - section_begin));
2397 else if (start > next)
2398 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
2399 (long)(start - section_begin), (long)(next - section_begin));
2403 if (offset >= bytes)
2405 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
2412 if (start + 2 * pointer_size > section_end)
2414 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2419 begin = byte_get (start, pointer_size);
2420 start += pointer_size;
2421 end = byte_get (start, pointer_size);
2422 start += pointer_size;
2424 if (begin == 0 && end == 0)
2426 printf (_(" %8.8lx <End of list>\n"), offset);
2430 /* Check base address specifiers. */
2431 if (begin == -1UL && end != -1UL)
2434 printf (_(" %8.8lx %8.8lx %8.8lx (base address)\n"),
2435 offset, begin, end);
2439 if (start + 2 > section_end)
2441 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2446 length = byte_get (start, 2);
2449 if (start + length > section_end)
2451 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2456 printf (" %8.8lx %8.8lx %8.8lx (",
2457 offset, begin + base_address, end + base_address);
2458 need_frame_base = decode_location_expression (start,
2464 if (need_frame_base && !has_frame_base)
2465 printf (_(" [without DW_AT_frame_base]"));
2468 fputs (_(" (start == end)"), stdout);
2469 else if (begin > end)
2470 fputs (_(" (start > end)"), stdout);
2482 display_debug_str (struct dwarf_section *section,
2483 void *file ATTRIBUTE_UNUSED)
2485 unsigned char *start = section->start;
2486 unsigned long bytes = section->size;
2487 dwarf_vma addr = section->address;
2491 printf (_("\nThe %s section is empty.\n"), section->name);
2495 printf (_("Contents of the %s section:\n\n"), section->name);
2503 lbytes = (bytes > 16 ? 16 : bytes);
2505 printf (" 0x%8.8lx ", (unsigned long) addr);
2507 for (j = 0; j < 16; j++)
2510 printf ("%2.2x", start[j]);
2518 for (j = 0; j < lbytes; j++)
2521 if (k >= ' ' && k < 0x80)
2540 display_debug_info (struct dwarf_section *section, void *file)
2542 return process_debug_info (section, file, 0);
2547 display_debug_aranges (struct dwarf_section *section,
2548 void *file ATTRIBUTE_UNUSED)
2550 unsigned char *start = section->start;
2551 unsigned char *end = start + section->size;
2553 printf (_("The section %s contains:\n\n"), section->name);
2557 unsigned char *hdrptr;
2558 DWARF2_Internal_ARange arange;
2559 unsigned char *ranges;
2560 unsigned long length;
2561 unsigned long address;
2562 unsigned char address_size;
2565 int initial_length_size;
2569 arange.ar_length = byte_get (hdrptr, 4);
2572 if (arange.ar_length == 0xffffffff)
2574 arange.ar_length = byte_get (hdrptr, 8);
2577 initial_length_size = 12;
2582 initial_length_size = 4;
2585 arange.ar_version = byte_get (hdrptr, 2);
2588 arange.ar_info_offset = byte_get (hdrptr, offset_size);
2589 hdrptr += offset_size;
2591 arange.ar_pointer_size = byte_get (hdrptr, 1);
2594 arange.ar_segment_size = byte_get (hdrptr, 1);
2597 if (arange.ar_version != 2 && arange.ar_version != 3)
2599 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
2603 printf (_(" Length: %ld\n"), arange.ar_length);
2604 printf (_(" Version: %d\n"), arange.ar_version);
2605 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
2606 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
2607 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
2609 address_size = arange.ar_pointer_size + arange.ar_segment_size;
2611 /* The DWARF spec does not require that the address size be a power
2612 of two, but we do. This will have to change if we ever encounter
2613 an uneven architecture. */
2614 if ((address_size & (address_size - 1)) != 0)
2616 warn (_("Pointer size + Segment size is not a power of two.\n"));
2620 if (address_size > 4)
2621 printf (_("\n Address Length\n"));
2623 printf (_("\n Address Length\n"));
2627 /* Must pad to an alignment boundary that is twice the address size. */
2628 excess = (hdrptr - start) % (2 * address_size);
2630 ranges += (2 * address_size) - excess;
2632 start += arange.ar_length + initial_length_size;
2634 while (ranges + 2 * address_size <= start)
2636 address = byte_get (ranges, address_size);
2638 ranges += address_size;
2640 length = byte_get (ranges, address_size);
2642 ranges += address_size;
2644 if (address_size > 4)
2645 printf (" 0x%16.16lx 0x%lx\n", address, length);
2647 printf (" 0x%8.8lx 0x%lx\n", address, length);
2657 display_debug_ranges (struct dwarf_section *section,
2658 void *file ATTRIBUTE_UNUSED)
2660 unsigned char *start = section->start;
2661 unsigned char *section_end;
2662 unsigned long bytes;
2663 unsigned char *section_begin = start;
2664 unsigned int num_range_list = 0;
2665 unsigned long last_offset = 0;
2666 unsigned int first = 0;
2669 int seen_first_offset = 0;
2670 int use_debug_info = 1;
2671 unsigned char *next;
2673 bytes = section->size;
2674 section_end = start + bytes;
2678 printf (_("\nThe %s section is empty.\n"), section->name);
2682 load_debug_info (file);
2684 /* Check the order of range list in .debug_info section. If
2685 offsets of range lists are in the ascending order, we can
2686 use `debug_information' directly. */
2687 for (i = 0; i < num_debug_info_entries; i++)
2691 num = debug_information [i].num_range_lists;
2692 num_range_list += num;
2694 /* Check if we can use `debug_information' directly. */
2695 if (use_debug_info && num != 0)
2697 if (!seen_first_offset)
2699 /* This is the first range list. */
2700 last_offset = debug_information [i].range_lists [0];
2702 seen_first_offset = 1;
2708 for (; j < num; j++)
2711 debug_information [i].range_lists [j])
2716 last_offset = debug_information [i].range_lists [j];
2721 if (!use_debug_info)
2722 /* FIXME: Should we handle this case? */
2723 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
2725 if (!seen_first_offset)
2726 error (_("No range lists in .debug_info section!\n"));
2728 /* DWARF sections under Mach-O have non-zero addresses. */
2729 if (debug_information [first].num_range_lists > 0
2730 && debug_information [first].range_lists [0] != section->address)
2731 warn (_("Range lists in %s section start at 0x%lx\n"),
2732 section->name, debug_information [first].range_lists [0]);
2734 printf (_("Contents of the %s section:\n\n"), section->name);
2735 printf (_(" Offset Begin End\n"));
2737 seen_first_offset = 0;
2738 for (i = first; i < num_debug_info_entries; i++)
2740 unsigned long begin;
2742 unsigned long offset;
2743 unsigned int pointer_size;
2744 unsigned long base_address;
2746 pointer_size = debug_information [i].pointer_size;
2748 for (j = 0; j < debug_information [i].num_range_lists; j++)
2750 /* DWARF sections under Mach-O have non-zero addresses. */
2751 offset = debug_information [i].range_lists [j] - section->address;
2752 next = section_begin + offset;
2753 base_address = debug_information [i].base_address;
2755 if (!seen_first_offset)
2756 seen_first_offset = 1;
2760 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
2761 (long)(start - section_begin),
2762 (long)(next - section_begin), section->name);
2763 else if (start > next)
2764 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
2765 (long)(start - section_begin),
2766 (long)(next - section_begin), section->name);
2772 begin = byte_get (start, pointer_size);
2773 start += pointer_size;
2774 end = byte_get (start, pointer_size);
2775 start += pointer_size;
2777 if (begin == 0 && end == 0)
2779 printf (_(" %8.8lx <End of list>\n"), offset);
2783 /* Check base address specifiers. */
2784 if (begin == -1UL && end != -1UL)
2787 printf (" %8.8lx %8.8lx %8.8lx (base address)\n",
2788 offset, begin, end);
2792 printf (" %8.8lx %8.8lx %8.8lx",
2793 offset, begin + base_address, end + base_address);
2796 fputs (_(" (start == end)"), stdout);
2797 else if (begin > end)
2798 fputs (_(" (start > end)"), stdout);
2808 typedef struct Frame_Chunk
2810 struct Frame_Chunk *next;
2811 unsigned char *chunk_start;
2813 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
2814 short int *col_type;
2817 unsigned int code_factor;
2819 unsigned long pc_begin;
2820 unsigned long pc_range;
2824 unsigned char fde_encoding;
2825 unsigned char cfa_exp;
2829 /* A marker for a col_type that means this column was never referenced
2830 in the frame info. */
2831 #define DW_CFA_unreferenced (-1)
2834 frame_need_space (Frame_Chunk *fc, int reg)
2836 int prev = fc->ncols;
2838 if (reg < fc->ncols)
2841 fc->ncols = reg + 1;
2842 fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int));
2843 fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
2845 while (prev < fc->ncols)
2847 fc->col_type[prev] = DW_CFA_unreferenced;
2848 fc->col_offset[prev] = 0;
2854 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
2859 if (*max_regs < fc->ncols)
2860 *max_regs = fc->ncols;
2862 if (*need_col_headers)
2864 *need_col_headers = 0;
2866 printf (" LOC CFA ");
2868 for (r = 0; r < *max_regs; r++)
2869 if (fc->col_type[r] != DW_CFA_unreferenced)
2874 printf ("r%-4d", r);
2880 printf ("%08lx ", fc->pc_begin);
2882 strcpy (tmp, "exp");
2884 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
2885 printf ("%-8s ", tmp);
2887 for (r = 0; r < fc->ncols; r++)
2889 if (fc->col_type[r] != DW_CFA_unreferenced)
2891 switch (fc->col_type[r])
2893 case DW_CFA_undefined:
2896 case DW_CFA_same_value:
2900 sprintf (tmp, "c%+d", fc->col_offset[r]);
2902 case DW_CFA_val_offset:
2903 sprintf (tmp, "v%+d", fc->col_offset[r]);
2905 case DW_CFA_register:
2906 sprintf (tmp, "r%d", fc->col_offset[r]);
2908 case DW_CFA_expression:
2909 strcpy (tmp, "exp");
2911 case DW_CFA_val_expression:
2912 strcpy (tmp, "vexp");
2915 strcpy (tmp, "n/a");
2918 printf ("%-5s", tmp);
2925 size_of_encoded_value (int encoding)
2927 switch (encoding & 0x7)
2930 case 0: return eh_addr_size;
2938 get_encoded_value (unsigned char *data, int encoding)
2940 int size = size_of_encoded_value (encoding);
2942 if (encoding & DW_EH_PE_signed)
2943 return byte_get_signed (data, size);
2945 return byte_get (data, size);
2948 #define GET(N) byte_get (start, N); start += N
2949 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
2950 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
2953 display_debug_frames (struct dwarf_section *section,
2954 void *file ATTRIBUTE_UNUSED)
2956 unsigned char *start = section->start;
2957 unsigned char *end = start + section->size;
2958 unsigned char *section_start = start;
2959 Frame_Chunk *chunks = 0;
2960 Frame_Chunk *remembered_state = 0;
2962 int is_eh = strcmp (section->name, ".eh_frame") == 0;
2963 unsigned int length_return;
2966 printf (_("The section %s contains:\n"), section->name);
2970 unsigned char *saved_start;
2971 unsigned char *block_end;
2972 unsigned long length;
2973 unsigned long cie_id;
2976 int need_col_headers = 1;
2977 unsigned char *augmentation_data = NULL;
2978 unsigned long augmentation_data_len = 0;
2979 int encoded_ptr_size = eh_addr_size;
2981 int initial_length_size;
2983 saved_start = start;
2984 length = byte_get (start, 4); start += 4;
2988 printf ("\n%08lx ZERO terminator\n\n",
2989 (unsigned long)(saved_start - section_start));
2993 if (length == 0xffffffff)
2995 length = byte_get (start, 8);
2998 initial_length_size = 12;
3003 initial_length_size = 4;
3006 block_end = saved_start + length + initial_length_size;
3007 if (block_end > end)
3009 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3010 length, (unsigned long)(saved_start - section_start));
3013 cie_id = byte_get (start, offset_size); start += offset_size;
3015 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
3019 fc = xmalloc (sizeof (Frame_Chunk));
3020 memset (fc, 0, sizeof (Frame_Chunk));
3024 fc->chunk_start = saved_start;
3026 fc->col_type = xmalloc (sizeof (short int));
3027 fc->col_offset = xmalloc (sizeof (int));
3028 frame_need_space (fc, max_regs-1);
3032 fc->augmentation = (char *) start;
3033 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
3035 if (fc->augmentation[0] == 'z')
3037 fc->code_factor = LEB ();
3038 fc->data_factor = SLEB ();
3047 augmentation_data_len = LEB ();
3048 augmentation_data = start;
3049 start += augmentation_data_len;
3051 else if (strcmp (fc->augmentation, "eh") == 0)
3053 start += eh_addr_size;
3054 fc->code_factor = LEB ();
3055 fc->data_factor = SLEB ();
3067 fc->code_factor = LEB ();
3068 fc->data_factor = SLEB ();
3080 if (do_debug_frames_interp)
3081 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3082 (unsigned long)(saved_start - section_start), length, cie_id,
3083 fc->augmentation, fc->code_factor, fc->data_factor,
3087 printf ("\n%08lx %08lx %08lx CIE\n",
3088 (unsigned long)(saved_start - section_start), length, cie_id);
3089 printf (" Version: %d\n", version);
3090 printf (" Augmentation: \"%s\"\n", fc->augmentation);
3091 printf (" Code alignment factor: %u\n", fc->code_factor);
3092 printf (" Data alignment factor: %d\n", fc->data_factor);
3093 printf (" Return address column: %d\n", fc->ra);
3095 if (augmentation_data_len)
3098 printf (" Augmentation data: ");
3099 for (i = 0; i < augmentation_data_len; ++i)
3100 printf (" %02x", augmentation_data[i]);
3106 if (augmentation_data_len)
3108 unsigned char *p, *q;
3109 p = (unsigned char *) fc->augmentation + 1;
3110 q = augmentation_data;
3117 q += 1 + size_of_encoded_value (*q);
3119 fc->fde_encoding = *q++;
3125 if (fc->fde_encoding)
3126 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3129 frame_need_space (fc, fc->ra);
3133 unsigned char *look_for;
3134 static Frame_Chunk fde_fc;
3137 memset (fc, 0, sizeof (Frame_Chunk));
3139 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
3141 for (cie = chunks; cie ; cie = cie->next)
3142 if (cie->chunk_start == look_for)
3147 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
3148 cie_id, (unsigned long)(saved_start - section_start));
3150 fc->col_type = xmalloc (sizeof (short int));
3151 fc->col_offset = xmalloc (sizeof (int));
3152 frame_need_space (fc, max_regs - 1);
3154 fc->augmentation = "";
3155 fc->fde_encoding = 0;
3159 fc->ncols = cie->ncols;
3160 fc->col_type = xcmalloc (fc->ncols, sizeof (short int));
3161 fc->col_offset = xcmalloc (fc->ncols, sizeof (int));
3162 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
3163 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
3164 fc->augmentation = cie->augmentation;
3165 fc->code_factor = cie->code_factor;
3166 fc->data_factor = cie->data_factor;
3167 fc->cfa_reg = cie->cfa_reg;
3168 fc->cfa_offset = cie->cfa_offset;
3170 frame_need_space (fc, max_regs-1);
3171 fc->fde_encoding = cie->fde_encoding;
3174 if (fc->fde_encoding)
3175 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3177 fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
3178 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel
3179 /* Don't adjust for relocatable file since there's
3180 invariably a pcrel reloc here, which we haven't
3183 fc->pc_begin += section->address + (start - section_start);
3184 start += encoded_ptr_size;
3185 fc->pc_range = byte_get (start, encoded_ptr_size);
3186 start += encoded_ptr_size;
3188 if (cie->augmentation[0] == 'z')
3190 augmentation_data_len = LEB ();
3191 augmentation_data = start;
3192 start += augmentation_data_len;
3195 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
3196 (unsigned long)(saved_start - section_start), length, cie_id,
3197 (unsigned long)(cie->chunk_start - section_start),
3198 fc->pc_begin, fc->pc_begin + fc->pc_range);
3199 if (! do_debug_frames_interp && augmentation_data_len)
3203 printf (" Augmentation data: ");
3204 for (i = 0; i < augmentation_data_len; ++i)
3205 printf (" %02x", augmentation_data[i]);
3211 /* At this point, fc is the current chunk, cie (if any) is set, and
3212 we're about to interpret instructions for the chunk. */
3213 /* ??? At present we need to do this always, since this sizes the
3214 fc->col_type and fc->col_offset arrays, which we write into always.
3215 We should probably split the interpreted and non-interpreted bits
3216 into two different routines, since there's so much that doesn't
3217 really overlap between them. */
3218 if (1 || do_debug_frames_interp)
3220 /* Start by making a pass over the chunk, allocating storage
3221 and taking note of what registers are used. */
3222 unsigned char *tmp = start;
3224 while (start < block_end)
3227 unsigned long reg, tmp;
3234 /* Warning: if you add any more cases to this switch, be
3235 sure to add them to the corresponding switch below. */
3238 case DW_CFA_advance_loc:
3242 frame_need_space (fc, opa);
3243 fc->col_type[opa] = DW_CFA_undefined;
3245 case DW_CFA_restore:
3246 frame_need_space (fc, opa);
3247 fc->col_type[opa] = DW_CFA_undefined;
3249 case DW_CFA_set_loc:
3250 start += encoded_ptr_size;
3252 case DW_CFA_advance_loc1:
3255 case DW_CFA_advance_loc2:
3258 case DW_CFA_advance_loc4:
3261 case DW_CFA_offset_extended:
3262 case DW_CFA_val_offset:
3263 reg = LEB (); LEB ();
3264 frame_need_space (fc, reg);
3265 fc->col_type[reg] = DW_CFA_undefined;
3267 case DW_CFA_restore_extended:
3269 frame_need_space (fc, reg);
3270 fc->col_type[reg] = DW_CFA_undefined;
3272 case DW_CFA_undefined:
3274 frame_need_space (fc, reg);
3275 fc->col_type[reg] = DW_CFA_undefined;
3277 case DW_CFA_same_value:
3279 frame_need_space (fc, reg);
3280 fc->col_type[reg] = DW_CFA_undefined;
3282 case DW_CFA_register:
3283 reg = LEB (); LEB ();
3284 frame_need_space (fc, reg);
3285 fc->col_type[reg] = DW_CFA_undefined;
3287 case DW_CFA_def_cfa:
3290 case DW_CFA_def_cfa_register:
3293 case DW_CFA_def_cfa_offset:
3296 case DW_CFA_def_cfa_expression:
3300 case DW_CFA_expression:
3301 case DW_CFA_val_expression:
3305 frame_need_space (fc, reg);
3306 fc->col_type[reg] = DW_CFA_undefined;
3308 case DW_CFA_offset_extended_sf:
3309 case DW_CFA_val_offset_sf:
3310 reg = LEB (); SLEB ();
3311 frame_need_space (fc, reg);
3312 fc->col_type[reg] = DW_CFA_undefined;
3314 case DW_CFA_def_cfa_sf:
3317 case DW_CFA_def_cfa_offset_sf:
3320 case DW_CFA_MIPS_advance_loc8:
3323 case DW_CFA_GNU_args_size:
3326 case DW_CFA_GNU_negative_offset_extended:
3327 reg = LEB (); LEB ();
3328 frame_need_space (fc, reg);
3329 fc->col_type[reg] = DW_CFA_undefined;
3338 /* Now we know what registers are used, make a second pass over
3339 the chunk, this time actually printing out the info. */
3341 while (start < block_end)
3344 unsigned long ul, reg, roffs;
3353 /* Warning: if you add any more cases to this switch, be
3354 sure to add them to the corresponding switch above. */
3357 case DW_CFA_advance_loc:
3358 if (do_debug_frames_interp)
3359 frame_display_row (fc, &need_col_headers, &max_regs);
3361 printf (" DW_CFA_advance_loc: %d to %08lx\n",
3362 opa * fc->code_factor,
3363 fc->pc_begin + opa * fc->code_factor);
3364 fc->pc_begin += opa * fc->code_factor;
3369 if (! do_debug_frames_interp)
3370 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
3371 opa, roffs * fc->data_factor);
3372 fc->col_type[opa] = DW_CFA_offset;
3373 fc->col_offset[opa] = roffs * fc->data_factor;
3376 case DW_CFA_restore:
3377 if (! do_debug_frames_interp)
3378 printf (" DW_CFA_restore: r%d\n", opa);
3379 fc->col_type[opa] = cie->col_type[opa];
3380 fc->col_offset[opa] = cie->col_offset[opa];
3383 case DW_CFA_set_loc:
3384 vma = get_encoded_value (start, fc->fde_encoding);
3385 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel
3387 vma += section->address + (start - section_start);
3388 start += encoded_ptr_size;
3389 if (do_debug_frames_interp)
3390 frame_display_row (fc, &need_col_headers, &max_regs);
3392 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
3396 case DW_CFA_advance_loc1:
3397 ofs = byte_get (start, 1); start += 1;
3398 if (do_debug_frames_interp)
3399 frame_display_row (fc, &need_col_headers, &max_regs);
3401 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
3402 ofs * fc->code_factor,
3403 fc->pc_begin + ofs * fc->code_factor);
3404 fc->pc_begin += ofs * fc->code_factor;
3407 case DW_CFA_advance_loc2:
3408 ofs = byte_get (start, 2); start += 2;
3409 if (do_debug_frames_interp)
3410 frame_display_row (fc, &need_col_headers, &max_regs);
3412 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
3413 ofs * fc->code_factor,
3414 fc->pc_begin + ofs * fc->code_factor);
3415 fc->pc_begin += ofs * fc->code_factor;
3418 case DW_CFA_advance_loc4:
3419 ofs = byte_get (start, 4); start += 4;
3420 if (do_debug_frames_interp)
3421 frame_display_row (fc, &need_col_headers, &max_regs);
3423 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
3424 ofs * fc->code_factor,
3425 fc->pc_begin + ofs * fc->code_factor);
3426 fc->pc_begin += ofs * fc->code_factor;
3429 case DW_CFA_offset_extended:
3432 if (! do_debug_frames_interp)
3433 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
3434 reg, roffs * fc->data_factor);
3435 fc->col_type[reg] = DW_CFA_offset;
3436 fc->col_offset[reg] = roffs * fc->data_factor;
3439 case DW_CFA_val_offset:
3442 if (! do_debug_frames_interp)
3443 printf (" DW_CFA_val_offset: r%ld at cfa%+ld\n",
3444 reg, roffs * fc->data_factor);
3445 fc->col_type[reg] = DW_CFA_val_offset;
3446 fc->col_offset[reg] = roffs * fc->data_factor;
3449 case DW_CFA_restore_extended:
3451 if (! do_debug_frames_interp)
3452 printf (" DW_CFA_restore_extended: r%ld\n", reg);
3453 fc->col_type[reg] = cie->col_type[reg];
3454 fc->col_offset[reg] = cie->col_offset[reg];
3457 case DW_CFA_undefined:
3459 if (! do_debug_frames_interp)
3460 printf (" DW_CFA_undefined: r%ld\n", reg);
3461 fc->col_type[reg] = DW_CFA_undefined;
3462 fc->col_offset[reg] = 0;
3465 case DW_CFA_same_value:
3467 if (! do_debug_frames_interp)
3468 printf (" DW_CFA_same_value: r%ld\n", reg);
3469 fc->col_type[reg] = DW_CFA_same_value;
3470 fc->col_offset[reg] = 0;
3473 case DW_CFA_register:
3476 if (! do_debug_frames_interp)
3477 printf (" DW_CFA_register: r%ld in r%ld\n", reg, roffs);
3478 fc->col_type[reg] = DW_CFA_register;
3479 fc->col_offset[reg] = roffs;
3482 case DW_CFA_remember_state:
3483 if (! do_debug_frames_interp)
3484 printf (" DW_CFA_remember_state\n");
3485 rs = xmalloc (sizeof (Frame_Chunk));
3486 rs->ncols = fc->ncols;
3487 rs->col_type = xcmalloc (rs->ncols, sizeof (short int));
3488 rs->col_offset = xcmalloc (rs->ncols, sizeof (int));
3489 memcpy (rs->col_type, fc->col_type, rs->ncols);
3490 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
3491 rs->next = remembered_state;
3492 remembered_state = rs;
3495 case DW_CFA_restore_state:
3496 if (! do_debug_frames_interp)
3497 printf (" DW_CFA_restore_state\n");
3498 rs = remembered_state;
3501 remembered_state = rs->next;
3502 frame_need_space (fc, rs->ncols-1);
3503 memcpy (fc->col_type, rs->col_type, rs->ncols);
3504 memcpy (fc->col_offset, rs->col_offset,
3505 rs->ncols * sizeof (int));
3506 free (rs->col_type);
3507 free (rs->col_offset);
3510 else if (do_debug_frames_interp)
3511 printf ("Mismatched DW_CFA_restore_state\n");
3514 case DW_CFA_def_cfa:
3515 fc->cfa_reg = LEB ();
3516 fc->cfa_offset = LEB ();
3518 if (! do_debug_frames_interp)
3519 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
3520 fc->cfa_reg, fc->cfa_offset);
3523 case DW_CFA_def_cfa_register:
3524 fc->cfa_reg = LEB ();
3526 if (! do_debug_frames_interp)
3527 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
3530 case DW_CFA_def_cfa_offset:
3531 fc->cfa_offset = LEB ();
3532 if (! do_debug_frames_interp)
3533 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
3537 if (! do_debug_frames_interp)
3538 printf (" DW_CFA_nop\n");
3541 case DW_CFA_def_cfa_expression:
3543 if (! do_debug_frames_interp)
3545 printf (" DW_CFA_def_cfa_expression (");
3546 decode_location_expression (start, eh_addr_size, ul, 0);
3553 case DW_CFA_expression:
3556 if (! do_debug_frames_interp)
3558 printf (" DW_CFA_expression: r%ld (", reg);
3559 decode_location_expression (start, eh_addr_size, ul, 0);
3562 fc->col_type[reg] = DW_CFA_expression;
3566 case DW_CFA_val_expression:
3569 if (! do_debug_frames_interp)
3571 printf (" DW_CFA_val_expression: r%ld (", reg);
3572 decode_location_expression (start, eh_addr_size, ul, 0);
3575 fc->col_type[reg] = DW_CFA_val_expression;
3579 case DW_CFA_offset_extended_sf:
3582 frame_need_space (fc, reg);
3583 if (! do_debug_frames_interp)
3584 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
3585 reg, l * fc->data_factor);
3586 fc->col_type[reg] = DW_CFA_offset;
3587 fc->col_offset[reg] = l * fc->data_factor;
3590 case DW_CFA_val_offset_sf:
3593 frame_need_space (fc, reg);
3594 if (! do_debug_frames_interp)
3595 printf (" DW_CFA_val_offset_sf: r%ld at cfa%+ld\n",
3596 reg, l * fc->data_factor);
3597 fc->col_type[reg] = DW_CFA_val_offset;
3598 fc->col_offset[reg] = l * fc->data_factor;
3601 case DW_CFA_def_cfa_sf:
3602 fc->cfa_reg = LEB ();
3603 fc->cfa_offset = SLEB ();
3604 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3606 if (! do_debug_frames_interp)
3607 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
3608 fc->cfa_reg, fc->cfa_offset);
3611 case DW_CFA_def_cfa_offset_sf:
3612 fc->cfa_offset = SLEB ();
3613 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3614 if (! do_debug_frames_interp)
3615 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
3618 case DW_CFA_MIPS_advance_loc8:
3619 ofs = byte_get (start, 8); start += 8;
3620 if (do_debug_frames_interp)
3621 frame_display_row (fc, &need_col_headers, &max_regs);
3623 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
3624 ofs * fc->code_factor,
3625 fc->pc_begin + ofs * fc->code_factor);
3626 fc->pc_begin += ofs * fc->code_factor;
3629 case DW_CFA_GNU_window_save:
3630 if (! do_debug_frames_interp)
3631 printf (" DW_CFA_GNU_window_save\n");
3634 case DW_CFA_GNU_args_size:
3636 if (! do_debug_frames_interp)
3637 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
3640 case DW_CFA_GNU_negative_offset_extended:
3643 frame_need_space (fc, reg);
3644 if (! do_debug_frames_interp)
3645 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
3646 reg, l * fc->data_factor);
3647 fc->col_type[reg] = DW_CFA_offset;
3648 fc->col_offset[reg] = l * fc->data_factor;
3652 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
3653 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
3655 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
3660 if (do_debug_frames_interp)
3661 frame_display_row (fc, &need_col_headers, &max_regs);
3676 display_debug_not_supported (struct dwarf_section *section,
3677 void *file ATTRIBUTE_UNUSED)
3679 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
3686 cmalloc (size_t nmemb, size_t size)
3688 /* Check for overflow. */
3689 if (nmemb >= ~(size_t) 0 / size)
3692 return malloc (nmemb * size);
3696 xcmalloc (size_t nmemb, size_t size)
3698 /* Check for overflow. */
3699 if (nmemb >= ~(size_t) 0 / size)
3702 return xmalloc (nmemb * size);
3706 xcrealloc (void *ptr, size_t nmemb, size_t size)
3708 /* Check for overflow. */
3709 if (nmemb >= ~(size_t) 0 / size)
3712 return xrealloc (ptr, nmemb * size);
3716 error (const char *message, ...)
3720 va_start (args, message);
3721 fprintf (stderr, _("%s: Error: "), program_name);
3722 vfprintf (stderr, message, args);
3727 warn (const char *message, ...)
3731 va_start (args, message);
3732 fprintf (stderr, _("%s: Warning: "), program_name);
3733 vfprintf (stderr, message, args);
3738 free_debug_memory (void)
3740 enum dwarf_section_display_enum i;
3744 for (i = 0; i < max; i++)
3745 free_debug_section (i);
3747 if (debug_information)
3749 for (i = 0; i < num_debug_info_entries; i++)
3751 if (!debug_information [i].max_loc_offsets)
3753 free (debug_information [i].loc_offsets);
3754 free (debug_information [i].have_frame_base);
3756 if (!debug_information [i].max_range_lists)
3757 free (debug_information [i].range_lists);
3759 free (debug_information);
3760 debug_information = NULL;
3761 num_debug_info_entries = 0;
3766 struct dwarf_section_display debug_displays[] =
3768 { { ".debug_abbrev", NULL, 0, 0 },
3769 display_debug_abbrev, 0, 0 },
3770 { { ".debug_aranges", NULL, 0, 0 },
3771 display_debug_aranges, 0, 0 },
3772 { { ".debug_frame", NULL, 0, 0 },
3773 display_debug_frames, 1, 0 },
3774 { { ".debug_info", NULL, 0, 0 },
3775 display_debug_info, 1, 0 },
3776 { { ".debug_line", NULL, 0, 0 },
3777 display_debug_lines, 0, 0 },
3778 { { ".debug_pubnames", NULL, 0, 0 },
3779 display_debug_pubnames, 0, 0 },
3780 { { ".eh_frame", NULL, 0, 0 },
3781 display_debug_frames, 1, 1 },
3782 { { ".debug_macinfo", NULL, 0, 0 },
3783 display_debug_macinfo, 0, 0 },
3784 { { ".debug_str", NULL, 0, 0 },
3785 display_debug_str, 0, 0 },
3786 { { ".debug_loc", NULL, 0, 0 },
3787 display_debug_loc, 0, 0 },
3788 { { ".debug_pubtypes", NULL, 0, 0 },
3789 display_debug_pubnames, 0, 0 },
3790 { { ".debug_ranges", NULL, 0, 0 },
3791 display_debug_ranges, 0, 0 },
3792 { { ".debug_static_func", NULL, 0, 0 },
3793 display_debug_not_supported, 0, 0 },
3794 { { ".debug_static_vars", NULL, 0, 0 },
3795 display_debug_not_supported, 0, 0 },
3796 { { ".debug_types", NULL, 0, 0 },
3797 display_debug_not_supported, 0, 0 },
3798 { { ".debug_weaknames", NULL, 0, 0 },
3799 display_debug_not_supported, 0, 0 }