1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
26 #include "elf/common.h"
27 #include "elf/dwarf2.h"
30 static int have_frame_base;
31 static int need_base_address;
33 static unsigned int last_pointer_size = 0;
34 static int warned_about_missing_comp_units = FALSE;
36 static unsigned int num_debug_info_entries = 0;
37 static debug_info *debug_information = NULL;
38 /* Special value for num_debug_info_entries to indicate
39 that the .debug_info section could not be loaded/parsed. */
40 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 int do_debug_pubnames;
51 int do_debug_frames_interp;
56 dwarf_vma (*byte_get) (unsigned char *, int);
59 byte_get_little_endian (unsigned char *field, int size)
67 return ((unsigned int) (field[0]))
68 | (((unsigned int) (field[1])) << 8);
71 return ((unsigned long) (field[0]))
72 | (((unsigned long) (field[1])) << 8)
73 | (((unsigned long) (field[2])) << 16)
74 | (((unsigned long) (field[3])) << 24);
77 if (sizeof (dwarf_vma) == 8)
78 return ((dwarf_vma) (field[0]))
79 | (((dwarf_vma) (field[1])) << 8)
80 | (((dwarf_vma) (field[2])) << 16)
81 | (((dwarf_vma) (field[3])) << 24)
82 | (((dwarf_vma) (field[4])) << 32)
83 | (((dwarf_vma) (field[5])) << 40)
84 | (((dwarf_vma) (field[6])) << 48)
85 | (((dwarf_vma) (field[7])) << 56);
86 else if (sizeof (dwarf_vma) == 4)
87 /* We want to extract data from an 8 byte wide field and
88 place it into a 4 byte wide field. Since this is a little
89 endian source we can just use the 4 byte extraction code. */
90 return ((unsigned long) (field[0]))
91 | (((unsigned long) (field[1])) << 8)
92 | (((unsigned long) (field[2])) << 16)
93 | (((unsigned long) (field[3])) << 24);
96 error (_("Unhandled data length: %d\n"), size);
102 byte_get_big_endian (unsigned char *field, int size)
110 return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
113 return ((unsigned long) (field[3]))
114 | (((unsigned long) (field[2])) << 8)
115 | (((unsigned long) (field[1])) << 16)
116 | (((unsigned long) (field[0])) << 24);
119 if (sizeof (dwarf_vma) == 8)
120 return ((dwarf_vma) (field[7]))
121 | (((dwarf_vma) (field[6])) << 8)
122 | (((dwarf_vma) (field[5])) << 16)
123 | (((dwarf_vma) (field[4])) << 24)
124 | (((dwarf_vma) (field[3])) << 32)
125 | (((dwarf_vma) (field[2])) << 40)
126 | (((dwarf_vma) (field[1])) << 48)
127 | (((dwarf_vma) (field[0])) << 56);
128 else if (sizeof (dwarf_vma) == 4)
130 /* Although we are extracing data from an 8 byte wide field,
131 we are returning only 4 bytes of data. */
133 return ((unsigned long) (field[3]))
134 | (((unsigned long) (field[2])) << 8)
135 | (((unsigned long) (field[1])) << 16)
136 | (((unsigned long) (field[0])) << 24);
140 error (_("Unhandled data length: %d\n"), size);
146 byte_get_signed (unsigned char *field, int size)
148 dwarf_vma x = byte_get (field, size);
153 return (x ^ 0x80) - 0x80;
155 return (x ^ 0x8000) - 0x8000;
157 return (x ^ 0x80000000) - 0x80000000;
165 static unsigned long int
166 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
168 unsigned long int result = 0;
169 unsigned int num_read = 0;
170 unsigned int shift = 0;
178 result |= ((unsigned long int) (byte & 0x7f)) << shift;
185 if (length_return != NULL)
186 *length_return = num_read;
188 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
189 result |= -1L << shift;
194 typedef struct State_Machine_Registers
196 unsigned long address;
203 /* This variable hold the number of the last entry seen
204 in the File Table. */
205 unsigned int last_file_entry;
208 static SMR state_machine_regs;
211 reset_state_machine (int is_stmt)
213 state_machine_regs.address = 0;
214 state_machine_regs.file = 1;
215 state_machine_regs.line = 1;
216 state_machine_regs.column = 0;
217 state_machine_regs.is_stmt = is_stmt;
218 state_machine_regs.basic_block = 0;
219 state_machine_regs.end_sequence = 0;
220 state_machine_regs.last_file_entry = 0;
223 /* Handled an extend line op.
224 Returns the number of bytes read. */
227 process_extended_line_op (unsigned char *data, int is_stmt)
229 unsigned char op_code;
230 unsigned int bytes_read;
235 len = read_leb128 (data, & bytes_read, 0);
240 warn (_("badly formed extended line op encountered!\n"));
247 printf (_(" Extended opcode %d: "), op_code);
251 case DW_LNE_end_sequence:
252 printf (_("End of Sequence\n\n"));
253 reset_state_machine (is_stmt);
256 case DW_LNE_set_address:
257 adr = byte_get (data, len - bytes_read - 1);
258 printf (_("set Address to 0x%lx\n"), adr);
259 state_machine_regs.address = adr;
262 case DW_LNE_define_file:
263 printf (_(" define new File Table entry\n"));
264 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
266 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
268 data += strlen ((char *) data) + 1;
269 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
271 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
273 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
274 printf (_("%s\n\n"), name);
278 case DW_LNE_HP_negate_is_UV_update:
279 printf ("DW_LNE_HP_negate_is_UV_update");
281 case DW_LNE_HP_push_context:
282 printf ("DW_LNE_HP_push_context");
284 case DW_LNE_HP_pop_context:
285 printf ("DW_LNE_HP_pop_context");
287 case DW_LNE_HP_set_file_line_column:
288 printf ("DW_LNE_HP_set_file_line_column");
290 case DW_LNE_HP_set_routine_name:
291 printf ("DW_LNE_HP_set_routine_name");
293 case DW_LNE_HP_set_sequence:
294 printf ("DW_LNE_HP_set_sequence");
296 case DW_LNE_HP_negate_post_semantics:
297 printf ("DW_LNE_HP_negate_post_semantics");
299 case DW_LNE_HP_negate_function_exit:
300 printf ("DW_LNE_HP_negate_function_exit");
302 case DW_LNE_HP_negate_front_end_logical:
303 printf ("DW_LNE_HP_negate_front_end_logical");
305 case DW_LNE_HP_define_proc:
306 printf ("DW_LNE_HP_define_proc");
310 if (op_code >= DW_LNE_lo_user
311 /* The test against DW_LNW_hi_user is redundant due to
312 the limited range of the unsigned char data type used
314 /*&& op_code <= DW_LNE_hi_user*/)
315 printf (_("user defined: length %d\n"), len - bytes_read);
317 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
325 fetch_indirect_string (unsigned long offset)
327 struct dwarf_section *section = &debug_displays [str].section;
329 if (section->start == NULL)
330 return _("<no .debug_str section>");
332 /* DWARF sections under Mach-O have non-zero addresses. */
333 offset -= section->address;
334 if (offset > section->size)
336 warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
337 return _("<offset is too big>");
340 return (const char *) section->start + offset;
343 /* FIXME: There are better and more efficient ways to handle
344 these structures. For now though, I just want something that
345 is simple to implement. */
346 typedef struct abbrev_attr
348 unsigned long attribute;
350 struct abbrev_attr *next;
354 typedef struct abbrev_entry
359 struct abbrev_attr *first_attr;
360 struct abbrev_attr *last_attr;
361 struct abbrev_entry *next;
365 static abbrev_entry *first_abbrev = NULL;
366 static abbrev_entry *last_abbrev = NULL;
371 abbrev_entry *abbrev;
373 for (abbrev = first_abbrev; abbrev;)
375 abbrev_entry *next = abbrev->next;
378 for (attr = abbrev->first_attr; attr;)
380 abbrev_attr *next = attr->next;
390 last_abbrev = first_abbrev = NULL;
394 add_abbrev (unsigned long number, unsigned long tag, int children)
398 entry = malloc (sizeof (*entry));
404 entry->entry = number;
406 entry->children = children;
407 entry->first_attr = NULL;
408 entry->last_attr = NULL;
411 if (first_abbrev == NULL)
412 first_abbrev = entry;
414 last_abbrev->next = entry;
420 add_abbrev_attr (unsigned long attribute, unsigned long form)
424 attr = malloc (sizeof (*attr));
430 attr->attribute = attribute;
434 if (last_abbrev->first_attr == NULL)
435 last_abbrev->first_attr = attr;
437 last_abbrev->last_attr->next = attr;
439 last_abbrev->last_attr = attr;
442 /* Processes the (partial) contents of a .debug_abbrev section.
443 Returns NULL if the end of the section was encountered.
444 Returns the address after the last byte read if the end of
445 an abbreviation set was found. */
447 static unsigned char *
448 process_abbrev_section (unsigned char *start, unsigned char *end)
450 if (first_abbrev != NULL)
455 unsigned int bytes_read;
458 unsigned long attribute;
461 entry = read_leb128 (start, & bytes_read, 0);
464 /* A single zero is supposed to end the section according
465 to the standard. If there's more, then signal that to
468 return start == end ? NULL : start;
470 tag = read_leb128 (start, & bytes_read, 0);
475 add_abbrev (entry, tag, children);
481 attribute = read_leb128 (start, & bytes_read, 0);
484 form = read_leb128 (start, & bytes_read, 0);
488 add_abbrev_attr (attribute, form);
490 while (attribute != 0);
497 get_TAG_name (unsigned long tag)
501 case DW_TAG_padding: return "DW_TAG_padding";
502 case DW_TAG_array_type: return "DW_TAG_array_type";
503 case DW_TAG_class_type: return "DW_TAG_class_type";
504 case DW_TAG_entry_point: return "DW_TAG_entry_point";
505 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
506 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
507 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
508 case DW_TAG_label: return "DW_TAG_label";
509 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
510 case DW_TAG_member: return "DW_TAG_member";
511 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
512 case DW_TAG_reference_type: return "DW_TAG_reference_type";
513 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
514 case DW_TAG_string_type: return "DW_TAG_string_type";
515 case DW_TAG_structure_type: return "DW_TAG_structure_type";
516 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
517 case DW_TAG_typedef: return "DW_TAG_typedef";
518 case DW_TAG_union_type: return "DW_TAG_union_type";
519 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
520 case DW_TAG_variant: return "DW_TAG_variant";
521 case DW_TAG_common_block: return "DW_TAG_common_block";
522 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
523 case DW_TAG_inheritance: return "DW_TAG_inheritance";
524 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
525 case DW_TAG_module: return "DW_TAG_module";
526 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
527 case DW_TAG_set_type: return "DW_TAG_set_type";
528 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
529 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
530 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
531 case DW_TAG_base_type: return "DW_TAG_base_type";
532 case DW_TAG_catch_block: return "DW_TAG_catch_block";
533 case DW_TAG_const_type: return "DW_TAG_const_type";
534 case DW_TAG_constant: return "DW_TAG_constant";
535 case DW_TAG_enumerator: return "DW_TAG_enumerator";
536 case DW_TAG_file_type: return "DW_TAG_file_type";
537 case DW_TAG_friend: return "DW_TAG_friend";
538 case DW_TAG_namelist: return "DW_TAG_namelist";
539 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
540 case DW_TAG_packed_type: return "DW_TAG_packed_type";
541 case DW_TAG_subprogram: return "DW_TAG_subprogram";
542 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
543 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
544 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
545 case DW_TAG_try_block: return "DW_TAG_try_block";
546 case DW_TAG_variant_part: return "DW_TAG_variant_part";
547 case DW_TAG_variable: return "DW_TAG_variable";
548 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
549 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
550 case DW_TAG_format_label: return "DW_TAG_format_label";
551 case DW_TAG_function_template: return "DW_TAG_function_template";
552 case DW_TAG_class_template: return "DW_TAG_class_template";
553 /* DWARF 2.1 values. */
554 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
555 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
556 case DW_TAG_interface_type: return "DW_TAG_interface_type";
557 case DW_TAG_namespace: return "DW_TAG_namespace";
558 case DW_TAG_imported_module: return "DW_TAG_imported_module";
559 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
560 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
561 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
563 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
564 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
565 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
568 static char buffer[100];
570 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
577 get_FORM_name (unsigned long form)
581 case DW_FORM_addr: return "DW_FORM_addr";
582 case DW_FORM_block2: return "DW_FORM_block2";
583 case DW_FORM_block4: return "DW_FORM_block4";
584 case DW_FORM_data2: return "DW_FORM_data2";
585 case DW_FORM_data4: return "DW_FORM_data4";
586 case DW_FORM_data8: return "DW_FORM_data8";
587 case DW_FORM_string: return "DW_FORM_string";
588 case DW_FORM_block: return "DW_FORM_block";
589 case DW_FORM_block1: return "DW_FORM_block1";
590 case DW_FORM_data1: return "DW_FORM_data1";
591 case DW_FORM_flag: return "DW_FORM_flag";
592 case DW_FORM_sdata: return "DW_FORM_sdata";
593 case DW_FORM_strp: return "DW_FORM_strp";
594 case DW_FORM_udata: return "DW_FORM_udata";
595 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
596 case DW_FORM_ref1: return "DW_FORM_ref1";
597 case DW_FORM_ref2: return "DW_FORM_ref2";
598 case DW_FORM_ref4: return "DW_FORM_ref4";
599 case DW_FORM_ref8: return "DW_FORM_ref8";
600 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
601 case DW_FORM_indirect: return "DW_FORM_indirect";
604 static char buffer[100];
606 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
612 static unsigned char *
613 display_block (unsigned char *data, unsigned long length)
615 printf (_(" %lu byte block: "), length);
618 printf ("%lx ", (unsigned long) byte_get (data++, 1));
624 decode_location_expression (unsigned char * data,
625 unsigned int pointer_size,
626 unsigned long length,
627 unsigned long cu_offset)
630 unsigned int bytes_read;
631 unsigned long uvalue;
632 unsigned char *end = data + length;
633 int need_frame_base = 0;
642 printf ("DW_OP_addr: %lx",
643 (unsigned long) byte_get (data, pointer_size));
644 data += pointer_size;
647 printf ("DW_OP_deref");
650 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
653 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
656 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
660 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
664 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
668 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
672 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
673 (unsigned long) byte_get (data + 4, 4));
677 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
678 (long) byte_get (data + 4, 4));
682 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
686 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
690 printf ("DW_OP_dup");
693 printf ("DW_OP_drop");
696 printf ("DW_OP_over");
699 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
702 printf ("DW_OP_swap");
705 printf ("DW_OP_rot");
708 printf ("DW_OP_xderef");
711 printf ("DW_OP_abs");
714 printf ("DW_OP_and");
717 printf ("DW_OP_div");
720 printf ("DW_OP_minus");
723 printf ("DW_OP_mod");
726 printf ("DW_OP_mul");
729 printf ("DW_OP_neg");
732 printf ("DW_OP_not");
738 printf ("DW_OP_plus");
740 case DW_OP_plus_uconst:
741 printf ("DW_OP_plus_uconst: %lu",
742 read_leb128 (data, &bytes_read, 0));
746 printf ("DW_OP_shl");
749 printf ("DW_OP_shr");
752 printf ("DW_OP_shra");
755 printf ("DW_OP_xor");
758 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
780 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
816 printf ("DW_OP_lit%d", op - DW_OP_lit0);
851 printf ("DW_OP_reg%d", op - DW_OP_reg0);
886 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
887 read_leb128 (data, &bytes_read, 1));
892 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
897 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
901 uvalue = read_leb128 (data, &bytes_read, 0);
903 printf ("DW_OP_bregx: %lu %ld", uvalue,
904 read_leb128 (data, &bytes_read, 1));
908 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
911 case DW_OP_deref_size:
912 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
914 case DW_OP_xderef_size:
915 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
918 printf ("DW_OP_nop");
921 /* DWARF 3 extensions. */
922 case DW_OP_push_object_address:
923 printf ("DW_OP_push_object_address");
926 /* XXX: Strictly speaking for 64-bit DWARF3 files
927 this ought to be an 8-byte wide computation. */
928 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset);
932 /* XXX: Strictly speaking for 64-bit DWARF3 files
933 this ought to be an 8-byte wide computation. */
934 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset);
938 /* XXX: Strictly speaking for 64-bit DWARF3 files
939 this ought to be an 8-byte wide computation. */
940 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data, 4) + cu_offset);
943 case DW_OP_form_tls_address:
944 printf ("DW_OP_form_tls_address");
946 case DW_OP_call_frame_cfa:
947 printf ("DW_OP_call_frame_cfa");
949 case DW_OP_bit_piece:
950 printf ("DW_OP_bit_piece: ");
951 printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
953 printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
957 /* GNU extensions. */
958 case DW_OP_GNU_push_tls_address:
959 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
961 case DW_OP_GNU_uninit:
962 printf ("DW_OP_GNU_uninit");
963 /* FIXME: Is there data associated with this OP ? */
967 case DW_OP_HP_is_value:
968 printf ("DW_OP_HP_is_value");
969 /* FIXME: Is there data associated with this OP ? */
971 case DW_OP_HP_fltconst4:
972 printf ("DW_OP_HP_fltconst4");
973 /* FIXME: Is there data associated with this OP ? */
975 case DW_OP_HP_fltconst8:
976 printf ("DW_OP_HP_fltconst8");
977 /* FIXME: Is there data associated with this OP ? */
979 case DW_OP_HP_mod_range:
980 printf ("DW_OP_HP_mod_range");
981 /* FIXME: Is there data associated with this OP ? */
983 case DW_OP_HP_unmod_range:
984 printf ("DW_OP_HP_unmod_range");
985 /* FIXME: Is there data associated with this OP ? */
988 printf ("DW_OP_HP_tls");
989 /* FIXME: Is there data associated with this OP ? */
993 if (op >= DW_OP_lo_user
994 && op <= DW_OP_hi_user)
995 printf (_("(User defined location op)"));
997 printf (_("(Unknown location op)"));
998 /* No way to tell where the next op is, so just bail. */
999 return need_frame_base;
1002 /* Separate the ops. */
1007 return need_frame_base;
1010 static unsigned char *
1011 read_and_display_attr_value (unsigned long attribute,
1013 unsigned char * data,
1014 unsigned long cu_offset,
1015 unsigned long pointer_size,
1016 unsigned long offset_size,
1018 debug_info * debug_info_p,
1020 struct dwarf_section * section)
1022 unsigned long uvalue = 0;
1023 unsigned char *block_start = NULL;
1024 unsigned char * orig_data = data;
1025 unsigned int bytes_read;
1032 case DW_FORM_ref_addr:
1033 if (dwarf_version == 2)
1035 uvalue = byte_get (data, pointer_size);
1036 data += pointer_size;
1038 else if (dwarf_version == 3)
1040 uvalue = byte_get (data, offset_size);
1041 data += offset_size;
1045 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1050 uvalue = byte_get (data, pointer_size);
1051 data += pointer_size;
1055 uvalue = byte_get (data, offset_size);
1056 data += offset_size;
1062 uvalue = byte_get (data++, 1);
1067 uvalue = byte_get (data, 2);
1073 uvalue = byte_get (data, 4);
1078 uvalue = read_leb128 (data, & bytes_read, 1);
1082 case DW_FORM_ref_udata:
1084 uvalue = read_leb128 (data, & bytes_read, 0);
1088 case DW_FORM_indirect:
1089 form = read_leb128 (data, & bytes_read, 0);
1092 printf (" %s", get_FORM_name (form));
1093 return read_and_display_attr_value (attribute, form, data,
1094 cu_offset, pointer_size,
1095 offset_size, dwarf_version,
1096 debug_info_p, do_loc,
1102 case DW_FORM_ref_addr:
1104 printf (" <0x%lx>", uvalue);
1110 case DW_FORM_ref_udata:
1112 printf (" <0x%lx>", uvalue + cu_offset);
1118 printf (" 0x%lx", uvalue);
1127 printf (" %ld", uvalue);
1134 uvalue = byte_get (data, 4);
1135 printf (" 0x%lx", uvalue);
1136 printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
1138 if ((do_loc || do_debug_loc || do_debug_ranges)
1139 && num_debug_info_entries == 0)
1141 if (sizeof (uvalue) == 8)
1142 uvalue = byte_get (data, 8);
1144 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1149 case DW_FORM_string:
1151 printf (" %s", data);
1152 data += strlen ((char *) data) + 1;
1156 uvalue = read_leb128 (data, & bytes_read, 0);
1157 block_start = data + bytes_read;
1159 data = block_start + uvalue;
1161 data = display_block (block_start, uvalue);
1164 case DW_FORM_block1:
1165 uvalue = byte_get (data, 1);
1166 block_start = data + 1;
1168 data = block_start + uvalue;
1170 data = display_block (block_start, uvalue);
1173 case DW_FORM_block2:
1174 uvalue = byte_get (data, 2);
1175 block_start = data + 2;
1177 data = block_start + uvalue;
1179 data = display_block (block_start, uvalue);
1182 case DW_FORM_block4:
1183 uvalue = byte_get (data, 4);
1184 block_start = data + 4;
1186 data = block_start + uvalue;
1188 data = display_block (block_start, uvalue);
1193 printf (_(" (indirect string, offset: 0x%lx): %s"),
1194 uvalue, fetch_indirect_string (uvalue));
1197 case DW_FORM_indirect:
1198 /* Handled above. */
1202 warn (_("Unrecognized form: %lu\n"), form);
1206 if ((do_loc || do_debug_loc || do_debug_ranges)
1207 && num_debug_info_entries == 0)
1211 case DW_AT_frame_base:
1212 have_frame_base = 1;
1213 case DW_AT_location:
1214 case DW_AT_string_length:
1215 case DW_AT_return_addr:
1216 case DW_AT_data_member_location:
1217 case DW_AT_vtable_elem_location:
1219 case DW_AT_static_link:
1220 case DW_AT_use_location:
1221 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1223 /* Process location list. */
1224 unsigned int max = debug_info_p->max_loc_offsets;
1225 unsigned int num = debug_info_p->num_loc_offsets;
1227 if (max == 0 || num >= max)
1230 debug_info_p->loc_offsets
1231 = xcrealloc (debug_info_p->loc_offsets,
1232 max, sizeof (*debug_info_p->loc_offsets));
1233 debug_info_p->have_frame_base
1234 = xcrealloc (debug_info_p->have_frame_base,
1235 max, sizeof (*debug_info_p->have_frame_base));
1236 debug_info_p->max_loc_offsets = max;
1238 debug_info_p->loc_offsets [num] = uvalue;
1239 debug_info_p->have_frame_base [num] = have_frame_base;
1240 debug_info_p->num_loc_offsets++;
1245 if (need_base_address)
1246 debug_info_p->base_address = uvalue;
1250 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1252 /* Process range list. */
1253 unsigned int max = debug_info_p->max_range_lists;
1254 unsigned int num = debug_info_p->num_range_lists;
1256 if (max == 0 || num >= max)
1259 debug_info_p->range_lists
1260 = xcrealloc (debug_info_p->range_lists,
1261 max, sizeof (*debug_info_p->range_lists));
1262 debug_info_p->max_range_lists = max;
1264 debug_info_p->range_lists [num] = uvalue;
1265 debug_info_p->num_range_lists++;
1277 /* For some attributes we can display further information. */
1285 case DW_INL_not_inlined:
1286 printf (_("(not inlined)"));
1288 case DW_INL_inlined:
1289 printf (_("(inlined)"));
1291 case DW_INL_declared_not_inlined:
1292 printf (_("(declared as inline but ignored)"));
1294 case DW_INL_declared_inlined:
1295 printf (_("(declared as inline and inlined)"));
1298 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
1303 case DW_AT_language:
1306 /* Ordered by the numeric value of these constants. */
1307 case DW_LANG_C89: printf ("(ANSI C)"); break;
1308 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1309 case DW_LANG_Ada83: printf ("(Ada)"); break;
1310 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1311 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1312 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1313 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1314 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1315 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1316 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1317 /* DWARF 2.1 values. */
1318 case DW_LANG_Java: printf ("(Java)"); break;
1319 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1320 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1321 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1322 /* DWARF 3 values. */
1323 case DW_LANG_PLI: printf ("(PLI)"); break;
1324 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1325 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1326 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1327 case DW_LANG_D: printf ("(D)"); break;
1328 /* MIPS extension. */
1329 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1330 /* UPC extension. */
1331 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1333 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1334 printf ("(implementation defined: %lx)", uvalue);
1336 printf ("(Unknown: %lx)", uvalue);
1341 case DW_AT_encoding:
1344 case DW_ATE_void: printf ("(void)"); break;
1345 case DW_ATE_address: printf ("(machine address)"); break;
1346 case DW_ATE_boolean: printf ("(boolean)"); break;
1347 case DW_ATE_complex_float: printf ("(complex float)"); break;
1348 case DW_ATE_float: printf ("(float)"); break;
1349 case DW_ATE_signed: printf ("(signed)"); break;
1350 case DW_ATE_signed_char: printf ("(signed char)"); break;
1351 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1352 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1353 /* DWARF 2.1 values: */
1354 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1355 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1356 /* DWARF 3 values: */
1357 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1358 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1359 case DW_ATE_edited: printf ("(edited)"); break;
1360 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1361 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1362 /* HP extensions: */
1363 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1364 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1365 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1366 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1367 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1368 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1369 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1372 if (uvalue >= DW_ATE_lo_user
1373 && uvalue <= DW_ATE_hi_user)
1374 printf ("(user defined type)");
1376 printf ("(unknown type)");
1381 case DW_AT_accessibility:
1384 case DW_ACCESS_public: printf ("(public)"); break;
1385 case DW_ACCESS_protected: printf ("(protected)"); break;
1386 case DW_ACCESS_private: printf ("(private)"); break;
1388 printf ("(unknown accessibility)");
1393 case DW_AT_visibility:
1396 case DW_VIS_local: printf ("(local)"); break;
1397 case DW_VIS_exported: printf ("(exported)"); break;
1398 case DW_VIS_qualified: printf ("(qualified)"); break;
1399 default: printf ("(unknown visibility)"); break;
1403 case DW_AT_virtuality:
1406 case DW_VIRTUALITY_none: printf ("(none)"); break;
1407 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1408 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1409 default: printf ("(unknown virtuality)"); break;
1413 case DW_AT_identifier_case:
1416 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1417 case DW_ID_up_case: printf ("(up_case)"); break;
1418 case DW_ID_down_case: printf ("(down_case)"); break;
1419 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1420 default: printf ("(unknown case)"); break;
1424 case DW_AT_calling_convention:
1427 case DW_CC_normal: printf ("(normal)"); break;
1428 case DW_CC_program: printf ("(program)"); break;
1429 case DW_CC_nocall: printf ("(nocall)"); break;
1431 if (uvalue >= DW_CC_lo_user
1432 && uvalue <= DW_CC_hi_user)
1433 printf ("(user defined)");
1435 printf ("(unknown convention)");
1439 case DW_AT_ordering:
1442 case -1: printf ("(undefined)"); break;
1443 case 0: printf ("(row major)"); break;
1444 case 1: printf ("(column major)"); break;
1448 case DW_AT_frame_base:
1449 have_frame_base = 1;
1450 case DW_AT_location:
1451 case DW_AT_string_length:
1452 case DW_AT_return_addr:
1453 case DW_AT_data_member_location:
1454 case DW_AT_vtable_elem_location:
1456 case DW_AT_static_link:
1457 case DW_AT_use_location:
1458 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1459 printf (_("(location list)"));
1461 case DW_AT_allocated:
1462 case DW_AT_associated:
1463 case DW_AT_data_location:
1465 case DW_AT_upper_bound:
1466 case DW_AT_lower_bound:
1469 int need_frame_base;
1472 need_frame_base = decode_location_expression (block_start,
1477 if (need_frame_base && !have_frame_base)
1478 printf (_(" [without DW_AT_frame_base]"));
1484 if (form == DW_FORM_ref1
1485 || form == DW_FORM_ref2
1486 || form == DW_FORM_ref4)
1487 uvalue += cu_offset;
1489 if (uvalue >= section->size)
1490 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1491 uvalue, (long int)(orig_data - section->start));
1494 unsigned long abbrev_number;
1495 abbrev_entry * entry;
1497 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1499 printf ("[Abbrev Number: %ld", abbrev_number);
1500 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1501 if (entry->entry == abbrev_number)
1504 printf (" (%s)", get_TAG_name (entry->tag));
1518 get_AT_name (unsigned long attribute)
1522 case DW_AT_sibling: return "DW_AT_sibling";
1523 case DW_AT_location: return "DW_AT_location";
1524 case DW_AT_name: return "DW_AT_name";
1525 case DW_AT_ordering: return "DW_AT_ordering";
1526 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1527 case DW_AT_byte_size: return "DW_AT_byte_size";
1528 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1529 case DW_AT_bit_size: return "DW_AT_bit_size";
1530 case DW_AT_element_list: return "DW_AT_element_list";
1531 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1532 case DW_AT_low_pc: return "DW_AT_low_pc";
1533 case DW_AT_high_pc: return "DW_AT_high_pc";
1534 case DW_AT_language: return "DW_AT_language";
1535 case DW_AT_member: return "DW_AT_member";
1536 case DW_AT_discr: return "DW_AT_discr";
1537 case DW_AT_discr_value: return "DW_AT_discr_value";
1538 case DW_AT_visibility: return "DW_AT_visibility";
1539 case DW_AT_import: return "DW_AT_import";
1540 case DW_AT_string_length: return "DW_AT_string_length";
1541 case DW_AT_common_reference: return "DW_AT_common_reference";
1542 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1543 case DW_AT_const_value: return "DW_AT_const_value";
1544 case DW_AT_containing_type: return "DW_AT_containing_type";
1545 case DW_AT_default_value: return "DW_AT_default_value";
1546 case DW_AT_inline: return "DW_AT_inline";
1547 case DW_AT_is_optional: return "DW_AT_is_optional";
1548 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1549 case DW_AT_producer: return "DW_AT_producer";
1550 case DW_AT_prototyped: return "DW_AT_prototyped";
1551 case DW_AT_return_addr: return "DW_AT_return_addr";
1552 case DW_AT_start_scope: return "DW_AT_start_scope";
1553 case DW_AT_stride_size: return "DW_AT_stride_size";
1554 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1555 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1556 case DW_AT_accessibility: return "DW_AT_accessibility";
1557 case DW_AT_address_class: return "DW_AT_address_class";
1558 case DW_AT_artificial: return "DW_AT_artificial";
1559 case DW_AT_base_types: return "DW_AT_base_types";
1560 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1561 case DW_AT_count: return "DW_AT_count";
1562 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1563 case DW_AT_decl_column: return "DW_AT_decl_column";
1564 case DW_AT_decl_file: return "DW_AT_decl_file";
1565 case DW_AT_decl_line: return "DW_AT_decl_line";
1566 case DW_AT_declaration: return "DW_AT_declaration";
1567 case DW_AT_discr_list: return "DW_AT_discr_list";
1568 case DW_AT_encoding: return "DW_AT_encoding";
1569 case DW_AT_external: return "DW_AT_external";
1570 case DW_AT_frame_base: return "DW_AT_frame_base";
1571 case DW_AT_friend: return "DW_AT_friend";
1572 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1573 case DW_AT_macro_info: return "DW_AT_macro_info";
1574 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1575 case DW_AT_priority: return "DW_AT_priority";
1576 case DW_AT_segment: return "DW_AT_segment";
1577 case DW_AT_specification: return "DW_AT_specification";
1578 case DW_AT_static_link: return "DW_AT_static_link";
1579 case DW_AT_type: return "DW_AT_type";
1580 case DW_AT_use_location: return "DW_AT_use_location";
1581 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1582 case DW_AT_virtuality: return "DW_AT_virtuality";
1583 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1584 /* DWARF 2.1 values. */
1585 case DW_AT_allocated: return "DW_AT_allocated";
1586 case DW_AT_associated: return "DW_AT_associated";
1587 case DW_AT_data_location: return "DW_AT_data_location";
1588 case DW_AT_stride: return "DW_AT_stride";
1589 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1590 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1591 case DW_AT_extension: return "DW_AT_extension";
1592 case DW_AT_ranges: return "DW_AT_ranges";
1593 case DW_AT_trampoline: return "DW_AT_trampoline";
1594 case DW_AT_call_column: return "DW_AT_call_column";
1595 case DW_AT_call_file: return "DW_AT_call_file";
1596 case DW_AT_call_line: return "DW_AT_call_line";
1597 case DW_AT_description: return "DW_AT_description";
1598 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1599 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1600 case DW_AT_small: return "DW_AT_small";
1601 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1602 case DW_AT_digit_count: return "DW_AT_digit_count";
1603 case DW_AT_picture_string: return "DW_AT_picture_string";
1604 case DW_AT_mutable: return "DW_AT_mutable";
1605 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1606 case DW_AT_explicit: return "DW_AT_explicit";
1607 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1608 case DW_AT_endianity: return "DW_AT_endianity";
1609 case DW_AT_elemental: return "DW_AT_elemental";
1610 case DW_AT_pure: return "DW_AT_pure";
1611 case DW_AT_recursive: return "DW_AT_recursive";
1613 /* HP and SGI/MIPS extensions. */
1614 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1615 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1616 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1617 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1618 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1619 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1620 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1621 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1622 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1623 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1625 /* HP Extensions. */
1626 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
1627 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1628 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1629 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1630 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1631 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1632 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1633 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1634 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1635 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1636 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1637 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1638 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1640 /* One value is shared by the MIPS and HP extensions: */
1641 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1643 /* GNU extensions. */
1644 case DW_AT_sf_names: return "DW_AT_sf_names";
1645 case DW_AT_src_info: return "DW_AT_src_info";
1646 case DW_AT_mac_info: return "DW_AT_mac_info";
1647 case DW_AT_src_coords: return "DW_AT_src_coords";
1648 case DW_AT_body_begin: return "DW_AT_body_begin";
1649 case DW_AT_body_end: return "DW_AT_body_end";
1650 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1652 /* UPC extension. */
1653 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1655 /* PGI (STMicroelectronics) extensions. */
1656 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1657 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1658 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1662 static char buffer[100];
1664 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1671 static unsigned char *
1672 read_and_display_attr (unsigned long attribute,
1674 unsigned char * data,
1675 unsigned long cu_offset,
1676 unsigned long pointer_size,
1677 unsigned long offset_size,
1679 debug_info * debug_info_p,
1681 struct dwarf_section * section)
1684 printf (" %-18s:", get_AT_name (attribute));
1685 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1686 pointer_size, offset_size,
1687 dwarf_version, debug_info_p,
1695 /* Process the contents of a .debug_info section. If do_loc is non-zero
1696 then we are scanning for location lists and we do not want to display
1697 anything to the user. */
1700 process_debug_info (struct dwarf_section *section,
1704 unsigned char *start = section->start;
1705 unsigned char *end = start + section->size;
1706 unsigned char *section_begin;
1708 unsigned int num_units = 0;
1710 if ((do_loc || do_debug_loc || do_debug_ranges)
1711 && num_debug_info_entries == 0)
1713 unsigned long length;
1715 /* First scan the section to get the number of comp units. */
1716 for (section_begin = start, num_units = 0; section_begin < end;
1719 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1720 will be the length. For a 64-bit DWARF section, it'll be
1721 the escape code 0xffffffff followed by an 8 byte length. */
1722 length = byte_get (section_begin, 4);
1724 if (length == 0xffffffff)
1726 length = byte_get (section_begin + 4, 8);
1727 section_begin += length + 12;
1729 else if (length >= 0xfffffff0 && length < 0xffffffff)
1731 warn (_("Reserved length value (%lx) found in section %s\n"), length, section->name);
1735 section_begin += length + 4;
1737 /* Negative values are illegal, they may even cause infinite
1738 looping. This can happen if we can't accurately apply
1739 relocations to an object file. */
1740 if ((signed long) length <= 0)
1742 warn (_("Corrupt unit length (%lx) found in section %s\n"), length, section->name);
1749 error (_("No comp units in %s section ?"), section->name);
1753 /* Then allocate an array to hold the information. */
1754 debug_information = cmalloc (num_units,
1755 sizeof (* debug_information));
1756 if (debug_information == NULL)
1758 error (_("Not enough memory for a debug info array of %u entries"),
1766 printf (_("The section %s contains:\n\n"), section->name);
1768 load_debug_section (str, file);
1771 load_debug_section (abbrev, file);
1772 if (debug_displays [abbrev].section.start == NULL)
1774 warn (_("Unable to locate %s section!\n"),
1775 debug_displays [abbrev].section.name);
1779 for (section_begin = start, unit = 0; start < end; unit++)
1781 DWARF2_Internal_CompUnit compunit;
1782 unsigned char *hdrptr;
1783 unsigned char *cu_abbrev_offset_ptr;
1784 unsigned char *tags;
1786 unsigned long cu_offset;
1788 int initial_length_size;
1792 compunit.cu_length = byte_get (hdrptr, 4);
1795 if (compunit.cu_length == 0xffffffff)
1797 compunit.cu_length = byte_get (hdrptr, 8);
1800 initial_length_size = 12;
1805 initial_length_size = 4;
1808 compunit.cu_version = byte_get (hdrptr, 2);
1811 cu_offset = start - section_begin;
1813 cu_abbrev_offset_ptr = hdrptr;
1814 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
1815 hdrptr += offset_size;
1817 compunit.cu_pointer_size = byte_get (hdrptr, 1);
1819 if ((do_loc || do_debug_loc || do_debug_ranges)
1820 && num_debug_info_entries == 0)
1822 debug_information [unit].cu_offset = cu_offset;
1823 debug_information [unit].pointer_size
1824 = compunit.cu_pointer_size;
1825 debug_information [unit].base_address = 0;
1826 debug_information [unit].loc_offsets = NULL;
1827 debug_information [unit].have_frame_base = NULL;
1828 debug_information [unit].max_loc_offsets = 0;
1829 debug_information [unit].num_loc_offsets = 0;
1830 debug_information [unit].range_lists = NULL;
1831 debug_information [unit].max_range_lists= 0;
1832 debug_information [unit].num_range_lists = 0;
1837 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset);
1838 printf (_(" Length: 0x%lx (%s)\n"), compunit.cu_length,
1839 initial_length_size == 8 ? "64-bit" : "32-bit");
1840 printf (_(" Version: %d\n"), compunit.cu_version);
1841 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
1842 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
1845 if (cu_offset + compunit.cu_length + initial_length_size
1848 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1849 cu_offset, compunit.cu_length);
1853 start += compunit.cu_length + initial_length_size;
1855 if (compunit.cu_version != 2 && compunit.cu_version != 3)
1857 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
1858 cu_offset, compunit.cu_version);
1864 /* Process the abbrevs used by this compilation unit. DWARF
1865 sections under Mach-O have non-zero addresses. */
1866 if (compunit.cu_abbrev_offset >= debug_displays [abbrev].section.size)
1867 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1868 (unsigned long) compunit.cu_abbrev_offset,
1869 (unsigned long) debug_displays [abbrev].section.size);
1871 process_abbrev_section
1872 ((unsigned char *) debug_displays [abbrev].section.start
1873 + compunit.cu_abbrev_offset - debug_displays [abbrev].section.address,
1874 (unsigned char *) debug_displays [abbrev].section.start
1875 + debug_displays [abbrev].section.size);
1878 while (tags < start)
1880 unsigned int bytes_read;
1881 unsigned long abbrev_number;
1882 unsigned long die_offset;
1883 abbrev_entry *entry;
1886 die_offset = tags - section_begin;
1888 abbrev_number = read_leb128 (tags, & bytes_read, 0);
1891 /* A null DIE marks the end of a list of siblings. */
1892 if (abbrev_number == 0)
1897 static unsigned num_bogus_warns = 0;
1899 if (num_bogus_warns < 3)
1901 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
1904 if (num_bogus_warns == 3)
1905 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
1912 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
1913 level, die_offset, abbrev_number);
1915 /* Scan through the abbreviation list until we reach the
1917 for (entry = first_abbrev;
1918 entry && entry->entry != abbrev_number;
1919 entry = entry->next)
1929 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
1930 die_offset, abbrev_number);
1935 printf (_(" (%s)\n"), get_TAG_name (entry->tag));
1940 need_base_address = 0;
1942 case DW_TAG_compile_unit:
1943 need_base_address = 1;
1945 case DW_TAG_entry_point:
1946 case DW_TAG_subprogram:
1947 need_base_address = 0;
1948 /* Assuming that there is no DW_AT_frame_base. */
1949 have_frame_base = 0;
1953 for (attr = entry->first_attr; attr; attr = attr->next)
1956 /* Show the offset from where the tag was extracted. */
1957 printf (" <%2lx>", (unsigned long)(tags - section_begin));
1959 tags = read_and_display_attr (attr->attribute,
1962 compunit.cu_pointer_size,
1964 compunit.cu_version,
1965 debug_information + unit,
1969 if (entry->children)
1974 /* Set num_debug_info_entries here so that it can be used to check if
1975 we need to process .debug_loc and .debug_ranges sections. */
1976 if ((do_loc || do_debug_loc || do_debug_ranges)
1977 && num_debug_info_entries == 0)
1978 num_debug_info_entries = num_units;
1988 /* Locate and scan the .debug_info section in the file and record the pointer
1989 sizes and offsets for the compilation units in it. Usually an executable
1990 will have just one pointer size, but this is not guaranteed, and so we try
1991 not to make any assumptions. Returns zero upon failure, or the number of
1992 compilation units upon success. */
1995 load_debug_info (void * file)
1997 /* Reset the last pointer size so that we can issue correct error
1998 messages if we are displaying the contents of more than one section. */
1999 last_pointer_size = 0;
2000 warned_about_missing_comp_units = FALSE;
2002 /* If we have already tried and failed to load the .debug_info
2003 section then do not bother to repear the task. */
2004 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2007 /* If we already have the information there is nothing else to do. */
2008 if (num_debug_info_entries > 0)
2009 return num_debug_info_entries;
2011 if (load_debug_section (info, file)
2012 && process_debug_info (&debug_displays [info].section, file, 1))
2013 return num_debug_info_entries;
2015 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2020 display_debug_lines (struct dwarf_section *section, void *file)
2022 unsigned char *start = section->start;
2023 unsigned char *data = start;
2024 unsigned char *end = start + section->size;
2026 printf (_("\nDump of debug contents of section %s:\n\n"),
2029 if (load_debug_info (file) == 0)
2031 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2038 DWARF2_Internal_LineInfo info;
2039 unsigned char *standard_opcodes;
2040 unsigned char *end_of_sequence;
2041 unsigned char *hdrptr;
2042 unsigned long hdroff;
2043 int initial_length_size;
2048 hdroff = hdrptr - start;
2050 /* Check the length of the block. */
2051 info.li_length = byte_get (hdrptr, 4);
2054 if (info.li_length == 0xffffffff)
2056 /* This section is 64-bit DWARF 3. */
2057 info.li_length = byte_get (hdrptr, 8);
2060 initial_length_size = 12;
2065 initial_length_size = 4;
2068 if (info.li_length + initial_length_size > section->size)
2071 (_("The line info appears to be corrupt - the section is too small\n"));
2075 /* Check its version number. */
2076 info.li_version = byte_get (hdrptr, 2);
2078 if (info.li_version != 2 && info.li_version != 3)
2080 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2084 info.li_prologue_length = byte_get (hdrptr, offset_size);
2085 hdrptr += offset_size;
2086 info.li_min_insn_length = byte_get (hdrptr, 1);
2088 info.li_default_is_stmt = byte_get (hdrptr, 1);
2090 info.li_line_base = byte_get (hdrptr, 1);
2092 info.li_line_range = byte_get (hdrptr, 1);
2094 info.li_opcode_base = byte_get (hdrptr, 1);
2097 /* Sign extend the line base field. */
2098 info.li_line_base <<= 24;
2099 info.li_line_base >>= 24;
2101 printf (_(" Offset: 0x%lx\n"), hdroff);
2102 printf (_(" Length: %ld\n"), info.li_length);
2103 printf (_(" DWARF Version: %d\n"), info.li_version);
2104 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
2105 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
2106 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
2107 printf (_(" Line Base: %d\n"), info.li_line_base);
2108 printf (_(" Line Range: %d\n"), info.li_line_range);
2109 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
2111 end_of_sequence = data + info.li_length + initial_length_size;
2113 reset_state_machine (info.li_default_is_stmt);
2115 /* Display the contents of the Opcodes table. */
2116 standard_opcodes = hdrptr;
2118 printf (_("\n Opcodes:\n"));
2120 for (i = 1; i < info.li_opcode_base; i++)
2121 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2123 /* Display the contents of the Directory table. */
2124 data = standard_opcodes + info.li_opcode_base - 1;
2127 printf (_("\n The Directory Table is empty.\n"));
2130 printf (_("\n The Directory Table:\n"));
2134 printf (_(" %s\n"), data);
2136 data += strlen ((char *) data) + 1;
2140 /* Skip the NUL at the end of the table. */
2143 /* Display the contents of the File Name table. */
2145 printf (_("\n The File Name Table is empty.\n"));
2148 printf (_("\n The File Name Table:\n"));
2149 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2153 unsigned char *name;
2154 unsigned int bytes_read;
2156 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
2159 data += strlen ((char *) data) + 1;
2161 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2163 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2165 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2167 printf (_("%s\n"), name);
2171 /* Skip the NUL at the end of the table. */
2174 /* Now display the statements. */
2175 printf (_("\n Line Number Statements:\n"));
2177 while (data < end_of_sequence)
2179 unsigned char op_code;
2181 unsigned long int uladv;
2182 unsigned int bytes_read;
2186 if (op_code >= info.li_opcode_base)
2188 op_code -= info.li_opcode_base;
2189 uladv = (op_code / info.li_line_range) * info.li_min_insn_length;
2190 state_machine_regs.address += uladv;
2191 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2192 op_code, uladv, state_machine_regs.address);
2193 adv = (op_code % info.li_line_range) + info.li_line_base;
2194 state_machine_regs.line += adv;
2195 printf (_(" and Line by %d to %d\n"),
2196 adv, state_machine_regs.line);
2198 else switch (op_code)
2200 case DW_LNS_extended_op:
2201 data += process_extended_line_op (data, info.li_default_is_stmt);
2205 printf (_(" Copy\n"));
2208 case DW_LNS_advance_pc:
2209 uladv = read_leb128 (data, & bytes_read, 0);
2210 uladv *= info.li_min_insn_length;
2212 state_machine_regs.address += uladv;
2213 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv,
2214 state_machine_regs.address);
2217 case DW_LNS_advance_line:
2218 adv = read_leb128 (data, & bytes_read, 1);
2220 state_machine_regs.line += adv;
2221 printf (_(" Advance Line by %d to %d\n"), adv,
2222 state_machine_regs.line);
2225 case DW_LNS_set_file:
2226 adv = read_leb128 (data, & bytes_read, 0);
2228 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2230 state_machine_regs.file = adv;
2233 case DW_LNS_set_column:
2234 uladv = read_leb128 (data, & bytes_read, 0);
2236 printf (_(" Set column to %lu\n"), uladv);
2237 state_machine_regs.column = uladv;
2240 case DW_LNS_negate_stmt:
2241 adv = state_machine_regs.is_stmt;
2243 printf (_(" Set is_stmt to %d\n"), adv);
2244 state_machine_regs.is_stmt = adv;
2247 case DW_LNS_set_basic_block:
2248 printf (_(" Set basic block\n"));
2249 state_machine_regs.basic_block = 1;
2252 case DW_LNS_const_add_pc:
2253 uladv = (((255 - info.li_opcode_base) / info.li_line_range)
2254 * info.li_min_insn_length);
2255 state_machine_regs.address += uladv;
2256 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv,
2257 state_machine_regs.address);
2260 case DW_LNS_fixed_advance_pc:
2261 uladv = byte_get (data, 2);
2263 state_machine_regs.address += uladv;
2264 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2265 uladv, state_machine_regs.address);
2268 case DW_LNS_set_prologue_end:
2269 printf (_(" Set prologue_end to true\n"));
2272 case DW_LNS_set_epilogue_begin:
2273 printf (_(" Set epilogue_begin to true\n"));
2276 case DW_LNS_set_isa:
2277 uladv = read_leb128 (data, & bytes_read, 0);
2279 printf (_(" Set ISA to %lu\n"), uladv);
2283 printf (_(" Unknown opcode %d with operands: "), op_code);
2285 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2287 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
2288 i == 1 ? "" : ", ");
2302 find_debug_info_for_offset (unsigned long offset)
2306 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2309 for (i = 0; i < num_debug_info_entries; i++)
2310 if (debug_information[i].cu_offset == offset)
2311 return debug_information + i;
2317 display_debug_pubnames (struct dwarf_section *section,
2318 void *file ATTRIBUTE_UNUSED)
2320 DWARF2_Internal_PubNames pubnames;
2321 unsigned char *start = section->start;
2322 unsigned char *end = start + section->size;
2324 /* It does not matter if this load fails,
2325 we test for that later on. */
2326 load_debug_info (file);
2328 printf (_("Contents of the %s section:\n\n"), section->name);
2332 unsigned char *data;
2333 unsigned long offset;
2334 int offset_size, initial_length_size;
2338 pubnames.pn_length = byte_get (data, 4);
2340 if (pubnames.pn_length == 0xffffffff)
2342 pubnames.pn_length = byte_get (data, 8);
2345 initial_length_size = 12;
2350 initial_length_size = 4;
2353 pubnames.pn_version = byte_get (data, 2);
2356 pubnames.pn_offset = byte_get (data, offset_size);
2357 data += offset_size;
2359 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
2360 && num_debug_info_entries > 0
2361 && find_debug_info_for_offset (pubnames.pn_offset) == NULL)
2362 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2363 pubnames.pn_offset, section->name);
2365 pubnames.pn_size = byte_get (data, offset_size);
2366 data += offset_size;
2368 start += pubnames.pn_length + initial_length_size;
2370 if (pubnames.pn_version != 2 && pubnames.pn_version != 3)
2372 static int warned = 0;
2376 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2383 printf (_(" Length: %ld\n"),
2384 pubnames.pn_length);
2385 printf (_(" Version: %d\n"),
2386 pubnames.pn_version);
2387 printf (_(" Offset into .debug_info section: 0x%lx\n"),
2388 pubnames.pn_offset);
2389 printf (_(" Size of area in .debug_info section: %ld\n"),
2392 printf (_("\n Offset\tName\n"));
2396 offset = byte_get (data, offset_size);
2400 data += offset_size;
2401 printf (" %-6ld\t\t%s\n", offset, data);
2402 data += strlen ((char *) data) + 1;
2405 while (offset != 0);
2413 display_debug_macinfo (struct dwarf_section *section,
2414 void *file ATTRIBUTE_UNUSED)
2416 unsigned char *start = section->start;
2417 unsigned char *end = start + section->size;
2418 unsigned char *curr = start;
2419 unsigned int bytes_read;
2420 enum dwarf_macinfo_record_type op;
2422 printf (_("Contents of the %s section:\n\n"), section->name);
2426 unsigned int lineno;
2434 case DW_MACINFO_start_file:
2436 unsigned int filenum;
2438 lineno = read_leb128 (curr, & bytes_read, 0);
2440 filenum = read_leb128 (curr, & bytes_read, 0);
2443 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2448 case DW_MACINFO_end_file:
2449 printf (_(" DW_MACINFO_end_file\n"));
2452 case DW_MACINFO_define:
2453 lineno = read_leb128 (curr, & bytes_read, 0);
2455 string = (char *) curr;
2456 curr += strlen (string) + 1;
2457 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2461 case DW_MACINFO_undef:
2462 lineno = read_leb128 (curr, & bytes_read, 0);
2464 string = (char *) curr;
2465 curr += strlen (string) + 1;
2466 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2470 case DW_MACINFO_vendor_ext:
2472 unsigned int constant;
2474 constant = read_leb128 (curr, & bytes_read, 0);
2476 string = (char *) curr;
2477 curr += strlen (string) + 1;
2478 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2489 display_debug_abbrev (struct dwarf_section *section,
2490 void *file ATTRIBUTE_UNUSED)
2492 abbrev_entry *entry;
2493 unsigned char *start = section->start;
2494 unsigned char *end = start + section->size;
2496 printf (_("Contents of the %s section:\n\n"), section->name);
2502 start = process_abbrev_section (start, end);
2504 if (first_abbrev == NULL)
2507 printf (_(" Number TAG\n"));
2509 for (entry = first_abbrev; entry; entry = entry->next)
2513 printf (_(" %ld %s [%s]\n"),
2515 get_TAG_name (entry->tag),
2516 entry->children ? _("has children") : _("no children"));
2518 for (attr = entry->first_attr; attr; attr = attr->next)
2519 printf (_(" %-18s %s\n"),
2520 get_AT_name (attr->attribute),
2521 get_FORM_name (attr->form));
2532 display_debug_loc (struct dwarf_section *section, void *file)
2534 unsigned char *start = section->start;
2535 unsigned char *section_end;
2536 unsigned long bytes;
2537 unsigned char *section_begin = start;
2538 unsigned int num_loc_list = 0;
2539 unsigned long last_offset = 0;
2540 unsigned int first = 0;
2543 int seen_first_offset = 0;
2544 int use_debug_info = 1;
2545 unsigned char *next;
2547 bytes = section->size;
2548 section_end = start + bytes;
2552 printf (_("\nThe %s section is empty.\n"), section->name);
2556 if (load_debug_info (file) == 0)
2558 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2563 /* Check the order of location list in .debug_info section. If
2564 offsets of location lists are in the ascending order, we can
2565 use `debug_information' directly. */
2566 for (i = 0; i < num_debug_info_entries; i++)
2570 num = debug_information [i].num_loc_offsets;
2571 num_loc_list += num;
2573 /* Check if we can use `debug_information' directly. */
2574 if (use_debug_info && num != 0)
2576 if (!seen_first_offset)
2578 /* This is the first location list. */
2579 last_offset = debug_information [i].loc_offsets [0];
2581 seen_first_offset = 1;
2587 for (; j < num; j++)
2590 debug_information [i].loc_offsets [j])
2595 last_offset = debug_information [i].loc_offsets [j];
2600 if (!use_debug_info)
2601 /* FIXME: Should we handle this case? */
2602 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
2604 if (!seen_first_offset)
2605 error (_("No location lists in .debug_info section!\n"));
2607 /* DWARF sections under Mach-O have non-zero addresses. */
2608 if (debug_information [first].num_loc_offsets > 0
2609 && debug_information [first].loc_offsets [0] != section->address)
2610 warn (_("Location lists in %s section start at 0x%lx\n"),
2611 section->name, debug_information [first].loc_offsets [0]);
2613 printf (_("Contents of the %s section:\n\n"), section->name);
2614 printf (_(" Offset Begin End Expression\n"));
2616 seen_first_offset = 0;
2617 for (i = first; i < num_debug_info_entries; i++)
2619 unsigned long begin;
2621 unsigned long minus_one;
2622 unsigned short length;
2623 unsigned long offset;
2624 unsigned int pointer_size;
2625 unsigned long cu_offset;
2626 unsigned long base_address;
2627 int need_frame_base;
2630 pointer_size = debug_information [i].pointer_size;
2631 cu_offset = debug_information [i].cu_offset;
2633 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
2635 has_frame_base = debug_information [i].have_frame_base [j];
2636 /* DWARF sections under Mach-O have non-zero addresses. */
2637 offset = debug_information [i].loc_offsets [j] - section->address;
2638 next = section_begin + offset;
2639 base_address = debug_information [i].base_address;
2641 if (!seen_first_offset)
2642 seen_first_offset = 1;
2646 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
2647 (long)(start - section_begin), (long)(next - section_begin));
2648 else if (start > next)
2649 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
2650 (long)(start - section_begin), (long)(next - section_begin));
2654 if (offset >= bytes)
2656 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
2663 if (start + 2 * pointer_size > section_end)
2665 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2670 begin = byte_get (start, pointer_size);
2671 start += pointer_size;
2672 end = byte_get (start, pointer_size);
2673 start += pointer_size;
2675 if (begin == 0 && end == 0)
2677 printf (_(" %8.8lx <End of list>\n"), offset);
2681 /* Check base address specifiers. */
2683 if (pointer_size < sizeof (minus_one))
2684 minus_one = (1L << (pointer_size * 8)) - 1;
2685 if (begin == minus_one && end != minus_one)
2688 printf (_(" %8.8lx %8.8lx %8.8lx (base address)\n"),
2689 offset, begin, end);
2693 if (start + 2 > section_end)
2695 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2700 length = byte_get (start, 2);
2703 if (start + length > section_end)
2705 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2710 printf (" %8.8lx %8.8lx %8.8lx (",
2711 offset, begin + base_address, end + base_address);
2712 need_frame_base = decode_location_expression (start,
2718 if (need_frame_base && !has_frame_base)
2719 printf (_(" [without DW_AT_frame_base]"));
2722 fputs (_(" (start == end)"), stdout);
2723 else if (begin > end)
2724 fputs (_(" (start > end)"), stdout);
2733 if (start < section_end)
2734 warn (_("There are %ld unused bytes at the end of section %s\n"),
2735 (long) (section_end - start), section->name);
2740 display_debug_str (struct dwarf_section *section,
2741 void *file ATTRIBUTE_UNUSED)
2743 unsigned char *start = section->start;
2744 unsigned long bytes = section->size;
2745 dwarf_vma addr = section->address;
2749 printf (_("\nThe %s section is empty.\n"), section->name);
2753 printf (_("Contents of the %s section:\n\n"), section->name);
2761 lbytes = (bytes > 16 ? 16 : bytes);
2763 printf (" 0x%8.8lx ", (unsigned long) addr);
2765 for (j = 0; j < 16; j++)
2768 printf ("%2.2x", start[j]);
2776 for (j = 0; j < lbytes; j++)
2779 if (k >= ' ' && k < 0x80)
2798 display_debug_info (struct dwarf_section *section, void *file)
2800 return process_debug_info (section, file, 0);
2805 display_debug_aranges (struct dwarf_section *section,
2806 void *file ATTRIBUTE_UNUSED)
2808 unsigned char *start = section->start;
2809 unsigned char *end = start + section->size;
2811 printf (_("The section %s contains:\n\n"), section->name);
2813 /* It does not matter if this load fails,
2814 we test for that later on. */
2815 load_debug_info (file);
2819 unsigned char *hdrptr;
2820 DWARF2_Internal_ARange arange;
2821 unsigned char *ranges;
2822 unsigned long length;
2823 unsigned long address;
2824 unsigned char address_size;
2827 int initial_length_size;
2831 arange.ar_length = byte_get (hdrptr, 4);
2834 if (arange.ar_length == 0xffffffff)
2836 arange.ar_length = byte_get (hdrptr, 8);
2839 initial_length_size = 12;
2844 initial_length_size = 4;
2847 arange.ar_version = byte_get (hdrptr, 2);
2850 arange.ar_info_offset = byte_get (hdrptr, offset_size);
2851 hdrptr += offset_size;
2853 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
2854 && num_debug_info_entries > 0
2855 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
2856 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2857 arange.ar_info_offset, section->name);
2859 arange.ar_pointer_size = byte_get (hdrptr, 1);
2862 arange.ar_segment_size = byte_get (hdrptr, 1);
2865 if (arange.ar_version != 2 && arange.ar_version != 3)
2867 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
2871 printf (_(" Length: %ld\n"), arange.ar_length);
2872 printf (_(" Version: %d\n"), arange.ar_version);
2873 printf (_(" Offset into .debug_info: 0x%lx\n"), arange.ar_info_offset);
2874 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
2875 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
2877 address_size = arange.ar_pointer_size + arange.ar_segment_size;
2879 /* The DWARF spec does not require that the address size be a power
2880 of two, but we do. This will have to change if we ever encounter
2881 an uneven architecture. */
2882 if ((address_size & (address_size - 1)) != 0)
2884 warn (_("Pointer size + Segment size is not a power of two.\n"));
2888 if (address_size > 4)
2889 printf (_("\n Address Length\n"));
2891 printf (_("\n Address Length\n"));
2895 /* Must pad to an alignment boundary that is twice the address size. */
2896 excess = (hdrptr - start) % (2 * address_size);
2898 ranges += (2 * address_size) - excess;
2900 start += arange.ar_length + initial_length_size;
2902 while (ranges + 2 * address_size <= start)
2904 address = byte_get (ranges, address_size);
2906 ranges += address_size;
2908 length = byte_get (ranges, address_size);
2910 ranges += address_size;
2912 if (address_size > 4)
2913 printf (" 0x%16.16lx 0x%lx\n", address, length);
2915 printf (" 0x%8.8lx 0x%lx\n", address, length);
2925 display_debug_ranges (struct dwarf_section *section,
2926 void *file ATTRIBUTE_UNUSED)
2928 unsigned char *start = section->start;
2929 unsigned char *section_end;
2930 unsigned long bytes;
2931 unsigned char *section_begin = start;
2932 unsigned int num_range_list = 0;
2933 unsigned long last_offset = 0;
2934 unsigned int first = 0;
2937 int seen_first_offset = 0;
2938 int use_debug_info = 1;
2939 unsigned char *next;
2941 bytes = section->size;
2942 section_end = start + bytes;
2946 printf (_("\nThe %s section is empty.\n"), section->name);
2950 if (load_debug_info (file) == 0)
2952 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2957 /* Check the order of range list in .debug_info section. If
2958 offsets of range lists are in the ascending order, we can
2959 use `debug_information' directly. */
2960 for (i = 0; i < num_debug_info_entries; i++)
2964 num = debug_information [i].num_range_lists;
2965 num_range_list += num;
2967 /* Check if we can use `debug_information' directly. */
2968 if (use_debug_info && num != 0)
2970 if (!seen_first_offset)
2972 /* This is the first range list. */
2973 last_offset = debug_information [i].range_lists [0];
2975 seen_first_offset = 1;
2981 for (; j < num; j++)
2984 debug_information [i].range_lists [j])
2989 last_offset = debug_information [i].range_lists [j];
2994 if (!use_debug_info)
2995 /* FIXME: Should we handle this case? */
2996 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
2998 if (!seen_first_offset)
2999 error (_("No range lists in .debug_info section!\n"));
3001 /* DWARF sections under Mach-O have non-zero addresses. */
3002 if (debug_information [first].num_range_lists > 0
3003 && debug_information [first].range_lists [0] != section->address)
3004 warn (_("Range lists in %s section start at 0x%lx\n"),
3005 section->name, debug_information [first].range_lists [0]);
3007 printf (_("Contents of the %s section:\n\n"), section->name);
3008 printf (_(" Offset Begin End\n"));
3010 seen_first_offset = 0;
3011 for (i = first; i < num_debug_info_entries; i++)
3013 unsigned long begin;
3015 unsigned long offset;
3016 unsigned int pointer_size;
3017 unsigned long base_address;
3019 pointer_size = debug_information [i].pointer_size;
3021 for (j = 0; j < debug_information [i].num_range_lists; j++)
3023 /* DWARF sections under Mach-O have non-zero addresses. */
3024 offset = debug_information [i].range_lists [j] - section->address;
3025 next = section_begin + offset;
3026 base_address = debug_information [i].base_address;
3028 if (!seen_first_offset)
3029 seen_first_offset = 1;
3033 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3034 (long)(start - section_begin),
3035 (long)(next - section_begin), section->name);
3036 else if (start > next)
3037 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3038 (long)(start - section_begin),
3039 (long)(next - section_begin), section->name);
3045 begin = byte_get (start, pointer_size);
3046 start += pointer_size;
3047 end = byte_get (start, pointer_size);
3048 start += pointer_size;
3050 if (begin == 0 && end == 0)
3052 printf (_(" %8.8lx <End of list>\n"), offset);
3056 /* Check base address specifiers. */
3057 if (begin == -1UL && end != -1UL)
3060 printf (" %8.8lx %8.8lx %8.8lx (base address)\n",
3061 offset, begin, end);
3065 printf (" %8.8lx %8.8lx %8.8lx",
3066 offset, begin + base_address, end + base_address);
3069 fputs (_(" (start == end)"), stdout);
3070 else if (begin > end)
3071 fputs (_(" (start > end)"), stdout);
3081 typedef struct Frame_Chunk
3083 struct Frame_Chunk *next;
3084 unsigned char *chunk_start;
3086 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3087 short int *col_type;
3090 unsigned int code_factor;
3092 unsigned long pc_begin;
3093 unsigned long pc_range;
3097 unsigned char fde_encoding;
3098 unsigned char cfa_exp;
3102 /* A marker for a col_type that means this column was never referenced
3103 in the frame info. */
3104 #define DW_CFA_unreferenced (-1)
3107 frame_need_space (Frame_Chunk *fc, int reg)
3109 int prev = fc->ncols;
3111 if (reg < fc->ncols)
3114 fc->ncols = reg + 1;
3115 fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int));
3116 fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
3118 while (prev < fc->ncols)
3120 fc->col_type[prev] = DW_CFA_unreferenced;
3121 fc->col_offset[prev] = 0;
3126 static const char *const dwarf_regnames_i386[] =
3128 "eax", "ecx", "edx", "ebx",
3129 "esp", "ebp", "esi", "edi",
3130 "eip", "eflags", NULL,
3131 "st0", "st1", "st2", "st3",
3132 "st4", "st5", "st6", "st7",
3134 "xmm0", "xmm1", "xmm2", "xmm3",
3135 "xmm4", "xmm5", "xmm6", "xmm7",
3136 "mm0", "mm1", "mm2", "mm3",
3137 "mm4", "mm5", "mm6", "mm7",
3138 "fcw", "fsw", "mxcsr",
3139 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3143 static const char *const dwarf_regnames_x86_64[] =
3145 "rax", "rdx", "rcx", "rbx",
3146 "rsi", "rdi", "rbp", "rsp",
3147 "r8", "r9", "r10", "r11",
3148 "r12", "r13", "r14", "r15",
3150 "xmm0", "xmm1", "xmm2", "xmm3",
3151 "xmm4", "xmm5", "xmm6", "xmm7",
3152 "xmm8", "xmm9", "xmm10", "xmm11",
3153 "xmm12", "xmm13", "xmm14", "xmm15",
3154 "st0", "st1", "st2", "st3",
3155 "st4", "st5", "st6", "st7",
3156 "mm0", "mm1", "mm2", "mm3",
3157 "mm4", "mm5", "mm6", "mm7",
3159 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3160 "fs.base", "gs.base", NULL, NULL,
3162 "mxcsr", "fcw", "fsw"
3165 static const char *const *dwarf_regnames;
3166 static unsigned int dwarf_regnames_count;
3169 init_dwarf_regnames (unsigned int e_machine)
3175 dwarf_regnames = dwarf_regnames_i386;
3176 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
3180 dwarf_regnames = dwarf_regnames_x86_64;
3181 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
3190 regname (unsigned int regno, int row)
3192 static char reg[64];
3194 && regno < dwarf_regnames_count
3195 && dwarf_regnames [regno] != NULL)
3198 return dwarf_regnames [regno];
3199 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
3200 dwarf_regnames [regno]);
3203 snprintf (reg, sizeof (reg), "r%d", regno);
3208 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
3213 if (*max_regs < fc->ncols)
3214 *max_regs = fc->ncols;
3216 if (*need_col_headers)
3218 static const char *loc = " LOC";
3220 *need_col_headers = 0;
3222 printf ("%-*s CFA ", eh_addr_size * 2, loc);
3224 for (r = 0; r < *max_regs; r++)
3225 if (fc->col_type[r] != DW_CFA_unreferenced)
3230 printf ("%-5s ", regname (r, 1));
3236 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
3238 strcpy (tmp, "exp");
3240 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
3241 printf ("%-8s ", tmp);
3243 for (r = 0; r < fc->ncols; r++)
3245 if (fc->col_type[r] != DW_CFA_unreferenced)
3247 switch (fc->col_type[r])
3249 case DW_CFA_undefined:
3252 case DW_CFA_same_value:
3256 sprintf (tmp, "c%+d", fc->col_offset[r]);
3258 case DW_CFA_val_offset:
3259 sprintf (tmp, "v%+d", fc->col_offset[r]);
3261 case DW_CFA_register:
3262 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
3264 case DW_CFA_expression:
3265 strcpy (tmp, "exp");
3267 case DW_CFA_val_expression:
3268 strcpy (tmp, "vexp");
3271 strcpy (tmp, "n/a");
3274 printf ("%-5s ", tmp);
3281 size_of_encoded_value (int encoding)
3283 switch (encoding & 0x7)
3286 case 0: return eh_addr_size;
3294 get_encoded_value (unsigned char *data, int encoding)
3296 int size = size_of_encoded_value (encoding);
3298 if (encoding & DW_EH_PE_signed)
3299 return byte_get_signed (data, size);
3301 return byte_get (data, size);
3304 #define GET(N) byte_get (start, N); start += N
3305 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3306 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3309 display_debug_frames (struct dwarf_section *section,
3310 void *file ATTRIBUTE_UNUSED)
3312 unsigned char *start = section->start;
3313 unsigned char *end = start + section->size;
3314 unsigned char *section_start = start;
3315 Frame_Chunk *chunks = 0;
3316 Frame_Chunk *remembered_state = 0;
3318 int is_eh = strcmp (section->name, ".eh_frame") == 0;
3319 unsigned int length_return;
3322 printf (_("The section %s contains:\n"), section->name);
3326 unsigned char *saved_start;
3327 unsigned char *block_end;
3328 unsigned long length;
3329 unsigned long cie_id;
3332 int need_col_headers = 1;
3333 unsigned char *augmentation_data = NULL;
3334 unsigned long augmentation_data_len = 0;
3335 int encoded_ptr_size = eh_addr_size;
3337 int initial_length_size;
3339 saved_start = start;
3340 length = byte_get (start, 4); start += 4;
3344 printf ("\n%08lx ZERO terminator\n\n",
3345 (unsigned long)(saved_start - section_start));
3349 if (length == 0xffffffff)
3351 length = byte_get (start, 8);
3354 initial_length_size = 12;
3359 initial_length_size = 4;
3362 block_end = saved_start + length + initial_length_size;
3363 if (block_end > end)
3365 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3366 length, (unsigned long)(saved_start - section_start));
3369 cie_id = byte_get (start, offset_size); start += offset_size;
3371 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
3375 fc = xmalloc (sizeof (Frame_Chunk));
3376 memset (fc, 0, sizeof (Frame_Chunk));
3380 fc->chunk_start = saved_start;
3382 fc->col_type = xmalloc (sizeof (short int));
3383 fc->col_offset = xmalloc (sizeof (int));
3384 frame_need_space (fc, max_regs - 1);
3388 fc->augmentation = (char *) start;
3389 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
3391 if (fc->augmentation[0] == 'z')
3393 fc->code_factor = LEB ();
3394 fc->data_factor = SLEB ();
3403 augmentation_data_len = LEB ();
3404 augmentation_data = start;
3405 start += augmentation_data_len;
3407 else if (strcmp (fc->augmentation, "eh") == 0)
3409 start += eh_addr_size;
3410 fc->code_factor = LEB ();
3411 fc->data_factor = SLEB ();
3423 fc->code_factor = LEB ();
3424 fc->data_factor = SLEB ();
3436 if (do_debug_frames_interp)
3437 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3438 (unsigned long)(saved_start - section_start), length, cie_id,
3439 fc->augmentation, fc->code_factor, fc->data_factor,
3443 printf ("\n%08lx %08lx %08lx CIE\n",
3444 (unsigned long)(saved_start - section_start), length, cie_id);
3445 printf (" Version: %d\n", version);
3446 printf (" Augmentation: \"%s\"\n", fc->augmentation);
3447 printf (" Code alignment factor: %u\n", fc->code_factor);
3448 printf (" Data alignment factor: %d\n", fc->data_factor);
3449 printf (" Return address column: %d\n", fc->ra);
3451 if (augmentation_data_len)
3454 printf (" Augmentation data: ");
3455 for (i = 0; i < augmentation_data_len; ++i)
3456 printf (" %02x", augmentation_data[i]);
3462 if (augmentation_data_len)
3464 unsigned char *p, *q;
3465 p = (unsigned char *) fc->augmentation + 1;
3466 q = augmentation_data;
3473 q += 1 + size_of_encoded_value (*q);
3475 fc->fde_encoding = *q++;
3481 if (fc->fde_encoding)
3482 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3485 frame_need_space (fc, fc->ra);
3489 unsigned char *look_for;
3490 static Frame_Chunk fde_fc;
3493 memset (fc, 0, sizeof (Frame_Chunk));
3495 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
3497 for (cie = chunks; cie ; cie = cie->next)
3498 if (cie->chunk_start == look_for)
3503 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
3504 cie_id, (unsigned long)(saved_start - section_start));
3506 fc->col_type = xmalloc (sizeof (short int));
3507 fc->col_offset = xmalloc (sizeof (int));
3508 frame_need_space (fc, max_regs - 1);
3510 fc->augmentation = "";
3511 fc->fde_encoding = 0;
3515 fc->ncols = cie->ncols;
3516 fc->col_type = xcmalloc (fc->ncols, sizeof (short int));
3517 fc->col_offset = xcmalloc (fc->ncols, sizeof (int));
3518 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
3519 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
3520 fc->augmentation = cie->augmentation;
3521 fc->code_factor = cie->code_factor;
3522 fc->data_factor = cie->data_factor;
3523 fc->cfa_reg = cie->cfa_reg;
3524 fc->cfa_offset = cie->cfa_offset;
3526 frame_need_space (fc, max_regs - 1);
3527 fc->fde_encoding = cie->fde_encoding;
3530 if (fc->fde_encoding)
3531 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3533 fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
3534 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
3535 fc->pc_begin += section->address + (start - section_start);
3536 start += encoded_ptr_size;
3537 fc->pc_range = byte_get (start, encoded_ptr_size);
3538 start += encoded_ptr_size;
3540 if (cie->augmentation[0] == 'z')
3542 augmentation_data_len = LEB ();
3543 augmentation_data = start;
3544 start += augmentation_data_len;
3547 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
3548 (unsigned long)(saved_start - section_start), length, cie_id,
3549 (unsigned long)(cie->chunk_start - section_start),
3550 fc->pc_begin, fc->pc_begin + fc->pc_range);
3551 if (! do_debug_frames_interp && augmentation_data_len)
3555 printf (" Augmentation data: ");
3556 for (i = 0; i < augmentation_data_len; ++i)
3557 printf (" %02x", augmentation_data[i]);
3563 /* At this point, fc is the current chunk, cie (if any) is set, and
3564 we're about to interpret instructions for the chunk. */
3565 /* ??? At present we need to do this always, since this sizes the
3566 fc->col_type and fc->col_offset arrays, which we write into always.
3567 We should probably split the interpreted and non-interpreted bits
3568 into two different routines, since there's so much that doesn't
3569 really overlap between them. */
3570 if (1 || do_debug_frames_interp)
3572 /* Start by making a pass over the chunk, allocating storage
3573 and taking note of what registers are used. */
3574 unsigned char *tmp = start;
3576 while (start < block_end)
3579 unsigned long reg, tmp;
3586 /* Warning: if you add any more cases to this switch, be
3587 sure to add them to the corresponding switch below. */
3590 case DW_CFA_advance_loc:
3594 frame_need_space (fc, opa);
3595 fc->col_type[opa] = DW_CFA_undefined;
3597 case DW_CFA_restore:
3598 frame_need_space (fc, opa);
3599 fc->col_type[opa] = DW_CFA_undefined;
3601 case DW_CFA_set_loc:
3602 start += encoded_ptr_size;
3604 case DW_CFA_advance_loc1:
3607 case DW_CFA_advance_loc2:
3610 case DW_CFA_advance_loc4:
3613 case DW_CFA_offset_extended:
3614 case DW_CFA_val_offset:
3615 reg = LEB (); LEB ();
3616 frame_need_space (fc, reg);
3617 fc->col_type[reg] = DW_CFA_undefined;
3619 case DW_CFA_restore_extended:
3621 frame_need_space (fc, reg);
3622 fc->col_type[reg] = DW_CFA_undefined;
3624 case DW_CFA_undefined:
3626 frame_need_space (fc, reg);
3627 fc->col_type[reg] = DW_CFA_undefined;
3629 case DW_CFA_same_value:
3631 frame_need_space (fc, reg);
3632 fc->col_type[reg] = DW_CFA_undefined;
3634 case DW_CFA_register:
3635 reg = LEB (); LEB ();
3636 frame_need_space (fc, reg);
3637 fc->col_type[reg] = DW_CFA_undefined;
3639 case DW_CFA_def_cfa:
3642 case DW_CFA_def_cfa_register:
3645 case DW_CFA_def_cfa_offset:
3648 case DW_CFA_def_cfa_expression:
3652 case DW_CFA_expression:
3653 case DW_CFA_val_expression:
3657 frame_need_space (fc, reg);
3658 fc->col_type[reg] = DW_CFA_undefined;
3660 case DW_CFA_offset_extended_sf:
3661 case DW_CFA_val_offset_sf:
3662 reg = LEB (); SLEB ();
3663 frame_need_space (fc, reg);
3664 fc->col_type[reg] = DW_CFA_undefined;
3666 case DW_CFA_def_cfa_sf:
3669 case DW_CFA_def_cfa_offset_sf:
3672 case DW_CFA_MIPS_advance_loc8:
3675 case DW_CFA_GNU_args_size:
3678 case DW_CFA_GNU_negative_offset_extended:
3679 reg = LEB (); LEB ();
3680 frame_need_space (fc, reg);
3681 fc->col_type[reg] = DW_CFA_undefined;
3690 /* Now we know what registers are used, make a second pass over
3691 the chunk, this time actually printing out the info. */
3693 while (start < block_end)
3696 unsigned long ul, reg, roffs;
3705 /* Warning: if you add any more cases to this switch, be
3706 sure to add them to the corresponding switch above. */
3709 case DW_CFA_advance_loc:
3710 if (do_debug_frames_interp)
3711 frame_display_row (fc, &need_col_headers, &max_regs);
3713 printf (" DW_CFA_advance_loc: %d to %08lx\n",
3714 opa * fc->code_factor,
3715 fc->pc_begin + opa * fc->code_factor);
3716 fc->pc_begin += opa * fc->code_factor;
3721 if (! do_debug_frames_interp)
3722 printf (" DW_CFA_offset: %s at cfa%+ld\n",
3723 regname (opa, 0), roffs * fc->data_factor);
3724 fc->col_type[opa] = DW_CFA_offset;
3725 fc->col_offset[opa] = roffs * fc->data_factor;
3728 case DW_CFA_restore:
3729 if (! do_debug_frames_interp)
3730 printf (" DW_CFA_restore: %s\n", regname (opa, 0));
3731 fc->col_type[opa] = cie->col_type[opa];
3732 fc->col_offset[opa] = cie->col_offset[opa];
3735 case DW_CFA_set_loc:
3736 vma = get_encoded_value (start, fc->fde_encoding);
3737 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
3738 vma += section->address + (start - section_start);
3739 start += encoded_ptr_size;
3740 if (do_debug_frames_interp)
3741 frame_display_row (fc, &need_col_headers, &max_regs);
3743 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
3747 case DW_CFA_advance_loc1:
3748 ofs = byte_get (start, 1); start += 1;
3749 if (do_debug_frames_interp)
3750 frame_display_row (fc, &need_col_headers, &max_regs);
3752 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
3753 ofs * fc->code_factor,
3754 fc->pc_begin + ofs * fc->code_factor);
3755 fc->pc_begin += ofs * fc->code_factor;
3758 case DW_CFA_advance_loc2:
3759 ofs = byte_get (start, 2); start += 2;
3760 if (do_debug_frames_interp)
3761 frame_display_row (fc, &need_col_headers, &max_regs);
3763 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
3764 ofs * fc->code_factor,
3765 fc->pc_begin + ofs * fc->code_factor);
3766 fc->pc_begin += ofs * fc->code_factor;
3769 case DW_CFA_advance_loc4:
3770 ofs = byte_get (start, 4); start += 4;
3771 if (do_debug_frames_interp)
3772 frame_display_row (fc, &need_col_headers, &max_regs);
3774 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
3775 ofs * fc->code_factor,
3776 fc->pc_begin + ofs * fc->code_factor);
3777 fc->pc_begin += ofs * fc->code_factor;
3780 case DW_CFA_offset_extended:
3783 if (! do_debug_frames_interp)
3784 printf (" DW_CFA_offset_extended: %s at cfa%+ld\n",
3785 regname (reg, 0), roffs * fc->data_factor);
3786 fc->col_type[reg] = DW_CFA_offset;
3787 fc->col_offset[reg] = roffs * fc->data_factor;
3790 case DW_CFA_val_offset:
3793 if (! do_debug_frames_interp)
3794 printf (" DW_CFA_val_offset: %s at cfa%+ld\n",
3795 regname (reg, 0), roffs * fc->data_factor);
3796 fc->col_type[reg] = DW_CFA_val_offset;
3797 fc->col_offset[reg] = roffs * fc->data_factor;
3800 case DW_CFA_restore_extended:
3802 if (! do_debug_frames_interp)
3803 printf (" DW_CFA_restore_extended: %s\n",
3805 fc->col_type[reg] = cie->col_type[reg];
3806 fc->col_offset[reg] = cie->col_offset[reg];
3809 case DW_CFA_undefined:
3811 if (! do_debug_frames_interp)
3812 printf (" DW_CFA_undefined: %s\n", regname (reg, 0));
3813 fc->col_type[reg] = DW_CFA_undefined;
3814 fc->col_offset[reg] = 0;
3817 case DW_CFA_same_value:
3819 if (! do_debug_frames_interp)
3820 printf (" DW_CFA_same_value: %s\n", regname (reg, 0));
3821 fc->col_type[reg] = DW_CFA_same_value;
3822 fc->col_offset[reg] = 0;
3825 case DW_CFA_register:
3828 if (! do_debug_frames_interp)
3830 printf (" DW_CFA_register: %s in ",
3832 puts (regname (roffs, 0));
3834 fc->col_type[reg] = DW_CFA_register;
3835 fc->col_offset[reg] = roffs;
3838 case DW_CFA_remember_state:
3839 if (! do_debug_frames_interp)
3840 printf (" DW_CFA_remember_state\n");
3841 rs = xmalloc (sizeof (Frame_Chunk));
3842 rs->ncols = fc->ncols;
3843 rs->col_type = xcmalloc (rs->ncols, sizeof (short int));
3844 rs->col_offset = xcmalloc (rs->ncols, sizeof (int));
3845 memcpy (rs->col_type, fc->col_type, rs->ncols);
3846 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
3847 rs->next = remembered_state;
3848 remembered_state = rs;
3851 case DW_CFA_restore_state:
3852 if (! do_debug_frames_interp)
3853 printf (" DW_CFA_restore_state\n");
3854 rs = remembered_state;
3857 remembered_state = rs->next;
3858 frame_need_space (fc, rs->ncols - 1);
3859 memcpy (fc->col_type, rs->col_type, rs->ncols);
3860 memcpy (fc->col_offset, rs->col_offset,
3861 rs->ncols * sizeof (int));
3862 free (rs->col_type);
3863 free (rs->col_offset);
3866 else if (do_debug_frames_interp)
3867 printf ("Mismatched DW_CFA_restore_state\n");
3870 case DW_CFA_def_cfa:
3871 fc->cfa_reg = LEB ();
3872 fc->cfa_offset = LEB ();
3874 if (! do_debug_frames_interp)
3875 printf (" DW_CFA_def_cfa: %s ofs %d\n",
3876 regname (fc->cfa_reg, 0), fc->cfa_offset);
3879 case DW_CFA_def_cfa_register:
3880 fc->cfa_reg = LEB ();
3882 if (! do_debug_frames_interp)
3883 printf (" DW_CFA_def_cfa_register: %s\n",
3884 regname (fc->cfa_reg, 0));
3887 case DW_CFA_def_cfa_offset:
3888 fc->cfa_offset = LEB ();
3889 if (! do_debug_frames_interp)
3890 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
3894 if (! do_debug_frames_interp)
3895 printf (" DW_CFA_nop\n");
3898 case DW_CFA_def_cfa_expression:
3900 if (! do_debug_frames_interp)
3902 printf (" DW_CFA_def_cfa_expression (");
3903 decode_location_expression (start, eh_addr_size, ul, 0);
3910 case DW_CFA_expression:
3913 if (! do_debug_frames_interp)
3915 printf (" DW_CFA_expression: %s (",
3917 decode_location_expression (start, eh_addr_size,
3921 fc->col_type[reg] = DW_CFA_expression;
3925 case DW_CFA_val_expression:
3928 if (! do_debug_frames_interp)
3930 printf (" DW_CFA_val_expression: %s (",
3932 decode_location_expression (start, eh_addr_size, ul, 0);
3935 fc->col_type[reg] = DW_CFA_val_expression;
3939 case DW_CFA_offset_extended_sf:
3942 frame_need_space (fc, reg);
3943 if (! do_debug_frames_interp)
3944 printf (" DW_CFA_offset_extended_sf: %s at cfa%+ld\n",
3945 regname (reg, 0), l * fc->data_factor);
3946 fc->col_type[reg] = DW_CFA_offset;
3947 fc->col_offset[reg] = l * fc->data_factor;
3950 case DW_CFA_val_offset_sf:
3953 frame_need_space (fc, reg);
3954 if (! do_debug_frames_interp)
3955 printf (" DW_CFA_val_offset_sf: %s at cfa%+ld\n",
3956 regname (reg, 0), l * fc->data_factor);
3957 fc->col_type[reg] = DW_CFA_val_offset;
3958 fc->col_offset[reg] = l * fc->data_factor;
3961 case DW_CFA_def_cfa_sf:
3962 fc->cfa_reg = LEB ();
3963 fc->cfa_offset = SLEB ();
3964 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3966 if (! do_debug_frames_interp)
3967 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
3968 regname (fc->cfa_reg, 0), fc->cfa_offset);
3971 case DW_CFA_def_cfa_offset_sf:
3972 fc->cfa_offset = SLEB ();
3973 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3974 if (! do_debug_frames_interp)
3975 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
3978 case DW_CFA_MIPS_advance_loc8:
3979 ofs = byte_get (start, 8); start += 8;
3980 if (do_debug_frames_interp)
3981 frame_display_row (fc, &need_col_headers, &max_regs);
3983 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
3984 ofs * fc->code_factor,
3985 fc->pc_begin + ofs * fc->code_factor);
3986 fc->pc_begin += ofs * fc->code_factor;
3989 case DW_CFA_GNU_window_save:
3990 if (! do_debug_frames_interp)
3991 printf (" DW_CFA_GNU_window_save\n");
3994 case DW_CFA_GNU_args_size:
3996 if (! do_debug_frames_interp)
3997 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
4000 case DW_CFA_GNU_negative_offset_extended:
4003 frame_need_space (fc, reg);
4004 if (! do_debug_frames_interp)
4005 printf (" DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n",
4006 regname (reg, 0), l * fc->data_factor);
4007 fc->col_type[reg] = DW_CFA_offset;
4008 fc->col_offset[reg] = l * fc->data_factor;
4012 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
4013 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
4015 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
4020 if (do_debug_frames_interp)
4021 frame_display_row (fc, &need_col_headers, &max_regs);
4036 display_debug_not_supported (struct dwarf_section *section,
4037 void *file ATTRIBUTE_UNUSED)
4039 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4046 cmalloc (size_t nmemb, size_t size)
4048 /* Check for overflow. */
4049 if (nmemb >= ~(size_t) 0 / size)
4052 return malloc (nmemb * size);
4056 xcmalloc (size_t nmemb, size_t size)
4058 /* Check for overflow. */
4059 if (nmemb >= ~(size_t) 0 / size)
4062 return xmalloc (nmemb * size);
4066 xcrealloc (void *ptr, size_t nmemb, size_t size)
4068 /* Check for overflow. */
4069 if (nmemb >= ~(size_t) 0 / size)
4072 return xrealloc (ptr, nmemb * size);
4076 error (const char *message, ...)
4080 va_start (args, message);
4081 fprintf (stderr, _("%s: Error: "), program_name);
4082 vfprintf (stderr, message, args);
4087 warn (const char *message, ...)
4091 va_start (args, message);
4092 fprintf (stderr, _("%s: Warning: "), program_name);
4093 vfprintf (stderr, message, args);
4098 free_debug_memory (void)
4100 enum dwarf_section_display_enum i;
4104 for (i = 0; i < max; i++)
4105 free_debug_section (i);
4107 if (debug_information != NULL)
4109 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
4111 for (i = 0; i < num_debug_info_entries; i++)
4113 if (!debug_information [i].max_loc_offsets)
4115 free (debug_information [i].loc_offsets);
4116 free (debug_information [i].have_frame_base);
4118 if (!debug_information [i].max_range_lists)
4119 free (debug_information [i].range_lists);
4123 free (debug_information);
4124 debug_information = NULL;
4125 num_debug_info_entries = 0;
4129 struct dwarf_section_display debug_displays[] =
4131 { { ".debug_abbrev", NULL, 0, 0 },
4132 display_debug_abbrev, 0, 0 },
4133 { { ".debug_aranges", NULL, 0, 0 },
4134 display_debug_aranges, 0, 0 },
4135 { { ".debug_frame", NULL, 0, 0 },
4136 display_debug_frames, 1, 0 },
4137 { { ".debug_info", NULL, 0, 0 },
4138 display_debug_info, 1, 0 },
4139 { { ".debug_line", NULL, 0, 0 },
4140 display_debug_lines, 0, 0 },
4141 { { ".debug_pubnames", NULL, 0, 0 },
4142 display_debug_pubnames, 0, 0 },
4143 { { ".eh_frame", NULL, 0, 0 },
4144 display_debug_frames, 1, 1 },
4145 { { ".debug_macinfo", NULL, 0, 0 },
4146 display_debug_macinfo, 0, 0 },
4147 { { ".debug_str", NULL, 0, 0 },
4148 display_debug_str, 0, 0 },
4149 { { ".debug_loc", NULL, 0, 0 },
4150 display_debug_loc, 0, 0 },
4151 { { ".debug_pubtypes", NULL, 0, 0 },
4152 display_debug_pubnames, 0, 0 },
4153 { { ".debug_ranges", NULL, 0, 0 },
4154 display_debug_ranges, 0, 0 },
4155 { { ".debug_static_func", NULL, 0, 0 },
4156 display_debug_not_supported, 0, 0 },
4157 { { ".debug_static_vars", NULL, 0, 0 },
4158 display_debug_not_supported, 0, 0 },
4159 { { ".debug_types", NULL, 0, 0 },
4160 display_debug_not_supported, 0, 0 },
4161 { { ".debug_weaknames", NULL, 0, 0 },
4162 display_debug_not_supported, 0, 0 }