1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
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"
25 #include "bfd_stdint.h"
28 #include "elf/common.h"
31 #include "gdb/gdb-index.h"
33 static const char *regname (unsigned int regno, int row);
35 static int have_frame_base;
36 static int need_base_address;
38 static unsigned int last_pointer_size = 0;
39 static int warned_about_missing_comp_units = FALSE;
41 static unsigned int num_debug_info_entries = 0;
42 static debug_info *debug_information = NULL;
43 /* Special value for num_debug_info_entries to indicate
44 that the .debug_info section could not be loaded/parsed. */
45 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
52 int do_debug_pubnames;
53 int do_debug_pubtypes;
57 int do_debug_frames_interp;
67 int dwarf_cutoff_level = -1;
68 unsigned long dwarf_start_die;
72 /* Values for do_debug_lines. */
73 #define FLAG_DEBUG_LINES_RAW 1
74 #define FLAG_DEBUG_LINES_DECODED 2
77 size_of_encoded_value (int encoding)
79 switch (encoding & 0x7)
82 case 0: return eh_addr_size;
90 get_encoded_value (unsigned char *data,
92 struct dwarf_section *section)
94 int size = size_of_encoded_value (encoding);
97 if (encoding & DW_EH_PE_signed)
98 val = byte_get_signed (data, size);
100 val = byte_get (data, size);
102 if ((encoding & 0x70) == DW_EH_PE_pcrel)
103 val += section->address + (data - section->start);
107 /* Print a dwarf_vma value (typically an address, offset or length) in
108 hexadecimal format, followed by a space. The length of the value (and
109 hence the precision displayed) is determined by the byte_size parameter. */
112 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
114 static char buff[18];
117 /* Printf does not have a way of specifiying a maximum field width for an
118 integer value, so we print the full value into a buffer and then select
119 the precision we need. */
120 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
122 snprintf (buff, sizeof (buff), "%16.16llx ", val);
124 snprintf (buff, sizeof (buff), "%016I64x ", val);
127 snprintf (buff, sizeof (buff), "%16.16lx ", val);
132 if (byte_size > 0 && byte_size <= 8)
133 offset = 16 - 2 * byte_size;
135 error (_("Wrong size in print_dwarf_vma"));
138 fputs (buff + offset, stdout);
141 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
143 #define DWARF_VMA_FMT "ll"
145 #define DWARF_VMA_FMT "I64"
148 #define DWARF_VMA_FMT "l"
152 dwarf_vmatoa (const char *fmtch, dwarf_vma value)
154 /* As dwarf_vmatoa is used more then once in a printf call
155 for output, we are cycling through an fixed array of pointers
156 for return address. */
157 static int buf_pos = 0;
158 static struct dwarf_vmatoa_buf
165 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
167 ret = buf[buf_pos++].place;
168 buf_pos %= ARRAY_SIZE (buf);
170 snprintf (ret, sizeof (buf[0].place), fmt, value);
175 /* Format a 64-bit value, given as two 32-bit values, in hex.
176 For reentrancy, this uses a buffer provided by the caller. */
179 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
180 unsigned int buf_len)
185 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
188 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
189 snprintf (buf + len, buf_len - len,
190 "%08" DWARF_VMA_FMT "x", lvalue);
197 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
199 dwarf_vma result = 0;
200 unsigned int num_read = 0;
201 unsigned int shift = 0;
209 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
216 if (length_return != NULL)
217 *length_return = num_read;
219 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
220 result |= -1L << shift;
225 /* Create a signed version to avoid painful typecasts. */
226 static dwarf_signed_vma
227 read_sleb128 (unsigned char *data, unsigned int *length_return)
229 return (dwarf_signed_vma) read_leb128 (data, length_return, 1);
232 typedef struct State_Machine_Registers
240 unsigned char op_index;
241 unsigned char end_sequence;
242 /* This variable hold the number of the last entry seen
243 in the File Table. */
244 unsigned int last_file_entry;
247 static SMR state_machine_regs;
250 reset_state_machine (int is_stmt)
252 state_machine_regs.address = 0;
253 state_machine_regs.op_index = 0;
254 state_machine_regs.file = 1;
255 state_machine_regs.line = 1;
256 state_machine_regs.column = 0;
257 state_machine_regs.is_stmt = is_stmt;
258 state_machine_regs.basic_block = 0;
259 state_machine_regs.end_sequence = 0;
260 state_machine_regs.last_file_entry = 0;
263 /* Handled an extend line op.
264 Returns the number of bytes read. */
267 process_extended_line_op (unsigned char *data, int is_stmt)
269 unsigned char op_code;
270 unsigned int bytes_read;
274 unsigned char *orig_data = data;
276 len = read_leb128 (data, & bytes_read, 0);
281 warn (_("badly formed extended line op encountered!\n"));
288 printf (_(" Extended opcode %d: "), op_code);
292 case DW_LNE_end_sequence:
293 printf (_("End of Sequence\n\n"));
294 reset_state_machine (is_stmt);
297 case DW_LNE_set_address:
298 adr = byte_get (data, len - bytes_read - 1);
299 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
300 state_machine_regs.address = adr;
301 state_machine_regs.op_index = 0;
304 case DW_LNE_define_file:
305 printf (_("define new File Table entry\n"));
306 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
308 printf (" %d\t", ++state_machine_regs.last_file_entry);
310 data += strlen ((char *) data) + 1;
311 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
313 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
315 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
318 if ((unsigned int) (data - orig_data) != len)
319 printf (_(" [Bad opcode length]"));
323 case DW_LNE_set_discriminator:
324 printf (_("set Discriminator to %s\n"),
325 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
329 case DW_LNE_HP_negate_is_UV_update:
330 printf ("DW_LNE_HP_negate_is_UV_update\n");
332 case DW_LNE_HP_push_context:
333 printf ("DW_LNE_HP_push_context\n");
335 case DW_LNE_HP_pop_context:
336 printf ("DW_LNE_HP_pop_context\n");
338 case DW_LNE_HP_set_file_line_column:
339 printf ("DW_LNE_HP_set_file_line_column\n");
341 case DW_LNE_HP_set_routine_name:
342 printf ("DW_LNE_HP_set_routine_name\n");
344 case DW_LNE_HP_set_sequence:
345 printf ("DW_LNE_HP_set_sequence\n");
347 case DW_LNE_HP_negate_post_semantics:
348 printf ("DW_LNE_HP_negate_post_semantics\n");
350 case DW_LNE_HP_negate_function_exit:
351 printf ("DW_LNE_HP_negate_function_exit\n");
353 case DW_LNE_HP_negate_front_end_logical:
354 printf ("DW_LNE_HP_negate_front_end_logical\n");
356 case DW_LNE_HP_define_proc:
357 printf ("DW_LNE_HP_define_proc\n");
359 case DW_LNE_HP_source_file_correlation:
361 unsigned char *edata = data + len - bytes_read - 1;
363 printf ("DW_LNE_HP_source_file_correlation\n");
369 opc = read_leb128 (data, & bytes_read, 0);
374 case DW_LNE_HP_SFC_formfeed:
375 printf (" DW_LNE_HP_SFC_formfeed\n");
377 case DW_LNE_HP_SFC_set_listing_line:
378 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
380 read_leb128 (data, & bytes_read, 0)));
383 case DW_LNE_HP_SFC_associate:
384 printf (" DW_LNE_HP_SFC_associate ");
387 read_leb128 (data, & bytes_read, 0)));
391 read_leb128 (data, & bytes_read, 0)));
395 read_leb128 (data, & bytes_read, 0)));
399 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
409 unsigned int rlen = len - bytes_read - 1;
411 if (op_code >= DW_LNE_lo_user
412 /* The test against DW_LNW_hi_user is redundant due to
413 the limited range of the unsigned char data type used
415 /*&& op_code <= DW_LNE_hi_user*/)
416 printf (_("user defined: "));
418 printf (_("UNKNOWN: "));
419 printf (_("length %d ["), rlen);
421 printf (" %02x", *data++);
431 fetch_indirect_string (dwarf_vma offset)
433 struct dwarf_section *section = &debug_displays [str].section;
435 if (section->start == NULL)
436 return _("<no .debug_str section>");
438 /* DWARF sections under Mach-O have non-zero addresses. */
439 offset -= section->address;
440 if (offset > section->size)
442 warn (_("DW_FORM_strp offset too big: %s\n"),
443 dwarf_vmatoa ("x", offset));
444 return _("<offset is too big>");
447 return (const char *) section->start + offset;
451 fetch_indexed_string (dwarf_vma idx, dwarf_vma offset_size, int dwo)
453 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
454 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
455 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
456 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
457 dwarf_vma index_offset = idx * offset_size;
458 dwarf_vma str_offset;
460 if (index_section->start == NULL)
461 return (dwo ? _("<no .debug_str_offsets.dwo section>")
462 : _("<no .debug_str_offsets section>"));
464 /* DWARF sections under Mach-O have non-zero addresses. */
465 index_offset -= index_section->address;
466 if (index_offset > index_section->size)
468 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
469 dwarf_vmatoa ("x", index_offset));
470 return _("<index offset is too big>");
473 if (str_section->start == NULL)
474 return (dwo ? _("<no .debug_str.dwo section>")
475 : _("<no .debug_str section>"));
477 str_offset = byte_get (index_section->start + index_offset, offset_size);
478 str_offset -= str_section->address;
479 if (str_offset > str_section->size)
481 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
482 dwarf_vmatoa ("x", str_offset));
483 return _("<indirect index offset is too big>");
486 return (const char *) str_section->start + str_offset;
490 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
492 struct dwarf_section *section = &debug_displays [debug_addr].section;
494 if (section->start == NULL)
495 return (_("<no .debug_addr section>"));
497 if (offset + bytes > section->size)
499 warn (_("Offset into section %s too big: %s\n"),
500 section->name, dwarf_vmatoa ("x", offset));
501 return "<offset too big>";
504 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
508 /* FIXME: There are better and more efficient ways to handle
509 these structures. For now though, I just want something that
510 is simple to implement. */
511 typedef struct abbrev_attr
513 unsigned long attribute;
515 struct abbrev_attr *next;
519 typedef struct abbrev_entry
524 struct abbrev_attr *first_attr;
525 struct abbrev_attr *last_attr;
526 struct abbrev_entry *next;
530 static abbrev_entry *first_abbrev = NULL;
531 static abbrev_entry *last_abbrev = NULL;
538 for (abbrv = first_abbrev; abbrv;)
540 abbrev_entry *next_abbrev = abbrv->next;
543 for (attr = abbrv->first_attr; attr;)
545 abbrev_attr *next_attr = attr->next;
555 last_abbrev = first_abbrev = NULL;
559 add_abbrev (unsigned long number, unsigned long tag, int children)
563 entry = (abbrev_entry *) malloc (sizeof (*entry));
568 entry->entry = number;
570 entry->children = children;
571 entry->first_attr = NULL;
572 entry->last_attr = NULL;
575 if (first_abbrev == NULL)
576 first_abbrev = entry;
578 last_abbrev->next = entry;
584 add_abbrev_attr (unsigned long attribute, unsigned long form)
588 attr = (abbrev_attr *) malloc (sizeof (*attr));
593 attr->attribute = attribute;
597 if (last_abbrev->first_attr == NULL)
598 last_abbrev->first_attr = attr;
600 last_abbrev->last_attr->next = attr;
602 last_abbrev->last_attr = attr;
605 /* Processes the (partial) contents of a .debug_abbrev section.
606 Returns NULL if the end of the section was encountered.
607 Returns the address after the last byte read if the end of
608 an abbreviation set was found. */
610 static unsigned char *
611 process_abbrev_section (unsigned char *start, unsigned char *end)
613 if (first_abbrev != NULL)
618 unsigned int bytes_read;
621 unsigned long attribute;
624 entry = read_leb128 (start, & bytes_read, 0);
627 /* A single zero is supposed to end the section according
628 to the standard. If there's more, then signal that to
631 return start == end ? NULL : start;
633 tag = read_leb128 (start, & bytes_read, 0);
638 add_abbrev (entry, tag, children);
644 attribute = read_leb128 (start, & bytes_read, 0);
647 form = read_leb128 (start, & bytes_read, 0);
650 add_abbrev_attr (attribute, form);
652 while (attribute != 0);
655 /* Report the missing single zero which ends the section. */
656 error (_(".debug_abbrev section not zero terminated\n"));
662 get_TAG_name (unsigned long tag)
664 const char *name = get_DW_TAG_name ((unsigned int)tag);
668 static char buffer[100];
670 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
678 get_FORM_name (unsigned long form)
683 return "DW_FORM value: 0";
685 name = get_DW_FORM_name (form);
688 static char buffer[100];
690 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
697 static unsigned char *
698 display_block (unsigned char *data, dwarf_vma length)
700 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
703 printf ("%lx ", (unsigned long) byte_get (data++, 1));
709 decode_location_expression (unsigned char * data,
710 unsigned int pointer_size,
711 unsigned int offset_size,
715 struct dwarf_section * section)
718 unsigned int bytes_read;
720 unsigned char *end = data + length;
721 int need_frame_base = 0;
730 printf ("DW_OP_addr: %s",
731 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
732 data += pointer_size;
735 printf ("DW_OP_deref");
738 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
741 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
744 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
748 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
752 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
756 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
760 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
761 (unsigned long) byte_get (data + 4, 4));
765 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
766 (long) byte_get (data + 4, 4));
770 printf ("DW_OP_constu: %s",
771 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
775 printf ("DW_OP_consts: %s",
776 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
780 printf ("DW_OP_dup");
783 printf ("DW_OP_drop");
786 printf ("DW_OP_over");
789 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
792 printf ("DW_OP_swap");
795 printf ("DW_OP_rot");
798 printf ("DW_OP_xderef");
801 printf ("DW_OP_abs");
804 printf ("DW_OP_and");
807 printf ("DW_OP_div");
810 printf ("DW_OP_minus");
813 printf ("DW_OP_mod");
816 printf ("DW_OP_mul");
819 printf ("DW_OP_neg");
822 printf ("DW_OP_not");
828 printf ("DW_OP_plus");
830 case DW_OP_plus_uconst:
831 printf ("DW_OP_plus_uconst: %s",
832 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
836 printf ("DW_OP_shl");
839 printf ("DW_OP_shr");
842 printf ("DW_OP_shra");
845 printf ("DW_OP_xor");
848 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
870 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
906 printf ("DW_OP_lit%d", op - DW_OP_lit0);
941 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
942 regname (op - DW_OP_reg0, 1));
977 printf ("DW_OP_breg%d (%s): %s",
979 regname (op - DW_OP_breg0, 1),
980 dwarf_vmatoa ("d", (dwarf_signed_vma)
981 read_leb128 (data, &bytes_read, 1)));
986 uvalue = read_leb128 (data, &bytes_read, 0);
988 printf ("DW_OP_regx: %s (%s)",
989 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
993 printf ("DW_OP_fbreg: %s",
994 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
998 uvalue = read_leb128 (data, &bytes_read, 0);
1000 printf ("DW_OP_bregx: %s (%s) %s",
1001 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1002 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1006 printf ("DW_OP_piece: %s",
1007 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1010 case DW_OP_deref_size:
1011 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
1013 case DW_OP_xderef_size:
1014 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
1017 printf ("DW_OP_nop");
1020 /* DWARF 3 extensions. */
1021 case DW_OP_push_object_address:
1022 printf ("DW_OP_push_object_address");
1025 /* XXX: Strictly speaking for 64-bit DWARF3 files
1026 this ought to be an 8-byte wide computation. */
1027 printf ("DW_OP_call2: <0x%s>",
1028 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2)
1033 /* XXX: Strictly speaking for 64-bit DWARF3 files
1034 this ought to be an 8-byte wide computation. */
1035 printf ("DW_OP_call4: <0x%s>",
1036 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4)
1040 case DW_OP_call_ref:
1041 /* XXX: Strictly speaking for 64-bit DWARF3 files
1042 this ought to be an 8-byte wide computation. */
1043 if (dwarf_version == -1)
1045 printf (_("(DW_OP_call_ref in frame info)"));
1046 /* No way to tell where the next op is, so just bail. */
1047 return need_frame_base;
1049 if (dwarf_version == 2)
1051 printf ("DW_OP_call_ref: <0x%s>",
1052 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
1053 data += pointer_size;
1057 printf ("DW_OP_call_ref: <0x%s>",
1058 dwarf_vmatoa ("x", byte_get (data, offset_size)));
1059 data += offset_size;
1062 case DW_OP_form_tls_address:
1063 printf ("DW_OP_form_tls_address");
1065 case DW_OP_call_frame_cfa:
1066 printf ("DW_OP_call_frame_cfa");
1068 case DW_OP_bit_piece:
1069 printf ("DW_OP_bit_piece: ");
1070 printf (_("size: %s "),
1071 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1073 printf (_("offset: %s "),
1074 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1078 /* DWARF 4 extensions. */
1079 case DW_OP_stack_value:
1080 printf ("DW_OP_stack_value");
1083 case DW_OP_implicit_value:
1084 printf ("DW_OP_implicit_value");
1085 uvalue = read_leb128 (data, &bytes_read, 0);
1087 display_block (data, uvalue);
1091 /* GNU extensions. */
1092 case DW_OP_GNU_push_tls_address:
1093 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1095 case DW_OP_GNU_uninit:
1096 printf ("DW_OP_GNU_uninit");
1097 /* FIXME: Is there data associated with this OP ? */
1099 case DW_OP_GNU_encoded_addr:
1105 addr = get_encoded_value (data, encoding, section);
1106 data += size_of_encoded_value (encoding);
1108 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1109 print_dwarf_vma (addr, pointer_size);
1112 case DW_OP_GNU_implicit_pointer:
1113 /* XXX: Strictly speaking for 64-bit DWARF3 files
1114 this ought to be an 8-byte wide computation. */
1115 if (dwarf_version == -1)
1117 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1118 /* No way to tell where the next op is, so just bail. */
1119 return need_frame_base;
1121 if (dwarf_version == 2)
1123 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1124 dwarf_vmatoa ("x", byte_get (data, pointer_size)),
1125 dwarf_vmatoa ("d", read_sleb128 (data + pointer_size,
1127 data += pointer_size + bytes_read;
1131 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1132 dwarf_vmatoa ("x", byte_get (data, offset_size)),
1133 dwarf_vmatoa ("d", read_sleb128 (data + offset_size,
1135 data += offset_size + bytes_read;
1138 case DW_OP_GNU_entry_value:
1139 uvalue = read_leb128 (data, &bytes_read, 0);
1141 printf ("DW_OP_GNU_entry_value: (");
1142 if (decode_location_expression (data, pointer_size, offset_size,
1143 dwarf_version, uvalue,
1144 cu_offset, section))
1145 need_frame_base = 1;
1149 case DW_OP_GNU_const_type:
1150 uvalue = read_leb128 (data, &bytes_read, 0);
1152 printf ("DW_OP_GNU_const_type: <0x%s> ",
1153 dwarf_vmatoa ("x", cu_offset + uvalue));
1154 uvalue = byte_get (data++, 1);
1155 display_block (data, uvalue);
1158 case DW_OP_GNU_regval_type:
1159 uvalue = read_leb128 (data, &bytes_read, 0);
1161 printf ("DW_OP_GNU_regval_type: %s (%s)",
1162 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1163 uvalue = read_leb128 (data, &bytes_read, 0);
1165 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1167 case DW_OP_GNU_deref_type:
1168 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data++, 1));
1169 uvalue = read_leb128 (data, &bytes_read, 0);
1171 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1173 case DW_OP_GNU_convert:
1174 uvalue = read_leb128 (data, &bytes_read, 0);
1176 printf ("DW_OP_GNU_convert <0x%s>",
1177 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1179 case DW_OP_GNU_reinterpret:
1180 uvalue = read_leb128 (data, &bytes_read, 0);
1182 printf ("DW_OP_GNU_reinterpret <0x%s>",
1183 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1185 case DW_OP_GNU_parameter_ref:
1186 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1187 dwarf_vmatoa ("x", cu_offset + byte_get (data, 4)));
1190 case DW_OP_GNU_addr_index:
1191 uvalue = read_leb128 (data, &bytes_read, 0);
1193 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1196 /* HP extensions. */
1197 case DW_OP_HP_is_value:
1198 printf ("DW_OP_HP_is_value");
1199 /* FIXME: Is there data associated with this OP ? */
1201 case DW_OP_HP_fltconst4:
1202 printf ("DW_OP_HP_fltconst4");
1203 /* FIXME: Is there data associated with this OP ? */
1205 case DW_OP_HP_fltconst8:
1206 printf ("DW_OP_HP_fltconst8");
1207 /* FIXME: Is there data associated with this OP ? */
1209 case DW_OP_HP_mod_range:
1210 printf ("DW_OP_HP_mod_range");
1211 /* FIXME: Is there data associated with this OP ? */
1213 case DW_OP_HP_unmod_range:
1214 printf ("DW_OP_HP_unmod_range");
1215 /* FIXME: Is there data associated with this OP ? */
1218 printf ("DW_OP_HP_tls");
1219 /* FIXME: Is there data associated with this OP ? */
1222 /* PGI (STMicroelectronics) extensions. */
1223 case DW_OP_PGI_omp_thread_num:
1224 /* Pushes the thread number for the current thread as it would be
1225 returned by the standard OpenMP library function:
1226 omp_get_thread_num(). The "current thread" is the thread for
1227 which the expression is being evaluated. */
1228 printf ("DW_OP_PGI_omp_thread_num");
1232 if (op >= DW_OP_lo_user
1233 && op <= DW_OP_hi_user)
1234 printf (_("(User defined location op)"));
1236 printf (_("(Unknown location op)"));
1237 /* No way to tell where the next op is, so just bail. */
1238 return need_frame_base;
1241 /* Separate the ops. */
1246 return need_frame_base;
1249 static unsigned char *
1250 read_and_display_attr_value (unsigned long attribute,
1252 unsigned char * data,
1253 dwarf_vma cu_offset,
1254 dwarf_vma pointer_size,
1255 dwarf_vma offset_size,
1257 debug_info * debug_info_p,
1259 struct dwarf_section * section)
1261 dwarf_vma uvalue = 0;
1262 unsigned char *block_start = NULL;
1263 unsigned char * orig_data = data;
1264 unsigned int bytes_read;
1271 case DW_FORM_ref_addr:
1272 if (dwarf_version == 2)
1274 uvalue = byte_get (data, pointer_size);
1275 data += pointer_size;
1277 else if (dwarf_version == 3 || dwarf_version == 4)
1279 uvalue = byte_get (data, offset_size);
1280 data += offset_size;
1283 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1288 uvalue = byte_get (data, pointer_size);
1289 data += pointer_size;
1293 case DW_FORM_sec_offset:
1294 case DW_FORM_GNU_ref_alt:
1295 case DW_FORM_GNU_strp_alt:
1296 uvalue = byte_get (data, offset_size);
1297 data += offset_size;
1300 case DW_FORM_flag_present:
1307 uvalue = byte_get (data++, 1);
1312 uvalue = byte_get (data, 2);
1318 uvalue = byte_get (data, 4);
1323 uvalue = read_leb128 (data, & bytes_read, 1);
1327 case DW_FORM_GNU_str_index:
1328 uvalue = read_leb128 (data, & bytes_read, 0);
1332 case DW_FORM_ref_udata:
1334 uvalue = read_leb128 (data, & bytes_read, 0);
1338 case DW_FORM_indirect:
1339 form = read_leb128 (data, & bytes_read, 0);
1342 printf (" %s", get_FORM_name (form));
1343 return read_and_display_attr_value (attribute, form, data,
1344 cu_offset, pointer_size,
1345 offset_size, dwarf_version,
1346 debug_info_p, do_loc,
1348 case DW_FORM_GNU_addr_index:
1349 uvalue = read_leb128 (data, & bytes_read, 0);
1356 case DW_FORM_ref_addr:
1358 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1361 case DW_FORM_GNU_ref_alt:
1363 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue));
1369 case DW_FORM_ref_udata:
1371 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1376 case DW_FORM_sec_offset:
1378 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1381 case DW_FORM_flag_present:
1388 printf (" %s", dwarf_vmatoa ("d", uvalue));
1395 dwarf_vma high_bits;
1398 byte_get_64 (data, &high_bits, &uvalue);
1400 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1402 if ((do_loc || do_debug_loc || do_debug_ranges)
1403 && num_debug_info_entries == 0)
1405 if (sizeof (uvalue) == 8)
1406 uvalue = byte_get (data, 8);
1408 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1413 case DW_FORM_string:
1415 printf (" %s", data);
1416 data += strlen ((char *) data) + 1;
1420 case DW_FORM_exprloc:
1421 uvalue = read_leb128 (data, & bytes_read, 0);
1422 block_start = data + bytes_read;
1424 data = block_start + uvalue;
1426 data = display_block (block_start, uvalue);
1429 case DW_FORM_block1:
1430 uvalue = byte_get (data, 1);
1431 block_start = data + 1;
1433 data = block_start + uvalue;
1435 data = display_block (block_start, uvalue);
1438 case DW_FORM_block2:
1439 uvalue = byte_get (data, 2);
1440 block_start = data + 2;
1442 data = block_start + uvalue;
1444 data = display_block (block_start, uvalue);
1447 case DW_FORM_block4:
1448 uvalue = byte_get (data, 4);
1449 block_start = data + 4;
1451 data = block_start + uvalue;
1453 data = display_block (block_start, uvalue);
1458 printf (_(" (indirect string, offset: 0x%s): %s"),
1459 dwarf_vmatoa ("x", uvalue),
1460 fetch_indirect_string (uvalue));
1463 case DW_FORM_GNU_str_index:
1466 const char *suffix = strrchr (section->name, '.');
1467 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1469 printf (_(" (indexed string: 0x%s): %s"),
1470 dwarf_vmatoa ("x", uvalue),
1471 fetch_indexed_string (uvalue, offset_size, dwo));
1475 case DW_FORM_GNU_strp_alt:
1477 printf (_(" (alt indirect string, offset: 0x%s)"),
1478 dwarf_vmatoa ("x", uvalue));
1481 case DW_FORM_indirect:
1482 /* Handled above. */
1485 case DW_FORM_ref_sig8:
1488 dwarf_vma high_bits;
1491 byte_get_64 (data, &high_bits, &uvalue);
1492 printf (" signature: 0x%s",
1493 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1498 case DW_FORM_GNU_addr_index:
1500 printf (_(" (addr_index: 0x%s): %s"),
1501 dwarf_vmatoa ("x", uvalue),
1502 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1506 warn (_("Unrecognized form: %lu\n"), form);
1510 if ((do_loc || do_debug_loc || do_debug_ranges)
1511 && num_debug_info_entries == 0
1512 && debug_info_p != NULL)
1516 case DW_AT_frame_base:
1517 have_frame_base = 1;
1518 case DW_AT_location:
1519 case DW_AT_string_length:
1520 case DW_AT_return_addr:
1521 case DW_AT_data_member_location:
1522 case DW_AT_vtable_elem_location:
1524 case DW_AT_static_link:
1525 case DW_AT_use_location:
1526 case DW_AT_GNU_call_site_value:
1527 case DW_AT_GNU_call_site_data_value:
1528 case DW_AT_GNU_call_site_target:
1529 case DW_AT_GNU_call_site_target_clobbered:
1530 if ((dwarf_version < 4
1531 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1532 || form == DW_FORM_sec_offset)
1534 /* Process location list. */
1535 unsigned int lmax = debug_info_p->max_loc_offsets;
1536 unsigned int num = debug_info_p->num_loc_offsets;
1538 if (lmax == 0 || num >= lmax)
1541 debug_info_p->loc_offsets = (dwarf_vma *)
1542 xcrealloc (debug_info_p->loc_offsets,
1543 lmax, sizeof (*debug_info_p->loc_offsets));
1544 debug_info_p->have_frame_base = (int *)
1545 xcrealloc (debug_info_p->have_frame_base,
1546 lmax, sizeof (*debug_info_p->have_frame_base));
1547 debug_info_p->max_loc_offsets = lmax;
1549 debug_info_p->loc_offsets [num] = uvalue;
1550 debug_info_p->have_frame_base [num] = have_frame_base;
1551 debug_info_p->num_loc_offsets++;
1556 if (need_base_address)
1557 debug_info_p->base_address = uvalue;
1560 case DW_AT_GNU_addr_base:
1561 debug_info_p->addr_base = uvalue;
1564 case DW_AT_GNU_ranges_base:
1565 debug_info_p->ranges_base = uvalue;
1569 if ((dwarf_version < 4
1570 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1571 || form == DW_FORM_sec_offset)
1573 /* Process range list. */
1574 unsigned int lmax = debug_info_p->max_range_lists;
1575 unsigned int num = debug_info_p->num_range_lists;
1577 if (lmax == 0 || num >= lmax)
1580 debug_info_p->range_lists = (dwarf_vma *)
1581 xcrealloc (debug_info_p->range_lists,
1582 lmax, sizeof (*debug_info_p->range_lists));
1583 debug_info_p->max_range_lists = lmax;
1585 debug_info_p->range_lists [num] = uvalue;
1586 debug_info_p->num_range_lists++;
1595 if (do_loc || attribute == 0)
1598 /* For some attributes we can display further information. */
1606 case DW_INL_not_inlined:
1607 printf (_("(not inlined)"));
1609 case DW_INL_inlined:
1610 printf (_("(inlined)"));
1612 case DW_INL_declared_not_inlined:
1613 printf (_("(declared as inline but ignored)"));
1615 case DW_INL_declared_inlined:
1616 printf (_("(declared as inline and inlined)"));
1619 printf (_(" (Unknown inline attribute value: %s)"),
1620 dwarf_vmatoa ("x", uvalue));
1625 case DW_AT_language:
1628 /* Ordered by the numeric value of these constants. */
1629 case DW_LANG_C89: printf ("(ANSI C)"); break;
1630 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1631 case DW_LANG_Ada83: printf ("(Ada)"); break;
1632 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1633 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1634 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1635 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1636 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1637 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1638 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1639 /* DWARF 2.1 values. */
1640 case DW_LANG_Java: printf ("(Java)"); break;
1641 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1642 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1643 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1644 /* DWARF 3 values. */
1645 case DW_LANG_PLI: printf ("(PLI)"); break;
1646 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1647 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1648 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1649 case DW_LANG_D: printf ("(D)"); break;
1650 /* DWARF 4 values. */
1651 case DW_LANG_Python: printf ("(Python)"); break;
1652 /* DWARF 5 values. */
1653 case DW_LANG_Go: printf ("(Go)"); break;
1654 /* MIPS extension. */
1655 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1656 /* UPC extension. */
1657 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1659 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1660 printf (_("(implementation defined: %s)"),
1661 dwarf_vmatoa ("x", uvalue));
1663 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1668 case DW_AT_encoding:
1671 case DW_ATE_void: printf ("(void)"); break;
1672 case DW_ATE_address: printf ("(machine address)"); break;
1673 case DW_ATE_boolean: printf ("(boolean)"); break;
1674 case DW_ATE_complex_float: printf ("(complex float)"); break;
1675 case DW_ATE_float: printf ("(float)"); break;
1676 case DW_ATE_signed: printf ("(signed)"); break;
1677 case DW_ATE_signed_char: printf ("(signed char)"); break;
1678 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1679 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1680 /* DWARF 2.1 values: */
1681 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1682 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1683 /* DWARF 3 values: */
1684 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1685 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1686 case DW_ATE_edited: printf ("(edited)"); break;
1687 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1688 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1689 /* HP extensions: */
1690 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1691 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1692 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1693 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1694 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1695 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1696 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1699 if (uvalue >= DW_ATE_lo_user
1700 && uvalue <= DW_ATE_hi_user)
1701 printf (_("(user defined type)"));
1703 printf (_("(unknown type)"));
1708 case DW_AT_accessibility:
1711 case DW_ACCESS_public: printf ("(public)"); break;
1712 case DW_ACCESS_protected: printf ("(protected)"); break;
1713 case DW_ACCESS_private: printf ("(private)"); break;
1715 printf (_("(unknown accessibility)"));
1720 case DW_AT_visibility:
1723 case DW_VIS_local: printf ("(local)"); break;
1724 case DW_VIS_exported: printf ("(exported)"); break;
1725 case DW_VIS_qualified: printf ("(qualified)"); break;
1726 default: printf (_("(unknown visibility)")); break;
1730 case DW_AT_virtuality:
1733 case DW_VIRTUALITY_none: printf ("(none)"); break;
1734 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1735 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1736 default: printf (_("(unknown virtuality)")); break;
1740 case DW_AT_identifier_case:
1743 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1744 case DW_ID_up_case: printf ("(up_case)"); break;
1745 case DW_ID_down_case: printf ("(down_case)"); break;
1746 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1747 default: printf (_("(unknown case)")); break;
1751 case DW_AT_calling_convention:
1754 case DW_CC_normal: printf ("(normal)"); break;
1755 case DW_CC_program: printf ("(program)"); break;
1756 case DW_CC_nocall: printf ("(nocall)"); break;
1758 if (uvalue >= DW_CC_lo_user
1759 && uvalue <= DW_CC_hi_user)
1760 printf (_("(user defined)"));
1762 printf (_("(unknown convention)"));
1766 case DW_AT_ordering:
1769 case -1: printf (_("(undefined)")); break;
1770 case 0: printf ("(row major)"); break;
1771 case 1: printf ("(column major)"); break;
1775 case DW_AT_frame_base:
1776 have_frame_base = 1;
1777 case DW_AT_location:
1778 case DW_AT_string_length:
1779 case DW_AT_return_addr:
1780 case DW_AT_data_member_location:
1781 case DW_AT_vtable_elem_location:
1783 case DW_AT_static_link:
1784 case DW_AT_use_location:
1785 case DW_AT_GNU_call_site_value:
1786 case DW_AT_GNU_call_site_data_value:
1787 case DW_AT_GNU_call_site_target:
1788 case DW_AT_GNU_call_site_target_clobbered:
1789 if ((dwarf_version < 4
1790 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1791 || form == DW_FORM_sec_offset)
1792 printf (_("(location list)"));
1794 case DW_AT_allocated:
1795 case DW_AT_associated:
1796 case DW_AT_data_location:
1798 case DW_AT_upper_bound:
1799 case DW_AT_lower_bound:
1802 int need_frame_base;
1805 need_frame_base = decode_location_expression (block_start,
1810 cu_offset, section);
1812 if (need_frame_base && !have_frame_base)
1813 printf (_(" [without DW_AT_frame_base]"));
1819 if (form == DW_FORM_ref_sig8
1820 || form == DW_FORM_GNU_ref_alt)
1823 if (form == DW_FORM_ref1
1824 || form == DW_FORM_ref2
1825 || form == DW_FORM_ref4
1826 || form == DW_FORM_ref_udata)
1827 uvalue += cu_offset;
1829 if (uvalue >= section->size)
1830 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1831 dwarf_vmatoa ("x", uvalue),
1832 (unsigned long) (orig_data - section->start));
1835 unsigned long abbrev_number;
1836 abbrev_entry * entry;
1838 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1840 printf (_("[Abbrev Number: %ld"), abbrev_number);
1841 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
1842 use different abbrev table, and we don't track .debug_info chunks
1844 if (form != DW_FORM_ref_addr)
1846 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1847 if (entry->entry == abbrev_number)
1850 printf (" (%s)", get_TAG_name (entry->tag));
1865 get_AT_name (unsigned long attribute)
1870 return "DW_AT value: 0";
1872 /* One value is shared by the MIPS and HP extensions: */
1873 if (attribute == DW_AT_MIPS_fde)
1874 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1876 name = get_DW_AT_name (attribute);
1880 static char buffer[100];
1882 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1890 static unsigned char *
1891 read_and_display_attr (unsigned long attribute,
1893 unsigned char * data,
1894 dwarf_vma cu_offset,
1895 dwarf_vma pointer_size,
1896 dwarf_vma offset_size,
1898 debug_info * debug_info_p,
1900 struct dwarf_section * section)
1903 printf (" %-18s:", get_AT_name (attribute));
1904 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1905 pointer_size, offset_size,
1906 dwarf_version, debug_info_p,
1914 /* Process the contents of a .debug_info section. If do_loc is non-zero
1915 then we are scanning for location lists and we do not want to display
1916 anything to the user. If do_types is non-zero, we are processing
1917 a .debug_types section instead of a .debug_info section. */
1920 process_debug_info (struct dwarf_section *section,
1922 enum dwarf_section_display_enum abbrev_sec,
1926 unsigned char *start = section->start;
1927 unsigned char *end = start + section->size;
1928 unsigned char *section_begin;
1930 unsigned int num_units = 0;
1932 if ((do_loc || do_debug_loc || do_debug_ranges)
1933 && num_debug_info_entries == 0
1938 /* First scan the section to get the number of comp units. */
1939 for (section_begin = start, num_units = 0; section_begin < end;
1942 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1943 will be the length. For a 64-bit DWARF section, it'll be
1944 the escape code 0xffffffff followed by an 8 byte length. */
1945 length = byte_get (section_begin, 4);
1947 if (length == 0xffffffff)
1949 length = byte_get (section_begin + 4, 8);
1950 section_begin += length + 12;
1952 else if (length >= 0xfffffff0 && length < 0xffffffff)
1954 warn (_("Reserved length value (0x%s) found in section %s\n"),
1955 dwarf_vmatoa ("x", length), section->name);
1959 section_begin += length + 4;
1961 /* Negative values are illegal, they may even cause infinite
1962 looping. This can happen if we can't accurately apply
1963 relocations to an object file. */
1964 if ((signed long) length <= 0)
1966 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
1967 dwarf_vmatoa ("x", length), section->name);
1974 error (_("No comp units in %s section ?"), section->name);
1978 /* Then allocate an array to hold the information. */
1979 debug_information = (debug_info *) cmalloc (num_units,
1980 sizeof (* debug_information));
1981 if (debug_information == NULL)
1983 error (_("Not enough memory for a debug info array of %u entries"),
1991 if (dwarf_start_die == 0)
1992 printf (_("Contents of the %s section:\n\n"), section->name);
1994 load_debug_section (str, file);
1995 load_debug_section (str_dwo, file);
1996 load_debug_section (str_index, file);
1997 load_debug_section (str_index_dwo, file);
1998 load_debug_section (debug_addr, file);
2001 load_debug_section (abbrev_sec, file);
2002 if (debug_displays [abbrev_sec].section.start == NULL)
2004 warn (_("Unable to locate %s section!\n"),
2005 debug_displays [abbrev_sec].section.name);
2009 for (section_begin = start, unit = 0; start < end; unit++)
2011 DWARF2_Internal_CompUnit compunit;
2012 unsigned char *hdrptr;
2013 unsigned char *tags;
2014 int level, last_level, saved_level;
2015 dwarf_vma cu_offset;
2017 int initial_length_size;
2018 dwarf_vma signature_high = 0;
2019 dwarf_vma signature_low = 0;
2020 dwarf_vma type_offset = 0;
2024 compunit.cu_length = byte_get (hdrptr, 4);
2027 if (compunit.cu_length == 0xffffffff)
2029 compunit.cu_length = byte_get (hdrptr, 8);
2032 initial_length_size = 12;
2037 initial_length_size = 4;
2040 compunit.cu_version = byte_get (hdrptr, 2);
2043 cu_offset = start - section_begin;
2045 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2046 hdrptr += offset_size;
2048 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2053 byte_get_64 (hdrptr, &signature_high, &signature_low);
2055 type_offset = byte_get (hdrptr, offset_size);
2056 hdrptr += offset_size;
2059 if ((do_loc || do_debug_loc || do_debug_ranges)
2060 && num_debug_info_entries == 0
2063 debug_information [unit].cu_offset = cu_offset;
2064 debug_information [unit].pointer_size
2065 = compunit.cu_pointer_size;
2066 debug_information [unit].offset_size = offset_size;
2067 debug_information [unit].dwarf_version = compunit.cu_version;
2068 debug_information [unit].base_address = 0;
2069 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2070 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2071 debug_information [unit].loc_offsets = NULL;
2072 debug_information [unit].have_frame_base = NULL;
2073 debug_information [unit].max_loc_offsets = 0;
2074 debug_information [unit].num_loc_offsets = 0;
2075 debug_information [unit].range_lists = NULL;
2076 debug_information [unit].max_range_lists= 0;
2077 debug_information [unit].num_range_lists = 0;
2080 if (!do_loc && dwarf_start_die == 0)
2082 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2083 dwarf_vmatoa ("x", cu_offset));
2084 printf (_(" Length: 0x%s (%s)\n"),
2085 dwarf_vmatoa ("x", compunit.cu_length),
2086 offset_size == 8 ? "64-bit" : "32-bit");
2087 printf (_(" Version: %d\n"), compunit.cu_version);
2088 printf (_(" Abbrev Offset: 0x%s\n"),
2089 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2090 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2095 printf (_(" Signature: 0x%s\n"),
2096 dwarf_vmatoa64 (signature_high, signature_low,
2097 buf, sizeof (buf)));
2098 printf (_(" Type Offset: 0x%s\n"),
2099 dwarf_vmatoa ("x", type_offset));
2103 if (cu_offset + compunit.cu_length + initial_length_size
2106 warn (_("Debug info is corrupted, length of CU at %s"
2107 " extends beyond end of section (length = %s)\n"),
2108 dwarf_vmatoa ("x", cu_offset),
2109 dwarf_vmatoa ("x", compunit.cu_length));
2113 start += compunit.cu_length + initial_length_size;
2115 if (compunit.cu_version != 2
2116 && compunit.cu_version != 3
2117 && compunit.cu_version != 4)
2119 warn (_("CU at offset %s contains corrupt or "
2120 "unsupported version number: %d.\n"),
2121 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2127 /* Process the abbrevs used by this compilation unit. DWARF
2128 sections under Mach-O have non-zero addresses. */
2129 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2130 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2131 (unsigned long) compunit.cu_abbrev_offset,
2132 (unsigned long) debug_displays [abbrev_sec].section.size);
2134 process_abbrev_section
2135 ((unsigned char *) debug_displays [abbrev_sec].section.start
2136 + compunit.cu_abbrev_offset,
2137 (unsigned char *) debug_displays [abbrev_sec].section.start
2138 + debug_displays [abbrev_sec].section.size);
2143 while (tags < start)
2145 unsigned int bytes_read;
2146 unsigned long abbrev_number;
2147 unsigned long die_offset;
2148 abbrev_entry *entry;
2150 int do_printing = 1;
2152 die_offset = tags - section_begin;
2154 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2157 /* A null DIE marks the end of a list of siblings or it may also be
2158 a section padding. */
2159 if (abbrev_number == 0)
2161 /* Check if it can be a section padding for the last CU. */
2162 if (level == 0 && start == end)
2166 for (chk = tags; chk < start; chk++)
2173 if (!do_loc && die_offset >= dwarf_start_die)
2174 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2180 static unsigned num_bogus_warns = 0;
2182 if (num_bogus_warns < 3)
2184 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2185 die_offset, section->name);
2187 if (num_bogus_warns == 3)
2188 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2191 if (dwarf_start_die != 0 && level < saved_level)
2198 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2202 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2203 saved_level = level;
2204 do_printing = (dwarf_cutoff_level == -1
2205 || level < dwarf_cutoff_level);
2207 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2208 level, die_offset, abbrev_number);
2209 else if (dwarf_cutoff_level == -1
2210 || last_level < dwarf_cutoff_level)
2211 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2216 /* Scan through the abbreviation list until we reach the
2218 for (entry = first_abbrev;
2219 entry && entry->entry != abbrev_number;
2220 entry = entry->next)
2225 if (!do_loc && do_printing)
2230 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2231 die_offset, abbrev_number);
2235 if (!do_loc && do_printing)
2236 printf (" (%s)\n", get_TAG_name (entry->tag));
2241 need_base_address = 0;
2243 case DW_TAG_compile_unit:
2244 need_base_address = 1;
2246 case DW_TAG_entry_point:
2247 case DW_TAG_subprogram:
2248 need_base_address = 0;
2249 /* Assuming that there is no DW_AT_frame_base. */
2250 have_frame_base = 0;
2254 for (attr = entry->first_attr;
2255 attr && attr->attribute;
2260 if (! do_loc && do_printing)
2261 /* Show the offset from where the tag was extracted. */
2262 printf (" <%lx>", (unsigned long)(tags - section_begin));
2264 arg = debug_information;
2265 if (debug_information)
2268 tags = read_and_display_attr (attr->attribute,
2271 compunit.cu_pointer_size,
2273 compunit.cu_version,
2275 do_loc || ! do_printing, section);
2278 if (entry->children)
2283 /* Set num_debug_info_entries here so that it can be used to check if
2284 we need to process .debug_loc and .debug_ranges sections. */
2285 if ((do_loc || do_debug_loc || do_debug_ranges)
2286 && num_debug_info_entries == 0
2288 num_debug_info_entries = num_units;
2296 /* Locate and scan the .debug_info section in the file and record the pointer
2297 sizes and offsets for the compilation units in it. Usually an executable
2298 will have just one pointer size, but this is not guaranteed, and so we try
2299 not to make any assumptions. Returns zero upon failure, or the number of
2300 compilation units upon success. */
2303 load_debug_info (void * file)
2305 /* Reset the last pointer size so that we can issue correct error
2306 messages if we are displaying the contents of more than one section. */
2307 last_pointer_size = 0;
2308 warned_about_missing_comp_units = FALSE;
2310 /* If we have already tried and failed to load the .debug_info
2311 section then do not bother to repear the task. */
2312 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2315 /* If we already have the information there is nothing else to do. */
2316 if (num_debug_info_entries > 0)
2317 return num_debug_info_entries;
2319 if (load_debug_section (info, file)
2320 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2321 return num_debug_info_entries;
2322 else if (load_debug_section (info_dwo, file)
2323 && process_debug_info (&debug_displays [info_dwo].section, file,
2325 return num_debug_info_entries;
2327 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2332 display_debug_lines_raw (struct dwarf_section *section,
2333 unsigned char *data,
2336 unsigned char *start = section->start;
2338 printf (_("Raw dump of debug contents of section %s:\n\n"),
2343 DWARF2_Internal_LineInfo linfo;
2344 unsigned char *standard_opcodes;
2345 unsigned char *end_of_sequence;
2346 unsigned char *hdrptr;
2347 unsigned long hdroff;
2348 int initial_length_size;
2353 hdroff = hdrptr - start;
2355 /* Check the length of the block. */
2356 linfo.li_length = byte_get (hdrptr, 4);
2359 if (linfo.li_length == 0xffffffff)
2361 /* This section is 64-bit DWARF 3. */
2362 linfo.li_length = byte_get (hdrptr, 8);
2365 initial_length_size = 12;
2370 initial_length_size = 4;
2373 if (linfo.li_length + initial_length_size > section->size)
2376 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2381 /* Check its version number. */
2382 linfo.li_version = byte_get (hdrptr, 2);
2384 if (linfo.li_version != 2
2385 && linfo.li_version != 3
2386 && linfo.li_version != 4)
2388 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2392 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2393 hdrptr += offset_size;
2394 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2396 if (linfo.li_version >= 4)
2398 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2400 if (linfo.li_max_ops_per_insn == 0)
2402 warn (_("Invalid maximum operations per insn.\n"));
2407 linfo.li_max_ops_per_insn = 1;
2408 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2410 linfo.li_line_base = byte_get (hdrptr, 1);
2412 linfo.li_line_range = byte_get (hdrptr, 1);
2414 linfo.li_opcode_base = byte_get (hdrptr, 1);
2417 /* Sign extend the line base field. */
2418 linfo.li_line_base <<= 24;
2419 linfo.li_line_base >>= 24;
2421 printf (_(" Offset: 0x%lx\n"), hdroff);
2422 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2423 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2424 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2425 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2426 if (linfo.li_version >= 4)
2427 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2428 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2429 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2430 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2431 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2433 end_of_sequence = data + linfo.li_length + initial_length_size;
2435 reset_state_machine (linfo.li_default_is_stmt);
2437 /* Display the contents of the Opcodes table. */
2438 standard_opcodes = hdrptr;
2440 printf (_("\n Opcodes:\n"));
2442 for (i = 1; i < linfo.li_opcode_base; i++)
2443 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2445 /* Display the contents of the Directory table. */
2446 data = standard_opcodes + linfo.li_opcode_base - 1;
2449 printf (_("\n The Directory Table is empty.\n"));
2452 printf (_("\n The Directory Table:\n"));
2456 printf (" %s\n", data);
2458 data += strlen ((char *) data) + 1;
2462 /* Skip the NUL at the end of the table. */
2465 /* Display the contents of the File Name table. */
2467 printf (_("\n The File Name Table is empty.\n"));
2470 printf (_("\n The File Name Table:\n"));
2471 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2475 unsigned char *name;
2476 unsigned int bytes_read;
2478 printf (" %d\t", ++state_machine_regs.last_file_entry);
2481 data += strlen ((char *) data) + 1;
2484 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2487 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2490 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2492 printf ("%s\n", name);
2496 /* Skip the NUL at the end of the table. */
2499 /* Now display the statements. */
2500 printf (_("\n Line Number Statements:\n"));
2502 while (data < end_of_sequence)
2504 unsigned char op_code;
2505 dwarf_signed_vma adv;
2507 unsigned int bytes_read;
2511 if (op_code >= linfo.li_opcode_base)
2513 op_code -= linfo.li_opcode_base;
2514 uladv = (op_code / linfo.li_line_range);
2515 if (linfo.li_max_ops_per_insn == 1)
2517 uladv *= linfo.li_min_insn_length;
2518 state_machine_regs.address += uladv;
2519 printf (_(" Special opcode %d: "
2520 "advance Address by %s to 0x%s"),
2521 op_code, dwarf_vmatoa ("u", uladv),
2522 dwarf_vmatoa ("x", state_machine_regs.address));
2526 state_machine_regs.address
2527 += ((state_machine_regs.op_index + uladv)
2528 / linfo.li_max_ops_per_insn)
2529 * linfo.li_min_insn_length;
2530 state_machine_regs.op_index
2531 = (state_machine_regs.op_index + uladv)
2532 % linfo.li_max_ops_per_insn;
2533 printf (_(" Special opcode %d: "
2534 "advance Address by %s to 0x%s[%d]"),
2535 op_code, dwarf_vmatoa ("u", uladv),
2536 dwarf_vmatoa ("x", state_machine_regs.address),
2537 state_machine_regs.op_index);
2539 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2540 state_machine_regs.line += adv;
2541 printf (_(" and Line by %s to %d\n"),
2542 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2544 else switch (op_code)
2546 case DW_LNS_extended_op:
2547 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2551 printf (_(" Copy\n"));
2554 case DW_LNS_advance_pc:
2555 uladv = read_leb128 (data, & bytes_read, 0);
2557 if (linfo.li_max_ops_per_insn == 1)
2559 uladv *= linfo.li_min_insn_length;
2560 state_machine_regs.address += uladv;
2561 printf (_(" Advance PC by %s to 0x%s\n"),
2562 dwarf_vmatoa ("u", uladv),
2563 dwarf_vmatoa ("x", state_machine_regs.address));
2567 state_machine_regs.address
2568 += ((state_machine_regs.op_index + uladv)
2569 / linfo.li_max_ops_per_insn)
2570 * linfo.li_min_insn_length;
2571 state_machine_regs.op_index
2572 = (state_machine_regs.op_index + uladv)
2573 % linfo.li_max_ops_per_insn;
2574 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2575 dwarf_vmatoa ("u", uladv),
2576 dwarf_vmatoa ("x", state_machine_regs.address),
2577 state_machine_regs.op_index);
2581 case DW_LNS_advance_line:
2582 adv = read_sleb128 (data, & bytes_read);
2584 state_machine_regs.line += adv;
2585 printf (_(" Advance Line by %s to %d\n"),
2586 dwarf_vmatoa ("d", adv),
2587 state_machine_regs.line);
2590 case DW_LNS_set_file:
2591 adv = read_leb128 (data, & bytes_read, 0);
2593 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2594 dwarf_vmatoa ("d", adv));
2595 state_machine_regs.file = adv;
2598 case DW_LNS_set_column:
2599 uladv = read_leb128 (data, & bytes_read, 0);
2601 printf (_(" Set column to %s\n"),
2602 dwarf_vmatoa ("u", uladv));
2603 state_machine_regs.column = uladv;
2606 case DW_LNS_negate_stmt:
2607 adv = state_machine_regs.is_stmt;
2609 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2610 state_machine_regs.is_stmt = adv;
2613 case DW_LNS_set_basic_block:
2614 printf (_(" Set basic block\n"));
2615 state_machine_regs.basic_block = 1;
2618 case DW_LNS_const_add_pc:
2619 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2620 if (linfo.li_max_ops_per_insn)
2622 uladv *= linfo.li_min_insn_length;
2623 state_machine_regs.address += uladv;
2624 printf (_(" Advance PC by constant %s to 0x%s\n"),
2625 dwarf_vmatoa ("u", uladv),
2626 dwarf_vmatoa ("x", state_machine_regs.address));
2630 state_machine_regs.address
2631 += ((state_machine_regs.op_index + uladv)
2632 / linfo.li_max_ops_per_insn)
2633 * linfo.li_min_insn_length;
2634 state_machine_regs.op_index
2635 = (state_machine_regs.op_index + uladv)
2636 % linfo.li_max_ops_per_insn;
2637 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2638 dwarf_vmatoa ("u", uladv),
2639 dwarf_vmatoa ("x", state_machine_regs.address),
2640 state_machine_regs.op_index);
2644 case DW_LNS_fixed_advance_pc:
2645 uladv = byte_get (data, 2);
2647 state_machine_regs.address += uladv;
2648 state_machine_regs.op_index = 0;
2649 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2650 dwarf_vmatoa ("u", uladv),
2651 dwarf_vmatoa ("x", state_machine_regs.address));
2654 case DW_LNS_set_prologue_end:
2655 printf (_(" Set prologue_end to true\n"));
2658 case DW_LNS_set_epilogue_begin:
2659 printf (_(" Set epilogue_begin to true\n"));
2662 case DW_LNS_set_isa:
2663 uladv = read_leb128 (data, & bytes_read, 0);
2665 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2669 printf (_(" Unknown opcode %d with operands: "), op_code);
2671 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2673 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2675 i == 1 ? "" : ", ");
2690 unsigned char *name;
2691 unsigned int directory_index;
2692 unsigned int modification_date;
2693 unsigned int length;
2696 /* Output a decoded representation of the .debug_line section. */
2699 display_debug_lines_decoded (struct dwarf_section *section,
2700 unsigned char *data,
2703 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2708 /* This loop amounts to one iteration per compilation unit. */
2709 DWARF2_Internal_LineInfo linfo;
2710 unsigned char *standard_opcodes;
2711 unsigned char *end_of_sequence;
2712 unsigned char *hdrptr;
2713 int initial_length_size;
2716 File_Entry *file_table = NULL;
2717 unsigned int n_files = 0;
2718 unsigned char **directory_table = NULL;
2719 unsigned int n_directories = 0;
2723 /* Extract information from the Line Number Program Header.
2724 (section 6.2.4 in the Dwarf3 doc). */
2726 /* Get the length of this CU's line number information block. */
2727 linfo.li_length = byte_get (hdrptr, 4);
2730 if (linfo.li_length == 0xffffffff)
2732 /* This section is 64-bit DWARF 3. */
2733 linfo.li_length = byte_get (hdrptr, 8);
2736 initial_length_size = 12;
2741 initial_length_size = 4;
2744 if (linfo.li_length + initial_length_size > section->size)
2746 warn (_("The line info appears to be corrupt - "
2747 "the section is too small\n"));
2751 /* Get this CU's Line Number Block version number. */
2752 linfo.li_version = byte_get (hdrptr, 2);
2754 if (linfo.li_version != 2
2755 && linfo.li_version != 3
2756 && linfo.li_version != 4)
2758 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2763 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2764 hdrptr += offset_size;
2765 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2767 if (linfo.li_version >= 4)
2769 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2771 if (linfo.li_max_ops_per_insn == 0)
2773 warn (_("Invalid maximum operations per insn.\n"));
2778 linfo.li_max_ops_per_insn = 1;
2779 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2781 linfo.li_line_base = byte_get (hdrptr, 1);
2783 linfo.li_line_range = byte_get (hdrptr, 1);
2785 linfo.li_opcode_base = byte_get (hdrptr, 1);
2788 /* Sign extend the line base field. */
2789 linfo.li_line_base <<= 24;
2790 linfo.li_line_base >>= 24;
2792 /* Find the end of this CU's Line Number Information Block. */
2793 end_of_sequence = data + linfo.li_length + initial_length_size;
2795 reset_state_machine (linfo.li_default_is_stmt);
2797 /* Save a pointer to the contents of the Opcodes table. */
2798 standard_opcodes = hdrptr;
2800 /* Traverse the Directory table just to count entries. */
2801 data = standard_opcodes + linfo.li_opcode_base - 1;
2804 unsigned char *ptr_directory_table = data;
2808 data += strlen ((char *) data) + 1;
2812 /* Go through the directory table again to save the directories. */
2813 directory_table = (unsigned char **)
2814 xmalloc (n_directories * sizeof (unsigned char *));
2817 while (*ptr_directory_table != 0)
2819 directory_table[i] = ptr_directory_table;
2820 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2824 /* Skip the NUL at the end of the table. */
2827 /* Traverse the File Name table just to count the entries. */
2830 unsigned char *ptr_file_name_table = data;
2834 unsigned int bytes_read;
2836 /* Skip Name, directory index, last modification time and length
2838 data += strlen ((char *) data) + 1;
2839 read_leb128 (data, & bytes_read, 0);
2841 read_leb128 (data, & bytes_read, 0);
2843 read_leb128 (data, & bytes_read, 0);
2849 /* Go through the file table again to save the strings. */
2850 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2853 while (*ptr_file_name_table != 0)
2855 unsigned int bytes_read;
2857 file_table[i].name = ptr_file_name_table;
2858 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2860 /* We are not interested in directory, time or size. */
2861 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2863 ptr_file_name_table += bytes_read;
2864 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2866 ptr_file_name_table += bytes_read;
2867 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2868 ptr_file_name_table += bytes_read;
2873 /* Print the Compilation Unit's name and a header. */
2874 if (directory_table == NULL)
2876 printf (_("CU: %s:\n"), file_table[0].name);
2877 printf (_("File name Line number Starting address\n"));
2881 unsigned int ix = file_table[0].directory_index;
2882 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
2883 if (do_wide || strlen (directory) < 76)
2884 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
2886 printf ("%s:\n", file_table[0].name);
2888 printf (_("File name Line number Starting address\n"));
2892 /* Skip the NUL at the end of the table. */
2895 /* This loop iterates through the Dwarf Line Number Program. */
2896 while (data < end_of_sequence)
2898 unsigned char op_code;
2900 unsigned long int uladv;
2901 unsigned int bytes_read;
2902 int is_special_opcode = 0;
2906 if (op_code >= linfo.li_opcode_base)
2908 op_code -= linfo.li_opcode_base;
2909 uladv = (op_code / linfo.li_line_range);
2910 if (linfo.li_max_ops_per_insn == 1)
2912 uladv *= linfo.li_min_insn_length;
2913 state_machine_regs.address += uladv;
2917 state_machine_regs.address
2918 += ((state_machine_regs.op_index + uladv)
2919 / linfo.li_max_ops_per_insn)
2920 * linfo.li_min_insn_length;
2921 state_machine_regs.op_index
2922 = (state_machine_regs.op_index + uladv)
2923 % linfo.li_max_ops_per_insn;
2926 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2927 state_machine_regs.line += adv;
2928 is_special_opcode = 1;
2930 else switch (op_code)
2932 case DW_LNS_extended_op:
2934 unsigned int ext_op_code_len;
2935 unsigned char ext_op_code;
2936 unsigned char *op_code_data = data;
2938 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
2939 op_code_data += bytes_read;
2941 if (ext_op_code_len == 0)
2943 warn (_("badly formed extended line op encountered!\n"));
2946 ext_op_code_len += bytes_read;
2947 ext_op_code = *op_code_data++;
2949 switch (ext_op_code)
2951 case DW_LNE_end_sequence:
2952 reset_state_machine (linfo.li_default_is_stmt);
2954 case DW_LNE_set_address:
2955 state_machine_regs.address =
2956 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
2957 state_machine_regs.op_index = 0;
2959 case DW_LNE_define_file:
2961 file_table = (File_Entry *) xrealloc
2962 (file_table, (n_files + 1) * sizeof (File_Entry));
2964 ++state_machine_regs.last_file_entry;
2965 /* Source file name. */
2966 file_table[n_files].name = op_code_data;
2967 op_code_data += strlen ((char *) op_code_data) + 1;
2968 /* Directory index. */
2969 file_table[n_files].directory_index =
2970 read_leb128 (op_code_data, & bytes_read, 0);
2971 op_code_data += bytes_read;
2972 /* Last modification time. */
2973 file_table[n_files].modification_date =
2974 read_leb128 (op_code_data, & bytes_read, 0);
2975 op_code_data += bytes_read;
2977 file_table[n_files].length =
2978 read_leb128 (op_code_data, & bytes_read, 0);
2983 case DW_LNE_set_discriminator:
2984 case DW_LNE_HP_set_sequence:
2985 /* Simply ignored. */
2989 printf (_("UNKNOWN (%u): length %d\n"),
2990 ext_op_code, ext_op_code_len - bytes_read);
2993 data += ext_op_code_len;
2999 case DW_LNS_advance_pc:
3000 uladv = read_leb128 (data, & bytes_read, 0);
3002 if (linfo.li_max_ops_per_insn == 1)
3004 uladv *= linfo.li_min_insn_length;
3005 state_machine_regs.address += uladv;
3009 state_machine_regs.address
3010 += ((state_machine_regs.op_index + uladv)
3011 / linfo.li_max_ops_per_insn)
3012 * linfo.li_min_insn_length;
3013 state_machine_regs.op_index
3014 = (state_machine_regs.op_index + uladv)
3015 % linfo.li_max_ops_per_insn;
3019 case DW_LNS_advance_line:
3020 adv = read_sleb128 (data, & bytes_read);
3022 state_machine_regs.line += adv;
3025 case DW_LNS_set_file:
3026 adv = read_leb128 (data, & bytes_read, 0);
3028 state_machine_regs.file = adv;
3029 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3031 /* If directory index is 0, that means current directory. */
3032 printf ("\n./%s:[++]\n",
3033 file_table[state_machine_regs.file - 1].name);
3037 /* The directory index starts counting at 1. */
3038 printf ("\n%s/%s:\n",
3039 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3040 file_table[state_machine_regs.file - 1].name);
3044 case DW_LNS_set_column:
3045 uladv = read_leb128 (data, & bytes_read, 0);
3047 state_machine_regs.column = uladv;
3050 case DW_LNS_negate_stmt:
3051 adv = state_machine_regs.is_stmt;
3053 state_machine_regs.is_stmt = adv;
3056 case DW_LNS_set_basic_block:
3057 state_machine_regs.basic_block = 1;
3060 case DW_LNS_const_add_pc:
3061 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3062 if (linfo.li_max_ops_per_insn == 1)
3064 uladv *= linfo.li_min_insn_length;
3065 state_machine_regs.address += uladv;
3069 state_machine_regs.address
3070 += ((state_machine_regs.op_index + uladv)
3071 / linfo.li_max_ops_per_insn)
3072 * linfo.li_min_insn_length;
3073 state_machine_regs.op_index
3074 = (state_machine_regs.op_index + uladv)
3075 % linfo.li_max_ops_per_insn;
3079 case DW_LNS_fixed_advance_pc:
3080 uladv = byte_get (data, 2);
3082 state_machine_regs.address += uladv;
3083 state_machine_regs.op_index = 0;
3086 case DW_LNS_set_prologue_end:
3089 case DW_LNS_set_epilogue_begin:
3092 case DW_LNS_set_isa:
3093 uladv = read_leb128 (data, & bytes_read, 0);
3095 printf (_(" Set ISA to %lu\n"), uladv);
3099 printf (_(" Unknown opcode %d with operands: "), op_code);
3101 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3103 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3105 i == 1 ? "" : ", ");
3112 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3113 to the DWARF address/line matrix. */
3114 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3115 || (op_code == DW_LNS_copy))
3117 const unsigned int MAX_FILENAME_LENGTH = 35;
3118 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3119 char *newFileName = NULL;
3120 size_t fileNameLength = strlen (fileName);
3122 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3124 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3125 /* Truncate file name */
3126 strncpy (newFileName,
3127 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3128 MAX_FILENAME_LENGTH + 1);
3132 newFileName = (char *) xmalloc (fileNameLength + 1);
3133 strncpy (newFileName, fileName, fileNameLength + 1);
3136 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3138 if (linfo.li_max_ops_per_insn == 1)
3139 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3140 newFileName, state_machine_regs.line,
3141 state_machine_regs.address);
3143 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3144 newFileName, state_machine_regs.line,
3145 state_machine_regs.address,
3146 state_machine_regs.op_index);
3150 if (linfo.li_max_ops_per_insn == 1)
3151 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3152 newFileName, state_machine_regs.line,
3153 state_machine_regs.address);
3155 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3156 newFileName, state_machine_regs.line,
3157 state_machine_regs.address,
3158 state_machine_regs.op_index);
3161 if (op_code == DW_LNE_end_sequence)
3169 free (directory_table);
3170 directory_table = NULL;
3178 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3180 unsigned char *data = section->start;
3181 unsigned char *end = data + section->size;
3183 int retValDecoded = 1;
3185 if (do_debug_lines == 0)
3186 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3188 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3189 retValRaw = display_debug_lines_raw (section, data, end);
3191 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3192 retValDecoded = display_debug_lines_decoded (section, data, end);
3194 if (!retValRaw || !retValDecoded)
3201 find_debug_info_for_offset (unsigned long offset)
3205 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3208 for (i = 0; i < num_debug_info_entries; i++)
3209 if (debug_information[i].cu_offset == offset)
3210 return debug_information + i;
3216 display_debug_pubnames (struct dwarf_section *section,
3217 void *file ATTRIBUTE_UNUSED)
3219 DWARF2_Internal_PubNames names;
3220 unsigned char *start = section->start;
3221 unsigned char *end = start + section->size;
3223 /* It does not matter if this load fails,
3224 we test for that later on. */
3225 load_debug_info (file);
3227 printf (_("Contents of the %s section:\n\n"), section->name);
3231 unsigned char *data;
3232 unsigned long offset;
3233 int offset_size, initial_length_size;
3237 names.pn_length = byte_get (data, 4);
3239 if (names.pn_length == 0xffffffff)
3241 names.pn_length = byte_get (data, 8);
3244 initial_length_size = 12;
3249 initial_length_size = 4;
3252 names.pn_version = byte_get (data, 2);
3255 names.pn_offset = byte_get (data, offset_size);
3256 data += offset_size;
3258 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3259 && num_debug_info_entries > 0
3260 && find_debug_info_for_offset (names.pn_offset) == NULL)
3261 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3262 (unsigned long) names.pn_offset, section->name);
3264 names.pn_size = byte_get (data, offset_size);
3265 data += offset_size;
3267 start += names.pn_length + initial_length_size;
3269 if (names.pn_version != 2 && names.pn_version != 3)
3271 static int warned = 0;
3275 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3282 printf (_(" Length: %ld\n"),
3283 (long) names.pn_length);
3284 printf (_(" Version: %d\n"),
3286 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3287 (unsigned long) names.pn_offset);
3288 printf (_(" Size of area in .debug_info section: %ld\n"),
3289 (long) names.pn_size);
3291 printf (_("\n Offset\tName\n"));
3295 offset = byte_get (data, offset_size);
3299 data += offset_size;
3300 printf (" %-6lx\t%s\n", offset, data);
3301 data += strlen ((char *) data) + 1;
3304 while (offset != 0);
3312 display_debug_macinfo (struct dwarf_section *section,
3313 void *file ATTRIBUTE_UNUSED)
3315 unsigned char *start = section->start;
3316 unsigned char *end = start + section->size;
3317 unsigned char *curr = start;
3318 unsigned int bytes_read;
3319 enum dwarf_macinfo_record_type op;
3321 printf (_("Contents of the %s section:\n\n"), section->name);
3325 unsigned int lineno;
3328 op = (enum dwarf_macinfo_record_type) *curr;
3333 case DW_MACINFO_start_file:
3335 unsigned int filenum;
3337 lineno = read_leb128 (curr, & bytes_read, 0);
3339 filenum = read_leb128 (curr, & bytes_read, 0);
3342 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3347 case DW_MACINFO_end_file:
3348 printf (_(" DW_MACINFO_end_file\n"));
3351 case DW_MACINFO_define:
3352 lineno = read_leb128 (curr, & bytes_read, 0);
3354 string = (char *) curr;
3355 curr += strlen (string) + 1;
3356 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3360 case DW_MACINFO_undef:
3361 lineno = read_leb128 (curr, & bytes_read, 0);
3363 string = (char *) curr;
3364 curr += strlen (string) + 1;
3365 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3369 case DW_MACINFO_vendor_ext:
3371 unsigned int constant;
3373 constant = read_leb128 (curr, & bytes_read, 0);
3375 string = (char *) curr;
3376 curr += strlen (string) + 1;
3377 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3387 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3388 filename and dirname corresponding to file name table entry with index
3389 FILEIDX. Return NULL on failure. */
3391 static unsigned char *
3392 get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
3393 unsigned char **dir_name)
3395 struct dwarf_section *section = &debug_displays [line].section;
3396 unsigned char *hdrptr, *dirtable, *file_name;
3397 unsigned int offset_size, initial_length_size;
3398 unsigned int version, opcode_base, bytes_read;
3399 dwarf_vma length, diridx;
3402 if (section->start == NULL
3403 || line_offset >= section->size
3407 hdrptr = section->start + line_offset;
3408 length = byte_get (hdrptr, 4);
3410 if (length == 0xffffffff)
3412 /* This section is 64-bit DWARF 3. */
3413 length = byte_get (hdrptr, 8);
3416 initial_length_size = 12;
3421 initial_length_size = 4;
3423 if (length + initial_length_size > section->size)
3425 version = byte_get (hdrptr, 2);
3427 if (version != 2 && version != 3 && version != 4)
3429 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3431 hdrptr++; /* Skip max_ops_per_insn. */
3432 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3433 opcode_base = byte_get (hdrptr, 1);
3434 if (opcode_base == 0)
3437 hdrptr += opcode_base - 1;
3439 /* Skip over dirname table. */
3440 while (*hdrptr != '\0')
3441 hdrptr += strlen ((char *) hdrptr) + 1;
3442 hdrptr++; /* Skip the NUL at the end of the table. */
3443 /* Now skip over preceding filename table entries. */
3444 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3446 hdrptr += strlen ((char *) hdrptr) + 1;
3447 read_leb128 (hdrptr, &bytes_read, 0);
3448 hdrptr += bytes_read;
3449 read_leb128 (hdrptr, &bytes_read, 0);
3450 hdrptr += bytes_read;
3451 read_leb128 (hdrptr, &bytes_read, 0);
3452 hdrptr += bytes_read;
3454 if (*hdrptr == '\0')
3457 hdrptr += strlen ((char *) hdrptr) + 1;
3458 diridx = read_leb128 (hdrptr, &bytes_read, 0);
3461 for (; *dirtable != '\0' && diridx > 1; diridx--)
3462 dirtable += strlen ((char *) dirtable) + 1;
3463 if (*dirtable == '\0')
3465 *dir_name = dirtable;
3470 display_debug_macro (struct dwarf_section *section,
3473 unsigned char *start = section->start;
3474 unsigned char *end = start + section->size;
3475 unsigned char *curr = start;
3476 unsigned char *extended_op_buf[256];
3477 unsigned int bytes_read;
3479 load_debug_section (str, file);
3480 load_debug_section (line, file);
3482 printf (_("Contents of the %s section:\n\n"), section->name);
3486 unsigned int lineno, version, flags;
3487 unsigned int offset_size = 4;
3489 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3490 unsigned char **extended_ops = NULL;
3492 version = byte_get (curr, 2);
3497 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3502 flags = byte_get (curr++, 1);
3505 printf (_(" Offset: 0x%lx\n"),
3506 (unsigned long) sec_offset);
3507 printf (_(" Version: %d\n"), version);
3508 printf (_(" Offset size: %d\n"), offset_size);
3511 line_offset = byte_get (curr, offset_size);
3512 curr += offset_size;
3513 printf (_(" Offset into .debug_line: 0x%lx\n"),
3514 (unsigned long) line_offset);
3518 unsigned int i, count = byte_get (curr++, 1), op;
3520 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3521 extended_ops = extended_op_buf;
3524 printf (_(" Extension opcode arguments:\n"));
3525 for (i = 0; i < count; i++)
3527 op = byte_get (curr++, 1);
3528 extended_ops[op] = curr;
3529 nargs = read_leb128 (curr, &bytes_read, 0);
3532 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3535 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3536 for (n = 0; n < nargs; n++)
3538 unsigned int form = byte_get (curr++, 1);
3539 printf ("%s%s", get_FORM_name (form),
3540 n == nargs - 1 ? "\n" : ", ");
3550 case DW_FORM_block1:
3551 case DW_FORM_block2:
3552 case DW_FORM_block4:
3554 case DW_FORM_string:
3556 case DW_FORM_sec_offset:
3559 error (_("Invalid extension opcode form %s\n"),
3560 get_FORM_name (form));
3576 error (_(".debug_macro section not zero terminated\n"));
3580 op = byte_get (curr++, 1);
3586 case DW_MACRO_GNU_start_file:
3588 unsigned int filenum;
3589 unsigned char *file_name = NULL, *dir_name = NULL;
3591 lineno = read_leb128 (curr, &bytes_read, 0);
3593 filenum = read_leb128 (curr, &bytes_read, 0);
3596 if ((flags & 2) == 0)
3597 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3600 = get_line_filename_and_dirname (line_offset, filenum,
3602 if (file_name == NULL)
3603 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3606 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3608 dir_name != NULL ? (const char *) dir_name : "",
3609 dir_name != NULL ? "/" : "", file_name);
3613 case DW_MACRO_GNU_end_file:
3614 printf (_(" DW_MACRO_GNU_end_file\n"));
3617 case DW_MACRO_GNU_define:
3618 lineno = read_leb128 (curr, &bytes_read, 0);
3620 string = (char *) curr;
3621 curr += strlen (string) + 1;
3622 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3626 case DW_MACRO_GNU_undef:
3627 lineno = read_leb128 (curr, &bytes_read, 0);
3629 string = (char *) curr;
3630 curr += strlen (string) + 1;
3631 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3635 case DW_MACRO_GNU_define_indirect:
3636 lineno = read_leb128 (curr, &bytes_read, 0);
3638 offset = byte_get (curr, offset_size);
3639 curr += offset_size;
3640 string = fetch_indirect_string (offset);
3641 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3645 case DW_MACRO_GNU_undef_indirect:
3646 lineno = read_leb128 (curr, &bytes_read, 0);
3648 offset = byte_get (curr, offset_size);
3649 curr += offset_size;
3650 string = fetch_indirect_string (offset);
3651 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3655 case DW_MACRO_GNU_transparent_include:
3656 offset = byte_get (curr, offset_size);
3657 curr += offset_size;
3658 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3659 (unsigned long) offset);
3662 case DW_MACRO_GNU_define_indirect_alt:
3663 lineno = read_leb128 (curr, &bytes_read, 0);
3665 offset = byte_get (curr, offset_size);
3666 curr += offset_size;
3667 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3668 lineno, (unsigned long) offset);
3671 case DW_MACRO_GNU_undef_indirect_alt:
3672 lineno = read_leb128 (curr, &bytes_read, 0);
3674 offset = byte_get (curr, offset_size);
3675 curr += offset_size;
3676 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3677 lineno, (unsigned long) offset);
3680 case DW_MACRO_GNU_transparent_include_alt:
3681 offset = byte_get (curr, offset_size);
3682 curr += offset_size;
3683 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
3684 (unsigned long) offset);
3688 if (extended_ops == NULL || extended_ops[op] == NULL)
3690 error (_(" Unknown macro opcode %02x seen\n"), op);
3695 /* Skip over unhandled opcodes. */
3697 unsigned char *desc = extended_ops[op];
3698 nargs = read_leb128 (desc, &bytes_read, 0);
3702 printf (_(" DW_MACRO_GNU_%02x\n"), op);
3705 printf (_(" DW_MACRO_GNU_%02x -"), op);
3706 for (n = 0; n < nargs; n++)
3709 = read_and_display_attr_value (0, byte_get (desc++, 1),
3710 curr, 0, 0, offset_size,
3711 version, NULL, 0, NULL);
3728 display_debug_abbrev (struct dwarf_section *section,
3729 void *file ATTRIBUTE_UNUSED)
3731 abbrev_entry *entry;
3732 unsigned char *start = section->start;
3733 unsigned char *end = start + section->size;
3735 printf (_("Contents of the %s section:\n\n"), section->name);
3739 unsigned char *last;
3744 start = process_abbrev_section (start, end);
3746 if (first_abbrev == NULL)
3749 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
3751 for (entry = first_abbrev; entry; entry = entry->next)
3755 printf (" %ld %s [%s]\n",
3757 get_TAG_name (entry->tag),
3758 entry->children ? _("has children") : _("no children"));
3760 for (attr = entry->first_attr; attr; attr = attr->next)
3761 printf (" %-18s %s\n",
3762 get_AT_name (attr->attribute),
3763 get_FORM_name (attr->form));
3773 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
3776 display_loc_list (struct dwarf_section *section,
3777 unsigned char **start_ptr,
3778 int debug_info_entry,
3779 unsigned long offset,
3780 unsigned long base_address,
3783 unsigned char *start = *start_ptr;
3784 unsigned char *section_end = section->start + section->size;
3785 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3786 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3787 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3788 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3792 unsigned short length;
3793 int need_frame_base;
3797 if (start + 2 * pointer_size > section_end)
3799 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3804 /* Note: we use sign extension here in order to be sure that we can detect
3805 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
3806 address will not affect the values that we display since we always show
3807 hex values, and always the bottom 32-bits. */
3808 begin = byte_get_signed (start, pointer_size);
3809 start += pointer_size;
3810 end = byte_get_signed (start, pointer_size);
3811 start += pointer_size;
3813 printf (" %8.8lx ", offset);
3815 if (begin == 0 && end == 0)
3817 printf (_("<End of list>\n"));
3821 /* Check base address specifiers. */
3822 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3825 print_dwarf_vma (begin, pointer_size);
3826 print_dwarf_vma (end, pointer_size);
3827 printf (_("(base address)\n"));
3831 if (start + 2 > section_end)
3833 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3838 length = byte_get (start, 2);
3841 if (start + length > section_end)
3843 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3848 print_dwarf_vma (begin + base_address, pointer_size);
3849 print_dwarf_vma (end + base_address, pointer_size);
3852 need_frame_base = decode_location_expression (start,
3857 cu_offset, section);
3860 if (need_frame_base && !has_frame_base)
3861 printf (_(" [without DW_AT_frame_base]"));
3864 fputs (_(" (start == end)"), stdout);
3865 else if (begin > end)
3866 fputs (_(" (start > end)"), stdout);
3876 /* Display a location list from a .dwo section. It uses address indexes rather
3877 than embedded addresses. This code closely follows display_loc_list, but the
3878 two are sufficiently different that combining things is very ugly. */
3881 display_loc_list_dwo (struct dwarf_section *section,
3882 unsigned char **start_ptr,
3883 int debug_info_entry,
3884 unsigned long offset,
3887 unsigned char *start = *start_ptr;
3888 unsigned char *section_end = section->start + section->size;
3889 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3890 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3891 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3892 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3894 unsigned short length;
3895 int need_frame_base;
3897 unsigned int bytes_read;
3901 printf (" %8.8lx ", offset);
3903 if (start + 2 > section_end)
3905 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3910 entry_type = byte_get (start, 1);
3914 case 0: /* A terminating entry. */
3915 idx = byte_get (start, 1);
3919 printf (_("<End of list>\n"));
3921 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3924 case 1: /* A base-address entry. */
3925 idx = read_leb128 (start, &bytes_read, 0);
3926 start += bytes_read;
3927 print_dwarf_vma (idx, pointer_size);
3928 printf (_("(base address index)\n"));
3930 case 2: /* A normal entry. */
3931 idx = read_leb128 (start, &bytes_read, 0);
3932 start += bytes_read;
3933 print_dwarf_vma (idx, pointer_size);
3934 idx = read_leb128 (start, &bytes_read, 0);
3935 start += bytes_read;
3936 print_dwarf_vma (idx, pointer_size);
3939 warn (_("Unknown location-list type 0x%x.\n"), entry_type);
3944 if (start + 2 > section_end)
3946 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3951 length = byte_get (start, 2);
3954 if (start + length > section_end)
3956 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3962 need_frame_base = decode_location_expression (start,
3967 cu_offset, section);
3970 if (need_frame_base && !has_frame_base)
3971 printf (_(" [without DW_AT_frame_base]"));
3981 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3983 static dwarf_vma *loc_offsets;
3986 loc_offsets_compar (const void *ap, const void *bp)
3988 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
3989 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
3991 return (a > b) - (b > a);
3995 display_debug_loc (struct dwarf_section *section, void *file)
3997 unsigned char *start = section->start;
3998 unsigned long bytes;
3999 unsigned char *section_begin = start;
4000 unsigned int num_loc_list = 0;
4001 unsigned long last_offset = 0;
4002 unsigned int first = 0;
4006 int seen_first_offset = 0;
4007 int locs_sorted = 1;
4008 unsigned char *next;
4009 unsigned int *array = NULL;
4010 const char *suffix = strrchr (section->name, '.');
4013 if (suffix && strcmp (suffix, ".dwo") == 0)
4016 bytes = section->size;
4020 printf (_("\nThe %s section is empty.\n"), section->name);
4024 if (load_debug_info (file) == 0)
4026 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4031 /* Check the order of location list in .debug_info section. If
4032 offsets of location lists are in the ascending order, we can
4033 use `debug_information' directly. */
4034 for (i = 0; i < num_debug_info_entries; i++)
4038 num = debug_information [i].num_loc_offsets;
4039 if (num > num_loc_list)
4042 /* Check if we can use `debug_information' directly. */
4043 if (locs_sorted && num != 0)
4045 if (!seen_first_offset)
4047 /* This is the first location list. */
4048 last_offset = debug_information [i].loc_offsets [0];
4050 seen_first_offset = 1;
4056 for (; j < num; j++)
4059 debug_information [i].loc_offsets [j])
4064 last_offset = debug_information [i].loc_offsets [j];
4069 if (!seen_first_offset)
4070 error (_("No location lists in .debug_info section!\n"));
4072 /* DWARF sections under Mach-O have non-zero addresses. */
4073 if (debug_information [first].num_loc_offsets > 0
4074 && debug_information [first].loc_offsets [0] != section->address)
4075 warn (_("Location lists in %s section start at 0x%s\n"),
4077 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4080 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4081 printf (_("Contents of the %s section:\n\n"), section->name);
4083 printf (_(" Offset Begin End Expression\n"));
4085 printf (_(" Offset Begin idx End idx Expression\n"));
4087 seen_first_offset = 0;
4088 for (i = first; i < num_debug_info_entries; i++)
4090 unsigned long offset;
4091 unsigned long base_address;
4096 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4098 loc_offsets = debug_information [i].loc_offsets;
4099 qsort (array, debug_information [i].num_loc_offsets,
4100 sizeof (*array), loc_offsets_compar);
4103 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4105 j = locs_sorted ? k : array[k];
4107 && debug_information [i].loc_offsets [locs_sorted
4108 ? k - 1 : array [k - 1]]
4109 == debug_information [i].loc_offsets [j])
4111 has_frame_base = debug_information [i].have_frame_base [j];
4112 /* DWARF sections under Mach-O have non-zero addresses. */
4113 offset = debug_information [i].loc_offsets [j] - section->address;
4114 next = section_begin + offset;
4115 base_address = debug_information [i].base_address;
4117 if (!seen_first_offset)
4118 seen_first_offset = 1;
4122 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4123 (unsigned long) (start - section_begin),
4124 (unsigned long) (next - section_begin));
4125 else if (start > next)
4126 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4127 (unsigned long) (start - section_begin),
4128 (unsigned long) (next - section_begin));
4132 if (offset >= bytes)
4134 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4140 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4142 display_loc_list (section, &start, i, offset, base_address,
4147 if (start < section->start + section->size)
4148 warn (_("There are %ld unused bytes at the end of section %s\n"),
4149 (long) (section->start + section->size - start), section->name);
4156 display_debug_str (struct dwarf_section *section,
4157 void *file ATTRIBUTE_UNUSED)
4159 unsigned char *start = section->start;
4160 unsigned long bytes = section->size;
4161 dwarf_vma addr = section->address;
4165 printf (_("\nThe %s section is empty.\n"), section->name);
4169 printf (_("Contents of the %s section:\n\n"), section->name);
4177 lbytes = (bytes > 16 ? 16 : bytes);
4179 printf (" 0x%8.8lx ", (unsigned long) addr);
4181 for (j = 0; j < 16; j++)
4184 printf ("%2.2x", start[j]);
4192 for (j = 0; j < lbytes; j++)
4195 if (k >= ' ' && k < 0x80)
4214 display_debug_info (struct dwarf_section *section, void *file)
4216 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4220 display_debug_types (struct dwarf_section *section, void *file)
4222 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4226 display_trace_info (struct dwarf_section *section, void *file)
4228 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4232 display_debug_aranges (struct dwarf_section *section,
4233 void *file ATTRIBUTE_UNUSED)
4235 unsigned char *start = section->start;
4236 unsigned char *end = start + section->size;
4238 printf (_("Contents of the %s section:\n\n"), section->name);
4240 /* It does not matter if this load fails,
4241 we test for that later on. */
4242 load_debug_info (file);
4246 unsigned char *hdrptr;
4247 DWARF2_Internal_ARange arange;
4248 unsigned char *addr_ranges;
4251 unsigned char address_size;
4254 int initial_length_size;
4258 arange.ar_length = byte_get (hdrptr, 4);
4261 if (arange.ar_length == 0xffffffff)
4263 arange.ar_length = byte_get (hdrptr, 8);
4266 initial_length_size = 12;
4271 initial_length_size = 4;
4274 arange.ar_version = byte_get (hdrptr, 2);
4277 arange.ar_info_offset = byte_get (hdrptr, offset_size);
4278 hdrptr += offset_size;
4280 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4281 && num_debug_info_entries > 0
4282 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4283 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4284 (unsigned long) arange.ar_info_offset, section->name);
4286 arange.ar_pointer_size = byte_get (hdrptr, 1);
4289 arange.ar_segment_size = byte_get (hdrptr, 1);
4292 if (arange.ar_version != 2 && arange.ar_version != 3)
4294 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4298 printf (_(" Length: %ld\n"),
4299 (long) arange.ar_length);
4300 printf (_(" Version: %d\n"), arange.ar_version);
4301 printf (_(" Offset into .debug_info: 0x%lx\n"),
4302 (unsigned long) arange.ar_info_offset);
4303 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4304 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4306 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4308 if (address_size == 0)
4310 error (_("Invalid address size in %s section!\n"),
4315 /* The DWARF spec does not require that the address size be a power
4316 of two, but we do. This will have to change if we ever encounter
4317 an uneven architecture. */
4318 if ((address_size & (address_size - 1)) != 0)
4320 warn (_("Pointer size + Segment size is not a power of two.\n"));
4324 if (address_size > 4)
4325 printf (_("\n Address Length\n"));
4327 printf (_("\n Address Length\n"));
4329 addr_ranges = hdrptr;
4331 /* Must pad to an alignment boundary that is twice the address size. */
4332 excess = (hdrptr - start) % (2 * address_size);
4334 addr_ranges += (2 * address_size) - excess;
4336 start += arange.ar_length + initial_length_size;
4338 while (addr_ranges + 2 * address_size <= start)
4340 address = byte_get (addr_ranges, address_size);
4342 addr_ranges += address_size;
4344 length = byte_get (addr_ranges, address_size);
4346 addr_ranges += address_size;
4349 print_dwarf_vma (address, address_size);
4350 print_dwarf_vma (length, address_size);
4360 /* Comparison function for qsort. */
4362 comp_addr_base (const void * v0, const void * v1)
4364 debug_info * info0 = (debug_info *) v0;
4365 debug_info * info1 = (debug_info *) v1;
4366 return info0->addr_base - info1->addr_base;
4369 /* Display the debug_addr section. */
4371 display_debug_addr (struct dwarf_section *section,
4374 debug_info **debug_addr_info;
4375 unsigned char *entry;
4380 if (section->size == 0)
4382 printf (_("\nThe %s section is empty.\n"), section->name);
4386 if (load_debug_info (file) == 0)
4388 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4393 printf (_("Contents of the %s section:\n\n"), section->name);
4395 debug_addr_info = (debug_info **) xmalloc (num_debug_info_entries + 1
4396 * sizeof (debug_info *));
4399 for (i = 0; i < num_debug_info_entries; i++)
4401 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4402 debug_addr_info [count++] = &debug_information [i];
4405 /* Add a sentinel to make iteration convenient. */
4406 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4407 debug_addr_info [count]->addr_base = section->size;
4409 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4410 for (i = 0; i < count; i++)
4414 printf (_(" For compilation unit at offset 0x%s:\n"),
4415 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4417 printf (_("\tIndex\tOffset\n"));
4418 entry = section->start + debug_addr_info [i]->addr_base;
4419 end = section->start + debug_addr_info [i + 1]->addr_base;
4423 dwarf_vma base = byte_get (entry, debug_addr_info [i]->pointer_size);
4424 printf (_("\t%d:\t%s\n"), idx, dwarf_vmatoa ("x", base));
4425 entry += debug_addr_info [i]->pointer_size;
4431 free (debug_addr_info);
4435 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4437 display_debug_str_offsets (struct dwarf_section *section,
4438 void *file ATTRIBUTE_UNUSED)
4440 if (section->size == 0)
4442 printf (_("\nThe %s section is empty.\n"), section->name);
4445 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4446 what the offset size is for this section. */
4450 /* Each debug_information[x].range_lists[y] gets this representation for
4451 sorting purposes. */
4455 /* The debug_information[x].range_lists[y] value. */
4456 unsigned long ranges_offset;
4458 /* Original debug_information to find parameters of the data. */
4459 debug_info *debug_info_p;
4462 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4465 range_entry_compar (const void *ap, const void *bp)
4467 const struct range_entry *a_re = (const struct range_entry *) ap;
4468 const struct range_entry *b_re = (const struct range_entry *) bp;
4469 const unsigned long a = a_re->ranges_offset;
4470 const unsigned long b = b_re->ranges_offset;
4472 return (a > b) - (b > a);
4476 display_debug_ranges (struct dwarf_section *section,
4477 void *file ATTRIBUTE_UNUSED)
4479 unsigned char *start = section->start;
4480 unsigned char *last_start = start;
4481 unsigned long bytes;
4482 unsigned char *section_begin = start;
4483 unsigned int num_range_list, i;
4484 struct range_entry *range_entries, *range_entry_fill;
4486 bytes = section->size;
4490 printf (_("\nThe %s section is empty.\n"), section->name);
4494 if (load_debug_info (file) == 0)
4496 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4502 for (i = 0; i < num_debug_info_entries; i++)
4503 num_range_list += debug_information [i].num_range_lists;
4505 if (num_range_list == 0)
4507 /* This can happen when the file was compiled with -gsplit-debug
4508 which removes references to range lists from the primary .o file. */
4509 printf (_("No range lists in .debug_info section.\n"));
4513 range_entries = (struct range_entry *)
4514 xmalloc (sizeof (*range_entries) * num_range_list);
4515 range_entry_fill = range_entries;
4517 for (i = 0; i < num_debug_info_entries; i++)
4519 debug_info *debug_info_p = &debug_information[i];
4522 for (j = 0; j < debug_info_p->num_range_lists; j++)
4524 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4525 range_entry_fill->debug_info_p = debug_info_p;
4530 qsort (range_entries, num_range_list, sizeof (*range_entries),
4531 range_entry_compar);
4533 /* DWARF sections under Mach-O have non-zero addresses. */
4534 if (dwarf_check != 0 && range_entries[0].ranges_offset != section->address)
4535 warn (_("Range lists in %s section start at 0x%lx\n"),
4536 section->name, range_entries[0].ranges_offset);
4538 printf (_("Contents of the %s section:\n\n"), section->name);
4539 printf (_(" Offset Begin End\n"));
4541 for (i = 0; i < num_range_list; i++)
4543 struct range_entry *range_entry = &range_entries[i];
4544 debug_info *debug_info_p = range_entry->debug_info_p;
4545 unsigned int pointer_size;
4546 unsigned long offset;
4547 unsigned char *next;
4548 unsigned long base_address;
4550 pointer_size = debug_info_p->pointer_size;
4552 /* DWARF sections under Mach-O have non-zero addresses. */
4553 offset = range_entry->ranges_offset - section->address;
4554 next = section_begin + offset;
4555 base_address = debug_info_p->base_address;
4557 if (dwarf_check != 0 && i > 0)
4560 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4561 (unsigned long) (start - section_begin),
4562 (unsigned long) (next - section_begin), section->name);
4563 else if (start > next)
4565 if (next == last_start)
4567 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4568 (unsigned long) (start - section_begin),
4569 (unsigned long) (next - section_begin), section->name);
4580 /* Note: we use sign extension here in order to be sure that
4581 we can detect the -1 escape value. Sign extension into the
4582 top 32 bits of a 32-bit address will not affect the values
4583 that we display since we always show hex values, and always
4584 the bottom 32-bits. */
4585 begin = byte_get_signed (start, pointer_size);
4586 start += pointer_size;
4587 end = byte_get_signed (start, pointer_size);
4588 start += pointer_size;
4590 printf (" %8.8lx ", offset);
4592 if (begin == 0 && end == 0)
4594 printf (_("<End of list>\n"));
4598 /* Check base address specifiers. */
4599 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4602 print_dwarf_vma (begin, pointer_size);
4603 print_dwarf_vma (end, pointer_size);
4604 printf ("(base address)\n");
4608 print_dwarf_vma (begin + base_address, pointer_size);
4609 print_dwarf_vma (end + base_address, pointer_size);
4612 fputs (_("(start == end)"), stdout);
4613 else if (begin > end)
4614 fputs (_("(start > end)"), stdout);
4621 free (range_entries);
4626 typedef struct Frame_Chunk
4628 struct Frame_Chunk *next;
4629 unsigned char *chunk_start;
4631 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4632 short int *col_type;
4635 unsigned int code_factor;
4637 unsigned long pc_begin;
4638 unsigned long pc_range;
4642 unsigned char fde_encoding;
4643 unsigned char cfa_exp;
4644 unsigned char ptr_size;
4645 unsigned char segment_size;
4649 static const char *const *dwarf_regnames;
4650 static unsigned int dwarf_regnames_count;
4652 /* A marker for a col_type that means this column was never referenced
4653 in the frame info. */
4654 #define DW_CFA_unreferenced (-1)
4656 /* Return 0 if not more space is needed, 1 if more space is needed,
4657 -1 for invalid reg. */
4660 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4662 int prev = fc->ncols;
4664 if (reg < (unsigned int) fc->ncols)
4667 if (dwarf_regnames_count
4668 && reg > dwarf_regnames_count)
4671 fc->ncols = reg + 1;
4672 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4673 sizeof (short int));
4674 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4676 while (prev < fc->ncols)
4678 fc->col_type[prev] = DW_CFA_unreferenced;
4679 fc->col_offset[prev] = 0;
4685 static const char *const dwarf_regnames_i386[] =
4687 "eax", "ecx", "edx", "ebx",
4688 "esp", "ebp", "esi", "edi",
4689 "eip", "eflags", NULL,
4690 "st0", "st1", "st2", "st3",
4691 "st4", "st5", "st6", "st7",
4693 "xmm0", "xmm1", "xmm2", "xmm3",
4694 "xmm4", "xmm5", "xmm6", "xmm7",
4695 "mm0", "mm1", "mm2", "mm3",
4696 "mm4", "mm5", "mm6", "mm7",
4697 "fcw", "fsw", "mxcsr",
4698 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4703 init_dwarf_regnames_i386 (void)
4705 dwarf_regnames = dwarf_regnames_i386;
4706 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4709 static const char *const dwarf_regnames_x86_64[] =
4711 "rax", "rdx", "rcx", "rbx",
4712 "rsi", "rdi", "rbp", "rsp",
4713 "r8", "r9", "r10", "r11",
4714 "r12", "r13", "r14", "r15",
4716 "xmm0", "xmm1", "xmm2", "xmm3",
4717 "xmm4", "xmm5", "xmm6", "xmm7",
4718 "xmm8", "xmm9", "xmm10", "xmm11",
4719 "xmm12", "xmm13", "xmm14", "xmm15",
4720 "st0", "st1", "st2", "st3",
4721 "st4", "st5", "st6", "st7",
4722 "mm0", "mm1", "mm2", "mm3",
4723 "mm4", "mm5", "mm6", "mm7",
4725 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4726 "fs.base", "gs.base", NULL, NULL,
4728 "mxcsr", "fcw", "fsw"
4732 init_dwarf_regnames_x86_64 (void)
4734 dwarf_regnames = dwarf_regnames_x86_64;
4735 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4739 init_dwarf_regnames (unsigned int e_machine)
4745 init_dwarf_regnames_i386 ();
4751 init_dwarf_regnames_x86_64 ();
4760 regname (unsigned int regno, int row)
4762 static char reg[64];
4764 && regno < dwarf_regnames_count
4765 && dwarf_regnames [regno] != NULL)
4768 return dwarf_regnames [regno];
4769 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4770 dwarf_regnames [regno]);
4773 snprintf (reg, sizeof (reg), "r%d", regno);
4778 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4783 if (*max_regs < fc->ncols)
4784 *max_regs = fc->ncols;
4786 if (*need_col_headers)
4788 static const char *sloc = " LOC";
4790 *need_col_headers = 0;
4792 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4794 for (r = 0; r < *max_regs; r++)
4795 if (fc->col_type[r] != DW_CFA_unreferenced)
4800 printf ("%-5s ", regname (r, 1));
4806 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4808 strcpy (tmp, "exp");
4810 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4811 printf ("%-8s ", tmp);
4813 for (r = 0; r < fc->ncols; r++)
4815 if (fc->col_type[r] != DW_CFA_unreferenced)
4817 switch (fc->col_type[r])
4819 case DW_CFA_undefined:
4822 case DW_CFA_same_value:
4826 sprintf (tmp, "c%+d", fc->col_offset[r]);
4828 case DW_CFA_val_offset:
4829 sprintf (tmp, "v%+d", fc->col_offset[r]);
4831 case DW_CFA_register:
4832 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4834 case DW_CFA_expression:
4835 strcpy (tmp, "exp");
4837 case DW_CFA_val_expression:
4838 strcpy (tmp, "vexp");
4841 strcpy (tmp, "n/a");
4844 printf ("%-5s ", tmp);
4850 #define GET(N) byte_get (start, N); start += N
4851 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4852 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4855 display_debug_frames (struct dwarf_section *section,
4856 void *file ATTRIBUTE_UNUSED)
4858 unsigned char *start = section->start;
4859 unsigned char *end = start + section->size;
4860 unsigned char *section_start = start;
4861 Frame_Chunk *chunks = 0;
4862 Frame_Chunk *remembered_state = 0;
4864 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4865 unsigned int length_return;
4867 const char *bad_reg = _("bad register: ");
4868 int saved_eh_addr_size = eh_addr_size;
4870 printf (_("Contents of the %s section:\n"), section->name);
4874 unsigned char *saved_start;
4875 unsigned char *block_end;
4876 unsigned long length;
4877 unsigned long cie_id;
4880 int need_col_headers = 1;
4881 unsigned char *augmentation_data = NULL;
4882 unsigned long augmentation_data_len = 0;
4883 int encoded_ptr_size = saved_eh_addr_size;
4885 int initial_length_size;
4887 saved_start = start;
4888 length = byte_get (start, 4); start += 4;
4892 printf ("\n%08lx ZERO terminator\n\n",
4893 (unsigned long)(saved_start - section_start));
4897 if (length == 0xffffffff)
4899 length = byte_get (start, 8);
4902 initial_length_size = 12;
4907 initial_length_size = 4;
4910 block_end = saved_start + length + initial_length_size;
4911 if (block_end > end)
4913 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4914 length, (unsigned long)(saved_start - section_start));
4917 cie_id = byte_get (start, offset_size); start += offset_size;
4919 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4923 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4924 memset (fc, 0, sizeof (Frame_Chunk));
4928 fc->chunk_start = saved_start;
4930 fc->col_type = (short int *) xmalloc (sizeof (short int));
4931 fc->col_offset = (int *) xmalloc (sizeof (int));
4932 frame_need_space (fc, max_regs - 1);
4936 fc->augmentation = (char *) start;
4937 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4939 if (strcmp (fc->augmentation, "eh") == 0)
4940 start += eh_addr_size;
4944 fc->ptr_size = GET (1);
4945 fc->segment_size = GET (1);
4946 eh_addr_size = fc->ptr_size;
4950 fc->ptr_size = eh_addr_size;
4951 fc->segment_size = 0;
4953 fc->code_factor = LEB ();
4954 fc->data_factor = SLEB ();
4964 if (fc->augmentation[0] == 'z')
4966 augmentation_data_len = LEB ();
4967 augmentation_data = start;
4968 start += augmentation_data_len;
4972 if (do_debug_frames_interp)
4973 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4974 (unsigned long)(saved_start - section_start), length, cie_id,
4975 fc->augmentation, fc->code_factor, fc->data_factor,
4979 printf ("\n%08lx %08lx %08lx CIE\n",
4980 (unsigned long)(saved_start - section_start), length, cie_id);
4981 printf (" Version: %d\n", version);
4982 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4985 printf (" Pointer Size: %u\n", fc->ptr_size);
4986 printf (" Segment Size: %u\n", fc->segment_size);
4988 printf (" Code alignment factor: %u\n", fc->code_factor);
4989 printf (" Data alignment factor: %d\n", fc->data_factor);
4990 printf (" Return address column: %d\n", fc->ra);
4992 if (augmentation_data_len)
4995 printf (" Augmentation data: ");
4996 for (i = 0; i < augmentation_data_len; ++i)
4997 printf (" %02x", augmentation_data[i]);
5003 if (augmentation_data_len)
5005 unsigned char *p, *q;
5006 p = (unsigned char *) fc->augmentation + 1;
5007 q = augmentation_data;
5014 q += 1 + size_of_encoded_value (*q);
5016 fc->fde_encoding = *q++;
5024 if (fc->fde_encoding)
5025 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5028 frame_need_space (fc, fc->ra);
5032 unsigned char *look_for;
5033 static Frame_Chunk fde_fc;
5034 unsigned long segment_selector;
5037 memset (fc, 0, sizeof (Frame_Chunk));
5039 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
5041 for (cie = chunks; cie ; cie = cie->next)
5042 if (cie->chunk_start == look_for)
5047 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
5048 cie_id, (unsigned long)(saved_start - section_start));
5050 fc->col_type = (short int *) xmalloc (sizeof (short int));
5051 fc->col_offset = (int *) xmalloc (sizeof (int));
5052 frame_need_space (fc, max_regs - 1);
5054 fc->augmentation = "";
5055 fc->fde_encoding = 0;
5056 fc->ptr_size = eh_addr_size;
5057 fc->segment_size = 0;
5061 fc->ncols = cie->ncols;
5062 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5063 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5064 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5065 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5066 fc->augmentation = cie->augmentation;
5067 fc->ptr_size = cie->ptr_size;
5068 eh_addr_size = cie->ptr_size;
5069 fc->segment_size = cie->segment_size;
5070 fc->code_factor = cie->code_factor;
5071 fc->data_factor = cie->data_factor;
5072 fc->cfa_reg = cie->cfa_reg;
5073 fc->cfa_offset = cie->cfa_offset;
5075 frame_need_space (fc, max_regs - 1);
5076 fc->fde_encoding = cie->fde_encoding;
5079 if (fc->fde_encoding)
5080 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5082 segment_selector = 0;
5083 if (fc->segment_size)
5085 segment_selector = byte_get (start, fc->segment_size);
5086 start += fc->segment_size;
5088 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
5089 start += encoded_ptr_size;
5090 fc->pc_range = byte_get (start, encoded_ptr_size);
5091 start += encoded_ptr_size;
5093 if (cie->augmentation[0] == 'z')
5095 augmentation_data_len = LEB ();
5096 augmentation_data = start;
5097 start += augmentation_data_len;
5100 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
5101 (unsigned long)(saved_start - section_start), length, cie_id,
5102 (unsigned long)(cie->chunk_start - section_start));
5103 if (fc->segment_size)
5104 printf ("%04lx:", segment_selector);
5105 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
5106 if (! do_debug_frames_interp && augmentation_data_len)
5110 printf (" Augmentation data: ");
5111 for (i = 0; i < augmentation_data_len; ++i)
5112 printf (" %02x", augmentation_data[i]);
5118 /* At this point, fc is the current chunk, cie (if any) is set, and
5119 we're about to interpret instructions for the chunk. */
5120 /* ??? At present we need to do this always, since this sizes the
5121 fc->col_type and fc->col_offset arrays, which we write into always.
5122 We should probably split the interpreted and non-interpreted bits
5123 into two different routines, since there's so much that doesn't
5124 really overlap between them. */
5125 if (1 || do_debug_frames_interp)
5127 /* Start by making a pass over the chunk, allocating storage
5128 and taking note of what registers are used. */
5129 unsigned char *tmp = start;
5131 while (start < block_end)
5134 unsigned long reg, temp;
5141 /* Warning: if you add any more cases to this switch, be
5142 sure to add them to the corresponding switch below. */
5145 case DW_CFA_advance_loc:
5149 if (frame_need_space (fc, opa) >= 0)
5150 fc->col_type[opa] = DW_CFA_undefined;
5152 case DW_CFA_restore:
5153 if (frame_need_space (fc, opa) >= 0)
5154 fc->col_type[opa] = DW_CFA_undefined;
5156 case DW_CFA_set_loc:
5157 start += encoded_ptr_size;
5159 case DW_CFA_advance_loc1:
5162 case DW_CFA_advance_loc2:
5165 case DW_CFA_advance_loc4:
5168 case DW_CFA_offset_extended:
5169 case DW_CFA_val_offset:
5170 reg = LEB (); LEB ();
5171 if (frame_need_space (fc, reg) >= 0)
5172 fc->col_type[reg] = DW_CFA_undefined;
5174 case DW_CFA_restore_extended:
5176 frame_need_space (fc, reg);
5177 if (frame_need_space (fc, reg) >= 0)
5178 fc->col_type[reg] = DW_CFA_undefined;
5180 case DW_CFA_undefined:
5182 if (frame_need_space (fc, reg) >= 0)
5183 fc->col_type[reg] = DW_CFA_undefined;
5185 case DW_CFA_same_value:
5187 if (frame_need_space (fc, reg) >= 0)
5188 fc->col_type[reg] = DW_CFA_undefined;
5190 case DW_CFA_register:
5191 reg = LEB (); LEB ();
5192 if (frame_need_space (fc, reg) >= 0)
5193 fc->col_type[reg] = DW_CFA_undefined;
5195 case DW_CFA_def_cfa:
5198 case DW_CFA_def_cfa_register:
5201 case DW_CFA_def_cfa_offset:
5204 case DW_CFA_def_cfa_expression:
5208 case DW_CFA_expression:
5209 case DW_CFA_val_expression:
5213 if (frame_need_space (fc, reg) >= 0)
5214 fc->col_type[reg] = DW_CFA_undefined;
5216 case DW_CFA_offset_extended_sf:
5217 case DW_CFA_val_offset_sf:
5218 reg = LEB (); SLEB ();
5219 if (frame_need_space (fc, reg) >= 0)
5220 fc->col_type[reg] = DW_CFA_undefined;
5222 case DW_CFA_def_cfa_sf:
5225 case DW_CFA_def_cfa_offset_sf:
5228 case DW_CFA_MIPS_advance_loc8:
5231 case DW_CFA_GNU_args_size:
5234 case DW_CFA_GNU_negative_offset_extended:
5235 reg = LEB (); LEB ();
5236 if (frame_need_space (fc, reg) >= 0)
5237 fc->col_type[reg] = DW_CFA_undefined;
5246 /* Now we know what registers are used, make a second pass over
5247 the chunk, this time actually printing out the info. */
5249 while (start < block_end)
5252 unsigned long ul, reg, roffs;
5255 const char *reg_prefix = "";
5262 /* Warning: if you add any more cases to this switch, be
5263 sure to add them to the corresponding switch above. */
5266 case DW_CFA_advance_loc:
5267 if (do_debug_frames_interp)
5268 frame_display_row (fc, &need_col_headers, &max_regs);
5270 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5271 opa * fc->code_factor,
5272 fc->pc_begin + opa * fc->code_factor);
5273 fc->pc_begin += opa * fc->code_factor;
5278 if (opa >= (unsigned int) fc->ncols)
5279 reg_prefix = bad_reg;
5280 if (! do_debug_frames_interp || *reg_prefix != '\0')
5281 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5282 reg_prefix, regname (opa, 0),
5283 roffs * fc->data_factor);
5284 if (*reg_prefix == '\0')
5286 fc->col_type[opa] = DW_CFA_offset;
5287 fc->col_offset[opa] = roffs * fc->data_factor;
5291 case DW_CFA_restore:
5292 if (opa >= (unsigned int) cie->ncols
5293 || opa >= (unsigned int) fc->ncols)
5294 reg_prefix = bad_reg;
5295 if (! do_debug_frames_interp || *reg_prefix != '\0')
5296 printf (" DW_CFA_restore: %s%s\n",
5297 reg_prefix, regname (opa, 0));
5298 if (*reg_prefix == '\0')
5300 fc->col_type[opa] = cie->col_type[opa];
5301 fc->col_offset[opa] = cie->col_offset[opa];
5302 if (do_debug_frames_interp
5303 && fc->col_type[opa] == DW_CFA_unreferenced)
5304 fc->col_type[opa] = DW_CFA_undefined;
5308 case DW_CFA_set_loc:
5309 vma = get_encoded_value (start, fc->fde_encoding, section);
5310 start += encoded_ptr_size;
5311 if (do_debug_frames_interp)
5312 frame_display_row (fc, &need_col_headers, &max_regs);
5314 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5318 case DW_CFA_advance_loc1:
5319 ofs = byte_get (start, 1); start += 1;
5320 if (do_debug_frames_interp)
5321 frame_display_row (fc, &need_col_headers, &max_regs);
5323 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5324 ofs * fc->code_factor,
5325 fc->pc_begin + ofs * fc->code_factor);
5326 fc->pc_begin += ofs * fc->code_factor;
5329 case DW_CFA_advance_loc2:
5330 ofs = byte_get (start, 2); start += 2;
5331 if (do_debug_frames_interp)
5332 frame_display_row (fc, &need_col_headers, &max_regs);
5334 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5335 ofs * fc->code_factor,
5336 fc->pc_begin + ofs * fc->code_factor);
5337 fc->pc_begin += ofs * fc->code_factor;
5340 case DW_CFA_advance_loc4:
5341 ofs = byte_get (start, 4); start += 4;
5342 if (do_debug_frames_interp)
5343 frame_display_row (fc, &need_col_headers, &max_regs);
5345 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5346 ofs * fc->code_factor,
5347 fc->pc_begin + ofs * fc->code_factor);
5348 fc->pc_begin += ofs * fc->code_factor;
5351 case DW_CFA_offset_extended:
5354 if (reg >= (unsigned int) fc->ncols)
5355 reg_prefix = bad_reg;
5356 if (! do_debug_frames_interp || *reg_prefix != '\0')
5357 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5358 reg_prefix, regname (reg, 0),
5359 roffs * fc->data_factor);
5360 if (*reg_prefix == '\0')
5362 fc->col_type[reg] = DW_CFA_offset;
5363 fc->col_offset[reg] = roffs * fc->data_factor;
5367 case DW_CFA_val_offset:
5370 if (reg >= (unsigned int) fc->ncols)
5371 reg_prefix = bad_reg;
5372 if (! do_debug_frames_interp || *reg_prefix != '\0')
5373 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5374 reg_prefix, regname (reg, 0),
5375 roffs * fc->data_factor);
5376 if (*reg_prefix == '\0')
5378 fc->col_type[reg] = DW_CFA_val_offset;
5379 fc->col_offset[reg] = roffs * fc->data_factor;
5383 case DW_CFA_restore_extended:
5385 if (reg >= (unsigned int) cie->ncols
5386 || reg >= (unsigned int) fc->ncols)
5387 reg_prefix = bad_reg;
5388 if (! do_debug_frames_interp || *reg_prefix != '\0')
5389 printf (" DW_CFA_restore_extended: %s%s\n",
5390 reg_prefix, regname (reg, 0));
5391 if (*reg_prefix == '\0')
5393 fc->col_type[reg] = cie->col_type[reg];
5394 fc->col_offset[reg] = cie->col_offset[reg];
5398 case DW_CFA_undefined:
5400 if (reg >= (unsigned int) fc->ncols)
5401 reg_prefix = bad_reg;
5402 if (! do_debug_frames_interp || *reg_prefix != '\0')
5403 printf (" DW_CFA_undefined: %s%s\n",
5404 reg_prefix, regname (reg, 0));
5405 if (*reg_prefix == '\0')
5407 fc->col_type[reg] = DW_CFA_undefined;
5408 fc->col_offset[reg] = 0;
5412 case DW_CFA_same_value:
5414 if (reg >= (unsigned int) fc->ncols)
5415 reg_prefix = bad_reg;
5416 if (! do_debug_frames_interp || *reg_prefix != '\0')
5417 printf (" DW_CFA_same_value: %s%s\n",
5418 reg_prefix, regname (reg, 0));
5419 if (*reg_prefix == '\0')
5421 fc->col_type[reg] = DW_CFA_same_value;
5422 fc->col_offset[reg] = 0;
5426 case DW_CFA_register:
5429 if (reg >= (unsigned int) fc->ncols)
5430 reg_prefix = bad_reg;
5431 if (! do_debug_frames_interp || *reg_prefix != '\0')
5433 printf (" DW_CFA_register: %s%s in ",
5434 reg_prefix, regname (reg, 0));
5435 puts (regname (roffs, 0));
5437 if (*reg_prefix == '\0')
5439 fc->col_type[reg] = DW_CFA_register;
5440 fc->col_offset[reg] = roffs;
5444 case DW_CFA_remember_state:
5445 if (! do_debug_frames_interp)
5446 printf (" DW_CFA_remember_state\n");
5447 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5448 rs->ncols = fc->ncols;
5449 rs->col_type = (short int *) xcmalloc (rs->ncols,
5450 sizeof (short int));
5451 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
5452 memcpy (rs->col_type, fc->col_type, rs->ncols);
5453 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5454 rs->next = remembered_state;
5455 remembered_state = rs;
5458 case DW_CFA_restore_state:
5459 if (! do_debug_frames_interp)
5460 printf (" DW_CFA_restore_state\n");
5461 rs = remembered_state;
5464 remembered_state = rs->next;
5465 frame_need_space (fc, rs->ncols - 1);
5466 memcpy (fc->col_type, rs->col_type, rs->ncols);
5467 memcpy (fc->col_offset, rs->col_offset,
5468 rs->ncols * sizeof (int));
5469 free (rs->col_type);
5470 free (rs->col_offset);
5473 else if (do_debug_frames_interp)
5474 printf ("Mismatched DW_CFA_restore_state\n");
5477 case DW_CFA_def_cfa:
5478 fc->cfa_reg = LEB ();
5479 fc->cfa_offset = LEB ();
5481 if (! do_debug_frames_interp)
5482 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5483 regname (fc->cfa_reg, 0), fc->cfa_offset);
5486 case DW_CFA_def_cfa_register:
5487 fc->cfa_reg = LEB ();
5489 if (! do_debug_frames_interp)
5490 printf (" DW_CFA_def_cfa_register: %s\n",
5491 regname (fc->cfa_reg, 0));
5494 case DW_CFA_def_cfa_offset:
5495 fc->cfa_offset = LEB ();
5496 if (! do_debug_frames_interp)
5497 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5501 if (! do_debug_frames_interp)
5502 printf (" DW_CFA_nop\n");
5505 case DW_CFA_def_cfa_expression:
5507 if (! do_debug_frames_interp)
5509 printf (" DW_CFA_def_cfa_expression (");
5510 decode_location_expression (start, eh_addr_size, 0, -1,
5518 case DW_CFA_expression:
5521 if (reg >= (unsigned int) fc->ncols)
5522 reg_prefix = bad_reg;
5523 if (! do_debug_frames_interp || *reg_prefix != '\0')
5525 printf (" DW_CFA_expression: %s%s (",
5526 reg_prefix, regname (reg, 0));
5527 decode_location_expression (start, eh_addr_size, 0, -1,
5531 if (*reg_prefix == '\0')
5532 fc->col_type[reg] = DW_CFA_expression;
5536 case DW_CFA_val_expression:
5539 if (reg >= (unsigned int) fc->ncols)
5540 reg_prefix = bad_reg;
5541 if (! do_debug_frames_interp || *reg_prefix != '\0')
5543 printf (" DW_CFA_val_expression: %s%s (",
5544 reg_prefix, regname (reg, 0));
5545 decode_location_expression (start, eh_addr_size, 0, -1,
5549 if (*reg_prefix == '\0')
5550 fc->col_type[reg] = DW_CFA_val_expression;
5554 case DW_CFA_offset_extended_sf:
5557 if (frame_need_space (fc, reg) < 0)
5558 reg_prefix = bad_reg;
5559 if (! do_debug_frames_interp || *reg_prefix != '\0')
5560 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5561 reg_prefix, regname (reg, 0),
5562 l * fc->data_factor);
5563 if (*reg_prefix == '\0')
5565 fc->col_type[reg] = DW_CFA_offset;
5566 fc->col_offset[reg] = l * fc->data_factor;
5570 case DW_CFA_val_offset_sf:
5573 if (frame_need_space (fc, reg) < 0)
5574 reg_prefix = bad_reg;
5575 if (! do_debug_frames_interp || *reg_prefix != '\0')
5576 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5577 reg_prefix, regname (reg, 0),
5578 l * fc->data_factor);
5579 if (*reg_prefix == '\0')
5581 fc->col_type[reg] = DW_CFA_val_offset;
5582 fc->col_offset[reg] = l * fc->data_factor;
5586 case DW_CFA_def_cfa_sf:
5587 fc->cfa_reg = LEB ();
5588 fc->cfa_offset = SLEB ();
5589 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5591 if (! do_debug_frames_interp)
5592 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5593 regname (fc->cfa_reg, 0), fc->cfa_offset);
5596 case DW_CFA_def_cfa_offset_sf:
5597 fc->cfa_offset = SLEB ();
5598 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5599 if (! do_debug_frames_interp)
5600 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5603 case DW_CFA_MIPS_advance_loc8:
5604 ofs = byte_get (start, 8); start += 8;
5605 if (do_debug_frames_interp)
5606 frame_display_row (fc, &need_col_headers, &max_regs);
5608 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5609 ofs * fc->code_factor,
5610 fc->pc_begin + ofs * fc->code_factor);
5611 fc->pc_begin += ofs * fc->code_factor;
5614 case DW_CFA_GNU_window_save:
5615 if (! do_debug_frames_interp)
5616 printf (" DW_CFA_GNU_window_save\n");
5619 case DW_CFA_GNU_args_size:
5621 if (! do_debug_frames_interp)
5622 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5625 case DW_CFA_GNU_negative_offset_extended:
5628 if (frame_need_space (fc, reg) < 0)
5629 reg_prefix = bad_reg;
5630 if (! do_debug_frames_interp || *reg_prefix != '\0')
5631 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5632 reg_prefix, regname (reg, 0),
5633 l * fc->data_factor);
5634 if (*reg_prefix == '\0')
5636 fc->col_type[reg] = DW_CFA_offset;
5637 fc->col_offset[reg] = l * fc->data_factor;
5642 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5643 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5645 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5650 if (do_debug_frames_interp)
5651 frame_display_row (fc, &need_col_headers, &max_regs);
5654 eh_addr_size = saved_eh_addr_size;
5667 display_gdb_index (struct dwarf_section *section,
5668 void *file ATTRIBUTE_UNUSED)
5670 unsigned char *start = section->start;
5672 uint32_t cu_list_offset, tu_list_offset;
5673 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5674 unsigned int cu_list_elements, tu_list_elements;
5675 unsigned int address_table_size, symbol_table_slots;
5676 unsigned char *cu_list, *tu_list;
5677 unsigned char *address_table, *symbol_table, *constant_pool;
5680 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5682 printf (_("Contents of the %s section:\n"), section->name);
5684 if (section->size < 6 * sizeof (uint32_t))
5686 warn (_("Truncated header in the %s section.\n"), section->name);
5690 version = byte_get_little_endian (start, 4);
5691 printf (_("Version %ld\n"), (long) version);
5693 /* Prior versions are obsolete, and future versions may not be
5694 backwards compatible. */
5695 if (version < 3 || version > 7)
5697 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5701 warn (_("The address table data in version 3 may be wrong.\n"));
5703 warn (_("Version 4 does not support case insensitive lookups.\n"));
5705 warn (_("Version 5 does not include inlined functions.\n"));
5707 warn (_("Version 6 does not include symbol attributes.\n"));
5709 cu_list_offset = byte_get_little_endian (start + 4, 4);
5710 tu_list_offset = byte_get_little_endian (start + 8, 4);
5711 address_table_offset = byte_get_little_endian (start + 12, 4);
5712 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5713 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5715 if (cu_list_offset > section->size
5716 || tu_list_offset > section->size
5717 || address_table_offset > section->size
5718 || symbol_table_offset > section->size
5719 || constant_pool_offset > section->size)
5721 warn (_("Corrupt header in the %s section.\n"), section->name);
5725 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5726 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5727 address_table_size = symbol_table_offset - address_table_offset;
5728 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5730 cu_list = start + cu_list_offset;
5731 tu_list = start + tu_list_offset;
5732 address_table = start + address_table_offset;
5733 symbol_table = start + symbol_table_offset;
5734 constant_pool = start + constant_pool_offset;
5736 printf (_("\nCU table:\n"));
5737 for (i = 0; i < cu_list_elements; i += 2)
5739 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5740 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5742 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5743 (unsigned long) cu_offset,
5744 (unsigned long) (cu_offset + cu_length - 1));
5747 printf (_("\nTU table:\n"));
5748 for (i = 0; i < tu_list_elements; i += 3)
5750 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5751 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5752 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5754 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5755 (unsigned long) tu_offset,
5756 (unsigned long) type_offset);
5757 print_dwarf_vma (signature, 8);
5761 printf (_("\nAddress table:\n"));
5762 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5764 uint64_t low = byte_get_little_endian (address_table + i, 8);
5765 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5766 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5768 print_dwarf_vma (low, 8);
5769 print_dwarf_vma (high, 8);
5770 printf (_("%lu\n"), (unsigned long) cu_index);
5773 printf (_("\nSymbol table:\n"));
5774 for (i = 0; i < symbol_table_slots; ++i)
5776 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5777 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5778 uint32_t num_cus, cu;
5780 if (name_offset != 0
5781 || cu_vector_offset != 0)
5785 printf ("[%3u] %s:", i, constant_pool + name_offset);
5786 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5789 for (j = 0; j < num_cus; ++j)
5791 gdb_index_symbol_kind kind;
5793 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5794 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
5795 cu = GDB_INDEX_CU_VALUE (cu);
5796 /* Convert to TU number if it's for a type unit. */
5797 if (cu >= cu_list_elements / 2)
5798 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
5799 (unsigned long) (cu - cu_list_elements / 2));
5801 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
5805 case GDB_INDEX_SYMBOL_KIND_NONE:
5806 printf (_(" [no symbol information]"));
5808 case GDB_INDEX_SYMBOL_KIND_TYPE:
5809 printf (_(" [type]"));
5811 case GDB_INDEX_SYMBOL_KIND_VARIABLE:
5812 printf (_(" [variable]"));
5814 case GDB_INDEX_SYMBOL_KIND_FUNCTION:
5815 printf (_(" [function]"));
5817 case GDB_INDEX_SYMBOL_KIND_OTHER:
5818 printf (_(" [other]"));
5821 printf (_(" [unknown: %d]"), kind);
5836 display_debug_not_supported (struct dwarf_section *section,
5837 void *file ATTRIBUTE_UNUSED)
5839 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5846 cmalloc (size_t nmemb, size_t size)
5848 /* Check for overflow. */
5849 if (nmemb >= ~(size_t) 0 / size)
5852 return malloc (nmemb * size);
5856 xcmalloc (size_t nmemb, size_t size)
5858 /* Check for overflow. */
5859 if (nmemb >= ~(size_t) 0 / size)
5862 return xmalloc (nmemb * size);
5866 xcrealloc (void *ptr, size_t nmemb, size_t size)
5868 /* Check for overflow. */
5869 if (nmemb >= ~(size_t) 0 / size)
5872 return xrealloc (ptr, nmemb * size);
5876 free_debug_memory (void)
5882 for (i = 0; i < max; i++)
5883 free_debug_section ((enum dwarf_section_display_enum) i);
5885 if (debug_information != NULL)
5887 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
5889 for (i = 0; i < num_debug_info_entries; i++)
5891 if (!debug_information [i].max_loc_offsets)
5893 free (debug_information [i].loc_offsets);
5894 free (debug_information [i].have_frame_base);
5896 if (!debug_information [i].max_range_lists)
5897 free (debug_information [i].range_lists);
5901 free (debug_information);
5902 debug_information = NULL;
5903 num_debug_info_entries = 0;
5908 dwarf_select_sections_by_names (const char *names)
5912 const char * option;
5916 debug_dump_long_opts;
5918 static const debug_dump_long_opts opts_table [] =
5920 /* Please keep this table alpha- sorted. */
5921 { "Ranges", & do_debug_ranges, 1 },
5922 { "abbrev", & do_debug_abbrevs, 1 },
5923 { "aranges", & do_debug_aranges, 1 },
5924 { "frames", & do_debug_frames, 1 },
5925 { "frames-interp", & do_debug_frames_interp, 1 },
5926 { "info", & do_debug_info, 1 },
5927 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5928 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5929 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5930 { "loc", & do_debug_loc, 1 },
5931 { "macro", & do_debug_macinfo, 1 },
5932 { "pubnames", & do_debug_pubnames, 1 },
5933 { "pubtypes", & do_debug_pubtypes, 1 },
5934 /* This entry is for compatability
5935 with earlier versions of readelf. */
5936 { "ranges", & do_debug_aranges, 1 },
5937 { "str", & do_debug_str, 1 },
5938 /* The special .gdb_index section. */
5939 { "gdb_index", & do_gdb_index, 1 },
5940 /* These trace_* sections are used by Itanium VMS. */
5941 { "trace_abbrev", & do_trace_abbrevs, 1 },
5942 { "trace_aranges", & do_trace_aranges, 1 },
5943 { "trace_info", & do_trace_info, 1 },
5952 const debug_dump_long_opts * entry;
5954 for (entry = opts_table; entry->option; entry++)
5956 size_t len = strlen (entry->option);
5958 if (strncmp (p, entry->option, len) == 0
5959 && (p[len] == ',' || p[len] == '\0'))
5961 * entry->variable |= entry->val;
5963 /* The --debug-dump=frames-interp option also
5964 enables the --debug-dump=frames option. */
5965 if (do_debug_frames_interp)
5966 do_debug_frames = 1;
5973 if (entry->option == NULL)
5975 warn (_("Unrecognized debug option '%s'\n"), p);
5976 p = strchr (p, ',');
5987 dwarf_select_sections_by_letters (const char *letters)
5989 unsigned int lindex = 0;
5991 while (letters[lindex])
5992 switch (letters[lindex++])
5999 do_debug_abbrevs = 1;
6003 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
6007 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
6011 do_debug_pubnames = 1;
6015 do_debug_pubtypes = 1;
6019 do_debug_aranges = 1;
6023 do_debug_ranges = 1;
6027 do_debug_frames_interp = 1;
6029 do_debug_frames = 1;
6033 do_debug_macinfo = 1;
6045 warn (_("Unrecognized debug option '%s'\n"), optarg);
6051 dwarf_select_sections_all (void)
6054 do_debug_abbrevs = 1;
6055 do_debug_lines = FLAG_DEBUG_LINES_RAW;
6056 do_debug_pubnames = 1;
6057 do_debug_pubtypes = 1;
6058 do_debug_aranges = 1;
6059 do_debug_ranges = 1;
6060 do_debug_frames = 1;
6061 do_debug_macinfo = 1;
6066 do_trace_abbrevs = 1;
6067 do_trace_aranges = 1;
6070 struct dwarf_section_display debug_displays[] =
6072 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, abbrev },
6073 display_debug_abbrev, &do_debug_abbrevs, 0 },
6074 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, abbrev },
6075 display_debug_aranges, &do_debug_aranges, 1 },
6076 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, abbrev },
6077 display_debug_frames, &do_debug_frames, 1 },
6078 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev },
6079 display_debug_info, &do_debug_info, 1 },
6080 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, abbrev },
6081 display_debug_lines, &do_debug_lines, 1 },
6082 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, abbrev },
6083 display_debug_pubnames, &do_debug_pubnames, 0 },
6084 { { ".eh_frame", "", NULL, NULL, 0, 0, abbrev },
6085 display_debug_frames, &do_debug_frames, 1 },
6086 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, abbrev },
6087 display_debug_macinfo, &do_debug_macinfo, 0 },
6088 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, abbrev },
6089 display_debug_macro, &do_debug_macinfo, 1 },
6090 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, abbrev },
6091 display_debug_str, &do_debug_str, 0 },
6092 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, abbrev },
6093 display_debug_loc, &do_debug_loc, 1 },
6094 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, abbrev },
6095 display_debug_pubnames, &do_debug_pubtypes, 0 },
6096 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, abbrev },
6097 display_debug_ranges, &do_debug_ranges, 1 },
6098 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, abbrev },
6099 display_debug_not_supported, NULL, 0 },
6100 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, abbrev },
6101 display_debug_not_supported, NULL, 0 },
6102 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev },
6103 display_debug_types, &do_debug_info, 1 },
6104 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, abbrev },
6105 display_debug_not_supported, NULL, 0 },
6106 { { ".gdb_index", "", NULL, NULL, 0, 0, abbrev },
6107 display_gdb_index, &do_gdb_index, 0 },
6108 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev },
6109 display_trace_info, &do_trace_info, 1 },
6110 { { ".trace_abbrev", "", NULL, NULL, 0, 0, abbrev },
6111 display_debug_abbrev, &do_trace_abbrevs, 0 },
6112 { { ".trace_aranges", "", NULL, NULL, 0, 0, abbrev },
6113 display_debug_aranges, &do_trace_aranges, 0 },
6114 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6115 display_debug_info, &do_debug_info, 1 },
6116 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6117 display_debug_abbrev, &do_debug_abbrevs, 0 },
6118 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6119 display_debug_types, &do_debug_info, 1 },
6120 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6121 display_debug_lines, &do_debug_lines, 1 },
6122 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6123 display_debug_loc, &do_debug_loc, 1 },
6124 { { ".debug_macro.dwo", ".zdebug_macro.dwo",NULL, NULL, 0, 0, abbrev },
6125 display_debug_macro, &do_debug_macinfo, 1 },
6126 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo",NULL, NULL, 0, 0, abbrev },
6127 display_debug_macinfo, &do_debug_macinfo, 0 },
6128 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, str_dwo },
6129 display_debug_str, &do_debug_str, 1 },
6130 { { ".debug_str_offsets",".zdebug_str_offsets", NULL, NULL, 0, 0, abbrev },
6131 display_debug_str_offsets, NULL, 0 },
6132 { { ".debug_str_offsets.dwo",".zdebug_str_offsets.dwo", NULL, NULL, 0, 0,
6134 display_debug_str_offsets, NULL, 0 },
6135 { { ".debug_addr",".zdebug_addr", NULL, NULL, 0, 0, debug_addr },
6136 display_debug_addr, NULL, 1 },