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 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
75 sections. For version 1 package files, each set is stored in SHNDX_POOL
76 as a zero-terminated list of section indexes comprising one set of debug
77 sections from a .dwo file. */
79 static int cu_tu_indexes_read = 0;
80 static unsigned int *shndx_pool = NULL;
81 static unsigned int shndx_pool_size = 0;
82 static unsigned int shndx_pool_used = 0;
84 /* For version 2 package files, each set contains an array of section offsets
85 and an array of section sizes, giving the offset and size of the
86 contribution from a CU or TU within one of the debug sections.
87 When displaying debug info from a package file, we need to use these
88 tables to locate the corresponding contributions to each section. */
93 dwarf_vma section_offsets[DW_SECT_MAX];
94 size_t section_sizes[DW_SECT_MAX];
97 static int cu_count = 0;
98 static int tu_count = 0;
99 static struct cu_tu_set *cu_sets = NULL;
100 static struct cu_tu_set *tu_sets = NULL;
102 static void load_cu_tu_indexes (void *file);
104 /* Values for do_debug_lines. */
105 #define FLAG_DEBUG_LINES_RAW 1
106 #define FLAG_DEBUG_LINES_DECODED 2
109 size_of_encoded_value (int encoding)
111 switch (encoding & 0x7)
114 case 0: return eh_addr_size;
122 get_encoded_value (unsigned char *data,
124 struct dwarf_section *section)
126 int size = size_of_encoded_value (encoding);
129 if (encoding & DW_EH_PE_signed)
130 val = byte_get_signed (data, size);
132 val = byte_get (data, size);
134 if ((encoding & 0x70) == DW_EH_PE_pcrel)
135 val += section->address + (data - section->start);
139 /* Print a dwarf_vma value (typically an address, offset or length) in
140 hexadecimal format, followed by a space. The length of the value (and
141 hence the precision displayed) is determined by the byte_size parameter. */
144 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
146 static char buff[18];
149 /* Printf does not have a way of specifiying a maximum field width for an
150 integer value, so we print the full value into a buffer and then select
151 the precision we need. */
152 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
154 snprintf (buff, sizeof (buff), "%16.16llx ", val);
156 snprintf (buff, sizeof (buff), "%016I64x ", val);
159 snprintf (buff, sizeof (buff), "%16.16lx ", val);
164 if (byte_size > 0 && byte_size <= 8)
165 offset = 16 - 2 * byte_size;
167 error (_("Wrong size in print_dwarf_vma"));
170 fputs (buff + offset, stdout);
173 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
175 #define DWARF_VMA_FMT "ll"
177 #define DWARF_VMA_FMT "I64"
180 #define DWARF_VMA_FMT "l"
184 dwarf_vmatoa (const char *fmtch, dwarf_vma value)
186 /* As dwarf_vmatoa is used more then once in a printf call
187 for output, we are cycling through an fixed array of pointers
188 for return address. */
189 static int buf_pos = 0;
190 static struct dwarf_vmatoa_buf
197 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
199 ret = buf[buf_pos++].place;
200 buf_pos %= ARRAY_SIZE (buf);
202 snprintf (ret, sizeof (buf[0].place), fmt, value);
207 /* Format a 64-bit value, given as two 32-bit values, in hex.
208 For reentrancy, this uses a buffer provided by the caller. */
211 dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf,
212 unsigned int buf_len)
217 snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue);
220 len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue);
221 snprintf (buf + len, buf_len - len,
222 "%08" DWARF_VMA_FMT "x", lvalue);
229 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
231 dwarf_vma result = 0;
232 unsigned int num_read = 0;
233 unsigned int shift = 0;
241 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
248 if (length_return != NULL)
249 *length_return = num_read;
251 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
252 result |= -1L << shift;
257 /* Create a signed version to avoid painful typecasts. */
258 static dwarf_signed_vma
259 read_sleb128 (unsigned char *data, unsigned int *length_return)
261 return (dwarf_signed_vma) read_leb128 (data, length_return, 1);
264 typedef struct State_Machine_Registers
272 unsigned char op_index;
273 unsigned char end_sequence;
274 /* This variable hold the number of the last entry seen
275 in the File Table. */
276 unsigned int last_file_entry;
279 static SMR state_machine_regs;
282 reset_state_machine (int is_stmt)
284 state_machine_regs.address = 0;
285 state_machine_regs.op_index = 0;
286 state_machine_regs.file = 1;
287 state_machine_regs.line = 1;
288 state_machine_regs.column = 0;
289 state_machine_regs.is_stmt = is_stmt;
290 state_machine_regs.basic_block = 0;
291 state_machine_regs.end_sequence = 0;
292 state_machine_regs.last_file_entry = 0;
295 /* Handled an extend line op.
296 Returns the number of bytes read. */
299 process_extended_line_op (unsigned char *data, int is_stmt)
301 unsigned char op_code;
302 unsigned int bytes_read;
306 unsigned char *orig_data = data;
308 len = read_leb128 (data, & bytes_read, 0);
313 warn (_("badly formed extended line op encountered!\n"));
320 printf (_(" Extended opcode %d: "), op_code);
324 case DW_LNE_end_sequence:
325 printf (_("End of Sequence\n\n"));
326 reset_state_machine (is_stmt);
329 case DW_LNE_set_address:
330 adr = byte_get (data, len - bytes_read - 1);
331 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
332 state_machine_regs.address = adr;
333 state_machine_regs.op_index = 0;
336 case DW_LNE_define_file:
337 printf (_("define new File Table entry\n"));
338 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
340 printf (" %d\t", ++state_machine_regs.last_file_entry);
342 data += strlen ((char *) data) + 1;
343 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
345 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
347 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
350 if ((unsigned int) (data - orig_data) != len)
351 printf (_(" [Bad opcode length]"));
355 case DW_LNE_set_discriminator:
356 printf (_("set Discriminator to %s\n"),
357 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
361 case DW_LNE_HP_negate_is_UV_update:
362 printf ("DW_LNE_HP_negate_is_UV_update\n");
364 case DW_LNE_HP_push_context:
365 printf ("DW_LNE_HP_push_context\n");
367 case DW_LNE_HP_pop_context:
368 printf ("DW_LNE_HP_pop_context\n");
370 case DW_LNE_HP_set_file_line_column:
371 printf ("DW_LNE_HP_set_file_line_column\n");
373 case DW_LNE_HP_set_routine_name:
374 printf ("DW_LNE_HP_set_routine_name\n");
376 case DW_LNE_HP_set_sequence:
377 printf ("DW_LNE_HP_set_sequence\n");
379 case DW_LNE_HP_negate_post_semantics:
380 printf ("DW_LNE_HP_negate_post_semantics\n");
382 case DW_LNE_HP_negate_function_exit:
383 printf ("DW_LNE_HP_negate_function_exit\n");
385 case DW_LNE_HP_negate_front_end_logical:
386 printf ("DW_LNE_HP_negate_front_end_logical\n");
388 case DW_LNE_HP_define_proc:
389 printf ("DW_LNE_HP_define_proc\n");
391 case DW_LNE_HP_source_file_correlation:
393 unsigned char *edata = data + len - bytes_read - 1;
395 printf ("DW_LNE_HP_source_file_correlation\n");
401 opc = read_leb128 (data, & bytes_read, 0);
406 case DW_LNE_HP_SFC_formfeed:
407 printf (" DW_LNE_HP_SFC_formfeed\n");
409 case DW_LNE_HP_SFC_set_listing_line:
410 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
412 read_leb128 (data, & bytes_read, 0)));
415 case DW_LNE_HP_SFC_associate:
416 printf (" DW_LNE_HP_SFC_associate ");
419 read_leb128 (data, & bytes_read, 0)));
423 read_leb128 (data, & bytes_read, 0)));
427 read_leb128 (data, & bytes_read, 0)));
431 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
441 unsigned int rlen = len - bytes_read - 1;
443 if (op_code >= DW_LNE_lo_user
444 /* The test against DW_LNW_hi_user is redundant due to
445 the limited range of the unsigned char data type used
447 /*&& op_code <= DW_LNE_hi_user*/)
448 printf (_("user defined: "));
450 printf (_("UNKNOWN: "));
451 printf (_("length %d ["), rlen);
453 printf (" %02x", *data++);
463 fetch_indirect_string (dwarf_vma offset)
465 struct dwarf_section *section = &debug_displays [str].section;
467 if (section->start == NULL)
468 return _("<no .debug_str section>");
470 /* DWARF sections under Mach-O have non-zero addresses. */
471 offset -= section->address;
472 if (offset > section->size)
474 warn (_("DW_FORM_strp offset too big: %s\n"),
475 dwarf_vmatoa ("x", offset));
476 return _("<offset is too big>");
479 return (const char *) section->start + offset;
483 fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set,
484 dwarf_vma offset_size, int dwo)
486 enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str;
487 enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index;
488 struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section;
489 struct dwarf_section *str_section = &debug_displays [str_sec_idx].section;
490 dwarf_vma index_offset = idx * offset_size;
491 dwarf_vma str_offset;
493 if (index_section->start == NULL)
494 return (dwo ? _("<no .debug_str_offsets.dwo section>")
495 : _("<no .debug_str_offsets section>"));
497 /* DWARF sections under Mach-O have non-zero addresses. */
498 index_offset -= index_section->address;
499 if (this_set != NULL)
500 index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS];
501 if (index_offset > index_section->size)
503 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
504 dwarf_vmatoa ("x", index_offset));
505 return _("<index offset is too big>");
508 if (str_section->start == NULL)
509 return (dwo ? _("<no .debug_str.dwo section>")
510 : _("<no .debug_str section>"));
512 str_offset = byte_get (index_section->start + index_offset, offset_size);
513 str_offset -= str_section->address;
514 if (str_offset > str_section->size)
516 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
517 dwarf_vmatoa ("x", str_offset));
518 return _("<indirect index offset is too big>");
521 return (const char *) str_section->start + str_offset;
525 fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes)
527 struct dwarf_section *section = &debug_displays [debug_addr].section;
529 if (section->start == NULL)
530 return (_("<no .debug_addr section>"));
532 if (offset + bytes > section->size)
534 warn (_("Offset into section %s too big: %s\n"),
535 section->name, dwarf_vmatoa ("x", offset));
536 return "<offset too big>";
539 return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes));
543 /* FIXME: There are better and more efficient ways to handle
544 these structures. For now though, I just want something that
545 is simple to implement. */
546 typedef struct abbrev_attr
548 unsigned long attribute;
550 struct abbrev_attr *next;
554 typedef struct abbrev_entry
559 struct abbrev_attr *first_attr;
560 struct abbrev_attr *last_attr;
561 struct abbrev_entry *next;
565 static abbrev_entry *first_abbrev = NULL;
566 static abbrev_entry *last_abbrev = NULL;
573 for (abbrv = first_abbrev; abbrv;)
575 abbrev_entry *next_abbrev = abbrv->next;
578 for (attr = abbrv->first_attr; attr;)
580 abbrev_attr *next_attr = attr->next;
590 last_abbrev = first_abbrev = NULL;
594 add_abbrev (unsigned long number, unsigned long tag, int children)
598 entry = (abbrev_entry *) malloc (sizeof (*entry));
603 entry->entry = number;
605 entry->children = children;
606 entry->first_attr = NULL;
607 entry->last_attr = NULL;
610 if (first_abbrev == NULL)
611 first_abbrev = entry;
613 last_abbrev->next = entry;
619 add_abbrev_attr (unsigned long attribute, unsigned long form)
623 attr = (abbrev_attr *) malloc (sizeof (*attr));
628 attr->attribute = attribute;
632 if (last_abbrev->first_attr == NULL)
633 last_abbrev->first_attr = attr;
635 last_abbrev->last_attr->next = attr;
637 last_abbrev->last_attr = attr;
640 /* Processes the (partial) contents of a .debug_abbrev section.
641 Returns NULL if the end of the section was encountered.
642 Returns the address after the last byte read if the end of
643 an abbreviation set was found. */
645 static unsigned char *
646 process_abbrev_section (unsigned char *start, unsigned char *end)
648 if (first_abbrev != NULL)
653 unsigned int bytes_read;
656 unsigned long attribute;
659 entry = read_leb128 (start, & bytes_read, 0);
662 /* A single zero is supposed to end the section according
663 to the standard. If there's more, then signal that to
666 return start == end ? NULL : start;
668 tag = read_leb128 (start, & bytes_read, 0);
673 add_abbrev (entry, tag, children);
679 attribute = read_leb128 (start, & bytes_read, 0);
682 form = read_leb128 (start, & bytes_read, 0);
685 add_abbrev_attr (attribute, form);
687 while (attribute != 0);
690 /* Report the missing single zero which ends the section. */
691 error (_(".debug_abbrev section not zero terminated\n"));
697 get_TAG_name (unsigned long tag)
699 const char *name = get_DW_TAG_name ((unsigned int)tag);
703 static char buffer[100];
705 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
713 get_FORM_name (unsigned long form)
718 return "DW_FORM value: 0";
720 name = get_DW_FORM_name (form);
723 static char buffer[100];
725 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
732 static unsigned char *
733 display_block (unsigned char *data, dwarf_vma length)
735 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
738 printf ("%lx ", (unsigned long) byte_get (data++, 1));
744 decode_location_expression (unsigned char * data,
745 unsigned int pointer_size,
746 unsigned int offset_size,
750 struct dwarf_section * section)
753 unsigned int bytes_read;
755 unsigned char *end = data + length;
756 int need_frame_base = 0;
765 printf ("DW_OP_addr: %s",
766 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
767 data += pointer_size;
770 printf ("DW_OP_deref");
773 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
776 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
779 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
783 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
787 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
791 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
795 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
796 (unsigned long) byte_get (data + 4, 4));
800 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
801 (long) byte_get (data + 4, 4));
805 printf ("DW_OP_constu: %s",
806 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
810 printf ("DW_OP_consts: %s",
811 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
815 printf ("DW_OP_dup");
818 printf ("DW_OP_drop");
821 printf ("DW_OP_over");
824 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
827 printf ("DW_OP_swap");
830 printf ("DW_OP_rot");
833 printf ("DW_OP_xderef");
836 printf ("DW_OP_abs");
839 printf ("DW_OP_and");
842 printf ("DW_OP_div");
845 printf ("DW_OP_minus");
848 printf ("DW_OP_mod");
851 printf ("DW_OP_mul");
854 printf ("DW_OP_neg");
857 printf ("DW_OP_not");
863 printf ("DW_OP_plus");
865 case DW_OP_plus_uconst:
866 printf ("DW_OP_plus_uconst: %s",
867 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
871 printf ("DW_OP_shl");
874 printf ("DW_OP_shr");
877 printf ("DW_OP_shra");
880 printf ("DW_OP_xor");
883 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
905 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
941 printf ("DW_OP_lit%d", op - DW_OP_lit0);
976 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
977 regname (op - DW_OP_reg0, 1));
1012 printf ("DW_OP_breg%d (%s): %s",
1014 regname (op - DW_OP_breg0, 1),
1015 dwarf_vmatoa ("d", (dwarf_signed_vma)
1016 read_leb128 (data, &bytes_read, 1)));
1021 uvalue = read_leb128 (data, &bytes_read, 0);
1023 printf ("DW_OP_regx: %s (%s)",
1024 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1027 need_frame_base = 1;
1028 printf ("DW_OP_fbreg: %s",
1029 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1033 uvalue = read_leb128 (data, &bytes_read, 0);
1035 printf ("DW_OP_bregx: %s (%s) %s",
1036 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1037 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1041 printf ("DW_OP_piece: %s",
1042 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1045 case DW_OP_deref_size:
1046 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
1048 case DW_OP_xderef_size:
1049 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
1052 printf ("DW_OP_nop");
1055 /* DWARF 3 extensions. */
1056 case DW_OP_push_object_address:
1057 printf ("DW_OP_push_object_address");
1060 /* XXX: Strictly speaking for 64-bit DWARF3 files
1061 this ought to be an 8-byte wide computation. */
1062 printf ("DW_OP_call2: <0x%s>",
1063 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2)
1068 /* XXX: Strictly speaking for 64-bit DWARF3 files
1069 this ought to be an 8-byte wide computation. */
1070 printf ("DW_OP_call4: <0x%s>",
1071 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4)
1075 case DW_OP_call_ref:
1076 /* XXX: Strictly speaking for 64-bit DWARF3 files
1077 this ought to be an 8-byte wide computation. */
1078 if (dwarf_version == -1)
1080 printf (_("(DW_OP_call_ref in frame info)"));
1081 /* No way to tell where the next op is, so just bail. */
1082 return need_frame_base;
1084 if (dwarf_version == 2)
1086 printf ("DW_OP_call_ref: <0x%s>",
1087 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
1088 data += pointer_size;
1092 printf ("DW_OP_call_ref: <0x%s>",
1093 dwarf_vmatoa ("x", byte_get (data, offset_size)));
1094 data += offset_size;
1097 case DW_OP_form_tls_address:
1098 printf ("DW_OP_form_tls_address");
1100 case DW_OP_call_frame_cfa:
1101 printf ("DW_OP_call_frame_cfa");
1103 case DW_OP_bit_piece:
1104 printf ("DW_OP_bit_piece: ");
1105 printf (_("size: %s "),
1106 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1108 printf (_("offset: %s "),
1109 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1113 /* DWARF 4 extensions. */
1114 case DW_OP_stack_value:
1115 printf ("DW_OP_stack_value");
1118 case DW_OP_implicit_value:
1119 printf ("DW_OP_implicit_value");
1120 uvalue = read_leb128 (data, &bytes_read, 0);
1122 display_block (data, uvalue);
1126 /* GNU extensions. */
1127 case DW_OP_GNU_push_tls_address:
1128 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1130 case DW_OP_GNU_uninit:
1131 printf ("DW_OP_GNU_uninit");
1132 /* FIXME: Is there data associated with this OP ? */
1134 case DW_OP_GNU_encoded_addr:
1140 addr = get_encoded_value (data, encoding, section);
1141 data += size_of_encoded_value (encoding);
1143 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1144 print_dwarf_vma (addr, pointer_size);
1147 case DW_OP_GNU_implicit_pointer:
1148 /* XXX: Strictly speaking for 64-bit DWARF3 files
1149 this ought to be an 8-byte wide computation. */
1150 if (dwarf_version == -1)
1152 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1153 /* No way to tell where the next op is, so just bail. */
1154 return need_frame_base;
1156 if (dwarf_version == 2)
1158 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1159 dwarf_vmatoa ("x", byte_get (data, pointer_size)),
1160 dwarf_vmatoa ("d", read_sleb128 (data + pointer_size,
1162 data += pointer_size + bytes_read;
1166 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1167 dwarf_vmatoa ("x", byte_get (data, offset_size)),
1168 dwarf_vmatoa ("d", read_sleb128 (data + offset_size,
1170 data += offset_size + bytes_read;
1173 case DW_OP_GNU_entry_value:
1174 uvalue = read_leb128 (data, &bytes_read, 0);
1176 printf ("DW_OP_GNU_entry_value: (");
1177 if (decode_location_expression (data, pointer_size, offset_size,
1178 dwarf_version, uvalue,
1179 cu_offset, section))
1180 need_frame_base = 1;
1184 case DW_OP_GNU_const_type:
1185 uvalue = read_leb128 (data, &bytes_read, 0);
1187 printf ("DW_OP_GNU_const_type: <0x%s> ",
1188 dwarf_vmatoa ("x", cu_offset + uvalue));
1189 uvalue = byte_get (data++, 1);
1190 display_block (data, uvalue);
1193 case DW_OP_GNU_regval_type:
1194 uvalue = read_leb128 (data, &bytes_read, 0);
1196 printf ("DW_OP_GNU_regval_type: %s (%s)",
1197 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1198 uvalue = read_leb128 (data, &bytes_read, 0);
1200 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1202 case DW_OP_GNU_deref_type:
1203 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data++, 1));
1204 uvalue = read_leb128 (data, &bytes_read, 0);
1206 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1208 case DW_OP_GNU_convert:
1209 uvalue = read_leb128 (data, &bytes_read, 0);
1211 printf ("DW_OP_GNU_convert <0x%s>",
1212 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1214 case DW_OP_GNU_reinterpret:
1215 uvalue = read_leb128 (data, &bytes_read, 0);
1217 printf ("DW_OP_GNU_reinterpret <0x%s>",
1218 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1220 case DW_OP_GNU_parameter_ref:
1221 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1222 dwarf_vmatoa ("x", cu_offset + byte_get (data, 4)));
1225 case DW_OP_GNU_addr_index:
1226 uvalue = read_leb128 (data, &bytes_read, 0);
1228 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1230 case DW_OP_GNU_const_index:
1231 uvalue = read_leb128 (data, &bytes_read, 0);
1233 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue));
1236 /* HP extensions. */
1237 case DW_OP_HP_is_value:
1238 printf ("DW_OP_HP_is_value");
1239 /* FIXME: Is there data associated with this OP ? */
1241 case DW_OP_HP_fltconst4:
1242 printf ("DW_OP_HP_fltconst4");
1243 /* FIXME: Is there data associated with this OP ? */
1245 case DW_OP_HP_fltconst8:
1246 printf ("DW_OP_HP_fltconst8");
1247 /* FIXME: Is there data associated with this OP ? */
1249 case DW_OP_HP_mod_range:
1250 printf ("DW_OP_HP_mod_range");
1251 /* FIXME: Is there data associated with this OP ? */
1253 case DW_OP_HP_unmod_range:
1254 printf ("DW_OP_HP_unmod_range");
1255 /* FIXME: Is there data associated with this OP ? */
1258 printf ("DW_OP_HP_tls");
1259 /* FIXME: Is there data associated with this OP ? */
1262 /* PGI (STMicroelectronics) extensions. */
1263 case DW_OP_PGI_omp_thread_num:
1264 /* Pushes the thread number for the current thread as it would be
1265 returned by the standard OpenMP library function:
1266 omp_get_thread_num(). The "current thread" is the thread for
1267 which the expression is being evaluated. */
1268 printf ("DW_OP_PGI_omp_thread_num");
1272 if (op >= DW_OP_lo_user
1273 && op <= DW_OP_hi_user)
1274 printf (_("(User defined location op)"));
1276 printf (_("(Unknown location op)"));
1277 /* No way to tell where the next op is, so just bail. */
1278 return need_frame_base;
1281 /* Separate the ops. */
1286 return need_frame_base;
1289 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1290 This is used for DWARF package files. */
1292 static struct cu_tu_set *
1293 find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types)
1295 struct cu_tu_set *p;
1297 unsigned int dw_sect;
1303 dw_sect = DW_SECT_TYPES;
1309 dw_sect = DW_SECT_INFO;
1313 if (p->section_offsets [dw_sect] == cu_offset)
1321 static unsigned char *
1322 read_and_display_attr_value (unsigned long attribute,
1324 unsigned char * data,
1325 dwarf_vma cu_offset,
1326 dwarf_vma pointer_size,
1327 dwarf_vma offset_size,
1329 debug_info * debug_info_p,
1331 struct dwarf_section * section,
1332 struct cu_tu_set * this_set)
1334 dwarf_vma uvalue = 0;
1335 unsigned char *block_start = NULL;
1336 unsigned char * orig_data = data;
1337 unsigned int bytes_read;
1344 case DW_FORM_ref_addr:
1345 if (dwarf_version == 2)
1347 uvalue = byte_get (data, pointer_size);
1348 data += pointer_size;
1350 else if (dwarf_version == 3 || dwarf_version == 4)
1352 uvalue = byte_get (data, offset_size);
1353 data += offset_size;
1356 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1361 uvalue = byte_get (data, pointer_size);
1362 data += pointer_size;
1366 case DW_FORM_sec_offset:
1367 case DW_FORM_GNU_ref_alt:
1368 case DW_FORM_GNU_strp_alt:
1369 uvalue = byte_get (data, offset_size);
1370 data += offset_size;
1373 case DW_FORM_flag_present:
1380 uvalue = byte_get (data++, 1);
1385 uvalue = byte_get (data, 2);
1391 uvalue = byte_get (data, 4);
1396 uvalue = read_leb128 (data, & bytes_read, 1);
1400 case DW_FORM_GNU_str_index:
1401 uvalue = read_leb128 (data, & bytes_read, 0);
1405 case DW_FORM_ref_udata:
1407 uvalue = read_leb128 (data, & bytes_read, 0);
1411 case DW_FORM_indirect:
1412 form = read_leb128 (data, & bytes_read, 0);
1415 printf (" %s", get_FORM_name (form));
1416 return read_and_display_attr_value (attribute, form, data,
1417 cu_offset, pointer_size,
1418 offset_size, dwarf_version,
1419 debug_info_p, do_loc,
1421 case DW_FORM_GNU_addr_index:
1422 uvalue = read_leb128 (data, & bytes_read, 0);
1429 case DW_FORM_ref_addr:
1431 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1434 case DW_FORM_GNU_ref_alt:
1436 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue));
1442 case DW_FORM_ref_udata:
1444 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1449 case DW_FORM_sec_offset:
1451 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1454 case DW_FORM_flag_present:
1461 printf (" %s", dwarf_vmatoa ("d", uvalue));
1468 dwarf_vma high_bits;
1471 byte_get_64 (data, &high_bits, &uvalue);
1473 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1475 if ((do_loc || do_debug_loc || do_debug_ranges)
1476 && num_debug_info_entries == 0)
1478 if (sizeof (uvalue) == 8)
1479 uvalue = byte_get (data, 8);
1481 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1486 case DW_FORM_string:
1488 printf (" %s", data);
1489 data += strlen ((char *) data) + 1;
1493 case DW_FORM_exprloc:
1494 uvalue = read_leb128 (data, & bytes_read, 0);
1495 block_start = data + bytes_read;
1497 data = block_start + uvalue;
1499 data = display_block (block_start, uvalue);
1502 case DW_FORM_block1:
1503 uvalue = byte_get (data, 1);
1504 block_start = data + 1;
1506 data = block_start + uvalue;
1508 data = display_block (block_start, uvalue);
1511 case DW_FORM_block2:
1512 uvalue = byte_get (data, 2);
1513 block_start = data + 2;
1515 data = block_start + uvalue;
1517 data = display_block (block_start, uvalue);
1520 case DW_FORM_block4:
1521 uvalue = byte_get (data, 4);
1522 block_start = data + 4;
1524 data = block_start + uvalue;
1526 data = display_block (block_start, uvalue);
1531 printf (_(" (indirect string, offset: 0x%s): %s"),
1532 dwarf_vmatoa ("x", uvalue),
1533 fetch_indirect_string (uvalue));
1536 case DW_FORM_GNU_str_index:
1539 const char *suffix = strrchr (section->name, '.');
1540 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1542 printf (_(" (indexed string: 0x%s): %s"),
1543 dwarf_vmatoa ("x", uvalue),
1544 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1548 case DW_FORM_GNU_strp_alt:
1550 printf (_(" (alt indirect string, offset: 0x%s)"),
1551 dwarf_vmatoa ("x", uvalue));
1554 case DW_FORM_indirect:
1555 /* Handled above. */
1558 case DW_FORM_ref_sig8:
1561 dwarf_vma high_bits;
1564 byte_get_64 (data, &high_bits, &uvalue);
1565 printf (" signature: 0x%s",
1566 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1571 case DW_FORM_GNU_addr_index:
1573 printf (_(" (addr_index: 0x%s): %s"),
1574 dwarf_vmatoa ("x", uvalue),
1575 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1579 warn (_("Unrecognized form: %lu\n"), form);
1583 if ((do_loc || do_debug_loc || do_debug_ranges)
1584 && num_debug_info_entries == 0
1585 && debug_info_p != NULL)
1589 case DW_AT_frame_base:
1590 have_frame_base = 1;
1591 case DW_AT_location:
1592 case DW_AT_string_length:
1593 case DW_AT_return_addr:
1594 case DW_AT_data_member_location:
1595 case DW_AT_vtable_elem_location:
1597 case DW_AT_static_link:
1598 case DW_AT_use_location:
1599 case DW_AT_GNU_call_site_value:
1600 case DW_AT_GNU_call_site_data_value:
1601 case DW_AT_GNU_call_site_target:
1602 case DW_AT_GNU_call_site_target_clobbered:
1603 if ((dwarf_version < 4
1604 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1605 || form == DW_FORM_sec_offset)
1607 /* Process location list. */
1608 unsigned int lmax = debug_info_p->max_loc_offsets;
1609 unsigned int num = debug_info_p->num_loc_offsets;
1611 if (lmax == 0 || num >= lmax)
1614 debug_info_p->loc_offsets = (dwarf_vma *)
1615 xcrealloc (debug_info_p->loc_offsets,
1616 lmax, sizeof (*debug_info_p->loc_offsets));
1617 debug_info_p->have_frame_base = (int *)
1618 xcrealloc (debug_info_p->have_frame_base,
1619 lmax, sizeof (*debug_info_p->have_frame_base));
1620 debug_info_p->max_loc_offsets = lmax;
1622 if (this_set != NULL)
1623 uvalue += this_set->section_offsets [DW_SECT_LOC];
1624 debug_info_p->loc_offsets [num] = uvalue;
1625 debug_info_p->have_frame_base [num] = have_frame_base;
1626 debug_info_p->num_loc_offsets++;
1631 if (need_base_address)
1632 debug_info_p->base_address = uvalue;
1635 case DW_AT_GNU_addr_base:
1636 debug_info_p->addr_base = uvalue;
1639 case DW_AT_GNU_ranges_base:
1640 debug_info_p->ranges_base = uvalue;
1644 if ((dwarf_version < 4
1645 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1646 || form == DW_FORM_sec_offset)
1648 /* Process range list. */
1649 unsigned int lmax = debug_info_p->max_range_lists;
1650 unsigned int num = debug_info_p->num_range_lists;
1652 if (lmax == 0 || num >= lmax)
1655 debug_info_p->range_lists = (dwarf_vma *)
1656 xcrealloc (debug_info_p->range_lists,
1657 lmax, sizeof (*debug_info_p->range_lists));
1658 debug_info_p->max_range_lists = lmax;
1660 debug_info_p->range_lists [num] = uvalue;
1661 debug_info_p->num_range_lists++;
1670 if (do_loc || attribute == 0)
1673 /* For some attributes we can display further information. */
1681 case DW_INL_not_inlined:
1682 printf (_("(not inlined)"));
1684 case DW_INL_inlined:
1685 printf (_("(inlined)"));
1687 case DW_INL_declared_not_inlined:
1688 printf (_("(declared as inline but ignored)"));
1690 case DW_INL_declared_inlined:
1691 printf (_("(declared as inline and inlined)"));
1694 printf (_(" (Unknown inline attribute value: %s)"),
1695 dwarf_vmatoa ("x", uvalue));
1700 case DW_AT_language:
1703 /* Ordered by the numeric value of these constants. */
1704 case DW_LANG_C89: printf ("(ANSI C)"); break;
1705 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1706 case DW_LANG_Ada83: printf ("(Ada)"); break;
1707 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1708 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1709 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1710 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1711 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1712 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1713 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1714 /* DWARF 2.1 values. */
1715 case DW_LANG_Java: printf ("(Java)"); break;
1716 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1717 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1718 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1719 /* DWARF 3 values. */
1720 case DW_LANG_PLI: printf ("(PLI)"); break;
1721 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1722 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1723 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1724 case DW_LANG_D: printf ("(D)"); break;
1725 /* DWARF 4 values. */
1726 case DW_LANG_Python: printf ("(Python)"); break;
1727 /* DWARF 5 values. */
1728 case DW_LANG_Go: printf ("(Go)"); break;
1729 /* MIPS extension. */
1730 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1731 /* UPC extension. */
1732 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1734 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1735 printf (_("(implementation defined: %s)"),
1736 dwarf_vmatoa ("x", uvalue));
1738 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1743 case DW_AT_encoding:
1746 case DW_ATE_void: printf ("(void)"); break;
1747 case DW_ATE_address: printf ("(machine address)"); break;
1748 case DW_ATE_boolean: printf ("(boolean)"); break;
1749 case DW_ATE_complex_float: printf ("(complex float)"); break;
1750 case DW_ATE_float: printf ("(float)"); break;
1751 case DW_ATE_signed: printf ("(signed)"); break;
1752 case DW_ATE_signed_char: printf ("(signed char)"); break;
1753 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1754 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1755 /* DWARF 2.1 values: */
1756 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1757 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1758 /* DWARF 3 values: */
1759 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1760 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1761 case DW_ATE_edited: printf ("(edited)"); break;
1762 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1763 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1764 /* HP extensions: */
1765 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1766 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1767 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1768 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1769 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1770 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1771 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1774 if (uvalue >= DW_ATE_lo_user
1775 && uvalue <= DW_ATE_hi_user)
1776 printf (_("(user defined type)"));
1778 printf (_("(unknown type)"));
1783 case DW_AT_accessibility:
1786 case DW_ACCESS_public: printf ("(public)"); break;
1787 case DW_ACCESS_protected: printf ("(protected)"); break;
1788 case DW_ACCESS_private: printf ("(private)"); break;
1790 printf (_("(unknown accessibility)"));
1795 case DW_AT_visibility:
1798 case DW_VIS_local: printf ("(local)"); break;
1799 case DW_VIS_exported: printf ("(exported)"); break;
1800 case DW_VIS_qualified: printf ("(qualified)"); break;
1801 default: printf (_("(unknown visibility)")); break;
1805 case DW_AT_virtuality:
1808 case DW_VIRTUALITY_none: printf ("(none)"); break;
1809 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1810 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1811 default: printf (_("(unknown virtuality)")); break;
1815 case DW_AT_identifier_case:
1818 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1819 case DW_ID_up_case: printf ("(up_case)"); break;
1820 case DW_ID_down_case: printf ("(down_case)"); break;
1821 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1822 default: printf (_("(unknown case)")); break;
1826 case DW_AT_calling_convention:
1829 case DW_CC_normal: printf ("(normal)"); break;
1830 case DW_CC_program: printf ("(program)"); break;
1831 case DW_CC_nocall: printf ("(nocall)"); break;
1833 if (uvalue >= DW_CC_lo_user
1834 && uvalue <= DW_CC_hi_user)
1835 printf (_("(user defined)"));
1837 printf (_("(unknown convention)"));
1841 case DW_AT_ordering:
1844 case -1: printf (_("(undefined)")); break;
1845 case 0: printf ("(row major)"); break;
1846 case 1: printf ("(column major)"); break;
1850 case DW_AT_frame_base:
1851 have_frame_base = 1;
1852 case DW_AT_location:
1853 case DW_AT_string_length:
1854 case DW_AT_return_addr:
1855 case DW_AT_data_member_location:
1856 case DW_AT_vtable_elem_location:
1858 case DW_AT_static_link:
1859 case DW_AT_use_location:
1860 case DW_AT_GNU_call_site_value:
1861 case DW_AT_GNU_call_site_data_value:
1862 case DW_AT_GNU_call_site_target:
1863 case DW_AT_GNU_call_site_target_clobbered:
1864 if ((dwarf_version < 4
1865 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1866 || form == DW_FORM_sec_offset)
1867 printf (_("(location list)"));
1869 case DW_AT_allocated:
1870 case DW_AT_associated:
1871 case DW_AT_data_location:
1873 case DW_AT_upper_bound:
1874 case DW_AT_lower_bound:
1877 int need_frame_base;
1880 need_frame_base = decode_location_expression (block_start,
1885 cu_offset, section);
1887 if (need_frame_base && !have_frame_base)
1888 printf (_(" [without DW_AT_frame_base]"));
1894 if (form == DW_FORM_ref_sig8
1895 || form == DW_FORM_GNU_ref_alt)
1898 if (form == DW_FORM_ref1
1899 || form == DW_FORM_ref2
1900 || form == DW_FORM_ref4
1901 || form == DW_FORM_ref_udata)
1902 uvalue += cu_offset;
1904 if (uvalue >= section->size)
1905 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1906 dwarf_vmatoa ("x", uvalue),
1907 (unsigned long) (orig_data - section->start));
1910 unsigned long abbrev_number;
1911 abbrev_entry * entry;
1913 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1915 printf (_("[Abbrev Number: %ld"), abbrev_number);
1916 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
1917 use different abbrev table, and we don't track .debug_info chunks
1919 if (form != DW_FORM_ref_addr)
1921 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1922 if (entry->entry == abbrev_number)
1925 printf (" (%s)", get_TAG_name (entry->tag));
1940 get_AT_name (unsigned long attribute)
1945 return "DW_AT value: 0";
1947 /* One value is shared by the MIPS and HP extensions: */
1948 if (attribute == DW_AT_MIPS_fde)
1949 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1951 name = get_DW_AT_name (attribute);
1955 static char buffer[100];
1957 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1965 static unsigned char *
1966 read_and_display_attr (unsigned long attribute,
1968 unsigned char * data,
1969 dwarf_vma cu_offset,
1970 dwarf_vma pointer_size,
1971 dwarf_vma offset_size,
1973 debug_info * debug_info_p,
1975 struct dwarf_section * section,
1976 struct cu_tu_set * this_set)
1979 printf (" %-18s:", get_AT_name (attribute));
1980 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1981 pointer_size, offset_size,
1982 dwarf_version, debug_info_p,
1983 do_loc, section, this_set);
1989 /* Process the contents of a .debug_info section. If do_loc is non-zero
1990 then we are scanning for location lists and we do not want to display
1991 anything to the user. If do_types is non-zero, we are processing
1992 a .debug_types section instead of a .debug_info section. */
1995 process_debug_info (struct dwarf_section *section,
1997 enum dwarf_section_display_enum abbrev_sec,
2001 unsigned char *start = section->start;
2002 unsigned char *end = start + section->size;
2003 unsigned char *section_begin;
2005 unsigned int num_units = 0;
2007 if ((do_loc || do_debug_loc || do_debug_ranges)
2008 && num_debug_info_entries == 0
2013 /* First scan the section to get the number of comp units. */
2014 for (section_begin = start, num_units = 0; section_begin < end;
2017 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2018 will be the length. For a 64-bit DWARF section, it'll be
2019 the escape code 0xffffffff followed by an 8 byte length. */
2020 length = byte_get (section_begin, 4);
2022 if (length == 0xffffffff)
2024 length = byte_get (section_begin + 4, 8);
2025 section_begin += length + 12;
2027 else if (length >= 0xfffffff0 && length < 0xffffffff)
2029 warn (_("Reserved length value (0x%s) found in section %s\n"),
2030 dwarf_vmatoa ("x", length), section->name);
2034 section_begin += length + 4;
2036 /* Negative values are illegal, they may even cause infinite
2037 looping. This can happen if we can't accurately apply
2038 relocations to an object file. */
2039 if ((signed long) length <= 0)
2041 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2042 dwarf_vmatoa ("x", length), section->name);
2049 error (_("No comp units in %s section ?"), section->name);
2053 /* Then allocate an array to hold the information. */
2054 debug_information = (debug_info *) cmalloc (num_units,
2055 sizeof (* debug_information));
2056 if (debug_information == NULL)
2058 error (_("Not enough memory for a debug info array of %u entries"),
2066 if (dwarf_start_die == 0)
2067 printf (_("Contents of the %s section:\n\n"), section->name);
2069 load_debug_section (str, file);
2070 load_debug_section (str_dwo, file);
2071 load_debug_section (str_index, file);
2072 load_debug_section (str_index_dwo, file);
2073 load_debug_section (debug_addr, file);
2076 load_debug_section (abbrev_sec, file);
2077 if (debug_displays [abbrev_sec].section.start == NULL)
2079 warn (_("Unable to locate %s section!\n"),
2080 debug_displays [abbrev_sec].section.name);
2084 for (section_begin = start, unit = 0; start < end; unit++)
2086 DWARF2_Internal_CompUnit compunit;
2087 unsigned char *hdrptr;
2088 unsigned char *tags;
2089 int level, last_level, saved_level;
2090 dwarf_vma cu_offset;
2092 int initial_length_size;
2093 dwarf_vma signature_high = 0;
2094 dwarf_vma signature_low = 0;
2095 dwarf_vma type_offset = 0;
2096 struct cu_tu_set *this_set;
2097 dwarf_vma abbrev_base;
2102 compunit.cu_length = byte_get (hdrptr, 4);
2105 if (compunit.cu_length == 0xffffffff)
2107 compunit.cu_length = byte_get (hdrptr, 8);
2110 initial_length_size = 12;
2115 initial_length_size = 4;
2118 compunit.cu_version = byte_get (hdrptr, 2);
2121 cu_offset = start - section_begin;
2123 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2125 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2126 hdrptr += offset_size;
2128 if (this_set == NULL)
2131 abbrev_size = debug_displays [abbrev_sec].section.size;
2135 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2136 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2139 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2144 byte_get_64 (hdrptr, &signature_high, &signature_low);
2146 type_offset = byte_get (hdrptr, offset_size);
2147 hdrptr += offset_size;
2150 if ((do_loc || do_debug_loc || do_debug_ranges)
2151 && num_debug_info_entries == 0
2154 debug_information [unit].cu_offset = cu_offset;
2155 debug_information [unit].pointer_size
2156 = compunit.cu_pointer_size;
2157 debug_information [unit].offset_size = offset_size;
2158 debug_information [unit].dwarf_version = compunit.cu_version;
2159 debug_information [unit].base_address = 0;
2160 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2161 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2162 debug_information [unit].loc_offsets = NULL;
2163 debug_information [unit].have_frame_base = NULL;
2164 debug_information [unit].max_loc_offsets = 0;
2165 debug_information [unit].num_loc_offsets = 0;
2166 debug_information [unit].range_lists = NULL;
2167 debug_information [unit].max_range_lists= 0;
2168 debug_information [unit].num_range_lists = 0;
2171 if (!do_loc && dwarf_start_die == 0)
2173 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2174 dwarf_vmatoa ("x", cu_offset));
2175 printf (_(" Length: 0x%s (%s)\n"),
2176 dwarf_vmatoa ("x", compunit.cu_length),
2177 offset_size == 8 ? "64-bit" : "32-bit");
2178 printf (_(" Version: %d\n"), compunit.cu_version);
2179 printf (_(" Abbrev Offset: 0x%s\n"),
2180 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2181 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2186 printf (_(" Signature: 0x%s\n"),
2187 dwarf_vmatoa64 (signature_high, signature_low,
2188 buf, sizeof (buf)));
2189 printf (_(" Type Offset: 0x%s\n"),
2190 dwarf_vmatoa ("x", type_offset));
2192 if (this_set != NULL)
2194 dwarf_vma *offsets = this_set->section_offsets;
2195 size_t *sizes = this_set->section_sizes;
2197 printf (_(" Section contributions:\n"));
2198 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2199 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2200 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2201 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2202 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2203 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2204 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2205 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2206 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2207 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2208 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2209 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2213 if (cu_offset + compunit.cu_length + initial_length_size
2216 warn (_("Debug info is corrupted, length of CU at %s"
2217 " extends beyond end of section (length = %s)\n"),
2218 dwarf_vmatoa ("x", cu_offset),
2219 dwarf_vmatoa ("x", compunit.cu_length));
2223 start += compunit.cu_length + initial_length_size;
2225 if (compunit.cu_version != 2
2226 && compunit.cu_version != 3
2227 && compunit.cu_version != 4)
2229 warn (_("CU at offset %s contains corrupt or "
2230 "unsupported version number: %d.\n"),
2231 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2237 /* Process the abbrevs used by this compilation unit. DWARF
2238 sections under Mach-O have non-zero addresses. */
2239 if (compunit.cu_abbrev_offset >= abbrev_size)
2240 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2241 (unsigned long) compunit.cu_abbrev_offset,
2242 (unsigned long) abbrev_size);
2244 process_abbrev_section
2245 (((unsigned char *) debug_displays [abbrev_sec].section.start
2246 + abbrev_base + compunit.cu_abbrev_offset),
2247 ((unsigned char *) debug_displays [abbrev_sec].section.start
2248 + abbrev_base + abbrev_size));
2253 while (tags < start)
2255 unsigned int bytes_read;
2256 unsigned long abbrev_number;
2257 unsigned long die_offset;
2258 abbrev_entry *entry;
2260 int do_printing = 1;
2262 die_offset = tags - section_begin;
2264 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2267 /* A null DIE marks the end of a list of siblings or it may also be
2268 a section padding. */
2269 if (abbrev_number == 0)
2271 /* Check if it can be a section padding for the last CU. */
2272 if (level == 0 && start == end)
2276 for (chk = tags; chk < start; chk++)
2283 if (!do_loc && die_offset >= dwarf_start_die)
2284 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2290 static unsigned num_bogus_warns = 0;
2292 if (num_bogus_warns < 3)
2294 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2295 die_offset, section->name);
2297 if (num_bogus_warns == 3)
2298 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2301 if (dwarf_start_die != 0 && level < saved_level)
2308 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2312 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2313 saved_level = level;
2314 do_printing = (dwarf_cutoff_level == -1
2315 || level < dwarf_cutoff_level);
2317 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2318 level, die_offset, abbrev_number);
2319 else if (dwarf_cutoff_level == -1
2320 || last_level < dwarf_cutoff_level)
2321 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2326 /* Scan through the abbreviation list until we reach the
2328 for (entry = first_abbrev;
2329 entry && entry->entry != abbrev_number;
2330 entry = entry->next)
2335 if (!do_loc && do_printing)
2340 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2341 die_offset, abbrev_number);
2345 if (!do_loc && do_printing)
2346 printf (" (%s)\n", get_TAG_name (entry->tag));
2351 need_base_address = 0;
2353 case DW_TAG_compile_unit:
2354 need_base_address = 1;
2356 case DW_TAG_entry_point:
2357 case DW_TAG_subprogram:
2358 need_base_address = 0;
2359 /* Assuming that there is no DW_AT_frame_base. */
2360 have_frame_base = 0;
2364 for (attr = entry->first_attr;
2365 attr && attr->attribute;
2370 if (! do_loc && do_printing)
2371 /* Show the offset from where the tag was extracted. */
2372 printf (" <%lx>", (unsigned long)(tags - section_begin));
2374 arg = debug_information;
2375 if (debug_information)
2378 tags = read_and_display_attr (attr->attribute,
2382 compunit.cu_pointer_size,
2384 compunit.cu_version,
2386 do_loc || ! do_printing,
2391 if (entry->children)
2396 /* Set num_debug_info_entries here so that it can be used to check if
2397 we need to process .debug_loc and .debug_ranges sections. */
2398 if ((do_loc || do_debug_loc || do_debug_ranges)
2399 && num_debug_info_entries == 0
2401 num_debug_info_entries = num_units;
2409 /* Locate and scan the .debug_info section in the file and record the pointer
2410 sizes and offsets for the compilation units in it. Usually an executable
2411 will have just one pointer size, but this is not guaranteed, and so we try
2412 not to make any assumptions. Returns zero upon failure, or the number of
2413 compilation units upon success. */
2416 load_debug_info (void * file)
2418 /* Reset the last pointer size so that we can issue correct error
2419 messages if we are displaying the contents of more than one section. */
2420 last_pointer_size = 0;
2421 warned_about_missing_comp_units = FALSE;
2423 /* If we have already tried and failed to load the .debug_info
2424 section then do not bother to repeat the task. */
2425 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2428 /* If we already have the information there is nothing else to do. */
2429 if (num_debug_info_entries > 0)
2430 return num_debug_info_entries;
2432 /* If this is a DWARF package file, load the CU and TU indexes. */
2433 load_cu_tu_indexes (file);
2435 if (load_debug_section (info, file)
2436 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2437 return num_debug_info_entries;
2438 else if (load_debug_section (info_dwo, file)
2439 && process_debug_info (&debug_displays [info_dwo].section, file,
2441 return num_debug_info_entries;
2443 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2448 display_debug_lines_raw (struct dwarf_section *section,
2449 unsigned char *data,
2452 unsigned char *start = section->start;
2454 printf (_("Raw dump of debug contents of section %s:\n\n"),
2459 DWARF2_Internal_LineInfo linfo;
2460 unsigned char *standard_opcodes;
2461 unsigned char *end_of_sequence;
2462 unsigned char *hdrptr;
2463 unsigned long hdroff;
2464 int initial_length_size;
2469 hdroff = hdrptr - start;
2471 /* Check the length of the block. */
2472 linfo.li_length = byte_get (hdrptr, 4);
2475 if (linfo.li_length == 0xffffffff)
2477 /* This section is 64-bit DWARF 3. */
2478 linfo.li_length = byte_get (hdrptr, 8);
2481 initial_length_size = 12;
2486 initial_length_size = 4;
2489 if (linfo.li_length + initial_length_size > section->size)
2492 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2497 /* Check its version number. */
2498 linfo.li_version = byte_get (hdrptr, 2);
2500 if (linfo.li_version != 2
2501 && linfo.li_version != 3
2502 && linfo.li_version != 4)
2504 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2508 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2509 hdrptr += offset_size;
2510 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2512 if (linfo.li_version >= 4)
2514 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2516 if (linfo.li_max_ops_per_insn == 0)
2518 warn (_("Invalid maximum operations per insn.\n"));
2523 linfo.li_max_ops_per_insn = 1;
2524 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2526 linfo.li_line_base = byte_get (hdrptr, 1);
2528 linfo.li_line_range = byte_get (hdrptr, 1);
2530 linfo.li_opcode_base = byte_get (hdrptr, 1);
2533 /* Sign extend the line base field. */
2534 linfo.li_line_base <<= 24;
2535 linfo.li_line_base >>= 24;
2537 printf (_(" Offset: 0x%lx\n"), hdroff);
2538 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2539 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2540 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2541 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2542 if (linfo.li_version >= 4)
2543 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2544 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2545 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2546 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2547 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2549 end_of_sequence = data + linfo.li_length + initial_length_size;
2551 reset_state_machine (linfo.li_default_is_stmt);
2553 /* Display the contents of the Opcodes table. */
2554 standard_opcodes = hdrptr;
2556 printf (_("\n Opcodes:\n"));
2558 for (i = 1; i < linfo.li_opcode_base; i++)
2559 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2561 /* Display the contents of the Directory table. */
2562 data = standard_opcodes + linfo.li_opcode_base - 1;
2565 printf (_("\n The Directory Table is empty.\n"));
2568 printf (_("\n The Directory Table:\n"));
2572 printf (" %s\n", data);
2574 data += strlen ((char *) data) + 1;
2578 /* Skip the NUL at the end of the table. */
2581 /* Display the contents of the File Name table. */
2583 printf (_("\n The File Name Table is empty.\n"));
2586 printf (_("\n The File Name Table:\n"));
2587 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2591 unsigned char *name;
2592 unsigned int bytes_read;
2594 printf (" %d\t", ++state_machine_regs.last_file_entry);
2597 data += strlen ((char *) data) + 1;
2600 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2603 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2606 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2608 printf ("%s\n", name);
2612 /* Skip the NUL at the end of the table. */
2615 /* Now display the statements. */
2616 printf (_("\n Line Number Statements:\n"));
2618 while (data < end_of_sequence)
2620 unsigned char op_code;
2621 dwarf_signed_vma adv;
2623 unsigned int bytes_read;
2627 if (op_code >= linfo.li_opcode_base)
2629 op_code -= linfo.li_opcode_base;
2630 uladv = (op_code / linfo.li_line_range);
2631 if (linfo.li_max_ops_per_insn == 1)
2633 uladv *= linfo.li_min_insn_length;
2634 state_machine_regs.address += uladv;
2635 printf (_(" Special opcode %d: "
2636 "advance Address by %s to 0x%s"),
2637 op_code, dwarf_vmatoa ("u", uladv),
2638 dwarf_vmatoa ("x", state_machine_regs.address));
2642 state_machine_regs.address
2643 += ((state_machine_regs.op_index + uladv)
2644 / linfo.li_max_ops_per_insn)
2645 * linfo.li_min_insn_length;
2646 state_machine_regs.op_index
2647 = (state_machine_regs.op_index + uladv)
2648 % linfo.li_max_ops_per_insn;
2649 printf (_(" Special opcode %d: "
2650 "advance Address by %s to 0x%s[%d]"),
2651 op_code, dwarf_vmatoa ("u", uladv),
2652 dwarf_vmatoa ("x", state_machine_regs.address),
2653 state_machine_regs.op_index);
2655 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2656 state_machine_regs.line += adv;
2657 printf (_(" and Line by %s to %d\n"),
2658 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2660 else switch (op_code)
2662 case DW_LNS_extended_op:
2663 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2667 printf (_(" Copy\n"));
2670 case DW_LNS_advance_pc:
2671 uladv = read_leb128 (data, & bytes_read, 0);
2673 if (linfo.li_max_ops_per_insn == 1)
2675 uladv *= linfo.li_min_insn_length;
2676 state_machine_regs.address += uladv;
2677 printf (_(" Advance PC by %s to 0x%s\n"),
2678 dwarf_vmatoa ("u", uladv),
2679 dwarf_vmatoa ("x", state_machine_regs.address));
2683 state_machine_regs.address
2684 += ((state_machine_regs.op_index + uladv)
2685 / linfo.li_max_ops_per_insn)
2686 * linfo.li_min_insn_length;
2687 state_machine_regs.op_index
2688 = (state_machine_regs.op_index + uladv)
2689 % linfo.li_max_ops_per_insn;
2690 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2691 dwarf_vmatoa ("u", uladv),
2692 dwarf_vmatoa ("x", state_machine_regs.address),
2693 state_machine_regs.op_index);
2697 case DW_LNS_advance_line:
2698 adv = read_sleb128 (data, & bytes_read);
2700 state_machine_regs.line += adv;
2701 printf (_(" Advance Line by %s to %d\n"),
2702 dwarf_vmatoa ("d", adv),
2703 state_machine_regs.line);
2706 case DW_LNS_set_file:
2707 adv = read_leb128 (data, & bytes_read, 0);
2709 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2710 dwarf_vmatoa ("d", adv));
2711 state_machine_regs.file = adv;
2714 case DW_LNS_set_column:
2715 uladv = read_leb128 (data, & bytes_read, 0);
2717 printf (_(" Set column to %s\n"),
2718 dwarf_vmatoa ("u", uladv));
2719 state_machine_regs.column = uladv;
2722 case DW_LNS_negate_stmt:
2723 adv = state_machine_regs.is_stmt;
2725 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2726 state_machine_regs.is_stmt = adv;
2729 case DW_LNS_set_basic_block:
2730 printf (_(" Set basic block\n"));
2731 state_machine_regs.basic_block = 1;
2734 case DW_LNS_const_add_pc:
2735 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2736 if (linfo.li_max_ops_per_insn)
2738 uladv *= linfo.li_min_insn_length;
2739 state_machine_regs.address += uladv;
2740 printf (_(" Advance PC by constant %s to 0x%s\n"),
2741 dwarf_vmatoa ("u", uladv),
2742 dwarf_vmatoa ("x", state_machine_regs.address));
2746 state_machine_regs.address
2747 += ((state_machine_regs.op_index + uladv)
2748 / linfo.li_max_ops_per_insn)
2749 * linfo.li_min_insn_length;
2750 state_machine_regs.op_index
2751 = (state_machine_regs.op_index + uladv)
2752 % linfo.li_max_ops_per_insn;
2753 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2754 dwarf_vmatoa ("u", uladv),
2755 dwarf_vmatoa ("x", state_machine_regs.address),
2756 state_machine_regs.op_index);
2760 case DW_LNS_fixed_advance_pc:
2761 uladv = byte_get (data, 2);
2763 state_machine_regs.address += uladv;
2764 state_machine_regs.op_index = 0;
2765 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2766 dwarf_vmatoa ("u", uladv),
2767 dwarf_vmatoa ("x", state_machine_regs.address));
2770 case DW_LNS_set_prologue_end:
2771 printf (_(" Set prologue_end to true\n"));
2774 case DW_LNS_set_epilogue_begin:
2775 printf (_(" Set epilogue_begin to true\n"));
2778 case DW_LNS_set_isa:
2779 uladv = read_leb128 (data, & bytes_read, 0);
2781 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2785 printf (_(" Unknown opcode %d with operands: "), op_code);
2787 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2789 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2791 i == 1 ? "" : ", ");
2806 unsigned char *name;
2807 unsigned int directory_index;
2808 unsigned int modification_date;
2809 unsigned int length;
2812 /* Output a decoded representation of the .debug_line section. */
2815 display_debug_lines_decoded (struct dwarf_section *section,
2816 unsigned char *data,
2819 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2824 /* This loop amounts to one iteration per compilation unit. */
2825 DWARF2_Internal_LineInfo linfo;
2826 unsigned char *standard_opcodes;
2827 unsigned char *end_of_sequence;
2828 unsigned char *hdrptr;
2829 int initial_length_size;
2832 File_Entry *file_table = NULL;
2833 unsigned int n_files = 0;
2834 unsigned char **directory_table = NULL;
2835 unsigned int n_directories = 0;
2839 /* Extract information from the Line Number Program Header.
2840 (section 6.2.4 in the Dwarf3 doc). */
2842 /* Get the length of this CU's line number information block. */
2843 linfo.li_length = byte_get (hdrptr, 4);
2846 if (linfo.li_length == 0xffffffff)
2848 /* This section is 64-bit DWARF 3. */
2849 linfo.li_length = byte_get (hdrptr, 8);
2852 initial_length_size = 12;
2857 initial_length_size = 4;
2860 if (linfo.li_length + initial_length_size > section->size)
2862 warn (_("The line info appears to be corrupt - "
2863 "the section is too small\n"));
2867 /* Get this CU's Line Number Block version number. */
2868 linfo.li_version = byte_get (hdrptr, 2);
2870 if (linfo.li_version != 2
2871 && linfo.li_version != 3
2872 && linfo.li_version != 4)
2874 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2879 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2880 hdrptr += offset_size;
2881 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2883 if (linfo.li_version >= 4)
2885 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2887 if (linfo.li_max_ops_per_insn == 0)
2889 warn (_("Invalid maximum operations per insn.\n"));
2894 linfo.li_max_ops_per_insn = 1;
2895 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2897 linfo.li_line_base = byte_get (hdrptr, 1);
2899 linfo.li_line_range = byte_get (hdrptr, 1);
2901 linfo.li_opcode_base = byte_get (hdrptr, 1);
2904 /* Sign extend the line base field. */
2905 linfo.li_line_base <<= 24;
2906 linfo.li_line_base >>= 24;
2908 /* Find the end of this CU's Line Number Information Block. */
2909 end_of_sequence = data + linfo.li_length + initial_length_size;
2911 reset_state_machine (linfo.li_default_is_stmt);
2913 /* Save a pointer to the contents of the Opcodes table. */
2914 standard_opcodes = hdrptr;
2916 /* Traverse the Directory table just to count entries. */
2917 data = standard_opcodes + linfo.li_opcode_base - 1;
2920 unsigned char *ptr_directory_table = data;
2924 data += strlen ((char *) data) + 1;
2928 /* Go through the directory table again to save the directories. */
2929 directory_table = (unsigned char **)
2930 xmalloc (n_directories * sizeof (unsigned char *));
2933 while (*ptr_directory_table != 0)
2935 directory_table[i] = ptr_directory_table;
2936 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2940 /* Skip the NUL at the end of the table. */
2943 /* Traverse the File Name table just to count the entries. */
2946 unsigned char *ptr_file_name_table = data;
2950 unsigned int bytes_read;
2952 /* Skip Name, directory index, last modification time and length
2954 data += strlen ((char *) data) + 1;
2955 read_leb128 (data, & bytes_read, 0);
2957 read_leb128 (data, & bytes_read, 0);
2959 read_leb128 (data, & bytes_read, 0);
2965 /* Go through the file table again to save the strings. */
2966 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2969 while (*ptr_file_name_table != 0)
2971 unsigned int bytes_read;
2973 file_table[i].name = ptr_file_name_table;
2974 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2976 /* We are not interested in directory, time or size. */
2977 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2979 ptr_file_name_table += bytes_read;
2980 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2982 ptr_file_name_table += bytes_read;
2983 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2984 ptr_file_name_table += bytes_read;
2989 /* Print the Compilation Unit's name and a header. */
2990 if (directory_table == NULL)
2992 printf (_("CU: %s:\n"), file_table[0].name);
2993 printf (_("File name Line number Starting address\n"));
2997 unsigned int ix = file_table[0].directory_index;
2998 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
2999 if (do_wide || strlen (directory) < 76)
3000 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3002 printf ("%s:\n", file_table[0].name);
3004 printf (_("File name Line number Starting address\n"));
3008 /* Skip the NUL at the end of the table. */
3011 /* This loop iterates through the Dwarf Line Number Program. */
3012 while (data < end_of_sequence)
3014 unsigned char op_code;
3016 unsigned long int uladv;
3017 unsigned int bytes_read;
3018 int is_special_opcode = 0;
3022 if (op_code >= linfo.li_opcode_base)
3024 op_code -= linfo.li_opcode_base;
3025 uladv = (op_code / linfo.li_line_range);
3026 if (linfo.li_max_ops_per_insn == 1)
3028 uladv *= linfo.li_min_insn_length;
3029 state_machine_regs.address += uladv;
3033 state_machine_regs.address
3034 += ((state_machine_regs.op_index + uladv)
3035 / linfo.li_max_ops_per_insn)
3036 * linfo.li_min_insn_length;
3037 state_machine_regs.op_index
3038 = (state_machine_regs.op_index + uladv)
3039 % linfo.li_max_ops_per_insn;
3042 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3043 state_machine_regs.line += adv;
3044 is_special_opcode = 1;
3046 else switch (op_code)
3048 case DW_LNS_extended_op:
3050 unsigned int ext_op_code_len;
3051 unsigned char ext_op_code;
3052 unsigned char *op_code_data = data;
3054 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
3055 op_code_data += bytes_read;
3057 if (ext_op_code_len == 0)
3059 warn (_("badly formed extended line op encountered!\n"));
3062 ext_op_code_len += bytes_read;
3063 ext_op_code = *op_code_data++;
3065 switch (ext_op_code)
3067 case DW_LNE_end_sequence:
3068 reset_state_machine (linfo.li_default_is_stmt);
3070 case DW_LNE_set_address:
3071 state_machine_regs.address =
3072 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
3073 state_machine_regs.op_index = 0;
3075 case DW_LNE_define_file:
3077 file_table = (File_Entry *) xrealloc
3078 (file_table, (n_files + 1) * sizeof (File_Entry));
3080 ++state_machine_regs.last_file_entry;
3081 /* Source file name. */
3082 file_table[n_files].name = op_code_data;
3083 op_code_data += strlen ((char *) op_code_data) + 1;
3084 /* Directory index. */
3085 file_table[n_files].directory_index =
3086 read_leb128 (op_code_data, & bytes_read, 0);
3087 op_code_data += bytes_read;
3088 /* Last modification time. */
3089 file_table[n_files].modification_date =
3090 read_leb128 (op_code_data, & bytes_read, 0);
3091 op_code_data += bytes_read;
3093 file_table[n_files].length =
3094 read_leb128 (op_code_data, & bytes_read, 0);
3099 case DW_LNE_set_discriminator:
3100 case DW_LNE_HP_set_sequence:
3101 /* Simply ignored. */
3105 printf (_("UNKNOWN (%u): length %d\n"),
3106 ext_op_code, ext_op_code_len - bytes_read);
3109 data += ext_op_code_len;
3115 case DW_LNS_advance_pc:
3116 uladv = read_leb128 (data, & bytes_read, 0);
3118 if (linfo.li_max_ops_per_insn == 1)
3120 uladv *= linfo.li_min_insn_length;
3121 state_machine_regs.address += uladv;
3125 state_machine_regs.address
3126 += ((state_machine_regs.op_index + uladv)
3127 / linfo.li_max_ops_per_insn)
3128 * linfo.li_min_insn_length;
3129 state_machine_regs.op_index
3130 = (state_machine_regs.op_index + uladv)
3131 % linfo.li_max_ops_per_insn;
3135 case DW_LNS_advance_line:
3136 adv = read_sleb128 (data, & bytes_read);
3138 state_machine_regs.line += adv;
3141 case DW_LNS_set_file:
3142 adv = read_leb128 (data, & bytes_read, 0);
3144 state_machine_regs.file = adv;
3145 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3147 /* If directory index is 0, that means current directory. */
3148 printf ("\n./%s:[++]\n",
3149 file_table[state_machine_regs.file - 1].name);
3153 /* The directory index starts counting at 1. */
3154 printf ("\n%s/%s:\n",
3155 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3156 file_table[state_machine_regs.file - 1].name);
3160 case DW_LNS_set_column:
3161 uladv = read_leb128 (data, & bytes_read, 0);
3163 state_machine_regs.column = uladv;
3166 case DW_LNS_negate_stmt:
3167 adv = state_machine_regs.is_stmt;
3169 state_machine_regs.is_stmt = adv;
3172 case DW_LNS_set_basic_block:
3173 state_machine_regs.basic_block = 1;
3176 case DW_LNS_const_add_pc:
3177 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3178 if (linfo.li_max_ops_per_insn == 1)
3180 uladv *= linfo.li_min_insn_length;
3181 state_machine_regs.address += uladv;
3185 state_machine_regs.address
3186 += ((state_machine_regs.op_index + uladv)
3187 / linfo.li_max_ops_per_insn)
3188 * linfo.li_min_insn_length;
3189 state_machine_regs.op_index
3190 = (state_machine_regs.op_index + uladv)
3191 % linfo.li_max_ops_per_insn;
3195 case DW_LNS_fixed_advance_pc:
3196 uladv = byte_get (data, 2);
3198 state_machine_regs.address += uladv;
3199 state_machine_regs.op_index = 0;
3202 case DW_LNS_set_prologue_end:
3205 case DW_LNS_set_epilogue_begin:
3208 case DW_LNS_set_isa:
3209 uladv = read_leb128 (data, & bytes_read, 0);
3211 printf (_(" Set ISA to %lu\n"), uladv);
3215 printf (_(" Unknown opcode %d with operands: "), op_code);
3217 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3219 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3221 i == 1 ? "" : ", ");
3228 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3229 to the DWARF address/line matrix. */
3230 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3231 || (op_code == DW_LNS_copy))
3233 const unsigned int MAX_FILENAME_LENGTH = 35;
3234 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3235 char *newFileName = NULL;
3236 size_t fileNameLength = strlen (fileName);
3238 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3240 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3241 /* Truncate file name */
3242 strncpy (newFileName,
3243 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3244 MAX_FILENAME_LENGTH + 1);
3248 newFileName = (char *) xmalloc (fileNameLength + 1);
3249 strncpy (newFileName, fileName, fileNameLength + 1);
3252 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3254 if (linfo.li_max_ops_per_insn == 1)
3255 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3256 newFileName, state_machine_regs.line,
3257 state_machine_regs.address);
3259 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3260 newFileName, state_machine_regs.line,
3261 state_machine_regs.address,
3262 state_machine_regs.op_index);
3266 if (linfo.li_max_ops_per_insn == 1)
3267 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3268 newFileName, state_machine_regs.line,
3269 state_machine_regs.address);
3271 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3272 newFileName, state_machine_regs.line,
3273 state_machine_regs.address,
3274 state_machine_regs.op_index);
3277 if (op_code == DW_LNE_end_sequence)
3285 free (directory_table);
3286 directory_table = NULL;
3294 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3296 unsigned char *data = section->start;
3297 unsigned char *end = data + section->size;
3299 int retValDecoded = 1;
3301 if (do_debug_lines == 0)
3302 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3304 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3305 retValRaw = display_debug_lines_raw (section, data, end);
3307 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3308 retValDecoded = display_debug_lines_decoded (section, data, end);
3310 if (!retValRaw || !retValDecoded)
3317 find_debug_info_for_offset (unsigned long offset)
3321 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3324 for (i = 0; i < num_debug_info_entries; i++)
3325 if (debug_information[i].cu_offset == offset)
3326 return debug_information + i;
3332 display_debug_pubnames (struct dwarf_section *section,
3333 void *file ATTRIBUTE_UNUSED)
3335 DWARF2_Internal_PubNames names;
3336 unsigned char *start = section->start;
3337 unsigned char *end = start + section->size;
3339 /* It does not matter if this load fails,
3340 we test for that later on. */
3341 load_debug_info (file);
3343 printf (_("Contents of the %s section:\n\n"), section->name);
3347 unsigned char *data;
3348 unsigned long offset;
3349 int offset_size, initial_length_size;
3353 names.pn_length = byte_get (data, 4);
3355 if (names.pn_length == 0xffffffff)
3357 names.pn_length = byte_get (data, 8);
3360 initial_length_size = 12;
3365 initial_length_size = 4;
3368 names.pn_version = byte_get (data, 2);
3371 names.pn_offset = byte_get (data, offset_size);
3372 data += offset_size;
3374 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3375 && num_debug_info_entries > 0
3376 && find_debug_info_for_offset (names.pn_offset) == NULL)
3377 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3378 (unsigned long) names.pn_offset, section->name);
3380 names.pn_size = byte_get (data, offset_size);
3381 data += offset_size;
3383 start += names.pn_length + initial_length_size;
3385 if (names.pn_version != 2 && names.pn_version != 3)
3387 static int warned = 0;
3391 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3398 printf (_(" Length: %ld\n"),
3399 (long) names.pn_length);
3400 printf (_(" Version: %d\n"),
3402 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3403 (unsigned long) names.pn_offset);
3404 printf (_(" Size of area in .debug_info section: %ld\n"),
3405 (long) names.pn_size);
3407 printf (_("\n Offset\tName\n"));
3411 offset = byte_get (data, offset_size);
3415 data += offset_size;
3416 printf (" %-6lx\t%s\n", offset, data);
3417 data += strlen ((char *) data) + 1;
3420 while (offset != 0);
3428 display_debug_macinfo (struct dwarf_section *section,
3429 void *file ATTRIBUTE_UNUSED)
3431 unsigned char *start = section->start;
3432 unsigned char *end = start + section->size;
3433 unsigned char *curr = start;
3434 unsigned int bytes_read;
3435 enum dwarf_macinfo_record_type op;
3437 printf (_("Contents of the %s section:\n\n"), section->name);
3441 unsigned int lineno;
3444 op = (enum dwarf_macinfo_record_type) *curr;
3449 case DW_MACINFO_start_file:
3451 unsigned int filenum;
3453 lineno = read_leb128 (curr, & bytes_read, 0);
3455 filenum = read_leb128 (curr, & bytes_read, 0);
3458 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3463 case DW_MACINFO_end_file:
3464 printf (_(" DW_MACINFO_end_file\n"));
3467 case DW_MACINFO_define:
3468 lineno = read_leb128 (curr, & bytes_read, 0);
3470 string = (char *) curr;
3471 curr += strlen (string) + 1;
3472 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3476 case DW_MACINFO_undef:
3477 lineno = read_leb128 (curr, & bytes_read, 0);
3479 string = (char *) curr;
3480 curr += strlen (string) + 1;
3481 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3485 case DW_MACINFO_vendor_ext:
3487 unsigned int constant;
3489 constant = read_leb128 (curr, & bytes_read, 0);
3491 string = (char *) curr;
3492 curr += strlen (string) + 1;
3493 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3503 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3504 filename and dirname corresponding to file name table entry with index
3505 FILEIDX. Return NULL on failure. */
3507 static unsigned char *
3508 get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
3509 unsigned char **dir_name)
3511 struct dwarf_section *section = &debug_displays [line].section;
3512 unsigned char *hdrptr, *dirtable, *file_name;
3513 unsigned int offset_size, initial_length_size;
3514 unsigned int version, opcode_base, bytes_read;
3515 dwarf_vma length, diridx;
3518 if (section->start == NULL
3519 || line_offset >= section->size
3523 hdrptr = section->start + line_offset;
3524 length = byte_get (hdrptr, 4);
3526 if (length == 0xffffffff)
3528 /* This section is 64-bit DWARF 3. */
3529 length = byte_get (hdrptr, 8);
3532 initial_length_size = 12;
3537 initial_length_size = 4;
3539 if (length + initial_length_size > section->size)
3541 version = byte_get (hdrptr, 2);
3543 if (version != 2 && version != 3 && version != 4)
3545 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3547 hdrptr++; /* Skip max_ops_per_insn. */
3548 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3549 opcode_base = byte_get (hdrptr, 1);
3550 if (opcode_base == 0)
3553 hdrptr += opcode_base - 1;
3555 /* Skip over dirname table. */
3556 while (*hdrptr != '\0')
3557 hdrptr += strlen ((char *) hdrptr) + 1;
3558 hdrptr++; /* Skip the NUL at the end of the table. */
3559 /* Now skip over preceding filename table entries. */
3560 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3562 hdrptr += strlen ((char *) hdrptr) + 1;
3563 read_leb128 (hdrptr, &bytes_read, 0);
3564 hdrptr += bytes_read;
3565 read_leb128 (hdrptr, &bytes_read, 0);
3566 hdrptr += bytes_read;
3567 read_leb128 (hdrptr, &bytes_read, 0);
3568 hdrptr += bytes_read;
3570 if (*hdrptr == '\0')
3573 hdrptr += strlen ((char *) hdrptr) + 1;
3574 diridx = read_leb128 (hdrptr, &bytes_read, 0);
3577 for (; *dirtable != '\0' && diridx > 1; diridx--)
3578 dirtable += strlen ((char *) dirtable) + 1;
3579 if (*dirtable == '\0')
3581 *dir_name = dirtable;
3586 display_debug_macro (struct dwarf_section *section,
3589 unsigned char *start = section->start;
3590 unsigned char *end = start + section->size;
3591 unsigned char *curr = start;
3592 unsigned char *extended_op_buf[256];
3593 unsigned int bytes_read;
3595 load_debug_section (str, file);
3596 load_debug_section (line, file);
3598 printf (_("Contents of the %s section:\n\n"), section->name);
3602 unsigned int lineno, version, flags;
3603 unsigned int offset_size = 4;
3605 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3606 unsigned char **extended_ops = NULL;
3608 version = byte_get (curr, 2);
3613 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3618 flags = byte_get (curr++, 1);
3621 printf (_(" Offset: 0x%lx\n"),
3622 (unsigned long) sec_offset);
3623 printf (_(" Version: %d\n"), version);
3624 printf (_(" Offset size: %d\n"), offset_size);
3627 line_offset = byte_get (curr, offset_size);
3628 curr += offset_size;
3629 printf (_(" Offset into .debug_line: 0x%lx\n"),
3630 (unsigned long) line_offset);
3634 unsigned int i, count = byte_get (curr++, 1), op;
3636 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3637 extended_ops = extended_op_buf;
3640 printf (_(" Extension opcode arguments:\n"));
3641 for (i = 0; i < count; i++)
3643 op = byte_get (curr++, 1);
3644 extended_ops[op] = curr;
3645 nargs = read_leb128 (curr, &bytes_read, 0);
3648 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3651 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3652 for (n = 0; n < nargs; n++)
3654 unsigned int form = byte_get (curr++, 1);
3655 printf ("%s%s", get_FORM_name (form),
3656 n == nargs - 1 ? "\n" : ", ");
3666 case DW_FORM_block1:
3667 case DW_FORM_block2:
3668 case DW_FORM_block4:
3670 case DW_FORM_string:
3672 case DW_FORM_sec_offset:
3675 error (_("Invalid extension opcode form %s\n"),
3676 get_FORM_name (form));
3692 error (_(".debug_macro section not zero terminated\n"));
3696 op = byte_get (curr++, 1);
3702 case DW_MACRO_GNU_start_file:
3704 unsigned int filenum;
3705 unsigned char *file_name = NULL, *dir_name = NULL;
3707 lineno = read_leb128 (curr, &bytes_read, 0);
3709 filenum = read_leb128 (curr, &bytes_read, 0);
3712 if ((flags & 2) == 0)
3713 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3716 = get_line_filename_and_dirname (line_offset, filenum,
3718 if (file_name == NULL)
3719 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3722 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3724 dir_name != NULL ? (const char *) dir_name : "",
3725 dir_name != NULL ? "/" : "", file_name);
3729 case DW_MACRO_GNU_end_file:
3730 printf (_(" DW_MACRO_GNU_end_file\n"));
3733 case DW_MACRO_GNU_define:
3734 lineno = read_leb128 (curr, &bytes_read, 0);
3736 string = (char *) curr;
3737 curr += strlen (string) + 1;
3738 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3742 case DW_MACRO_GNU_undef:
3743 lineno = read_leb128 (curr, &bytes_read, 0);
3745 string = (char *) curr;
3746 curr += strlen (string) + 1;
3747 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3751 case DW_MACRO_GNU_define_indirect:
3752 lineno = read_leb128 (curr, &bytes_read, 0);
3754 offset = byte_get (curr, offset_size);
3755 curr += offset_size;
3756 string = fetch_indirect_string (offset);
3757 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3761 case DW_MACRO_GNU_undef_indirect:
3762 lineno = read_leb128 (curr, &bytes_read, 0);
3764 offset = byte_get (curr, offset_size);
3765 curr += offset_size;
3766 string = fetch_indirect_string (offset);
3767 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3771 case DW_MACRO_GNU_transparent_include:
3772 offset = byte_get (curr, offset_size);
3773 curr += offset_size;
3774 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3775 (unsigned long) offset);
3778 case DW_MACRO_GNU_define_indirect_alt:
3779 lineno = read_leb128 (curr, &bytes_read, 0);
3781 offset = byte_get (curr, offset_size);
3782 curr += offset_size;
3783 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3784 lineno, (unsigned long) offset);
3787 case DW_MACRO_GNU_undef_indirect_alt:
3788 lineno = read_leb128 (curr, &bytes_read, 0);
3790 offset = byte_get (curr, offset_size);
3791 curr += offset_size;
3792 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
3793 lineno, (unsigned long) offset);
3796 case DW_MACRO_GNU_transparent_include_alt:
3797 offset = byte_get (curr, offset_size);
3798 curr += offset_size;
3799 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
3800 (unsigned long) offset);
3804 if (extended_ops == NULL || extended_ops[op] == NULL)
3806 error (_(" Unknown macro opcode %02x seen\n"), op);
3811 /* Skip over unhandled opcodes. */
3813 unsigned char *desc = extended_ops[op];
3814 nargs = read_leb128 (desc, &bytes_read, 0);
3818 printf (_(" DW_MACRO_GNU_%02x\n"), op);
3821 printf (_(" DW_MACRO_GNU_%02x -"), op);
3822 for (n = 0; n < nargs; n++)
3825 = read_and_display_attr_value (0, byte_get (desc++, 1),
3826 curr, 0, 0, offset_size,
3827 version, NULL, 0, NULL,
3845 display_debug_abbrev (struct dwarf_section *section,
3846 void *file ATTRIBUTE_UNUSED)
3848 abbrev_entry *entry;
3849 unsigned char *start = section->start;
3850 unsigned char *end = start + section->size;
3852 printf (_("Contents of the %s section:\n\n"), section->name);
3856 unsigned char *last;
3861 start = process_abbrev_section (start, end);
3863 if (first_abbrev == NULL)
3866 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
3868 for (entry = first_abbrev; entry; entry = entry->next)
3872 printf (" %ld %s [%s]\n",
3874 get_TAG_name (entry->tag),
3875 entry->children ? _("has children") : _("no children"));
3877 for (attr = entry->first_attr; attr; attr = attr->next)
3878 printf (" %-18s %s\n",
3879 get_AT_name (attr->attribute),
3880 get_FORM_name (attr->form));
3890 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
3893 display_loc_list (struct dwarf_section *section,
3894 unsigned char **start_ptr,
3895 int debug_info_entry,
3896 unsigned long offset,
3897 unsigned long base_address,
3900 unsigned char *start = *start_ptr;
3901 unsigned char *section_end = section->start + section->size;
3902 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
3903 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
3904 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
3905 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
3909 unsigned short length;
3910 int need_frame_base;
3914 if (start + 2 * pointer_size > section_end)
3916 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3921 printf (" %8.8lx ", offset + (start - *start_ptr));
3923 /* Note: we use sign extension here in order to be sure that we can detect
3924 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
3925 address will not affect the values that we display since we always show
3926 hex values, and always the bottom 32-bits. */
3927 begin = byte_get_signed (start, pointer_size);
3928 start += pointer_size;
3929 end = byte_get_signed (start, pointer_size);
3930 start += pointer_size;
3932 if (begin == 0 && end == 0)
3934 printf (_("<End of list>\n"));
3938 /* Check base address specifiers. */
3939 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3942 print_dwarf_vma (begin, pointer_size);
3943 print_dwarf_vma (end, pointer_size);
3944 printf (_("(base address)\n"));
3948 if (start + 2 > section_end)
3950 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3955 length = byte_get (start, 2);
3958 if (start + length > section_end)
3960 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3965 print_dwarf_vma (begin + base_address, pointer_size);
3966 print_dwarf_vma (end + base_address, pointer_size);
3969 need_frame_base = decode_location_expression (start,
3974 cu_offset, section);
3977 if (need_frame_base && !has_frame_base)
3978 printf (_(" [without DW_AT_frame_base]"));
3981 fputs (_(" (start == end)"), stdout);
3982 else if (begin > end)
3983 fputs (_(" (start > end)"), stdout);
3993 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
3994 right-adjusted in a field of length LEN, and followed by a space. */
3997 print_addr_index (unsigned int idx, unsigned int len)
3999 static char buf[15];
4000 snprintf (buf, sizeof (buf), "[%d]", idx);
4001 printf ("%*s ", len, buf);
4004 /* Display a location list from a .dwo section. It uses address indexes rather
4005 than embedded addresses. This code closely follows display_loc_list, but the
4006 two are sufficiently different that combining things is very ugly. */
4009 display_loc_list_dwo (struct dwarf_section *section,
4010 unsigned char **start_ptr,
4011 int debug_info_entry,
4012 unsigned long offset,
4015 unsigned char *start = *start_ptr;
4016 unsigned char *section_end = section->start + section->size;
4017 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
4018 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
4019 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
4020 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
4022 unsigned short length;
4023 int need_frame_base;
4025 unsigned int bytes_read;
4029 printf (" %8.8lx ", offset + (start - *start_ptr));
4031 if (start >= section_end)
4033 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4038 entry_type = byte_get (start, 1);
4042 case 0: /* A terminating entry. */
4044 printf (_("<End of list>\n"));
4046 case 1: /* A base-address entry. */
4047 idx = read_leb128 (start, &bytes_read, 0);
4048 start += bytes_read;
4049 print_addr_index (idx, 8);
4051 printf (_("(base address selection entry)\n"));
4053 case 2: /* A start/end entry. */
4054 idx = read_leb128 (start, &bytes_read, 0);
4055 start += bytes_read;
4056 print_addr_index (idx, 8);
4057 idx = read_leb128 (start, &bytes_read, 0);
4058 start += bytes_read;
4059 print_addr_index (idx, 8);
4061 case 3: /* A start/length entry. */
4062 idx = read_leb128 (start, &bytes_read, 0);
4063 start += bytes_read;
4064 print_addr_index (idx, 8);
4065 idx = byte_get (start, 4);
4067 printf ("%08x ", idx);
4069 case 4: /* An offset pair entry. */
4070 idx = byte_get (start, 4);
4072 printf ("%08x ", idx);
4073 idx = byte_get (start, 4);
4075 printf ("%08x ", idx);
4078 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
4083 if (start + 2 > section_end)
4085 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4090 length = byte_get (start, 2);
4093 if (start + length > section_end)
4095 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4101 need_frame_base = decode_location_expression (start,
4106 cu_offset, section);
4109 if (need_frame_base && !has_frame_base)
4110 printf (_(" [without DW_AT_frame_base]"));
4120 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4122 static dwarf_vma *loc_offsets;
4125 loc_offsets_compar (const void *ap, const void *bp)
4127 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
4128 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
4130 return (a > b) - (b > a);
4134 display_debug_loc (struct dwarf_section *section, void *file)
4136 unsigned char *start = section->start;
4137 unsigned long bytes;
4138 unsigned char *section_begin = start;
4139 unsigned int num_loc_list = 0;
4140 unsigned long last_offset = 0;
4141 unsigned int first = 0;
4145 int seen_first_offset = 0;
4146 int locs_sorted = 1;
4147 unsigned char *next;
4148 unsigned int *array = NULL;
4149 const char *suffix = strrchr (section->name, '.');
4152 if (suffix && strcmp (suffix, ".dwo") == 0)
4155 bytes = section->size;
4159 printf (_("\nThe %s section is empty.\n"), section->name);
4163 if (load_debug_info (file) == 0)
4165 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4170 /* Check the order of location list in .debug_info section. If
4171 offsets of location lists are in the ascending order, we can
4172 use `debug_information' directly. */
4173 for (i = 0; i < num_debug_info_entries; i++)
4177 num = debug_information [i].num_loc_offsets;
4178 if (num > num_loc_list)
4181 /* Check if we can use `debug_information' directly. */
4182 if (locs_sorted && num != 0)
4184 if (!seen_first_offset)
4186 /* This is the first location list. */
4187 last_offset = debug_information [i].loc_offsets [0];
4189 seen_first_offset = 1;
4195 for (; j < num; j++)
4198 debug_information [i].loc_offsets [j])
4203 last_offset = debug_information [i].loc_offsets [j];
4208 if (!seen_first_offset)
4209 error (_("No location lists in .debug_info section!\n"));
4211 /* DWARF sections under Mach-O have non-zero addresses. */
4212 if (debug_information [first].num_loc_offsets > 0
4213 && debug_information [first].loc_offsets [0] != section->address)
4214 warn (_("Location lists in %s section start at 0x%s\n"),
4216 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4219 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4220 printf (_("Contents of the %s section:\n\n"), section->name);
4221 printf (_(" Offset Begin End Expression\n"));
4223 seen_first_offset = 0;
4224 for (i = first; i < num_debug_info_entries; i++)
4226 unsigned long offset;
4227 unsigned long base_address;
4232 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4234 loc_offsets = debug_information [i].loc_offsets;
4235 qsort (array, debug_information [i].num_loc_offsets,
4236 sizeof (*array), loc_offsets_compar);
4239 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4241 j = locs_sorted ? k : array[k];
4243 && debug_information [i].loc_offsets [locs_sorted
4244 ? k - 1 : array [k - 1]]
4245 == debug_information [i].loc_offsets [j])
4247 has_frame_base = debug_information [i].have_frame_base [j];
4248 /* DWARF sections under Mach-O have non-zero addresses. */
4249 offset = debug_information [i].loc_offsets [j] - section->address;
4250 next = section_begin + offset;
4251 base_address = debug_information [i].base_address;
4253 if (!seen_first_offset)
4254 seen_first_offset = 1;
4258 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4259 (unsigned long) (start - section_begin),
4260 (unsigned long) (next - section_begin));
4261 else if (start > next)
4262 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4263 (unsigned long) (start - section_begin),
4264 (unsigned long) (next - section_begin));
4268 if (offset >= bytes)
4270 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4276 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4278 display_loc_list (section, &start, i, offset, base_address,
4283 if (start < section->start + section->size)
4284 warn (_("There are %ld unused bytes at the end of section %s\n"),
4285 (long) (section->start + section->size - start), section->name);
4292 display_debug_str (struct dwarf_section *section,
4293 void *file ATTRIBUTE_UNUSED)
4295 unsigned char *start = section->start;
4296 unsigned long bytes = section->size;
4297 dwarf_vma addr = section->address;
4301 printf (_("\nThe %s section is empty.\n"), section->name);
4305 printf (_("Contents of the %s section:\n\n"), section->name);
4313 lbytes = (bytes > 16 ? 16 : bytes);
4315 printf (" 0x%8.8lx ", (unsigned long) addr);
4317 for (j = 0; j < 16; j++)
4320 printf ("%2.2x", start[j]);
4328 for (j = 0; j < lbytes; j++)
4331 if (k >= ' ' && k < 0x80)
4350 display_debug_info (struct dwarf_section *section, void *file)
4352 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4356 display_debug_types (struct dwarf_section *section, void *file)
4358 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4362 display_trace_info (struct dwarf_section *section, void *file)
4364 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4368 display_debug_aranges (struct dwarf_section *section,
4369 void *file ATTRIBUTE_UNUSED)
4371 unsigned char *start = section->start;
4372 unsigned char *end = start + section->size;
4374 printf (_("Contents of the %s section:\n\n"), section->name);
4376 /* It does not matter if this load fails,
4377 we test for that later on. */
4378 load_debug_info (file);
4382 unsigned char *hdrptr;
4383 DWARF2_Internal_ARange arange;
4384 unsigned char *addr_ranges;
4387 unsigned char address_size;
4390 int initial_length_size;
4394 arange.ar_length = byte_get (hdrptr, 4);
4397 if (arange.ar_length == 0xffffffff)
4399 arange.ar_length = byte_get (hdrptr, 8);
4402 initial_length_size = 12;
4407 initial_length_size = 4;
4410 arange.ar_version = byte_get (hdrptr, 2);
4413 arange.ar_info_offset = byte_get (hdrptr, offset_size);
4414 hdrptr += offset_size;
4416 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4417 && num_debug_info_entries > 0
4418 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4419 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4420 (unsigned long) arange.ar_info_offset, section->name);
4422 arange.ar_pointer_size = byte_get (hdrptr, 1);
4425 arange.ar_segment_size = byte_get (hdrptr, 1);
4428 if (arange.ar_version != 2 && arange.ar_version != 3)
4430 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4434 printf (_(" Length: %ld\n"),
4435 (long) arange.ar_length);
4436 printf (_(" Version: %d\n"), arange.ar_version);
4437 printf (_(" Offset into .debug_info: 0x%lx\n"),
4438 (unsigned long) arange.ar_info_offset);
4439 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4440 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4442 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4444 if (address_size == 0)
4446 error (_("Invalid address size in %s section!\n"),
4451 /* The DWARF spec does not require that the address size be a power
4452 of two, but we do. This will have to change if we ever encounter
4453 an uneven architecture. */
4454 if ((address_size & (address_size - 1)) != 0)
4456 warn (_("Pointer size + Segment size is not a power of two.\n"));
4460 if (address_size > 4)
4461 printf (_("\n Address Length\n"));
4463 printf (_("\n Address Length\n"));
4465 addr_ranges = hdrptr;
4467 /* Must pad to an alignment boundary that is twice the address size. */
4468 excess = (hdrptr - start) % (2 * address_size);
4470 addr_ranges += (2 * address_size) - excess;
4472 start += arange.ar_length + initial_length_size;
4474 while (addr_ranges + 2 * address_size <= start)
4476 address = byte_get (addr_ranges, address_size);
4478 addr_ranges += address_size;
4480 length = byte_get (addr_ranges, address_size);
4482 addr_ranges += address_size;
4485 print_dwarf_vma (address, address_size);
4486 print_dwarf_vma (length, address_size);
4496 /* Comparison function for qsort. */
4498 comp_addr_base (const void * v0, const void * v1)
4500 debug_info * info0 = (debug_info *) v0;
4501 debug_info * info1 = (debug_info *) v1;
4502 return info0->addr_base - info1->addr_base;
4505 /* Display the debug_addr section. */
4507 display_debug_addr (struct dwarf_section *section,
4510 debug_info **debug_addr_info;
4511 unsigned char *entry;
4516 if (section->size == 0)
4518 printf (_("\nThe %s section is empty.\n"), section->name);
4522 if (load_debug_info (file) == 0)
4524 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4529 printf (_("Contents of the %s section:\n\n"), section->name);
4531 debug_addr_info = (debug_info **) xmalloc ((num_debug_info_entries + 1)
4532 * sizeof (debug_info *));
4535 for (i = 0; i < num_debug_info_entries; i++)
4537 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4538 debug_addr_info [count++] = &debug_information [i];
4541 /* Add a sentinel to make iteration convenient. */
4542 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4543 debug_addr_info [count]->addr_base = section->size;
4545 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4546 for (i = 0; i < count; i++)
4549 unsigned int address_size = debug_addr_info [i]->pointer_size;
4551 printf (_(" For compilation unit at offset 0x%s:\n"),
4552 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4554 printf (_("\tIndex\tAddress\n"));
4555 entry = section->start + debug_addr_info [i]->addr_base;
4556 end = section->start + debug_addr_info [i + 1]->addr_base;
4560 dwarf_vma base = byte_get (entry, address_size);
4561 printf (_("\t%d:\t"), idx);
4562 print_dwarf_vma (base, address_size);
4564 entry += address_size;
4570 free (debug_addr_info);
4574 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4576 display_debug_str_offsets (struct dwarf_section *section,
4577 void *file ATTRIBUTE_UNUSED)
4579 if (section->size == 0)
4581 printf (_("\nThe %s section is empty.\n"), section->name);
4584 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4585 what the offset size is for this section. */
4589 /* Each debug_information[x].range_lists[y] gets this representation for
4590 sorting purposes. */
4594 /* The debug_information[x].range_lists[y] value. */
4595 unsigned long ranges_offset;
4597 /* Original debug_information to find parameters of the data. */
4598 debug_info *debug_info_p;
4601 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4604 range_entry_compar (const void *ap, const void *bp)
4606 const struct range_entry *a_re = (const struct range_entry *) ap;
4607 const struct range_entry *b_re = (const struct range_entry *) bp;
4608 const unsigned long a = a_re->ranges_offset;
4609 const unsigned long b = b_re->ranges_offset;
4611 return (a > b) - (b > a);
4615 display_debug_ranges (struct dwarf_section *section,
4616 void *file ATTRIBUTE_UNUSED)
4618 unsigned char *start = section->start;
4619 unsigned char *last_start = start;
4620 unsigned long bytes;
4621 unsigned char *section_begin = start;
4622 unsigned int num_range_list, i;
4623 struct range_entry *range_entries, *range_entry_fill;
4625 bytes = section->size;
4629 printf (_("\nThe %s section is empty.\n"), section->name);
4633 if (load_debug_info (file) == 0)
4635 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4641 for (i = 0; i < num_debug_info_entries; i++)
4642 num_range_list += debug_information [i].num_range_lists;
4644 if (num_range_list == 0)
4646 /* This can happen when the file was compiled with -gsplit-debug
4647 which removes references to range lists from the primary .o file. */
4648 printf (_("No range lists in .debug_info section.\n"));
4652 range_entries = (struct range_entry *)
4653 xmalloc (sizeof (*range_entries) * num_range_list);
4654 range_entry_fill = range_entries;
4656 for (i = 0; i < num_debug_info_entries; i++)
4658 debug_info *debug_info_p = &debug_information[i];
4661 for (j = 0; j < debug_info_p->num_range_lists; j++)
4663 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4664 range_entry_fill->debug_info_p = debug_info_p;
4669 qsort (range_entries, num_range_list, sizeof (*range_entries),
4670 range_entry_compar);
4672 /* DWARF sections under Mach-O have non-zero addresses. */
4673 if (dwarf_check != 0 && range_entries[0].ranges_offset != section->address)
4674 warn (_("Range lists in %s section start at 0x%lx\n"),
4675 section->name, range_entries[0].ranges_offset);
4677 printf (_("Contents of the %s section:\n\n"), section->name);
4678 printf (_(" Offset Begin End\n"));
4680 for (i = 0; i < num_range_list; i++)
4682 struct range_entry *range_entry = &range_entries[i];
4683 debug_info *debug_info_p = range_entry->debug_info_p;
4684 unsigned int pointer_size;
4685 unsigned long offset;
4686 unsigned char *next;
4687 unsigned long base_address;
4689 pointer_size = debug_info_p->pointer_size;
4691 /* DWARF sections under Mach-O have non-zero addresses. */
4692 offset = range_entry->ranges_offset - section->address;
4693 next = section_begin + offset;
4694 base_address = debug_info_p->base_address;
4696 if (dwarf_check != 0 && i > 0)
4699 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4700 (unsigned long) (start - section_begin),
4701 (unsigned long) (next - section_begin), section->name);
4702 else if (start > next)
4704 if (next == last_start)
4706 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4707 (unsigned long) (start - section_begin),
4708 (unsigned long) (next - section_begin), section->name);
4719 /* Note: we use sign extension here in order to be sure that
4720 we can detect the -1 escape value. Sign extension into the
4721 top 32 bits of a 32-bit address will not affect the values
4722 that we display since we always show hex values, and always
4723 the bottom 32-bits. */
4724 begin = byte_get_signed (start, pointer_size);
4725 start += pointer_size;
4726 end = byte_get_signed (start, pointer_size);
4727 start += pointer_size;
4729 printf (" %8.8lx ", offset);
4731 if (begin == 0 && end == 0)
4733 printf (_("<End of list>\n"));
4737 /* Check base address specifiers. */
4738 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4741 print_dwarf_vma (begin, pointer_size);
4742 print_dwarf_vma (end, pointer_size);
4743 printf ("(base address)\n");
4747 print_dwarf_vma (begin + base_address, pointer_size);
4748 print_dwarf_vma (end + base_address, pointer_size);
4751 fputs (_("(start == end)"), stdout);
4752 else if (begin > end)
4753 fputs (_("(start > end)"), stdout);
4760 free (range_entries);
4765 typedef struct Frame_Chunk
4767 struct Frame_Chunk *next;
4768 unsigned char *chunk_start;
4770 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4771 short int *col_type;
4774 unsigned int code_factor;
4776 unsigned long pc_begin;
4777 unsigned long pc_range;
4781 unsigned char fde_encoding;
4782 unsigned char cfa_exp;
4783 unsigned char ptr_size;
4784 unsigned char segment_size;
4788 static const char *const *dwarf_regnames;
4789 static unsigned int dwarf_regnames_count;
4791 /* A marker for a col_type that means this column was never referenced
4792 in the frame info. */
4793 #define DW_CFA_unreferenced (-1)
4795 /* Return 0 if not more space is needed, 1 if more space is needed,
4796 -1 for invalid reg. */
4799 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4801 int prev = fc->ncols;
4803 if (reg < (unsigned int) fc->ncols)
4806 if (dwarf_regnames_count
4807 && reg > dwarf_regnames_count)
4810 fc->ncols = reg + 1;
4811 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4812 sizeof (short int));
4813 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4815 while (prev < fc->ncols)
4817 fc->col_type[prev] = DW_CFA_unreferenced;
4818 fc->col_offset[prev] = 0;
4824 static const char *const dwarf_regnames_i386[] =
4826 "eax", "ecx", "edx", "ebx",
4827 "esp", "ebp", "esi", "edi",
4828 "eip", "eflags", NULL,
4829 "st0", "st1", "st2", "st3",
4830 "st4", "st5", "st6", "st7",
4832 "xmm0", "xmm1", "xmm2", "xmm3",
4833 "xmm4", "xmm5", "xmm6", "xmm7",
4834 "mm0", "mm1", "mm2", "mm3",
4835 "mm4", "mm5", "mm6", "mm7",
4836 "fcw", "fsw", "mxcsr",
4837 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4842 init_dwarf_regnames_i386 (void)
4844 dwarf_regnames = dwarf_regnames_i386;
4845 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4848 static const char *const dwarf_regnames_x86_64[] =
4850 "rax", "rdx", "rcx", "rbx",
4851 "rsi", "rdi", "rbp", "rsp",
4852 "r8", "r9", "r10", "r11",
4853 "r12", "r13", "r14", "r15",
4855 "xmm0", "xmm1", "xmm2", "xmm3",
4856 "xmm4", "xmm5", "xmm6", "xmm7",
4857 "xmm8", "xmm9", "xmm10", "xmm11",
4858 "xmm12", "xmm13", "xmm14", "xmm15",
4859 "st0", "st1", "st2", "st3",
4860 "st4", "st5", "st6", "st7",
4861 "mm0", "mm1", "mm2", "mm3",
4862 "mm4", "mm5", "mm6", "mm7",
4864 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4865 "fs.base", "gs.base", NULL, NULL,
4867 "mxcsr", "fcw", "fsw"
4871 init_dwarf_regnames_x86_64 (void)
4873 dwarf_regnames = dwarf_regnames_x86_64;
4874 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4878 init_dwarf_regnames (unsigned int e_machine)
4884 init_dwarf_regnames_i386 ();
4890 init_dwarf_regnames_x86_64 ();
4899 regname (unsigned int regno, int row)
4901 static char reg[64];
4903 && regno < dwarf_regnames_count
4904 && dwarf_regnames [regno] != NULL)
4907 return dwarf_regnames [regno];
4908 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4909 dwarf_regnames [regno]);
4912 snprintf (reg, sizeof (reg), "r%d", regno);
4917 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4922 if (*max_regs < fc->ncols)
4923 *max_regs = fc->ncols;
4925 if (*need_col_headers)
4927 static const char *sloc = " LOC";
4929 *need_col_headers = 0;
4931 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4933 for (r = 0; r < *max_regs; r++)
4934 if (fc->col_type[r] != DW_CFA_unreferenced)
4939 printf ("%-5s ", regname (r, 1));
4945 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4947 strcpy (tmp, "exp");
4949 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4950 printf ("%-8s ", tmp);
4952 for (r = 0; r < fc->ncols; r++)
4954 if (fc->col_type[r] != DW_CFA_unreferenced)
4956 switch (fc->col_type[r])
4958 case DW_CFA_undefined:
4961 case DW_CFA_same_value:
4965 sprintf (tmp, "c%+d", fc->col_offset[r]);
4967 case DW_CFA_val_offset:
4968 sprintf (tmp, "v%+d", fc->col_offset[r]);
4970 case DW_CFA_register:
4971 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4973 case DW_CFA_expression:
4974 strcpy (tmp, "exp");
4976 case DW_CFA_val_expression:
4977 strcpy (tmp, "vexp");
4980 strcpy (tmp, "n/a");
4983 printf ("%-5s ", tmp);
4989 #define GET(N) byte_get (start, N); start += N
4990 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4991 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4994 display_debug_frames (struct dwarf_section *section,
4995 void *file ATTRIBUTE_UNUSED)
4997 unsigned char *start = section->start;
4998 unsigned char *end = start + section->size;
4999 unsigned char *section_start = start;
5000 Frame_Chunk *chunks = 0;
5001 Frame_Chunk *remembered_state = 0;
5003 int is_eh = strcmp (section->name, ".eh_frame") == 0;
5004 unsigned int length_return;
5006 const char *bad_reg = _("bad register: ");
5007 int saved_eh_addr_size = eh_addr_size;
5009 printf (_("Contents of the %s section:\n"), section->name);
5013 unsigned char *saved_start;
5014 unsigned char *block_end;
5015 unsigned long length;
5016 unsigned long cie_id;
5019 int need_col_headers = 1;
5020 unsigned char *augmentation_data = NULL;
5021 unsigned long augmentation_data_len = 0;
5022 int encoded_ptr_size = saved_eh_addr_size;
5024 int initial_length_size;
5026 saved_start = start;
5027 length = byte_get (start, 4); start += 4;
5031 printf ("\n%08lx ZERO terminator\n\n",
5032 (unsigned long)(saved_start - section_start));
5036 if (length == 0xffffffff)
5038 length = byte_get (start, 8);
5041 initial_length_size = 12;
5046 initial_length_size = 4;
5049 block_end = saved_start + length + initial_length_size;
5050 if (block_end > end)
5052 warn ("Invalid length %#08lx in FDE at %#08lx\n",
5053 length, (unsigned long)(saved_start - section_start));
5056 cie_id = byte_get (start, offset_size); start += offset_size;
5058 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
5062 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5063 memset (fc, 0, sizeof (Frame_Chunk));
5067 fc->chunk_start = saved_start;
5069 fc->col_type = (short int *) xmalloc (sizeof (short int));
5070 fc->col_offset = (int *) xmalloc (sizeof (int));
5071 frame_need_space (fc, max_regs - 1);
5075 fc->augmentation = (char *) start;
5076 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
5078 if (strcmp (fc->augmentation, "eh") == 0)
5079 start += eh_addr_size;
5083 fc->ptr_size = GET (1);
5084 fc->segment_size = GET (1);
5085 eh_addr_size = fc->ptr_size;
5089 fc->ptr_size = eh_addr_size;
5090 fc->segment_size = 0;
5092 fc->code_factor = LEB ();
5093 fc->data_factor = SLEB ();
5103 if (fc->augmentation[0] == 'z')
5105 augmentation_data_len = LEB ();
5106 augmentation_data = start;
5107 start += augmentation_data_len;
5111 if (do_debug_frames_interp)
5112 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
5113 (unsigned long)(saved_start - section_start), length, cie_id,
5114 fc->augmentation, fc->code_factor, fc->data_factor,
5118 printf ("\n%08lx %08lx %08lx CIE\n",
5119 (unsigned long)(saved_start - section_start), length, cie_id);
5120 printf (" Version: %d\n", version);
5121 printf (" Augmentation: \"%s\"\n", fc->augmentation);
5124 printf (" Pointer Size: %u\n", fc->ptr_size);
5125 printf (" Segment Size: %u\n", fc->segment_size);
5127 printf (" Code alignment factor: %u\n", fc->code_factor);
5128 printf (" Data alignment factor: %d\n", fc->data_factor);
5129 printf (" Return address column: %d\n", fc->ra);
5131 if (augmentation_data_len)
5134 printf (" Augmentation data: ");
5135 for (i = 0; i < augmentation_data_len; ++i)
5136 printf (" %02x", augmentation_data[i]);
5142 if (augmentation_data_len)
5144 unsigned char *p, *q;
5145 p = (unsigned char *) fc->augmentation + 1;
5146 q = augmentation_data;
5153 q += 1 + size_of_encoded_value (*q);
5155 fc->fde_encoding = *q++;
5163 if (fc->fde_encoding)
5164 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5167 frame_need_space (fc, fc->ra);
5171 unsigned char *look_for;
5172 static Frame_Chunk fde_fc;
5173 unsigned long segment_selector;
5176 memset (fc, 0, sizeof (Frame_Chunk));
5178 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
5180 for (cie = chunks; cie ; cie = cie->next)
5181 if (cie->chunk_start == look_for)
5186 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
5187 cie_id, (unsigned long)(saved_start - section_start));
5189 fc->col_type = (short int *) xmalloc (sizeof (short int));
5190 fc->col_offset = (int *) xmalloc (sizeof (int));
5191 frame_need_space (fc, max_regs - 1);
5193 fc->augmentation = "";
5194 fc->fde_encoding = 0;
5195 fc->ptr_size = eh_addr_size;
5196 fc->segment_size = 0;
5200 fc->ncols = cie->ncols;
5201 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5202 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5203 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5204 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5205 fc->augmentation = cie->augmentation;
5206 fc->ptr_size = cie->ptr_size;
5207 eh_addr_size = cie->ptr_size;
5208 fc->segment_size = cie->segment_size;
5209 fc->code_factor = cie->code_factor;
5210 fc->data_factor = cie->data_factor;
5211 fc->cfa_reg = cie->cfa_reg;
5212 fc->cfa_offset = cie->cfa_offset;
5214 frame_need_space (fc, max_regs - 1);
5215 fc->fde_encoding = cie->fde_encoding;
5218 if (fc->fde_encoding)
5219 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5221 segment_selector = 0;
5222 if (fc->segment_size)
5224 segment_selector = byte_get (start, fc->segment_size);
5225 start += fc->segment_size;
5227 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
5228 start += encoded_ptr_size;
5229 fc->pc_range = byte_get (start, encoded_ptr_size);
5230 start += encoded_ptr_size;
5232 if (cie->augmentation[0] == 'z')
5234 augmentation_data_len = LEB ();
5235 augmentation_data = start;
5236 start += augmentation_data_len;
5239 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
5240 (unsigned long)(saved_start - section_start), length, cie_id,
5241 (unsigned long)(cie->chunk_start - section_start));
5242 if (fc->segment_size)
5243 printf ("%04lx:", segment_selector);
5244 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
5245 if (! do_debug_frames_interp && augmentation_data_len)
5249 printf (" Augmentation data: ");
5250 for (i = 0; i < augmentation_data_len; ++i)
5251 printf (" %02x", augmentation_data[i]);
5257 /* At this point, fc is the current chunk, cie (if any) is set, and
5258 we're about to interpret instructions for the chunk. */
5259 /* ??? At present we need to do this always, since this sizes the
5260 fc->col_type and fc->col_offset arrays, which we write into always.
5261 We should probably split the interpreted and non-interpreted bits
5262 into two different routines, since there's so much that doesn't
5263 really overlap between them. */
5264 if (1 || do_debug_frames_interp)
5266 /* Start by making a pass over the chunk, allocating storage
5267 and taking note of what registers are used. */
5268 unsigned char *tmp = start;
5270 while (start < block_end)
5273 unsigned long reg, temp;
5280 /* Warning: if you add any more cases to this switch, be
5281 sure to add them to the corresponding switch below. */
5284 case DW_CFA_advance_loc:
5288 if (frame_need_space (fc, opa) >= 0)
5289 fc->col_type[opa] = DW_CFA_undefined;
5291 case DW_CFA_restore:
5292 if (frame_need_space (fc, opa) >= 0)
5293 fc->col_type[opa] = DW_CFA_undefined;
5295 case DW_CFA_set_loc:
5296 start += encoded_ptr_size;
5298 case DW_CFA_advance_loc1:
5301 case DW_CFA_advance_loc2:
5304 case DW_CFA_advance_loc4:
5307 case DW_CFA_offset_extended:
5308 case DW_CFA_val_offset:
5309 reg = LEB (); LEB ();
5310 if (frame_need_space (fc, reg) >= 0)
5311 fc->col_type[reg] = DW_CFA_undefined;
5313 case DW_CFA_restore_extended:
5315 frame_need_space (fc, reg);
5316 if (frame_need_space (fc, reg) >= 0)
5317 fc->col_type[reg] = DW_CFA_undefined;
5319 case DW_CFA_undefined:
5321 if (frame_need_space (fc, reg) >= 0)
5322 fc->col_type[reg] = DW_CFA_undefined;
5324 case DW_CFA_same_value:
5326 if (frame_need_space (fc, reg) >= 0)
5327 fc->col_type[reg] = DW_CFA_undefined;
5329 case DW_CFA_register:
5330 reg = LEB (); LEB ();
5331 if (frame_need_space (fc, reg) >= 0)
5332 fc->col_type[reg] = DW_CFA_undefined;
5334 case DW_CFA_def_cfa:
5337 case DW_CFA_def_cfa_register:
5340 case DW_CFA_def_cfa_offset:
5343 case DW_CFA_def_cfa_expression:
5347 case DW_CFA_expression:
5348 case DW_CFA_val_expression:
5352 if (frame_need_space (fc, reg) >= 0)
5353 fc->col_type[reg] = DW_CFA_undefined;
5355 case DW_CFA_offset_extended_sf:
5356 case DW_CFA_val_offset_sf:
5357 reg = LEB (); SLEB ();
5358 if (frame_need_space (fc, reg) >= 0)
5359 fc->col_type[reg] = DW_CFA_undefined;
5361 case DW_CFA_def_cfa_sf:
5364 case DW_CFA_def_cfa_offset_sf:
5367 case DW_CFA_MIPS_advance_loc8:
5370 case DW_CFA_GNU_args_size:
5373 case DW_CFA_GNU_negative_offset_extended:
5374 reg = LEB (); LEB ();
5375 if (frame_need_space (fc, reg) >= 0)
5376 fc->col_type[reg] = DW_CFA_undefined;
5385 /* Now we know what registers are used, make a second pass over
5386 the chunk, this time actually printing out the info. */
5388 while (start < block_end)
5391 unsigned long ul, reg, roffs;
5394 const char *reg_prefix = "";
5401 /* Warning: if you add any more cases to this switch, be
5402 sure to add them to the corresponding switch above. */
5405 case DW_CFA_advance_loc:
5406 if (do_debug_frames_interp)
5407 frame_display_row (fc, &need_col_headers, &max_regs);
5409 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5410 opa * fc->code_factor,
5411 fc->pc_begin + opa * fc->code_factor);
5412 fc->pc_begin += opa * fc->code_factor;
5417 if (opa >= (unsigned int) fc->ncols)
5418 reg_prefix = bad_reg;
5419 if (! do_debug_frames_interp || *reg_prefix != '\0')
5420 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5421 reg_prefix, regname (opa, 0),
5422 roffs * fc->data_factor);
5423 if (*reg_prefix == '\0')
5425 fc->col_type[opa] = DW_CFA_offset;
5426 fc->col_offset[opa] = roffs * fc->data_factor;
5430 case DW_CFA_restore:
5431 if (opa >= (unsigned int) cie->ncols
5432 || opa >= (unsigned int) fc->ncols)
5433 reg_prefix = bad_reg;
5434 if (! do_debug_frames_interp || *reg_prefix != '\0')
5435 printf (" DW_CFA_restore: %s%s\n",
5436 reg_prefix, regname (opa, 0));
5437 if (*reg_prefix == '\0')
5439 fc->col_type[opa] = cie->col_type[opa];
5440 fc->col_offset[opa] = cie->col_offset[opa];
5441 if (do_debug_frames_interp
5442 && fc->col_type[opa] == DW_CFA_unreferenced)
5443 fc->col_type[opa] = DW_CFA_undefined;
5447 case DW_CFA_set_loc:
5448 vma = get_encoded_value (start, fc->fde_encoding, section);
5449 start += encoded_ptr_size;
5450 if (do_debug_frames_interp)
5451 frame_display_row (fc, &need_col_headers, &max_regs);
5453 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5457 case DW_CFA_advance_loc1:
5458 ofs = byte_get (start, 1); start += 1;
5459 if (do_debug_frames_interp)
5460 frame_display_row (fc, &need_col_headers, &max_regs);
5462 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5463 ofs * fc->code_factor,
5464 fc->pc_begin + ofs * fc->code_factor);
5465 fc->pc_begin += ofs * fc->code_factor;
5468 case DW_CFA_advance_loc2:
5469 ofs = byte_get (start, 2); start += 2;
5470 if (do_debug_frames_interp)
5471 frame_display_row (fc, &need_col_headers, &max_regs);
5473 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5474 ofs * fc->code_factor,
5475 fc->pc_begin + ofs * fc->code_factor);
5476 fc->pc_begin += ofs * fc->code_factor;
5479 case DW_CFA_advance_loc4:
5480 ofs = byte_get (start, 4); start += 4;
5481 if (do_debug_frames_interp)
5482 frame_display_row (fc, &need_col_headers, &max_regs);
5484 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5485 ofs * fc->code_factor,
5486 fc->pc_begin + ofs * fc->code_factor);
5487 fc->pc_begin += ofs * fc->code_factor;
5490 case DW_CFA_offset_extended:
5493 if (reg >= (unsigned int) fc->ncols)
5494 reg_prefix = bad_reg;
5495 if (! do_debug_frames_interp || *reg_prefix != '\0')
5496 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5497 reg_prefix, regname (reg, 0),
5498 roffs * fc->data_factor);
5499 if (*reg_prefix == '\0')
5501 fc->col_type[reg] = DW_CFA_offset;
5502 fc->col_offset[reg] = roffs * fc->data_factor;
5506 case DW_CFA_val_offset:
5509 if (reg >= (unsigned int) fc->ncols)
5510 reg_prefix = bad_reg;
5511 if (! do_debug_frames_interp || *reg_prefix != '\0')
5512 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5513 reg_prefix, regname (reg, 0),
5514 roffs * fc->data_factor);
5515 if (*reg_prefix == '\0')
5517 fc->col_type[reg] = DW_CFA_val_offset;
5518 fc->col_offset[reg] = roffs * fc->data_factor;
5522 case DW_CFA_restore_extended:
5524 if (reg >= (unsigned int) cie->ncols
5525 || reg >= (unsigned int) fc->ncols)
5526 reg_prefix = bad_reg;
5527 if (! do_debug_frames_interp || *reg_prefix != '\0')
5528 printf (" DW_CFA_restore_extended: %s%s\n",
5529 reg_prefix, regname (reg, 0));
5530 if (*reg_prefix == '\0')
5532 fc->col_type[reg] = cie->col_type[reg];
5533 fc->col_offset[reg] = cie->col_offset[reg];
5537 case DW_CFA_undefined:
5539 if (reg >= (unsigned int) fc->ncols)
5540 reg_prefix = bad_reg;
5541 if (! do_debug_frames_interp || *reg_prefix != '\0')
5542 printf (" DW_CFA_undefined: %s%s\n",
5543 reg_prefix, regname (reg, 0));
5544 if (*reg_prefix == '\0')
5546 fc->col_type[reg] = DW_CFA_undefined;
5547 fc->col_offset[reg] = 0;
5551 case DW_CFA_same_value:
5553 if (reg >= (unsigned int) fc->ncols)
5554 reg_prefix = bad_reg;
5555 if (! do_debug_frames_interp || *reg_prefix != '\0')
5556 printf (" DW_CFA_same_value: %s%s\n",
5557 reg_prefix, regname (reg, 0));
5558 if (*reg_prefix == '\0')
5560 fc->col_type[reg] = DW_CFA_same_value;
5561 fc->col_offset[reg] = 0;
5565 case DW_CFA_register:
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_register: %s%s in ",
5573 reg_prefix, regname (reg, 0));
5574 puts (regname (roffs, 0));
5576 if (*reg_prefix == '\0')
5578 fc->col_type[reg] = DW_CFA_register;
5579 fc->col_offset[reg] = roffs;
5583 case DW_CFA_remember_state:
5584 if (! do_debug_frames_interp)
5585 printf (" DW_CFA_remember_state\n");
5586 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5587 rs->ncols = fc->ncols;
5588 rs->col_type = (short int *) xcmalloc (rs->ncols,
5589 sizeof (short int));
5590 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
5591 memcpy (rs->col_type, fc->col_type, rs->ncols);
5592 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5593 rs->next = remembered_state;
5594 remembered_state = rs;
5597 case DW_CFA_restore_state:
5598 if (! do_debug_frames_interp)
5599 printf (" DW_CFA_restore_state\n");
5600 rs = remembered_state;
5603 remembered_state = rs->next;
5604 frame_need_space (fc, rs->ncols - 1);
5605 memcpy (fc->col_type, rs->col_type, rs->ncols);
5606 memcpy (fc->col_offset, rs->col_offset,
5607 rs->ncols * sizeof (int));
5608 free (rs->col_type);
5609 free (rs->col_offset);
5612 else if (do_debug_frames_interp)
5613 printf ("Mismatched DW_CFA_restore_state\n");
5616 case DW_CFA_def_cfa:
5617 fc->cfa_reg = LEB ();
5618 fc->cfa_offset = LEB ();
5620 if (! do_debug_frames_interp)
5621 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5622 regname (fc->cfa_reg, 0), fc->cfa_offset);
5625 case DW_CFA_def_cfa_register:
5626 fc->cfa_reg = LEB ();
5628 if (! do_debug_frames_interp)
5629 printf (" DW_CFA_def_cfa_register: %s\n",
5630 regname (fc->cfa_reg, 0));
5633 case DW_CFA_def_cfa_offset:
5634 fc->cfa_offset = LEB ();
5635 if (! do_debug_frames_interp)
5636 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5640 if (! do_debug_frames_interp)
5641 printf (" DW_CFA_nop\n");
5644 case DW_CFA_def_cfa_expression:
5646 if (! do_debug_frames_interp)
5648 printf (" DW_CFA_def_cfa_expression (");
5649 decode_location_expression (start, eh_addr_size, 0, -1,
5657 case DW_CFA_expression:
5660 if (reg >= (unsigned int) fc->ncols)
5661 reg_prefix = bad_reg;
5662 if (! do_debug_frames_interp || *reg_prefix != '\0')
5664 printf (" DW_CFA_expression: %s%s (",
5665 reg_prefix, regname (reg, 0));
5666 decode_location_expression (start, eh_addr_size, 0, -1,
5670 if (*reg_prefix == '\0')
5671 fc->col_type[reg] = DW_CFA_expression;
5675 case DW_CFA_val_expression:
5678 if (reg >= (unsigned int) fc->ncols)
5679 reg_prefix = bad_reg;
5680 if (! do_debug_frames_interp || *reg_prefix != '\0')
5682 printf (" DW_CFA_val_expression: %s%s (",
5683 reg_prefix, regname (reg, 0));
5684 decode_location_expression (start, eh_addr_size, 0, -1,
5688 if (*reg_prefix == '\0')
5689 fc->col_type[reg] = DW_CFA_val_expression;
5693 case DW_CFA_offset_extended_sf:
5696 if (frame_need_space (fc, reg) < 0)
5697 reg_prefix = bad_reg;
5698 if (! do_debug_frames_interp || *reg_prefix != '\0')
5699 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5700 reg_prefix, regname (reg, 0),
5701 l * fc->data_factor);
5702 if (*reg_prefix == '\0')
5704 fc->col_type[reg] = DW_CFA_offset;
5705 fc->col_offset[reg] = l * fc->data_factor;
5709 case DW_CFA_val_offset_sf:
5712 if (frame_need_space (fc, reg) < 0)
5713 reg_prefix = bad_reg;
5714 if (! do_debug_frames_interp || *reg_prefix != '\0')
5715 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5716 reg_prefix, regname (reg, 0),
5717 l * fc->data_factor);
5718 if (*reg_prefix == '\0')
5720 fc->col_type[reg] = DW_CFA_val_offset;
5721 fc->col_offset[reg] = l * fc->data_factor;
5725 case DW_CFA_def_cfa_sf:
5726 fc->cfa_reg = LEB ();
5727 fc->cfa_offset = SLEB ();
5728 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5730 if (! do_debug_frames_interp)
5731 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5732 regname (fc->cfa_reg, 0), fc->cfa_offset);
5735 case DW_CFA_def_cfa_offset_sf:
5736 fc->cfa_offset = SLEB ();
5737 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5738 if (! do_debug_frames_interp)
5739 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5742 case DW_CFA_MIPS_advance_loc8:
5743 ofs = byte_get (start, 8); start += 8;
5744 if (do_debug_frames_interp)
5745 frame_display_row (fc, &need_col_headers, &max_regs);
5747 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5748 ofs * fc->code_factor,
5749 fc->pc_begin + ofs * fc->code_factor);
5750 fc->pc_begin += ofs * fc->code_factor;
5753 case DW_CFA_GNU_window_save:
5754 if (! do_debug_frames_interp)
5755 printf (" DW_CFA_GNU_window_save\n");
5758 case DW_CFA_GNU_args_size:
5760 if (! do_debug_frames_interp)
5761 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5764 case DW_CFA_GNU_negative_offset_extended:
5767 if (frame_need_space (fc, reg) < 0)
5768 reg_prefix = bad_reg;
5769 if (! do_debug_frames_interp || *reg_prefix != '\0')
5770 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5771 reg_prefix, regname (reg, 0),
5772 l * fc->data_factor);
5773 if (*reg_prefix == '\0')
5775 fc->col_type[reg] = DW_CFA_offset;
5776 fc->col_offset[reg] = l * fc->data_factor;
5781 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5782 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5784 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5789 if (do_debug_frames_interp)
5790 frame_display_row (fc, &need_col_headers, &max_regs);
5793 eh_addr_size = saved_eh_addr_size;
5806 display_gdb_index (struct dwarf_section *section,
5807 void *file ATTRIBUTE_UNUSED)
5809 unsigned char *start = section->start;
5811 uint32_t cu_list_offset, tu_list_offset;
5812 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5813 unsigned int cu_list_elements, tu_list_elements;
5814 unsigned int address_table_size, symbol_table_slots;
5815 unsigned char *cu_list, *tu_list;
5816 unsigned char *address_table, *symbol_table, *constant_pool;
5819 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5821 printf (_("Contents of the %s section:\n"), section->name);
5823 if (section->size < 6 * sizeof (uint32_t))
5825 warn (_("Truncated header in the %s section.\n"), section->name);
5829 version = byte_get_little_endian (start, 4);
5830 printf (_("Version %ld\n"), (long) version);
5832 /* Prior versions are obsolete, and future versions may not be
5833 backwards compatible. */
5834 if (version < 3 || version > 8)
5836 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5840 warn (_("The address table data in version 3 may be wrong.\n"));
5842 warn (_("Version 4 does not support case insensitive lookups.\n"));
5844 warn (_("Version 5 does not include inlined functions.\n"));
5846 warn (_("Version 6 does not include symbol attributes.\n"));
5847 /* Version 7 indices generated by Gold have bad type unit references,
5848 PR binutils/15021. But we don't know if the index was generated by
5849 Gold or not, so to avoid worrying users with gdb-generated indices
5850 we say nothing for version 7 here. */
5852 cu_list_offset = byte_get_little_endian (start + 4, 4);
5853 tu_list_offset = byte_get_little_endian (start + 8, 4);
5854 address_table_offset = byte_get_little_endian (start + 12, 4);
5855 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5856 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5858 if (cu_list_offset > section->size
5859 || tu_list_offset > section->size
5860 || address_table_offset > section->size
5861 || symbol_table_offset > section->size
5862 || constant_pool_offset > section->size)
5864 warn (_("Corrupt header in the %s section.\n"), section->name);
5868 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5869 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5870 address_table_size = symbol_table_offset - address_table_offset;
5871 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5873 cu_list = start + cu_list_offset;
5874 tu_list = start + tu_list_offset;
5875 address_table = start + address_table_offset;
5876 symbol_table = start + symbol_table_offset;
5877 constant_pool = start + constant_pool_offset;
5879 printf (_("\nCU table:\n"));
5880 for (i = 0; i < cu_list_elements; i += 2)
5882 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5883 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5885 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5886 (unsigned long) cu_offset,
5887 (unsigned long) (cu_offset + cu_length - 1));
5890 printf (_("\nTU table:\n"));
5891 for (i = 0; i < tu_list_elements; i += 3)
5893 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5894 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5895 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5897 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5898 (unsigned long) tu_offset,
5899 (unsigned long) type_offset);
5900 print_dwarf_vma (signature, 8);
5904 printf (_("\nAddress table:\n"));
5905 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5907 uint64_t low = byte_get_little_endian (address_table + i, 8);
5908 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5909 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5911 print_dwarf_vma (low, 8);
5912 print_dwarf_vma (high, 8);
5913 printf (_("%lu\n"), (unsigned long) cu_index);
5916 printf (_("\nSymbol table:\n"));
5917 for (i = 0; i < symbol_table_slots; ++i)
5919 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5920 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5921 uint32_t num_cus, cu;
5923 if (name_offset != 0
5924 || cu_vector_offset != 0)
5928 printf ("[%3u] %s:", i, constant_pool + name_offset);
5929 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5932 for (j = 0; j < num_cus; ++j)
5935 gdb_index_symbol_kind kind;
5937 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5938 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
5939 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
5940 cu = GDB_INDEX_CU_VALUE (cu);
5941 /* Convert to TU number if it's for a type unit. */
5942 if (cu >= cu_list_elements / 2)
5943 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
5944 (unsigned long) (cu - cu_list_elements / 2));
5946 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
5950 case GDB_INDEX_SYMBOL_KIND_NONE:
5951 printf (_(" [no symbol information]"));
5953 case GDB_INDEX_SYMBOL_KIND_TYPE:
5955 ? _(" [static type]")
5956 : _(" [global type]"));
5958 case GDB_INDEX_SYMBOL_KIND_VARIABLE:
5960 ? _(" [static variable]")
5961 : _(" [global variable]"));
5963 case GDB_INDEX_SYMBOL_KIND_FUNCTION:
5965 ? _(" [static function]")
5966 : _(" [global function]"));
5968 case GDB_INDEX_SYMBOL_KIND_OTHER:
5970 ? _(" [static other]")
5971 : _(" [global other]"));
5975 ? _(" [static unknown: %d]")
5976 : _(" [global unknown: %d]"),
5991 /* Pre-allocate enough space for the CU/TU sets needed. */
5994 prealloc_cu_tu_list (unsigned int nshndx)
5996 if (shndx_pool == NULL)
5998 shndx_pool_size = nshndx;
5999 shndx_pool_used = 0;
6000 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
6001 sizeof (unsigned int));
6005 shndx_pool_size = shndx_pool_used + nshndx;
6006 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
6007 sizeof (unsigned int));
6012 add_shndx_to_cu_tu_entry (unsigned int shndx)
6014 if (shndx_pool_used >= shndx_pool_size)
6016 error (_("Internal error: out of space in the shndx pool.\n"));
6019 shndx_pool [shndx_pool_used++] = shndx;
6023 end_cu_tu_entry (void)
6025 if (shndx_pool_used >= shndx_pool_size)
6027 error (_("Internal error: out of space in the shndx pool.\n"));
6030 shndx_pool [shndx_pool_used++] = 0;
6033 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6036 get_DW_SECT_short_name (unsigned int dw_sect)
6038 static char buf[16];
6046 case DW_SECT_ABBREV:
6052 case DW_SECT_STR_OFFSETS:
6054 case DW_SECT_MACINFO:
6062 snprintf (buf, sizeof (buf), "%d", dw_sect);
6066 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6067 These sections are extensions for Fission.
6068 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6071 process_cu_tu_index (struct dwarf_section *section, int do_display)
6073 unsigned char *phdr = section->start;
6074 unsigned char *limit = phdr + section->size;
6075 unsigned char *phash;
6076 unsigned char *pindex;
6077 unsigned char *ppool;
6078 unsigned int version;
6079 unsigned int ncols = 0;
6081 unsigned int nslots;
6084 dwarf_vma signature_high;
6085 dwarf_vma signature_low;
6088 version = byte_get (phdr, 4);
6090 ncols = byte_get (phdr + 4, 4);
6091 nused = byte_get (phdr + 8, 4);
6092 nslots = byte_get (phdr + 12, 4);
6094 pindex = phash + nslots * 8;
6095 ppool = pindex + nslots * 4;
6099 printf (_("Contents of the %s section:\n\n"), section->name);
6100 printf (_(" Version: %d\n"), version);
6102 printf (_(" Number of columns: %d\n"), ncols);
6103 printf (_(" Number of used entries: %d\n"), nused);
6104 printf (_(" Number of slots: %d\n\n"), nslots);
6109 warn (_("Section %s too small for %d hash table entries\n"),
6110 section->name, nslots);
6117 prealloc_cu_tu_list ((limit - ppool) / 4);
6118 for (i = 0; i < nslots; i++)
6120 unsigned char *shndx_list;
6123 byte_get_64 (phash, &signature_high, &signature_low);
6124 if (signature_high != 0 || signature_low != 0)
6126 j = byte_get (pindex, 4);
6127 shndx_list = ppool + j * 4;
6129 printf (_(" [%3d] Signature: 0x%s Sections: "),
6130 i, dwarf_vmatoa64 (signature_high, signature_low,
6131 buf, sizeof (buf)));
6134 if (shndx_list >= limit)
6136 warn (_("Section %s too small for shndx pool\n"),
6140 shndx = byte_get (shndx_list, 4);
6144 printf (" %d", shndx);
6146 add_shndx_to_cu_tu_entry (shndx);
6158 else if (version == 2)
6161 unsigned int dw_sect;
6162 unsigned char *ph = phash;
6163 unsigned char *pi = pindex;
6164 unsigned char *poffsets = ppool + ncols * 4;
6165 unsigned char *psizes = poffsets + nused * ncols * 4;
6166 unsigned char *pend = psizes + nused * ncols * 4;
6167 bfd_boolean is_tu_index;
6168 struct cu_tu_set *this_set = NULL;
6170 unsigned char *prow;
6172 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
6176 warn (_("Section %s too small for offset and size tables\n"),
6183 printf (_(" Offset table\n"));
6184 printf (" slot %-16s ",
6185 is_tu_index ? _("signature") : _("dwo_id"));
6192 tu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6198 cu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6204 for (j = 0; j < ncols; j++)
6206 dw_sect = byte_get (ppool + j * 4, 4);
6207 printf (" %8s", get_DW_SECT_short_name (dw_sect));
6211 for (i = 0; i < nslots; i++)
6213 byte_get_64 (ph, &signature_high, &signature_low);
6214 row = byte_get (pi, 4);
6218 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
6219 prow = poffsets + (row - 1) * ncols * 4;
6221 printf (_(" [%3d] 0x%s"),
6222 i, dwarf_vmatoa64 (signature_high, signature_low,
6223 buf, sizeof (buf)));
6224 for (j = 0; j < ncols; j++)
6226 val = byte_get (prow + j * 4, 4);
6228 printf (" %8d", val);
6231 dw_sect = byte_get (ppool + j * 4, 4);
6232 this_set [row - 1].section_offsets [dw_sect] = val;
6247 printf (_(" Size table\n"));
6248 printf (" slot %-16s ",
6249 is_tu_index ? _("signature") : _("dwo_id"));
6251 for (j = 0; j < ncols; j++)
6253 val = byte_get (ppool + j * 4, 4);
6255 printf (" %8s", get_DW_SECT_short_name (val));
6259 for (i = 0; i < nslots; i++)
6261 byte_get_64 (ph, &signature_high, &signature_low);
6262 row = byte_get (pi, 4);
6265 prow = psizes + (row - 1) * ncols * 4;
6267 printf (_(" [%3d] 0x%s"),
6268 i, dwarf_vmatoa64 (signature_high, signature_low,
6269 buf, sizeof (buf)));
6270 for (j = 0; j < ncols; j++)
6272 val = byte_get (prow + j * 4, 4);
6274 printf (" %8d", val);
6277 dw_sect = byte_get (ppool + j * 4, 4);
6278 this_set [row - 1].section_sizes [dw_sect] = val;
6288 else if (do_display)
6289 printf (_(" Unsupported version\n"));
6297 /* Load the CU and TU indexes if present. This will build a list of
6298 section sets that we can use to associate a .debug_info.dwo section
6299 with its associated .debug_abbrev.dwo section in a .dwp file. */
6302 load_cu_tu_indexes (void *file)
6304 /* If we have already loaded (or tried to load) the CU and TU indexes
6305 then do not bother to repeat the task. */
6306 if (cu_tu_indexes_read)
6309 if (load_debug_section (dwp_cu_index, file))
6310 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
6312 if (load_debug_section (dwp_tu_index, file))
6313 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
6315 cu_tu_indexes_read = 1;
6318 /* Find the set of sections that includes section SHNDX. */
6321 find_cu_tu_set (void *file, unsigned int shndx)
6325 load_cu_tu_indexes (file);
6327 /* Find SHNDX in the shndx pool. */
6328 for (i = 0; i < shndx_pool_used; i++)
6329 if (shndx_pool [i] == shndx)
6332 if (i >= shndx_pool_used)
6335 /* Now backup to find the first entry in the set. */
6336 while (i > 0 && shndx_pool [i - 1] != 0)
6339 return shndx_pool + i;
6342 /* Display a .debug_cu_index or .debug_tu_index section. */
6345 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
6347 return process_cu_tu_index (section, 1);
6351 display_debug_not_supported (struct dwarf_section *section,
6352 void *file ATTRIBUTE_UNUSED)
6354 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6361 cmalloc (size_t nmemb, size_t size)
6363 /* Check for overflow. */
6364 if (nmemb >= ~(size_t) 0 / size)
6367 return malloc (nmemb * size);
6371 xcmalloc (size_t nmemb, size_t size)
6373 /* Check for overflow. */
6374 if (nmemb >= ~(size_t) 0 / size)
6377 return xmalloc (nmemb * size);
6381 xcrealloc (void *ptr, size_t nmemb, size_t size)
6383 /* Check for overflow. */
6384 if (nmemb >= ~(size_t) 0 / size)
6387 return xrealloc (ptr, nmemb * size);
6391 free_debug_memory (void)
6397 for (i = 0; i < max; i++)
6398 free_debug_section ((enum dwarf_section_display_enum) i);
6400 if (debug_information != NULL)
6402 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
6404 for (i = 0; i < num_debug_info_entries; i++)
6406 if (!debug_information [i].max_loc_offsets)
6408 free (debug_information [i].loc_offsets);
6409 free (debug_information [i].have_frame_base);
6411 if (!debug_information [i].max_range_lists)
6412 free (debug_information [i].range_lists);
6416 free (debug_information);
6417 debug_information = NULL;
6418 num_debug_info_entries = 0;
6423 dwarf_select_sections_by_names (const char *names)
6427 const char * option;
6431 debug_dump_long_opts;
6433 static const debug_dump_long_opts opts_table [] =
6435 /* Please keep this table alpha- sorted. */
6436 { "Ranges", & do_debug_ranges, 1 },
6437 { "abbrev", & do_debug_abbrevs, 1 },
6438 { "addr", & do_debug_addr, 1 },
6439 { "aranges", & do_debug_aranges, 1 },
6440 { "cu_index", & do_debug_cu_index, 1 },
6441 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
6442 { "frames", & do_debug_frames, 1 },
6443 { "frames-interp", & do_debug_frames_interp, 1 },
6444 /* The special .gdb_index section. */
6445 { "gdb_index", & do_gdb_index, 1 },
6446 { "info", & do_debug_info, 1 },
6447 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
6448 { "loc", & do_debug_loc, 1 },
6449 { "macro", & do_debug_macinfo, 1 },
6450 { "pubnames", & do_debug_pubnames, 1 },
6451 { "pubtypes", & do_debug_pubtypes, 1 },
6452 /* This entry is for compatability
6453 with earlier versions of readelf. */
6454 { "ranges", & do_debug_aranges, 1 },
6455 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
6456 { "str", & do_debug_str, 1 },
6457 /* These trace_* sections are used by Itanium VMS. */
6458 { "trace_abbrev", & do_trace_abbrevs, 1 },
6459 { "trace_aranges", & do_trace_aranges, 1 },
6460 { "trace_info", & do_trace_info, 1 },
6469 const debug_dump_long_opts * entry;
6471 for (entry = opts_table; entry->option; entry++)
6473 size_t len = strlen (entry->option);
6475 if (strncmp (p, entry->option, len) == 0
6476 && (p[len] == ',' || p[len] == '\0'))
6478 * entry->variable |= entry->val;
6480 /* The --debug-dump=frames-interp option also
6481 enables the --debug-dump=frames option. */
6482 if (do_debug_frames_interp)
6483 do_debug_frames = 1;
6490 if (entry->option == NULL)
6492 warn (_("Unrecognized debug option '%s'\n"), p);
6493 p = strchr (p, ',');
6504 dwarf_select_sections_by_letters (const char *letters)
6506 unsigned int lindex = 0;
6508 while (letters[lindex])
6509 switch (letters[lindex++])
6516 do_debug_abbrevs = 1;
6520 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
6524 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
6528 do_debug_pubnames = 1;
6532 do_debug_pubtypes = 1;
6536 do_debug_aranges = 1;
6540 do_debug_ranges = 1;
6544 do_debug_frames_interp = 1;
6546 do_debug_frames = 1;
6550 do_debug_macinfo = 1;
6562 warn (_("Unrecognized debug option '%s'\n"), optarg);
6568 dwarf_select_sections_all (void)
6571 do_debug_abbrevs = 1;
6572 do_debug_lines = FLAG_DEBUG_LINES_RAW;
6573 do_debug_pubnames = 1;
6574 do_debug_pubtypes = 1;
6575 do_debug_aranges = 1;
6576 do_debug_ranges = 1;
6577 do_debug_frames = 1;
6578 do_debug_macinfo = 1;
6583 do_trace_abbrevs = 1;
6584 do_trace_aranges = 1;
6586 do_debug_cu_index = 1;
6589 struct dwarf_section_display debug_displays[] =
6591 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0 },
6592 display_debug_abbrev, &do_debug_abbrevs, 0 },
6593 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0 },
6594 display_debug_aranges, &do_debug_aranges, 1 },
6595 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0 },
6596 display_debug_frames, &do_debug_frames, 1 },
6597 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev },
6598 display_debug_info, &do_debug_info, 1 },
6599 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0 },
6600 display_debug_lines, &do_debug_lines, 1 },
6601 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0 },
6602 display_debug_pubnames, &do_debug_pubnames, 0 },
6603 { { ".eh_frame", "", NULL, NULL, 0, 0, 0 },
6604 display_debug_frames, &do_debug_frames, 1 },
6605 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0 },
6606 display_debug_macinfo, &do_debug_macinfo, 0 },
6607 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0 },
6608 display_debug_macro, &do_debug_macinfo, 1 },
6609 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0 },
6610 display_debug_str, &do_debug_str, 0 },
6611 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0 },
6612 display_debug_loc, &do_debug_loc, 1 },
6613 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0 },
6614 display_debug_pubnames, &do_debug_pubtypes, 0 },
6615 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0 },
6616 display_debug_ranges, &do_debug_ranges, 1 },
6617 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0 },
6618 display_debug_not_supported, NULL, 0 },
6619 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0 },
6620 display_debug_not_supported, NULL, 0 },
6621 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev },
6622 display_debug_types, &do_debug_info, 1 },
6623 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0 },
6624 display_debug_not_supported, NULL, 0 },
6625 { { ".gdb_index", "", NULL, NULL, 0, 0, 0 },
6626 display_gdb_index, &do_gdb_index, 0 },
6627 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev },
6628 display_trace_info, &do_trace_info, 1 },
6629 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0 },
6630 display_debug_abbrev, &do_trace_abbrevs, 0 },
6631 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0 },
6632 display_debug_aranges, &do_trace_aranges, 0 },
6633 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6634 display_debug_info, &do_debug_info, 1 },
6635 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0 },
6636 display_debug_abbrev, &do_debug_abbrevs, 0 },
6637 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6638 display_debug_types, &do_debug_info, 1 },
6639 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0 },
6640 display_debug_lines, &do_debug_lines, 1 },
6641 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0 },
6642 display_debug_loc, &do_debug_loc, 1 },
6643 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0 },
6644 display_debug_macro, &do_debug_macinfo, 1 },
6645 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0 },
6646 display_debug_macinfo, &do_debug_macinfo, 0 },
6647 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0 },
6648 display_debug_str, &do_debug_str, 1 },
6649 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0 },
6650 display_debug_str_offsets, NULL, 0 },
6651 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0 },
6652 display_debug_str_offsets, NULL, 0 },
6653 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0 },
6654 display_debug_addr, &do_debug_addr, 1 },
6655 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0 },
6656 display_cu_index, &do_debug_cu_index, 0 },
6657 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0 },
6658 display_cu_index, &do_debug_cu_index, 0 },