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 printf (" %8.8lx ", offset + (start - *start_ptr));
3813 /* Note: we use sign extension here in order to be sure that we can detect
3814 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
3815 address will not affect the values that we display since we always show
3816 hex values, and always the bottom 32-bits. */
3817 begin = byte_get_signed (start, pointer_size);
3818 start += pointer_size;
3819 end = byte_get_signed (start, pointer_size);
3820 start += pointer_size;
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 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
3884 right-adjusted in a field of length LEN, and followed by a space. */
3887 print_addr_index (unsigned int idx, unsigned int len)
3889 static char buf[15];
3890 snprintf (buf, sizeof (buf), "[%d]", idx);
3891 printf("%*s ", len, buf);
3894 /* Display a location list from a .dwo section. It uses address indexes rather
3895 than embedded addresses. This code closely follows display_loc_list, but the
3896 two are sufficiently different that combining things is very ugly. */
3899 display_loc_list_dwo (struct dwarf_section *section,
3900 unsigned char **start_ptr,
3901 int debug_info_entry,
3902 unsigned long offset,
3905 unsigned char *start = *start_ptr;
3906 unsigned char *section_end = section->start + section->size;
3907 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3908 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3909 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3910 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3912 unsigned short length;
3913 int need_frame_base;
3915 unsigned int bytes_read;
3919 printf (" %8.8lx ", offset + (start - *start_ptr));
3921 if (start >= section_end)
3923 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3928 entry_type = byte_get (start, 1);
3932 case 0: /* A terminating entry. */
3934 printf (_("<End of list>\n"));
3936 case 1: /* A base-address entry. */
3937 idx = read_leb128 (start, &bytes_read, 0);
3938 start += bytes_read;
3939 print_addr_index (idx, 8);
3941 printf (_("(base address selection entry)\n"));
3943 case 2: /* A start/end entry. */
3944 idx = read_leb128 (start, &bytes_read, 0);
3945 start += bytes_read;
3946 print_addr_index (idx, 8);
3947 idx = read_leb128 (start, &bytes_read, 0);
3948 start += bytes_read;
3949 print_addr_index (idx, 8);
3951 case 3: /* A start/length entry. */
3952 idx = read_leb128 (start, &bytes_read, 0);
3953 start += bytes_read;
3954 print_addr_index (idx, 8);
3955 idx = byte_get (start, 4);
3957 printf ("%08x ", idx);
3959 case 4: /* An offset pair entry. */
3960 idx = byte_get (start, 4);
3962 printf ("%08x ", idx);
3963 idx = byte_get (start, 4);
3965 printf ("%08x ", idx);
3968 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
3973 if (start + 2 > section_end)
3975 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3980 length = byte_get (start, 2);
3983 if (start + length > section_end)
3985 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3991 need_frame_base = decode_location_expression (start,
3996 cu_offset, section);
3999 if (need_frame_base && !has_frame_base)
4000 printf (_(" [without DW_AT_frame_base]"));
4010 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4012 static dwarf_vma *loc_offsets;
4015 loc_offsets_compar (const void *ap, const void *bp)
4017 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
4018 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
4020 return (a > b) - (b > a);
4024 display_debug_loc (struct dwarf_section *section, void *file)
4026 unsigned char *start = section->start;
4027 unsigned long bytes;
4028 unsigned char *section_begin = start;
4029 unsigned int num_loc_list = 0;
4030 unsigned long last_offset = 0;
4031 unsigned int first = 0;
4035 int seen_first_offset = 0;
4036 int locs_sorted = 1;
4037 unsigned char *next;
4038 unsigned int *array = NULL;
4039 const char *suffix = strrchr (section->name, '.');
4042 if (suffix && strcmp (suffix, ".dwo") == 0)
4045 bytes = section->size;
4049 printf (_("\nThe %s section is empty.\n"), section->name);
4053 if (load_debug_info (file) == 0)
4055 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4060 /* Check the order of location list in .debug_info section. If
4061 offsets of location lists are in the ascending order, we can
4062 use `debug_information' directly. */
4063 for (i = 0; i < num_debug_info_entries; i++)
4067 num = debug_information [i].num_loc_offsets;
4068 if (num > num_loc_list)
4071 /* Check if we can use `debug_information' directly. */
4072 if (locs_sorted && num != 0)
4074 if (!seen_first_offset)
4076 /* This is the first location list. */
4077 last_offset = debug_information [i].loc_offsets [0];
4079 seen_first_offset = 1;
4085 for (; j < num; j++)
4088 debug_information [i].loc_offsets [j])
4093 last_offset = debug_information [i].loc_offsets [j];
4098 if (!seen_first_offset)
4099 error (_("No location lists in .debug_info section!\n"));
4101 /* DWARF sections under Mach-O have non-zero addresses. */
4102 if (debug_information [first].num_loc_offsets > 0
4103 && debug_information [first].loc_offsets [0] != section->address)
4104 warn (_("Location lists in %s section start at 0x%s\n"),
4106 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4109 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4110 printf (_("Contents of the %s section:\n\n"), section->name);
4111 printf (_(" Offset Begin End Expression\n"));
4113 seen_first_offset = 0;
4114 for (i = first; i < num_debug_info_entries; i++)
4116 unsigned long offset;
4117 unsigned long base_address;
4122 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4124 loc_offsets = debug_information [i].loc_offsets;
4125 qsort (array, debug_information [i].num_loc_offsets,
4126 sizeof (*array), loc_offsets_compar);
4129 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4131 j = locs_sorted ? k : array[k];
4133 && debug_information [i].loc_offsets [locs_sorted
4134 ? k - 1 : array [k - 1]]
4135 == debug_information [i].loc_offsets [j])
4137 has_frame_base = debug_information [i].have_frame_base [j];
4138 /* DWARF sections under Mach-O have non-zero addresses. */
4139 offset = debug_information [i].loc_offsets [j] - section->address;
4140 next = section_begin + offset;
4141 base_address = debug_information [i].base_address;
4143 if (!seen_first_offset)
4144 seen_first_offset = 1;
4148 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4149 (unsigned long) (start - section_begin),
4150 (unsigned long) (next - section_begin));
4151 else if (start > next)
4152 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4153 (unsigned long) (start - section_begin),
4154 (unsigned long) (next - section_begin));
4158 if (offset >= bytes)
4160 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4166 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4168 display_loc_list (section, &start, i, offset, base_address,
4173 if (start < section->start + section->size)
4174 warn (_("There are %ld unused bytes at the end of section %s\n"),
4175 (long) (section->start + section->size - start), section->name);
4182 display_debug_str (struct dwarf_section *section,
4183 void *file ATTRIBUTE_UNUSED)
4185 unsigned char *start = section->start;
4186 unsigned long bytes = section->size;
4187 dwarf_vma addr = section->address;
4191 printf (_("\nThe %s section is empty.\n"), section->name);
4195 printf (_("Contents of the %s section:\n\n"), section->name);
4203 lbytes = (bytes > 16 ? 16 : bytes);
4205 printf (" 0x%8.8lx ", (unsigned long) addr);
4207 for (j = 0; j < 16; j++)
4210 printf ("%2.2x", start[j]);
4218 for (j = 0; j < lbytes; j++)
4221 if (k >= ' ' && k < 0x80)
4240 display_debug_info (struct dwarf_section *section, void *file)
4242 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4246 display_debug_types (struct dwarf_section *section, void *file)
4248 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4252 display_trace_info (struct dwarf_section *section, void *file)
4254 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4258 display_debug_aranges (struct dwarf_section *section,
4259 void *file ATTRIBUTE_UNUSED)
4261 unsigned char *start = section->start;
4262 unsigned char *end = start + section->size;
4264 printf (_("Contents of the %s section:\n\n"), section->name);
4266 /* It does not matter if this load fails,
4267 we test for that later on. */
4268 load_debug_info (file);
4272 unsigned char *hdrptr;
4273 DWARF2_Internal_ARange arange;
4274 unsigned char *addr_ranges;
4277 unsigned char address_size;
4280 int initial_length_size;
4284 arange.ar_length = byte_get (hdrptr, 4);
4287 if (arange.ar_length == 0xffffffff)
4289 arange.ar_length = byte_get (hdrptr, 8);
4292 initial_length_size = 12;
4297 initial_length_size = 4;
4300 arange.ar_version = byte_get (hdrptr, 2);
4303 arange.ar_info_offset = byte_get (hdrptr, offset_size);
4304 hdrptr += offset_size;
4306 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4307 && num_debug_info_entries > 0
4308 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4309 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4310 (unsigned long) arange.ar_info_offset, section->name);
4312 arange.ar_pointer_size = byte_get (hdrptr, 1);
4315 arange.ar_segment_size = byte_get (hdrptr, 1);
4318 if (arange.ar_version != 2 && arange.ar_version != 3)
4320 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4324 printf (_(" Length: %ld\n"),
4325 (long) arange.ar_length);
4326 printf (_(" Version: %d\n"), arange.ar_version);
4327 printf (_(" Offset into .debug_info: 0x%lx\n"),
4328 (unsigned long) arange.ar_info_offset);
4329 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4330 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4332 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4334 if (address_size == 0)
4336 error (_("Invalid address size in %s section!\n"),
4341 /* The DWARF spec does not require that the address size be a power
4342 of two, but we do. This will have to change if we ever encounter
4343 an uneven architecture. */
4344 if ((address_size & (address_size - 1)) != 0)
4346 warn (_("Pointer size + Segment size is not a power of two.\n"));
4350 if (address_size > 4)
4351 printf (_("\n Address Length\n"));
4353 printf (_("\n Address Length\n"));
4355 addr_ranges = hdrptr;
4357 /* Must pad to an alignment boundary that is twice the address size. */
4358 excess = (hdrptr - start) % (2 * address_size);
4360 addr_ranges += (2 * address_size) - excess;
4362 start += arange.ar_length + initial_length_size;
4364 while (addr_ranges + 2 * address_size <= start)
4366 address = byte_get (addr_ranges, address_size);
4368 addr_ranges += address_size;
4370 length = byte_get (addr_ranges, address_size);
4372 addr_ranges += address_size;
4375 print_dwarf_vma (address, address_size);
4376 print_dwarf_vma (length, address_size);
4386 /* Comparison function for qsort. */
4388 comp_addr_base (const void * v0, const void * v1)
4390 debug_info * info0 = (debug_info *) v0;
4391 debug_info * info1 = (debug_info *) v1;
4392 return info0->addr_base - info1->addr_base;
4395 /* Display the debug_addr section. */
4397 display_debug_addr (struct dwarf_section *section,
4400 debug_info **debug_addr_info;
4401 unsigned char *entry;
4406 if (section->size == 0)
4408 printf (_("\nThe %s section is empty.\n"), section->name);
4412 if (load_debug_info (file) == 0)
4414 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4419 printf (_("Contents of the %s section:\n\n"), section->name);
4421 debug_addr_info = (debug_info **) xmalloc ((num_debug_info_entries + 1)
4422 * sizeof (debug_info *));
4425 for (i = 0; i < num_debug_info_entries; i++)
4427 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4428 debug_addr_info [count++] = &debug_information [i];
4431 /* Add a sentinel to make iteration convenient. */
4432 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4433 debug_addr_info [count]->addr_base = section->size;
4435 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4436 for (i = 0; i < count; i++)
4439 unsigned int address_size = debug_addr_info [i]->pointer_size;
4441 printf (_(" For compilation unit at offset 0x%s:\n"),
4442 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4444 printf (_("\tIndex\tAddress\n"));
4445 entry = section->start + debug_addr_info [i]->addr_base;
4446 end = section->start + debug_addr_info [i + 1]->addr_base;
4450 dwarf_vma base = byte_get (entry, address_size);
4451 printf (_("\t%d:\t"), idx);
4452 print_dwarf_vma (base, address_size);
4454 entry += address_size;
4460 free (debug_addr_info);
4464 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4466 display_debug_str_offsets (struct dwarf_section *section,
4467 void *file ATTRIBUTE_UNUSED)
4469 if (section->size == 0)
4471 printf (_("\nThe %s section is empty.\n"), section->name);
4474 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4475 what the offset size is for this section. */
4479 /* Each debug_information[x].range_lists[y] gets this representation for
4480 sorting purposes. */
4484 /* The debug_information[x].range_lists[y] value. */
4485 unsigned long ranges_offset;
4487 /* Original debug_information to find parameters of the data. */
4488 debug_info *debug_info_p;
4491 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4494 range_entry_compar (const void *ap, const void *bp)
4496 const struct range_entry *a_re = (const struct range_entry *) ap;
4497 const struct range_entry *b_re = (const struct range_entry *) bp;
4498 const unsigned long a = a_re->ranges_offset;
4499 const unsigned long b = b_re->ranges_offset;
4501 return (a > b) - (b > a);
4505 display_debug_ranges (struct dwarf_section *section,
4506 void *file ATTRIBUTE_UNUSED)
4508 unsigned char *start = section->start;
4509 unsigned char *last_start = start;
4510 unsigned long bytes;
4511 unsigned char *section_begin = start;
4512 unsigned int num_range_list, i;
4513 struct range_entry *range_entries, *range_entry_fill;
4515 bytes = section->size;
4519 printf (_("\nThe %s section is empty.\n"), section->name);
4523 if (load_debug_info (file) == 0)
4525 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4531 for (i = 0; i < num_debug_info_entries; i++)
4532 num_range_list += debug_information [i].num_range_lists;
4534 if (num_range_list == 0)
4536 /* This can happen when the file was compiled with -gsplit-debug
4537 which removes references to range lists from the primary .o file. */
4538 printf (_("No range lists in .debug_info section.\n"));
4542 range_entries = (struct range_entry *)
4543 xmalloc (sizeof (*range_entries) * num_range_list);
4544 range_entry_fill = range_entries;
4546 for (i = 0; i < num_debug_info_entries; i++)
4548 debug_info *debug_info_p = &debug_information[i];
4551 for (j = 0; j < debug_info_p->num_range_lists; j++)
4553 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4554 range_entry_fill->debug_info_p = debug_info_p;
4559 qsort (range_entries, num_range_list, sizeof (*range_entries),
4560 range_entry_compar);
4562 /* DWARF sections under Mach-O have non-zero addresses. */
4563 if (dwarf_check != 0 && range_entries[0].ranges_offset != section->address)
4564 warn (_("Range lists in %s section start at 0x%lx\n"),
4565 section->name, range_entries[0].ranges_offset);
4567 printf (_("Contents of the %s section:\n\n"), section->name);
4568 printf (_(" Offset Begin End\n"));
4570 for (i = 0; i < num_range_list; i++)
4572 struct range_entry *range_entry = &range_entries[i];
4573 debug_info *debug_info_p = range_entry->debug_info_p;
4574 unsigned int pointer_size;
4575 unsigned long offset;
4576 unsigned char *next;
4577 unsigned long base_address;
4579 pointer_size = debug_info_p->pointer_size;
4581 /* DWARF sections under Mach-O have non-zero addresses. */
4582 offset = range_entry->ranges_offset - section->address;
4583 next = section_begin + offset;
4584 base_address = debug_info_p->base_address;
4586 if (dwarf_check != 0 && i > 0)
4589 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4590 (unsigned long) (start - section_begin),
4591 (unsigned long) (next - section_begin), section->name);
4592 else if (start > next)
4594 if (next == last_start)
4596 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4597 (unsigned long) (start - section_begin),
4598 (unsigned long) (next - section_begin), section->name);
4609 /* Note: we use sign extension here in order to be sure that
4610 we can detect the -1 escape value. Sign extension into the
4611 top 32 bits of a 32-bit address will not affect the values
4612 that we display since we always show hex values, and always
4613 the bottom 32-bits. */
4614 begin = byte_get_signed (start, pointer_size);
4615 start += pointer_size;
4616 end = byte_get_signed (start, pointer_size);
4617 start += pointer_size;
4619 printf (" %8.8lx ", offset);
4621 if (begin == 0 && end == 0)
4623 printf (_("<End of list>\n"));
4627 /* Check base address specifiers. */
4628 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4631 print_dwarf_vma (begin, pointer_size);
4632 print_dwarf_vma (end, pointer_size);
4633 printf ("(base address)\n");
4637 print_dwarf_vma (begin + base_address, pointer_size);
4638 print_dwarf_vma (end + base_address, pointer_size);
4641 fputs (_("(start == end)"), stdout);
4642 else if (begin > end)
4643 fputs (_("(start > end)"), stdout);
4650 free (range_entries);
4655 typedef struct Frame_Chunk
4657 struct Frame_Chunk *next;
4658 unsigned char *chunk_start;
4660 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4661 short int *col_type;
4664 unsigned int code_factor;
4666 unsigned long pc_begin;
4667 unsigned long pc_range;
4671 unsigned char fde_encoding;
4672 unsigned char cfa_exp;
4673 unsigned char ptr_size;
4674 unsigned char segment_size;
4678 static const char *const *dwarf_regnames;
4679 static unsigned int dwarf_regnames_count;
4681 /* A marker for a col_type that means this column was never referenced
4682 in the frame info. */
4683 #define DW_CFA_unreferenced (-1)
4685 /* Return 0 if not more space is needed, 1 if more space is needed,
4686 -1 for invalid reg. */
4689 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4691 int prev = fc->ncols;
4693 if (reg < (unsigned int) fc->ncols)
4696 if (dwarf_regnames_count
4697 && reg > dwarf_regnames_count)
4700 fc->ncols = reg + 1;
4701 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4702 sizeof (short int));
4703 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4705 while (prev < fc->ncols)
4707 fc->col_type[prev] = DW_CFA_unreferenced;
4708 fc->col_offset[prev] = 0;
4714 static const char *const dwarf_regnames_i386[] =
4716 "eax", "ecx", "edx", "ebx",
4717 "esp", "ebp", "esi", "edi",
4718 "eip", "eflags", NULL,
4719 "st0", "st1", "st2", "st3",
4720 "st4", "st5", "st6", "st7",
4722 "xmm0", "xmm1", "xmm2", "xmm3",
4723 "xmm4", "xmm5", "xmm6", "xmm7",
4724 "mm0", "mm1", "mm2", "mm3",
4725 "mm4", "mm5", "mm6", "mm7",
4726 "fcw", "fsw", "mxcsr",
4727 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4732 init_dwarf_regnames_i386 (void)
4734 dwarf_regnames = dwarf_regnames_i386;
4735 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4738 static const char *const dwarf_regnames_x86_64[] =
4740 "rax", "rdx", "rcx", "rbx",
4741 "rsi", "rdi", "rbp", "rsp",
4742 "r8", "r9", "r10", "r11",
4743 "r12", "r13", "r14", "r15",
4745 "xmm0", "xmm1", "xmm2", "xmm3",
4746 "xmm4", "xmm5", "xmm6", "xmm7",
4747 "xmm8", "xmm9", "xmm10", "xmm11",
4748 "xmm12", "xmm13", "xmm14", "xmm15",
4749 "st0", "st1", "st2", "st3",
4750 "st4", "st5", "st6", "st7",
4751 "mm0", "mm1", "mm2", "mm3",
4752 "mm4", "mm5", "mm6", "mm7",
4754 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4755 "fs.base", "gs.base", NULL, NULL,
4757 "mxcsr", "fcw", "fsw"
4761 init_dwarf_regnames_x86_64 (void)
4763 dwarf_regnames = dwarf_regnames_x86_64;
4764 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4768 init_dwarf_regnames (unsigned int e_machine)
4774 init_dwarf_regnames_i386 ();
4780 init_dwarf_regnames_x86_64 ();
4789 regname (unsigned int regno, int row)
4791 static char reg[64];
4793 && regno < dwarf_regnames_count
4794 && dwarf_regnames [regno] != NULL)
4797 return dwarf_regnames [regno];
4798 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4799 dwarf_regnames [regno]);
4802 snprintf (reg, sizeof (reg), "r%d", regno);
4807 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4812 if (*max_regs < fc->ncols)
4813 *max_regs = fc->ncols;
4815 if (*need_col_headers)
4817 static const char *sloc = " LOC";
4819 *need_col_headers = 0;
4821 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4823 for (r = 0; r < *max_regs; r++)
4824 if (fc->col_type[r] != DW_CFA_unreferenced)
4829 printf ("%-5s ", regname (r, 1));
4835 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4837 strcpy (tmp, "exp");
4839 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4840 printf ("%-8s ", tmp);
4842 for (r = 0; r < fc->ncols; r++)
4844 if (fc->col_type[r] != DW_CFA_unreferenced)
4846 switch (fc->col_type[r])
4848 case DW_CFA_undefined:
4851 case DW_CFA_same_value:
4855 sprintf (tmp, "c%+d", fc->col_offset[r]);
4857 case DW_CFA_val_offset:
4858 sprintf (tmp, "v%+d", fc->col_offset[r]);
4860 case DW_CFA_register:
4861 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4863 case DW_CFA_expression:
4864 strcpy (tmp, "exp");
4866 case DW_CFA_val_expression:
4867 strcpy (tmp, "vexp");
4870 strcpy (tmp, "n/a");
4873 printf ("%-5s ", tmp);
4879 #define GET(N) byte_get (start, N); start += N
4880 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4881 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4884 display_debug_frames (struct dwarf_section *section,
4885 void *file ATTRIBUTE_UNUSED)
4887 unsigned char *start = section->start;
4888 unsigned char *end = start + section->size;
4889 unsigned char *section_start = start;
4890 Frame_Chunk *chunks = 0;
4891 Frame_Chunk *remembered_state = 0;
4893 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4894 unsigned int length_return;
4896 const char *bad_reg = _("bad register: ");
4897 int saved_eh_addr_size = eh_addr_size;
4899 printf (_("Contents of the %s section:\n"), section->name);
4903 unsigned char *saved_start;
4904 unsigned char *block_end;
4905 unsigned long length;
4906 unsigned long cie_id;
4909 int need_col_headers = 1;
4910 unsigned char *augmentation_data = NULL;
4911 unsigned long augmentation_data_len = 0;
4912 int encoded_ptr_size = saved_eh_addr_size;
4914 int initial_length_size;
4916 saved_start = start;
4917 length = byte_get (start, 4); start += 4;
4921 printf ("\n%08lx ZERO terminator\n\n",
4922 (unsigned long)(saved_start - section_start));
4926 if (length == 0xffffffff)
4928 length = byte_get (start, 8);
4931 initial_length_size = 12;
4936 initial_length_size = 4;
4939 block_end = saved_start + length + initial_length_size;
4940 if (block_end > end)
4942 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4943 length, (unsigned long)(saved_start - section_start));
4946 cie_id = byte_get (start, offset_size); start += offset_size;
4948 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4952 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4953 memset (fc, 0, sizeof (Frame_Chunk));
4957 fc->chunk_start = saved_start;
4959 fc->col_type = (short int *) xmalloc (sizeof (short int));
4960 fc->col_offset = (int *) xmalloc (sizeof (int));
4961 frame_need_space (fc, max_regs - 1);
4965 fc->augmentation = (char *) start;
4966 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4968 if (strcmp (fc->augmentation, "eh") == 0)
4969 start += eh_addr_size;
4973 fc->ptr_size = GET (1);
4974 fc->segment_size = GET (1);
4975 eh_addr_size = fc->ptr_size;
4979 fc->ptr_size = eh_addr_size;
4980 fc->segment_size = 0;
4982 fc->code_factor = LEB ();
4983 fc->data_factor = SLEB ();
4993 if (fc->augmentation[0] == 'z')
4995 augmentation_data_len = LEB ();
4996 augmentation_data = start;
4997 start += augmentation_data_len;
5001 if (do_debug_frames_interp)
5002 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
5003 (unsigned long)(saved_start - section_start), length, cie_id,
5004 fc->augmentation, fc->code_factor, fc->data_factor,
5008 printf ("\n%08lx %08lx %08lx CIE\n",
5009 (unsigned long)(saved_start - section_start), length, cie_id);
5010 printf (" Version: %d\n", version);
5011 printf (" Augmentation: \"%s\"\n", fc->augmentation);
5014 printf (" Pointer Size: %u\n", fc->ptr_size);
5015 printf (" Segment Size: %u\n", fc->segment_size);
5017 printf (" Code alignment factor: %u\n", fc->code_factor);
5018 printf (" Data alignment factor: %d\n", fc->data_factor);
5019 printf (" Return address column: %d\n", fc->ra);
5021 if (augmentation_data_len)
5024 printf (" Augmentation data: ");
5025 for (i = 0; i < augmentation_data_len; ++i)
5026 printf (" %02x", augmentation_data[i]);
5032 if (augmentation_data_len)
5034 unsigned char *p, *q;
5035 p = (unsigned char *) fc->augmentation + 1;
5036 q = augmentation_data;
5043 q += 1 + size_of_encoded_value (*q);
5045 fc->fde_encoding = *q++;
5053 if (fc->fde_encoding)
5054 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5057 frame_need_space (fc, fc->ra);
5061 unsigned char *look_for;
5062 static Frame_Chunk fde_fc;
5063 unsigned long segment_selector;
5066 memset (fc, 0, sizeof (Frame_Chunk));
5068 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
5070 for (cie = chunks; cie ; cie = cie->next)
5071 if (cie->chunk_start == look_for)
5076 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
5077 cie_id, (unsigned long)(saved_start - section_start));
5079 fc->col_type = (short int *) xmalloc (sizeof (short int));
5080 fc->col_offset = (int *) xmalloc (sizeof (int));
5081 frame_need_space (fc, max_regs - 1);
5083 fc->augmentation = "";
5084 fc->fde_encoding = 0;
5085 fc->ptr_size = eh_addr_size;
5086 fc->segment_size = 0;
5090 fc->ncols = cie->ncols;
5091 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5092 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5093 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5094 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5095 fc->augmentation = cie->augmentation;
5096 fc->ptr_size = cie->ptr_size;
5097 eh_addr_size = cie->ptr_size;
5098 fc->segment_size = cie->segment_size;
5099 fc->code_factor = cie->code_factor;
5100 fc->data_factor = cie->data_factor;
5101 fc->cfa_reg = cie->cfa_reg;
5102 fc->cfa_offset = cie->cfa_offset;
5104 frame_need_space (fc, max_regs - 1);
5105 fc->fde_encoding = cie->fde_encoding;
5108 if (fc->fde_encoding)
5109 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5111 segment_selector = 0;
5112 if (fc->segment_size)
5114 segment_selector = byte_get (start, fc->segment_size);
5115 start += fc->segment_size;
5117 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
5118 start += encoded_ptr_size;
5119 fc->pc_range = byte_get (start, encoded_ptr_size);
5120 start += encoded_ptr_size;
5122 if (cie->augmentation[0] == 'z')
5124 augmentation_data_len = LEB ();
5125 augmentation_data = start;
5126 start += augmentation_data_len;
5129 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
5130 (unsigned long)(saved_start - section_start), length, cie_id,
5131 (unsigned long)(cie->chunk_start - section_start));
5132 if (fc->segment_size)
5133 printf ("%04lx:", segment_selector);
5134 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
5135 if (! do_debug_frames_interp && augmentation_data_len)
5139 printf (" Augmentation data: ");
5140 for (i = 0; i < augmentation_data_len; ++i)
5141 printf (" %02x", augmentation_data[i]);
5147 /* At this point, fc is the current chunk, cie (if any) is set, and
5148 we're about to interpret instructions for the chunk. */
5149 /* ??? At present we need to do this always, since this sizes the
5150 fc->col_type and fc->col_offset arrays, which we write into always.
5151 We should probably split the interpreted and non-interpreted bits
5152 into two different routines, since there's so much that doesn't
5153 really overlap between them. */
5154 if (1 || do_debug_frames_interp)
5156 /* Start by making a pass over the chunk, allocating storage
5157 and taking note of what registers are used. */
5158 unsigned char *tmp = start;
5160 while (start < block_end)
5163 unsigned long reg, temp;
5170 /* Warning: if you add any more cases to this switch, be
5171 sure to add them to the corresponding switch below. */
5174 case DW_CFA_advance_loc:
5178 if (frame_need_space (fc, opa) >= 0)
5179 fc->col_type[opa] = DW_CFA_undefined;
5181 case DW_CFA_restore:
5182 if (frame_need_space (fc, opa) >= 0)
5183 fc->col_type[opa] = DW_CFA_undefined;
5185 case DW_CFA_set_loc:
5186 start += encoded_ptr_size;
5188 case DW_CFA_advance_loc1:
5191 case DW_CFA_advance_loc2:
5194 case DW_CFA_advance_loc4:
5197 case DW_CFA_offset_extended:
5198 case DW_CFA_val_offset:
5199 reg = LEB (); LEB ();
5200 if (frame_need_space (fc, reg) >= 0)
5201 fc->col_type[reg] = DW_CFA_undefined;
5203 case DW_CFA_restore_extended:
5205 frame_need_space (fc, reg);
5206 if (frame_need_space (fc, reg) >= 0)
5207 fc->col_type[reg] = DW_CFA_undefined;
5209 case DW_CFA_undefined:
5211 if (frame_need_space (fc, reg) >= 0)
5212 fc->col_type[reg] = DW_CFA_undefined;
5214 case DW_CFA_same_value:
5216 if (frame_need_space (fc, reg) >= 0)
5217 fc->col_type[reg] = DW_CFA_undefined;
5219 case DW_CFA_register:
5220 reg = LEB (); LEB ();
5221 if (frame_need_space (fc, reg) >= 0)
5222 fc->col_type[reg] = DW_CFA_undefined;
5224 case DW_CFA_def_cfa:
5227 case DW_CFA_def_cfa_register:
5230 case DW_CFA_def_cfa_offset:
5233 case DW_CFA_def_cfa_expression:
5237 case DW_CFA_expression:
5238 case DW_CFA_val_expression:
5242 if (frame_need_space (fc, reg) >= 0)
5243 fc->col_type[reg] = DW_CFA_undefined;
5245 case DW_CFA_offset_extended_sf:
5246 case DW_CFA_val_offset_sf:
5247 reg = LEB (); SLEB ();
5248 if (frame_need_space (fc, reg) >= 0)
5249 fc->col_type[reg] = DW_CFA_undefined;
5251 case DW_CFA_def_cfa_sf:
5254 case DW_CFA_def_cfa_offset_sf:
5257 case DW_CFA_MIPS_advance_loc8:
5260 case DW_CFA_GNU_args_size:
5263 case DW_CFA_GNU_negative_offset_extended:
5264 reg = LEB (); LEB ();
5265 if (frame_need_space (fc, reg) >= 0)
5266 fc->col_type[reg] = DW_CFA_undefined;
5275 /* Now we know what registers are used, make a second pass over
5276 the chunk, this time actually printing out the info. */
5278 while (start < block_end)
5281 unsigned long ul, reg, roffs;
5284 const char *reg_prefix = "";
5291 /* Warning: if you add any more cases to this switch, be
5292 sure to add them to the corresponding switch above. */
5295 case DW_CFA_advance_loc:
5296 if (do_debug_frames_interp)
5297 frame_display_row (fc, &need_col_headers, &max_regs);
5299 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5300 opa * fc->code_factor,
5301 fc->pc_begin + opa * fc->code_factor);
5302 fc->pc_begin += opa * fc->code_factor;
5307 if (opa >= (unsigned int) fc->ncols)
5308 reg_prefix = bad_reg;
5309 if (! do_debug_frames_interp || *reg_prefix != '\0')
5310 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5311 reg_prefix, regname (opa, 0),
5312 roffs * fc->data_factor);
5313 if (*reg_prefix == '\0')
5315 fc->col_type[opa] = DW_CFA_offset;
5316 fc->col_offset[opa] = roffs * fc->data_factor;
5320 case DW_CFA_restore:
5321 if (opa >= (unsigned int) cie->ncols
5322 || opa >= (unsigned int) fc->ncols)
5323 reg_prefix = bad_reg;
5324 if (! do_debug_frames_interp || *reg_prefix != '\0')
5325 printf (" DW_CFA_restore: %s%s\n",
5326 reg_prefix, regname (opa, 0));
5327 if (*reg_prefix == '\0')
5329 fc->col_type[opa] = cie->col_type[opa];
5330 fc->col_offset[opa] = cie->col_offset[opa];
5331 if (do_debug_frames_interp
5332 && fc->col_type[opa] == DW_CFA_unreferenced)
5333 fc->col_type[opa] = DW_CFA_undefined;
5337 case DW_CFA_set_loc:
5338 vma = get_encoded_value (start, fc->fde_encoding, section);
5339 start += encoded_ptr_size;
5340 if (do_debug_frames_interp)
5341 frame_display_row (fc, &need_col_headers, &max_regs);
5343 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5347 case DW_CFA_advance_loc1:
5348 ofs = byte_get (start, 1); start += 1;
5349 if (do_debug_frames_interp)
5350 frame_display_row (fc, &need_col_headers, &max_regs);
5352 printf (" DW_CFA_advance_loc1: %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_advance_loc2:
5359 ofs = byte_get (start, 2); start += 2;
5360 if (do_debug_frames_interp)
5361 frame_display_row (fc, &need_col_headers, &max_regs);
5363 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5364 ofs * fc->code_factor,
5365 fc->pc_begin + ofs * fc->code_factor);
5366 fc->pc_begin += ofs * fc->code_factor;
5369 case DW_CFA_advance_loc4:
5370 ofs = byte_get (start, 4); start += 4;
5371 if (do_debug_frames_interp)
5372 frame_display_row (fc, &need_col_headers, &max_regs);
5374 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5375 ofs * fc->code_factor,
5376 fc->pc_begin + ofs * fc->code_factor);
5377 fc->pc_begin += ofs * fc->code_factor;
5380 case DW_CFA_offset_extended:
5383 if (reg >= (unsigned int) fc->ncols)
5384 reg_prefix = bad_reg;
5385 if (! do_debug_frames_interp || *reg_prefix != '\0')
5386 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5387 reg_prefix, regname (reg, 0),
5388 roffs * fc->data_factor);
5389 if (*reg_prefix == '\0')
5391 fc->col_type[reg] = DW_CFA_offset;
5392 fc->col_offset[reg] = roffs * fc->data_factor;
5396 case DW_CFA_val_offset:
5399 if (reg >= (unsigned int) fc->ncols)
5400 reg_prefix = bad_reg;
5401 if (! do_debug_frames_interp || *reg_prefix != '\0')
5402 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5403 reg_prefix, regname (reg, 0),
5404 roffs * fc->data_factor);
5405 if (*reg_prefix == '\0')
5407 fc->col_type[reg] = DW_CFA_val_offset;
5408 fc->col_offset[reg] = roffs * fc->data_factor;
5412 case DW_CFA_restore_extended:
5414 if (reg >= (unsigned int) cie->ncols
5415 || reg >= (unsigned int) fc->ncols)
5416 reg_prefix = bad_reg;
5417 if (! do_debug_frames_interp || *reg_prefix != '\0')
5418 printf (" DW_CFA_restore_extended: %s%s\n",
5419 reg_prefix, regname (reg, 0));
5420 if (*reg_prefix == '\0')
5422 fc->col_type[reg] = cie->col_type[reg];
5423 fc->col_offset[reg] = cie->col_offset[reg];
5427 case DW_CFA_undefined:
5429 if (reg >= (unsigned int) fc->ncols)
5430 reg_prefix = bad_reg;
5431 if (! do_debug_frames_interp || *reg_prefix != '\0')
5432 printf (" DW_CFA_undefined: %s%s\n",
5433 reg_prefix, regname (reg, 0));
5434 if (*reg_prefix == '\0')
5436 fc->col_type[reg] = DW_CFA_undefined;
5437 fc->col_offset[reg] = 0;
5441 case DW_CFA_same_value:
5443 if (reg >= (unsigned int) fc->ncols)
5444 reg_prefix = bad_reg;
5445 if (! do_debug_frames_interp || *reg_prefix != '\0')
5446 printf (" DW_CFA_same_value: %s%s\n",
5447 reg_prefix, regname (reg, 0));
5448 if (*reg_prefix == '\0')
5450 fc->col_type[reg] = DW_CFA_same_value;
5451 fc->col_offset[reg] = 0;
5455 case DW_CFA_register:
5458 if (reg >= (unsigned int) fc->ncols)
5459 reg_prefix = bad_reg;
5460 if (! do_debug_frames_interp || *reg_prefix != '\0')
5462 printf (" DW_CFA_register: %s%s in ",
5463 reg_prefix, regname (reg, 0));
5464 puts (regname (roffs, 0));
5466 if (*reg_prefix == '\0')
5468 fc->col_type[reg] = DW_CFA_register;
5469 fc->col_offset[reg] = roffs;
5473 case DW_CFA_remember_state:
5474 if (! do_debug_frames_interp)
5475 printf (" DW_CFA_remember_state\n");
5476 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5477 rs->ncols = fc->ncols;
5478 rs->col_type = (short int *) xcmalloc (rs->ncols,
5479 sizeof (short int));
5480 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
5481 memcpy (rs->col_type, fc->col_type, rs->ncols);
5482 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5483 rs->next = remembered_state;
5484 remembered_state = rs;
5487 case DW_CFA_restore_state:
5488 if (! do_debug_frames_interp)
5489 printf (" DW_CFA_restore_state\n");
5490 rs = remembered_state;
5493 remembered_state = rs->next;
5494 frame_need_space (fc, rs->ncols - 1);
5495 memcpy (fc->col_type, rs->col_type, rs->ncols);
5496 memcpy (fc->col_offset, rs->col_offset,
5497 rs->ncols * sizeof (int));
5498 free (rs->col_type);
5499 free (rs->col_offset);
5502 else if (do_debug_frames_interp)
5503 printf ("Mismatched DW_CFA_restore_state\n");
5506 case DW_CFA_def_cfa:
5507 fc->cfa_reg = LEB ();
5508 fc->cfa_offset = LEB ();
5510 if (! do_debug_frames_interp)
5511 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5512 regname (fc->cfa_reg, 0), fc->cfa_offset);
5515 case DW_CFA_def_cfa_register:
5516 fc->cfa_reg = LEB ();
5518 if (! do_debug_frames_interp)
5519 printf (" DW_CFA_def_cfa_register: %s\n",
5520 regname (fc->cfa_reg, 0));
5523 case DW_CFA_def_cfa_offset:
5524 fc->cfa_offset = LEB ();
5525 if (! do_debug_frames_interp)
5526 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5530 if (! do_debug_frames_interp)
5531 printf (" DW_CFA_nop\n");
5534 case DW_CFA_def_cfa_expression:
5536 if (! do_debug_frames_interp)
5538 printf (" DW_CFA_def_cfa_expression (");
5539 decode_location_expression (start, eh_addr_size, 0, -1,
5547 case DW_CFA_expression:
5550 if (reg >= (unsigned int) fc->ncols)
5551 reg_prefix = bad_reg;
5552 if (! do_debug_frames_interp || *reg_prefix != '\0')
5554 printf (" DW_CFA_expression: %s%s (",
5555 reg_prefix, regname (reg, 0));
5556 decode_location_expression (start, eh_addr_size, 0, -1,
5560 if (*reg_prefix == '\0')
5561 fc->col_type[reg] = DW_CFA_expression;
5565 case DW_CFA_val_expression:
5568 if (reg >= (unsigned int) fc->ncols)
5569 reg_prefix = bad_reg;
5570 if (! do_debug_frames_interp || *reg_prefix != '\0')
5572 printf (" DW_CFA_val_expression: %s%s (",
5573 reg_prefix, regname (reg, 0));
5574 decode_location_expression (start, eh_addr_size, 0, -1,
5578 if (*reg_prefix == '\0')
5579 fc->col_type[reg] = DW_CFA_val_expression;
5583 case DW_CFA_offset_extended_sf:
5586 if (frame_need_space (fc, reg) < 0)
5587 reg_prefix = bad_reg;
5588 if (! do_debug_frames_interp || *reg_prefix != '\0')
5589 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5590 reg_prefix, regname (reg, 0),
5591 l * fc->data_factor);
5592 if (*reg_prefix == '\0')
5594 fc->col_type[reg] = DW_CFA_offset;
5595 fc->col_offset[reg] = l * fc->data_factor;
5599 case DW_CFA_val_offset_sf:
5602 if (frame_need_space (fc, reg) < 0)
5603 reg_prefix = bad_reg;
5604 if (! do_debug_frames_interp || *reg_prefix != '\0')
5605 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5606 reg_prefix, regname (reg, 0),
5607 l * fc->data_factor);
5608 if (*reg_prefix == '\0')
5610 fc->col_type[reg] = DW_CFA_val_offset;
5611 fc->col_offset[reg] = l * fc->data_factor;
5615 case DW_CFA_def_cfa_sf:
5616 fc->cfa_reg = LEB ();
5617 fc->cfa_offset = SLEB ();
5618 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5620 if (! do_debug_frames_interp)
5621 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5622 regname (fc->cfa_reg, 0), fc->cfa_offset);
5625 case DW_CFA_def_cfa_offset_sf:
5626 fc->cfa_offset = SLEB ();
5627 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5628 if (! do_debug_frames_interp)
5629 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5632 case DW_CFA_MIPS_advance_loc8:
5633 ofs = byte_get (start, 8); start += 8;
5634 if (do_debug_frames_interp)
5635 frame_display_row (fc, &need_col_headers, &max_regs);
5637 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5638 ofs * fc->code_factor,
5639 fc->pc_begin + ofs * fc->code_factor);
5640 fc->pc_begin += ofs * fc->code_factor;
5643 case DW_CFA_GNU_window_save:
5644 if (! do_debug_frames_interp)
5645 printf (" DW_CFA_GNU_window_save\n");
5648 case DW_CFA_GNU_args_size:
5650 if (! do_debug_frames_interp)
5651 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5654 case DW_CFA_GNU_negative_offset_extended:
5657 if (frame_need_space (fc, reg) < 0)
5658 reg_prefix = bad_reg;
5659 if (! do_debug_frames_interp || *reg_prefix != '\0')
5660 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5661 reg_prefix, regname (reg, 0),
5662 l * fc->data_factor);
5663 if (*reg_prefix == '\0')
5665 fc->col_type[reg] = DW_CFA_offset;
5666 fc->col_offset[reg] = l * fc->data_factor;
5671 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5672 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5674 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5679 if (do_debug_frames_interp)
5680 frame_display_row (fc, &need_col_headers, &max_regs);
5683 eh_addr_size = saved_eh_addr_size;
5696 display_gdb_index (struct dwarf_section *section,
5697 void *file ATTRIBUTE_UNUSED)
5699 unsigned char *start = section->start;
5701 uint32_t cu_list_offset, tu_list_offset;
5702 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5703 unsigned int cu_list_elements, tu_list_elements;
5704 unsigned int address_table_size, symbol_table_slots;
5705 unsigned char *cu_list, *tu_list;
5706 unsigned char *address_table, *symbol_table, *constant_pool;
5709 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5711 printf (_("Contents of the %s section:\n"), section->name);
5713 if (section->size < 6 * sizeof (uint32_t))
5715 warn (_("Truncated header in the %s section.\n"), section->name);
5719 version = byte_get_little_endian (start, 4);
5720 printf (_("Version %ld\n"), (long) version);
5722 /* Prior versions are obsolete, and future versions may not be
5723 backwards compatible. */
5724 if (version < 3 || version > 7)
5726 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5730 warn (_("The address table data in version 3 may be wrong.\n"));
5732 warn (_("Version 4 does not support case insensitive lookups.\n"));
5734 warn (_("Version 5 does not include inlined functions.\n"));
5736 warn (_("Version 6 does not include symbol attributes.\n"));
5738 cu_list_offset = byte_get_little_endian (start + 4, 4);
5739 tu_list_offset = byte_get_little_endian (start + 8, 4);
5740 address_table_offset = byte_get_little_endian (start + 12, 4);
5741 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5742 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5744 if (cu_list_offset > section->size
5745 || tu_list_offset > section->size
5746 || address_table_offset > section->size
5747 || symbol_table_offset > section->size
5748 || constant_pool_offset > section->size)
5750 warn (_("Corrupt header in the %s section.\n"), section->name);
5754 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5755 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5756 address_table_size = symbol_table_offset - address_table_offset;
5757 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5759 cu_list = start + cu_list_offset;
5760 tu_list = start + tu_list_offset;
5761 address_table = start + address_table_offset;
5762 symbol_table = start + symbol_table_offset;
5763 constant_pool = start + constant_pool_offset;
5765 printf (_("\nCU table:\n"));
5766 for (i = 0; i < cu_list_elements; i += 2)
5768 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5769 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5771 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5772 (unsigned long) cu_offset,
5773 (unsigned long) (cu_offset + cu_length - 1));
5776 printf (_("\nTU table:\n"));
5777 for (i = 0; i < tu_list_elements; i += 3)
5779 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5780 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5781 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5783 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5784 (unsigned long) tu_offset,
5785 (unsigned long) type_offset);
5786 print_dwarf_vma (signature, 8);
5790 printf (_("\nAddress table:\n"));
5791 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5793 uint64_t low = byte_get_little_endian (address_table + i, 8);
5794 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5795 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5797 print_dwarf_vma (low, 8);
5798 print_dwarf_vma (high, 8);
5799 printf (_("%lu\n"), (unsigned long) cu_index);
5802 printf (_("\nSymbol table:\n"));
5803 for (i = 0; i < symbol_table_slots; ++i)
5805 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5806 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5807 uint32_t num_cus, cu;
5809 if (name_offset != 0
5810 || cu_vector_offset != 0)
5814 printf ("[%3u] %s:", i, constant_pool + name_offset);
5815 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5818 for (j = 0; j < num_cus; ++j)
5821 gdb_index_symbol_kind kind;
5823 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5824 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
5825 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
5826 cu = GDB_INDEX_CU_VALUE (cu);
5827 /* Convert to TU number if it's for a type unit. */
5828 if (cu >= cu_list_elements / 2)
5829 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
5830 (unsigned long) (cu - cu_list_elements / 2));
5832 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
5836 case GDB_INDEX_SYMBOL_KIND_NONE:
5837 printf (_(" [no symbol information]"));
5839 case GDB_INDEX_SYMBOL_KIND_TYPE:
5841 ? _(" [static type]")
5842 : _(" [global type]"));
5844 case GDB_INDEX_SYMBOL_KIND_VARIABLE:
5846 ? _(" [static variable]")
5847 : _(" [global variable]"));
5849 case GDB_INDEX_SYMBOL_KIND_FUNCTION:
5851 ? _(" [static function]")
5852 : _(" [global function]"));
5854 case GDB_INDEX_SYMBOL_KIND_OTHER:
5856 ? _(" [static other]")
5857 : _(" [global other]"));
5861 ? _(" [static unknown: %d]")
5862 : _(" [global unknown: %d]"),
5877 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
5878 sections. Each set is stored in SHNDX_POOL as a zero-terminated list of
5879 section indexes comprising one set of debug sections from a .dwo file. */
5881 int cu_tu_indexes_read = 0;
5882 unsigned int *shndx_pool = NULL;
5883 unsigned int shndx_pool_size = 0;
5884 unsigned int shndx_pool_used = 0;
5886 /* Pre-allocate enough space for the CU/TU sets needed. */
5889 prealloc_cu_tu_list (unsigned int nshndx)
5891 if (shndx_pool == NULL)
5893 shndx_pool_size = nshndx;
5894 shndx_pool_used = 0;
5895 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
5896 sizeof (unsigned int));
5900 shndx_pool_size = shndx_pool_used + nshndx;
5901 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
5902 sizeof (unsigned int));
5907 add_shndx_to_cu_tu_entry (unsigned int shndx)
5909 if (shndx_pool_used >= shndx_pool_size)
5911 error (_("Internal error: out of space in the shndx pool.\n"));
5914 shndx_pool [shndx_pool_used++] = shndx;
5918 end_cu_tu_entry (void)
5920 if (shndx_pool_used >= shndx_pool_size)
5922 error (_("Internal error: out of space in the shndx pool.\n"));
5925 shndx_pool [shndx_pool_used++] = 0;
5928 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents. */
5931 process_cu_tu_index (struct dwarf_section *section, int do_display)
5933 unsigned char *phdr = section->start;
5934 unsigned char *limit = phdr + section->size;
5935 unsigned char *phash;
5936 unsigned char *pindex;
5937 unsigned char *ppool;
5938 unsigned int version;
5940 unsigned int nslots;
5943 version = byte_get (phdr, 4);
5944 nused = byte_get (phdr + 8, 4);
5945 nslots = byte_get (phdr + 12, 4);
5947 pindex = phash + nslots * 8;
5948 ppool = pindex + nslots * 4;
5951 prealloc_cu_tu_list((limit - ppool) / 4);
5955 printf (_("Contents of the %s section:\n\n"), section->name);
5956 printf (_(" Version: %d\n"), version);
5957 printf (_(" Number of used entries: %d\n"), nused);
5958 printf (_(" Number of slots: %d\n\n"), nslots);
5963 warn (_("Section %s too small for %d hash table entries\n"),
5964 section->name, nslots);
5968 for (i = 0; i < nslots; i++)
5970 dwarf_vma signature_high;
5971 dwarf_vma signature_low;
5973 unsigned char *shndx_list;
5977 byte_get_64 (phash, &signature_high, &signature_low);
5978 if (signature_high != 0 || signature_low != 0)
5980 j = byte_get (pindex, 4);
5981 shndx_list = ppool + j * 4;
5983 printf (_(" [%3d] Signature: 0x%s Sections: "),
5984 i, dwarf_vmatoa64 (signature_high, signature_low,
5985 buf, sizeof (buf)));
5988 if (shndx_list >= limit)
5990 warn (_("Section %s too small for shndx pool\n"),
5994 shndx = byte_get (shndx_list, 4);
5998 printf (" %d", shndx);
6000 add_shndx_to_cu_tu_entry (shndx);
6018 /* Load the CU and TU indexes if present. This will build a list of
6019 section sets that we can use to associate a .debug_info.dwo section
6020 with its associated .debug_abbrev.dwo section in a .dwp file. */
6023 load_cu_tu_indexes (void *file)
6025 /* If we have already loaded (or tried to load) the CU and TU indexes
6026 then do not bother to repeat the task. */
6027 if (cu_tu_indexes_read)
6030 if (load_debug_section (dwp_cu_index, file))
6031 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
6033 if (load_debug_section (dwp_tu_index, file))
6034 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
6036 cu_tu_indexes_read = 1;
6039 /* Find the set of sections that includes section SHNDX. */
6042 find_cu_tu_set (void *file, unsigned int shndx)
6046 load_cu_tu_indexes (file);
6048 /* Find SHNDX in the shndx pool. */
6049 for (i = 0; i < shndx_pool_used; i++)
6050 if (shndx_pool [i] == shndx)
6053 if (i >= shndx_pool_used)
6056 /* Now backup to find the first entry in the set. */
6057 while (i > 0 && shndx_pool [i - 1] != 0)
6060 return shndx_pool + i;
6063 /* Display a .debug_cu_index or .debug_tu_index section. */
6066 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
6068 return process_cu_tu_index (section, 1);
6072 display_debug_not_supported (struct dwarf_section *section,
6073 void *file ATTRIBUTE_UNUSED)
6075 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6082 cmalloc (size_t nmemb, size_t size)
6084 /* Check for overflow. */
6085 if (nmemb >= ~(size_t) 0 / size)
6088 return malloc (nmemb * size);
6092 xcmalloc (size_t nmemb, size_t size)
6094 /* Check for overflow. */
6095 if (nmemb >= ~(size_t) 0 / size)
6098 return xmalloc (nmemb * size);
6102 xcrealloc (void *ptr, size_t nmemb, size_t size)
6104 /* Check for overflow. */
6105 if (nmemb >= ~(size_t) 0 / size)
6108 return xrealloc (ptr, nmemb * size);
6112 free_debug_memory (void)
6118 for (i = 0; i < max; i++)
6119 free_debug_section ((enum dwarf_section_display_enum) i);
6121 if (debug_information != NULL)
6123 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
6125 for (i = 0; i < num_debug_info_entries; i++)
6127 if (!debug_information [i].max_loc_offsets)
6129 free (debug_information [i].loc_offsets);
6130 free (debug_information [i].have_frame_base);
6132 if (!debug_information [i].max_range_lists)
6133 free (debug_information [i].range_lists);
6137 free (debug_information);
6138 debug_information = NULL;
6139 num_debug_info_entries = 0;
6144 dwarf_select_sections_by_names (const char *names)
6148 const char * option;
6152 debug_dump_long_opts;
6154 static const debug_dump_long_opts opts_table [] =
6156 /* Please keep this table alpha- sorted. */
6157 { "Ranges", & do_debug_ranges, 1 },
6158 { "abbrev", & do_debug_abbrevs, 1 },
6159 { "addr", & do_debug_addr, 1 },
6160 { "aranges", & do_debug_aranges, 1 },
6161 { "cu_index", & do_debug_cu_index, 1 },
6162 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
6163 { "frames", & do_debug_frames, 1 },
6164 { "frames-interp", & do_debug_frames_interp, 1 },
6165 /* The special .gdb_index section. */
6166 { "gdb_index", & do_gdb_index, 1 },
6167 { "info", & do_debug_info, 1 },
6168 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
6169 { "loc", & do_debug_loc, 1 },
6170 { "macro", & do_debug_macinfo, 1 },
6171 { "pubnames", & do_debug_pubnames, 1 },
6172 { "pubtypes", & do_debug_pubtypes, 1 },
6173 /* This entry is for compatability
6174 with earlier versions of readelf. */
6175 { "ranges", & do_debug_aranges, 1 },
6176 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
6177 { "str", & do_debug_str, 1 },
6178 /* These trace_* sections are used by Itanium VMS. */
6179 { "trace_abbrev", & do_trace_abbrevs, 1 },
6180 { "trace_aranges", & do_trace_aranges, 1 },
6181 { "trace_info", & do_trace_info, 1 },
6190 const debug_dump_long_opts * entry;
6192 for (entry = opts_table; entry->option; entry++)
6194 size_t len = strlen (entry->option);
6196 if (strncmp (p, entry->option, len) == 0
6197 && (p[len] == ',' || p[len] == '\0'))
6199 * entry->variable |= entry->val;
6201 /* The --debug-dump=frames-interp option also
6202 enables the --debug-dump=frames option. */
6203 if (do_debug_frames_interp)
6204 do_debug_frames = 1;
6211 if (entry->option == NULL)
6213 warn (_("Unrecognized debug option '%s'\n"), p);
6214 p = strchr (p, ',');
6225 dwarf_select_sections_by_letters (const char *letters)
6227 unsigned int lindex = 0;
6229 while (letters[lindex])
6230 switch (letters[lindex++])
6237 do_debug_abbrevs = 1;
6241 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
6245 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
6249 do_debug_pubnames = 1;
6253 do_debug_pubtypes = 1;
6257 do_debug_aranges = 1;
6261 do_debug_ranges = 1;
6265 do_debug_frames_interp = 1;
6267 do_debug_frames = 1;
6271 do_debug_macinfo = 1;
6283 warn (_("Unrecognized debug option '%s'\n"), optarg);
6289 dwarf_select_sections_all (void)
6292 do_debug_abbrevs = 1;
6293 do_debug_lines = FLAG_DEBUG_LINES_RAW;
6294 do_debug_pubnames = 1;
6295 do_debug_pubtypes = 1;
6296 do_debug_aranges = 1;
6297 do_debug_ranges = 1;
6298 do_debug_frames = 1;
6299 do_debug_macinfo = 1;
6304 do_trace_abbrevs = 1;
6305 do_trace_aranges = 1;
6307 do_debug_cu_index = 1;
6310 struct dwarf_section_display debug_displays[] =
6312 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0 },
6313 display_debug_abbrev, &do_debug_abbrevs, 0 },
6314 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0 },
6315 display_debug_aranges, &do_debug_aranges, 1 },
6316 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0 },
6317 display_debug_frames, &do_debug_frames, 1 },
6318 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev },
6319 display_debug_info, &do_debug_info, 1 },
6320 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0 },
6321 display_debug_lines, &do_debug_lines, 1 },
6322 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0 },
6323 display_debug_pubnames, &do_debug_pubnames, 0 },
6324 { { ".eh_frame", "", NULL, NULL, 0, 0, 0 },
6325 display_debug_frames, &do_debug_frames, 1 },
6326 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0 },
6327 display_debug_macinfo, &do_debug_macinfo, 0 },
6328 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0 },
6329 display_debug_macro, &do_debug_macinfo, 1 },
6330 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0 },
6331 display_debug_str, &do_debug_str, 0 },
6332 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0 },
6333 display_debug_loc, &do_debug_loc, 1 },
6334 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0 },
6335 display_debug_pubnames, &do_debug_pubtypes, 0 },
6336 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0 },
6337 display_debug_ranges, &do_debug_ranges, 1 },
6338 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0 },
6339 display_debug_not_supported, NULL, 0 },
6340 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0 },
6341 display_debug_not_supported, NULL, 0 },
6342 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev },
6343 display_debug_types, &do_debug_info, 1 },
6344 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0 },
6345 display_debug_not_supported, NULL, 0 },
6346 { { ".gdb_index", "", NULL, NULL, 0, 0, 0 },
6347 display_gdb_index, &do_gdb_index, 0 },
6348 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev },
6349 display_trace_info, &do_trace_info, 1 },
6350 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0 },
6351 display_debug_abbrev, &do_trace_abbrevs, 0 },
6352 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0 },
6353 display_debug_aranges, &do_trace_aranges, 0 },
6354 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6355 display_debug_info, &do_debug_info, 1 },
6356 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0 },
6357 display_debug_abbrev, &do_debug_abbrevs, 0 },
6358 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6359 display_debug_types, &do_debug_info, 1 },
6360 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0 },
6361 display_debug_lines, &do_debug_lines, 1 },
6362 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0 },
6363 display_debug_loc, &do_debug_loc, 1 },
6364 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0 },
6365 display_debug_macro, &do_debug_macinfo, 1 },
6366 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0 },
6367 display_debug_macinfo, &do_debug_macinfo, 0 },
6368 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0 },
6369 display_debug_str, &do_debug_str, 1 },
6370 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0 },
6371 display_debug_str_offsets, NULL, 0 },
6372 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0 },
6373 display_debug_str_offsets, NULL, 0 },
6374 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0 },
6375 display_debug_addr, &do_debug_addr, 1 },
6376 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0 },
6377 display_cu_index, &do_debug_cu_index, 0 },
6378 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0 },
6379 display_cu_index, &do_debug_cu_index, 0 },