Add -lpwl to ppllibs, and -lisl to clooglibs.
[binutils.git] / binutils / dwarf.c
blob36d4ac2db9736fc2fc1b9c472935ddcd9ada5c6e
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 static const char *
127 dwarf_vmatoa (const char *fmtch, bfd_vma value)
129 /* As dwarf_vmatoa is used more then once in a printf call
130 for output, we are cycling through an fixed array of pointers
131 for return address. */
132 static int buf_pos = 0;
133 static struct dwarf_vmatoa_buf {
134 char place[64];
135 } buf[16];
136 char fmt[32];
137 char *ret;
139 sprintf (fmt, "%%%s%s", BFD_VMA_FMT, fmtch);
141 ret = buf[buf_pos++].place;
142 buf_pos %= ARRAY_SIZE(buf);
144 snprintf (ret, sizeof (buf[0].place), fmt, value);
146 return ret;
149 bfd_vma
150 read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
152 bfd_vma result = 0;
153 unsigned int num_read = 0;
154 unsigned int shift = 0;
155 unsigned char byte;
159 byte = *data++;
160 num_read++;
162 result |= ((bfd_vma) (byte & 0x7f)) << shift;
164 shift += 7;
167 while (byte & 0x80);
169 if (length_return != NULL)
170 *length_return = num_read;
172 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
173 result |= -1L << shift;
175 return result;
178 typedef struct State_Machine_Registers
180 unsigned long address;
181 unsigned int file;
182 unsigned int line;
183 unsigned int column;
184 int is_stmt;
185 int basic_block;
186 unsigned char op_index;
187 unsigned char end_sequence;
188 /* This variable hold the number of the last entry seen
189 in the File Table. */
190 unsigned int last_file_entry;
191 } SMR;
193 static SMR state_machine_regs;
195 static void
196 reset_state_machine (int is_stmt)
198 state_machine_regs.address = 0;
199 state_machine_regs.op_index = 0;
200 state_machine_regs.file = 1;
201 state_machine_regs.line = 1;
202 state_machine_regs.column = 0;
203 state_machine_regs.is_stmt = is_stmt;
204 state_machine_regs.basic_block = 0;
205 state_machine_regs.end_sequence = 0;
206 state_machine_regs.last_file_entry = 0;
209 /* Handled an extend line op.
210 Returns the number of bytes read. */
212 static int
213 process_extended_line_op (unsigned char *data, int is_stmt)
215 unsigned char op_code;
216 unsigned int bytes_read;
217 unsigned int len;
218 unsigned char *name;
219 bfd_vma adr;
221 len = read_leb128 (data, & bytes_read, 0);
222 data += bytes_read;
224 if (len == 0)
226 warn (_("badly formed extended line op encountered!\n"));
227 return bytes_read;
230 len += bytes_read;
231 op_code = *data++;
233 printf (_(" Extended opcode %d: "), op_code);
235 switch (op_code)
237 case DW_LNE_end_sequence:
238 printf (_("End of Sequence\n\n"));
239 reset_state_machine (is_stmt);
240 break;
242 case DW_LNE_set_address:
243 adr = byte_get (data, len - bytes_read - 1);
244 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr));
245 state_machine_regs.address = adr;
246 state_machine_regs.op_index = 0;
247 break;
249 case DW_LNE_define_file:
250 printf (_(" define new File Table entry\n"));
251 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
253 printf (" %d\t", ++state_machine_regs.last_file_entry);
254 name = data;
255 data += strlen ((char *) data) + 1;
256 printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
257 data += bytes_read;
258 printf ("%" BFD_VMA_FMT "u\t",
259 read_leb128 (data, & bytes_read, 0));
260 data += bytes_read;
261 printf ("%" BFD_VMA_FMT "u\t", read_leb128 (data, & bytes_read, 0));
262 printf ("%s\n\n", name);
263 break;
265 case DW_LNE_set_discriminator:
266 printf (_("set Discriminator to %s\n"),
267 dwarf_vmatoa ("u",
268 read_leb128 (data, & bytes_read, 0)));
269 break;
271 /* HP extensions. */
272 case DW_LNE_HP_negate_is_UV_update:
273 printf ("DW_LNE_HP_negate_is_UV_update\n");
274 break;
275 case DW_LNE_HP_push_context:
276 printf ("DW_LNE_HP_push_context\n");
277 break;
278 case DW_LNE_HP_pop_context:
279 printf ("DW_LNE_HP_pop_context\n");
280 break;
281 case DW_LNE_HP_set_file_line_column:
282 printf ("DW_LNE_HP_set_file_line_column\n");
283 break;
284 case DW_LNE_HP_set_routine_name:
285 printf ("DW_LNE_HP_set_routine_name\n");
286 break;
287 case DW_LNE_HP_set_sequence:
288 printf ("DW_LNE_HP_set_sequence\n");
289 break;
290 case DW_LNE_HP_negate_post_semantics:
291 printf ("DW_LNE_HP_negate_post_semantics\n");
292 break;
293 case DW_LNE_HP_negate_function_exit:
294 printf ("DW_LNE_HP_negate_function_exit\n");
295 break;
296 case DW_LNE_HP_negate_front_end_logical:
297 printf ("DW_LNE_HP_negate_front_end_logical\n");
298 break;
299 case DW_LNE_HP_define_proc:
300 printf ("DW_LNE_HP_define_proc\n");
301 break;
303 default:
304 if (op_code >= DW_LNE_lo_user
305 /* The test against DW_LNW_hi_user is redundant due to
306 the limited range of the unsigned char data type used
307 for op_code. */
308 /*&& op_code <= DW_LNE_hi_user*/)
309 printf (_("user defined: length %d\n"), len - bytes_read);
310 else
311 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
312 break;
315 return len;
318 static const char *
319 fetch_indirect_string (bfd_vma offset)
321 struct dwarf_section *section = &debug_displays [str].section;
323 if (section->start == NULL)
324 return _("<no .debug_str section>");
326 /* DWARF sections under Mach-O have non-zero addresses. */
327 offset -= section->address;
328 if (offset > section->size)
330 warn (_("DW_FORM_strp offset too big: %lx\n"), (long) offset);
331 return _("<offset is too big>");
334 return (const char *) section->start + offset;
337 /* FIXME: There are better and more efficient ways to handle
338 these structures. For now though, I just want something that
339 is simple to implement. */
340 typedef struct abbrev_attr
342 unsigned long attribute;
343 unsigned long form;
344 struct abbrev_attr *next;
346 abbrev_attr;
348 typedef struct abbrev_entry
350 unsigned long entry;
351 unsigned long tag;
352 int children;
353 struct abbrev_attr *first_attr;
354 struct abbrev_attr *last_attr;
355 struct abbrev_entry *next;
357 abbrev_entry;
359 static abbrev_entry *first_abbrev = NULL;
360 static abbrev_entry *last_abbrev = NULL;
362 static void
363 free_abbrevs (void)
365 abbrev_entry *abbrv;
367 for (abbrv = first_abbrev; abbrv;)
369 abbrev_entry *next_abbrev = abbrv->next;
370 abbrev_attr *attr;
372 for (attr = abbrv->first_attr; attr;)
374 abbrev_attr *next_attr = attr->next;
376 free (attr);
377 attr = next_attr;
380 free (abbrv);
381 abbrv = next_abbrev;
384 last_abbrev = first_abbrev = NULL;
387 static void
388 add_abbrev (unsigned long number, unsigned long tag, int children)
390 abbrev_entry *entry;
392 entry = (abbrev_entry *) malloc (sizeof (*entry));
394 if (entry == NULL)
395 /* ugg */
396 return;
398 entry->entry = number;
399 entry->tag = tag;
400 entry->children = children;
401 entry->first_attr = NULL;
402 entry->last_attr = NULL;
403 entry->next = NULL;
405 if (first_abbrev == NULL)
406 first_abbrev = entry;
407 else
408 last_abbrev->next = entry;
410 last_abbrev = entry;
413 static void
414 add_abbrev_attr (unsigned long attribute, unsigned long form)
416 abbrev_attr *attr;
418 attr = (abbrev_attr *) malloc (sizeof (*attr));
420 if (attr == NULL)
421 /* ugg */
422 return;
424 attr->attribute = attribute;
425 attr->form = form;
426 attr->next = NULL;
428 if (last_abbrev->first_attr == NULL)
429 last_abbrev->first_attr = attr;
430 else
431 last_abbrev->last_attr->next = attr;
433 last_abbrev->last_attr = attr;
436 /* Processes the (partial) contents of a .debug_abbrev section.
437 Returns NULL if the end of the section was encountered.
438 Returns the address after the last byte read if the end of
439 an abbreviation set was found. */
441 static unsigned char *
442 process_abbrev_section (unsigned char *start, unsigned char *end)
444 if (first_abbrev != NULL)
445 return NULL;
447 while (start < end)
449 unsigned int bytes_read;
450 unsigned long entry;
451 unsigned long tag;
452 unsigned long attribute;
453 int children;
455 entry = read_leb128 (start, & bytes_read, 0);
456 start += bytes_read;
458 /* A single zero is supposed to end the section according
459 to the standard. If there's more, then signal that to
460 the caller. */
461 if (entry == 0)
462 return start == end ? NULL : start;
464 tag = read_leb128 (start, & bytes_read, 0);
465 start += bytes_read;
467 children = *start++;
469 add_abbrev (entry, tag, children);
473 unsigned long form;
475 attribute = read_leb128 (start, & bytes_read, 0);
476 start += bytes_read;
478 form = read_leb128 (start, & bytes_read, 0);
479 start += bytes_read;
481 if (attribute != 0)
482 add_abbrev_attr (attribute, form);
484 while (attribute != 0);
487 return NULL;
490 static char *
491 get_TAG_name (unsigned long tag)
493 switch (tag)
495 case DW_TAG_padding: return "DW_TAG_padding";
496 case DW_TAG_array_type: return "DW_TAG_array_type";
497 case DW_TAG_class_type: return "DW_TAG_class_type";
498 case DW_TAG_entry_point: return "DW_TAG_entry_point";
499 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
500 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
501 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
502 case DW_TAG_label: return "DW_TAG_label";
503 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
504 case DW_TAG_member: return "DW_TAG_member";
505 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
506 case DW_TAG_reference_type: return "DW_TAG_reference_type";
507 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
508 case DW_TAG_string_type: return "DW_TAG_string_type";
509 case DW_TAG_structure_type: return "DW_TAG_structure_type";
510 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
511 case DW_TAG_typedef: return "DW_TAG_typedef";
512 case DW_TAG_union_type: return "DW_TAG_union_type";
513 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
514 case DW_TAG_variant: return "DW_TAG_variant";
515 case DW_TAG_common_block: return "DW_TAG_common_block";
516 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
517 case DW_TAG_inheritance: return "DW_TAG_inheritance";
518 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
519 case DW_TAG_module: return "DW_TAG_module";
520 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
521 case DW_TAG_set_type: return "DW_TAG_set_type";
522 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
523 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
524 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
525 case DW_TAG_base_type: return "DW_TAG_base_type";
526 case DW_TAG_catch_block: return "DW_TAG_catch_block";
527 case DW_TAG_const_type: return "DW_TAG_const_type";
528 case DW_TAG_constant: return "DW_TAG_constant";
529 case DW_TAG_enumerator: return "DW_TAG_enumerator";
530 case DW_TAG_file_type: return "DW_TAG_file_type";
531 case DW_TAG_friend: return "DW_TAG_friend";
532 case DW_TAG_namelist: return "DW_TAG_namelist";
533 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
534 case DW_TAG_packed_type: return "DW_TAG_packed_type";
535 case DW_TAG_subprogram: return "DW_TAG_subprogram";
536 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
537 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
538 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
539 case DW_TAG_try_block: return "DW_TAG_try_block";
540 case DW_TAG_variant_part: return "DW_TAG_variant_part";
541 case DW_TAG_variable: return "DW_TAG_variable";
542 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
543 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
544 case DW_TAG_format_label: return "DW_TAG_format_label";
545 case DW_TAG_function_template: return "DW_TAG_function_template";
546 case DW_TAG_class_template: return "DW_TAG_class_template";
547 /* DWARF 2.1 values. */
548 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
549 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
550 case DW_TAG_interface_type: return "DW_TAG_interface_type";
551 case DW_TAG_namespace: return "DW_TAG_namespace";
552 case DW_TAG_imported_module: return "DW_TAG_imported_module";
553 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
554 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
555 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
556 case DW_TAG_condition: return "DW_TAG_condition";
557 case DW_TAG_shared_type: return "DW_TAG_shared_type";
558 /* DWARF 4 values. */
559 case DW_TAG_type_unit: return "DW_TAG_type_unit";
560 case DW_TAG_rvalue_reference_type: return "DW_TAG_rvalue_reference_type";
561 case DW_TAG_template_alias: return "DW_TAG_template_alias";
562 /* UPC values. */
563 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
564 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
565 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
566 default:
568 static char buffer[100];
570 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
571 return buffer;
576 static char *
577 get_FORM_name (unsigned long form)
579 switch (form)
581 case DW_FORM_addr: return "DW_FORM_addr";
582 case DW_FORM_block2: return "DW_FORM_block2";
583 case DW_FORM_block4: return "DW_FORM_block4";
584 case DW_FORM_data2: return "DW_FORM_data2";
585 case DW_FORM_data4: return "DW_FORM_data4";
586 case DW_FORM_data8: return "DW_FORM_data8";
587 case DW_FORM_string: return "DW_FORM_string";
588 case DW_FORM_block: return "DW_FORM_block";
589 case DW_FORM_block1: return "DW_FORM_block1";
590 case DW_FORM_data1: return "DW_FORM_data1";
591 case DW_FORM_flag: return "DW_FORM_flag";
592 case DW_FORM_sdata: return "DW_FORM_sdata";
593 case DW_FORM_strp: return "DW_FORM_strp";
594 case DW_FORM_udata: return "DW_FORM_udata";
595 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
596 case DW_FORM_ref1: return "DW_FORM_ref1";
597 case DW_FORM_ref2: return "DW_FORM_ref2";
598 case DW_FORM_ref4: return "DW_FORM_ref4";
599 case DW_FORM_ref8: return "DW_FORM_ref8";
600 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
601 case DW_FORM_indirect: return "DW_FORM_indirect";
602 /* DWARF 4 values. */
603 case DW_FORM_sec_offset: return "DW_FORM_sec_offset";
604 case DW_FORM_exprloc: return "DW_FORM_exprloc";
605 case DW_FORM_flag_present: return "DW_FORM_flag_present";
606 case DW_FORM_ref_sig8: return "DW_FORM_ref_sig8";
607 default:
609 static char buffer[100];
611 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
612 return buffer;
617 static unsigned char *
618 display_block (unsigned char *data, unsigned long length)
620 printf (_(" %lu byte block: "), length);
622 while (length --)
623 printf ("%lx ", (unsigned long) byte_get (data++, 1));
625 return data;
628 static int
629 decode_location_expression (unsigned char * data,
630 unsigned int pointer_size,
631 unsigned int offset_size,
632 int dwarf_version,
633 bfd_vma length,
634 bfd_vma cu_offset,
635 struct dwarf_section * section)
637 unsigned op;
638 unsigned int bytes_read;
639 bfd_vma uvalue;
640 unsigned char *end = data + length;
641 int need_frame_base = 0;
643 while (data < end)
645 op = *data++;
647 switch (op)
649 case DW_OP_addr:
650 printf ("DW_OP_addr: %lx",
651 (unsigned long) byte_get (data, pointer_size));
652 data += pointer_size;
653 break;
654 case DW_OP_deref:
655 printf ("DW_OP_deref");
656 break;
657 case DW_OP_const1u:
658 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
659 break;
660 case DW_OP_const1s:
661 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
662 break;
663 case DW_OP_const2u:
664 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
665 data += 2;
666 break;
667 case DW_OP_const2s:
668 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
669 data += 2;
670 break;
671 case DW_OP_const4u:
672 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
673 data += 4;
674 break;
675 case DW_OP_const4s:
676 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
677 data += 4;
678 break;
679 case DW_OP_const8u:
680 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
681 (unsigned long) byte_get (data + 4, 4));
682 data += 8;
683 break;
684 case DW_OP_const8s:
685 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
686 (long) byte_get (data + 4, 4));
687 data += 8;
688 break;
689 case DW_OP_constu:
690 printf ("DW_OP_constu: %" BFD_VMA_FMT "u",
691 read_leb128 (data, &bytes_read, 0));
692 data += bytes_read;
693 break;
694 case DW_OP_consts:
695 printf ("DW_OP_consts: %" BFD_VMA_FMT "d",
696 read_leb128 (data, &bytes_read, 1));
697 data += bytes_read;
698 break;
699 case DW_OP_dup:
700 printf ("DW_OP_dup");
701 break;
702 case DW_OP_drop:
703 printf ("DW_OP_drop");
704 break;
705 case DW_OP_over:
706 printf ("DW_OP_over");
707 break;
708 case DW_OP_pick:
709 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
710 break;
711 case DW_OP_swap:
712 printf ("DW_OP_swap");
713 break;
714 case DW_OP_rot:
715 printf ("DW_OP_rot");
716 break;
717 case DW_OP_xderef:
718 printf ("DW_OP_xderef");
719 break;
720 case DW_OP_abs:
721 printf ("DW_OP_abs");
722 break;
723 case DW_OP_and:
724 printf ("DW_OP_and");
725 break;
726 case DW_OP_div:
727 printf ("DW_OP_div");
728 break;
729 case DW_OP_minus:
730 printf ("DW_OP_minus");
731 break;
732 case DW_OP_mod:
733 printf ("DW_OP_mod");
734 break;
735 case DW_OP_mul:
736 printf ("DW_OP_mul");
737 break;
738 case DW_OP_neg:
739 printf ("DW_OP_neg");
740 break;
741 case DW_OP_not:
742 printf ("DW_OP_not");
743 break;
744 case DW_OP_or:
745 printf ("DW_OP_or");
746 break;
747 case DW_OP_plus:
748 printf ("DW_OP_plus");
749 break;
750 case DW_OP_plus_uconst:
751 printf ("DW_OP_plus_uconst: %" BFD_VMA_FMT "u",
752 read_leb128 (data, &bytes_read, 0));
753 data += bytes_read;
754 break;
755 case DW_OP_shl:
756 printf ("DW_OP_shl");
757 break;
758 case DW_OP_shr:
759 printf ("DW_OP_shr");
760 break;
761 case DW_OP_shra:
762 printf ("DW_OP_shra");
763 break;
764 case DW_OP_xor:
765 printf ("DW_OP_xor");
766 break;
767 case DW_OP_bra:
768 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
769 data += 2;
770 break;
771 case DW_OP_eq:
772 printf ("DW_OP_eq");
773 break;
774 case DW_OP_ge:
775 printf ("DW_OP_ge");
776 break;
777 case DW_OP_gt:
778 printf ("DW_OP_gt");
779 break;
780 case DW_OP_le:
781 printf ("DW_OP_le");
782 break;
783 case DW_OP_lt:
784 printf ("DW_OP_lt");
785 break;
786 case DW_OP_ne:
787 printf ("DW_OP_ne");
788 break;
789 case DW_OP_skip:
790 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
791 data += 2;
792 break;
794 case DW_OP_lit0:
795 case DW_OP_lit1:
796 case DW_OP_lit2:
797 case DW_OP_lit3:
798 case DW_OP_lit4:
799 case DW_OP_lit5:
800 case DW_OP_lit6:
801 case DW_OP_lit7:
802 case DW_OP_lit8:
803 case DW_OP_lit9:
804 case DW_OP_lit10:
805 case DW_OP_lit11:
806 case DW_OP_lit12:
807 case DW_OP_lit13:
808 case DW_OP_lit14:
809 case DW_OP_lit15:
810 case DW_OP_lit16:
811 case DW_OP_lit17:
812 case DW_OP_lit18:
813 case DW_OP_lit19:
814 case DW_OP_lit20:
815 case DW_OP_lit21:
816 case DW_OP_lit22:
817 case DW_OP_lit23:
818 case DW_OP_lit24:
819 case DW_OP_lit25:
820 case DW_OP_lit26:
821 case DW_OP_lit27:
822 case DW_OP_lit28:
823 case DW_OP_lit29:
824 case DW_OP_lit30:
825 case DW_OP_lit31:
826 printf ("DW_OP_lit%d", op - DW_OP_lit0);
827 break;
829 case DW_OP_reg0:
830 case DW_OP_reg1:
831 case DW_OP_reg2:
832 case DW_OP_reg3:
833 case DW_OP_reg4:
834 case DW_OP_reg5:
835 case DW_OP_reg6:
836 case DW_OP_reg7:
837 case DW_OP_reg8:
838 case DW_OP_reg9:
839 case DW_OP_reg10:
840 case DW_OP_reg11:
841 case DW_OP_reg12:
842 case DW_OP_reg13:
843 case DW_OP_reg14:
844 case DW_OP_reg15:
845 case DW_OP_reg16:
846 case DW_OP_reg17:
847 case DW_OP_reg18:
848 case DW_OP_reg19:
849 case DW_OP_reg20:
850 case DW_OP_reg21:
851 case DW_OP_reg22:
852 case DW_OP_reg23:
853 case DW_OP_reg24:
854 case DW_OP_reg25:
855 case DW_OP_reg26:
856 case DW_OP_reg27:
857 case DW_OP_reg28:
858 case DW_OP_reg29:
859 case DW_OP_reg30:
860 case DW_OP_reg31:
861 printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0,
862 regname (op - DW_OP_reg0, 1));
863 break;
865 case DW_OP_breg0:
866 case DW_OP_breg1:
867 case DW_OP_breg2:
868 case DW_OP_breg3:
869 case DW_OP_breg4:
870 case DW_OP_breg5:
871 case DW_OP_breg6:
872 case DW_OP_breg7:
873 case DW_OP_breg8:
874 case DW_OP_breg9:
875 case DW_OP_breg10:
876 case DW_OP_breg11:
877 case DW_OP_breg12:
878 case DW_OP_breg13:
879 case DW_OP_breg14:
880 case DW_OP_breg15:
881 case DW_OP_breg16:
882 case DW_OP_breg17:
883 case DW_OP_breg18:
884 case DW_OP_breg19:
885 case DW_OP_breg20:
886 case DW_OP_breg21:
887 case DW_OP_breg22:
888 case DW_OP_breg23:
889 case DW_OP_breg24:
890 case DW_OP_breg25:
891 case DW_OP_breg26:
892 case DW_OP_breg27:
893 case DW_OP_breg28:
894 case DW_OP_breg29:
895 case DW_OP_breg30:
896 case DW_OP_breg31:
897 printf ("DW_OP_breg%d (%s): %" BFD_VMA_FMT "d",
898 op - DW_OP_breg0,
899 regname (op - DW_OP_breg0, 1),
900 read_leb128 (data, &bytes_read, 1));
901 data += bytes_read;
902 break;
904 case DW_OP_regx:
905 uvalue = read_leb128 (data, &bytes_read, 0);
906 data += bytes_read;
907 printf ("DW_OP_regx: %" BFD_VMA_FMT "u (%s)",
908 uvalue, regname (uvalue, 1));
909 break;
910 case DW_OP_fbreg:
911 need_frame_base = 1;
912 printf ("DW_OP_fbreg: %" BFD_VMA_FMT "d",
913 read_leb128 (data, &bytes_read, 1));
914 data += bytes_read;
915 break;
916 case DW_OP_bregx:
917 uvalue = read_leb128 (data, &bytes_read, 0);
918 data += bytes_read;
919 printf ("DW_OP_bregx: %" BFD_VMA_FMT "u (%s) %" BFD_VMA_FMT "d",
920 uvalue, regname (uvalue, 1),
921 read_leb128 (data, &bytes_read, 1));
922 data += bytes_read;
923 break;
924 case DW_OP_piece:
925 printf ("DW_OP_piece: %" BFD_VMA_FMT "u",
926 read_leb128 (data, &bytes_read, 0));
927 data += bytes_read;
928 break;
929 case DW_OP_deref_size:
930 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
931 break;
932 case DW_OP_xderef_size:
933 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
934 break;
935 case DW_OP_nop:
936 printf ("DW_OP_nop");
937 break;
939 /* DWARF 3 extensions. */
940 case DW_OP_push_object_address:
941 printf ("DW_OP_push_object_address");
942 break;
943 case DW_OP_call2:
944 /* XXX: Strictly speaking for 64-bit DWARF3 files
945 this ought to be an 8-byte wide computation. */
946 printf ("DW_OP_call2: <0x%" BFD_VMA_FMT "x>",
947 (bfd_signed_vma) byte_get (data, 2) + cu_offset);
948 data += 2;
949 break;
950 case DW_OP_call4:
951 /* XXX: Strictly speaking for 64-bit DWARF3 files
952 this ought to be an 8-byte wide computation. */
953 printf ("DW_OP_call4: <0x%" BFD_VMA_FMT "x>",
954 (bfd_signed_vma) byte_get (data, 4) + cu_offset);
955 data += 4;
956 break;
957 case DW_OP_call_ref:
958 /* XXX: Strictly speaking for 64-bit DWARF3 files
959 this ought to be an 8-byte wide computation. */
960 if (dwarf_version == -1)
962 printf (_("(DW_OP_call_ref in frame info)"));
963 /* No way to tell where the next op is, so just bail. */
964 return need_frame_base;
966 if (dwarf_version == 2)
968 printf ("DW_OP_call_ref: <0x%lx>",
969 (long) byte_get (data, pointer_size));
970 data += pointer_size;
972 else
974 printf ("DW_OP_call_ref: <0x%lx>",
975 (long) byte_get (data, offset_size));
976 data += offset_size;
978 break;
979 case DW_OP_form_tls_address:
980 printf ("DW_OP_form_tls_address");
981 break;
982 case DW_OP_call_frame_cfa:
983 printf ("DW_OP_call_frame_cfa");
984 break;
985 case DW_OP_bit_piece:
986 printf ("DW_OP_bit_piece: ");
987 printf ("size: %" BFD_VMA_FMT "u ",
988 read_leb128 (data, &bytes_read, 0));
989 data += bytes_read;
990 printf ("offset: %" BFD_VMA_FMT "u ",
991 read_leb128 (data, &bytes_read, 0));
992 data += bytes_read;
993 break;
995 /* DWARF 4 extensions. */
996 case DW_OP_stack_value:
997 printf ("DW_OP_stack_value");
998 break;
1000 case DW_OP_implicit_value:
1001 printf ("DW_OP_implicit_value");
1002 uvalue = read_leb128 (data, &bytes_read, 0);
1003 data += bytes_read;
1004 display_block (data, uvalue);
1005 data += uvalue;
1006 break;
1008 /* GNU extensions. */
1009 case DW_OP_GNU_push_tls_address:
1010 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
1011 break;
1012 case DW_OP_GNU_uninit:
1013 printf ("DW_OP_GNU_uninit");
1014 /* FIXME: Is there data associated with this OP ? */
1015 break;
1016 case DW_OP_GNU_encoded_addr:
1018 int encoding;
1019 dwarf_vma addr;
1021 encoding = *data++;
1022 addr = get_encoded_value (data, encoding, section);
1023 data += size_of_encoded_value (encoding);
1025 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding);
1026 print_dwarf_vma (addr, pointer_size);
1028 break;
1029 case DW_OP_GNU_implicit_pointer:
1030 /* XXX: Strictly speaking for 64-bit DWARF3 files
1031 this ought to be an 8-byte wide computation. */
1032 if (dwarf_version == -1)
1034 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1035 /* No way to tell where the next op is, so just bail. */
1036 return need_frame_base;
1038 if (dwarf_version == 2)
1040 printf ("DW_OP_GNU_implicit_pointer: "
1041 "<0x%" BFD_VMA_FMT "x> %" BFD_VMA_FMT "d",
1042 (bfd_vma) byte_get (data, pointer_size),
1043 (bfd_signed_vma) read_leb128 (data + pointer_size,
1044 &bytes_read, 1));
1045 data += pointer_size + bytes_read;
1047 else
1049 printf ("DW_OP_GNU_implicit_pointer: "
1050 "<0x%" BFD_VMA_FMT "x> %" BFD_VMA_FMT "d",
1051 (bfd_vma) byte_get (data, offset_size),
1052 (bfd_signed_vma) read_leb128 (data + offset_size,
1053 &bytes_read, 1));
1054 data += offset_size + bytes_read;
1056 break;
1058 /* HP extensions. */
1059 case DW_OP_HP_is_value:
1060 printf ("DW_OP_HP_is_value");
1061 /* FIXME: Is there data associated with this OP ? */
1062 break;
1063 case DW_OP_HP_fltconst4:
1064 printf ("DW_OP_HP_fltconst4");
1065 /* FIXME: Is there data associated with this OP ? */
1066 break;
1067 case DW_OP_HP_fltconst8:
1068 printf ("DW_OP_HP_fltconst8");
1069 /* FIXME: Is there data associated with this OP ? */
1070 break;
1071 case DW_OP_HP_mod_range:
1072 printf ("DW_OP_HP_mod_range");
1073 /* FIXME: Is there data associated with this OP ? */
1074 break;
1075 case DW_OP_HP_unmod_range:
1076 printf ("DW_OP_HP_unmod_range");
1077 /* FIXME: Is there data associated with this OP ? */
1078 break;
1079 case DW_OP_HP_tls:
1080 printf ("DW_OP_HP_tls");
1081 /* FIXME: Is there data associated with this OP ? */
1082 break;
1084 /* PGI (STMicroelectronics) extensions. */
1085 case DW_OP_PGI_omp_thread_num:
1086 /* Pushes the thread number for the current thread as it would be
1087 returned by the standard OpenMP library function:
1088 omp_get_thread_num(). The "current thread" is the thread for
1089 which the expression is being evaluated. */
1090 printf ("DW_OP_PGI_omp_thread_num");
1091 break;
1093 default:
1094 if (op >= DW_OP_lo_user
1095 && op <= DW_OP_hi_user)
1096 printf (_("(User defined location op)"));
1097 else
1098 printf (_("(Unknown location op)"));
1099 /* No way to tell where the next op is, so just bail. */
1100 return need_frame_base;
1103 /* Separate the ops. */
1104 if (data < end)
1105 printf ("; ");
1108 return need_frame_base;
1111 static unsigned char *
1112 read_and_display_attr_value (unsigned long attribute,
1113 unsigned long form,
1114 unsigned char * data,
1115 bfd_vma cu_offset,
1116 bfd_vma pointer_size,
1117 bfd_vma offset_size,
1118 int dwarf_version,
1119 debug_info * debug_info_p,
1120 int do_loc,
1121 struct dwarf_section * section)
1123 bfd_vma uvalue = 0;
1124 unsigned char *block_start = NULL;
1125 unsigned char * orig_data = data;
1126 unsigned int bytes_read;
1128 switch (form)
1130 default:
1131 break;
1133 case DW_FORM_ref_addr:
1134 if (dwarf_version == 2)
1136 uvalue = byte_get (data, pointer_size);
1137 data += pointer_size;
1139 else if (dwarf_version == 3 || dwarf_version == 4)
1141 uvalue = byte_get (data, offset_size);
1142 data += offset_size;
1144 else
1146 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1148 break;
1150 case DW_FORM_addr:
1151 uvalue = byte_get (data, pointer_size);
1152 data += pointer_size;
1153 break;
1155 case DW_FORM_strp:
1156 case DW_FORM_sec_offset:
1157 uvalue = byte_get (data, offset_size);
1158 data += offset_size;
1159 break;
1161 case DW_FORM_flag_present:
1162 uvalue = 1;
1163 break;
1165 case DW_FORM_ref1:
1166 case DW_FORM_flag:
1167 case DW_FORM_data1:
1168 uvalue = byte_get (data++, 1);
1169 break;
1171 case DW_FORM_ref2:
1172 case DW_FORM_data2:
1173 uvalue = byte_get (data, 2);
1174 data += 2;
1175 break;
1177 case DW_FORM_ref4:
1178 case DW_FORM_data4:
1179 uvalue = byte_get (data, 4);
1180 data += 4;
1181 break;
1183 case DW_FORM_sdata:
1184 uvalue = read_leb128 (data, & bytes_read, 1);
1185 data += bytes_read;
1186 break;
1188 case DW_FORM_ref_udata:
1189 case DW_FORM_udata:
1190 uvalue = read_leb128 (data, & bytes_read, 0);
1191 data += bytes_read;
1192 break;
1194 case DW_FORM_indirect:
1195 form = read_leb128 (data, & bytes_read, 0);
1196 data += bytes_read;
1197 if (!do_loc)
1198 printf (" %s", get_FORM_name (form));
1199 return read_and_display_attr_value (attribute, form, data,
1200 cu_offset, pointer_size,
1201 offset_size, dwarf_version,
1202 debug_info_p, do_loc,
1203 section);
1206 switch (form)
1208 case DW_FORM_ref_addr:
1209 if (!do_loc)
1210 printf (" <0x%" BFD_VMA_FMT "x>", uvalue);
1211 break;
1213 case DW_FORM_ref1:
1214 case DW_FORM_ref2:
1215 case DW_FORM_ref4:
1216 case DW_FORM_ref_udata:
1217 if (!do_loc)
1218 printf (" <0x%" BFD_VMA_FMT "x>", uvalue + cu_offset);
1219 break;
1221 case DW_FORM_data4:
1222 case DW_FORM_addr:
1223 case DW_FORM_sec_offset:
1224 if (!do_loc)
1225 printf (" 0x%" BFD_VMA_FMT "x", uvalue);
1226 break;
1228 case DW_FORM_flag_present:
1229 case DW_FORM_flag:
1230 case DW_FORM_data1:
1231 case DW_FORM_data2:
1232 case DW_FORM_sdata:
1233 case DW_FORM_udata:
1234 if (!do_loc)
1235 printf (" %" BFD_VMA_FMT "d", uvalue);
1236 break;
1238 case DW_FORM_ref8:
1239 case DW_FORM_data8:
1240 if (!do_loc)
1242 uvalue = byte_get (data, 4);
1243 printf (" 0x%" BFD_VMA_FMT "x", uvalue);
1244 printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
1246 if ((do_loc || do_debug_loc || do_debug_ranges)
1247 && num_debug_info_entries == 0)
1249 if (sizeof (uvalue) == 8)
1250 uvalue = byte_get (data, 8);
1251 else
1252 error (_("DW_FORM_data8 is unsupported when sizeof (bfd_vma) != 8\n"));
1254 data += 8;
1255 break;
1257 case DW_FORM_string:
1258 if (!do_loc)
1259 printf (" %s", data);
1260 data += strlen ((char *) data) + 1;
1261 break;
1263 case DW_FORM_block:
1264 case DW_FORM_exprloc:
1265 uvalue = read_leb128 (data, & bytes_read, 0);
1266 block_start = data + bytes_read;
1267 if (do_loc)
1268 data = block_start + uvalue;
1269 else
1270 data = display_block (block_start, uvalue);
1271 break;
1273 case DW_FORM_block1:
1274 uvalue = byte_get (data, 1);
1275 block_start = data + 1;
1276 if (do_loc)
1277 data = block_start + uvalue;
1278 else
1279 data = display_block (block_start, uvalue);
1280 break;
1282 case DW_FORM_block2:
1283 uvalue = byte_get (data, 2);
1284 block_start = data + 2;
1285 if (do_loc)
1286 data = block_start + uvalue;
1287 else
1288 data = display_block (block_start, uvalue);
1289 break;
1291 case DW_FORM_block4:
1292 uvalue = byte_get (data, 4);
1293 block_start = data + 4;
1294 if (do_loc)
1295 data = block_start + uvalue;
1296 else
1297 data = display_block (block_start, uvalue);
1298 break;
1300 case DW_FORM_strp:
1301 if (!do_loc)
1302 printf (_(" (indirect string, offset: 0x%s): %s"),
1303 dwarf_vmatoa ("x", uvalue),
1304 fetch_indirect_string (uvalue));
1305 break;
1307 case DW_FORM_indirect:
1308 /* Handled above. */
1309 break;
1311 case DW_FORM_ref_sig8:
1312 if (!do_loc)
1314 int i;
1315 printf (" signature: ");
1316 for (i = 0; i < 8; i++)
1318 printf ("%02x", (unsigned) byte_get (data, 1));
1319 data += 1;
1322 else
1323 data += 8;
1324 break;
1326 default:
1327 warn (_("Unrecognized form: %lu\n"), form);
1328 break;
1331 if ((do_loc || do_debug_loc || do_debug_ranges)
1332 && num_debug_info_entries == 0)
1334 switch (attribute)
1336 case DW_AT_frame_base:
1337 have_frame_base = 1;
1338 case DW_AT_location:
1339 case DW_AT_string_length:
1340 case DW_AT_return_addr:
1341 case DW_AT_data_member_location:
1342 case DW_AT_vtable_elem_location:
1343 case DW_AT_segment:
1344 case DW_AT_static_link:
1345 case DW_AT_use_location:
1346 if (form == DW_FORM_data4
1347 || form == DW_FORM_data8
1348 || form == DW_FORM_sec_offset)
1350 /* Process location list. */
1351 unsigned int lmax = debug_info_p->max_loc_offsets;
1352 unsigned int num = debug_info_p->num_loc_offsets;
1354 if (lmax == 0 || num >= lmax)
1356 lmax += 1024;
1357 debug_info_p->loc_offsets = (bfd_vma *)
1358 xcrealloc (debug_info_p->loc_offsets,
1359 lmax, sizeof (*debug_info_p->loc_offsets));
1360 debug_info_p->have_frame_base = (int *)
1361 xcrealloc (debug_info_p->have_frame_base,
1362 lmax, sizeof (*debug_info_p->have_frame_base));
1363 debug_info_p->max_loc_offsets = lmax;
1365 debug_info_p->loc_offsets [num] = uvalue;
1366 debug_info_p->have_frame_base [num] = have_frame_base;
1367 debug_info_p->num_loc_offsets++;
1369 break;
1371 case DW_AT_low_pc:
1372 if (need_base_address)
1373 debug_info_p->base_address = uvalue;
1374 break;
1376 case DW_AT_ranges:
1377 if (form == DW_FORM_data4
1378 || form == DW_FORM_data8
1379 || form == DW_FORM_sec_offset)
1381 /* Process range list. */
1382 unsigned int lmax = debug_info_p->max_range_lists;
1383 unsigned int num = debug_info_p->num_range_lists;
1385 if (lmax == 0 || num >= lmax)
1387 lmax += 1024;
1388 debug_info_p->range_lists = (bfd_vma *)
1389 xcrealloc (debug_info_p->range_lists,
1390 lmax, sizeof (*debug_info_p->range_lists));
1391 debug_info_p->max_range_lists = lmax;
1393 debug_info_p->range_lists [num] = uvalue;
1394 debug_info_p->num_range_lists++;
1396 break;
1398 default:
1399 break;
1403 if (do_loc)
1404 return data;
1406 /* For some attributes we can display further information. */
1407 printf ("\t");
1409 switch (attribute)
1411 case DW_AT_inline:
1412 switch (uvalue)
1414 case DW_INL_not_inlined:
1415 printf (_("(not inlined)"));
1416 break;
1417 case DW_INL_inlined:
1418 printf (_("(inlined)"));
1419 break;
1420 case DW_INL_declared_not_inlined:
1421 printf (_("(declared as inline but ignored)"));
1422 break;
1423 case DW_INL_declared_inlined:
1424 printf (_("(declared as inline and inlined)"));
1425 break;
1426 default:
1427 printf (_(" (Unknown inline attribute value: %s)"),
1428 dwarf_vmatoa ("x", uvalue));
1429 break;
1431 break;
1433 case DW_AT_language:
1434 switch (uvalue)
1436 /* Ordered by the numeric value of these constants. */
1437 case DW_LANG_C89: printf ("(ANSI C)"); break;
1438 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1439 case DW_LANG_Ada83: printf ("(Ada)"); break;
1440 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1441 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1442 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1443 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1444 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1445 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1446 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1447 /* DWARF 2.1 values. */
1448 case DW_LANG_Java: printf ("(Java)"); break;
1449 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1450 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1451 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1452 /* DWARF 3 values. */
1453 case DW_LANG_PLI: printf ("(PLI)"); break;
1454 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1455 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1456 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1457 case DW_LANG_D: printf ("(D)"); break;
1458 /* DWARF 4 values. */
1459 case DW_LANG_Python: printf ("(Python)"); break;
1460 /* MIPS extension. */
1461 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1462 /* UPC extension. */
1463 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1464 default:
1465 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1466 printf ("(implementation defined: %" BFD_VMA_FMT "x)", uvalue);
1467 else
1468 printf ("(Unknown: %" BFD_VMA_FMT "x)", uvalue);
1469 break;
1471 break;
1473 case DW_AT_encoding:
1474 switch (uvalue)
1476 case DW_ATE_void: printf ("(void)"); break;
1477 case DW_ATE_address: printf ("(machine address)"); break;
1478 case DW_ATE_boolean: printf ("(boolean)"); break;
1479 case DW_ATE_complex_float: printf ("(complex float)"); break;
1480 case DW_ATE_float: printf ("(float)"); break;
1481 case DW_ATE_signed: printf ("(signed)"); break;
1482 case DW_ATE_signed_char: printf ("(signed char)"); break;
1483 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1484 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1485 /* DWARF 2.1 values: */
1486 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1487 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1488 /* DWARF 3 values: */
1489 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1490 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1491 case DW_ATE_edited: printf ("(edited)"); break;
1492 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1493 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1494 /* HP extensions: */
1495 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1496 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1497 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1498 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1499 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1500 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1501 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1503 default:
1504 if (uvalue >= DW_ATE_lo_user
1505 && uvalue <= DW_ATE_hi_user)
1506 printf ("(user defined type)");
1507 else
1508 printf ("(unknown type)");
1509 break;
1511 break;
1513 case DW_AT_accessibility:
1514 switch (uvalue)
1516 case DW_ACCESS_public: printf ("(public)"); break;
1517 case DW_ACCESS_protected: printf ("(protected)"); break;
1518 case DW_ACCESS_private: printf ("(private)"); break;
1519 default:
1520 printf ("(unknown accessibility)");
1521 break;
1523 break;
1525 case DW_AT_visibility:
1526 switch (uvalue)
1528 case DW_VIS_local: printf ("(local)"); break;
1529 case DW_VIS_exported: printf ("(exported)"); break;
1530 case DW_VIS_qualified: printf ("(qualified)"); break;
1531 default: printf ("(unknown visibility)"); break;
1533 break;
1535 case DW_AT_virtuality:
1536 switch (uvalue)
1538 case DW_VIRTUALITY_none: printf ("(none)"); break;
1539 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1540 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1541 default: printf ("(unknown virtuality)"); break;
1543 break;
1545 case DW_AT_identifier_case:
1546 switch (uvalue)
1548 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1549 case DW_ID_up_case: printf ("(up_case)"); break;
1550 case DW_ID_down_case: printf ("(down_case)"); break;
1551 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1552 default: printf ("(unknown case)"); break;
1554 break;
1556 case DW_AT_calling_convention:
1557 switch (uvalue)
1559 case DW_CC_normal: printf ("(normal)"); break;
1560 case DW_CC_program: printf ("(program)"); break;
1561 case DW_CC_nocall: printf ("(nocall)"); break;
1562 default:
1563 if (uvalue >= DW_CC_lo_user
1564 && uvalue <= DW_CC_hi_user)
1565 printf ("(user defined)");
1566 else
1567 printf ("(unknown convention)");
1569 break;
1571 case DW_AT_ordering:
1572 switch (uvalue)
1574 case -1: printf ("(undefined)"); break;
1575 case 0: printf ("(row major)"); break;
1576 case 1: printf ("(column major)"); break;
1578 break;
1580 case DW_AT_frame_base:
1581 have_frame_base = 1;
1582 case DW_AT_location:
1583 case DW_AT_string_length:
1584 case DW_AT_return_addr:
1585 case DW_AT_data_member_location:
1586 case DW_AT_vtable_elem_location:
1587 case DW_AT_segment:
1588 case DW_AT_static_link:
1589 case DW_AT_use_location:
1590 if (form == DW_FORM_data4
1591 || form == DW_FORM_data8
1592 || form == DW_FORM_sec_offset)
1593 printf (_("(location list)"));
1594 /* Fall through. */
1595 case DW_AT_allocated:
1596 case DW_AT_associated:
1597 case DW_AT_data_location:
1598 case DW_AT_stride:
1599 case DW_AT_upper_bound:
1600 case DW_AT_lower_bound:
1601 if (block_start)
1603 int need_frame_base;
1605 printf ("(");
1606 need_frame_base = decode_location_expression (block_start,
1607 pointer_size,
1608 offset_size,
1609 dwarf_version,
1610 uvalue,
1611 cu_offset, section);
1612 printf (")");
1613 if (need_frame_base && !have_frame_base)
1614 printf (_(" [without DW_AT_frame_base]"));
1616 break;
1618 case DW_AT_import:
1620 if (form == DW_FORM_ref_sig8)
1621 break;
1623 if (form == DW_FORM_ref1
1624 || form == DW_FORM_ref2
1625 || form == DW_FORM_ref4)
1626 uvalue += cu_offset;
1628 if (uvalue >= section->size)
1629 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1630 dwarf_vmatoa ("x", uvalue),
1631 (unsigned long) (orig_data - section->start));
1632 else
1634 unsigned long abbrev_number;
1635 abbrev_entry * entry;
1637 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
1639 printf ("[Abbrev Number: %ld", abbrev_number);
1640 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1641 if (entry->entry == abbrev_number)
1642 break;
1643 if (entry != NULL)
1644 printf (" (%s)", get_TAG_name (entry->tag));
1645 printf ("]");
1648 break;
1650 default:
1651 break;
1654 return data;
1657 static char *
1658 get_AT_name (unsigned long attribute)
1660 switch (attribute)
1662 case DW_AT_sibling: return "DW_AT_sibling";
1663 case DW_AT_location: return "DW_AT_location";
1664 case DW_AT_name: return "DW_AT_name";
1665 case DW_AT_ordering: return "DW_AT_ordering";
1666 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1667 case DW_AT_byte_size: return "DW_AT_byte_size";
1668 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1669 case DW_AT_bit_size: return "DW_AT_bit_size";
1670 case DW_AT_element_list: return "DW_AT_element_list";
1671 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1672 case DW_AT_low_pc: return "DW_AT_low_pc";
1673 case DW_AT_high_pc: return "DW_AT_high_pc";
1674 case DW_AT_language: return "DW_AT_language";
1675 case DW_AT_member: return "DW_AT_member";
1676 case DW_AT_discr: return "DW_AT_discr";
1677 case DW_AT_discr_value: return "DW_AT_discr_value";
1678 case DW_AT_visibility: return "DW_AT_visibility";
1679 case DW_AT_import: return "DW_AT_import";
1680 case DW_AT_string_length: return "DW_AT_string_length";
1681 case DW_AT_common_reference: return "DW_AT_common_reference";
1682 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1683 case DW_AT_const_value: return "DW_AT_const_value";
1684 case DW_AT_containing_type: return "DW_AT_containing_type";
1685 case DW_AT_default_value: return "DW_AT_default_value";
1686 case DW_AT_inline: return "DW_AT_inline";
1687 case DW_AT_is_optional: return "DW_AT_is_optional";
1688 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1689 case DW_AT_producer: return "DW_AT_producer";
1690 case DW_AT_prototyped: return "DW_AT_prototyped";
1691 case DW_AT_return_addr: return "DW_AT_return_addr";
1692 case DW_AT_start_scope: return "DW_AT_start_scope";
1693 case DW_AT_stride_size: return "DW_AT_stride_size";
1694 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1695 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1696 case DW_AT_accessibility: return "DW_AT_accessibility";
1697 case DW_AT_address_class: return "DW_AT_address_class";
1698 case DW_AT_artificial: return "DW_AT_artificial";
1699 case DW_AT_base_types: return "DW_AT_base_types";
1700 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1701 case DW_AT_count: return "DW_AT_count";
1702 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1703 case DW_AT_decl_column: return "DW_AT_decl_column";
1704 case DW_AT_decl_file: return "DW_AT_decl_file";
1705 case DW_AT_decl_line: return "DW_AT_decl_line";
1706 case DW_AT_declaration: return "DW_AT_declaration";
1707 case DW_AT_discr_list: return "DW_AT_discr_list";
1708 case DW_AT_encoding: return "DW_AT_encoding";
1709 case DW_AT_external: return "DW_AT_external";
1710 case DW_AT_frame_base: return "DW_AT_frame_base";
1711 case DW_AT_friend: return "DW_AT_friend";
1712 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1713 case DW_AT_macro_info: return "DW_AT_macro_info";
1714 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1715 case DW_AT_priority: return "DW_AT_priority";
1716 case DW_AT_segment: return "DW_AT_segment";
1717 case DW_AT_specification: return "DW_AT_specification";
1718 case DW_AT_static_link: return "DW_AT_static_link";
1719 case DW_AT_type: return "DW_AT_type";
1720 case DW_AT_use_location: return "DW_AT_use_location";
1721 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1722 case DW_AT_virtuality: return "DW_AT_virtuality";
1723 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1724 /* DWARF 2.1 values. */
1725 case DW_AT_allocated: return "DW_AT_allocated";
1726 case DW_AT_associated: return "DW_AT_associated";
1727 case DW_AT_data_location: return "DW_AT_data_location";
1728 case DW_AT_stride: return "DW_AT_stride";
1729 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1730 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1731 case DW_AT_extension: return "DW_AT_extension";
1732 case DW_AT_ranges: return "DW_AT_ranges";
1733 case DW_AT_trampoline: return "DW_AT_trampoline";
1734 case DW_AT_call_column: return "DW_AT_call_column";
1735 case DW_AT_call_file: return "DW_AT_call_file";
1736 case DW_AT_call_line: return "DW_AT_call_line";
1737 case DW_AT_description: return "DW_AT_description";
1738 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1739 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1740 case DW_AT_small: return "DW_AT_small";
1741 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1742 case DW_AT_digit_count: return "DW_AT_digit_count";
1743 case DW_AT_picture_string: return "DW_AT_picture_string";
1744 case DW_AT_mutable: return "DW_AT_mutable";
1745 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1746 case DW_AT_explicit: return "DW_AT_explicit";
1747 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1748 case DW_AT_endianity: return "DW_AT_endianity";
1749 case DW_AT_elemental: return "DW_AT_elemental";
1750 case DW_AT_pure: return "DW_AT_pure";
1751 case DW_AT_recursive: return "DW_AT_recursive";
1752 /* DWARF 4 values. */
1753 case DW_AT_signature: return "DW_AT_signature";
1754 case DW_AT_main_subprogram: return "DW_AT_main_subprogram";
1755 case DW_AT_data_bit_offset: return "DW_AT_data_bit_offset";
1756 case DW_AT_const_expr: return "DW_AT_const_expr";
1757 case DW_AT_enum_class: return "DW_AT_enum_class";
1758 case DW_AT_linkage_name: return "DW_AT_linkage_name";
1760 /* HP and SGI/MIPS extensions. */
1761 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1762 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1763 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1764 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1765 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1766 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1767 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1768 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1769 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1770 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1772 /* HP Extensions. */
1773 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
1774 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1775 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1776 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1777 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1778 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1779 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1780 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1781 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1782 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1783 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1784 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1785 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1787 /* One value is shared by the MIPS and HP extensions: */
1788 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1790 /* GNU extensions. */
1791 case DW_AT_sf_names: return "DW_AT_sf_names";
1792 case DW_AT_src_info: return "DW_AT_src_info";
1793 case DW_AT_mac_info: return "DW_AT_mac_info";
1794 case DW_AT_src_coords: return "DW_AT_src_coords";
1795 case DW_AT_body_begin: return "DW_AT_body_begin";
1796 case DW_AT_body_end: return "DW_AT_body_end";
1797 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
1798 case DW_AT_GNU_guarded_by: return "DW_AT_GNU_guarded_by";
1799 case DW_AT_GNU_pt_guarded_by: return "DW_AT_GNU_pt_guarded_by";
1800 case DW_AT_GNU_guarded: return "DW_AT_GNU_guarded";
1801 case DW_AT_GNU_pt_guarded: return "DW_AT_GNU_pt_guarded";
1802 case DW_AT_GNU_locks_excluded: return "DW_AT_GNU_locks_excluded";
1803 case DW_AT_GNU_exclusive_locks_required: return "DW_AT_GNU_exclusive_locks_required";
1804 case DW_AT_GNU_shared_locks_required: return "DW_AT_GNU_shared_locks_required";
1805 case DW_AT_GNU_odr_signature: return "DW_AT_GNU_odr_signature";
1806 case DW_AT_use_GNAT_descriptive_type: return "DW_AT_use_GNAT_descriptive_type";
1807 case DW_AT_GNAT_descriptive_type: return "DW_AT_GNAT_descriptive_type";
1809 /* UPC extension. */
1810 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
1812 /* PGI (STMicroelectronics) extensions. */
1813 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1814 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1815 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1817 default:
1819 static char buffer[100];
1821 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1822 attribute);
1823 return buffer;
1828 static unsigned char *
1829 read_and_display_attr (unsigned long attribute,
1830 unsigned long form,
1831 unsigned char * data,
1832 bfd_vma cu_offset,
1833 bfd_vma pointer_size,
1834 bfd_vma offset_size,
1835 int dwarf_version,
1836 debug_info * debug_info_p,
1837 int do_loc,
1838 struct dwarf_section * section)
1840 if (!do_loc)
1841 printf (" %-18s:", get_AT_name (attribute));
1842 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1843 pointer_size, offset_size,
1844 dwarf_version, debug_info_p,
1845 do_loc, section);
1846 if (!do_loc)
1847 printf ("\n");
1848 return data;
1852 /* Process the contents of a .debug_info section. If do_loc is non-zero
1853 then we are scanning for location lists and we do not want to display
1854 anything to the user. If do_types is non-zero, we are processing
1855 a .debug_types section instead of a .debug_info section. */
1857 static int
1858 process_debug_info (struct dwarf_section *section,
1859 void *file,
1860 enum dwarf_section_display_enum abbrev_sec,
1861 int do_loc,
1862 int do_types)
1864 unsigned char *start = section->start;
1865 unsigned char *end = start + section->size;
1866 unsigned char *section_begin;
1867 unsigned int unit;
1868 unsigned int num_units = 0;
1870 if ((do_loc || do_debug_loc || do_debug_ranges)
1871 && num_debug_info_entries == 0
1872 && ! do_types)
1874 unsigned long length;
1876 /* First scan the section to get the number of comp units. */
1877 for (section_begin = start, num_units = 0; section_begin < end;
1878 num_units ++)
1880 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1881 will be the length. For a 64-bit DWARF section, it'll be
1882 the escape code 0xffffffff followed by an 8 byte length. */
1883 length = byte_get (section_begin, 4);
1885 if (length == 0xffffffff)
1887 length = byte_get (section_begin + 4, 8);
1888 section_begin += length + 12;
1890 else if (length >= 0xfffffff0 && length < 0xffffffff)
1892 warn (_("Reserved length value (%lx) found in section %s\n"), length, section->name);
1893 return 0;
1895 else
1896 section_begin += length + 4;
1898 /* Negative values are illegal, they may even cause infinite
1899 looping. This can happen if we can't accurately apply
1900 relocations to an object file. */
1901 if ((signed long) length <= 0)
1903 warn (_("Corrupt unit length (%lx) found in section %s\n"), length, section->name);
1904 return 0;
1908 if (num_units == 0)
1910 error (_("No comp units in %s section ?"), section->name);
1911 return 0;
1914 /* Then allocate an array to hold the information. */
1915 debug_information = (debug_info *) cmalloc (num_units,
1916 sizeof (* debug_information));
1917 if (debug_information == NULL)
1919 error (_("Not enough memory for a debug info array of %u entries"),
1920 num_units);
1921 return 0;
1925 if (!do_loc)
1927 printf (_("Contents of the %s section:\n\n"), section->name);
1929 load_debug_section (str, file);
1932 load_debug_section (abbrev_sec, file);
1933 if (debug_displays [abbrev_sec].section.start == NULL)
1935 warn (_("Unable to locate %s section!\n"),
1936 debug_displays [abbrev_sec].section.name);
1937 return 0;
1940 for (section_begin = start, unit = 0; start < end; unit++)
1942 DWARF2_Internal_CompUnit compunit;
1943 unsigned char *hdrptr;
1944 unsigned char *tags;
1945 int level;
1946 bfd_vma cu_offset;
1947 int offset_size;
1948 int initial_length_size;
1949 unsigned char signature[8] = { 0 };
1950 unsigned long type_offset = 0;
1952 hdrptr = start;
1954 compunit.cu_length = byte_get (hdrptr, 4);
1955 hdrptr += 4;
1957 if (compunit.cu_length == 0xffffffff)
1959 compunit.cu_length = byte_get (hdrptr, 8);
1960 hdrptr += 8;
1961 offset_size = 8;
1962 initial_length_size = 12;
1964 else
1966 offset_size = 4;
1967 initial_length_size = 4;
1970 compunit.cu_version = byte_get (hdrptr, 2);
1971 hdrptr += 2;
1973 cu_offset = start - section_begin;
1975 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
1976 hdrptr += offset_size;
1978 compunit.cu_pointer_size = byte_get (hdrptr, 1);
1979 hdrptr += 1;
1981 if (do_types)
1983 int i;
1985 for (i = 0; i < 8; i++)
1987 signature[i] = byte_get (hdrptr, 1);
1988 hdrptr += 1;
1991 type_offset = byte_get (hdrptr, offset_size);
1992 hdrptr += offset_size;
1995 if ((do_loc || do_debug_loc || do_debug_ranges)
1996 && num_debug_info_entries == 0
1997 && ! do_types)
1999 debug_information [unit].cu_offset = cu_offset;
2000 debug_information [unit].pointer_size
2001 = compunit.cu_pointer_size;
2002 debug_information [unit].offset_size = offset_size;
2003 debug_information [unit].dwarf_version = compunit.cu_version;
2004 debug_information [unit].base_address = 0;
2005 debug_information [unit].loc_offsets = NULL;
2006 debug_information [unit].have_frame_base = NULL;
2007 debug_information [unit].max_loc_offsets = 0;
2008 debug_information [unit].num_loc_offsets = 0;
2009 debug_information [unit].range_lists = NULL;
2010 debug_information [unit].max_range_lists= 0;
2011 debug_information [unit].num_range_lists = 0;
2014 if (!do_loc)
2016 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2017 dwarf_vmatoa ("x", cu_offset));
2018 printf (_(" Length: 0x%s (%s)\n"),
2019 dwarf_vmatoa ("x", compunit.cu_length),
2020 initial_length_size == 8 ? "64-bit" : "32-bit");
2021 printf (_(" Version: %d\n"), compunit.cu_version);
2022 printf (_(" Abbrev Offset: %s\n"),
2023 dwarf_vmatoa ("d", compunit.cu_abbrev_offset));
2024 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2025 if (do_types)
2027 int i;
2028 printf (_(" Signature: "));
2029 for (i = 0; i < 8; i++)
2030 printf ("%02x", signature[i]);
2031 printf ("\n");
2032 printf (_(" Type Offset: 0x%lx\n"), type_offset);
2036 if (cu_offset + compunit.cu_length + initial_length_size
2037 > section->size)
2039 warn (_("Debug info is corrupted, length of CU at %s"
2040 " extends beyond end of section (length = %s)\n"),
2041 dwarf_vmatoa ("x", cu_offset),
2042 dwarf_vmatoa ("x", compunit.cu_length));
2043 break;
2045 tags = hdrptr;
2046 start += compunit.cu_length + initial_length_size;
2048 if (compunit.cu_version != 2
2049 && compunit.cu_version != 3
2050 && compunit.cu_version != 4)
2052 warn (_("CU at offset %s contains corrupt or "
2053 "unsupported version number: %d.\n"),
2054 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2055 continue;
2058 free_abbrevs ();
2060 /* Process the abbrevs used by this compilation unit. DWARF
2061 sections under Mach-O have non-zero addresses. */
2062 if (compunit.cu_abbrev_offset >= debug_displays [abbrev_sec].section.size)
2063 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2064 (unsigned long) compunit.cu_abbrev_offset,
2065 (unsigned long) debug_displays [abbrev_sec].section.size);
2066 else
2067 process_abbrev_section
2068 ((unsigned char *) debug_displays [abbrev_sec].section.start
2069 + compunit.cu_abbrev_offset,
2070 (unsigned char *) debug_displays [abbrev_sec].section.start
2071 + debug_displays [abbrev_sec].section.size);
2073 level = 0;
2074 while (tags < start)
2076 unsigned int bytes_read;
2077 unsigned long abbrev_number;
2078 unsigned long die_offset;
2079 abbrev_entry *entry;
2080 abbrev_attr *attr;
2082 die_offset = tags - section_begin;
2084 abbrev_number = read_leb128 (tags, & bytes_read, 0);
2085 tags += bytes_read;
2087 /* A null DIE marks the end of a list of siblings or it may also be
2088 a section padding. */
2089 if (abbrev_number == 0)
2091 /* Check if it can be a section padding for the last CU. */
2092 if (level == 0 && start == end)
2094 unsigned char *chk;
2096 for (chk = tags; chk < start; chk++)
2097 if (*chk != 0)
2098 break;
2099 if (chk == start)
2100 break;
2103 --level;
2104 if (level < 0)
2106 static unsigned num_bogus_warns = 0;
2108 if (num_bogus_warns < 3)
2110 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
2111 die_offset);
2112 num_bogus_warns ++;
2113 if (num_bogus_warns == 3)
2114 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2117 continue;
2120 if (!do_loc)
2121 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2122 level, die_offset, abbrev_number);
2124 /* Scan through the abbreviation list until we reach the
2125 correct entry. */
2126 for (entry = first_abbrev;
2127 entry && entry->entry != abbrev_number;
2128 entry = entry->next)
2129 continue;
2131 if (entry == NULL)
2133 if (!do_loc)
2135 printf ("\n");
2136 fflush (stdout);
2138 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2139 die_offset, abbrev_number);
2140 return 0;
2143 if (!do_loc)
2144 printf (" (%s)\n", get_TAG_name (entry->tag));
2146 switch (entry->tag)
2148 default:
2149 need_base_address = 0;
2150 break;
2151 case DW_TAG_compile_unit:
2152 need_base_address = 1;
2153 break;
2154 case DW_TAG_entry_point:
2155 case DW_TAG_subprogram:
2156 need_base_address = 0;
2157 /* Assuming that there is no DW_AT_frame_base. */
2158 have_frame_base = 0;
2159 break;
2162 for (attr = entry->first_attr; attr; attr = attr->next)
2164 if (! do_loc)
2165 /* Show the offset from where the tag was extracted. */
2166 printf (" <%2lx>", (unsigned long)(tags - section_begin));
2168 tags = read_and_display_attr (attr->attribute,
2169 attr->form,
2170 tags, cu_offset,
2171 compunit.cu_pointer_size,
2172 offset_size,
2173 compunit.cu_version,
2174 debug_information + unit,
2175 do_loc, section);
2178 if (entry->children)
2179 ++level;
2183 /* Set num_debug_info_entries here so that it can be used to check if
2184 we need to process .debug_loc and .debug_ranges sections. */
2185 if ((do_loc || do_debug_loc || do_debug_ranges)
2186 && num_debug_info_entries == 0
2187 && ! do_types)
2188 num_debug_info_entries = num_units;
2190 if (!do_loc)
2192 printf ("\n");
2195 return 1;
2198 /* Locate and scan the .debug_info section in the file and record the pointer
2199 sizes and offsets for the compilation units in it. Usually an executable
2200 will have just one pointer size, but this is not guaranteed, and so we try
2201 not to make any assumptions. Returns zero upon failure, or the number of
2202 compilation units upon success. */
2204 static unsigned int
2205 load_debug_info (void * file)
2207 /* Reset the last pointer size so that we can issue correct error
2208 messages if we are displaying the contents of more than one section. */
2209 last_pointer_size = 0;
2210 warned_about_missing_comp_units = FALSE;
2212 /* If we have already tried and failed to load the .debug_info
2213 section then do not bother to repear the task. */
2214 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2215 return 0;
2217 /* If we already have the information there is nothing else to do. */
2218 if (num_debug_info_entries > 0)
2219 return num_debug_info_entries;
2221 if (load_debug_section (info, file)
2222 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2223 return num_debug_info_entries;
2225 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2226 return 0;
2229 static int
2230 display_debug_lines_raw (struct dwarf_section *section,
2231 unsigned char *data,
2232 unsigned char *end)
2234 unsigned char *start = section->start;
2236 printf (_("Raw dump of debug contents of section %s:\n\n"),
2237 section->name);
2239 while (data < end)
2241 DWARF2_Internal_LineInfo linfo;
2242 unsigned char *standard_opcodes;
2243 unsigned char *end_of_sequence;
2244 unsigned char *hdrptr;
2245 unsigned long hdroff;
2246 int initial_length_size;
2247 int offset_size;
2248 int i;
2250 hdrptr = data;
2251 hdroff = hdrptr - start;
2253 /* Check the length of the block. */
2254 linfo.li_length = byte_get (hdrptr, 4);
2255 hdrptr += 4;
2257 if (linfo.li_length == 0xffffffff)
2259 /* This section is 64-bit DWARF 3. */
2260 linfo.li_length = byte_get (hdrptr, 8);
2261 hdrptr += 8;
2262 offset_size = 8;
2263 initial_length_size = 12;
2265 else
2267 offset_size = 4;
2268 initial_length_size = 4;
2271 if (linfo.li_length + initial_length_size > section->size)
2273 warn
2274 (_("The information in section %s appears to be corrupt - the section is too small\n"),
2275 section->name);
2276 return 0;
2279 /* Check its version number. */
2280 linfo.li_version = byte_get (hdrptr, 2);
2281 hdrptr += 2;
2282 if (linfo.li_version != 2
2283 && linfo.li_version != 3
2284 && linfo.li_version != 4)
2286 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2287 return 0;
2290 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2291 hdrptr += offset_size;
2292 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2293 hdrptr++;
2294 if (linfo.li_version >= 4)
2296 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2297 hdrptr++;
2298 if (linfo.li_max_ops_per_insn == 0)
2300 warn (_("Invalid maximum operations per insn.\n"));
2301 return 0;
2304 else
2305 linfo.li_max_ops_per_insn = 1;
2306 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2307 hdrptr++;
2308 linfo.li_line_base = byte_get (hdrptr, 1);
2309 hdrptr++;
2310 linfo.li_line_range = byte_get (hdrptr, 1);
2311 hdrptr++;
2312 linfo.li_opcode_base = byte_get (hdrptr, 1);
2313 hdrptr++;
2315 /* Sign extend the line base field. */
2316 linfo.li_line_base <<= 24;
2317 linfo.li_line_base >>= 24;
2319 printf (_(" Offset: 0x%lx\n"), hdroff);
2320 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2321 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2322 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2323 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2324 if (linfo.li_version >= 4)
2325 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2326 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2327 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2328 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2329 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2331 end_of_sequence = data + linfo.li_length + initial_length_size;
2333 reset_state_machine (linfo.li_default_is_stmt);
2335 /* Display the contents of the Opcodes table. */
2336 standard_opcodes = hdrptr;
2338 printf (_("\n Opcodes:\n"));
2340 for (i = 1; i < linfo.li_opcode_base; i++)
2341 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2343 /* Display the contents of the Directory table. */
2344 data = standard_opcodes + linfo.li_opcode_base - 1;
2346 if (*data == 0)
2347 printf (_("\n The Directory Table is empty.\n"));
2348 else
2350 printf (_("\n The Directory Table:\n"));
2352 while (*data != 0)
2354 printf (" %s\n", data);
2356 data += strlen ((char *) data) + 1;
2360 /* Skip the NUL at the end of the table. */
2361 data++;
2363 /* Display the contents of the File Name table. */
2364 if (*data == 0)
2365 printf (_("\n The File Name Table is empty.\n"));
2366 else
2368 printf (_("\n The File Name Table:\n"));
2369 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2371 while (*data != 0)
2373 unsigned char *name;
2374 unsigned int bytes_read;
2376 printf (" %d\t", ++state_machine_regs.last_file_entry);
2377 name = data;
2379 data += strlen ((char *) data) + 1;
2381 printf ("%" BFD_VMA_FMT "u\t",
2382 read_leb128 (data, & bytes_read, 0));
2383 data += bytes_read;
2384 printf ("%" BFD_VMA_FMT "u\t",
2385 read_leb128 (data, & bytes_read, 0));
2386 data += bytes_read;
2387 printf ("%" BFD_VMA_FMT "u\t",
2388 read_leb128 (data, & bytes_read, 0));
2389 data += bytes_read;
2390 printf ("%s\n", name);
2394 /* Skip the NUL at the end of the table. */
2395 data++;
2397 /* Now display the statements. */
2398 printf (_("\n Line Number Statements:\n"));
2400 while (data < end_of_sequence)
2402 unsigned char op_code;
2403 int adv;
2404 unsigned long int uladv;
2405 unsigned int bytes_read;
2407 op_code = *data++;
2409 if (op_code >= linfo.li_opcode_base)
2411 op_code -= linfo.li_opcode_base;
2412 uladv = (op_code / linfo.li_line_range);
2413 if (linfo.li_max_ops_per_insn == 1)
2415 uladv *= linfo.li_min_insn_length;
2416 state_machine_regs.address += uladv;
2417 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2418 op_code, uladv, state_machine_regs.address);
2420 else
2422 state_machine_regs.address
2423 += ((state_machine_regs.op_index + uladv)
2424 / linfo.li_max_ops_per_insn)
2425 * linfo.li_min_insn_length;
2426 state_machine_regs.op_index
2427 = (state_machine_regs.op_index + uladv)
2428 % linfo.li_max_ops_per_insn;
2429 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx[%d]"),
2430 op_code, uladv, state_machine_regs.address,
2431 state_machine_regs.op_index);
2433 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2434 state_machine_regs.line += adv;
2435 printf (_(" and Line by %d to %d\n"),
2436 adv, state_machine_regs.line);
2438 else switch (op_code)
2440 case DW_LNS_extended_op:
2441 data += process_extended_line_op (data, linfo.li_default_is_stmt);
2442 break;
2444 case DW_LNS_copy:
2445 printf (_(" Copy\n"));
2446 break;
2448 case DW_LNS_advance_pc:
2449 uladv = read_leb128 (data, & bytes_read, 0);
2450 data += bytes_read;
2451 if (linfo.li_max_ops_per_insn == 1)
2453 uladv *= linfo.li_min_insn_length;
2454 state_machine_regs.address += uladv;
2455 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv,
2456 state_machine_regs.address);
2458 else
2460 state_machine_regs.address
2461 += ((state_machine_regs.op_index + uladv)
2462 / linfo.li_max_ops_per_insn)
2463 * linfo.li_min_insn_length;
2464 state_machine_regs.op_index
2465 = (state_machine_regs.op_index + uladv)
2466 % linfo.li_max_ops_per_insn;
2467 printf (_(" Advance PC by %lu to 0x%lx[%d]\n"), uladv,
2468 state_machine_regs.address,
2469 state_machine_regs.op_index);
2471 break;
2473 case DW_LNS_advance_line:
2474 adv = read_leb128 (data, & bytes_read, 1);
2475 data += bytes_read;
2476 state_machine_regs.line += adv;
2477 printf (_(" Advance Line by %d to %d\n"), adv,
2478 state_machine_regs.line);
2479 break;
2481 case DW_LNS_set_file:
2482 adv = read_leb128 (data, & bytes_read, 0);
2483 data += bytes_read;
2484 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2485 adv);
2486 state_machine_regs.file = adv;
2487 break;
2489 case DW_LNS_set_column:
2490 uladv = read_leb128 (data, & bytes_read, 0);
2491 data += bytes_read;
2492 printf (_(" Set column to %lu\n"), uladv);
2493 state_machine_regs.column = uladv;
2494 break;
2496 case DW_LNS_negate_stmt:
2497 adv = state_machine_regs.is_stmt;
2498 adv = ! adv;
2499 printf (_(" Set is_stmt to %d\n"), adv);
2500 state_machine_regs.is_stmt = adv;
2501 break;
2503 case DW_LNS_set_basic_block:
2504 printf (_(" Set basic block\n"));
2505 state_machine_regs.basic_block = 1;
2506 break;
2508 case DW_LNS_const_add_pc:
2509 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2510 if (linfo.li_max_ops_per_insn)
2512 uladv *= linfo.li_min_insn_length;
2513 state_machine_regs.address += uladv;
2514 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv,
2515 state_machine_regs.address);
2517 else
2519 state_machine_regs.address
2520 += ((state_machine_regs.op_index + uladv)
2521 / linfo.li_max_ops_per_insn)
2522 * linfo.li_min_insn_length;
2523 state_machine_regs.op_index
2524 = (state_machine_regs.op_index + uladv)
2525 % linfo.li_max_ops_per_insn;
2526 printf (_(" Advance PC by constant %lu to 0x%lx[%d]\n"),
2527 uladv, state_machine_regs.address,
2528 state_machine_regs.op_index);
2530 break;
2532 case DW_LNS_fixed_advance_pc:
2533 uladv = byte_get (data, 2);
2534 data += 2;
2535 state_machine_regs.address += uladv;
2536 state_machine_regs.op_index = 0;
2537 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2538 uladv, state_machine_regs.address);
2539 break;
2541 case DW_LNS_set_prologue_end:
2542 printf (_(" Set prologue_end to true\n"));
2543 break;
2545 case DW_LNS_set_epilogue_begin:
2546 printf (_(" Set epilogue_begin to true\n"));
2547 break;
2549 case DW_LNS_set_isa:
2550 uladv = read_leb128 (data, & bytes_read, 0);
2551 data += bytes_read;
2552 printf (_(" Set ISA to %lu\n"), uladv);
2553 break;
2555 default:
2556 printf (_(" Unknown opcode %d with operands: "), op_code);
2558 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2560 printf ("0x%" BFD_VMA_FMT "x%s",
2561 read_leb128 (data, &bytes_read, 0),
2562 i == 1 ? "" : ", ");
2563 data += bytes_read;
2565 putchar ('\n');
2566 break;
2569 putchar ('\n');
2572 return 1;
2575 typedef struct
2577 unsigned char *name;
2578 unsigned int directory_index;
2579 unsigned int modification_date;
2580 unsigned int length;
2581 } File_Entry;
2583 /* Output a decoded representation of the .debug_line section. */
2585 static int
2586 display_debug_lines_decoded (struct dwarf_section *section,
2587 unsigned char *data,
2588 unsigned char *end)
2590 printf (_("Decoded dump of debug contents of section %s:\n\n"),
2591 section->name);
2593 while (data < end)
2595 /* This loop amounts to one iteration per compilation unit. */
2596 DWARF2_Internal_LineInfo linfo;
2597 unsigned char *standard_opcodes;
2598 unsigned char *end_of_sequence;
2599 unsigned char *hdrptr;
2600 int initial_length_size;
2601 int offset_size;
2602 int i;
2603 File_Entry *file_table = NULL;
2604 unsigned char **directory_table = NULL;
2606 hdrptr = data;
2608 /* Extract information from the Line Number Program Header.
2609 (section 6.2.4 in the Dwarf3 doc). */
2611 /* Get the length of this CU's line number information block. */
2612 linfo.li_length = byte_get (hdrptr, 4);
2613 hdrptr += 4;
2615 if (linfo.li_length == 0xffffffff)
2617 /* This section is 64-bit DWARF 3. */
2618 linfo.li_length = byte_get (hdrptr, 8);
2619 hdrptr += 8;
2620 offset_size = 8;
2621 initial_length_size = 12;
2623 else
2625 offset_size = 4;
2626 initial_length_size = 4;
2629 if (linfo.li_length + initial_length_size > section->size)
2631 warn (_("The line info appears to be corrupt - "
2632 "the section is too small\n"));
2633 return 0;
2636 /* Get this CU's Line Number Block version number. */
2637 linfo.li_version = byte_get (hdrptr, 2);
2638 hdrptr += 2;
2639 if (linfo.li_version != 2
2640 && linfo.li_version != 3
2641 && linfo.li_version != 4)
2643 warn (_("Only DWARF version 2, 3 and 4 line info is currently "
2644 "supported.\n"));
2645 return 0;
2648 linfo.li_prologue_length = byte_get (hdrptr, offset_size);
2649 hdrptr += offset_size;
2650 linfo.li_min_insn_length = byte_get (hdrptr, 1);
2651 hdrptr++;
2652 if (linfo.li_version >= 4)
2654 linfo.li_max_ops_per_insn = byte_get (hdrptr, 1);
2655 hdrptr++;
2656 if (linfo.li_max_ops_per_insn == 0)
2658 warn (_("Invalid maximum operations per insn.\n"));
2659 return 0;
2662 else
2663 linfo.li_max_ops_per_insn = 1;
2664 linfo.li_default_is_stmt = byte_get (hdrptr, 1);
2665 hdrptr++;
2666 linfo.li_line_base = byte_get (hdrptr, 1);
2667 hdrptr++;
2668 linfo.li_line_range = byte_get (hdrptr, 1);
2669 hdrptr++;
2670 linfo.li_opcode_base = byte_get (hdrptr, 1);
2671 hdrptr++;
2673 /* Sign extend the line base field. */
2674 linfo.li_line_base <<= 24;
2675 linfo.li_line_base >>= 24;
2677 /* Find the end of this CU's Line Number Information Block. */
2678 end_of_sequence = data + linfo.li_length + initial_length_size;
2680 reset_state_machine (linfo.li_default_is_stmt);
2682 /* Save a pointer to the contents of the Opcodes table. */
2683 standard_opcodes = hdrptr;
2685 /* Traverse the Directory table just to count entries. */
2686 data = standard_opcodes + linfo.li_opcode_base - 1;
2687 if (*data != 0)
2689 unsigned int n_directories = 0;
2690 unsigned char *ptr_directory_table = data;
2692 while (*data != 0)
2694 data += strlen ((char *) data) + 1;
2695 n_directories++;
2698 /* Go through the directory table again to save the directories. */
2699 directory_table = (unsigned char **)
2700 xmalloc (n_directories * sizeof (unsigned char *));
2702 i = 0;
2703 while (*ptr_directory_table != 0)
2705 directory_table[i] = ptr_directory_table;
2706 ptr_directory_table += strlen ((char *) ptr_directory_table) + 1;
2707 i++;
2710 /* Skip the NUL at the end of the table. */
2711 data++;
2713 /* Traverse the File Name table just to count the entries. */
2714 if (*data != 0)
2716 unsigned int n_files = 0;
2717 unsigned char *ptr_file_name_table = data;
2719 while (*data != 0)
2721 unsigned int bytes_read;
2723 /* Skip Name, directory index, last modification time and length
2724 of file. */
2725 data += strlen ((char *) data) + 1;
2726 read_leb128 (data, & bytes_read, 0);
2727 data += bytes_read;
2728 read_leb128 (data, & bytes_read, 0);
2729 data += bytes_read;
2730 read_leb128 (data, & bytes_read, 0);
2731 data += bytes_read;
2733 n_files++;
2736 /* Go through the file table again to save the strings. */
2737 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
2739 i = 0;
2740 while (*ptr_file_name_table != 0)
2742 unsigned int bytes_read;
2744 file_table[i].name = ptr_file_name_table;
2745 ptr_file_name_table += strlen ((char *) ptr_file_name_table) + 1;
2747 /* We are not interested in directory, time or size. */
2748 file_table[i].directory_index = read_leb128 (ptr_file_name_table,
2749 & bytes_read, 0);
2750 ptr_file_name_table += bytes_read;
2751 file_table[i].modification_date = read_leb128 (ptr_file_name_table,
2752 & bytes_read, 0);
2753 ptr_file_name_table += bytes_read;
2754 file_table[i].length = read_leb128 (ptr_file_name_table, & bytes_read, 0);
2755 ptr_file_name_table += bytes_read;
2756 i++;
2758 i = 0;
2760 /* Print the Compilation Unit's name and a header. */
2761 if (directory_table == NULL)
2763 printf (_("CU: %s:\n"), file_table[0].name);
2764 printf (_("File name Line number Starting address\n"));
2766 else
2768 if (do_wide || strlen ((char *) directory_table[0]) < 76)
2769 printf (_("CU: %s/%s:\n"), directory_table[0],
2770 file_table[0].name);
2771 else
2772 printf ("%s:\n", file_table[0].name);
2774 printf (_("File name Line number Starting address\n"));
2778 /* Skip the NUL at the end of the table. */
2779 data++;
2781 /* This loop iterates through the Dwarf Line Number Program. */
2782 while (data < end_of_sequence)
2784 unsigned char op_code;
2785 int adv;
2786 unsigned long int uladv;
2787 unsigned int bytes_read;
2788 int is_special_opcode = 0;
2790 op_code = *data++;
2792 if (op_code >= linfo.li_opcode_base)
2794 op_code -= linfo.li_opcode_base;
2795 uladv = (op_code / linfo.li_line_range);
2796 if (linfo.li_max_ops_per_insn == 1)
2798 uladv *= linfo.li_min_insn_length;
2799 state_machine_regs.address += uladv;
2801 else
2803 state_machine_regs.address
2804 += ((state_machine_regs.op_index + uladv)
2805 / linfo.li_max_ops_per_insn)
2806 * linfo.li_min_insn_length;
2807 state_machine_regs.op_index
2808 = (state_machine_regs.op_index + uladv)
2809 % linfo.li_max_ops_per_insn;
2812 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2813 state_machine_regs.line += adv;
2814 is_special_opcode = 1;
2816 else switch (op_code)
2818 case DW_LNS_extended_op:
2820 unsigned int ext_op_code_len;
2821 unsigned char ext_op_code;
2822 unsigned char *op_code_data = data;
2824 ext_op_code_len = read_leb128 (op_code_data, &bytes_read, 0);
2825 op_code_data += bytes_read;
2827 if (ext_op_code_len == 0)
2829 warn (_("badly formed extended line op encountered!\n"));
2830 break;
2832 ext_op_code_len += bytes_read;
2833 ext_op_code = *op_code_data++;
2835 switch (ext_op_code)
2837 case DW_LNE_end_sequence:
2838 reset_state_machine (linfo.li_default_is_stmt);
2839 break;
2840 case DW_LNE_set_address:
2841 state_machine_regs.address =
2842 byte_get (op_code_data, ext_op_code_len - bytes_read - 1);
2843 state_machine_regs.op_index = 0;
2844 break;
2845 case DW_LNE_define_file:
2847 unsigned int dir_index = 0;
2849 ++state_machine_regs.last_file_entry;
2850 op_code_data += strlen ((char *) op_code_data) + 1;
2851 dir_index = read_leb128 (op_code_data, & bytes_read, 0);
2852 op_code_data += bytes_read;
2853 read_leb128 (op_code_data, & bytes_read, 0);
2854 op_code_data += bytes_read;
2855 read_leb128 (op_code_data, & bytes_read, 0);
2857 printf ("%s:\n", directory_table[dir_index]);
2858 break;
2860 default:
2861 printf (_("UNKNOWN: length %d\n"), ext_op_code_len - bytes_read);
2862 break;
2864 data += ext_op_code_len;
2865 break;
2867 case DW_LNS_copy:
2868 break;
2870 case DW_LNS_advance_pc:
2871 uladv = read_leb128 (data, & bytes_read, 0);
2872 data += bytes_read;
2873 if (linfo.li_max_ops_per_insn == 1)
2875 uladv *= linfo.li_min_insn_length;
2876 state_machine_regs.address += uladv;
2878 else
2880 state_machine_regs.address
2881 += ((state_machine_regs.op_index + uladv)
2882 / linfo.li_max_ops_per_insn)
2883 * linfo.li_min_insn_length;
2884 state_machine_regs.op_index
2885 = (state_machine_regs.op_index + uladv)
2886 % linfo.li_max_ops_per_insn;
2888 break;
2890 case DW_LNS_advance_line:
2891 adv = read_leb128 (data, & bytes_read, 1);
2892 data += bytes_read;
2893 state_machine_regs.line += adv;
2894 break;
2896 case DW_LNS_set_file:
2897 adv = read_leb128 (data, & bytes_read, 0);
2898 data += bytes_read;
2899 state_machine_regs.file = adv;
2900 if (file_table[state_machine_regs.file - 1].directory_index == 0)
2902 /* If directory index is 0, that means current directory. */
2903 printf ("\n./%s:[++]\n",
2904 file_table[state_machine_regs.file - 1].name);
2906 else
2908 /* The directory index starts counting at 1. */
2909 printf ("\n%s/%s:\n",
2910 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
2911 file_table[state_machine_regs.file - 1].name);
2913 break;
2915 case DW_LNS_set_column:
2916 uladv = read_leb128 (data, & bytes_read, 0);
2917 data += bytes_read;
2918 state_machine_regs.column = uladv;
2919 break;
2921 case DW_LNS_negate_stmt:
2922 adv = state_machine_regs.is_stmt;
2923 adv = ! adv;
2924 state_machine_regs.is_stmt = adv;
2925 break;
2927 case DW_LNS_set_basic_block:
2928 state_machine_regs.basic_block = 1;
2929 break;
2931 case DW_LNS_const_add_pc:
2932 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2933 if (linfo.li_max_ops_per_insn == 1)
2935 uladv *= linfo.li_min_insn_length;
2936 state_machine_regs.address += uladv;
2938 else
2940 state_machine_regs.address
2941 += ((state_machine_regs.op_index + uladv)
2942 / linfo.li_max_ops_per_insn)
2943 * linfo.li_min_insn_length;
2944 state_machine_regs.op_index
2945 = (state_machine_regs.op_index + uladv)
2946 % linfo.li_max_ops_per_insn;
2948 break;
2950 case DW_LNS_fixed_advance_pc:
2951 uladv = byte_get (data, 2);
2952 data += 2;
2953 state_machine_regs.address += uladv;
2954 state_machine_regs.op_index = 0;
2955 break;
2957 case DW_LNS_set_prologue_end:
2958 break;
2960 case DW_LNS_set_epilogue_begin:
2961 break;
2963 case DW_LNS_set_isa:
2964 uladv = read_leb128 (data, & bytes_read, 0);
2965 data += bytes_read;
2966 printf (_(" Set ISA to %lu\n"), uladv);
2967 break;
2969 default:
2970 printf (_(" Unknown opcode %d with operands: "), op_code);
2972 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2974 printf ("0x%" BFD_VMA_FMT "x%s",
2975 read_leb128 (data, &bytes_read, 0),
2976 i == 1 ? "" : ", ");
2977 data += bytes_read;
2979 putchar ('\n');
2980 break;
2983 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
2984 to the DWARF address/line matrix. */
2985 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
2986 || (op_code == DW_LNS_copy))
2988 const unsigned int MAX_FILENAME_LENGTH = 35;
2989 char *fileName = (char *)file_table[state_machine_regs.file - 1].name;
2990 char *newFileName = NULL;
2991 size_t fileNameLength = strlen (fileName);
2993 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
2995 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
2996 /* Truncate file name */
2997 strncpy (newFileName,
2998 fileName + fileNameLength - MAX_FILENAME_LENGTH,
2999 MAX_FILENAME_LENGTH + 1);
3001 else
3003 newFileName = (char *) xmalloc (fileNameLength + 1);
3004 strncpy (newFileName, fileName, fileNameLength + 1);
3007 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3009 if (linfo.li_max_ops_per_insn == 1)
3010 printf ("%-35s %11d %#18lx\n", newFileName,
3011 state_machine_regs.line,
3012 state_machine_regs.address);
3013 else
3014 printf ("%-35s %11d %#18lx[%d]\n", newFileName,
3015 state_machine_regs.line,
3016 state_machine_regs.address,
3017 state_machine_regs.op_index);
3019 else
3021 if (linfo.li_max_ops_per_insn == 1)
3022 printf ("%s %11d %#18lx\n", newFileName,
3023 state_machine_regs.line,
3024 state_machine_regs.address);
3025 else
3026 printf ("%s %11d %#18lx[%d]\n", newFileName,
3027 state_machine_regs.line,
3028 state_machine_regs.address,
3029 state_machine_regs.op_index);
3032 if (op_code == DW_LNE_end_sequence)
3033 printf ("\n");
3035 free (newFileName);
3038 free (file_table);
3039 file_table = NULL;
3040 free (directory_table);
3041 directory_table = NULL;
3042 putchar ('\n');
3045 return 1;
3048 static int
3049 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3051 unsigned char *data = section->start;
3052 unsigned char *end = data + section->size;
3053 int retValRaw = 1;
3054 int retValDecoded = 1;
3056 if (do_debug_lines == 0)
3057 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3059 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3060 retValRaw = display_debug_lines_raw (section, data, end);
3062 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3063 retValDecoded = display_debug_lines_decoded (section, data, end);
3065 if (!retValRaw || !retValDecoded)
3066 return 0;
3068 return 1;
3071 static debug_info *
3072 find_debug_info_for_offset (unsigned long offset)
3074 unsigned int i;
3076 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3077 return NULL;
3079 for (i = 0; i < num_debug_info_entries; i++)
3080 if (debug_information[i].cu_offset == offset)
3081 return debug_information + i;
3083 return NULL;
3086 static int
3087 display_debug_pubnames (struct dwarf_section *section,
3088 void *file ATTRIBUTE_UNUSED)
3090 DWARF2_Internal_PubNames names;
3091 unsigned char *start = section->start;
3092 unsigned char *end = start + section->size;
3094 /* It does not matter if this load fails,
3095 we test for that later on. */
3096 load_debug_info (file);
3098 printf (_("Contents of the %s section:\n\n"), section->name);
3100 while (start < end)
3102 unsigned char *data;
3103 unsigned long offset;
3104 int offset_size, initial_length_size;
3106 data = start;
3108 names.pn_length = byte_get (data, 4);
3109 data += 4;
3110 if (names.pn_length == 0xffffffff)
3112 names.pn_length = byte_get (data, 8);
3113 data += 8;
3114 offset_size = 8;
3115 initial_length_size = 12;
3117 else
3119 offset_size = 4;
3120 initial_length_size = 4;
3123 names.pn_version = byte_get (data, 2);
3124 data += 2;
3126 names.pn_offset = byte_get (data, offset_size);
3127 data += offset_size;
3129 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3130 && num_debug_info_entries > 0
3131 && find_debug_info_for_offset (names.pn_offset) == NULL)
3132 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3133 (unsigned long) names.pn_offset, section->name);
3135 names.pn_size = byte_get (data, offset_size);
3136 data += offset_size;
3138 start += names.pn_length + initial_length_size;
3140 if (names.pn_version != 2 && names.pn_version != 3)
3142 static int warned = 0;
3144 if (! warned)
3146 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3147 warned = 1;
3150 continue;
3153 printf (_(" Length: %ld\n"),
3154 (long) names.pn_length);
3155 printf (_(" Version: %d\n"),
3156 names.pn_version);
3157 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3158 (unsigned long) names.pn_offset);
3159 printf (_(" Size of area in .debug_info section: %ld\n"),
3160 (long) names.pn_size);
3162 printf (_("\n Offset\tName\n"));
3166 offset = byte_get (data, offset_size);
3168 if (offset != 0)
3170 data += offset_size;
3171 printf (" %-6lx\t%s\n", offset, data);
3172 data += strlen ((char *) data) + 1;
3175 while (offset != 0);
3178 printf ("\n");
3179 return 1;
3182 static int
3183 display_debug_macinfo (struct dwarf_section *section,
3184 void *file ATTRIBUTE_UNUSED)
3186 unsigned char *start = section->start;
3187 unsigned char *end = start + section->size;
3188 unsigned char *curr = start;
3189 unsigned int bytes_read;
3190 enum dwarf_macinfo_record_type op;
3192 printf (_("Contents of the %s section:\n\n"), section->name);
3194 while (curr < end)
3196 unsigned int lineno;
3197 const char *string;
3199 op = (enum dwarf_macinfo_record_type) *curr;
3200 curr++;
3202 switch (op)
3204 case DW_MACINFO_start_file:
3206 unsigned int filenum;
3208 lineno = read_leb128 (curr, & bytes_read, 0);
3209 curr += bytes_read;
3210 filenum = read_leb128 (curr, & bytes_read, 0);
3211 curr += bytes_read;
3213 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3214 lineno, filenum);
3216 break;
3218 case DW_MACINFO_end_file:
3219 printf (_(" DW_MACINFO_end_file\n"));
3220 break;
3222 case DW_MACINFO_define:
3223 lineno = read_leb128 (curr, & bytes_read, 0);
3224 curr += bytes_read;
3225 string = (char *) curr;
3226 curr += strlen (string) + 1;
3227 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3228 lineno, string);
3229 break;
3231 case DW_MACINFO_undef:
3232 lineno = read_leb128 (curr, & bytes_read, 0);
3233 curr += bytes_read;
3234 string = (char *) curr;
3235 curr += strlen (string) + 1;
3236 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3237 lineno, string);
3238 break;
3240 case DW_MACINFO_vendor_ext:
3242 unsigned int constant;
3244 constant = read_leb128 (curr, & bytes_read, 0);
3245 curr += bytes_read;
3246 string = (char *) curr;
3247 curr += strlen (string) + 1;
3248 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3249 constant, string);
3251 break;
3255 return 1;
3258 static int
3259 display_debug_abbrev (struct dwarf_section *section,
3260 void *file ATTRIBUTE_UNUSED)
3262 abbrev_entry *entry;
3263 unsigned char *start = section->start;
3264 unsigned char *end = start + section->size;
3266 printf (_("Contents of the %s section:\n\n"), section->name);
3270 free_abbrevs ();
3272 start = process_abbrev_section (start, end);
3274 if (first_abbrev == NULL)
3275 continue;
3277 printf (_(" Number TAG\n"));
3279 for (entry = first_abbrev; entry; entry = entry->next)
3281 abbrev_attr *attr;
3283 printf (" %ld %s [%s]\n",
3284 entry->entry,
3285 get_TAG_name (entry->tag),
3286 entry->children ? _("has children") : _("no children"));
3288 for (attr = entry->first_attr; attr; attr = attr->next)
3289 printf (" %-18s %s\n",
3290 get_AT_name (attr->attribute),
3291 get_FORM_name (attr->form));
3294 while (start);
3296 printf ("\n");
3298 return 1;
3301 static int
3302 display_debug_loc (struct dwarf_section *section, void *file)
3304 unsigned char *start = section->start;
3305 unsigned char *section_end;
3306 unsigned long bytes;
3307 unsigned char *section_begin = start;
3308 unsigned int num_loc_list = 0;
3309 unsigned long last_offset = 0;
3310 unsigned int first = 0;
3311 unsigned int i;
3312 unsigned int j;
3313 int seen_first_offset = 0;
3314 int use_debug_info = 1;
3315 unsigned char *next;
3317 bytes = section->size;
3318 section_end = start + bytes;
3320 if (bytes == 0)
3322 printf (_("\nThe %s section is empty.\n"), section->name);
3323 return 0;
3326 if (load_debug_info (file) == 0)
3328 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3329 section->name);
3330 return 0;
3333 /* Check the order of location list in .debug_info section. If
3334 offsets of location lists are in the ascending order, we can
3335 use `debug_information' directly. */
3336 for (i = 0; i < num_debug_info_entries; i++)
3338 unsigned int num;
3340 num = debug_information [i].num_loc_offsets;
3341 num_loc_list += num;
3343 /* Check if we can use `debug_information' directly. */
3344 if (use_debug_info && num != 0)
3346 if (!seen_first_offset)
3348 /* This is the first location list. */
3349 last_offset = debug_information [i].loc_offsets [0];
3350 first = i;
3351 seen_first_offset = 1;
3352 j = 1;
3354 else
3355 j = 0;
3357 for (; j < num; j++)
3359 if (last_offset >
3360 debug_information [i].loc_offsets [j])
3362 use_debug_info = 0;
3363 break;
3365 last_offset = debug_information [i].loc_offsets [j];
3370 if (!use_debug_info)
3371 /* FIXME: Should we handle this case? */
3372 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
3374 if (!seen_first_offset)
3375 error (_("No location lists in .debug_info section!\n"));
3377 /* DWARF sections under Mach-O have non-zero addresses. */
3378 if (debug_information [first].num_loc_offsets > 0
3379 && debug_information [first].loc_offsets [0] != section->address)
3380 warn (_("Location lists in %s section start at 0x%s\n"),
3381 section->name,
3382 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
3384 printf (_("Contents of the %s section:\n\n"), section->name);
3385 printf (_(" Offset Begin End Expression\n"));
3387 seen_first_offset = 0;
3388 for (i = first; i < num_debug_info_entries; i++)
3390 dwarf_vma begin;
3391 dwarf_vma end;
3392 unsigned short length;
3393 unsigned long offset;
3394 unsigned int pointer_size;
3395 unsigned int offset_size;
3396 int dwarf_version;
3397 unsigned long cu_offset;
3398 unsigned long base_address;
3399 int need_frame_base;
3400 int has_frame_base;
3402 pointer_size = debug_information [i].pointer_size;
3403 cu_offset = debug_information [i].cu_offset;
3404 offset_size = debug_information [i].offset_size;
3405 dwarf_version = debug_information [i].dwarf_version;
3407 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
3409 has_frame_base = debug_information [i].have_frame_base [j];
3410 /* DWARF sections under Mach-O have non-zero addresses. */
3411 offset = debug_information [i].loc_offsets [j] - section->address;
3412 next = section_begin + offset;
3413 base_address = debug_information [i].base_address;
3415 if (!seen_first_offset)
3416 seen_first_offset = 1;
3417 else
3419 if (start < next)
3420 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
3421 (unsigned long) (start - section_begin),
3422 (unsigned long) (next - section_begin));
3423 else if (start > next)
3424 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
3425 (unsigned long) (start - section_begin),
3426 (unsigned long) (next - section_begin));
3428 start = next;
3430 if (offset >= bytes)
3432 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
3433 offset);
3434 continue;
3437 while (1)
3439 if (start + 2 * pointer_size > section_end)
3441 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3442 offset);
3443 break;
3446 /* Note: we use sign extension here in order to be sure that
3447 we can detect the -1 escape value. Sign extension into the
3448 top 32 bits of a 32-bit address will not affect the values
3449 that we display since we always show hex values, and always
3450 the bottom 32-bits. */
3451 begin = byte_get_signed (start, pointer_size);
3452 start += pointer_size;
3453 end = byte_get_signed (start, pointer_size);
3454 start += pointer_size;
3456 printf (" %8.8lx ", offset);
3458 if (begin == 0 && end == 0)
3460 printf (_("<End of list>\n"));
3461 break;
3464 /* Check base address specifiers. */
3465 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3467 base_address = end;
3468 print_dwarf_vma (begin, pointer_size);
3469 print_dwarf_vma (end, pointer_size);
3470 printf (_("(base address)\n"));
3471 continue;
3474 if (start + 2 > section_end)
3476 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3477 offset);
3478 break;
3481 length = byte_get (start, 2);
3482 start += 2;
3484 if (start + length > section_end)
3486 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
3487 offset);
3488 break;
3491 print_dwarf_vma (begin + base_address, pointer_size);
3492 print_dwarf_vma (end + base_address, pointer_size);
3494 putchar ('(');
3495 need_frame_base = decode_location_expression (start,
3496 pointer_size,
3497 offset_size,
3498 dwarf_version,
3499 length,
3500 cu_offset, section);
3501 putchar (')');
3503 if (need_frame_base && !has_frame_base)
3504 printf (_(" [without DW_AT_frame_base]"));
3506 if (begin == end)
3507 fputs (_(" (start == end)"), stdout);
3508 else if (begin > end)
3509 fputs (_(" (start > end)"), stdout);
3511 putchar ('\n');
3513 start += length;
3518 if (start < section_end)
3519 warn (_("There are %ld unused bytes at the end of section %s\n"),
3520 (long) (section_end - start), section->name);
3521 putchar ('\n');
3522 return 1;
3525 static int
3526 display_debug_str (struct dwarf_section *section,
3527 void *file ATTRIBUTE_UNUSED)
3529 unsigned char *start = section->start;
3530 unsigned long bytes = section->size;
3531 dwarf_vma addr = section->address;
3533 if (bytes == 0)
3535 printf (_("\nThe %s section is empty.\n"), section->name);
3536 return 0;
3539 printf (_("Contents of the %s section:\n\n"), section->name);
3541 while (bytes)
3543 int j;
3544 int k;
3545 int lbytes;
3547 lbytes = (bytes > 16 ? 16 : bytes);
3549 printf (" 0x%8.8lx ", (unsigned long) addr);
3551 for (j = 0; j < 16; j++)
3553 if (j < lbytes)
3554 printf ("%2.2x", start[j]);
3555 else
3556 printf (" ");
3558 if ((j & 3) == 3)
3559 printf (" ");
3562 for (j = 0; j < lbytes; j++)
3564 k = start[j];
3565 if (k >= ' ' && k < 0x80)
3566 printf ("%c", k);
3567 else
3568 printf (".");
3571 putchar ('\n');
3573 start += lbytes;
3574 addr += lbytes;
3575 bytes -= lbytes;
3578 putchar ('\n');
3580 return 1;
3583 static int
3584 display_debug_info (struct dwarf_section *section, void *file)
3586 return process_debug_info (section, file, abbrev, 0, 0);
3589 static int
3590 display_debug_types (struct dwarf_section *section, void *file)
3592 return process_debug_info (section, file, abbrev, 0, 1);
3595 static int
3596 display_trace_info (struct dwarf_section *section, void *file)
3598 return process_debug_info (section, file, trace_abbrev, 0, 0);
3601 static int
3602 display_debug_aranges (struct dwarf_section *section,
3603 void *file ATTRIBUTE_UNUSED)
3605 unsigned char *start = section->start;
3606 unsigned char *end = start + section->size;
3608 printf (_("Contents of the %s section:\n\n"), section->name);
3610 /* It does not matter if this load fails,
3611 we test for that later on. */
3612 load_debug_info (file);
3614 while (start < end)
3616 unsigned char *hdrptr;
3617 DWARF2_Internal_ARange arange;
3618 unsigned char *addr_ranges;
3619 dwarf_vma length;
3620 dwarf_vma address;
3621 unsigned char address_size;
3622 int excess;
3623 int offset_size;
3624 int initial_length_size;
3626 hdrptr = start;
3628 arange.ar_length = byte_get (hdrptr, 4);
3629 hdrptr += 4;
3631 if (arange.ar_length == 0xffffffff)
3633 arange.ar_length = byte_get (hdrptr, 8);
3634 hdrptr += 8;
3635 offset_size = 8;
3636 initial_length_size = 12;
3638 else
3640 offset_size = 4;
3641 initial_length_size = 4;
3644 arange.ar_version = byte_get (hdrptr, 2);
3645 hdrptr += 2;
3647 arange.ar_info_offset = byte_get (hdrptr, offset_size);
3648 hdrptr += offset_size;
3650 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3651 && num_debug_info_entries > 0
3652 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
3653 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3654 (unsigned long) arange.ar_info_offset, section->name);
3656 arange.ar_pointer_size = byte_get (hdrptr, 1);
3657 hdrptr += 1;
3659 arange.ar_segment_size = byte_get (hdrptr, 1);
3660 hdrptr += 1;
3662 if (arange.ar_version != 2 && arange.ar_version != 3)
3664 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
3665 break;
3668 printf (_(" Length: %ld\n"),
3669 (long) arange.ar_length);
3670 printf (_(" Version: %d\n"), arange.ar_version);
3671 printf (_(" Offset into .debug_info: 0x%lx\n"),
3672 (unsigned long) arange.ar_info_offset);
3673 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
3674 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
3676 address_size = arange.ar_pointer_size + arange.ar_segment_size;
3678 /* The DWARF spec does not require that the address size be a power
3679 of two, but we do. This will have to change if we ever encounter
3680 an uneven architecture. */
3681 if ((address_size & (address_size - 1)) != 0)
3683 warn (_("Pointer size + Segment size is not a power of two.\n"));
3684 break;
3687 if (address_size > 4)
3688 printf (_("\n Address Length\n"));
3689 else
3690 printf (_("\n Address Length\n"));
3692 addr_ranges = hdrptr;
3694 /* Must pad to an alignment boundary that is twice the address size. */
3695 excess = (hdrptr - start) % (2 * address_size);
3696 if (excess)
3697 addr_ranges += (2 * address_size) - excess;
3699 start += arange.ar_length + initial_length_size;
3701 while (addr_ranges + 2 * address_size <= start)
3703 address = byte_get (addr_ranges, address_size);
3705 addr_ranges += address_size;
3707 length = byte_get (addr_ranges, address_size);
3709 addr_ranges += address_size;
3711 printf (" ");
3712 print_dwarf_vma (address, address_size);
3713 print_dwarf_vma (length, address_size);
3714 putchar ('\n');
3718 printf ("\n");
3720 return 1;
3723 /* Each debug_information[x].range_lists[y] gets this representation for
3724 sorting purposes. */
3726 struct range_entry
3728 /* The debug_information[x].range_lists[y] value. */
3729 unsigned long ranges_offset;
3731 /* Original debug_information to find parameters of the data. */
3732 debug_info *debug_info_p;
3735 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
3737 static int
3738 range_entry_compar (const void *ap, const void *bp)
3740 const struct range_entry *a_re = (const struct range_entry *) ap;
3741 const struct range_entry *b_re = (const struct range_entry *) bp;
3742 const unsigned long a = a_re->ranges_offset;
3743 const unsigned long b = b_re->ranges_offset;
3745 return (a > b) - (b > a);
3748 static int
3749 display_debug_ranges (struct dwarf_section *section,
3750 void *file ATTRIBUTE_UNUSED)
3752 unsigned char *start = section->start;
3753 unsigned long bytes;
3754 unsigned char *section_begin = start;
3755 unsigned int num_range_list, i;
3756 struct range_entry *range_entries, *range_entry_fill;
3758 bytes = section->size;
3760 if (bytes == 0)
3762 printf (_("\nThe %s section is empty.\n"), section->name);
3763 return 0;
3766 if (load_debug_info (file) == 0)
3768 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
3769 section->name);
3770 return 0;
3773 num_range_list = 0;
3774 for (i = 0; i < num_debug_info_entries; i++)
3775 num_range_list += debug_information [i].num_range_lists;
3777 if (num_range_list == 0)
3778 error (_("No range lists in .debug_info section!\n"));
3780 range_entries = (struct range_entry *)
3781 xmalloc (sizeof (*range_entries) * num_range_list);
3782 range_entry_fill = range_entries;
3784 for (i = 0; i < num_debug_info_entries; i++)
3786 debug_info *debug_info_p = &debug_information[i];
3787 unsigned int j;
3789 for (j = 0; j < debug_info_p->num_range_lists; j++)
3791 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
3792 range_entry_fill->debug_info_p = debug_info_p;
3793 range_entry_fill++;
3797 qsort (range_entries, num_range_list, sizeof (*range_entries),
3798 range_entry_compar);
3800 /* DWARF sections under Mach-O have non-zero addresses. */
3801 if (range_entries[0].ranges_offset != section->address)
3802 warn (_("Range lists in %s section start at 0x%lx\n"),
3803 section->name, range_entries[0].ranges_offset);
3805 printf (_("Contents of the %s section:\n\n"), section->name);
3806 printf (_(" Offset Begin End\n"));
3808 for (i = 0; i < num_range_list; i++)
3810 struct range_entry *range_entry = &range_entries[i];
3811 debug_info *debug_info_p = range_entry->debug_info_p;
3812 unsigned int pointer_size;
3813 unsigned long offset;
3814 unsigned char *next;
3815 unsigned long base_address;
3817 pointer_size = debug_info_p->pointer_size;
3819 /* DWARF sections under Mach-O have non-zero addresses. */
3820 offset = range_entry->ranges_offset - section->address;
3821 next = section_begin + offset;
3822 base_address = debug_info_p->base_address;
3824 if (i > 0)
3826 if (start < next)
3827 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3828 (unsigned long) (start - section_begin),
3829 (unsigned long) (next - section_begin), section->name);
3830 else if (start > next)
3831 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3832 (unsigned long) (start - section_begin),
3833 (unsigned long) (next - section_begin), section->name);
3835 start = next;
3837 while (1)
3839 dwarf_vma begin;
3840 dwarf_vma end;
3842 /* Note: we use sign extension here in order to be sure that
3843 we can detect the -1 escape value. Sign extension into the
3844 top 32 bits of a 32-bit address will not affect the values
3845 that we display since we always show hex values, and always
3846 the bottom 32-bits. */
3847 begin = byte_get_signed (start, pointer_size);
3848 start += pointer_size;
3849 end = byte_get_signed (start, pointer_size);
3850 start += pointer_size;
3852 printf (" %8.8lx ", offset);
3854 if (begin == 0 && end == 0)
3856 printf (_("<End of list>\n"));
3857 break;
3860 /* Check base address specifiers. */
3861 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
3863 base_address = end;
3864 print_dwarf_vma (begin, pointer_size);
3865 print_dwarf_vma (end, pointer_size);
3866 printf ("(base address)\n");
3867 continue;
3870 print_dwarf_vma (begin + base_address, pointer_size);
3871 print_dwarf_vma (end + base_address, pointer_size);
3873 if (begin == end)
3874 fputs (_("(start == end)"), stdout);
3875 else if (begin > end)
3876 fputs (_("(start > end)"), stdout);
3878 putchar ('\n');
3881 putchar ('\n');
3883 free (range_entries);
3885 return 1;
3888 typedef struct Frame_Chunk
3890 struct Frame_Chunk *next;
3891 unsigned char *chunk_start;
3892 int ncols;
3893 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3894 short int *col_type;
3895 int *col_offset;
3896 char *augmentation;
3897 unsigned int code_factor;
3898 int data_factor;
3899 unsigned long pc_begin;
3900 unsigned long pc_range;
3901 int cfa_reg;
3902 int cfa_offset;
3903 int ra;
3904 unsigned char fde_encoding;
3905 unsigned char cfa_exp;
3906 unsigned char ptr_size;
3907 unsigned char segment_size;
3909 Frame_Chunk;
3911 static const char *const *dwarf_regnames;
3912 static unsigned int dwarf_regnames_count;
3914 /* A marker for a col_type that means this column was never referenced
3915 in the frame info. */
3916 #define DW_CFA_unreferenced (-1)
3918 /* Return 0 if not more space is needed, 1 if more space is needed,
3919 -1 for invalid reg. */
3921 static int
3922 frame_need_space (Frame_Chunk *fc, unsigned int reg)
3924 int prev = fc->ncols;
3926 if (reg < (unsigned int) fc->ncols)
3927 return 0;
3929 if (dwarf_regnames_count
3930 && reg > dwarf_regnames_count)
3931 return -1;
3933 fc->ncols = reg + 1;
3934 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
3935 sizeof (short int));
3936 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
3938 while (prev < fc->ncols)
3940 fc->col_type[prev] = DW_CFA_unreferenced;
3941 fc->col_offset[prev] = 0;
3942 prev++;
3944 return 1;
3947 static const char *const dwarf_regnames_i386[] =
3949 "eax", "ecx", "edx", "ebx",
3950 "esp", "ebp", "esi", "edi",
3951 "eip", "eflags", NULL,
3952 "st0", "st1", "st2", "st3",
3953 "st4", "st5", "st6", "st7",
3954 NULL, NULL,
3955 "xmm0", "xmm1", "xmm2", "xmm3",
3956 "xmm4", "xmm5", "xmm6", "xmm7",
3957 "mm0", "mm1", "mm2", "mm3",
3958 "mm4", "mm5", "mm6", "mm7",
3959 "fcw", "fsw", "mxcsr",
3960 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3961 "tr", "ldtr"
3964 void
3965 init_dwarf_regnames_i386 (void)
3967 dwarf_regnames = dwarf_regnames_i386;
3968 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
3971 static const char *const dwarf_regnames_x86_64[] =
3973 "rax", "rdx", "rcx", "rbx",
3974 "rsi", "rdi", "rbp", "rsp",
3975 "r8", "r9", "r10", "r11",
3976 "r12", "r13", "r14", "r15",
3977 "rip",
3978 "xmm0", "xmm1", "xmm2", "xmm3",
3979 "xmm4", "xmm5", "xmm6", "xmm7",
3980 "xmm8", "xmm9", "xmm10", "xmm11",
3981 "xmm12", "xmm13", "xmm14", "xmm15",
3982 "st0", "st1", "st2", "st3",
3983 "st4", "st5", "st6", "st7",
3984 "mm0", "mm1", "mm2", "mm3",
3985 "mm4", "mm5", "mm6", "mm7",
3986 "rflags",
3987 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3988 "fs.base", "gs.base", NULL, NULL,
3989 "tr", "ldtr",
3990 "mxcsr", "fcw", "fsw"
3993 void
3994 init_dwarf_regnames_x86_64 (void)
3996 dwarf_regnames = dwarf_regnames_x86_64;
3997 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
4000 void
4001 init_dwarf_regnames (unsigned int e_machine)
4003 switch (e_machine)
4005 case EM_386:
4006 case EM_486:
4007 init_dwarf_regnames_i386 ();
4008 break;
4010 case EM_X86_64:
4011 case EM_L1OM:
4012 init_dwarf_regnames_x86_64 ();
4013 break;
4015 default:
4016 break;
4020 static const char *
4021 regname (unsigned int regno, int row)
4023 static char reg[64];
4024 if (dwarf_regnames
4025 && regno < dwarf_regnames_count
4026 && dwarf_regnames [regno] != NULL)
4028 if (row)
4029 return dwarf_regnames [regno];
4030 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
4031 dwarf_regnames [regno]);
4033 else
4034 snprintf (reg, sizeof (reg), "r%d", regno);
4035 return reg;
4038 static void
4039 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
4041 int r;
4042 char tmp[100];
4044 if (*max_regs < fc->ncols)
4045 *max_regs = fc->ncols;
4047 if (*need_col_headers)
4049 static const char *sloc = " LOC";
4051 *need_col_headers = 0;
4053 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
4055 for (r = 0; r < *max_regs; r++)
4056 if (fc->col_type[r] != DW_CFA_unreferenced)
4058 if (r == fc->ra)
4059 printf ("ra ");
4060 else
4061 printf ("%-5s ", regname (r, 1));
4064 printf ("\n");
4067 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
4068 if (fc->cfa_exp)
4069 strcpy (tmp, "exp");
4070 else
4071 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
4072 printf ("%-8s ", tmp);
4074 for (r = 0; r < fc->ncols; r++)
4076 if (fc->col_type[r] != DW_CFA_unreferenced)
4078 switch (fc->col_type[r])
4080 case DW_CFA_undefined:
4081 strcpy (tmp, "u");
4082 break;
4083 case DW_CFA_same_value:
4084 strcpy (tmp, "s");
4085 break;
4086 case DW_CFA_offset:
4087 sprintf (tmp, "c%+d", fc->col_offset[r]);
4088 break;
4089 case DW_CFA_val_offset:
4090 sprintf (tmp, "v%+d", fc->col_offset[r]);
4091 break;
4092 case DW_CFA_register:
4093 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
4094 break;
4095 case DW_CFA_expression:
4096 strcpy (tmp, "exp");
4097 break;
4098 case DW_CFA_val_expression:
4099 strcpy (tmp, "vexp");
4100 break;
4101 default:
4102 strcpy (tmp, "n/a");
4103 break;
4105 printf ("%-5s ", tmp);
4108 printf ("\n");
4111 #define GET(N) byte_get (start, N); start += N
4112 #define LEB() read_leb128 (start, & length_return, 0); start += length_return
4113 #define SLEB() read_leb128 (start, & length_return, 1); start += length_return
4115 static int
4116 display_debug_frames (struct dwarf_section *section,
4117 void *file ATTRIBUTE_UNUSED)
4119 unsigned char *start = section->start;
4120 unsigned char *end = start + section->size;
4121 unsigned char *section_start = start;
4122 Frame_Chunk *chunks = 0;
4123 Frame_Chunk *remembered_state = 0;
4124 Frame_Chunk *rs;
4125 int is_eh = strcmp (section->name, ".eh_frame") == 0;
4126 unsigned int length_return;
4127 int max_regs = 0;
4128 const char *bad_reg = _("bad register: ");
4129 int saved_eh_addr_size = eh_addr_size;
4131 printf (_("Contents of the %s section:\n"), section->name);
4133 while (start < end)
4135 unsigned char *saved_start;
4136 unsigned char *block_end;
4137 unsigned long length;
4138 unsigned long cie_id;
4139 Frame_Chunk *fc;
4140 Frame_Chunk *cie;
4141 int need_col_headers = 1;
4142 unsigned char *augmentation_data = NULL;
4143 unsigned long augmentation_data_len = 0;
4144 int encoded_ptr_size = saved_eh_addr_size;
4145 int offset_size;
4146 int initial_length_size;
4148 saved_start = start;
4149 length = byte_get (start, 4); start += 4;
4151 if (length == 0)
4153 printf ("\n%08lx ZERO terminator\n\n",
4154 (unsigned long)(saved_start - section_start));
4155 continue;
4158 if (length == 0xffffffff)
4160 length = byte_get (start, 8);
4161 start += 8;
4162 offset_size = 8;
4163 initial_length_size = 12;
4165 else
4167 offset_size = 4;
4168 initial_length_size = 4;
4171 block_end = saved_start + length + initial_length_size;
4172 if (block_end > end)
4174 warn ("Invalid length %#08lx in FDE at %#08lx\n",
4175 length, (unsigned long)(saved_start - section_start));
4176 block_end = end;
4178 cie_id = byte_get (start, offset_size); start += offset_size;
4180 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
4182 int version;
4184 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4185 memset (fc, 0, sizeof (Frame_Chunk));
4187 fc->next = chunks;
4188 chunks = fc;
4189 fc->chunk_start = saved_start;
4190 fc->ncols = 0;
4191 fc->col_type = (short int *) xmalloc (sizeof (short int));
4192 fc->col_offset = (int *) xmalloc (sizeof (int));
4193 frame_need_space (fc, max_regs - 1);
4195 version = *start++;
4197 fc->augmentation = (char *) start;
4198 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
4200 if (strcmp (fc->augmentation, "eh") == 0)
4201 start += eh_addr_size;
4203 if (version >= 4)
4205 fc->ptr_size = GET (1);
4206 fc->segment_size = GET (1);
4207 eh_addr_size = fc->ptr_size;
4209 else
4211 fc->ptr_size = eh_addr_size;
4212 fc->segment_size = 0;
4214 fc->code_factor = LEB ();
4215 fc->data_factor = SLEB ();
4216 if (version == 1)
4218 fc->ra = GET (1);
4220 else
4222 fc->ra = LEB ();
4225 if (fc->augmentation[0] == 'z')
4227 augmentation_data_len = LEB ();
4228 augmentation_data = start;
4229 start += augmentation_data_len;
4231 cie = fc;
4233 if (do_debug_frames_interp)
4234 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
4235 (unsigned long)(saved_start - section_start), length, cie_id,
4236 fc->augmentation, fc->code_factor, fc->data_factor,
4237 fc->ra);
4238 else
4240 printf ("\n%08lx %08lx %08lx CIE\n",
4241 (unsigned long)(saved_start - section_start), length, cie_id);
4242 printf (" Version: %d\n", version);
4243 printf (" Augmentation: \"%s\"\n", fc->augmentation);
4244 if (version >= 4)
4246 printf (" Pointer Size: %u\n", fc->ptr_size);
4247 printf (" Segment Size: %u\n", fc->segment_size);
4249 printf (" Code alignment factor: %u\n", fc->code_factor);
4250 printf (" Data alignment factor: %d\n", fc->data_factor);
4251 printf (" Return address column: %d\n", fc->ra);
4253 if (augmentation_data_len)
4255 unsigned long i;
4256 printf (" Augmentation data: ");
4257 for (i = 0; i < augmentation_data_len; ++i)
4258 printf (" %02x", augmentation_data[i]);
4259 putchar ('\n');
4261 putchar ('\n');
4264 if (augmentation_data_len)
4266 unsigned char *p, *q;
4267 p = (unsigned char *) fc->augmentation + 1;
4268 q = augmentation_data;
4270 while (1)
4272 if (*p == 'L')
4273 q++;
4274 else if (*p == 'P')
4275 q += 1 + size_of_encoded_value (*q);
4276 else if (*p == 'R')
4277 fc->fde_encoding = *q++;
4278 else if (*p == 'S')
4280 else
4281 break;
4282 p++;
4285 if (fc->fde_encoding)
4286 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4289 frame_need_space (fc, fc->ra);
4291 else
4293 unsigned char *look_for;
4294 static Frame_Chunk fde_fc;
4295 unsigned long segment_selector;
4297 fc = & fde_fc;
4298 memset (fc, 0, sizeof (Frame_Chunk));
4300 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
4302 for (cie = chunks; cie ; cie = cie->next)
4303 if (cie->chunk_start == look_for)
4304 break;
4306 if (!cie)
4308 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
4309 cie_id, (unsigned long)(saved_start - section_start));
4310 fc->ncols = 0;
4311 fc->col_type = (short int *) xmalloc (sizeof (short int));
4312 fc->col_offset = (int *) xmalloc (sizeof (int));
4313 frame_need_space (fc, max_regs - 1);
4314 cie = fc;
4315 fc->augmentation = "";
4316 fc->fde_encoding = 0;
4317 fc->ptr_size = eh_addr_size;
4318 fc->segment_size = 0;
4320 else
4322 fc->ncols = cie->ncols;
4323 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
4324 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
4325 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
4326 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
4327 fc->augmentation = cie->augmentation;
4328 fc->ptr_size = cie->ptr_size;
4329 eh_addr_size = cie->ptr_size;
4330 fc->segment_size = cie->segment_size;
4331 fc->code_factor = cie->code_factor;
4332 fc->data_factor = cie->data_factor;
4333 fc->cfa_reg = cie->cfa_reg;
4334 fc->cfa_offset = cie->cfa_offset;
4335 fc->ra = cie->ra;
4336 frame_need_space (fc, max_regs - 1);
4337 fc->fde_encoding = cie->fde_encoding;
4340 if (fc->fde_encoding)
4341 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
4343 segment_selector = 0;
4344 if (fc->segment_size)
4346 segment_selector = byte_get (start, fc->segment_size);
4347 start += fc->segment_size;
4349 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
4350 start += encoded_ptr_size;
4351 fc->pc_range = byte_get (start, encoded_ptr_size);
4352 start += encoded_ptr_size;
4354 if (cie->augmentation[0] == 'z')
4356 augmentation_data_len = LEB ();
4357 augmentation_data = start;
4358 start += augmentation_data_len;
4361 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=",
4362 (unsigned long)(saved_start - section_start), length, cie_id,
4363 (unsigned long)(cie->chunk_start - section_start));
4364 if (fc->segment_size)
4365 printf ("%04lx:", segment_selector);
4366 printf ("%08lx..%08lx\n", fc->pc_begin, fc->pc_begin + fc->pc_range);
4367 if (! do_debug_frames_interp && augmentation_data_len)
4369 unsigned long i;
4371 printf (" Augmentation data: ");
4372 for (i = 0; i < augmentation_data_len; ++i)
4373 printf (" %02x", augmentation_data[i]);
4374 putchar ('\n');
4375 putchar ('\n');
4379 /* At this point, fc is the current chunk, cie (if any) is set, and
4380 we're about to interpret instructions for the chunk. */
4381 /* ??? At present we need to do this always, since this sizes the
4382 fc->col_type and fc->col_offset arrays, which we write into always.
4383 We should probably split the interpreted and non-interpreted bits
4384 into two different routines, since there's so much that doesn't
4385 really overlap between them. */
4386 if (1 || do_debug_frames_interp)
4388 /* Start by making a pass over the chunk, allocating storage
4389 and taking note of what registers are used. */
4390 unsigned char *tmp = start;
4392 while (start < block_end)
4394 unsigned op, opa;
4395 unsigned long reg, temp;
4397 op = *start++;
4398 opa = op & 0x3f;
4399 if (op & 0xc0)
4400 op &= 0xc0;
4402 /* Warning: if you add any more cases to this switch, be
4403 sure to add them to the corresponding switch below. */
4404 switch (op)
4406 case DW_CFA_advance_loc:
4407 break;
4408 case DW_CFA_offset:
4409 LEB ();
4410 if (frame_need_space (fc, opa) >= 0)
4411 fc->col_type[opa] = DW_CFA_undefined;
4412 break;
4413 case DW_CFA_restore:
4414 if (frame_need_space (fc, opa) >= 0)
4415 fc->col_type[opa] = DW_CFA_undefined;
4416 break;
4417 case DW_CFA_set_loc:
4418 start += encoded_ptr_size;
4419 break;
4420 case DW_CFA_advance_loc1:
4421 start += 1;
4422 break;
4423 case DW_CFA_advance_loc2:
4424 start += 2;
4425 break;
4426 case DW_CFA_advance_loc4:
4427 start += 4;
4428 break;
4429 case DW_CFA_offset_extended:
4430 case DW_CFA_val_offset:
4431 reg = LEB (); LEB ();
4432 if (frame_need_space (fc, reg) >= 0)
4433 fc->col_type[reg] = DW_CFA_undefined;
4434 break;
4435 case DW_CFA_restore_extended:
4436 reg = LEB ();
4437 frame_need_space (fc, reg);
4438 if (frame_need_space (fc, reg) >= 0)
4439 fc->col_type[reg] = DW_CFA_undefined;
4440 break;
4441 case DW_CFA_undefined:
4442 reg = LEB ();
4443 if (frame_need_space (fc, reg) >= 0)
4444 fc->col_type[reg] = DW_CFA_undefined;
4445 break;
4446 case DW_CFA_same_value:
4447 reg = LEB ();
4448 if (frame_need_space (fc, reg) >= 0)
4449 fc->col_type[reg] = DW_CFA_undefined;
4450 break;
4451 case DW_CFA_register:
4452 reg = LEB (); LEB ();
4453 if (frame_need_space (fc, reg) >= 0)
4454 fc->col_type[reg] = DW_CFA_undefined;
4455 break;
4456 case DW_CFA_def_cfa:
4457 LEB (); LEB ();
4458 break;
4459 case DW_CFA_def_cfa_register:
4460 LEB ();
4461 break;
4462 case DW_CFA_def_cfa_offset:
4463 LEB ();
4464 break;
4465 case DW_CFA_def_cfa_expression:
4466 temp = LEB ();
4467 start += temp;
4468 break;
4469 case DW_CFA_expression:
4470 case DW_CFA_val_expression:
4471 reg = LEB ();
4472 temp = LEB ();
4473 start += temp;
4474 if (frame_need_space (fc, reg) >= 0)
4475 fc->col_type[reg] = DW_CFA_undefined;
4476 break;
4477 case DW_CFA_offset_extended_sf:
4478 case DW_CFA_val_offset_sf:
4479 reg = LEB (); SLEB ();
4480 if (frame_need_space (fc, reg) >= 0)
4481 fc->col_type[reg] = DW_CFA_undefined;
4482 break;
4483 case DW_CFA_def_cfa_sf:
4484 LEB (); SLEB ();
4485 break;
4486 case DW_CFA_def_cfa_offset_sf:
4487 SLEB ();
4488 break;
4489 case DW_CFA_MIPS_advance_loc8:
4490 start += 8;
4491 break;
4492 case DW_CFA_GNU_args_size:
4493 LEB ();
4494 break;
4495 case DW_CFA_GNU_negative_offset_extended:
4496 reg = LEB (); LEB ();
4497 if (frame_need_space (fc, reg) >= 0)
4498 fc->col_type[reg] = DW_CFA_undefined;
4499 break;
4500 default:
4501 break;
4504 start = tmp;
4507 /* Now we know what registers are used, make a second pass over
4508 the chunk, this time actually printing out the info. */
4510 while (start < block_end)
4512 unsigned op, opa;
4513 unsigned long ul, reg, roffs;
4514 long l, ofs;
4515 dwarf_vma vma;
4516 const char *reg_prefix = "";
4518 op = *start++;
4519 opa = op & 0x3f;
4520 if (op & 0xc0)
4521 op &= 0xc0;
4523 /* Warning: if you add any more cases to this switch, be
4524 sure to add them to the corresponding switch above. */
4525 switch (op)
4527 case DW_CFA_advance_loc:
4528 if (do_debug_frames_interp)
4529 frame_display_row (fc, &need_col_headers, &max_regs);
4530 else
4531 printf (" DW_CFA_advance_loc: %d to %08lx\n",
4532 opa * fc->code_factor,
4533 fc->pc_begin + opa * fc->code_factor);
4534 fc->pc_begin += opa * fc->code_factor;
4535 break;
4537 case DW_CFA_offset:
4538 roffs = LEB ();
4539 if (opa >= (unsigned int) fc->ncols)
4540 reg_prefix = bad_reg;
4541 if (! do_debug_frames_interp || *reg_prefix != '\0')
4542 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
4543 reg_prefix, regname (opa, 0),
4544 roffs * fc->data_factor);
4545 if (*reg_prefix == '\0')
4547 fc->col_type[opa] = DW_CFA_offset;
4548 fc->col_offset[opa] = roffs * fc->data_factor;
4550 break;
4552 case DW_CFA_restore:
4553 if (opa >= (unsigned int) cie->ncols
4554 || opa >= (unsigned int) fc->ncols)
4555 reg_prefix = bad_reg;
4556 if (! do_debug_frames_interp || *reg_prefix != '\0')
4557 printf (" DW_CFA_restore: %s%s\n",
4558 reg_prefix, regname (opa, 0));
4559 if (*reg_prefix == '\0')
4561 fc->col_type[opa] = cie->col_type[opa];
4562 fc->col_offset[opa] = cie->col_offset[opa];
4564 break;
4566 case DW_CFA_set_loc:
4567 vma = get_encoded_value (start, fc->fde_encoding, section);
4568 start += encoded_ptr_size;
4569 if (do_debug_frames_interp)
4570 frame_display_row (fc, &need_col_headers, &max_regs);
4571 else
4572 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
4573 fc->pc_begin = vma;
4574 break;
4576 case DW_CFA_advance_loc1:
4577 ofs = byte_get (start, 1); start += 1;
4578 if (do_debug_frames_interp)
4579 frame_display_row (fc, &need_col_headers, &max_regs);
4580 else
4581 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
4582 ofs * fc->code_factor,
4583 fc->pc_begin + ofs * fc->code_factor);
4584 fc->pc_begin += ofs * fc->code_factor;
4585 break;
4587 case DW_CFA_advance_loc2:
4588 ofs = byte_get (start, 2); start += 2;
4589 if (do_debug_frames_interp)
4590 frame_display_row (fc, &need_col_headers, &max_regs);
4591 else
4592 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
4593 ofs * fc->code_factor,
4594 fc->pc_begin + ofs * fc->code_factor);
4595 fc->pc_begin += ofs * fc->code_factor;
4596 break;
4598 case DW_CFA_advance_loc4:
4599 ofs = byte_get (start, 4); start += 4;
4600 if (do_debug_frames_interp)
4601 frame_display_row (fc, &need_col_headers, &max_regs);
4602 else
4603 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
4604 ofs * fc->code_factor,
4605 fc->pc_begin + ofs * fc->code_factor);
4606 fc->pc_begin += ofs * fc->code_factor;
4607 break;
4609 case DW_CFA_offset_extended:
4610 reg = LEB ();
4611 roffs = LEB ();
4612 if (reg >= (unsigned int) fc->ncols)
4613 reg_prefix = bad_reg;
4614 if (! do_debug_frames_interp || *reg_prefix != '\0')
4615 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
4616 reg_prefix, regname (reg, 0),
4617 roffs * fc->data_factor);
4618 if (*reg_prefix == '\0')
4620 fc->col_type[reg] = DW_CFA_offset;
4621 fc->col_offset[reg] = roffs * fc->data_factor;
4623 break;
4625 case DW_CFA_val_offset:
4626 reg = LEB ();
4627 roffs = LEB ();
4628 if (reg >= (unsigned int) fc->ncols)
4629 reg_prefix = bad_reg;
4630 if (! do_debug_frames_interp || *reg_prefix != '\0')
4631 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
4632 reg_prefix, regname (reg, 0),
4633 roffs * fc->data_factor);
4634 if (*reg_prefix == '\0')
4636 fc->col_type[reg] = DW_CFA_val_offset;
4637 fc->col_offset[reg] = roffs * fc->data_factor;
4639 break;
4641 case DW_CFA_restore_extended:
4642 reg = LEB ();
4643 if (reg >= (unsigned int) cie->ncols
4644 || reg >= (unsigned int) fc->ncols)
4645 reg_prefix = bad_reg;
4646 if (! do_debug_frames_interp || *reg_prefix != '\0')
4647 printf (" DW_CFA_restore_extended: %s%s\n",
4648 reg_prefix, regname (reg, 0));
4649 if (*reg_prefix == '\0')
4651 fc->col_type[reg] = cie->col_type[reg];
4652 fc->col_offset[reg] = cie->col_offset[reg];
4654 break;
4656 case DW_CFA_undefined:
4657 reg = LEB ();
4658 if (reg >= (unsigned int) fc->ncols)
4659 reg_prefix = bad_reg;
4660 if (! do_debug_frames_interp || *reg_prefix != '\0')
4661 printf (" DW_CFA_undefined: %s%s\n",
4662 reg_prefix, regname (reg, 0));
4663 if (*reg_prefix == '\0')
4665 fc->col_type[reg] = DW_CFA_undefined;
4666 fc->col_offset[reg] = 0;
4668 break;
4670 case DW_CFA_same_value:
4671 reg = LEB ();
4672 if (reg >= (unsigned int) fc->ncols)
4673 reg_prefix = bad_reg;
4674 if (! do_debug_frames_interp || *reg_prefix != '\0')
4675 printf (" DW_CFA_same_value: %s%s\n",
4676 reg_prefix, regname (reg, 0));
4677 if (*reg_prefix == '\0')
4679 fc->col_type[reg] = DW_CFA_same_value;
4680 fc->col_offset[reg] = 0;
4682 break;
4684 case DW_CFA_register:
4685 reg = LEB ();
4686 roffs = LEB ();
4687 if (reg >= (unsigned int) fc->ncols)
4688 reg_prefix = bad_reg;
4689 if (! do_debug_frames_interp || *reg_prefix != '\0')
4691 printf (" DW_CFA_register: %s%s in ",
4692 reg_prefix, regname (reg, 0));
4693 puts (regname (roffs, 0));
4695 if (*reg_prefix == '\0')
4697 fc->col_type[reg] = DW_CFA_register;
4698 fc->col_offset[reg] = roffs;
4700 break;
4702 case DW_CFA_remember_state:
4703 if (! do_debug_frames_interp)
4704 printf (" DW_CFA_remember_state\n");
4705 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
4706 rs->ncols = fc->ncols;
4707 rs->col_type = (short int *) xcmalloc (rs->ncols,
4708 sizeof (short int));
4709 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (int));
4710 memcpy (rs->col_type, fc->col_type, rs->ncols);
4711 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
4712 rs->next = remembered_state;
4713 remembered_state = rs;
4714 break;
4716 case DW_CFA_restore_state:
4717 if (! do_debug_frames_interp)
4718 printf (" DW_CFA_restore_state\n");
4719 rs = remembered_state;
4720 if (rs)
4722 remembered_state = rs->next;
4723 frame_need_space (fc, rs->ncols - 1);
4724 memcpy (fc->col_type, rs->col_type, rs->ncols);
4725 memcpy (fc->col_offset, rs->col_offset,
4726 rs->ncols * sizeof (int));
4727 free (rs->col_type);
4728 free (rs->col_offset);
4729 free (rs);
4731 else if (do_debug_frames_interp)
4732 printf ("Mismatched DW_CFA_restore_state\n");
4733 break;
4735 case DW_CFA_def_cfa:
4736 fc->cfa_reg = LEB ();
4737 fc->cfa_offset = LEB ();
4738 fc->cfa_exp = 0;
4739 if (! do_debug_frames_interp)
4740 printf (" DW_CFA_def_cfa: %s ofs %d\n",
4741 regname (fc->cfa_reg, 0), fc->cfa_offset);
4742 break;
4744 case DW_CFA_def_cfa_register:
4745 fc->cfa_reg = LEB ();
4746 fc->cfa_exp = 0;
4747 if (! do_debug_frames_interp)
4748 printf (" DW_CFA_def_cfa_register: %s\n",
4749 regname (fc->cfa_reg, 0));
4750 break;
4752 case DW_CFA_def_cfa_offset:
4753 fc->cfa_offset = LEB ();
4754 if (! do_debug_frames_interp)
4755 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
4756 break;
4758 case DW_CFA_nop:
4759 if (! do_debug_frames_interp)
4760 printf (" DW_CFA_nop\n");
4761 break;
4763 case DW_CFA_def_cfa_expression:
4764 ul = LEB ();
4765 if (! do_debug_frames_interp)
4767 printf (" DW_CFA_def_cfa_expression (");
4768 decode_location_expression (start, eh_addr_size, 0, -1,
4769 ul, 0, section);
4770 printf (")\n");
4772 fc->cfa_exp = 1;
4773 start += ul;
4774 break;
4776 case DW_CFA_expression:
4777 reg = LEB ();
4778 ul = LEB ();
4779 if (reg >= (unsigned int) fc->ncols)
4780 reg_prefix = bad_reg;
4781 if (! do_debug_frames_interp || *reg_prefix != '\0')
4783 printf (" DW_CFA_expression: %s%s (",
4784 reg_prefix, regname (reg, 0));
4785 decode_location_expression (start, eh_addr_size, 0, -1,
4786 ul, 0, section);
4787 printf (")\n");
4789 if (*reg_prefix == '\0')
4790 fc->col_type[reg] = DW_CFA_expression;
4791 start += ul;
4792 break;
4794 case DW_CFA_val_expression:
4795 reg = LEB ();
4796 ul = LEB ();
4797 if (reg >= (unsigned int) fc->ncols)
4798 reg_prefix = bad_reg;
4799 if (! do_debug_frames_interp || *reg_prefix != '\0')
4801 printf (" DW_CFA_val_expression: %s%s (",
4802 reg_prefix, regname (reg, 0));
4803 decode_location_expression (start, eh_addr_size, 0, -1,
4804 ul, 0, section);
4805 printf (")\n");
4807 if (*reg_prefix == '\0')
4808 fc->col_type[reg] = DW_CFA_val_expression;
4809 start += ul;
4810 break;
4812 case DW_CFA_offset_extended_sf:
4813 reg = LEB ();
4814 l = SLEB ();
4815 if (frame_need_space (fc, reg) < 0)
4816 reg_prefix = bad_reg;
4817 if (! do_debug_frames_interp || *reg_prefix != '\0')
4818 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
4819 reg_prefix, regname (reg, 0),
4820 l * fc->data_factor);
4821 if (*reg_prefix == '\0')
4823 fc->col_type[reg] = DW_CFA_offset;
4824 fc->col_offset[reg] = l * fc->data_factor;
4826 break;
4828 case DW_CFA_val_offset_sf:
4829 reg = LEB ();
4830 l = SLEB ();
4831 if (frame_need_space (fc, reg) < 0)
4832 reg_prefix = bad_reg;
4833 if (! do_debug_frames_interp || *reg_prefix != '\0')
4834 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
4835 reg_prefix, regname (reg, 0),
4836 l * fc->data_factor);
4837 if (*reg_prefix == '\0')
4839 fc->col_type[reg] = DW_CFA_val_offset;
4840 fc->col_offset[reg] = l * fc->data_factor;
4842 break;
4844 case DW_CFA_def_cfa_sf:
4845 fc->cfa_reg = LEB ();
4846 fc->cfa_offset = SLEB ();
4847 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
4848 fc->cfa_exp = 0;
4849 if (! do_debug_frames_interp)
4850 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4851 regname (fc->cfa_reg, 0), fc->cfa_offset);
4852 break;
4854 case DW_CFA_def_cfa_offset_sf:
4855 fc->cfa_offset = SLEB ();
4856 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
4857 if (! do_debug_frames_interp)
4858 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
4859 break;
4861 case DW_CFA_MIPS_advance_loc8:
4862 ofs = byte_get (start, 8); start += 8;
4863 if (do_debug_frames_interp)
4864 frame_display_row (fc, &need_col_headers, &max_regs);
4865 else
4866 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4867 ofs * fc->code_factor,
4868 fc->pc_begin + ofs * fc->code_factor);
4869 fc->pc_begin += ofs * fc->code_factor;
4870 break;
4872 case DW_CFA_GNU_window_save:
4873 if (! do_debug_frames_interp)
4874 printf (" DW_CFA_GNU_window_save\n");
4875 break;
4877 case DW_CFA_GNU_args_size:
4878 ul = LEB ();
4879 if (! do_debug_frames_interp)
4880 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
4881 break;
4883 case DW_CFA_GNU_negative_offset_extended:
4884 reg = LEB ();
4885 l = - LEB ();
4886 if (frame_need_space (fc, reg) < 0)
4887 reg_prefix = bad_reg;
4888 if (! do_debug_frames_interp || *reg_prefix != '\0')
4889 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
4890 reg_prefix, regname (reg, 0),
4891 l * fc->data_factor);
4892 if (*reg_prefix == '\0')
4894 fc->col_type[reg] = DW_CFA_offset;
4895 fc->col_offset[reg] = l * fc->data_factor;
4897 break;
4899 default:
4900 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
4901 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
4902 else
4903 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
4904 start = block_end;
4908 if (do_debug_frames_interp)
4909 frame_display_row (fc, &need_col_headers, &max_regs);
4911 start = block_end;
4912 eh_addr_size = saved_eh_addr_size;
4915 printf ("\n");
4917 return 1;
4920 #undef GET
4921 #undef LEB
4922 #undef SLEB
4924 static int
4925 display_gdb_index (struct dwarf_section *section,
4926 void *file ATTRIBUTE_UNUSED)
4928 unsigned char *start = section->start;
4929 uint32_t version;
4930 uint32_t cu_list_offset, tu_list_offset;
4931 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
4932 unsigned int cu_list_elements, tu_list_elements;
4933 unsigned int address_table_size, symbol_table_slots;
4934 unsigned char *cu_list, *tu_list;
4935 unsigned char *address_table, *symbol_table, *constant_pool;
4936 unsigned int i;
4938 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
4940 printf (_("Contents of the %s section:\n"), section->name);
4942 if (section->size < 6 * sizeof (uint32_t))
4944 warn (_("Truncated header in the %s section.\n"), section->name);
4945 return 0;
4948 version = byte_get_little_endian (start, 4);
4949 printf (_("Version %ld\n"), (long) version);
4951 /* Prior versions are obsolete, and future versions may not be
4952 backwards compatible. */
4953 switch (version)
4955 case 3:
4956 warn (_("The address table data in version 3 may be wrong.\n"));
4957 break;
4958 case 4:
4959 break;
4960 default:
4961 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
4962 return 0;
4965 cu_list_offset = byte_get_little_endian (start + 4, 4);
4966 tu_list_offset = byte_get_little_endian (start + 8, 4);
4967 address_table_offset = byte_get_little_endian (start + 12, 4);
4968 symbol_table_offset = byte_get_little_endian (start + 16, 4);
4969 constant_pool_offset = byte_get_little_endian (start + 20, 4);
4971 if (cu_list_offset > section->size
4972 || tu_list_offset > section->size
4973 || address_table_offset > section->size
4974 || symbol_table_offset > section->size
4975 || constant_pool_offset > section->size)
4977 warn (_("Corrupt header in the %s section.\n"), section->name);
4978 return 0;
4981 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
4982 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
4983 address_table_size = symbol_table_offset - address_table_offset;
4984 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
4986 cu_list = start + cu_list_offset;
4987 tu_list = start + tu_list_offset;
4988 address_table = start + address_table_offset;
4989 symbol_table = start + symbol_table_offset;
4990 constant_pool = start + constant_pool_offset;
4992 printf (_("\nCU table:\n"));
4993 for (i = 0; i < cu_list_elements; i += 2)
4995 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
4996 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
4998 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
4999 (unsigned long) cu_offset,
5000 (unsigned long) (cu_offset + cu_length - 1));
5003 printf (_("\nTU table:\n"));
5004 for (i = 0; i < tu_list_elements; i += 3)
5006 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
5007 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
5008 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
5010 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
5011 (unsigned long) tu_offset,
5012 (unsigned long) type_offset);
5013 print_dwarf_vma (signature, 8);
5014 printf ("\n");
5017 printf (_("\nAddress table:\n"));
5018 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
5020 uint64_t low = byte_get_little_endian (address_table + i, 8);
5021 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
5022 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
5024 print_dwarf_vma (low, 8);
5025 print_dwarf_vma (high, 8);
5026 printf (_("%lu\n"), (unsigned long) cu_index);
5029 printf (_("\nSymbol table:\n"));
5030 for (i = 0; i < symbol_table_slots; ++i)
5032 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
5033 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
5034 uint32_t num_cus, cu;
5036 if (name_offset != 0
5037 || cu_vector_offset != 0)
5039 unsigned int j;
5041 printf ("[%3u] %s:", i, constant_pool + name_offset);
5042 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
5043 for (j = 0; j < num_cus; ++j)
5045 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
5046 /* Convert to TU number if it's for a type unit. */
5047 if (cu >= cu_list_elements)
5048 printf (" T%lu", (unsigned long) (cu - cu_list_elements));
5049 else
5050 printf (" %lu", (unsigned long) cu);
5052 printf ("\n");
5056 return 1;
5059 static int
5060 display_debug_not_supported (struct dwarf_section *section,
5061 void *file ATTRIBUTE_UNUSED)
5063 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
5064 section->name);
5066 return 1;
5069 void *
5070 cmalloc (size_t nmemb, size_t size)
5072 /* Check for overflow. */
5073 if (nmemb >= ~(size_t) 0 / size)
5074 return NULL;
5075 else
5076 return malloc (nmemb * size);
5079 void *
5080 xcmalloc (size_t nmemb, size_t size)
5082 /* Check for overflow. */
5083 if (nmemb >= ~(size_t) 0 / size)
5084 return NULL;
5085 else
5086 return xmalloc (nmemb * size);
5089 void *
5090 xcrealloc (void *ptr, size_t nmemb, size_t size)
5092 /* Check for overflow. */
5093 if (nmemb >= ~(size_t) 0 / size)
5094 return NULL;
5095 else
5096 return xrealloc (ptr, nmemb * size);
5099 void
5100 free_debug_memory (void)
5102 unsigned int i;
5104 free_abbrevs ();
5106 for (i = 0; i < max; i++)
5107 free_debug_section ((enum dwarf_section_display_enum) i);
5109 if (debug_information != NULL)
5111 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
5113 for (i = 0; i < num_debug_info_entries; i++)
5115 if (!debug_information [i].max_loc_offsets)
5117 free (debug_information [i].loc_offsets);
5118 free (debug_information [i].have_frame_base);
5120 if (!debug_information [i].max_range_lists)
5121 free (debug_information [i].range_lists);
5125 free (debug_information);
5126 debug_information = NULL;
5127 num_debug_info_entries = 0;
5131 void
5132 dwarf_select_sections_by_names (const char *names)
5134 typedef struct
5136 const char * option;
5137 int * variable;
5138 int val;
5140 debug_dump_long_opts;
5142 static const debug_dump_long_opts opts_table [] =
5144 /* Please keep this table alpha- sorted. */
5145 { "Ranges", & do_debug_ranges, 1 },
5146 { "abbrev", & do_debug_abbrevs, 1 },
5147 { "aranges", & do_debug_aranges, 1 },
5148 { "frames", & do_debug_frames, 1 },
5149 { "frames-interp", & do_debug_frames_interp, 1 },
5150 { "info", & do_debug_info, 1 },
5151 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
5152 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
5153 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
5154 { "loc", & do_debug_loc, 1 },
5155 { "macro", & do_debug_macinfo, 1 },
5156 { "pubnames", & do_debug_pubnames, 1 },
5157 { "pubtypes", & do_debug_pubtypes, 1 },
5158 /* This entry is for compatability
5159 with earlier versions of readelf. */
5160 { "ranges", & do_debug_aranges, 1 },
5161 { "str", & do_debug_str, 1 },
5162 /* The special .gdb_index section. */
5163 { "gdb_index", & do_gdb_index, 1 },
5164 /* These trace_* sections are used by Itanium VMS. */
5165 { "trace_abbrev", & do_trace_abbrevs, 1 },
5166 { "trace_aranges", & do_trace_aranges, 1 },
5167 { "trace_info", & do_trace_info, 1 },
5168 { NULL, NULL, 0 }
5171 const char *p;
5173 p = names;
5174 while (*p)
5176 const debug_dump_long_opts * entry;
5178 for (entry = opts_table; entry->option; entry++)
5180 size_t len = strlen (entry->option);
5182 if (strncmp (p, entry->option, len) == 0
5183 && (p[len] == ',' || p[len] == '\0'))
5185 * entry->variable |= entry->val;
5187 /* The --debug-dump=frames-interp option also
5188 enables the --debug-dump=frames option. */
5189 if (do_debug_frames_interp)
5190 do_debug_frames = 1;
5192 p += len;
5193 break;
5197 if (entry->option == NULL)
5199 warn (_("Unrecognized debug option '%s'\n"), p);
5200 p = strchr (p, ',');
5201 if (p == NULL)
5202 break;
5205 if (*p == ',')
5206 p++;
5210 void
5211 dwarf_select_sections_by_letters (const char *letters)
5213 unsigned int lindex = 0;
5215 while (letters[lindex])
5216 switch (letters[lindex++])
5218 case 'i':
5219 do_debug_info = 1;
5220 break;
5222 case 'a':
5223 do_debug_abbrevs = 1;
5224 break;
5226 case 'l':
5227 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
5228 break;
5230 case 'L':
5231 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
5232 break;
5234 case 'p':
5235 do_debug_pubnames = 1;
5236 break;
5238 case 't':
5239 do_debug_pubtypes = 1;
5240 break;
5242 case 'r':
5243 do_debug_aranges = 1;
5244 break;
5246 case 'R':
5247 do_debug_ranges = 1;
5248 break;
5250 case 'F':
5251 do_debug_frames_interp = 1;
5252 case 'f':
5253 do_debug_frames = 1;
5254 break;
5256 case 'm':
5257 do_debug_macinfo = 1;
5258 break;
5260 case 's':
5261 do_debug_str = 1;
5262 break;
5264 case 'o':
5265 do_debug_loc = 1;
5266 break;
5268 default:
5269 warn (_("Unrecognized debug option '%s'\n"), optarg);
5270 break;
5274 void
5275 dwarf_select_sections_all (void)
5277 do_debug_info = 1;
5278 do_debug_abbrevs = 1;
5279 do_debug_lines = FLAG_DEBUG_LINES_RAW;
5280 do_debug_pubnames = 1;
5281 do_debug_pubtypes = 1;
5282 do_debug_aranges = 1;
5283 do_debug_ranges = 1;
5284 do_debug_frames = 1;
5285 do_debug_macinfo = 1;
5286 do_debug_str = 1;
5287 do_debug_loc = 1;
5288 do_gdb_index = 1;
5289 do_trace_info = 1;
5290 do_trace_abbrevs = 1;
5291 do_trace_aranges = 1;
5294 struct dwarf_section_display debug_displays[] =
5296 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0 },
5297 display_debug_abbrev, &do_debug_abbrevs, 0 },
5298 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0 },
5299 display_debug_aranges, &do_debug_aranges, 1 },
5300 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0 },
5301 display_debug_frames, &do_debug_frames, 1 },
5302 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0 },
5303 display_debug_info, &do_debug_info, 1 },
5304 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0 },
5305 display_debug_lines, &do_debug_lines, 1 },
5306 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0 },
5307 display_debug_pubnames, &do_debug_pubnames, 0 },
5308 { { ".eh_frame", "", NULL, NULL, 0, 0 },
5309 display_debug_frames, &do_debug_frames, 1 },
5310 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0 },
5311 display_debug_macinfo, &do_debug_macinfo, 0 },
5312 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0 },
5313 display_debug_str, &do_debug_str, 0 },
5314 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0 },
5315 display_debug_loc, &do_debug_loc, 1 },
5316 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0 },
5317 display_debug_pubnames, &do_debug_pubtypes, 0 },
5318 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0 },
5319 display_debug_ranges, &do_debug_ranges, 1 },
5320 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0 },
5321 display_debug_not_supported, NULL, 0 },
5322 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0 },
5323 display_debug_not_supported, NULL, 0 },
5324 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0 },
5325 display_debug_types, &do_debug_info, 1 },
5326 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0 },
5327 display_debug_not_supported, NULL, 0 },
5328 { { ".gdb_index", "", NULL, NULL, 0, 0 },
5329 display_gdb_index, &do_gdb_index, 0 },
5330 { { ".trace_info", "", NULL, NULL, 0, 0 },
5331 display_trace_info, &do_trace_info, 1 },
5332 { { ".trace_abbrev", "", NULL, NULL, 0, 0 },
5333 display_debug_abbrev, &do_trace_abbrevs, 0 },
5334 { { ".trace_aranges", "", NULL, NULL, 0, 0 },
5335 display_debug_aranges, &do_trace_aranges, 0 }