1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
26 #include "elf/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 short length;
2622 unsigned long offset;
2623 unsigned int pointer_size;
2624 unsigned long cu_offset;
2625 unsigned long base_address;
2626 int need_frame_base;
2629 pointer_size = debug_information [i].pointer_size;
2630 cu_offset = debug_information [i].cu_offset;
2632 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
2634 has_frame_base = debug_information [i].have_frame_base [j];
2635 /* DWARF sections under Mach-O have non-zero addresses. */
2636 offset = debug_information [i].loc_offsets [j] - section->address;
2637 next = section_begin + offset;
2638 base_address = debug_information [i].base_address;
2640 if (!seen_first_offset)
2641 seen_first_offset = 1;
2645 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
2646 (long)(start - section_begin), (long)(next - section_begin));
2647 else if (start > next)
2648 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
2649 (long)(start - section_begin), (long)(next - section_begin));
2653 if (offset >= bytes)
2655 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
2662 if (start + 2 * pointer_size > section_end)
2664 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2669 begin = byte_get (start, pointer_size);
2670 start += pointer_size;
2671 end = byte_get (start, pointer_size);
2672 start += pointer_size;
2674 if (begin == 0 && end == 0)
2676 printf (_(" %8.8lx <End of list>\n"), offset);
2680 /* Check base address specifiers. */
2681 if (begin == -1UL && end != -1UL)
2684 printf (_(" %8.8lx %8.8lx %8.8lx (base address)\n"),
2685 offset, begin, end);
2689 if (start + 2 > section_end)
2691 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2696 length = byte_get (start, 2);
2699 if (start + length > section_end)
2701 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2706 printf (" %8.8lx %8.8lx %8.8lx (",
2707 offset, begin + base_address, end + base_address);
2708 need_frame_base = decode_location_expression (start,
2714 if (need_frame_base && !has_frame_base)
2715 printf (_(" [without DW_AT_frame_base]"));
2718 fputs (_(" (start == end)"), stdout);
2719 else if (begin > end)
2720 fputs (_(" (start > end)"), stdout);
2729 if (start < section_end)
2730 warn (_("There are %ld unused bytes at the end of section %s\n"),
2731 (long) (section_end - start), section->name);
2736 display_debug_str (struct dwarf_section *section,
2737 void *file ATTRIBUTE_UNUSED)
2739 unsigned char *start = section->start;
2740 unsigned long bytes = section->size;
2741 dwarf_vma addr = section->address;
2745 printf (_("\nThe %s section is empty.\n"), section->name);
2749 printf (_("Contents of the %s section:\n\n"), section->name);
2757 lbytes = (bytes > 16 ? 16 : bytes);
2759 printf (" 0x%8.8lx ", (unsigned long) addr);
2761 for (j = 0; j < 16; j++)
2764 printf ("%2.2x", start[j]);
2772 for (j = 0; j < lbytes; j++)
2775 if (k >= ' ' && k < 0x80)
2794 display_debug_info (struct dwarf_section *section, void *file)
2796 return process_debug_info (section, file, 0);
2801 display_debug_aranges (struct dwarf_section *section,
2802 void *file ATTRIBUTE_UNUSED)
2804 unsigned char *start = section->start;
2805 unsigned char *end = start + section->size;
2807 printf (_("The section %s contains:\n\n"), section->name);
2809 /* It does not matter if this load fails,
2810 we test for that later on. */
2811 load_debug_info (file);
2815 unsigned char *hdrptr;
2816 DWARF2_Internal_ARange arange;
2817 unsigned char *ranges;
2818 unsigned long length;
2819 unsigned long address;
2820 unsigned char address_size;
2823 int initial_length_size;
2827 arange.ar_length = byte_get (hdrptr, 4);
2830 if (arange.ar_length == 0xffffffff)
2832 arange.ar_length = byte_get (hdrptr, 8);
2835 initial_length_size = 12;
2840 initial_length_size = 4;
2843 arange.ar_version = byte_get (hdrptr, 2);
2846 arange.ar_info_offset = byte_get (hdrptr, offset_size);
2847 hdrptr += offset_size;
2849 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
2850 && num_debug_info_entries > 0
2851 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
2852 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2853 arange.ar_info_offset, section->name);
2855 arange.ar_pointer_size = byte_get (hdrptr, 1);
2858 arange.ar_segment_size = byte_get (hdrptr, 1);
2861 if (arange.ar_version != 2 && arange.ar_version != 3)
2863 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
2867 printf (_(" Length: %ld\n"), arange.ar_length);
2868 printf (_(" Version: %d\n"), arange.ar_version);
2869 printf (_(" Offset into .debug_info: 0x%lx\n"), arange.ar_info_offset);
2870 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
2871 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
2873 address_size = arange.ar_pointer_size + arange.ar_segment_size;
2875 /* The DWARF spec does not require that the address size be a power
2876 of two, but we do. This will have to change if we ever encounter
2877 an uneven architecture. */
2878 if ((address_size & (address_size - 1)) != 0)
2880 warn (_("Pointer size + Segment size is not a power of two.\n"));
2884 if (address_size > 4)
2885 printf (_("\n Address Length\n"));
2887 printf (_("\n Address Length\n"));
2891 /* Must pad to an alignment boundary that is twice the address size. */
2892 excess = (hdrptr - start) % (2 * address_size);
2894 ranges += (2 * address_size) - excess;
2896 start += arange.ar_length + initial_length_size;
2898 while (ranges + 2 * address_size <= start)
2900 address = byte_get (ranges, address_size);
2902 ranges += address_size;
2904 length = byte_get (ranges, address_size);
2906 ranges += address_size;
2908 if (address_size > 4)
2909 printf (" 0x%16.16lx 0x%lx\n", address, length);
2911 printf (" 0x%8.8lx 0x%lx\n", address, length);
2921 display_debug_ranges (struct dwarf_section *section,
2922 void *file ATTRIBUTE_UNUSED)
2924 unsigned char *start = section->start;
2925 unsigned char *section_end;
2926 unsigned long bytes;
2927 unsigned char *section_begin = start;
2928 unsigned int num_range_list = 0;
2929 unsigned long last_offset = 0;
2930 unsigned int first = 0;
2933 int seen_first_offset = 0;
2934 int use_debug_info = 1;
2935 unsigned char *next;
2937 bytes = section->size;
2938 section_end = start + bytes;
2942 printf (_("\nThe %s section is empty.\n"), section->name);
2946 if (load_debug_info (file) == 0)
2948 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2953 /* Check the order of range list in .debug_info section. If
2954 offsets of range lists are in the ascending order, we can
2955 use `debug_information' directly. */
2956 for (i = 0; i < num_debug_info_entries; i++)
2960 num = debug_information [i].num_range_lists;
2961 num_range_list += num;
2963 /* Check if we can use `debug_information' directly. */
2964 if (use_debug_info && num != 0)
2966 if (!seen_first_offset)
2968 /* This is the first range list. */
2969 last_offset = debug_information [i].range_lists [0];
2971 seen_first_offset = 1;
2977 for (; j < num; j++)
2980 debug_information [i].range_lists [j])
2985 last_offset = debug_information [i].range_lists [j];
2990 if (!use_debug_info)
2991 /* FIXME: Should we handle this case? */
2992 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
2994 if (!seen_first_offset)
2995 error (_("No range lists in .debug_info section!\n"));
2997 /* DWARF sections under Mach-O have non-zero addresses. */
2998 if (debug_information [first].num_range_lists > 0
2999 && debug_information [first].range_lists [0] != section->address)
3000 warn (_("Range lists in %s section start at 0x%lx\n"),
3001 section->name, debug_information [first].range_lists [0]);
3003 printf (_("Contents of the %s section:\n\n"), section->name);
3004 printf (_(" Offset Begin End\n"));
3006 seen_first_offset = 0;
3007 for (i = first; i < num_debug_info_entries; i++)
3009 unsigned long begin;
3011 unsigned long offset;
3012 unsigned int pointer_size;
3013 unsigned long base_address;
3015 pointer_size = debug_information [i].pointer_size;
3017 for (j = 0; j < debug_information [i].num_range_lists; j++)
3019 /* DWARF sections under Mach-O have non-zero addresses. */
3020 offset = debug_information [i].range_lists [j] - section->address;
3021 next = section_begin + offset;
3022 base_address = debug_information [i].base_address;
3024 if (!seen_first_offset)
3025 seen_first_offset = 1;
3029 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3030 (long)(start - section_begin),
3031 (long)(next - section_begin), section->name);
3032 else if (start > next)
3033 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3034 (long)(start - section_begin),
3035 (long)(next - section_begin), section->name);
3041 begin = byte_get (start, pointer_size);
3042 start += pointer_size;
3043 end = byte_get (start, pointer_size);
3044 start += pointer_size;
3046 if (begin == 0 && end == 0)
3048 printf (_(" %8.8lx <End of list>\n"), offset);
3052 /* Check base address specifiers. */
3053 if (begin == -1UL && end != -1UL)
3056 printf (" %8.8lx %8.8lx %8.8lx (base address)\n",
3057 offset, begin, end);
3061 printf (" %8.8lx %8.8lx %8.8lx",
3062 offset, begin + base_address, end + base_address);
3065 fputs (_(" (start == end)"), stdout);
3066 else if (begin > end)
3067 fputs (_(" (start > end)"), stdout);
3077 typedef struct Frame_Chunk
3079 struct Frame_Chunk *next;
3080 unsigned char *chunk_start;
3082 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3083 short int *col_type;
3086 unsigned int code_factor;
3088 unsigned long pc_begin;
3089 unsigned long pc_range;
3093 unsigned char fde_encoding;
3094 unsigned char cfa_exp;
3098 /* A marker for a col_type that means this column was never referenced
3099 in the frame info. */
3100 #define DW_CFA_unreferenced (-1)
3103 frame_need_space (Frame_Chunk *fc, int reg)
3105 int prev = fc->ncols;
3107 if (reg < fc->ncols)
3110 fc->ncols = reg + 1;
3111 fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int));
3112 fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
3114 while (prev < fc->ncols)
3116 fc->col_type[prev] = DW_CFA_unreferenced;
3117 fc->col_offset[prev] = 0;
3122 static const char *const dwarf_regnames_i386[] =
3124 "eax", "ecx", "edx", "ebx",
3125 "esp", "ebp", "esi", "edi",
3126 "eip", "eflags", NULL,
3127 "st0", "st1", "st2", "st3",
3128 "st4", "st5", "st6", "st7",
3130 "xmm0", "xmm1", "xmm2", "xmm3",
3131 "xmm4", "xmm5", "xmm6", "xmm7",
3132 "mm0", "mm1", "mm2", "mm3",
3133 "mm4", "mm5", "mm6", "mm7",
3134 "fcw", "fsw", "mxcsr",
3135 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3139 static const char *const dwarf_regnames_x86_64[] =
3141 "rax", "rdx", "rcx", "rbx",
3142 "rsi", "rdi", "rbp", "rsp",
3143 "r8", "r9", "r10", "r11",
3144 "r12", "r13", "r14", "r15",
3146 "xmm0", "xmm1", "xmm2", "xmm3",
3147 "xmm4", "xmm5", "xmm6", "xmm7",
3148 "xmm8", "xmm9", "xmm10", "xmm11",
3149 "xmm12", "xmm13", "xmm14", "xmm15",
3150 "st0", "st1", "st2", "st3",
3151 "st4", "st5", "st6", "st7",
3152 "mm0", "mm1", "mm2", "mm3",
3153 "mm4", "mm5", "mm6", "mm7",
3155 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3156 "fs.base", "gs.base", NULL, NULL,
3158 "mxcsr", "fcw", "fsw"
3161 static const char *const *dwarf_regnames;
3162 static unsigned int dwarf_regnames_count;
3165 init_dwarf_regnames (unsigned int e_machine)
3171 dwarf_regnames = dwarf_regnames_i386;
3172 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
3176 dwarf_regnames = dwarf_regnames_x86_64;
3177 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
3186 regname (unsigned int regno, int row)
3188 static char reg[64];
3190 && regno < dwarf_regnames_count
3191 && dwarf_regnames [regno] != NULL)
3194 return dwarf_regnames [regno];
3195 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
3196 dwarf_regnames [regno]);
3199 snprintf (reg, sizeof (reg), "r%d", regno);
3204 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
3209 if (*max_regs < fc->ncols)
3210 *max_regs = fc->ncols;
3212 if (*need_col_headers)
3214 static const char *loc = " LOC";
3216 *need_col_headers = 0;
3218 printf ("%-*s CFA ", eh_addr_size * 2, loc);
3220 for (r = 0; r < *max_regs; r++)
3221 if (fc->col_type[r] != DW_CFA_unreferenced)
3226 printf ("%-5s ", regname (r, 1));
3232 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
3234 strcpy (tmp, "exp");
3236 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
3237 printf ("%-8s ", tmp);
3239 for (r = 0; r < fc->ncols; r++)
3241 if (fc->col_type[r] != DW_CFA_unreferenced)
3243 switch (fc->col_type[r])
3245 case DW_CFA_undefined:
3248 case DW_CFA_same_value:
3252 sprintf (tmp, "c%+d", fc->col_offset[r]);
3254 case DW_CFA_val_offset:
3255 sprintf (tmp, "v%+d", fc->col_offset[r]);
3257 case DW_CFA_register:
3258 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
3260 case DW_CFA_expression:
3261 strcpy (tmp, "exp");
3263 case DW_CFA_val_expression:
3264 strcpy (tmp, "vexp");
3267 strcpy (tmp, "n/a");
3270 printf ("%-5s ", tmp);
3277 size_of_encoded_value (int encoding)
3279 switch (encoding & 0x7)
3282 case 0: return eh_addr_size;
3290 get_encoded_value (unsigned char *data, int encoding)
3292 int size = size_of_encoded_value (encoding);
3294 if (encoding & DW_EH_PE_signed)
3295 return byte_get_signed (data, size);
3297 return byte_get (data, size);
3300 #define GET(N) byte_get (start, N); start += N
3301 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3302 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3305 display_debug_frames (struct dwarf_section *section,
3306 void *file ATTRIBUTE_UNUSED)
3308 unsigned char *start = section->start;
3309 unsigned char *end = start + section->size;
3310 unsigned char *section_start = start;
3311 Frame_Chunk *chunks = 0;
3312 Frame_Chunk *remembered_state = 0;
3314 int is_eh = strcmp (section->name, ".eh_frame") == 0;
3315 unsigned int length_return;
3318 printf (_("The section %s contains:\n"), section->name);
3322 unsigned char *saved_start;
3323 unsigned char *block_end;
3324 unsigned long length;
3325 unsigned long cie_id;
3328 int need_col_headers = 1;
3329 unsigned char *augmentation_data = NULL;
3330 unsigned long augmentation_data_len = 0;
3331 int encoded_ptr_size = eh_addr_size;
3333 int initial_length_size;
3335 saved_start = start;
3336 length = byte_get (start, 4); start += 4;
3340 printf ("\n%08lx ZERO terminator\n\n",
3341 (unsigned long)(saved_start - section_start));
3345 if (length == 0xffffffff)
3347 length = byte_get (start, 8);
3350 initial_length_size = 12;
3355 initial_length_size = 4;
3358 block_end = saved_start + length + initial_length_size;
3359 if (block_end > end)
3361 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3362 length, (unsigned long)(saved_start - section_start));
3365 cie_id = byte_get (start, offset_size); start += offset_size;
3367 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
3371 fc = xmalloc (sizeof (Frame_Chunk));
3372 memset (fc, 0, sizeof (Frame_Chunk));
3376 fc->chunk_start = saved_start;
3378 fc->col_type = xmalloc (sizeof (short int));
3379 fc->col_offset = xmalloc (sizeof (int));
3380 frame_need_space (fc, max_regs - 1);
3384 fc->augmentation = (char *) start;
3385 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
3387 if (fc->augmentation[0] == 'z')
3389 fc->code_factor = LEB ();
3390 fc->data_factor = SLEB ();
3399 augmentation_data_len = LEB ();
3400 augmentation_data = start;
3401 start += augmentation_data_len;
3403 else if (strcmp (fc->augmentation, "eh") == 0)
3405 start += eh_addr_size;
3406 fc->code_factor = LEB ();
3407 fc->data_factor = SLEB ();
3419 fc->code_factor = LEB ();
3420 fc->data_factor = SLEB ();
3432 if (do_debug_frames_interp)
3433 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3434 (unsigned long)(saved_start - section_start), length, cie_id,
3435 fc->augmentation, fc->code_factor, fc->data_factor,
3439 printf ("\n%08lx %08lx %08lx CIE\n",
3440 (unsigned long)(saved_start - section_start), length, cie_id);
3441 printf (" Version: %d\n", version);
3442 printf (" Augmentation: \"%s\"\n", fc->augmentation);
3443 printf (" Code alignment factor: %u\n", fc->code_factor);
3444 printf (" Data alignment factor: %d\n", fc->data_factor);
3445 printf (" Return address column: %d\n", fc->ra);
3447 if (augmentation_data_len)
3450 printf (" Augmentation data: ");
3451 for (i = 0; i < augmentation_data_len; ++i)
3452 printf (" %02x", augmentation_data[i]);
3458 if (augmentation_data_len)
3460 unsigned char *p, *q;
3461 p = (unsigned char *) fc->augmentation + 1;
3462 q = augmentation_data;
3469 q += 1 + size_of_encoded_value (*q);
3471 fc->fde_encoding = *q++;
3477 if (fc->fde_encoding)
3478 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3481 frame_need_space (fc, fc->ra);
3485 unsigned char *look_for;
3486 static Frame_Chunk fde_fc;
3489 memset (fc, 0, sizeof (Frame_Chunk));
3491 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
3493 for (cie = chunks; cie ; cie = cie->next)
3494 if (cie->chunk_start == look_for)
3499 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
3500 cie_id, (unsigned long)(saved_start - section_start));
3502 fc->col_type = xmalloc (sizeof (short int));
3503 fc->col_offset = xmalloc (sizeof (int));
3504 frame_need_space (fc, max_regs - 1);
3506 fc->augmentation = "";
3507 fc->fde_encoding = 0;
3511 fc->ncols = cie->ncols;
3512 fc->col_type = xcmalloc (fc->ncols, sizeof (short int));
3513 fc->col_offset = xcmalloc (fc->ncols, sizeof (int));
3514 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
3515 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
3516 fc->augmentation = cie->augmentation;
3517 fc->code_factor = cie->code_factor;
3518 fc->data_factor = cie->data_factor;
3519 fc->cfa_reg = cie->cfa_reg;
3520 fc->cfa_offset = cie->cfa_offset;
3522 frame_need_space (fc, max_regs - 1);
3523 fc->fde_encoding = cie->fde_encoding;
3526 if (fc->fde_encoding)
3527 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3529 fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
3530 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
3531 fc->pc_begin += section->address + (start - section_start);
3532 start += encoded_ptr_size;
3533 fc->pc_range = byte_get (start, encoded_ptr_size);
3534 start += encoded_ptr_size;
3536 if (cie->augmentation[0] == 'z')
3538 augmentation_data_len = LEB ();
3539 augmentation_data = start;
3540 start += augmentation_data_len;
3543 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
3544 (unsigned long)(saved_start - section_start), length, cie_id,
3545 (unsigned long)(cie->chunk_start - section_start),
3546 fc->pc_begin, fc->pc_begin + fc->pc_range);
3547 if (! do_debug_frames_interp && augmentation_data_len)
3551 printf (" Augmentation data: ");
3552 for (i = 0; i < augmentation_data_len; ++i)
3553 printf (" %02x", augmentation_data[i]);
3559 /* At this point, fc is the current chunk, cie (if any) is set, and
3560 we're about to interpret instructions for the chunk. */
3561 /* ??? At present we need to do this always, since this sizes the
3562 fc->col_type and fc->col_offset arrays, which we write into always.
3563 We should probably split the interpreted and non-interpreted bits
3564 into two different routines, since there's so much that doesn't
3565 really overlap between them. */
3566 if (1 || do_debug_frames_interp)
3568 /* Start by making a pass over the chunk, allocating storage
3569 and taking note of what registers are used. */
3570 unsigned char *tmp = start;
3572 while (start < block_end)
3575 unsigned long reg, tmp;
3582 /* Warning: if you add any more cases to this switch, be
3583 sure to add them to the corresponding switch below. */
3586 case DW_CFA_advance_loc:
3590 frame_need_space (fc, opa);
3591 fc->col_type[opa] = DW_CFA_undefined;
3593 case DW_CFA_restore:
3594 frame_need_space (fc, opa);
3595 fc->col_type[opa] = DW_CFA_undefined;
3597 case DW_CFA_set_loc:
3598 start += encoded_ptr_size;
3600 case DW_CFA_advance_loc1:
3603 case DW_CFA_advance_loc2:
3606 case DW_CFA_advance_loc4:
3609 case DW_CFA_offset_extended:
3610 case DW_CFA_val_offset:
3611 reg = LEB (); LEB ();
3612 frame_need_space (fc, reg);
3613 fc->col_type[reg] = DW_CFA_undefined;
3615 case DW_CFA_restore_extended:
3617 frame_need_space (fc, reg);
3618 fc->col_type[reg] = DW_CFA_undefined;
3620 case DW_CFA_undefined:
3622 frame_need_space (fc, reg);
3623 fc->col_type[reg] = DW_CFA_undefined;
3625 case DW_CFA_same_value:
3627 frame_need_space (fc, reg);
3628 fc->col_type[reg] = DW_CFA_undefined;
3630 case DW_CFA_register:
3631 reg = LEB (); LEB ();
3632 frame_need_space (fc, reg);
3633 fc->col_type[reg] = DW_CFA_undefined;
3635 case DW_CFA_def_cfa:
3638 case DW_CFA_def_cfa_register:
3641 case DW_CFA_def_cfa_offset:
3644 case DW_CFA_def_cfa_expression:
3648 case DW_CFA_expression:
3649 case DW_CFA_val_expression:
3653 frame_need_space (fc, reg);
3654 fc->col_type[reg] = DW_CFA_undefined;
3656 case DW_CFA_offset_extended_sf:
3657 case DW_CFA_val_offset_sf:
3658 reg = LEB (); SLEB ();
3659 frame_need_space (fc, reg);
3660 fc->col_type[reg] = DW_CFA_undefined;
3662 case DW_CFA_def_cfa_sf:
3665 case DW_CFA_def_cfa_offset_sf:
3668 case DW_CFA_MIPS_advance_loc8:
3671 case DW_CFA_GNU_args_size:
3674 case DW_CFA_GNU_negative_offset_extended:
3675 reg = LEB (); LEB ();
3676 frame_need_space (fc, reg);
3677 fc->col_type[reg] = DW_CFA_undefined;
3686 /* Now we know what registers are used, make a second pass over
3687 the chunk, this time actually printing out the info. */
3689 while (start < block_end)
3692 unsigned long ul, reg, roffs;
3701 /* Warning: if you add any more cases to this switch, be
3702 sure to add them to the corresponding switch above. */
3705 case DW_CFA_advance_loc:
3706 if (do_debug_frames_interp)
3707 frame_display_row (fc, &need_col_headers, &max_regs);
3709 printf (" DW_CFA_advance_loc: %d to %08lx\n",
3710 opa * fc->code_factor,
3711 fc->pc_begin + opa * fc->code_factor);
3712 fc->pc_begin += opa * fc->code_factor;
3717 if (! do_debug_frames_interp)
3718 printf (" DW_CFA_offset: %s at cfa%+ld\n",
3719 regname (opa, 0), roffs * fc->data_factor);
3720 fc->col_type[opa] = DW_CFA_offset;
3721 fc->col_offset[opa] = roffs * fc->data_factor;
3724 case DW_CFA_restore:
3725 if (! do_debug_frames_interp)
3726 printf (" DW_CFA_restore: %s\n", regname (opa, 0));
3727 fc->col_type[opa] = cie->col_type[opa];
3728 fc->col_offset[opa] = cie->col_offset[opa];
3731 case DW_CFA_set_loc:
3732 vma = get_encoded_value (start, fc->fde_encoding);
3733 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
3734 vma += section->address + (start - section_start);
3735 start += encoded_ptr_size;
3736 if (do_debug_frames_interp)
3737 frame_display_row (fc, &need_col_headers, &max_regs);
3739 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
3743 case DW_CFA_advance_loc1:
3744 ofs = byte_get (start, 1); start += 1;
3745 if (do_debug_frames_interp)
3746 frame_display_row (fc, &need_col_headers, &max_regs);
3748 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
3749 ofs * fc->code_factor,
3750 fc->pc_begin + ofs * fc->code_factor);
3751 fc->pc_begin += ofs * fc->code_factor;
3754 case DW_CFA_advance_loc2:
3755 ofs = byte_get (start, 2); start += 2;
3756 if (do_debug_frames_interp)
3757 frame_display_row (fc, &need_col_headers, &max_regs);
3759 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
3760 ofs * fc->code_factor,
3761 fc->pc_begin + ofs * fc->code_factor);
3762 fc->pc_begin += ofs * fc->code_factor;
3765 case DW_CFA_advance_loc4:
3766 ofs = byte_get (start, 4); start += 4;
3767 if (do_debug_frames_interp)
3768 frame_display_row (fc, &need_col_headers, &max_regs);
3770 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
3771 ofs * fc->code_factor,
3772 fc->pc_begin + ofs * fc->code_factor);
3773 fc->pc_begin += ofs * fc->code_factor;
3776 case DW_CFA_offset_extended:
3779 if (! do_debug_frames_interp)
3780 printf (" DW_CFA_offset_extended: %s at cfa%+ld\n",
3781 regname (reg, 0), roffs * fc->data_factor);
3782 fc->col_type[reg] = DW_CFA_offset;
3783 fc->col_offset[reg] = roffs * fc->data_factor;
3786 case DW_CFA_val_offset:
3789 if (! do_debug_frames_interp)
3790 printf (" DW_CFA_val_offset: %s at cfa%+ld\n",
3791 regname (reg, 0), roffs * fc->data_factor);
3792 fc->col_type[reg] = DW_CFA_val_offset;
3793 fc->col_offset[reg] = roffs * fc->data_factor;
3796 case DW_CFA_restore_extended:
3798 if (! do_debug_frames_interp)
3799 printf (" DW_CFA_restore_extended: %s\n",
3801 fc->col_type[reg] = cie->col_type[reg];
3802 fc->col_offset[reg] = cie->col_offset[reg];
3805 case DW_CFA_undefined:
3807 if (! do_debug_frames_interp)
3808 printf (" DW_CFA_undefined: %s\n", regname (reg, 0));
3809 fc->col_type[reg] = DW_CFA_undefined;
3810 fc->col_offset[reg] = 0;
3813 case DW_CFA_same_value:
3815 if (! do_debug_frames_interp)
3816 printf (" DW_CFA_same_value: %s\n", regname (reg, 0));
3817 fc->col_type[reg] = DW_CFA_same_value;
3818 fc->col_offset[reg] = 0;
3821 case DW_CFA_register:
3824 if (! do_debug_frames_interp)
3826 printf (" DW_CFA_register: %s in ",
3828 puts (regname (roffs, 0));
3830 fc->col_type[reg] = DW_CFA_register;
3831 fc->col_offset[reg] = roffs;
3834 case DW_CFA_remember_state:
3835 if (! do_debug_frames_interp)
3836 printf (" DW_CFA_remember_state\n");
3837 rs = xmalloc (sizeof (Frame_Chunk));
3838 rs->ncols = fc->ncols;
3839 rs->col_type = xcmalloc (rs->ncols, sizeof (short int));
3840 rs->col_offset = xcmalloc (rs->ncols, sizeof (int));
3841 memcpy (rs->col_type, fc->col_type, rs->ncols);
3842 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
3843 rs->next = remembered_state;
3844 remembered_state = rs;
3847 case DW_CFA_restore_state:
3848 if (! do_debug_frames_interp)
3849 printf (" DW_CFA_restore_state\n");
3850 rs = remembered_state;
3853 remembered_state = rs->next;
3854 frame_need_space (fc, rs->ncols - 1);
3855 memcpy (fc->col_type, rs->col_type, rs->ncols);
3856 memcpy (fc->col_offset, rs->col_offset,
3857 rs->ncols * sizeof (int));
3858 free (rs->col_type);
3859 free (rs->col_offset);
3862 else if (do_debug_frames_interp)
3863 printf ("Mismatched DW_CFA_restore_state\n");
3866 case DW_CFA_def_cfa:
3867 fc->cfa_reg = LEB ();
3868 fc->cfa_offset = LEB ();
3870 if (! do_debug_frames_interp)
3871 printf (" DW_CFA_def_cfa: %s ofs %d\n",
3872 regname (fc->cfa_reg, 0), fc->cfa_offset);
3875 case DW_CFA_def_cfa_register:
3876 fc->cfa_reg = LEB ();
3878 if (! do_debug_frames_interp)
3879 printf (" DW_CFA_def_cfa_register: %s\n",
3880 regname (fc->cfa_reg, 0));
3883 case DW_CFA_def_cfa_offset:
3884 fc->cfa_offset = LEB ();
3885 if (! do_debug_frames_interp)
3886 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
3890 if (! do_debug_frames_interp)
3891 printf (" DW_CFA_nop\n");
3894 case DW_CFA_def_cfa_expression:
3896 if (! do_debug_frames_interp)
3898 printf (" DW_CFA_def_cfa_expression (");
3899 decode_location_expression (start, eh_addr_size, ul, 0);
3906 case DW_CFA_expression:
3909 if (! do_debug_frames_interp)
3911 printf (" DW_CFA_expression: %s (",
3913 decode_location_expression (start, eh_addr_size,
3917 fc->col_type[reg] = DW_CFA_expression;
3921 case DW_CFA_val_expression:
3924 if (! do_debug_frames_interp)
3926 printf (" DW_CFA_val_expression: %s (",
3928 decode_location_expression (start, eh_addr_size, ul, 0);
3931 fc->col_type[reg] = DW_CFA_val_expression;
3935 case DW_CFA_offset_extended_sf:
3938 frame_need_space (fc, reg);
3939 if (! do_debug_frames_interp)
3940 printf (" DW_CFA_offset_extended_sf: %s at cfa%+ld\n",
3941 regname (reg, 0), l * fc->data_factor);
3942 fc->col_type[reg] = DW_CFA_offset;
3943 fc->col_offset[reg] = l * fc->data_factor;
3946 case DW_CFA_val_offset_sf:
3949 frame_need_space (fc, reg);
3950 if (! do_debug_frames_interp)
3951 printf (" DW_CFA_val_offset_sf: %s at cfa%+ld\n",
3952 regname (reg, 0), l * fc->data_factor);
3953 fc->col_type[reg] = DW_CFA_val_offset;
3954 fc->col_offset[reg] = l * fc->data_factor;
3957 case DW_CFA_def_cfa_sf:
3958 fc->cfa_reg = LEB ();
3959 fc->cfa_offset = SLEB ();
3960 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3962 if (! do_debug_frames_interp)
3963 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
3964 regname (fc->cfa_reg, 0), fc->cfa_offset);
3967 case DW_CFA_def_cfa_offset_sf:
3968 fc->cfa_offset = SLEB ();
3969 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3970 if (! do_debug_frames_interp)
3971 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
3974 case DW_CFA_MIPS_advance_loc8:
3975 ofs = byte_get (start, 8); start += 8;
3976 if (do_debug_frames_interp)
3977 frame_display_row (fc, &need_col_headers, &max_regs);
3979 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
3980 ofs * fc->code_factor,
3981 fc->pc_begin + ofs * fc->code_factor);
3982 fc->pc_begin += ofs * fc->code_factor;
3985 case DW_CFA_GNU_window_save:
3986 if (! do_debug_frames_interp)
3987 printf (" DW_CFA_GNU_window_save\n");
3990 case DW_CFA_GNU_args_size:
3992 if (! do_debug_frames_interp)
3993 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
3996 case DW_CFA_GNU_negative_offset_extended:
3999 frame_need_space (fc, reg);
4000 if (! do_debug_frames_interp)
4001 printf (" DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n",
4002 regname (reg, 0), l * fc->data_factor);
4003 fc->col_type[reg] = DW_CFA_offset;
4004 fc->col_offset[reg] = l * fc->data_factor;
4008 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
4009 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
4011 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
4016 if (do_debug_frames_interp)
4017 frame_display_row (fc, &need_col_headers, &max_regs);
4032 display_debug_not_supported (struct dwarf_section *section,
4033 void *file ATTRIBUTE_UNUSED)
4035 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4042 cmalloc (size_t nmemb, size_t size)
4044 /* Check for overflow. */
4045 if (nmemb >= ~(size_t) 0 / size)
4048 return malloc (nmemb * size);
4052 xcmalloc (size_t nmemb, size_t size)
4054 /* Check for overflow. */
4055 if (nmemb >= ~(size_t) 0 / size)
4058 return xmalloc (nmemb * size);
4062 xcrealloc (void *ptr, size_t nmemb, size_t size)
4064 /* Check for overflow. */
4065 if (nmemb >= ~(size_t) 0 / size)
4068 return xrealloc (ptr, nmemb * size);
4072 error (const char *message, ...)
4076 va_start (args, message);
4077 fprintf (stderr, _("%s: Error: "), program_name);
4078 vfprintf (stderr, message, args);
4083 warn (const char *message, ...)
4087 va_start (args, message);
4088 fprintf (stderr, _("%s: Warning: "), program_name);
4089 vfprintf (stderr, message, args);
4094 free_debug_memory (void)
4096 enum dwarf_section_display_enum i;
4100 for (i = 0; i < max; i++)
4101 free_debug_section (i);
4103 if (debug_information != NULL)
4105 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
4107 for (i = 0; i < num_debug_info_entries; i++)
4109 if (!debug_information [i].max_loc_offsets)
4111 free (debug_information [i].loc_offsets);
4112 free (debug_information [i].have_frame_base);
4114 if (!debug_information [i].max_range_lists)
4115 free (debug_information [i].range_lists);
4119 free (debug_information);
4120 debug_information = NULL;
4121 num_debug_info_entries = 0;
4125 struct dwarf_section_display debug_displays[] =
4127 { { ".debug_abbrev", NULL, 0, 0 },
4128 display_debug_abbrev, 0, 0 },
4129 { { ".debug_aranges", NULL, 0, 0 },
4130 display_debug_aranges, 0, 0 },
4131 { { ".debug_frame", NULL, 0, 0 },
4132 display_debug_frames, 1, 0 },
4133 { { ".debug_info", NULL, 0, 0 },
4134 display_debug_info, 1, 0 },
4135 { { ".debug_line", NULL, 0, 0 },
4136 display_debug_lines, 0, 0 },
4137 { { ".debug_pubnames", NULL, 0, 0 },
4138 display_debug_pubnames, 0, 0 },
4139 { { ".eh_frame", NULL, 0, 0 },
4140 display_debug_frames, 1, 1 },
4141 { { ".debug_macinfo", NULL, 0, 0 },
4142 display_debug_macinfo, 0, 0 },
4143 { { ".debug_str", NULL, 0, 0 },
4144 display_debug_str, 0, 0 },
4145 { { ".debug_loc", NULL, 0, 0 },
4146 display_debug_loc, 0, 0 },
4147 { { ".debug_pubtypes", NULL, 0, 0 },
4148 display_debug_pubnames, 0, 0 },
4149 { { ".debug_ranges", NULL, 0, 0 },
4150 display_debug_ranges, 0, 0 },
4151 { { ".debug_static_func", NULL, 0, 0 },
4152 display_debug_not_supported, 0, 0 },
4153 { { ".debug_static_vars", NULL, 0, 0 },
4154 display_debug_not_supported, 0, 0 },
4155 { { ".debug_types", NULL, 0, 0 },
4156 display_debug_not_supported, 0, 0 },
4157 { { ".debug_weaknames", NULL, 0, 0 },
4158 display_debug_not_supported, 0, 0 }