1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
3 Free Software Foundation, Inc.
5 This file is part of GNU Binutils.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
23 #include "libiberty.h"
25 #include "bfd_stdint.h"
28 #include "elf/common.h"
31 #include "gdb/gdb-index.h"
33 static const char *regname (unsigned int regno, int row);
35 static int have_frame_base;
36 static int need_base_address;
38 static unsigned int last_pointer_size = 0;
39 static int warned_about_missing_comp_units = FALSE;
41 static unsigned int num_debug_info_entries = 0;
42 static debug_info *debug_information = NULL;
43 /* Special value for num_debug_info_entries to indicate
44 that the .debug_info section could not be loaded/parsed. */
45 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
52 int do_debug_pubnames;
53 int do_debug_pubtypes;
57 int do_debug_frames_interp;
66 int do_debug_cu_index;
69 int dwarf_cutoff_level = -1;
70 unsigned long dwarf_start_die;
74 /* Values for do_debug_lines. */
75 #define FLAG_DEBUG_LINES_RAW 1
76 #define FLAG_DEBUG_LINES_DECODED 2
79 size_of_encoded_value (int encoding)
81 switch (encoding & 0x7)
84 case 0: return eh_addr_size;
92 get_encoded_value (unsigned char *data,
94 struct dwarf_section *section)
96 int size = size_of_encoded_value (encoding);
99 if (encoding & DW_EH_PE_signed)
100 val = byte_get_signed (data, size);
102 val = byte_get (data, size);
104 if ((encoding & 0x70) == DW_EH_PE_pcrel)
105 val += section->address + (data - section->start);
109 /* Print a dwarf_vma value (typically an address, offset or length) in
110 hexadecimal format, followed by a space. The length of the value (and
111 hence the precision displayed) is determined by the byte_size parameter. */
114 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
116 static char buff[18];
119 /* Printf does not have a way of specifiying a maximum field width for an
120 integer value, so we print the full value into a buffer and then select
121 the precision we need. */
122 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
124 snprintf (buff, sizeof (buff), "%16.16llx ", val);
126 snprintf (buff, sizeof (buff), "%016I64x ", val);
129 snprintf (buff, sizeof (buff), "%16.16lx ", val);
134 if (byte_size > 0 && byte_size <= 8)
135 offset = 16 - 2 * byte_size;
137 error (_("Wrong size in print_dwarf_vma"));
140 fputs (buff + offset, stdout);
143 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
145 #define DWARF_VMA_FMT "ll"
147 #define DWARF_VMA_FMT "I64"
150 #define DWARF_VMA_FMT "l"
154 dwarf_vmatoa (const char *fmtch, dwarf_vma value)
156 /* As dwarf_vmatoa is used more then once in a printf call
157 for output, we are cycling through an fixed array of pointers
158 for return address. */
159 static int buf_pos = 0;
160 static struct dwarf_vmatoa_buf
167 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
169 ret = buf[buf_pos++].place;
170 buf_pos %= ARRAY_SIZE (buf);
172 snprintf (ret, sizeof (buf[0].place), fmt, value);
177 /* Format a 64-bit value, given as two 32-bit values, in hex.
178 For reentrancy, this uses a buffer provided by the caller. */
181 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
182 unsigned int buf_len)
187 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
190 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
191 snprintf (buf + len, buf_len - len,
192 "%08" DWARF_VMA_FMT "x", lvalue);
199 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
201 dwarf_vma result = 0;
202 unsigned int num_read = 0;
203 unsigned int shift = 0;
211 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
218 if (length_return != NULL)
219 *length_return = num_read;
221 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
222 result |= -1L << shift;
227 /* Create a signed version to avoid painful typecasts. */
228 static dwarf_signed_vma
229 read_sleb128 (unsigned char *data, unsigned int *length_return)
231 return (dwarf_signed_vma) read_leb128 (data, length_return, 1);
234 typedef struct State_Machine_Registers
242 unsigned char op_index;
243 unsigned char end_sequence;
244 /* This variable hold the number of the last entry seen
245 in the File Table. */
246 unsigned int last_file_entry;
249 static SMR state_machine_regs;
252 reset_state_machine (int is_stmt)
254 state_machine_regs.address = 0;
255 state_machine_regs.op_index = 0;
256 state_machine_regs.file = 1;
257 state_machine_regs.line = 1;
258 state_machine_regs.column = 0;
259 state_machine_regs.is_stmt = is_stmt;
260 state_machine_regs.basic_block = 0;
261 state_machine_regs.end_sequence = 0;
262 state_machine_regs.last_file_entry = 0;
265 /* Handled an extend line op.
266 Returns the number of bytes read. */
269 process_extended_line_op (unsigned char *data, int is_stmt)
271 unsigned char op_code;
272 unsigned int bytes_read;
276 unsigned char *orig_data = data;
278 len = read_leb128 (data, & bytes_read, 0);
283 warn (_("badly formed extended line op encountered!\n"));
290 printf (_(" Extended opcode %d: "), op_code);
294 case DW_LNE_end_sequence:
295 printf (_("End of Sequence\n\n"));
296 reset_state_machine (is_stmt);
299 case DW_LNE_set_address:
300 adr = byte_get (data, len - bytes_read - 1);
301 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
302 state_machine_regs.address = adr;
303 state_machine_regs.op_index = 0;
306 case DW_LNE_define_file:
307 printf (_("define new File Table entry\n"));
308 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
310 printf (" %d\t", ++state_machine_regs.last_file_entry);
312 data += strlen ((char *) data) + 1;
313 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
315 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
317 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
320 if ((unsigned int) (data - orig_data) != len)
321 printf (_(" [Bad opcode length]"));
325 case DW_LNE_set_discriminator:
326 printf (_("set Discriminator to %s\n"),
327 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
331 case DW_LNE_HP_negate_is_UV_update:
332 printf ("DW_LNE_HP_negate_is_UV_update\n");
334 case DW_LNE_HP_push_context:
335 printf ("DW_LNE_HP_push_context\n");
337 case DW_LNE_HP_pop_context:
338 printf ("DW_LNE_HP_pop_context\n");
340 case DW_LNE_HP_set_file_line_column:
341 printf ("DW_LNE_HP_set_file_line_column\n");
343 case DW_LNE_HP_set_routine_name:
344 printf ("DW_LNE_HP_set_routine_name\n");
346 case DW_LNE_HP_set_sequence:
347 printf ("DW_LNE_HP_set_sequence\n");
349 case DW_LNE_HP_negate_post_semantics:
350 printf ("DW_LNE_HP_negate_post_semantics\n");
352 case DW_LNE_HP_negate_function_exit:
353 printf ("DW_LNE_HP_negate_function_exit\n");
355 case DW_LNE_HP_negate_front_end_logical:
356 printf ("DW_LNE_HP_negate_front_end_logical\n");
358 case DW_LNE_HP_define_proc:
359 printf ("DW_LNE_HP_define_proc\n");
361 case DW_LNE_HP_source_file_correlation:
363 unsigned char *edata = data + len - bytes_read - 1;
365 printf ("DW_LNE_HP_source_file_correlation\n");
371 opc = read_leb128 (data, & bytes_read, 0);
376 case DW_LNE_HP_SFC_formfeed:
377 printf (" DW_LNE_HP_SFC_formfeed\n");
379 case DW_LNE_HP_SFC_set_listing_line:
380 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
382 read_leb128 (data, & bytes_read, 0)));
385 case DW_LNE_HP_SFC_associate:
386 printf (" DW_LNE_HP_SFC_associate ");
389 read_leb128 (data, & bytes_read, 0)));
393 read_leb128 (data, & bytes_read, 0)));
397 read_leb128 (data, & bytes_read, 0)));
401 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
411 unsigned int rlen = len - bytes_read - 1;
413 if (op_code >= DW_LNE_lo_user
414 /* The test against DW_LNW_hi_user is redundant due to
415 the limited range of the unsigned char data type used
417 /*&& op_code <= DW_LNE_hi_user*/)
418 printf (_("user defined: "));
420 printf (_("UNKNOWN: "));
421 printf (_("length %d ["), rlen);
423 printf (" %02x", *data++);
433 fetch_indirect_string (dwarf_vma offset)
435 struct dwarf_section *section = &debug_displays [str].section;
437 if (section->start == NULL)
438 return _("<no .debug_str section>");
440 /* DWARF sections under Mach-O have non-zero addresses. */
441 offset -= section->address;
442 if (offset > section->size)
444 warn (_("DW_FORM_strp offset too big: %s\n"),
445 dwarf_vmatoa ("x", offset));
446 return _("<offset is too big>");
449 return (const char *) section->start + offset;
453 fetch_indexed_string (dwarf_vma idx, dwarf_vma offset_size, int dwo)
455 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
456 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
457 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
458 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
459 dwarf_vma index_offset = idx * offset_size;
460 dwarf_vma str_offset;
462 if (index_section->start == NULL)
463 return (dwo ? _("<no .debug_str_offsets.dwo section>")
464 : _("<no .debug_str_offsets section>"));
466 /* DWARF sections under Mach-O have non-zero addresses. */
467 index_offset -= index_section->address;
468 if (index_offset > index_section->size)
470 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
471 dwarf_vmatoa ("x", index_offset));
472 return _("<index offset is too big>");
475 if (str_section->start == NULL)
476 return (dwo ? _("<no .debug_str.dwo section>")
477 : _("<no .debug_str section>"));
479 str_offset = byte_get (index_section->start + index_offset, offset_size);
480 str_offset -= str_section->address;
481 if (str_offset > str_section->size)
483 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
484 dwarf_vmatoa ("x", str_offset));
485 return _("<indirect index offset is too big>");
488 return (const char *) str_section->start + str_offset;
492 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
494 struct dwarf_section *section = &debug_displays [debug_addr].section;
496 if (section->start == NULL)
497 return (_("<no .debug_addr section>"));
499 if (offset + bytes > section->size)
501 warn (_("Offset into section %s too big: %s\n"),
502 section->name, dwarf_vmatoa ("x", offset));
503 return "<offset too big>";
506 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
510 /* FIXME: There are better and more efficient ways to handle
511 these structures. For now though, I just want something that
512 is simple to implement. */
513 typedef struct abbrev_attr
515 unsigned long attribute;
517 struct abbrev_attr *next;
521 typedef struct abbrev_entry
526 struct abbrev_attr *first_attr;
527 struct abbrev_attr *last_attr;
528 struct abbrev_entry *next;
532 static abbrev_entry *first_abbrev = NULL;
533 static abbrev_entry *last_abbrev = NULL;
540 for (abbrv = first_abbrev; abbrv;)
542 abbrev_entry *next_abbrev = abbrv->next;
545 for (attr = abbrv->first_attr; attr;)
547 abbrev_attr *next_attr = attr->next;
557 last_abbrev = first_abbrev = NULL;
561 add_abbrev (unsigned long number, unsigned long tag, int children)
565 entry = (abbrev_entry *) malloc (sizeof (*entry));
570 entry->entry = number;
572 entry->children = children;
573 entry->first_attr = NULL;
574 entry->last_attr = NULL;
577 if (first_abbrev == NULL)
578 first_abbrev = entry;
580 last_abbrev->next = entry;
586 add_abbrev_attr (unsigned long attribute, unsigned long form)
590 attr = (abbrev_attr *) malloc (sizeof (*attr));
595 attr->attribute = attribute;
599 if (last_abbrev->first_attr == NULL)
600 last_abbrev->first_attr = attr;
602 last_abbrev->last_attr->next = attr;
604 last_abbrev->last_attr = attr;
607 /* Processes the (partial) contents of a .debug_abbrev section.
608 Returns NULL if the end of the section was encountered.
609 Returns the address after the last byte read if the end of
610 an abbreviation set was found. */
612 static unsigned char *
613 process_abbrev_section (unsigned char *start, unsigned char *end)
615 if (first_abbrev != NULL)
620 unsigned int bytes_read;
623 unsigned long attribute;
626 entry = read_leb128 (start, & bytes_read, 0);
629 /* A single zero is supposed to end the section according
630 to the standard. If there's more, then signal that to
633 return start == end ? NULL : start;
635 tag = read_leb128 (start, & bytes_read, 0);
640 add_abbrev (entry, tag, children);
646 attribute = read_leb128 (start, & bytes_read, 0);
649 form = read_leb128 (start, & bytes_read, 0);
652 add_abbrev_attr (attribute, form);
654 while (attribute != 0);
657 /* Report the missing single zero which ends the section. */
658 error (_(".debug_abbrev section not zero terminated\n"));
664 get_TAG_name (unsigned long tag)
666 const char *name = get_DW_TAG_name ((unsigned int)tag);
670 static char buffer[100];
672 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
680 get_FORM_name (unsigned long form)
685 return "DW_FORM value: 0";
687 name = get_DW_FORM_name (form);
690 static char buffer[100];
692 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
699 static unsigned char *
700 display_block (unsigned char *data, dwarf_vma length)
702 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
705 printf ("%lx ", (unsigned long) byte_get (data++, 1));
711 decode_location_expression (unsigned char * data,
712 unsigned int pointer_size,
713 unsigned int offset_size,
717 struct dwarf_section * section)
720 unsigned int bytes_read;
722 unsigned char *end = data + length;
723 int need_frame_base = 0;
732 printf ("DW_OP_addr: %s",
733 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
734 data += pointer_size;
737 printf ("DW_OP_deref");
740 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
743 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
746 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
750 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
754 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
758 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
762 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
763 (unsigned long) byte_get (data + 4, 4));
767 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
768 (long) byte_get (data + 4, 4));
772 printf ("DW_OP_constu: %s",
773 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
777 printf ("DW_OP_consts: %s",
778 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
782 printf ("DW_OP_dup");
785 printf ("DW_OP_drop");
788 printf ("DW_OP_over");
791 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
794 printf ("DW_OP_swap");
797 printf ("DW_OP_rot");
800 printf ("DW_OP_xderef");
803 printf ("DW_OP_abs");
806 printf ("DW_OP_and");
809 printf ("DW_OP_div");
812 printf ("DW_OP_minus");
815 printf ("DW_OP_mod");
818 printf ("DW_OP_mul");
821 printf ("DW_OP_neg");
824 printf ("DW_OP_not");
830 printf ("DW_OP_plus");
832 case DW_OP_plus_uconst:
833 printf ("DW_OP_plus_uconst: %s",
834 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
838 printf ("DW_OP_shl");
841 printf ("DW_OP_shr");
844 printf ("DW_OP_shra");
847 printf ("DW_OP_xor");
850 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
872 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
908 printf ("DW_OP_lit%d", op - DW_OP_lit0);
943 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
944 regname (op - DW_OP_reg0, 1));
979 printf ("DW_OP_breg%d (%s): %s",
981 regname (op - DW_OP_breg0, 1),
982 dwarf_vmatoa ("d", (dwarf_signed_vma)
983 read_leb128 (data, &bytes_read, 1)));
988 uvalue = read_leb128 (data, &bytes_read, 0);
990 printf ("DW_OP_regx: %s (%s)",
991 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
995 printf ("DW_OP_fbreg: %s",
996 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1000 uvalue = read_leb128 (data, &bytes_read, 0);
1002 printf ("DW_OP_bregx: %s (%s) %s",
1003 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1004 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1008 printf ("DW_OP_piece: %s",
1009 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1012 case DW_OP_deref_size:
1013 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
1015 case DW_OP_xderef_size:
1016 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
1019 printf ("DW_OP_nop");
1022 /* DWARF 3 extensions. */
1023 case DW_OP_push_object_address:
1024 printf ("DW_OP_push_object_address");
1027 /* XXX: Strictly speaking for 64-bit DWARF3 files
1028 this ought to be an 8-byte wide computation. */
1029 printf ("DW_OP_call2: <0x%s>",
1030 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2)
1035 /* XXX: Strictly speaking for 64-bit DWARF3 files
1036 this ought to be an 8-byte wide computation. */
1037 printf ("DW_OP_call4: <0x%s>",
1038 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4)
1042 case DW_OP_call_ref:
1043 /* XXX: Strictly speaking for 64-bit DWARF3 files
1044 this ought to be an 8-byte wide computation. */
1045 if (dwarf_version == -1)
1047 printf (_("(DW_OP_call_ref in frame info)"));
1048 /* No way to tell where the next op is, so just bail. */
1049 return need_frame_base;
1051 if (dwarf_version == 2)
1053 printf ("DW_OP_call_ref: <0x%s>",
1054 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
1055 data += pointer_size;
1059 printf ("DW_OP_call_ref: <0x%s>",
1060 dwarf_vmatoa ("x", byte_get (data, offset_size)));
1061 data += offset_size;
1064 case DW_OP_form_tls_address:
1065 printf ("DW_OP_form_tls_address");
1067 case DW_OP_call_frame_cfa:
1068 printf ("DW_OP_call_frame_cfa");
1070 case DW_OP_bit_piece:
1071 printf ("DW_OP_bit_piece: ");
1072 printf (_("size: %s "),
1073 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1075 printf (_("offset: %s "),
1076 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1080 /* DWARF 4 extensions. */
1081 case DW_OP_stack_value:
1082 printf ("DW_OP_stack_value");
1085 case DW_OP_implicit_value:
1086 printf ("DW_OP_implicit_value");
1087 uvalue = read_leb128 (data, &bytes_read, 0);
1089 display_block (data, uvalue);
1093 /* GNU extensions. */
1094 case DW_OP_GNU_push_tls_address:
1095 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1097 case DW_OP_GNU_uninit:
1098 printf ("DW_OP_GNU_uninit");
1099 /* FIXME: Is there data associated with this OP ? */
1101 case DW_OP_GNU_encoded_addr:
1107 addr = get_encoded_value (data, encoding, section);
1108 data += size_of_encoded_value (encoding);
1110 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1111 print_dwarf_vma (addr, pointer_size);
1114 case DW_OP_GNU_implicit_pointer:
1115 /* XXX: Strictly speaking for 64-bit DWARF3 files
1116 this ought to be an 8-byte wide computation. */
1117 if (dwarf_version == -1)
1119 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1120 /* No way to tell where the next op is, so just bail. */
1121 return need_frame_base;
1123 if (dwarf_version == 2)
1125 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1126 dwarf_vmatoa ("x", byte_get (data, pointer_size)),
1127 dwarf_vmatoa ("d", read_sleb128 (data + pointer_size,
1129 data += pointer_size + bytes_read;
1133 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1134 dwarf_vmatoa ("x", byte_get (data, offset_size)),
1135 dwarf_vmatoa ("d", read_sleb128 (data + offset_size,
1137 data += offset_size + bytes_read;
1140 case DW_OP_GNU_entry_value:
1141 uvalue = read_leb128 (data, &bytes_read, 0);
1143 printf ("DW_OP_GNU_entry_value: (");
1144 if (decode_location_expression (data, pointer_size, offset_size,
1145 dwarf_version, uvalue,
1146 cu_offset, section))
1147 need_frame_base = 1;
1151 case DW_OP_GNU_const_type:
1152 uvalue = read_leb128 (data, &bytes_read, 0);
1154 printf ("DW_OP_GNU_const_type: <0x%s> ",
1155 dwarf_vmatoa ("x", cu_offset + uvalue));
1156 uvalue = byte_get (data++, 1);
1157 display_block (data, uvalue);
1160 case DW_OP_GNU_regval_type:
1161 uvalue = read_leb128 (data, &bytes_read, 0);
1163 printf ("DW_OP_GNU_regval_type: %s (%s)",
1164 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1165 uvalue = read_leb128 (data, &bytes_read, 0);
1167 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1169 case DW_OP_GNU_deref_type:
1170 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data++, 1));
1171 uvalue = read_leb128 (data, &bytes_read, 0);
1173 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1175 case DW_OP_GNU_convert:
1176 uvalue = read_leb128 (data, &bytes_read, 0);
1178 printf ("DW_OP_GNU_convert <0x%s>",
1179 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1181 case DW_OP_GNU_reinterpret:
1182 uvalue = read_leb128 (data, &bytes_read, 0);
1184 printf ("DW_OP_GNU_reinterpret <0x%s>",
1185 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1187 case DW_OP_GNU_parameter_ref:
1188 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1189 dwarf_vmatoa ("x", cu_offset + byte_get (data, 4)));
1192 case DW_OP_GNU_addr_index:
1193 uvalue = read_leb128 (data, &bytes_read, 0);
1195 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1197 case DW_OP_GNU_const_index:
1198 uvalue = read_leb128 (data, &bytes_read, 0);
1200 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1203 /* HP extensions. */
1204 case DW_OP_HP_is_value:
1205 printf ("DW_OP_HP_is_value");
1206 /* FIXME: Is there data associated with this OP ? */
1208 case DW_OP_HP_fltconst4:
1209 printf ("DW_OP_HP_fltconst4");
1210 /* FIXME: Is there data associated with this OP ? */
1212 case DW_OP_HP_fltconst8:
1213 printf ("DW_OP_HP_fltconst8");
1214 /* FIXME: Is there data associated with this OP ? */
1216 case DW_OP_HP_mod_range:
1217 printf ("DW_OP_HP_mod_range");
1218 /* FIXME: Is there data associated with this OP ? */
1220 case DW_OP_HP_unmod_range:
1221 printf ("DW_OP_HP_unmod_range");
1222 /* FIXME: Is there data associated with this OP ? */
1225 printf ("DW_OP_HP_tls");
1226 /* FIXME: Is there data associated with this OP ? */
1229 /* PGI (STMicroelectronics) extensions. */
1230 case DW_OP_PGI_omp_thread_num:
1231 /* Pushes the thread number for the current thread as it would be
1232 returned by the standard OpenMP library function:
1233 omp_get_thread_num(). The "current thread" is the thread for
1234 which the expression is being evaluated. */
1235 printf ("DW_OP_PGI_omp_thread_num");
1239 if (op >= DW_OP_lo_user
1240 && op <= DW_OP_hi_user)
1241 printf (_("(User defined location op)"));
1243 printf (_("(Unknown location op)"));
1244 /* No way to tell where the next op is, so just bail. */
1245 return need_frame_base;
1248 /* Separate the ops. */
1253 return need_frame_base;
1256 static unsigned char *
1257 read_and_display_attr_value (unsigned long attribute,
1259 unsigned char * data,
1260 dwarf_vma cu_offset,
1261 dwarf_vma pointer_size,
1262 dwarf_vma offset_size,
1264 debug_info * debug_info_p,
1266 struct dwarf_section * section)
1268 dwarf_vma uvalue = 0;
1269 unsigned char *block_start = NULL;
1270 unsigned char * orig_data = data;
1271 unsigned int bytes_read;
1278 case DW_FORM_ref_addr:
1279 if (dwarf_version == 2)
1281 uvalue = byte_get (data, pointer_size);
1282 data += pointer_size;
1284 else if (dwarf_version == 3 || dwarf_version == 4)
1286 uvalue = byte_get (data, offset_size);
1287 data += offset_size;
1290 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1295 uvalue = byte_get (data, pointer_size);
1296 data += pointer_size;
1300 case DW_FORM_sec_offset:
1301 case DW_FORM_GNU_ref_alt:
1302 case DW_FORM_GNU_strp_alt:
1303 uvalue = byte_get (data, offset_size);
1304 data += offset_size;
1307 case DW_FORM_flag_present:
1314 uvalue = byte_get (data++, 1);
1319 uvalue = byte_get (data, 2);
1325 uvalue = byte_get (data, 4);
1330 uvalue = read_leb128 (data, & bytes_read, 1);
1334 case DW_FORM_GNU_str_index:
1335 uvalue = read_leb128 (data, & bytes_read, 0);
1339 case DW_FORM_ref_udata:
1341 uvalue = read_leb128 (data, & bytes_read, 0);
1345 case DW_FORM_indirect:
1346 form = read_leb128 (data, & bytes_read, 0);
1349 printf (" %s", get_FORM_name (form));
1350 return read_and_display_attr_value (attribute, form, data,
1351 cu_offset, pointer_size,
1352 offset_size, dwarf_version,
1353 debug_info_p, do_loc,
1355 case DW_FORM_GNU_addr_index:
1356 uvalue = read_leb128 (data, & bytes_read, 0);
1363 case DW_FORM_ref_addr:
1365 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1368 case DW_FORM_GNU_ref_alt:
1370 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue));
1376 case DW_FORM_ref_udata:
1378 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1383 case DW_FORM_sec_offset:
1385 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1388 case DW_FORM_flag_present:
1395 printf (" %s", dwarf_vmatoa ("d", uvalue));
1402 dwarf_vma high_bits;
1405 byte_get_64 (data, &high_bits, &uvalue);
1407 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1409 if ((do_loc || do_debug_loc || do_debug_ranges)
1410 && num_debug_info_entries == 0)
1412 if (sizeof (uvalue) == 8)
1413 uvalue = byte_get (data, 8);
1415 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1420 case DW_FORM_string:
1422 printf (" %s", data);
1423 data += strlen ((char *) data) + 1;
1427 case DW_FORM_exprloc:
1428 uvalue = read_leb128 (data, & bytes_read, 0);
1429 block_start = data + bytes_read;
1431 data = block_start + uvalue;
1433 data = display_block (block_start, uvalue);
1436 case DW_FORM_block1:
1437 uvalue = byte_get (data, 1);
1438 block_start = data + 1;
1440 data = block_start + uvalue;
1442 data = display_block (block_start, uvalue);
1445 case DW_FORM_block2:
1446 uvalue = byte_get (data, 2);
1447 block_start = data + 2;
1449 data = block_start + uvalue;
1451 data = display_block (block_start, uvalue);
1454 case DW_FORM_block4:
1455 uvalue = byte_get (data, 4);
1456 block_start = data + 4;
1458 data = block_start + uvalue;
1460 data = display_block (block_start, uvalue);
1465 printf (_(" (indirect string, offset: 0x%s): %s"),
1466 dwarf_vmatoa ("x", uvalue),
1467 fetch_indirect_string (uvalue));
1470 case DW_FORM_GNU_str_index:
1473 const char *suffix = strrchr (section->name, '.');
1474 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1476 printf (_(" (indexed string: 0x%s): %s"),
1477 dwarf_vmatoa ("x", uvalue),
1478 fetch_indexed_string (uvalue, offset_size, dwo));
1482 case DW_FORM_GNU_strp_alt:
1484 printf (_(" (alt indirect string, offset: 0x%s)"),
1485 dwarf_vmatoa ("x", uvalue));
1488 case DW_FORM_indirect:
1489 /* Handled above. */
1492 case DW_FORM_ref_sig8:
1495 dwarf_vma high_bits;
1498 byte_get_64 (data, &high_bits, &uvalue);
1499 printf (" signature: 0x%s",
1500 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1505 case DW_FORM_GNU_addr_index:
1507 printf (_(" (addr_index: 0x%s): %s"),
1508 dwarf_vmatoa ("x", uvalue),
1509 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1513 warn (_("Unrecognized form: %lu\n"), form);
1517 if ((do_loc || do_debug_loc || do_debug_ranges)
1518 && num_debug_info_entries == 0
1519 && debug_info_p != NULL)
1523 case DW_AT_frame_base:
1524 have_frame_base = 1;
1525 case DW_AT_location:
1526 case DW_AT_string_length:
1527 case DW_AT_return_addr:
1528 case DW_AT_data_member_location:
1529 case DW_AT_vtable_elem_location:
1531 case DW_AT_static_link:
1532 case DW_AT_use_location:
1533 case DW_AT_GNU_call_site_value:
1534 case DW_AT_GNU_call_site_data_value:
1535 case DW_AT_GNU_call_site_target:
1536 case DW_AT_GNU_call_site_target_clobbered:
1537 if ((dwarf_version < 4
1538 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1539 || form == DW_FORM_sec_offset)
1541 /* Process location list. */
1542 unsigned int lmax = debug_info_p->max_loc_offsets;
1543 unsigned int num = debug_info_p->num_loc_offsets;
1545 if (lmax == 0 || num >= lmax)
1548 debug_info_p->loc_offsets = (dwarf_vma *)
1549 xcrealloc (debug_info_p->loc_offsets,
1550 lmax, sizeof (*debug_info_p->loc_offsets));
1551 debug_info_p->have_frame_base = (int *)
1552 xcrealloc (debug_info_p->have_frame_base,
1553 lmax, sizeof (*debug_info_p->have_frame_base));
1554 debug_info_p->max_loc_offsets = lmax;
1556 debug_info_p->loc_offsets [num] = uvalue;
1557 debug_info_p->have_frame_base [num] = have_frame_base;
1558 debug_info_p->num_loc_offsets++;
1563 if (need_base_address)
1564 debug_info_p->base_address = uvalue;
1567 case DW_AT_GNU_addr_base:
1568 debug_info_p->addr_base = uvalue;
1571 case DW_AT_GNU_ranges_base:
1572 debug_info_p->ranges_base = uvalue;
1576 if ((dwarf_version < 4
1577 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1578 || form == DW_FORM_sec_offset)
1580 /* Process range list. */
1581 unsigned int lmax = debug_info_p->max_range_lists;
1582 unsigned int num = debug_info_p->num_range_lists;
1584 if (lmax == 0 || num >= lmax)
1587 debug_info_p->range_lists = (dwarf_vma *)
1588 xcrealloc (debug_info_p->range_lists,
1589 lmax, sizeof (*debug_info_p->range_lists));
1590 debug_info_p->max_range_lists = lmax;
1592 debug_info_p->range_lists [num] = uvalue;
1593 debug_info_p->num_range_lists++;
1602 if (do_loc || attribute == 0)
1605 /* For some attributes we can display further information. */
1613 case DW_INL_not_inlined:
1614 printf (_("(not inlined)"));
1616 case DW_INL_inlined:
1617 printf (_("(inlined)"));
1619 case DW_INL_declared_not_inlined:
1620 printf (_("(declared as inline but ignored)"));
1622 case DW_INL_declared_inlined:
1623 printf (_("(declared as inline and inlined)"));
1626 printf (_(" (Unknown inline attribute value: %s)"),
1627 dwarf_vmatoa ("x", uvalue));
1632 case DW_AT_language:
1635 /* Ordered by the numeric value of these constants. */
1636 case DW_LANG_C89: printf ("(ANSI C)"); break;
1637 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1638 case DW_LANG_Ada83: printf ("(Ada)"); break;
1639 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1640 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1641 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1642 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1643 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1644 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1645 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1646 /* DWARF 2.1 values. */
1647 case DW_LANG_Java: printf ("(Java)"); break;
1648 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1649 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1650 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1651 /* DWARF 3 values. */
1652 case DW_LANG_PLI: printf ("(PLI)"); break;
1653 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1654 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1655 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1656 case DW_LANG_D: printf ("(D)"); break;
1657 /* DWARF 4 values. */
1658 case DW_LANG_Python: printf ("(Python)"); break;
1659 /* DWARF 5 values. */
1660 case DW_LANG_Go: printf ("(Go)"); break;
1661 /* MIPS extension. */
1662 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1663 /* UPC extension. */
1664 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1666 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1667 printf (_("(implementation defined: %s)"),
1668 dwarf_vmatoa ("x", uvalue));
1670 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1675 case DW_AT_encoding:
1678 case DW_ATE_void: printf ("(void)"); break;
1679 case DW_ATE_address: printf ("(machine address)"); break;
1680 case DW_ATE_boolean: printf ("(boolean)"); break;
1681 case DW_ATE_complex_float: printf ("(complex float)"); break;
1682 case DW_ATE_float: printf ("(float)"); break;
1683 case DW_ATE_signed: printf ("(signed)"); break;
1684 case DW_ATE_signed_char: printf ("(signed char)"); break;
1685 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1686 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1687 /* DWARF 2.1 values: */
1688 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1689 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1690 /* DWARF 3 values: */
1691 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1692 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1693 case DW_ATE_edited: printf ("(edited)"); break;
1694 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1695 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1696 /* HP extensions: */
1697 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1698 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1699 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1700 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1701 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1702 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1703 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1706 if (uvalue >= DW_ATE_lo_user
1707 && uvalue <= DW_ATE_hi_user)
1708 printf (_("(user defined type)"));
1710 printf (_("(unknown type)"));
1715 case DW_AT_accessibility:
1718 case DW_ACCESS_public: printf ("(public)"); break;
1719 case DW_ACCESS_protected: printf ("(protected)"); break;
1720 case DW_ACCESS_private: printf ("(private)"); break;
1722 printf (_("(unknown accessibility)"));
1727 case DW_AT_visibility:
1730 case DW_VIS_local: printf ("(local)"); break;
1731 case DW_VIS_exported: printf ("(exported)"); break;
1732 case DW_VIS_qualified: printf ("(qualified)"); break;
1733 default: printf (_("(unknown visibility)")); break;
1737 case DW_AT_virtuality:
1740 case DW_VIRTUALITY_none: printf ("(none)"); break;
1741 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1742 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1743 default: printf (_("(unknown virtuality)")); break;
1747 case DW_AT_identifier_case:
1750 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1751 case DW_ID_up_case: printf ("(up_case)"); break;
1752 case DW_ID_down_case: printf ("(down_case)"); break;
1753 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1754 default: printf (_("(unknown case)")); break;
1758 case DW_AT_calling_convention:
1761 case DW_CC_normal: printf ("(normal)"); break;
1762 case DW_CC_program: printf ("(program)"); break;
1763 case DW_CC_nocall: printf ("(nocall)"); break;
1765 if (uvalue >= DW_CC_lo_user
1766 && uvalue <= DW_CC_hi_user)
1767 printf (_("(user defined)"));
1769 printf (_("(unknown convention)"));
1773 case DW_AT_ordering:
1776 case -1: printf (_("(undefined)")); break;
1777 case 0: printf ("(row major)"); break;
1778 case 1: printf ("(column major)"); break;
1782 case DW_AT_frame_base:
1783 have_frame_base = 1;
1784 case DW_AT_location:
1785 case DW_AT_string_length:
1786 case DW_AT_return_addr:
1787 case DW_AT_data_member_location:
1788 case DW_AT_vtable_elem_location:
1790 case DW_AT_static_link:
1791 case DW_AT_use_location:
1792 case DW_AT_GNU_call_site_value:
1793 case DW_AT_GNU_call_site_data_value:
1794 case DW_AT_GNU_call_site_target:
1795 case DW_AT_GNU_call_site_target_clobbered:
1796 if ((dwarf_version < 4
1797 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1798 || form == DW_FORM_sec_offset)
1799 printf (_("(location list)"));
1801 case DW_AT_allocated:
1802 case DW_AT_associated:
1803 case DW_AT_data_location:
1805 case DW_AT_upper_bound:
1806 case DW_AT_lower_bound:
1809 int need_frame_base;
1812 need_frame_base = decode_location_expression (block_start,
1817 cu_offset, section);
1819 if (need_frame_base && !have_frame_base)
1820 printf (_(" [without DW_AT_frame_base]"));
1826 if (form == DW_FORM_ref_sig8
1827 || form == DW_FORM_GNU_ref_alt)
1830 if (form == DW_FORM_ref1
1831 || form == DW_FORM_ref2
1832 || form == DW_FORM_ref4
1833 || form == DW_FORM_ref_udata)
1834 uvalue += cu_offset;
1836 if (uvalue >= section->size)
1837 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1838 dwarf_vmatoa ("x", uvalue),
1839 (unsigned long) (orig_data - section->start));
1842 unsigned long abbrev_number;
1843 abbrev_entry * entry;
1845 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1847 printf (_("[Abbrev Number: %ld"), abbrev_number);
1848 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
1849 use different abbrev table, and we don't track .debug_info chunks
1851 if (form != DW_FORM_ref_addr)
1853 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1854 if (entry->entry == abbrev_number)
1857 printf (" (%s)", get_TAG_name (entry->tag));
1872 get_AT_name (unsigned long attribute)
1877 return "DW_AT value: 0";
1879 /* One value is shared by the MIPS and HP extensions: */
1880 if (attribute == DW_AT_MIPS_fde)
1881 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1883 name = get_DW_AT_name (attribute);
1887 static char buffer[100];
1889 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1897 static unsigned char *
1898 read_and_display_attr (unsigned long attribute,
1900 unsigned char * data,
1901 dwarf_vma cu_offset,
1902 dwarf_vma pointer_size,
1903 dwarf_vma offset_size,
1905 debug_info * debug_info_p,
1907 struct dwarf_section * section)
1910 printf (" %-18s:", get_AT_name (attribute));
1911 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1912 pointer_size, offset_size,
1913 dwarf_version, debug_info_p,
1921 /* Process the contents of a .debug_info section. If do_loc is non-zero
1922 then we are scanning for location lists and we do not want to display
1923 anything to the user. If do_types is non-zero, we are processing
1924 a .debug_types section instead of a .debug_info section. */
1927 process_debug_info (struct dwarf_section *section,
1929 enum dwarf_section_display_enum abbrev_sec,
1933 unsigned char *start = section->start;
1934 unsigned char *end = start + section->size;
1935 unsigned char *section_begin;
1937 unsigned int num_units = 0;
1939 if ((do_loc || do_debug_loc || do_debug_ranges)
1940 && num_debug_info_entries == 0
1945 /* First scan the section to get the number of comp units. */
1946 for (section_begin = start, num_units = 0; section_begin < end;
1949 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1950 will be the length. For a 64-bit DWARF section, it'll be
1951 the escape code 0xffffffff followed by an 8 byte length. */
1952 length = byte_get (section_begin, 4);
1954 if (length == 0xffffffff)
1956 length = byte_get (section_begin + 4, 8);
1957 section_begin += length + 12;
1959 else if (length >= 0xfffffff0 && length < 0xffffffff)
1961 warn (_("Reserved length value (0x%s) found in section %s\n"),
1962 dwarf_vmatoa ("x", length), section->name);
1966 section_begin += length + 4;
1968 /* Negative values are illegal, they may even cause infinite
1969 looping. This can happen if we can't accurately apply
1970 relocations to an object file. */
1971 if ((signed long) length <= 0)
1973 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
1974 dwarf_vmatoa ("x", length), section->name);
1981 error (_("No comp units in %s section ?"), section->name);
1985 /* Then allocate an array to hold the information. */
1986 debug_information = (debug_info *) cmalloc (num_units,
1987 sizeof (* debug_information));
1988 if (debug_information == NULL)
1990 error (_("Not enough memory for a debug info array of %u entries"),
1998 if (dwarf_start_die == 0)
1999 printf (_("Contents of the %s section:\n\n"), section->name);
2001 load_debug_section (str, file);
2002 load_debug_section (str_dwo, file);
2003 load_debug_section (str_index, file);
2004 load_debug_section (str_index_dwo, file);
2005 load_debug_section (debug_addr, file);
2008 load_debug_section (abbrev_sec, file);
2009 if (debug_displays [abbrev_sec].section.start == NULL)
2011 warn (_("Unable to locate %s section!\n"),
2012 debug_displays [abbrev_sec].section.name);
2016 for (section_begin = start, unit = 0; start < end; unit++)
2018 DWARF2_Internal_CompUnit compunit;
2019 unsigned char *hdrptr;
2020 unsigned char *tags;
2021 int level, last_level, saved_level;
2022 dwarf_vma cu_offset;
2024 int initial_length_size;
2025 dwarf_vma signature_high = 0;
2026 dwarf_vma signature_low = 0;
2027 dwarf_vma type_offset = 0;
2031 compunit.cu_length = byte_get (hdrptr, 4);
2034 if (compunit.cu_length == 0xffffffff)
2036 compunit.cu_length = byte_get (hdrptr, 8);
2039 initial_length_size = 12;
2044 initial_length_size = 4;
2047 compunit.cu_version = byte_get (hdrptr, 2);
2050 cu_offset = start - section_begin;
2052 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2053 hdrptr += offset_size;
2055 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2060 byte_get_64 (hdrptr, &signature_high, &signature_low);
2062 type_offset = byte_get (hdrptr, offset_size);
2063 hdrptr += offset_size;
2066 if ((do_loc || do_debug_loc || do_debug_ranges)
2067 && num_debug_info_entries == 0
2070 debug_information [unit].cu_offset = cu_offset;
2071 debug_information [unit].pointer_size
2072 = compunit.cu_pointer_size;
2073 debug_information [unit].offset_size = offset_size;
2074 debug_information [unit].dwarf_version = compunit.cu_version;
2075 debug_information [unit].base_address = 0;
2076 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2077 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2078 debug_information [unit].loc_offsets = NULL;
2079 debug_information [unit].have_frame_base = NULL;
2080 debug_information [unit].max_loc_offsets = 0;
2081 debug_information [unit].num_loc_offsets = 0;
2082 debug_information [unit].range_lists = NULL;
2083 debug_information [unit].max_range_lists= 0;
2084 debug_information [unit].num_range_lists = 0;
2087 if (!do_loc && dwarf_start_die == 0)
2089 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2090 dwarf_vmatoa ("x", cu_offset));
2091 printf (_(" Length: 0x%s (%s)\n"),
2092 dwarf_vmatoa ("x", compunit.cu_length),
2093 offset_size == 8 ? "64-bit" : "32-bit");
2094 printf (_(" Version: %d\n"), compunit.cu_version);
2095 printf (_(" Abbrev Offset: 0x%s\n"),
2096 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2097 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2102 printf (_(" Signature: 0x%s\n"),
2103 dwarf_vmatoa64 (signature_high, signature_low,
2104 buf, sizeof (buf)));
2105 printf (_(" Type Offset: 0x%s\n"),
2106 dwarf_vmatoa ("x", type_offset));
2110 if (cu_offset + compunit.cu_length + initial_length_size
2113 warn (_("Debug info is corrupted, length of CU at %s"
2114 " extends beyond end of section (length = %s)\n"),
2115 dwarf_vmatoa ("x", cu_offset),
2116 dwarf_vmatoa ("x", compunit.cu_length));
2120 start += compunit.cu_length + initial_length_size;
2122 if (compunit.cu_version != 2
2123 && compunit.cu_version != 3
2124 && compunit.cu_version != 4)
2126 warn (_("CU at offset %s contains corrupt or "
2127 "unsupported version number: %d.\n"),
2128 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2134 /* Process the abbrevs used by this compilation unit. DWARF
2135 sections under Mach-O have non-zero addresses. */
2136 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2137 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2138 (unsigned long) compunit.cu_abbrev_offset,
2139 (unsigned long) debug_displays [abbrev_sec].section.size);
2141 process_abbrev_section
2142 ((unsigned char *) debug_displays [abbrev_sec].section.start
2143 + compunit.cu_abbrev_offset,
2144 (unsigned char *) debug_displays [abbrev_sec].section.start
2145 + debug_displays [abbrev_sec].section.size);
2150 while (tags < start)
2152 unsigned int bytes_read;
2153 unsigned long abbrev_number;
2154 unsigned long die_offset;
2155 abbrev_entry *entry;
2157 int do_printing = 1;
2159 die_offset = tags - section_begin;
2161 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2164 /* A null DIE marks the end of a list of siblings or it may also be
2165 a section padding. */
2166 if (abbrev_number == 0)
2168 /* Check if it can be a section padding for the last CU. */
2169 if (level == 0 && start == end)
2173 for (chk = tags; chk < start; chk++)
2180 if (!do_loc && die_offset >= dwarf_start_die)
2181 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2187 static unsigned num_bogus_warns = 0;
2189 if (num_bogus_warns < 3)
2191 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2192 die_offset, section->name);
2194 if (num_bogus_warns == 3)
2195 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2198 if (dwarf_start_die != 0 && level < saved_level)
2205 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2209 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2210 saved_level = level;
2211 do_printing = (dwarf_cutoff_level == -1
2212 || level < dwarf_cutoff_level);
2214 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2215 level, die_offset, abbrev_number);
2216 else if (dwarf_cutoff_level == -1
2217 || last_level < dwarf_cutoff_level)
2218 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2223 /* Scan through the abbreviation list until we reach the
2225 for (entry = first_abbrev;
2226 entry && entry->entry != abbrev_number;
2227 entry = entry->next)
2232 if (!do_loc && do_printing)
2237 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2238 die_offset, abbrev_number);
2242 if (!do_loc && do_printing)
2243 printf (" (%s)\n", get_TAG_name (entry->tag));
2248 need_base_address = 0;
2250 case DW_TAG_compile_unit:
2251 need_base_address = 1;
2253 case DW_TAG_entry_point:
2254 case DW_TAG_subprogram:
2255 need_base_address = 0;
2256 /* Assuming that there is no DW_AT_frame_base. */
2257 have_frame_base = 0;
2261 for (attr = entry->first_attr;
2262 attr && attr->attribute;
2267 if (! do_loc && do_printing)
2268 /* Show the offset from where the tag was extracted. */
2269 printf (" <%lx>", (unsigned long)(tags - section_begin));
2271 arg = debug_information;
2272 if (debug_information)
2275 tags = read_and_display_attr (attr->attribute,
2278 compunit.cu_pointer_size,
2280 compunit.cu_version,
2282 do_loc || ! do_printing, section);
2285 if (entry->children)
2290 /* Set num_debug_info_entries here so that it can be used to check if
2291 we need to process .debug_loc and .debug_ranges sections. */
2292 if ((do_loc || do_debug_loc || do_debug_ranges)
2293 && num_debug_info_entries == 0
2295 num_debug_info_entries = num_units;
2303 /* Locate and scan the .debug_info section in the file and record the pointer
2304 sizes and offsets for the compilation units in it. Usually an executable
2305 will have just one pointer size, but this is not guaranteed, and so we try
2306 not to make any assumptions. Returns zero upon failure, or the number of
2307 compilation units upon success. */
2310 load_debug_info (void * file)
2312 /* Reset the last pointer size so that we can issue correct error
2313 messages if we are displaying the contents of more than one section. */
2314 last_pointer_size = 0;
2315 warned_about_missing_comp_units = FALSE;
2317 /* If we have already tried and failed to load the .debug_info
2318 section then do not bother to repeat the task. */
2319 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2322 /* If we already have the information there is nothing else to do. */
2323 if (num_debug_info_entries > 0)
2324 return num_debug_info_entries;
2326 if (load_debug_section (info, file)
2327 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2328 return num_debug_info_entries;
2329 else if (load_debug_section (info_dwo, file)
2330 && process_debug_info (&debug_displays [info_dwo].section, file,
2332 return num_debug_info_entries;
2334 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2339 display_debug_lines_raw (struct dwarf_section *section,
2340 unsigned char *data,
2343 unsigned char *start = section->start;
2345 printf (_("Raw dump of debug contents of section %s:\n\n"),
2350 DWARF2_Internal_LineInfo linfo;
2351 unsigned char *standard_opcodes;
2352 unsigned char *end_of_sequence;
2353 unsigned char *hdrptr;
2354 unsigned long hdroff;
2355 int initial_length_size;
2360 hdroff = hdrptr - start;
2362 /* Check the length of the block. */
2363 linfo.li_length = byte_get (hdrptr, 4);
2366 if (linfo.li_length == 0xffffffff)
2368 /* This section is 64-bit DWARF 3. */
2369 linfo.li_length = byte_get (hdrptr, 8);
2372 initial_length_size = 12;
2377 initial_length_size = 4;
2380 if (linfo.li_length + initial_length_size > section->size)
2383 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2388 /* Check its version number. */
2389 linfo.li_version = byte_get (hdrptr, 2);
2391 if (linfo.li_version != 2
2392 && linfo.li_version != 3
2393 && linfo.li_version != 4)
2395 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2399 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2400 hdrptr += offset_size;
2401 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2403 if (linfo.li_version >= 4)
2405 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2407 if (linfo.li_max_ops_per_insn == 0)
2409 warn (_("Invalid maximum operations per insn.\n"));
2414 linfo.li_max_ops_per_insn = 1;
2415 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2417 linfo.li_line_base = byte_get (hdrptr, 1);
2419 linfo.li_line_range = byte_get (hdrptr, 1);
2421 linfo.li_opcode_base = byte_get (hdrptr, 1);
2424 /* Sign extend the line base field. */
2425 linfo.li_line_base <<= 24;
2426 linfo.li_line_base >>= 24;
2428 printf (_(" Offset: 0x%lx\n"), hdroff);
2429 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2430 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2431 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2432 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2433 if (linfo.li_version >= 4)
2434 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2435 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2436 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2437 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2438 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2440 end_of_sequence = data + linfo.li_length + initial_length_size;
2442 reset_state_machine (linfo.li_default_is_stmt);
2444 /* Display the contents of the Opcodes table. */
2445 standard_opcodes = hdrptr;
2447 printf (_("\n Opcodes:\n"));
2449 for (i = 1; i < linfo.li_opcode_base; i++)
2450 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2452 /* Display the contents of the Directory table. */
2453 data = standard_opcodes + linfo.li_opcode_base - 1;
2456 printf (_("\n The Directory Table is empty.\n"));
2459 printf (_("\n The Directory Table:\n"));
2463 printf (" %s\n", data);
2465 data += strlen ((char *) data) + 1;
2469 /* Skip the NUL at the end of the table. */
2472 /* Display the contents of the File Name table. */
2474 printf (_("\n The File Name Table is empty.\n"));
2477 printf (_("\n The File Name Table:\n"));
2478 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2482 unsigned char *name;
2483 unsigned int bytes_read;
2485 printf (" %d\t", ++state_machine_regs.last_file_entry);
2488 data += strlen ((char *) data) + 1;
2491 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2494 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2497 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2499 printf ("%s\n", name);
2503 /* Skip the NUL at the end of the table. */
2506 /* Now display the statements. */
2507 printf (_("\n Line Number Statements:\n"));
2509 while (data < end_of_sequence)
2511 unsigned char op_code;
2512 dwarf_signed_vma adv;
2514 unsigned int bytes_read;
2518 if (op_code >= linfo.li_opcode_base)
2520 op_code -= linfo.li_opcode_base;
2521 uladv = (op_code / linfo.li_line_range);
2522 if (linfo.li_max_ops_per_insn == 1)
2524 uladv *= linfo.li_min_insn_length;
2525 state_machine_regs.address += uladv;
2526 printf (_(" Special opcode %d: "
2527 "advance Address by %s to 0x%s"),
2528 op_code, dwarf_vmatoa ("u", uladv),
2529 dwarf_vmatoa ("x", state_machine_regs.address));
2533 state_machine_regs.address
2534 += ((state_machine_regs.op_index + uladv)
2535 / linfo.li_max_ops_per_insn)
2536 * linfo.li_min_insn_length;
2537 state_machine_regs.op_index
2538 = (state_machine_regs.op_index + uladv)
2539 % linfo.li_max_ops_per_insn;
2540 printf (_(" Special opcode %d: "
2541 "advance Address by %s to 0x%s[%d]"),
2542 op_code, dwarf_vmatoa ("u", uladv),
2543 dwarf_vmatoa ("x", state_machine_regs.address),
2544 state_machine_regs.op_index);
2546 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2547 state_machine_regs.line += adv;
2548 printf (_(" and Line by %s to %d\n"),
2549 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2551 else switch (op_code)
2553 case DW_LNS_extended_op:
2554 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2558 printf (_(" Copy\n"));
2561 case DW_LNS_advance_pc:
2562 uladv = read_leb128 (data, & bytes_read, 0);
2564 if (linfo.li_max_ops_per_insn == 1)
2566 uladv *= linfo.li_min_insn_length;
2567 state_machine_regs.address += uladv;
2568 printf (_(" Advance PC by %s to 0x%s\n"),
2569 dwarf_vmatoa ("u", uladv),
2570 dwarf_vmatoa ("x", state_machine_regs.address));
2574 state_machine_regs.address
2575 += ((state_machine_regs.op_index + uladv)
2576 / linfo.li_max_ops_per_insn)
2577 * linfo.li_min_insn_length;
2578 state_machine_regs.op_index
2579 = (state_machine_regs.op_index + uladv)
2580 % linfo.li_max_ops_per_insn;
2581 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2582 dwarf_vmatoa ("u", uladv),
2583 dwarf_vmatoa ("x", state_machine_regs.address),
2584 state_machine_regs.op_index);
2588 case DW_LNS_advance_line:
2589 adv = read_sleb128 (data, & bytes_read);
2591 state_machine_regs.line += adv;
2592 printf (_(" Advance Line by %s to %d\n"),
2593 dwarf_vmatoa ("d", adv),
2594 state_machine_regs.line);
2597 case DW_LNS_set_file:
2598 adv = read_leb128 (data, & bytes_read, 0);
2600 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2601 dwarf_vmatoa ("d", adv));
2602 state_machine_regs.file = adv;
2605 case DW_LNS_set_column:
2606 uladv = read_leb128 (data, & bytes_read, 0);
2608 printf (_(" Set column to %s\n"),
2609 dwarf_vmatoa ("u", uladv));
2610 state_machine_regs.column = uladv;
2613 case DW_LNS_negate_stmt:
2614 adv = state_machine_regs.is_stmt;
2616 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2617 state_machine_regs.is_stmt = adv;
2620 case DW_LNS_set_basic_block:
2621 printf (_(" Set basic block\n"));
2622 state_machine_regs.basic_block = 1;
2625 case DW_LNS_const_add_pc:
2626 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2627 if (linfo.li_max_ops_per_insn)
2629 uladv *= linfo.li_min_insn_length;
2630 state_machine_regs.address += uladv;
2631 printf (_(" Advance PC by constant %s to 0x%s\n"),
2632 dwarf_vmatoa ("u", uladv),
2633 dwarf_vmatoa ("x", state_machine_regs.address));
2637 state_machine_regs.address
2638 += ((state_machine_regs.op_index + uladv)
2639 / linfo.li_max_ops_per_insn)
2640 * linfo.li_min_insn_length;
2641 state_machine_regs.op_index
2642 = (state_machine_regs.op_index + uladv)
2643 % linfo.li_max_ops_per_insn;
2644 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2645 dwarf_vmatoa ("u", uladv),
2646 dwarf_vmatoa ("x", state_machine_regs.address),
2647 state_machine_regs.op_index);
2651 case DW_LNS_fixed_advance_pc:
2652 uladv = byte_get (data, 2);
2654 state_machine_regs.address += uladv;
2655 state_machine_regs.op_index = 0;
2656 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2657 dwarf_vmatoa ("u", uladv),
2658 dwarf_vmatoa ("x", state_machine_regs.address));
2661 case DW_LNS_set_prologue_end:
2662 printf (_(" Set prologue_end to true\n"));
2665 case DW_LNS_set_epilogue_begin:
2666 printf (_(" Set epilogue_begin to true\n"));
2669 case DW_LNS_set_isa:
2670 uladv = read_leb128 (data, & bytes_read, 0);
2672 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2676 printf (_(" Unknown opcode %d with operands: "), op_code);
2678 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2680 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2682 i == 1 ? "" : ", ");
2697 unsigned char *name;
2698 unsigned int directory_index;
2699 unsigned int modification_date;
2700 unsigned int length;
2703 /* Output a decoded representation of the .debug_line section. */
2706 display_debug_lines_decoded (struct dwarf_section *section,
2707 unsigned char *data,
2710 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2715 /* This loop amounts to one iteration per compilation unit. */
2716 DWARF2_Internal_LineInfo linfo;
2717 unsigned char *standard_opcodes;
2718 unsigned char *end_of_sequence;
2719 unsigned char *hdrptr;
2720 int initial_length_size;
2723 File_Entry *file_table = NULL;
2724 unsigned int n_files = 0;
2725 unsigned char **directory_table = NULL;
2726 unsigned int n_directories = 0;
2730 /* Extract information from the Line Number Program Header.
2731 (section 6.2.4 in the Dwarf3 doc). */
2733 /* Get the length of this CU's line number information block. */
2734 linfo.li_length = byte_get (hdrptr, 4);
2737 if (linfo.li_length == 0xffffffff)
2739 /* This section is 64-bit DWARF 3. */
2740 linfo.li_length = byte_get (hdrptr, 8);
2743 initial_length_size = 12;
2748 initial_length_size = 4;
2751 if (linfo.li_length + initial_length_size > section->size)
2753 warn (_("The line info appears to be corrupt - "
2754 "the section is too small\n"));
2758 /* Get this CU's Line Number Block version number. */
2759 linfo.li_version = byte_get (hdrptr, 2);
2761 if (linfo.li_version != 2
2762 && linfo.li_version != 3
2763 && linfo.li_version != 4)
2765 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2770 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2771 hdrptr += offset_size;
2772 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2774 if (linfo.li_version >= 4)
2776 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2778 if (linfo.li_max_ops_per_insn == 0)
2780 warn (_("Invalid maximum operations per insn.\n"));
2785 linfo.li_max_ops_per_insn = 1;
2786 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2788 linfo.li_line_base = byte_get (hdrptr, 1);
2790 linfo.li_line_range = byte_get (hdrptr, 1);
2792 linfo.li_opcode_base = byte_get (hdrptr, 1);
2795 /* Sign extend the line base field. */
2796 linfo.li_line_base <<= 24;
2797 linfo.li_line_base >>= 24;
2799 /* Find the end of this CU's Line Number Information Block. */
2800 end_of_sequence = data + linfo.li_length + initial_length_size;
2802 reset_state_machine (linfo.li_default_is_stmt);
2804 /* Save a pointer to the contents of the Opcodes table. */
2805 standard_opcodes = hdrptr;
2807 /* Traverse the Directory table just to count entries. */
2808 data = standard_opcodes + linfo.li_opcode_base - 1;
2811 unsigned char *ptr_directory_table = data;
2815 data += strlen ((char *) data) + 1;
2819 /* Go through the directory table again to save the directories. */
2820 directory_table = (unsigned char **)
2821 xmalloc (n_directories * sizeof (unsigned char *));
2824 while (*ptr_directory_table != 0)
2826 directory_table[i] = ptr_directory_table;
2827 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2831 /* Skip the NUL at the end of the table. */
2834 /* Traverse the File Name table just to count the entries. */
2837 unsigned char *ptr_file_name_table = data;
2841 unsigned int bytes_read;
2843 /* Skip Name, directory index, last modification time and length
2845 data += strlen ((char *) data) + 1;
2846 read_leb128 (data, & bytes_read, 0);
2848 read_leb128 (data, & bytes_read, 0);
2850 read_leb128 (data, & bytes_read, 0);
2856 /* Go through the file table again to save the strings. */
2857 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2860 while (*ptr_file_name_table != 0)
2862 unsigned int bytes_read;
2864 file_table[i].name = ptr_file_name_table;
2865 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2867 /* We are not interested in directory, time or size. */
2868 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2870 ptr_file_name_table += bytes_read;
2871 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2873 ptr_file_name_table += bytes_read;
2874 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2875 ptr_file_name_table += bytes_read;
2880 /* Print the Compilation Unit's name and a header. */
2881 if (directory_table == NULL)
2883 printf (_("CU: %s:\n"), file_table[0].name);
2884 printf (_("File name Line number Starting address\n"));
2888 unsigned int ix = file_table[0].directory_index;
2889 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
2890 if (do_wide || strlen (directory) < 76)
2891 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
2893 printf ("%s:\n", file_table[0].name);
2895 printf (_("File name Line number Starting address\n"));
2899 /* Skip the NUL at the end of the table. */
2902 /* This loop iterates through the Dwarf Line Number Program. */
2903 while (data < end_of_sequence)
2905 unsigned char op_code;
2907 unsigned long int uladv;
2908 unsigned int bytes_read;
2909 int is_special_opcode = 0;
2913 if (op_code >= linfo.li_opcode_base)
2915 op_code -= linfo.li_opcode_base;
2916 uladv = (op_code / linfo.li_line_range);
2917 if (linfo.li_max_ops_per_insn == 1)
2919 uladv *= linfo.li_min_insn_length;
2920 state_machine_regs.address += uladv;
2924 state_machine_regs.address
2925 += ((state_machine_regs.op_index + uladv)
2926 / linfo.li_max_ops_per_insn)
2927 * linfo.li_min_insn_length;
2928 state_machine_regs.op_index
2929 = (state_machine_regs.op_index + uladv)
2930 % linfo.li_max_ops_per_insn;
2933 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2934 state_machine_regs.line += adv;
2935 is_special_opcode = 1;
2937 else switch (op_code)
2939 case DW_LNS_extended_op:
2941 unsigned int ext_op_code_len;
2942 unsigned char ext_op_code;
2943 unsigned char *op_code_data = data;
2945 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
2946 op_code_data += bytes_read;
2948 if (ext_op_code_len == 0)
2950 warn (_("badly formed extended line op encountered!\n"));
2953 ext_op_code_len += bytes_read;
2954 ext_op_code = *op_code_data++;
2956 switch (ext_op_code)
2958 case DW_LNE_end_sequence:
2959 reset_state_machine (linfo.li_default_is_stmt);
2961 case DW_LNE_set_address:
2962 state_machine_regs.address =
2963 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
2964 state_machine_regs.op_index = 0;
2966 case DW_LNE_define_file:
2968 file_table = (File_Entry *) xrealloc
2969 (file_table, (n_files + 1) * sizeof (File_Entry));
2971 ++state_machine_regs.last_file_entry;
2972 /* Source file name. */
2973 file_table[n_files].name = op_code_data;
2974 op_code_data += strlen ((char *) op_code_data) + 1;
2975 /* Directory index. */
2976 file_table[n_files].directory_index =
2977 read_leb128 (op_code_data, & bytes_read, 0);
2978 op_code_data += bytes_read;
2979 /* Last modification time. */
2980 file_table[n_files].modification_date =
2981 read_leb128 (op_code_data, & bytes_read, 0);
2982 op_code_data += bytes_read;
2984 file_table[n_files].length =
2985 read_leb128 (op_code_data, & bytes_read, 0);
2990 case DW_LNE_set_discriminator:
2991 case DW_LNE_HP_set_sequence:
2992 /* Simply ignored. */
2996 printf (_("UNKNOWN (%u): length %d\n"),
2997 ext_op_code, ext_op_code_len - bytes_read);
3000 data += ext_op_code_len;
3006 case DW_LNS_advance_pc:
3007 uladv = read_leb128 (data, & bytes_read, 0);
3009 if (linfo.li_max_ops_per_insn == 1)
3011 uladv *= linfo.li_min_insn_length;
3012 state_machine_regs.address += uladv;
3016 state_machine_regs.address
3017 += ((state_machine_regs.op_index + uladv)
3018 / linfo.li_max_ops_per_insn)
3019 * linfo.li_min_insn_length;
3020 state_machine_regs.op_index
3021 = (state_machine_regs.op_index + uladv)
3022 % linfo.li_max_ops_per_insn;
3026 case DW_LNS_advance_line:
3027 adv = read_sleb128 (data, & bytes_read);
3029 state_machine_regs.line += adv;
3032 case DW_LNS_set_file:
3033 adv = read_leb128 (data, & bytes_read, 0);
3035 state_machine_regs.file = adv;
3036 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3038 /* If directory index is 0, that means current directory. */
3039 printf ("\n./%s:[++]\n",
3040 file_table[state_machine_regs.file - 1].name);
3044 /* The directory index starts counting at 1. */
3045 printf ("\n%s/%s:\n",
3046 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3047 file_table[state_machine_regs.file - 1].name);
3051 case DW_LNS_set_column:
3052 uladv = read_leb128 (data, & bytes_read, 0);
3054 state_machine_regs.column = uladv;
3057 case DW_LNS_negate_stmt:
3058 adv = state_machine_regs.is_stmt;
3060 state_machine_regs.is_stmt = adv;
3063 case DW_LNS_set_basic_block:
3064 state_machine_regs.basic_block = 1;
3067 case DW_LNS_const_add_pc:
3068 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3069 if (linfo.li_max_ops_per_insn == 1)
3071 uladv *= linfo.li_min_insn_length;
3072 state_machine_regs.address += uladv;
3076 state_machine_regs.address
3077 += ((state_machine_regs.op_index + uladv)
3078 / linfo.li_max_ops_per_insn)
3079 * linfo.li_min_insn_length;
3080 state_machine_regs.op_index
3081 = (state_machine_regs.op_index + uladv)
3082 % linfo.li_max_ops_per_insn;
3086 case DW_LNS_fixed_advance_pc:
3087 uladv = byte_get (data, 2);
3089 state_machine_regs.address += uladv;
3090 state_machine_regs.op_index = 0;
3093 case DW_LNS_set_prologue_end:
3096 case DW_LNS_set_epilogue_begin:
3099 case DW_LNS_set_isa:
3100 uladv = read_leb128 (data, & bytes_read, 0);
3102 printf (_(" Set ISA to %lu\n"), uladv);
3106 printf (_(" Unknown opcode %d with operands: "), op_code);
3108 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3110 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3112 i == 1 ? "" : ", ");
3119 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3120 to the DWARF address/line matrix. */
3121 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3122 || (op_code == DW_LNS_copy))
3124 const unsigned int MAX_FILENAME_LENGTH = 35;
3125 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3126 char *newFileName = NULL;
3127 size_t fileNameLength = strlen (fileName);
3129 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3131 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3132 /* Truncate file name */
3133 strncpy (newFileName,
3134 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3135 MAX_FILENAME_LENGTH + 1);
3139 newFileName = (char *) xmalloc (fileNameLength + 1);
3140 strncpy (newFileName, fileName, fileNameLength + 1);
3143 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3145 if (linfo.li_max_ops_per_insn == 1)
3146 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3147 newFileName, state_machine_regs.line,
3148 state_machine_regs.address);
3150 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3151 newFileName, state_machine_regs.line,
3152 state_machine_regs.address,
3153 state_machine_regs.op_index);
3157 if (linfo.li_max_ops_per_insn == 1)
3158 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3159 newFileName, state_machine_regs.line,
3160 state_machine_regs.address);
3162 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3163 newFileName, state_machine_regs.line,
3164 state_machine_regs.address,
3165 state_machine_regs.op_index);
3168 if (op_code == DW_LNE_end_sequence)
3176 free (directory_table);
3177 directory_table = NULL;
3185 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3187 unsigned char *data = section->start;
3188 unsigned char *end = data + section->size;
3190 int retValDecoded = 1;
3192 if (do_debug_lines == 0)
3193 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3195 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3196 retValRaw = display_debug_lines_raw (section, data, end);
3198 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3199 retValDecoded = display_debug_lines_decoded (section, data, end);
3201 if (!retValRaw || !retValDecoded)
3208 find_debug_info_for_offset (unsigned long offset)
3212 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3215 for (i = 0; i < num_debug_info_entries; i++)
3216 if (debug_information[i].cu_offset == offset)
3217 return debug_information + i;
3223 display_debug_pubnames (struct dwarf_section *section,
3224 void *file ATTRIBUTE_UNUSED)
3226 DWARF2_Internal_PubNames names;
3227 unsigned char *start = section->start;
3228 unsigned char *end = start + section->size;
3230 /* It does not matter if this load fails,
3231 we test for that later on. */
3232 load_debug_info (file);
3234 printf (_("Contents of the %s section:\n\n"), section->name);
3238 unsigned char *data;
3239 unsigned long offset;
3240 int offset_size, initial_length_size;
3244 names.pn_length = byte_get (data, 4);
3246 if (names.pn_length == 0xffffffff)
3248 names.pn_length = byte_get (data, 8);
3251 initial_length_size = 12;
3256 initial_length_size = 4;
3259 names.pn_version = byte_get (data, 2);
3262 names.pn_offset = byte_get (data, offset_size);
3263 data += offset_size;
3265 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3266 && num_debug_info_entries > 0
3267 && find_debug_info_for_offset (names.pn_offset) == NULL)
3268 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3269 (unsigned long) names.pn_offset, section->name);
3271 names.pn_size = byte_get (data, offset_size);
3272 data += offset_size;
3274 start += names.pn_length + initial_length_size;
3276 if (names.pn_version != 2 && names.pn_version != 3)
3278 static int warned = 0;
3282 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3289 printf (_(" Length: %ld\n"),
3290 (long) names.pn_length);
3291 printf (_(" Version: %d\n"),
3293 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3294 (unsigned long) names.pn_offset);
3295 printf (_(" Size of area in .debug_info section: %ld\n"),
3296 (long) names.pn_size);
3298 printf (_("\n Offset\tName\n"));
3302 offset = byte_get (data, offset_size);
3306 data += offset_size;
3307 printf (" %-6lx\t%s\n", offset, data);
3308 data += strlen ((char *) data) + 1;
3311 while (offset != 0);
3319 display_debug_macinfo (struct dwarf_section *section,
3320 void *file ATTRIBUTE_UNUSED)
3322 unsigned char *start = section->start;
3323 unsigned char *end = start + section->size;
3324 unsigned char *curr = start;
3325 unsigned int bytes_read;
3326 enum dwarf_macinfo_record_type op;
3328 printf (_("Contents of the %s section:\n\n"), section->name);
3332 unsigned int lineno;
3335 op = (enum dwarf_macinfo_record_type) *curr;
3340 case DW_MACINFO_start_file:
3342 unsigned int filenum;
3344 lineno = read_leb128 (curr, & bytes_read, 0);
3346 filenum = read_leb128 (curr, & bytes_read, 0);
3349 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3354 case DW_MACINFO_end_file:
3355 printf (_(" DW_MACINFO_end_file\n"));
3358 case DW_MACINFO_define:
3359 lineno = read_leb128 (curr, & bytes_read, 0);
3361 string = (char *) curr;
3362 curr += strlen (string) + 1;
3363 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3367 case DW_MACINFO_undef:
3368 lineno = read_leb128 (curr, & bytes_read, 0);
3370 string = (char *) curr;
3371 curr += strlen (string) + 1;
3372 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3376 case DW_MACINFO_vendor_ext:
3378 unsigned int constant;
3380 constant = read_leb128 (curr, & bytes_read, 0);
3382 string = (char *) curr;
3383 curr += strlen (string) + 1;
3384 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3394 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3395 filename and dirname corresponding to file name table entry with index
3396 FILEIDX. Return NULL on failure. */
3398 static unsigned char *
3399 get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
3400 unsigned char **dir_name)
3402 struct dwarf_section *section = &debug_displays [line].section;
3403 unsigned char *hdrptr, *dirtable, *file_name;
3404 unsigned int offset_size, initial_length_size;
3405 unsigned int version, opcode_base, bytes_read;
3406 dwarf_vma length, diridx;
3409 if (section->start == NULL
3410 || line_offset >= section->size
3414 hdrptr = section->start + line_offset;
3415 length = byte_get (hdrptr, 4);
3417 if (length == 0xffffffff)
3419 /* This section is 64-bit DWARF 3. */
3420 length = byte_get (hdrptr, 8);
3423 initial_length_size = 12;
3428 initial_length_size = 4;
3430 if (length + initial_length_size > section->size)
3432 version = byte_get (hdrptr, 2);
3434 if (version != 2 && version != 3 && version != 4)
3436 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3438 hdrptr++; /* Skip max_ops_per_insn. */
3439 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3440 opcode_base = byte_get (hdrptr, 1);
3441 if (opcode_base == 0)
3444 hdrptr += opcode_base - 1;
3446 /* Skip over dirname table. */
3447 while (*hdrptr != '\0')
3448 hdrptr += strlen ((char *) hdrptr) + 1;
3449 hdrptr++; /* Skip the NUL at the end of the table. */
3450 /* Now skip over preceding filename table entries. */
3451 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3453 hdrptr += strlen ((char *) hdrptr) + 1;
3454 read_leb128 (hdrptr, &bytes_read, 0);
3455 hdrptr += bytes_read;
3456 read_leb128 (hdrptr, &bytes_read, 0);
3457 hdrptr += bytes_read;
3458 read_leb128 (hdrptr, &bytes_read, 0);
3459 hdrptr += bytes_read;
3461 if (*hdrptr == '\0')
3464 hdrptr += strlen ((char *) hdrptr) + 1;
3465 diridx = read_leb128 (hdrptr, &bytes_read, 0);
3468 for (; *dirtable != '\0' && diridx > 1; diridx--)
3469 dirtable += strlen ((char *) dirtable) + 1;
3470 if (*dirtable == '\0')
3472 *dir_name = dirtable;
3477 display_debug_macro (struct dwarf_section *section,
3480 unsigned char *start = section->start;
3481 unsigned char *end = start + section->size;
3482 unsigned char *curr = start;
3483 unsigned char *extended_op_buf[256];
3484 unsigned int bytes_read;
3486 load_debug_section (str, file);
3487 load_debug_section (line, file);
3489 printf (_("Contents of the %s section:\n\n"), section->name);
3493 unsigned int lineno, version, flags;
3494 unsigned int offset_size = 4;
3496 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3497 unsigned char **extended_ops = NULL;
3499 version = byte_get (curr, 2);
3504 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3509 flags = byte_get (curr++, 1);
3512 printf (_(" Offset: 0x%lx\n"),
3513 (unsigned long) sec_offset);
3514 printf (_(" Version: %d\n"), version);
3515 printf (_(" Offset size: %d\n"), offset_size);
3518 line_offset = byte_get (curr, offset_size);
3519 curr += offset_size;
3520 printf (_(" Offset into .debug_line: 0x%lx\n"),
3521 (unsigned long) line_offset);
3525 unsigned int i, count = byte_get (curr++, 1), op;
3527 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3528 extended_ops = extended_op_buf;
3531 printf (_(" Extension opcode arguments:\n"));
3532 for (i = 0; i < count; i++)
3534 op = byte_get (curr++, 1);
3535 extended_ops[op] = curr;
3536 nargs = read_leb128 (curr, &bytes_read, 0);
3539 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3542 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3543 for (n = 0; n < nargs; n++)
3545 unsigned int form = byte_get (curr++, 1);
3546 printf ("%s%s", get_FORM_name (form),
3547 n == nargs - 1 ? "\n" : ", ");
3557 case DW_FORM_block1:
3558 case DW_FORM_block2:
3559 case DW_FORM_block4:
3561 case DW_FORM_string:
3563 case DW_FORM_sec_offset:
3566 error (_("Invalid extension opcode form %s\n"),
3567 get_FORM_name (form));
3583 error (_(".debug_macro section not zero terminated\n"));
3587 op = byte_get (curr++, 1);
3593 case DW_MACRO_GNU_start_file:
3595 unsigned int filenum;
3596 unsigned char *file_name = NULL, *dir_name = NULL;
3598 lineno = read_leb128 (curr, &bytes_read, 0);
3600 filenum = read_leb128 (curr, &bytes_read, 0);
3603 if ((flags & 2) == 0)
3604 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3607 = get_line_filename_and_dirname (line_offset, filenum,
3609 if (file_name == NULL)
3610 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3613 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3615 dir_name != NULL ? (const char *) dir_name : "",
3616 dir_name != NULL ? "/" : "", file_name);
3620 case DW_MACRO_GNU_end_file:
3621 printf (_(" DW_MACRO_GNU_end_file\n"));
3624 case DW_MACRO_GNU_define:
3625 lineno = read_leb128 (curr, &bytes_read, 0);
3627 string = (char *) curr;
3628 curr += strlen (string) + 1;
3629 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3633 case DW_MACRO_GNU_undef:
3634 lineno = read_leb128 (curr, &bytes_read, 0);
3636 string = (char *) curr;
3637 curr += strlen (string) + 1;
3638 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3642 case DW_MACRO_GNU_define_indirect:
3643 lineno = read_leb128 (curr, &bytes_read, 0);
3645 offset = byte_get (curr, offset_size);
3646 curr += offset_size;
3647 string = fetch_indirect_string (offset);
3648 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3652 case DW_MACRO_GNU_undef_indirect:
3653 lineno = read_leb128 (curr, &bytes_read, 0);
3655 offset = byte_get (curr, offset_size);
3656 curr += offset_size;
3657 string = fetch_indirect_string (offset);
3658 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3662 case DW_MACRO_GNU_transparent_include:
3663 offset = byte_get (curr, offset_size);
3664 curr += offset_size;
3665 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3666 (unsigned long) offset);
3669 case DW_MACRO_GNU_define_indirect_alt:
3670 lineno = read_leb128 (curr, &bytes_read, 0);
3672 offset = byte_get (curr, offset_size);
3673 curr += offset_size;
3674 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3675 lineno, (unsigned long) offset);
3678 case DW_MACRO_GNU_undef_indirect_alt:
3679 lineno = read_leb128 (curr, &bytes_read, 0);
3681 offset = byte_get (curr, offset_size);
3682 curr += offset_size;
3683 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3684 lineno, (unsigned long) offset);
3687 case DW_MACRO_GNU_transparent_include_alt:
3688 offset = byte_get (curr, offset_size);
3689 curr += offset_size;
3690 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
3691 (unsigned long) offset);
3695 if (extended_ops == NULL || extended_ops[op] == NULL)
3697 error (_(" Unknown macro opcode %02x seen\n"), op);
3702 /* Skip over unhandled opcodes. */
3704 unsigned char *desc = extended_ops[op];
3705 nargs = read_leb128 (desc, &bytes_read, 0);
3709 printf (_(" DW_MACRO_GNU_%02x\n"), op);
3712 printf (_(" DW_MACRO_GNU_%02x -"), op);
3713 for (n = 0; n < nargs; n++)
3716 = read_and_display_attr_value (0, byte_get (desc++, 1),
3717 curr, 0, 0, offset_size,
3718 version, NULL, 0, NULL);
3735 display_debug_abbrev (struct dwarf_section *section,
3736 void *file ATTRIBUTE_UNUSED)
3738 abbrev_entry *entry;
3739 unsigned char *start = section->start;
3740 unsigned char *end = start + section->size;
3742 printf (_("Contents of the %s section:\n\n"), section->name);
3746 unsigned char *last;
3751 start = process_abbrev_section (start, end);
3753 if (first_abbrev == NULL)
3756 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
3758 for (entry = first_abbrev; entry; entry = entry->next)
3762 printf (" %ld %s [%s]\n",
3764 get_TAG_name (entry->tag),
3765 entry->children ? _("has children") : _("no children"));
3767 for (attr = entry->first_attr; attr; attr = attr->next)
3768 printf (" %-18s %s\n",
3769 get_AT_name (attr->attribute),
3770 get_FORM_name (attr->form));
3780 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
3783 display_loc_list (struct dwarf_section *section,
3784 unsigned char **start_ptr,
3785 int debug_info_entry,
3786 unsigned long offset,
3787 unsigned long base_address,
3790 unsigned char *start = *start_ptr;
3791 unsigned char *section_end = section->start + section->size;
3792 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3793 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3794 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3795 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3799 unsigned short length;
3800 int need_frame_base;
3804 if (start + 2 * pointer_size > section_end)
3806 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3811 /* Note: we use sign extension here in order to be sure that we can detect
3812 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
3813 address will not affect the values that we display since we always show
3814 hex values, and always the bottom 32-bits. */
3815 begin = byte_get_signed (start, pointer_size);
3816 start += pointer_size;
3817 end = byte_get_signed (start, pointer_size);
3818 start += pointer_size;
3820 printf (" %8.8lx ", offset);
3822 if (begin == 0 && end == 0)
3824 printf (_("<End of list>\n"));
3828 /* Check base address specifiers. */
3829 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3832 print_dwarf_vma (begin, pointer_size);
3833 print_dwarf_vma (end, pointer_size);
3834 printf (_("(base address)\n"));
3838 if (start + 2 > section_end)
3840 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3845 length = byte_get (start, 2);
3848 if (start + length > section_end)
3850 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3855 print_dwarf_vma (begin + base_address, pointer_size);
3856 print_dwarf_vma (end + base_address, pointer_size);
3859 need_frame_base = decode_location_expression (start,
3864 cu_offset, section);
3867 if (need_frame_base && !has_frame_base)
3868 printf (_(" [without DW_AT_frame_base]"));
3871 fputs (_(" (start == end)"), stdout);
3872 else if (begin > end)
3873 fputs (_(" (start > end)"), stdout);
3883 /* Display a location list from a .dwo section. It uses address indexes rather
3884 than embedded addresses. This code closely follows display_loc_list, but the
3885 two are sufficiently different that combining things is very ugly. */
3888 display_loc_list_dwo (struct dwarf_section *section,
3889 unsigned char **start_ptr,
3890 int debug_info_entry,
3891 unsigned long offset,
3894 unsigned char *start = *start_ptr;
3895 unsigned char *section_end = section->start + section->size;
3896 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3897 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3898 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3899 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3901 unsigned short length;
3902 int need_frame_base;
3904 unsigned int bytes_read;
3908 printf (" %8.8lx ", offset);
3910 if (start + 2 > section_end)
3912 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3917 entry_type = byte_get (start, 1);
3921 case 0: /* A terminating entry. */
3922 idx = byte_get (start, 1);
3926 printf (_("<End of list>\n"));
3928 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3931 case 1: /* A base-address entry. */
3932 idx = read_leb128 (start, &bytes_read, 0);
3933 start += bytes_read;
3934 print_dwarf_vma (idx, pointer_size);
3935 printf (_("(base address index)\n"));
3937 case 2: /* A normal entry. */
3938 idx = read_leb128 (start, &bytes_read, 0);
3939 start += bytes_read;
3940 print_dwarf_vma (idx, pointer_size);
3941 idx = read_leb128 (start, &bytes_read, 0);
3942 start += bytes_read;
3943 print_dwarf_vma (idx, pointer_size);
3946 warn (_("Unknown location-list type 0x%x.\n"), entry_type);
3951 if (start + 2 > section_end)
3953 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3958 length = byte_get (start, 2);
3961 if (start + length > section_end)
3963 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3969 need_frame_base = decode_location_expression (start,
3974 cu_offset, section);
3977 if (need_frame_base && !has_frame_base)
3978 printf (_(" [without DW_AT_frame_base]"));
3988 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3990 static dwarf_vma *loc_offsets;
3993 loc_offsets_compar (const void *ap, const void *bp)
3995 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
3996 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
3998 return (a > b) - (b > a);
4002 display_debug_loc (struct dwarf_section *section, void *file)
4004 unsigned char *start = section->start;
4005 unsigned long bytes;
4006 unsigned char *section_begin = start;
4007 unsigned int num_loc_list = 0;
4008 unsigned long last_offset = 0;
4009 unsigned int first = 0;
4013 int seen_first_offset = 0;
4014 int locs_sorted = 1;
4015 unsigned char *next;
4016 unsigned int *array = NULL;
4017 const char *suffix = strrchr (section->name, '.');
4020 if (suffix && strcmp (suffix, ".dwo") == 0)
4023 bytes = section->size;
4027 printf (_("\nThe %s section is empty.\n"), section->name);
4031 if (load_debug_info (file) == 0)
4033 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4038 /* Check the order of location list in .debug_info section. If
4039 offsets of location lists are in the ascending order, we can
4040 use `debug_information' directly. */
4041 for (i = 0; i < num_debug_info_entries; i++)
4045 num = debug_information [i].num_loc_offsets;
4046 if (num > num_loc_list)
4049 /* Check if we can use `debug_information' directly. */
4050 if (locs_sorted && num != 0)
4052 if (!seen_first_offset)
4054 /* This is the first location list. */
4055 last_offset = debug_information [i].loc_offsets [0];
4057 seen_first_offset = 1;
4063 for (; j < num; j++)
4066 debug_information [i].loc_offsets [j])
4071 last_offset = debug_information [i].loc_offsets [j];
4076 if (!seen_first_offset)
4077 error (_("No location lists in .debug_info section!\n"));
4079 /* DWARF sections under Mach-O have non-zero addresses. */
4080 if (debug_information [first].num_loc_offsets > 0
4081 && debug_information [first].loc_offsets [0] != section->address)
4082 warn (_("Location lists in %s section start at 0x%s\n"),
4084 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4087 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4088 printf (_("Contents of the %s section:\n\n"), section->name);
4090 printf (_(" Offset Begin End Expression\n"));
4092 printf (_(" Offset Begin idx End idx Expression\n"));
4094 seen_first_offset = 0;
4095 for (i = first; i < num_debug_info_entries; i++)
4097 unsigned long offset;
4098 unsigned long base_address;
4103 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4105 loc_offsets = debug_information [i].loc_offsets;
4106 qsort (array, debug_information [i].num_loc_offsets,
4107 sizeof (*array), loc_offsets_compar);
4110 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4112 j = locs_sorted ? k : array[k];
4114 && debug_information [i].loc_offsets [locs_sorted
4115 ? k - 1 : array [k - 1]]
4116 == debug_information [i].loc_offsets [j])
4118 has_frame_base = debug_information [i].have_frame_base [j];
4119 /* DWARF sections under Mach-O have non-zero addresses. */
4120 offset = debug_information [i].loc_offsets [j] - section->address;
4121 next = section_begin + offset;
4122 base_address = debug_information [i].base_address;
4124 if (!seen_first_offset)
4125 seen_first_offset = 1;
4129 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4130 (unsigned long) (start - section_begin),
4131 (unsigned long) (next - section_begin));
4132 else if (start > next)
4133 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4134 (unsigned long) (start - section_begin),
4135 (unsigned long) (next - section_begin));
4139 if (offset >= bytes)
4141 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4147 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4149 display_loc_list (section, &start, i, offset, base_address,
4154 if (start < section->start + section->size)
4155 warn (_("There are %ld unused bytes at the end of section %s\n"),
4156 (long) (section->start + section->size - start), section->name);
4163 display_debug_str (struct dwarf_section *section,
4164 void *file ATTRIBUTE_UNUSED)
4166 unsigned char *start = section->start;
4167 unsigned long bytes = section->size;
4168 dwarf_vma addr = section->address;
4172 printf (_("\nThe %s section is empty.\n"), section->name);
4176 printf (_("Contents of the %s section:\n\n"), section->name);
4184 lbytes = (bytes > 16 ? 16 : bytes);
4186 printf (" 0x%8.8lx ", (unsigned long) addr);
4188 for (j = 0; j < 16; j++)
4191 printf ("%2.2x", start[j]);
4199 for (j = 0; j < lbytes; j++)
4202 if (k >= ' ' && k < 0x80)
4221 display_debug_info (struct dwarf_section *section, void *file)
4223 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4227 display_debug_types (struct dwarf_section *section, void *file)
4229 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4233 display_trace_info (struct dwarf_section *section, void *file)
4235 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4239 display_debug_aranges (struct dwarf_section *section,
4240 void *file ATTRIBUTE_UNUSED)
4242 unsigned char *start = section->start;
4243 unsigned char *end = start + section->size;
4245 printf (_("Contents of the %s section:\n\n"), section->name);
4247 /* It does not matter if this load fails,
4248 we test for that later on. */
4249 load_debug_info (file);
4253 unsigned char *hdrptr;
4254 DWARF2_Internal_ARange arange;
4255 unsigned char *addr_ranges;
4258 unsigned char address_size;
4261 int initial_length_size;
4265 arange.ar_length = byte_get (hdrptr, 4);
4268 if (arange.ar_length == 0xffffffff)
4270 arange.ar_length = byte_get (hdrptr, 8);
4273 initial_length_size = 12;
4278 initial_length_size = 4;
4281 arange.ar_version = byte_get (hdrptr, 2);
4284 arange.ar_info_offset = byte_get (hdrptr, offset_size);
4285 hdrptr += offset_size;
4287 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4288 && num_debug_info_entries > 0
4289 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4290 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4291 (unsigned long) arange.ar_info_offset, section->name);
4293 arange.ar_pointer_size = byte_get (hdrptr, 1);
4296 arange.ar_segment_size = byte_get (hdrptr, 1);
4299 if (arange.ar_version != 2 && arange.ar_version != 3)
4301 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4305 printf (_(" Length: %ld\n"),
4306 (long) arange.ar_length);
4307 printf (_(" Version: %d\n"), arange.ar_version);
4308 printf (_(" Offset into .debug_info: 0x%lx\n"),
4309 (unsigned long) arange.ar_info_offset);
4310 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4311 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4313 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4315 if (address_size == 0)
4317 error (_("Invalid address size in %s section!\n"),
4322 /* The DWARF spec does not require that the address size be a power
4323 of two, but we do. This will have to change if we ever encounter
4324 an uneven architecture. */
4325 if ((address_size & (address_size - 1)) != 0)
4327 warn (_("Pointer size + Segment size is not a power of two.\n"));
4331 if (address_size > 4)
4332 printf (_("\n Address Length\n"));
4334 printf (_("\n Address Length\n"));
4336 addr_ranges = hdrptr;
4338 /* Must pad to an alignment boundary that is twice the address size. */
4339 excess = (hdrptr - start) % (2 * address_size);
4341 addr_ranges += (2 * address_size) - excess;
4343 start += arange.ar_length + initial_length_size;
4345 while (addr_ranges + 2 * address_size <= start)
4347 address = byte_get (addr_ranges, address_size);
4349 addr_ranges += address_size;
4351 length = byte_get (addr_ranges, address_size);
4353 addr_ranges += address_size;
4356 print_dwarf_vma (address, address_size);
4357 print_dwarf_vma (length, address_size);
4367 /* Comparison function for qsort. */
4369 comp_addr_base (const void * v0, const void * v1)
4371 debug_info * info0 = (debug_info *) v0;
4372 debug_info * info1 = (debug_info *) v1;
4373 return info0->addr_base - info1->addr_base;
4376 /* Display the debug_addr section. */
4378 display_debug_addr (struct dwarf_section *section,
4381 debug_info **debug_addr_info;
4382 unsigned char *entry;
4387 if (section->size == 0)
4389 printf (_("\nThe %s section is empty.\n"), section->name);
4393 if (load_debug_info (file) == 0)
4395 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4400 printf (_("Contents of the %s section:\n\n"), section->name);
4402 debug_addr_info = (debug_info **) xmalloc (num_debug_info_entries + 1
4403 * sizeof (debug_info *));
4406 for (i = 0; i < num_debug_info_entries; i++)
4408 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4409 debug_addr_info [count++] = &debug_information [i];
4412 /* Add a sentinel to make iteration convenient. */
4413 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4414 debug_addr_info [count]->addr_base = section->size;
4416 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4417 for (i = 0; i < count; i++)
4421 printf (_(" For compilation unit at offset 0x%s:\n"),
4422 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4424 printf (_("\tIndex\tOffset\n"));
4425 entry = section->start + debug_addr_info [i]->addr_base;
4426 end = section->start + debug_addr_info [i + 1]->addr_base;
4430 dwarf_vma base = byte_get (entry, debug_addr_info [i]->pointer_size);
4431 printf (_("\t%d:\t%s\n"), idx, dwarf_vmatoa ("x", base));
4432 entry += debug_addr_info [i]->pointer_size;
4438 free (debug_addr_info);
4442 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4444 display_debug_str_offsets (struct dwarf_section *section,
4445 void *file ATTRIBUTE_UNUSED)
4447 if (section->size == 0)
4449 printf (_("\nThe %s section is empty.\n"), section->name);
4452 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4453 what the offset size is for this section. */
4457 /* Each debug_information[x].range_lists[y] gets this representation for
4458 sorting purposes. */
4462 /* The debug_information[x].range_lists[y] value. */
4463 unsigned long ranges_offset;
4465 /* Original debug_information to find parameters of the data. */
4466 debug_info *debug_info_p;
4469 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4472 range_entry_compar (const void *ap, const void *bp)
4474 const struct range_entry *a_re = (const struct range_entry *) ap;
4475 const struct range_entry *b_re = (const struct range_entry *) bp;
4476 const unsigned long a = a_re->ranges_offset;
4477 const unsigned long b = b_re->ranges_offset;
4479 return (a > b) - (b > a);
4483 display_debug_ranges (struct dwarf_section *section,
4484 void *file ATTRIBUTE_UNUSED)
4486 unsigned char *start = section->start;
4487 unsigned char *last_start = start;
4488 unsigned long bytes;
4489 unsigned char *section_begin = start;
4490 unsigned int num_range_list, i;
4491 struct range_entry *range_entries, *range_entry_fill;
4493 bytes = section->size;
4497 printf (_("\nThe %s section is empty.\n"), section->name);
4501 if (load_debug_info (file) == 0)
4503 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4509 for (i = 0; i < num_debug_info_entries; i++)
4510 num_range_list += debug_information [i].num_range_lists;
4512 if (num_range_list == 0)
4514 /* This can happen when the file was compiled with -gsplit-debug
4515 which removes references to range lists from the primary .o file. */
4516 printf (_("No range lists in .debug_info section.\n"));
4520 range_entries = (struct range_entry *)
4521 xmalloc (sizeof (*range_entries) * num_range_list);
4522 range_entry_fill = range_entries;
4524 for (i = 0; i < num_debug_info_entries; i++)
4526 debug_info *debug_info_p = &debug_information[i];
4529 for (j = 0; j < debug_info_p->num_range_lists; j++)
4531 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4532 range_entry_fill->debug_info_p = debug_info_p;
4537 qsort (range_entries, num_range_list, sizeof (*range_entries),
4538 range_entry_compar);
4540 /* DWARF sections under Mach-O have non-zero addresses. */
4541 if (dwarf_check != 0 && range_entries[0].ranges_offset != section->address)
4542 warn (_("Range lists in %s section start at 0x%lx\n"),
4543 section->name, range_entries[0].ranges_offset);
4545 printf (_("Contents of the %s section:\n\n"), section->name);
4546 printf (_(" Offset Begin End\n"));
4548 for (i = 0; i < num_range_list; i++)
4550 struct range_entry *range_entry = &range_entries[i];
4551 debug_info *debug_info_p = range_entry->debug_info_p;
4552 unsigned int pointer_size;
4553 unsigned long offset;
4554 unsigned char *next;
4555 unsigned long base_address;
4557 pointer_size = debug_info_p->pointer_size;
4559 /* DWARF sections under Mach-O have non-zero addresses. */
4560 offset = range_entry->ranges_offset - section->address;
4561 next = section_begin + offset;
4562 base_address = debug_info_p->base_address;
4564 if (dwarf_check != 0 && i > 0)
4567 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4568 (unsigned long) (start - section_begin),
4569 (unsigned long) (next - section_begin), section->name);
4570 else if (start > next)
4572 if (next == last_start)
4574 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4575 (unsigned long) (start - section_begin),
4576 (unsigned long) (next - section_begin), section->name);
4587 /* Note: we use sign extension here in order to be sure that
4588 we can detect the -1 escape value. Sign extension into the
4589 top 32 bits of a 32-bit address will not affect the values
4590 that we display since we always show hex values, and always
4591 the bottom 32-bits. */
4592 begin = byte_get_signed (start, pointer_size);
4593 start += pointer_size;
4594 end = byte_get_signed (start, pointer_size);
4595 start += pointer_size;
4597 printf (" %8.8lx ", offset);
4599 if (begin == 0 && end == 0)
4601 printf (_("<End of list>\n"));
4605 /* Check base address specifiers. */
4606 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4609 print_dwarf_vma (begin, pointer_size);
4610 print_dwarf_vma (end, pointer_size);
4611 printf ("(base address)\n");
4615 print_dwarf_vma (begin + base_address, pointer_size);
4616 print_dwarf_vma (end + base_address, pointer_size);
4619 fputs (_("(start == end)"), stdout);
4620 else if (begin > end)
4621 fputs (_("(start > end)"), stdout);
4628 free (range_entries);
4633 typedef struct Frame_Chunk
4635 struct Frame_Chunk *next;
4636 unsigned char *chunk_start;
4638 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4639 short int *col_type;
4642 unsigned int code_factor;
4644 unsigned long pc_begin;
4645 unsigned long pc_range;
4649 unsigned char fde_encoding;
4650 unsigned char cfa_exp;
4651 unsigned char ptr_size;
4652 unsigned char segment_size;
4656 static const char *const *dwarf_regnames;
4657 static unsigned int dwarf_regnames_count;
4659 /* A marker for a col_type that means this column was never referenced
4660 in the frame info. */
4661 #define DW_CFA_unreferenced (-1)
4663 /* Return 0 if not more space is needed, 1 if more space is needed,
4664 -1 for invalid reg. */
4667 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4669 int prev = fc->ncols;
4671 if (reg < (unsigned int) fc->ncols)
4674 if (dwarf_regnames_count
4675 && reg > dwarf_regnames_count)
4678 fc->ncols = reg + 1;
4679 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4680 sizeof (short int));
4681 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4683 while (prev < fc->ncols)
4685 fc->col_type[prev] = DW_CFA_unreferenced;
4686 fc->col_offset[prev] = 0;
4692 static const char *const dwarf_regnames_i386[] =
4694 "eax", "ecx", "edx", "ebx",
4695 "esp", "ebp", "esi", "edi",
4696 "eip", "eflags", NULL,
4697 "st0", "st1", "st2", "st3",
4698 "st4", "st5", "st6", "st7",
4700 "xmm0", "xmm1", "xmm2", "xmm3",
4701 "xmm4", "xmm5", "xmm6", "xmm7",
4702 "mm0", "mm1", "mm2", "mm3",
4703 "mm4", "mm5", "mm6", "mm7",
4704 "fcw", "fsw", "mxcsr",
4705 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4710 init_dwarf_regnames_i386 (void)
4712 dwarf_regnames = dwarf_regnames_i386;
4713 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4716 static const char *const dwarf_regnames_x86_64[] =
4718 "rax", "rdx", "rcx", "rbx",
4719 "rsi", "rdi", "rbp", "rsp",
4720 "r8", "r9", "r10", "r11",
4721 "r12", "r13", "r14", "r15",
4723 "xmm0", "xmm1", "xmm2", "xmm3",
4724 "xmm4", "xmm5", "xmm6", "xmm7",
4725 "xmm8", "xmm9", "xmm10", "xmm11",
4726 "xmm12", "xmm13", "xmm14", "xmm15",
4727 "st0", "st1", "st2", "st3",
4728 "st4", "st5", "st6", "st7",
4729 "mm0", "mm1", "mm2", "mm3",
4730 "mm4", "mm5", "mm6", "mm7",
4732 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4733 "fs.base", "gs.base", NULL, NULL,
4735 "mxcsr", "fcw", "fsw"
4739 init_dwarf_regnames_x86_64 (void)
4741 dwarf_regnames = dwarf_regnames_x86_64;
4742 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4746 init_dwarf_regnames (unsigned int e_machine)
4752 init_dwarf_regnames_i386 ();
4758 init_dwarf_regnames_x86_64 ();
4767 regname (unsigned int regno, int row)
4769 static char reg[64];
4771 && regno < dwarf_regnames_count
4772 && dwarf_regnames [regno] != NULL)
4775 return dwarf_regnames [regno];
4776 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4777 dwarf_regnames [regno]);
4780 snprintf (reg, sizeof (reg), "r%d", regno);
4785 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4790 if (*max_regs < fc->ncols)
4791 *max_regs = fc->ncols;
4793 if (*need_col_headers)
4795 static const char *sloc = " LOC";
4797 *need_col_headers = 0;
4799 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4801 for (r = 0; r < *max_regs; r++)
4802 if (fc->col_type[r] != DW_CFA_unreferenced)
4807 printf ("%-5s ", regname (r, 1));
4813 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4815 strcpy (tmp, "exp");
4817 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4818 printf ("%-8s ", tmp);
4820 for (r = 0; r < fc->ncols; r++)
4822 if (fc->col_type[r] != DW_CFA_unreferenced)
4824 switch (fc->col_type[r])
4826 case DW_CFA_undefined:
4829 case DW_CFA_same_value:
4833 sprintf (tmp, "c%+d", fc->col_offset[r]);
4835 case DW_CFA_val_offset:
4836 sprintf (tmp, "v%+d", fc->col_offset[r]);
4838 case DW_CFA_register:
4839 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4841 case DW_CFA_expression:
4842 strcpy (tmp, "exp");
4844 case DW_CFA_val_expression:
4845 strcpy (tmp, "vexp");
4848 strcpy (tmp, "n/a");
4851 printf ("%-5s ", tmp);
4857 #define GET(N) byte_get (start, N); start += N
4858 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4859 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4862 display_debug_frames (struct dwarf_section *section,
4863 void *file ATTRIBUTE_UNUSED)
4865 unsigned char *start = section->start;
4866 unsigned char *end = start + section->size;
4867 unsigned char *section_start = start;
4868 Frame_Chunk *chunks = 0;
4869 Frame_Chunk *remembered_state = 0;
4871 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4872 unsigned int length_return;
4874 const char *bad_reg = _("bad register: ");
4875 int saved_eh_addr_size = eh_addr_size;
4877 printf (_("Contents of the %s section:\n"), section->name);
4881 unsigned char *saved_start;
4882 unsigned char *block_end;
4883 unsigned long length;
4884 unsigned long cie_id;
4887 int need_col_headers = 1;
4888 unsigned char *augmentation_data = NULL;
4889 unsigned long augmentation_data_len = 0;
4890 int encoded_ptr_size = saved_eh_addr_size;
4892 int initial_length_size;
4894 saved_start = start;
4895 length = byte_get (start, 4); start += 4;
4899 printf ("\n%08lx ZERO terminator\n\n",
4900 (unsigned long)(saved_start - section_start));
4904 if (length == 0xffffffff)
4906 length = byte_get (start, 8);
4909 initial_length_size = 12;
4914 initial_length_size = 4;
4917 block_end = saved_start + length + initial_length_size;
4918 if (block_end > end)
4920 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4921 length, (unsigned long)(saved_start - section_start));
4924 cie_id = byte_get (start, offset_size); start += offset_size;
4926 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4930 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4931 memset (fc, 0, sizeof (Frame_Chunk));
4935 fc->chunk_start = saved_start;
4937 fc->col_type = (short int *) xmalloc (sizeof (short int));
4938 fc->col_offset = (int *) xmalloc (sizeof (int));
4939 frame_need_space (fc, max_regs - 1);
4943 fc->augmentation = (char *) start;
4944 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4946 if (strcmp (fc->augmentation, "eh") == 0)
4947 start += eh_addr_size;
4951 fc->ptr_size = GET (1);
4952 fc->segment_size = GET (1);
4953 eh_addr_size = fc->ptr_size;
4957 fc->ptr_size = eh_addr_size;
4958 fc->segment_size = 0;
4960 fc->code_factor = LEB ();
4961 fc->data_factor = SLEB ();
4971 if (fc->augmentation[0] == 'z')
4973 augmentation_data_len = LEB ();
4974 augmentation_data = start;
4975 start += augmentation_data_len;
4979 if (do_debug_frames_interp)
4980 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4981 (unsigned long)(saved_start - section_start), length, cie_id,
4982 fc->augmentation, fc->code_factor, fc->data_factor,
4986 printf ("\n%08lx %08lx %08lx CIE\n",
4987 (unsigned long)(saved_start - section_start), length, cie_id);
4988 printf (" Version: %d\n", version);
4989 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4992 printf (" Pointer Size: %u\n", fc->ptr_size);
4993 printf (" Segment Size: %u\n", fc->segment_size);
4995 printf (" Code alignment factor: %u\n", fc->code_factor);
4996 printf (" Data alignment factor: %d\n", fc->data_factor);
4997 printf (" Return address column: %d\n", fc->ra);
4999 if (augmentation_data_len)
5002 printf (" Augmentation data: ");
5003 for (i = 0; i < augmentation_data_len; ++i)
5004 printf (" %02x", augmentation_data[i]);
5010 if (augmentation_data_len)
5012 unsigned char *p, *q;
5013 p = (unsigned char *) fc->augmentation + 1;
5014 q = augmentation_data;
5021 q += 1 + size_of_encoded_value (*q);
5023 fc->fde_encoding = *q++;
5031 if (fc->fde_encoding)
5032 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5035 frame_need_space (fc, fc->ra);
5039 unsigned char *look_for;
5040 static Frame_Chunk fde_fc;
5041 unsigned long segment_selector;
5044 memset (fc, 0, sizeof (Frame_Chunk));
5046 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
5048 for (cie = chunks; cie ; cie = cie->next)
5049 if (cie->chunk_start == look_for)
5054 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
5055 cie_id, (unsigned long)(saved_start - section_start));
5057 fc->col_type = (short int *) xmalloc (sizeof (short int));
5058 fc->col_offset = (int *) xmalloc (sizeof (int));
5059 frame_need_space (fc, max_regs - 1);
5061 fc->augmentation = "";
5062 fc->fde_encoding = 0;
5063 fc->ptr_size = eh_addr_size;
5064 fc->segment_size = 0;
5068 fc->ncols = cie->ncols;
5069 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5070 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5071 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5072 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5073 fc->augmentation = cie->augmentation;
5074 fc->ptr_size = cie->ptr_size;
5075 eh_addr_size = cie->ptr_size;
5076 fc->segment_size = cie->segment_size;
5077 fc->code_factor = cie->code_factor;
5078 fc->data_factor = cie->data_factor;
5079 fc->cfa_reg = cie->cfa_reg;
5080 fc->cfa_offset = cie->cfa_offset;
5082 frame_need_space (fc, max_regs - 1);
5083 fc->fde_encoding = cie->fde_encoding;
5086 if (fc->fde_encoding)
5087 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5089 segment_selector = 0;
5090 if (fc->segment_size)
5092 segment_selector = byte_get (start, fc->segment_size);
5093 start += fc->segment_size;
5095 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
5096 start += encoded_ptr_size;
5097 fc->pc_range = byte_get (start, encoded_ptr_size);
5098 start += encoded_ptr_size;
5100 if (cie->augmentation[0] == 'z')
5102 augmentation_data_len = LEB ();
5103 augmentation_data = start;
5104 start += augmentation_data_len;
5107 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
5108 (unsigned long)(saved_start - section_start), length, cie_id,
5109 (unsigned long)(cie->chunk_start - section_start));
5110 if (fc->segment_size)
5111 printf ("%04lx:", segment_selector);
5112 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
5113 if (! do_debug_frames_interp && augmentation_data_len)
5117 printf (" Augmentation data: ");
5118 for (i = 0; i < augmentation_data_len; ++i)
5119 printf (" %02x", augmentation_data[i]);
5125 /* At this point, fc is the current chunk, cie (if any) is set, and
5126 we're about to interpret instructions for the chunk. */
5127 /* ??? At present we need to do this always, since this sizes the
5128 fc->col_type and fc->col_offset arrays, which we write into always.
5129 We should probably split the interpreted and non-interpreted bits
5130 into two different routines, since there's so much that doesn't
5131 really overlap between them. */
5132 if (1 || do_debug_frames_interp)
5134 /* Start by making a pass over the chunk, allocating storage
5135 and taking note of what registers are used. */
5136 unsigned char *tmp = start;
5138 while (start < block_end)
5141 unsigned long reg, temp;
5148 /* Warning: if you add any more cases to this switch, be
5149 sure to add them to the corresponding switch below. */
5152 case DW_CFA_advance_loc:
5156 if (frame_need_space (fc, opa) >= 0)
5157 fc->col_type[opa] = DW_CFA_undefined;
5159 case DW_CFA_restore:
5160 if (frame_need_space (fc, opa) >= 0)
5161 fc->col_type[opa] = DW_CFA_undefined;
5163 case DW_CFA_set_loc:
5164 start += encoded_ptr_size;
5166 case DW_CFA_advance_loc1:
5169 case DW_CFA_advance_loc2:
5172 case DW_CFA_advance_loc4:
5175 case DW_CFA_offset_extended:
5176 case DW_CFA_val_offset:
5177 reg = LEB (); LEB ();
5178 if (frame_need_space (fc, reg) >= 0)
5179 fc->col_type[reg] = DW_CFA_undefined;
5181 case DW_CFA_restore_extended:
5183 frame_need_space (fc, reg);
5184 if (frame_need_space (fc, reg) >= 0)
5185 fc->col_type[reg] = DW_CFA_undefined;
5187 case DW_CFA_undefined:
5189 if (frame_need_space (fc, reg) >= 0)
5190 fc->col_type[reg] = DW_CFA_undefined;
5192 case DW_CFA_same_value:
5194 if (frame_need_space (fc, reg) >= 0)
5195 fc->col_type[reg] = DW_CFA_undefined;
5197 case DW_CFA_register:
5198 reg = LEB (); LEB ();
5199 if (frame_need_space (fc, reg) >= 0)
5200 fc->col_type[reg] = DW_CFA_undefined;
5202 case DW_CFA_def_cfa:
5205 case DW_CFA_def_cfa_register:
5208 case DW_CFA_def_cfa_offset:
5211 case DW_CFA_def_cfa_expression:
5215 case DW_CFA_expression:
5216 case DW_CFA_val_expression:
5220 if (frame_need_space (fc, reg) >= 0)
5221 fc->col_type[reg] = DW_CFA_undefined;
5223 case DW_CFA_offset_extended_sf:
5224 case DW_CFA_val_offset_sf:
5225 reg = LEB (); SLEB ();
5226 if (frame_need_space (fc, reg) >= 0)
5227 fc->col_type[reg] = DW_CFA_undefined;
5229 case DW_CFA_def_cfa_sf:
5232 case DW_CFA_def_cfa_offset_sf:
5235 case DW_CFA_MIPS_advance_loc8:
5238 case DW_CFA_GNU_args_size:
5241 case DW_CFA_GNU_negative_offset_extended:
5242 reg = LEB (); LEB ();
5243 if (frame_need_space (fc, reg) >= 0)
5244 fc->col_type[reg] = DW_CFA_undefined;
5253 /* Now we know what registers are used, make a second pass over
5254 the chunk, this time actually printing out the info. */
5256 while (start < block_end)
5259 unsigned long ul, reg, roffs;
5262 const char *reg_prefix = "";
5269 /* Warning: if you add any more cases to this switch, be
5270 sure to add them to the corresponding switch above. */
5273 case DW_CFA_advance_loc:
5274 if (do_debug_frames_interp)
5275 frame_display_row (fc, &need_col_headers, &max_regs);
5277 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5278 opa * fc->code_factor,
5279 fc->pc_begin + opa * fc->code_factor);
5280 fc->pc_begin += opa * fc->code_factor;
5285 if (opa >= (unsigned int) fc->ncols)
5286 reg_prefix = bad_reg;
5287 if (! do_debug_frames_interp || *reg_prefix != '\0')
5288 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5289 reg_prefix, regname (opa, 0),
5290 roffs * fc->data_factor);
5291 if (*reg_prefix == '\0')
5293 fc->col_type[opa] = DW_CFA_offset;
5294 fc->col_offset[opa] = roffs * fc->data_factor;
5298 case DW_CFA_restore:
5299 if (opa >= (unsigned int) cie->ncols
5300 || opa >= (unsigned int) fc->ncols)
5301 reg_prefix = bad_reg;
5302 if (! do_debug_frames_interp || *reg_prefix != '\0')
5303 printf (" DW_CFA_restore: %s%s\n",
5304 reg_prefix, regname (opa, 0));
5305 if (*reg_prefix == '\0')
5307 fc->col_type[opa] = cie->col_type[opa];
5308 fc->col_offset[opa] = cie->col_offset[opa];
5309 if (do_debug_frames_interp
5310 && fc->col_type[opa] == DW_CFA_unreferenced)
5311 fc->col_type[opa] = DW_CFA_undefined;
5315 case DW_CFA_set_loc:
5316 vma = get_encoded_value (start, fc->fde_encoding, section);
5317 start += encoded_ptr_size;
5318 if (do_debug_frames_interp)
5319 frame_display_row (fc, &need_col_headers, &max_regs);
5321 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5325 case DW_CFA_advance_loc1:
5326 ofs = byte_get (start, 1); start += 1;
5327 if (do_debug_frames_interp)
5328 frame_display_row (fc, &need_col_headers, &max_regs);
5330 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5331 ofs * fc->code_factor,
5332 fc->pc_begin + ofs * fc->code_factor);
5333 fc->pc_begin += ofs * fc->code_factor;
5336 case DW_CFA_advance_loc2:
5337 ofs = byte_get (start, 2); start += 2;
5338 if (do_debug_frames_interp)
5339 frame_display_row (fc, &need_col_headers, &max_regs);
5341 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5342 ofs * fc->code_factor,
5343 fc->pc_begin + ofs * fc->code_factor);
5344 fc->pc_begin += ofs * fc->code_factor;
5347 case DW_CFA_advance_loc4:
5348 ofs = byte_get (start, 4); start += 4;
5349 if (do_debug_frames_interp)
5350 frame_display_row (fc, &need_col_headers, &max_regs);
5352 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5353 ofs * fc->code_factor,
5354 fc->pc_begin + ofs * fc->code_factor);
5355 fc->pc_begin += ofs * fc->code_factor;
5358 case DW_CFA_offset_extended:
5361 if (reg >= (unsigned int) fc->ncols)
5362 reg_prefix = bad_reg;
5363 if (! do_debug_frames_interp || *reg_prefix != '\0')
5364 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5365 reg_prefix, regname (reg, 0),
5366 roffs * fc->data_factor);
5367 if (*reg_prefix == '\0')
5369 fc->col_type[reg] = DW_CFA_offset;
5370 fc->col_offset[reg] = roffs * fc->data_factor;
5374 case DW_CFA_val_offset:
5377 if (reg >= (unsigned int) fc->ncols)
5378 reg_prefix = bad_reg;
5379 if (! do_debug_frames_interp || *reg_prefix != '\0')
5380 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5381 reg_prefix, regname (reg, 0),
5382 roffs * fc->data_factor);
5383 if (*reg_prefix == '\0')
5385 fc->col_type[reg] = DW_CFA_val_offset;
5386 fc->col_offset[reg] = roffs * fc->data_factor;
5390 case DW_CFA_restore_extended:
5392 if (reg >= (unsigned int) cie->ncols
5393 || reg >= (unsigned int) fc->ncols)
5394 reg_prefix = bad_reg;
5395 if (! do_debug_frames_interp || *reg_prefix != '\0')
5396 printf (" DW_CFA_restore_extended: %s%s\n",
5397 reg_prefix, regname (reg, 0));
5398 if (*reg_prefix == '\0')
5400 fc->col_type[reg] = cie->col_type[reg];
5401 fc->col_offset[reg] = cie->col_offset[reg];
5405 case DW_CFA_undefined:
5407 if (reg >= (unsigned int) fc->ncols)
5408 reg_prefix = bad_reg;
5409 if (! do_debug_frames_interp || *reg_prefix != '\0')
5410 printf (" DW_CFA_undefined: %s%s\n",
5411 reg_prefix, regname (reg, 0));
5412 if (*reg_prefix == '\0')
5414 fc->col_type[reg] = DW_CFA_undefined;
5415 fc->col_offset[reg] = 0;
5419 case DW_CFA_same_value:
5421 if (reg >= (unsigned int) fc->ncols)
5422 reg_prefix = bad_reg;
5423 if (! do_debug_frames_interp || *reg_prefix != '\0')
5424 printf (" DW_CFA_same_value: %s%s\n",
5425 reg_prefix, regname (reg, 0));
5426 if (*reg_prefix == '\0')
5428 fc->col_type[reg] = DW_CFA_same_value;
5429 fc->col_offset[reg] = 0;
5433 case DW_CFA_register:
5436 if (reg >= (unsigned int) fc->ncols)
5437 reg_prefix = bad_reg;
5438 if (! do_debug_frames_interp || *reg_prefix != '\0')
5440 printf (" DW_CFA_register: %s%s in ",
5441 reg_prefix, regname (reg, 0));
5442 puts (regname (roffs, 0));
5444 if (*reg_prefix == '\0')
5446 fc->col_type[reg] = DW_CFA_register;
5447 fc->col_offset[reg] = roffs;
5451 case DW_CFA_remember_state:
5452 if (! do_debug_frames_interp)
5453 printf (" DW_CFA_remember_state\n");
5454 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5455 rs->ncols = fc->ncols;
5456 rs->col_type = (short int *) xcmalloc (rs->ncols,
5457 sizeof (short int));
5458 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
5459 memcpy (rs->col_type, fc->col_type, rs->ncols);
5460 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5461 rs->next = remembered_state;
5462 remembered_state = rs;
5465 case DW_CFA_restore_state:
5466 if (! do_debug_frames_interp)
5467 printf (" DW_CFA_restore_state\n");
5468 rs = remembered_state;
5471 remembered_state = rs->next;
5472 frame_need_space (fc, rs->ncols - 1);
5473 memcpy (fc->col_type, rs->col_type, rs->ncols);
5474 memcpy (fc->col_offset, rs->col_offset,
5475 rs->ncols * sizeof (int));
5476 free (rs->col_type);
5477 free (rs->col_offset);
5480 else if (do_debug_frames_interp)
5481 printf ("Mismatched DW_CFA_restore_state\n");
5484 case DW_CFA_def_cfa:
5485 fc->cfa_reg = LEB ();
5486 fc->cfa_offset = LEB ();
5488 if (! do_debug_frames_interp)
5489 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5490 regname (fc->cfa_reg, 0), fc->cfa_offset);
5493 case DW_CFA_def_cfa_register:
5494 fc->cfa_reg = LEB ();
5496 if (! do_debug_frames_interp)
5497 printf (" DW_CFA_def_cfa_register: %s\n",
5498 regname (fc->cfa_reg, 0));
5501 case DW_CFA_def_cfa_offset:
5502 fc->cfa_offset = LEB ();
5503 if (! do_debug_frames_interp)
5504 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5508 if (! do_debug_frames_interp)
5509 printf (" DW_CFA_nop\n");
5512 case DW_CFA_def_cfa_expression:
5514 if (! do_debug_frames_interp)
5516 printf (" DW_CFA_def_cfa_expression (");
5517 decode_location_expression (start, eh_addr_size, 0, -1,
5525 case DW_CFA_expression:
5528 if (reg >= (unsigned int) fc->ncols)
5529 reg_prefix = bad_reg;
5530 if (! do_debug_frames_interp || *reg_prefix != '\0')
5532 printf (" DW_CFA_expression: %s%s (",
5533 reg_prefix, regname (reg, 0));
5534 decode_location_expression (start, eh_addr_size, 0, -1,
5538 if (*reg_prefix == '\0')
5539 fc->col_type[reg] = DW_CFA_expression;
5543 case DW_CFA_val_expression:
5546 if (reg >= (unsigned int) fc->ncols)
5547 reg_prefix = bad_reg;
5548 if (! do_debug_frames_interp || *reg_prefix != '\0')
5550 printf (" DW_CFA_val_expression: %s%s (",
5551 reg_prefix, regname (reg, 0));
5552 decode_location_expression (start, eh_addr_size, 0, -1,
5556 if (*reg_prefix == '\0')
5557 fc->col_type[reg] = DW_CFA_val_expression;
5561 case DW_CFA_offset_extended_sf:
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_offset_extended_sf: %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;
5577 case DW_CFA_val_offset_sf:
5580 if (frame_need_space (fc, reg) < 0)
5581 reg_prefix = bad_reg;
5582 if (! do_debug_frames_interp || *reg_prefix != '\0')
5583 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5584 reg_prefix, regname (reg, 0),
5585 l * fc->data_factor);
5586 if (*reg_prefix == '\0')
5588 fc->col_type[reg] = DW_CFA_val_offset;
5589 fc->col_offset[reg] = l * fc->data_factor;
5593 case DW_CFA_def_cfa_sf:
5594 fc->cfa_reg = LEB ();
5595 fc->cfa_offset = SLEB ();
5596 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5598 if (! do_debug_frames_interp)
5599 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5600 regname (fc->cfa_reg, 0), fc->cfa_offset);
5603 case DW_CFA_def_cfa_offset_sf:
5604 fc->cfa_offset = SLEB ();
5605 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5606 if (! do_debug_frames_interp)
5607 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5610 case DW_CFA_MIPS_advance_loc8:
5611 ofs = byte_get (start, 8); start += 8;
5612 if (do_debug_frames_interp)
5613 frame_display_row (fc, &need_col_headers, &max_regs);
5615 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5616 ofs * fc->code_factor,
5617 fc->pc_begin + ofs * fc->code_factor);
5618 fc->pc_begin += ofs * fc->code_factor;
5621 case DW_CFA_GNU_window_save:
5622 if (! do_debug_frames_interp)
5623 printf (" DW_CFA_GNU_window_save\n");
5626 case DW_CFA_GNU_args_size:
5628 if (! do_debug_frames_interp)
5629 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5632 case DW_CFA_GNU_negative_offset_extended:
5635 if (frame_need_space (fc, reg) < 0)
5636 reg_prefix = bad_reg;
5637 if (! do_debug_frames_interp || *reg_prefix != '\0')
5638 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5639 reg_prefix, regname (reg, 0),
5640 l * fc->data_factor);
5641 if (*reg_prefix == '\0')
5643 fc->col_type[reg] = DW_CFA_offset;
5644 fc->col_offset[reg] = l * fc->data_factor;
5649 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5650 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5652 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5657 if (do_debug_frames_interp)
5658 frame_display_row (fc, &need_col_headers, &max_regs);
5661 eh_addr_size = saved_eh_addr_size;
5674 display_gdb_index (struct dwarf_section *section,
5675 void *file ATTRIBUTE_UNUSED)
5677 unsigned char *start = section->start;
5679 uint32_t cu_list_offset, tu_list_offset;
5680 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5681 unsigned int cu_list_elements, tu_list_elements;
5682 unsigned int address_table_size, symbol_table_slots;
5683 unsigned char *cu_list, *tu_list;
5684 unsigned char *address_table, *symbol_table, *constant_pool;
5687 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5689 printf (_("Contents of the %s section:\n"), section->name);
5691 if (section->size < 6 * sizeof (uint32_t))
5693 warn (_("Truncated header in the %s section.\n"), section->name);
5697 version = byte_get_little_endian (start, 4);
5698 printf (_("Version %ld\n"), (long) version);
5700 /* Prior versions are obsolete, and future versions may not be
5701 backwards compatible. */
5702 if (version < 3 || version > 7)
5704 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5708 warn (_("The address table data in version 3 may be wrong.\n"));
5710 warn (_("Version 4 does not support case insensitive lookups.\n"));
5712 warn (_("Version 5 does not include inlined functions.\n"));
5714 warn (_("Version 6 does not include symbol attributes.\n"));
5716 cu_list_offset = byte_get_little_endian (start + 4, 4);
5717 tu_list_offset = byte_get_little_endian (start + 8, 4);
5718 address_table_offset = byte_get_little_endian (start + 12, 4);
5719 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5720 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5722 if (cu_list_offset > section->size
5723 || tu_list_offset > section->size
5724 || address_table_offset > section->size
5725 || symbol_table_offset > section->size
5726 || constant_pool_offset > section->size)
5728 warn (_("Corrupt header in the %s section.\n"), section->name);
5732 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5733 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5734 address_table_size = symbol_table_offset - address_table_offset;
5735 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5737 cu_list = start + cu_list_offset;
5738 tu_list = start + tu_list_offset;
5739 address_table = start + address_table_offset;
5740 symbol_table = start + symbol_table_offset;
5741 constant_pool = start + constant_pool_offset;
5743 printf (_("\nCU table:\n"));
5744 for (i = 0; i < cu_list_elements; i += 2)
5746 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5747 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5749 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5750 (unsigned long) cu_offset,
5751 (unsigned long) (cu_offset + cu_length - 1));
5754 printf (_("\nTU table:\n"));
5755 for (i = 0; i < tu_list_elements; i += 3)
5757 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5758 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5759 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5761 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5762 (unsigned long) tu_offset,
5763 (unsigned long) type_offset);
5764 print_dwarf_vma (signature, 8);
5768 printf (_("\nAddress table:\n"));
5769 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5771 uint64_t low = byte_get_little_endian (address_table + i, 8);
5772 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5773 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5775 print_dwarf_vma (low, 8);
5776 print_dwarf_vma (high, 8);
5777 printf (_("%lu\n"), (unsigned long) cu_index);
5780 printf (_("\nSymbol table:\n"));
5781 for (i = 0; i < symbol_table_slots; ++i)
5783 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5784 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5785 uint32_t num_cus, cu;
5787 if (name_offset != 0
5788 || cu_vector_offset != 0)
5792 printf ("[%3u] %s:", i, constant_pool + name_offset);
5793 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5796 for (j = 0; j < num_cus; ++j)
5799 gdb_index_symbol_kind kind;
5801 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5802 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
5803 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
5804 cu = GDB_INDEX_CU_VALUE (cu);
5805 /* Convert to TU number if it's for a type unit. */
5806 if (cu >= cu_list_elements / 2)
5807 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
5808 (unsigned long) (cu - cu_list_elements / 2));
5810 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
5814 case GDB_INDEX_SYMBOL_KIND_NONE:
5815 printf (_(" [no symbol information]"));
5817 case GDB_INDEX_SYMBOL_KIND_TYPE:
5819 ? _(" [static type]")
5820 : _(" [global type]"));
5822 case GDB_INDEX_SYMBOL_KIND_VARIABLE:
5824 ? _(" [static variable]")
5825 : _(" [global variable]"));
5827 case GDB_INDEX_SYMBOL_KIND_FUNCTION:
5829 ? _(" [static function]")
5830 : _(" [global function]"));
5832 case GDB_INDEX_SYMBOL_KIND_OTHER:
5834 ? _(" [static other]")
5835 : _(" [global other]"));
5839 ? _(" [static unknown: %d]")
5840 : _(" [global unknown: %d]"),
5855 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
5856 sections. Each set is stored in SHNDX_POOL as a zero-terminated list of
5857 section indexes comprising one set of debug sections from a .dwo file. */
5859 int cu_tu_indexes_read = 0;
5860 unsigned int *shndx_pool = NULL;
5861 unsigned int shndx_pool_size = 0;
5862 unsigned int shndx_pool_used = 0;
5864 /* Pre-allocate enough space for the CU/TU sets needed. */
5867 prealloc_cu_tu_list (unsigned int nshndx)
5869 if (shndx_pool == NULL)
5871 shndx_pool_size = nshndx;
5872 shndx_pool_used = 0;
5873 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
5874 sizeof (unsigned int));
5878 shndx_pool_size = shndx_pool_used + nshndx;
5879 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
5880 sizeof (unsigned int));
5885 add_shndx_to_cu_tu_entry (unsigned int shndx)
5887 if (shndx_pool_used >= shndx_pool_size)
5889 error (_("Internal error: out of space in the shndx pool.\n"));
5892 shndx_pool [shndx_pool_used++] = shndx;
5896 end_cu_tu_entry (void)
5898 if (shndx_pool_used >= shndx_pool_size)
5900 error (_("Internal error: out of space in the shndx pool.\n"));
5903 shndx_pool [shndx_pool_used++] = 0;
5906 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. */
5909 process_cu_tu_index (struct dwarf_section *section, int do_display)
5911 unsigned char *phdr = section->start;
5912 unsigned char *limit = phdr + section->size;
5913 unsigned char *phash;
5914 unsigned char *pindex;
5915 unsigned char *ppool;
5916 unsigned int version;
5918 unsigned int nslots;
5921 version = byte_get (phdr, 4);
5922 nused = byte_get (phdr + 8, 4);
5923 nslots = byte_get (phdr + 12, 4);
5925 pindex = phash + nslots * 8;
5926 ppool = pindex + nslots * 4;
5929 prealloc_cu_tu_list((limit - ppool) / 4);
5933 printf (_("Contents of the %s section:\n\n"), section->name);
5934 printf (_(" Version: %d\n"), version);
5935 printf (_(" Number of used entries: %d\n"), nused);
5936 printf (_(" Number of slots: %d\n\n"), nslots);
5941 warn (_("Section %s too small for %d hash table entries\n"),
5942 section->name, nslots);
5946 for (i = 0; i < nslots; i++)
5948 dwarf_vma signature_high;
5949 dwarf_vma signature_low;
5951 unsigned char *shndx_list;
5955 byte_get_64 (phash, &signature_high, &signature_low);
5956 if (signature_high != 0 || signature_low != 0)
5958 j = byte_get (pindex, 4);
5959 shndx_list = ppool + j * 4;
5961 printf (_(" [%3d] Signature: 0x%s Sections: "),
5962 i, dwarf_vmatoa64 (signature_high, signature_low,
5963 buf, sizeof (buf)));
5966 if (shndx_list >= limit)
5968 warn (_("Section %s too small for shndx pool\n"),
5972 shndx = byte_get (shndx_list, 4);
5976 printf (" %d", shndx);
5978 add_shndx_to_cu_tu_entry (shndx);
5996 /* Load the CU and TU indexes if present. This will build a list of
5997 section sets that we can use to associate a .debug_info.dwo section
5998 with its associated .debug_abbrev.dwo section in a .dwp file. */
6001 load_cu_tu_indexes (void *file)
6003 /* If we have already loaded (or tried to load) the CU and TU indexes
6004 then do not bother to repeat the task. */
6005 if (cu_tu_indexes_read)
6008 if (load_debug_section (dwp_cu_index, file))
6009 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
6011 if (load_debug_section (dwp_tu_index, file))
6012 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
6014 cu_tu_indexes_read = 1;
6017 /* Find the set of sections that includes section SHNDX. */
6020 find_cu_tu_set (void *file, unsigned int shndx)
6024 load_cu_tu_indexes (file);
6026 /* Find SHNDX in the shndx pool. */
6027 for (i = 0; i < shndx_pool_used; i++)
6028 if (shndx_pool [i] == shndx)
6031 if (i >= shndx_pool_used)
6034 /* Now backup to find the first entry in the set. */
6035 while (i > 0 && shndx_pool [i - 1] != 0)
6038 return shndx_pool + i;
6041 /* Display a .debug_cu_index or .debug_tu_index section. */
6044 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
6046 return process_cu_tu_index (section, 1);
6050 display_debug_not_supported (struct dwarf_section *section,
6051 void *file ATTRIBUTE_UNUSED)
6053 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6060 cmalloc (size_t nmemb, size_t size)
6062 /* Check for overflow. */
6063 if (nmemb >= ~(size_t) 0 / size)
6066 return malloc (nmemb * size);
6070 xcmalloc (size_t nmemb, size_t size)
6072 /* Check for overflow. */
6073 if (nmemb >= ~(size_t) 0 / size)
6076 return xmalloc (nmemb * size);
6080 xcrealloc (void *ptr, size_t nmemb, size_t size)
6082 /* Check for overflow. */
6083 if (nmemb >= ~(size_t) 0 / size)
6086 return xrealloc (ptr, nmemb * size);
6090 free_debug_memory (void)
6096 for (i = 0; i < max; i++)
6097 free_debug_section ((enum dwarf_section_display_enum) i);
6099 if (debug_information != NULL)
6101 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
6103 for (i = 0; i < num_debug_info_entries; i++)
6105 if (!debug_information [i].max_loc_offsets)
6107 free (debug_information [i].loc_offsets);
6108 free (debug_information [i].have_frame_base);
6110 if (!debug_information [i].max_range_lists)
6111 free (debug_information [i].range_lists);
6115 free (debug_information);
6116 debug_information = NULL;
6117 num_debug_info_entries = 0;
6122 dwarf_select_sections_by_names (const char *names)
6126 const char * option;
6130 debug_dump_long_opts;
6132 static const debug_dump_long_opts opts_table [] =
6134 /* Please keep this table alpha- sorted. */
6135 { "Ranges", & do_debug_ranges, 1 },
6136 { "abbrev", & do_debug_abbrevs, 1 },
6137 { "addr", & do_debug_addr, 1 },
6138 { "aranges", & do_debug_aranges, 1 },
6139 { "cu_index", & do_debug_cu_index, 1 },
6140 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
6141 { "frames", & do_debug_frames, 1 },
6142 { "frames-interp", & do_debug_frames_interp, 1 },
6143 /* The special .gdb_index section. */
6144 { "gdb_index", & do_gdb_index, 1 },
6145 { "info", & do_debug_info, 1 },
6146 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
6147 { "loc", & do_debug_loc, 1 },
6148 { "macro", & do_debug_macinfo, 1 },
6149 { "pubnames", & do_debug_pubnames, 1 },
6150 { "pubtypes", & do_debug_pubtypes, 1 },
6151 /* This entry is for compatability
6152 with earlier versions of readelf. */
6153 { "ranges", & do_debug_aranges, 1 },
6154 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
6155 { "str", & do_debug_str, 1 },
6156 /* These trace_* sections are used by Itanium VMS. */
6157 { "trace_abbrev", & do_trace_abbrevs, 1 },
6158 { "trace_aranges", & do_trace_aranges, 1 },
6159 { "trace_info", & do_trace_info, 1 },
6168 const debug_dump_long_opts * entry;
6170 for (entry = opts_table; entry->option; entry++)
6172 size_t len = strlen (entry->option);
6174 if (strncmp (p, entry->option, len) == 0
6175 && (p[len] == ',' || p[len] == '\0'))
6177 * entry->variable |= entry->val;
6179 /* The --debug-dump=frames-interp option also
6180 enables the --debug-dump=frames option. */
6181 if (do_debug_frames_interp)
6182 do_debug_frames = 1;
6189 if (entry->option == NULL)
6191 warn (_("Unrecognized debug option '%s'\n"), p);
6192 p = strchr (p, ',');
6203 dwarf_select_sections_by_letters (const char *letters)
6205 unsigned int lindex = 0;
6207 while (letters[lindex])
6208 switch (letters[lindex++])
6215 do_debug_abbrevs = 1;
6219 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
6223 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
6227 do_debug_pubnames = 1;
6231 do_debug_pubtypes = 1;
6235 do_debug_aranges = 1;
6239 do_debug_ranges = 1;
6243 do_debug_frames_interp = 1;
6245 do_debug_frames = 1;
6249 do_debug_macinfo = 1;
6261 warn (_("Unrecognized debug option '%s'\n"), optarg);
6267 dwarf_select_sections_all (void)
6270 do_debug_abbrevs = 1;
6271 do_debug_lines = FLAG_DEBUG_LINES_RAW;
6272 do_debug_pubnames = 1;
6273 do_debug_pubtypes = 1;
6274 do_debug_aranges = 1;
6275 do_debug_ranges = 1;
6276 do_debug_frames = 1;
6277 do_debug_macinfo = 1;
6282 do_trace_abbrevs = 1;
6283 do_trace_aranges = 1;
6285 do_debug_cu_index = 1;
6288 struct dwarf_section_display debug_displays[] =
6290 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0 },
6291 display_debug_abbrev, &do_debug_abbrevs, 0 },
6292 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0 },
6293 display_debug_aranges, &do_debug_aranges, 1 },
6294 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0 },
6295 display_debug_frames, &do_debug_frames, 1 },
6296 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev },
6297 display_debug_info, &do_debug_info, 1 },
6298 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0 },
6299 display_debug_lines, &do_debug_lines, 1 },
6300 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0 },
6301 display_debug_pubnames, &do_debug_pubnames, 0 },
6302 { { ".eh_frame", "", NULL, NULL, 0, 0, 0 },
6303 display_debug_frames, &do_debug_frames, 1 },
6304 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0 },
6305 display_debug_macinfo, &do_debug_macinfo, 0 },
6306 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0 },
6307 display_debug_macro, &do_debug_macinfo, 1 },
6308 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0 },
6309 display_debug_str, &do_debug_str, 0 },
6310 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0 },
6311 display_debug_loc, &do_debug_loc, 1 },
6312 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0 },
6313 display_debug_pubnames, &do_debug_pubtypes, 0 },
6314 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0 },
6315 display_debug_ranges, &do_debug_ranges, 1 },
6316 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0 },
6317 display_debug_not_supported, NULL, 0 },
6318 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0 },
6319 display_debug_not_supported, NULL, 0 },
6320 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev },
6321 display_debug_types, &do_debug_info, 1 },
6322 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0 },
6323 display_debug_not_supported, NULL, 0 },
6324 { { ".gdb_index", "", NULL, NULL, 0, 0, 0 },
6325 display_gdb_index, &do_gdb_index, 0 },
6326 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev },
6327 display_trace_info, &do_trace_info, 1 },
6328 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0 },
6329 display_debug_abbrev, &do_trace_abbrevs, 0 },
6330 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0 },
6331 display_debug_aranges, &do_trace_aranges, 0 },
6332 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6333 display_debug_info, &do_debug_info, 1 },
6334 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0 },
6335 display_debug_abbrev, &do_debug_abbrevs, 0 },
6336 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6337 display_debug_types, &do_debug_info, 1 },
6338 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0 },
6339 display_debug_lines, &do_debug_lines, 1 },
6340 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0 },
6341 display_debug_loc, &do_debug_loc, 1 },
6342 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0 },
6343 display_debug_macro, &do_debug_macinfo, 1 },
6344 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0 },
6345 display_debug_macinfo, &do_debug_macinfo, 0 },
6346 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0 },
6347 display_debug_str, &do_debug_str, 1 },
6348 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0 },
6349 display_debug_str_offsets, NULL, 0 },
6350 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0 },
6351 display_debug_str_offsets, NULL, 0 },
6352 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0 },
6353 display_debug_addr, &do_debug_addr, 1 },
6354 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0 },
6355 display_cu_index, &do_debug_cu_index, 0 },
6356 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0 },
6357 display_cu_index, &do_debug_cu_index, 0 },