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"
32 static const char *regname (unsigned int regno, int row);
34 static int have_frame_base;
35 static int need_base_address;
37 static unsigned int last_pointer_size = 0;
38 static int warned_about_missing_comp_units = FALSE;
40 static unsigned int num_debug_info_entries = 0;
41 static debug_info *debug_information = NULL;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
51 int do_debug_pubnames;
52 int do_debug_pubtypes;
56 int do_debug_frames_interp;
66 int dwarf_cutoff_level = -1;
67 unsigned long dwarf_start_die;
71 /* Values for do_debug_lines. */
72 #define FLAG_DEBUG_LINES_RAW 1
73 #define FLAG_DEBUG_LINES_DECODED 2
76 size_of_encoded_value (int encoding)
78 switch (encoding & 0x7)
81 case 0: return eh_addr_size;
89 get_encoded_value (unsigned char *data,
91 struct dwarf_section *section)
93 int size = size_of_encoded_value (encoding);
96 if (encoding & DW_EH_PE_signed)
97 val = byte_get_signed (data, size);
99 val = byte_get (data, size);
101 if ((encoding & 0x70) == DW_EH_PE_pcrel)
102 val += section->address + (data - section->start);
106 /* Print a dwarf_vma value (typically an address, offset or length) in
107 hexadecimal format, followed by a space. The length of the value (and
108 hence the precision displayed) is determined by the byte_size parameter. */
111 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
113 static char buff[18];
116 /* Printf does not have a way of specifiying a maximum field width for an
117 integer value, so we print the full value into a buffer and then select
118 the precision we need. */
119 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
121 snprintf (buff, sizeof (buff), "%16.16llx ", val);
123 snprintf (buff, sizeof (buff), "%016I64x ", val);
126 snprintf (buff, sizeof (buff), "%16.16lx ", val);
131 if (byte_size > 0 && byte_size <= 8)
132 offset = 16 - 2 * byte_size;
134 error (_("Wrong size in print_dwarf_vma"));
137 fputs (buff + offset, stdout);
140 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
142 #define DWARF_VMA_FMT "ll"
144 #define DWARF_VMA_FMT "I64"
147 #define DWARF_VMA_FMT "l"
151 dwarf_vmatoa (const char *fmtch, dwarf_vma value)
153 /* As dwarf_vmatoa is used more then once in a printf call
154 for output, we are cycling through an fixed array of pointers
155 for return address. */
156 static int buf_pos = 0;
157 static struct dwarf_vmatoa_buf
164 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
166 ret = buf[buf_pos++].place;
167 buf_pos %= ARRAY_SIZE (buf);
169 snprintf (ret, sizeof (buf[0].place), fmt, value);
174 /* Format a 64-bit value, given as two 32-bit values, in hex.
175 For reentrancy, this uses a buffer provided by the caller. */
178 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
179 unsigned int buf_len)
184 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
187 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
188 snprintf (buf + len, buf_len - len,
189 "%08" DWARF_VMA_FMT "x", lvalue);
196 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
198 dwarf_vma result = 0;
199 unsigned int num_read = 0;
200 unsigned int shift = 0;
208 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
215 if (length_return != NULL)
216 *length_return = num_read;
218 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
219 result |= -1L << shift;
224 /* Create a signed version to avoid painful typecasts. */
225 static dwarf_signed_vma
226 read_sleb128 (unsigned char *data, unsigned int *length_return)
228 return (dwarf_signed_vma) read_leb128 (data, length_return, 1);
231 typedef struct State_Machine_Registers
239 unsigned char op_index;
240 unsigned char end_sequence;
241 /* This variable hold the number of the last entry seen
242 in the File Table. */
243 unsigned int last_file_entry;
246 static SMR state_machine_regs;
249 reset_state_machine (int is_stmt)
251 state_machine_regs.address = 0;
252 state_machine_regs.op_index = 0;
253 state_machine_regs.file = 1;
254 state_machine_regs.line = 1;
255 state_machine_regs.column = 0;
256 state_machine_regs.is_stmt = is_stmt;
257 state_machine_regs.basic_block = 0;
258 state_machine_regs.end_sequence = 0;
259 state_machine_regs.last_file_entry = 0;
262 /* Handled an extend line op.
263 Returns the number of bytes read. */
266 process_extended_line_op (unsigned char *data, int is_stmt)
268 unsigned char op_code;
269 unsigned int bytes_read;
273 unsigned char *orig_data = data;
275 len = read_leb128 (data, & bytes_read, 0);
280 warn (_("badly formed extended line op encountered!\n"));
287 printf (_(" Extended opcode %d: "), op_code);
291 case DW_LNE_end_sequence:
292 printf (_("End of Sequence\n\n"));
293 reset_state_machine (is_stmt);
296 case DW_LNE_set_address:
297 adr = byte_get (data, len - bytes_read - 1);
298 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
299 state_machine_regs.address = adr;
300 state_machine_regs.op_index = 0;
303 case DW_LNE_define_file:
304 printf (_("define new File Table entry\n"));
305 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
307 printf (" %d\t", ++state_machine_regs.last_file_entry);
309 data += strlen ((char *) data) + 1;
310 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
312 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
314 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
317 if ((unsigned int) (data - orig_data) != len)
318 printf (_(" [Bad opcode length]"));
322 case DW_LNE_set_discriminator:
323 printf (_("set Discriminator to %s\n"),
324 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
328 case DW_LNE_HP_negate_is_UV_update:
329 printf ("DW_LNE_HP_negate_is_UV_update\n");
331 case DW_LNE_HP_push_context:
332 printf ("DW_LNE_HP_push_context\n");
334 case DW_LNE_HP_pop_context:
335 printf ("DW_LNE_HP_pop_context\n");
337 case DW_LNE_HP_set_file_line_column:
338 printf ("DW_LNE_HP_set_file_line_column\n");
340 case DW_LNE_HP_set_routine_name:
341 printf ("DW_LNE_HP_set_routine_name\n");
343 case DW_LNE_HP_set_sequence:
344 printf ("DW_LNE_HP_set_sequence\n");
346 case DW_LNE_HP_negate_post_semantics:
347 printf ("DW_LNE_HP_negate_post_semantics\n");
349 case DW_LNE_HP_negate_function_exit:
350 printf ("DW_LNE_HP_negate_function_exit\n");
352 case DW_LNE_HP_negate_front_end_logical:
353 printf ("DW_LNE_HP_negate_front_end_logical\n");
355 case DW_LNE_HP_define_proc:
356 printf ("DW_LNE_HP_define_proc\n");
358 case DW_LNE_HP_source_file_correlation:
360 unsigned char *edata = data + len - bytes_read - 1;
362 printf ("DW_LNE_HP_source_file_correlation\n");
368 opc = read_leb128 (data, & bytes_read, 0);
373 case DW_LNE_HP_SFC_formfeed:
374 printf (" DW_LNE_HP_SFC_formfeed\n");
376 case DW_LNE_HP_SFC_set_listing_line:
377 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
379 read_leb128 (data, & bytes_read, 0)));
382 case DW_LNE_HP_SFC_associate:
383 printf (" DW_LNE_HP_SFC_associate ");
386 read_leb128 (data, & bytes_read, 0)));
390 read_leb128 (data, & bytes_read, 0)));
394 read_leb128 (data, & bytes_read, 0)));
398 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
408 unsigned int rlen = len - bytes_read - 1;
410 if (op_code >= DW_LNE_lo_user
411 /* The test against DW_LNW_hi_user is redundant due to
412 the limited range of the unsigned char data type used
414 /*&& op_code <= DW_LNE_hi_user*/)
415 printf (_("user defined: "));
417 printf (_("UNKNOWN: "));
418 printf (_("length %d ["), rlen);
420 printf (" %02x", *data++);
430 fetch_indirect_string (dwarf_vma offset)
432 struct dwarf_section *section = &debug_displays [str].section;
434 if (section->start == NULL)
435 return _("<no .debug_str section>");
437 /* DWARF sections under Mach-O have non-zero addresses. */
438 offset -= section->address;
439 if (offset > section->size)
441 warn (_("DW_FORM_strp offset too big: %s\n"),
442 dwarf_vmatoa ("x", offset));
443 return _("<offset is too big>");
446 return (const char *) section->start + offset;
450 fetch_indexed_string (dwarf_vma idx, dwarf_vma offset_size, int dwo)
452 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
453 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
454 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
455 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
456 dwarf_vma index_offset = idx * offset_size;
457 dwarf_vma str_offset;
459 if (index_section->start == NULL)
460 return (dwo ? _("<no .debug_str_offsets.dwo section>")
461 : _("<no .debug_str_offsets section>"));
463 /* DWARF sections under Mach-O have non-zero addresses. */
464 index_offset -= index_section->address;
465 if (index_offset > index_section->size)
467 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
468 dwarf_vmatoa ("x", index_offset));
469 return _("<index offset is too big>");
472 if (str_section->start == NULL)
473 return (dwo ? _("<no .debug_str.dwo section>")
474 : _("<no .debug_str section>"));
476 str_offset = byte_get (index_section->start + index_offset, offset_size);
477 str_offset -= str_section->address;
478 if (str_offset > str_section->size)
480 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
481 dwarf_vmatoa ("x", str_offset));
482 return _("<indirect index offset is too big>");
485 return (const char *) str_section->start + str_offset;
489 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
491 struct dwarf_section *section = &debug_displays [debug_addr].section;
493 if (section->start == NULL)
494 return (_("<no .debug_addr section>"));
496 if (offset + bytes > section->size)
498 warn (_("Offset into section %s too big: %s\n"),
499 section->name, dwarf_vmatoa ("x", offset));
500 return "<offset too big>";
503 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
507 /* FIXME: There are better and more efficient ways to handle
508 these structures. For now though, I just want something that
509 is simple to implement. */
510 typedef struct abbrev_attr
512 unsigned long attribute;
514 struct abbrev_attr *next;
518 typedef struct abbrev_entry
523 struct abbrev_attr *first_attr;
524 struct abbrev_attr *last_attr;
525 struct abbrev_entry *next;
529 static abbrev_entry *first_abbrev = NULL;
530 static abbrev_entry *last_abbrev = NULL;
537 for (abbrv = first_abbrev; abbrv;)
539 abbrev_entry *next_abbrev = abbrv->next;
542 for (attr = abbrv->first_attr; attr;)
544 abbrev_attr *next_attr = attr->next;
554 last_abbrev = first_abbrev = NULL;
558 add_abbrev (unsigned long number, unsigned long tag, int children)
562 entry = (abbrev_entry *) malloc (sizeof (*entry));
567 entry->entry = number;
569 entry->children = children;
570 entry->first_attr = NULL;
571 entry->last_attr = NULL;
574 if (first_abbrev == NULL)
575 first_abbrev = entry;
577 last_abbrev->next = entry;
583 add_abbrev_attr (unsigned long attribute, unsigned long form)
587 attr = (abbrev_attr *) malloc (sizeof (*attr));
592 attr->attribute = attribute;
596 if (last_abbrev->first_attr == NULL)
597 last_abbrev->first_attr = attr;
599 last_abbrev->last_attr->next = attr;
601 last_abbrev->last_attr = attr;
604 /* Processes the (partial) contents of a .debug_abbrev section.
605 Returns NULL if the end of the section was encountered.
606 Returns the address after the last byte read if the end of
607 an abbreviation set was found. */
609 static unsigned char *
610 process_abbrev_section (unsigned char *start, unsigned char *end)
612 if (first_abbrev != NULL)
617 unsigned int bytes_read;
620 unsigned long attribute;
623 entry = read_leb128 (start, & bytes_read, 0);
626 /* A single zero is supposed to end the section according
627 to the standard. If there's more, then signal that to
630 return start == end ? NULL : start;
632 tag = read_leb128 (start, & bytes_read, 0);
637 add_abbrev (entry, tag, children);
643 attribute = read_leb128 (start, & bytes_read, 0);
646 form = read_leb128 (start, & bytes_read, 0);
650 add_abbrev_attr (attribute, form);
652 while (attribute != 0);
659 get_TAG_name (unsigned long tag)
661 const char *name = get_DW_TAG_name ((unsigned int)tag);
665 static char buffer[100];
667 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
675 get_FORM_name (unsigned long form)
677 const char *name = get_DW_FORM_name (form);
681 static char buffer[100];
683 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
690 static unsigned char *
691 display_block (unsigned char *data, dwarf_vma length)
693 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
696 printf ("%lx ", (unsigned long) byte_get (data++, 1));
702 decode_location_expression (unsigned char * data,
703 unsigned int pointer_size,
704 unsigned int offset_size,
708 struct dwarf_section * section)
711 unsigned int bytes_read;
713 unsigned char *end = data + length;
714 int need_frame_base = 0;
723 printf ("DW_OP_addr: %s",
724 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
725 data += pointer_size;
728 printf ("DW_OP_deref");
731 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
734 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
737 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
741 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
745 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
749 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
753 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
754 (unsigned long) byte_get (data + 4, 4));
758 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
759 (long) byte_get (data + 4, 4));
763 printf ("DW_OP_constu: %s",
764 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
768 printf ("DW_OP_consts: %s",
769 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
773 printf ("DW_OP_dup");
776 printf ("DW_OP_drop");
779 printf ("DW_OP_over");
782 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
785 printf ("DW_OP_swap");
788 printf ("DW_OP_rot");
791 printf ("DW_OP_xderef");
794 printf ("DW_OP_abs");
797 printf ("DW_OP_and");
800 printf ("DW_OP_div");
803 printf ("DW_OP_minus");
806 printf ("DW_OP_mod");
809 printf ("DW_OP_mul");
812 printf ("DW_OP_neg");
815 printf ("DW_OP_not");
821 printf ("DW_OP_plus");
823 case DW_OP_plus_uconst:
824 printf ("DW_OP_plus_uconst: %s",
825 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
829 printf ("DW_OP_shl");
832 printf ("DW_OP_shr");
835 printf ("DW_OP_shra");
838 printf ("DW_OP_xor");
841 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
863 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
899 printf ("DW_OP_lit%d", op - DW_OP_lit0);
934 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
935 regname (op - DW_OP_reg0, 1));
970 printf ("DW_OP_breg%d (%s): %s",
972 regname (op - DW_OP_breg0, 1),
973 dwarf_vmatoa ("d", (dwarf_signed_vma)
974 read_leb128 (data, &bytes_read, 1)));
979 uvalue = read_leb128 (data, &bytes_read, 0);
981 printf ("DW_OP_regx: %s (%s)",
982 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
986 printf ("DW_OP_fbreg: %s",
987 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
991 uvalue = read_leb128 (data, &bytes_read, 0);
993 printf ("DW_OP_bregx: %s (%s) %s",
994 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
995 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
999 printf ("DW_OP_piece: %s",
1000 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1003 case DW_OP_deref_size:
1004 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
1006 case DW_OP_xderef_size:
1007 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
1010 printf ("DW_OP_nop");
1013 /* DWARF 3 extensions. */
1014 case DW_OP_push_object_address:
1015 printf ("DW_OP_push_object_address");
1018 /* XXX: Strictly speaking for 64-bit DWARF3 files
1019 this ought to be an 8-byte wide computation. */
1020 printf ("DW_OP_call2: <0x%s>",
1021 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2)
1026 /* XXX: Strictly speaking for 64-bit DWARF3 files
1027 this ought to be an 8-byte wide computation. */
1028 printf ("DW_OP_call4: <0x%s>",
1029 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4)
1033 case DW_OP_call_ref:
1034 /* XXX: Strictly speaking for 64-bit DWARF3 files
1035 this ought to be an 8-byte wide computation. */
1036 if (dwarf_version == -1)
1038 printf (_("(DW_OP_call_ref in frame info)"));
1039 /* No way to tell where the next op is, so just bail. */
1040 return need_frame_base;
1042 if (dwarf_version == 2)
1044 printf ("DW_OP_call_ref: <0x%s>",
1045 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
1046 data += pointer_size;
1050 printf ("DW_OP_call_ref: <0x%s>",
1051 dwarf_vmatoa ("x", byte_get (data, offset_size)));
1052 data += offset_size;
1055 case DW_OP_form_tls_address:
1056 printf ("DW_OP_form_tls_address");
1058 case DW_OP_call_frame_cfa:
1059 printf ("DW_OP_call_frame_cfa");
1061 case DW_OP_bit_piece:
1062 printf ("DW_OP_bit_piece: ");
1063 printf (_("size: %s "),
1064 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1066 printf (_("offset: %s "),
1067 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1071 /* DWARF 4 extensions. */
1072 case DW_OP_stack_value:
1073 printf ("DW_OP_stack_value");
1076 case DW_OP_implicit_value:
1077 printf ("DW_OP_implicit_value");
1078 uvalue = read_leb128 (data, &bytes_read, 0);
1080 display_block (data, uvalue);
1084 /* GNU extensions. */
1085 case DW_OP_GNU_push_tls_address:
1086 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1088 case DW_OP_GNU_uninit:
1089 printf ("DW_OP_GNU_uninit");
1090 /* FIXME: Is there data associated with this OP ? */
1092 case DW_OP_GNU_encoded_addr:
1098 addr = get_encoded_value (data, encoding, section);
1099 data += size_of_encoded_value (encoding);
1101 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1102 print_dwarf_vma (addr, pointer_size);
1105 case DW_OP_GNU_implicit_pointer:
1106 /* XXX: Strictly speaking for 64-bit DWARF3 files
1107 this ought to be an 8-byte wide computation. */
1108 if (dwarf_version == -1)
1110 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1111 /* No way to tell where the next op is, so just bail. */
1112 return need_frame_base;
1114 if (dwarf_version == 2)
1116 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1117 dwarf_vmatoa ("x", byte_get (data, pointer_size)),
1118 dwarf_vmatoa ("d", read_sleb128 (data + pointer_size,
1120 data += pointer_size + bytes_read;
1124 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1125 dwarf_vmatoa ("x", byte_get (data, offset_size)),
1126 dwarf_vmatoa ("d", read_sleb128 (data + offset_size,
1128 data += offset_size + bytes_read;
1131 case DW_OP_GNU_entry_value:
1132 uvalue = read_leb128 (data, &bytes_read, 0);
1134 printf ("DW_OP_GNU_entry_value: (");
1135 if (decode_location_expression (data, pointer_size, offset_size,
1136 dwarf_version, uvalue,
1137 cu_offset, section))
1138 need_frame_base = 1;
1142 case DW_OP_GNU_const_type:
1143 uvalue = read_leb128 (data, &bytes_read, 0);
1145 printf ("DW_OP_GNU_const_type: <0x%s> ",
1146 dwarf_vmatoa ("x", cu_offset + uvalue));
1147 uvalue = byte_get (data++, 1);
1148 display_block (data, uvalue);
1151 case DW_OP_GNU_regval_type:
1152 uvalue = read_leb128 (data, &bytes_read, 0);
1154 printf ("DW_OP_GNU_regval_type: %s (%s)",
1155 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1156 uvalue = read_leb128 (data, &bytes_read, 0);
1158 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1160 case DW_OP_GNU_deref_type:
1161 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data++, 1));
1162 uvalue = read_leb128 (data, &bytes_read, 0);
1164 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1166 case DW_OP_GNU_convert:
1167 uvalue = read_leb128 (data, &bytes_read, 0);
1169 printf ("DW_OP_GNU_convert <0x%s>",
1170 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1172 case DW_OP_GNU_reinterpret:
1173 uvalue = read_leb128 (data, &bytes_read, 0);
1175 printf ("DW_OP_GNU_reinterpret <0x%s>",
1176 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1178 case DW_OP_GNU_parameter_ref:
1179 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1180 dwarf_vmatoa ("x", cu_offset + byte_get (data, 4)));
1183 case DW_OP_GNU_addr_index:
1184 uvalue = read_leb128 (data, &bytes_read, 0);
1186 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1189 /* HP extensions. */
1190 case DW_OP_HP_is_value:
1191 printf ("DW_OP_HP_is_value");
1192 /* FIXME: Is there data associated with this OP ? */
1194 case DW_OP_HP_fltconst4:
1195 printf ("DW_OP_HP_fltconst4");
1196 /* FIXME: Is there data associated with this OP ? */
1198 case DW_OP_HP_fltconst8:
1199 printf ("DW_OP_HP_fltconst8");
1200 /* FIXME: Is there data associated with this OP ? */
1202 case DW_OP_HP_mod_range:
1203 printf ("DW_OP_HP_mod_range");
1204 /* FIXME: Is there data associated with this OP ? */
1206 case DW_OP_HP_unmod_range:
1207 printf ("DW_OP_HP_unmod_range");
1208 /* FIXME: Is there data associated with this OP ? */
1211 printf ("DW_OP_HP_tls");
1212 /* FIXME: Is there data associated with this OP ? */
1215 /* PGI (STMicroelectronics) extensions. */
1216 case DW_OP_PGI_omp_thread_num:
1217 /* Pushes the thread number for the current thread as it would be
1218 returned by the standard OpenMP library function:
1219 omp_get_thread_num(). The "current thread" is the thread for
1220 which the expression is being evaluated. */
1221 printf ("DW_OP_PGI_omp_thread_num");
1225 if (op >= DW_OP_lo_user
1226 && op <= DW_OP_hi_user)
1227 printf (_("(User defined location op)"));
1229 printf (_("(Unknown location op)"));
1230 /* No way to tell where the next op is, so just bail. */
1231 return need_frame_base;
1234 /* Separate the ops. */
1239 return need_frame_base;
1242 static unsigned char *
1243 read_and_display_attr_value (unsigned long attribute,
1245 unsigned char * data,
1246 dwarf_vma cu_offset,
1247 dwarf_vma pointer_size,
1248 dwarf_vma offset_size,
1250 debug_info * debug_info_p,
1252 struct dwarf_section * section)
1254 dwarf_vma uvalue = 0;
1255 unsigned char *block_start = NULL;
1256 unsigned char * orig_data = data;
1257 unsigned int bytes_read;
1264 case DW_FORM_ref_addr:
1265 if (dwarf_version == 2)
1267 uvalue = byte_get (data, pointer_size);
1268 data += pointer_size;
1270 else if (dwarf_version == 3 || dwarf_version == 4)
1272 uvalue = byte_get (data, offset_size);
1273 data += offset_size;
1276 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1281 uvalue = byte_get (data, pointer_size);
1282 data += pointer_size;
1286 case DW_FORM_sec_offset:
1287 uvalue = byte_get (data, offset_size);
1288 data += offset_size;
1291 case DW_FORM_flag_present:
1298 uvalue = byte_get (data++, 1);
1303 uvalue = byte_get (data, 2);
1309 uvalue = byte_get (data, 4);
1314 uvalue = read_leb128 (data, & bytes_read, 1);
1318 case DW_FORM_GNU_str_index:
1319 uvalue = read_leb128 (data, & bytes_read, 0);
1323 case DW_FORM_ref_udata:
1325 uvalue = read_leb128 (data, & bytes_read, 0);
1329 case DW_FORM_indirect:
1330 form = read_leb128 (data, & bytes_read, 0);
1333 printf (" %s", get_FORM_name (form));
1334 return read_and_display_attr_value (attribute, form, data,
1335 cu_offset, pointer_size,
1336 offset_size, dwarf_version,
1337 debug_info_p, do_loc,
1339 case DW_FORM_GNU_addr_index:
1340 uvalue = read_leb128 (data, & bytes_read, 0);
1347 case DW_FORM_ref_addr:
1349 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1355 case DW_FORM_ref_udata:
1357 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1362 case DW_FORM_sec_offset:
1364 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1367 case DW_FORM_flag_present:
1374 printf (" %s", dwarf_vmatoa ("d", uvalue));
1381 dwarf_vma high_bits;
1384 byte_get_64 (data, &high_bits, &uvalue);
1386 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1388 if ((do_loc || do_debug_loc || do_debug_ranges)
1389 && num_debug_info_entries == 0)
1391 if (sizeof (uvalue) == 8)
1392 uvalue = byte_get (data, 8);
1394 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1399 case DW_FORM_string:
1401 printf (" %s", data);
1402 data += strlen ((char *) data) + 1;
1406 case DW_FORM_exprloc:
1407 uvalue = read_leb128 (data, & bytes_read, 0);
1408 block_start = data + bytes_read;
1410 data = block_start + uvalue;
1412 data = display_block (block_start, uvalue);
1415 case DW_FORM_block1:
1416 uvalue = byte_get (data, 1);
1417 block_start = data + 1;
1419 data = block_start + uvalue;
1421 data = display_block (block_start, uvalue);
1424 case DW_FORM_block2:
1425 uvalue = byte_get (data, 2);
1426 block_start = data + 2;
1428 data = block_start + uvalue;
1430 data = display_block (block_start, uvalue);
1433 case DW_FORM_block4:
1434 uvalue = byte_get (data, 4);
1435 block_start = data + 4;
1437 data = block_start + uvalue;
1439 data = display_block (block_start, uvalue);
1444 printf (_(" (indirect string, offset: 0x%s): %s"),
1445 dwarf_vmatoa ("x", uvalue),
1446 fetch_indirect_string (uvalue));
1449 case DW_FORM_GNU_str_index:
1452 const char *suffix = strrchr (section->name, '.');
1453 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1455 printf (_(" (indexed string: 0x%s): %s"),
1456 dwarf_vmatoa ("x", uvalue),
1457 fetch_indexed_string (uvalue, offset_size, dwo));
1461 case DW_FORM_indirect:
1462 /* Handled above. */
1465 case DW_FORM_ref_sig8:
1468 dwarf_vma high_bits;
1471 byte_get_64 (data, &high_bits, &uvalue);
1472 printf (" signature: 0x%s",
1473 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1478 case DW_FORM_GNU_addr_index:
1480 printf (_(" (addr_index: 0x%s): %s"),
1481 dwarf_vmatoa ("x", uvalue),
1482 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1486 warn (_("Unrecognized form: %lu\n"), form);
1490 if ((do_loc || do_debug_loc || do_debug_ranges)
1491 && num_debug_info_entries == 0
1492 && debug_info_p != NULL)
1496 case DW_AT_frame_base:
1497 have_frame_base = 1;
1498 case DW_AT_location:
1499 case DW_AT_string_length:
1500 case DW_AT_return_addr:
1501 case DW_AT_data_member_location:
1502 case DW_AT_vtable_elem_location:
1504 case DW_AT_static_link:
1505 case DW_AT_use_location:
1506 case DW_AT_GNU_call_site_value:
1507 case DW_AT_GNU_call_site_data_value:
1508 case DW_AT_GNU_call_site_target:
1509 case DW_AT_GNU_call_site_target_clobbered:
1510 if ((dwarf_version < 4
1511 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1512 || form == DW_FORM_sec_offset)
1514 /* Process location list. */
1515 unsigned int lmax = debug_info_p->max_loc_offsets;
1516 unsigned int num = debug_info_p->num_loc_offsets;
1518 if (lmax == 0 || num >= lmax)
1521 debug_info_p->loc_offsets = (dwarf_vma *)
1522 xcrealloc (debug_info_p->loc_offsets,
1523 lmax, sizeof (*debug_info_p->loc_offsets));
1524 debug_info_p->have_frame_base = (int *)
1525 xcrealloc (debug_info_p->have_frame_base,
1526 lmax, sizeof (*debug_info_p->have_frame_base));
1527 debug_info_p->max_loc_offsets = lmax;
1529 debug_info_p->loc_offsets [num] = uvalue;
1530 debug_info_p->have_frame_base [num] = have_frame_base;
1531 debug_info_p->num_loc_offsets++;
1536 if (need_base_address)
1537 debug_info_p->base_address = uvalue;
1540 case DW_AT_GNU_addr_base:
1541 debug_info_p->addr_base = uvalue;
1544 case DW_AT_GNU_ranges_base:
1545 debug_info_p->ranges_base = uvalue;
1549 if ((dwarf_version < 4
1550 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1551 || form == DW_FORM_sec_offset)
1553 /* Process range list. */
1554 unsigned int lmax = debug_info_p->max_range_lists;
1555 unsigned int num = debug_info_p->num_range_lists;
1557 if (lmax == 0 || num >= lmax)
1560 debug_info_p->range_lists = (dwarf_vma *)
1561 xcrealloc (debug_info_p->range_lists,
1562 lmax, sizeof (*debug_info_p->range_lists));
1563 debug_info_p->max_range_lists = lmax;
1565 debug_info_p->range_lists [num] = uvalue;
1566 debug_info_p->num_range_lists++;
1575 if (do_loc || attribute == 0)
1578 /* For some attributes we can display further information. */
1586 case DW_INL_not_inlined:
1587 printf (_("(not inlined)"));
1589 case DW_INL_inlined:
1590 printf (_("(inlined)"));
1592 case DW_INL_declared_not_inlined:
1593 printf (_("(declared as inline but ignored)"));
1595 case DW_INL_declared_inlined:
1596 printf (_("(declared as inline and inlined)"));
1599 printf (_(" (Unknown inline attribute value: %s)"),
1600 dwarf_vmatoa ("x", uvalue));
1605 case DW_AT_language:
1608 /* Ordered by the numeric value of these constants. */
1609 case DW_LANG_C89: printf ("(ANSI C)"); break;
1610 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1611 case DW_LANG_Ada83: printf ("(Ada)"); break;
1612 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1613 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1614 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1615 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1616 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1617 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1618 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1619 /* DWARF 2.1 values. */
1620 case DW_LANG_Java: printf ("(Java)"); break;
1621 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1622 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1623 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1624 /* DWARF 3 values. */
1625 case DW_LANG_PLI: printf ("(PLI)"); break;
1626 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1627 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1628 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1629 case DW_LANG_D: printf ("(D)"); break;
1630 /* DWARF 4 values. */
1631 case DW_LANG_Python: printf ("(Python)"); break;
1632 /* DWARF 5 values. */
1633 case DW_LANG_Go: printf ("(Go)"); break;
1634 /* MIPS extension. */
1635 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1636 /* UPC extension. */
1637 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1639 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1640 printf (_("(implementation defined: %s)"),
1641 dwarf_vmatoa ("x", uvalue));
1643 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1648 case DW_AT_encoding:
1651 case DW_ATE_void: printf ("(void)"); break;
1652 case DW_ATE_address: printf ("(machine address)"); break;
1653 case DW_ATE_boolean: printf ("(boolean)"); break;
1654 case DW_ATE_complex_float: printf ("(complex float)"); break;
1655 case DW_ATE_float: printf ("(float)"); break;
1656 case DW_ATE_signed: printf ("(signed)"); break;
1657 case DW_ATE_signed_char: printf ("(signed char)"); break;
1658 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1659 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1660 /* DWARF 2.1 values: */
1661 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1662 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1663 /* DWARF 3 values: */
1664 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1665 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1666 case DW_ATE_edited: printf ("(edited)"); break;
1667 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1668 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1669 /* HP extensions: */
1670 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1671 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1672 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1673 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1674 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1675 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1676 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1679 if (uvalue >= DW_ATE_lo_user
1680 && uvalue <= DW_ATE_hi_user)
1681 printf (_("(user defined type)"));
1683 printf (_("(unknown type)"));
1688 case DW_AT_accessibility:
1691 case DW_ACCESS_public: printf ("(public)"); break;
1692 case DW_ACCESS_protected: printf ("(protected)"); break;
1693 case DW_ACCESS_private: printf ("(private)"); break;
1695 printf (_("(unknown accessibility)"));
1700 case DW_AT_visibility:
1703 case DW_VIS_local: printf ("(local)"); break;
1704 case DW_VIS_exported: printf ("(exported)"); break;
1705 case DW_VIS_qualified: printf ("(qualified)"); break;
1706 default: printf (_("(unknown visibility)")); break;
1710 case DW_AT_virtuality:
1713 case DW_VIRTUALITY_none: printf ("(none)"); break;
1714 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1715 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1716 default: printf (_("(unknown virtuality)")); break;
1720 case DW_AT_identifier_case:
1723 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1724 case DW_ID_up_case: printf ("(up_case)"); break;
1725 case DW_ID_down_case: printf ("(down_case)"); break;
1726 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1727 default: printf (_("(unknown case)")); break;
1731 case DW_AT_calling_convention:
1734 case DW_CC_normal: printf ("(normal)"); break;
1735 case DW_CC_program: printf ("(program)"); break;
1736 case DW_CC_nocall: printf ("(nocall)"); break;
1738 if (uvalue >= DW_CC_lo_user
1739 && uvalue <= DW_CC_hi_user)
1740 printf (_("(user defined)"));
1742 printf (_("(unknown convention)"));
1746 case DW_AT_ordering:
1749 case -1: printf (_("(undefined)")); break;
1750 case 0: printf ("(row major)"); break;
1751 case 1: printf ("(column major)"); break;
1755 case DW_AT_frame_base:
1756 have_frame_base = 1;
1757 case DW_AT_location:
1758 case DW_AT_string_length:
1759 case DW_AT_return_addr:
1760 case DW_AT_data_member_location:
1761 case DW_AT_vtable_elem_location:
1763 case DW_AT_static_link:
1764 case DW_AT_use_location:
1765 case DW_AT_GNU_call_site_value:
1766 case DW_AT_GNU_call_site_data_value:
1767 case DW_AT_GNU_call_site_target:
1768 case DW_AT_GNU_call_site_target_clobbered:
1769 if ((dwarf_version < 4
1770 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1771 || form == DW_FORM_sec_offset)
1772 printf (_("(location list)"));
1774 case DW_AT_allocated:
1775 case DW_AT_associated:
1776 case DW_AT_data_location:
1778 case DW_AT_upper_bound:
1779 case DW_AT_lower_bound:
1782 int need_frame_base;
1785 need_frame_base = decode_location_expression (block_start,
1790 cu_offset, section);
1792 if (need_frame_base && !have_frame_base)
1793 printf (_(" [without DW_AT_frame_base]"));
1799 if (form == DW_FORM_ref_sig8)
1802 if (form == DW_FORM_ref1
1803 || form == DW_FORM_ref2
1804 || form == DW_FORM_ref4
1805 || form == DW_FORM_ref_udata)
1806 uvalue += cu_offset;
1808 if (uvalue >= section->size)
1809 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1810 dwarf_vmatoa ("x", uvalue),
1811 (unsigned long) (orig_data - section->start));
1814 unsigned long abbrev_number;
1815 abbrev_entry * entry;
1817 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1819 printf (_("[Abbrev Number: %ld"), abbrev_number);
1820 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
1821 use different abbrev table, and we don't track .debug_info chunks
1823 if (form != DW_FORM_ref_addr)
1825 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1826 if (entry->entry == abbrev_number)
1829 printf (" (%s)", get_TAG_name (entry->tag));
1844 get_AT_name (unsigned long attribute)
1848 /* One value is shared by the MIPS and HP extensions: */
1849 if (attribute == DW_AT_MIPS_fde)
1850 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1852 name = get_DW_AT_name (attribute);
1856 static char buffer[100];
1858 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1866 static unsigned char *
1867 read_and_display_attr (unsigned long attribute,
1869 unsigned char * data,
1870 dwarf_vma cu_offset,
1871 dwarf_vma pointer_size,
1872 dwarf_vma offset_size,
1874 debug_info * debug_info_p,
1876 struct dwarf_section * section)
1879 printf (" %-18s:", get_AT_name (attribute));
1880 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1881 pointer_size, offset_size,
1882 dwarf_version, debug_info_p,
1890 /* Process the contents of a .debug_info section. If do_loc is non-zero
1891 then we are scanning for location lists and we do not want to display
1892 anything to the user. If do_types is non-zero, we are processing
1893 a .debug_types section instead of a .debug_info section. */
1896 process_debug_info (struct dwarf_section *section,
1898 enum dwarf_section_display_enum abbrev_sec,
1902 unsigned char *start = section->start;
1903 unsigned char *end = start + section->size;
1904 unsigned char *section_begin;
1906 unsigned int num_units = 0;
1908 if ((do_loc || do_debug_loc || do_debug_ranges)
1909 && num_debug_info_entries == 0
1914 /* First scan the section to get the number of comp units. */
1915 for (section_begin = start, num_units = 0; section_begin < end;
1918 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1919 will be the length. For a 64-bit DWARF section, it'll be
1920 the escape code 0xffffffff followed by an 8 byte length. */
1921 length = byte_get (section_begin, 4);
1923 if (length == 0xffffffff)
1925 length = byte_get (section_begin + 4, 8);
1926 section_begin += length + 12;
1928 else if (length >= 0xfffffff0 && length < 0xffffffff)
1930 warn (_("Reserved length value (0x%s) found in section %s\n"),
1931 dwarf_vmatoa ("x", length), section->name);
1935 section_begin += length + 4;
1937 /* Negative values are illegal, they may even cause infinite
1938 looping. This can happen if we can't accurately apply
1939 relocations to an object file. */
1940 if ((signed long) length <= 0)
1942 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
1943 dwarf_vmatoa ("x", length), section->name);
1950 error (_("No comp units in %s section ?"), section->name);
1954 /* Then allocate an array to hold the information. */
1955 debug_information = (debug_info *) cmalloc (num_units,
1956 sizeof (* debug_information));
1957 if (debug_information == NULL)
1959 error (_("Not enough memory for a debug info array of %u entries"),
1967 if (dwarf_start_die == 0)
1968 printf (_("Contents of the %s section:\n\n"), section->name);
1970 load_debug_section (str, file);
1971 load_debug_section (str_dwo, file);
1972 load_debug_section (str_index, file);
1973 load_debug_section (str_index_dwo, file);
1974 load_debug_section (debug_addr, file);
1977 load_debug_section (abbrev_sec, file);
1978 if (debug_displays [abbrev_sec].section.start == NULL)
1980 warn (_("Unable to locate %s section!\n"),
1981 debug_displays [abbrev_sec].section.name);
1985 for (section_begin = start, unit = 0; start < end; unit++)
1987 DWARF2_Internal_CompUnit compunit;
1988 unsigned char *hdrptr;
1989 unsigned char *tags;
1990 int level, last_level, saved_level;
1991 dwarf_vma cu_offset;
1993 int initial_length_size;
1994 dwarf_vma signature_high = 0;
1995 dwarf_vma signature_low = 0;
1996 dwarf_vma type_offset = 0;
2000 compunit.cu_length = byte_get (hdrptr, 4);
2003 if (compunit.cu_length == 0xffffffff)
2005 compunit.cu_length = byte_get (hdrptr, 8);
2008 initial_length_size = 12;
2013 initial_length_size = 4;
2016 compunit.cu_version = byte_get (hdrptr, 2);
2019 cu_offset = start - section_begin;
2021 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2022 hdrptr += offset_size;
2024 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2029 byte_get_64 (hdrptr, &signature_high, &signature_low);
2031 type_offset = byte_get (hdrptr, offset_size);
2032 hdrptr += offset_size;
2035 if ((do_loc || do_debug_loc || do_debug_ranges)
2036 && num_debug_info_entries == 0
2039 debug_information [unit].cu_offset = cu_offset;
2040 debug_information [unit].pointer_size
2041 = compunit.cu_pointer_size;
2042 debug_information [unit].offset_size = offset_size;
2043 debug_information [unit].dwarf_version = compunit.cu_version;
2044 debug_information [unit].base_address = 0;
2045 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2046 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2047 debug_information [unit].loc_offsets = NULL;
2048 debug_information [unit].have_frame_base = NULL;
2049 debug_information [unit].max_loc_offsets = 0;
2050 debug_information [unit].num_loc_offsets = 0;
2051 debug_information [unit].range_lists = NULL;
2052 debug_information [unit].max_range_lists= 0;
2053 debug_information [unit].num_range_lists = 0;
2056 if (!do_loc && dwarf_start_die == 0)
2058 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2059 dwarf_vmatoa ("x", cu_offset));
2060 printf (_(" Length: 0x%s (%s)\n"),
2061 dwarf_vmatoa ("x", compunit.cu_length),
2062 offset_size == 8 ? "64-bit" : "32-bit");
2063 printf (_(" Version: %d\n"), compunit.cu_version);
2064 printf (_(" Abbrev Offset: %s\n"),
2065 dwarf_vmatoa ("d", compunit.cu_abbrev_offset));
2066 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2071 printf (_(" Signature: 0x%s\n"),
2072 dwarf_vmatoa64 (signature_high, signature_low,
2073 buf, sizeof (buf)));
2074 printf (_(" Type Offset: 0x%s\n"),
2075 dwarf_vmatoa ("x", type_offset));
2079 if (cu_offset + compunit.cu_length + initial_length_size
2082 warn (_("Debug info is corrupted, length of CU at %s"
2083 " extends beyond end of section (length = %s)\n"),
2084 dwarf_vmatoa ("x", cu_offset),
2085 dwarf_vmatoa ("x", compunit.cu_length));
2089 start += compunit.cu_length + initial_length_size;
2091 if (compunit.cu_version != 2
2092 && compunit.cu_version != 3
2093 && compunit.cu_version != 4)
2095 warn (_("CU at offset %s contains corrupt or "
2096 "unsupported version number: %d.\n"),
2097 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2103 /* Process the abbrevs used by this compilation unit. DWARF
2104 sections under Mach-O have non-zero addresses. */
2105 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2106 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2107 (unsigned long) compunit.cu_abbrev_offset,
2108 (unsigned long) debug_displays [abbrev_sec].section.size);
2110 process_abbrev_section
2111 ((unsigned char *) debug_displays [abbrev_sec].section.start
2112 + compunit.cu_abbrev_offset,
2113 (unsigned char *) debug_displays [abbrev_sec].section.start
2114 + debug_displays [abbrev_sec].section.size);
2119 while (tags < start)
2121 unsigned int bytes_read;
2122 unsigned long abbrev_number;
2123 unsigned long die_offset;
2124 abbrev_entry *entry;
2126 int do_printing = 1;
2128 die_offset = tags - section_begin;
2130 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2133 /* A null DIE marks the end of a list of siblings or it may also be
2134 a section padding. */
2135 if (abbrev_number == 0)
2137 /* Check if it can be a section padding for the last CU. */
2138 if (level == 0 && start == end)
2142 for (chk = tags; chk < start; chk++)
2152 static unsigned num_bogus_warns = 0;
2154 if (num_bogus_warns < 3)
2156 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2157 die_offset, section->name);
2159 if (num_bogus_warns == 3)
2160 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2163 if (dwarf_start_die != 0 && level < saved_level)
2170 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2174 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2175 saved_level = level;
2176 do_printing = (dwarf_cutoff_level == -1
2177 || level < dwarf_cutoff_level);
2179 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2180 level, die_offset, abbrev_number);
2181 else if (dwarf_cutoff_level == -1
2182 || last_level < dwarf_cutoff_level)
2183 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2188 /* Scan through the abbreviation list until we reach the
2190 for (entry = first_abbrev;
2191 entry && entry->entry != abbrev_number;
2192 entry = entry->next)
2197 if (!do_loc && do_printing)
2202 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2203 die_offset, abbrev_number);
2207 if (!do_loc && do_printing)
2208 printf (" (%s)\n", get_TAG_name (entry->tag));
2213 need_base_address = 0;
2215 case DW_TAG_compile_unit:
2216 need_base_address = 1;
2218 case DW_TAG_entry_point:
2219 case DW_TAG_subprogram:
2220 need_base_address = 0;
2221 /* Assuming that there is no DW_AT_frame_base. */
2222 have_frame_base = 0;
2226 for (attr = entry->first_attr; attr; attr = attr->next)
2230 if (! do_loc && do_printing)
2231 /* Show the offset from where the tag was extracted. */
2232 printf (" <%lx>", (unsigned long)(tags - section_begin));
2234 arg = debug_information;
2235 if (debug_information)
2238 tags = read_and_display_attr (attr->attribute,
2241 compunit.cu_pointer_size,
2243 compunit.cu_version,
2245 do_loc || ! do_printing, section);
2248 if (entry->children)
2253 /* Set num_debug_info_entries here so that it can be used to check if
2254 we need to process .debug_loc and .debug_ranges sections. */
2255 if ((do_loc || do_debug_loc || do_debug_ranges)
2256 && num_debug_info_entries == 0
2258 num_debug_info_entries = num_units;
2266 /* Locate and scan the .debug_info section in the file and record the pointer
2267 sizes and offsets for the compilation units in it. Usually an executable
2268 will have just one pointer size, but this is not guaranteed, and so we try
2269 not to make any assumptions. Returns zero upon failure, or the number of
2270 compilation units upon success. */
2273 load_debug_info (void * file)
2275 /* Reset the last pointer size so that we can issue correct error
2276 messages if we are displaying the contents of more than one section. */
2277 last_pointer_size = 0;
2278 warned_about_missing_comp_units = FALSE;
2280 /* If we have already tried and failed to load the .debug_info
2281 section then do not bother to repear the task. */
2282 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2285 /* If we already have the information there is nothing else to do. */
2286 if (num_debug_info_entries > 0)
2287 return num_debug_info_entries;
2289 if (load_debug_section (info, file)
2290 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2291 return num_debug_info_entries;
2292 else if (load_debug_section (info_dwo, file)
2293 && process_debug_info (&debug_displays [info_dwo].section, file,
2295 return num_debug_info_entries;
2297 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2302 display_debug_lines_raw (struct dwarf_section *section,
2303 unsigned char *data,
2306 unsigned char *start = section->start;
2308 printf (_("Raw dump of debug contents of section %s:\n\n"),
2313 DWARF2_Internal_LineInfo linfo;
2314 unsigned char *standard_opcodes;
2315 unsigned char *end_of_sequence;
2316 unsigned char *hdrptr;
2317 unsigned long hdroff;
2318 int initial_length_size;
2323 hdroff = hdrptr - start;
2325 /* Check the length of the block. */
2326 linfo.li_length = byte_get (hdrptr, 4);
2329 if (linfo.li_length == 0xffffffff)
2331 /* This section is 64-bit DWARF 3. */
2332 linfo.li_length = byte_get (hdrptr, 8);
2335 initial_length_size = 12;
2340 initial_length_size = 4;
2343 if (linfo.li_length + initial_length_size > section->size)
2346 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2351 /* Check its version number. */
2352 linfo.li_version = byte_get (hdrptr, 2);
2354 if (linfo.li_version != 2
2355 && linfo.li_version != 3
2356 && linfo.li_version != 4)
2358 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2362 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2363 hdrptr += offset_size;
2364 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2366 if (linfo.li_version >= 4)
2368 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2370 if (linfo.li_max_ops_per_insn == 0)
2372 warn (_("Invalid maximum operations per insn.\n"));
2377 linfo.li_max_ops_per_insn = 1;
2378 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2380 linfo.li_line_base = byte_get (hdrptr, 1);
2382 linfo.li_line_range = byte_get (hdrptr, 1);
2384 linfo.li_opcode_base = byte_get (hdrptr, 1);
2387 /* Sign extend the line base field. */
2388 linfo.li_line_base <<= 24;
2389 linfo.li_line_base >>= 24;
2391 printf (_(" Offset: 0x%lx\n"), hdroff);
2392 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2393 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2394 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2395 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2396 if (linfo.li_version >= 4)
2397 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2398 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2399 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2400 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2401 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2403 end_of_sequence = data + linfo.li_length + initial_length_size;
2405 reset_state_machine (linfo.li_default_is_stmt);
2407 /* Display the contents of the Opcodes table. */
2408 standard_opcodes = hdrptr;
2410 printf (_("\n Opcodes:\n"));
2412 for (i = 1; i < linfo.li_opcode_base; i++)
2413 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2415 /* Display the contents of the Directory table. */
2416 data = standard_opcodes + linfo.li_opcode_base - 1;
2419 printf (_("\n The Directory Table is empty.\n"));
2422 printf (_("\n The Directory Table:\n"));
2426 printf (" %s\n", data);
2428 data += strlen ((char *) data) + 1;
2432 /* Skip the NUL at the end of the table. */
2435 /* Display the contents of the File Name table. */
2437 printf (_("\n The File Name Table is empty.\n"));
2440 printf (_("\n The File Name Table:\n"));
2441 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2445 unsigned char *name;
2446 unsigned int bytes_read;
2448 printf (" %d\t", ++state_machine_regs.last_file_entry);
2451 data += strlen ((char *) data) + 1;
2454 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2457 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2460 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2462 printf ("%s\n", name);
2466 /* Skip the NUL at the end of the table. */
2469 /* Now display the statements. */
2470 printf (_("\n Line Number Statements:\n"));
2472 while (data < end_of_sequence)
2474 unsigned char op_code;
2475 dwarf_signed_vma adv;
2477 unsigned int bytes_read;
2481 if (op_code >= linfo.li_opcode_base)
2483 op_code -= linfo.li_opcode_base;
2484 uladv = (op_code / linfo.li_line_range);
2485 if (linfo.li_max_ops_per_insn == 1)
2487 uladv *= linfo.li_min_insn_length;
2488 state_machine_regs.address += uladv;
2489 printf (_(" Special opcode %d: "
2490 "advance Address by %s to 0x%s"),
2491 op_code, dwarf_vmatoa ("u", uladv),
2492 dwarf_vmatoa ("x", state_machine_regs.address));
2496 state_machine_regs.address
2497 += ((state_machine_regs.op_index + uladv)
2498 / linfo.li_max_ops_per_insn)
2499 * linfo.li_min_insn_length;
2500 state_machine_regs.op_index
2501 = (state_machine_regs.op_index + uladv)
2502 % linfo.li_max_ops_per_insn;
2503 printf (_(" Special opcode %d: "
2504 "advance Address by %s to 0x%s[%d]"),
2505 op_code, dwarf_vmatoa ("u", uladv),
2506 dwarf_vmatoa ("x", state_machine_regs.address),
2507 state_machine_regs.op_index);
2509 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2510 state_machine_regs.line += adv;
2511 printf (_(" and Line by %s to %d\n"),
2512 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2514 else switch (op_code)
2516 case DW_LNS_extended_op:
2517 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2521 printf (_(" Copy\n"));
2524 case DW_LNS_advance_pc:
2525 uladv = read_leb128 (data, & bytes_read, 0);
2527 if (linfo.li_max_ops_per_insn == 1)
2529 uladv *= linfo.li_min_insn_length;
2530 state_machine_regs.address += uladv;
2531 printf (_(" Advance PC by %s to 0x%s\n"),
2532 dwarf_vmatoa ("u", uladv),
2533 dwarf_vmatoa ("x", state_machine_regs.address));
2537 state_machine_regs.address
2538 += ((state_machine_regs.op_index + uladv)
2539 / linfo.li_max_ops_per_insn)
2540 * linfo.li_min_insn_length;
2541 state_machine_regs.op_index
2542 = (state_machine_regs.op_index + uladv)
2543 % linfo.li_max_ops_per_insn;
2544 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2545 dwarf_vmatoa ("u", uladv),
2546 dwarf_vmatoa ("x", state_machine_regs.address),
2547 state_machine_regs.op_index);
2551 case DW_LNS_advance_line:
2552 adv = read_sleb128 (data, & bytes_read);
2554 state_machine_regs.line += adv;
2555 printf (_(" Advance Line by %s to %d\n"),
2556 dwarf_vmatoa ("d", adv),
2557 state_machine_regs.line);
2560 case DW_LNS_set_file:
2561 adv = read_leb128 (data, & bytes_read, 0);
2563 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2564 dwarf_vmatoa ("d", adv));
2565 state_machine_regs.file = adv;
2568 case DW_LNS_set_column:
2569 uladv = read_leb128 (data, & bytes_read, 0);
2571 printf (_(" Set column to %s\n"),
2572 dwarf_vmatoa ("u", uladv));
2573 state_machine_regs.column = uladv;
2576 case DW_LNS_negate_stmt:
2577 adv = state_machine_regs.is_stmt;
2579 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2580 state_machine_regs.is_stmt = adv;
2583 case DW_LNS_set_basic_block:
2584 printf (_(" Set basic block\n"));
2585 state_machine_regs.basic_block = 1;
2588 case DW_LNS_const_add_pc:
2589 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2590 if (linfo.li_max_ops_per_insn)
2592 uladv *= linfo.li_min_insn_length;
2593 state_machine_regs.address += uladv;
2594 printf (_(" Advance PC by constant %s to 0x%s\n"),
2595 dwarf_vmatoa ("u", uladv),
2596 dwarf_vmatoa ("x", state_machine_regs.address));
2600 state_machine_regs.address
2601 += ((state_machine_regs.op_index + uladv)
2602 / linfo.li_max_ops_per_insn)
2603 * linfo.li_min_insn_length;
2604 state_machine_regs.op_index
2605 = (state_machine_regs.op_index + uladv)
2606 % linfo.li_max_ops_per_insn;
2607 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2608 dwarf_vmatoa ("u", uladv),
2609 dwarf_vmatoa ("x", state_machine_regs.address),
2610 state_machine_regs.op_index);
2614 case DW_LNS_fixed_advance_pc:
2615 uladv = byte_get (data, 2);
2617 state_machine_regs.address += uladv;
2618 state_machine_regs.op_index = 0;
2619 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2620 dwarf_vmatoa ("u", uladv),
2621 dwarf_vmatoa ("x", state_machine_regs.address));
2624 case DW_LNS_set_prologue_end:
2625 printf (_(" Set prologue_end to true\n"));
2628 case DW_LNS_set_epilogue_begin:
2629 printf (_(" Set epilogue_begin to true\n"));
2632 case DW_LNS_set_isa:
2633 uladv = read_leb128 (data, & bytes_read, 0);
2635 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2639 printf (_(" Unknown opcode %d with operands: "), op_code);
2641 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2643 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2645 i == 1 ? "" : ", ");
2660 unsigned char *name;
2661 unsigned int directory_index;
2662 unsigned int modification_date;
2663 unsigned int length;
2666 /* Output a decoded representation of the .debug_line section. */
2669 display_debug_lines_decoded (struct dwarf_section *section,
2670 unsigned char *data,
2673 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2678 /* This loop amounts to one iteration per compilation unit. */
2679 DWARF2_Internal_LineInfo linfo;
2680 unsigned char *standard_opcodes;
2681 unsigned char *end_of_sequence;
2682 unsigned char *hdrptr;
2683 int initial_length_size;
2686 File_Entry *file_table = NULL;
2687 unsigned int n_files = 0;
2688 unsigned char **directory_table = NULL;
2689 unsigned int n_directories = 0;
2693 /* Extract information from the Line Number Program Header.
2694 (section 6.2.4 in the Dwarf3 doc). */
2696 /* Get the length of this CU's line number information block. */
2697 linfo.li_length = byte_get (hdrptr, 4);
2700 if (linfo.li_length == 0xffffffff)
2702 /* This section is 64-bit DWARF 3. */
2703 linfo.li_length = byte_get (hdrptr, 8);
2706 initial_length_size = 12;
2711 initial_length_size = 4;
2714 if (linfo.li_length + initial_length_size > section->size)
2716 warn (_("The line info appears to be corrupt - "
2717 "the section is too small\n"));
2721 /* Get this CU's Line Number Block version number. */
2722 linfo.li_version = byte_get (hdrptr, 2);
2724 if (linfo.li_version != 2
2725 && linfo.li_version != 3
2726 && linfo.li_version != 4)
2728 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2733 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2734 hdrptr += offset_size;
2735 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2737 if (linfo.li_version >= 4)
2739 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2741 if (linfo.li_max_ops_per_insn == 0)
2743 warn (_("Invalid maximum operations per insn.\n"));
2748 linfo.li_max_ops_per_insn = 1;
2749 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2751 linfo.li_line_base = byte_get (hdrptr, 1);
2753 linfo.li_line_range = byte_get (hdrptr, 1);
2755 linfo.li_opcode_base = byte_get (hdrptr, 1);
2758 /* Sign extend the line base field. */
2759 linfo.li_line_base <<= 24;
2760 linfo.li_line_base >>= 24;
2762 /* Find the end of this CU's Line Number Information Block. */
2763 end_of_sequence = data + linfo.li_length + initial_length_size;
2765 reset_state_machine (linfo.li_default_is_stmt);
2767 /* Save a pointer to the contents of the Opcodes table. */
2768 standard_opcodes = hdrptr;
2770 /* Traverse the Directory table just to count entries. */
2771 data = standard_opcodes + linfo.li_opcode_base - 1;
2774 unsigned char *ptr_directory_table = data;
2778 data += strlen ((char *) data) + 1;
2782 /* Go through the directory table again to save the directories. */
2783 directory_table = (unsigned char **)
2784 xmalloc (n_directories * sizeof (unsigned char *));
2787 while (*ptr_directory_table != 0)
2789 directory_table[i] = ptr_directory_table;
2790 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2794 /* Skip the NUL at the end of the table. */
2797 /* Traverse the File Name table just to count the entries. */
2800 unsigned char *ptr_file_name_table = data;
2804 unsigned int bytes_read;
2806 /* Skip Name, directory index, last modification time and length
2808 data += strlen ((char *) data) + 1;
2809 read_leb128 (data, & bytes_read, 0);
2811 read_leb128 (data, & bytes_read, 0);
2813 read_leb128 (data, & bytes_read, 0);
2819 /* Go through the file table again to save the strings. */
2820 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2823 while (*ptr_file_name_table != 0)
2825 unsigned int bytes_read;
2827 file_table[i].name = ptr_file_name_table;
2828 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2830 /* We are not interested in directory, time or size. */
2831 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2833 ptr_file_name_table += bytes_read;
2834 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2836 ptr_file_name_table += bytes_read;
2837 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2838 ptr_file_name_table += bytes_read;
2843 /* Print the Compilation Unit's name and a header. */
2844 if (directory_table == NULL)
2846 printf (_("CU: %s:\n"), file_table[0].name);
2847 printf (_("File name Line number Starting address\n"));
2851 unsigned int ix = file_table[0].directory_index;
2852 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
2853 if (do_wide || strlen (directory) < 76)
2854 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
2856 printf ("%s:\n", file_table[0].name);
2858 printf (_("File name Line number Starting address\n"));
2862 /* Skip the NUL at the end of the table. */
2865 /* This loop iterates through the Dwarf Line Number Program. */
2866 while (data < end_of_sequence)
2868 unsigned char op_code;
2870 unsigned long int uladv;
2871 unsigned int bytes_read;
2872 int is_special_opcode = 0;
2876 if (op_code >= linfo.li_opcode_base)
2878 op_code -= linfo.li_opcode_base;
2879 uladv = (op_code / linfo.li_line_range);
2880 if (linfo.li_max_ops_per_insn == 1)
2882 uladv *= linfo.li_min_insn_length;
2883 state_machine_regs.address += uladv;
2887 state_machine_regs.address
2888 += ((state_machine_regs.op_index + uladv)
2889 / linfo.li_max_ops_per_insn)
2890 * linfo.li_min_insn_length;
2891 state_machine_regs.op_index
2892 = (state_machine_regs.op_index + uladv)
2893 % linfo.li_max_ops_per_insn;
2896 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2897 state_machine_regs.line += adv;
2898 is_special_opcode = 1;
2900 else switch (op_code)
2902 case DW_LNS_extended_op:
2904 unsigned int ext_op_code_len;
2905 unsigned char ext_op_code;
2906 unsigned char *op_code_data = data;
2908 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
2909 op_code_data += bytes_read;
2911 if (ext_op_code_len == 0)
2913 warn (_("badly formed extended line op encountered!\n"));
2916 ext_op_code_len += bytes_read;
2917 ext_op_code = *op_code_data++;
2919 switch (ext_op_code)
2921 case DW_LNE_end_sequence:
2922 reset_state_machine (linfo.li_default_is_stmt);
2924 case DW_LNE_set_address:
2925 state_machine_regs.address =
2926 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
2927 state_machine_regs.op_index = 0;
2929 case DW_LNE_define_file:
2931 file_table = (File_Entry *) xrealloc
2932 (file_table, (n_files + 1) * sizeof (File_Entry));
2934 ++state_machine_regs.last_file_entry;
2935 /* Source file name. */
2936 file_table[n_files].name = op_code_data;
2937 op_code_data += strlen ((char *) op_code_data) + 1;
2938 /* Directory index. */
2939 file_table[n_files].directory_index =
2940 read_leb128 (op_code_data, & bytes_read, 0);
2941 op_code_data += bytes_read;
2942 /* Last modification time. */
2943 file_table[n_files].modification_date =
2944 read_leb128 (op_code_data, & bytes_read, 0);
2945 op_code_data += bytes_read;
2947 file_table[n_files].length =
2948 read_leb128 (op_code_data, & bytes_read, 0);
2953 case DW_LNE_set_discriminator:
2954 case DW_LNE_HP_set_sequence:
2955 /* Simply ignored. */
2959 printf (_("UNKNOWN (%u): length %d\n"),
2960 ext_op_code, ext_op_code_len - bytes_read);
2963 data += ext_op_code_len;
2969 case DW_LNS_advance_pc:
2970 uladv = read_leb128 (data, & bytes_read, 0);
2972 if (linfo.li_max_ops_per_insn == 1)
2974 uladv *= linfo.li_min_insn_length;
2975 state_machine_regs.address += uladv;
2979 state_machine_regs.address
2980 += ((state_machine_regs.op_index + uladv)
2981 / linfo.li_max_ops_per_insn)
2982 * linfo.li_min_insn_length;
2983 state_machine_regs.op_index
2984 = (state_machine_regs.op_index + uladv)
2985 % linfo.li_max_ops_per_insn;
2989 case DW_LNS_advance_line:
2990 adv = read_sleb128 (data, & bytes_read);
2992 state_machine_regs.line += adv;
2995 case DW_LNS_set_file:
2996 adv = read_leb128 (data, & bytes_read, 0);
2998 state_machine_regs.file = adv;
2999 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3001 /* If directory index is 0, that means current directory. */
3002 printf ("\n./%s:[++]\n",
3003 file_table[state_machine_regs.file - 1].name);
3007 /* The directory index starts counting at 1. */
3008 printf ("\n%s/%s:\n",
3009 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3010 file_table[state_machine_regs.file - 1].name);
3014 case DW_LNS_set_column:
3015 uladv = read_leb128 (data, & bytes_read, 0);
3017 state_machine_regs.column = uladv;
3020 case DW_LNS_negate_stmt:
3021 adv = state_machine_regs.is_stmt;
3023 state_machine_regs.is_stmt = adv;
3026 case DW_LNS_set_basic_block:
3027 state_machine_regs.basic_block = 1;
3030 case DW_LNS_const_add_pc:
3031 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3032 if (linfo.li_max_ops_per_insn == 1)
3034 uladv *= linfo.li_min_insn_length;
3035 state_machine_regs.address += uladv;
3039 state_machine_regs.address
3040 += ((state_machine_regs.op_index + uladv)
3041 / linfo.li_max_ops_per_insn)
3042 * linfo.li_min_insn_length;
3043 state_machine_regs.op_index
3044 = (state_machine_regs.op_index + uladv)
3045 % linfo.li_max_ops_per_insn;
3049 case DW_LNS_fixed_advance_pc:
3050 uladv = byte_get (data, 2);
3052 state_machine_regs.address += uladv;
3053 state_machine_regs.op_index = 0;
3056 case DW_LNS_set_prologue_end:
3059 case DW_LNS_set_epilogue_begin:
3062 case DW_LNS_set_isa:
3063 uladv = read_leb128 (data, & bytes_read, 0);
3065 printf (_(" Set ISA to %lu\n"), uladv);
3069 printf (_(" Unknown opcode %d with operands: "), op_code);
3071 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3073 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3075 i == 1 ? "" : ", ");
3082 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3083 to the DWARF address/line matrix. */
3084 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3085 || (op_code == DW_LNS_copy))
3087 const unsigned int MAX_FILENAME_LENGTH = 35;
3088 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3089 char *newFileName = NULL;
3090 size_t fileNameLength = strlen (fileName);
3092 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3094 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3095 /* Truncate file name */
3096 strncpy (newFileName,
3097 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3098 MAX_FILENAME_LENGTH + 1);
3102 newFileName = (char *) xmalloc (fileNameLength + 1);
3103 strncpy (newFileName, fileName, fileNameLength + 1);
3106 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3108 if (linfo.li_max_ops_per_insn == 1)
3109 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3110 newFileName, state_machine_regs.line,
3111 state_machine_regs.address);
3113 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3114 newFileName, state_machine_regs.line,
3115 state_machine_regs.address,
3116 state_machine_regs.op_index);
3120 if (linfo.li_max_ops_per_insn == 1)
3121 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3122 newFileName, state_machine_regs.line,
3123 state_machine_regs.address);
3125 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3126 newFileName, state_machine_regs.line,
3127 state_machine_regs.address,
3128 state_machine_regs.op_index);
3131 if (op_code == DW_LNE_end_sequence)
3139 free (directory_table);
3140 directory_table = NULL;
3148 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3150 unsigned char *data = section->start;
3151 unsigned char *end = data + section->size;
3153 int retValDecoded = 1;
3155 if (do_debug_lines == 0)
3156 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3158 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3159 retValRaw = display_debug_lines_raw (section, data, end);
3161 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3162 retValDecoded = display_debug_lines_decoded (section, data, end);
3164 if (!retValRaw || !retValDecoded)
3171 find_debug_info_for_offset (unsigned long offset)
3175 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3178 for (i = 0; i < num_debug_info_entries; i++)
3179 if (debug_information[i].cu_offset == offset)
3180 return debug_information + i;
3186 display_debug_pubnames (struct dwarf_section *section,
3187 void *file ATTRIBUTE_UNUSED)
3189 DWARF2_Internal_PubNames names;
3190 unsigned char *start = section->start;
3191 unsigned char *end = start + section->size;
3193 /* It does not matter if this load fails,
3194 we test for that later on. */
3195 load_debug_info (file);
3197 printf (_("Contents of the %s section:\n\n"), section->name);
3201 unsigned char *data;
3202 unsigned long offset;
3203 int offset_size, initial_length_size;
3207 names.pn_length = byte_get (data, 4);
3209 if (names.pn_length == 0xffffffff)
3211 names.pn_length = byte_get (data, 8);
3214 initial_length_size = 12;
3219 initial_length_size = 4;
3222 names.pn_version = byte_get (data, 2);
3225 names.pn_offset = byte_get (data, offset_size);
3226 data += offset_size;
3228 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3229 && num_debug_info_entries > 0
3230 && find_debug_info_for_offset (names.pn_offset) == NULL)
3231 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3232 (unsigned long) names.pn_offset, section->name);
3234 names.pn_size = byte_get (data, offset_size);
3235 data += offset_size;
3237 start += names.pn_length + initial_length_size;
3239 if (names.pn_version != 2 && names.pn_version != 3)
3241 static int warned = 0;
3245 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3252 printf (_(" Length: %ld\n"),
3253 (long) names.pn_length);
3254 printf (_(" Version: %d\n"),
3256 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3257 (unsigned long) names.pn_offset);
3258 printf (_(" Size of area in .debug_info section: %ld\n"),
3259 (long) names.pn_size);
3261 printf (_("\n Offset\tName\n"));
3265 offset = byte_get (data, offset_size);
3269 data += offset_size;
3270 printf (" %-6lx\t%s\n", offset, data);
3271 data += strlen ((char *) data) + 1;
3274 while (offset != 0);
3282 display_debug_macinfo (struct dwarf_section *section,
3283 void *file ATTRIBUTE_UNUSED)
3285 unsigned char *start = section->start;
3286 unsigned char *end = start + section->size;
3287 unsigned char *curr = start;
3288 unsigned int bytes_read;
3289 enum dwarf_macinfo_record_type op;
3291 printf (_("Contents of the %s section:\n\n"), section->name);
3295 unsigned int lineno;
3298 op = (enum dwarf_macinfo_record_type) *curr;
3303 case DW_MACINFO_start_file:
3305 unsigned int filenum;
3307 lineno = read_leb128 (curr, & bytes_read, 0);
3309 filenum = read_leb128 (curr, & bytes_read, 0);
3312 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3317 case DW_MACINFO_end_file:
3318 printf (_(" DW_MACINFO_end_file\n"));
3321 case DW_MACINFO_define:
3322 lineno = read_leb128 (curr, & bytes_read, 0);
3324 string = (char *) curr;
3325 curr += strlen (string) + 1;
3326 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3330 case DW_MACINFO_undef:
3331 lineno = read_leb128 (curr, & bytes_read, 0);
3333 string = (char *) curr;
3334 curr += strlen (string) + 1;
3335 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3339 case DW_MACINFO_vendor_ext:
3341 unsigned int constant;
3343 constant = read_leb128 (curr, & bytes_read, 0);
3345 string = (char *) curr;
3346 curr += strlen (string) + 1;
3347 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3357 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3358 filename and dirname corresponding to file name table entry with index
3359 FILEIDX. Return NULL on failure. */
3361 static unsigned char *
3362 get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
3363 unsigned char **dir_name)
3365 struct dwarf_section *section = &debug_displays [line].section;
3366 unsigned char *hdrptr, *dirtable, *file_name;
3367 unsigned int offset_size, initial_length_size;
3368 unsigned int version, opcode_base, bytes_read;
3369 dwarf_vma length, diridx;
3372 if (section->start == NULL
3373 || line_offset >= section->size
3377 hdrptr = section->start + line_offset;
3378 length = byte_get (hdrptr, 4);
3380 if (length == 0xffffffff)
3382 /* This section is 64-bit DWARF 3. */
3383 length = byte_get (hdrptr, 8);
3386 initial_length_size = 12;
3391 initial_length_size = 4;
3393 if (length + initial_length_size > section->size)
3395 version = byte_get (hdrptr, 2);
3397 if (version != 2 && version != 3 && version != 4)
3399 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3401 hdrptr++; /* Skip max_ops_per_insn. */
3402 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3403 opcode_base = byte_get (hdrptr, 1);
3404 if (opcode_base == 0)
3407 hdrptr += opcode_base - 1;
3409 /* Skip over dirname table. */
3410 while (*hdrptr != '\0')
3411 hdrptr += strlen ((char *) hdrptr) + 1;
3412 hdrptr++; /* Skip the NUL at the end of the table. */
3413 /* Now skip over preceding filename table entries. */
3414 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3416 hdrptr += strlen ((char *) hdrptr) + 1;
3417 read_leb128 (hdrptr, &bytes_read, 0);
3418 hdrptr += bytes_read;
3419 read_leb128 (hdrptr, &bytes_read, 0);
3420 hdrptr += bytes_read;
3421 read_leb128 (hdrptr, &bytes_read, 0);
3422 hdrptr += bytes_read;
3424 if (*hdrptr == '\0')
3427 hdrptr += strlen ((char *) hdrptr) + 1;
3428 diridx = read_leb128 (hdrptr, &bytes_read, 0);
3431 for (; *dirtable != '\0' && diridx > 1; diridx--)
3432 dirtable += strlen ((char *) dirtable) + 1;
3433 if (*dirtable == '\0')
3435 *dir_name = dirtable;
3440 display_debug_macro (struct dwarf_section *section,
3443 unsigned char *start = section->start;
3444 unsigned char *end = start + section->size;
3445 unsigned char *curr = start;
3446 unsigned char *extended_op_buf[256];
3447 unsigned int bytes_read;
3449 load_debug_section (str, file);
3450 load_debug_section (line, file);
3452 printf (_("Contents of the %s section:\n\n"), section->name);
3456 unsigned int lineno, version, flags;
3457 unsigned int offset_size = 4;
3459 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3460 unsigned char **extended_ops = NULL;
3462 version = byte_get (curr, 2);
3467 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3472 flags = byte_get (curr++, 1);
3475 printf (_(" Offset: 0x%lx\n"),
3476 (unsigned long) sec_offset);
3477 printf (_(" Version: %d\n"), version);
3478 printf (_(" Offset size: %d\n"), offset_size);
3481 line_offset = byte_get (curr, offset_size);
3482 curr += offset_size;
3483 printf (_(" Offset into .debug_line: 0x%lx\n"),
3484 (unsigned long) line_offset);
3488 unsigned int i, count = byte_get (curr++, 1), op;
3490 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3491 extended_ops = extended_op_buf;
3494 printf (_(" Extension opcode arguments:\n"));
3495 for (i = 0; i < count; i++)
3497 op = byte_get (curr++, 1);
3498 extended_ops[op] = curr;
3499 nargs = read_leb128 (curr, &bytes_read, 0);
3502 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3505 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3506 for (n = 0; n < nargs; n++)
3508 unsigned int form = byte_get (curr++, 1);
3509 printf ("%s%s", get_FORM_name (form),
3510 n == nargs - 1 ? "\n" : ", ");
3520 case DW_FORM_block1:
3521 case DW_FORM_block2:
3522 case DW_FORM_block4:
3524 case DW_FORM_string:
3526 case DW_FORM_sec_offset:
3529 error (_("Invalid extension opcode form %s\n"),
3530 get_FORM_name (form));
3546 error (_(".debug_macro section not zero terminated\n"));
3550 op = byte_get (curr++, 1);
3556 case DW_MACRO_GNU_start_file:
3558 unsigned int filenum;
3559 unsigned char *file_name = NULL, *dir_name = NULL;
3561 lineno = read_leb128 (curr, &bytes_read, 0);
3563 filenum = read_leb128 (curr, &bytes_read, 0);
3566 if ((flags & 2) == 0)
3567 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3570 = get_line_filename_and_dirname (line_offset, filenum,
3572 if (file_name == NULL)
3573 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3576 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3578 dir_name != NULL ? (const char *) dir_name : "",
3579 dir_name != NULL ? "/" : "", file_name);
3583 case DW_MACRO_GNU_end_file:
3584 printf (_(" DW_MACRO_GNU_end_file\n"));
3587 case DW_MACRO_GNU_define:
3588 lineno = read_leb128 (curr, &bytes_read, 0);
3590 string = (char *) curr;
3591 curr += strlen (string) + 1;
3592 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3596 case DW_MACRO_GNU_undef:
3597 lineno = read_leb128 (curr, &bytes_read, 0);
3599 string = (char *) curr;
3600 curr += strlen (string) + 1;
3601 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3605 case DW_MACRO_GNU_define_indirect:
3606 lineno = read_leb128 (curr, &bytes_read, 0);
3608 offset = byte_get (curr, offset_size);
3609 curr += offset_size;
3610 string = fetch_indirect_string (offset);
3611 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3615 case DW_MACRO_GNU_undef_indirect:
3616 lineno = read_leb128 (curr, &bytes_read, 0);
3618 offset = byte_get (curr, offset_size);
3619 curr += offset_size;
3620 string = fetch_indirect_string (offset);
3621 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3625 case DW_MACRO_GNU_transparent_include:
3626 offset = byte_get (curr, offset_size);
3627 curr += offset_size;
3628 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3629 (unsigned long) offset);
3633 if (extended_ops == NULL || extended_ops[op] == NULL)
3635 error (_(" Unknown macro opcode %02x seen\n"), op);
3640 /* Skip over unhandled opcodes. */
3642 unsigned char *desc = extended_ops[op];
3643 nargs = read_leb128 (desc, &bytes_read, 0);
3647 printf (_(" DW_MACRO_GNU_%02x\n"), op);
3650 printf (_(" DW_MACRO_GNU_%02x -"), op);
3651 for (n = 0; n < nargs; n++)
3654 = read_and_display_attr_value (0, byte_get (desc++, 1),
3655 curr, 0, 0, offset_size,
3656 version, NULL, 0, NULL);
3673 display_debug_abbrev (struct dwarf_section *section,
3674 void *file ATTRIBUTE_UNUSED)
3676 abbrev_entry *entry;
3677 unsigned char *start = section->start;
3678 unsigned char *end = start + section->size;
3680 printf (_("Contents of the %s section:\n\n"), section->name);
3686 start = process_abbrev_section (start, end);
3688 if (first_abbrev == NULL)
3691 printf (_(" Number TAG\n"));
3693 for (entry = first_abbrev; entry; entry = entry->next)
3697 printf (" %ld %s [%s]\n",
3699 get_TAG_name (entry->tag),
3700 entry->children ? _("has children") : _("no children"));
3702 for (attr = entry->first_attr; attr; attr = attr->next)
3703 printf (" %-18s %s\n",
3704 get_AT_name (attr->attribute),
3705 get_FORM_name (attr->form));
3715 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
3718 display_loc_list (struct dwarf_section *section,
3719 unsigned char **start_ptr,
3720 int debug_info_entry,
3721 unsigned long offset,
3722 unsigned long base_address,
3725 unsigned char *start = *start_ptr;
3726 unsigned char *section_end = section->start + section->size;
3727 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3728 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3729 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3730 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3734 unsigned short length;
3735 int need_frame_base;
3739 if (start + 2 * pointer_size > section_end)
3741 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3746 /* Note: we use sign extension here in order to be sure that we can detect
3747 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
3748 address will not affect the values that we display since we always show
3749 hex values, and always the bottom 32-bits. */
3750 begin = byte_get_signed (start, pointer_size);
3751 start += pointer_size;
3752 end = byte_get_signed (start, pointer_size);
3753 start += pointer_size;
3755 printf (" %8.8lx ", offset);
3757 if (begin == 0 && end == 0)
3759 printf (_("<End of list>\n"));
3763 /* Check base address specifiers. */
3764 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3767 print_dwarf_vma (begin, pointer_size);
3768 print_dwarf_vma (end, pointer_size);
3769 printf (_("(base address)\n"));
3773 if (start + 2 > section_end)
3775 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3780 length = byte_get (start, 2);
3783 if (start + length > section_end)
3785 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3790 print_dwarf_vma (begin + base_address, pointer_size);
3791 print_dwarf_vma (end + base_address, pointer_size);
3794 need_frame_base = decode_location_expression (start,
3799 cu_offset, section);
3802 if (need_frame_base && !has_frame_base)
3803 printf (_(" [without DW_AT_frame_base]"));
3806 fputs (_(" (start == end)"), stdout);
3807 else if (begin > end)
3808 fputs (_(" (start > end)"), stdout);
3818 /* Display a location list from a .dwo section. It uses address indexes rather
3819 than embedded addresses. This code closely follows display_loc_list, but the
3820 two are sufficiently different that combining things is very ugly. */
3823 display_loc_list_dwo (struct dwarf_section *section,
3824 unsigned char **start_ptr,
3825 int debug_info_entry,
3826 unsigned long offset,
3829 unsigned char *start = *start_ptr;
3830 unsigned char *section_end = section->start + section->size;
3831 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3832 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3833 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3834 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3836 unsigned short length;
3837 int need_frame_base;
3839 unsigned int bytes_read;
3843 printf (" %8.8lx ", offset);
3845 if (start + 2 > section_end)
3847 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3852 entry_type = byte_get (start, 1);
3856 case 0: /* A terminating entry. */
3857 idx = byte_get (start, 1);
3861 printf (_("<End of list>\n"));
3863 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3866 case 1: /* A base-address entry. */
3867 idx = read_leb128 (start, &bytes_read, 0);
3868 start += bytes_read;
3869 print_dwarf_vma (idx, pointer_size);
3870 printf (_("(base address index)\n"));
3872 case 2: /* A normal entry. */
3873 idx = read_leb128 (start, &bytes_read, 0);
3874 start += bytes_read;
3875 print_dwarf_vma (idx, pointer_size);
3876 idx = read_leb128 (start, &bytes_read, 0);
3877 start += bytes_read;
3878 print_dwarf_vma (idx, pointer_size);
3881 warn (_("Unknown location-list type 0x%x.\n"), entry_type);
3886 if (start + 2 > section_end)
3888 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3893 length = byte_get (start, 2);
3896 if (start + length > section_end)
3898 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3904 need_frame_base = decode_location_expression (start,
3909 cu_offset, section);
3912 if (need_frame_base && !has_frame_base)
3913 printf (_(" [without DW_AT_frame_base]"));
3923 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3925 static dwarf_vma *loc_offsets;
3928 loc_offsets_compar (const void *ap, const void *bp)
3930 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
3931 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
3933 return (a > b) - (b > a);
3937 display_debug_loc (struct dwarf_section *section, void *file)
3939 unsigned char *start = section->start;
3940 unsigned long bytes;
3941 unsigned char *section_begin = start;
3942 unsigned int num_loc_list = 0;
3943 unsigned long last_offset = 0;
3944 unsigned int first = 0;
3948 int seen_first_offset = 0;
3949 int locs_sorted = 1;
3950 unsigned char *next;
3951 unsigned int *array = NULL;
3952 const char *suffix = strrchr (section->name, '.');
3955 if (suffix && strcmp (suffix, ".dwo") == 0)
3958 bytes = section->size;
3962 printf (_("\nThe %s section is empty.\n"), section->name);
3966 if (load_debug_info (file) == 0)
3968 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3973 /* Check the order of location list in .debug_info section. If
3974 offsets of location lists are in the ascending order, we can
3975 use `debug_information' directly. */
3976 for (i = 0; i < num_debug_info_entries; i++)
3980 num = debug_information [i].num_loc_offsets;
3981 if (num > num_loc_list)
3984 /* Check if we can use `debug_information' directly. */
3985 if (locs_sorted && num != 0)
3987 if (!seen_first_offset)
3989 /* This is the first location list. */
3990 last_offset = debug_information [i].loc_offsets [0];
3992 seen_first_offset = 1;
3998 for (; j < num; j++)
4001 debug_information [i].loc_offsets [j])
4006 last_offset = debug_information [i].loc_offsets [j];
4011 if (!seen_first_offset)
4012 error (_("No location lists in .debug_info section!\n"));
4014 /* DWARF sections under Mach-O have non-zero addresses. */
4015 if (debug_information [first].num_loc_offsets > 0
4016 && debug_information [first].loc_offsets [0] != section->address)
4017 warn (_("Location lists in %s section start at 0x%s\n"),
4019 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4022 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4023 printf (_("Contents of the %s section:\n\n"), section->name);
4025 printf (_(" Offset Begin End Expression\n"));
4027 printf (_(" Offset Begin idx End idx Expression\n"));
4029 seen_first_offset = 0;
4030 for (i = first; i < num_debug_info_entries; i++)
4032 unsigned long offset;
4033 unsigned long base_address;
4038 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4040 loc_offsets = debug_information [i].loc_offsets;
4041 qsort (array, debug_information [i].num_loc_offsets,
4042 sizeof (*array), loc_offsets_compar);
4045 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4047 j = locs_sorted ? k : array[k];
4049 && debug_information [i].loc_offsets [locs_sorted
4050 ? k - 1 : array [k - 1]]
4051 == debug_information [i].loc_offsets [j])
4053 has_frame_base = debug_information [i].have_frame_base [j];
4054 /* DWARF sections under Mach-O have non-zero addresses. */
4055 offset = debug_information [i].loc_offsets [j] - section->address;
4056 next = section_begin + offset;
4057 base_address = debug_information [i].base_address;
4059 if (!seen_first_offset)
4060 seen_first_offset = 1;
4064 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4065 (unsigned long) (start - section_begin),
4066 (unsigned long) (next - section_begin));
4067 else if (start > next)
4068 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4069 (unsigned long) (start - section_begin),
4070 (unsigned long) (next - section_begin));
4074 if (offset >= bytes)
4076 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4082 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4084 display_loc_list (section, &start, i, offset, base_address,
4089 if (start < section->start + section->size)
4090 warn (_("There are %ld unused bytes at the end of section %s\n"),
4091 (long) (section->start + section->size - start), section->name);
4098 display_debug_str (struct dwarf_section *section,
4099 void *file ATTRIBUTE_UNUSED)
4101 unsigned char *start = section->start;
4102 unsigned long bytes = section->size;
4103 dwarf_vma addr = section->address;
4107 printf (_("\nThe %s section is empty.\n"), section->name);
4111 printf (_("Contents of the %s section:\n\n"), section->name);
4119 lbytes = (bytes > 16 ? 16 : bytes);
4121 printf (" 0x%8.8lx ", (unsigned long) addr);
4123 for (j = 0; j < 16; j++)
4126 printf ("%2.2x", start[j]);
4134 for (j = 0; j < lbytes; j++)
4137 if (k >= ' ' && k < 0x80)
4156 display_debug_info (struct dwarf_section *section, void *file)
4158 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4162 display_debug_types (struct dwarf_section *section, void *file)
4164 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4168 display_trace_info (struct dwarf_section *section, void *file)
4170 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4174 display_debug_aranges (struct dwarf_section *section,
4175 void *file ATTRIBUTE_UNUSED)
4177 unsigned char *start = section->start;
4178 unsigned char *end = start + section->size;
4180 printf (_("Contents of the %s section:\n\n"), section->name);
4182 /* It does not matter if this load fails,
4183 we test for that later on. */
4184 load_debug_info (file);
4188 unsigned char *hdrptr;
4189 DWARF2_Internal_ARange arange;
4190 unsigned char *addr_ranges;
4193 unsigned char address_size;
4196 int initial_length_size;
4200 arange.ar_length = byte_get (hdrptr, 4);
4203 if (arange.ar_length == 0xffffffff)
4205 arange.ar_length = byte_get (hdrptr, 8);
4208 initial_length_size = 12;
4213 initial_length_size = 4;
4216 arange.ar_version = byte_get (hdrptr, 2);
4219 arange.ar_info_offset = byte_get (hdrptr, offset_size);
4220 hdrptr += offset_size;
4222 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4223 && num_debug_info_entries > 0
4224 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4225 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4226 (unsigned long) arange.ar_info_offset, section->name);
4228 arange.ar_pointer_size = byte_get (hdrptr, 1);
4231 arange.ar_segment_size = byte_get (hdrptr, 1);
4234 if (arange.ar_version != 2 && arange.ar_version != 3)
4236 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4240 printf (_(" Length: %ld\n"),
4241 (long) arange.ar_length);
4242 printf (_(" Version: %d\n"), arange.ar_version);
4243 printf (_(" Offset into .debug_info: 0x%lx\n"),
4244 (unsigned long) arange.ar_info_offset);
4245 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4246 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4248 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4250 if (address_size == 0)
4252 error (_("Invalid address size in %s section!\n"),
4257 /* The DWARF spec does not require that the address size be a power
4258 of two, but we do. This will have to change if we ever encounter
4259 an uneven architecture. */
4260 if ((address_size & (address_size - 1)) != 0)
4262 warn (_("Pointer size + Segment size is not a power of two.\n"));
4266 if (address_size > 4)
4267 printf (_("\n Address Length\n"));
4269 printf (_("\n Address Length\n"));
4271 addr_ranges = hdrptr;
4273 /* Must pad to an alignment boundary that is twice the address size. */
4274 excess = (hdrptr - start) % (2 * address_size);
4276 addr_ranges += (2 * address_size) - excess;
4278 start += arange.ar_length + initial_length_size;
4280 while (addr_ranges + 2 * address_size <= start)
4282 address = byte_get (addr_ranges, address_size);
4284 addr_ranges += address_size;
4286 length = byte_get (addr_ranges, address_size);
4288 addr_ranges += address_size;
4291 print_dwarf_vma (address, address_size);
4292 print_dwarf_vma (length, address_size);
4302 /* Comparison function for qsort. */
4304 comp_addr_base (const void * v0, const void * v1)
4306 debug_info * info0 = (debug_info *) v0;
4307 debug_info * info1 = (debug_info *) v1;
4308 return info0->addr_base - info1->addr_base;
4311 /* Display the debug_addr section. */
4313 display_debug_addr (struct dwarf_section *section,
4316 debug_info **debug_addr_info;
4317 unsigned char *entry;
4322 if (section->size == 0)
4324 printf (_("\nThe %s section is empty.\n"), section->name);
4328 if (load_debug_info (file) == 0)
4330 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4335 printf (_("Contents of the %s section:\n\n"), section->name);
4337 debug_addr_info = (debug_info **) xmalloc (num_debug_info_entries + 1
4338 * sizeof (debug_info *));
4341 for (i = 0; i < num_debug_info_entries; i++)
4343 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4344 debug_addr_info [count++] = &debug_information [i];
4347 /* Add a sentinel to make iteration convenient. */
4348 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4349 debug_addr_info [count]->addr_base = section->size;
4351 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4352 for (i = 0; i < count; i++)
4356 printf (_(" For compilation unit at offset 0x%s:\n"),
4357 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4359 printf (_("\tIndex\tOffset\n"));
4360 entry = section->start + debug_addr_info [i]->addr_base;
4361 end = section->start + debug_addr_info [i + 1]->addr_base;
4365 dwarf_vma base = byte_get (entry, debug_addr_info [i]->pointer_size);
4366 printf (_("\t%d:\t%s\n"), idx, dwarf_vmatoa ("x", base));
4367 entry += debug_addr_info [i]->pointer_size;
4373 free (debug_addr_info);
4377 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4379 display_debug_str_offsets (struct dwarf_section *section,
4380 void *file ATTRIBUTE_UNUSED)
4382 if (section->size == 0)
4384 printf (_("\nThe %s section is empty.\n"), section->name);
4387 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4388 what the offset size is for this section. */
4392 /* Each debug_information[x].range_lists[y] gets this representation for
4393 sorting purposes. */
4397 /* The debug_information[x].range_lists[y] value. */
4398 unsigned long ranges_offset;
4400 /* Original debug_information to find parameters of the data. */
4401 debug_info *debug_info_p;
4404 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4407 range_entry_compar (const void *ap, const void *bp)
4409 const struct range_entry *a_re = (const struct range_entry *) ap;
4410 const struct range_entry *b_re = (const struct range_entry *) bp;
4411 const unsigned long a = a_re->ranges_offset;
4412 const unsigned long b = b_re->ranges_offset;
4414 return (a > b) - (b > a);
4418 display_debug_ranges (struct dwarf_section *section,
4419 void *file ATTRIBUTE_UNUSED)
4421 unsigned char *start = section->start;
4422 unsigned long bytes;
4423 unsigned char *section_begin = start;
4424 unsigned int num_range_list, i;
4425 struct range_entry *range_entries, *range_entry_fill;
4427 bytes = section->size;
4431 printf (_("\nThe %s section is empty.\n"), section->name);
4435 if (load_debug_info (file) == 0)
4437 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4443 for (i = 0; i < num_debug_info_entries; i++)
4444 num_range_list += debug_information [i].num_range_lists;
4446 if (num_range_list == 0)
4448 /* This can happen when the file was compiled with -gsplit-debug
4449 which removes references to range lists from the primary .o file. */
4450 printf (_("No range lists in .debug_info section.\n"));
4454 range_entries = (struct range_entry *)
4455 xmalloc (sizeof (*range_entries) * num_range_list);
4456 range_entry_fill = range_entries;
4458 for (i = 0; i < num_debug_info_entries; i++)
4460 debug_info *debug_info_p = &debug_information[i];
4463 for (j = 0; j < debug_info_p->num_range_lists; j++)
4465 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4466 range_entry_fill->debug_info_p = debug_info_p;
4471 qsort (range_entries, num_range_list, sizeof (*range_entries),
4472 range_entry_compar);
4474 /* DWARF sections under Mach-O have non-zero addresses. */
4475 if (dwarf_check != 0 && range_entries[0].ranges_offset != section->address)
4476 warn (_("Range lists in %s section start at 0x%lx\n"),
4477 section->name, range_entries[0].ranges_offset);
4479 printf (_("Contents of the %s section:\n\n"), section->name);
4480 printf (_(" Offset Begin End\n"));
4482 for (i = 0; i < num_range_list; i++)
4484 struct range_entry *range_entry = &range_entries[i];
4485 debug_info *debug_info_p = range_entry->debug_info_p;
4486 unsigned int pointer_size;
4487 unsigned long offset;
4488 unsigned char *next;
4489 unsigned long base_address;
4491 pointer_size = debug_info_p->pointer_size;
4493 /* DWARF sections under Mach-O have non-zero addresses. */
4494 offset = range_entry->ranges_offset - section->address;
4495 next = section_begin + offset;
4496 base_address = debug_info_p->base_address;
4498 if (dwarf_check != 0 && i > 0)
4501 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4502 (unsigned long) (start - section_begin),
4503 (unsigned long) (next - section_begin), section->name);
4504 else if (start > next)
4505 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4506 (unsigned long) (start - section_begin),
4507 (unsigned long) (next - section_begin), section->name);
4516 /* Note: we use sign extension here in order to be sure that
4517 we can detect the -1 escape value. Sign extension into the
4518 top 32 bits of a 32-bit address will not affect the values
4519 that we display since we always show hex values, and always
4520 the bottom 32-bits. */
4521 begin = byte_get_signed (start, pointer_size);
4522 start += pointer_size;
4523 end = byte_get_signed (start, pointer_size);
4524 start += pointer_size;
4526 printf (" %8.8lx ", offset);
4528 if (begin == 0 && end == 0)
4530 printf (_("<End of list>\n"));
4534 /* Check base address specifiers. */
4535 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4538 print_dwarf_vma (begin, pointer_size);
4539 print_dwarf_vma (end, pointer_size);
4540 printf ("(base address)\n");
4544 print_dwarf_vma (begin + base_address, pointer_size);
4545 print_dwarf_vma (end + base_address, pointer_size);
4548 fputs (_("(start == end)"), stdout);
4549 else if (begin > end)
4550 fputs (_("(start > end)"), stdout);
4557 free (range_entries);
4562 typedef struct Frame_Chunk
4564 struct Frame_Chunk *next;
4565 unsigned char *chunk_start;
4567 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4568 short int *col_type;
4571 unsigned int code_factor;
4573 unsigned long pc_begin;
4574 unsigned long pc_range;
4578 unsigned char fde_encoding;
4579 unsigned char cfa_exp;
4580 unsigned char ptr_size;
4581 unsigned char segment_size;
4585 static const char *const *dwarf_regnames;
4586 static unsigned int dwarf_regnames_count;
4588 /* A marker for a col_type that means this column was never referenced
4589 in the frame info. */
4590 #define DW_CFA_unreferenced (-1)
4592 /* Return 0 if not more space is needed, 1 if more space is needed,
4593 -1 for invalid reg. */
4596 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4598 int prev = fc->ncols;
4600 if (reg < (unsigned int) fc->ncols)
4603 if (dwarf_regnames_count
4604 && reg > dwarf_regnames_count)
4607 fc->ncols = reg + 1;
4608 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4609 sizeof (short int));
4610 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4612 while (prev < fc->ncols)
4614 fc->col_type[prev] = DW_CFA_unreferenced;
4615 fc->col_offset[prev] = 0;
4621 static const char *const dwarf_regnames_i386[] =
4623 "eax", "ecx", "edx", "ebx",
4624 "esp", "ebp", "esi", "edi",
4625 "eip", "eflags", NULL,
4626 "st0", "st1", "st2", "st3",
4627 "st4", "st5", "st6", "st7",
4629 "xmm0", "xmm1", "xmm2", "xmm3",
4630 "xmm4", "xmm5", "xmm6", "xmm7",
4631 "mm0", "mm1", "mm2", "mm3",
4632 "mm4", "mm5", "mm6", "mm7",
4633 "fcw", "fsw", "mxcsr",
4634 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4639 init_dwarf_regnames_i386 (void)
4641 dwarf_regnames = dwarf_regnames_i386;
4642 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4645 static const char *const dwarf_regnames_x86_64[] =
4647 "rax", "rdx", "rcx", "rbx",
4648 "rsi", "rdi", "rbp", "rsp",
4649 "r8", "r9", "r10", "r11",
4650 "r12", "r13", "r14", "r15",
4652 "xmm0", "xmm1", "xmm2", "xmm3",
4653 "xmm4", "xmm5", "xmm6", "xmm7",
4654 "xmm8", "xmm9", "xmm10", "xmm11",
4655 "xmm12", "xmm13", "xmm14", "xmm15",
4656 "st0", "st1", "st2", "st3",
4657 "st4", "st5", "st6", "st7",
4658 "mm0", "mm1", "mm2", "mm3",
4659 "mm4", "mm5", "mm6", "mm7",
4661 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4662 "fs.base", "gs.base", NULL, NULL,
4664 "mxcsr", "fcw", "fsw"
4668 init_dwarf_regnames_x86_64 (void)
4670 dwarf_regnames = dwarf_regnames_x86_64;
4671 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4675 init_dwarf_regnames (unsigned int e_machine)
4681 init_dwarf_regnames_i386 ();
4687 init_dwarf_regnames_x86_64 ();
4696 regname (unsigned int regno, int row)
4698 static char reg[64];
4700 && regno < dwarf_regnames_count
4701 && dwarf_regnames [regno] != NULL)
4704 return dwarf_regnames [regno];
4705 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4706 dwarf_regnames [regno]);
4709 snprintf (reg, sizeof (reg), "r%d", regno);
4714 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4719 if (*max_regs < fc->ncols)
4720 *max_regs = fc->ncols;
4722 if (*need_col_headers)
4724 static const char *sloc = " LOC";
4726 *need_col_headers = 0;
4728 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4730 for (r = 0; r < *max_regs; r++)
4731 if (fc->col_type[r] != DW_CFA_unreferenced)
4736 printf ("%-5s ", regname (r, 1));
4742 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4744 strcpy (tmp, "exp");
4746 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4747 printf ("%-8s ", tmp);
4749 for (r = 0; r < fc->ncols; r++)
4751 if (fc->col_type[r] != DW_CFA_unreferenced)
4753 switch (fc->col_type[r])
4755 case DW_CFA_undefined:
4758 case DW_CFA_same_value:
4762 sprintf (tmp, "c%+d", fc->col_offset[r]);
4764 case DW_CFA_val_offset:
4765 sprintf (tmp, "v%+d", fc->col_offset[r]);
4767 case DW_CFA_register:
4768 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4770 case DW_CFA_expression:
4771 strcpy (tmp, "exp");
4773 case DW_CFA_val_expression:
4774 strcpy (tmp, "vexp");
4777 strcpy (tmp, "n/a");
4780 printf ("%-5s ", tmp);
4786 #define GET(N) byte_get (start, N); start += N
4787 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4788 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4791 display_debug_frames (struct dwarf_section *section,
4792 void *file ATTRIBUTE_UNUSED)
4794 unsigned char *start = section->start;
4795 unsigned char *end = start + section->size;
4796 unsigned char *section_start = start;
4797 Frame_Chunk *chunks = 0;
4798 Frame_Chunk *remembered_state = 0;
4800 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4801 unsigned int length_return;
4803 const char *bad_reg = _("bad register: ");
4804 int saved_eh_addr_size = eh_addr_size;
4806 printf (_("Contents of the %s section:\n"), section->name);
4810 unsigned char *saved_start;
4811 unsigned char *block_end;
4812 unsigned long length;
4813 unsigned long cie_id;
4816 int need_col_headers = 1;
4817 unsigned char *augmentation_data = NULL;
4818 unsigned long augmentation_data_len = 0;
4819 int encoded_ptr_size = saved_eh_addr_size;
4821 int initial_length_size;
4823 saved_start = start;
4824 length = byte_get (start, 4); start += 4;
4828 printf ("\n%08lx ZERO terminator\n\n",
4829 (unsigned long)(saved_start - section_start));
4833 if (length == 0xffffffff)
4835 length = byte_get (start, 8);
4838 initial_length_size = 12;
4843 initial_length_size = 4;
4846 block_end = saved_start + length + initial_length_size;
4847 if (block_end > end)
4849 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4850 length, (unsigned long)(saved_start - section_start));
4853 cie_id = byte_get (start, offset_size); start += offset_size;
4855 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4859 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4860 memset (fc, 0, sizeof (Frame_Chunk));
4864 fc->chunk_start = saved_start;
4866 fc->col_type = (short int *) xmalloc (sizeof (short int));
4867 fc->col_offset = (int *) xmalloc (sizeof (int));
4868 frame_need_space (fc, max_regs - 1);
4872 fc->augmentation = (char *) start;
4873 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4875 if (strcmp (fc->augmentation, "eh") == 0)
4876 start += eh_addr_size;
4880 fc->ptr_size = GET (1);
4881 fc->segment_size = GET (1);
4882 eh_addr_size = fc->ptr_size;
4886 fc->ptr_size = eh_addr_size;
4887 fc->segment_size = 0;
4889 fc->code_factor = LEB ();
4890 fc->data_factor = SLEB ();
4900 if (fc->augmentation[0] == 'z')
4902 augmentation_data_len = LEB ();
4903 augmentation_data = start;
4904 start += augmentation_data_len;
4908 if (do_debug_frames_interp)
4909 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4910 (unsigned long)(saved_start - section_start), length, cie_id,
4911 fc->augmentation, fc->code_factor, fc->data_factor,
4915 printf ("\n%08lx %08lx %08lx CIE\n",
4916 (unsigned long)(saved_start - section_start), length, cie_id);
4917 printf (" Version: %d\n", version);
4918 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4921 printf (" Pointer Size: %u\n", fc->ptr_size);
4922 printf (" Segment Size: %u\n", fc->segment_size);
4924 printf (" Code alignment factor: %u\n", fc->code_factor);
4925 printf (" Data alignment factor: %d\n", fc->data_factor);
4926 printf (" Return address column: %d\n", fc->ra);
4928 if (augmentation_data_len)
4931 printf (" Augmentation data: ");
4932 for (i = 0; i < augmentation_data_len; ++i)
4933 printf (" %02x", augmentation_data[i]);
4939 if (augmentation_data_len)
4941 unsigned char *p, *q;
4942 p = (unsigned char *) fc->augmentation + 1;
4943 q = augmentation_data;
4950 q += 1 + size_of_encoded_value (*q);
4952 fc->fde_encoding = *q++;
4960 if (fc->fde_encoding)
4961 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4964 frame_need_space (fc, fc->ra);
4968 unsigned char *look_for;
4969 static Frame_Chunk fde_fc;
4970 unsigned long segment_selector;
4973 memset (fc, 0, sizeof (Frame_Chunk));
4975 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
4977 for (cie = chunks; cie ; cie = cie->next)
4978 if (cie->chunk_start == look_for)
4983 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4984 cie_id, (unsigned long)(saved_start - section_start));
4986 fc->col_type = (short int *) xmalloc (sizeof (short int));
4987 fc->col_offset = (int *) xmalloc (sizeof (int));
4988 frame_need_space (fc, max_regs - 1);
4990 fc->augmentation = "";
4991 fc->fde_encoding = 0;
4992 fc->ptr_size = eh_addr_size;
4993 fc->segment_size = 0;
4997 fc->ncols = cie->ncols;
4998 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
4999 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5000 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5001 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5002 fc->augmentation = cie->augmentation;
5003 fc->ptr_size = cie->ptr_size;
5004 eh_addr_size = cie->ptr_size;
5005 fc->segment_size = cie->segment_size;
5006 fc->code_factor = cie->code_factor;
5007 fc->data_factor = cie->data_factor;
5008 fc->cfa_reg = cie->cfa_reg;
5009 fc->cfa_offset = cie->cfa_offset;
5011 frame_need_space (fc, max_regs - 1);
5012 fc->fde_encoding = cie->fde_encoding;
5015 if (fc->fde_encoding)
5016 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5018 segment_selector = 0;
5019 if (fc->segment_size)
5021 segment_selector = byte_get (start, fc->segment_size);
5022 start += fc->segment_size;
5024 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
5025 start += encoded_ptr_size;
5026 fc->pc_range = byte_get (start, encoded_ptr_size);
5027 start += encoded_ptr_size;
5029 if (cie->augmentation[0] == 'z')
5031 augmentation_data_len = LEB ();
5032 augmentation_data = start;
5033 start += augmentation_data_len;
5036 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
5037 (unsigned long)(saved_start - section_start), length, cie_id,
5038 (unsigned long)(cie->chunk_start - section_start));
5039 if (fc->segment_size)
5040 printf ("%04lx:", segment_selector);
5041 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
5042 if (! do_debug_frames_interp && augmentation_data_len)
5046 printf (" Augmentation data: ");
5047 for (i = 0; i < augmentation_data_len; ++i)
5048 printf (" %02x", augmentation_data[i]);
5054 /* At this point, fc is the current chunk, cie (if any) is set, and
5055 we're about to interpret instructions for the chunk. */
5056 /* ??? At present we need to do this always, since this sizes the
5057 fc->col_type and fc->col_offset arrays, which we write into always.
5058 We should probably split the interpreted and non-interpreted bits
5059 into two different routines, since there's so much that doesn't
5060 really overlap between them. */
5061 if (1 || do_debug_frames_interp)
5063 /* Start by making a pass over the chunk, allocating storage
5064 and taking note of what registers are used. */
5065 unsigned char *tmp = start;
5067 while (start < block_end)
5070 unsigned long reg, temp;
5077 /* Warning: if you add any more cases to this switch, be
5078 sure to add them to the corresponding switch below. */
5081 case DW_CFA_advance_loc:
5085 if (frame_need_space (fc, opa) >= 0)
5086 fc->col_type[opa] = DW_CFA_undefined;
5088 case DW_CFA_restore:
5089 if (frame_need_space (fc, opa) >= 0)
5090 fc->col_type[opa] = DW_CFA_undefined;
5092 case DW_CFA_set_loc:
5093 start += encoded_ptr_size;
5095 case DW_CFA_advance_loc1:
5098 case DW_CFA_advance_loc2:
5101 case DW_CFA_advance_loc4:
5104 case DW_CFA_offset_extended:
5105 case DW_CFA_val_offset:
5106 reg = LEB (); LEB ();
5107 if (frame_need_space (fc, reg) >= 0)
5108 fc->col_type[reg] = DW_CFA_undefined;
5110 case DW_CFA_restore_extended:
5112 frame_need_space (fc, reg);
5113 if (frame_need_space (fc, reg) >= 0)
5114 fc->col_type[reg] = DW_CFA_undefined;
5116 case DW_CFA_undefined:
5118 if (frame_need_space (fc, reg) >= 0)
5119 fc->col_type[reg] = DW_CFA_undefined;
5121 case DW_CFA_same_value:
5123 if (frame_need_space (fc, reg) >= 0)
5124 fc->col_type[reg] = DW_CFA_undefined;
5126 case DW_CFA_register:
5127 reg = LEB (); LEB ();
5128 if (frame_need_space (fc, reg) >= 0)
5129 fc->col_type[reg] = DW_CFA_undefined;
5131 case DW_CFA_def_cfa:
5134 case DW_CFA_def_cfa_register:
5137 case DW_CFA_def_cfa_offset:
5140 case DW_CFA_def_cfa_expression:
5144 case DW_CFA_expression:
5145 case DW_CFA_val_expression:
5149 if (frame_need_space (fc, reg) >= 0)
5150 fc->col_type[reg] = DW_CFA_undefined;
5152 case DW_CFA_offset_extended_sf:
5153 case DW_CFA_val_offset_sf:
5154 reg = LEB (); SLEB ();
5155 if (frame_need_space (fc, reg) >= 0)
5156 fc->col_type[reg] = DW_CFA_undefined;
5158 case DW_CFA_def_cfa_sf:
5161 case DW_CFA_def_cfa_offset_sf:
5164 case DW_CFA_MIPS_advance_loc8:
5167 case DW_CFA_GNU_args_size:
5170 case DW_CFA_GNU_negative_offset_extended:
5171 reg = LEB (); LEB ();
5172 if (frame_need_space (fc, reg) >= 0)
5173 fc->col_type[reg] = DW_CFA_undefined;
5182 /* Now we know what registers are used, make a second pass over
5183 the chunk, this time actually printing out the info. */
5185 while (start < block_end)
5188 unsigned long ul, reg, roffs;
5191 const char *reg_prefix = "";
5198 /* Warning: if you add any more cases to this switch, be
5199 sure to add them to the corresponding switch above. */
5202 case DW_CFA_advance_loc:
5203 if (do_debug_frames_interp)
5204 frame_display_row (fc, &need_col_headers, &max_regs);
5206 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5207 opa * fc->code_factor,
5208 fc->pc_begin + opa * fc->code_factor);
5209 fc->pc_begin += opa * fc->code_factor;
5214 if (opa >= (unsigned int) fc->ncols)
5215 reg_prefix = bad_reg;
5216 if (! do_debug_frames_interp || *reg_prefix != '\0')
5217 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5218 reg_prefix, regname (opa, 0),
5219 roffs * fc->data_factor);
5220 if (*reg_prefix == '\0')
5222 fc->col_type[opa] = DW_CFA_offset;
5223 fc->col_offset[opa] = roffs * fc->data_factor;
5227 case DW_CFA_restore:
5228 if (opa >= (unsigned int) cie->ncols
5229 || opa >= (unsigned int) fc->ncols)
5230 reg_prefix = bad_reg;
5231 if (! do_debug_frames_interp || *reg_prefix != '\0')
5232 printf (" DW_CFA_restore: %s%s\n",
5233 reg_prefix, regname (opa, 0));
5234 if (*reg_prefix == '\0')
5236 fc->col_type[opa] = cie->col_type[opa];
5237 fc->col_offset[opa] = cie->col_offset[opa];
5238 if (do_debug_frames_interp
5239 && fc->col_type[opa] == DW_CFA_unreferenced)
5240 fc->col_type[opa] = DW_CFA_undefined;
5244 case DW_CFA_set_loc:
5245 vma = get_encoded_value (start, fc->fde_encoding, section);
5246 start += encoded_ptr_size;
5247 if (do_debug_frames_interp)
5248 frame_display_row (fc, &need_col_headers, &max_regs);
5250 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5254 case DW_CFA_advance_loc1:
5255 ofs = byte_get (start, 1); start += 1;
5256 if (do_debug_frames_interp)
5257 frame_display_row (fc, &need_col_headers, &max_regs);
5259 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5260 ofs * fc->code_factor,
5261 fc->pc_begin + ofs * fc->code_factor);
5262 fc->pc_begin += ofs * fc->code_factor;
5265 case DW_CFA_advance_loc2:
5266 ofs = byte_get (start, 2); start += 2;
5267 if (do_debug_frames_interp)
5268 frame_display_row (fc, &need_col_headers, &max_regs);
5270 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5271 ofs * fc->code_factor,
5272 fc->pc_begin + ofs * fc->code_factor);
5273 fc->pc_begin += ofs * fc->code_factor;
5276 case DW_CFA_advance_loc4:
5277 ofs = byte_get (start, 4); start += 4;
5278 if (do_debug_frames_interp)
5279 frame_display_row (fc, &need_col_headers, &max_regs);
5281 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5282 ofs * fc->code_factor,
5283 fc->pc_begin + ofs * fc->code_factor);
5284 fc->pc_begin += ofs * fc->code_factor;
5287 case DW_CFA_offset_extended:
5290 if (reg >= (unsigned int) fc->ncols)
5291 reg_prefix = bad_reg;
5292 if (! do_debug_frames_interp || *reg_prefix != '\0')
5293 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5294 reg_prefix, regname (reg, 0),
5295 roffs * fc->data_factor);
5296 if (*reg_prefix == '\0')
5298 fc->col_type[reg] = DW_CFA_offset;
5299 fc->col_offset[reg] = roffs * fc->data_factor;
5303 case DW_CFA_val_offset:
5306 if (reg >= (unsigned int) fc->ncols)
5307 reg_prefix = bad_reg;
5308 if (! do_debug_frames_interp || *reg_prefix != '\0')
5309 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5310 reg_prefix, regname (reg, 0),
5311 roffs * fc->data_factor);
5312 if (*reg_prefix == '\0')
5314 fc->col_type[reg] = DW_CFA_val_offset;
5315 fc->col_offset[reg] = roffs * fc->data_factor;
5319 case DW_CFA_restore_extended:
5321 if (reg >= (unsigned int) cie->ncols
5322 || reg >= (unsigned int) fc->ncols)
5323 reg_prefix = bad_reg;
5324 if (! do_debug_frames_interp || *reg_prefix != '\0')
5325 printf (" DW_CFA_restore_extended: %s%s\n",
5326 reg_prefix, regname (reg, 0));
5327 if (*reg_prefix == '\0')
5329 fc->col_type[reg] = cie->col_type[reg];
5330 fc->col_offset[reg] = cie->col_offset[reg];
5334 case DW_CFA_undefined:
5336 if (reg >= (unsigned int) fc->ncols)
5337 reg_prefix = bad_reg;
5338 if (! do_debug_frames_interp || *reg_prefix != '\0')
5339 printf (" DW_CFA_undefined: %s%s\n",
5340 reg_prefix, regname (reg, 0));
5341 if (*reg_prefix == '\0')
5343 fc->col_type[reg] = DW_CFA_undefined;
5344 fc->col_offset[reg] = 0;
5348 case DW_CFA_same_value:
5350 if (reg >= (unsigned int) fc->ncols)
5351 reg_prefix = bad_reg;
5352 if (! do_debug_frames_interp || *reg_prefix != '\0')
5353 printf (" DW_CFA_same_value: %s%s\n",
5354 reg_prefix, regname (reg, 0));
5355 if (*reg_prefix == '\0')
5357 fc->col_type[reg] = DW_CFA_same_value;
5358 fc->col_offset[reg] = 0;
5362 case DW_CFA_register:
5365 if (reg >= (unsigned int) fc->ncols)
5366 reg_prefix = bad_reg;
5367 if (! do_debug_frames_interp || *reg_prefix != '\0')
5369 printf (" DW_CFA_register: %s%s in ",
5370 reg_prefix, regname (reg, 0));
5371 puts (regname (roffs, 0));
5373 if (*reg_prefix == '\0')
5375 fc->col_type[reg] = DW_CFA_register;
5376 fc->col_offset[reg] = roffs;
5380 case DW_CFA_remember_state:
5381 if (! do_debug_frames_interp)
5382 printf (" DW_CFA_remember_state\n");
5383 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5384 rs->ncols = fc->ncols;
5385 rs->col_type = (short int *) xcmalloc (rs->ncols,
5386 sizeof (short int));
5387 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
5388 memcpy (rs->col_type, fc->col_type, rs->ncols);
5389 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5390 rs->next = remembered_state;
5391 remembered_state = rs;
5394 case DW_CFA_restore_state:
5395 if (! do_debug_frames_interp)
5396 printf (" DW_CFA_restore_state\n");
5397 rs = remembered_state;
5400 remembered_state = rs->next;
5401 frame_need_space (fc, rs->ncols - 1);
5402 memcpy (fc->col_type, rs->col_type, rs->ncols);
5403 memcpy (fc->col_offset, rs->col_offset,
5404 rs->ncols * sizeof (int));
5405 free (rs->col_type);
5406 free (rs->col_offset);
5409 else if (do_debug_frames_interp)
5410 printf ("Mismatched DW_CFA_restore_state\n");
5413 case DW_CFA_def_cfa:
5414 fc->cfa_reg = LEB ();
5415 fc->cfa_offset = LEB ();
5417 if (! do_debug_frames_interp)
5418 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5419 regname (fc->cfa_reg, 0), fc->cfa_offset);
5422 case DW_CFA_def_cfa_register:
5423 fc->cfa_reg = LEB ();
5425 if (! do_debug_frames_interp)
5426 printf (" DW_CFA_def_cfa_register: %s\n",
5427 regname (fc->cfa_reg, 0));
5430 case DW_CFA_def_cfa_offset:
5431 fc->cfa_offset = LEB ();
5432 if (! do_debug_frames_interp)
5433 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5437 if (! do_debug_frames_interp)
5438 printf (" DW_CFA_nop\n");
5441 case DW_CFA_def_cfa_expression:
5443 if (! do_debug_frames_interp)
5445 printf (" DW_CFA_def_cfa_expression (");
5446 decode_location_expression (start, eh_addr_size, 0, -1,
5454 case DW_CFA_expression:
5457 if (reg >= (unsigned int) fc->ncols)
5458 reg_prefix = bad_reg;
5459 if (! do_debug_frames_interp || *reg_prefix != '\0')
5461 printf (" DW_CFA_expression: %s%s (",
5462 reg_prefix, regname (reg, 0));
5463 decode_location_expression (start, eh_addr_size, 0, -1,
5467 if (*reg_prefix == '\0')
5468 fc->col_type[reg] = DW_CFA_expression;
5472 case DW_CFA_val_expression:
5475 if (reg >= (unsigned int) fc->ncols)
5476 reg_prefix = bad_reg;
5477 if (! do_debug_frames_interp || *reg_prefix != '\0')
5479 printf (" DW_CFA_val_expression: %s%s (",
5480 reg_prefix, regname (reg, 0));
5481 decode_location_expression (start, eh_addr_size, 0, -1,
5485 if (*reg_prefix == '\0')
5486 fc->col_type[reg] = DW_CFA_val_expression;
5490 case DW_CFA_offset_extended_sf:
5493 if (frame_need_space (fc, reg) < 0)
5494 reg_prefix = bad_reg;
5495 if (! do_debug_frames_interp || *reg_prefix != '\0')
5496 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5497 reg_prefix, regname (reg, 0),
5498 l * fc->data_factor);
5499 if (*reg_prefix == '\0')
5501 fc->col_type[reg] = DW_CFA_offset;
5502 fc->col_offset[reg] = l * fc->data_factor;
5506 case DW_CFA_val_offset_sf:
5509 if (frame_need_space (fc, reg) < 0)
5510 reg_prefix = bad_reg;
5511 if (! do_debug_frames_interp || *reg_prefix != '\0')
5512 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5513 reg_prefix, regname (reg, 0),
5514 l * fc->data_factor);
5515 if (*reg_prefix == '\0')
5517 fc->col_type[reg] = DW_CFA_val_offset;
5518 fc->col_offset[reg] = l * fc->data_factor;
5522 case DW_CFA_def_cfa_sf:
5523 fc->cfa_reg = LEB ();
5524 fc->cfa_offset = SLEB ();
5525 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5527 if (! do_debug_frames_interp)
5528 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5529 regname (fc->cfa_reg, 0), fc->cfa_offset);
5532 case DW_CFA_def_cfa_offset_sf:
5533 fc->cfa_offset = SLEB ();
5534 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5535 if (! do_debug_frames_interp)
5536 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5539 case DW_CFA_MIPS_advance_loc8:
5540 ofs = byte_get (start, 8); start += 8;
5541 if (do_debug_frames_interp)
5542 frame_display_row (fc, &need_col_headers, &max_regs);
5544 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5545 ofs * fc->code_factor,
5546 fc->pc_begin + ofs * fc->code_factor);
5547 fc->pc_begin += ofs * fc->code_factor;
5550 case DW_CFA_GNU_window_save:
5551 if (! do_debug_frames_interp)
5552 printf (" DW_CFA_GNU_window_save\n");
5555 case DW_CFA_GNU_args_size:
5557 if (! do_debug_frames_interp)
5558 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5561 case DW_CFA_GNU_negative_offset_extended:
5564 if (frame_need_space (fc, reg) < 0)
5565 reg_prefix = bad_reg;
5566 if (! do_debug_frames_interp || *reg_prefix != '\0')
5567 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5568 reg_prefix, regname (reg, 0),
5569 l * fc->data_factor);
5570 if (*reg_prefix == '\0')
5572 fc->col_type[reg] = DW_CFA_offset;
5573 fc->col_offset[reg] = l * fc->data_factor;
5578 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5579 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5581 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5586 if (do_debug_frames_interp)
5587 frame_display_row (fc, &need_col_headers, &max_regs);
5590 eh_addr_size = saved_eh_addr_size;
5603 display_gdb_index (struct dwarf_section *section,
5604 void *file ATTRIBUTE_UNUSED)
5606 unsigned char *start = section->start;
5608 uint32_t cu_list_offset, tu_list_offset;
5609 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5610 unsigned int cu_list_elements, tu_list_elements;
5611 unsigned int address_table_size, symbol_table_slots;
5612 unsigned char *cu_list, *tu_list;
5613 unsigned char *address_table, *symbol_table, *constant_pool;
5616 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5618 printf (_("Contents of the %s section:\n"), section->name);
5620 if (section->size < 6 * sizeof (uint32_t))
5622 warn (_("Truncated header in the %s section.\n"), section->name);
5626 version = byte_get_little_endian (start, 4);
5627 printf (_("Version %ld\n"), (long) version);
5629 /* Prior versions are obsolete, and future versions may not be
5630 backwards compatible. */
5634 warn (_("The address table data in version 3 may be wrong.\n"));
5637 warn (_("Version 4 does not support case insensitive lookups.\n"));
5640 warn (_("Version 5 does not include inlined functions.\n"));
5645 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5649 cu_list_offset = byte_get_little_endian (start + 4, 4);
5650 tu_list_offset = byte_get_little_endian (start + 8, 4);
5651 address_table_offset = byte_get_little_endian (start + 12, 4);
5652 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5653 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5655 if (cu_list_offset > section->size
5656 || tu_list_offset > section->size
5657 || address_table_offset > section->size
5658 || symbol_table_offset > section->size
5659 || constant_pool_offset > section->size)
5661 warn (_("Corrupt header in the %s section.\n"), section->name);
5665 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5666 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5667 address_table_size = symbol_table_offset - address_table_offset;
5668 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5670 cu_list = start + cu_list_offset;
5671 tu_list = start + tu_list_offset;
5672 address_table = start + address_table_offset;
5673 symbol_table = start + symbol_table_offset;
5674 constant_pool = start + constant_pool_offset;
5676 printf (_("\nCU table:\n"));
5677 for (i = 0; i < cu_list_elements; i += 2)
5679 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5680 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5682 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5683 (unsigned long) cu_offset,
5684 (unsigned long) (cu_offset + cu_length - 1));
5687 printf (_("\nTU table:\n"));
5688 for (i = 0; i < tu_list_elements; i += 3)
5690 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5691 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5692 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5694 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5695 (unsigned long) tu_offset,
5696 (unsigned long) type_offset);
5697 print_dwarf_vma (signature, 8);
5701 printf (_("\nAddress table:\n"));
5702 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5704 uint64_t low = byte_get_little_endian (address_table + i, 8);
5705 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5706 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5708 print_dwarf_vma (low, 8);
5709 print_dwarf_vma (high, 8);
5710 printf (_("%lu\n"), (unsigned long) cu_index);
5713 printf (_("\nSymbol table:\n"));
5714 for (i = 0; i < symbol_table_slots; ++i)
5716 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5717 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5718 uint32_t num_cus, cu;
5720 if (name_offset != 0
5721 || cu_vector_offset != 0)
5725 printf ("[%3u] %s:", i, constant_pool + name_offset);
5726 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5727 for (j = 0; j < num_cus; ++j)
5729 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5730 /* Convert to TU number if it's for a type unit. */
5731 if (cu >= cu_list_elements / 2)
5732 printf (" T%lu", (unsigned long) (cu - cu_list_elements / 2));
5734 printf (" %lu", (unsigned long) cu);
5744 display_debug_not_supported (struct dwarf_section *section,
5745 void *file ATTRIBUTE_UNUSED)
5747 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5754 cmalloc (size_t nmemb, size_t size)
5756 /* Check for overflow. */
5757 if (nmemb >= ~(size_t) 0 / size)
5760 return malloc (nmemb * size);
5764 xcmalloc (size_t nmemb, size_t size)
5766 /* Check for overflow. */
5767 if (nmemb >= ~(size_t) 0 / size)
5770 return xmalloc (nmemb * size);
5774 xcrealloc (void *ptr, size_t nmemb, size_t size)
5776 /* Check for overflow. */
5777 if (nmemb >= ~(size_t) 0 / size)
5780 return xrealloc (ptr, nmemb * size);
5784 free_debug_memory (void)
5790 for (i = 0; i < max; i++)
5791 free_debug_section ((enum dwarf_section_display_enum) i);
5793 if (debug_information != NULL)
5795 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
5797 for (i = 0; i < num_debug_info_entries; i++)
5799 if (!debug_information [i].max_loc_offsets)
5801 free (debug_information [i].loc_offsets);
5802 free (debug_information [i].have_frame_base);
5804 if (!debug_information [i].max_range_lists)
5805 free (debug_information [i].range_lists);
5809 free (debug_information);
5810 debug_information = NULL;
5811 num_debug_info_entries = 0;
5816 dwarf_select_sections_by_names (const char *names)
5820 const char * option;
5824 debug_dump_long_opts;
5826 static const debug_dump_long_opts opts_table [] =
5828 /* Please keep this table alpha- sorted. */
5829 { "Ranges", & do_debug_ranges, 1 },
5830 { "abbrev", & do_debug_abbrevs, 1 },
5831 { "aranges", & do_debug_aranges, 1 },
5832 { "frames", & do_debug_frames, 1 },
5833 { "frames-interp", & do_debug_frames_interp, 1 },
5834 { "info", & do_debug_info, 1 },
5835 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5836 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5837 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5838 { "loc", & do_debug_loc, 1 },
5839 { "macro", & do_debug_macinfo, 1 },
5840 { "pubnames", & do_debug_pubnames, 1 },
5841 { "pubtypes", & do_debug_pubtypes, 1 },
5842 /* This entry is for compatability
5843 with earlier versions of readelf. */
5844 { "ranges", & do_debug_aranges, 1 },
5845 { "str", & do_debug_str, 1 },
5846 /* The special .gdb_index section. */
5847 { "gdb_index", & do_gdb_index, 1 },
5848 /* These trace_* sections are used by Itanium VMS. */
5849 { "trace_abbrev", & do_trace_abbrevs, 1 },
5850 { "trace_aranges", & do_trace_aranges, 1 },
5851 { "trace_info", & do_trace_info, 1 },
5860 const debug_dump_long_opts * entry;
5862 for (entry = opts_table; entry->option; entry++)
5864 size_t len = strlen (entry->option);
5866 if (strncmp (p, entry->option, len) == 0
5867 && (p[len] == ',' || p[len] == '\0'))
5869 * entry->variable |= entry->val;
5871 /* The --debug-dump=frames-interp option also
5872 enables the --debug-dump=frames option. */
5873 if (do_debug_frames_interp)
5874 do_debug_frames = 1;
5881 if (entry->option == NULL)
5883 warn (_("Unrecognized debug option '%s'\n"), p);
5884 p = strchr (p, ',');
5895 dwarf_select_sections_by_letters (const char *letters)
5897 unsigned int lindex = 0;
5899 while (letters[lindex])
5900 switch (letters[lindex++])
5907 do_debug_abbrevs = 1;
5911 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
5915 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
5919 do_debug_pubnames = 1;
5923 do_debug_pubtypes = 1;
5927 do_debug_aranges = 1;
5931 do_debug_ranges = 1;
5935 do_debug_frames_interp = 1;
5937 do_debug_frames = 1;
5941 do_debug_macinfo = 1;
5953 warn (_("Unrecognized debug option '%s'\n"), optarg);
5959 dwarf_select_sections_all (void)
5962 do_debug_abbrevs = 1;
5963 do_debug_lines = FLAG_DEBUG_LINES_RAW;
5964 do_debug_pubnames = 1;
5965 do_debug_pubtypes = 1;
5966 do_debug_aranges = 1;
5967 do_debug_ranges = 1;
5968 do_debug_frames = 1;
5969 do_debug_macinfo = 1;
5974 do_trace_abbrevs = 1;
5975 do_trace_aranges = 1;
5978 struct dwarf_section_display debug_displays[] =
5980 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, abbrev },
5981 display_debug_abbrev, &do_debug_abbrevs, 0 },
5982 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, abbrev },
5983 display_debug_aranges, &do_debug_aranges, 1 },
5984 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, abbrev },
5985 display_debug_frames, &do_debug_frames, 1 },
5986 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev },
5987 display_debug_info, &do_debug_info, 1 },
5988 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, abbrev },
5989 display_debug_lines, &do_debug_lines, 1 },
5990 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, abbrev },
5991 display_debug_pubnames, &do_debug_pubnames, 0 },
5992 { { ".eh_frame", "", NULL, NULL, 0, 0, abbrev },
5993 display_debug_frames, &do_debug_frames, 1 },
5994 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, abbrev },
5995 display_debug_macinfo, &do_debug_macinfo, 0 },
5996 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, abbrev },
5997 display_debug_macro, &do_debug_macinfo, 1 },
5998 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, abbrev },
5999 display_debug_str, &do_debug_str, 0 },
6000 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, abbrev },
6001 display_debug_loc, &do_debug_loc, 1 },
6002 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, abbrev },
6003 display_debug_pubnames, &do_debug_pubtypes, 0 },
6004 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, abbrev },
6005 display_debug_ranges, &do_debug_ranges, 1 },
6006 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, abbrev },
6007 display_debug_not_supported, NULL, 0 },
6008 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, abbrev },
6009 display_debug_not_supported, NULL, 0 },
6010 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev },
6011 display_debug_types, &do_debug_info, 1 },
6012 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, abbrev },
6013 display_debug_not_supported, NULL, 0 },
6014 { { ".gdb_index", "", NULL, NULL, 0, 0, abbrev },
6015 display_gdb_index, &do_gdb_index, 0 },
6016 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev },
6017 display_trace_info, &do_trace_info, 1 },
6018 { { ".trace_abbrev", "", NULL, NULL, 0, 0, abbrev },
6019 display_debug_abbrev, &do_trace_abbrevs, 0 },
6020 { { ".trace_aranges", "", NULL, NULL, 0, 0, abbrev },
6021 display_debug_aranges, &do_trace_aranges, 0 },
6022 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6023 display_debug_info, &do_debug_info, 1 },
6024 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6025 display_debug_abbrev, &do_debug_abbrevs, 0 },
6026 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6027 display_debug_types, &do_debug_info, 1 },
6028 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6029 display_debug_lines, &do_debug_lines, 1 },
6030 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6031 display_debug_loc, &do_debug_loc, 1 },
6032 { { ".debug_macro.dwo", ".zdebug_macro.dwo",NULL, NULL, 0, 0, abbrev },
6033 display_debug_macro, &do_debug_macinfo, 1 },
6034 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo",NULL, NULL, 0, 0, abbrev },
6035 display_debug_macinfo, &do_debug_macinfo, 0 },
6036 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, str_dwo },
6037 display_debug_str, &do_debug_str, 1 },
6038 { { ".debug_str_offsets",".zdebug_str_offsets", NULL, NULL, 0, 0, abbrev },
6039 display_debug_str_offsets, NULL, 0 },
6040 { { ".debug_str_offsets.dwo",".zdebug_str_offsets.dwo", NULL, NULL, 0, 0,
6042 display_debug_str_offsets, NULL, 0 },
6043 { { ".debug_addr",".zdebug_addr", NULL, NULL, 0, 0, debug_addr },
6044 display_debug_addr, NULL, 1 },