PR ld/10144
[binutils.git] / binutils / dwarf.c
blob1196246194244dfba8191675401a9aa90138bac0
1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011
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
20 02110-1301, USA. */
22 #include "sysdep.h"
23 #include "libiberty.h"
24 #include "bfd.h"
25 #include "bfd_stdint.h"
26 #include "bucomm.h"
27 #include "elfcomm.h"
28 #include "elf/common.h"
29 #include "dwarf2.h"
30 #include "dwarf.h"
32 static const char *regname (unsigned int regno, int row);
34 static int have_frame_base;
35 static int need_base_address;
37 static unsigned int last_pointer_size = 0;
38 static int warned_about_missing_comp_units = FALSE;
40 static unsigned int num_debug_info_entries = 0;
41 static debug_info *debug_information = NULL;
42 /* Special value for num_debug_info_entries to indicate
43 that the .debug_info section could not be loaded/parsed. */
44 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
46 int eh_addr_size;
48 int do_debug_info;
49 int do_debug_abbrevs;
50 int do_debug_lines;
51 int do_debug_pubnames;
52 int do_debug_pubtypes;
53 int do_debug_aranges;
54 int do_debug_ranges;
55 int do_debug_frames;
56 int do_debug_frames_interp;
57 int do_debug_macinfo;
58 int do_debug_str;
59 int do_debug_loc;
60 int do_gdb_index;
61 int do_trace_info;
62 int do_trace_abbrevs;
63 int do_trace_aranges;
64 int do_wide;
66 int dwarf_cutoff_level = -1;
67 unsigned long dwarf_start_die;
69 /* Values for do_debug_lines. */
70 #define FLAG_DEBUG_LINES_RAW 1
71 #define FLAG_DEBUG_LINES_DECODED 2
73 static int
74 size_of_encoded_value (int encoding)
76 switch (encoding & 0x7)
78 default: /* ??? */
79 case 0: return eh_addr_size;
80 case 2: return 2;
81 case 3: return 4;
82 case 4: return 8;
86 static dwarf_vma
87 get_encoded_value (unsigned char *data,
88 int encoding,
89 struct dwarf_section *section)
91 int size = size_of_encoded_value (encoding);
92 dwarf_vma val;
94 if (encoding & DW_EH_PE_signed)
95 val = byte_get_signed (data, size);
96 else
97 val = byte_get (data, size);
99 if ((encoding & 0x70) == DW_EH_PE_pcrel)
100 val += section->address + (data - section->start);
101 return val;
104 /* Print a dwarf_vma value (typically an address, offset or length) in
105 hexadecimal format, followed by a space. The length of the value (and
106 hence the precision displayed) is determined by the byte_size parameter. */
108 static void
109 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
111 static char buff[18];
112 int offset = 0;
114 /* Printf does not have a way of specifiying a maximum field width for an
115 integer value, so we print the full value into a buffer and then select
116 the precision we need. */
117 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
118 #ifndef __MINGW32__
119 snprintf (buff, sizeof (buff), "%16.16llx ", val);
120 #else
121 snprintf (buff, sizeof (buff), "%016I64x ", val);
122 #endif
123 #else
124 snprintf (buff, sizeof (buff), "%16.16lx ", val);
125 #endif
127 if (byte_size != 0)
129 if (byte_size > 0 && byte_size <= 8)
130 offset = 16 - 2 * byte_size;
131 else
132 error (_("Wrong size in print_dwarf_vma"));
135 fputs (buff + offset, stdout);
138 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
139 #ifndef __MINGW32__
140 #define DWARF_VMA_FMT "ll"
141 #else
142 #define DWARF_VMA_FMT "I64"
143 #endif
144 #else
145 #define DWARF_VMA_FMT "l"
146 #endif
148 static const char *
149 dwarf_vmatoa (const char *fmtch, dwarf_vma value)
151 /* As dwarf_vmatoa is used more then once in a printf call
152 for output, we are cycling through an fixed array of pointers
153 for return address. */
154 static int buf_pos = 0;
155 static struct dwarf_vmatoa_buf
157 char place[64];
158 } buf[16];
159 char fmt[32];
160 char *ret;
162 sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
164 ret = buf[buf_pos++].place;
165 buf_pos %= ARRAY_SIZE (buf);
167 snprintf (ret, sizeof (buf[0].place), fmt, value);
169 return ret;
172 dwarf_vma
173 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
175 dwarf_vma result = 0;
176 unsigned int num_read = 0;
177 unsigned int shift = 0;
178 unsigned char byte;
182 byte = *data++;
183 num_read++;
185 result |= ((dwarf_vma) (byte & 0x7f)) << shift;
187 shift += 7;
190 while (byte & 0x80);
192 if (length_return != NULL)
193 *length_return = num_read;
195 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
196 result |= -1L << shift;
198 return result;
201 /* Create a signed version to avoid painful typecasts. */
202 static dwarf_signed_vma
203 read_sleb128 (unsigned char *data, unsigned int *length_return)
205 return (dwarf_signed_vma) read_leb128 (data, length_return, 1);
208 typedef struct State_Machine_Registers
210 dwarf_vma address;
211 unsigned int file;
212 unsigned int line;
213 unsigned int column;
214 int is_stmt;
215 int basic_block;
216 unsigned char op_index;
217 unsigned char end_sequence;
218 /* This variable hold the number of the last entry seen
219 in the File Table. */
220 unsigned int last_file_entry;
221 } SMR;
223 static SMR state_machine_regs;
225 static void
226 reset_state_machine (int is_stmt)
228 state_machine_regs.address = 0;
229 state_machine_regs.op_index = 0;
230 state_machine_regs.file = 1;
231 state_machine_regs.line = 1;
232 state_machine_regs.column = 0;
233 state_machine_regs.is_stmt = is_stmt;
234 state_machine_regs.basic_block = 0;
235 state_machine_regs.end_sequence = 0;
236 state_machine_regs.last_file_entry = 0;
239 /* Handled an extend line op.
240 Returns the number of bytes read. */
242 static int
243 process_extended_line_op (unsigned char *data, int is_stmt)
245 unsigned char op_code;
246 unsigned int bytes_read;
247 unsigned int len;
248 unsigned char *name;
249 dwarf_vma adr;
251 len = read_leb128 (data, & bytes_read, 0);
252 data += bytes_read;
254 if (len == 0)
256 warn (_("badly formed extended line op encountered!\n"));
257 return bytes_read;
260 len += bytes_read;
261 op_code = *data++;
263 printf (_(" Extended opcode %d: "), op_code);
265 switch (op_code)
267 case DW_LNE_end_sequence:
268 printf (_("End of Sequence\n\n"));
269 reset_state_machine (is_stmt);
270 break;
272 case DW_LNE_set_address:
273 adr = byte_get (data, len - bytes_read - 1);
274 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
275 state_machine_regs.address = adr;
276 state_machine_regs.op_index = 0;
277 break;
279 case DW_LNE_define_file:
280 printf (_(" define new File Table entry\n"));
281 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
283 printf (" %d\t", ++state_machine_regs.last_file_entry);
284 name = data;
285 data += strlen ((char *) data) + 1;
286 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
287 data += bytes_read;
288 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
289 data += bytes_read;
290 printf ("%s\t", dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
291 printf ("%s\n\n", name);
292 break;
294 case DW_LNE_set_discriminator:
295 printf (_("set Discriminator to %s\n"),
296 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
297 break;
299 /* HP extensions. */
300 case DW_LNE_HP_negate_is_UV_update:
301 printf ("DW_LNE_HP_negate_is_UV_update\n");
302 break;
303 case DW_LNE_HP_push_context:
304 printf ("DW_LNE_HP_push_context\n");
305 break;
306 case DW_LNE_HP_pop_context:
307 printf ("DW_LNE_HP_pop_context\n");
308 break;
309 case DW_LNE_HP_set_file_line_column:
310 printf ("DW_LNE_HP_set_file_line_column\n");
311 break;
312 case DW_LNE_HP_set_routine_name:
313 printf ("DW_LNE_HP_set_routine_name\n");
314 break;
315 case DW_LNE_HP_set_sequence:
316 printf ("DW_LNE_HP_set_sequence\n");
317 break;
318 case DW_LNE_HP_negate_post_semantics:
319 printf ("DW_LNE_HP_negate_post_semantics\n");
320 break;
321 case DW_LNE_HP_negate_function_exit:
322 printf ("DW_LNE_HP_negate_function_exit\n");
323 break;
324 case DW_LNE_HP_negate_front_end_logical:
325 printf ("DW_LNE_HP_negate_front_end_logical\n");
326 break;
327 case DW_LNE_HP_define_proc:
328 printf ("DW_LNE_HP_define_proc\n");
329 break;
330 case DW_LNE_HP_source_file_correlation:
332 unsigned char *edata = data + len - bytes_read - 1;
334 printf ("DW_LNE_HP_source_file_correlation\n");
336 while (data < edata)
338 unsigned int opc;
340 opc = read_leb128 (data, & bytes_read, 0);
341 data += bytes_read;
343 switch (opc)
345 case DW_LNE_HP_SFC_formfeed:
346 printf (" DW_LNE_HP_SFC_formfeed\n");
347 break;
348 case DW_LNE_HP_SFC_set_listing_line:
349 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
350 dwarf_vmatoa ("u",
351 read_leb128 (data, & bytes_read, 0)));
352 data += bytes_read;
353 break;
354 case DW_LNE_HP_SFC_associate:
355 printf (" DW_LNE_HP_SFC_associate ");
356 printf ("(%s",
357 dwarf_vmatoa ("u",
358 read_leb128 (data, & bytes_read, 0)));
359 data += bytes_read;
360 printf (",%s",
361 dwarf_vmatoa ("u",
362 read_leb128 (data, & bytes_read, 0)));
363 data += bytes_read;
364 printf (",%s)\n",
365 dwarf_vmatoa ("u",
366 read_leb128 (data, & bytes_read, 0)));
367 data += bytes_read;
368 break;
369 default:
370 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc);
371 data = edata;
372 break;
376 break;
378 default:
380 unsigned int rlen = len - bytes_read - 1;
382 if (op_code >= DW_LNE_lo_user
383 /* The test against DW_LNW_hi_user is redundant due to
384 the limited range of the unsigned char data type used
385 for op_code. */
386 /*&& op_code <= DW_LNE_hi_user*/)
387 printf (_("user defined: "));
388 else
389 printf (_("UNKNOWN: "));
390 printf (_("length %d ["), rlen);
391 for (; rlen; rlen--)
392 printf (" %02x", *data++);
393 printf ("]\n");
395 break;
398 return len;
401 static const char *
402 fetch_indirect_string (dwarf_vma offset)
404 struct dwarf_section *section = &debug_displays [str].section;
406 if (section->start == NULL)
407 return _("<no .debug_str section>");
409 /* DWARF sections under Mach-O have non-zero addresses. */
410 offset -= section->address;
411 if (offset > section->size)
413 warn (_("DW_FORM_strp offset too big: %s\n"),
414 dwarf_vmatoa ("x", offset));
415 return _("<offset is too big>");
418 return (const char *) section->start + offset;
421 /* FIXME: There are better and more efficient ways to handle
422 these structures. For now though, I just want something that
423 is simple to implement. */
424 typedef struct abbrev_attr
426 unsigned long attribute;
427 unsigned long form;
428 struct abbrev_attr *next;
430 abbrev_attr;
432 typedef struct abbrev_entry
434 unsigned long entry;
435 unsigned long tag;
436 int children;
437 struct abbrev_attr *first_attr;
438 struct abbrev_attr *last_attr;
439 struct abbrev_entry *next;
441 abbrev_entry;
443 static abbrev_entry *first_abbrev = NULL;
444 static abbrev_entry *last_abbrev = NULL;
446 static void
447 free_abbrevs (void)
449 abbrev_entry *abbrv;
451 for (abbrv = first_abbrev; abbrv;)
453 abbrev_entry *next_abbrev = abbrv->next;
454 abbrev_attr *attr;
456 for (attr = abbrv->first_attr; attr;)
458 abbrev_attr *next_attr = attr->next;
460 free (attr);
461 attr = next_attr;
464 free (abbrv);
465 abbrv = next_abbrev;
468 last_abbrev = first_abbrev = NULL;
471 static void
472 add_abbrev (unsigned long number, unsigned long tag, int children)
474 abbrev_entry *entry;
476 entry = (abbrev_entry *) malloc (sizeof (*entry));
477 if (entry == NULL)
478 /* ugg */
479 return;
481 entry->entry = number;
482 entry->tag = tag;
483 entry->children = children;
484 entry->first_attr = NULL;
485 entry->last_attr = NULL;
486 entry->next = NULL;
488 if (first_abbrev == NULL)
489 first_abbrev = entry;
490 else
491 last_abbrev->next = entry;
493 last_abbrev = entry;
496 static void
497 add_abbrev_attr (unsigned long attribute, unsigned long form)
499 abbrev_attr *attr;
501 attr = (abbrev_attr *) malloc (sizeof (*attr));
502 if (attr == NULL)
503 /* ugg */
504 return;
506 attr->attribute = attribute;
507 attr->form = form;
508 attr->next = NULL;
510 if (last_abbrev->first_attr == NULL)
511 last_abbrev->first_attr = attr;
512 else
513 last_abbrev->last_attr->next = attr;
515 last_abbrev->last_attr = attr;
518 /* Processes the (partial) contents of a .debug_abbrev section.
519 Returns NULL if the end of the section was encountered.
520 Returns the address after the last byte read if the end of
521 an abbreviation set was found. */
523 static unsigned char *
524 process_abbrev_section (unsigned char *start, unsigned char *end)
526 if (first_abbrev != NULL)
527 return NULL;
529 while (start < end)
531 unsigned int bytes_read;
532 unsigned long entry;
533 unsigned long tag;
534 unsigned long attribute;
535 int children;
537 entry = read_leb128 (start, & bytes_read, 0);
538 start += bytes_read;
540 /* A single zero is supposed to end the section according
541 to the standard. If there's more, then signal that to
542 the caller. */
543 if (entry == 0)
544 return start == end ? NULL : start;
546 tag = read_leb128 (start, & bytes_read, 0);
547 start += bytes_read;
549 children = *start++;
551 add_abbrev (entry, tag, children);
555 unsigned long form;
557 attribute = read_leb128 (start, & bytes_read, 0);
558 start += bytes_read;
560 form = read_leb128 (start, & bytes_read, 0);
561 start += bytes_read;
563 if (attribute != 0)
564 add_abbrev_attr (attribute, form);
566 while (attribute != 0);
569 return NULL;
572 static char *
573 get_TAG_name (unsigned long tag)
575 switch (tag)
577 case DW_TAG_padding: return "DW_TAG_padding";
578 case DW_TAG_array_type: return "DW_TAG_array_type";
579 case DW_TAG_class_type: return "DW_TAG_class_type";
580 case DW_TAG_entry_point: return "DW_TAG_entry_point";
581 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
582 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
583 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
584 case DW_TAG_label: return "DW_TAG_label";
585 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
586 case DW_TAG_member: return "DW_TAG_member";
587 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
588 case DW_TAG_reference_type: return "DW_TAG_reference_type";
589 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
590 case DW_TAG_string_type: return "DW_TAG_string_type";
591 case DW_TAG_structure_type: return "DW_TAG_structure_type";
592 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
593 case DW_TAG_typedef: return "DW_TAG_typedef";
594 case DW_TAG_union_type: return "DW_TAG_union_type";
595 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
596 case DW_TAG_variant: return "DW_TAG_variant";
597 case DW_TAG_common_block: return "DW_TAG_common_block";
598 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
599 case DW_TAG_inheritance: return "DW_TAG_inheritance";
600 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
601 case DW_TAG_module: return "DW_TAG_module";
602 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
603 case DW_TAG_set_type: return "DW_TAG_set_type";
604 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
605 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
606 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
607 case DW_TAG_base_type: return "DW_TAG_base_type";
608 case DW_TAG_catch_block: return "DW_TAG_catch_block";
609 case DW_TAG_const_type: return "DW_TAG_const_type";
610 case DW_TAG_constant: return "DW_TAG_constant";
611 case DW_TAG_enumerator: return "DW_TAG_enumerator";
612 case DW_TAG_file_type: return "DW_TAG_file_type";
613 case DW_TAG_friend: return "DW_TAG_friend";
614 case DW_TAG_namelist: return "DW_TAG_namelist";
615 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
616 case DW_TAG_packed_type: return "DW_TAG_packed_type";
617 case DW_TAG_subprogram: return "DW_TAG_subprogram";
618 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
619 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
620 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
621 case DW_TAG_try_block: return "DW_TAG_try_block";
622 case DW_TAG_variant_part: return "DW_TAG_variant_part";
623 case DW_TAG_variable: return "DW_TAG_variable";
624 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
625 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
626 case DW_TAG_format_label: return "DW_TAG_format_label";
627 case DW_TAG_function_template: return "DW_TAG_function_template";
628 case DW_TAG_class_template: return "DW_TAG_class_template";
629 /* DWARF 2.1 values. */
630 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
631 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
632 case DW_TAG_interface_type: return "DW_TAG_interface_type";
633 case DW_TAG_namespace: return "DW_TAG_namespace";
634 case DW_TAG_imported_module: return "DW_TAG_imported_module";
635 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
636 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
637 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
638 case DW_TAG_condition: return "DW_TAG_condition";
639 case DW_TAG_shared_type: return "DW_TAG_shared_type";
640 /* DWARF 4 values. */
641 case DW_TAG_type_unit: return "DW_TAG_type_unit";
642 case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type";
643 case DW_TAG_template_alias: return "DW_TAG_template_alias";
644 /* UPC values. */
645 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
646 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
647 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
648 /* GNU values. */
649 case DW_TAG_GNU_call_site: return "DW_TAG_GNU_call_site";
650 case DW_TAG_GNU_call_site_parameter:return "DW_TAG_GNU_call_site_parameter";
651 default:
653 static char buffer[100];
655 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
656 return buffer;
661 static char *
662 get_FORM_name (unsigned long form)
664 switch (form)
666 case DW_FORM_addr: return "DW_FORM_addr";
667 case DW_FORM_block2: return "DW_FORM_block2";
668 case DW_FORM_block4: return "DW_FORM_block4";
669 case DW_FORM_data2: return "DW_FORM_data2";
670 case DW_FORM_data4: return "DW_FORM_data4";
671 case DW_FORM_data8: return "DW_FORM_data8";
672 case DW_FORM_string: return "DW_FORM_string";
673 case DW_FORM_block: return "DW_FORM_block";
674 case DW_FORM_block1: return "DW_FORM_block1";
675 case DW_FORM_data1: return "DW_FORM_data1";
676 case DW_FORM_flag: return "DW_FORM_flag";
677 case DW_FORM_sdata: return "DW_FORM_sdata";
678 case DW_FORM_strp: return "DW_FORM_strp";
679 case DW_FORM_udata: return "DW_FORM_udata";
680 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
681 case DW_FORM_ref1: return "DW_FORM_ref1";
682 case DW_FORM_ref2: return "DW_FORM_ref2";
683 case DW_FORM_ref4: return "DW_FORM_ref4";
684 case DW_FORM_ref8: return "DW_FORM_ref8";
685 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
686 case DW_FORM_indirect: return "DW_FORM_indirect";
687 /* DWARF 4 values. */
688 case DW_FORM_sec_offset: return "DW_FORM_sec_offset";
689 case DW_FORM_exprloc: return "DW_FORM_exprloc";
690 case DW_FORM_flag_present: return "DW_FORM_flag_present";
691 case DW_FORM_ref_sig8: return "DW_FORM_ref_sig8";
692 default:
694 static char buffer[100];
696 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
697 return buffer;
702 static unsigned char *
703 display_block (unsigned char *data, dwarf_vma length)
705 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length));
707 while (length --)
708 printf ("%lx ", (unsigned long) byte_get (data++, 1));
710 return data;
713 static int
714 decode_location_expression (unsigned char * data,
715 unsigned int pointer_size,
716 unsigned int offset_size,
717 int dwarf_version,
718 dwarf_vma length,
719 dwarf_vma cu_offset,
720 struct dwarf_section * section)
722 unsigned op;
723 unsigned int bytes_read;
724 dwarf_vma uvalue;
725 unsigned char *end = data + length;
726 int need_frame_base = 0;
728 while (data < end)
730 op = *data++;
732 switch (op)
734 case DW_OP_addr:
735 printf ("DW_OP_addr: %s",
736 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
737 data += pointer_size;
738 break;
739 case DW_OP_deref:
740 printf ("DW_OP_deref");
741 break;
742 case DW_OP_const1u:
743 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
744 break;
745 case DW_OP_const1s:
746 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
747 break;
748 case DW_OP_const2u:
749 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
750 data += 2;
751 break;
752 case DW_OP_const2s:
753 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
754 data += 2;
755 break;
756 case DW_OP_const4u:
757 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
758 data += 4;
759 break;
760 case DW_OP_const4s:
761 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
762 data += 4;
763 break;
764 case DW_OP_const8u:
765 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
766 (unsigned long) byte_get (data + 4, 4));
767 data += 8;
768 break;
769 case DW_OP_const8s:
770 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
771 (long) byte_get (data + 4, 4));
772 data += 8;
773 break;
774 case DW_OP_constu:
775 printf ("DW_OP_constu: %s",
776 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
777 data += bytes_read;
778 break;
779 case DW_OP_consts:
780 printf ("DW_OP_consts: %s",
781 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
782 data += bytes_read;
783 break;
784 case DW_OP_dup:
785 printf ("DW_OP_dup");
786 break;
787 case DW_OP_drop:
788 printf ("DW_OP_drop");
789 break;
790 case DW_OP_over:
791 printf ("DW_OP_over");
792 break;
793 case DW_OP_pick:
794 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
795 break;
796 case DW_OP_swap:
797 printf ("DW_OP_swap");
798 break;
799 case DW_OP_rot:
800 printf ("DW_OP_rot");
801 break;
802 case DW_OP_xderef:
803 printf ("DW_OP_xderef");
804 break;
805 case DW_OP_abs:
806 printf ("DW_OP_abs");
807 break;
808 case DW_OP_and:
809 printf ("DW_OP_and");
810 break;
811 case DW_OP_div:
812 printf ("DW_OP_div");
813 break;
814 case DW_OP_minus:
815 printf ("DW_OP_minus");
816 break;
817 case DW_OP_mod:
818 printf ("DW_OP_mod");
819 break;
820 case DW_OP_mul:
821 printf ("DW_OP_mul");
822 break;
823 case DW_OP_neg:
824 printf ("DW_OP_neg");
825 break;
826 case DW_OP_not:
827 printf ("DW_OP_not");
828 break;
829 case DW_OP_or:
830 printf ("DW_OP_or");
831 break;
832 case DW_OP_plus:
833 printf ("DW_OP_plus");
834 break;
835 case DW_OP_plus_uconst:
836 printf ("DW_OP_plus_uconst: %s",
837 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
838 data += bytes_read;
839 break;
840 case DW_OP_shl:
841 printf ("DW_OP_shl");
842 break;
843 case DW_OP_shr:
844 printf ("DW_OP_shr");
845 break;
846 case DW_OP_shra:
847 printf ("DW_OP_shra");
848 break;
849 case DW_OP_xor:
850 printf ("DW_OP_xor");
851 break;
852 case DW_OP_bra:
853 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
854 data += 2;
855 break;
856 case DW_OP_eq:
857 printf ("DW_OP_eq");
858 break;
859 case DW_OP_ge:
860 printf ("DW_OP_ge");
861 break;
862 case DW_OP_gt:
863 printf ("DW_OP_gt");
864 break;
865 case DW_OP_le:
866 printf ("DW_OP_le");
867 break;
868 case DW_OP_lt:
869 printf ("DW_OP_lt");
870 break;
871 case DW_OP_ne:
872 printf ("DW_OP_ne");
873 break;
874 case DW_OP_skip:
875 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
876 data += 2;
877 break;
879 case DW_OP_lit0:
880 case DW_OP_lit1:
881 case DW_OP_lit2:
882 case DW_OP_lit3:
883 case DW_OP_lit4:
884 case DW_OP_lit5:
885 case DW_OP_lit6:
886 case DW_OP_lit7:
887 case DW_OP_lit8:
888 case DW_OP_lit9:
889 case DW_OP_lit10:
890 case DW_OP_lit11:
891 case DW_OP_lit12:
892 case DW_OP_lit13:
893 case DW_OP_lit14:
894 case DW_OP_lit15:
895 case DW_OP_lit16:
896 case DW_OP_lit17:
897 case DW_OP_lit18:
898 case DW_OP_lit19:
899 case DW_OP_lit20:
900 case DW_OP_lit21:
901 case DW_OP_lit22:
902 case DW_OP_lit23:
903 case DW_OP_lit24:
904 case DW_OP_lit25:
905 case DW_OP_lit26:
906 case DW_OP_lit27:
907 case DW_OP_lit28:
908 case DW_OP_lit29:
909 case DW_OP_lit30:
910 case DW_OP_lit31:
911 printf ("DW_OP_lit%d", op - DW_OP_lit0);
912 break;
914 case DW_OP_reg0:
915 case DW_OP_reg1:
916 case DW_OP_reg2:
917 case DW_OP_reg3:
918 case DW_OP_reg4:
919 case DW_OP_reg5:
920 case DW_OP_reg6:
921 case DW_OP_reg7:
922 case DW_OP_reg8:
923 case DW_OP_reg9:
924 case DW_OP_reg10:
925 case DW_OP_reg11:
926 case DW_OP_reg12:
927 case DW_OP_reg13:
928 case DW_OP_reg14:
929 case DW_OP_reg15:
930 case DW_OP_reg16:
931 case DW_OP_reg17:
932 case DW_OP_reg18:
933 case DW_OP_reg19:
934 case DW_OP_reg20:
935 case DW_OP_reg21:
936 case DW_OP_reg22:
937 case DW_OP_reg23:
938 case DW_OP_reg24:
939 case DW_OP_reg25:
940 case DW_OP_reg26:
941 case DW_OP_reg27:
942 case DW_OP_reg28:
943 case DW_OP_reg29:
944 case DW_OP_reg30:
945 case DW_OP_reg31:
946 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
947 regname (op - DW_OP_reg0, 1));
948 break;
950 case DW_OP_breg0:
951 case DW_OP_breg1:
952 case DW_OP_breg2:
953 case DW_OP_breg3:
954 case DW_OP_breg4:
955 case DW_OP_breg5:
956 case DW_OP_breg6:
957 case DW_OP_breg7:
958 case DW_OP_breg8:
959 case DW_OP_breg9:
960 case DW_OP_breg10:
961 case DW_OP_breg11:
962 case DW_OP_breg12:
963 case DW_OP_breg13:
964 case DW_OP_breg14:
965 case DW_OP_breg15:
966 case DW_OP_breg16:
967 case DW_OP_breg17:
968 case DW_OP_breg18:
969 case DW_OP_breg19:
970 case DW_OP_breg20:
971 case DW_OP_breg21:
972 case DW_OP_breg22:
973 case DW_OP_breg23:
974 case DW_OP_breg24:
975 case DW_OP_breg25:
976 case DW_OP_breg26:
977 case DW_OP_breg27:
978 case DW_OP_breg28:
979 case DW_OP_breg29:
980 case DW_OP_breg30:
981 case DW_OP_breg31:
982 printf ("DW_OP_breg%d (%s): %s",
983 op - DW_OP_breg0,
984 regname (op - DW_OP_breg0, 1),
985 dwarf_vmatoa ("d", (dwarf_signed_vma)
986 read_leb128 (data, &bytes_read, 1)));
987 data += bytes_read;
988 break;
990 case DW_OP_regx:
991 uvalue = read_leb128 (data, &bytes_read, 0);
992 data += bytes_read;
993 printf ("DW_OP_regx: %s (%s)",
994 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
995 break;
996 case DW_OP_fbreg:
997 need_frame_base = 1;
998 printf ("DW_OP_fbreg: %s",
999 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1000 data += bytes_read;
1001 break;
1002 case DW_OP_bregx:
1003 uvalue = read_leb128 (data, &bytes_read, 0);
1004 data += bytes_read;
1005 printf ("DW_OP_bregx: %s (%s) %s",
1006 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1),
1007 dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read)));
1008 data += bytes_read;
1009 break;
1010 case DW_OP_piece:
1011 printf ("DW_OP_piece: %s",
1012 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1013 data += bytes_read;
1014 break;
1015 case DW_OP_deref_size:
1016 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
1017 break;
1018 case DW_OP_xderef_size:
1019 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
1020 break;
1021 case DW_OP_nop:
1022 printf ("DW_OP_nop");
1023 break;
1025 /* DWARF 3 extensions. */
1026 case DW_OP_push_object_address:
1027 printf ("DW_OP_push_object_address");
1028 break;
1029 case DW_OP_call2:
1030 /* XXX: Strictly speaking for 64-bit DWARF3 files
1031 this ought to be an 8-byte wide computation. */
1032 printf ("DW_OP_call2: <0x%s>",
1033 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 2)
1034 + cu_offset));
1035 data += 2;
1036 break;
1037 case DW_OP_call4:
1038 /* XXX: Strictly speaking for 64-bit DWARF3 files
1039 this ought to be an 8-byte wide computation. */
1040 printf ("DW_OP_call4: <0x%s>",
1041 dwarf_vmatoa ("x", (dwarf_signed_vma) byte_get (data, 4)
1042 + cu_offset));
1043 data += 4;
1044 break;
1045 case DW_OP_call_ref:
1046 /* XXX: Strictly speaking for 64-bit DWARF3 files
1047 this ought to be an 8-byte wide computation. */
1048 if (dwarf_version == -1)
1050 printf (_("(DW_OP_call_ref in frame info)"));
1051 /* No way to tell where the next op is, so just bail. */
1052 return need_frame_base;
1054 if (dwarf_version == 2)
1056 printf ("DW_OP_call_ref: <0x%s>",
1057 dwarf_vmatoa ("x", byte_get (data, pointer_size)));
1058 data += pointer_size;
1060 else
1062 printf ("DW_OP_call_ref: <0x%s>",
1063 dwarf_vmatoa ("x", byte_get (data, offset_size)));
1064 data += offset_size;
1066 break;
1067 case DW_OP_form_tls_address:
1068 printf ("DW_OP_form_tls_address");
1069 break;
1070 case DW_OP_call_frame_cfa:
1071 printf ("DW_OP_call_frame_cfa");
1072 break;
1073 case DW_OP_bit_piece:
1074 printf ("DW_OP_bit_piece: ");
1075 printf (_("size: %s "),
1076 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1077 data += bytes_read;
1078 printf (_("offset: %s "),
1079 dwarf_vmatoa ("u", read_leb128 (data, &bytes_read, 0)));
1080 data += bytes_read;
1081 break;
1083 /* DWARF 4 extensions. */
1084 case DW_OP_stack_value:
1085 printf ("DW_OP_stack_value");
1086 break;
1088 case DW_OP_implicit_value:
1089 printf ("DW_OP_implicit_value");
1090 uvalue = read_leb128 (data, &bytes_read, 0);
1091 data += bytes_read;
1092 display_block (data, uvalue);
1093 data += uvalue;
1094 break;
1096 /* GNU extensions. */
1097 case DW_OP_GNU_push_tls_address:
1098 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1099 break;
1100 case DW_OP_GNU_uninit:
1101 printf ("DW_OP_GNU_uninit");
1102 /* FIXME: Is there data associated with this OP ? */
1103 break;
1104 case DW_OP_GNU_encoded_addr:
1106 int encoding;
1107 dwarf_vma addr;
1109 encoding = *data++;
1110 addr = get_encoded_value (data, encoding, section);
1111 data += size_of_encoded_value (encoding);
1113 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1114 print_dwarf_vma (addr, pointer_size);
1116 break;
1117 case DW_OP_GNU_implicit_pointer:
1118 /* XXX: Strictly speaking for 64-bit DWARF3 files
1119 this ought to be an 8-byte wide computation. */
1120 if (dwarf_version == -1)
1122 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1123 /* No way to tell where the next op is, so just bail. */
1124 return need_frame_base;
1126 if (dwarf_version == 2)
1128 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1129 dwarf_vmatoa ("x", byte_get (data, pointer_size)),
1130 dwarf_vmatoa ("d", read_sleb128 (data + pointer_size,
1131 &bytes_read)));
1132 data += pointer_size + bytes_read;
1134 else
1136 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1137 dwarf_vmatoa ("x", byte_get (data, offset_size)),
1138 dwarf_vmatoa ("d", read_sleb128 (data + offset_size,
1139 &bytes_read)));
1140 data += offset_size + bytes_read;
1142 break;
1143 case DW_OP_GNU_entry_value:
1144 uvalue = read_leb128 (data, &bytes_read, 0);
1145 data += bytes_read;
1146 printf ("DW_OP_GNU_entry_value: (");
1147 if (decode_location_expression (data, pointer_size, offset_size,
1148 dwarf_version, uvalue,
1149 cu_offset, section))
1150 need_frame_base = 1;
1151 putchar (')');
1152 data += uvalue;
1153 break;
1154 case DW_OP_GNU_const_type:
1155 uvalue = read_leb128 (data, &bytes_read, 0);
1156 data += bytes_read;
1157 printf ("DW_OP_GNU_const_type: <0x%s> ",
1158 dwarf_vmatoa ("x", cu_offset + uvalue));
1159 uvalue = byte_get (data++, 1);
1160 display_block (data, uvalue);
1161 data += uvalue;
1162 break;
1163 case DW_OP_GNU_regval_type:
1164 uvalue = read_leb128 (data, &bytes_read, 0);
1165 data += bytes_read;
1166 printf ("DW_OP_GNU_regval_type: %s (%s)",
1167 dwarf_vmatoa ("u", uvalue), regname (uvalue, 1));
1168 uvalue = read_leb128 (data, &bytes_read, 0);
1169 data += bytes_read;
1170 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1171 break;
1172 case DW_OP_GNU_deref_type:
1173 printf ("DW_OP_GNU_deref_type: %ld", (long) byte_get (data++, 1));
1174 uvalue = read_leb128 (data, &bytes_read, 0);
1175 data += bytes_read;
1176 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue));
1177 break;
1178 case DW_OP_GNU_convert:
1179 uvalue = read_leb128 (data, &bytes_read, 0);
1180 data += bytes_read;
1181 printf ("DW_OP_GNU_convert <0x%s>",
1182 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1183 break;
1184 case DW_OP_GNU_reinterpret:
1185 uvalue = read_leb128 (data, &bytes_read, 0);
1186 data += bytes_read;
1187 printf ("DW_OP_GNU_reinterpret <0x%s>",
1188 dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
1189 break;
1190 case DW_OP_GNU_parameter_ref:
1191 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1192 dwarf_vmatoa ("x", cu_offset + byte_get (data, 4)));
1193 data += 4;
1194 break;
1196 /* HP extensions. */
1197 case DW_OP_HP_is_value:
1198 printf ("DW_OP_HP_is_value");
1199 /* FIXME: Is there data associated with this OP ? */
1200 break;
1201 case DW_OP_HP_fltconst4:
1202 printf ("DW_OP_HP_fltconst4");
1203 /* FIXME: Is there data associated with this OP ? */
1204 break;
1205 case DW_OP_HP_fltconst8:
1206 printf ("DW_OP_HP_fltconst8");
1207 /* FIXME: Is there data associated with this OP ? */
1208 break;
1209 case DW_OP_HP_mod_range:
1210 printf ("DW_OP_HP_mod_range");
1211 /* FIXME: Is there data associated with this OP ? */
1212 break;
1213 case DW_OP_HP_unmod_range:
1214 printf ("DW_OP_HP_unmod_range");
1215 /* FIXME: Is there data associated with this OP ? */
1216 break;
1217 case DW_OP_HP_tls:
1218 printf ("DW_OP_HP_tls");
1219 /* FIXME: Is there data associated with this OP ? */
1220 break;
1222 /* PGI (STMicroelectronics) extensions. */
1223 case DW_OP_PGI_omp_thread_num:
1224 /* Pushes the thread number for the current thread as it would be
1225 returned by the standard OpenMP library function:
1226 omp_get_thread_num(). The "current thread" is the thread for
1227 which the expression is being evaluated. */
1228 printf ("DW_OP_PGI_omp_thread_num");
1229 break;
1231 default:
1232 if (op >= DW_OP_lo_user
1233 && op <= DW_OP_hi_user)
1234 printf (_("(User defined location op)"));
1235 else
1236 printf (_("(Unknown location op)"));
1237 /* No way to tell where the next op is, so just bail. */
1238 return need_frame_base;
1241 /* Separate the ops. */
1242 if (data < end)
1243 printf ("; ");
1246 return need_frame_base;
1249 static unsigned char *
1250 read_and_display_attr_value (unsigned long attribute,
1251 unsigned long form,
1252 unsigned char * data,
1253 dwarf_vma cu_offset,
1254 dwarf_vma pointer_size,
1255 dwarf_vma offset_size,
1256 int dwarf_version,
1257 debug_info * debug_info_p,
1258 int do_loc,
1259 struct dwarf_section * section)
1261 dwarf_vma uvalue = 0;
1262 unsigned char *block_start = NULL;
1263 unsigned char * orig_data = data;
1264 unsigned int bytes_read;
1266 switch (form)
1268 default:
1269 break;
1271 case DW_FORM_ref_addr:
1272 if (dwarf_version == 2)
1274 uvalue = byte_get (data, pointer_size);
1275 data += pointer_size;
1277 else if (dwarf_version == 3 || dwarf_version == 4)
1279 uvalue = byte_get (data, offset_size);
1280 data += offset_size;
1282 else
1283 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1285 break;
1287 case DW_FORM_addr:
1288 uvalue = byte_get (data, pointer_size);
1289 data += pointer_size;
1290 break;
1292 case DW_FORM_strp:
1293 case DW_FORM_sec_offset:
1294 uvalue = byte_get (data, offset_size);
1295 data += offset_size;
1296 break;
1298 case DW_FORM_flag_present:
1299 uvalue = 1;
1300 break;
1302 case DW_FORM_ref1:
1303 case DW_FORM_flag:
1304 case DW_FORM_data1:
1305 uvalue = byte_get (data++, 1);
1306 break;
1308 case DW_FORM_ref2:
1309 case DW_FORM_data2:
1310 uvalue = byte_get (data, 2);
1311 data += 2;
1312 break;
1314 case DW_FORM_ref4:
1315 case DW_FORM_data4:
1316 uvalue = byte_get (data, 4);
1317 data += 4;
1318 break;
1320 case DW_FORM_sdata:
1321 uvalue = read_leb128 (data, & bytes_read, 1);
1322 data += bytes_read;
1323 break;
1325 case DW_FORM_ref_udata:
1326 case DW_FORM_udata:
1327 uvalue = read_leb128 (data, & bytes_read, 0);
1328 data += bytes_read;
1329 break;
1331 case DW_FORM_indirect:
1332 form = read_leb128 (data, & bytes_read, 0);
1333 data += bytes_read;
1334 if (!do_loc)
1335 printf (" %s", get_FORM_name (form));
1336 return read_and_display_attr_value (attribute, form, data,
1337 cu_offset, pointer_size,
1338 offset_size, dwarf_version,
1339 debug_info_p, do_loc,
1340 section);
1343 switch (form)
1345 case DW_FORM_ref_addr:
1346 if (!do_loc)
1347 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue));
1348 break;
1350 case DW_FORM_ref1:
1351 case DW_FORM_ref2:
1352 case DW_FORM_ref4:
1353 case DW_FORM_ref_udata:
1354 if (!do_loc)
1355 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset));
1356 break;
1358 case DW_FORM_data4:
1359 case DW_FORM_addr:
1360 case DW_FORM_sec_offset:
1361 if (!do_loc)
1362 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1363 break;
1365 case DW_FORM_flag_present:
1366 case DW_FORM_flag:
1367 case DW_FORM_data1:
1368 case DW_FORM_data2:
1369 case DW_FORM_sdata:
1370 case DW_FORM_udata:
1371 if (!do_loc)
1372 printf (" %s", dwarf_vmatoa ("d", uvalue));
1373 break;
1375 case DW_FORM_ref8:
1376 case DW_FORM_data8:
1377 if (!do_loc)
1379 uvalue = byte_get (data, 4);
1380 printf (" 0x%s", dwarf_vmatoa ("x", uvalue));
1381 printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
1383 if ((do_loc || do_debug_loc || do_debug_ranges)
1384 && num_debug_info_entries == 0)
1386 if (sizeof (uvalue) == 8)
1387 uvalue = byte_get (data, 8);
1388 else
1389 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1391 data += 8;
1392 break;
1394 case DW_FORM_string:
1395 if (!do_loc)
1396 printf (" %s", data);
1397 data += strlen ((char *) data) + 1;
1398 break;
1400 case DW_FORM_block:
1401 case DW_FORM_exprloc:
1402 uvalue = read_leb128 (data, & bytes_read, 0);
1403 block_start = data + bytes_read;
1404 if (do_loc)
1405 data = block_start + uvalue;
1406 else
1407 data = display_block (block_start, uvalue);
1408 break;
1410 case DW_FORM_block1:
1411 uvalue = byte_get (data, 1);
1412 block_start = data + 1;
1413 if (do_loc)
1414 data = block_start + uvalue;
1415 else
1416 data = display_block (block_start, uvalue);
1417 break;
1419 case DW_FORM_block2:
1420 uvalue = byte_get (data, 2);
1421 block_start = data + 2;
1422 if (do_loc)
1423 data = block_start + uvalue;
1424 else
1425 data = display_block (block_start, uvalue);
1426 break;
1428 case DW_FORM_block4:
1429 uvalue = byte_get (data, 4);
1430 block_start = data + 4;
1431 if (do_loc)
1432 data = block_start + uvalue;
1433 else
1434 data = display_block (block_start, uvalue);
1435 break;
1437 case DW_FORM_strp:
1438 if (!do_loc)
1439 printf (_(" (indirect string, offset: 0x%s): %s"),
1440 dwarf_vmatoa ("x", uvalue),
1441 fetch_indirect_string (uvalue));
1442 break;
1444 case DW_FORM_indirect:
1445 /* Handled above. */
1446 break;
1448 case DW_FORM_ref_sig8:
1449 if (!do_loc)
1451 int i;
1452 printf (" signature: ");
1453 for (i = 0; i < 8; i++)
1455 printf ("%02x", (unsigned) byte_get (data, 1));
1456 data += 1;
1459 else
1460 data += 8;
1461 break;
1463 default:
1464 warn (_("Unrecognized form: %lu\n"), form);
1465 break;
1468 if ((do_loc || do_debug_loc || do_debug_ranges)
1469 && num_debug_info_entries == 0
1470 && debug_info_p != NULL)
1472 switch (attribute)
1474 case DW_AT_frame_base:
1475 have_frame_base = 1;
1476 case DW_AT_location:
1477 case DW_AT_string_length:
1478 case DW_AT_return_addr:
1479 case DW_AT_data_member_location:
1480 case DW_AT_vtable_elem_location:
1481 case DW_AT_segment:
1482 case DW_AT_static_link:
1483 case DW_AT_use_location:
1484 case DW_AT_GNU_call_site_value:
1485 case DW_AT_GNU_call_site_data_value:
1486 case DW_AT_GNU_call_site_target:
1487 case DW_AT_GNU_call_site_target_clobbered:
1488 if ((dwarf_version < 4
1489 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1490 || form == DW_FORM_sec_offset)
1492 /* Process location list. */
1493 unsigned int lmax = debug_info_p->max_loc_offsets;
1494 unsigned int num = debug_info_p->num_loc_offsets;
1496 if (lmax == 0 || num >= lmax)
1498 lmax += 1024;
1499 debug_info_p->loc_offsets = (dwarf_vma *)
1500 xcrealloc (debug_info_p->loc_offsets,
1501 lmax, sizeof (*debug_info_p->loc_offsets));
1502 debug_info_p->have_frame_base = (int *)
1503 xcrealloc (debug_info_p->have_frame_base,
1504 lmax, sizeof (*debug_info_p->have_frame_base));
1505 debug_info_p->max_loc_offsets = lmax;
1507 debug_info_p->loc_offsets [num] = uvalue;
1508 debug_info_p->have_frame_base [num] = have_frame_base;
1509 debug_info_p->num_loc_offsets++;
1511 break;
1513 case DW_AT_low_pc:
1514 if (need_base_address)
1515 debug_info_p->base_address = uvalue;
1516 break;
1518 case DW_AT_ranges:
1519 if ((dwarf_version < 4
1520 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1521 || form == DW_FORM_sec_offset)
1523 /* Process range list. */
1524 unsigned int lmax = debug_info_p->max_range_lists;
1525 unsigned int num = debug_info_p->num_range_lists;
1527 if (lmax == 0 || num >= lmax)
1529 lmax += 1024;
1530 debug_info_p->range_lists = (dwarf_vma *)
1531 xcrealloc (debug_info_p->range_lists,
1532 lmax, sizeof (*debug_info_p->range_lists));
1533 debug_info_p->max_range_lists = lmax;
1535 debug_info_p->range_lists [num] = uvalue;
1536 debug_info_p->num_range_lists++;
1538 break;
1540 default:
1541 break;
1545 if (do_loc || attribute == 0)
1546 return data;
1548 /* For some attributes we can display further information. */
1549 printf ("\t");
1551 switch (attribute)
1553 case DW_AT_inline:
1554 switch (uvalue)
1556 case DW_INL_not_inlined:
1557 printf (_("(not inlined)"));
1558 break;
1559 case DW_INL_inlined:
1560 printf (_("(inlined)"));
1561 break;
1562 case DW_INL_declared_not_inlined:
1563 printf (_("(declared as inline but ignored)"));
1564 break;
1565 case DW_INL_declared_inlined:
1566 printf (_("(declared as inline and inlined)"));
1567 break;
1568 default:
1569 printf (_(" (Unknown inline attribute value: %s)"),
1570 dwarf_vmatoa ("x", uvalue));
1571 break;
1573 break;
1575 case DW_AT_language:
1576 switch (uvalue)
1578 /* Ordered by the numeric value of these constants. */
1579 case DW_LANG_C89: printf ("(ANSI C)"); break;
1580 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1581 case DW_LANG_Ada83: printf ("(Ada)"); break;
1582 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1583 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1584 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1585 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1586 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1587 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1588 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1589 /* DWARF 2.1 values. */
1590 case DW_LANG_Java: printf ("(Java)"); break;
1591 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1592 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1593 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1594 /* DWARF 3 values. */
1595 case DW_LANG_PLI: printf ("(PLI)"); break;
1596 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1597 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1598 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1599 case DW_LANG_D: printf ("(D)"); break;
1600 /* DWARF 4 values. */
1601 case DW_LANG_Python: printf ("(Python)"); break;
1602 /* MIPS extension. */
1603 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1604 /* UPC extension. */
1605 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1606 default:
1607 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1608 printf (_("(implementation defined: %s)"),
1609 dwarf_vmatoa ("x", uvalue));
1610 else
1611 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1612 break;
1614 break;
1616 case DW_AT_encoding:
1617 switch (uvalue)
1619 case DW_ATE_void: printf ("(void)"); break;
1620 case DW_ATE_address: printf ("(machine address)"); break;
1621 case DW_ATE_boolean: printf ("(boolean)"); break;
1622 case DW_ATE_complex_float: printf ("(complex float)"); break;
1623 case DW_ATE_float: printf ("(float)"); break;
1624 case DW_ATE_signed: printf ("(signed)"); break;
1625 case DW_ATE_signed_char: printf ("(signed char)"); break;
1626 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1627 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1628 /* DWARF 2.1 values: */
1629 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1630 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1631 /* DWARF 3 values: */
1632 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1633 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1634 case DW_ATE_edited: printf ("(edited)"); break;
1635 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1636 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1637 /* HP extensions: */
1638 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1639 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1640 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1641 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1642 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1643 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1644 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1646 default:
1647 if (uvalue >= DW_ATE_lo_user
1648 && uvalue <= DW_ATE_hi_user)
1649 printf (_("(user defined type)"));
1650 else
1651 printf (_("(unknown type)"));
1652 break;
1654 break;
1656 case DW_AT_accessibility:
1657 switch (uvalue)
1659 case DW_ACCESS_public: printf ("(public)"); break;
1660 case DW_ACCESS_protected: printf ("(protected)"); break;
1661 case DW_ACCESS_private: printf ("(private)"); break;
1662 default:
1663 printf (_("(unknown accessibility)"));
1664 break;
1666 break;
1668 case DW_AT_visibility:
1669 switch (uvalue)
1671 case DW_VIS_local: printf ("(local)"); break;
1672 case DW_VIS_exported: printf ("(exported)"); break;
1673 case DW_VIS_qualified: printf ("(qualified)"); break;
1674 default: printf (_("(unknown visibility)")); break;
1676 break;
1678 case DW_AT_virtuality:
1679 switch (uvalue)
1681 case DW_VIRTUALITY_none: printf ("(none)"); break;
1682 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1683 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1684 default: printf (_("(unknown virtuality)")); break;
1686 break;
1688 case DW_AT_identifier_case:
1689 switch (uvalue)
1691 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1692 case DW_ID_up_case: printf ("(up_case)"); break;
1693 case DW_ID_down_case: printf ("(down_case)"); break;
1694 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1695 default: printf (_("(unknown case)")); break;
1697 break;
1699 case DW_AT_calling_convention:
1700 switch (uvalue)
1702 case DW_CC_normal: printf ("(normal)"); break;
1703 case DW_CC_program: printf ("(program)"); break;
1704 case DW_CC_nocall: printf ("(nocall)"); break;
1705 default:
1706 if (uvalue >= DW_CC_lo_user
1707 && uvalue <= DW_CC_hi_user)
1708 printf (_("(user defined)"));
1709 else
1710 printf (_("(unknown convention)"));
1712 break;
1714 case DW_AT_ordering:
1715 switch (uvalue)
1717 case -1: printf (_("(undefined)")); break;
1718 case 0: printf ("(row major)"); break;
1719 case 1: printf ("(column major)"); break;
1721 break;
1723 case DW_AT_frame_base:
1724 have_frame_base = 1;
1725 case DW_AT_location:
1726 case DW_AT_string_length:
1727 case DW_AT_return_addr:
1728 case DW_AT_data_member_location:
1729 case DW_AT_vtable_elem_location:
1730 case DW_AT_segment:
1731 case DW_AT_static_link:
1732 case DW_AT_use_location:
1733 case DW_AT_GNU_call_site_value:
1734 case DW_AT_GNU_call_site_data_value:
1735 case DW_AT_GNU_call_site_target:
1736 case DW_AT_GNU_call_site_target_clobbered:
1737 if ((dwarf_version < 4
1738 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1739 || form == DW_FORM_sec_offset)
1740 printf (_("(location list)"));
1741 /* Fall through. */
1742 case DW_AT_allocated:
1743 case DW_AT_associated:
1744 case DW_AT_data_location:
1745 case DW_AT_stride:
1746 case DW_AT_upper_bound:
1747 case DW_AT_lower_bound:
1748 if (block_start)
1750 int need_frame_base;
1752 printf ("(");
1753 need_frame_base = decode_location_expression (block_start,
1754 pointer_size,
1755 offset_size,
1756 dwarf_version,
1757 uvalue,
1758 cu_offset, section);
1759 printf (")");
1760 if (need_frame_base && !have_frame_base)
1761 printf (_(" [without DW_AT_frame_base]"));
1763 break;
1765 case DW_AT_import:
1767 if (form == DW_FORM_ref_sig8)
1768 break;
1770 if (form == DW_FORM_ref1
1771 || form == DW_FORM_ref2
1772 || form == DW_FORM_ref4
1773 || form == DW_FORM_ref_udata)
1774 uvalue += cu_offset;
1776 if (uvalue >= section->size)
1777 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1778 dwarf_vmatoa ("x", uvalue),
1779 (unsigned long) (orig_data - section->start));
1780 else
1782 unsigned long abbrev_number;
1783 abbrev_entry * entry;
1785 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1787 printf (_("[Abbrev Number: %ld"), abbrev_number);
1788 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1789 if (entry->entry == abbrev_number)
1790 break;
1791 if (entry != NULL)
1792 printf (" (%s)", get_TAG_name (entry->tag));
1793 printf ("]");
1796 break;
1798 default:
1799 break;
1802 return data;
1805 static char *
1806 get_AT_name (unsigned long attribute)
1808 switch (attribute)
1810 case DW_AT_sibling: return "DW_AT_sibling";
1811 case DW_AT_location: return "DW_AT_location";
1812 case DW_AT_name: return "DW_AT_name";
1813 case DW_AT_ordering: return "DW_AT_ordering";
1814 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1815 case DW_AT_byte_size: return "DW_AT_byte_size";
1816 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1817 case DW_AT_bit_size: return "DW_AT_bit_size";
1818 case DW_AT_element_list: return "DW_AT_element_list";
1819 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1820 case DW_AT_low_pc: return "DW_AT_low_pc";
1821 case DW_AT_high_pc: return "DW_AT_high_pc";
1822 case DW_AT_language: return "DW_AT_language";
1823 case DW_AT_member: return "DW_AT_member";
1824 case DW_AT_discr: return "DW_AT_discr";
1825 case DW_AT_discr_value: return "DW_AT_discr_value";
1826 case DW_AT_visibility: return "DW_AT_visibility";
1827 case DW_AT_import: return "DW_AT_import";
1828 case DW_AT_string_length: return "DW_AT_string_length";
1829 case DW_AT_common_reference: return "DW_AT_common_reference";
1830 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1831 case DW_AT_const_value: return "DW_AT_const_value";
1832 case DW_AT_containing_type: return "DW_AT_containing_type";
1833 case DW_AT_default_value: return "DW_AT_default_value";
1834 case DW_AT_inline: return "DW_AT_inline";
1835 case DW_AT_is_optional: return "DW_AT_is_optional";
1836 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1837 case DW_AT_producer: return "DW_AT_producer";
1838 case DW_AT_prototyped: return "DW_AT_prototyped";
1839 case DW_AT_return_addr: return "DW_AT_return_addr";
1840 case DW_AT_start_scope: return "DW_AT_start_scope";
1841 case DW_AT_stride_size: return "DW_AT_stride_size";
1842 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1843 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1844 case DW_AT_accessibility: return "DW_AT_accessibility";
1845 case DW_AT_address_class: return "DW_AT_address_class";
1846 case DW_AT_artificial: return "DW_AT_artificial";
1847 case DW_AT_base_types: return "DW_AT_base_types";
1848 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1849 case DW_AT_count: return "DW_AT_count";
1850 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1851 case DW_AT_decl_column: return "DW_AT_decl_column";
1852 case DW_AT_decl_file: return "DW_AT_decl_file";
1853 case DW_AT_decl_line: return "DW_AT_decl_line";
1854 case DW_AT_declaration: return "DW_AT_declaration";
1855 case DW_AT_discr_list: return "DW_AT_discr_list";
1856 case DW_AT_encoding: return "DW_AT_encoding";
1857 case DW_AT_external: return "DW_AT_external";
1858 case DW_AT_frame_base: return "DW_AT_frame_base";
1859 case DW_AT_friend: return "DW_AT_friend";
1860 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1861 case DW_AT_macro_info: return "DW_AT_macro_info";
1862 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1863 case DW_AT_priority: return "DW_AT_priority";
1864 case DW_AT_segment: return "DW_AT_segment";
1865 case DW_AT_specification: return "DW_AT_specification";
1866 case DW_AT_static_link: return "DW_AT_static_link";
1867 case DW_AT_type: return "DW_AT_type";
1868 case DW_AT_use_location: return "DW_AT_use_location";
1869 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1870 case DW_AT_virtuality: return "DW_AT_virtuality";
1871 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1872 /* DWARF 2.1 values. */
1873 case DW_AT_allocated: return "DW_AT_allocated";
1874 case DW_AT_associated: return "DW_AT_associated";
1875 case DW_AT_data_location: return "DW_AT_data_location";
1876 case DW_AT_stride: return "DW_AT_stride";
1877 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1878 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1879 case DW_AT_extension: return "DW_AT_extension";
1880 case DW_AT_ranges: return "DW_AT_ranges";
1881 case DW_AT_trampoline: return "DW_AT_trampoline";
1882 case DW_AT_call_column: return "DW_AT_call_column";
1883 case DW_AT_call_file: return "DW_AT_call_file";
1884 case DW_AT_call_line: return "DW_AT_call_line";
1885 case DW_AT_description: return "DW_AT_description";
1886 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1887 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1888 case DW_AT_small: return "DW_AT_small";
1889 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1890 case DW_AT_digit_count: return "DW_AT_digit_count";
1891 case DW_AT_picture_string: return "DW_AT_picture_string";
1892 case DW_AT_mutable: return "DW_AT_mutable";
1893 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1894 case DW_AT_explicit: return "DW_AT_explicit";
1895 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1896 case DW_AT_endianity: return "DW_AT_endianity";
1897 case DW_AT_elemental: return "DW_AT_elemental";
1898 case DW_AT_pure: return "DW_AT_pure";
1899 case DW_AT_recursive: return "DW_AT_recursive";
1900 /* DWARF 4 values. */
1901 case DW_AT_signature: return "DW_AT_signature";
1902 case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
1903 case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
1904 case DW_AT_const_expr: return "DW_AT_const_expr";
1905 case DW_AT_enum_class: return "DW_AT_enum_class";
1906 case DW_AT_linkage_name: return "DW_AT_linkage_name";
1908 /* HP and SGI/MIPS extensions. */
1909 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1910 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1911 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1912 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1913 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1914 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1915 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1916 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1917 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1918 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1920 /* HP Extensions. */
1921 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
1922 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1923 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1924 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1925 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1926 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1927 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1928 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1929 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1930 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1931 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1932 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1933 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1935 /* One value is shared by the MIPS and HP extensions: */
1936 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1938 /* GNU extensions. */
1939 case DW_AT_sf_names: return "DW_AT_sf_names";
1940 case DW_AT_src_info: return "DW_AT_src_info";
1941 case DW_AT_mac_info: return "DW_AT_mac_info";
1942 case DW_AT_src_coords: return "DW_AT_src_coords";
1943 case DW_AT_body_begin: return "DW_AT_body_begin";
1944 case DW_AT_body_end: return "DW_AT_body_end";
1945 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1946 case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by";
1947 case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by";
1948 case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded";
1949 case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded";
1950 case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded";
1951 case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required";
1952 case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required";
1953 case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature";
1954 case DW_AT_use_GNAT_descriptive_type: return "DW_AT_use_GNAT_descriptive_type";
1955 case DW_AT_GNAT_descriptive_type: return "DW_AT_GNAT_descriptive_type";
1956 case DW_AT_GNU_call_site_value: return "DW_AT_GNU_call_site_value";
1957 case DW_AT_GNU_call_site_data_value: return "DW_AT_GNU_call_site_data_value";
1958 case DW_AT_GNU_call_site_target: return "DW_AT_GNU_call_site_target";
1959 case DW_AT_GNU_call_site_target_clobbered: return "DW_AT_GNU_call_site_target_clobbered";
1960 case DW_AT_GNU_tail_call: return "DW_AT_GNU_tail_call";
1961 case DW_AT_GNU_all_tail_call_sites: return "DW_AT_GNU_all_tail_call_sites";
1962 case DW_AT_GNU_all_call_sites: return "DW_AT_GNU_all_call_sites";
1963 case DW_AT_GNU_all_source_call_sites: return "DW_AT_GNU_all_source_call_sites";
1964 case DW_AT_GNU_macros: return "DW_AT_GNU_macros";
1966 /* UPC extension. */
1967 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1969 /* PGI (STMicroelectronics) extensions. */
1970 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1971 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1972 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1974 default:
1976 static char buffer[100];
1978 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1979 attribute);
1980 return buffer;
1985 static unsigned char *
1986 read_and_display_attr (unsigned long attribute,
1987 unsigned long form,
1988 unsigned char * data,
1989 dwarf_vma cu_offset,
1990 dwarf_vma pointer_size,
1991 dwarf_vma offset_size,
1992 int dwarf_version,
1993 debug_info * debug_info_p,
1994 int do_loc,
1995 struct dwarf_section * section)
1997 if (!do_loc)
1998 printf (" %-18s:", get_AT_name (attribute));
1999 data = read_and_display_attr_value (attribute, form, data, cu_offset,
2000 pointer_size, offset_size,
2001 dwarf_version, debug_info_p,
2002 do_loc, section);
2003 if (!do_loc)
2004 printf ("\n");
2005 return data;
2009 /* Process the contents of a .debug_info section. If do_loc is non-zero
2010 then we are scanning for location lists and we do not want to display
2011 anything to the user. If do_types is non-zero, we are processing
2012 a .debug_types section instead of a .debug_info section. */
2014 static int
2015 process_debug_info (struct dwarf_section *section,
2016 void *file,
2017 enum dwarf_section_display_enum abbrev_sec,
2018 int do_loc,
2019 int do_types)
2021 unsigned char *start = section->start;
2022 unsigned char *end = start + section->size;
2023 unsigned char *section_begin;
2024 unsigned int unit;
2025 unsigned int num_units = 0;
2027 if ((do_loc || do_debug_loc || do_debug_ranges)
2028 && num_debug_info_entries == 0
2029 && ! do_types)
2031 dwarf_vma length;
2033 /* First scan the section to get the number of comp units. */
2034 for (section_begin = start, num_units = 0; section_begin < end;
2035 num_units ++)
2037 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2038 will be the length. For a 64-bit DWARF section, it'll be
2039 the escape code 0xffffffff followed by an 8 byte length. */
2040 length = byte_get (section_begin, 4);
2042 if (length == 0xffffffff)
2044 length = byte_get (section_begin + 4, 8);
2045 section_begin += length + 12;
2047 else if (length >= 0xfffffff0 && length < 0xffffffff)
2049 warn (_("Reserved length value (0x%s) found in section %s\n"),
2050 dwarf_vmatoa ("x", length), section->name);
2051 return 0;
2053 else
2054 section_begin += length + 4;
2056 /* Negative values are illegal, they may even cause infinite
2057 looping. This can happen if we can't accurately apply
2058 relocations to an object file. */
2059 if ((signed long) length <= 0)
2061 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2062 dwarf_vmatoa ("x", length), section->name);
2063 return 0;
2067 if (num_units == 0)
2069 error (_("No comp units in %s section ?"), section->name);
2070 return 0;
2073 /* Then allocate an array to hold the information. */
2074 debug_information = (debug_info *) cmalloc (num_units,
2075 sizeof (* debug_information));
2076 if (debug_information == NULL)
2078 error (_("Not enough memory for a debug info array of %u entries"),
2079 num_units);
2080 return 0;
2084 if (!do_loc)
2086 if (dwarf_start_die == 0)
2087 printf (_("Contents of the %s section:\n\n"), section->name);
2089 load_debug_section (str, file);
2092 load_debug_section (abbrev_sec, file);
2093 if (debug_displays [abbrev_sec].section.start == NULL)
2095 warn (_("Unable to locate %s section!\n"),
2096 debug_displays [abbrev_sec].section.name);
2097 return 0;
2100 for (section_begin = start, unit = 0; start < end; unit++)
2102 DWARF2_Internal_CompUnit compunit;
2103 unsigned char *hdrptr;
2104 unsigned char *tags;
2105 int level, last_level, saved_level;
2106 dwarf_vma cu_offset;
2107 int offset_size;
2108 int initial_length_size;
2109 unsigned char signature[8] = { 0 };
2110 dwarf_vma type_offset = 0;
2112 hdrptr = start;
2114 compunit.cu_length = byte_get (hdrptr, 4);
2115 hdrptr += 4;
2117 if (compunit.cu_length == 0xffffffff)
2119 compunit.cu_length = byte_get (hdrptr, 8);
2120 hdrptr += 8;
2121 offset_size = 8;
2122 initial_length_size = 12;
2124 else
2126 offset_size = 4;
2127 initial_length_size = 4;
2130 compunit.cu_version = byte_get (hdrptr, 2);
2131 hdrptr += 2;
2133 cu_offset = start - section_begin;
2135 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
2136 hdrptr += offset_size;
2138 compunit.cu_pointer_size = byte_get (hdrptr, 1);
2139 hdrptr += 1;
2141 if (do_types)
2143 int i;
2145 for (i = 0; i < 8; i++)
2147 signature[i] = byte_get (hdrptr, 1);
2148 hdrptr += 1;
2151 type_offset = byte_get (hdrptr, offset_size);
2152 hdrptr += offset_size;
2155 if ((do_loc || do_debug_loc || do_debug_ranges)
2156 && num_debug_info_entries == 0
2157 && ! do_types)
2159 debug_information [unit].cu_offset = cu_offset;
2160 debug_information [unit].pointer_size
2161 = compunit.cu_pointer_size;
2162 debug_information [unit].offset_size = offset_size;
2163 debug_information [unit].dwarf_version = compunit.cu_version;
2164 debug_information [unit].base_address = 0;
2165 debug_information [unit].loc_offsets = NULL;
2166 debug_information [unit].have_frame_base = NULL;
2167 debug_information [unit].max_loc_offsets = 0;
2168 debug_information [unit].num_loc_offsets = 0;
2169 debug_information [unit].range_lists = NULL;
2170 debug_information [unit].max_range_lists= 0;
2171 debug_information [unit].num_range_lists = 0;
2174 if (!do_loc && dwarf_start_die == 0)
2176 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2177 dwarf_vmatoa ("x", cu_offset));
2178 printf (_(" Length: 0x%s (%s)\n"),
2179 dwarf_vmatoa ("x", compunit.cu_length),
2180 offset_size == 8 ? "64-bit" : "32-bit");
2181 printf (_(" Version: %d\n"), compunit.cu_version);
2182 printf (_(" Abbrev Offset: %s\n"),
2183 dwarf_vmatoa ("d", compunit.cu_abbrev_offset));
2184 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2185 if (do_types)
2187 int i;
2188 printf (_(" Signature: "));
2189 for (i = 0; i < 8; i++)
2190 printf ("%02x", signature[i]);
2191 printf ("\n");
2192 printf (_(" Type Offset: 0x%s\n"),
2193 dwarf_vmatoa ("x", type_offset));
2197 if (cu_offset + compunit.cu_length + initial_length_size
2198 > section->size)
2200 warn (_("Debug info is corrupted, length of CU at %s"
2201 " extends beyond end of section (length = %s)\n"),
2202 dwarf_vmatoa ("x", cu_offset),
2203 dwarf_vmatoa ("x", compunit.cu_length));
2204 break;
2206 tags = hdrptr;
2207 start += compunit.cu_length + initial_length_size;
2209 if (compunit.cu_version != 2
2210 && compunit.cu_version != 3
2211 && compunit.cu_version != 4)
2213 warn (_("CU at offset %s contains corrupt or "
2214 "unsupported version number: %d.\n"),
2215 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2216 continue;
2219 free_abbrevs ();
2221 /* Process the abbrevs used by this compilation unit. DWARF
2222 sections under Mach-O have non-zero addresses. */
2223 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2224 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2225 (unsigned long) compunit.cu_abbrev_offset,
2226 (unsigned long) debug_displays [abbrev_sec].section.size);
2227 else
2228 process_abbrev_section
2229 ((unsigned char *) debug_displays [abbrev_sec].section.start
2230 + compunit.cu_abbrev_offset,
2231 (unsigned char *) debug_displays [abbrev_sec].section.start
2232 + debug_displays [abbrev_sec].section.size);
2234 level = 0;
2235 last_level = level;
2236 saved_level = -1;
2237 while (tags < start)
2239 unsigned int bytes_read;
2240 unsigned long abbrev_number;
2241 unsigned long die_offset;
2242 abbrev_entry *entry;
2243 abbrev_attr *attr;
2244 int do_printing = 1;
2246 die_offset = tags - section_begin;
2248 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2249 tags += bytes_read;
2251 /* A null DIE marks the end of a list of siblings or it may also be
2252 a section padding. */
2253 if (abbrev_number == 0)
2255 /* Check if it can be a section padding for the last CU. */
2256 if (level == 0 && start == end)
2258 unsigned char *chk;
2260 for (chk = tags; chk < start; chk++)
2261 if (*chk != 0)
2262 break;
2263 if (chk == start)
2264 break;
2267 --level;
2268 if (level < 0)
2270 static unsigned num_bogus_warns = 0;
2272 if (num_bogus_warns < 3)
2274 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2275 die_offset);
2276 num_bogus_warns ++;
2277 if (num_bogus_warns == 3)
2278 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2281 if (dwarf_start_die != 0 && level < saved_level)
2282 return 1;
2283 continue;
2286 if (!do_loc)
2288 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2289 do_printing = 0;
2290 else
2292 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2293 saved_level = level;
2294 do_printing = (dwarf_cutoff_level == -1
2295 || level < dwarf_cutoff_level);
2296 if (do_printing)
2297 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2298 level, die_offset, abbrev_number);
2299 else if (dwarf_cutoff_level == -1
2300 || last_level < dwarf_cutoff_level)
2301 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2302 last_level = level;
2306 /* Scan through the abbreviation list until we reach the
2307 correct entry. */
2308 for (entry = first_abbrev;
2309 entry && entry->entry != abbrev_number;
2310 entry = entry->next)
2311 continue;
2313 if (entry == NULL)
2315 if (!do_loc && do_printing)
2317 printf ("\n");
2318 fflush (stdout);
2320 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2321 die_offset, abbrev_number);
2322 return 0;
2325 if (!do_loc && do_printing)
2326 printf (" (%s)\n", get_TAG_name (entry->tag));
2328 switch (entry->tag)
2330 default:
2331 need_base_address = 0;
2332 break;
2333 case DW_TAG_compile_unit:
2334 need_base_address = 1;
2335 break;
2336 case DW_TAG_entry_point:
2337 case DW_TAG_subprogram:
2338 need_base_address = 0;
2339 /* Assuming that there is no DW_AT_frame_base. */
2340 have_frame_base = 0;
2341 break;
2344 for (attr = entry->first_attr; attr; attr = attr->next)
2346 debug_info *arg;
2348 if (! do_loc && do_printing)
2349 /* Show the offset from where the tag was extracted. */
2350 printf (" <%lx>", (unsigned long)(tags - section_begin));
2352 arg = debug_information;
2353 if (debug_information)
2354 arg += unit;
2356 tags = read_and_display_attr (attr->attribute,
2357 attr->form,
2358 tags, cu_offset,
2359 compunit.cu_pointer_size,
2360 offset_size,
2361 compunit.cu_version,
2362 arg,
2363 do_loc || ! do_printing, section);
2366 if (entry->children)
2367 ++level;
2371 /* Set num_debug_info_entries here so that it can be used to check if
2372 we need to process .debug_loc and .debug_ranges sections. */
2373 if ((do_loc || do_debug_loc || do_debug_ranges)
2374 && num_debug_info_entries == 0
2375 && ! do_types)
2376 num_debug_info_entries = num_units;
2378 if (!do_loc)
2379 printf ("\n");
2381 return 1;
2384 /* Locate and scan the .debug_info section in the file and record the pointer
2385 sizes and offsets for the compilation units in it. Usually an executable
2386 will have just one pointer size, but this is not guaranteed, and so we try
2387 not to make any assumptions. Returns zero upon failure, or the number of
2388 compilation units upon success. */
2390 static unsigned int
2391 load_debug_info (void * file)
2393 /* Reset the last pointer size so that we can issue correct error
2394 messages if we are displaying the contents of more than one section. */
2395 last_pointer_size = 0;
2396 warned_about_missing_comp_units = FALSE;
2398 /* If we have already tried and failed to load the .debug_info
2399 section then do not bother to repear the task. */
2400 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2401 return 0;
2403 /* If we already have the information there is nothing else to do. */
2404 if (num_debug_info_entries > 0)
2405 return num_debug_info_entries;
2407 if (load_debug_section (info, file)
2408 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2409 return num_debug_info_entries;
2411 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2412 return 0;
2415 static int
2416 display_debug_lines_raw (struct dwarf_section *section,
2417 unsigned char *data,
2418 unsigned char *end)
2420 unsigned char *start = section->start;
2422 printf (_("Raw dump of debug contents of section %s:\n\n"),
2423 section->name);
2425 while (data < end)
2427 DWARF2_Internal_LineInfo linfo;
2428 unsigned char *standard_opcodes;
2429 unsigned char *end_of_sequence;
2430 unsigned char *hdrptr;
2431 unsigned long hdroff;
2432 int initial_length_size;
2433 int offset_size;
2434 int i;
2436 hdrptr = data;
2437 hdroff = hdrptr - start;
2439 /* Check the length of the block. */
2440 linfo.li_length = byte_get (hdrptr, 4);
2441 hdrptr += 4;
2443 if (linfo.li_length == 0xffffffff)
2445 /* This section is 64-bit DWARF 3. */
2446 linfo.li_length = byte_get (hdrptr, 8);
2447 hdrptr += 8;
2448 offset_size = 8;
2449 initial_length_size = 12;
2451 else
2453 offset_size = 4;
2454 initial_length_size = 4;
2457 if (linfo.li_length + initial_length_size > section->size)
2459 warn
2460 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2461 section->name);
2462 return 0;
2465 /* Check its version number. */
2466 linfo.li_version = byte_get (hdrptr, 2);
2467 hdrptr += 2;
2468 if (linfo.li_version != 2
2469 && linfo.li_version != 3
2470 && linfo.li_version != 4)
2472 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2473 return 0;
2476 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2477 hdrptr += offset_size;
2478 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2479 hdrptr++;
2480 if (linfo.li_version >= 4)
2482 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2483 hdrptr++;
2484 if (linfo.li_max_ops_per_insn == 0)
2486 warn (_("Invalid maximum operations per insn.\n"));
2487 return 0;
2490 else
2491 linfo.li_max_ops_per_insn = 1;
2492 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2493 hdrptr++;
2494 linfo.li_line_base = byte_get (hdrptr, 1);
2495 hdrptr++;
2496 linfo.li_line_range = byte_get (hdrptr, 1);
2497 hdrptr++;
2498 linfo.li_opcode_base = byte_get (hdrptr, 1);
2499 hdrptr++;
2501 /* Sign extend the line base field. */
2502 linfo.li_line_base <<= 24;
2503 linfo.li_line_base >>= 24;
2505 printf (_(" Offset: 0x%lx\n"), hdroff);
2506 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2507 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2508 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2509 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2510 if (linfo.li_version >= 4)
2511 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2512 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2513 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2514 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2515 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2517 end_of_sequence = data + linfo.li_length + initial_length_size;
2519 reset_state_machine (linfo.li_default_is_stmt);
2521 /* Display the contents of the Opcodes table. */
2522 standard_opcodes = hdrptr;
2524 printf (_("\n Opcodes:\n"));
2526 for (i = 1; i < linfo.li_opcode_base; i++)
2527 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2529 /* Display the contents of the Directory table. */
2530 data = standard_opcodes + linfo.li_opcode_base - 1;
2532 if (*data == 0)
2533 printf (_("\n The Directory Table is empty.\n"));
2534 else
2536 printf (_("\n The Directory Table:\n"));
2538 while (*data != 0)
2540 printf (" %s\n", data);
2542 data += strlen ((char *) data) + 1;
2546 /* Skip the NUL at the end of the table. */
2547 data++;
2549 /* Display the contents of the File Name table. */
2550 if (*data == 0)
2551 printf (_("\n The File Name Table is empty.\n"));
2552 else
2554 printf (_("\n The File Name Table:\n"));
2555 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2557 while (*data != 0)
2559 unsigned char *name;
2560 unsigned int bytes_read;
2562 printf (" %d\t", ++state_machine_regs.last_file_entry);
2563 name = data;
2565 data += strlen ((char *) data) + 1;
2567 printf ("%s\t",
2568 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2569 data += bytes_read;
2570 printf ("%s\t",
2571 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2572 data += bytes_read;
2573 printf ("%s\t",
2574 dwarf_vmatoa ("u", read_leb128 (data, & bytes_read, 0)));
2575 data += bytes_read;
2576 printf ("%s\n", name);
2580 /* Skip the NUL at the end of the table. */
2581 data++;
2583 /* Now display the statements. */
2584 printf (_("\n Line Number Statements:\n"));
2586 while (data < end_of_sequence)
2588 unsigned char op_code;
2589 dwarf_signed_vma adv;
2590 dwarf_vma uladv;
2591 unsigned int bytes_read;
2593 op_code = *data++;
2595 if (op_code >= linfo.li_opcode_base)
2597 op_code -= linfo.li_opcode_base;
2598 uladv = (op_code / linfo.li_line_range);
2599 if (linfo.li_max_ops_per_insn == 1)
2601 uladv *= linfo.li_min_insn_length;
2602 state_machine_regs.address += uladv;
2603 printf (_(" Special opcode %d: "
2604 "advance Address by %s to 0x%s"),
2605 op_code, dwarf_vmatoa ("u", uladv),
2606 dwarf_vmatoa ("x", state_machine_regs.address));
2608 else
2610 state_machine_regs.address
2611 += ((state_machine_regs.op_index + uladv)
2612 / linfo.li_max_ops_per_insn)
2613 * linfo.li_min_insn_length;
2614 state_machine_regs.op_index
2615 = (state_machine_regs.op_index + uladv)
2616 % linfo.li_max_ops_per_insn;
2617 printf (_(" Special opcode %d: "
2618 "advance Address by %s to 0x%s[%d]"),
2619 op_code, dwarf_vmatoa ("u", uladv),
2620 dwarf_vmatoa ("x", state_machine_regs.address),
2621 state_machine_regs.op_index);
2623 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2624 state_machine_regs.line += adv;
2625 printf (_(" and Line by %s to %d\n"),
2626 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2628 else switch (op_code)
2630 case DW_LNS_extended_op:
2631 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2632 break;
2634 case DW_LNS_copy:
2635 printf (_(" Copy\n"));
2636 break;
2638 case DW_LNS_advance_pc:
2639 uladv = read_leb128 (data, & bytes_read, 0);
2640 data += bytes_read;
2641 if (linfo.li_max_ops_per_insn == 1)
2643 uladv *= linfo.li_min_insn_length;
2644 state_machine_regs.address += uladv;
2645 printf (_(" Advance PC by %s to 0x%s\n"),
2646 dwarf_vmatoa ("u", uladv),
2647 dwarf_vmatoa ("x", state_machine_regs.address));
2649 else
2651 state_machine_regs.address
2652 += ((state_machine_regs.op_index + uladv)
2653 / linfo.li_max_ops_per_insn)
2654 * linfo.li_min_insn_length;
2655 state_machine_regs.op_index
2656 = (state_machine_regs.op_index + uladv)
2657 % linfo.li_max_ops_per_insn;
2658 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2659 dwarf_vmatoa ("u", uladv),
2660 dwarf_vmatoa ("x", state_machine_regs.address),
2661 state_machine_regs.op_index);
2663 break;
2665 case DW_LNS_advance_line:
2666 adv = read_sleb128 (data, & bytes_read);
2667 data += bytes_read;
2668 state_machine_regs.line += adv;
2669 printf (_(" Advance Line by %s to %d\n"),
2670 dwarf_vmatoa ("d", adv),
2671 state_machine_regs.line);
2672 break;
2674 case DW_LNS_set_file:
2675 adv = read_leb128 (data, & bytes_read, 0);
2676 data += bytes_read;
2677 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2678 dwarf_vmatoa ("d", adv));
2679 state_machine_regs.file = adv;
2680 break;
2682 case DW_LNS_set_column:
2683 uladv = read_leb128 (data, & bytes_read, 0);
2684 data += bytes_read;
2685 printf (_(" Set column to %s\n"),
2686 dwarf_vmatoa ("u", uladv));
2687 state_machine_regs.column = uladv;
2688 break;
2690 case DW_LNS_negate_stmt:
2691 adv = state_machine_regs.is_stmt;
2692 adv = ! adv;
2693 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2694 state_machine_regs.is_stmt = adv;
2695 break;
2697 case DW_LNS_set_basic_block:
2698 printf (_(" Set basic block\n"));
2699 state_machine_regs.basic_block = 1;
2700 break;
2702 case DW_LNS_const_add_pc:
2703 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2704 if (linfo.li_max_ops_per_insn)
2706 uladv *= linfo.li_min_insn_length;
2707 state_machine_regs.address += uladv;
2708 printf (_(" Advance PC by constant %s to 0x%s\n"),
2709 dwarf_vmatoa ("u", uladv),
2710 dwarf_vmatoa ("x", state_machine_regs.address));
2712 else
2714 state_machine_regs.address
2715 += ((state_machine_regs.op_index + uladv)
2716 / linfo.li_max_ops_per_insn)
2717 * linfo.li_min_insn_length;
2718 state_machine_regs.op_index
2719 = (state_machine_regs.op_index + uladv)
2720 % linfo.li_max_ops_per_insn;
2721 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2722 dwarf_vmatoa ("u", uladv),
2723 dwarf_vmatoa ("x", state_machine_regs.address),
2724 state_machine_regs.op_index);
2726 break;
2728 case DW_LNS_fixed_advance_pc:
2729 uladv = byte_get (data, 2);
2730 data += 2;
2731 state_machine_regs.address += uladv;
2732 state_machine_regs.op_index = 0;
2733 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2734 dwarf_vmatoa ("u", uladv),
2735 dwarf_vmatoa ("x", state_machine_regs.address));
2736 break;
2738 case DW_LNS_set_prologue_end:
2739 printf (_(" Set prologue_end to true\n"));
2740 break;
2742 case DW_LNS_set_epilogue_begin:
2743 printf (_(" Set epilogue_begin to true\n"));
2744 break;
2746 case DW_LNS_set_isa:
2747 uladv = read_leb128 (data, & bytes_read, 0);
2748 data += bytes_read;
2749 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2750 break;
2752 default:
2753 printf (_(" Unknown opcode %d with operands: "), op_code);
2755 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2757 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
2758 &bytes_read, 0)),
2759 i == 1 ? "" : ", ");
2760 data += bytes_read;
2762 putchar ('\n');
2763 break;
2766 putchar ('\n');
2769 return 1;
2772 typedef struct
2774 unsigned char *name;
2775 unsigned int directory_index;
2776 unsigned int modification_date;
2777 unsigned int length;
2778 } File_Entry;
2780 /* Output a decoded representation of the .debug_line section. */
2782 static int
2783 display_debug_lines_decoded (struct dwarf_section *section,
2784 unsigned char *data,
2785 unsigned char *end)
2787 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2788 section->name);
2790 while (data < end)
2792 /* This loop amounts to one iteration per compilation unit. */
2793 DWARF2_Internal_LineInfo linfo;
2794 unsigned char *standard_opcodes;
2795 unsigned char *end_of_sequence;
2796 unsigned char *hdrptr;
2797 int initial_length_size;
2798 int offset_size;
2799 int i;
2800 File_Entry *file_table = NULL;
2801 unsigned char **directory_table = NULL;
2803 hdrptr = data;
2805 /* Extract information from the Line Number Program Header.
2806 (section 6.2.4 in the Dwarf3 doc). */
2808 /* Get the length of this CU's line number information block. */
2809 linfo.li_length = byte_get (hdrptr, 4);
2810 hdrptr += 4;
2812 if (linfo.li_length == 0xffffffff)
2814 /* This section is 64-bit DWARF 3. */
2815 linfo.li_length = byte_get (hdrptr, 8);
2816 hdrptr += 8;
2817 offset_size = 8;
2818 initial_length_size = 12;
2820 else
2822 offset_size = 4;
2823 initial_length_size = 4;
2826 if (linfo.li_length + initial_length_size > section->size)
2828 warn (_("The line info appears to be corrupt - "
2829 "the section is too small\n"));
2830 return 0;
2833 /* Get this CU's Line Number Block version number. */
2834 linfo.li_version = byte_get (hdrptr, 2);
2835 hdrptr += 2;
2836 if (linfo.li_version != 2
2837 && linfo.li_version != 3
2838 && linfo.li_version != 4)
2840 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2841 "supported.\n"));
2842 return 0;
2845 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2846 hdrptr += offset_size;
2847 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2848 hdrptr++;
2849 if (linfo.li_version >= 4)
2851 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2852 hdrptr++;
2853 if (linfo.li_max_ops_per_insn == 0)
2855 warn (_("Invalid maximum operations per insn.\n"));
2856 return 0;
2859 else
2860 linfo.li_max_ops_per_insn = 1;
2861 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2862 hdrptr++;
2863 linfo.li_line_base = byte_get (hdrptr, 1);
2864 hdrptr++;
2865 linfo.li_line_range = byte_get (hdrptr, 1);
2866 hdrptr++;
2867 linfo.li_opcode_base = byte_get (hdrptr, 1);
2868 hdrptr++;
2870 /* Sign extend the line base field. */
2871 linfo.li_line_base <<= 24;
2872 linfo.li_line_base >>= 24;
2874 /* Find the end of this CU's Line Number Information Block. */
2875 end_of_sequence = data + linfo.li_length + initial_length_size;
2877 reset_state_machine (linfo.li_default_is_stmt);
2879 /* Save a pointer to the contents of the Opcodes table. */
2880 standard_opcodes = hdrptr;
2882 /* Traverse the Directory table just to count entries. */
2883 data = standard_opcodes + linfo.li_opcode_base - 1;
2884 if (*data != 0)
2886 unsigned int n_directories = 0;
2887 unsigned char *ptr_directory_table = data;
2889 while (*data != 0)
2891 data += strlen ((char *) data) + 1;
2892 n_directories++;
2895 /* Go through the directory table again to save the directories. */
2896 directory_table = (unsigned char **)
2897 xmalloc (n_directories * sizeof (unsigned char *));
2899 i = 0;
2900 while (*ptr_directory_table != 0)
2902 directory_table[i] = ptr_directory_table;
2903 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2904 i++;
2907 /* Skip the NUL at the end of the table. */
2908 data++;
2910 /* Traverse the File Name table just to count the entries. */
2911 if (*data != 0)
2913 unsigned int n_files = 0;
2914 unsigned char *ptr_file_name_table = data;
2916 while (*data != 0)
2918 unsigned int bytes_read;
2920 /* Skip Name, directory index, last modification time and length
2921 of file. */
2922 data += strlen ((char *) data) + 1;
2923 read_leb128 (data, & bytes_read, 0);
2924 data += bytes_read;
2925 read_leb128 (data, & bytes_read, 0);
2926 data += bytes_read;
2927 read_leb128 (data, & bytes_read, 0);
2928 data += bytes_read;
2930 n_files++;
2933 /* Go through the file table again to save the strings. */
2934 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2936 i = 0;
2937 while (*ptr_file_name_table != 0)
2939 unsigned int bytes_read;
2941 file_table[i].name = ptr_file_name_table;
2942 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2944 /* We are not interested in directory, time or size. */
2945 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2946 & bytes_read, 0);
2947 ptr_file_name_table += bytes_read;
2948 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2949 & bytes_read, 0);
2950 ptr_file_name_table += bytes_read;
2951 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2952 ptr_file_name_table += bytes_read;
2953 i++;
2955 i = 0;
2957 /* Print the Compilation Unit's name and a header. */
2958 if (directory_table == NULL)
2960 printf (_("CU: %s:\n"), file_table[0].name);
2961 printf (_("File name Line number Starting address\n"));
2963 else
2965 unsigned int ix = file_table[0].directory_index;
2966 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
2967 if (do_wide || strlen (directory) < 76)
2968 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
2969 else
2970 printf ("%s:\n", file_table[0].name);
2972 printf (_("File name Line number Starting address\n"));
2976 /* Skip the NUL at the end of the table. */
2977 data++;
2979 /* This loop iterates through the Dwarf Line Number Program. */
2980 while (data < end_of_sequence)
2982 unsigned char op_code;
2983 int adv;
2984 unsigned long int uladv;
2985 unsigned int bytes_read;
2986 int is_special_opcode = 0;
2988 op_code = *data++;
2990 if (op_code >= linfo.li_opcode_base)
2992 op_code -= linfo.li_opcode_base;
2993 uladv = (op_code / linfo.li_line_range);
2994 if (linfo.li_max_ops_per_insn == 1)
2996 uladv *= linfo.li_min_insn_length;
2997 state_machine_regs.address += uladv;
2999 else
3001 state_machine_regs.address
3002 += ((state_machine_regs.op_index + uladv)
3003 / linfo.li_max_ops_per_insn)
3004 * linfo.li_min_insn_length;
3005 state_machine_regs.op_index
3006 = (state_machine_regs.op_index + uladv)
3007 % linfo.li_max_ops_per_insn;
3010 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3011 state_machine_regs.line += adv;
3012 is_special_opcode = 1;
3014 else switch (op_code)
3016 case DW_LNS_extended_op:
3018 unsigned int ext_op_code_len;
3019 unsigned char ext_op_code;
3020 unsigned char *op_code_data = data;
3022 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
3023 op_code_data += bytes_read;
3025 if (ext_op_code_len == 0)
3027 warn (_("badly formed extended line op encountered!\n"));
3028 break;
3030 ext_op_code_len += bytes_read;
3031 ext_op_code = *op_code_data++;
3033 switch (ext_op_code)
3035 case DW_LNE_end_sequence:
3036 reset_state_machine (linfo.li_default_is_stmt);
3037 break;
3038 case DW_LNE_set_address:
3039 state_machine_regs.address =
3040 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
3041 state_machine_regs.op_index = 0;
3042 break;
3043 case DW_LNE_define_file:
3045 unsigned int dir_index = 0;
3047 ++state_machine_regs.last_file_entry;
3048 op_code_data += strlen ((char *) op_code_data) + 1;
3049 dir_index = read_leb128 (op_code_data, & bytes_read, 0);
3050 op_code_data += bytes_read;
3051 read_leb128 (op_code_data, & bytes_read, 0);
3052 op_code_data += bytes_read;
3053 read_leb128 (op_code_data, & bytes_read, 0);
3055 printf ("%s:\n", directory_table[dir_index]);
3056 break;
3058 default:
3059 printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
3060 break;
3062 data += ext_op_code_len;
3063 break;
3065 case DW_LNS_copy:
3066 break;
3068 case DW_LNS_advance_pc:
3069 uladv = read_leb128 (data, & bytes_read, 0);
3070 data += bytes_read;
3071 if (linfo.li_max_ops_per_insn == 1)
3073 uladv *= linfo.li_min_insn_length;
3074 state_machine_regs.address += uladv;
3076 else
3078 state_machine_regs.address
3079 += ((state_machine_regs.op_index + uladv)
3080 / linfo.li_max_ops_per_insn)
3081 * linfo.li_min_insn_length;
3082 state_machine_regs.op_index
3083 = (state_machine_regs.op_index + uladv)
3084 % linfo.li_max_ops_per_insn;
3086 break;
3088 case DW_LNS_advance_line:
3089 adv = read_sleb128 (data, & bytes_read);
3090 data += bytes_read;
3091 state_machine_regs.line += adv;
3092 break;
3094 case DW_LNS_set_file:
3095 adv = read_leb128 (data, & bytes_read, 0);
3096 data += bytes_read;
3097 state_machine_regs.file = adv;
3098 if (file_table[state_machine_regs.file - 1].directory_index == 0)
3100 /* If directory index is 0, that means current directory. */
3101 printf ("\n./%s:[++]\n",
3102 file_table[state_machine_regs.file - 1].name);
3104 else
3106 /* The directory index starts counting at 1. */
3107 printf ("\n%s/%s:\n",
3108 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3109 file_table[state_machine_regs.file - 1].name);
3111 break;
3113 case DW_LNS_set_column:
3114 uladv = read_leb128 (data, & bytes_read, 0);
3115 data += bytes_read;
3116 state_machine_regs.column = uladv;
3117 break;
3119 case DW_LNS_negate_stmt:
3120 adv = state_machine_regs.is_stmt;
3121 adv = ! adv;
3122 state_machine_regs.is_stmt = adv;
3123 break;
3125 case DW_LNS_set_basic_block:
3126 state_machine_regs.basic_block = 1;
3127 break;
3129 case DW_LNS_const_add_pc:
3130 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3131 if (linfo.li_max_ops_per_insn == 1)
3133 uladv *= linfo.li_min_insn_length;
3134 state_machine_regs.address += uladv;
3136 else
3138 state_machine_regs.address
3139 += ((state_machine_regs.op_index + uladv)
3140 / linfo.li_max_ops_per_insn)
3141 * linfo.li_min_insn_length;
3142 state_machine_regs.op_index
3143 = (state_machine_regs.op_index + uladv)
3144 % linfo.li_max_ops_per_insn;
3146 break;
3148 case DW_LNS_fixed_advance_pc:
3149 uladv = byte_get (data, 2);
3150 data += 2;
3151 state_machine_regs.address += uladv;
3152 state_machine_regs.op_index = 0;
3153 break;
3155 case DW_LNS_set_prologue_end:
3156 break;
3158 case DW_LNS_set_epilogue_begin:
3159 break;
3161 case DW_LNS_set_isa:
3162 uladv = read_leb128 (data, & bytes_read, 0);
3163 data += bytes_read;
3164 printf (_(" Set ISA to %lu\n"), uladv);
3165 break;
3167 default:
3168 printf (_(" Unknown opcode %d with operands: "), op_code);
3170 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3172 printf ("0x%s%s", dwarf_vmatoa ("x", read_leb128 (data,
3173 &bytes_read, 0)),
3174 i == 1 ? "" : ", ");
3175 data += bytes_read;
3177 putchar ('\n');
3178 break;
3181 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3182 to the DWARF address/line matrix. */
3183 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3184 || (op_code == DW_LNS_copy))
3186 const unsigned int MAX_FILENAME_LENGTH = 35;
3187 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
3188 char *newFileName = NULL;
3189 size_t fileNameLength = strlen (fileName);
3191 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3193 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3194 /* Truncate file name */
3195 strncpy (newFileName,
3196 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3197 MAX_FILENAME_LENGTH + 1);
3199 else
3201 newFileName = (char *) xmalloc (fileNameLength + 1);
3202 strncpy (newFileName, fileName, fileNameLength + 1);
3205 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3207 if (linfo.li_max_ops_per_insn == 1)
3208 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3209 newFileName, state_machine_regs.line,
3210 state_machine_regs.address);
3211 else
3212 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3213 newFileName, state_machine_regs.line,
3214 state_machine_regs.address,
3215 state_machine_regs.op_index);
3217 else
3219 if (linfo.li_max_ops_per_insn == 1)
3220 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3221 newFileName, state_machine_regs.line,
3222 state_machine_regs.address);
3223 else
3224 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3225 newFileName, state_machine_regs.line,
3226 state_machine_regs.address,
3227 state_machine_regs.op_index);
3230 if (op_code == DW_LNE_end_sequence)
3231 printf ("\n");
3233 free (newFileName);
3236 free (file_table);
3237 file_table = NULL;
3238 free (directory_table);
3239 directory_table = NULL;
3240 putchar ('\n');
3243 return 1;
3246 static int
3247 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3249 unsigned char *data = section->start;
3250 unsigned char *end = data + section->size;
3251 int retValRaw = 1;
3252 int retValDecoded = 1;
3254 if (do_debug_lines == 0)
3255 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3257 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3258 retValRaw = display_debug_lines_raw (section, data, end);
3260 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3261 retValDecoded = display_debug_lines_decoded (section, data, end);
3263 if (!retValRaw || !retValDecoded)
3264 return 0;
3266 return 1;
3269 static debug_info *
3270 find_debug_info_for_offset (unsigned long offset)
3272 unsigned int i;
3274 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3275 return NULL;
3277 for (i = 0; i < num_debug_info_entries; i++)
3278 if (debug_information[i].cu_offset == offset)
3279 return debug_information + i;
3281 return NULL;
3284 static int
3285 display_debug_pubnames (struct dwarf_section *section,
3286 void *file ATTRIBUTE_UNUSED)
3288 DWARF2_Internal_PubNames names;
3289 unsigned char *start = section->start;
3290 unsigned char *end = start + section->size;
3292 /* It does not matter if this load fails,
3293 we test for that later on. */
3294 load_debug_info (file);
3296 printf (_("Contents of the %s section:\n\n"), section->name);
3298 while (start < end)
3300 unsigned char *data;
3301 unsigned long offset;
3302 int offset_size, initial_length_size;
3304 data = start;
3306 names.pn_length = byte_get (data, 4);
3307 data += 4;
3308 if (names.pn_length == 0xffffffff)
3310 names.pn_length = byte_get (data, 8);
3311 data += 8;
3312 offset_size = 8;
3313 initial_length_size = 12;
3315 else
3317 offset_size = 4;
3318 initial_length_size = 4;
3321 names.pn_version = byte_get (data, 2);
3322 data += 2;
3324 names.pn_offset = byte_get (data, offset_size);
3325 data += offset_size;
3327 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3328 && num_debug_info_entries > 0
3329 && find_debug_info_for_offset (names.pn_offset) == NULL)
3330 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3331 (unsigned long) names.pn_offset, section->name);
3333 names.pn_size = byte_get (data, offset_size);
3334 data += offset_size;
3336 start += names.pn_length + initial_length_size;
3338 if (names.pn_version != 2 && names.pn_version != 3)
3340 static int warned = 0;
3342 if (! warned)
3344 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3345 warned = 1;
3348 continue;
3351 printf (_(" Length: %ld\n"),
3352 (long) names.pn_length);
3353 printf (_(" Version: %d\n"),
3354 names.pn_version);
3355 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3356 (unsigned long) names.pn_offset);
3357 printf (_(" Size of area in .debug_info section: %ld\n"),
3358 (long) names.pn_size);
3360 printf (_("\n Offset\tName\n"));
3364 offset = byte_get (data, offset_size);
3366 if (offset != 0)
3368 data += offset_size;
3369 printf (" %-6lx\t%s\n", offset, data);
3370 data += strlen ((char *) data) + 1;
3373 while (offset != 0);
3376 printf ("\n");
3377 return 1;
3380 static int
3381 display_debug_macinfo (struct dwarf_section *section,
3382 void *file ATTRIBUTE_UNUSED)
3384 unsigned char *start = section->start;
3385 unsigned char *end = start + section->size;
3386 unsigned char *curr = start;
3387 unsigned int bytes_read;
3388 enum dwarf_macinfo_record_type op;
3390 printf (_("Contents of the %s section:\n\n"), section->name);
3392 while (curr < end)
3394 unsigned int lineno;
3395 const char *string;
3397 op = (enum dwarf_macinfo_record_type) *curr;
3398 curr++;
3400 switch (op)
3402 case DW_MACINFO_start_file:
3404 unsigned int filenum;
3406 lineno = read_leb128 (curr, & bytes_read, 0);
3407 curr += bytes_read;
3408 filenum = read_leb128 (curr, & bytes_read, 0);
3409 curr += bytes_read;
3411 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3412 lineno, filenum);
3414 break;
3416 case DW_MACINFO_end_file:
3417 printf (_(" DW_MACINFO_end_file\n"));
3418 break;
3420 case DW_MACINFO_define:
3421 lineno = read_leb128 (curr, & bytes_read, 0);
3422 curr += bytes_read;
3423 string = (char *) curr;
3424 curr += strlen (string) + 1;
3425 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3426 lineno, string);
3427 break;
3429 case DW_MACINFO_undef:
3430 lineno = read_leb128 (curr, & bytes_read, 0);
3431 curr += bytes_read;
3432 string = (char *) curr;
3433 curr += strlen (string) + 1;
3434 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3435 lineno, string);
3436 break;
3438 case DW_MACINFO_vendor_ext:
3440 unsigned int constant;
3442 constant = read_leb128 (curr, & bytes_read, 0);
3443 curr += bytes_read;
3444 string = (char *) curr;
3445 curr += strlen (string) + 1;
3446 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3447 constant, string);
3449 break;
3453 return 1;
3456 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3457 filename and dirname corresponding to file name table entry with index
3458 FILEIDX. Return NULL on failure. */
3460 static unsigned char *
3461 get_line_filename_and_dirname (dwarf_vma line_offset, dwarf_vma fileidx,
3462 unsigned char **dir_name)
3464 struct dwarf_section *section = &debug_displays [line].section;
3465 unsigned char *hdrptr, *dirtable, *file_name;
3466 unsigned int offset_size, initial_length_size;
3467 unsigned int version, opcode_base, bytes_read;
3468 dwarf_vma length, diridx;
3470 *dir_name = NULL;
3471 if (section->start == NULL
3472 || line_offset >= section->size
3473 || fileidx == 0)
3474 return NULL;
3476 hdrptr = section->start + line_offset;
3477 length = byte_get (hdrptr, 4);
3478 hdrptr += 4;
3479 if (length == 0xffffffff)
3481 /* This section is 64-bit DWARF 3. */
3482 length = byte_get (hdrptr, 8);
3483 hdrptr += 8;
3484 offset_size = 8;
3485 initial_length_size = 12;
3487 else
3489 offset_size = 4;
3490 initial_length_size = 4;
3492 if (length + initial_length_size > section->size)
3493 return NULL;
3494 version = byte_get (hdrptr, 2);
3495 hdrptr += 2;
3496 if (version != 2 && version != 3 && version != 4)
3497 return NULL;
3498 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3499 if (version >= 4)
3500 hdrptr++; /* Skip max_ops_per_insn. */
3501 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3502 opcode_base = byte_get (hdrptr, 1);
3503 if (opcode_base == 0)
3504 return NULL;
3505 hdrptr++;
3506 hdrptr += opcode_base - 1;
3507 dirtable = hdrptr;
3508 /* Skip over dirname table. */
3509 while (*hdrptr != '\0')
3510 hdrptr += strlen ((char *) hdrptr) + 1;
3511 hdrptr++; /* Skip the NUL at the end of the table. */
3512 /* Now skip over preceding filename table entries. */
3513 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3515 hdrptr += strlen ((char *) hdrptr) + 1;
3516 read_leb128 (hdrptr, &bytes_read, 0);
3517 hdrptr += bytes_read;
3518 read_leb128 (hdrptr, &bytes_read, 0);
3519 hdrptr += bytes_read;
3520 read_leb128 (hdrptr, &bytes_read, 0);
3521 hdrptr += bytes_read;
3523 if (*hdrptr == '\0')
3524 return NULL;
3525 file_name = hdrptr;
3526 hdrptr += strlen ((char *) hdrptr) + 1;
3527 diridx = read_leb128 (hdrptr, &bytes_read, 0);
3528 if (diridx == 0)
3529 return file_name;
3530 for (; *dirtable != '\0' && diridx > 1; diridx--)
3531 dirtable += strlen ((char *) dirtable) + 1;
3532 if (*dirtable == '\0')
3533 return NULL;
3534 *dir_name = dirtable;
3535 return file_name;
3538 static int
3539 display_debug_macro (struct dwarf_section *section,
3540 void *file)
3542 unsigned char *start = section->start;
3543 unsigned char *end = start + section->size;
3544 unsigned char *curr = start;
3545 unsigned char *extended_op_buf[256];
3546 unsigned int bytes_read;
3548 load_debug_section (str, file);
3549 load_debug_section (line, file);
3551 printf (_("Contents of the %s section:\n\n"), section->name);
3553 while (curr < end)
3555 unsigned int lineno, version, flags;
3556 unsigned int offset_size = 4;
3557 const char *string;
3558 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3559 unsigned char **extended_ops = NULL;
3561 version = byte_get (curr, 2);
3562 curr += 2;
3564 if (version != 4)
3566 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3567 section->name);
3568 return 0;
3571 flags = byte_get (curr++, 1);
3572 if (flags & 1)
3573 offset_size = 8;
3574 printf (_(" Offset: 0x%lx\n"),
3575 (unsigned long) sec_offset);
3576 printf (_(" Version: %d\n"), version);
3577 printf (_(" Offset size: %d\n"), offset_size);
3578 if (flags & 2)
3580 line_offset = byte_get (curr, offset_size);
3581 curr += offset_size;
3582 printf (_(" Offset into .debug_line: 0x%lx\n"),
3583 (unsigned long) line_offset);
3585 if (flags & 4)
3587 unsigned int i, count = byte_get (curr++, 1), op;
3588 dwarf_vma nargs, n;
3589 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3590 extended_ops = extended_op_buf;
3591 if (count)
3593 printf (_(" Extension opcode arguments:\n"));
3594 for (i = 0; i < count; i++)
3596 op = byte_get (curr++, 1);
3597 extended_ops[op] = curr;
3598 nargs = read_leb128 (curr, &bytes_read, 0);
3599 curr += bytes_read;
3600 if (nargs == 0)
3601 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3602 else
3604 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3605 for (n = 0; n < nargs; n++)
3607 unsigned int form = byte_get (curr++, 1);
3608 printf ("%s%s", get_FORM_name (form),
3609 n == nargs - 1 ? "\n" : ", ");
3610 switch (form)
3612 case DW_FORM_data1:
3613 case DW_FORM_data2:
3614 case DW_FORM_data4:
3615 case DW_FORM_data8:
3616 case DW_FORM_sdata:
3617 case DW_FORM_udata:
3618 case DW_FORM_block:
3619 case DW_FORM_block1:
3620 case DW_FORM_block2:
3621 case DW_FORM_block4:
3622 case DW_FORM_flag:
3623 case DW_FORM_string:
3624 case DW_FORM_strp:
3625 case DW_FORM_sec_offset:
3626 break;
3627 default:
3628 error (_("Invalid extension opcode form %s\n"),
3629 get_FORM_name (form));
3630 return 0;
3637 printf ("\n");
3639 while (1)
3641 unsigned int op;
3643 if (curr >= end)
3645 error (_(".debug_macro section not zero terminated\n"));
3646 return 0;
3649 op = byte_get (curr++, 1);
3650 if (op == 0)
3651 break;
3653 switch (op)
3655 case DW_MACRO_GNU_start_file:
3657 unsigned int filenum;
3658 unsigned char *file_name = NULL, *dir_name = NULL;
3660 lineno = read_leb128 (curr, &bytes_read, 0);
3661 curr += bytes_read;
3662 filenum = read_leb128 (curr, &bytes_read, 0);
3663 curr += bytes_read;
3665 if ((flags & 2) == 0)
3666 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3667 else
3668 file_name
3669 = get_line_filename_and_dirname (line_offset, filenum,
3670 &dir_name);
3671 if (file_name == NULL)
3672 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3673 lineno, filenum);
3674 else
3675 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3676 lineno, filenum,
3677 dir_name != NULL ? (const char *) dir_name : "",
3678 dir_name != NULL ? "/" : "", file_name);
3680 break;
3682 case DW_MACRO_GNU_end_file:
3683 printf (_(" DW_MACRO_GNU_end_file\n"));
3684 break;
3686 case DW_MACRO_GNU_define:
3687 lineno = read_leb128 (curr, &bytes_read, 0);
3688 curr += bytes_read;
3689 string = (char *) curr;
3690 curr += strlen (string) + 1;
3691 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3692 lineno, string);
3693 break;
3695 case DW_MACRO_GNU_undef:
3696 lineno = read_leb128 (curr, &bytes_read, 0);
3697 curr += bytes_read;
3698 string = (char *) curr;
3699 curr += strlen (string) + 1;
3700 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3701 lineno, string);
3702 break;
3704 case DW_MACRO_GNU_define_indirect:
3705 lineno = read_leb128 (curr, &bytes_read, 0);
3706 curr += bytes_read;
3707 offset = byte_get (curr, offset_size);
3708 curr += offset_size;
3709 string = fetch_indirect_string (offset);
3710 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3711 lineno, string);
3712 break;
3714 case DW_MACRO_GNU_undef_indirect:
3715 lineno = read_leb128 (curr, &bytes_read, 0);
3716 curr += bytes_read;
3717 offset = byte_get (curr, offset_size);
3718 curr += offset_size;
3719 string = fetch_indirect_string (offset);
3720 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3721 lineno, string);
3722 break;
3724 case DW_MACRO_GNU_transparent_include:
3725 offset = byte_get (curr, offset_size);
3726 curr += offset_size;
3727 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
3728 (unsigned long) offset);
3729 break;
3731 default:
3732 if (extended_ops == NULL || extended_ops[op] == NULL)
3734 error (_(" Unknown macro opcode %02x seen\n"), op);
3735 return 0;
3737 else
3739 /* Skip over unhandled opcodes. */
3740 dwarf_vma nargs, n;
3741 unsigned char *desc = extended_ops[op];
3742 nargs = read_leb128 (desc, &bytes_read, 0);
3743 desc += bytes_read;
3744 if (nargs == 0)
3746 printf (_(" DW_MACRO_GNU_%02x\n"), op);
3747 break;
3749 printf (_(" DW_MACRO_GNU_%02x -"), op);
3750 for (n = 0; n < nargs; n++)
3752 curr
3753 = read_and_display_attr_value (0, byte_get (desc++, 1),
3754 curr, 0, 0, offset_size,
3755 version, NULL, 0, NULL);
3756 if (n != nargs - 1)
3757 printf (",");
3759 printf ("\n");
3761 break;
3765 printf ("\n");
3768 return 1;
3771 static int
3772 display_debug_abbrev (struct dwarf_section *section,
3773 void *file ATTRIBUTE_UNUSED)
3775 abbrev_entry *entry;
3776 unsigned char *start = section->start;
3777 unsigned char *end = start + section->size;
3779 printf (_("Contents of the %s section:\n\n"), section->name);
3783 free_abbrevs ();
3785 start = process_abbrev_section (start, end);
3787 if (first_abbrev == NULL)
3788 continue;
3790 printf (_(" Number TAG\n"));
3792 for (entry = first_abbrev; entry; entry = entry->next)
3794 abbrev_attr *attr;
3796 printf (" %ld %s [%s]\n",
3797 entry->entry,
3798 get_TAG_name (entry->tag),
3799 entry->children ? _("has children") : _("no children"));
3801 for (attr = entry->first_attr; attr; attr = attr->next)
3802 printf (" %-18s %s\n",
3803 get_AT_name (attr->attribute),
3804 get_FORM_name (attr->form));
3807 while (start);
3809 printf ("\n");
3811 return 1;
3814 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
3816 static dwarf_vma *loc_offsets;
3818 static int
3819 loc_offsets_compar (const void *ap, const void *bp)
3821 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
3822 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
3824 return (a > b) - (b > a);
3827 static int
3828 display_debug_loc (struct dwarf_section *section, void *file)
3830 unsigned char *start = section->start;
3831 unsigned char *section_end;
3832 unsigned long bytes;
3833 unsigned char *section_begin = start;
3834 unsigned int num_loc_list = 0;
3835 unsigned long last_offset = 0;
3836 unsigned int first = 0;
3837 unsigned int i;
3838 unsigned int j;
3839 unsigned int k;
3840 int seen_first_offset = 0;
3841 int locs_sorted = 1;
3842 unsigned char *next;
3843 unsigned int *array = NULL;
3845 bytes = section->size;
3846 section_end = start + bytes;
3848 if (bytes == 0)
3850 printf (_("\nThe %s section is empty.\n"), section->name);
3851 return 0;
3854 if (load_debug_info (file) == 0)
3856 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3857 section->name);
3858 return 0;
3861 /* Check the order of location list in .debug_info section. If
3862 offsets of location lists are in the ascending order, we can
3863 use `debug_information' directly. */
3864 for (i = 0; i < num_debug_info_entries; i++)
3866 unsigned int num;
3868 num = debug_information [i].num_loc_offsets;
3869 if (num > num_loc_list)
3870 num_loc_list = num;
3872 /* Check if we can use `debug_information' directly. */
3873 if (locs_sorted && num != 0)
3875 if (!seen_first_offset)
3877 /* This is the first location list. */
3878 last_offset = debug_information [i].loc_offsets [0];
3879 first = i;
3880 seen_first_offset = 1;
3881 j = 1;
3883 else
3884 j = 0;
3886 for (; j < num; j++)
3888 if (last_offset >
3889 debug_information [i].loc_offsets [j])
3891 locs_sorted = 0;
3892 break;
3894 last_offset = debug_information [i].loc_offsets [j];
3899 if (!seen_first_offset)
3900 error (_("No location lists in .debug_info section!\n"));
3902 /* DWARF sections under Mach-O have non-zero addresses. */
3903 if (debug_information [first].num_loc_offsets > 0
3904 && debug_information [first].loc_offsets [0] != section->address)
3905 warn (_("Location lists in %s section start at 0x%s\n"),
3906 section->name,
3907 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
3909 if (!locs_sorted)
3910 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
3911 printf (_("Contents of the %s section:\n\n"), section->name);
3912 printf (_(" Offset Begin End Expression\n"));
3914 seen_first_offset = 0;
3915 for (i = first; i < num_debug_info_entries; i++)
3917 dwarf_vma begin;
3918 dwarf_vma end;
3919 unsigned short length;
3920 unsigned long offset;
3921 unsigned int pointer_size;
3922 unsigned int offset_size;
3923 int dwarf_version;
3924 unsigned long cu_offset;
3925 unsigned long base_address;
3926 int need_frame_base;
3927 int has_frame_base;
3929 pointer_size = debug_information [i].pointer_size;
3930 cu_offset = debug_information [i].cu_offset;
3931 offset_size = debug_information [i].offset_size;
3932 dwarf_version = debug_information [i].dwarf_version;
3933 if (!locs_sorted)
3935 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
3936 array[k] = k;
3937 loc_offsets = debug_information [i].loc_offsets;
3938 qsort (array, debug_information [i].num_loc_offsets,
3939 sizeof (*array), loc_offsets_compar);
3942 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
3944 j = locs_sorted ? k : array[k];
3945 if (k
3946 && debug_information [i].loc_offsets [locs_sorted
3947 ? k - 1 : array [k - 1]]
3948 == debug_information [i].loc_offsets [j])
3949 continue;
3950 has_frame_base = debug_information [i].have_frame_base [j];
3951 /* DWARF sections under Mach-O have non-zero addresses. */
3952 offset = debug_information [i].loc_offsets [j] - section->address;
3953 next = section_begin + offset;
3954 base_address = debug_information [i].base_address;
3956 if (!seen_first_offset)
3957 seen_first_offset = 1;
3958 else
3960 if (start < next)
3961 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3962 (unsigned long) (start - section_begin),
3963 (unsigned long) (next - section_begin));
3964 else if (start > next)
3965 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3966 (unsigned long) (start - section_begin),
3967 (unsigned long) (next - section_begin));
3969 start = next;
3971 if (offset >= bytes)
3973 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3974 offset);
3975 continue;
3978 while (1)
3980 if (start + 2 * pointer_size > section_end)
3982 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3983 offset);
3984 break;
3987 /* Note: we use sign extension here in order to be sure that
3988 we can detect the -1 escape value. Sign extension into the
3989 top 32 bits of a 32-bit address will not affect the values
3990 that we display since we always show hex values, and always
3991 the bottom 32-bits. */
3992 begin = byte_get_signed (start, pointer_size);
3993 start += pointer_size;
3994 end = byte_get_signed (start, pointer_size);
3995 start += pointer_size;
3997 printf (" %8.8lx ", offset);
3999 if (begin == 0 && end == 0)
4001 printf (_("<End of list>\n"));
4002 break;
4005 /* Check base address specifiers. */
4006 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4008 base_address = end;
4009 print_dwarf_vma (begin, pointer_size);
4010 print_dwarf_vma (end, pointer_size);
4011 printf (_("(base address)\n"));
4012 continue;
4015 if (start + 2 > section_end)
4017 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4018 offset);
4019 break;
4022 length = byte_get (start, 2);
4023 start += 2;
4025 if (start + length > section_end)
4027 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4028 offset);
4029 break;
4032 print_dwarf_vma (begin + base_address, pointer_size);
4033 print_dwarf_vma (end + base_address, pointer_size);
4035 putchar ('(');
4036 need_frame_base = decode_location_expression (start,
4037 pointer_size,
4038 offset_size,
4039 dwarf_version,
4040 length,
4041 cu_offset, section);
4042 putchar (')');
4044 if (need_frame_base && !has_frame_base)
4045 printf (_(" [without DW_AT_frame_base]"));
4047 if (begin == end)
4048 fputs (_(" (start == end)"), stdout);
4049 else if (begin > end)
4050 fputs (_(" (start > end)"), stdout);
4052 putchar ('\n');
4054 start += length;
4059 if (start < section_end)
4060 warn (_("There are %ld unused bytes at the end of section %s\n"),
4061 (long) (section_end - start), section->name);
4062 putchar ('\n');
4063 free (array);
4064 return 1;
4067 static int
4068 display_debug_str (struct dwarf_section *section,
4069 void *file ATTRIBUTE_UNUSED)
4071 unsigned char *start = section->start;
4072 unsigned long bytes = section->size;
4073 dwarf_vma addr = section->address;
4075 if (bytes == 0)
4077 printf (_("\nThe %s section is empty.\n"), section->name);
4078 return 0;
4081 printf (_("Contents of the %s section:\n\n"), section->name);
4083 while (bytes)
4085 int j;
4086 int k;
4087 int lbytes;
4089 lbytes = (bytes > 16 ? 16 : bytes);
4091 printf (" 0x%8.8lx ", (unsigned long) addr);
4093 for (j = 0; j < 16; j++)
4095 if (j < lbytes)
4096 printf ("%2.2x", start[j]);
4097 else
4098 printf (" ");
4100 if ((j & 3) == 3)
4101 printf (" ");
4104 for (j = 0; j < lbytes; j++)
4106 k = start[j];
4107 if (k >= ' ' && k < 0x80)
4108 printf ("%c", k);
4109 else
4110 printf (".");
4113 putchar ('\n');
4115 start += lbytes;
4116 addr += lbytes;
4117 bytes -= lbytes;
4120 putchar ('\n');
4122 return 1;
4125 static int
4126 display_debug_info (struct dwarf_section *section, void *file)
4128 return process_debug_info (section, file, abbrev, 0, 0);
4131 static int
4132 display_debug_types (struct dwarf_section *section, void *file)
4134 return process_debug_info (section, file, abbrev, 0, 1);
4137 static int
4138 display_trace_info (struct dwarf_section *section, void *file)
4140 return process_debug_info (section, file, trace_abbrev, 0, 0);
4143 static int
4144 display_debug_aranges (struct dwarf_section *section,
4145 void *file ATTRIBUTE_UNUSED)
4147 unsigned char *start = section->start;
4148 unsigned char *end = start + section->size;
4150 printf (_("Contents of the %s section:\n\n"), section->name);
4152 /* It does not matter if this load fails,
4153 we test for that later on. */
4154 load_debug_info (file);
4156 while (start < end)
4158 unsigned char *hdrptr;
4159 DWARF2_Internal_ARange arange;
4160 unsigned char *addr_ranges;
4161 dwarf_vma length;
4162 dwarf_vma address;
4163 unsigned char address_size;
4164 int excess;
4165 int offset_size;
4166 int initial_length_size;
4168 hdrptr = start;
4170 arange.ar_length = byte_get (hdrptr, 4);
4171 hdrptr += 4;
4173 if (arange.ar_length == 0xffffffff)
4175 arange.ar_length = byte_get (hdrptr, 8);
4176 hdrptr += 8;
4177 offset_size = 8;
4178 initial_length_size = 12;
4180 else
4182 offset_size = 4;
4183 initial_length_size = 4;
4186 arange.ar_version = byte_get (hdrptr, 2);
4187 hdrptr += 2;
4189 arange.ar_info_offset = byte_get (hdrptr, offset_size);
4190 hdrptr += offset_size;
4192 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4193 && num_debug_info_entries > 0
4194 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4195 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4196 (unsigned long) arange.ar_info_offset, section->name);
4198 arange.ar_pointer_size = byte_get (hdrptr, 1);
4199 hdrptr += 1;
4201 arange.ar_segment_size = byte_get (hdrptr, 1);
4202 hdrptr += 1;
4204 if (arange.ar_version != 2 && arange.ar_version != 3)
4206 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4207 break;
4210 printf (_(" Length: %ld\n"),
4211 (long) arange.ar_length);
4212 printf (_(" Version: %d\n"), arange.ar_version);
4213 printf (_(" Offset into .debug_info: 0x%lx\n"),
4214 (unsigned long) arange.ar_info_offset);
4215 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4216 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4218 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4220 if (address_size == 0)
4222 error (_("Invalid address size in %s section!\n"),
4223 section->name);
4224 break;
4227 /* The DWARF spec does not require that the address size be a power
4228 of two, but we do. This will have to change if we ever encounter
4229 an uneven architecture. */
4230 if ((address_size & (address_size - 1)) != 0)
4232 warn (_("Pointer size + Segment size is not a power of two.\n"));
4233 break;
4236 if (address_size > 4)
4237 printf (_("\n Address Length\n"));
4238 else
4239 printf (_("\n Address Length\n"));
4241 addr_ranges = hdrptr;
4243 /* Must pad to an alignment boundary that is twice the address size. */
4244 excess = (hdrptr - start) % (2 * address_size);
4245 if (excess)
4246 addr_ranges += (2 * address_size) - excess;
4248 start += arange.ar_length + initial_length_size;
4250 while (addr_ranges + 2 * address_size <= start)
4252 address = byte_get (addr_ranges, address_size);
4254 addr_ranges += address_size;
4256 length = byte_get (addr_ranges, address_size);
4258 addr_ranges += address_size;
4260 printf (" ");
4261 print_dwarf_vma (address, address_size);
4262 print_dwarf_vma (length, address_size);
4263 putchar ('\n');
4267 printf ("\n");
4269 return 1;
4272 /* Each debug_information[x].range_lists[y] gets this representation for
4273 sorting purposes. */
4275 struct range_entry
4277 /* The debug_information[x].range_lists[y] value. */
4278 unsigned long ranges_offset;
4280 /* Original debug_information to find parameters of the data. */
4281 debug_info *debug_info_p;
4284 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4286 static int
4287 range_entry_compar (const void *ap, const void *bp)
4289 const struct range_entry *a_re = (const struct range_entry *) ap;
4290 const struct range_entry *b_re = (const struct range_entry *) bp;
4291 const unsigned long a = a_re->ranges_offset;
4292 const unsigned long b = b_re->ranges_offset;
4294 return (a > b) - (b > a);
4297 static int
4298 display_debug_ranges (struct dwarf_section *section,
4299 void *file ATTRIBUTE_UNUSED)
4301 unsigned char *start = section->start;
4302 unsigned long bytes;
4303 unsigned char *section_begin = start;
4304 unsigned int num_range_list, i;
4305 struct range_entry *range_entries, *range_entry_fill;
4307 bytes = section->size;
4309 if (bytes == 0)
4311 printf (_("\nThe %s section is empty.\n"), section->name);
4312 return 0;
4315 if (load_debug_info (file) == 0)
4317 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4318 section->name);
4319 return 0;
4322 num_range_list = 0;
4323 for (i = 0; i < num_debug_info_entries; i++)
4324 num_range_list += debug_information [i].num_range_lists;
4326 if (num_range_list == 0)
4327 error (_("No range lists in .debug_info section!\n"));
4329 range_entries = (struct range_entry *)
4330 xmalloc (sizeof (*range_entries) * num_range_list);
4331 range_entry_fill = range_entries;
4333 for (i = 0; i < num_debug_info_entries; i++)
4335 debug_info *debug_info_p = &debug_information[i];
4336 unsigned int j;
4338 for (j = 0; j < debug_info_p->num_range_lists; j++)
4340 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4341 range_entry_fill->debug_info_p = debug_info_p;
4342 range_entry_fill++;
4346 qsort (range_entries, num_range_list, sizeof (*range_entries),
4347 range_entry_compar);
4349 /* DWARF sections under Mach-O have non-zero addresses. */
4350 if (range_entries[0].ranges_offset != section->address)
4351 warn (_("Range lists in %s section start at 0x%lx\n"),
4352 section->name, range_entries[0].ranges_offset);
4354 printf (_("Contents of the %s section:\n\n"), section->name);
4355 printf (_(" Offset Begin End\n"));
4357 for (i = 0; i < num_range_list; i++)
4359 struct range_entry *range_entry = &range_entries[i];
4360 debug_info *debug_info_p = range_entry->debug_info_p;
4361 unsigned int pointer_size;
4362 unsigned long offset;
4363 unsigned char *next;
4364 unsigned long base_address;
4366 pointer_size = debug_info_p->pointer_size;
4368 /* DWARF sections under Mach-O have non-zero addresses. */
4369 offset = range_entry->ranges_offset - section->address;
4370 next = section_begin + offset;
4371 base_address = debug_info_p->base_address;
4373 if (i > 0)
4375 if (start < next)
4376 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4377 (unsigned long) (start - section_begin),
4378 (unsigned long) (next - section_begin), section->name);
4379 else if (start > next)
4380 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4381 (unsigned long) (start - section_begin),
4382 (unsigned long) (next - section_begin), section->name);
4384 start = next;
4386 while (1)
4388 dwarf_vma begin;
4389 dwarf_vma end;
4391 /* Note: we use sign extension here in order to be sure that
4392 we can detect the -1 escape value. Sign extension into the
4393 top 32 bits of a 32-bit address will not affect the values
4394 that we display since we always show hex values, and always
4395 the bottom 32-bits. */
4396 begin = byte_get_signed (start, pointer_size);
4397 start += pointer_size;
4398 end = byte_get_signed (start, pointer_size);
4399 start += pointer_size;
4401 printf (" %8.8lx ", offset);
4403 if (begin == 0 && end == 0)
4405 printf (_("<End of list>\n"));
4406 break;
4409 /* Check base address specifiers. */
4410 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4412 base_address = end;
4413 print_dwarf_vma (begin, pointer_size);
4414 print_dwarf_vma (end, pointer_size);
4415 printf ("(base address)\n");
4416 continue;
4419 print_dwarf_vma (begin + base_address, pointer_size);
4420 print_dwarf_vma (end + base_address, pointer_size);
4422 if (begin == end)
4423 fputs (_("(start == end)"), stdout);
4424 else if (begin > end)
4425 fputs (_("(start > end)"), stdout);
4427 putchar ('\n');
4430 putchar ('\n');
4432 free (range_entries);
4434 return 1;
4437 typedef struct Frame_Chunk
4439 struct Frame_Chunk *next;
4440 unsigned char *chunk_start;
4441 int ncols;
4442 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4443 short int *col_type;
4444 int *col_offset;
4445 char *augmentation;
4446 unsigned int code_factor;
4447 int data_factor;
4448 unsigned long pc_begin;
4449 unsigned long pc_range;
4450 int cfa_reg;
4451 int cfa_offset;
4452 int ra;
4453 unsigned char fde_encoding;
4454 unsigned char cfa_exp;
4455 unsigned char ptr_size;
4456 unsigned char segment_size;
4458 Frame_Chunk;
4460 static const char *const *dwarf_regnames;
4461 static unsigned int dwarf_regnames_count;
4463 /* A marker for a col_type that means this column was never referenced
4464 in the frame info. */
4465 #define DW_CFA_unreferenced (-1)
4467 /* Return 0 if not more space is needed, 1 if more space is needed,
4468 -1 for invalid reg. */
4470 static int
4471 frame_need_space (Frame_Chunk *fc, unsigned int reg)
4473 int prev = fc->ncols;
4475 if (reg < (unsigned int) fc->ncols)
4476 return 0;
4478 if (dwarf_regnames_count
4479 && reg > dwarf_regnames_count)
4480 return -1;
4482 fc->ncols = reg + 1;
4483 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
4484 sizeof (short int));
4485 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
4487 while (prev < fc->ncols)
4489 fc->col_type[prev] = DW_CFA_unreferenced;
4490 fc->col_offset[prev] = 0;
4491 prev++;
4493 return 1;
4496 static const char *const dwarf_regnames_i386[] =
4498 "eax", "ecx", "edx", "ebx",
4499 "esp", "ebp", "esi", "edi",
4500 "eip", "eflags", NULL,
4501 "st0", "st1", "st2", "st3",
4502 "st4", "st5", "st6", "st7",
4503 NULL, NULL,
4504 "xmm0", "xmm1", "xmm2", "xmm3",
4505 "xmm4", "xmm5", "xmm6", "xmm7",
4506 "mm0", "mm1", "mm2", "mm3",
4507 "mm4", "mm5", "mm6", "mm7",
4508 "fcw", "fsw", "mxcsr",
4509 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4510 "tr", "ldtr"
4513 void
4514 init_dwarf_regnames_i386 (void)
4516 dwarf_regnames = dwarf_regnames_i386;
4517 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
4520 static const char *const dwarf_regnames_x86_64[] =
4522 "rax", "rdx", "rcx", "rbx",
4523 "rsi", "rdi", "rbp", "rsp",
4524 "r8", "r9", "r10", "r11",
4525 "r12", "r13", "r14", "r15",
4526 "rip",
4527 "xmm0", "xmm1", "xmm2", "xmm3",
4528 "xmm4", "xmm5", "xmm6", "xmm7",
4529 "xmm8", "xmm9", "xmm10", "xmm11",
4530 "xmm12", "xmm13", "xmm14", "xmm15",
4531 "st0", "st1", "st2", "st3",
4532 "st4", "st5", "st6", "st7",
4533 "mm0", "mm1", "mm2", "mm3",
4534 "mm4", "mm5", "mm6", "mm7",
4535 "rflags",
4536 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
4537 "fs.base", "gs.base", NULL, NULL,
4538 "tr", "ldtr",
4539 "mxcsr", "fcw", "fsw"
4542 void
4543 init_dwarf_regnames_x86_64 (void)
4545 dwarf_regnames = dwarf_regnames_x86_64;
4546 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4549 void
4550 init_dwarf_regnames (unsigned int e_machine)
4552 switch (e_machine)
4554 case EM_386:
4555 case EM_486:
4556 init_dwarf_regnames_i386 ();
4557 break;
4559 case EM_X86_64:
4560 case EM_L1OM:
4561 case EM_K1OM:
4562 init_dwarf_regnames_x86_64 ();
4563 break;
4565 default:
4566 break;
4570 static const char *
4571 regname (unsigned int regno, int row)
4573 static char reg[64];
4574 if (dwarf_regnames
4575 && regno < dwarf_regnames_count
4576 && dwarf_regnames [regno] != NULL)
4578 if (row)
4579 return dwarf_regnames [regno];
4580 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4581 dwarf_regnames [regno]);
4583 else
4584 snprintf (reg, sizeof (reg), "r%d", regno);
4585 return reg;
4588 static void
4589 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4591 int r;
4592 char tmp[100];
4594 if (*max_regs < fc->ncols)
4595 *max_regs = fc->ncols;
4597 if (*need_col_headers)
4599 static const char *sloc = " LOC";
4601 *need_col_headers = 0;
4603 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4605 for (r = 0; r < *max_regs; r++)
4606 if (fc->col_type[r] != DW_CFA_unreferenced)
4608 if (r == fc->ra)
4609 printf ("ra ");
4610 else
4611 printf ("%-5s ", regname (r, 1));
4614 printf ("\n");
4617 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4618 if (fc->cfa_exp)
4619 strcpy (tmp, "exp");
4620 else
4621 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4622 printf ("%-8s ", tmp);
4624 for (r = 0; r < fc->ncols; r++)
4626 if (fc->col_type[r] != DW_CFA_unreferenced)
4628 switch (fc->col_type[r])
4630 case DW_CFA_undefined:
4631 strcpy (tmp, "u");
4632 break;
4633 case DW_CFA_same_value:
4634 strcpy (tmp, "s");
4635 break;
4636 case DW_CFA_offset:
4637 sprintf (tmp, "c%+d", fc->col_offset[r]);
4638 break;
4639 case DW_CFA_val_offset:
4640 sprintf (tmp, "v%+d", fc->col_offset[r]);
4641 break;
4642 case DW_CFA_register:
4643 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4644 break;
4645 case DW_CFA_expression:
4646 strcpy (tmp, "exp");
4647 break;
4648 case DW_CFA_val_expression:
4649 strcpy (tmp, "vexp");
4650 break;
4651 default:
4652 strcpy (tmp, "n/a");
4653 break;
4655 printf ("%-5s ", tmp);
4658 printf ("\n");
4661 #define GET(N) byte_get (start, N); start += N
4662 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4663 #define SLEB() read_sleb128 (start, & length_return); start += length_return
4665 static int
4666 display_debug_frames (struct dwarf_section *section,
4667 void *file ATTRIBUTE_UNUSED)
4669 unsigned char *start = section->start;
4670 unsigned char *end = start + section->size;
4671 unsigned char *section_start = start;
4672 Frame_Chunk *chunks = 0;
4673 Frame_Chunk *remembered_state = 0;
4674 Frame_Chunk *rs;
4675 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4676 unsigned int length_return;
4677 int max_regs = 0;
4678 const char *bad_reg = _("bad register: ");
4679 int saved_eh_addr_size = eh_addr_size;
4681 printf (_("Contents of the %s section:\n"), section->name);
4683 while (start < end)
4685 unsigned char *saved_start;
4686 unsigned char *block_end;
4687 unsigned long length;
4688 unsigned long cie_id;
4689 Frame_Chunk *fc;
4690 Frame_Chunk *cie;
4691 int need_col_headers = 1;
4692 unsigned char *augmentation_data = NULL;
4693 unsigned long augmentation_data_len = 0;
4694 int encoded_ptr_size = saved_eh_addr_size;
4695 int offset_size;
4696 int initial_length_size;
4698 saved_start = start;
4699 length = byte_get (start, 4); start += 4;
4701 if (length == 0)
4703 printf ("\n%08lx ZERO terminator\n\n",
4704 (unsigned long)(saved_start - section_start));
4705 continue;
4708 if (length == 0xffffffff)
4710 length = byte_get (start, 8);
4711 start += 8;
4712 offset_size = 8;
4713 initial_length_size = 12;
4715 else
4717 offset_size = 4;
4718 initial_length_size = 4;
4721 block_end = saved_start + length + initial_length_size;
4722 if (block_end > end)
4724 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4725 length, (unsigned long)(saved_start - section_start));
4726 block_end = end;
4728 cie_id = byte_get (start, offset_size); start += offset_size;
4730 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4732 int version;
4734 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4735 memset (fc, 0, sizeof (Frame_Chunk));
4737 fc->next = chunks;
4738 chunks = fc;
4739 fc->chunk_start = saved_start;
4740 fc->ncols = 0;
4741 fc->col_type = (short int *) xmalloc (sizeof (short int));
4742 fc->col_offset = (int *) xmalloc (sizeof (int));
4743 frame_need_space (fc, max_regs - 1);
4745 version = *start++;
4747 fc->augmentation = (char *) start;
4748 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4750 if (strcmp (fc->augmentation, "eh") == 0)
4751 start += eh_addr_size;
4753 if (version >= 4)
4755 fc->ptr_size = GET (1);
4756 fc->segment_size = GET (1);
4757 eh_addr_size = fc->ptr_size;
4759 else
4761 fc->ptr_size = eh_addr_size;
4762 fc->segment_size = 0;
4764 fc->code_factor = LEB ();
4765 fc->data_factor = SLEB ();
4766 if (version == 1)
4768 fc->ra = GET (1);
4770 else
4772 fc->ra = LEB ();
4775 if (fc->augmentation[0] == 'z')
4777 augmentation_data_len = LEB ();
4778 augmentation_data = start;
4779 start += augmentation_data_len;
4781 cie = fc;
4783 if (do_debug_frames_interp)
4784 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4785 (unsigned long)(saved_start - section_start), length, cie_id,
4786 fc->augmentation, fc->code_factor, fc->data_factor,
4787 fc->ra);
4788 else
4790 printf ("\n%08lx %08lx %08lx CIE\n",
4791 (unsigned long)(saved_start - section_start), length, cie_id);
4792 printf (" Version: %d\n", version);
4793 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4794 if (version >= 4)
4796 printf (" Pointer Size: %u\n", fc->ptr_size);
4797 printf (" Segment Size: %u\n", fc->segment_size);
4799 printf (" Code alignment factor: %u\n", fc->code_factor);
4800 printf (" Data alignment factor: %d\n", fc->data_factor);
4801 printf (" Return address column: %d\n", fc->ra);
4803 if (augmentation_data_len)
4805 unsigned long i;
4806 printf (" Augmentation data: ");
4807 for (i = 0; i < augmentation_data_len; ++i)
4808 printf (" %02x", augmentation_data[i]);
4809 putchar ('\n');
4811 putchar ('\n');
4814 if (augmentation_data_len)
4816 unsigned char *p, *q;
4817 p = (unsigned char *) fc->augmentation + 1;
4818 q = augmentation_data;
4820 while (1)
4822 if (*p == 'L')
4823 q++;
4824 else if (*p == 'P')
4825 q += 1 + size_of_encoded_value (*q);
4826 else if (*p == 'R')
4827 fc->fde_encoding = *q++;
4828 else if (*p == 'S')
4830 else
4831 break;
4832 p++;
4835 if (fc->fde_encoding)
4836 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4839 frame_need_space (fc, fc->ra);
4841 else
4843 unsigned char *look_for;
4844 static Frame_Chunk fde_fc;
4845 unsigned long segment_selector;
4847 fc = & fde_fc;
4848 memset (fc, 0, sizeof (Frame_Chunk));
4850 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
4852 for (cie = chunks; cie ; cie = cie->next)
4853 if (cie->chunk_start == look_for)
4854 break;
4856 if (!cie)
4858 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4859 cie_id, (unsigned long)(saved_start - section_start));
4860 fc->ncols = 0;
4861 fc->col_type = (short int *) xmalloc (sizeof (short int));
4862 fc->col_offset = (int *) xmalloc (sizeof (int));
4863 frame_need_space (fc, max_regs - 1);
4864 cie = fc;
4865 fc->augmentation = "";
4866 fc->fde_encoding = 0;
4867 fc->ptr_size = eh_addr_size;
4868 fc->segment_size = 0;
4870 else
4872 fc->ncols = cie->ncols;
4873 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
4874 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
4875 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
4876 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
4877 fc->augmentation = cie->augmentation;
4878 fc->ptr_size = cie->ptr_size;
4879 eh_addr_size = cie->ptr_size;
4880 fc->segment_size = cie->segment_size;
4881 fc->code_factor = cie->code_factor;
4882 fc->data_factor = cie->data_factor;
4883 fc->cfa_reg = cie->cfa_reg;
4884 fc->cfa_offset = cie->cfa_offset;
4885 fc->ra = cie->ra;
4886 frame_need_space (fc, max_regs - 1);
4887 fc->fde_encoding = cie->fde_encoding;
4890 if (fc->fde_encoding)
4891 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4893 segment_selector = 0;
4894 if (fc->segment_size)
4896 segment_selector = byte_get (start, fc->segment_size);
4897 start += fc->segment_size;
4899 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
4900 start += encoded_ptr_size;
4901 fc->pc_range = byte_get (start, encoded_ptr_size);
4902 start += encoded_ptr_size;
4904 if (cie->augmentation[0] == 'z')
4906 augmentation_data_len = LEB ();
4907 augmentation_data = start;
4908 start += augmentation_data_len;
4911 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4912 (unsigned long)(saved_start - section_start), length, cie_id,
4913 (unsigned long)(cie->chunk_start - section_start));
4914 if (fc->segment_size)
4915 printf ("%04lx:", segment_selector);
4916 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
4917 if (! do_debug_frames_interp && augmentation_data_len)
4919 unsigned long i;
4921 printf (" Augmentation data: ");
4922 for (i = 0; i < augmentation_data_len; ++i)
4923 printf (" %02x", augmentation_data[i]);
4924 putchar ('\n');
4925 putchar ('\n');
4929 /* At this point, fc is the current chunk, cie (if any) is set, and
4930 we're about to interpret instructions for the chunk. */
4931 /* ??? At present we need to do this always, since this sizes the
4932 fc->col_type and fc->col_offset arrays, which we write into always.
4933 We should probably split the interpreted and non-interpreted bits
4934 into two different routines, since there's so much that doesn't
4935 really overlap between them. */
4936 if (1 || do_debug_frames_interp)
4938 /* Start by making a pass over the chunk, allocating storage
4939 and taking note of what registers are used. */
4940 unsigned char *tmp = start;
4942 while (start < block_end)
4944 unsigned op, opa;
4945 unsigned long reg, temp;
4947 op = *start++;
4948 opa = op & 0x3f;
4949 if (op & 0xc0)
4950 op &= 0xc0;
4952 /* Warning: if you add any more cases to this switch, be
4953 sure to add them to the corresponding switch below. */
4954 switch (op)
4956 case DW_CFA_advance_loc:
4957 break;
4958 case DW_CFA_offset:
4959 LEB ();
4960 if (frame_need_space (fc, opa) >= 0)
4961 fc->col_type[opa] = DW_CFA_undefined;
4962 break;
4963 case DW_CFA_restore:
4964 if (frame_need_space (fc, opa) >= 0)
4965 fc->col_type[opa] = DW_CFA_undefined;
4966 break;
4967 case DW_CFA_set_loc:
4968 start += encoded_ptr_size;
4969 break;
4970 case DW_CFA_advance_loc1:
4971 start += 1;
4972 break;
4973 case DW_CFA_advance_loc2:
4974 start += 2;
4975 break;
4976 case DW_CFA_advance_loc4:
4977 start += 4;
4978 break;
4979 case DW_CFA_offset_extended:
4980 case DW_CFA_val_offset:
4981 reg = LEB (); LEB ();
4982 if (frame_need_space (fc, reg) >= 0)
4983 fc->col_type[reg] = DW_CFA_undefined;
4984 break;
4985 case DW_CFA_restore_extended:
4986 reg = LEB ();
4987 frame_need_space (fc, reg);
4988 if (frame_need_space (fc, reg) >= 0)
4989 fc->col_type[reg] = DW_CFA_undefined;
4990 break;
4991 case DW_CFA_undefined:
4992 reg = LEB ();
4993 if (frame_need_space (fc, reg) >= 0)
4994 fc->col_type[reg] = DW_CFA_undefined;
4995 break;
4996 case DW_CFA_same_value:
4997 reg = LEB ();
4998 if (frame_need_space (fc, reg) >= 0)
4999 fc->col_type[reg] = DW_CFA_undefined;
5000 break;
5001 case DW_CFA_register:
5002 reg = LEB (); LEB ();
5003 if (frame_need_space (fc, reg) >= 0)
5004 fc->col_type[reg] = DW_CFA_undefined;
5005 break;
5006 case DW_CFA_def_cfa:
5007 LEB (); LEB ();
5008 break;
5009 case DW_CFA_def_cfa_register:
5010 LEB ();
5011 break;
5012 case DW_CFA_def_cfa_offset:
5013 LEB ();
5014 break;
5015 case DW_CFA_def_cfa_expression:
5016 temp = LEB ();
5017 start += temp;
5018 break;
5019 case DW_CFA_expression:
5020 case DW_CFA_val_expression:
5021 reg = LEB ();
5022 temp = LEB ();
5023 start += temp;
5024 if (frame_need_space (fc, reg) >= 0)
5025 fc->col_type[reg] = DW_CFA_undefined;
5026 break;
5027 case DW_CFA_offset_extended_sf:
5028 case DW_CFA_val_offset_sf:
5029 reg = LEB (); SLEB ();
5030 if (frame_need_space (fc, reg) >= 0)
5031 fc->col_type[reg] = DW_CFA_undefined;
5032 break;
5033 case DW_CFA_def_cfa_sf:
5034 LEB (); SLEB ();
5035 break;
5036 case DW_CFA_def_cfa_offset_sf:
5037 SLEB ();
5038 break;
5039 case DW_CFA_MIPS_advance_loc8:
5040 start += 8;
5041 break;
5042 case DW_CFA_GNU_args_size:
5043 LEB ();
5044 break;
5045 case DW_CFA_GNU_negative_offset_extended:
5046 reg = LEB (); LEB ();
5047 if (frame_need_space (fc, reg) >= 0)
5048 fc->col_type[reg] = DW_CFA_undefined;
5049 break;
5050 default:
5051 break;
5054 start = tmp;
5057 /* Now we know what registers are used, make a second pass over
5058 the chunk, this time actually printing out the info. */
5060 while (start < block_end)
5062 unsigned op, opa;
5063 unsigned long ul, reg, roffs;
5064 long l, ofs;
5065 dwarf_vma vma;
5066 const char *reg_prefix = "";
5068 op = *start++;
5069 opa = op & 0x3f;
5070 if (op & 0xc0)
5071 op &= 0xc0;
5073 /* Warning: if you add any more cases to this switch, be
5074 sure to add them to the corresponding switch above. */
5075 switch (op)
5077 case DW_CFA_advance_loc:
5078 if (do_debug_frames_interp)
5079 frame_display_row (fc, &need_col_headers, &max_regs);
5080 else
5081 printf (" DW_CFA_advance_loc: %d to %08lx\n",
5082 opa * fc->code_factor,
5083 fc->pc_begin + opa * fc->code_factor);
5084 fc->pc_begin += opa * fc->code_factor;
5085 break;
5087 case DW_CFA_offset:
5088 roffs = LEB ();
5089 if (opa >= (unsigned int) fc->ncols)
5090 reg_prefix = bad_reg;
5091 if (! do_debug_frames_interp || *reg_prefix != '\0')
5092 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5093 reg_prefix, regname (opa, 0),
5094 roffs * fc->data_factor);
5095 if (*reg_prefix == '\0')
5097 fc->col_type[opa] = DW_CFA_offset;
5098 fc->col_offset[opa] = roffs * fc->data_factor;
5100 break;
5102 case DW_CFA_restore:
5103 if (opa >= (unsigned int) cie->ncols
5104 || opa >= (unsigned int) fc->ncols)
5105 reg_prefix = bad_reg;
5106 if (! do_debug_frames_interp || *reg_prefix != '\0')
5107 printf (" DW_CFA_restore: %s%s\n",
5108 reg_prefix, regname (opa, 0));
5109 if (*reg_prefix == '\0')
5111 fc->col_type[opa] = cie->col_type[opa];
5112 fc->col_offset[opa] = cie->col_offset[opa];
5113 if (do_debug_frames_interp
5114 && fc->col_type[opa] == DW_CFA_unreferenced)
5115 fc->col_type[opa] = DW_CFA_undefined;
5117 break;
5119 case DW_CFA_set_loc:
5120 vma = get_encoded_value (start, fc->fde_encoding, section);
5121 start += encoded_ptr_size;
5122 if (do_debug_frames_interp)
5123 frame_display_row (fc, &need_col_headers, &max_regs);
5124 else
5125 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
5126 fc->pc_begin = vma;
5127 break;
5129 case DW_CFA_advance_loc1:
5130 ofs = byte_get (start, 1); start += 1;
5131 if (do_debug_frames_interp)
5132 frame_display_row (fc, &need_col_headers, &max_regs);
5133 else
5134 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
5135 ofs * fc->code_factor,
5136 fc->pc_begin + ofs * fc->code_factor);
5137 fc->pc_begin += ofs * fc->code_factor;
5138 break;
5140 case DW_CFA_advance_loc2:
5141 ofs = byte_get (start, 2); start += 2;
5142 if (do_debug_frames_interp)
5143 frame_display_row (fc, &need_col_headers, &max_regs);
5144 else
5145 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
5146 ofs * fc->code_factor,
5147 fc->pc_begin + ofs * fc->code_factor);
5148 fc->pc_begin += ofs * fc->code_factor;
5149 break;
5151 case DW_CFA_advance_loc4:
5152 ofs = byte_get (start, 4); start += 4;
5153 if (do_debug_frames_interp)
5154 frame_display_row (fc, &need_col_headers, &max_regs);
5155 else
5156 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
5157 ofs * fc->code_factor,
5158 fc->pc_begin + ofs * fc->code_factor);
5159 fc->pc_begin += ofs * fc->code_factor;
5160 break;
5162 case DW_CFA_offset_extended:
5163 reg = LEB ();
5164 roffs = LEB ();
5165 if (reg >= (unsigned int) fc->ncols)
5166 reg_prefix = bad_reg;
5167 if (! do_debug_frames_interp || *reg_prefix != '\0')
5168 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5169 reg_prefix, regname (reg, 0),
5170 roffs * fc->data_factor);
5171 if (*reg_prefix == '\0')
5173 fc->col_type[reg] = DW_CFA_offset;
5174 fc->col_offset[reg] = roffs * fc->data_factor;
5176 break;
5178 case DW_CFA_val_offset:
5179 reg = LEB ();
5180 roffs = LEB ();
5181 if (reg >= (unsigned int) fc->ncols)
5182 reg_prefix = bad_reg;
5183 if (! do_debug_frames_interp || *reg_prefix != '\0')
5184 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5185 reg_prefix, regname (reg, 0),
5186 roffs * fc->data_factor);
5187 if (*reg_prefix == '\0')
5189 fc->col_type[reg] = DW_CFA_val_offset;
5190 fc->col_offset[reg] = roffs * fc->data_factor;
5192 break;
5194 case DW_CFA_restore_extended:
5195 reg = LEB ();
5196 if (reg >= (unsigned int) cie->ncols
5197 || reg >= (unsigned int) fc->ncols)
5198 reg_prefix = bad_reg;
5199 if (! do_debug_frames_interp || *reg_prefix != '\0')
5200 printf (" DW_CFA_restore_extended: %s%s\n",
5201 reg_prefix, regname (reg, 0));
5202 if (*reg_prefix == '\0')
5204 fc->col_type[reg] = cie->col_type[reg];
5205 fc->col_offset[reg] = cie->col_offset[reg];
5207 break;
5209 case DW_CFA_undefined:
5210 reg = LEB ();
5211 if (reg >= (unsigned int) fc->ncols)
5212 reg_prefix = bad_reg;
5213 if (! do_debug_frames_interp || *reg_prefix != '\0')
5214 printf (" DW_CFA_undefined: %s%s\n",
5215 reg_prefix, regname (reg, 0));
5216 if (*reg_prefix == '\0')
5218 fc->col_type[reg] = DW_CFA_undefined;
5219 fc->col_offset[reg] = 0;
5221 break;
5223 case DW_CFA_same_value:
5224 reg = LEB ();
5225 if (reg >= (unsigned int) fc->ncols)
5226 reg_prefix = bad_reg;
5227 if (! do_debug_frames_interp || *reg_prefix != '\0')
5228 printf (" DW_CFA_same_value: %s%s\n",
5229 reg_prefix, regname (reg, 0));
5230 if (*reg_prefix == '\0')
5232 fc->col_type[reg] = DW_CFA_same_value;
5233 fc->col_offset[reg] = 0;
5235 break;
5237 case DW_CFA_register:
5238 reg = LEB ();
5239 roffs = LEB ();
5240 if (reg >= (unsigned int) fc->ncols)
5241 reg_prefix = bad_reg;
5242 if (! do_debug_frames_interp || *reg_prefix != '\0')
5244 printf (" DW_CFA_register: %s%s in ",
5245 reg_prefix, regname (reg, 0));
5246 puts (regname (roffs, 0));
5248 if (*reg_prefix == '\0')
5250 fc->col_type[reg] = DW_CFA_register;
5251 fc->col_offset[reg] = roffs;
5253 break;
5255 case DW_CFA_remember_state:
5256 if (! do_debug_frames_interp)
5257 printf (" DW_CFA_remember_state\n");
5258 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5259 rs->ncols = fc->ncols;
5260 rs->col_type = (short int *) xcmalloc (rs->ncols,
5261 sizeof (short int));
5262 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
5263 memcpy (rs->col_type, fc->col_type, rs->ncols);
5264 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
5265 rs->next = remembered_state;
5266 remembered_state = rs;
5267 break;
5269 case DW_CFA_restore_state:
5270 if (! do_debug_frames_interp)
5271 printf (" DW_CFA_restore_state\n");
5272 rs = remembered_state;
5273 if (rs)
5275 remembered_state = rs->next;
5276 frame_need_space (fc, rs->ncols - 1);
5277 memcpy (fc->col_type, rs->col_type, rs->ncols);
5278 memcpy (fc->col_offset, rs->col_offset,
5279 rs->ncols * sizeof (int));
5280 free (rs->col_type);
5281 free (rs->col_offset);
5282 free (rs);
5284 else if (do_debug_frames_interp)
5285 printf ("Mismatched DW_CFA_restore_state\n");
5286 break;
5288 case DW_CFA_def_cfa:
5289 fc->cfa_reg = LEB ();
5290 fc->cfa_offset = LEB ();
5291 fc->cfa_exp = 0;
5292 if (! do_debug_frames_interp)
5293 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5294 regname (fc->cfa_reg, 0), fc->cfa_offset);
5295 break;
5297 case DW_CFA_def_cfa_register:
5298 fc->cfa_reg = LEB ();
5299 fc->cfa_exp = 0;
5300 if (! do_debug_frames_interp)
5301 printf (" DW_CFA_def_cfa_register: %s\n",
5302 regname (fc->cfa_reg, 0));
5303 break;
5305 case DW_CFA_def_cfa_offset:
5306 fc->cfa_offset = LEB ();
5307 if (! do_debug_frames_interp)
5308 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5309 break;
5311 case DW_CFA_nop:
5312 if (! do_debug_frames_interp)
5313 printf (" DW_CFA_nop\n");
5314 break;
5316 case DW_CFA_def_cfa_expression:
5317 ul = LEB ();
5318 if (! do_debug_frames_interp)
5320 printf (" DW_CFA_def_cfa_expression (");
5321 decode_location_expression (start, eh_addr_size, 0, -1,
5322 ul, 0, section);
5323 printf (")\n");
5325 fc->cfa_exp = 1;
5326 start += ul;
5327 break;
5329 case DW_CFA_expression:
5330 reg = LEB ();
5331 ul = LEB ();
5332 if (reg >= (unsigned int) fc->ncols)
5333 reg_prefix = bad_reg;
5334 if (! do_debug_frames_interp || *reg_prefix != '\0')
5336 printf (" DW_CFA_expression: %s%s (",
5337 reg_prefix, regname (reg, 0));
5338 decode_location_expression (start, eh_addr_size, 0, -1,
5339 ul, 0, section);
5340 printf (")\n");
5342 if (*reg_prefix == '\0')
5343 fc->col_type[reg] = DW_CFA_expression;
5344 start += ul;
5345 break;
5347 case DW_CFA_val_expression:
5348 reg = LEB ();
5349 ul = LEB ();
5350 if (reg >= (unsigned int) fc->ncols)
5351 reg_prefix = bad_reg;
5352 if (! do_debug_frames_interp || *reg_prefix != '\0')
5354 printf (" DW_CFA_val_expression: %s%s (",
5355 reg_prefix, regname (reg, 0));
5356 decode_location_expression (start, eh_addr_size, 0, -1,
5357 ul, 0, section);
5358 printf (")\n");
5360 if (*reg_prefix == '\0')
5361 fc->col_type[reg] = DW_CFA_val_expression;
5362 start += ul;
5363 break;
5365 case DW_CFA_offset_extended_sf:
5366 reg = LEB ();
5367 l = SLEB ();
5368 if (frame_need_space (fc, reg) < 0)
5369 reg_prefix = bad_reg;
5370 if (! do_debug_frames_interp || *reg_prefix != '\0')
5371 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5372 reg_prefix, regname (reg, 0),
5373 l * fc->data_factor);
5374 if (*reg_prefix == '\0')
5376 fc->col_type[reg] = DW_CFA_offset;
5377 fc->col_offset[reg] = l * fc->data_factor;
5379 break;
5381 case DW_CFA_val_offset_sf:
5382 reg = LEB ();
5383 l = SLEB ();
5384 if (frame_need_space (fc, reg) < 0)
5385 reg_prefix = bad_reg;
5386 if (! do_debug_frames_interp || *reg_prefix != '\0')
5387 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5388 reg_prefix, regname (reg, 0),
5389 l * fc->data_factor);
5390 if (*reg_prefix == '\0')
5392 fc->col_type[reg] = DW_CFA_val_offset;
5393 fc->col_offset[reg] = l * fc->data_factor;
5395 break;
5397 case DW_CFA_def_cfa_sf:
5398 fc->cfa_reg = LEB ();
5399 fc->cfa_offset = SLEB ();
5400 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5401 fc->cfa_exp = 0;
5402 if (! do_debug_frames_interp)
5403 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5404 regname (fc->cfa_reg, 0), fc->cfa_offset);
5405 break;
5407 case DW_CFA_def_cfa_offset_sf:
5408 fc->cfa_offset = SLEB ();
5409 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5410 if (! do_debug_frames_interp)
5411 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5412 break;
5414 case DW_CFA_MIPS_advance_loc8:
5415 ofs = byte_get (start, 8); start += 8;
5416 if (do_debug_frames_interp)
5417 frame_display_row (fc, &need_col_headers, &max_regs);
5418 else
5419 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
5420 ofs * fc->code_factor,
5421 fc->pc_begin + ofs * fc->code_factor);
5422 fc->pc_begin += ofs * fc->code_factor;
5423 break;
5425 case DW_CFA_GNU_window_save:
5426 if (! do_debug_frames_interp)
5427 printf (" DW_CFA_GNU_window_save\n");
5428 break;
5430 case DW_CFA_GNU_args_size:
5431 ul = LEB ();
5432 if (! do_debug_frames_interp)
5433 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
5434 break;
5436 case DW_CFA_GNU_negative_offset_extended:
5437 reg = LEB ();
5438 l = - LEB ();
5439 if (frame_need_space (fc, reg) < 0)
5440 reg_prefix = bad_reg;
5441 if (! do_debug_frames_interp || *reg_prefix != '\0')
5442 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
5443 reg_prefix, regname (reg, 0),
5444 l * fc->data_factor);
5445 if (*reg_prefix == '\0')
5447 fc->col_type[reg] = DW_CFA_offset;
5448 fc->col_offset[reg] = l * fc->data_factor;
5450 break;
5452 default:
5453 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
5454 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
5455 else
5456 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
5457 start = block_end;
5461 if (do_debug_frames_interp)
5462 frame_display_row (fc, &need_col_headers, &max_regs);
5464 start = block_end;
5465 eh_addr_size = saved_eh_addr_size;
5468 printf ("\n");
5470 return 1;
5473 #undef GET
5474 #undef LEB
5475 #undef SLEB
5477 static int
5478 display_gdb_index (struct dwarf_section *section,
5479 void *file ATTRIBUTE_UNUSED)
5481 unsigned char *start = section->start;
5482 uint32_t version;
5483 uint32_t cu_list_offset, tu_list_offset;
5484 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
5485 unsigned int cu_list_elements, tu_list_elements;
5486 unsigned int address_table_size, symbol_table_slots;
5487 unsigned char *cu_list, *tu_list;
5488 unsigned char *address_table, *symbol_table, *constant_pool;
5489 unsigned int i;
5491 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
5493 printf (_("Contents of the %s section:\n"), section->name);
5495 if (section->size < 6 * sizeof (uint32_t))
5497 warn (_("Truncated header in the %s section.\n"), section->name);
5498 return 0;
5501 version = byte_get_little_endian (start, 4);
5502 printf (_("Version %ld\n"), (long) version);
5504 /* Prior versions are obsolete, and future versions may not be
5505 backwards compatible. */
5506 switch (version)
5508 case 3:
5509 warn (_("The address table data in version 3 may be wrong.\n"));
5510 break;
5511 case 4:
5512 warn (_("Version 4 does not support case insensitive lookups.\n"));
5513 break;
5514 case 5:
5515 break;
5516 default:
5517 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
5518 return 0;
5521 cu_list_offset = byte_get_little_endian (start + 4, 4);
5522 tu_list_offset = byte_get_little_endian (start + 8, 4);
5523 address_table_offset = byte_get_little_endian (start + 12, 4);
5524 symbol_table_offset = byte_get_little_endian (start + 16, 4);
5525 constant_pool_offset = byte_get_little_endian (start + 20, 4);
5527 if (cu_list_offset > section->size
5528 || tu_list_offset > section->size
5529 || address_table_offset > section->size
5530 || symbol_table_offset > section->size
5531 || constant_pool_offset > section->size)
5533 warn (_("Corrupt header in the %s section.\n"), section->name);
5534 return 0;
5537 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
5538 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
5539 address_table_size = symbol_table_offset - address_table_offset;
5540 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
5542 cu_list = start + cu_list_offset;
5543 tu_list = start + tu_list_offset;
5544 address_table = start + address_table_offset;
5545 symbol_table = start + symbol_table_offset;
5546 constant_pool = start + constant_pool_offset;
5548 printf (_("\nCU table:\n"));
5549 for (i = 0; i < cu_list_elements; i += 2)
5551 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
5552 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
5554 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
5555 (unsigned long) cu_offset,
5556 (unsigned long) (cu_offset + cu_length - 1));
5559 printf (_("\nTU table:\n"));
5560 for (i = 0; i < tu_list_elements; i += 3)
5562 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5563 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5564 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5566 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5567 (unsigned long) tu_offset,
5568 (unsigned long) type_offset);
5569 print_dwarf_vma (signature, 8);
5570 printf ("\n");
5573 printf (_("\nAddress table:\n"));
5574 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5576 uint64_t low = byte_get_little_endian (address_table + i, 8);
5577 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5578 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5580 print_dwarf_vma (low, 8);
5581 print_dwarf_vma (high, 8);
5582 printf (_("%lu\n"), (unsigned long) cu_index);
5585 printf (_("\nSymbol table:\n"));
5586 for (i = 0; i < symbol_table_slots; ++i)
5588 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5589 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5590 uint32_t num_cus, cu;
5592 if (name_offset != 0
5593 || cu_vector_offset != 0)
5595 unsigned int j;
5597 printf ("[%3u] %s:", i, constant_pool + name_offset);
5598 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5599 for (j = 0; j < num_cus; ++j)
5601 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5602 /* Convert to TU number if it's for a type unit. */
5603 if (cu >= cu_list_elements / 2)
5604 printf (" T%lu", (unsigned long) (cu - cu_list_elements / 2));
5605 else
5606 printf (" %lu", (unsigned long) cu);
5608 printf ("\n");
5612 return 1;
5615 static int
5616 display_debug_not_supported (struct dwarf_section *section,
5617 void *file ATTRIBUTE_UNUSED)
5619 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5620 section->name);
5622 return 1;
5625 void *
5626 cmalloc (size_t nmemb, size_t size)
5628 /* Check for overflow. */
5629 if (nmemb >= ~(size_t) 0 / size)
5630 return NULL;
5631 else
5632 return malloc (nmemb * size);
5635 void *
5636 xcmalloc (size_t nmemb, size_t size)
5638 /* Check for overflow. */
5639 if (nmemb >= ~(size_t) 0 / size)
5640 return NULL;
5641 else
5642 return xmalloc (nmemb * size);
5645 void *
5646 xcrealloc (void *ptr, size_t nmemb, size_t size)
5648 /* Check for overflow. */
5649 if (nmemb >= ~(size_t) 0 / size)
5650 return NULL;
5651 else
5652 return xrealloc (ptr, nmemb * size);
5655 void
5656 free_debug_memory (void)
5658 unsigned int i;
5660 free_abbrevs ();
5662 for (i = 0; i < max; i++)
5663 free_debug_section ((enum dwarf_section_display_enum) i);
5665 if (debug_information != NULL)
5667 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
5669 for (i = 0; i < num_debug_info_entries; i++)
5671 if (!debug_information [i].max_loc_offsets)
5673 free (debug_information [i].loc_offsets);
5674 free (debug_information [i].have_frame_base);
5676 if (!debug_information [i].max_range_lists)
5677 free (debug_information [i].range_lists);
5681 free (debug_information);
5682 debug_information = NULL;
5683 num_debug_info_entries = 0;
5687 void
5688 dwarf_select_sections_by_names (const char *names)
5690 typedef struct
5692 const char * option;
5693 int * variable;
5694 int val;
5696 debug_dump_long_opts;
5698 static const debug_dump_long_opts opts_table [] =
5700 /* Please keep this table alpha- sorted. */
5701 { "Ranges", & do_debug_ranges, 1 },
5702 { "abbrev", & do_debug_abbrevs, 1 },
5703 { "aranges", & do_debug_aranges, 1 },
5704 { "frames", & do_debug_frames, 1 },
5705 { "frames-interp", & do_debug_frames_interp, 1 },
5706 { "info", & do_debug_info, 1 },
5707 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5708 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5709 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5710 { "loc", & do_debug_loc, 1 },
5711 { "macro", & do_debug_macinfo, 1 },
5712 { "pubnames", & do_debug_pubnames, 1 },
5713 { "pubtypes", & do_debug_pubtypes, 1 },
5714 /* This entry is for compatability
5715 with earlier versions of readelf. */
5716 { "ranges", & do_debug_aranges, 1 },
5717 { "str", & do_debug_str, 1 },
5718 /* The special .gdb_index section. */
5719 { "gdb_index", & do_gdb_index, 1 },
5720 /* These trace_* sections are used by Itanium VMS. */
5721 { "trace_abbrev", & do_trace_abbrevs, 1 },
5722 { "trace_aranges", & do_trace_aranges, 1 },
5723 { "trace_info", & do_trace_info, 1 },
5724 { NULL, NULL, 0 }
5727 const char *p;
5729 p = names;
5730 while (*p)
5732 const debug_dump_long_opts * entry;
5734 for (entry = opts_table; entry->option; entry++)
5736 size_t len = strlen (entry->option);
5738 if (strncmp (p, entry->option, len) == 0
5739 && (p[len] == ',' || p[len] == '\0'))
5741 * entry->variable |= entry->val;
5743 /* The --debug-dump=frames-interp option also
5744 enables the --debug-dump=frames option. */
5745 if (do_debug_frames_interp)
5746 do_debug_frames = 1;
5748 p += len;
5749 break;
5753 if (entry->option == NULL)
5755 warn (_("Unrecognized debug option '%s'\n"), p);
5756 p = strchr (p, ',');
5757 if (p == NULL)
5758 break;
5761 if (*p == ',')
5762 p++;
5766 void
5767 dwarf_select_sections_by_letters (const char *letters)
5769 unsigned int lindex = 0;
5771 while (letters[lindex])
5772 switch (letters[lindex++])
5774 case 'i':
5775 do_debug_info = 1;
5776 break;
5778 case 'a':
5779 do_debug_abbrevs = 1;
5780 break;
5782 case 'l':
5783 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
5784 break;
5786 case 'L':
5787 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
5788 break;
5790 case 'p':
5791 do_debug_pubnames = 1;
5792 break;
5794 case 't':
5795 do_debug_pubtypes = 1;
5796 break;
5798 case 'r':
5799 do_debug_aranges = 1;
5800 break;
5802 case 'R':
5803 do_debug_ranges = 1;
5804 break;
5806 case 'F':
5807 do_debug_frames_interp = 1;
5808 case 'f':
5809 do_debug_frames = 1;
5810 break;
5812 case 'm':
5813 do_debug_macinfo = 1;
5814 break;
5816 case 's':
5817 do_debug_str = 1;
5818 break;
5820 case 'o':
5821 do_debug_loc = 1;
5822 break;
5824 default:
5825 warn (_("Unrecognized debug option '%s'\n"), optarg);
5826 break;
5830 void
5831 dwarf_select_sections_all (void)
5833 do_debug_info = 1;
5834 do_debug_abbrevs = 1;
5835 do_debug_lines = FLAG_DEBUG_LINES_RAW;
5836 do_debug_pubnames = 1;
5837 do_debug_pubtypes = 1;
5838 do_debug_aranges = 1;
5839 do_debug_ranges = 1;
5840 do_debug_frames = 1;
5841 do_debug_macinfo = 1;
5842 do_debug_str = 1;
5843 do_debug_loc = 1;
5844 do_gdb_index = 1;
5845 do_trace_info = 1;
5846 do_trace_abbrevs = 1;
5847 do_trace_aranges = 1;
5850 struct dwarf_section_display debug_displays[] =
5852 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 },
5853 display_debug_abbrev, &do_debug_abbrevs, 0 },
5854 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 },
5855 display_debug_aranges, &do_debug_aranges, 1 },
5856 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 },
5857 display_debug_frames, &do_debug_frames, 1 },
5858 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 },
5859 display_debug_info, &do_debug_info, 1 },
5860 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 },
5861 display_debug_lines, &do_debug_lines, 1 },
5862 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 },
5863 display_debug_pubnames, &do_debug_pubnames, 0 },
5864 { { ".eh_frame", "", NULL, NULL, 0, 0 },
5865 display_debug_frames, &do_debug_frames, 1 },
5866 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 },
5867 display_debug_macinfo, &do_debug_macinfo, 0 },
5868 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0 },
5869 display_debug_macro, &do_debug_macinfo, 1 },
5870 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 },
5871 display_debug_str, &do_debug_str, 0 },
5872 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 },
5873 display_debug_loc, &do_debug_loc, 1 },
5874 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 },
5875 display_debug_pubnames, &do_debug_pubtypes, 0 },
5876 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 },
5877 display_debug_ranges, &do_debug_ranges, 1 },
5878 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 },
5879 display_debug_not_supported, NULL, 0 },
5880 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 },
5881 display_debug_not_supported, NULL, 0 },
5882 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 },
5883 display_debug_types, &do_debug_info, 1 },
5884 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 },
5885 display_debug_not_supported, NULL, 0 },
5886 { { ".gdb_index", "", NULL, NULL, 0, 0 },
5887 display_gdb_index, &do_gdb_index, 0 },
5888 { { ".trace_info", "", NULL, NULL, 0, 0 },
5889 display_trace_info, &do_trace_info, 1 },
5890 { { ".trace_abbrev", "", NULL, NULL, 0, 0 },
5891 display_debug_abbrev, &do_trace_abbrevs, 0 },
5892 { { ".trace_aranges", "", NULL, NULL, 0, 0 },
5893 display_debug_aranges, &do_trace_aranges, 0 }