1 /* dwarf.c -- display DWARF contents of a BFD binary file
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 2 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
27 #include "libiberty.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, int pointer_size)
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, pointer_size);
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 if (offset > section->size)
292 warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
293 return _("<offset is too big>");
296 return (const char *) section->start + offset;
299 /* FIXME: There are better and more efficient ways to handle
300 these structures. For now though, I just want something that
301 is simple to implement. */
302 typedef struct abbrev_attr
304 unsigned long attribute;
306 struct abbrev_attr *next;
310 typedef struct abbrev_entry
315 struct abbrev_attr *first_attr;
316 struct abbrev_attr *last_attr;
317 struct abbrev_entry *next;
321 static abbrev_entry *first_abbrev = NULL;
322 static abbrev_entry *last_abbrev = NULL;
327 abbrev_entry *abbrev;
329 for (abbrev = first_abbrev; abbrev;)
331 abbrev_entry *next = abbrev->next;
334 for (attr = abbrev->first_attr; attr;)
336 abbrev_attr *next = attr->next;
346 last_abbrev = first_abbrev = NULL;
350 add_abbrev (unsigned long number, unsigned long tag, int children)
354 entry = malloc (sizeof (*entry));
360 entry->entry = number;
362 entry->children = children;
363 entry->first_attr = NULL;
364 entry->last_attr = NULL;
367 if (first_abbrev == NULL)
368 first_abbrev = entry;
370 last_abbrev->next = entry;
376 add_abbrev_attr (unsigned long attribute, unsigned long form)
380 attr = malloc (sizeof (*attr));
386 attr->attribute = attribute;
390 if (last_abbrev->first_attr == NULL)
391 last_abbrev->first_attr = attr;
393 last_abbrev->last_attr->next = attr;
395 last_abbrev->last_attr = attr;
398 /* Processes the (partial) contents of a .debug_abbrev section.
399 Returns NULL if the end of the section was encountered.
400 Returns the address after the last byte read if the end of
401 an abbreviation set was found. */
403 static unsigned char *
404 process_abbrev_section (unsigned char *start, unsigned char *end)
406 if (first_abbrev != NULL)
411 unsigned int bytes_read;
414 unsigned long attribute;
417 entry = read_leb128 (start, & bytes_read, 0);
420 /* A single zero is supposed to end the section according
421 to the standard. If there's more, then signal that to
424 return start == end ? NULL : start;
426 tag = read_leb128 (start, & bytes_read, 0);
431 add_abbrev (entry, tag, children);
437 attribute = read_leb128 (start, & bytes_read, 0);
440 form = read_leb128 (start, & bytes_read, 0);
444 add_abbrev_attr (attribute, form);
446 while (attribute != 0);
453 get_TAG_name (unsigned long tag)
457 case DW_TAG_padding: return "DW_TAG_padding";
458 case DW_TAG_array_type: return "DW_TAG_array_type";
459 case DW_TAG_class_type: return "DW_TAG_class_type";
460 case DW_TAG_entry_point: return "DW_TAG_entry_point";
461 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
462 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
463 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
464 case DW_TAG_label: return "DW_TAG_label";
465 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
466 case DW_TAG_member: return "DW_TAG_member";
467 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
468 case DW_TAG_reference_type: return "DW_TAG_reference_type";
469 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
470 case DW_TAG_string_type: return "DW_TAG_string_type";
471 case DW_TAG_structure_type: return "DW_TAG_structure_type";
472 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
473 case DW_TAG_typedef: return "DW_TAG_typedef";
474 case DW_TAG_union_type: return "DW_TAG_union_type";
475 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
476 case DW_TAG_variant: return "DW_TAG_variant";
477 case DW_TAG_common_block: return "DW_TAG_common_block";
478 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
479 case DW_TAG_inheritance: return "DW_TAG_inheritance";
480 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
481 case DW_TAG_module: return "DW_TAG_module";
482 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
483 case DW_TAG_set_type: return "DW_TAG_set_type";
484 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
485 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
486 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
487 case DW_TAG_base_type: return "DW_TAG_base_type";
488 case DW_TAG_catch_block: return "DW_TAG_catch_block";
489 case DW_TAG_const_type: return "DW_TAG_const_type";
490 case DW_TAG_constant: return "DW_TAG_constant";
491 case DW_TAG_enumerator: return "DW_TAG_enumerator";
492 case DW_TAG_file_type: return "DW_TAG_file_type";
493 case DW_TAG_friend: return "DW_TAG_friend";
494 case DW_TAG_namelist: return "DW_TAG_namelist";
495 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
496 case DW_TAG_packed_type: return "DW_TAG_packed_type";
497 case DW_TAG_subprogram: return "DW_TAG_subprogram";
498 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
499 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
500 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
501 case DW_TAG_try_block: return "DW_TAG_try_block";
502 case DW_TAG_variant_part: return "DW_TAG_variant_part";
503 case DW_TAG_variable: return "DW_TAG_variable";
504 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
505 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
506 case DW_TAG_format_label: return "DW_TAG_format_label";
507 case DW_TAG_function_template: return "DW_TAG_function_template";
508 case DW_TAG_class_template: return "DW_TAG_class_template";
509 /* DWARF 2.1 values. */
510 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
511 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
512 case DW_TAG_interface_type: return "DW_TAG_interface_type";
513 case DW_TAG_namespace: return "DW_TAG_namespace";
514 case DW_TAG_imported_module: return "DW_TAG_imported_module";
515 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
516 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
517 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
519 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
520 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
521 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
524 static char buffer[100];
526 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
533 get_FORM_name (unsigned long form)
537 case DW_FORM_addr: return "DW_FORM_addr";
538 case DW_FORM_block2: return "DW_FORM_block2";
539 case DW_FORM_block4: return "DW_FORM_block4";
540 case DW_FORM_data2: return "DW_FORM_data2";
541 case DW_FORM_data4: return "DW_FORM_data4";
542 case DW_FORM_data8: return "DW_FORM_data8";
543 case DW_FORM_string: return "DW_FORM_string";
544 case DW_FORM_block: return "DW_FORM_block";
545 case DW_FORM_block1: return "DW_FORM_block1";
546 case DW_FORM_data1: return "DW_FORM_data1";
547 case DW_FORM_flag: return "DW_FORM_flag";
548 case DW_FORM_sdata: return "DW_FORM_sdata";
549 case DW_FORM_strp: return "DW_FORM_strp";
550 case DW_FORM_udata: return "DW_FORM_udata";
551 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
552 case DW_FORM_ref1: return "DW_FORM_ref1";
553 case DW_FORM_ref2: return "DW_FORM_ref2";
554 case DW_FORM_ref4: return "DW_FORM_ref4";
555 case DW_FORM_ref8: return "DW_FORM_ref8";
556 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
557 case DW_FORM_indirect: return "DW_FORM_indirect";
560 static char buffer[100];
562 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
568 static unsigned char *
569 display_block (unsigned char *data, unsigned long length)
571 printf (_(" %lu byte block: "), length);
574 printf ("%lx ", (unsigned long) byte_get (data++, 1));
580 decode_location_expression (unsigned char * data,
581 unsigned int pointer_size,
582 unsigned long length,
583 unsigned long cu_offset)
586 unsigned int bytes_read;
587 unsigned long uvalue;
588 unsigned char *end = data + length;
589 int need_frame_base = 0;
598 printf ("DW_OP_addr: %lx",
599 (unsigned long) byte_get (data, pointer_size));
600 data += pointer_size;
603 printf ("DW_OP_deref");
606 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
609 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
612 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
616 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
620 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
624 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
628 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
629 (unsigned long) byte_get (data + 4, 4));
633 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
634 (long) byte_get (data + 4, 4));
638 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
642 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
646 printf ("DW_OP_dup");
649 printf ("DW_OP_drop");
652 printf ("DW_OP_over");
655 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
658 printf ("DW_OP_swap");
661 printf ("DW_OP_rot");
664 printf ("DW_OP_xderef");
667 printf ("DW_OP_abs");
670 printf ("DW_OP_and");
673 printf ("DW_OP_div");
676 printf ("DW_OP_minus");
679 printf ("DW_OP_mod");
682 printf ("DW_OP_mul");
685 printf ("DW_OP_neg");
688 printf ("DW_OP_not");
694 printf ("DW_OP_plus");
696 case DW_OP_plus_uconst:
697 printf ("DW_OP_plus_uconst: %lu",
698 read_leb128 (data, &bytes_read, 0));
702 printf ("DW_OP_shl");
705 printf ("DW_OP_shr");
708 printf ("DW_OP_shra");
711 printf ("DW_OP_xor");
714 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
736 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
772 printf ("DW_OP_lit%d", op - DW_OP_lit0);
807 printf ("DW_OP_reg%d", op - DW_OP_reg0);
842 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
843 read_leb128 (data, &bytes_read, 1));
848 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
853 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
857 uvalue = read_leb128 (data, &bytes_read, 0);
859 printf ("DW_OP_bregx: %lu %ld", uvalue,
860 read_leb128 (data, &bytes_read, 1));
864 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
867 case DW_OP_deref_size:
868 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
870 case DW_OP_xderef_size:
871 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
874 printf ("DW_OP_nop");
877 /* DWARF 3 extensions. */
878 case DW_OP_push_object_address:
879 printf ("DW_OP_push_object_address");
882 /* XXX: Strictly speaking for 64-bit DWARF3 files
883 this ought to be an 8-byte wide computation. */
884 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset);
888 /* XXX: Strictly speaking for 64-bit DWARF3 files
889 this ought to be an 8-byte wide computation. */
890 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset);
894 printf ("DW_OP_call_ref");
897 /* GNU extensions. */
898 case DW_OP_GNU_push_tls_address:
899 printf ("DW_OP_GNU_push_tls_address");
903 if (op >= DW_OP_lo_user
904 && op <= DW_OP_hi_user)
905 printf (_("(User defined location op)"));
907 printf (_("(Unknown location op)"));
908 /* No way to tell where the next op is, so just bail. */
909 return need_frame_base;
912 /* Separate the ops. */
917 return need_frame_base;
920 static unsigned char *
921 read_and_display_attr_value (unsigned long attribute,
924 unsigned long cu_offset,
925 unsigned long pointer_size,
926 unsigned long offset_size,
928 debug_info *debug_info_p,
931 unsigned long uvalue = 0;
932 unsigned char *block_start = NULL;
933 unsigned int bytes_read;
940 case DW_FORM_ref_addr:
941 if (dwarf_version == 2)
943 uvalue = byte_get (data, pointer_size);
944 data += pointer_size;
946 else if (dwarf_version == 3)
948 uvalue = byte_get (data, offset_size);
953 error (_("Internal error: DWARF version is not 2 or 3.\n"));
958 uvalue = byte_get (data, pointer_size);
959 data += pointer_size;
963 uvalue = byte_get (data, offset_size);
970 uvalue = byte_get (data++, 1);
975 uvalue = byte_get (data, 2);
981 uvalue = byte_get (data, 4);
986 uvalue = read_leb128 (data, & bytes_read, 1);
990 case DW_FORM_ref_udata:
992 uvalue = read_leb128 (data, & bytes_read, 0);
996 case DW_FORM_indirect:
997 form = read_leb128 (data, & bytes_read, 0);
1000 printf (" %s", get_FORM_name (form));
1001 return read_and_display_attr_value (attribute, form, data,
1002 cu_offset, pointer_size,
1003 offset_size, dwarf_version,
1004 debug_info_p, do_loc);
1009 case DW_FORM_ref_addr:
1011 printf (" <#%lx>", uvalue);
1017 case DW_FORM_ref_udata:
1019 printf (" <%lx>", uvalue + cu_offset);
1025 printf (" %#lx", uvalue);
1034 printf (" %ld", uvalue);
1041 uvalue = byte_get (data, 4);
1042 printf (" %lx", uvalue);
1043 printf (" %lx", (unsigned long) byte_get (data + 4, 4));
1045 if ((do_loc || do_debug_loc || do_debug_ranges)
1046 && num_debug_info_entries == 0)
1048 if (sizeof (uvalue) == 8)
1049 uvalue = byte_get (data, 8);
1051 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1056 case DW_FORM_string:
1058 printf (" %s", data);
1059 data += strlen ((char *) data) + 1;
1063 uvalue = read_leb128 (data, & bytes_read, 0);
1064 block_start = data + bytes_read;
1066 data = block_start + uvalue;
1068 data = display_block (block_start, uvalue);
1071 case DW_FORM_block1:
1072 uvalue = byte_get (data, 1);
1073 block_start = data + 1;
1075 data = block_start + uvalue;
1077 data = display_block (block_start, uvalue);
1080 case DW_FORM_block2:
1081 uvalue = byte_get (data, 2);
1082 block_start = data + 2;
1084 data = block_start + uvalue;
1086 data = display_block (block_start, uvalue);
1089 case DW_FORM_block4:
1090 uvalue = byte_get (data, 4);
1091 block_start = data + 4;
1093 data = block_start + uvalue;
1095 data = display_block (block_start, uvalue);
1100 printf (_(" (indirect string, offset: 0x%lx): %s"),
1101 uvalue, fetch_indirect_string (uvalue));
1104 case DW_FORM_indirect:
1105 /* Handled above. */
1109 warn (_("Unrecognized form: %lu\n"), form);
1113 /* For some attributes we can display further information. */
1114 if ((do_loc || do_debug_loc || do_debug_ranges)
1115 && num_debug_info_entries == 0)
1119 case DW_AT_frame_base:
1120 have_frame_base = 1;
1121 case DW_AT_location:
1122 case DW_AT_data_member_location:
1123 case DW_AT_vtable_elem_location:
1124 case DW_AT_allocated:
1125 case DW_AT_associated:
1126 case DW_AT_data_location:
1128 case DW_AT_upper_bound:
1129 case DW_AT_lower_bound:
1130 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1132 /* Process location list. */
1133 unsigned int max = debug_info_p->max_loc_offsets;
1134 unsigned int num = debug_info_p->num_loc_offsets;
1136 if (max == 0 || num >= max)
1139 debug_info_p->loc_offsets
1140 = xcrealloc (debug_info_p->loc_offsets,
1141 max, sizeof (*debug_info_p->loc_offsets));
1142 debug_info_p->have_frame_base
1143 = xcrealloc (debug_info_p->have_frame_base,
1144 max, sizeof (*debug_info_p->have_frame_base));
1145 debug_info_p->max_loc_offsets = max;
1147 debug_info_p->loc_offsets [num] = uvalue;
1148 debug_info_p->have_frame_base [num] = have_frame_base;
1149 debug_info_p->num_loc_offsets++;
1154 if (need_base_address)
1155 debug_info_p->base_address = uvalue;
1159 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1161 /* Process range list. */
1162 unsigned int max = debug_info_p->max_range_lists;
1163 unsigned int num = debug_info_p->num_range_lists;
1165 if (max == 0 || num >= max)
1168 debug_info_p->range_lists
1169 = xcrealloc (debug_info_p->range_lists,
1170 max, sizeof (*debug_info_p->range_lists));
1171 debug_info_p->max_range_lists = max;
1173 debug_info_p->range_lists [num] = uvalue;
1174 debug_info_p->num_range_lists++;
1193 case DW_INL_not_inlined:
1194 printf (_("(not inlined)"));
1196 case DW_INL_inlined:
1197 printf (_("(inlined)"));
1199 case DW_INL_declared_not_inlined:
1200 printf (_("(declared as inline but ignored)"));
1202 case DW_INL_declared_inlined:
1203 printf (_("(declared as inline and inlined)"));
1206 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
1211 case DW_AT_language:
1214 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1215 case DW_LANG_C89: printf ("(ANSI C)"); break;
1216 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1217 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1218 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1219 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1220 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1221 case DW_LANG_Ada83: printf ("(Ada)"); break;
1222 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1223 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1224 /* DWARF 2.1 values. */
1225 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1226 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1227 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1228 /* MIPS extension. */
1229 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1230 /* UPC extension. */
1231 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1233 printf ("(Unknown: %lx)", uvalue);
1238 case DW_AT_encoding:
1241 case DW_ATE_void: printf ("(void)"); break;
1242 case DW_ATE_address: printf ("(machine address)"); break;
1243 case DW_ATE_boolean: printf ("(boolean)"); break;
1244 case DW_ATE_complex_float: printf ("(complex float)"); break;
1245 case DW_ATE_float: printf ("(float)"); break;
1246 case DW_ATE_signed: printf ("(signed)"); break;
1247 case DW_ATE_signed_char: printf ("(signed char)"); break;
1248 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1249 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1250 /* DWARF 2.1 value. */
1251 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1252 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1254 if (uvalue >= DW_ATE_lo_user
1255 && uvalue <= DW_ATE_hi_user)
1256 printf ("(user defined type)");
1258 printf ("(unknown type)");
1263 case DW_AT_accessibility:
1266 case DW_ACCESS_public: printf ("(public)"); break;
1267 case DW_ACCESS_protected: printf ("(protected)"); break;
1268 case DW_ACCESS_private: printf ("(private)"); break;
1270 printf ("(unknown accessibility)");
1275 case DW_AT_visibility:
1278 case DW_VIS_local: printf ("(local)"); break;
1279 case DW_VIS_exported: printf ("(exported)"); break;
1280 case DW_VIS_qualified: printf ("(qualified)"); break;
1281 default: printf ("(unknown visibility)"); break;
1285 case DW_AT_virtuality:
1288 case DW_VIRTUALITY_none: printf ("(none)"); break;
1289 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1290 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1291 default: printf ("(unknown virtuality)"); break;
1295 case DW_AT_identifier_case:
1298 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1299 case DW_ID_up_case: printf ("(up_case)"); break;
1300 case DW_ID_down_case: printf ("(down_case)"); break;
1301 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1302 default: printf ("(unknown case)"); break;
1306 case DW_AT_calling_convention:
1309 case DW_CC_normal: printf ("(normal)"); break;
1310 case DW_CC_program: printf ("(program)"); break;
1311 case DW_CC_nocall: printf ("(nocall)"); break;
1313 if (uvalue >= DW_CC_lo_user
1314 && uvalue <= DW_CC_hi_user)
1315 printf ("(user defined)");
1317 printf ("(unknown convention)");
1321 case DW_AT_ordering:
1324 case -1: printf ("(undefined)"); break;
1325 case 0: printf ("(row major)"); break;
1326 case 1: printf ("(column major)"); break;
1330 case DW_AT_frame_base:
1331 have_frame_base = 1;
1332 case DW_AT_location:
1333 case DW_AT_data_member_location:
1334 case DW_AT_vtable_elem_location:
1335 case DW_AT_allocated:
1336 case DW_AT_associated:
1337 case DW_AT_data_location:
1339 case DW_AT_upper_bound:
1340 case DW_AT_lower_bound:
1343 int need_frame_base;
1346 need_frame_base = decode_location_expression (block_start,
1351 if (need_frame_base && !have_frame_base)
1352 printf (_(" [without DW_AT_frame_base]"));
1354 else if (form == DW_FORM_data4 || form == DW_FORM_data8)
1355 printf (_("(location list)"));
1367 get_AT_name (unsigned long attribute)
1371 case DW_AT_sibling: return "DW_AT_sibling";
1372 case DW_AT_location: return "DW_AT_location";
1373 case DW_AT_name: return "DW_AT_name";
1374 case DW_AT_ordering: return "DW_AT_ordering";
1375 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1376 case DW_AT_byte_size: return "DW_AT_byte_size";
1377 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1378 case DW_AT_bit_size: return "DW_AT_bit_size";
1379 case DW_AT_element_list: return "DW_AT_element_list";
1380 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1381 case DW_AT_low_pc: return "DW_AT_low_pc";
1382 case DW_AT_high_pc: return "DW_AT_high_pc";
1383 case DW_AT_language: return "DW_AT_language";
1384 case DW_AT_member: return "DW_AT_member";
1385 case DW_AT_discr: return "DW_AT_discr";
1386 case DW_AT_discr_value: return "DW_AT_discr_value";
1387 case DW_AT_visibility: return "DW_AT_visibility";
1388 case DW_AT_import: return "DW_AT_import";
1389 case DW_AT_string_length: return "DW_AT_string_length";
1390 case DW_AT_common_reference: return "DW_AT_common_reference";
1391 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1392 case DW_AT_const_value: return "DW_AT_const_value";
1393 case DW_AT_containing_type: return "DW_AT_containing_type";
1394 case DW_AT_default_value: return "DW_AT_default_value";
1395 case DW_AT_inline: return "DW_AT_inline";
1396 case DW_AT_is_optional: return "DW_AT_is_optional";
1397 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1398 case DW_AT_producer: return "DW_AT_producer";
1399 case DW_AT_prototyped: return "DW_AT_prototyped";
1400 case DW_AT_return_addr: return "DW_AT_return_addr";
1401 case DW_AT_start_scope: return "DW_AT_start_scope";
1402 case DW_AT_stride_size: return "DW_AT_stride_size";
1403 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1404 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1405 case DW_AT_accessibility: return "DW_AT_accessibility";
1406 case DW_AT_address_class: return "DW_AT_address_class";
1407 case DW_AT_artificial: return "DW_AT_artificial";
1408 case DW_AT_base_types: return "DW_AT_base_types";
1409 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1410 case DW_AT_count: return "DW_AT_count";
1411 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1412 case DW_AT_decl_column: return "DW_AT_decl_column";
1413 case DW_AT_decl_file: return "DW_AT_decl_file";
1414 case DW_AT_decl_line: return "DW_AT_decl_line";
1415 case DW_AT_declaration: return "DW_AT_declaration";
1416 case DW_AT_discr_list: return "DW_AT_discr_list";
1417 case DW_AT_encoding: return "DW_AT_encoding";
1418 case DW_AT_external: return "DW_AT_external";
1419 case DW_AT_frame_base: return "DW_AT_frame_base";
1420 case DW_AT_friend: return "DW_AT_friend";
1421 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1422 case DW_AT_macro_info: return "DW_AT_macro_info";
1423 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1424 case DW_AT_priority: return "DW_AT_priority";
1425 case DW_AT_segment: return "DW_AT_segment";
1426 case DW_AT_specification: return "DW_AT_specification";
1427 case DW_AT_static_link: return "DW_AT_static_link";
1428 case DW_AT_type: return "DW_AT_type";
1429 case DW_AT_use_location: return "DW_AT_use_location";
1430 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1431 case DW_AT_virtuality: return "DW_AT_virtuality";
1432 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1433 /* DWARF 2.1 values. */
1434 case DW_AT_allocated: return "DW_AT_allocated";
1435 case DW_AT_associated: return "DW_AT_associated";
1436 case DW_AT_data_location: return "DW_AT_data_location";
1437 case DW_AT_stride: return "DW_AT_stride";
1438 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1439 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1440 case DW_AT_extension: return "DW_AT_extension";
1441 case DW_AT_ranges: return "DW_AT_ranges";
1442 case DW_AT_trampoline: return "DW_AT_trampoline";
1443 case DW_AT_call_column: return "DW_AT_call_column";
1444 case DW_AT_call_file: return "DW_AT_call_file";
1445 case DW_AT_call_line: return "DW_AT_call_line";
1446 /* SGI/MIPS extensions. */
1447 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde";
1448 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1449 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1450 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1451 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1452 case DW_AT_MIPS_software_pipeline_depth:
1453 return "DW_AT_MIPS_software_pipeline_depth";
1454 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1455 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1456 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1457 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1458 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1459 /* GNU extensions. */
1460 case DW_AT_sf_names: return "DW_AT_sf_names";
1461 case DW_AT_src_info: return "DW_AT_src_info";
1462 case DW_AT_mac_info: return "DW_AT_mac_info";
1463 case DW_AT_src_coords: return "DW_AT_src_coords";
1464 case DW_AT_body_begin: return "DW_AT_body_begin";
1465 case DW_AT_body_end: return "DW_AT_body_end";
1466 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1467 /* UPC extension. */
1468 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1471 static char buffer[100];
1473 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1480 static unsigned char *
1481 read_and_display_attr (unsigned long attribute,
1483 unsigned char *data,
1484 unsigned long cu_offset,
1485 unsigned long pointer_size,
1486 unsigned long offset_size,
1488 debug_info *debug_info_p,
1492 printf (" %-18s:", get_AT_name (attribute));
1493 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1494 pointer_size, offset_size,
1495 dwarf_version, debug_info_p,
1503 /* Process the contents of a .debug_info section. If do_loc is non-zero
1504 then we are scanning for location lists and we do not want to display
1505 anything to the user. */
1508 process_debug_info (struct dwarf_section *section, void *file,
1511 unsigned char *start = section->start;
1512 unsigned char *end = start + section->size;
1513 unsigned char *section_begin;
1515 unsigned int num_units = 0;
1517 if ((do_loc || do_debug_loc || do_debug_ranges)
1518 && num_debug_info_entries == 0)
1520 unsigned long length;
1522 /* First scan the section to get the number of comp units. */
1523 for (section_begin = start, num_units = 0; section_begin < end;
1526 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1527 will be the length. For a 64-bit DWARF section, it'll be
1528 the escape code 0xffffffff followed by an 8 byte length. */
1529 length = byte_get (section_begin, 4);
1531 if (length == 0xffffffff)
1533 length = byte_get (section_begin + 4, 8);
1534 section_begin += length + 12;
1537 section_begin += length + 4;
1542 error (_("No comp units in %s section ?"), section->name);
1546 /* Then allocate an array to hold the information. */
1547 debug_information = cmalloc (num_units,
1548 sizeof (* debug_information));
1549 if (debug_information == NULL)
1551 error (_("Not enough memory for a debug info array of %u entries"),
1559 printf (_("The section %s contains:\n\n"), section->name);
1561 load_debug_section (str, file);
1564 load_debug_section (abbrev, file);
1565 if (debug_displays [abbrev].section.start == NULL)
1567 warn (_("Unable to locate %s section!\n"),
1568 debug_displays [abbrev].section.name);
1572 for (section_begin = start, unit = 0; start < end; unit++)
1574 DWARF2_Internal_CompUnit compunit;
1575 unsigned char *hdrptr;
1576 unsigned char *cu_abbrev_offset_ptr;
1577 unsigned char *tags;
1579 unsigned long cu_offset;
1581 int initial_length_size;
1585 compunit.cu_length = byte_get (hdrptr, 4);
1588 if (compunit.cu_length == 0xffffffff)
1590 compunit.cu_length = byte_get (hdrptr, 8);
1593 initial_length_size = 12;
1598 initial_length_size = 4;
1601 compunit.cu_version = byte_get (hdrptr, 2);
1604 cu_offset = start - section_begin;
1605 start += compunit.cu_length + initial_length_size;
1607 cu_abbrev_offset_ptr = hdrptr;
1608 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
1609 hdrptr += offset_size;
1611 compunit.cu_pointer_size = byte_get (hdrptr, 1);
1613 if ((do_loc || do_debug_loc || do_debug_ranges)
1614 && num_debug_info_entries == 0)
1616 debug_information [unit].cu_offset = cu_offset;
1617 debug_information [unit].pointer_size
1618 = compunit.cu_pointer_size;
1619 debug_information [unit].base_address = 0;
1620 debug_information [unit].loc_offsets = NULL;
1621 debug_information [unit].have_frame_base = NULL;
1622 debug_information [unit].max_loc_offsets = 0;
1623 debug_information [unit].num_loc_offsets = 0;
1624 debug_information [unit].range_lists = NULL;
1625 debug_information [unit].max_range_lists= 0;
1626 debug_information [unit].num_range_lists = 0;
1633 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset);
1634 printf (_(" Length: %ld\n"), compunit.cu_length);
1635 printf (_(" Version: %d\n"), compunit.cu_version);
1636 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
1637 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
1640 if (compunit.cu_version != 2 && compunit.cu_version != 3)
1642 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
1648 /* Process the abbrevs used by this compilation unit. */
1649 process_abbrev_section
1650 ((unsigned char *) debug_displays [abbrev].section.start
1651 + compunit.cu_abbrev_offset,
1652 (unsigned char *) debug_displays [abbrev].section.start
1653 + debug_displays [abbrev].section.size);
1656 while (tags < start)
1658 unsigned int bytes_read;
1659 unsigned long abbrev_number;
1660 abbrev_entry *entry;
1663 abbrev_number = read_leb128 (tags, & bytes_read, 0);
1666 /* A null DIE marks the end of a list of children. */
1667 if (abbrev_number == 0)
1673 /* Scan through the abbreviation list until we reach the
1675 for (entry = first_abbrev;
1676 entry && entry->entry != abbrev_number;
1677 entry = entry->next)
1682 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
1688 printf (_(" <%d><%lx>: Abbrev Number: %lu (%s)\n"),
1690 (unsigned long) (tags - section_begin
1693 get_TAG_name (entry->tag));
1698 need_base_address = 0;
1700 case DW_TAG_compile_unit:
1701 need_base_address = 1;
1703 case DW_TAG_entry_point:
1704 case DW_TAG_inlined_subroutine:
1705 case DW_TAG_subprogram:
1706 need_base_address = 0;
1707 /* Assuming that there is no DW_AT_frame_base. */
1708 have_frame_base = 0;
1712 for (attr = entry->first_attr; attr; attr = attr->next)
1713 tags = read_and_display_attr (attr->attribute,
1716 compunit.cu_pointer_size,
1718 compunit.cu_version,
1719 &debug_information [unit],
1722 if (entry->children)
1727 /* Set num_debug_info_entries here so that it can be used to check if
1728 we need to process .debug_loc and .debug_ranges sections. */
1729 if ((do_loc || do_debug_loc || do_debug_ranges)
1730 && num_debug_info_entries == 0)
1731 num_debug_info_entries = num_units;
1741 /* Locate and scan the .debug_info section in the file and record the pointer
1742 sizes and offsets for the compilation units in it. Usually an executable
1743 will have just one pointer size, but this is not guaranteed, and so we try
1744 not to make any assumptions. Returns zero upon failure, or the number of
1745 compilation units upon success. */
1748 load_debug_info (void * file)
1750 /* Reset the last pointer size so that we can issue correct error
1751 messages if we are displaying the contents of more than one section. */
1752 last_pointer_size = 0;
1753 warned_about_missing_comp_units = FALSE;
1755 /* If we already have the information there is nothing else to do. */
1756 if (num_debug_info_entries > 0)
1757 return num_debug_info_entries;
1759 if (load_debug_section (info, file)
1760 && process_debug_info (&debug_displays [info].section, file, 1))
1761 return num_debug_info_entries;
1766 /* Retrieve the pointer size associated with the given compilation unit.
1767 Optionally the offset of this unit into the .debug_info section is
1768 also retutned. If there is no .debug_info section then an error
1769 message is issued and 0 is returned. If the requested comp unit has
1770 not been defined in the .debug_info section then a warning message
1771 is issued and the last know pointer size is returned. This message
1772 is only issued once per section dumped per file dumped. */
1775 get_pointer_size_and_offset_of_comp_unit (unsigned int comp_unit,
1776 const char * section_name,
1777 unsigned long * offset_return)
1779 unsigned long offset = 0;
1781 if (num_debug_info_entries == 0)
1782 error (_("%s section needs a populated .debug_info section\n"),
1785 else if (comp_unit >= num_debug_info_entries)
1787 if (!warned_about_missing_comp_units)
1789 warn (_("%s section has more comp units than .debug_info section\n"),
1791 warn (_("assuming that the pointer size is %d, from the last comp unit in .debug_info\n\n"),
1793 warned_about_missing_comp_units = TRUE;
1798 last_pointer_size = debug_information [comp_unit].pointer_size;
1799 offset = debug_information [comp_unit].cu_offset;
1802 if (offset_return != NULL)
1803 * offset_return = offset;
1805 return last_pointer_size;
1809 display_debug_lines (struct dwarf_section *section, void *file)
1811 unsigned char *start = section->start;
1812 unsigned char *data = start;
1813 unsigned char *end = start + section->size;
1814 unsigned int comp_unit = 0;
1816 printf (_("\nDump of debug contents of section %s:\n\n"),
1819 load_debug_info (file);
1823 DWARF2_Internal_LineInfo info;
1824 unsigned char *standard_opcodes;
1825 unsigned char *end_of_sequence;
1826 unsigned char *hdrptr;
1827 unsigned int pointer_size;
1828 int initial_length_size;
1834 /* Check the length of the block. */
1835 info.li_length = byte_get (hdrptr, 4);
1838 if (info.li_length == 0xffffffff)
1840 /* This section is 64-bit DWARF 3. */
1841 info.li_length = byte_get (hdrptr, 8);
1844 initial_length_size = 12;
1849 initial_length_size = 4;
1852 if (info.li_length + initial_length_size > section->size)
1855 (_("The line info appears to be corrupt - the section is too small\n"));
1859 /* Check its version number. */
1860 info.li_version = byte_get (hdrptr, 2);
1862 if (info.li_version != 2 && info.li_version != 3)
1864 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
1868 info.li_prologue_length = byte_get (hdrptr, offset_size);
1869 hdrptr += offset_size;
1870 info.li_min_insn_length = byte_get (hdrptr, 1);
1872 info.li_default_is_stmt = byte_get (hdrptr, 1);
1874 info.li_line_base = byte_get (hdrptr, 1);
1876 info.li_line_range = byte_get (hdrptr, 1);
1878 info.li_opcode_base = byte_get (hdrptr, 1);
1881 /* Sign extend the line base field. */
1882 info.li_line_base <<= 24;
1883 info.li_line_base >>= 24;
1885 /* Get the pointer size from the comp unit associated
1886 with this block of line number information. */
1887 pointer_size = get_pointer_size_and_offset_of_comp_unit
1888 (comp_unit, ".debug_line", NULL);
1891 printf (_(" Length: %ld\n"), info.li_length);
1892 printf (_(" DWARF Version: %d\n"), info.li_version);
1893 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
1894 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
1895 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
1896 printf (_(" Line Base: %d\n"), info.li_line_base);
1897 printf (_(" Line Range: %d\n"), info.li_line_range);
1898 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
1899 printf (_(" (Pointer size: %u)%s\n"),
1901 warned_about_missing_comp_units ? " [assumed]" : "" );
1903 end_of_sequence = data + info.li_length + initial_length_size;
1905 reset_state_machine (info.li_default_is_stmt);
1907 /* Display the contents of the Opcodes table. */
1908 standard_opcodes = hdrptr;
1910 printf (_("\n Opcodes:\n"));
1912 for (i = 1; i < info.li_opcode_base; i++)
1913 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
1915 /* Display the contents of the Directory table. */
1916 data = standard_opcodes + info.li_opcode_base - 1;
1919 printf (_("\n The Directory Table is empty.\n"));
1922 printf (_("\n The Directory Table:\n"));
1926 printf (_(" %s\n"), data);
1928 data += strlen ((char *) data) + 1;
1932 /* Skip the NUL at the end of the table. */
1935 /* Display the contents of the File Name table. */
1937 printf (_("\n The File Name Table is empty.\n"));
1940 printf (_("\n The File Name Table:\n"));
1941 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
1945 unsigned char *name;
1946 unsigned int bytes_read;
1948 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
1951 data += strlen ((char *) data) + 1;
1953 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
1955 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
1957 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
1959 printf (_("%s\n"), name);
1963 /* Skip the NUL at the end of the table. */
1966 /* Now display the statements. */
1967 printf (_("\n Line Number Statements:\n"));
1969 while (data < end_of_sequence)
1971 unsigned char op_code;
1973 unsigned long int uladv;
1974 unsigned int bytes_read;
1978 if (op_code >= info.li_opcode_base)
1980 op_code -= info.li_opcode_base;
1981 uladv = (op_code / info.li_line_range) * info.li_min_insn_length;
1982 state_machine_regs.address += uladv;
1983 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
1984 op_code, uladv, state_machine_regs.address);
1985 adv = (op_code % info.li_line_range) + info.li_line_base;
1986 state_machine_regs.line += adv;
1987 printf (_(" and Line by %d to %d\n"),
1988 adv, state_machine_regs.line);
1990 else switch (op_code)
1992 case DW_LNS_extended_op:
1993 if (pointer_size == 0)
1995 warn (_("Extend line ops need a valid pointer size, guessing at 4\n"));
1999 data += process_extended_line_op (data, info.li_default_is_stmt,
2004 printf (_(" Copy\n"));
2007 case DW_LNS_advance_pc:
2008 uladv = read_leb128 (data, & bytes_read, 0);
2009 uladv *= info.li_min_insn_length;
2011 state_machine_regs.address += uladv;
2012 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv,
2013 state_machine_regs.address);
2016 case DW_LNS_advance_line:
2017 adv = read_leb128 (data, & bytes_read, 1);
2019 state_machine_regs.line += adv;
2020 printf (_(" Advance Line by %d to %d\n"), adv,
2021 state_machine_regs.line);
2024 case DW_LNS_set_file:
2025 adv = read_leb128 (data, & bytes_read, 0);
2027 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2029 state_machine_regs.file = adv;
2032 case DW_LNS_set_column:
2033 uladv = read_leb128 (data, & bytes_read, 0);
2035 printf (_(" Set column to %lu\n"), uladv);
2036 state_machine_regs.column = uladv;
2039 case DW_LNS_negate_stmt:
2040 adv = state_machine_regs.is_stmt;
2042 printf (_(" Set is_stmt to %d\n"), adv);
2043 state_machine_regs.is_stmt = adv;
2046 case DW_LNS_set_basic_block:
2047 printf (_(" Set basic block\n"));
2048 state_machine_regs.basic_block = 1;
2051 case DW_LNS_const_add_pc:
2052 uladv = (((255 - info.li_opcode_base) / info.li_line_range)
2053 * info.li_min_insn_length);
2054 state_machine_regs.address += uladv;
2055 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv,
2056 state_machine_regs.address);
2059 case DW_LNS_fixed_advance_pc:
2060 uladv = byte_get (data, 2);
2062 state_machine_regs.address += uladv;
2063 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2064 uladv, state_machine_regs.address);
2067 case DW_LNS_set_prologue_end:
2068 printf (_(" Set prologue_end to true\n"));
2071 case DW_LNS_set_epilogue_begin:
2072 printf (_(" Set epilogue_begin to true\n"));
2075 case DW_LNS_set_isa:
2076 uladv = read_leb128 (data, & bytes_read, 0);
2078 printf (_(" Set ISA to %lu\n"), uladv);
2082 printf (_(" Unknown opcode %d with operands: "), op_code);
2084 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2086 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
2087 i == 1 ? "" : ", ");
2101 display_debug_pubnames (struct dwarf_section *section,
2102 void *file ATTRIBUTE_UNUSED)
2104 DWARF2_Internal_PubNames pubnames;
2105 unsigned char *start = section->start;
2106 unsigned char *end = start + section->size;
2108 printf (_("Contents of the %s section:\n\n"), section->name);
2112 unsigned char *data;
2113 unsigned long offset;
2114 int offset_size, initial_length_size;
2118 pubnames.pn_length = byte_get (data, 4);
2120 if (pubnames.pn_length == 0xffffffff)
2122 pubnames.pn_length = byte_get (data, 8);
2125 initial_length_size = 12;
2130 initial_length_size = 4;
2133 pubnames.pn_version = byte_get (data, 2);
2135 pubnames.pn_offset = byte_get (data, offset_size);
2136 data += offset_size;
2137 pubnames.pn_size = byte_get (data, offset_size);
2138 data += offset_size;
2140 start += pubnames.pn_length + initial_length_size;
2142 if (pubnames.pn_version != 2 && pubnames.pn_version != 3)
2144 static int warned = 0;
2148 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2155 printf (_(" Length: %ld\n"),
2156 pubnames.pn_length);
2157 printf (_(" Version: %d\n"),
2158 pubnames.pn_version);
2159 printf (_(" Offset into .debug_info section: %ld\n"),
2160 pubnames.pn_offset);
2161 printf (_(" Size of area in .debug_info section: %ld\n"),
2164 printf (_("\n Offset\tName\n"));
2168 offset = byte_get (data, offset_size);
2172 data += offset_size;
2173 printf (" %-6ld\t\t%s\n", offset, data);
2174 data += strlen ((char *) data) + 1;
2177 while (offset != 0);
2185 display_debug_macinfo (struct dwarf_section *section,
2186 void *file ATTRIBUTE_UNUSED)
2188 unsigned char *start = section->start;
2189 unsigned char *end = start + section->size;
2190 unsigned char *curr = start;
2191 unsigned int bytes_read;
2192 enum dwarf_macinfo_record_type op;
2194 printf (_("Contents of the %s section:\n\n"), section->name);
2198 unsigned int lineno;
2206 case DW_MACINFO_start_file:
2208 unsigned int filenum;
2210 lineno = read_leb128 (curr, & bytes_read, 0);
2212 filenum = read_leb128 (curr, & bytes_read, 0);
2215 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2220 case DW_MACINFO_end_file:
2221 printf (_(" DW_MACINFO_end_file\n"));
2224 case DW_MACINFO_define:
2225 lineno = read_leb128 (curr, & bytes_read, 0);
2227 string = (char *) curr;
2228 curr += strlen (string) + 1;
2229 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2233 case DW_MACINFO_undef:
2234 lineno = read_leb128 (curr, & bytes_read, 0);
2236 string = (char *) curr;
2237 curr += strlen (string) + 1;
2238 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2242 case DW_MACINFO_vendor_ext:
2244 unsigned int constant;
2246 constant = read_leb128 (curr, & bytes_read, 0);
2248 string = (char *) curr;
2249 curr += strlen (string) + 1;
2250 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2261 display_debug_abbrev (struct dwarf_section *section,
2262 void *file ATTRIBUTE_UNUSED)
2264 abbrev_entry *entry;
2265 unsigned char *start = section->start;
2266 unsigned char *end = start + section->size;
2268 printf (_("Contents of the %s section:\n\n"), section->name);
2274 start = process_abbrev_section (start, end);
2276 if (first_abbrev == NULL)
2279 printf (_(" Number TAG\n"));
2281 for (entry = first_abbrev; entry; entry = entry->next)
2285 printf (_(" %ld %s [%s]\n"),
2287 get_TAG_name (entry->tag),
2288 entry->children ? _("has children") : _("no children"));
2290 for (attr = entry->first_attr; attr; attr = attr->next)
2291 printf (_(" %-18s %s\n"),
2292 get_AT_name (attr->attribute),
2293 get_FORM_name (attr->form));
2304 display_debug_loc (struct dwarf_section *section, void *file)
2306 unsigned char *start = section->start;
2307 unsigned char *section_end;
2308 unsigned long bytes;
2309 unsigned char *section_begin = start;
2310 unsigned int num_loc_list = 0;
2311 unsigned long last_offset = 0;
2312 unsigned int first = 0;
2315 int seen_first_offset = 0;
2316 int use_debug_info = 1;
2317 unsigned char *next;
2319 bytes = section->size;
2320 section_end = start + bytes;
2324 printf (_("\nThe %s section is empty.\n"), section->name);
2328 load_debug_info (file);
2330 /* Check the order of location list in .debug_info section. If
2331 offsets of location lists are in the ascending order, we can
2332 use `debug_information' directly. */
2333 for (i = 0; i < num_debug_info_entries; i++)
2337 num = debug_information [i].num_loc_offsets;
2338 num_loc_list += num;
2340 /* Check if we can use `debug_information' directly. */
2341 if (use_debug_info && num != 0)
2343 if (!seen_first_offset)
2345 /* This is the first location list. */
2346 last_offset = debug_information [i].loc_offsets [0];
2348 seen_first_offset = 1;
2354 for (; j < num; j++)
2357 debug_information [i].loc_offsets [j])
2362 last_offset = debug_information [i].loc_offsets [j];
2367 if (!use_debug_info)
2368 /* FIXME: Should we handle this case? */
2369 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
2371 if (!seen_first_offset)
2372 error (_("No location lists in .debug_info section!\n"));
2374 if (debug_information [first].loc_offsets [0] != 0)
2375 warn (_("Location lists in %s section start at 0x%lx\n"),
2376 section->name, debug_information [first].loc_offsets [0]);
2378 printf (_("Contents of the %s section:\n\n"), section->name);
2379 printf (_(" Offset Begin End Expression\n"));
2381 seen_first_offset = 0;
2382 for (i = first; i < num_debug_info_entries; i++)
2384 unsigned long begin;
2386 unsigned short length;
2387 unsigned long offset;
2388 unsigned int pointer_size;
2389 unsigned long cu_offset;
2390 unsigned long base_address;
2391 int need_frame_base;
2394 pointer_size = debug_information [i].pointer_size;
2395 cu_offset = debug_information [i].cu_offset;
2397 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
2399 has_frame_base = debug_information [i].have_frame_base [j];
2400 offset = debug_information [i].loc_offsets [j];
2401 next = section_begin + offset;
2402 base_address = debug_information [i].base_address;
2404 if (!seen_first_offset)
2405 seen_first_offset = 1;
2409 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
2410 (long)(start - section_begin), (long)(next - section_begin));
2411 else if (start > next)
2412 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
2413 (long)(start - section_begin), (long)(next - section_begin));
2417 if (offset >= bytes)
2419 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
2426 if (start + 2 * pointer_size > section_end)
2428 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2433 begin = byte_get (start, pointer_size);
2434 start += pointer_size;
2435 end = byte_get (start, pointer_size);
2436 start += pointer_size;
2438 if (begin == 0 && end == 0)
2440 printf (_(" %8.8lx <End of list>\n"), offset);
2444 /* Check base address specifiers. */
2445 if (begin == -1UL && end != -1UL)
2448 printf (_(" %8.8lx %8.8lx %8.8lx (base address)\n"),
2449 offset, begin, end);
2453 if (start + 2 > section_end)
2455 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2460 length = byte_get (start, 2);
2463 if (start + length > section_end)
2465 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2470 printf (" %8.8lx %8.8lx %8.8lx (",
2471 offset, begin + base_address, end + base_address);
2472 need_frame_base = decode_location_expression (start,
2478 if (need_frame_base && !has_frame_base)
2479 printf (_(" [without DW_AT_frame_base]"));
2482 fputs (_(" (start == end)"), stdout);
2483 else if (begin > end)
2484 fputs (_(" (start > end)"), stdout);
2496 display_debug_str (struct dwarf_section *section,
2497 void *file ATTRIBUTE_UNUSED)
2499 unsigned char *start = section->start;
2500 unsigned long bytes = section->size;
2501 dwarf_vma addr = section->address;
2505 printf (_("\nThe %s section is empty.\n"), section->name);
2509 printf (_("Contents of the %s section:\n\n"), section->name);
2517 lbytes = (bytes > 16 ? 16 : bytes);
2519 printf (" 0x%8.8lx ", (unsigned long) addr);
2521 for (j = 0; j < 16; j++)
2524 printf ("%2.2x", start[j]);
2532 for (j = 0; j < lbytes; j++)
2535 if (k >= ' ' && k < 0x80)
2555 display_debug_info (struct dwarf_section *section, void *file)
2557 return process_debug_info (section, file, 0);
2562 display_debug_aranges (struct dwarf_section *section,
2563 void *file ATTRIBUTE_UNUSED)
2565 unsigned char *start = section->start;
2566 unsigned char *end = start + section->size;
2568 printf (_("The section %s contains:\n\n"), section->name);
2572 unsigned char *hdrptr;
2573 DWARF2_Internal_ARange arange;
2574 unsigned char *ranges;
2575 unsigned long length;
2576 unsigned long address;
2579 int initial_length_size;
2583 arange.ar_length = byte_get (hdrptr, 4);
2586 if (arange.ar_length == 0xffffffff)
2588 arange.ar_length = byte_get (hdrptr, 8);
2591 initial_length_size = 12;
2596 initial_length_size = 4;
2599 arange.ar_version = byte_get (hdrptr, 2);
2602 arange.ar_info_offset = byte_get (hdrptr, offset_size);
2603 hdrptr += offset_size;
2605 arange.ar_pointer_size = byte_get (hdrptr, 1);
2608 arange.ar_segment_size = byte_get (hdrptr, 1);
2611 if (arange.ar_version != 2 && arange.ar_version != 3)
2613 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
2617 printf (_(" Length: %ld\n"), arange.ar_length);
2618 printf (_(" Version: %d\n"), arange.ar_version);
2619 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
2620 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
2621 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
2623 printf (_("\n Address Length\n"));
2627 /* Must pad to an alignment boundary that is twice the pointer size. */
2628 excess = (hdrptr - start) % (2 * arange.ar_pointer_size);
2630 ranges += (2 * arange.ar_pointer_size) - excess;
2634 address = byte_get (ranges, arange.ar_pointer_size);
2636 ranges += arange.ar_pointer_size;
2638 length = byte_get (ranges, arange.ar_pointer_size);
2640 ranges += arange.ar_pointer_size;
2642 /* A pair of zeros marks the end of the list. */
2643 if (address == 0 && length == 0)
2646 printf (" %8.8lx %lu\n", address, length);
2649 start += arange.ar_length + initial_length_size;
2658 display_debug_ranges (struct dwarf_section *section,
2659 void *file ATTRIBUTE_UNUSED)
2661 unsigned char *start = section->start;
2662 unsigned char *section_end;
2663 unsigned long bytes;
2664 unsigned char *section_begin = start;
2665 unsigned int num_range_list = 0;
2666 unsigned long last_offset = 0;
2667 unsigned int first = 0;
2670 int seen_first_offset = 0;
2671 int use_debug_info = 1;
2672 unsigned char *next;
2674 bytes = section->size;
2675 section_end = start + bytes;
2679 printf (_("\nThe %s section is empty.\n"), section->name);
2683 load_debug_info (file);
2685 /* Check the order of range list in .debug_info section. If
2686 offsets of range lists are in the ascending order, we can
2687 use `debug_information' directly. */
2688 for (i = 0; i < num_debug_info_entries; i++)
2692 num = debug_information [i].num_range_lists;
2693 num_range_list += num;
2695 /* Check if we can use `debug_information' directly. */
2696 if (use_debug_info && num != 0)
2698 if (!seen_first_offset)
2700 /* This is the first range list. */
2701 last_offset = debug_information [i].range_lists [0];
2703 seen_first_offset = 1;
2709 for (; j < num; j++)
2712 debug_information [i].range_lists [j])
2717 last_offset = debug_information [i].range_lists [j];
2722 if (!use_debug_info)
2723 /* FIXME: Should we handle this case? */
2724 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
2726 if (!seen_first_offset)
2727 error (_("No range lists in .debug_info section!\n"));
2729 if (debug_information [first].range_lists [0] != 0)
2730 warn (_("Range lists in %s section start at 0x%lx\n"),
2731 section->name, debug_information [first].range_lists [0]);
2733 printf (_("Contents of the %s section:\n\n"), section->name);
2734 printf (_(" Offset Begin End\n"));
2736 seen_first_offset = 0;
2737 for (i = first; i < num_debug_info_entries; i++)
2739 unsigned long begin;
2741 unsigned long offset;
2742 unsigned int pointer_size;
2743 unsigned long base_address;
2745 pointer_size = debug_information [i].pointer_size;
2747 for (j = 0; j < debug_information [i].num_range_lists; j++)
2749 offset = debug_information [i].range_lists [j];
2750 next = section_begin + offset;
2751 base_address = debug_information [i].base_address;
2753 if (!seen_first_offset)
2754 seen_first_offset = 1;
2758 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
2759 (long)(start - section_begin),
2760 (long)(next - section_begin), section->name);
2761 else if (start > next)
2762 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
2763 (long)(start - section_begin),
2764 (long)(next - section_begin), section->name);
2770 begin = byte_get (start, pointer_size);
2771 start += pointer_size;
2772 end = byte_get (start, pointer_size);
2773 start += pointer_size;
2775 if (begin == 0 && end == 0)
2777 printf (_(" %8.8lx <End of list>\n"), offset);
2781 /* Check base address specifiers. */
2782 if (begin == -1UL && end != -1UL)
2785 printf (" %8.8lx %8.8lx %8.8lx (base address)\n",
2786 offset, begin, end);
2790 printf (" %8.8lx %8.8lx %8.8lx",
2791 offset, begin + base_address, end + base_address);
2794 fputs (_(" (start == end)"), stdout);
2795 else if (begin > end)
2796 fputs (_(" (start > end)"), stdout);
2806 typedef struct Frame_Chunk
2808 struct Frame_Chunk *next;
2809 unsigned char *chunk_start;
2811 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
2812 short int *col_type;
2815 unsigned int code_factor;
2817 unsigned long pc_begin;
2818 unsigned long pc_range;
2822 unsigned char fde_encoding;
2823 unsigned char cfa_exp;
2827 /* A marker for a col_type that means this column was never referenced
2828 in the frame info. */
2829 #define DW_CFA_unreferenced (-1)
2832 frame_need_space (Frame_Chunk *fc, int reg)
2834 int prev = fc->ncols;
2836 if (reg < fc->ncols)
2839 fc->ncols = reg + 1;
2840 fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int));
2841 fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
2843 while (prev < fc->ncols)
2845 fc->col_type[prev] = DW_CFA_unreferenced;
2846 fc->col_offset[prev] = 0;
2852 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
2857 if (*max_regs < fc->ncols)
2858 *max_regs = fc->ncols;
2860 if (*need_col_headers)
2862 *need_col_headers = 0;
2864 printf (" LOC CFA ");
2866 for (r = 0; r < *max_regs; r++)
2867 if (fc->col_type[r] != DW_CFA_unreferenced)
2872 printf ("r%-4d", r);
2878 printf ("%08lx ", fc->pc_begin);
2880 strcpy (tmp, "exp");
2882 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
2883 printf ("%-8s ", tmp);
2885 for (r = 0; r < fc->ncols; r++)
2887 if (fc->col_type[r] != DW_CFA_unreferenced)
2889 switch (fc->col_type[r])
2891 case DW_CFA_undefined:
2894 case DW_CFA_same_value:
2898 sprintf (tmp, "c%+d", fc->col_offset[r]);
2900 case DW_CFA_register:
2901 sprintf (tmp, "r%d", fc->col_offset[r]);
2903 case DW_CFA_expression:
2904 strcpy (tmp, "exp");
2907 strcpy (tmp, "n/a");
2910 printf ("%-5s", tmp);
2917 size_of_encoded_value (int encoding)
2919 switch (encoding & 0x7)
2922 case 0: return eh_addr_size;
2930 get_encoded_value (unsigned char *data, int encoding)
2932 int size = size_of_encoded_value (encoding);
2933 if (encoding & DW_EH_PE_signed)
2934 return byte_get_signed (data, size);
2936 return byte_get (data, size);
2939 #define GET(N) byte_get (start, N); start += N
2940 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
2941 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
2944 display_debug_frames (struct dwarf_section *section,
2945 void *file ATTRIBUTE_UNUSED)
2947 unsigned char *start = section->start;
2948 unsigned char *end = start + section->size;
2949 unsigned char *section_start = start;
2950 Frame_Chunk *chunks = 0;
2951 Frame_Chunk *remembered_state = 0;
2953 int is_eh = strcmp (section->name, ".eh_frame") == 0;
2954 unsigned int length_return;
2957 printf (_("The section %s contains:\n"), section->name);
2961 unsigned char *saved_start;
2962 unsigned char *block_end;
2963 unsigned long length;
2964 unsigned long cie_id;
2967 int need_col_headers = 1;
2968 unsigned char *augmentation_data = NULL;
2969 unsigned long augmentation_data_len = 0;
2970 int encoded_ptr_size = eh_addr_size;
2972 int initial_length_size;
2974 saved_start = start;
2975 length = byte_get (start, 4); start += 4;
2979 printf ("\n%08lx ZERO terminator\n\n",
2980 (unsigned long)(saved_start - section_start));
2984 if (length == 0xffffffff)
2986 length = byte_get (start, 8);
2989 initial_length_size = 12;
2994 initial_length_size = 4;
2997 block_end = saved_start + length + initial_length_size;
2998 cie_id = byte_get (start, offset_size); start += offset_size;
3000 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
3004 fc = xmalloc (sizeof (Frame_Chunk));
3005 memset (fc, 0, sizeof (Frame_Chunk));
3009 fc->chunk_start = saved_start;
3011 fc->col_type = xmalloc (sizeof (short int));
3012 fc->col_offset = xmalloc (sizeof (int));
3013 frame_need_space (fc, max_regs-1);
3017 fc->augmentation = (char *) start;
3018 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
3020 if (fc->augmentation[0] == 'z')
3022 fc->code_factor = LEB ();
3023 fc->data_factor = SLEB ();
3032 augmentation_data_len = LEB ();
3033 augmentation_data = start;
3034 start += augmentation_data_len;
3036 else if (strcmp (fc->augmentation, "eh") == 0)
3038 start += eh_addr_size;
3039 fc->code_factor = LEB ();
3040 fc->data_factor = SLEB ();
3052 fc->code_factor = LEB ();
3053 fc->data_factor = SLEB ();
3065 if (do_debug_frames_interp)
3066 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3067 (unsigned long)(saved_start - section_start), length, cie_id,
3068 fc->augmentation, fc->code_factor, fc->data_factor,
3072 printf ("\n%08lx %08lx %08lx CIE\n",
3073 (unsigned long)(saved_start - section_start), length, cie_id);
3074 printf (" Version: %d\n", version);
3075 printf (" Augmentation: \"%s\"\n", fc->augmentation);
3076 printf (" Code alignment factor: %u\n", fc->code_factor);
3077 printf (" Data alignment factor: %d\n", fc->data_factor);
3078 printf (" Return address column: %d\n", fc->ra);
3080 if (augmentation_data_len)
3083 printf (" Augmentation data: ");
3084 for (i = 0; i < augmentation_data_len; ++i)
3085 printf (" %02x", augmentation_data[i]);
3091 if (augmentation_data_len)
3093 unsigned char *p, *q;
3094 p = (unsigned char *) fc->augmentation + 1;
3095 q = augmentation_data;
3102 q += 1 + size_of_encoded_value (*q);
3104 fc->fde_encoding = *q++;
3110 if (fc->fde_encoding)
3111 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3114 frame_need_space (fc, fc->ra);
3118 unsigned char *look_for;
3119 static Frame_Chunk fde_fc;
3122 memset (fc, 0, sizeof (Frame_Chunk));
3124 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
3126 for (cie = chunks; cie ; cie = cie->next)
3127 if (cie->chunk_start == look_for)
3132 warn ("Invalid CIE pointer %08lx in FDE at %p\n",
3133 cie_id, saved_start);
3136 fc->col_type = xmalloc (sizeof (short int));
3137 fc->col_offset = xmalloc (sizeof (int));
3138 frame_need_space (fc, max_regs - 1);
3140 fc->augmentation = "";
3141 fc->fde_encoding = 0;
3145 fc->ncols = cie->ncols;
3146 fc->col_type = xcmalloc (fc->ncols, sizeof (short int));
3147 fc->col_offset = xcmalloc (fc->ncols, sizeof (int));
3148 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
3149 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
3150 fc->augmentation = cie->augmentation;
3151 fc->code_factor = cie->code_factor;
3152 fc->data_factor = cie->data_factor;
3153 fc->cfa_reg = cie->cfa_reg;
3154 fc->cfa_offset = cie->cfa_offset;
3156 frame_need_space (fc, max_regs-1);
3157 fc->fde_encoding = cie->fde_encoding;
3160 if (fc->fde_encoding)
3161 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3163 fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
3164 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel
3165 /* Don't adjust for relocatable file since there's
3166 invariably a pcrel reloc here, which we haven't
3169 fc->pc_begin += section->address + (start - section_start);
3170 start += encoded_ptr_size;
3171 fc->pc_range = byte_get (start, encoded_ptr_size);
3172 start += encoded_ptr_size;
3174 if (cie->augmentation[0] == 'z')
3176 augmentation_data_len = LEB ();
3177 augmentation_data = start;
3178 start += augmentation_data_len;
3181 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
3182 (unsigned long)(saved_start - section_start), length, cie_id,
3183 (unsigned long)(cie->chunk_start - section_start),
3184 fc->pc_begin, fc->pc_begin + fc->pc_range);
3185 if (! do_debug_frames_interp && augmentation_data_len)
3189 printf (" Augmentation data: ");
3190 for (i = 0; i < augmentation_data_len; ++i)
3191 printf (" %02x", augmentation_data[i]);
3197 /* At this point, fc is the current chunk, cie (if any) is set, and
3198 we're about to interpret instructions for the chunk. */
3199 /* ??? At present we need to do this always, since this sizes the
3200 fc->col_type and fc->col_offset arrays, which we write into always.
3201 We should probably split the interpreted and non-interpreted bits
3202 into two different routines, since there's so much that doesn't
3203 really overlap between them. */
3204 if (1 || do_debug_frames_interp)
3206 /* Start by making a pass over the chunk, allocating storage
3207 and taking note of what registers are used. */
3208 unsigned char *tmp = start;
3210 while (start < block_end)
3213 unsigned long reg, tmp;
3220 /* Warning: if you add any more cases to this switch, be
3221 sure to add them to the corresponding switch below. */
3224 case DW_CFA_advance_loc:
3228 frame_need_space (fc, opa);
3229 fc->col_type[opa] = DW_CFA_undefined;
3231 case DW_CFA_restore:
3232 frame_need_space (fc, opa);
3233 fc->col_type[opa] = DW_CFA_undefined;
3235 case DW_CFA_set_loc:
3236 start += encoded_ptr_size;
3238 case DW_CFA_advance_loc1:
3241 case DW_CFA_advance_loc2:
3244 case DW_CFA_advance_loc4:
3247 case DW_CFA_offset_extended:
3248 reg = LEB (); LEB ();
3249 frame_need_space (fc, reg);
3250 fc->col_type[reg] = DW_CFA_undefined;
3252 case DW_CFA_restore_extended:
3254 frame_need_space (fc, reg);
3255 fc->col_type[reg] = DW_CFA_undefined;
3257 case DW_CFA_undefined:
3259 frame_need_space (fc, reg);
3260 fc->col_type[reg] = DW_CFA_undefined;
3262 case DW_CFA_same_value:
3264 frame_need_space (fc, reg);
3265 fc->col_type[reg] = DW_CFA_undefined;
3267 case DW_CFA_register:
3268 reg = LEB (); LEB ();
3269 frame_need_space (fc, reg);
3270 fc->col_type[reg] = DW_CFA_undefined;
3272 case DW_CFA_def_cfa:
3275 case DW_CFA_def_cfa_register:
3278 case DW_CFA_def_cfa_offset:
3281 case DW_CFA_def_cfa_expression:
3285 case DW_CFA_expression:
3289 frame_need_space (fc, reg);
3290 fc->col_type[reg] = DW_CFA_undefined;
3292 case DW_CFA_offset_extended_sf:
3293 reg = LEB (); SLEB ();
3294 frame_need_space (fc, reg);
3295 fc->col_type[reg] = DW_CFA_undefined;
3297 case DW_CFA_def_cfa_sf:
3300 case DW_CFA_def_cfa_offset_sf:
3303 case DW_CFA_MIPS_advance_loc8:
3306 case DW_CFA_GNU_args_size:
3309 case DW_CFA_GNU_negative_offset_extended:
3310 reg = LEB (); LEB ();
3311 frame_need_space (fc, reg);
3312 fc->col_type[reg] = DW_CFA_undefined;
3321 /* Now we know what registers are used, make a second pass over
3322 the chunk, this time actually printing out the info. */
3324 while (start < block_end)
3327 unsigned long ul, reg, roffs;
3336 /* Warning: if you add any more cases to this switch, be
3337 sure to add them to the corresponding switch above. */
3340 case DW_CFA_advance_loc:
3341 if (do_debug_frames_interp)
3342 frame_display_row (fc, &need_col_headers, &max_regs);
3344 printf (" DW_CFA_advance_loc: %d to %08lx\n",
3345 opa * fc->code_factor,
3346 fc->pc_begin + opa * fc->code_factor);
3347 fc->pc_begin += opa * fc->code_factor;
3352 if (! do_debug_frames_interp)
3353 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
3354 opa, roffs * fc->data_factor);
3355 fc->col_type[opa] = DW_CFA_offset;
3356 fc->col_offset[opa] = roffs * fc->data_factor;
3359 case DW_CFA_restore:
3360 if (! do_debug_frames_interp)
3361 printf (" DW_CFA_restore: r%d\n", opa);
3362 fc->col_type[opa] = cie->col_type[opa];
3363 fc->col_offset[opa] = cie->col_offset[opa];
3366 case DW_CFA_set_loc:
3367 vma = get_encoded_value (start, fc->fde_encoding);
3368 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel
3370 vma += section->address + (start - section_start);
3371 start += encoded_ptr_size;
3372 if (do_debug_frames_interp)
3373 frame_display_row (fc, &need_col_headers, &max_regs);
3375 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
3379 case DW_CFA_advance_loc1:
3380 ofs = byte_get (start, 1); start += 1;
3381 if (do_debug_frames_interp)
3382 frame_display_row (fc, &need_col_headers, &max_regs);
3384 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
3385 ofs * fc->code_factor,
3386 fc->pc_begin + ofs * fc->code_factor);
3387 fc->pc_begin += ofs * fc->code_factor;
3390 case DW_CFA_advance_loc2:
3391 ofs = byte_get (start, 2); start += 2;
3392 if (do_debug_frames_interp)
3393 frame_display_row (fc, &need_col_headers, &max_regs);
3395 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
3396 ofs * fc->code_factor,
3397 fc->pc_begin + ofs * fc->code_factor);
3398 fc->pc_begin += ofs * fc->code_factor;
3401 case DW_CFA_advance_loc4:
3402 ofs = byte_get (start, 4); start += 4;
3403 if (do_debug_frames_interp)
3404 frame_display_row (fc, &need_col_headers, &max_regs);
3406 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
3407 ofs * fc->code_factor,
3408 fc->pc_begin + ofs * fc->code_factor);
3409 fc->pc_begin += ofs * fc->code_factor;
3412 case DW_CFA_offset_extended:
3415 if (! do_debug_frames_interp)
3416 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
3417 reg, roffs * fc->data_factor);
3418 fc->col_type[reg] = DW_CFA_offset;
3419 fc->col_offset[reg] = roffs * fc->data_factor;
3422 case DW_CFA_restore_extended:
3424 if (! do_debug_frames_interp)
3425 printf (" DW_CFA_restore_extended: r%ld\n", reg);
3426 fc->col_type[reg] = cie->col_type[reg];
3427 fc->col_offset[reg] = cie->col_offset[reg];
3430 case DW_CFA_undefined:
3432 if (! do_debug_frames_interp)
3433 printf (" DW_CFA_undefined: r%ld\n", reg);
3434 fc->col_type[reg] = DW_CFA_undefined;
3435 fc->col_offset[reg] = 0;
3438 case DW_CFA_same_value:
3440 if (! do_debug_frames_interp)
3441 printf (" DW_CFA_same_value: r%ld\n", reg);
3442 fc->col_type[reg] = DW_CFA_same_value;
3443 fc->col_offset[reg] = 0;
3446 case DW_CFA_register:
3449 if (! do_debug_frames_interp)
3450 printf (" DW_CFA_register: r%ld in r%ld\n", reg, roffs);
3451 fc->col_type[reg] = DW_CFA_register;
3452 fc->col_offset[reg] = roffs;
3455 case DW_CFA_remember_state:
3456 if (! do_debug_frames_interp)
3457 printf (" DW_CFA_remember_state\n");
3458 rs = xmalloc (sizeof (Frame_Chunk));
3459 rs->ncols = fc->ncols;
3460 rs->col_type = xcmalloc (rs->ncols, sizeof (short int));
3461 rs->col_offset = xcmalloc (rs->ncols, sizeof (int));
3462 memcpy (rs->col_type, fc->col_type, rs->ncols);
3463 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
3464 rs->next = remembered_state;
3465 remembered_state = rs;
3468 case DW_CFA_restore_state:
3469 if (! do_debug_frames_interp)
3470 printf (" DW_CFA_restore_state\n");
3471 rs = remembered_state;
3474 remembered_state = rs->next;
3475 frame_need_space (fc, rs->ncols-1);
3476 memcpy (fc->col_type, rs->col_type, rs->ncols);
3477 memcpy (fc->col_offset, rs->col_offset,
3478 rs->ncols * sizeof (int));
3479 free (rs->col_type);
3480 free (rs->col_offset);
3483 else if (do_debug_frames_interp)
3484 printf ("Mismatched DW_CFA_restore_state\n");
3487 case DW_CFA_def_cfa:
3488 fc->cfa_reg = LEB ();
3489 fc->cfa_offset = LEB ();
3491 if (! do_debug_frames_interp)
3492 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
3493 fc->cfa_reg, fc->cfa_offset);
3496 case DW_CFA_def_cfa_register:
3497 fc->cfa_reg = LEB ();
3499 if (! do_debug_frames_interp)
3500 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
3503 case DW_CFA_def_cfa_offset:
3504 fc->cfa_offset = LEB ();
3505 if (! do_debug_frames_interp)
3506 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
3510 if (! do_debug_frames_interp)
3511 printf (" DW_CFA_nop\n");
3514 case DW_CFA_def_cfa_expression:
3516 if (! do_debug_frames_interp)
3518 printf (" DW_CFA_def_cfa_expression (");
3519 decode_location_expression (start, eh_addr_size, ul, 0);
3526 case DW_CFA_expression:
3529 if (! do_debug_frames_interp)
3531 printf (" DW_CFA_expression: r%ld (", reg);
3532 decode_location_expression (start, eh_addr_size, ul, 0);
3535 fc->col_type[reg] = DW_CFA_expression;
3539 case DW_CFA_offset_extended_sf:
3542 frame_need_space (fc, reg);
3543 if (! do_debug_frames_interp)
3544 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
3545 reg, l * fc->data_factor);
3546 fc->col_type[reg] = DW_CFA_offset;
3547 fc->col_offset[reg] = l * fc->data_factor;
3550 case DW_CFA_def_cfa_sf:
3551 fc->cfa_reg = LEB ();
3552 fc->cfa_offset = SLEB ();
3553 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3555 if (! do_debug_frames_interp)
3556 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
3557 fc->cfa_reg, fc->cfa_offset);
3560 case DW_CFA_def_cfa_offset_sf:
3561 fc->cfa_offset = SLEB ();
3562 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3563 if (! do_debug_frames_interp)
3564 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
3567 case DW_CFA_MIPS_advance_loc8:
3568 ofs = byte_get (start, 8); start += 8;
3569 if (do_debug_frames_interp)
3570 frame_display_row (fc, &need_col_headers, &max_regs);
3572 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
3573 ofs * fc->code_factor,
3574 fc->pc_begin + ofs * fc->code_factor);
3575 fc->pc_begin += ofs * fc->code_factor;
3578 case DW_CFA_GNU_window_save:
3579 if (! do_debug_frames_interp)
3580 printf (" DW_CFA_GNU_window_save\n");
3583 case DW_CFA_GNU_args_size:
3585 if (! do_debug_frames_interp)
3586 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
3589 case DW_CFA_GNU_negative_offset_extended:
3592 frame_need_space (fc, reg);
3593 if (! do_debug_frames_interp)
3594 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
3595 reg, l * fc->data_factor);
3596 fc->col_type[reg] = DW_CFA_offset;
3597 fc->col_offset[reg] = l * fc->data_factor;
3601 warn (_("unsupported or unknown DW_CFA_%d\n"), op);
3606 if (do_debug_frames_interp)
3607 frame_display_row (fc, &need_col_headers, &max_regs);
3622 display_debug_not_supported (struct dwarf_section *section,
3623 void *file ATTRIBUTE_UNUSED)
3625 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
3632 cmalloc (size_t nmemb, size_t size)
3634 /* Check for overflow. */
3635 if (nmemb >= ~(size_t) 0 / size)
3638 return malloc (nmemb * size);
3642 xcmalloc (size_t nmemb, size_t size)
3644 /* Check for overflow. */
3645 if (nmemb >= ~(size_t) 0 / size)
3648 return xmalloc (nmemb * size);
3652 xcrealloc (void *ptr, size_t nmemb, size_t size)
3654 /* Check for overflow. */
3655 if (nmemb >= ~(size_t) 0 / size)
3658 return xrealloc (ptr, nmemb * size);
3662 error (const char *message, ...)
3666 va_start (args, message);
3667 fprintf (stderr, _("%s: Error: "), program_name);
3668 vfprintf (stderr, message, args);
3673 warn (const char *message, ...)
3677 va_start (args, message);
3678 fprintf (stderr, _("%s: Warning: "), program_name);
3679 vfprintf (stderr, message, args);
3684 free_debug_memory (void)
3686 enum dwarf_section_display_enum i;
3690 for (i = 0; i < max; i++)
3691 free_debug_section (i);
3693 if (debug_information)
3695 for (i = 0; i < num_debug_info_entries; i++)
3697 if (!debug_information [i].max_loc_offsets)
3699 free (debug_information [i].loc_offsets);
3700 free (debug_information [i].have_frame_base);
3702 if (!debug_information [i].max_range_lists)
3703 free (debug_information [i].range_lists);
3705 free (debug_information);
3706 debug_information = NULL;
3707 num_debug_info_entries = 0;
3712 struct dwarf_section_display debug_displays[] =
3714 { { ".debug_abbrev", NULL, 0, 0 },
3715 display_debug_abbrev, 0, 0 },
3716 { { ".debug_aranges", NULL, 0, 0 },
3717 display_debug_aranges, 0, 0 },
3718 { { ".debug_frame", NULL, 0, 0 },
3719 display_debug_frames, 1, 0 },
3720 { { ".debug_info", NULL, 0, 0 },
3721 display_debug_info, 1, 0 },
3722 { { ".debug_line", NULL, 0, 0 },
3723 display_debug_lines, 0, 0 },
3724 { { ".debug_pubnames", NULL, 0, 0 },
3725 display_debug_pubnames, 0, 0 },
3726 { { ".eh_frame", NULL, 0, 0 },
3727 display_debug_frames, 1, 1 },
3728 { { ".debug_macinfo", NULL, 0, 0 },
3729 display_debug_macinfo, 0, 0 },
3730 { { ".debug_str", NULL, 0, 0 },
3731 display_debug_str, 0, 0 },
3732 { { ".debug_loc", NULL, 0, 0 },
3733 display_debug_loc, 0, 0 },
3734 { { ".debug_pubtypes", NULL, 0, 0 },
3735 display_debug_pubnames, 0, 0 },
3736 { { ".debug_ranges", NULL, 0, 0 },
3737 display_debug_ranges, 0, 0 },
3738 { { ".debug_static_func", NULL, 0, 0 },
3739 display_debug_not_supported, 0, 0 },
3740 { { ".debug_static_vars", NULL, 0, 0 },
3741 display_debug_not_supported, 0, 0 },
3742 { { ".debug_types", NULL, 0, 0 },
3743 display_debug_not_supported, 0, 0 },
3744 { { ".debug_weaknames", NULL, 0, 0 },
3745 display_debug_not_supported, 0, 0 }