1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
26 #include "elf/dwarf2.h"
29 static int have_frame_base;
30 static int need_base_address;
32 static unsigned int last_pointer_size = 0;
33 static int warned_about_missing_comp_units = FALSE;
35 static unsigned int num_debug_info_entries = 0;
36 static debug_info *debug_information = NULL;
38 dwarf_vma eh_addr_size;
43 int do_debug_pubnames;
47 int do_debug_frames_interp;
52 dwarf_vma (*byte_get) (unsigned char *, int);
55 byte_get_little_endian (unsigned char *field, int size)
63 return ((unsigned int) (field[0]))
64 | (((unsigned int) (field[1])) << 8);
67 return ((unsigned long) (field[0]))
68 | (((unsigned long) (field[1])) << 8)
69 | (((unsigned long) (field[2])) << 16)
70 | (((unsigned long) (field[3])) << 24);
73 if (sizeof (dwarf_vma) == 8)
74 return ((dwarf_vma) (field[0]))
75 | (((dwarf_vma) (field[1])) << 8)
76 | (((dwarf_vma) (field[2])) << 16)
77 | (((dwarf_vma) (field[3])) << 24)
78 | (((dwarf_vma) (field[4])) << 32)
79 | (((dwarf_vma) (field[5])) << 40)
80 | (((dwarf_vma) (field[6])) << 48)
81 | (((dwarf_vma) (field[7])) << 56);
82 else if (sizeof (dwarf_vma) == 4)
83 /* We want to extract data from an 8 byte wide field and
84 place it into a 4 byte wide field. Since this is a little
85 endian source we can just use the 4 byte extraction code. */
86 return ((unsigned long) (field[0]))
87 | (((unsigned long) (field[1])) << 8)
88 | (((unsigned long) (field[2])) << 16)
89 | (((unsigned long) (field[3])) << 24);
92 error (_("Unhandled data length: %d\n"), size);
98 byte_get_big_endian (unsigned char *field, int size)
106 return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
109 return ((unsigned long) (field[3]))
110 | (((unsigned long) (field[2])) << 8)
111 | (((unsigned long) (field[1])) << 16)
112 | (((unsigned long) (field[0])) << 24);
115 if (sizeof (dwarf_vma) == 8)
116 return ((dwarf_vma) (field[7]))
117 | (((dwarf_vma) (field[6])) << 8)
118 | (((dwarf_vma) (field[5])) << 16)
119 | (((dwarf_vma) (field[4])) << 24)
120 | (((dwarf_vma) (field[3])) << 32)
121 | (((dwarf_vma) (field[2])) << 40)
122 | (((dwarf_vma) (field[1])) << 48)
123 | (((dwarf_vma) (field[0])) << 56);
124 else if (sizeof (dwarf_vma) == 4)
126 /* Although we are extracing data from an 8 byte wide field,
127 we are returning only 4 bytes of data. */
129 return ((unsigned long) (field[3]))
130 | (((unsigned long) (field[2])) << 8)
131 | (((unsigned long) (field[1])) << 16)
132 | (((unsigned long) (field[0])) << 24);
136 error (_("Unhandled data length: %d\n"), size);
142 byte_get_signed (unsigned char *field, int size)
144 dwarf_vma x = byte_get (field, size);
149 return (x ^ 0x80) - 0x80;
151 return (x ^ 0x8000) - 0x8000;
153 return (x ^ 0x80000000) - 0x80000000;
161 static unsigned long int
162 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
164 unsigned long int result = 0;
165 unsigned int num_read = 0;
166 unsigned int shift = 0;
174 result |= ((unsigned long int) (byte & 0x7f)) << shift;
181 if (length_return != NULL)
182 *length_return = num_read;
184 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
185 result |= -1L << shift;
190 typedef struct State_Machine_Registers
192 unsigned long address;
199 /* This variable hold the number of the last entry seen
200 in the File Table. */
201 unsigned int last_file_entry;
204 static SMR state_machine_regs;
207 reset_state_machine (int is_stmt)
209 state_machine_regs.address = 0;
210 state_machine_regs.file = 1;
211 state_machine_regs.line = 1;
212 state_machine_regs.column = 0;
213 state_machine_regs.is_stmt = is_stmt;
214 state_machine_regs.basic_block = 0;
215 state_machine_regs.end_sequence = 0;
216 state_machine_regs.last_file_entry = 0;
219 /* Handled an extend line op.
220 Returns the number of bytes read. */
223 process_extended_line_op (unsigned char *data, int is_stmt)
225 unsigned char op_code;
226 unsigned int bytes_read;
231 len = read_leb128 (data, & bytes_read, 0);
236 warn (_("badly formed extended line op encountered!\n"));
243 printf (_(" Extended opcode %d: "), op_code);
247 case DW_LNE_end_sequence:
248 printf (_("End of Sequence\n\n"));
249 reset_state_machine (is_stmt);
252 case DW_LNE_set_address:
253 adr = byte_get (data, len - bytes_read - 1);
254 printf (_("set Address to 0x%lx\n"), adr);
255 state_machine_regs.address = adr;
258 case DW_LNE_define_file:
259 printf (_(" define new File Table entry\n"));
260 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
262 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
264 data += strlen ((char *) data) + 1;
265 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
267 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
269 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
270 printf (_("%s\n\n"), name);
274 case DW_LNE_HP_negate_is_UV_update:
275 printf ("DW_LNE_HP_negate_is_UV_update");
277 case DW_LNE_HP_push_context:
278 printf ("DW_LNE_HP_push_context");
280 case DW_LNE_HP_pop_context:
281 printf ("DW_LNE_HP_pop_context");
283 case DW_LNE_HP_set_file_line_column:
284 printf ("DW_LNE_HP_set_file_line_column");
286 case DW_LNE_HP_set_routine_name:
287 printf ("DW_LNE_HP_set_routine_name");
289 case DW_LNE_HP_set_sequence:
290 printf ("DW_LNE_HP_set_sequence");
292 case DW_LNE_HP_negate_post_semantics:
293 printf ("DW_LNE_HP_negate_post_semantics");
295 case DW_LNE_HP_negate_function_exit:
296 printf ("DW_LNE_HP_negate_function_exit");
298 case DW_LNE_HP_negate_front_end_logical:
299 printf ("DW_LNE_HP_negate_front_end_logical");
301 case DW_LNE_HP_define_proc:
302 printf ("DW_LNE_HP_define_proc");
306 if (op_code >= DW_LNE_lo_user
307 /* The test against DW_LNW_hi_user is redundant due to
308 the limited range of the unsigned char data type used
310 /*&& op_code <= DW_LNE_hi_user*/)
311 printf (_("user defined: length %d\n"), len - bytes_read);
313 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
321 fetch_indirect_string (unsigned long offset)
323 struct dwarf_section *section = &debug_displays [str].section;
325 if (section->start == NULL)
326 return _("<no .debug_str section>");
328 /* DWARF sections under Mach-O have non-zero addresses. */
329 offset -= section->address;
330 if (offset > section->size)
332 warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
333 return _("<offset is too big>");
336 return (const char *) section->start + offset;
339 /* FIXME: There are better and more efficient ways to handle
340 these structures. For now though, I just want something that
341 is simple to implement. */
342 typedef struct abbrev_attr
344 unsigned long attribute;
346 struct abbrev_attr *next;
350 typedef struct abbrev_entry
355 struct abbrev_attr *first_attr;
356 struct abbrev_attr *last_attr;
357 struct abbrev_entry *next;
361 static abbrev_entry *first_abbrev = NULL;
362 static abbrev_entry *last_abbrev = NULL;
367 abbrev_entry *abbrev;
369 for (abbrev = first_abbrev; abbrev;)
371 abbrev_entry *next = abbrev->next;
374 for (attr = abbrev->first_attr; attr;)
376 abbrev_attr *next = attr->next;
386 last_abbrev = first_abbrev = NULL;
390 add_abbrev (unsigned long number, unsigned long tag, int children)
394 entry = malloc (sizeof (*entry));
400 entry->entry = number;
402 entry->children = children;
403 entry->first_attr = NULL;
404 entry->last_attr = NULL;
407 if (first_abbrev == NULL)
408 first_abbrev = entry;
410 last_abbrev->next = entry;
416 add_abbrev_attr (unsigned long attribute, unsigned long form)
420 attr = malloc (sizeof (*attr));
426 attr->attribute = attribute;
430 if (last_abbrev->first_attr == NULL)
431 last_abbrev->first_attr = attr;
433 last_abbrev->last_attr->next = attr;
435 last_abbrev->last_attr = attr;
438 /* Processes the (partial) contents of a .debug_abbrev section.
439 Returns NULL if the end of the section was encountered.
440 Returns the address after the last byte read if the end of
441 an abbreviation set was found. */
443 static unsigned char *
444 process_abbrev_section (unsigned char *start, unsigned char *end)
446 if (first_abbrev != NULL)
451 unsigned int bytes_read;
454 unsigned long attribute;
457 entry = read_leb128 (start, & bytes_read, 0);
460 /* A single zero is supposed to end the section according
461 to the standard. If there's more, then signal that to
464 return start == end ? NULL : start;
466 tag = read_leb128 (start, & bytes_read, 0);
471 add_abbrev (entry, tag, children);
477 attribute = read_leb128 (start, & bytes_read, 0);
480 form = read_leb128 (start, & bytes_read, 0);
484 add_abbrev_attr (attribute, form);
486 while (attribute != 0);
493 get_TAG_name (unsigned long tag)
497 case DW_TAG_padding: return "DW_TAG_padding";
498 case DW_TAG_array_type: return "DW_TAG_array_type";
499 case DW_TAG_class_type: return "DW_TAG_class_type";
500 case DW_TAG_entry_point: return "DW_TAG_entry_point";
501 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
502 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
503 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
504 case DW_TAG_label: return "DW_TAG_label";
505 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
506 case DW_TAG_member: return "DW_TAG_member";
507 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
508 case DW_TAG_reference_type: return "DW_TAG_reference_type";
509 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
510 case DW_TAG_string_type: return "DW_TAG_string_type";
511 case DW_TAG_structure_type: return "DW_TAG_structure_type";
512 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
513 case DW_TAG_typedef: return "DW_TAG_typedef";
514 case DW_TAG_union_type: return "DW_TAG_union_type";
515 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
516 case DW_TAG_variant: return "DW_TAG_variant";
517 case DW_TAG_common_block: return "DW_TAG_common_block";
518 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
519 case DW_TAG_inheritance: return "DW_TAG_inheritance";
520 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
521 case DW_TAG_module: return "DW_TAG_module";
522 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
523 case DW_TAG_set_type: return "DW_TAG_set_type";
524 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
525 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
526 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
527 case DW_TAG_base_type: return "DW_TAG_base_type";
528 case DW_TAG_catch_block: return "DW_TAG_catch_block";
529 case DW_TAG_const_type: return "DW_TAG_const_type";
530 case DW_TAG_constant: return "DW_TAG_constant";
531 case DW_TAG_enumerator: return "DW_TAG_enumerator";
532 case DW_TAG_file_type: return "DW_TAG_file_type";
533 case DW_TAG_friend: return "DW_TAG_friend";
534 case DW_TAG_namelist: return "DW_TAG_namelist";
535 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
536 case DW_TAG_packed_type: return "DW_TAG_packed_type";
537 case DW_TAG_subprogram: return "DW_TAG_subprogram";
538 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
539 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
540 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
541 case DW_TAG_try_block: return "DW_TAG_try_block";
542 case DW_TAG_variant_part: return "DW_TAG_variant_part";
543 case DW_TAG_variable: return "DW_TAG_variable";
544 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
545 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
546 case DW_TAG_format_label: return "DW_TAG_format_label";
547 case DW_TAG_function_template: return "DW_TAG_function_template";
548 case DW_TAG_class_template: return "DW_TAG_class_template";
549 /* DWARF 2.1 values. */
550 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
551 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
552 case DW_TAG_interface_type: return "DW_TAG_interface_type";
553 case DW_TAG_namespace: return "DW_TAG_namespace";
554 case DW_TAG_imported_module: return "DW_TAG_imported_module";
555 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
556 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
557 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
559 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
560 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
561 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
564 static char buffer[100];
566 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
573 get_FORM_name (unsigned long form)
577 case DW_FORM_addr: return "DW_FORM_addr";
578 case DW_FORM_block2: return "DW_FORM_block2";
579 case DW_FORM_block4: return "DW_FORM_block4";
580 case DW_FORM_data2: return "DW_FORM_data2";
581 case DW_FORM_data4: return "DW_FORM_data4";
582 case DW_FORM_data8: return "DW_FORM_data8";
583 case DW_FORM_string: return "DW_FORM_string";
584 case DW_FORM_block: return "DW_FORM_block";
585 case DW_FORM_block1: return "DW_FORM_block1";
586 case DW_FORM_data1: return "DW_FORM_data1";
587 case DW_FORM_flag: return "DW_FORM_flag";
588 case DW_FORM_sdata: return "DW_FORM_sdata";
589 case DW_FORM_strp: return "DW_FORM_strp";
590 case DW_FORM_udata: return "DW_FORM_udata";
591 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
592 case DW_FORM_ref1: return "DW_FORM_ref1";
593 case DW_FORM_ref2: return "DW_FORM_ref2";
594 case DW_FORM_ref4: return "DW_FORM_ref4";
595 case DW_FORM_ref8: return "DW_FORM_ref8";
596 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
597 case DW_FORM_indirect: return "DW_FORM_indirect";
600 static char buffer[100];
602 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
608 static unsigned char *
609 display_block (unsigned char *data, unsigned long length)
611 printf (_(" %lu byte block: "), length);
614 printf ("%lx ", (unsigned long) byte_get (data++, 1));
620 decode_location_expression (unsigned char * data,
621 unsigned int pointer_size,
622 unsigned long length,
623 unsigned long cu_offset)
626 unsigned int bytes_read;
627 unsigned long uvalue;
628 unsigned char *end = data + length;
629 int need_frame_base = 0;
638 printf ("DW_OP_addr: %lx",
639 (unsigned long) byte_get (data, pointer_size));
640 data += pointer_size;
643 printf ("DW_OP_deref");
646 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
649 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
652 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
656 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
660 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
664 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
668 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
669 (unsigned long) byte_get (data + 4, 4));
673 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
674 (long) byte_get (data + 4, 4));
678 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
682 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
686 printf ("DW_OP_dup");
689 printf ("DW_OP_drop");
692 printf ("DW_OP_over");
695 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
698 printf ("DW_OP_swap");
701 printf ("DW_OP_rot");
704 printf ("DW_OP_xderef");
707 printf ("DW_OP_abs");
710 printf ("DW_OP_and");
713 printf ("DW_OP_div");
716 printf ("DW_OP_minus");
719 printf ("DW_OP_mod");
722 printf ("DW_OP_mul");
725 printf ("DW_OP_neg");
728 printf ("DW_OP_not");
734 printf ("DW_OP_plus");
736 case DW_OP_plus_uconst:
737 printf ("DW_OP_plus_uconst: %lu",
738 read_leb128 (data, &bytes_read, 0));
742 printf ("DW_OP_shl");
745 printf ("DW_OP_shr");
748 printf ("DW_OP_shra");
751 printf ("DW_OP_xor");
754 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
776 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
812 printf ("DW_OP_lit%d", op - DW_OP_lit0);
847 printf ("DW_OP_reg%d", op - DW_OP_reg0);
882 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
883 read_leb128 (data, &bytes_read, 1));
888 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
893 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
897 uvalue = read_leb128 (data, &bytes_read, 0);
899 printf ("DW_OP_bregx: %lu %ld", uvalue,
900 read_leb128 (data, &bytes_read, 1));
904 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
907 case DW_OP_deref_size:
908 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
910 case DW_OP_xderef_size:
911 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
914 printf ("DW_OP_nop");
917 /* DWARF 3 extensions. */
918 case DW_OP_push_object_address:
919 printf ("DW_OP_push_object_address");
922 /* XXX: Strictly speaking for 64-bit DWARF3 files
923 this ought to be an 8-byte wide computation. */
924 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset);
928 /* XXX: Strictly speaking for 64-bit DWARF3 files
929 this ought to be an 8-byte wide computation. */
930 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset);
934 /* XXX: Strictly speaking for 64-bit DWARF3 files
935 this ought to be an 8-byte wide computation. */
936 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data, 4) + cu_offset);
939 case DW_OP_form_tls_address:
940 printf ("DW_OP_form_tls_address");
942 case DW_OP_call_frame_cfa:
943 printf ("DW_OP_call_frame_cfa");
945 case DW_OP_bit_piece:
946 printf ("DW_OP_bit_piece: ");
947 printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
949 printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
953 /* GNU extensions. */
954 case DW_OP_GNU_push_tls_address:
955 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
957 case DW_OP_GNU_uninit:
958 printf ("DW_OP_GNU_uninit");
959 /* FIXME: Is there data associated with this OP ? */
963 case DW_OP_HP_is_value:
964 printf ("DW_OP_HP_is_value");
965 /* FIXME: Is there data associated with this OP ? */
967 case DW_OP_HP_fltconst4:
968 printf ("DW_OP_HP_fltconst4");
969 /* FIXME: Is there data associated with this OP ? */
971 case DW_OP_HP_fltconst8:
972 printf ("DW_OP_HP_fltconst8");
973 /* FIXME: Is there data associated with this OP ? */
975 case DW_OP_HP_mod_range:
976 printf ("DW_OP_HP_mod_range");
977 /* FIXME: Is there data associated with this OP ? */
979 case DW_OP_HP_unmod_range:
980 printf ("DW_OP_HP_unmod_range");
981 /* FIXME: Is there data associated with this OP ? */
984 printf ("DW_OP_HP_tls");
985 /* FIXME: Is there data associated with this OP ? */
989 if (op >= DW_OP_lo_user
990 && op <= DW_OP_hi_user)
991 printf (_("(User defined location op)"));
993 printf (_("(Unknown location op)"));
994 /* No way to tell where the next op is, so just bail. */
995 return need_frame_base;
998 /* Separate the ops. */
1003 return need_frame_base;
1006 static unsigned char *
1007 read_and_display_attr_value (unsigned long attribute,
1009 unsigned char * data,
1010 unsigned long cu_offset,
1011 unsigned long pointer_size,
1012 unsigned long offset_size,
1014 debug_info * debug_info_p,
1016 unsigned char * section_start)
1018 unsigned long uvalue = 0;
1019 unsigned char *block_start = NULL;
1020 unsigned int bytes_read;
1027 case DW_FORM_ref_addr:
1028 if (dwarf_version == 2)
1030 uvalue = byte_get (data, pointer_size);
1031 data += pointer_size;
1033 else if (dwarf_version == 3)
1035 uvalue = byte_get (data, offset_size);
1036 data += offset_size;
1040 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1045 uvalue = byte_get (data, pointer_size);
1046 data += pointer_size;
1050 uvalue = byte_get (data, offset_size);
1051 data += offset_size;
1057 uvalue = byte_get (data++, 1);
1062 uvalue = byte_get (data, 2);
1068 uvalue = byte_get (data, 4);
1073 uvalue = read_leb128 (data, & bytes_read, 1);
1077 case DW_FORM_ref_udata:
1079 uvalue = read_leb128 (data, & bytes_read, 0);
1083 case DW_FORM_indirect:
1084 form = read_leb128 (data, & bytes_read, 0);
1087 printf (" %s", get_FORM_name (form));
1088 return read_and_display_attr_value (attribute, form, data,
1089 cu_offset, pointer_size,
1090 offset_size, dwarf_version,
1091 debug_info_p, do_loc,
1097 case DW_FORM_ref_addr:
1099 printf (" <0x%lx>", uvalue);
1105 case DW_FORM_ref_udata:
1107 printf (" <0x%lx>", uvalue + cu_offset);
1113 printf (" 0x%lx", uvalue);
1122 printf (" %ld", uvalue);
1129 uvalue = byte_get (data, 4);
1130 printf (" 0x%lx", uvalue);
1131 printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
1133 if ((do_loc || do_debug_loc || do_debug_ranges)
1134 && num_debug_info_entries == 0)
1136 if (sizeof (uvalue) == 8)
1137 uvalue = byte_get (data, 8);
1139 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1144 case DW_FORM_string:
1146 printf (" %s", data);
1147 data += strlen ((char *) data) + 1;
1151 uvalue = read_leb128 (data, & bytes_read, 0);
1152 block_start = data + bytes_read;
1154 data = block_start + uvalue;
1156 data = display_block (block_start, uvalue);
1159 case DW_FORM_block1:
1160 uvalue = byte_get (data, 1);
1161 block_start = data + 1;
1163 data = block_start + uvalue;
1165 data = display_block (block_start, uvalue);
1168 case DW_FORM_block2:
1169 uvalue = byte_get (data, 2);
1170 block_start = data + 2;
1172 data = block_start + uvalue;
1174 data = display_block (block_start, uvalue);
1177 case DW_FORM_block4:
1178 uvalue = byte_get (data, 4);
1179 block_start = data + 4;
1181 data = block_start + uvalue;
1183 data = display_block (block_start, uvalue);
1188 printf (_(" (indirect string, offset: 0x%lx): %s"),
1189 uvalue, fetch_indirect_string (uvalue));
1192 case DW_FORM_indirect:
1193 /* Handled above. */
1197 warn (_("Unrecognized form: %lu\n"), form);
1201 if ((do_loc || do_debug_loc || do_debug_ranges)
1202 && num_debug_info_entries == 0)
1206 case DW_AT_frame_base:
1207 have_frame_base = 1;
1208 case DW_AT_location:
1209 case DW_AT_string_length:
1210 case DW_AT_return_addr:
1211 case DW_AT_data_member_location:
1212 case DW_AT_vtable_elem_location:
1214 case DW_AT_static_link:
1215 case DW_AT_use_location:
1216 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1218 /* Process location list. */
1219 unsigned int max = debug_info_p->max_loc_offsets;
1220 unsigned int num = debug_info_p->num_loc_offsets;
1222 if (max == 0 || num >= max)
1225 debug_info_p->loc_offsets
1226 = xcrealloc (debug_info_p->loc_offsets,
1227 max, sizeof (*debug_info_p->loc_offsets));
1228 debug_info_p->have_frame_base
1229 = xcrealloc (debug_info_p->have_frame_base,
1230 max, sizeof (*debug_info_p->have_frame_base));
1231 debug_info_p->max_loc_offsets = max;
1233 debug_info_p->loc_offsets [num] = uvalue;
1234 debug_info_p->have_frame_base [num] = have_frame_base;
1235 debug_info_p->num_loc_offsets++;
1240 if (need_base_address)
1241 debug_info_p->base_address = uvalue;
1245 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1247 /* Process range list. */
1248 unsigned int max = debug_info_p->max_range_lists;
1249 unsigned int num = debug_info_p->num_range_lists;
1251 if (max == 0 || num >= max)
1254 debug_info_p->range_lists
1255 = xcrealloc (debug_info_p->range_lists,
1256 max, sizeof (*debug_info_p->range_lists));
1257 debug_info_p->max_range_lists = max;
1259 debug_info_p->range_lists [num] = uvalue;
1260 debug_info_p->num_range_lists++;
1272 /* For some attributes we can display further information. */
1280 case DW_INL_not_inlined:
1281 printf (_("(not inlined)"));
1283 case DW_INL_inlined:
1284 printf (_("(inlined)"));
1286 case DW_INL_declared_not_inlined:
1287 printf (_("(declared as inline but ignored)"));
1289 case DW_INL_declared_inlined:
1290 printf (_("(declared as inline and inlined)"));
1293 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
1298 case DW_AT_language:
1301 /* Ordered by the numeric value of these constants. */
1302 case DW_LANG_C89: printf ("(ANSI C)"); break;
1303 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1304 case DW_LANG_Ada83: printf ("(Ada)"); break;
1305 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1306 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1307 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1308 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1309 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1310 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1311 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1312 /* DWARF 2.1 values. */
1313 case DW_LANG_Java: printf ("(Java)"); break;
1314 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1315 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1316 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1317 /* DWARF 3 values. */
1318 case DW_LANG_PLI: printf ("(PLI)"); break;
1319 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1320 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1321 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1322 case DW_LANG_D: printf ("(D)"); break;
1323 /* MIPS extension. */
1324 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1325 /* UPC extension. */
1326 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1328 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1329 printf ("(implementation defined: %lx)", uvalue);
1331 printf ("(Unknown: %lx)", uvalue);
1336 case DW_AT_encoding:
1339 case DW_ATE_void: printf ("(void)"); break;
1340 case DW_ATE_address: printf ("(machine address)"); break;
1341 case DW_ATE_boolean: printf ("(boolean)"); break;
1342 case DW_ATE_complex_float: printf ("(complex float)"); break;
1343 case DW_ATE_float: printf ("(float)"); break;
1344 case DW_ATE_signed: printf ("(signed)"); break;
1345 case DW_ATE_signed_char: printf ("(signed char)"); break;
1346 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1347 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1348 /* DWARF 2.1 values: */
1349 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1350 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1351 /* DWARF 3 values: */
1352 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1353 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1354 case DW_ATE_edited: printf ("(edited)"); break;
1355 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1356 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1357 /* HP extensions: */
1358 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1359 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1360 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1361 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1362 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1363 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1364 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1367 if (uvalue >= DW_ATE_lo_user
1368 && uvalue <= DW_ATE_hi_user)
1369 printf ("(user defined type)");
1371 printf ("(unknown type)");
1376 case DW_AT_accessibility:
1379 case DW_ACCESS_public: printf ("(public)"); break;
1380 case DW_ACCESS_protected: printf ("(protected)"); break;
1381 case DW_ACCESS_private: printf ("(private)"); break;
1383 printf ("(unknown accessibility)");
1388 case DW_AT_visibility:
1391 case DW_VIS_local: printf ("(local)"); break;
1392 case DW_VIS_exported: printf ("(exported)"); break;
1393 case DW_VIS_qualified: printf ("(qualified)"); break;
1394 default: printf ("(unknown visibility)"); break;
1398 case DW_AT_virtuality:
1401 case DW_VIRTUALITY_none: printf ("(none)"); break;
1402 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1403 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1404 default: printf ("(unknown virtuality)"); break;
1408 case DW_AT_identifier_case:
1411 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1412 case DW_ID_up_case: printf ("(up_case)"); break;
1413 case DW_ID_down_case: printf ("(down_case)"); break;
1414 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1415 default: printf ("(unknown case)"); break;
1419 case DW_AT_calling_convention:
1422 case DW_CC_normal: printf ("(normal)"); break;
1423 case DW_CC_program: printf ("(program)"); break;
1424 case DW_CC_nocall: printf ("(nocall)"); break;
1426 if (uvalue >= DW_CC_lo_user
1427 && uvalue <= DW_CC_hi_user)
1428 printf ("(user defined)");
1430 printf ("(unknown convention)");
1434 case DW_AT_ordering:
1437 case -1: printf ("(undefined)"); break;
1438 case 0: printf ("(row major)"); break;
1439 case 1: printf ("(column major)"); break;
1443 case DW_AT_frame_base:
1444 have_frame_base = 1;
1445 case DW_AT_location:
1446 case DW_AT_string_length:
1447 case DW_AT_return_addr:
1448 case DW_AT_data_member_location:
1449 case DW_AT_vtable_elem_location:
1451 case DW_AT_static_link:
1452 case DW_AT_use_location:
1453 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1454 printf (_("(location list)"));
1456 case DW_AT_allocated:
1457 case DW_AT_associated:
1458 case DW_AT_data_location:
1460 case DW_AT_upper_bound:
1461 case DW_AT_lower_bound:
1464 int need_frame_base;
1467 need_frame_base = decode_location_expression (block_start,
1472 if (need_frame_base && !have_frame_base)
1473 printf (_(" [without DW_AT_frame_base]"));
1479 unsigned long abbrev_number;
1480 abbrev_entry * entry;
1482 if (form == DW_FORM_ref1
1483 || form == DW_FORM_ref2
1484 || form == DW_FORM_ref4)
1485 uvalue += cu_offset;
1487 abbrev_number = read_leb128 (section_start + uvalue, NULL, 0);
1489 printf ("[Abbrev Number: %ld", abbrev_number);
1490 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1491 if (entry->entry == abbrev_number)
1494 printf (" (%s)", get_TAG_name (entry->tag));
1507 get_AT_name (unsigned long attribute)
1511 case DW_AT_sibling: return "DW_AT_sibling";
1512 case DW_AT_location: return "DW_AT_location";
1513 case DW_AT_name: return "DW_AT_name";
1514 case DW_AT_ordering: return "DW_AT_ordering";
1515 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1516 case DW_AT_byte_size: return "DW_AT_byte_size";
1517 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1518 case DW_AT_bit_size: return "DW_AT_bit_size";
1519 case DW_AT_element_list: return "DW_AT_element_list";
1520 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1521 case DW_AT_low_pc: return "DW_AT_low_pc";
1522 case DW_AT_high_pc: return "DW_AT_high_pc";
1523 case DW_AT_language: return "DW_AT_language";
1524 case DW_AT_member: return "DW_AT_member";
1525 case DW_AT_discr: return "DW_AT_discr";
1526 case DW_AT_discr_value: return "DW_AT_discr_value";
1527 case DW_AT_visibility: return "DW_AT_visibility";
1528 case DW_AT_import: return "DW_AT_import";
1529 case DW_AT_string_length: return "DW_AT_string_length";
1530 case DW_AT_common_reference: return "DW_AT_common_reference";
1531 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1532 case DW_AT_const_value: return "DW_AT_const_value";
1533 case DW_AT_containing_type: return "DW_AT_containing_type";
1534 case DW_AT_default_value: return "DW_AT_default_value";
1535 case DW_AT_inline: return "DW_AT_inline";
1536 case DW_AT_is_optional: return "DW_AT_is_optional";
1537 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1538 case DW_AT_producer: return "DW_AT_producer";
1539 case DW_AT_prototyped: return "DW_AT_prototyped";
1540 case DW_AT_return_addr: return "DW_AT_return_addr";
1541 case DW_AT_start_scope: return "DW_AT_start_scope";
1542 case DW_AT_stride_size: return "DW_AT_stride_size";
1543 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1544 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1545 case DW_AT_accessibility: return "DW_AT_accessibility";
1546 case DW_AT_address_class: return "DW_AT_address_class";
1547 case DW_AT_artificial: return "DW_AT_artificial";
1548 case DW_AT_base_types: return "DW_AT_base_types";
1549 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1550 case DW_AT_count: return "DW_AT_count";
1551 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1552 case DW_AT_decl_column: return "DW_AT_decl_column";
1553 case DW_AT_decl_file: return "DW_AT_decl_file";
1554 case DW_AT_decl_line: return "DW_AT_decl_line";
1555 case DW_AT_declaration: return "DW_AT_declaration";
1556 case DW_AT_discr_list: return "DW_AT_discr_list";
1557 case DW_AT_encoding: return "DW_AT_encoding";
1558 case DW_AT_external: return "DW_AT_external";
1559 case DW_AT_frame_base: return "DW_AT_frame_base";
1560 case DW_AT_friend: return "DW_AT_friend";
1561 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1562 case DW_AT_macro_info: return "DW_AT_macro_info";
1563 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1564 case DW_AT_priority: return "DW_AT_priority";
1565 case DW_AT_segment: return "DW_AT_segment";
1566 case DW_AT_specification: return "DW_AT_specification";
1567 case DW_AT_static_link: return "DW_AT_static_link";
1568 case DW_AT_type: return "DW_AT_type";
1569 case DW_AT_use_location: return "DW_AT_use_location";
1570 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1571 case DW_AT_virtuality: return "DW_AT_virtuality";
1572 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1573 /* DWARF 2.1 values. */
1574 case DW_AT_allocated: return "DW_AT_allocated";
1575 case DW_AT_associated: return "DW_AT_associated";
1576 case DW_AT_data_location: return "DW_AT_data_location";
1577 case DW_AT_stride: return "DW_AT_stride";
1578 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1579 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1580 case DW_AT_extension: return "DW_AT_extension";
1581 case DW_AT_ranges: return "DW_AT_ranges";
1582 case DW_AT_trampoline: return "DW_AT_trampoline";
1583 case DW_AT_call_column: return "DW_AT_call_column";
1584 case DW_AT_call_file: return "DW_AT_call_file";
1585 case DW_AT_call_line: return "DW_AT_call_line";
1586 case DW_AT_description: return "DW_AT_description";
1587 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1588 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1589 case DW_AT_small: return "DW_AT_small";
1590 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1591 case DW_AT_digit_count: return "DW_AT_digit_count";
1592 case DW_AT_picture_string: return "DW_AT_picture_string";
1593 case DW_AT_mutable: return "DW_AT_mutable";
1594 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1595 case DW_AT_explicit: return "DW_AT_explicit";
1596 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1597 case DW_AT_endianity: return "DW_AT_endianity";
1598 case DW_AT_elemental: return "DW_AT_elemental";
1599 case DW_AT_pure: return "DW_AT_pure";
1600 case DW_AT_recursive: return "DW_AT_recursive";
1602 /* HP and SGI/MIPS extensions. */
1603 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1604 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1605 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1606 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1607 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1608 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1609 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1610 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1611 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1612 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1614 /* HP Extensions. */
1615 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
1616 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1617 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1618 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1619 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1620 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1621 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1622 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1623 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1624 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1625 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1626 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1627 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1629 /* One value is shared by the MIPS and HP extensions: */
1630 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1632 /* GNU extensions. */
1633 case DW_AT_sf_names: return "DW_AT_sf_names";
1634 case DW_AT_src_info: return "DW_AT_src_info";
1635 case DW_AT_mac_info: return "DW_AT_mac_info";
1636 case DW_AT_src_coords: return "DW_AT_src_coords";
1637 case DW_AT_body_begin: return "DW_AT_body_begin";
1638 case DW_AT_body_end: return "DW_AT_body_end";
1639 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1641 /* UPC extension. */
1642 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1644 /* PGI (STMicroelectronics) extensions. */
1645 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1646 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1647 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1651 static char buffer[100];
1653 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1660 static unsigned char *
1661 read_and_display_attr (unsigned long attribute,
1663 unsigned char * data,
1664 unsigned long cu_offset,
1665 unsigned long pointer_size,
1666 unsigned long offset_size,
1668 debug_info * debug_info_p,
1670 unsigned char * section_start)
1673 printf (" %-18s:", get_AT_name (attribute));
1674 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1675 pointer_size, offset_size,
1676 dwarf_version, debug_info_p,
1677 do_loc, section_start);
1684 /* Process the contents of a .debug_info section. If do_loc is non-zero
1685 then we are scanning for location lists and we do not want to display
1686 anything to the user. */
1689 process_debug_info (struct dwarf_section *section, void *file,
1692 unsigned char *start = section->start;
1693 unsigned char *end = start + section->size;
1694 unsigned char *section_begin;
1696 unsigned int num_units = 0;
1698 if ((do_loc || do_debug_loc || do_debug_ranges)
1699 && num_debug_info_entries == 0)
1701 unsigned long length;
1703 /* First scan the section to get the number of comp units. */
1704 for (section_begin = start, num_units = 0; section_begin < end;
1707 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1708 will be the length. For a 64-bit DWARF section, it'll be
1709 the escape code 0xffffffff followed by an 8 byte length. */
1710 length = byte_get (section_begin, 4);
1712 if (length == 0xffffffff)
1714 length = byte_get (section_begin + 4, 8);
1715 section_begin += length + 12;
1717 else if (length >= 0xfffffff0 && length < 0xffffffff)
1719 warn (_("Reserved length value (%lx) found in section %s\n"), length, section->name);
1723 section_begin += length + 4;
1725 /* Negative values are illegal, they may even cause infinite
1726 looping. This can happen if we can't accurately apply
1727 relocations to an object file. */
1728 if ((signed long) length <= 0)
1730 warn (_("Corrupt unit length (%lx) found in section %s\n"), length, section->name);
1737 error (_("No comp units in %s section ?"), section->name);
1741 /* Then allocate an array to hold the information. */
1742 debug_information = cmalloc (num_units,
1743 sizeof (* debug_information));
1744 if (debug_information == NULL)
1746 error (_("Not enough memory for a debug info array of %u entries"),
1754 printf (_("The section %s contains:\n\n"), section->name);
1756 load_debug_section (str, file);
1759 load_debug_section (abbrev, file);
1760 if (debug_displays [abbrev].section.start == NULL)
1762 warn (_("Unable to locate %s section!\n"),
1763 debug_displays [abbrev].section.name);
1767 for (section_begin = start, unit = 0; start < end; unit++)
1769 DWARF2_Internal_CompUnit compunit;
1770 unsigned char *hdrptr;
1771 unsigned char *cu_abbrev_offset_ptr;
1772 unsigned char *tags;
1774 unsigned long cu_offset;
1776 int initial_length_size;
1780 compunit.cu_length = byte_get (hdrptr, 4);
1783 if (compunit.cu_length == 0xffffffff)
1785 compunit.cu_length = byte_get (hdrptr, 8);
1788 initial_length_size = 12;
1793 initial_length_size = 4;
1796 compunit.cu_version = byte_get (hdrptr, 2);
1799 cu_offset = start - section_begin;
1801 cu_abbrev_offset_ptr = hdrptr;
1802 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
1803 hdrptr += offset_size;
1805 compunit.cu_pointer_size = byte_get (hdrptr, 1);
1807 if ((do_loc || do_debug_loc || do_debug_ranges)
1808 && num_debug_info_entries == 0)
1810 debug_information [unit].cu_offset = cu_offset;
1811 debug_information [unit].pointer_size
1812 = compunit.cu_pointer_size;
1813 debug_information [unit].base_address = 0;
1814 debug_information [unit].loc_offsets = NULL;
1815 debug_information [unit].have_frame_base = NULL;
1816 debug_information [unit].max_loc_offsets = 0;
1817 debug_information [unit].num_loc_offsets = 0;
1818 debug_information [unit].range_lists = NULL;
1819 debug_information [unit].max_range_lists= 0;
1820 debug_information [unit].num_range_lists = 0;
1825 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset);
1826 printf (_(" Length: %ld\n"), compunit.cu_length);
1827 printf (_(" Version: %d\n"), compunit.cu_version);
1828 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
1829 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
1832 if (cu_offset + compunit.cu_length + initial_length_size
1835 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1836 cu_offset, compunit.cu_length);
1840 start += compunit.cu_length + initial_length_size;
1842 if (compunit.cu_version != 2 && compunit.cu_version != 3)
1844 warn (_("Only version 2 and 3 DWARF debug information is currently supported.\n"));
1850 /* Process the abbrevs used by this compilation unit. DWARF
1851 sections under Mach-O have non-zero addresses. */
1852 if (compunit.cu_abbrev_offset >= debug_displays [abbrev].section.size)
1853 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1854 (unsigned long) compunit.cu_abbrev_offset,
1855 (unsigned long) debug_displays [abbrev].section.size);
1857 process_abbrev_section
1858 ((unsigned char *) debug_displays [abbrev].section.start
1859 + compunit.cu_abbrev_offset - debug_displays [abbrev].section.address,
1860 (unsigned char *) debug_displays [abbrev].section.start
1861 + debug_displays [abbrev].section.size);
1864 while (tags < start)
1866 unsigned int bytes_read;
1867 unsigned long abbrev_number;
1868 unsigned long die_offset;
1869 abbrev_entry *entry;
1872 die_offset = tags - section_begin;
1874 abbrev_number = read_leb128 (tags, & bytes_read, 0);
1877 /* A null DIE marks the end of a list of siblings. */
1878 if (abbrev_number == 0)
1883 static unsigned num_bogus_warns = 0;
1885 if (num_bogus_warns < 3)
1887 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
1890 if (num_bogus_warns == 3)
1891 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
1898 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
1899 level, die_offset, abbrev_number);
1901 /* Scan through the abbreviation list until we reach the
1903 for (entry = first_abbrev;
1904 entry && entry->entry != abbrev_number;
1905 entry = entry->next)
1915 warn (_("Unable to locate entry %lu in the abbreviation table\n"),
1921 printf (_(" (%s)\n"), get_TAG_name (entry->tag));
1926 need_base_address = 0;
1928 case DW_TAG_compile_unit:
1929 need_base_address = 1;
1931 case DW_TAG_entry_point:
1932 case DW_TAG_subprogram:
1933 need_base_address = 0;
1934 /* Assuming that there is no DW_AT_frame_base. */
1935 have_frame_base = 0;
1939 for (attr = entry->first_attr; attr; attr = attr->next)
1942 /* Show the offset from where the tag was extracted. */
1943 printf (" <%2lx>", (unsigned long)(tags - section_begin));
1945 tags = read_and_display_attr (attr->attribute,
1948 compunit.cu_pointer_size,
1950 compunit.cu_version,
1951 debug_information + unit,
1952 do_loc, section->start);
1955 if (entry->children)
1960 /* Set num_debug_info_entries here so that it can be used to check if
1961 we need to process .debug_loc and .debug_ranges sections. */
1962 if ((do_loc || do_debug_loc || do_debug_ranges)
1963 && num_debug_info_entries == 0)
1964 num_debug_info_entries = num_units;
1974 /* Locate and scan the .debug_info section in the file and record the pointer
1975 sizes and offsets for the compilation units in it. Usually an executable
1976 will have just one pointer size, but this is not guaranteed, and so we try
1977 not to make any assumptions. Returns zero upon failure, or the number of
1978 compilation units upon success. */
1981 load_debug_info (void * file)
1983 /* Reset the last pointer size so that we can issue correct error
1984 messages if we are displaying the contents of more than one section. */
1985 last_pointer_size = 0;
1986 warned_about_missing_comp_units = FALSE;
1988 /* If we already have the information there is nothing else to do. */
1989 if (num_debug_info_entries > 0)
1990 return num_debug_info_entries;
1992 if (load_debug_section (info, file)
1993 && process_debug_info (&debug_displays [info].section, file, 1))
1994 return num_debug_info_entries;
2000 display_debug_lines (struct dwarf_section *section, void *file)
2002 unsigned char *start = section->start;
2003 unsigned char *data = start;
2004 unsigned char *end = start + section->size;
2006 printf (_("\nDump of debug contents of section %s:\n\n"),
2009 load_debug_info (file);
2013 DWARF2_Internal_LineInfo info;
2014 unsigned char *standard_opcodes;
2015 unsigned char *end_of_sequence;
2016 unsigned char *hdrptr;
2017 unsigned long hdroff;
2018 int initial_length_size;
2023 hdroff = hdrptr - start;
2025 /* Check the length of the block. */
2026 info.li_length = byte_get (hdrptr, 4);
2029 if (info.li_length == 0xffffffff)
2031 /* This section is 64-bit DWARF 3. */
2032 info.li_length = byte_get (hdrptr, 8);
2035 initial_length_size = 12;
2040 initial_length_size = 4;
2043 if (info.li_length + initial_length_size > section->size)
2046 (_("The line info appears to be corrupt - the section is too small\n"));
2050 /* Check its version number. */
2051 info.li_version = byte_get (hdrptr, 2);
2053 if (info.li_version != 2 && info.li_version != 3)
2055 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2059 info.li_prologue_length = byte_get (hdrptr, offset_size);
2060 hdrptr += offset_size;
2061 info.li_min_insn_length = byte_get (hdrptr, 1);
2063 info.li_default_is_stmt = byte_get (hdrptr, 1);
2065 info.li_line_base = byte_get (hdrptr, 1);
2067 info.li_line_range = byte_get (hdrptr, 1);
2069 info.li_opcode_base = byte_get (hdrptr, 1);
2072 /* Sign extend the line base field. */
2073 info.li_line_base <<= 24;
2074 info.li_line_base >>= 24;
2076 printf (_(" Offset: 0x%lx\n"), hdroff);
2077 printf (_(" Length: %ld\n"), info.li_length);
2078 printf (_(" DWARF Version: %d\n"), info.li_version);
2079 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
2080 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
2081 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
2082 printf (_(" Line Base: %d\n"), info.li_line_base);
2083 printf (_(" Line Range: %d\n"), info.li_line_range);
2084 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
2086 end_of_sequence = data + info.li_length + initial_length_size;
2088 reset_state_machine (info.li_default_is_stmt);
2090 /* Display the contents of the Opcodes table. */
2091 standard_opcodes = hdrptr;
2093 printf (_("\n Opcodes:\n"));
2095 for (i = 1; i < info.li_opcode_base; i++)
2096 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2098 /* Display the contents of the Directory table. */
2099 data = standard_opcodes + info.li_opcode_base - 1;
2102 printf (_("\n The Directory Table is empty.\n"));
2105 printf (_("\n The Directory Table:\n"));
2109 printf (_(" %s\n"), data);
2111 data += strlen ((char *) data) + 1;
2115 /* Skip the NUL at the end of the table. */
2118 /* Display the contents of the File Name table. */
2120 printf (_("\n The File Name Table is empty.\n"));
2123 printf (_("\n The File Name Table:\n"));
2124 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2128 unsigned char *name;
2129 unsigned int bytes_read;
2131 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
2134 data += strlen ((char *) data) + 1;
2136 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2138 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2140 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2142 printf (_("%s\n"), name);
2146 /* Skip the NUL at the end of the table. */
2149 /* Now display the statements. */
2150 printf (_("\n Line Number Statements:\n"));
2152 while (data < end_of_sequence)
2154 unsigned char op_code;
2156 unsigned long int uladv;
2157 unsigned int bytes_read;
2161 if (op_code >= info.li_opcode_base)
2163 op_code -= info.li_opcode_base;
2164 uladv = (op_code / info.li_line_range) * info.li_min_insn_length;
2165 state_machine_regs.address += uladv;
2166 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2167 op_code, uladv, state_machine_regs.address);
2168 adv = (op_code % info.li_line_range) + info.li_line_base;
2169 state_machine_regs.line += adv;
2170 printf (_(" and Line by %d to %d\n"),
2171 adv, state_machine_regs.line);
2173 else switch (op_code)
2175 case DW_LNS_extended_op:
2176 data += process_extended_line_op (data, info.li_default_is_stmt);
2180 printf (_(" Copy\n"));
2183 case DW_LNS_advance_pc:
2184 uladv = read_leb128 (data, & bytes_read, 0);
2185 uladv *= info.li_min_insn_length;
2187 state_machine_regs.address += uladv;
2188 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv,
2189 state_machine_regs.address);
2192 case DW_LNS_advance_line:
2193 adv = read_leb128 (data, & bytes_read, 1);
2195 state_machine_regs.line += adv;
2196 printf (_(" Advance Line by %d to %d\n"), adv,
2197 state_machine_regs.line);
2200 case DW_LNS_set_file:
2201 adv = read_leb128 (data, & bytes_read, 0);
2203 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2205 state_machine_regs.file = adv;
2208 case DW_LNS_set_column:
2209 uladv = read_leb128 (data, & bytes_read, 0);
2211 printf (_(" Set column to %lu\n"), uladv);
2212 state_machine_regs.column = uladv;
2215 case DW_LNS_negate_stmt:
2216 adv = state_machine_regs.is_stmt;
2218 printf (_(" Set is_stmt to %d\n"), adv);
2219 state_machine_regs.is_stmt = adv;
2222 case DW_LNS_set_basic_block:
2223 printf (_(" Set basic block\n"));
2224 state_machine_regs.basic_block = 1;
2227 case DW_LNS_const_add_pc:
2228 uladv = (((255 - info.li_opcode_base) / info.li_line_range)
2229 * info.li_min_insn_length);
2230 state_machine_regs.address += uladv;
2231 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv,
2232 state_machine_regs.address);
2235 case DW_LNS_fixed_advance_pc:
2236 uladv = byte_get (data, 2);
2238 state_machine_regs.address += uladv;
2239 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2240 uladv, state_machine_regs.address);
2243 case DW_LNS_set_prologue_end:
2244 printf (_(" Set prologue_end to true\n"));
2247 case DW_LNS_set_epilogue_begin:
2248 printf (_(" Set epilogue_begin to true\n"));
2251 case DW_LNS_set_isa:
2252 uladv = read_leb128 (data, & bytes_read, 0);
2254 printf (_(" Set ISA to %lu\n"), uladv);
2258 printf (_(" Unknown opcode %d with operands: "), op_code);
2260 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2262 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
2263 i == 1 ? "" : ", ");
2277 display_debug_pubnames (struct dwarf_section *section,
2278 void *file ATTRIBUTE_UNUSED)
2280 DWARF2_Internal_PubNames pubnames;
2281 unsigned char *start = section->start;
2282 unsigned char *end = start + section->size;
2284 printf (_("Contents of the %s section:\n\n"), section->name);
2288 unsigned char *data;
2289 unsigned long offset;
2290 int offset_size, initial_length_size;
2294 pubnames.pn_length = byte_get (data, 4);
2296 if (pubnames.pn_length == 0xffffffff)
2298 pubnames.pn_length = byte_get (data, 8);
2301 initial_length_size = 12;
2306 initial_length_size = 4;
2309 pubnames.pn_version = byte_get (data, 2);
2311 pubnames.pn_offset = byte_get (data, offset_size);
2312 data += offset_size;
2313 pubnames.pn_size = byte_get (data, offset_size);
2314 data += offset_size;
2316 start += pubnames.pn_length + initial_length_size;
2318 if (pubnames.pn_version != 2 && pubnames.pn_version != 3)
2320 static int warned = 0;
2324 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2331 printf (_(" Length: %ld\n"),
2332 pubnames.pn_length);
2333 printf (_(" Version: %d\n"),
2334 pubnames.pn_version);
2335 printf (_(" Offset into .debug_info section: %ld\n"),
2336 pubnames.pn_offset);
2337 printf (_(" Size of area in .debug_info section: %ld\n"),
2340 printf (_("\n Offset\tName\n"));
2344 offset = byte_get (data, offset_size);
2348 data += offset_size;
2349 printf (" %-6ld\t\t%s\n", offset, data);
2350 data += strlen ((char *) data) + 1;
2353 while (offset != 0);
2361 display_debug_macinfo (struct dwarf_section *section,
2362 void *file ATTRIBUTE_UNUSED)
2364 unsigned char *start = section->start;
2365 unsigned char *end = start + section->size;
2366 unsigned char *curr = start;
2367 unsigned int bytes_read;
2368 enum dwarf_macinfo_record_type op;
2370 printf (_("Contents of the %s section:\n\n"), section->name);
2374 unsigned int lineno;
2382 case DW_MACINFO_start_file:
2384 unsigned int filenum;
2386 lineno = read_leb128 (curr, & bytes_read, 0);
2388 filenum = read_leb128 (curr, & bytes_read, 0);
2391 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2396 case DW_MACINFO_end_file:
2397 printf (_(" DW_MACINFO_end_file\n"));
2400 case DW_MACINFO_define:
2401 lineno = read_leb128 (curr, & bytes_read, 0);
2403 string = (char *) curr;
2404 curr += strlen (string) + 1;
2405 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2409 case DW_MACINFO_undef:
2410 lineno = read_leb128 (curr, & bytes_read, 0);
2412 string = (char *) curr;
2413 curr += strlen (string) + 1;
2414 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2418 case DW_MACINFO_vendor_ext:
2420 unsigned int constant;
2422 constant = read_leb128 (curr, & bytes_read, 0);
2424 string = (char *) curr;
2425 curr += strlen (string) + 1;
2426 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2437 display_debug_abbrev (struct dwarf_section *section,
2438 void *file ATTRIBUTE_UNUSED)
2440 abbrev_entry *entry;
2441 unsigned char *start = section->start;
2442 unsigned char *end = start + section->size;
2444 printf (_("Contents of the %s section:\n\n"), section->name);
2450 start = process_abbrev_section (start, end);
2452 if (first_abbrev == NULL)
2455 printf (_(" Number TAG\n"));
2457 for (entry = first_abbrev; entry; entry = entry->next)
2461 printf (_(" %ld %s [%s]\n"),
2463 get_TAG_name (entry->tag),
2464 entry->children ? _("has children") : _("no children"));
2466 for (attr = entry->first_attr; attr; attr = attr->next)
2467 printf (_(" %-18s %s\n"),
2468 get_AT_name (attr->attribute),
2469 get_FORM_name (attr->form));
2480 display_debug_loc (struct dwarf_section *section, void *file)
2482 unsigned char *start = section->start;
2483 unsigned char *section_end;
2484 unsigned long bytes;
2485 unsigned char *section_begin = start;
2486 unsigned int num_loc_list = 0;
2487 unsigned long last_offset = 0;
2488 unsigned int first = 0;
2491 int seen_first_offset = 0;
2492 int use_debug_info = 1;
2493 unsigned char *next;
2495 bytes = section->size;
2496 section_end = start + bytes;
2500 printf (_("\nThe %s section is empty.\n"), section->name);
2504 load_debug_info (file);
2506 /* Check the order of location list in .debug_info section. If
2507 offsets of location lists are in the ascending order, we can
2508 use `debug_information' directly. */
2509 for (i = 0; i < num_debug_info_entries; i++)
2513 num = debug_information [i].num_loc_offsets;
2514 num_loc_list += num;
2516 /* Check if we can use `debug_information' directly. */
2517 if (use_debug_info && num != 0)
2519 if (!seen_first_offset)
2521 /* This is the first location list. */
2522 last_offset = debug_information [i].loc_offsets [0];
2524 seen_first_offset = 1;
2530 for (; j < num; j++)
2533 debug_information [i].loc_offsets [j])
2538 last_offset = debug_information [i].loc_offsets [j];
2543 if (!use_debug_info)
2544 /* FIXME: Should we handle this case? */
2545 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
2547 if (!seen_first_offset)
2548 error (_("No location lists in .debug_info section!\n"));
2550 /* DWARF sections under Mach-O have non-zero addresses. */
2551 if (debug_information [first].num_loc_offsets > 0
2552 && debug_information [first].loc_offsets [0] != section->address)
2553 warn (_("Location lists in %s section start at 0x%lx\n"),
2554 section->name, debug_information [first].loc_offsets [0]);
2556 printf (_("Contents of the %s section:\n\n"), section->name);
2557 printf (_(" Offset Begin End Expression\n"));
2559 seen_first_offset = 0;
2560 for (i = first; i < num_debug_info_entries; i++)
2562 unsigned long begin;
2564 unsigned short length;
2565 unsigned long offset;
2566 unsigned int pointer_size;
2567 unsigned long cu_offset;
2568 unsigned long base_address;
2569 int need_frame_base;
2572 pointer_size = debug_information [i].pointer_size;
2573 cu_offset = debug_information [i].cu_offset;
2575 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
2577 has_frame_base = debug_information [i].have_frame_base [j];
2578 /* DWARF sections under Mach-O have non-zero addresses. */
2579 offset = debug_information [i].loc_offsets [j] - section->address;
2580 next = section_begin + offset;
2581 base_address = debug_information [i].base_address;
2583 if (!seen_first_offset)
2584 seen_first_offset = 1;
2588 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
2589 (long)(start - section_begin), (long)(next - section_begin));
2590 else if (start > next)
2591 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
2592 (long)(start - section_begin), (long)(next - section_begin));
2596 if (offset >= bytes)
2598 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
2605 if (start + 2 * pointer_size > section_end)
2607 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2612 begin = byte_get (start, pointer_size);
2613 start += pointer_size;
2614 end = byte_get (start, pointer_size);
2615 start += pointer_size;
2617 if (begin == 0 && end == 0)
2619 printf (_(" %8.8lx <End of list>\n"), offset);
2623 /* Check base address specifiers. */
2624 if (begin == -1UL && end != -1UL)
2627 printf (_(" %8.8lx %8.8lx %8.8lx (base address)\n"),
2628 offset, begin, end);
2632 if (start + 2 > section_end)
2634 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2639 length = byte_get (start, 2);
2642 if (start + length > section_end)
2644 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2649 printf (" %8.8lx %8.8lx %8.8lx (",
2650 offset, begin + base_address, end + base_address);
2651 need_frame_base = decode_location_expression (start,
2657 if (need_frame_base && !has_frame_base)
2658 printf (_(" [without DW_AT_frame_base]"));
2661 fputs (_(" (start == end)"), stdout);
2662 else if (begin > end)
2663 fputs (_(" (start > end)"), stdout);
2672 if (start < section_end)
2673 warn (_("There are %ld unused bytes at the end of section %s\n"),
2674 (long) (section_end - start), section->name);
2679 display_debug_str (struct dwarf_section *section,
2680 void *file ATTRIBUTE_UNUSED)
2682 unsigned char *start = section->start;
2683 unsigned long bytes = section->size;
2684 dwarf_vma addr = section->address;
2688 printf (_("\nThe %s section is empty.\n"), section->name);
2692 printf (_("Contents of the %s section:\n\n"), section->name);
2700 lbytes = (bytes > 16 ? 16 : bytes);
2702 printf (" 0x%8.8lx ", (unsigned long) addr);
2704 for (j = 0; j < 16; j++)
2707 printf ("%2.2x", start[j]);
2715 for (j = 0; j < lbytes; j++)
2718 if (k >= ' ' && k < 0x80)
2737 display_debug_info (struct dwarf_section *section, void *file)
2739 return process_debug_info (section, file, 0);
2744 display_debug_aranges (struct dwarf_section *section,
2745 void *file ATTRIBUTE_UNUSED)
2747 unsigned char *start = section->start;
2748 unsigned char *end = start + section->size;
2750 printf (_("The section %s contains:\n\n"), section->name);
2754 unsigned char *hdrptr;
2755 DWARF2_Internal_ARange arange;
2756 unsigned char *ranges;
2757 unsigned long length;
2758 unsigned long address;
2759 unsigned char address_size;
2762 int initial_length_size;
2766 arange.ar_length = byte_get (hdrptr, 4);
2769 if (arange.ar_length == 0xffffffff)
2771 arange.ar_length = byte_get (hdrptr, 8);
2774 initial_length_size = 12;
2779 initial_length_size = 4;
2782 arange.ar_version = byte_get (hdrptr, 2);
2785 arange.ar_info_offset = byte_get (hdrptr, offset_size);
2786 hdrptr += offset_size;
2788 arange.ar_pointer_size = byte_get (hdrptr, 1);
2791 arange.ar_segment_size = byte_get (hdrptr, 1);
2794 if (arange.ar_version != 2 && arange.ar_version != 3)
2796 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
2800 printf (_(" Length: %ld\n"), arange.ar_length);
2801 printf (_(" Version: %d\n"), arange.ar_version);
2802 printf (_(" Offset into .debug_info: %lx\n"), arange.ar_info_offset);
2803 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
2804 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
2806 address_size = arange.ar_pointer_size + arange.ar_segment_size;
2808 /* The DWARF spec does not require that the address size be a power
2809 of two, but we do. This will have to change if we ever encounter
2810 an uneven architecture. */
2811 if ((address_size & (address_size - 1)) != 0)
2813 warn (_("Pointer size + Segment size is not a power of two.\n"));
2817 if (address_size > 4)
2818 printf (_("\n Address Length\n"));
2820 printf (_("\n Address Length\n"));
2824 /* Must pad to an alignment boundary that is twice the address size. */
2825 excess = (hdrptr - start) % (2 * address_size);
2827 ranges += (2 * address_size) - excess;
2829 start += arange.ar_length + initial_length_size;
2831 while (ranges + 2 * address_size <= start)
2833 address = byte_get (ranges, address_size);
2835 ranges += address_size;
2837 length = byte_get (ranges, address_size);
2839 ranges += address_size;
2841 if (address_size > 4)
2842 printf (" 0x%16.16lx 0x%lx\n", address, length);
2844 printf (" 0x%8.8lx 0x%lx\n", address, length);
2854 display_debug_ranges (struct dwarf_section *section,
2855 void *file ATTRIBUTE_UNUSED)
2857 unsigned char *start = section->start;
2858 unsigned char *section_end;
2859 unsigned long bytes;
2860 unsigned char *section_begin = start;
2861 unsigned int num_range_list = 0;
2862 unsigned long last_offset = 0;
2863 unsigned int first = 0;
2866 int seen_first_offset = 0;
2867 int use_debug_info = 1;
2868 unsigned char *next;
2870 bytes = section->size;
2871 section_end = start + bytes;
2875 printf (_("\nThe %s section is empty.\n"), section->name);
2879 load_debug_info (file);
2881 /* Check the order of range list in .debug_info section. If
2882 offsets of range lists are in the ascending order, we can
2883 use `debug_information' directly. */
2884 for (i = 0; i < num_debug_info_entries; i++)
2888 num = debug_information [i].num_range_lists;
2889 num_range_list += num;
2891 /* Check if we can use `debug_information' directly. */
2892 if (use_debug_info && num != 0)
2894 if (!seen_first_offset)
2896 /* This is the first range list. */
2897 last_offset = debug_information [i].range_lists [0];
2899 seen_first_offset = 1;
2905 for (; j < num; j++)
2908 debug_information [i].range_lists [j])
2913 last_offset = debug_information [i].range_lists [j];
2918 if (!use_debug_info)
2919 /* FIXME: Should we handle this case? */
2920 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
2922 if (!seen_first_offset)
2923 error (_("No range lists in .debug_info section!\n"));
2925 /* DWARF sections under Mach-O have non-zero addresses. */
2926 if (debug_information [first].num_range_lists > 0
2927 && debug_information [first].range_lists [0] != section->address)
2928 warn (_("Range lists in %s section start at 0x%lx\n"),
2929 section->name, debug_information [first].range_lists [0]);
2931 printf (_("Contents of the %s section:\n\n"), section->name);
2932 printf (_(" Offset Begin End\n"));
2934 seen_first_offset = 0;
2935 for (i = first; i < num_debug_info_entries; i++)
2937 unsigned long begin;
2939 unsigned long offset;
2940 unsigned int pointer_size;
2941 unsigned long base_address;
2943 pointer_size = debug_information [i].pointer_size;
2945 for (j = 0; j < debug_information [i].num_range_lists; j++)
2947 /* DWARF sections under Mach-O have non-zero addresses. */
2948 offset = debug_information [i].range_lists [j] - section->address;
2949 next = section_begin + offset;
2950 base_address = debug_information [i].base_address;
2952 if (!seen_first_offset)
2953 seen_first_offset = 1;
2957 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
2958 (long)(start - section_begin),
2959 (long)(next - section_begin), section->name);
2960 else if (start > next)
2961 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
2962 (long)(start - section_begin),
2963 (long)(next - section_begin), section->name);
2969 begin = byte_get (start, pointer_size);
2970 start += pointer_size;
2971 end = byte_get (start, pointer_size);
2972 start += pointer_size;
2974 if (begin == 0 && end == 0)
2976 printf (_(" %8.8lx <End of list>\n"), offset);
2980 /* Check base address specifiers. */
2981 if (begin == -1UL && end != -1UL)
2984 printf (" %8.8lx %8.8lx %8.8lx (base address)\n",
2985 offset, begin, end);
2989 printf (" %8.8lx %8.8lx %8.8lx",
2990 offset, begin + base_address, end + base_address);
2993 fputs (_(" (start == end)"), stdout);
2994 else if (begin > end)
2995 fputs (_(" (start > end)"), stdout);
3005 typedef struct Frame_Chunk
3007 struct Frame_Chunk *next;
3008 unsigned char *chunk_start;
3010 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3011 short int *col_type;
3014 unsigned int code_factor;
3016 unsigned long pc_begin;
3017 unsigned long pc_range;
3021 unsigned char fde_encoding;
3022 unsigned char cfa_exp;
3026 /* A marker for a col_type that means this column was never referenced
3027 in the frame info. */
3028 #define DW_CFA_unreferenced (-1)
3031 frame_need_space (Frame_Chunk *fc, int reg)
3033 int prev = fc->ncols;
3035 if (reg < fc->ncols)
3038 fc->ncols = reg + 1;
3039 fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int));
3040 fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
3042 while (prev < fc->ncols)
3044 fc->col_type[prev] = DW_CFA_unreferenced;
3045 fc->col_offset[prev] = 0;
3051 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
3056 if (*max_regs < fc->ncols)
3057 *max_regs = fc->ncols;
3059 if (*need_col_headers)
3061 *need_col_headers = 0;
3063 printf (" LOC CFA ");
3065 for (r = 0; r < *max_regs; r++)
3066 if (fc->col_type[r] != DW_CFA_unreferenced)
3071 printf ("r%-4d", r);
3077 printf ("%08lx ", fc->pc_begin);
3079 strcpy (tmp, "exp");
3081 sprintf (tmp, "r%d%+d", fc->cfa_reg, fc->cfa_offset);
3082 printf ("%-8s ", tmp);
3084 for (r = 0; r < fc->ncols; r++)
3086 if (fc->col_type[r] != DW_CFA_unreferenced)
3088 switch (fc->col_type[r])
3090 case DW_CFA_undefined:
3093 case DW_CFA_same_value:
3097 sprintf (tmp, "c%+d", fc->col_offset[r]);
3099 case DW_CFA_val_offset:
3100 sprintf (tmp, "v%+d", fc->col_offset[r]);
3102 case DW_CFA_register:
3103 sprintf (tmp, "r%d", fc->col_offset[r]);
3105 case DW_CFA_expression:
3106 strcpy (tmp, "exp");
3108 case DW_CFA_val_expression:
3109 strcpy (tmp, "vexp");
3112 strcpy (tmp, "n/a");
3115 printf ("%-5s", tmp);
3122 size_of_encoded_value (int encoding)
3124 switch (encoding & 0x7)
3127 case 0: return eh_addr_size;
3135 get_encoded_value (unsigned char *data, int encoding)
3137 int size = size_of_encoded_value (encoding);
3139 if (encoding & DW_EH_PE_signed)
3140 return byte_get_signed (data, size);
3142 return byte_get (data, size);
3145 #define GET(N) byte_get (start, N); start += N
3146 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
3147 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3150 display_debug_frames (struct dwarf_section *section,
3151 void *file ATTRIBUTE_UNUSED)
3153 unsigned char *start = section->start;
3154 unsigned char *end = start + section->size;
3155 unsigned char *section_start = start;
3156 Frame_Chunk *chunks = 0;
3157 Frame_Chunk *remembered_state = 0;
3159 int is_eh = strcmp (section->name, ".eh_frame") == 0;
3160 unsigned int length_return;
3163 printf (_("The section %s contains:\n"), section->name);
3167 unsigned char *saved_start;
3168 unsigned char *block_end;
3169 unsigned long length;
3170 unsigned long cie_id;
3173 int need_col_headers = 1;
3174 unsigned char *augmentation_data = NULL;
3175 unsigned long augmentation_data_len = 0;
3176 int encoded_ptr_size = eh_addr_size;
3178 int initial_length_size;
3180 saved_start = start;
3181 length = byte_get (start, 4); start += 4;
3185 printf ("\n%08lx ZERO terminator\n\n",
3186 (unsigned long)(saved_start - section_start));
3190 if (length == 0xffffffff)
3192 length = byte_get (start, 8);
3195 initial_length_size = 12;
3200 initial_length_size = 4;
3203 block_end = saved_start + length + initial_length_size;
3204 if (block_end > end)
3206 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3207 length, (unsigned long)(saved_start - section_start));
3210 cie_id = byte_get (start, offset_size); start += offset_size;
3212 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
3216 fc = xmalloc (sizeof (Frame_Chunk));
3217 memset (fc, 0, sizeof (Frame_Chunk));
3221 fc->chunk_start = saved_start;
3223 fc->col_type = xmalloc (sizeof (short int));
3224 fc->col_offset = xmalloc (sizeof (int));
3225 frame_need_space (fc, max_regs-1);
3229 fc->augmentation = (char *) start;
3230 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
3232 if (fc->augmentation[0] == 'z')
3234 fc->code_factor = LEB ();
3235 fc->data_factor = SLEB ();
3244 augmentation_data_len = LEB ();
3245 augmentation_data = start;
3246 start += augmentation_data_len;
3248 else if (strcmp (fc->augmentation, "eh") == 0)
3250 start += eh_addr_size;
3251 fc->code_factor = LEB ();
3252 fc->data_factor = SLEB ();
3264 fc->code_factor = LEB ();
3265 fc->data_factor = SLEB ();
3277 if (do_debug_frames_interp)
3278 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3279 (unsigned long)(saved_start - section_start), length, cie_id,
3280 fc->augmentation, fc->code_factor, fc->data_factor,
3284 printf ("\n%08lx %08lx %08lx CIE\n",
3285 (unsigned long)(saved_start - section_start), length, cie_id);
3286 printf (" Version: %d\n", version);
3287 printf (" Augmentation: \"%s\"\n", fc->augmentation);
3288 printf (" Code alignment factor: %u\n", fc->code_factor);
3289 printf (" Data alignment factor: %d\n", fc->data_factor);
3290 printf (" Return address column: %d\n", fc->ra);
3292 if (augmentation_data_len)
3295 printf (" Augmentation data: ");
3296 for (i = 0; i < augmentation_data_len; ++i)
3297 printf (" %02x", augmentation_data[i]);
3303 if (augmentation_data_len)
3305 unsigned char *p, *q;
3306 p = (unsigned char *) fc->augmentation + 1;
3307 q = augmentation_data;
3314 q += 1 + size_of_encoded_value (*q);
3316 fc->fde_encoding = *q++;
3322 if (fc->fde_encoding)
3323 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3326 frame_need_space (fc, fc->ra);
3330 unsigned char *look_for;
3331 static Frame_Chunk fde_fc;
3334 memset (fc, 0, sizeof (Frame_Chunk));
3336 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
3338 for (cie = chunks; cie ; cie = cie->next)
3339 if (cie->chunk_start == look_for)
3344 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
3345 cie_id, (unsigned long)(saved_start - section_start));
3347 fc->col_type = xmalloc (sizeof (short int));
3348 fc->col_offset = xmalloc (sizeof (int));
3349 frame_need_space (fc, max_regs - 1);
3351 fc->augmentation = "";
3352 fc->fde_encoding = 0;
3356 fc->ncols = cie->ncols;
3357 fc->col_type = xcmalloc (fc->ncols, sizeof (short int));
3358 fc->col_offset = xcmalloc (fc->ncols, sizeof (int));
3359 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
3360 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
3361 fc->augmentation = cie->augmentation;
3362 fc->code_factor = cie->code_factor;
3363 fc->data_factor = cie->data_factor;
3364 fc->cfa_reg = cie->cfa_reg;
3365 fc->cfa_offset = cie->cfa_offset;
3367 frame_need_space (fc, max_regs-1);
3368 fc->fde_encoding = cie->fde_encoding;
3371 if (fc->fde_encoding)
3372 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3374 fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
3375 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
3376 fc->pc_begin += section->address + (start - section_start);
3377 start += encoded_ptr_size;
3378 fc->pc_range = byte_get (start, encoded_ptr_size);
3379 start += encoded_ptr_size;
3381 if (cie->augmentation[0] == 'z')
3383 augmentation_data_len = LEB ();
3384 augmentation_data = start;
3385 start += augmentation_data_len;
3388 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
3389 (unsigned long)(saved_start - section_start), length, cie_id,
3390 (unsigned long)(cie->chunk_start - section_start),
3391 fc->pc_begin, fc->pc_begin + fc->pc_range);
3392 if (! do_debug_frames_interp && augmentation_data_len)
3396 printf (" Augmentation data: ");
3397 for (i = 0; i < augmentation_data_len; ++i)
3398 printf (" %02x", augmentation_data[i]);
3404 /* At this point, fc is the current chunk, cie (if any) is set, and
3405 we're about to interpret instructions for the chunk. */
3406 /* ??? At present we need to do this always, since this sizes the
3407 fc->col_type and fc->col_offset arrays, which we write into always.
3408 We should probably split the interpreted and non-interpreted bits
3409 into two different routines, since there's so much that doesn't
3410 really overlap between them. */
3411 if (1 || do_debug_frames_interp)
3413 /* Start by making a pass over the chunk, allocating storage
3414 and taking note of what registers are used. */
3415 unsigned char *tmp = start;
3417 while (start < block_end)
3420 unsigned long reg, tmp;
3427 /* Warning: if you add any more cases to this switch, be
3428 sure to add them to the corresponding switch below. */
3431 case DW_CFA_advance_loc:
3435 frame_need_space (fc, opa);
3436 fc->col_type[opa] = DW_CFA_undefined;
3438 case DW_CFA_restore:
3439 frame_need_space (fc, opa);
3440 fc->col_type[opa] = DW_CFA_undefined;
3442 case DW_CFA_set_loc:
3443 start += encoded_ptr_size;
3445 case DW_CFA_advance_loc1:
3448 case DW_CFA_advance_loc2:
3451 case DW_CFA_advance_loc4:
3454 case DW_CFA_offset_extended:
3455 case DW_CFA_val_offset:
3456 reg = LEB (); LEB ();
3457 frame_need_space (fc, reg);
3458 fc->col_type[reg] = DW_CFA_undefined;
3460 case DW_CFA_restore_extended:
3462 frame_need_space (fc, reg);
3463 fc->col_type[reg] = DW_CFA_undefined;
3465 case DW_CFA_undefined:
3467 frame_need_space (fc, reg);
3468 fc->col_type[reg] = DW_CFA_undefined;
3470 case DW_CFA_same_value:
3472 frame_need_space (fc, reg);
3473 fc->col_type[reg] = DW_CFA_undefined;
3475 case DW_CFA_register:
3476 reg = LEB (); LEB ();
3477 frame_need_space (fc, reg);
3478 fc->col_type[reg] = DW_CFA_undefined;
3480 case DW_CFA_def_cfa:
3483 case DW_CFA_def_cfa_register:
3486 case DW_CFA_def_cfa_offset:
3489 case DW_CFA_def_cfa_expression:
3493 case DW_CFA_expression:
3494 case DW_CFA_val_expression:
3498 frame_need_space (fc, reg);
3499 fc->col_type[reg] = DW_CFA_undefined;
3501 case DW_CFA_offset_extended_sf:
3502 case DW_CFA_val_offset_sf:
3503 reg = LEB (); SLEB ();
3504 frame_need_space (fc, reg);
3505 fc->col_type[reg] = DW_CFA_undefined;
3507 case DW_CFA_def_cfa_sf:
3510 case DW_CFA_def_cfa_offset_sf:
3513 case DW_CFA_MIPS_advance_loc8:
3516 case DW_CFA_GNU_args_size:
3519 case DW_CFA_GNU_negative_offset_extended:
3520 reg = LEB (); LEB ();
3521 frame_need_space (fc, reg);
3522 fc->col_type[reg] = DW_CFA_undefined;
3531 /* Now we know what registers are used, make a second pass over
3532 the chunk, this time actually printing out the info. */
3534 while (start < block_end)
3537 unsigned long ul, reg, roffs;
3546 /* Warning: if you add any more cases to this switch, be
3547 sure to add them to the corresponding switch above. */
3550 case DW_CFA_advance_loc:
3551 if (do_debug_frames_interp)
3552 frame_display_row (fc, &need_col_headers, &max_regs);
3554 printf (" DW_CFA_advance_loc: %d to %08lx\n",
3555 opa * fc->code_factor,
3556 fc->pc_begin + opa * fc->code_factor);
3557 fc->pc_begin += opa * fc->code_factor;
3562 if (! do_debug_frames_interp)
3563 printf (" DW_CFA_offset: r%d at cfa%+ld\n",
3564 opa, roffs * fc->data_factor);
3565 fc->col_type[opa] = DW_CFA_offset;
3566 fc->col_offset[opa] = roffs * fc->data_factor;
3569 case DW_CFA_restore:
3570 if (! do_debug_frames_interp)
3571 printf (" DW_CFA_restore: r%d\n", opa);
3572 fc->col_type[opa] = cie->col_type[opa];
3573 fc->col_offset[opa] = cie->col_offset[opa];
3576 case DW_CFA_set_loc:
3577 vma = get_encoded_value (start, fc->fde_encoding);
3578 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
3579 vma += section->address + (start - section_start);
3580 start += encoded_ptr_size;
3581 if (do_debug_frames_interp)
3582 frame_display_row (fc, &need_col_headers, &max_regs);
3584 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
3588 case DW_CFA_advance_loc1:
3589 ofs = byte_get (start, 1); start += 1;
3590 if (do_debug_frames_interp)
3591 frame_display_row (fc, &need_col_headers, &max_regs);
3593 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
3594 ofs * fc->code_factor,
3595 fc->pc_begin + ofs * fc->code_factor);
3596 fc->pc_begin += ofs * fc->code_factor;
3599 case DW_CFA_advance_loc2:
3600 ofs = byte_get (start, 2); start += 2;
3601 if (do_debug_frames_interp)
3602 frame_display_row (fc, &need_col_headers, &max_regs);
3604 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
3605 ofs * fc->code_factor,
3606 fc->pc_begin + ofs * fc->code_factor);
3607 fc->pc_begin += ofs * fc->code_factor;
3610 case DW_CFA_advance_loc4:
3611 ofs = byte_get (start, 4); start += 4;
3612 if (do_debug_frames_interp)
3613 frame_display_row (fc, &need_col_headers, &max_regs);
3615 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
3616 ofs * fc->code_factor,
3617 fc->pc_begin + ofs * fc->code_factor);
3618 fc->pc_begin += ofs * fc->code_factor;
3621 case DW_CFA_offset_extended:
3624 if (! do_debug_frames_interp)
3625 printf (" DW_CFA_offset_extended: r%ld at cfa%+ld\n",
3626 reg, roffs * fc->data_factor);
3627 fc->col_type[reg] = DW_CFA_offset;
3628 fc->col_offset[reg] = roffs * fc->data_factor;
3631 case DW_CFA_val_offset:
3634 if (! do_debug_frames_interp)
3635 printf (" DW_CFA_val_offset: r%ld at cfa%+ld\n",
3636 reg, roffs * fc->data_factor);
3637 fc->col_type[reg] = DW_CFA_val_offset;
3638 fc->col_offset[reg] = roffs * fc->data_factor;
3641 case DW_CFA_restore_extended:
3643 if (! do_debug_frames_interp)
3644 printf (" DW_CFA_restore_extended: r%ld\n", reg);
3645 fc->col_type[reg] = cie->col_type[reg];
3646 fc->col_offset[reg] = cie->col_offset[reg];
3649 case DW_CFA_undefined:
3651 if (! do_debug_frames_interp)
3652 printf (" DW_CFA_undefined: r%ld\n", reg);
3653 fc->col_type[reg] = DW_CFA_undefined;
3654 fc->col_offset[reg] = 0;
3657 case DW_CFA_same_value:
3659 if (! do_debug_frames_interp)
3660 printf (" DW_CFA_same_value: r%ld\n", reg);
3661 fc->col_type[reg] = DW_CFA_same_value;
3662 fc->col_offset[reg] = 0;
3665 case DW_CFA_register:
3668 if (! do_debug_frames_interp)
3669 printf (" DW_CFA_register: r%ld in r%ld\n", reg, roffs);
3670 fc->col_type[reg] = DW_CFA_register;
3671 fc->col_offset[reg] = roffs;
3674 case DW_CFA_remember_state:
3675 if (! do_debug_frames_interp)
3676 printf (" DW_CFA_remember_state\n");
3677 rs = xmalloc (sizeof (Frame_Chunk));
3678 rs->ncols = fc->ncols;
3679 rs->col_type = xcmalloc (rs->ncols, sizeof (short int));
3680 rs->col_offset = xcmalloc (rs->ncols, sizeof (int));
3681 memcpy (rs->col_type, fc->col_type, rs->ncols);
3682 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
3683 rs->next = remembered_state;
3684 remembered_state = rs;
3687 case DW_CFA_restore_state:
3688 if (! do_debug_frames_interp)
3689 printf (" DW_CFA_restore_state\n");
3690 rs = remembered_state;
3693 remembered_state = rs->next;
3694 frame_need_space (fc, rs->ncols-1);
3695 memcpy (fc->col_type, rs->col_type, rs->ncols);
3696 memcpy (fc->col_offset, rs->col_offset,
3697 rs->ncols * sizeof (int));
3698 free (rs->col_type);
3699 free (rs->col_offset);
3702 else if (do_debug_frames_interp)
3703 printf ("Mismatched DW_CFA_restore_state\n");
3706 case DW_CFA_def_cfa:
3707 fc->cfa_reg = LEB ();
3708 fc->cfa_offset = LEB ();
3710 if (! do_debug_frames_interp)
3711 printf (" DW_CFA_def_cfa: r%d ofs %d\n",
3712 fc->cfa_reg, fc->cfa_offset);
3715 case DW_CFA_def_cfa_register:
3716 fc->cfa_reg = LEB ();
3718 if (! do_debug_frames_interp)
3719 printf (" DW_CFA_def_cfa_reg: r%d\n", fc->cfa_reg);
3722 case DW_CFA_def_cfa_offset:
3723 fc->cfa_offset = LEB ();
3724 if (! do_debug_frames_interp)
3725 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
3729 if (! do_debug_frames_interp)
3730 printf (" DW_CFA_nop\n");
3733 case DW_CFA_def_cfa_expression:
3735 if (! do_debug_frames_interp)
3737 printf (" DW_CFA_def_cfa_expression (");
3738 decode_location_expression (start, eh_addr_size, ul, 0);
3745 case DW_CFA_expression:
3748 if (! do_debug_frames_interp)
3750 printf (" DW_CFA_expression: r%ld (", reg);
3751 decode_location_expression (start, eh_addr_size, ul, 0);
3754 fc->col_type[reg] = DW_CFA_expression;
3758 case DW_CFA_val_expression:
3761 if (! do_debug_frames_interp)
3763 printf (" DW_CFA_val_expression: r%ld (", reg);
3764 decode_location_expression (start, eh_addr_size, ul, 0);
3767 fc->col_type[reg] = DW_CFA_val_expression;
3771 case DW_CFA_offset_extended_sf:
3774 frame_need_space (fc, reg);
3775 if (! do_debug_frames_interp)
3776 printf (" DW_CFA_offset_extended_sf: r%ld at cfa%+ld\n",
3777 reg, l * fc->data_factor);
3778 fc->col_type[reg] = DW_CFA_offset;
3779 fc->col_offset[reg] = l * fc->data_factor;
3782 case DW_CFA_val_offset_sf:
3785 frame_need_space (fc, reg);
3786 if (! do_debug_frames_interp)
3787 printf (" DW_CFA_val_offset_sf: r%ld at cfa%+ld\n",
3788 reg, l * fc->data_factor);
3789 fc->col_type[reg] = DW_CFA_val_offset;
3790 fc->col_offset[reg] = l * fc->data_factor;
3793 case DW_CFA_def_cfa_sf:
3794 fc->cfa_reg = LEB ();
3795 fc->cfa_offset = SLEB ();
3796 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3798 if (! do_debug_frames_interp)
3799 printf (" DW_CFA_def_cfa_sf: r%d ofs %d\n",
3800 fc->cfa_reg, fc->cfa_offset);
3803 case DW_CFA_def_cfa_offset_sf:
3804 fc->cfa_offset = SLEB ();
3805 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
3806 if (! do_debug_frames_interp)
3807 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
3810 case DW_CFA_MIPS_advance_loc8:
3811 ofs = byte_get (start, 8); start += 8;
3812 if (do_debug_frames_interp)
3813 frame_display_row (fc, &need_col_headers, &max_regs);
3815 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
3816 ofs * fc->code_factor,
3817 fc->pc_begin + ofs * fc->code_factor);
3818 fc->pc_begin += ofs * fc->code_factor;
3821 case DW_CFA_GNU_window_save:
3822 if (! do_debug_frames_interp)
3823 printf (" DW_CFA_GNU_window_save\n");
3826 case DW_CFA_GNU_args_size:
3828 if (! do_debug_frames_interp)
3829 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
3832 case DW_CFA_GNU_negative_offset_extended:
3835 frame_need_space (fc, reg);
3836 if (! do_debug_frames_interp)
3837 printf (" DW_CFA_GNU_negative_offset_extended: r%ld at cfa%+ld\n",
3838 reg, l * fc->data_factor);
3839 fc->col_type[reg] = DW_CFA_offset;
3840 fc->col_offset[reg] = l * fc->data_factor;
3844 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
3845 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
3847 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
3852 if (do_debug_frames_interp)
3853 frame_display_row (fc, &need_col_headers, &max_regs);
3868 display_debug_not_supported (struct dwarf_section *section,
3869 void *file ATTRIBUTE_UNUSED)
3871 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
3878 cmalloc (size_t nmemb, size_t size)
3880 /* Check for overflow. */
3881 if (nmemb >= ~(size_t) 0 / size)
3884 return malloc (nmemb * size);
3888 xcmalloc (size_t nmemb, size_t size)
3890 /* Check for overflow. */
3891 if (nmemb >= ~(size_t) 0 / size)
3894 return xmalloc (nmemb * size);
3898 xcrealloc (void *ptr, size_t nmemb, size_t size)
3900 /* Check for overflow. */
3901 if (nmemb >= ~(size_t) 0 / size)
3904 return xrealloc (ptr, nmemb * size);
3908 error (const char *message, ...)
3912 va_start (args, message);
3913 fprintf (stderr, _("%s: Error: "), program_name);
3914 vfprintf (stderr, message, args);
3919 warn (const char *message, ...)
3923 va_start (args, message);
3924 fprintf (stderr, _("%s: Warning: "), program_name);
3925 vfprintf (stderr, message, args);
3930 free_debug_memory (void)
3932 enum dwarf_section_display_enum i;
3936 for (i = 0; i < max; i++)
3937 free_debug_section (i);
3939 if (debug_information)
3941 for (i = 0; i < num_debug_info_entries; i++)
3943 if (!debug_information [i].max_loc_offsets)
3945 free (debug_information [i].loc_offsets);
3946 free (debug_information [i].have_frame_base);
3948 if (!debug_information [i].max_range_lists)
3949 free (debug_information [i].range_lists);
3951 free (debug_information);
3952 debug_information = NULL;
3953 num_debug_info_entries = 0;
3958 struct dwarf_section_display debug_displays[] =
3960 { { ".debug_abbrev", NULL, 0, 0 },
3961 display_debug_abbrev, 0, 0 },
3962 { { ".debug_aranges", NULL, 0, 0 },
3963 display_debug_aranges, 0, 0 },
3964 { { ".debug_frame", NULL, 0, 0 },
3965 display_debug_frames, 1, 0 },
3966 { { ".debug_info", NULL, 0, 0 },
3967 display_debug_info, 1, 0 },
3968 { { ".debug_line", NULL, 0, 0 },
3969 display_debug_lines, 0, 0 },
3970 { { ".debug_pubnames", NULL, 0, 0 },
3971 display_debug_pubnames, 0, 0 },
3972 { { ".eh_frame", NULL, 0, 0 },
3973 display_debug_frames, 1, 1 },
3974 { { ".debug_macinfo", NULL, 0, 0 },
3975 display_debug_macinfo, 0, 0 },
3976 { { ".debug_str", NULL, 0, 0 },
3977 display_debug_str, 0, 0 },
3978 { { ".debug_loc", NULL, 0, 0 },
3979 display_debug_loc, 0, 0 },
3980 { { ".debug_pubtypes", NULL, 0, 0 },
3981 display_debug_pubnames, 0, 0 },
3982 { { ".debug_ranges", NULL, 0, 0 },
3983 display_debug_ranges, 0, 0 },
3984 { { ".debug_static_func", NULL, 0, 0 },
3985 display_debug_not_supported, 0, 0 },
3986 { { ".debug_static_vars", NULL, 0, 0 },
3987 display_debug_not_supported, 0, 0 },
3988 { { ".debug_types", NULL, 0, 0 },
3989 display_debug_not_supported, 0, 0 },
3990 { { ".debug_weaknames", NULL, 0, 0 },
3991 display_debug_not_supported, 0, 0 }