2010-02-18 Rafael Ávila de Espíndola <respindola@mozilla.com>
[binutils.git] / binutils / dwarf.c
blob2337c53d4b7f6bccbc936114c84202ed4247a4a9
1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright 2005, 2006, 2007, 2008, 2009, 2010
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 /* Values for do_debug_lines. */
67 #define FLAG_DEBUG_LINES_RAW 1
68 #define FLAG_DEBUG_LINES_DECODED 2
70 static int
71 size_of_encoded_value (int encoding)
73 switch (encoding & 0x7)
75 default: /* ??? */
76 case 0: return eh_addr_size;
77 case 2: return 2;
78 case 3: return 4;
79 case 4: return 8;
83 static dwarf_vma
84 get_encoded_value (unsigned char *data,
85 int encoding,
86 struct dwarf_section *section)
88 int size = size_of_encoded_value (encoding);
89 dwarf_vma val;
91 if (encoding & DW_EH_PE_signed)
92 val = byte_get_signed (data, size);
93 else
94 val = byte_get (data, size);
96 if ((encoding & 0x70) == DW_EH_PE_pcrel)
97 val += section->address + (data - section->start);
98 return val;
101 /* Print a dwarf_vma value (typically an address, offset or length) in
102 hexadecimal format, followed by a space. The length of the value (and
103 hence the precision displayed) is determined by the byte_size parameter. */
105 static void
106 print_dwarf_vma (dwarf_vma val, unsigned byte_size)
108 static char buff[18];
110 /* Printf does not have a way of specifiying a maximum field width for an
111 integer value, so we print the full value into a buffer and then select
112 the precision we need. */
113 #if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
114 #ifndef __MSVCRT__
115 snprintf (buff, sizeof (buff), "%16.16llx ", val);
116 #else
117 snprintf (buff, sizeof (buff), "%016I64x ", val);
118 #endif
119 #else
120 snprintf (buff, sizeof (buff), "%16.16lx ", val);
121 #endif
123 fputs (buff + (byte_size == 4 ? 8 : 0), stdout);
126 unsigned long int
127 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
129 unsigned long int result = 0;
130 unsigned int num_read = 0;
131 unsigned int shift = 0;
132 unsigned char byte;
136 byte = *data++;
137 num_read++;
139 result |= ((unsigned long int) (byte & 0x7f)) << shift;
141 shift += 7;
144 while (byte & 0x80);
146 if (length_return != NULL)
147 *length_return = num_read;
149 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
150 result |= -1L << shift;
152 return result;
155 typedef struct State_Machine_Registers
157 unsigned long address;
158 unsigned int file;
159 unsigned int line;
160 unsigned int column;
161 int is_stmt;
162 int basic_block;
163 unsigned char op_index;
164 unsigned char end_sequence;
165 /* This variable hold the number of the last entry seen
166 in the File Table. */
167 unsigned int last_file_entry;
168 } SMR;
170 static SMR state_machine_regs;
172 static void
173 reset_state_machine (int is_stmt)
175 state_machine_regs.address = 0;
176 state_machine_regs.op_index = 0;
177 state_machine_regs.file = 1;
178 state_machine_regs.line = 1;
179 state_machine_regs.column = 0;
180 state_machine_regs.is_stmt = is_stmt;
181 state_machine_regs.basic_block = 0;
182 state_machine_regs.end_sequence = 0;
183 state_machine_regs.last_file_entry = 0;
186 /* Handled an extend line op.
187 Returns the number of bytes read. */
189 static int
190 process_extended_line_op (unsigned char *data, int is_stmt)
192 unsigned char op_code;
193 unsigned int bytes_read;
194 unsigned int len;
195 unsigned char *name;
196 unsigned long adr;
198 len = read_leb128 (data, & bytes_read, 0);
199 data += bytes_read;
201 if (len == 0)
203 warn (_("badly formed extended line op encountered!\n"));
204 return bytes_read;
207 len += bytes_read;
208 op_code = *data++;
210 printf (_(" Extended opcode %d: "), op_code);
212 switch (op_code)
214 case DW_LNE_end_sequence:
215 printf (_("End of Sequence\n\n"));
216 reset_state_machine (is_stmt);
217 break;
219 case DW_LNE_set_address:
220 adr = byte_get (data, len - bytes_read - 1);
221 printf (_("set Address to 0x%lx\n"), adr);
222 state_machine_regs.address = adr;
223 state_machine_regs.op_index = 0;
224 break;
226 case DW_LNE_define_file:
227 printf (_(" define new File Table entry\n"));
228 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
230 printf (" %d\t", ++state_machine_regs.last_file_entry);
231 name = data;
232 data += strlen ((char *) data) + 1;
233 printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
234 data += bytes_read;
235 printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
236 data += bytes_read;
237 printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
238 printf ("%s\n\n", name);
239 break;
241 case DW_LNE_set_discriminator:
242 printf (_("set Discriminator to %lu\n"),
243 read_leb128 (data, & bytes_read, 0));
244 break;
246 /* HP extensions. */
247 case DW_LNE_HP_negate_is_UV_update:
248 printf ("DW_LNE_HP_negate_is_UV_update\n");
249 break;
250 case DW_LNE_HP_push_context:
251 printf ("DW_LNE_HP_push_context\n");
252 break;
253 case DW_LNE_HP_pop_context:
254 printf ("DW_LNE_HP_pop_context\n");
255 break;
256 case DW_LNE_HP_set_file_line_column:
257 printf ("DW_LNE_HP_set_file_line_column\n");
258 break;
259 case DW_LNE_HP_set_routine_name:
260 printf ("DW_LNE_HP_set_routine_name\n");
261 break;
262 case DW_LNE_HP_set_sequence:
263 printf ("DW_LNE_HP_set_sequence\n");
264 break;
265 case DW_LNE_HP_negate_post_semantics:
266 printf ("DW_LNE_HP_negate_post_semantics\n");
267 break;
268 case DW_LNE_HP_negate_function_exit:
269 printf ("DW_LNE_HP_negate_function_exit\n");
270 break;
271 case DW_LNE_HP_negate_front_end_logical:
272 printf ("DW_LNE_HP_negate_front_end_logical\n");
273 break;
274 case DW_LNE_HP_define_proc:
275 printf ("DW_LNE_HP_define_proc\n");
276 break;
278 default:
279 if (op_code >= DW_LNE_lo_user
280 /* The test against DW_LNW_hi_user is redundant due to
281 the limited range of the unsigned char data type used
282 for op_code. */
283 /*&& op_code <= DW_LNE_hi_user*/)
284 printf (_("user defined: length %d\n"), len - bytes_read);
285 else
286 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
287 break;
290 return len;
293 static const char *
294 fetch_indirect_string (unsigned long offset)
296 struct dwarf_section *section = &debug_displays [str].section;
298 if (section->start == NULL)
299 return _("<no .debug_str section>");
301 /* DWARF sections under Mach-O have non-zero addresses. */
302 offset -= section->address;
303 if (offset > section->size)
305 warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
306 return _("<offset is too big>");
309 return (const char *) section->start + offset;
312 /* FIXME: There are better and more efficient ways to handle
313 these structures. For now though, I just want something that
314 is simple to implement. */
315 typedef struct abbrev_attr
317 unsigned long attribute;
318 unsigned long form;
319 struct abbrev_attr *next;
321 abbrev_attr;
323 typedef struct abbrev_entry
325 unsigned long entry;
326 unsigned long tag;
327 int children;
328 struct abbrev_attr *first_attr;
329 struct abbrev_attr *last_attr;
330 struct abbrev_entry *next;
332 abbrev_entry;
334 static abbrev_entry *first_abbrev = NULL;
335 static abbrev_entry *last_abbrev = NULL;
337 static void
338 free_abbrevs (void)
340 abbrev_entry *abbrv;
342 for (abbrv = first_abbrev; abbrv;)
344 abbrev_entry *next_abbrev = abbrv->next;
345 abbrev_attr *attr;
347 for (attr = abbrv->first_attr; attr;)
349 abbrev_attr *next_attr = attr->next;
351 free (attr);
352 attr = next_attr;
355 free (abbrv);
356 abbrv = next_abbrev;
359 last_abbrev = first_abbrev = NULL;
362 static void
363 add_abbrev (unsigned long number, unsigned long tag, int children)
365 abbrev_entry *entry;
367 entry = (abbrev_entry *) malloc (sizeof (*entry));
369 if (entry == NULL)
370 /* ugg */
371 return;
373 entry->entry = number;
374 entry->tag = tag;
375 entry->children = children;
376 entry->first_attr = NULL;
377 entry->last_attr = NULL;
378 entry->next = NULL;
380 if (first_abbrev == NULL)
381 first_abbrev = entry;
382 else
383 last_abbrev->next = entry;
385 last_abbrev = entry;
388 static void
389 add_abbrev_attr (unsigned long attribute, unsigned long form)
391 abbrev_attr *attr;
393 attr = (abbrev_attr *) malloc (sizeof (*attr));
395 if (attr == NULL)
396 /* ugg */
397 return;
399 attr->attribute = attribute;
400 attr->form = form;
401 attr->next = NULL;
403 if (last_abbrev->first_attr == NULL)
404 last_abbrev->first_attr = attr;
405 else
406 last_abbrev->last_attr->next = attr;
408 last_abbrev->last_attr = attr;
411 /* Processes the (partial) contents of a .debug_abbrev section.
412 Returns NULL if the end of the section was encountered.
413 Returns the address after the last byte read if the end of
414 an abbreviation set was found. */
416 static unsigned char *
417 process_abbrev_section (unsigned char *start, unsigned char *end)
419 if (first_abbrev != NULL)
420 return NULL;
422 while (start < end)
424 unsigned int bytes_read;
425 unsigned long entry;
426 unsigned long tag;
427 unsigned long attribute;
428 int children;
430 entry = read_leb128 (start, & bytes_read, 0);
431 start += bytes_read;
433 /* A single zero is supposed to end the section according
434 to the standard. If there's more, then signal that to
435 the caller. */
436 if (entry == 0)
437 return start == end ? NULL : start;
439 tag = read_leb128 (start, & bytes_read, 0);
440 start += bytes_read;
442 children = *start++;
444 add_abbrev (entry, tag, children);
448 unsigned long form;
450 attribute = read_leb128 (start, & bytes_read, 0);
451 start += bytes_read;
453 form = read_leb128 (start, & bytes_read, 0);
454 start += bytes_read;
456 if (attribute != 0)
457 add_abbrev_attr (attribute, form);
459 while (attribute != 0);
462 return NULL;
465 static char *
466 get_TAG_name (unsigned long tag)
468 switch (tag)
470 case DW_TAG_padding: return "DW_TAG_padding";
471 case DW_TAG_array_type: return "DW_TAG_array_type";
472 case DW_TAG_class_type: return "DW_TAG_class_type";
473 case DW_TAG_entry_point: return "DW_TAG_entry_point";
474 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
475 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
476 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
477 case DW_TAG_label: return "DW_TAG_label";
478 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
479 case DW_TAG_member: return "DW_TAG_member";
480 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
481 case DW_TAG_reference_type: return "DW_TAG_reference_type";
482 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
483 case DW_TAG_string_type: return "DW_TAG_string_type";
484 case DW_TAG_structure_type: return "DW_TAG_structure_type";
485 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
486 case DW_TAG_typedef: return "DW_TAG_typedef";
487 case DW_TAG_union_type: return "DW_TAG_union_type";
488 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
489 case DW_TAG_variant: return "DW_TAG_variant";
490 case DW_TAG_common_block: return "DW_TAG_common_block";
491 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
492 case DW_TAG_inheritance: return "DW_TAG_inheritance";
493 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
494 case DW_TAG_module: return "DW_TAG_module";
495 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
496 case DW_TAG_set_type: return "DW_TAG_set_type";
497 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
498 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
499 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
500 case DW_TAG_base_type: return "DW_TAG_base_type";
501 case DW_TAG_catch_block: return "DW_TAG_catch_block";
502 case DW_TAG_const_type: return "DW_TAG_const_type";
503 case DW_TAG_constant: return "DW_TAG_constant";
504 case DW_TAG_enumerator: return "DW_TAG_enumerator";
505 case DW_TAG_file_type: return "DW_TAG_file_type";
506 case DW_TAG_friend: return "DW_TAG_friend";
507 case DW_TAG_namelist: return "DW_TAG_namelist";
508 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
509 case DW_TAG_packed_type: return "DW_TAG_packed_type";
510 case DW_TAG_subprogram: return "DW_TAG_subprogram";
511 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
512 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
513 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
514 case DW_TAG_try_block: return "DW_TAG_try_block";
515 case DW_TAG_variant_part: return "DW_TAG_variant_part";
516 case DW_TAG_variable: return "DW_TAG_variable";
517 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
518 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
519 case DW_TAG_format_label: return "DW_TAG_format_label";
520 case DW_TAG_function_template: return "DW_TAG_function_template";
521 case DW_TAG_class_template: return "DW_TAG_class_template";
522 /* DWARF 2.1 values. */
523 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
524 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
525 case DW_TAG_interface_type: return "DW_TAG_interface_type";
526 case DW_TAG_namespace: return "DW_TAG_namespace";
527 case DW_TAG_imported_module: return "DW_TAG_imported_module";
528 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
529 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
530 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
531 case DW_TAG_condition: return "DW_TAG_condition";
532 case DW_TAG_shared_type: return "DW_TAG_shared_type";
533 /* DWARF 4 values. */
534 case DW_TAG_type_unit: return "DW_TAG_type_unit";
535 case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type";
536 case DW_TAG_template_alias: return "DW_TAG_template_alias";
537 /* UPC values. */
538 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
539 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
540 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
541 default:
543 static char buffer[100];
545 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
546 return buffer;
551 static char *
552 get_FORM_name (unsigned long form)
554 switch (form)
556 case DW_FORM_addr: return "DW_FORM_addr";
557 case DW_FORM_block2: return "DW_FORM_block2";
558 case DW_FORM_block4: return "DW_FORM_block4";
559 case DW_FORM_data2: return "DW_FORM_data2";
560 case DW_FORM_data4: return "DW_FORM_data4";
561 case DW_FORM_data8: return "DW_FORM_data8";
562 case DW_FORM_string: return "DW_FORM_string";
563 case DW_FORM_block: return "DW_FORM_block";
564 case DW_FORM_block1: return "DW_FORM_block1";
565 case DW_FORM_data1: return "DW_FORM_data1";
566 case DW_FORM_flag: return "DW_FORM_flag";
567 case DW_FORM_sdata: return "DW_FORM_sdata";
568 case DW_FORM_strp: return "DW_FORM_strp";
569 case DW_FORM_udata: return "DW_FORM_udata";
570 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
571 case DW_FORM_ref1: return "DW_FORM_ref1";
572 case DW_FORM_ref2: return "DW_FORM_ref2";
573 case DW_FORM_ref4: return "DW_FORM_ref4";
574 case DW_FORM_ref8: return "DW_FORM_ref8";
575 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
576 case DW_FORM_indirect: return "DW_FORM_indirect";
577 /* DWARF 4 values. */
578 case DW_FORM_sec_offset: return "DW_FORM_sec_offset";
579 case DW_FORM_exprloc: return "DW_FORM_exprloc";
580 case DW_FORM_flag_present: return "DW_FORM_flag_present";
581 case DW_FORM_ref_sig8: return "DW_FORM_ref_sig8";
582 default:
584 static char buffer[100];
586 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
587 return buffer;
592 static unsigned char *
593 display_block (unsigned char *data, unsigned long length)
595 printf (_(" %lu byte block: "), length);
597 while (length --)
598 printf ("%lx ", (unsigned long) byte_get (data++, 1));
600 return data;
603 static int
604 decode_location_expression (unsigned char * data,
605 unsigned int pointer_size,
606 unsigned int offset_size,
607 int dwarf_version,
608 unsigned long length,
609 unsigned long cu_offset,
610 struct dwarf_section * section)
612 unsigned op;
613 unsigned int bytes_read;
614 unsigned long uvalue;
615 unsigned char *end = data + length;
616 int need_frame_base = 0;
618 while (data < end)
620 op = *data++;
622 switch (op)
624 case DW_OP_addr:
625 printf ("DW_OP_addr: %lx",
626 (unsigned long) byte_get (data, pointer_size));
627 data += pointer_size;
628 break;
629 case DW_OP_deref:
630 printf ("DW_OP_deref");
631 break;
632 case DW_OP_const1u:
633 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
634 break;
635 case DW_OP_const1s:
636 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
637 break;
638 case DW_OP_const2u:
639 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
640 data += 2;
641 break;
642 case DW_OP_const2s:
643 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
644 data += 2;
645 break;
646 case DW_OP_const4u:
647 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
648 data += 4;
649 break;
650 case DW_OP_const4s:
651 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
652 data += 4;
653 break;
654 case DW_OP_const8u:
655 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
656 (unsigned long) byte_get (data + 4, 4));
657 data += 8;
658 break;
659 case DW_OP_const8s:
660 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
661 (long) byte_get (data + 4, 4));
662 data += 8;
663 break;
664 case DW_OP_constu:
665 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
666 data += bytes_read;
667 break;
668 case DW_OP_consts:
669 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
670 data += bytes_read;
671 break;
672 case DW_OP_dup:
673 printf ("DW_OP_dup");
674 break;
675 case DW_OP_drop:
676 printf ("DW_OP_drop");
677 break;
678 case DW_OP_over:
679 printf ("DW_OP_over");
680 break;
681 case DW_OP_pick:
682 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
683 break;
684 case DW_OP_swap:
685 printf ("DW_OP_swap");
686 break;
687 case DW_OP_rot:
688 printf ("DW_OP_rot");
689 break;
690 case DW_OP_xderef:
691 printf ("DW_OP_xderef");
692 break;
693 case DW_OP_abs:
694 printf ("DW_OP_abs");
695 break;
696 case DW_OP_and:
697 printf ("DW_OP_and");
698 break;
699 case DW_OP_div:
700 printf ("DW_OP_div");
701 break;
702 case DW_OP_minus:
703 printf ("DW_OP_minus");
704 break;
705 case DW_OP_mod:
706 printf ("DW_OP_mod");
707 break;
708 case DW_OP_mul:
709 printf ("DW_OP_mul");
710 break;
711 case DW_OP_neg:
712 printf ("DW_OP_neg");
713 break;
714 case DW_OP_not:
715 printf ("DW_OP_not");
716 break;
717 case DW_OP_or:
718 printf ("DW_OP_or");
719 break;
720 case DW_OP_plus:
721 printf ("DW_OP_plus");
722 break;
723 case DW_OP_plus_uconst:
724 printf ("DW_OP_plus_uconst: %lu",
725 read_leb128 (data, &bytes_read, 0));
726 data += bytes_read;
727 break;
728 case DW_OP_shl:
729 printf ("DW_OP_shl");
730 break;
731 case DW_OP_shr:
732 printf ("DW_OP_shr");
733 break;
734 case DW_OP_shra:
735 printf ("DW_OP_shra");
736 break;
737 case DW_OP_xor:
738 printf ("DW_OP_xor");
739 break;
740 case DW_OP_bra:
741 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
742 data += 2;
743 break;
744 case DW_OP_eq:
745 printf ("DW_OP_eq");
746 break;
747 case DW_OP_ge:
748 printf ("DW_OP_ge");
749 break;
750 case DW_OP_gt:
751 printf ("DW_OP_gt");
752 break;
753 case DW_OP_le:
754 printf ("DW_OP_le");
755 break;
756 case DW_OP_lt:
757 printf ("DW_OP_lt");
758 break;
759 case DW_OP_ne:
760 printf ("DW_OP_ne");
761 break;
762 case DW_OP_skip:
763 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
764 data += 2;
765 break;
767 case DW_OP_lit0:
768 case DW_OP_lit1:
769 case DW_OP_lit2:
770 case DW_OP_lit3:
771 case DW_OP_lit4:
772 case DW_OP_lit5:
773 case DW_OP_lit6:
774 case DW_OP_lit7:
775 case DW_OP_lit8:
776 case DW_OP_lit9:
777 case DW_OP_lit10:
778 case DW_OP_lit11:
779 case DW_OP_lit12:
780 case DW_OP_lit13:
781 case DW_OP_lit14:
782 case DW_OP_lit15:
783 case DW_OP_lit16:
784 case DW_OP_lit17:
785 case DW_OP_lit18:
786 case DW_OP_lit19:
787 case DW_OP_lit20:
788 case DW_OP_lit21:
789 case DW_OP_lit22:
790 case DW_OP_lit23:
791 case DW_OP_lit24:
792 case DW_OP_lit25:
793 case DW_OP_lit26:
794 case DW_OP_lit27:
795 case DW_OP_lit28:
796 case DW_OP_lit29:
797 case DW_OP_lit30:
798 case DW_OP_lit31:
799 printf ("DW_OP_lit%d", op - DW_OP_lit0);
800 break;
802 case DW_OP_reg0:
803 case DW_OP_reg1:
804 case DW_OP_reg2:
805 case DW_OP_reg3:
806 case DW_OP_reg4:
807 case DW_OP_reg5:
808 case DW_OP_reg6:
809 case DW_OP_reg7:
810 case DW_OP_reg8:
811 case DW_OP_reg9:
812 case DW_OP_reg10:
813 case DW_OP_reg11:
814 case DW_OP_reg12:
815 case DW_OP_reg13:
816 case DW_OP_reg14:
817 case DW_OP_reg15:
818 case DW_OP_reg16:
819 case DW_OP_reg17:
820 case DW_OP_reg18:
821 case DW_OP_reg19:
822 case DW_OP_reg20:
823 case DW_OP_reg21:
824 case DW_OP_reg22:
825 case DW_OP_reg23:
826 case DW_OP_reg24:
827 case DW_OP_reg25:
828 case DW_OP_reg26:
829 case DW_OP_reg27:
830 case DW_OP_reg28:
831 case DW_OP_reg29:
832 case DW_OP_reg30:
833 case DW_OP_reg31:
834 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
835 regname (op - DW_OP_reg0, 1));
836 break;
838 case DW_OP_breg0:
839 case DW_OP_breg1:
840 case DW_OP_breg2:
841 case DW_OP_breg3:
842 case DW_OP_breg4:
843 case DW_OP_breg5:
844 case DW_OP_breg6:
845 case DW_OP_breg7:
846 case DW_OP_breg8:
847 case DW_OP_breg9:
848 case DW_OP_breg10:
849 case DW_OP_breg11:
850 case DW_OP_breg12:
851 case DW_OP_breg13:
852 case DW_OP_breg14:
853 case DW_OP_breg15:
854 case DW_OP_breg16:
855 case DW_OP_breg17:
856 case DW_OP_breg18:
857 case DW_OP_breg19:
858 case DW_OP_breg20:
859 case DW_OP_breg21:
860 case DW_OP_breg22:
861 case DW_OP_breg23:
862 case DW_OP_breg24:
863 case DW_OP_breg25:
864 case DW_OP_breg26:
865 case DW_OP_breg27:
866 case DW_OP_breg28:
867 case DW_OP_breg29:
868 case DW_OP_breg30:
869 case DW_OP_breg31:
870 printf ("DW_OP_breg%d (%s): %ld", op - DW_OP_breg0,
871 regname (op - DW_OP_breg0, 1),
872 read_leb128 (data, &bytes_read, 1));
873 data += bytes_read;
874 break;
876 case DW_OP_regx:
877 uvalue = read_leb128 (data, &bytes_read, 0);
878 data += bytes_read;
879 printf ("DW_OP_regx: %lu (%s)", uvalue, regname (uvalue, 1));
880 break;
881 case DW_OP_fbreg:
882 need_frame_base = 1;
883 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
884 data += bytes_read;
885 break;
886 case DW_OP_bregx:
887 uvalue = read_leb128 (data, &bytes_read, 0);
888 data += bytes_read;
889 printf ("DW_OP_bregx: %lu (%s) %ld", uvalue, regname (uvalue, 1),
890 read_leb128 (data, &bytes_read, 1));
891 data += bytes_read;
892 break;
893 case DW_OP_piece:
894 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
895 data += bytes_read;
896 break;
897 case DW_OP_deref_size:
898 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
899 break;
900 case DW_OP_xderef_size:
901 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
902 break;
903 case DW_OP_nop:
904 printf ("DW_OP_nop");
905 break;
907 /* DWARF 3 extensions. */
908 case DW_OP_push_object_address:
909 printf ("DW_OP_push_object_address");
910 break;
911 case DW_OP_call2:
912 /* XXX: Strictly speaking for 64-bit DWARF3 files
913 this ought to be an 8-byte wide computation. */
914 printf ("DW_OP_call2: <0x%lx>", (long) byte_get (data, 2) + cu_offset);
915 data += 2;
916 break;
917 case DW_OP_call4:
918 /* XXX: Strictly speaking for 64-bit DWARF3 files
919 this ought to be an 8-byte wide computation. */
920 printf ("DW_OP_call4: <0x%lx>", (long) byte_get (data, 4) + cu_offset);
921 data += 4;
922 break;
923 case DW_OP_call_ref:
924 /* XXX: Strictly speaking for 64-bit DWARF3 files
925 this ought to be an 8-byte wide computation. */
926 if (dwarf_version == -1)
928 printf (_("(DW_OP_call_ref in frame info)"));
929 /* No way to tell where the next op is, so just bail. */
930 return need_frame_base;
932 if (dwarf_version == 2)
934 printf ("DW_OP_call_ref: <0x%lx>",
935 (long) byte_get (data, pointer_size));
936 data += pointer_size;
938 else
940 printf ("DW_OP_call_ref: <0x%lx>",
941 (long) byte_get (data, offset_size));
942 data += offset_size;
944 break;
945 case DW_OP_form_tls_address:
946 printf ("DW_OP_form_tls_address");
947 break;
948 case DW_OP_call_frame_cfa:
949 printf ("DW_OP_call_frame_cfa");
950 break;
951 case DW_OP_bit_piece:
952 printf ("DW_OP_bit_piece: ");
953 printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
954 data += bytes_read;
955 printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
956 data += bytes_read;
957 break;
959 /* DWARF 4 extensions. */
960 case DW_OP_stack_value:
961 printf ("DW_OP_stack_value");
962 break;
964 case DW_OP_implicit_value:
965 printf ("DW_OP_implicit_value");
966 uvalue = read_leb128 (data, &bytes_read, 0);
967 data += bytes_read;
968 display_block (data, uvalue);
969 data += uvalue;
970 break;
972 /* GNU extensions. */
973 case DW_OP_GNU_push_tls_address:
974 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
975 break;
976 case DW_OP_GNU_uninit:
977 printf ("DW_OP_GNU_uninit");
978 /* FIXME: Is there data associated with this OP ? */
979 break;
980 case DW_OP_GNU_encoded_addr:
982 int encoding;
983 dwarf_vma addr;
985 encoding = *data++;
986 addr = get_encoded_value (data, encoding, section);
987 data += size_of_encoded_value (encoding);
989 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
990 print_dwarf_vma (addr, pointer_size);
992 break;
993 case DW_OP_GNU_implicit_pointer:
994 /* XXX: Strictly speaking for 64-bit DWARF3 files
995 this ought to be an 8-byte wide computation. */
996 if (dwarf_version == -1)
998 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
999 /* No way to tell where the next op is, so just bail. */
1000 return need_frame_base;
1002 if (dwarf_version == 2)
1004 printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
1005 (long) byte_get (data, pointer_size),
1006 read_leb128 (data + pointer_size, &bytes_read, 1));
1007 data += pointer_size + bytes_read;
1009 else
1011 printf ("DW_OP_GNU_implicit_pointer: <0x%lx> %ld",
1012 (long) byte_get (data, offset_size),
1013 read_leb128 (data + offset_size, &bytes_read, 1));
1014 data += offset_size + bytes_read;
1016 break;
1018 /* HP extensions. */
1019 case DW_OP_HP_is_value:
1020 printf ("DW_OP_HP_is_value");
1021 /* FIXME: Is there data associated with this OP ? */
1022 break;
1023 case DW_OP_HP_fltconst4:
1024 printf ("DW_OP_HP_fltconst4");
1025 /* FIXME: Is there data associated with this OP ? */
1026 break;
1027 case DW_OP_HP_fltconst8:
1028 printf ("DW_OP_HP_fltconst8");
1029 /* FIXME: Is there data associated with this OP ? */
1030 break;
1031 case DW_OP_HP_mod_range:
1032 printf ("DW_OP_HP_mod_range");
1033 /* FIXME: Is there data associated with this OP ? */
1034 break;
1035 case DW_OP_HP_unmod_range:
1036 printf ("DW_OP_HP_unmod_range");
1037 /* FIXME: Is there data associated with this OP ? */
1038 break;
1039 case DW_OP_HP_tls:
1040 printf ("DW_OP_HP_tls");
1041 /* FIXME: Is there data associated with this OP ? */
1042 break;
1044 /* PGI (STMicroelectronics) extensions. */
1045 case DW_OP_PGI_omp_thread_num:
1046 /* Pushes the thread number for the current thread as it would be
1047 returned by the standard OpenMP library function:
1048 omp_get_thread_num(). The "current thread" is the thread for
1049 which the expression is being evaluated. */
1050 printf ("DW_OP_PGI_omp_thread_num");
1051 break;
1053 default:
1054 if (op >= DW_OP_lo_user
1055 && op <= DW_OP_hi_user)
1056 printf (_("(User defined location op)"));
1057 else
1058 printf (_("(Unknown location op)"));
1059 /* No way to tell where the next op is, so just bail. */
1060 return need_frame_base;
1063 /* Separate the ops. */
1064 if (data < end)
1065 printf ("; ");
1068 return need_frame_base;
1071 static unsigned char *
1072 read_and_display_attr_value (unsigned long attribute,
1073 unsigned long form,
1074 unsigned char * data,
1075 unsigned long cu_offset,
1076 unsigned long pointer_size,
1077 unsigned long offset_size,
1078 int dwarf_version,
1079 debug_info * debug_info_p,
1080 int do_loc,
1081 struct dwarf_section * section)
1083 unsigned long uvalue = 0;
1084 unsigned char *block_start = NULL;
1085 unsigned char * orig_data = data;
1086 unsigned int bytes_read;
1088 switch (form)
1090 default:
1091 break;
1093 case DW_FORM_ref_addr:
1094 if (dwarf_version == 2)
1096 uvalue = byte_get (data, pointer_size);
1097 data += pointer_size;
1099 else if (dwarf_version == 3 || dwarf_version == 4)
1101 uvalue = byte_get (data, offset_size);
1102 data += offset_size;
1104 else
1106 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1108 break;
1110 case DW_FORM_addr:
1111 uvalue = byte_get (data, pointer_size);
1112 data += pointer_size;
1113 break;
1115 case DW_FORM_strp:
1116 case DW_FORM_sec_offset:
1117 uvalue = byte_get (data, offset_size);
1118 data += offset_size;
1119 break;
1121 case DW_FORM_flag_present:
1122 uvalue = 1;
1123 break;
1125 case DW_FORM_ref1:
1126 case DW_FORM_flag:
1127 case DW_FORM_data1:
1128 uvalue = byte_get (data++, 1);
1129 break;
1131 case DW_FORM_ref2:
1132 case DW_FORM_data2:
1133 uvalue = byte_get (data, 2);
1134 data += 2;
1135 break;
1137 case DW_FORM_ref4:
1138 case DW_FORM_data4:
1139 uvalue = byte_get (data, 4);
1140 data += 4;
1141 break;
1143 case DW_FORM_sdata:
1144 uvalue = read_leb128 (data, & bytes_read, 1);
1145 data += bytes_read;
1146 break;
1148 case DW_FORM_ref_udata:
1149 case DW_FORM_udata:
1150 uvalue = read_leb128 (data, & bytes_read, 0);
1151 data += bytes_read;
1152 break;
1154 case DW_FORM_indirect:
1155 form = read_leb128 (data, & bytes_read, 0);
1156 data += bytes_read;
1157 if (!do_loc)
1158 printf (" %s", get_FORM_name (form));
1159 return read_and_display_attr_value (attribute, form, data,
1160 cu_offset, pointer_size,
1161 offset_size, dwarf_version,
1162 debug_info_p, do_loc,
1163 section);
1166 switch (form)
1168 case DW_FORM_ref_addr:
1169 if (!do_loc)
1170 printf (" <0x%lx>", uvalue);
1171 break;
1173 case DW_FORM_ref1:
1174 case DW_FORM_ref2:
1175 case DW_FORM_ref4:
1176 case DW_FORM_ref_udata:
1177 if (!do_loc)
1178 printf (" <0x%lx>", uvalue + cu_offset);
1179 break;
1181 case DW_FORM_data4:
1182 case DW_FORM_addr:
1183 case DW_FORM_sec_offset:
1184 if (!do_loc)
1185 printf (" 0x%lx", uvalue);
1186 break;
1188 case DW_FORM_flag_present:
1189 case DW_FORM_flag:
1190 case DW_FORM_data1:
1191 case DW_FORM_data2:
1192 case DW_FORM_sdata:
1193 case DW_FORM_udata:
1194 if (!do_loc)
1195 printf (" %ld", uvalue);
1196 break;
1198 case DW_FORM_ref8:
1199 case DW_FORM_data8:
1200 if (!do_loc)
1202 uvalue = byte_get (data, 4);
1203 printf (" 0x%lx", uvalue);
1204 printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
1206 if ((do_loc || do_debug_loc || do_debug_ranges)
1207 && num_debug_info_entries == 0)
1209 if (sizeof (uvalue) == 8)
1210 uvalue = byte_get (data, 8);
1211 else
1212 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1214 data += 8;
1215 break;
1217 case DW_FORM_string:
1218 if (!do_loc)
1219 printf (" %s", data);
1220 data += strlen ((char *) data) + 1;
1221 break;
1223 case DW_FORM_block:
1224 case DW_FORM_exprloc:
1225 uvalue = read_leb128 (data, & bytes_read, 0);
1226 block_start = data + bytes_read;
1227 if (do_loc)
1228 data = block_start + uvalue;
1229 else
1230 data = display_block (block_start, uvalue);
1231 break;
1233 case DW_FORM_block1:
1234 uvalue = byte_get (data, 1);
1235 block_start = data + 1;
1236 if (do_loc)
1237 data = block_start + uvalue;
1238 else
1239 data = display_block (block_start, uvalue);
1240 break;
1242 case DW_FORM_block2:
1243 uvalue = byte_get (data, 2);
1244 block_start = data + 2;
1245 if (do_loc)
1246 data = block_start + uvalue;
1247 else
1248 data = display_block (block_start, uvalue);
1249 break;
1251 case DW_FORM_block4:
1252 uvalue = byte_get (data, 4);
1253 block_start = data + 4;
1254 if (do_loc)
1255 data = block_start + uvalue;
1256 else
1257 data = display_block (block_start, uvalue);
1258 break;
1260 case DW_FORM_strp:
1261 if (!do_loc)
1262 printf (_(" (indirect string, offset: 0x%lx): %s"),
1263 uvalue, fetch_indirect_string (uvalue));
1264 break;
1266 case DW_FORM_indirect:
1267 /* Handled above. */
1268 break;
1270 case DW_FORM_ref_sig8:
1271 if (!do_loc)
1273 int i;
1274 printf (" signature: ");
1275 for (i = 0; i < 8; i++)
1277 printf ("%02x", (unsigned) byte_get (data, 1));
1278 data += 1;
1281 else
1282 data += 8;
1283 break;
1285 default:
1286 warn (_("Unrecognized form: %lu\n"), form);
1287 break;
1290 if ((do_loc || do_debug_loc || do_debug_ranges)
1291 && num_debug_info_entries == 0)
1293 switch (attribute)
1295 case DW_AT_frame_base:
1296 have_frame_base = 1;
1297 case DW_AT_location:
1298 case DW_AT_string_length:
1299 case DW_AT_return_addr:
1300 case DW_AT_data_member_location:
1301 case DW_AT_vtable_elem_location:
1302 case DW_AT_segment:
1303 case DW_AT_static_link:
1304 case DW_AT_use_location:
1305 if (form == DW_FORM_data4
1306 || form == DW_FORM_data8
1307 || form == DW_FORM_sec_offset)
1309 /* Process location list. */
1310 unsigned int lmax = debug_info_p->max_loc_offsets;
1311 unsigned int num = debug_info_p->num_loc_offsets;
1313 if (lmax == 0 || num >= lmax)
1315 lmax += 1024;
1316 debug_info_p->loc_offsets = (long unsigned int *)
1317 xcrealloc (debug_info_p->loc_offsets,
1318 lmax, sizeof (*debug_info_p->loc_offsets));
1319 debug_info_p->have_frame_base = (int *)
1320 xcrealloc (debug_info_p->have_frame_base,
1321 lmax, sizeof (*debug_info_p->have_frame_base));
1322 debug_info_p->max_loc_offsets = lmax;
1324 debug_info_p->loc_offsets [num] = uvalue;
1325 debug_info_p->have_frame_base [num] = have_frame_base;
1326 debug_info_p->num_loc_offsets++;
1328 break;
1330 case DW_AT_low_pc:
1331 if (need_base_address)
1332 debug_info_p->base_address = uvalue;
1333 break;
1335 case DW_AT_ranges:
1336 if (form == DW_FORM_data4
1337 || form == DW_FORM_data8
1338 || form == DW_FORM_sec_offset)
1340 /* Process range list. */
1341 unsigned int lmax = debug_info_p->max_range_lists;
1342 unsigned int num = debug_info_p->num_range_lists;
1344 if (lmax == 0 || num >= lmax)
1346 lmax += 1024;
1347 debug_info_p->range_lists = (long unsigned int *)
1348 xcrealloc (debug_info_p->range_lists,
1349 lmax, sizeof (*debug_info_p->range_lists));
1350 debug_info_p->max_range_lists = lmax;
1352 debug_info_p->range_lists [num] = uvalue;
1353 debug_info_p->num_range_lists++;
1355 break;
1357 default:
1358 break;
1362 if (do_loc)
1363 return data;
1365 /* For some attributes we can display further information. */
1366 printf ("\t");
1368 switch (attribute)
1370 case DW_AT_inline:
1371 switch (uvalue)
1373 case DW_INL_not_inlined:
1374 printf (_("(not inlined)"));
1375 break;
1376 case DW_INL_inlined:
1377 printf (_("(inlined)"));
1378 break;
1379 case DW_INL_declared_not_inlined:
1380 printf (_("(declared as inline but ignored)"));
1381 break;
1382 case DW_INL_declared_inlined:
1383 printf (_("(declared as inline and inlined)"));
1384 break;
1385 default:
1386 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
1387 break;
1389 break;
1391 case DW_AT_language:
1392 switch (uvalue)
1394 /* Ordered by the numeric value of these constants. */
1395 case DW_LANG_C89: printf ("(ANSI C)"); break;
1396 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1397 case DW_LANG_Ada83: printf ("(Ada)"); break;
1398 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1399 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1400 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1401 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1402 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1403 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1404 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1405 /* DWARF 2.1 values. */
1406 case DW_LANG_Java: printf ("(Java)"); break;
1407 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1408 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1409 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1410 /* DWARF 3 values. */
1411 case DW_LANG_PLI: printf ("(PLI)"); break;
1412 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1413 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1414 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1415 case DW_LANG_D: printf ("(D)"); break;
1416 /* DWARF 4 values. */
1417 case DW_LANG_Python: printf ("(Python)"); break;
1418 /* MIPS extension. */
1419 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1420 /* UPC extension. */
1421 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1422 default:
1423 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1424 printf ("(implementation defined: %lx)", uvalue);
1425 else
1426 printf ("(Unknown: %lx)", uvalue);
1427 break;
1429 break;
1431 case DW_AT_encoding:
1432 switch (uvalue)
1434 case DW_ATE_void: printf ("(void)"); break;
1435 case DW_ATE_address: printf ("(machine address)"); break;
1436 case DW_ATE_boolean: printf ("(boolean)"); break;
1437 case DW_ATE_complex_float: printf ("(complex float)"); break;
1438 case DW_ATE_float: printf ("(float)"); break;
1439 case DW_ATE_signed: printf ("(signed)"); break;
1440 case DW_ATE_signed_char: printf ("(signed char)"); break;
1441 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1442 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1443 /* DWARF 2.1 values: */
1444 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1445 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1446 /* DWARF 3 values: */
1447 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1448 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1449 case DW_ATE_edited: printf ("(edited)"); break;
1450 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1451 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1452 /* HP extensions: */
1453 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1454 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1455 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1456 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1457 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1458 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1459 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1461 default:
1462 if (uvalue >= DW_ATE_lo_user
1463 && uvalue <= DW_ATE_hi_user)
1464 printf ("(user defined type)");
1465 else
1466 printf ("(unknown type)");
1467 break;
1469 break;
1471 case DW_AT_accessibility:
1472 switch (uvalue)
1474 case DW_ACCESS_public: printf ("(public)"); break;
1475 case DW_ACCESS_protected: printf ("(protected)"); break;
1476 case DW_ACCESS_private: printf ("(private)"); break;
1477 default:
1478 printf ("(unknown accessibility)");
1479 break;
1481 break;
1483 case DW_AT_visibility:
1484 switch (uvalue)
1486 case DW_VIS_local: printf ("(local)"); break;
1487 case DW_VIS_exported: printf ("(exported)"); break;
1488 case DW_VIS_qualified: printf ("(qualified)"); break;
1489 default: printf ("(unknown visibility)"); break;
1491 break;
1493 case DW_AT_virtuality:
1494 switch (uvalue)
1496 case DW_VIRTUALITY_none: printf ("(none)"); break;
1497 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1498 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1499 default: printf ("(unknown virtuality)"); break;
1501 break;
1503 case DW_AT_identifier_case:
1504 switch (uvalue)
1506 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1507 case DW_ID_up_case: printf ("(up_case)"); break;
1508 case DW_ID_down_case: printf ("(down_case)"); break;
1509 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1510 default: printf ("(unknown case)"); break;
1512 break;
1514 case DW_AT_calling_convention:
1515 switch (uvalue)
1517 case DW_CC_normal: printf ("(normal)"); break;
1518 case DW_CC_program: printf ("(program)"); break;
1519 case DW_CC_nocall: printf ("(nocall)"); break;
1520 default:
1521 if (uvalue >= DW_CC_lo_user
1522 && uvalue <= DW_CC_hi_user)
1523 printf ("(user defined)");
1524 else
1525 printf ("(unknown convention)");
1527 break;
1529 case DW_AT_ordering:
1530 switch (uvalue)
1532 case -1: printf ("(undefined)"); break;
1533 case 0: printf ("(row major)"); break;
1534 case 1: printf ("(column major)"); break;
1536 break;
1538 case DW_AT_frame_base:
1539 have_frame_base = 1;
1540 case DW_AT_location:
1541 case DW_AT_string_length:
1542 case DW_AT_return_addr:
1543 case DW_AT_data_member_location:
1544 case DW_AT_vtable_elem_location:
1545 case DW_AT_segment:
1546 case DW_AT_static_link:
1547 case DW_AT_use_location:
1548 if (form == DW_FORM_data4
1549 || form == DW_FORM_data8
1550 || form == DW_FORM_sec_offset)
1551 printf (_("(location list)"));
1552 /* Fall through. */
1553 case DW_AT_allocated:
1554 case DW_AT_associated:
1555 case DW_AT_data_location:
1556 case DW_AT_stride:
1557 case DW_AT_upper_bound:
1558 case DW_AT_lower_bound:
1559 if (block_start)
1561 int need_frame_base;
1563 printf ("(");
1564 need_frame_base = decode_location_expression (block_start,
1565 pointer_size,
1566 offset_size,
1567 dwarf_version,
1568 uvalue,
1569 cu_offset, section);
1570 printf (")");
1571 if (need_frame_base && !have_frame_base)
1572 printf (_(" [without DW_AT_frame_base]"));
1574 break;
1576 case DW_AT_import:
1578 if (form == DW_FORM_ref_sig8)
1579 break;
1581 if (form == DW_FORM_ref1
1582 || form == DW_FORM_ref2
1583 || form == DW_FORM_ref4)
1584 uvalue += cu_offset;
1586 if (uvalue >= section->size)
1587 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1588 uvalue, (unsigned long) (orig_data - section->start));
1589 else
1591 unsigned long abbrev_number;
1592 abbrev_entry * entry;
1594 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1596 printf ("[Abbrev Number: %ld", abbrev_number);
1597 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1598 if (entry->entry == abbrev_number)
1599 break;
1600 if (entry != NULL)
1601 printf (" (%s)", get_TAG_name (entry->tag));
1602 printf ("]");
1605 break;
1607 default:
1608 break;
1611 return data;
1614 static char *
1615 get_AT_name (unsigned long attribute)
1617 switch (attribute)
1619 case DW_AT_sibling: return "DW_AT_sibling";
1620 case DW_AT_location: return "DW_AT_location";
1621 case DW_AT_name: return "DW_AT_name";
1622 case DW_AT_ordering: return "DW_AT_ordering";
1623 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1624 case DW_AT_byte_size: return "DW_AT_byte_size";
1625 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1626 case DW_AT_bit_size: return "DW_AT_bit_size";
1627 case DW_AT_element_list: return "DW_AT_element_list";
1628 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1629 case DW_AT_low_pc: return "DW_AT_low_pc";
1630 case DW_AT_high_pc: return "DW_AT_high_pc";
1631 case DW_AT_language: return "DW_AT_language";
1632 case DW_AT_member: return "DW_AT_member";
1633 case DW_AT_discr: return "DW_AT_discr";
1634 case DW_AT_discr_value: return "DW_AT_discr_value";
1635 case DW_AT_visibility: return "DW_AT_visibility";
1636 case DW_AT_import: return "DW_AT_import";
1637 case DW_AT_string_length: return "DW_AT_string_length";
1638 case DW_AT_common_reference: return "DW_AT_common_reference";
1639 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1640 case DW_AT_const_value: return "DW_AT_const_value";
1641 case DW_AT_containing_type: return "DW_AT_containing_type";
1642 case DW_AT_default_value: return "DW_AT_default_value";
1643 case DW_AT_inline: return "DW_AT_inline";
1644 case DW_AT_is_optional: return "DW_AT_is_optional";
1645 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1646 case DW_AT_producer: return "DW_AT_producer";
1647 case DW_AT_prototyped: return "DW_AT_prototyped";
1648 case DW_AT_return_addr: return "DW_AT_return_addr";
1649 case DW_AT_start_scope: return "DW_AT_start_scope";
1650 case DW_AT_stride_size: return "DW_AT_stride_size";
1651 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1652 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1653 case DW_AT_accessibility: return "DW_AT_accessibility";
1654 case DW_AT_address_class: return "DW_AT_address_class";
1655 case DW_AT_artificial: return "DW_AT_artificial";
1656 case DW_AT_base_types: return "DW_AT_base_types";
1657 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1658 case DW_AT_count: return "DW_AT_count";
1659 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1660 case DW_AT_decl_column: return "DW_AT_decl_column";
1661 case DW_AT_decl_file: return "DW_AT_decl_file";
1662 case DW_AT_decl_line: return "DW_AT_decl_line";
1663 case DW_AT_declaration: return "DW_AT_declaration";
1664 case DW_AT_discr_list: return "DW_AT_discr_list";
1665 case DW_AT_encoding: return "DW_AT_encoding";
1666 case DW_AT_external: return "DW_AT_external";
1667 case DW_AT_frame_base: return "DW_AT_frame_base";
1668 case DW_AT_friend: return "DW_AT_friend";
1669 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1670 case DW_AT_macro_info: return "DW_AT_macro_info";
1671 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1672 case DW_AT_priority: return "DW_AT_priority";
1673 case DW_AT_segment: return "DW_AT_segment";
1674 case DW_AT_specification: return "DW_AT_specification";
1675 case DW_AT_static_link: return "DW_AT_static_link";
1676 case DW_AT_type: return "DW_AT_type";
1677 case DW_AT_use_location: return "DW_AT_use_location";
1678 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1679 case DW_AT_virtuality: return "DW_AT_virtuality";
1680 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1681 /* DWARF 2.1 values. */
1682 case DW_AT_allocated: return "DW_AT_allocated";
1683 case DW_AT_associated: return "DW_AT_associated";
1684 case DW_AT_data_location: return "DW_AT_data_location";
1685 case DW_AT_stride: return "DW_AT_stride";
1686 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1687 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1688 case DW_AT_extension: return "DW_AT_extension";
1689 case DW_AT_ranges: return "DW_AT_ranges";
1690 case DW_AT_trampoline: return "DW_AT_trampoline";
1691 case DW_AT_call_column: return "DW_AT_call_column";
1692 case DW_AT_call_file: return "DW_AT_call_file";
1693 case DW_AT_call_line: return "DW_AT_call_line";
1694 case DW_AT_description: return "DW_AT_description";
1695 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1696 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1697 case DW_AT_small: return "DW_AT_small";
1698 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1699 case DW_AT_digit_count: return "DW_AT_digit_count";
1700 case DW_AT_picture_string: return "DW_AT_picture_string";
1701 case DW_AT_mutable: return "DW_AT_mutable";
1702 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1703 case DW_AT_explicit: return "DW_AT_explicit";
1704 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1705 case DW_AT_endianity: return "DW_AT_endianity";
1706 case DW_AT_elemental: return "DW_AT_elemental";
1707 case DW_AT_pure: return "DW_AT_pure";
1708 case DW_AT_recursive: return "DW_AT_recursive";
1709 /* DWARF 4 values. */
1710 case DW_AT_signature: return "DW_AT_signature";
1711 case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
1712 case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
1713 case DW_AT_const_expr: return "DW_AT_const_expr";
1714 case DW_AT_enum_class: return "DW_AT_enum_class";
1715 case DW_AT_linkage_name: return "DW_AT_linkage_name";
1717 /* HP and SGI/MIPS extensions. */
1718 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1719 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1720 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1721 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1722 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1723 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1724 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1725 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1726 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1727 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1729 /* HP Extensions. */
1730 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
1731 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1732 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1733 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1734 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1735 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1736 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1737 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1738 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1739 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1740 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1741 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1742 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1744 /* One value is shared by the MIPS and HP extensions: */
1745 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1747 /* GNU extensions. */
1748 case DW_AT_sf_names: return "DW_AT_sf_names";
1749 case DW_AT_src_info: return "DW_AT_src_info";
1750 case DW_AT_mac_info: return "DW_AT_mac_info";
1751 case DW_AT_src_coords: return "DW_AT_src_coords";
1752 case DW_AT_body_begin: return "DW_AT_body_begin";
1753 case DW_AT_body_end: return "DW_AT_body_end";
1754 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1755 case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by";
1756 case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by";
1757 case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded";
1758 case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded";
1759 case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded";
1760 case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required";
1761 case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required";
1762 case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature";
1763 case DW_AT_use_GNAT_descriptive_type: return "DW_AT_use_GNAT_descriptive_type";
1764 case DW_AT_GNAT_descriptive_type: return "DW_AT_GNAT_descriptive_type";
1766 /* UPC extension. */
1767 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1769 /* PGI (STMicroelectronics) extensions. */
1770 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1771 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1772 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1774 default:
1776 static char buffer[100];
1778 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1779 attribute);
1780 return buffer;
1785 static unsigned char *
1786 read_and_display_attr (unsigned long attribute,
1787 unsigned long form,
1788 unsigned char * data,
1789 unsigned long cu_offset,
1790 unsigned long pointer_size,
1791 unsigned long offset_size,
1792 int dwarf_version,
1793 debug_info * debug_info_p,
1794 int do_loc,
1795 struct dwarf_section * section)
1797 if (!do_loc)
1798 printf (" %-18s:", get_AT_name (attribute));
1799 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1800 pointer_size, offset_size,
1801 dwarf_version, debug_info_p,
1802 do_loc, section);
1803 if (!do_loc)
1804 printf ("\n");
1805 return data;
1809 /* Process the contents of a .debug_info section. If do_loc is non-zero
1810 then we are scanning for location lists and we do not want to display
1811 anything to the user. If do_types is non-zero, we are processing
1812 a .debug_types section instead of a .debug_info section. */
1814 static int
1815 process_debug_info (struct dwarf_section *section,
1816 void *file,
1817 enum dwarf_section_display_enum abbrev_sec,
1818 int do_loc,
1819 int do_types)
1821 unsigned char *start = section->start;
1822 unsigned char *end = start + section->size;
1823 unsigned char *section_begin;
1824 unsigned int unit;
1825 unsigned int num_units = 0;
1827 if ((do_loc || do_debug_loc || do_debug_ranges)
1828 && num_debug_info_entries == 0
1829 && ! do_types)
1831 unsigned long length;
1833 /* First scan the section to get the number of comp units. */
1834 for (section_begin = start, num_units = 0; section_begin < end;
1835 num_units ++)
1837 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1838 will be the length. For a 64-bit DWARF section, it'll be
1839 the escape code 0xffffffff followed by an 8 byte length. */
1840 length = byte_get (section_begin, 4);
1842 if (length == 0xffffffff)
1844 length = byte_get (section_begin + 4, 8);
1845 section_begin += length + 12;
1847 else if (length >= 0xfffffff0 && length < 0xffffffff)
1849 warn (_("Reserved length value (%lx) found in section %s\n"), length, section->name);
1850 return 0;
1852 else
1853 section_begin += length + 4;
1855 /* Negative values are illegal, they may even cause infinite
1856 looping. This can happen if we can't accurately apply
1857 relocations to an object file. */
1858 if ((signed long) length <= 0)
1860 warn (_("Corrupt unit length (%lx) found in section %s\n"), length, section->name);
1861 return 0;
1865 if (num_units == 0)
1867 error (_("No comp units in %s section ?"), section->name);
1868 return 0;
1871 /* Then allocate an array to hold the information. */
1872 debug_information = (debug_info *) cmalloc (num_units,
1873 sizeof (* debug_information));
1874 if (debug_information == NULL)
1876 error (_("Not enough memory for a debug info array of %u entries"),
1877 num_units);
1878 return 0;
1882 if (!do_loc)
1884 printf (_("Contents of the %s section:\n\n"), section->name);
1886 load_debug_section (str, file);
1889 load_debug_section (abbrev_sec, file);
1890 if (debug_displays [abbrev_sec].section.start == NULL)
1892 warn (_("Unable to locate %s section!\n"),
1893 debug_displays [abbrev_sec].section.name);
1894 return 0;
1897 for (section_begin = start, unit = 0; start < end; unit++)
1899 DWARF2_Internal_CompUnit compunit;
1900 unsigned char *hdrptr;
1901 unsigned char *tags;
1902 int level;
1903 unsigned long cu_offset;
1904 int offset_size;
1905 int initial_length_size;
1906 unsigned char signature[8] = { 0 };
1907 unsigned long type_offset = 0;
1909 hdrptr = start;
1911 compunit.cu_length = byte_get (hdrptr, 4);
1912 hdrptr += 4;
1914 if (compunit.cu_length == 0xffffffff)
1916 compunit.cu_length = byte_get (hdrptr, 8);
1917 hdrptr += 8;
1918 offset_size = 8;
1919 initial_length_size = 12;
1921 else
1923 offset_size = 4;
1924 initial_length_size = 4;
1927 compunit.cu_version = byte_get (hdrptr, 2);
1928 hdrptr += 2;
1930 cu_offset = start - section_begin;
1932 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
1933 hdrptr += offset_size;
1935 compunit.cu_pointer_size = byte_get (hdrptr, 1);
1936 hdrptr += 1;
1938 if (do_types)
1940 int i;
1942 for (i = 0; i < 8; i++)
1944 signature[i] = byte_get (hdrptr, 1);
1945 hdrptr += 1;
1948 type_offset = byte_get (hdrptr, offset_size);
1949 hdrptr += offset_size;
1952 if ((do_loc || do_debug_loc || do_debug_ranges)
1953 && num_debug_info_entries == 0
1954 && ! do_types)
1956 debug_information [unit].cu_offset = cu_offset;
1957 debug_information [unit].pointer_size
1958 = compunit.cu_pointer_size;
1959 debug_information [unit].offset_size = offset_size;
1960 debug_information [unit].dwarf_version = compunit.cu_version;
1961 debug_information [unit].base_address = 0;
1962 debug_information [unit].loc_offsets = NULL;
1963 debug_information [unit].have_frame_base = NULL;
1964 debug_information [unit].max_loc_offsets = 0;
1965 debug_information [unit].num_loc_offsets = 0;
1966 debug_information [unit].range_lists = NULL;
1967 debug_information [unit].max_range_lists= 0;
1968 debug_information [unit].num_range_lists = 0;
1971 if (!do_loc)
1973 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset);
1974 printf (_(" Length: 0x%lx (%s)\n"), compunit.cu_length,
1975 initial_length_size == 8 ? "64-bit" : "32-bit");
1976 printf (_(" Version: %d\n"), compunit.cu_version);
1977 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
1978 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
1979 if (do_types)
1981 int i;
1982 printf (_(" Signature: "));
1983 for (i = 0; i < 8; i++)
1984 printf ("%02x", signature[i]);
1985 printf ("\n");
1986 printf (_(" Type Offset: 0x%lx\n"), type_offset);
1990 if (cu_offset + compunit.cu_length + initial_length_size
1991 > section->size)
1993 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1994 cu_offset, compunit.cu_length);
1995 break;
1997 tags = hdrptr;
1998 start += compunit.cu_length + initial_length_size;
2000 if (compunit.cu_version != 2
2001 && compunit.cu_version != 3
2002 && compunit.cu_version != 4)
2004 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
2005 cu_offset, compunit.cu_version);
2006 continue;
2009 free_abbrevs ();
2011 /* Process the abbrevs used by this compilation unit. DWARF
2012 sections under Mach-O have non-zero addresses. */
2013 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2014 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2015 (unsigned long) compunit.cu_abbrev_offset,
2016 (unsigned long) debug_displays [abbrev_sec].section.size);
2017 else
2018 process_abbrev_section
2019 ((unsigned char *) debug_displays [abbrev_sec].section.start
2020 + compunit.cu_abbrev_offset,
2021 (unsigned char *) debug_displays [abbrev_sec].section.start
2022 + debug_displays [abbrev_sec].section.size);
2024 level = 0;
2025 while (tags < start)
2027 unsigned int bytes_read;
2028 unsigned long abbrev_number;
2029 unsigned long die_offset;
2030 abbrev_entry *entry;
2031 abbrev_attr *attr;
2033 die_offset = tags - section_begin;
2035 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2036 tags += bytes_read;
2038 /* A null DIE marks the end of a list of siblings or it may also be
2039 a section padding. */
2040 if (abbrev_number == 0)
2042 /* Check if it can be a section padding for the last CU. */
2043 if (level == 0 && start == end)
2045 unsigned char *chk;
2047 for (chk = tags; chk < start; chk++)
2048 if (*chk != 0)
2049 break;
2050 if (chk == start)
2051 break;
2054 --level;
2055 if (level < 0)
2057 static unsigned num_bogus_warns = 0;
2059 if (num_bogus_warns < 3)
2061 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2062 die_offset);
2063 num_bogus_warns ++;
2064 if (num_bogus_warns == 3)
2065 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2068 continue;
2071 if (!do_loc)
2072 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2073 level, die_offset, abbrev_number);
2075 /* Scan through the abbreviation list until we reach the
2076 correct entry. */
2077 for (entry = first_abbrev;
2078 entry && entry->entry != abbrev_number;
2079 entry = entry->next)
2080 continue;
2082 if (entry == NULL)
2084 if (!do_loc)
2086 printf ("\n");
2087 fflush (stdout);
2089 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2090 die_offset, abbrev_number);
2091 return 0;
2094 if (!do_loc)
2095 printf (" (%s)\n", get_TAG_name (entry->tag));
2097 switch (entry->tag)
2099 default:
2100 need_base_address = 0;
2101 break;
2102 case DW_TAG_compile_unit:
2103 need_base_address = 1;
2104 break;
2105 case DW_TAG_entry_point:
2106 case DW_TAG_subprogram:
2107 need_base_address = 0;
2108 /* Assuming that there is no DW_AT_frame_base. */
2109 have_frame_base = 0;
2110 break;
2113 for (attr = entry->first_attr; attr; attr = attr->next)
2115 if (! do_loc)
2116 /* Show the offset from where the tag was extracted. */
2117 printf (" <%2lx>", (unsigned long)(tags - section_begin));
2119 tags = read_and_display_attr (attr->attribute,
2120 attr->form,
2121 tags, cu_offset,
2122 compunit.cu_pointer_size,
2123 offset_size,
2124 compunit.cu_version,
2125 debug_information + unit,
2126 do_loc, section);
2129 if (entry->children)
2130 ++level;
2134 /* Set num_debug_info_entries here so that it can be used to check if
2135 we need to process .debug_loc and .debug_ranges sections. */
2136 if ((do_loc || do_debug_loc || do_debug_ranges)
2137 && num_debug_info_entries == 0
2138 && ! do_types)
2139 num_debug_info_entries = num_units;
2141 if (!do_loc)
2143 printf ("\n");
2146 return 1;
2149 /* Locate and scan the .debug_info section in the file and record the pointer
2150 sizes and offsets for the compilation units in it. Usually an executable
2151 will have just one pointer size, but this is not guaranteed, and so we try
2152 not to make any assumptions. Returns zero upon failure, or the number of
2153 compilation units upon success. */
2155 static unsigned int
2156 load_debug_info (void * file)
2158 /* Reset the last pointer size so that we can issue correct error
2159 messages if we are displaying the contents of more than one section. */
2160 last_pointer_size = 0;
2161 warned_about_missing_comp_units = FALSE;
2163 /* If we have already tried and failed to load the .debug_info
2164 section then do not bother to repear the task. */
2165 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2166 return 0;
2168 /* If we already have the information there is nothing else to do. */
2169 if (num_debug_info_entries > 0)
2170 return num_debug_info_entries;
2172 if (load_debug_section (info, file)
2173 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2174 return num_debug_info_entries;
2176 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2177 return 0;
2180 static int
2181 display_debug_lines_raw (struct dwarf_section *section,
2182 unsigned char *data,
2183 unsigned char *end)
2185 unsigned char *start = section->start;
2187 printf (_("Raw dump of debug contents of section %s:\n\n"),
2188 section->name);
2190 while (data < end)
2192 DWARF2_Internal_LineInfo linfo;
2193 unsigned char *standard_opcodes;
2194 unsigned char *end_of_sequence;
2195 unsigned char *hdrptr;
2196 unsigned long hdroff;
2197 int initial_length_size;
2198 int offset_size;
2199 int i;
2201 hdrptr = data;
2202 hdroff = hdrptr - start;
2204 /* Check the length of the block. */
2205 linfo.li_length = byte_get (hdrptr, 4);
2206 hdrptr += 4;
2208 if (linfo.li_length == 0xffffffff)
2210 /* This section is 64-bit DWARF 3. */
2211 linfo.li_length = byte_get (hdrptr, 8);
2212 hdrptr += 8;
2213 offset_size = 8;
2214 initial_length_size = 12;
2216 else
2218 offset_size = 4;
2219 initial_length_size = 4;
2222 if (linfo.li_length + initial_length_size > section->size)
2224 warn
2225 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2226 section->name);
2227 return 0;
2230 /* Check its version number. */
2231 linfo.li_version = byte_get (hdrptr, 2);
2232 hdrptr += 2;
2233 if (linfo.li_version != 2
2234 && linfo.li_version != 3
2235 && linfo.li_version != 4)
2237 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2238 return 0;
2241 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2242 hdrptr += offset_size;
2243 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2244 hdrptr++;
2245 if (linfo.li_version >= 4)
2247 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2248 hdrptr++;
2249 if (linfo.li_max_ops_per_insn == 0)
2251 warn (_("Invalid maximum operations per insn.\n"));
2252 return 0;
2255 else
2256 linfo.li_max_ops_per_insn = 1;
2257 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2258 hdrptr++;
2259 linfo.li_line_base = byte_get (hdrptr, 1);
2260 hdrptr++;
2261 linfo.li_line_range = byte_get (hdrptr, 1);
2262 hdrptr++;
2263 linfo.li_opcode_base = byte_get (hdrptr, 1);
2264 hdrptr++;
2266 /* Sign extend the line base field. */
2267 linfo.li_line_base <<= 24;
2268 linfo.li_line_base >>= 24;
2270 printf (_(" Offset: 0x%lx\n"), hdroff);
2271 printf (_(" Length: %ld\n"), linfo.li_length);
2272 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2273 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2274 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2275 if (linfo.li_version >= 4)
2276 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2277 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2278 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2279 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2280 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2282 end_of_sequence = data + linfo.li_length + initial_length_size;
2284 reset_state_machine (linfo.li_default_is_stmt);
2286 /* Display the contents of the Opcodes table. */
2287 standard_opcodes = hdrptr;
2289 printf (_("\n Opcodes:\n"));
2291 for (i = 1; i < linfo.li_opcode_base; i++)
2292 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2294 /* Display the contents of the Directory table. */
2295 data = standard_opcodes + linfo.li_opcode_base - 1;
2297 if (*data == 0)
2298 printf (_("\n The Directory Table is empty.\n"));
2299 else
2301 printf (_("\n The Directory Table:\n"));
2303 while (*data != 0)
2305 printf (" %s\n", data);
2307 data += strlen ((char *) data) + 1;
2311 /* Skip the NUL at the end of the table. */
2312 data++;
2314 /* Display the contents of the File Name table. */
2315 if (*data == 0)
2316 printf (_("\n The File Name Table is empty.\n"));
2317 else
2319 printf (_("\n The File Name Table:\n"));
2320 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2322 while (*data != 0)
2324 unsigned char *name;
2325 unsigned int bytes_read;
2327 printf (" %d\t", ++state_machine_regs.last_file_entry);
2328 name = data;
2330 data += strlen ((char *) data) + 1;
2332 printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
2333 data += bytes_read;
2334 printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
2335 data += bytes_read;
2336 printf ("%lu\t", read_leb128 (data, & bytes_read, 0));
2337 data += bytes_read;
2338 printf ("%s\n", name);
2342 /* Skip the NUL at the end of the table. */
2343 data++;
2345 /* Now display the statements. */
2346 printf (_("\n Line Number Statements:\n"));
2348 while (data < end_of_sequence)
2350 unsigned char op_code;
2351 int adv;
2352 unsigned long int uladv;
2353 unsigned int bytes_read;
2355 op_code = *data++;
2357 if (op_code >= linfo.li_opcode_base)
2359 op_code -= linfo.li_opcode_base;
2360 uladv = (op_code / linfo.li_line_range);
2361 if (linfo.li_max_ops_per_insn == 1)
2363 uladv *= linfo.li_min_insn_length;
2364 state_machine_regs.address += uladv;
2365 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2366 op_code, uladv, state_machine_regs.address);
2368 else
2370 state_machine_regs.address
2371 += ((state_machine_regs.op_index + uladv)
2372 / linfo.li_max_ops_per_insn)
2373 * linfo.li_min_insn_length;
2374 state_machine_regs.op_index
2375 = (state_machine_regs.op_index + uladv)
2376 % linfo.li_max_ops_per_insn;
2377 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx[%d]"),
2378 op_code, uladv, state_machine_regs.address,
2379 state_machine_regs.op_index);
2381 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2382 state_machine_regs.line += adv;
2383 printf (_(" and Line by %d to %d\n"),
2384 adv, state_machine_regs.line);
2386 else switch (op_code)
2388 case DW_LNS_extended_op:
2389 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2390 break;
2392 case DW_LNS_copy:
2393 printf (_(" Copy\n"));
2394 break;
2396 case DW_LNS_advance_pc:
2397 uladv = read_leb128 (data, & bytes_read, 0);
2398 data += bytes_read;
2399 if (linfo.li_max_ops_per_insn == 1)
2401 uladv *= linfo.li_min_insn_length;
2402 state_machine_regs.address += uladv;
2403 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv,
2404 state_machine_regs.address);
2406 else
2408 state_machine_regs.address
2409 += ((state_machine_regs.op_index + uladv)
2410 / linfo.li_max_ops_per_insn)
2411 * linfo.li_min_insn_length;
2412 state_machine_regs.op_index
2413 = (state_machine_regs.op_index + uladv)
2414 % linfo.li_max_ops_per_insn;
2415 printf (_(" Advance PC by %lu to 0x%lx[%d]\n"), uladv,
2416 state_machine_regs.address,
2417 state_machine_regs.op_index);
2419 break;
2421 case DW_LNS_advance_line:
2422 adv = read_leb128 (data, & bytes_read, 1);
2423 data += bytes_read;
2424 state_machine_regs.line += adv;
2425 printf (_(" Advance Line by %d to %d\n"), adv,
2426 state_machine_regs.line);
2427 break;
2429 case DW_LNS_set_file:
2430 adv = read_leb128 (data, & bytes_read, 0);
2431 data += bytes_read;
2432 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2433 adv);
2434 state_machine_regs.file = adv;
2435 break;
2437 case DW_LNS_set_column:
2438 uladv = read_leb128 (data, & bytes_read, 0);
2439 data += bytes_read;
2440 printf (_(" Set column to %lu\n"), uladv);
2441 state_machine_regs.column = uladv;
2442 break;
2444 case DW_LNS_negate_stmt:
2445 adv = state_machine_regs.is_stmt;
2446 adv = ! adv;
2447 printf (_(" Set is_stmt to %d\n"), adv);
2448 state_machine_regs.is_stmt = adv;
2449 break;
2451 case DW_LNS_set_basic_block:
2452 printf (_(" Set basic block\n"));
2453 state_machine_regs.basic_block = 1;
2454 break;
2456 case DW_LNS_const_add_pc:
2457 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2458 if (linfo.li_max_ops_per_insn)
2460 uladv *= linfo.li_min_insn_length;
2461 state_machine_regs.address += uladv;
2462 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv,
2463 state_machine_regs.address);
2465 else
2467 state_machine_regs.address
2468 += ((state_machine_regs.op_index + uladv)
2469 / linfo.li_max_ops_per_insn)
2470 * linfo.li_min_insn_length;
2471 state_machine_regs.op_index
2472 = (state_machine_regs.op_index + uladv)
2473 % linfo.li_max_ops_per_insn;
2474 printf (_(" Advance PC by constant %lu to 0x%lx[%d]\n"),
2475 uladv, state_machine_regs.address,
2476 state_machine_regs.op_index);
2478 break;
2480 case DW_LNS_fixed_advance_pc:
2481 uladv = byte_get (data, 2);
2482 data += 2;
2483 state_machine_regs.address += uladv;
2484 state_machine_regs.op_index = 0;
2485 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2486 uladv, state_machine_regs.address);
2487 break;
2489 case DW_LNS_set_prologue_end:
2490 printf (_(" Set prologue_end to true\n"));
2491 break;
2493 case DW_LNS_set_epilogue_begin:
2494 printf (_(" Set epilogue_begin to true\n"));
2495 break;
2497 case DW_LNS_set_isa:
2498 uladv = read_leb128 (data, & bytes_read, 0);
2499 data += bytes_read;
2500 printf (_(" Set ISA to %lu\n"), uladv);
2501 break;
2503 default:
2504 printf (_(" Unknown opcode %d with operands: "), op_code);
2506 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2508 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
2509 i == 1 ? "" : ", ");
2510 data += bytes_read;
2512 putchar ('\n');
2513 break;
2516 putchar ('\n');
2519 return 1;
2522 typedef struct
2524 unsigned char *name;
2525 unsigned int directory_index;
2526 unsigned int modification_date;
2527 unsigned int length;
2528 } File_Entry;
2530 /* Output a decoded representation of the .debug_line section. */
2532 static int
2533 display_debug_lines_decoded (struct dwarf_section *section,
2534 unsigned char *data,
2535 unsigned char *end)
2537 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2538 section->name);
2540 while (data < end)
2542 /* This loop amounts to one iteration per compilation unit. */
2543 DWARF2_Internal_LineInfo linfo;
2544 unsigned char *standard_opcodes;
2545 unsigned char *end_of_sequence;
2546 unsigned char *hdrptr;
2547 int initial_length_size;
2548 int offset_size;
2549 int i;
2550 File_Entry *file_table = NULL;
2551 unsigned char **directory_table = NULL;
2553 hdrptr = data;
2555 /* Extract information from the Line Number Program Header.
2556 (section 6.2.4 in the Dwarf3 doc). */
2558 /* Get the length of this CU's line number information block. */
2559 linfo.li_length = byte_get (hdrptr, 4);
2560 hdrptr += 4;
2562 if (linfo.li_length == 0xffffffff)
2564 /* This section is 64-bit DWARF 3. */
2565 linfo.li_length = byte_get (hdrptr, 8);
2566 hdrptr += 8;
2567 offset_size = 8;
2568 initial_length_size = 12;
2570 else
2572 offset_size = 4;
2573 initial_length_size = 4;
2576 if (linfo.li_length + initial_length_size > section->size)
2578 warn (_("The line info appears to be corrupt - "
2579 "the section is too small\n"));
2580 return 0;
2583 /* Get this CU's Line Number Block version number. */
2584 linfo.li_version = byte_get (hdrptr, 2);
2585 hdrptr += 2;
2586 if (linfo.li_version != 2
2587 && linfo.li_version != 3
2588 && linfo.li_version != 4)
2590 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2591 "supported.\n"));
2592 return 0;
2595 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2596 hdrptr += offset_size;
2597 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2598 hdrptr++;
2599 if (linfo.li_version >= 4)
2601 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2602 hdrptr++;
2603 if (linfo.li_max_ops_per_insn == 0)
2605 warn (_("Invalid maximum operations per insn.\n"));
2606 return 0;
2609 else
2610 linfo.li_max_ops_per_insn = 1;
2611 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2612 hdrptr++;
2613 linfo.li_line_base = byte_get (hdrptr, 1);
2614 hdrptr++;
2615 linfo.li_line_range = byte_get (hdrptr, 1);
2616 hdrptr++;
2617 linfo.li_opcode_base = byte_get (hdrptr, 1);
2618 hdrptr++;
2620 /* Sign extend the line base field. */
2621 linfo.li_line_base <<= 24;
2622 linfo.li_line_base >>= 24;
2624 /* Find the end of this CU's Line Number Information Block. */
2625 end_of_sequence = data + linfo.li_length + initial_length_size;
2627 reset_state_machine (linfo.li_default_is_stmt);
2629 /* Save a pointer to the contents of the Opcodes table. */
2630 standard_opcodes = hdrptr;
2632 /* Traverse the Directory table just to count entries. */
2633 data = standard_opcodes + linfo.li_opcode_base - 1;
2634 if (*data != 0)
2636 unsigned int n_directories = 0;
2637 unsigned char *ptr_directory_table = data;
2639 while (*data != 0)
2641 data += strlen ((char *) data) + 1;
2642 n_directories++;
2645 /* Go through the directory table again to save the directories. */
2646 directory_table = (unsigned char **)
2647 xmalloc (n_directories * sizeof (unsigned char *));
2649 i = 0;
2650 while (*ptr_directory_table != 0)
2652 directory_table[i] = ptr_directory_table;
2653 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2654 i++;
2657 /* Skip the NUL at the end of the table. */
2658 data++;
2660 /* Traverse the File Name table just to count the entries. */
2661 if (*data != 0)
2663 unsigned int n_files = 0;
2664 unsigned char *ptr_file_name_table = data;
2666 while (*data != 0)
2668 unsigned int bytes_read;
2670 /* Skip Name, directory index, last modification time and length
2671 of file. */
2672 data += strlen ((char *) data) + 1;
2673 read_leb128 (data, & bytes_read, 0);
2674 data += bytes_read;
2675 read_leb128 (data, & bytes_read, 0);
2676 data += bytes_read;
2677 read_leb128 (data, & bytes_read, 0);
2678 data += bytes_read;
2680 n_files++;
2683 /* Go through the file table again to save the strings. */
2684 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2686 i = 0;
2687 while (*ptr_file_name_table != 0)
2689 unsigned int bytes_read;
2691 file_table[i].name = ptr_file_name_table;
2692 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2694 /* We are not interested in directory, time or size. */
2695 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2696 & bytes_read, 0);
2697 ptr_file_name_table += bytes_read;
2698 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2699 & bytes_read, 0);
2700 ptr_file_name_table += bytes_read;
2701 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2702 ptr_file_name_table += bytes_read;
2703 i++;
2705 i = 0;
2707 /* Print the Compilation Unit's name and a header. */
2708 if (directory_table == NULL)
2710 printf (_("CU: %s:\n"), file_table[0].name);
2711 printf (_("File name Line number Starting address\n"));
2713 else
2715 if (do_wide || strlen ((char *) directory_table[0]) < 76)
2716 printf (_("CU: %s/%s:\n"), directory_table[0],
2717 file_table[0].name);
2718 else
2719 printf ("%s:\n", file_table[0].name);
2721 printf (_("File name Line number Starting address\n"));
2725 /* Skip the NUL at the end of the table. */
2726 data++;
2728 /* This loop iterates through the Dwarf Line Number Program. */
2729 while (data < end_of_sequence)
2731 unsigned char op_code;
2732 int adv;
2733 unsigned long int uladv;
2734 unsigned int bytes_read;
2735 int is_special_opcode = 0;
2737 op_code = *data++;
2739 if (op_code >= linfo.li_opcode_base)
2741 op_code -= linfo.li_opcode_base;
2742 uladv = (op_code / linfo.li_line_range);
2743 if (linfo.li_max_ops_per_insn == 1)
2745 uladv *= linfo.li_min_insn_length;
2746 state_machine_regs.address += uladv;
2748 else
2750 state_machine_regs.address
2751 += ((state_machine_regs.op_index + uladv)
2752 / linfo.li_max_ops_per_insn)
2753 * linfo.li_min_insn_length;
2754 state_machine_regs.op_index
2755 = (state_machine_regs.op_index + uladv)
2756 % linfo.li_max_ops_per_insn;
2759 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2760 state_machine_regs.line += adv;
2761 is_special_opcode = 1;
2763 else switch (op_code)
2765 case DW_LNS_extended_op:
2767 unsigned int ext_op_code_len;
2768 unsigned char ext_op_code;
2769 unsigned char *op_code_data = data;
2771 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
2772 op_code_data += bytes_read;
2774 if (ext_op_code_len == 0)
2776 warn (_("badly formed extended line op encountered!\n"));
2777 break;
2779 ext_op_code_len += bytes_read;
2780 ext_op_code = *op_code_data++;
2782 switch (ext_op_code)
2784 case DW_LNE_end_sequence:
2785 reset_state_machine (linfo.li_default_is_stmt);
2786 break;
2787 case DW_LNE_set_address:
2788 state_machine_regs.address =
2789 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
2790 state_machine_regs.op_index = 0;
2791 break;
2792 case DW_LNE_define_file:
2794 unsigned int dir_index = 0;
2796 ++state_machine_regs.last_file_entry;
2797 op_code_data += strlen ((char *) op_code_data) + 1;
2798 dir_index = read_leb128 (op_code_data, & bytes_read, 0);
2799 op_code_data += bytes_read;
2800 read_leb128 (op_code_data, & bytes_read, 0);
2801 op_code_data += bytes_read;
2802 read_leb128 (op_code_data, & bytes_read, 0);
2804 printf ("%s:\n", directory_table[dir_index]);
2805 break;
2807 default:
2808 printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
2809 break;
2811 data += ext_op_code_len;
2812 break;
2814 case DW_LNS_copy:
2815 break;
2817 case DW_LNS_advance_pc:
2818 uladv = read_leb128 (data, & bytes_read, 0);
2819 data += bytes_read;
2820 if (linfo.li_max_ops_per_insn == 1)
2822 uladv *= linfo.li_min_insn_length;
2823 state_machine_regs.address += uladv;
2825 else
2827 state_machine_regs.address
2828 += ((state_machine_regs.op_index + uladv)
2829 / linfo.li_max_ops_per_insn)
2830 * linfo.li_min_insn_length;
2831 state_machine_regs.op_index
2832 = (state_machine_regs.op_index + uladv)
2833 % linfo.li_max_ops_per_insn;
2835 break;
2837 case DW_LNS_advance_line:
2838 adv = read_leb128 (data, & bytes_read, 1);
2839 data += bytes_read;
2840 state_machine_regs.line += adv;
2841 break;
2843 case DW_LNS_set_file:
2844 adv = read_leb128 (data, & bytes_read, 0);
2845 data += bytes_read;
2846 state_machine_regs.file = adv;
2847 if (file_table[state_machine_regs.file - 1].directory_index == 0)
2849 /* If directory index is 0, that means current directory. */
2850 printf ("\n./%s:[++]\n",
2851 file_table[state_machine_regs.file - 1].name);
2853 else
2855 /* The directory index starts counting at 1. */
2856 printf ("\n%s/%s:\n",
2857 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
2858 file_table[state_machine_regs.file - 1].name);
2860 break;
2862 case DW_LNS_set_column:
2863 uladv = read_leb128 (data, & bytes_read, 0);
2864 data += bytes_read;
2865 state_machine_regs.column = uladv;
2866 break;
2868 case DW_LNS_negate_stmt:
2869 adv = state_machine_regs.is_stmt;
2870 adv = ! adv;
2871 state_machine_regs.is_stmt = adv;
2872 break;
2874 case DW_LNS_set_basic_block:
2875 state_machine_regs.basic_block = 1;
2876 break;
2878 case DW_LNS_const_add_pc:
2879 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2880 if (linfo.li_max_ops_per_insn == 1)
2882 uladv *= linfo.li_min_insn_length;
2883 state_machine_regs.address += uladv;
2885 else
2887 state_machine_regs.address
2888 += ((state_machine_regs.op_index + uladv)
2889 / linfo.li_max_ops_per_insn)
2890 * linfo.li_min_insn_length;
2891 state_machine_regs.op_index
2892 = (state_machine_regs.op_index + uladv)
2893 % linfo.li_max_ops_per_insn;
2895 break;
2897 case DW_LNS_fixed_advance_pc:
2898 uladv = byte_get (data, 2);
2899 data += 2;
2900 state_machine_regs.address += uladv;
2901 state_machine_regs.op_index = 0;
2902 break;
2904 case DW_LNS_set_prologue_end:
2905 break;
2907 case DW_LNS_set_epilogue_begin:
2908 break;
2910 case DW_LNS_set_isa:
2911 uladv = read_leb128 (data, & bytes_read, 0);
2912 data += bytes_read;
2913 printf (_(" Set ISA to %lu\n"), uladv);
2914 break;
2916 default:
2917 printf (_(" Unknown opcode %d with operands: "), op_code);
2919 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2921 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
2922 i == 1 ? "" : ", ");
2923 data += bytes_read;
2925 putchar ('\n');
2926 break;
2929 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2930 to the DWARF address/line matrix. */
2931 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
2932 || (op_code == DW_LNS_copy))
2934 const unsigned int MAX_FILENAME_LENGTH = 35;
2935 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
2936 char *newFileName = NULL;
2937 size_t fileNameLength = strlen (fileName);
2939 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
2941 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
2942 /* Truncate file name */
2943 strncpy (newFileName,
2944 fileName + fileNameLength - MAX_FILENAME_LENGTH,
2945 MAX_FILENAME_LENGTH + 1);
2947 else
2949 newFileName = (char *) xmalloc (fileNameLength + 1);
2950 strncpy (newFileName, fileName, fileNameLength + 1);
2953 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
2955 if (linfo.li_max_ops_per_insn == 1)
2956 printf ("%-35s %11d %#18lx\n", newFileName,
2957 state_machine_regs.line,
2958 state_machine_regs.address);
2959 else
2960 printf ("%-35s %11d %#18lx[%d]\n", newFileName,
2961 state_machine_regs.line,
2962 state_machine_regs.address,
2963 state_machine_regs.op_index);
2965 else
2967 if (linfo.li_max_ops_per_insn == 1)
2968 printf ("%s %11d %#18lx\n", newFileName,
2969 state_machine_regs.line,
2970 state_machine_regs.address);
2971 else
2972 printf ("%s %11d %#18lx[%d]\n", newFileName,
2973 state_machine_regs.line,
2974 state_machine_regs.address,
2975 state_machine_regs.op_index);
2978 if (op_code == DW_LNE_end_sequence)
2979 printf ("\n");
2981 free (newFileName);
2984 free (file_table);
2985 file_table = NULL;
2986 free (directory_table);
2987 directory_table = NULL;
2988 putchar ('\n');
2991 return 1;
2994 static int
2995 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
2997 unsigned char *data = section->start;
2998 unsigned char *end = data + section->size;
2999 int retValRaw = 1;
3000 int retValDecoded = 1;
3002 if (do_debug_lines == 0)
3003 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3005 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3006 retValRaw = display_debug_lines_raw (section, data, end);
3008 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3009 retValDecoded = display_debug_lines_decoded (section, data, end);
3011 if (!retValRaw || !retValDecoded)
3012 return 0;
3014 return 1;
3017 static debug_info *
3018 find_debug_info_for_offset (unsigned long offset)
3020 unsigned int i;
3022 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3023 return NULL;
3025 for (i = 0; i < num_debug_info_entries; i++)
3026 if (debug_information[i].cu_offset == offset)
3027 return debug_information + i;
3029 return NULL;
3032 static int
3033 display_debug_pubnames (struct dwarf_section *section,
3034 void *file ATTRIBUTE_UNUSED)
3036 DWARF2_Internal_PubNames names;
3037 unsigned char *start = section->start;
3038 unsigned char *end = start + section->size;
3040 /* It does not matter if this load fails,
3041 we test for that later on. */
3042 load_debug_info (file);
3044 printf (_("Contents of the %s section:\n\n"), section->name);
3046 while (start < end)
3048 unsigned char *data;
3049 unsigned long offset;
3050 int offset_size, initial_length_size;
3052 data = start;
3054 names.pn_length = byte_get (data, 4);
3055 data += 4;
3056 if (names.pn_length == 0xffffffff)
3058 names.pn_length = byte_get (data, 8);
3059 data += 8;
3060 offset_size = 8;
3061 initial_length_size = 12;
3063 else
3065 offset_size = 4;
3066 initial_length_size = 4;
3069 names.pn_version = byte_get (data, 2);
3070 data += 2;
3072 names.pn_offset = byte_get (data, offset_size);
3073 data += offset_size;
3075 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3076 && num_debug_info_entries > 0
3077 && find_debug_info_for_offset (names.pn_offset) == NULL)
3078 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3079 names.pn_offset, section->name);
3081 names.pn_size = byte_get (data, offset_size);
3082 data += offset_size;
3084 start += names.pn_length + initial_length_size;
3086 if (names.pn_version != 2 && names.pn_version != 3)
3088 static int warned = 0;
3090 if (! warned)
3092 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3093 warned = 1;
3096 continue;
3099 printf (_(" Length: %ld\n"),
3100 names.pn_length);
3101 printf (_(" Version: %d\n"),
3102 names.pn_version);
3103 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3104 names.pn_offset);
3105 printf (_(" Size of area in .debug_info section: %ld\n"),
3106 names.pn_size);
3108 printf (_("\n Offset\tName\n"));
3112 offset = byte_get (data, offset_size);
3114 if (offset != 0)
3116 data += offset_size;
3117 printf (" %-6lx\t%s\n", offset, data);
3118 data += strlen ((char *) data) + 1;
3121 while (offset != 0);
3124 printf ("\n");
3125 return 1;
3128 static int
3129 display_debug_macinfo (struct dwarf_section *section,
3130 void *file ATTRIBUTE_UNUSED)
3132 unsigned char *start = section->start;
3133 unsigned char *end = start + section->size;
3134 unsigned char *curr = start;
3135 unsigned int bytes_read;
3136 enum dwarf_macinfo_record_type op;
3138 printf (_("Contents of the %s section:\n\n"), section->name);
3140 while (curr < end)
3142 unsigned int lineno;
3143 const char *string;
3145 op = (enum dwarf_macinfo_record_type) *curr;
3146 curr++;
3148 switch (op)
3150 case DW_MACINFO_start_file:
3152 unsigned int filenum;
3154 lineno = read_leb128 (curr, & bytes_read, 0);
3155 curr += bytes_read;
3156 filenum = read_leb128 (curr, & bytes_read, 0);
3157 curr += bytes_read;
3159 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3160 lineno, filenum);
3162 break;
3164 case DW_MACINFO_end_file:
3165 printf (_(" DW_MACINFO_end_file\n"));
3166 break;
3168 case DW_MACINFO_define:
3169 lineno = read_leb128 (curr, & bytes_read, 0);
3170 curr += bytes_read;
3171 string = (char *) curr;
3172 curr += strlen (string) + 1;
3173 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3174 lineno, string);
3175 break;
3177 case DW_MACINFO_undef:
3178 lineno = read_leb128 (curr, & bytes_read, 0);
3179 curr += bytes_read;
3180 string = (char *) curr;
3181 curr += strlen (string) + 1;
3182 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3183 lineno, string);
3184 break;
3186 case DW_MACINFO_vendor_ext:
3188 unsigned int constant;
3190 constant = read_leb128 (curr, & bytes_read, 0);
3191 curr += bytes_read;
3192 string = (char *) curr;
3193 curr += strlen (string) + 1;
3194 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3195 constant, string);
3197 break;
3201 return 1;
3204 static int
3205 display_debug_abbrev (struct dwarf_section *section,
3206 void *file ATTRIBUTE_UNUSED)
3208 abbrev_entry *entry;
3209 unsigned char *start = section->start;
3210 unsigned char *end = start + section->size;
3212 printf (_("Contents of the %s section:\n\n"), section->name);
3216 free_abbrevs ();
3218 start = process_abbrev_section (start, end);
3220 if (first_abbrev == NULL)
3221 continue;
3223 printf (_(" Number TAG\n"));
3225 for (entry = first_abbrev; entry; entry = entry->next)
3227 abbrev_attr *attr;
3229 printf (" %ld %s [%s]\n",
3230 entry->entry,
3231 get_TAG_name (entry->tag),
3232 entry->children ? _("has children") : _("no children"));
3234 for (attr = entry->first_attr; attr; attr = attr->next)
3235 printf (" %-18s %s\n",
3236 get_AT_name (attr->attribute),
3237 get_FORM_name (attr->form));
3240 while (start);
3242 printf ("\n");
3244 return 1;
3247 static int
3248 display_debug_loc (struct dwarf_section *section, void *file)
3250 unsigned char *start = section->start;
3251 unsigned char *section_end;
3252 unsigned long bytes;
3253 unsigned char *section_begin = start;
3254 unsigned int num_loc_list = 0;
3255 unsigned long last_offset = 0;
3256 unsigned int first = 0;
3257 unsigned int i;
3258 unsigned int j;
3259 int seen_first_offset = 0;
3260 int use_debug_info = 1;
3261 unsigned char *next;
3263 bytes = section->size;
3264 section_end = start + bytes;
3266 if (bytes == 0)
3268 printf (_("\nThe %s section is empty.\n"), section->name);
3269 return 0;
3272 if (load_debug_info (file) == 0)
3274 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3275 section->name);
3276 return 0;
3279 /* Check the order of location list in .debug_info section. If
3280 offsets of location lists are in the ascending order, we can
3281 use `debug_information' directly. */
3282 for (i = 0; i < num_debug_info_entries; i++)
3284 unsigned int num;
3286 num = debug_information [i].num_loc_offsets;
3287 num_loc_list += num;
3289 /* Check if we can use `debug_information' directly. */
3290 if (use_debug_info && num != 0)
3292 if (!seen_first_offset)
3294 /* This is the first location list. */
3295 last_offset = debug_information [i].loc_offsets [0];
3296 first = i;
3297 seen_first_offset = 1;
3298 j = 1;
3300 else
3301 j = 0;
3303 for (; j < num; j++)
3305 if (last_offset >
3306 debug_information [i].loc_offsets [j])
3308 use_debug_info = 0;
3309 break;
3311 last_offset = debug_information [i].loc_offsets [j];
3316 if (!use_debug_info)
3317 /* FIXME: Should we handle this case? */
3318 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3320 if (!seen_first_offset)
3321 error (_("No location lists in .debug_info section!\n"));
3323 /* DWARF sections under Mach-O have non-zero addresses. */
3324 if (debug_information [first].num_loc_offsets > 0
3325 && debug_information [first].loc_offsets [0] != section->address)
3326 warn (_("Location lists in %s section start at 0x%lx\n"),
3327 section->name, debug_information [first].loc_offsets [0]);
3329 printf (_("Contents of the %s section:\n\n"), section->name);
3330 printf (_(" Offset Begin End Expression\n"));
3332 seen_first_offset = 0;
3333 for (i = first; i < num_debug_info_entries; i++)
3335 dwarf_vma begin;
3336 dwarf_vma end;
3337 unsigned short length;
3338 unsigned long offset;
3339 unsigned int pointer_size;
3340 unsigned int offset_size;
3341 int dwarf_version;
3342 unsigned long cu_offset;
3343 unsigned long base_address;
3344 int need_frame_base;
3345 int has_frame_base;
3347 pointer_size = debug_information [i].pointer_size;
3348 cu_offset = debug_information [i].cu_offset;
3349 offset_size = debug_information [i].offset_size;
3350 dwarf_version = debug_information [i].dwarf_version;
3352 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
3354 has_frame_base = debug_information [i].have_frame_base [j];
3355 /* DWARF sections under Mach-O have non-zero addresses. */
3356 offset = debug_information [i].loc_offsets [j] - section->address;
3357 next = section_begin + offset;
3358 base_address = debug_information [i].base_address;
3360 if (!seen_first_offset)
3361 seen_first_offset = 1;
3362 else
3364 if (start < next)
3365 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3366 (unsigned long) (start - section_begin),
3367 (unsigned long) (next - section_begin));
3368 else if (start > next)
3369 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3370 (unsigned long) (start - section_begin),
3371 (unsigned long) (next - section_begin));
3373 start = next;
3375 if (offset >= bytes)
3377 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3378 offset);
3379 continue;
3382 while (1)
3384 if (start + 2 * pointer_size > section_end)
3386 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3387 offset);
3388 break;
3391 /* Note: we use sign extension here in order to be sure that
3392 we can detect the -1 escape value. Sign extension into the
3393 top 32 bits of a 32-bit address will not affect the values
3394 that we display since we always show hex values, and always
3395 the bottom 32-bits. */
3396 begin = byte_get_signed (start, pointer_size);
3397 start += pointer_size;
3398 end = byte_get_signed (start, pointer_size);
3399 start += pointer_size;
3401 printf (" %8.8lx ", offset);
3403 if (begin == 0 && end == 0)
3405 printf (_("<End of list>\n"));
3406 break;
3409 /* Check base address specifiers. */
3410 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3412 base_address = end;
3413 print_dwarf_vma (begin, pointer_size);
3414 print_dwarf_vma (end, pointer_size);
3415 printf (_("(base address)\n"));
3416 continue;
3419 if (start + 2 > section_end)
3421 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3422 offset);
3423 break;
3426 length = byte_get (start, 2);
3427 start += 2;
3429 if (start + length > section_end)
3431 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3432 offset);
3433 break;
3436 print_dwarf_vma (begin + base_address, pointer_size);
3437 print_dwarf_vma (end + base_address, pointer_size);
3439 putchar ('(');
3440 need_frame_base = decode_location_expression (start,
3441 pointer_size,
3442 offset_size,
3443 dwarf_version,
3444 length,
3445 cu_offset, section);
3446 putchar (')');
3448 if (need_frame_base && !has_frame_base)
3449 printf (_(" [without DW_AT_frame_base]"));
3451 if (begin == end)
3452 fputs (_(" (start == end)"), stdout);
3453 else if (begin > end)
3454 fputs (_(" (start > end)"), stdout);
3456 putchar ('\n');
3458 start += length;
3463 if (start < section_end)
3464 warn (_("There are %ld unused bytes at the end of section %s\n"),
3465 (long) (section_end - start), section->name);
3466 putchar ('\n');
3467 return 1;
3470 static int
3471 display_debug_str (struct dwarf_section *section,
3472 void *file ATTRIBUTE_UNUSED)
3474 unsigned char *start = section->start;
3475 unsigned long bytes = section->size;
3476 dwarf_vma addr = section->address;
3478 if (bytes == 0)
3480 printf (_("\nThe %s section is empty.\n"), section->name);
3481 return 0;
3484 printf (_("Contents of the %s section:\n\n"), section->name);
3486 while (bytes)
3488 int j;
3489 int k;
3490 int lbytes;
3492 lbytes = (bytes > 16 ? 16 : bytes);
3494 printf (" 0x%8.8lx ", (unsigned long) addr);
3496 for (j = 0; j < 16; j++)
3498 if (j < lbytes)
3499 printf ("%2.2x", start[j]);
3500 else
3501 printf (" ");
3503 if ((j & 3) == 3)
3504 printf (" ");
3507 for (j = 0; j < lbytes; j++)
3509 k = start[j];
3510 if (k >= ' ' && k < 0x80)
3511 printf ("%c", k);
3512 else
3513 printf (".");
3516 putchar ('\n');
3518 start += lbytes;
3519 addr += lbytes;
3520 bytes -= lbytes;
3523 putchar ('\n');
3525 return 1;
3528 static int
3529 display_debug_info (struct dwarf_section *section, void *file)
3531 return process_debug_info (section, file, abbrev, 0, 0);
3534 static int
3535 display_debug_types (struct dwarf_section *section, void *file)
3537 return process_debug_info (section, file, abbrev, 0, 1);
3540 static int
3541 display_trace_info (struct dwarf_section *section, void *file)
3543 return process_debug_info (section, file, trace_abbrev, 0, 0);
3546 static int
3547 display_debug_aranges (struct dwarf_section *section,
3548 void *file ATTRIBUTE_UNUSED)
3550 unsigned char *start = section->start;
3551 unsigned char *end = start + section->size;
3553 printf (_("Contents of the %s section:\n\n"), section->name);
3555 /* It does not matter if this load fails,
3556 we test for that later on. */
3557 load_debug_info (file);
3559 while (start < end)
3561 unsigned char *hdrptr;
3562 DWARF2_Internal_ARange arange;
3563 unsigned char *addr_ranges;
3564 dwarf_vma length;
3565 dwarf_vma address;
3566 unsigned char address_size;
3567 int excess;
3568 int offset_size;
3569 int initial_length_size;
3571 hdrptr = start;
3573 arange.ar_length = byte_get (hdrptr, 4);
3574 hdrptr += 4;
3576 if (arange.ar_length == 0xffffffff)
3578 arange.ar_length = byte_get (hdrptr, 8);
3579 hdrptr += 8;
3580 offset_size = 8;
3581 initial_length_size = 12;
3583 else
3585 offset_size = 4;
3586 initial_length_size = 4;
3589 arange.ar_version = byte_get (hdrptr, 2);
3590 hdrptr += 2;
3592 arange.ar_info_offset = byte_get (hdrptr, offset_size);
3593 hdrptr += offset_size;
3595 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3596 && num_debug_info_entries > 0
3597 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
3598 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3599 arange.ar_info_offset, section->name);
3601 arange.ar_pointer_size = byte_get (hdrptr, 1);
3602 hdrptr += 1;
3604 arange.ar_segment_size = byte_get (hdrptr, 1);
3605 hdrptr += 1;
3607 if (arange.ar_version != 2 && arange.ar_version != 3)
3609 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3610 break;
3613 printf (_(" Length: %ld\n"), arange.ar_length);
3614 printf (_(" Version: %d\n"), arange.ar_version);
3615 printf (_(" Offset into .debug_info: 0x%lx\n"), arange.ar_info_offset);
3616 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
3617 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
3619 address_size = arange.ar_pointer_size + arange.ar_segment_size;
3621 /* The DWARF spec does not require that the address size be a power
3622 of two, but we do. This will have to change if we ever encounter
3623 an uneven architecture. */
3624 if ((address_size & (address_size - 1)) != 0)
3626 warn (_("Pointer size + Segment size is not a power of two.\n"));
3627 break;
3630 if (address_size > 4)
3631 printf (_("\n Address Length\n"));
3632 else
3633 printf (_("\n Address Length\n"));
3635 addr_ranges = hdrptr;
3637 /* Must pad to an alignment boundary that is twice the address size. */
3638 excess = (hdrptr - start) % (2 * address_size);
3639 if (excess)
3640 addr_ranges += (2 * address_size) - excess;
3642 start += arange.ar_length + initial_length_size;
3644 while (addr_ranges + 2 * address_size <= start)
3646 address = byte_get (addr_ranges, address_size);
3648 addr_ranges += address_size;
3650 length = byte_get (addr_ranges, address_size);
3652 addr_ranges += address_size;
3654 printf (" ");
3655 print_dwarf_vma (address, address_size);
3656 print_dwarf_vma (length, address_size);
3657 putchar ('\n');
3661 printf ("\n");
3663 return 1;
3666 /* Each debug_information[x].range_lists[y] gets this representation for
3667 sorting purposes. */
3669 struct range_entry
3671 /* The debug_information[x].range_lists[y] value. */
3672 unsigned long ranges_offset;
3674 /* Original debug_information to find parameters of the data. */
3675 debug_info *debug_info_p;
3678 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3680 static int
3681 range_entry_compar (const void *ap, const void *bp)
3683 const struct range_entry *a_re = (const struct range_entry *) ap;
3684 const struct range_entry *b_re = (const struct range_entry *) bp;
3685 const unsigned long a = a_re->ranges_offset;
3686 const unsigned long b = b_re->ranges_offset;
3688 return (a > b) - (b > a);
3691 static int
3692 display_debug_ranges (struct dwarf_section *section,
3693 void *file ATTRIBUTE_UNUSED)
3695 unsigned char *start = section->start;
3696 unsigned long bytes;
3697 unsigned char *section_begin = start;
3698 unsigned int num_range_list, i;
3699 struct range_entry *range_entries, *range_entry_fill;
3701 bytes = section->size;
3703 if (bytes == 0)
3705 printf (_("\nThe %s section is empty.\n"), section->name);
3706 return 0;
3709 if (load_debug_info (file) == 0)
3711 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3712 section->name);
3713 return 0;
3716 num_range_list = 0;
3717 for (i = 0; i < num_debug_info_entries; i++)
3718 num_range_list += debug_information [i].num_range_lists;
3720 if (num_range_list == 0)
3721 error (_("No range lists in .debug_info section!\n"));
3723 range_entries = (struct range_entry *)
3724 xmalloc (sizeof (*range_entries) * num_range_list);
3725 range_entry_fill = range_entries;
3727 for (i = 0; i < num_debug_info_entries; i++)
3729 debug_info *debug_info_p = &debug_information[i];
3730 unsigned int j;
3732 for (j = 0; j < debug_info_p->num_range_lists; j++)
3734 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
3735 range_entry_fill->debug_info_p = debug_info_p;
3736 range_entry_fill++;
3740 qsort (range_entries, num_range_list, sizeof (*range_entries),
3741 range_entry_compar);
3743 /* DWARF sections under Mach-O have non-zero addresses. */
3744 if (range_entries[0].ranges_offset != section->address)
3745 warn (_("Range lists in %s section start at 0x%lx\n"),
3746 section->name, range_entries[0].ranges_offset);
3748 printf (_("Contents of the %s section:\n\n"), section->name);
3749 printf (_(" Offset Begin End\n"));
3751 for (i = 0; i < num_range_list; i++)
3753 struct range_entry *range_entry = &range_entries[i];
3754 debug_info *debug_info_p = range_entry->debug_info_p;
3755 unsigned int pointer_size;
3756 unsigned long offset;
3757 unsigned char *next;
3758 unsigned long base_address;
3760 pointer_size = debug_info_p->pointer_size;
3762 /* DWARF sections under Mach-O have non-zero addresses. */
3763 offset = range_entry->ranges_offset - section->address;
3764 next = section_begin + offset;
3765 base_address = debug_info_p->base_address;
3767 if (i > 0)
3769 if (start < next)
3770 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3771 (unsigned long) (start - section_begin),
3772 (unsigned long) (next - section_begin), section->name);
3773 else if (start > next)
3774 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3775 (unsigned long) (start - section_begin),
3776 (unsigned long) (next - section_begin), section->name);
3778 start = next;
3780 while (1)
3782 dwarf_vma begin;
3783 dwarf_vma end;
3785 /* Note: we use sign extension here in order to be sure that
3786 we can detect the -1 escape value. Sign extension into the
3787 top 32 bits of a 32-bit address will not affect the values
3788 that we display since we always show hex values, and always
3789 the bottom 32-bits. */
3790 begin = byte_get_signed (start, pointer_size);
3791 start += pointer_size;
3792 end = byte_get_signed (start, pointer_size);
3793 start += pointer_size;
3795 printf (" %8.8lx ", offset);
3797 if (begin == 0 && end == 0)
3799 printf (_("<End of list>\n"));
3800 break;
3803 /* Check base address specifiers. */
3804 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3806 base_address = end;
3807 print_dwarf_vma (begin, pointer_size);
3808 print_dwarf_vma (end, pointer_size);
3809 printf ("(base address)\n");
3810 continue;
3813 print_dwarf_vma (begin + base_address, pointer_size);
3814 print_dwarf_vma (end + base_address, pointer_size);
3816 if (begin == end)
3817 fputs (_("(start == end)"), stdout);
3818 else if (begin > end)
3819 fputs (_("(start > end)"), stdout);
3821 putchar ('\n');
3824 putchar ('\n');
3826 free (range_entries);
3828 return 1;
3831 typedef struct Frame_Chunk
3833 struct Frame_Chunk *next;
3834 unsigned char *chunk_start;
3835 int ncols;
3836 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3837 short int *col_type;
3838 int *col_offset;
3839 char *augmentation;
3840 unsigned int code_factor;
3841 int data_factor;
3842 unsigned long pc_begin;
3843 unsigned long pc_range;
3844 int cfa_reg;
3845 int cfa_offset;
3846 int ra;
3847 unsigned char fde_encoding;
3848 unsigned char cfa_exp;
3849 unsigned char ptr_size;
3850 unsigned char segment_size;
3852 Frame_Chunk;
3854 static const char *const *dwarf_regnames;
3855 static unsigned int dwarf_regnames_count;
3857 /* A marker for a col_type that means this column was never referenced
3858 in the frame info. */
3859 #define DW_CFA_unreferenced (-1)
3861 /* Return 0 if not more space is needed, 1 if more space is needed,
3862 -1 for invalid reg. */
3864 static int
3865 frame_need_space (Frame_Chunk *fc, unsigned int reg)
3867 int prev = fc->ncols;
3869 if (reg < (unsigned int) fc->ncols)
3870 return 0;
3872 if (dwarf_regnames_count
3873 && reg > dwarf_regnames_count)
3874 return -1;
3876 fc->ncols = reg + 1;
3877 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
3878 sizeof (short int));
3879 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
3881 while (prev < fc->ncols)
3883 fc->col_type[prev] = DW_CFA_unreferenced;
3884 fc->col_offset[prev] = 0;
3885 prev++;
3887 return 1;
3890 static const char *const dwarf_regnames_i386[] =
3892 "eax", "ecx", "edx", "ebx",
3893 "esp", "ebp", "esi", "edi",
3894 "eip", "eflags", NULL,
3895 "st0", "st1", "st2", "st3",
3896 "st4", "st5", "st6", "st7",
3897 NULL, NULL,
3898 "xmm0", "xmm1", "xmm2", "xmm3",
3899 "xmm4", "xmm5", "xmm6", "xmm7",
3900 "mm0", "mm1", "mm2", "mm3",
3901 "mm4", "mm5", "mm6", "mm7",
3902 "fcw", "fsw", "mxcsr",
3903 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3904 "tr", "ldtr"
3907 void
3908 init_dwarf_regnames_i386 (void)
3910 dwarf_regnames = dwarf_regnames_i386;
3911 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
3914 static const char *const dwarf_regnames_x86_64[] =
3916 "rax", "rdx", "rcx", "rbx",
3917 "rsi", "rdi", "rbp", "rsp",
3918 "r8", "r9", "r10", "r11",
3919 "r12", "r13", "r14", "r15",
3920 "rip",
3921 "xmm0", "xmm1", "xmm2", "xmm3",
3922 "xmm4", "xmm5", "xmm6", "xmm7",
3923 "xmm8", "xmm9", "xmm10", "xmm11",
3924 "xmm12", "xmm13", "xmm14", "xmm15",
3925 "st0", "st1", "st2", "st3",
3926 "st4", "st5", "st6", "st7",
3927 "mm0", "mm1", "mm2", "mm3",
3928 "mm4", "mm5", "mm6", "mm7",
3929 "rflags",
3930 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3931 "fs.base", "gs.base", NULL, NULL,
3932 "tr", "ldtr",
3933 "mxcsr", "fcw", "fsw"
3936 void
3937 init_dwarf_regnames_x86_64 (void)
3939 dwarf_regnames = dwarf_regnames_x86_64;
3940 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
3943 void
3944 init_dwarf_regnames (unsigned int e_machine)
3946 switch (e_machine)
3948 case EM_386:
3949 case EM_486:
3950 init_dwarf_regnames_i386 ();
3951 break;
3953 case EM_X86_64:
3954 case EM_L1OM:
3955 init_dwarf_regnames_x86_64 ();
3956 break;
3958 default:
3959 break;
3963 static const char *
3964 regname (unsigned int regno, int row)
3966 static char reg[64];
3967 if (dwarf_regnames
3968 && regno < dwarf_regnames_count
3969 && dwarf_regnames [regno] != NULL)
3971 if (row)
3972 return dwarf_regnames [regno];
3973 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
3974 dwarf_regnames [regno]);
3976 else
3977 snprintf (reg, sizeof (reg), "r%d", regno);
3978 return reg;
3981 static void
3982 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
3984 int r;
3985 char tmp[100];
3987 if (*max_regs < fc->ncols)
3988 *max_regs = fc->ncols;
3990 if (*need_col_headers)
3992 static const char *sloc = " LOC";
3994 *need_col_headers = 0;
3996 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
3998 for (r = 0; r < *max_regs; r++)
3999 if (fc->col_type[r] != DW_CFA_unreferenced)
4001 if (r == fc->ra)
4002 printf ("ra ");
4003 else
4004 printf ("%-5s ", regname (r, 1));
4007 printf ("\n");
4010 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4011 if (fc->cfa_exp)
4012 strcpy (tmp, "exp");
4013 else
4014 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4015 printf ("%-8s ", tmp);
4017 for (r = 0; r < fc->ncols; r++)
4019 if (fc->col_type[r] != DW_CFA_unreferenced)
4021 switch (fc->col_type[r])
4023 case DW_CFA_undefined:
4024 strcpy (tmp, "u");
4025 break;
4026 case DW_CFA_same_value:
4027 strcpy (tmp, "s");
4028 break;
4029 case DW_CFA_offset:
4030 sprintf (tmp, "c%+d", fc->col_offset[r]);
4031 break;
4032 case DW_CFA_val_offset:
4033 sprintf (tmp, "v%+d", fc->col_offset[r]);
4034 break;
4035 case DW_CFA_register:
4036 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4037 break;
4038 case DW_CFA_expression:
4039 strcpy (tmp, "exp");
4040 break;
4041 case DW_CFA_val_expression:
4042 strcpy (tmp, "vexp");
4043 break;
4044 default:
4045 strcpy (tmp, "n/a");
4046 break;
4048 printf ("%-5s ", tmp);
4051 printf ("\n");
4054 #define GET(N) byte_get (start, N); start += N
4055 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4056 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
4058 static int
4059 display_debug_frames (struct dwarf_section *section,
4060 void *file ATTRIBUTE_UNUSED)
4062 unsigned char *start = section->start;
4063 unsigned char *end = start + section->size;
4064 unsigned char *section_start = start;
4065 Frame_Chunk *chunks = 0;
4066 Frame_Chunk *remembered_state = 0;
4067 Frame_Chunk *rs;
4068 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4069 unsigned int length_return;
4070 int max_regs = 0;
4071 const char *bad_reg = _("bad register: ");
4072 int saved_eh_addr_size = eh_addr_size;
4074 printf (_("Contents of the %s section:\n"), section->name);
4076 while (start < end)
4078 unsigned char *saved_start;
4079 unsigned char *block_end;
4080 unsigned long length;
4081 unsigned long cie_id;
4082 Frame_Chunk *fc;
4083 Frame_Chunk *cie;
4084 int need_col_headers = 1;
4085 unsigned char *augmentation_data = NULL;
4086 unsigned long augmentation_data_len = 0;
4087 int encoded_ptr_size = saved_eh_addr_size;
4088 int offset_size;
4089 int initial_length_size;
4091 saved_start = start;
4092 length = byte_get (start, 4); start += 4;
4094 if (length == 0)
4096 printf ("\n%08lx ZERO terminator\n\n",
4097 (unsigned long)(saved_start - section_start));
4098 continue;
4101 if (length == 0xffffffff)
4103 length = byte_get (start, 8);
4104 start += 8;
4105 offset_size = 8;
4106 initial_length_size = 12;
4108 else
4110 offset_size = 4;
4111 initial_length_size = 4;
4114 block_end = saved_start + length + initial_length_size;
4115 if (block_end > end)
4117 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4118 length, (unsigned long)(saved_start - section_start));
4119 block_end = end;
4121 cie_id = byte_get (start, offset_size); start += offset_size;
4123 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4125 int version;
4127 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4128 memset (fc, 0, sizeof (Frame_Chunk));
4130 fc->next = chunks;
4131 chunks = fc;
4132 fc->chunk_start = saved_start;
4133 fc->ncols = 0;
4134 fc->col_type = (short int *) xmalloc (sizeof (short int));
4135 fc->col_offset = (int *) xmalloc (sizeof (int));
4136 frame_need_space (fc, max_regs - 1);
4138 version = *start++;
4140 fc->augmentation = (char *) start;
4141 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4143 if (strcmp (fc->augmentation, "eh") == 0)
4144 start += eh_addr_size;
4146 if (version >= 4)
4148 fc->ptr_size = GET (1);
4149 fc->segment_size = GET (1);
4150 eh_addr_size = fc->ptr_size;
4152 else
4154 fc->ptr_size = eh_addr_size;
4155 fc->segment_size = 0;
4157 fc->code_factor = LEB ();
4158 fc->data_factor = SLEB ();
4159 if (version == 1)
4161 fc->ra = GET (1);
4163 else
4165 fc->ra = LEB ();
4168 if (fc->augmentation[0] == 'z')
4170 augmentation_data_len = LEB ();
4171 augmentation_data = start;
4172 start += augmentation_data_len;
4174 cie = fc;
4176 if (do_debug_frames_interp)
4177 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4178 (unsigned long)(saved_start - section_start), length, cie_id,
4179 fc->augmentation, fc->code_factor, fc->data_factor,
4180 fc->ra);
4181 else
4183 printf ("\n%08lx %08lx %08lx CIE\n",
4184 (unsigned long)(saved_start - section_start), length, cie_id);
4185 printf (" Version: %d\n", version);
4186 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4187 if (version >= 4)
4189 printf (" Pointer Size: %u\n", fc->ptr_size);
4190 printf (" Segment Size: %u\n", fc->segment_size);
4192 printf (" Code alignment factor: %u\n", fc->code_factor);
4193 printf (" Data alignment factor: %d\n", fc->data_factor);
4194 printf (" Return address column: %d\n", fc->ra);
4196 if (augmentation_data_len)
4198 unsigned long i;
4199 printf (" Augmentation data: ");
4200 for (i = 0; i < augmentation_data_len; ++i)
4201 printf (" %02x", augmentation_data[i]);
4202 putchar ('\n');
4204 putchar ('\n');
4207 if (augmentation_data_len)
4209 unsigned char *p, *q;
4210 p = (unsigned char *) fc->augmentation + 1;
4211 q = augmentation_data;
4213 while (1)
4215 if (*p == 'L')
4216 q++;
4217 else if (*p == 'P')
4218 q += 1 + size_of_encoded_value (*q);
4219 else if (*p == 'R')
4220 fc->fde_encoding = *q++;
4221 else if (*p == 'S')
4223 else
4224 break;
4225 p++;
4228 if (fc->fde_encoding)
4229 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4232 frame_need_space (fc, fc->ra);
4234 else
4236 unsigned char *look_for;
4237 static Frame_Chunk fde_fc;
4238 unsigned long segment_selector;
4240 fc = & fde_fc;
4241 memset (fc, 0, sizeof (Frame_Chunk));
4243 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
4245 for (cie = chunks; cie ; cie = cie->next)
4246 if (cie->chunk_start == look_for)
4247 break;
4249 if (!cie)
4251 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4252 cie_id, (unsigned long)(saved_start - section_start));
4253 fc->ncols = 0;
4254 fc->col_type = (short int *) xmalloc (sizeof (short int));
4255 fc->col_offset = (int *) xmalloc (sizeof (int));
4256 frame_need_space (fc, max_regs - 1);
4257 cie = fc;
4258 fc->augmentation = "";
4259 fc->fde_encoding = 0;
4260 fc->ptr_size = eh_addr_size;
4261 fc->segment_size = 0;
4263 else
4265 fc->ncols = cie->ncols;
4266 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
4267 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
4268 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
4269 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
4270 fc->augmentation = cie->augmentation;
4271 fc->ptr_size = cie->ptr_size;
4272 eh_addr_size = cie->ptr_size;
4273 fc->segment_size = cie->segment_size;
4274 fc->code_factor = cie->code_factor;
4275 fc->data_factor = cie->data_factor;
4276 fc->cfa_reg = cie->cfa_reg;
4277 fc->cfa_offset = cie->cfa_offset;
4278 fc->ra = cie->ra;
4279 frame_need_space (fc, max_regs - 1);
4280 fc->fde_encoding = cie->fde_encoding;
4283 if (fc->fde_encoding)
4284 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4286 segment_selector = 0;
4287 if (fc->segment_size)
4289 segment_selector = byte_get (start, fc->segment_size);
4290 start += fc->segment_size;
4292 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
4293 start += encoded_ptr_size;
4294 fc->pc_range = byte_get (start, encoded_ptr_size);
4295 start += encoded_ptr_size;
4297 if (cie->augmentation[0] == 'z')
4299 augmentation_data_len = LEB ();
4300 augmentation_data = start;
4301 start += augmentation_data_len;
4304 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4305 (unsigned long)(saved_start - section_start), length, cie_id,
4306 (unsigned long)(cie->chunk_start - section_start));
4307 if (fc->segment_size)
4308 printf ("%04lx:", segment_selector);
4309 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
4310 if (! do_debug_frames_interp && augmentation_data_len)
4312 unsigned long i;
4314 printf (" Augmentation data: ");
4315 for (i = 0; i < augmentation_data_len; ++i)
4316 printf (" %02x", augmentation_data[i]);
4317 putchar ('\n');
4318 putchar ('\n');
4322 /* At this point, fc is the current chunk, cie (if any) is set, and
4323 we're about to interpret instructions for the chunk. */
4324 /* ??? At present we need to do this always, since this sizes the
4325 fc->col_type and fc->col_offset arrays, which we write into always.
4326 We should probably split the interpreted and non-interpreted bits
4327 into two different routines, since there's so much that doesn't
4328 really overlap between them. */
4329 if (1 || do_debug_frames_interp)
4331 /* Start by making a pass over the chunk, allocating storage
4332 and taking note of what registers are used. */
4333 unsigned char *tmp = start;
4335 while (start < block_end)
4337 unsigned op, opa;
4338 unsigned long reg, temp;
4340 op = *start++;
4341 opa = op & 0x3f;
4342 if (op & 0xc0)
4343 op &= 0xc0;
4345 /* Warning: if you add any more cases to this switch, be
4346 sure to add them to the corresponding switch below. */
4347 switch (op)
4349 case DW_CFA_advance_loc:
4350 break;
4351 case DW_CFA_offset:
4352 LEB ();
4353 if (frame_need_space (fc, opa) >= 0)
4354 fc->col_type[opa] = DW_CFA_undefined;
4355 break;
4356 case DW_CFA_restore:
4357 if (frame_need_space (fc, opa) >= 0)
4358 fc->col_type[opa] = DW_CFA_undefined;
4359 break;
4360 case DW_CFA_set_loc:
4361 start += encoded_ptr_size;
4362 break;
4363 case DW_CFA_advance_loc1:
4364 start += 1;
4365 break;
4366 case DW_CFA_advance_loc2:
4367 start += 2;
4368 break;
4369 case DW_CFA_advance_loc4:
4370 start += 4;
4371 break;
4372 case DW_CFA_offset_extended:
4373 case DW_CFA_val_offset:
4374 reg = LEB (); LEB ();
4375 if (frame_need_space (fc, reg) >= 0)
4376 fc->col_type[reg] = DW_CFA_undefined;
4377 break;
4378 case DW_CFA_restore_extended:
4379 reg = LEB ();
4380 frame_need_space (fc, reg);
4381 if (frame_need_space (fc, reg) >= 0)
4382 fc->col_type[reg] = DW_CFA_undefined;
4383 break;
4384 case DW_CFA_undefined:
4385 reg = LEB ();
4386 if (frame_need_space (fc, reg) >= 0)
4387 fc->col_type[reg] = DW_CFA_undefined;
4388 break;
4389 case DW_CFA_same_value:
4390 reg = LEB ();
4391 if (frame_need_space (fc, reg) >= 0)
4392 fc->col_type[reg] = DW_CFA_undefined;
4393 break;
4394 case DW_CFA_register:
4395 reg = LEB (); LEB ();
4396 if (frame_need_space (fc, reg) >= 0)
4397 fc->col_type[reg] = DW_CFA_undefined;
4398 break;
4399 case DW_CFA_def_cfa:
4400 LEB (); LEB ();
4401 break;
4402 case DW_CFA_def_cfa_register:
4403 LEB ();
4404 break;
4405 case DW_CFA_def_cfa_offset:
4406 LEB ();
4407 break;
4408 case DW_CFA_def_cfa_expression:
4409 temp = LEB ();
4410 start += temp;
4411 break;
4412 case DW_CFA_expression:
4413 case DW_CFA_val_expression:
4414 reg = LEB ();
4415 temp = LEB ();
4416 start += temp;
4417 if (frame_need_space (fc, reg) >= 0)
4418 fc->col_type[reg] = DW_CFA_undefined;
4419 break;
4420 case DW_CFA_offset_extended_sf:
4421 case DW_CFA_val_offset_sf:
4422 reg = LEB (); SLEB ();
4423 if (frame_need_space (fc, reg) >= 0)
4424 fc->col_type[reg] = DW_CFA_undefined;
4425 break;
4426 case DW_CFA_def_cfa_sf:
4427 LEB (); SLEB ();
4428 break;
4429 case DW_CFA_def_cfa_offset_sf:
4430 SLEB ();
4431 break;
4432 case DW_CFA_MIPS_advance_loc8:
4433 start += 8;
4434 break;
4435 case DW_CFA_GNU_args_size:
4436 LEB ();
4437 break;
4438 case DW_CFA_GNU_negative_offset_extended:
4439 reg = LEB (); LEB ();
4440 if (frame_need_space (fc, reg) >= 0)
4441 fc->col_type[reg] = DW_CFA_undefined;
4442 break;
4443 default:
4444 break;
4447 start = tmp;
4450 /* Now we know what registers are used, make a second pass over
4451 the chunk, this time actually printing out the info. */
4453 while (start < block_end)
4455 unsigned op, opa;
4456 unsigned long ul, reg, roffs;
4457 long l, ofs;
4458 dwarf_vma vma;
4459 const char *reg_prefix = "";
4461 op = *start++;
4462 opa = op & 0x3f;
4463 if (op & 0xc0)
4464 op &= 0xc0;
4466 /* Warning: if you add any more cases to this switch, be
4467 sure to add them to the corresponding switch above. */
4468 switch (op)
4470 case DW_CFA_advance_loc:
4471 if (do_debug_frames_interp)
4472 frame_display_row (fc, &need_col_headers, &max_regs);
4473 else
4474 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4475 opa * fc->code_factor,
4476 fc->pc_begin + opa * fc->code_factor);
4477 fc->pc_begin += opa * fc->code_factor;
4478 break;
4480 case DW_CFA_offset:
4481 roffs = LEB ();
4482 if (opa >= (unsigned int) fc->ncols)
4483 reg_prefix = bad_reg;
4484 if (! do_debug_frames_interp || *reg_prefix != '\0')
4485 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4486 reg_prefix, regname (opa, 0),
4487 roffs * fc->data_factor);
4488 if (*reg_prefix == '\0')
4490 fc->col_type[opa] = DW_CFA_offset;
4491 fc->col_offset[opa] = roffs * fc->data_factor;
4493 break;
4495 case DW_CFA_restore:
4496 if (opa >= (unsigned int) cie->ncols
4497 || opa >= (unsigned int) fc->ncols)
4498 reg_prefix = bad_reg;
4499 if (! do_debug_frames_interp || *reg_prefix != '\0')
4500 printf (" DW_CFA_restore: %s%s\n",
4501 reg_prefix, regname (opa, 0));
4502 if (*reg_prefix == '\0')
4504 fc->col_type[opa] = cie->col_type[opa];
4505 fc->col_offset[opa] = cie->col_offset[opa];
4507 break;
4509 case DW_CFA_set_loc:
4510 vma = get_encoded_value (start, fc->fde_encoding, section);
4511 start += encoded_ptr_size;
4512 if (do_debug_frames_interp)
4513 frame_display_row (fc, &need_col_headers, &max_regs);
4514 else
4515 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
4516 fc->pc_begin = vma;
4517 break;
4519 case DW_CFA_advance_loc1:
4520 ofs = byte_get (start, 1); start += 1;
4521 if (do_debug_frames_interp)
4522 frame_display_row (fc, &need_col_headers, &max_regs);
4523 else
4524 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4525 ofs * fc->code_factor,
4526 fc->pc_begin + ofs * fc->code_factor);
4527 fc->pc_begin += ofs * fc->code_factor;
4528 break;
4530 case DW_CFA_advance_loc2:
4531 ofs = byte_get (start, 2); start += 2;
4532 if (do_debug_frames_interp)
4533 frame_display_row (fc, &need_col_headers, &max_regs);
4534 else
4535 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4536 ofs * fc->code_factor,
4537 fc->pc_begin + ofs * fc->code_factor);
4538 fc->pc_begin += ofs * fc->code_factor;
4539 break;
4541 case DW_CFA_advance_loc4:
4542 ofs = byte_get (start, 4); start += 4;
4543 if (do_debug_frames_interp)
4544 frame_display_row (fc, &need_col_headers, &max_regs);
4545 else
4546 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4547 ofs * fc->code_factor,
4548 fc->pc_begin + ofs * fc->code_factor);
4549 fc->pc_begin += ofs * fc->code_factor;
4550 break;
4552 case DW_CFA_offset_extended:
4553 reg = LEB ();
4554 roffs = LEB ();
4555 if (reg >= (unsigned int) fc->ncols)
4556 reg_prefix = bad_reg;
4557 if (! do_debug_frames_interp || *reg_prefix != '\0')
4558 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4559 reg_prefix, regname (reg, 0),
4560 roffs * fc->data_factor);
4561 if (*reg_prefix == '\0')
4563 fc->col_type[reg] = DW_CFA_offset;
4564 fc->col_offset[reg] = roffs * fc->data_factor;
4566 break;
4568 case DW_CFA_val_offset:
4569 reg = LEB ();
4570 roffs = LEB ();
4571 if (reg >= (unsigned int) fc->ncols)
4572 reg_prefix = bad_reg;
4573 if (! do_debug_frames_interp || *reg_prefix != '\0')
4574 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4575 reg_prefix, regname (reg, 0),
4576 roffs * fc->data_factor);
4577 if (*reg_prefix == '\0')
4579 fc->col_type[reg] = DW_CFA_val_offset;
4580 fc->col_offset[reg] = roffs * fc->data_factor;
4582 break;
4584 case DW_CFA_restore_extended:
4585 reg = LEB ();
4586 if (reg >= (unsigned int) cie->ncols
4587 || reg >= (unsigned int) fc->ncols)
4588 reg_prefix = bad_reg;
4589 if (! do_debug_frames_interp || *reg_prefix != '\0')
4590 printf (" DW_CFA_restore_extended: %s%s\n",
4591 reg_prefix, regname (reg, 0));
4592 if (*reg_prefix == '\0')
4594 fc->col_type[reg] = cie->col_type[reg];
4595 fc->col_offset[reg] = cie->col_offset[reg];
4597 break;
4599 case DW_CFA_undefined:
4600 reg = LEB ();
4601 if (reg >= (unsigned int) fc->ncols)
4602 reg_prefix = bad_reg;
4603 if (! do_debug_frames_interp || *reg_prefix != '\0')
4604 printf (" DW_CFA_undefined: %s%s\n",
4605 reg_prefix, regname (reg, 0));
4606 if (*reg_prefix == '\0')
4608 fc->col_type[reg] = DW_CFA_undefined;
4609 fc->col_offset[reg] = 0;
4611 break;
4613 case DW_CFA_same_value:
4614 reg = LEB ();
4615 if (reg >= (unsigned int) fc->ncols)
4616 reg_prefix = bad_reg;
4617 if (! do_debug_frames_interp || *reg_prefix != '\0')
4618 printf (" DW_CFA_same_value: %s%s\n",
4619 reg_prefix, regname (reg, 0));
4620 if (*reg_prefix == '\0')
4622 fc->col_type[reg] = DW_CFA_same_value;
4623 fc->col_offset[reg] = 0;
4625 break;
4627 case DW_CFA_register:
4628 reg = LEB ();
4629 roffs = LEB ();
4630 if (reg >= (unsigned int) fc->ncols)
4631 reg_prefix = bad_reg;
4632 if (! do_debug_frames_interp || *reg_prefix != '\0')
4634 printf (" DW_CFA_register: %s%s in ",
4635 reg_prefix, regname (reg, 0));
4636 puts (regname (roffs, 0));
4638 if (*reg_prefix == '\0')
4640 fc->col_type[reg] = DW_CFA_register;
4641 fc->col_offset[reg] = roffs;
4643 break;
4645 case DW_CFA_remember_state:
4646 if (! do_debug_frames_interp)
4647 printf (" DW_CFA_remember_state\n");
4648 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4649 rs->ncols = fc->ncols;
4650 rs->col_type = (short int *) xcmalloc (rs->ncols,
4651 sizeof (short int));
4652 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
4653 memcpy (rs->col_type, fc->col_type, rs->ncols);
4654 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
4655 rs->next = remembered_state;
4656 remembered_state = rs;
4657 break;
4659 case DW_CFA_restore_state:
4660 if (! do_debug_frames_interp)
4661 printf (" DW_CFA_restore_state\n");
4662 rs = remembered_state;
4663 if (rs)
4665 remembered_state = rs->next;
4666 frame_need_space (fc, rs->ncols - 1);
4667 memcpy (fc->col_type, rs->col_type, rs->ncols);
4668 memcpy (fc->col_offset, rs->col_offset,
4669 rs->ncols * sizeof (int));
4670 free (rs->col_type);
4671 free (rs->col_offset);
4672 free (rs);
4674 else if (do_debug_frames_interp)
4675 printf ("Mismatched DW_CFA_restore_state\n");
4676 break;
4678 case DW_CFA_def_cfa:
4679 fc->cfa_reg = LEB ();
4680 fc->cfa_offset = LEB ();
4681 fc->cfa_exp = 0;
4682 if (! do_debug_frames_interp)
4683 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4684 regname (fc->cfa_reg, 0), fc->cfa_offset);
4685 break;
4687 case DW_CFA_def_cfa_register:
4688 fc->cfa_reg = LEB ();
4689 fc->cfa_exp = 0;
4690 if (! do_debug_frames_interp)
4691 printf (" DW_CFA_def_cfa_register: %s\n",
4692 regname (fc->cfa_reg, 0));
4693 break;
4695 case DW_CFA_def_cfa_offset:
4696 fc->cfa_offset = LEB ();
4697 if (! do_debug_frames_interp)
4698 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
4699 break;
4701 case DW_CFA_nop:
4702 if (! do_debug_frames_interp)
4703 printf (" DW_CFA_nop\n");
4704 break;
4706 case DW_CFA_def_cfa_expression:
4707 ul = LEB ();
4708 if (! do_debug_frames_interp)
4710 printf (" DW_CFA_def_cfa_expression (");
4711 decode_location_expression (start, eh_addr_size, 0, -1,
4712 ul, 0, section);
4713 printf (")\n");
4715 fc->cfa_exp = 1;
4716 start += ul;
4717 break;
4719 case DW_CFA_expression:
4720 reg = LEB ();
4721 ul = LEB ();
4722 if (reg >= (unsigned int) fc->ncols)
4723 reg_prefix = bad_reg;
4724 if (! do_debug_frames_interp || *reg_prefix != '\0')
4726 printf (" DW_CFA_expression: %s%s (",
4727 reg_prefix, regname (reg, 0));
4728 decode_location_expression (start, eh_addr_size, 0, -1,
4729 ul, 0, section);
4730 printf (")\n");
4732 if (*reg_prefix == '\0')
4733 fc->col_type[reg] = DW_CFA_expression;
4734 start += ul;
4735 break;
4737 case DW_CFA_val_expression:
4738 reg = LEB ();
4739 ul = LEB ();
4740 if (reg >= (unsigned int) fc->ncols)
4741 reg_prefix = bad_reg;
4742 if (! do_debug_frames_interp || *reg_prefix != '\0')
4744 printf (" DW_CFA_val_expression: %s%s (",
4745 reg_prefix, regname (reg, 0));
4746 decode_location_expression (start, eh_addr_size, 0, -1,
4747 ul, 0, section);
4748 printf (")\n");
4750 if (*reg_prefix == '\0')
4751 fc->col_type[reg] = DW_CFA_val_expression;
4752 start += ul;
4753 break;
4755 case DW_CFA_offset_extended_sf:
4756 reg = LEB ();
4757 l = SLEB ();
4758 if (frame_need_space (fc, reg) < 0)
4759 reg_prefix = bad_reg;
4760 if (! do_debug_frames_interp || *reg_prefix != '\0')
4761 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4762 reg_prefix, regname (reg, 0),
4763 l * fc->data_factor);
4764 if (*reg_prefix == '\0')
4766 fc->col_type[reg] = DW_CFA_offset;
4767 fc->col_offset[reg] = l * fc->data_factor;
4769 break;
4771 case DW_CFA_val_offset_sf:
4772 reg = LEB ();
4773 l = SLEB ();
4774 if (frame_need_space (fc, reg) < 0)
4775 reg_prefix = bad_reg;
4776 if (! do_debug_frames_interp || *reg_prefix != '\0')
4777 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4778 reg_prefix, regname (reg, 0),
4779 l * fc->data_factor);
4780 if (*reg_prefix == '\0')
4782 fc->col_type[reg] = DW_CFA_val_offset;
4783 fc->col_offset[reg] = l * fc->data_factor;
4785 break;
4787 case DW_CFA_def_cfa_sf:
4788 fc->cfa_reg = LEB ();
4789 fc->cfa_offset = SLEB ();
4790 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
4791 fc->cfa_exp = 0;
4792 if (! do_debug_frames_interp)
4793 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4794 regname (fc->cfa_reg, 0), fc->cfa_offset);
4795 break;
4797 case DW_CFA_def_cfa_offset_sf:
4798 fc->cfa_offset = SLEB ();
4799 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
4800 if (! do_debug_frames_interp)
4801 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
4802 break;
4804 case DW_CFA_MIPS_advance_loc8:
4805 ofs = byte_get (start, 8); start += 8;
4806 if (do_debug_frames_interp)
4807 frame_display_row (fc, &need_col_headers, &max_regs);
4808 else
4809 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4810 ofs * fc->code_factor,
4811 fc->pc_begin + ofs * fc->code_factor);
4812 fc->pc_begin += ofs * fc->code_factor;
4813 break;
4815 case DW_CFA_GNU_window_save:
4816 if (! do_debug_frames_interp)
4817 printf (" DW_CFA_GNU_window_save\n");
4818 break;
4820 case DW_CFA_GNU_args_size:
4821 ul = LEB ();
4822 if (! do_debug_frames_interp)
4823 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
4824 break;
4826 case DW_CFA_GNU_negative_offset_extended:
4827 reg = LEB ();
4828 l = - LEB ();
4829 if (frame_need_space (fc, reg) < 0)
4830 reg_prefix = bad_reg;
4831 if (! do_debug_frames_interp || *reg_prefix != '\0')
4832 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4833 reg_prefix, regname (reg, 0),
4834 l * fc->data_factor);
4835 if (*reg_prefix == '\0')
4837 fc->col_type[reg] = DW_CFA_offset;
4838 fc->col_offset[reg] = l * fc->data_factor;
4840 break;
4842 default:
4843 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
4844 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
4845 else
4846 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
4847 start = block_end;
4851 if (do_debug_frames_interp)
4852 frame_display_row (fc, &need_col_headers, &max_regs);
4854 start = block_end;
4855 eh_addr_size = saved_eh_addr_size;
4858 printf ("\n");
4860 return 1;
4863 #undef GET
4864 #undef LEB
4865 #undef SLEB
4867 static int
4868 display_gdb_index (struct dwarf_section *section,
4869 void *file ATTRIBUTE_UNUSED)
4871 unsigned char *start = section->start;
4872 uint32_t version;
4873 uint32_t cu_list_offset, tu_list_offset;
4874 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
4875 unsigned int cu_list_elements, tu_list_elements;
4876 unsigned int address_table_size, symbol_table_slots;
4877 unsigned char *cu_list, *tu_list;
4878 unsigned char *address_table, *symbol_table, *constant_pool;
4879 unsigned int i;
4881 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
4883 printf (_("Contents of the %s section:\n"), section->name);
4885 if (section->size < 6 * sizeof (uint32_t))
4887 warn (_("Truncated header in the %s section.\n"), section->name);
4888 return 0;
4891 version = byte_get_little_endian (start, 4);
4892 printf (_("Version %ld\n"), (long) version);
4894 /* Prior versions are obsolete, and future versions may not be
4895 backwards compatible. */
4896 switch (version)
4898 case 3:
4899 warn (_("The address table data in version 3 may be wrong.\n"));
4900 break;
4901 case 4:
4902 break;
4903 default:
4904 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
4905 return 0;
4908 cu_list_offset = byte_get_little_endian (start + 4, 4);
4909 tu_list_offset = byte_get_little_endian (start + 8, 4);
4910 address_table_offset = byte_get_little_endian (start + 12, 4);
4911 symbol_table_offset = byte_get_little_endian (start + 16, 4);
4912 constant_pool_offset = byte_get_little_endian (start + 20, 4);
4914 if (cu_list_offset > section->size
4915 || tu_list_offset > section->size
4916 || address_table_offset > section->size
4917 || symbol_table_offset > section->size
4918 || constant_pool_offset > section->size)
4920 warn (_("Corrupt header in the %s section.\n"), section->name);
4921 return 0;
4924 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
4925 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
4926 address_table_size = symbol_table_offset - address_table_offset;
4927 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
4929 cu_list = start + cu_list_offset;
4930 tu_list = start + tu_list_offset;
4931 address_table = start + address_table_offset;
4932 symbol_table = start + symbol_table_offset;
4933 constant_pool = start + constant_pool_offset;
4935 printf (_("\nCU table:\n"));
4936 for (i = 0; i < cu_list_elements; i += 2)
4938 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
4939 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
4941 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
4942 (unsigned long) cu_offset,
4943 (unsigned long) (cu_offset + cu_length - 1));
4946 printf (_("\nTU table:\n"));
4947 for (i = 0; i < tu_list_elements; i += 3)
4949 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
4950 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
4951 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
4953 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
4954 (unsigned long) tu_offset,
4955 (unsigned long) type_offset);
4956 print_dwarf_vma (signature, 8);
4957 printf ("\n");
4960 printf (_("\nAddress table:\n"));
4961 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
4963 uint64_t low = byte_get_little_endian (address_table + i, 8);
4964 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
4965 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
4967 print_dwarf_vma (low, 8);
4968 print_dwarf_vma (high, 8);
4969 printf (_("%lu\n"), (unsigned long) cu_index);
4972 printf (_("\nSymbol table:\n"));
4973 for (i = 0; i < symbol_table_slots; ++i)
4975 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
4976 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
4977 uint32_t num_cus, cu;
4979 if (name_offset != 0
4980 || cu_vector_offset != 0)
4982 unsigned int j;
4984 printf ("[%3u] %s:", i, constant_pool + name_offset);
4985 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
4986 for (j = 0; j < num_cus; ++j)
4988 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
4989 /* Convert to TU number if it's for a type unit. */
4990 if (cu >= cu_list_elements)
4991 printf (" T%lu", (unsigned long) (cu - cu_list_elements));
4992 else
4993 printf (" %lu", (unsigned long) cu);
4995 printf ("\n");
4999 return 1;
5002 static int
5003 display_debug_not_supported (struct dwarf_section *section,
5004 void *file ATTRIBUTE_UNUSED)
5006 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5007 section->name);
5009 return 1;
5012 void *
5013 cmalloc (size_t nmemb, size_t size)
5015 /* Check for overflow. */
5016 if (nmemb >= ~(size_t) 0 / size)
5017 return NULL;
5018 else
5019 return malloc (nmemb * size);
5022 void *
5023 xcmalloc (size_t nmemb, size_t size)
5025 /* Check for overflow. */
5026 if (nmemb >= ~(size_t) 0 / size)
5027 return NULL;
5028 else
5029 return xmalloc (nmemb * size);
5032 void *
5033 xcrealloc (void *ptr, size_t nmemb, size_t size)
5035 /* Check for overflow. */
5036 if (nmemb >= ~(size_t) 0 / size)
5037 return NULL;
5038 else
5039 return xrealloc (ptr, nmemb * size);
5042 void
5043 free_debug_memory (void)
5045 unsigned int i;
5047 free_abbrevs ();
5049 for (i = 0; i < max; i++)
5050 free_debug_section ((enum dwarf_section_display_enum) i);
5052 if (debug_information != NULL)
5054 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
5056 for (i = 0; i < num_debug_info_entries; i++)
5058 if (!debug_information [i].max_loc_offsets)
5060 free (debug_information [i].loc_offsets);
5061 free (debug_information [i].have_frame_base);
5063 if (!debug_information [i].max_range_lists)
5064 free (debug_information [i].range_lists);
5068 free (debug_information);
5069 debug_information = NULL;
5070 num_debug_info_entries = 0;
5074 void
5075 dwarf_select_sections_by_names (const char *names)
5077 typedef struct
5079 const char * option;
5080 int * variable;
5081 int val;
5083 debug_dump_long_opts;
5085 static const debug_dump_long_opts opts_table [] =
5087 /* Please keep this table alpha- sorted. */
5088 { "Ranges", & do_debug_ranges, 1 },
5089 { "abbrev", & do_debug_abbrevs, 1 },
5090 { "aranges", & do_debug_aranges, 1 },
5091 { "frames", & do_debug_frames, 1 },
5092 { "frames-interp", & do_debug_frames_interp, 1 },
5093 { "info", & do_debug_info, 1 },
5094 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5095 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5096 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5097 { "loc", & do_debug_loc, 1 },
5098 { "macro", & do_debug_macinfo, 1 },
5099 { "pubnames", & do_debug_pubnames, 1 },
5100 { "pubtypes", & do_debug_pubtypes, 1 },
5101 /* This entry is for compatability
5102 with earlier versions of readelf. */
5103 { "ranges", & do_debug_aranges, 1 },
5104 { "str", & do_debug_str, 1 },
5105 /* The special .gdb_index section. */
5106 { "gdb_index", & do_gdb_index, 1 },
5107 /* These trace_* sections are used by Itanium VMS. */
5108 { "trace_abbrev", & do_trace_abbrevs, 1 },
5109 { "trace_aranges", & do_trace_aranges, 1 },
5110 { "trace_info", & do_trace_info, 1 },
5111 { NULL, NULL, 0 }
5114 const char *p;
5116 p = names;
5117 while (*p)
5119 const debug_dump_long_opts * entry;
5121 for (entry = opts_table; entry->option; entry++)
5123 size_t len = strlen (entry->option);
5125 if (strncmp (p, entry->option, len) == 0
5126 && (p[len] == ',' || p[len] == '\0'))
5128 * entry->variable |= entry->val;
5130 /* The --debug-dump=frames-interp option also
5131 enables the --debug-dump=frames option. */
5132 if (do_debug_frames_interp)
5133 do_debug_frames = 1;
5135 p += len;
5136 break;
5140 if (entry->option == NULL)
5142 warn (_("Unrecognized debug option '%s'\n"), p);
5143 p = strchr (p, ',');
5144 if (p == NULL)
5145 break;
5148 if (*p == ',')
5149 p++;
5153 void
5154 dwarf_select_sections_by_letters (const char *letters)
5156 unsigned int lindex = 0;
5158 while (letters[lindex])
5159 switch (letters[lindex++])
5161 case 'i':
5162 do_debug_info = 1;
5163 break;
5165 case 'a':
5166 do_debug_abbrevs = 1;
5167 break;
5169 case 'l':
5170 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
5171 break;
5173 case 'L':
5174 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
5175 break;
5177 case 'p':
5178 do_debug_pubnames = 1;
5179 break;
5181 case 't':
5182 do_debug_pubtypes = 1;
5183 break;
5185 case 'r':
5186 do_debug_aranges = 1;
5187 break;
5189 case 'R':
5190 do_debug_ranges = 1;
5191 break;
5193 case 'F':
5194 do_debug_frames_interp = 1;
5195 case 'f':
5196 do_debug_frames = 1;
5197 break;
5199 case 'm':
5200 do_debug_macinfo = 1;
5201 break;
5203 case 's':
5204 do_debug_str = 1;
5205 break;
5207 case 'o':
5208 do_debug_loc = 1;
5209 break;
5211 default:
5212 warn (_("Unrecognized debug option '%s'\n"), optarg);
5213 break;
5217 void
5218 dwarf_select_sections_all (void)
5220 do_debug_info = 1;
5221 do_debug_abbrevs = 1;
5222 do_debug_lines = FLAG_DEBUG_LINES_RAW;
5223 do_debug_pubnames = 1;
5224 do_debug_pubtypes = 1;
5225 do_debug_aranges = 1;
5226 do_debug_ranges = 1;
5227 do_debug_frames = 1;
5228 do_debug_macinfo = 1;
5229 do_debug_str = 1;
5230 do_debug_loc = 1;
5231 do_gdb_index = 1;
5232 do_trace_info = 1;
5233 do_trace_abbrevs = 1;
5234 do_trace_aranges = 1;
5237 struct dwarf_section_display debug_displays[] =
5239 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 },
5240 display_debug_abbrev, &do_debug_abbrevs, 0 },
5241 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 },
5242 display_debug_aranges, &do_debug_aranges, 1 },
5243 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 },
5244 display_debug_frames, &do_debug_frames, 1 },
5245 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 },
5246 display_debug_info, &do_debug_info, 1 },
5247 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 },
5248 display_debug_lines, &do_debug_lines, 1 },
5249 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 },
5250 display_debug_pubnames, &do_debug_pubnames, 0 },
5251 { { ".eh_frame", "", NULL, NULL, 0, 0 },
5252 display_debug_frames, &do_debug_frames, 1 },
5253 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 },
5254 display_debug_macinfo, &do_debug_macinfo, 0 },
5255 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 },
5256 display_debug_str, &do_debug_str, 0 },
5257 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 },
5258 display_debug_loc, &do_debug_loc, 1 },
5259 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 },
5260 display_debug_pubnames, &do_debug_pubtypes, 0 },
5261 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 },
5262 display_debug_ranges, &do_debug_ranges, 1 },
5263 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 },
5264 display_debug_not_supported, NULL, 0 },
5265 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 },
5266 display_debug_not_supported, NULL, 0 },
5267 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 },
5268 display_debug_types, &do_debug_info, 1 },
5269 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 },
5270 display_debug_not_supported, NULL, 0 },
5271 { { ".gdb_index", "", NULL, NULL, 0, 0 },
5272 display_gdb_index, &do_gdb_index, 0 },
5273 { { ".trace_info", "", NULL, NULL, 0, 0 },
5274 display_trace_info, &do_trace_info, 1 },
5275 { { ".trace_abbrev", "", NULL, NULL, 0, 0 },
5276 display_debug_abbrev, &do_trace_abbrevs, 0 },
5277 { { ".trace_aranges", "", NULL, NULL, 0, 0 },
5278 display_debug_aranges, &do_trace_aranges, 0 }