daily update
[deliverable/binutils-gdb.git] / binutils / dwarf.c
CommitLineData
19e6b90e 1/* dwarf.c -- display DWARF contents of a BFD binary file
fe4eaaf4 2 Copyright 2005, 2006, 2007, 2008
19e6b90e
L
3 Free Software Foundation, Inc.
4
5 This file is part of GNU Binutils.
6
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
32866df7 9 the Free Software Foundation; either version 3 of the License, or
19e6b90e
L
10 (at your option) any later version.
11
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.
16
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. */
21
3db64b00 22#include "sysdep.h"
19e6b90e 23#include "libiberty.h"
3db64b00
AM
24#include "bfd.h"
25#include "bucomm.h"
2dc4cec1 26#include "elf/common.h"
3db64b00
AM
27#include "elf/dwarf2.h"
28#include "dwarf.h"
19e6b90e
L
29
30static int have_frame_base;
31static int need_base_address;
32
33static unsigned int last_pointer_size = 0;
34static int warned_about_missing_comp_units = FALSE;
35
36static unsigned int num_debug_info_entries = 0;
37static debug_info *debug_information = NULL;
cc86f28f
NC
38/* Special value for num_debug_info_entries to indicate
39 that the .debug_info section could not be loaded/parsed. */
40#define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
19e6b90e 41
2dc4cec1 42int eh_addr_size;
19e6b90e
L
43
44int do_debug_info;
45int do_debug_abbrevs;
46int do_debug_lines;
47int do_debug_pubnames;
48int do_debug_aranges;
49int do_debug_ranges;
50int do_debug_frames;
51int do_debug_frames_interp;
52int do_debug_macinfo;
53int do_debug_str;
54int do_debug_loc;
55
56dwarf_vma (*byte_get) (unsigned char *, int);
57
58dwarf_vma
59byte_get_little_endian (unsigned char *field, int size)
60{
61 switch (size)
62 {
63 case 1:
64 return *field;
65
66 case 2:
67 return ((unsigned int) (field[0]))
68 | (((unsigned int) (field[1])) << 8);
69
70 case 4:
71 return ((unsigned long) (field[0]))
72 | (((unsigned long) (field[1])) << 8)
73 | (((unsigned long) (field[2])) << 16)
74 | (((unsigned long) (field[3])) << 24);
75
76 case 8:
77 if (sizeof (dwarf_vma) == 8)
78 return ((dwarf_vma) (field[0]))
79 | (((dwarf_vma) (field[1])) << 8)
80 | (((dwarf_vma) (field[2])) << 16)
81 | (((dwarf_vma) (field[3])) << 24)
82 | (((dwarf_vma) (field[4])) << 32)
83 | (((dwarf_vma) (field[5])) << 40)
84 | (((dwarf_vma) (field[6])) << 48)
85 | (((dwarf_vma) (field[7])) << 56);
86 else if (sizeof (dwarf_vma) == 4)
87 /* We want to extract data from an 8 byte wide field and
88 place it into a 4 byte wide field. Since this is a little
89 endian source we can just use the 4 byte extraction code. */
90 return ((unsigned long) (field[0]))
91 | (((unsigned long) (field[1])) << 8)
92 | (((unsigned long) (field[2])) << 16)
93 | (((unsigned long) (field[3])) << 24);
94
95 default:
96 error (_("Unhandled data length: %d\n"), size);
97 abort ();
98 }
99}
100
101dwarf_vma
102byte_get_big_endian (unsigned char *field, int size)
103{
104 switch (size)
105 {
106 case 1:
107 return *field;
108
109 case 2:
110 return ((unsigned int) (field[1])) | (((int) (field[0])) << 8);
111
112 case 4:
113 return ((unsigned long) (field[3]))
114 | (((unsigned long) (field[2])) << 8)
115 | (((unsigned long) (field[1])) << 16)
116 | (((unsigned long) (field[0])) << 24);
117
118 case 8:
119 if (sizeof (dwarf_vma) == 8)
120 return ((dwarf_vma) (field[7]))
121 | (((dwarf_vma) (field[6])) << 8)
122 | (((dwarf_vma) (field[5])) << 16)
123 | (((dwarf_vma) (field[4])) << 24)
124 | (((dwarf_vma) (field[3])) << 32)
125 | (((dwarf_vma) (field[2])) << 40)
126 | (((dwarf_vma) (field[1])) << 48)
127 | (((dwarf_vma) (field[0])) << 56);
128 else if (sizeof (dwarf_vma) == 4)
129 {
130 /* Although we are extracing data from an 8 byte wide field,
131 we are returning only 4 bytes of data. */
132 field += 4;
133 return ((unsigned long) (field[3]))
134 | (((unsigned long) (field[2])) << 8)
135 | (((unsigned long) (field[1])) << 16)
136 | (((unsigned long) (field[0])) << 24);
137 }
138
139 default:
140 error (_("Unhandled data length: %d\n"), size);
141 abort ();
142 }
143}
144
145static dwarf_vma
146byte_get_signed (unsigned char *field, int size)
147{
148 dwarf_vma x = byte_get (field, size);
149
150 switch (size)
151 {
152 case 1:
153 return (x ^ 0x80) - 0x80;
154 case 2:
155 return (x ^ 0x8000) - 0x8000;
156 case 4:
157 return (x ^ 0x80000000) - 0x80000000;
158 case 8:
159 return x;
160 default:
161 abort ();
162 }
163}
164
2d9472a2
NC
165/* Print a dwarf_vma value (typically an address, offset or length) in
166 hexadecimal format, followed by a space. The length of the value (and
167 hence the precision displayed) is determined by the byte_size parameter. */
cecf136e 168
2d9472a2
NC
169static void
170print_dwarf_vma (dwarf_vma val, unsigned byte_size)
171{
172 static char buff[18];
173
174 /* Printf does not have a way of specifiying a maximum field width for an
175 integer value, so we print the full value into a buffer and then select
176 the precision we need. */
177#if __STDC_VERSION__ >= 199901L || (defined(__GNUC__) && __GNUC__ >= 2)
2e14fae2 178#ifndef __MSVCRT__
2d9472a2 179 snprintf (buff, sizeof (buff), "%16.16llx ", val);
2e14fae2
NC
180#else
181 snprintf (buff, sizeof (buff), "%016I64x ", val);
182#endif
2d9472a2
NC
183#else
184 snprintf (buff, sizeof (buff), "%16.16lx ", val);
185#endif
186
187 printf (buff + (byte_size == 4 ? 8 : 0));
188}
189
19e6b90e
L
190static unsigned long int
191read_leb128 (unsigned char *data, unsigned int *length_return, int sign)
192{
193 unsigned long int result = 0;
194 unsigned int num_read = 0;
195 unsigned int shift = 0;
196 unsigned char byte;
197
198 do
199 {
200 byte = *data++;
201 num_read++;
202
203 result |= ((unsigned long int) (byte & 0x7f)) << shift;
204
205 shift += 7;
206
207 }
208 while (byte & 0x80);
209
210 if (length_return != NULL)
211 *length_return = num_read;
212
213 if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40))
214 result |= -1L << shift;
215
216 return result;
217}
218
219typedef struct State_Machine_Registers
220{
221 unsigned long address;
222 unsigned int file;
223 unsigned int line;
224 unsigned int column;
225 int is_stmt;
226 int basic_block;
227 int end_sequence;
228/* This variable hold the number of the last entry seen
229 in the File Table. */
230 unsigned int last_file_entry;
231} SMR;
232
233static SMR state_machine_regs;
234
235static void
236reset_state_machine (int is_stmt)
237{
238 state_machine_regs.address = 0;
239 state_machine_regs.file = 1;
240 state_machine_regs.line = 1;
241 state_machine_regs.column = 0;
242 state_machine_regs.is_stmt = is_stmt;
243 state_machine_regs.basic_block = 0;
244 state_machine_regs.end_sequence = 0;
245 state_machine_regs.last_file_entry = 0;
246}
247
248/* Handled an extend line op.
249 Returns the number of bytes read. */
250
251static int
1617e571 252process_extended_line_op (unsigned char *data, int is_stmt)
19e6b90e
L
253{
254 unsigned char op_code;
255 unsigned int bytes_read;
256 unsigned int len;
257 unsigned char *name;
258 unsigned long adr;
259
260 len = read_leb128 (data, & bytes_read, 0);
261 data += bytes_read;
262
263 if (len == 0)
264 {
265 warn (_("badly formed extended line op encountered!\n"));
266 return bytes_read;
267 }
268
269 len += bytes_read;
270 op_code = *data++;
271
272 printf (_(" Extended opcode %d: "), op_code);
273
274 switch (op_code)
275 {
276 case DW_LNE_end_sequence:
277 printf (_("End of Sequence\n\n"));
278 reset_state_machine (is_stmt);
279 break;
280
281 case DW_LNE_set_address:
1617e571 282 adr = byte_get (data, len - bytes_read - 1);
19e6b90e
L
283 printf (_("set Address to 0x%lx\n"), adr);
284 state_machine_regs.address = adr;
285 break;
286
287 case DW_LNE_define_file:
288 printf (_(" define new File Table entry\n"));
289 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
290
291 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
292 name = data;
293 data += strlen ((char *) data) + 1;
294 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
295 data += bytes_read;
296 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
297 data += bytes_read;
298 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
299 printf (_("%s\n\n"), name);
300 break;
301
e2a0d921
NC
302 /* HP extensions. */
303 case DW_LNE_HP_negate_is_UV_update:
304 printf ("DW_LNE_HP_negate_is_UV_update");
305 break;
306 case DW_LNE_HP_push_context:
307 printf ("DW_LNE_HP_push_context");
308 break;
309 case DW_LNE_HP_pop_context:
310 printf ("DW_LNE_HP_pop_context");
311 break;
312 case DW_LNE_HP_set_file_line_column:
313 printf ("DW_LNE_HP_set_file_line_column");
314 break;
315 case DW_LNE_HP_set_routine_name:
316 printf ("DW_LNE_HP_set_routine_name");
317 break;
318 case DW_LNE_HP_set_sequence:
319 printf ("DW_LNE_HP_set_sequence");
320 break;
321 case DW_LNE_HP_negate_post_semantics:
322 printf ("DW_LNE_HP_negate_post_semantics");
323 break;
324 case DW_LNE_HP_negate_function_exit:
325 printf ("DW_LNE_HP_negate_function_exit");
326 break;
327 case DW_LNE_HP_negate_front_end_logical:
328 printf ("DW_LNE_HP_negate_front_end_logical");
329 break;
330 case DW_LNE_HP_define_proc:
331 printf ("DW_LNE_HP_define_proc");
332 break;
cecf136e 333
19e6b90e 334 default:
e2a0d921
NC
335 if (op_code >= DW_LNE_lo_user
336 /* The test against DW_LNW_hi_user is redundant due to
337 the limited range of the unsigned char data type used
338 for op_code. */
339 /*&& op_code <= DW_LNE_hi_user*/)
340 printf (_("user defined: length %d\n"), len - bytes_read);
341 else
342 printf (_("UNKNOWN: length %d\n"), len - bytes_read);
19e6b90e
L
343 break;
344 }
345
346 return len;
347}
348
349static const char *
350fetch_indirect_string (unsigned long offset)
351{
352 struct dwarf_section *section = &debug_displays [str].section;
353
354 if (section->start == NULL)
355 return _("<no .debug_str section>");
356
bfe2612a
L
357 /* DWARF sections under Mach-O have non-zero addresses. */
358 offset -= section->address;
19e6b90e
L
359 if (offset > section->size)
360 {
361 warn (_("DW_FORM_strp offset too big: %lx\n"), offset);
362 return _("<offset is too big>");
363 }
364
365 return (const char *) section->start + offset;
366}
367
368/* FIXME: There are better and more efficient ways to handle
369 these structures. For now though, I just want something that
370 is simple to implement. */
371typedef struct abbrev_attr
372{
373 unsigned long attribute;
374 unsigned long form;
375 struct abbrev_attr *next;
376}
377abbrev_attr;
378
379typedef struct abbrev_entry
380{
381 unsigned long entry;
382 unsigned long tag;
383 int children;
384 struct abbrev_attr *first_attr;
385 struct abbrev_attr *last_attr;
386 struct abbrev_entry *next;
387}
388abbrev_entry;
389
390static abbrev_entry *first_abbrev = NULL;
391static abbrev_entry *last_abbrev = NULL;
392
393static void
394free_abbrevs (void)
395{
396 abbrev_entry *abbrev;
397
398 for (abbrev = first_abbrev; abbrev;)
399 {
400 abbrev_entry *next = abbrev->next;
401 abbrev_attr *attr;
402
403 for (attr = abbrev->first_attr; attr;)
404 {
405 abbrev_attr *next = attr->next;
406
407 free (attr);
408 attr = next;
409 }
410
411 free (abbrev);
412 abbrev = next;
413 }
414
415 last_abbrev = first_abbrev = NULL;
416}
417
418static void
419add_abbrev (unsigned long number, unsigned long tag, int children)
420{
421 abbrev_entry *entry;
422
423 entry = malloc (sizeof (*entry));
424
425 if (entry == NULL)
426 /* ugg */
427 return;
428
429 entry->entry = number;
430 entry->tag = tag;
431 entry->children = children;
432 entry->first_attr = NULL;
433 entry->last_attr = NULL;
434 entry->next = NULL;
435
436 if (first_abbrev == NULL)
437 first_abbrev = entry;
438 else
439 last_abbrev->next = entry;
440
441 last_abbrev = entry;
442}
443
444static void
445add_abbrev_attr (unsigned long attribute, unsigned long form)
446{
447 abbrev_attr *attr;
448
449 attr = malloc (sizeof (*attr));
450
451 if (attr == NULL)
452 /* ugg */
453 return;
454
455 attr->attribute = attribute;
456 attr->form = form;
457 attr->next = NULL;
458
459 if (last_abbrev->first_attr == NULL)
460 last_abbrev->first_attr = attr;
461 else
462 last_abbrev->last_attr->next = attr;
463
464 last_abbrev->last_attr = attr;
465}
466
467/* Processes the (partial) contents of a .debug_abbrev section.
468 Returns NULL if the end of the section was encountered.
469 Returns the address after the last byte read if the end of
470 an abbreviation set was found. */
471
472static unsigned char *
473process_abbrev_section (unsigned char *start, unsigned char *end)
474{
475 if (first_abbrev != NULL)
476 return NULL;
477
478 while (start < end)
479 {
480 unsigned int bytes_read;
481 unsigned long entry;
482 unsigned long tag;
483 unsigned long attribute;
484 int children;
485
486 entry = read_leb128 (start, & bytes_read, 0);
487 start += bytes_read;
488
489 /* A single zero is supposed to end the section according
490 to the standard. If there's more, then signal that to
491 the caller. */
492 if (entry == 0)
493 return start == end ? NULL : start;
494
495 tag = read_leb128 (start, & bytes_read, 0);
496 start += bytes_read;
497
498 children = *start++;
499
500 add_abbrev (entry, tag, children);
501
502 do
503 {
504 unsigned long form;
505
506 attribute = read_leb128 (start, & bytes_read, 0);
507 start += bytes_read;
508
509 form = read_leb128 (start, & bytes_read, 0);
510 start += bytes_read;
511
512 if (attribute != 0)
513 add_abbrev_attr (attribute, form);
514 }
515 while (attribute != 0);
516 }
517
518 return NULL;
519}
520
521static char *
522get_TAG_name (unsigned long tag)
523{
524 switch (tag)
525 {
526 case DW_TAG_padding: return "DW_TAG_padding";
527 case DW_TAG_array_type: return "DW_TAG_array_type";
528 case DW_TAG_class_type: return "DW_TAG_class_type";
529 case DW_TAG_entry_point: return "DW_TAG_entry_point";
530 case DW_TAG_enumeration_type: return "DW_TAG_enumeration_type";
531 case DW_TAG_formal_parameter: return "DW_TAG_formal_parameter";
532 case DW_TAG_imported_declaration: return "DW_TAG_imported_declaration";
533 case DW_TAG_label: return "DW_TAG_label";
534 case DW_TAG_lexical_block: return "DW_TAG_lexical_block";
535 case DW_TAG_member: return "DW_TAG_member";
536 case DW_TAG_pointer_type: return "DW_TAG_pointer_type";
537 case DW_TAG_reference_type: return "DW_TAG_reference_type";
538 case DW_TAG_compile_unit: return "DW_TAG_compile_unit";
539 case DW_TAG_string_type: return "DW_TAG_string_type";
540 case DW_TAG_structure_type: return "DW_TAG_structure_type";
541 case DW_TAG_subroutine_type: return "DW_TAG_subroutine_type";
542 case DW_TAG_typedef: return "DW_TAG_typedef";
543 case DW_TAG_union_type: return "DW_TAG_union_type";
544 case DW_TAG_unspecified_parameters: return "DW_TAG_unspecified_parameters";
545 case DW_TAG_variant: return "DW_TAG_variant";
546 case DW_TAG_common_block: return "DW_TAG_common_block";
547 case DW_TAG_common_inclusion: return "DW_TAG_common_inclusion";
548 case DW_TAG_inheritance: return "DW_TAG_inheritance";
549 case DW_TAG_inlined_subroutine: return "DW_TAG_inlined_subroutine";
550 case DW_TAG_module: return "DW_TAG_module";
551 case DW_TAG_ptr_to_member_type: return "DW_TAG_ptr_to_member_type";
552 case DW_TAG_set_type: return "DW_TAG_set_type";
553 case DW_TAG_subrange_type: return "DW_TAG_subrange_type";
554 case DW_TAG_with_stmt: return "DW_TAG_with_stmt";
555 case DW_TAG_access_declaration: return "DW_TAG_access_declaration";
556 case DW_TAG_base_type: return "DW_TAG_base_type";
557 case DW_TAG_catch_block: return "DW_TAG_catch_block";
558 case DW_TAG_const_type: return "DW_TAG_const_type";
559 case DW_TAG_constant: return "DW_TAG_constant";
560 case DW_TAG_enumerator: return "DW_TAG_enumerator";
561 case DW_TAG_file_type: return "DW_TAG_file_type";
562 case DW_TAG_friend: return "DW_TAG_friend";
563 case DW_TAG_namelist: return "DW_TAG_namelist";
564 case DW_TAG_namelist_item: return "DW_TAG_namelist_item";
565 case DW_TAG_packed_type: return "DW_TAG_packed_type";
566 case DW_TAG_subprogram: return "DW_TAG_subprogram";
567 case DW_TAG_template_type_param: return "DW_TAG_template_type_param";
568 case DW_TAG_template_value_param: return "DW_TAG_template_value_param";
569 case DW_TAG_thrown_type: return "DW_TAG_thrown_type";
570 case DW_TAG_try_block: return "DW_TAG_try_block";
571 case DW_TAG_variant_part: return "DW_TAG_variant_part";
572 case DW_TAG_variable: return "DW_TAG_variable";
573 case DW_TAG_volatile_type: return "DW_TAG_volatile_type";
574 case DW_TAG_MIPS_loop: return "DW_TAG_MIPS_loop";
575 case DW_TAG_format_label: return "DW_TAG_format_label";
576 case DW_TAG_function_template: return "DW_TAG_function_template";
577 case DW_TAG_class_template: return "DW_TAG_class_template";
578 /* DWARF 2.1 values. */
579 case DW_TAG_dwarf_procedure: return "DW_TAG_dwarf_procedure";
580 case DW_TAG_restrict_type: return "DW_TAG_restrict_type";
581 case DW_TAG_interface_type: return "DW_TAG_interface_type";
582 case DW_TAG_namespace: return "DW_TAG_namespace";
583 case DW_TAG_imported_module: return "DW_TAG_imported_module";
584 case DW_TAG_unspecified_type: return "DW_TAG_unspecified_type";
585 case DW_TAG_partial_unit: return "DW_TAG_partial_unit";
586 case DW_TAG_imported_unit: return "DW_TAG_imported_unit";
587 /* UPC values. */
588 case DW_TAG_upc_shared_type: return "DW_TAG_upc_shared_type";
589 case DW_TAG_upc_strict_type: return "DW_TAG_upc_strict_type";
590 case DW_TAG_upc_relaxed_type: return "DW_TAG_upc_relaxed_type";
591 default:
592 {
593 static char buffer[100];
594
595 snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag);
596 return buffer;
597 }
598 }
599}
600
601static char *
602get_FORM_name (unsigned long form)
603{
604 switch (form)
605 {
606 case DW_FORM_addr: return "DW_FORM_addr";
607 case DW_FORM_block2: return "DW_FORM_block2";
608 case DW_FORM_block4: return "DW_FORM_block4";
609 case DW_FORM_data2: return "DW_FORM_data2";
610 case DW_FORM_data4: return "DW_FORM_data4";
611 case DW_FORM_data8: return "DW_FORM_data8";
612 case DW_FORM_string: return "DW_FORM_string";
613 case DW_FORM_block: return "DW_FORM_block";
614 case DW_FORM_block1: return "DW_FORM_block1";
615 case DW_FORM_data1: return "DW_FORM_data1";
616 case DW_FORM_flag: return "DW_FORM_flag";
617 case DW_FORM_sdata: return "DW_FORM_sdata";
618 case DW_FORM_strp: return "DW_FORM_strp";
619 case DW_FORM_udata: return "DW_FORM_udata";
620 case DW_FORM_ref_addr: return "DW_FORM_ref_addr";
621 case DW_FORM_ref1: return "DW_FORM_ref1";
622 case DW_FORM_ref2: return "DW_FORM_ref2";
623 case DW_FORM_ref4: return "DW_FORM_ref4";
624 case DW_FORM_ref8: return "DW_FORM_ref8";
625 case DW_FORM_ref_udata: return "DW_FORM_ref_udata";
626 case DW_FORM_indirect: return "DW_FORM_indirect";
627 default:
628 {
629 static char buffer[100];
630
631 snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form);
632 return buffer;
633 }
634 }
635}
636
637static unsigned char *
638display_block (unsigned char *data, unsigned long length)
639{
640 printf (_(" %lu byte block: "), length);
641
642 while (length --)
643 printf ("%lx ", (unsigned long) byte_get (data++, 1));
644
645 return data;
646}
647
648static int
649decode_location_expression (unsigned char * data,
650 unsigned int pointer_size,
651 unsigned long length,
652 unsigned long cu_offset)
653{
654 unsigned op;
655 unsigned int bytes_read;
656 unsigned long uvalue;
657 unsigned char *end = data + length;
658 int need_frame_base = 0;
659
660 while (data < end)
661 {
662 op = *data++;
663
664 switch (op)
665 {
666 case DW_OP_addr:
667 printf ("DW_OP_addr: %lx",
668 (unsigned long) byte_get (data, pointer_size));
669 data += pointer_size;
670 break;
671 case DW_OP_deref:
672 printf ("DW_OP_deref");
673 break;
674 case DW_OP_const1u:
675 printf ("DW_OP_const1u: %lu", (unsigned long) byte_get (data++, 1));
676 break;
677 case DW_OP_const1s:
678 printf ("DW_OP_const1s: %ld", (long) byte_get_signed (data++, 1));
679 break;
680 case DW_OP_const2u:
681 printf ("DW_OP_const2u: %lu", (unsigned long) byte_get (data, 2));
682 data += 2;
683 break;
684 case DW_OP_const2s:
685 printf ("DW_OP_const2s: %ld", (long) byte_get_signed (data, 2));
686 data += 2;
687 break;
688 case DW_OP_const4u:
689 printf ("DW_OP_const4u: %lu", (unsigned long) byte_get (data, 4));
690 data += 4;
691 break;
692 case DW_OP_const4s:
693 printf ("DW_OP_const4s: %ld", (long) byte_get_signed (data, 4));
694 data += 4;
695 break;
696 case DW_OP_const8u:
697 printf ("DW_OP_const8u: %lu %lu", (unsigned long) byte_get (data, 4),
698 (unsigned long) byte_get (data + 4, 4));
699 data += 8;
700 break;
701 case DW_OP_const8s:
702 printf ("DW_OP_const8s: %ld %ld", (long) byte_get (data, 4),
703 (long) byte_get (data + 4, 4));
704 data += 8;
705 break;
706 case DW_OP_constu:
707 printf ("DW_OP_constu: %lu", read_leb128 (data, &bytes_read, 0));
708 data += bytes_read;
709 break;
710 case DW_OP_consts:
711 printf ("DW_OP_consts: %ld", read_leb128 (data, &bytes_read, 1));
712 data += bytes_read;
713 break;
714 case DW_OP_dup:
715 printf ("DW_OP_dup");
716 break;
717 case DW_OP_drop:
718 printf ("DW_OP_drop");
719 break;
720 case DW_OP_over:
721 printf ("DW_OP_over");
722 break;
723 case DW_OP_pick:
724 printf ("DW_OP_pick: %ld", (unsigned long) byte_get (data++, 1));
725 break;
726 case DW_OP_swap:
727 printf ("DW_OP_swap");
728 break;
729 case DW_OP_rot:
730 printf ("DW_OP_rot");
731 break;
732 case DW_OP_xderef:
733 printf ("DW_OP_xderef");
734 break;
735 case DW_OP_abs:
736 printf ("DW_OP_abs");
737 break;
738 case DW_OP_and:
739 printf ("DW_OP_and");
740 break;
741 case DW_OP_div:
742 printf ("DW_OP_div");
743 break;
744 case DW_OP_minus:
745 printf ("DW_OP_minus");
746 break;
747 case DW_OP_mod:
748 printf ("DW_OP_mod");
749 break;
750 case DW_OP_mul:
751 printf ("DW_OP_mul");
752 break;
753 case DW_OP_neg:
754 printf ("DW_OP_neg");
755 break;
756 case DW_OP_not:
757 printf ("DW_OP_not");
758 break;
759 case DW_OP_or:
760 printf ("DW_OP_or");
761 break;
762 case DW_OP_plus:
763 printf ("DW_OP_plus");
764 break;
765 case DW_OP_plus_uconst:
766 printf ("DW_OP_plus_uconst: %lu",
767 read_leb128 (data, &bytes_read, 0));
768 data += bytes_read;
769 break;
770 case DW_OP_shl:
771 printf ("DW_OP_shl");
772 break;
773 case DW_OP_shr:
774 printf ("DW_OP_shr");
775 break;
776 case DW_OP_shra:
777 printf ("DW_OP_shra");
778 break;
779 case DW_OP_xor:
780 printf ("DW_OP_xor");
781 break;
782 case DW_OP_bra:
783 printf ("DW_OP_bra: %ld", (long) byte_get_signed (data, 2));
784 data += 2;
785 break;
786 case DW_OP_eq:
787 printf ("DW_OP_eq");
788 break;
789 case DW_OP_ge:
790 printf ("DW_OP_ge");
791 break;
792 case DW_OP_gt:
793 printf ("DW_OP_gt");
794 break;
795 case DW_OP_le:
796 printf ("DW_OP_le");
797 break;
798 case DW_OP_lt:
799 printf ("DW_OP_lt");
800 break;
801 case DW_OP_ne:
802 printf ("DW_OP_ne");
803 break;
804 case DW_OP_skip:
805 printf ("DW_OP_skip: %ld", (long) byte_get_signed (data, 2));
806 data += 2;
807 break;
808
809 case DW_OP_lit0:
810 case DW_OP_lit1:
811 case DW_OP_lit2:
812 case DW_OP_lit3:
813 case DW_OP_lit4:
814 case DW_OP_lit5:
815 case DW_OP_lit6:
816 case DW_OP_lit7:
817 case DW_OP_lit8:
818 case DW_OP_lit9:
819 case DW_OP_lit10:
820 case DW_OP_lit11:
821 case DW_OP_lit12:
822 case DW_OP_lit13:
823 case DW_OP_lit14:
824 case DW_OP_lit15:
825 case DW_OP_lit16:
826 case DW_OP_lit17:
827 case DW_OP_lit18:
828 case DW_OP_lit19:
829 case DW_OP_lit20:
830 case DW_OP_lit21:
831 case DW_OP_lit22:
832 case DW_OP_lit23:
833 case DW_OP_lit24:
834 case DW_OP_lit25:
835 case DW_OP_lit26:
836 case DW_OP_lit27:
837 case DW_OP_lit28:
838 case DW_OP_lit29:
839 case DW_OP_lit30:
840 case DW_OP_lit31:
841 printf ("DW_OP_lit%d", op - DW_OP_lit0);
842 break;
843
844 case DW_OP_reg0:
845 case DW_OP_reg1:
846 case DW_OP_reg2:
847 case DW_OP_reg3:
848 case DW_OP_reg4:
849 case DW_OP_reg5:
850 case DW_OP_reg6:
851 case DW_OP_reg7:
852 case DW_OP_reg8:
853 case DW_OP_reg9:
854 case DW_OP_reg10:
855 case DW_OP_reg11:
856 case DW_OP_reg12:
857 case DW_OP_reg13:
858 case DW_OP_reg14:
859 case DW_OP_reg15:
860 case DW_OP_reg16:
861 case DW_OP_reg17:
862 case DW_OP_reg18:
863 case DW_OP_reg19:
864 case DW_OP_reg20:
865 case DW_OP_reg21:
866 case DW_OP_reg22:
867 case DW_OP_reg23:
868 case DW_OP_reg24:
869 case DW_OP_reg25:
870 case DW_OP_reg26:
871 case DW_OP_reg27:
872 case DW_OP_reg28:
873 case DW_OP_reg29:
874 case DW_OP_reg30:
875 case DW_OP_reg31:
876 printf ("DW_OP_reg%d", op - DW_OP_reg0);
877 break;
878
879 case DW_OP_breg0:
880 case DW_OP_breg1:
881 case DW_OP_breg2:
882 case DW_OP_breg3:
883 case DW_OP_breg4:
884 case DW_OP_breg5:
885 case DW_OP_breg6:
886 case DW_OP_breg7:
887 case DW_OP_breg8:
888 case DW_OP_breg9:
889 case DW_OP_breg10:
890 case DW_OP_breg11:
891 case DW_OP_breg12:
892 case DW_OP_breg13:
893 case DW_OP_breg14:
894 case DW_OP_breg15:
895 case DW_OP_breg16:
896 case DW_OP_breg17:
897 case DW_OP_breg18:
898 case DW_OP_breg19:
899 case DW_OP_breg20:
900 case DW_OP_breg21:
901 case DW_OP_breg22:
902 case DW_OP_breg23:
903 case DW_OP_breg24:
904 case DW_OP_breg25:
905 case DW_OP_breg26:
906 case DW_OP_breg27:
907 case DW_OP_breg28:
908 case DW_OP_breg29:
909 case DW_OP_breg30:
910 case DW_OP_breg31:
911 printf ("DW_OP_breg%d: %ld", op - DW_OP_breg0,
912 read_leb128 (data, &bytes_read, 1));
913 data += bytes_read;
914 break;
915
916 case DW_OP_regx:
917 printf ("DW_OP_regx: %lu", read_leb128 (data, &bytes_read, 0));
918 data += bytes_read;
919 break;
920 case DW_OP_fbreg:
921 need_frame_base = 1;
922 printf ("DW_OP_fbreg: %ld", read_leb128 (data, &bytes_read, 1));
923 data += bytes_read;
924 break;
925 case DW_OP_bregx:
926 uvalue = read_leb128 (data, &bytes_read, 0);
927 data += bytes_read;
928 printf ("DW_OP_bregx: %lu %ld", uvalue,
929 read_leb128 (data, &bytes_read, 1));
930 data += bytes_read;
931 break;
932 case DW_OP_piece:
933 printf ("DW_OP_piece: %lu", read_leb128 (data, &bytes_read, 0));
934 data += bytes_read;
935 break;
936 case DW_OP_deref_size:
937 printf ("DW_OP_deref_size: %ld", (long) byte_get (data++, 1));
938 break;
939 case DW_OP_xderef_size:
940 printf ("DW_OP_xderef_size: %ld", (long) byte_get (data++, 1));
941 break;
942 case DW_OP_nop:
943 printf ("DW_OP_nop");
944 break;
945
946 /* DWARF 3 extensions. */
947 case DW_OP_push_object_address:
948 printf ("DW_OP_push_object_address");
949 break;
950 case DW_OP_call2:
951 /* XXX: Strictly speaking for 64-bit DWARF3 files
952 this ought to be an 8-byte wide computation. */
953 printf ("DW_OP_call2: <%lx>", (long) byte_get (data, 2) + cu_offset);
954 data += 2;
955 break;
956 case DW_OP_call4:
957 /* XXX: Strictly speaking for 64-bit DWARF3 files
958 this ought to be an 8-byte wide computation. */
959 printf ("DW_OP_call4: <%lx>", (long) byte_get (data, 4) + cu_offset);
960 data += 4;
961 break;
962 case DW_OP_call_ref:
e2a0d921
NC
963 /* XXX: Strictly speaking for 64-bit DWARF3 files
964 this ought to be an 8-byte wide computation. */
965 printf ("DW_OP_call_ref: <%lx>", (long) byte_get (data, 4) + cu_offset);
966 data += 4;
19e6b90e 967 break;
a87b0a59
NS
968 case DW_OP_form_tls_address:
969 printf ("DW_OP_form_tls_address");
970 break;
e2a0d921
NC
971 case DW_OP_call_frame_cfa:
972 printf ("DW_OP_call_frame_cfa");
973 break;
974 case DW_OP_bit_piece:
975 printf ("DW_OP_bit_piece: ");
976 printf ("size: %lu ", read_leb128 (data, &bytes_read, 0));
977 data += bytes_read;
978 printf ("offset: %lu ", read_leb128 (data, &bytes_read, 0));
979 data += bytes_read;
980 break;
19e6b90e
L
981
982 /* GNU extensions. */
983 case DW_OP_GNU_push_tls_address:
e2a0d921
NC
984 printf ("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown");
985 break;
986 case DW_OP_GNU_uninit:
987 printf ("DW_OP_GNU_uninit");
988 /* FIXME: Is there data associated with this OP ? */
989 break;
990
991 /* HP extensions. */
992 case DW_OP_HP_is_value:
993 printf ("DW_OP_HP_is_value");
994 /* FIXME: Is there data associated with this OP ? */
995 break;
996 case DW_OP_HP_fltconst4:
997 printf ("DW_OP_HP_fltconst4");
998 /* FIXME: Is there data associated with this OP ? */
999 break;
1000 case DW_OP_HP_fltconst8:
1001 printf ("DW_OP_HP_fltconst8");
1002 /* FIXME: Is there data associated with this OP ? */
1003 break;
1004 case DW_OP_HP_mod_range:
1005 printf ("DW_OP_HP_mod_range");
1006 /* FIXME: Is there data associated with this OP ? */
1007 break;
1008 case DW_OP_HP_unmod_range:
1009 printf ("DW_OP_HP_unmod_range");
1010 /* FIXME: Is there data associated with this OP ? */
1011 break;
1012 case DW_OP_HP_tls:
1013 printf ("DW_OP_HP_tls");
1014 /* FIXME: Is there data associated with this OP ? */
19e6b90e
L
1015 break;
1016
35d60fe4
NC
1017 /* PGI (STMicroelectronics) extensions. */
1018 case DW_OP_PGI_omp_thread_num:
1019 /* Pushes the thread number for the current thread as it would be
1020 returned by the standard OpenMP library function:
1021 omp_get_thread_num(). The "current thread" is the thread for
1022 which the expression is being evaluated. */
1023 printf ("DW_OP_PGI_omp_thread_num");
1024 break;
1025
19e6b90e
L
1026 default:
1027 if (op >= DW_OP_lo_user
1028 && op <= DW_OP_hi_user)
1029 printf (_("(User defined location op)"));
1030 else
1031 printf (_("(Unknown location op)"));
1032 /* No way to tell where the next op is, so just bail. */
1033 return need_frame_base;
1034 }
1035
1036 /* Separate the ops. */
1037 if (data < end)
1038 printf ("; ");
1039 }
1040
1041 return need_frame_base;
1042}
1043
1044static unsigned char *
6e3d6dc1
NC
1045read_and_display_attr_value (unsigned long attribute,
1046 unsigned long form,
ec4d4525 1047 unsigned char * data,
6e3d6dc1
NC
1048 unsigned long cu_offset,
1049 unsigned long pointer_size,
1050 unsigned long offset_size,
1051 int dwarf_version,
1052 debug_info * debug_info_p,
1053 int do_loc,
1054 struct dwarf_section * section)
19e6b90e
L
1055{
1056 unsigned long uvalue = 0;
1057 unsigned char *block_start = NULL;
6e3d6dc1 1058 unsigned char * orig_data = data;
19e6b90e
L
1059 unsigned int bytes_read;
1060
1061 switch (form)
1062 {
1063 default:
1064 break;
1065
1066 case DW_FORM_ref_addr:
1067 if (dwarf_version == 2)
1068 {
1069 uvalue = byte_get (data, pointer_size);
1070 data += pointer_size;
1071 }
1072 else if (dwarf_version == 3)
1073 {
1074 uvalue = byte_get (data, offset_size);
1075 data += offset_size;
1076 }
1077 else
1078 {
1079 error (_("Internal error: DWARF version is not 2 or 3.\n"));
1080 }
1081 break;
1082
1083 case DW_FORM_addr:
1084 uvalue = byte_get (data, pointer_size);
1085 data += pointer_size;
1086 break;
1087
1088 case DW_FORM_strp:
1089 uvalue = byte_get (data, offset_size);
1090 data += offset_size;
1091 break;
1092
1093 case DW_FORM_ref1:
1094 case DW_FORM_flag:
1095 case DW_FORM_data1:
1096 uvalue = byte_get (data++, 1);
1097 break;
1098
1099 case DW_FORM_ref2:
1100 case DW_FORM_data2:
1101 uvalue = byte_get (data, 2);
1102 data += 2;
1103 break;
1104
1105 case DW_FORM_ref4:
1106 case DW_FORM_data4:
1107 uvalue = byte_get (data, 4);
1108 data += 4;
1109 break;
1110
1111 case DW_FORM_sdata:
1112 uvalue = read_leb128 (data, & bytes_read, 1);
1113 data += bytes_read;
1114 break;
1115
1116 case DW_FORM_ref_udata:
1117 case DW_FORM_udata:
1118 uvalue = read_leb128 (data, & bytes_read, 0);
1119 data += bytes_read;
1120 break;
1121
1122 case DW_FORM_indirect:
1123 form = read_leb128 (data, & bytes_read, 0);
1124 data += bytes_read;
1125 if (!do_loc)
1126 printf (" %s", get_FORM_name (form));
1127 return read_and_display_attr_value (attribute, form, data,
1128 cu_offset, pointer_size,
1129 offset_size, dwarf_version,
ec4d4525 1130 debug_info_p, do_loc,
6e3d6dc1 1131 section);
19e6b90e
L
1132 }
1133
1134 switch (form)
1135 {
1136 case DW_FORM_ref_addr:
1137 if (!do_loc)
ec4d4525 1138 printf (" <0x%lx>", uvalue);
19e6b90e
L
1139 break;
1140
1141 case DW_FORM_ref1:
1142 case DW_FORM_ref2:
1143 case DW_FORM_ref4:
1144 case DW_FORM_ref_udata:
1145 if (!do_loc)
ec4d4525 1146 printf (" <0x%lx>", uvalue + cu_offset);
19e6b90e
L
1147 break;
1148
1149 case DW_FORM_data4:
1150 case DW_FORM_addr:
1151 if (!do_loc)
ec4d4525 1152 printf (" 0x%lx", uvalue);
19e6b90e
L
1153 break;
1154
1155 case DW_FORM_flag:
1156 case DW_FORM_data1:
1157 case DW_FORM_data2:
1158 case DW_FORM_sdata:
1159 case DW_FORM_udata:
1160 if (!do_loc)
1161 printf (" %ld", uvalue);
1162 break;
1163
1164 case DW_FORM_ref8:
1165 case DW_FORM_data8:
1166 if (!do_loc)
1167 {
1168 uvalue = byte_get (data, 4);
ec4d4525
NC
1169 printf (" 0x%lx", uvalue);
1170 printf (" 0x%lx", (unsigned long) byte_get (data + 4, 4));
19e6b90e
L
1171 }
1172 if ((do_loc || do_debug_loc || do_debug_ranges)
1173 && num_debug_info_entries == 0)
1174 {
1175 if (sizeof (uvalue) == 8)
1176 uvalue = byte_get (data, 8);
1177 else
1178 error (_("DW_FORM_data8 is unsupported when sizeof (unsigned long) != 8\n"));
1179 }
1180 data += 8;
1181 break;
1182
1183 case DW_FORM_string:
1184 if (!do_loc)
1185 printf (" %s", data);
1186 data += strlen ((char *) data) + 1;
1187 break;
1188
1189 case DW_FORM_block:
1190 uvalue = read_leb128 (data, & bytes_read, 0);
1191 block_start = data + bytes_read;
1192 if (do_loc)
1193 data = block_start + uvalue;
1194 else
1195 data = display_block (block_start, uvalue);
1196 break;
1197
1198 case DW_FORM_block1:
1199 uvalue = byte_get (data, 1);
1200 block_start = data + 1;
1201 if (do_loc)
1202 data = block_start + uvalue;
1203 else
1204 data = display_block (block_start, uvalue);
1205 break;
1206
1207 case DW_FORM_block2:
1208 uvalue = byte_get (data, 2);
1209 block_start = data + 2;
1210 if (do_loc)
1211 data = block_start + uvalue;
1212 else
1213 data = display_block (block_start, uvalue);
1214 break;
1215
1216 case DW_FORM_block4:
1217 uvalue = byte_get (data, 4);
1218 block_start = data + 4;
1219 if (do_loc)
1220 data = block_start + uvalue;
1221 else
1222 data = display_block (block_start, uvalue);
1223 break;
1224
1225 case DW_FORM_strp:
1226 if (!do_loc)
1227 printf (_(" (indirect string, offset: 0x%lx): %s"),
1228 uvalue, fetch_indirect_string (uvalue));
1229 break;
1230
1231 case DW_FORM_indirect:
1232 /* Handled above. */
1233 break;
1234
1235 default:
1236 warn (_("Unrecognized form: %lu\n"), form);
1237 break;
1238 }
1239
19e6b90e
L
1240 if ((do_loc || do_debug_loc || do_debug_ranges)
1241 && num_debug_info_entries == 0)
1242 {
1243 switch (attribute)
1244 {
1245 case DW_AT_frame_base:
1246 have_frame_base = 1;
1247 case DW_AT_location:
e2a0d921
NC
1248 case DW_AT_string_length:
1249 case DW_AT_return_addr:
19e6b90e
L
1250 case DW_AT_data_member_location:
1251 case DW_AT_vtable_elem_location:
e2a0d921
NC
1252 case DW_AT_segment:
1253 case DW_AT_static_link:
1254 case DW_AT_use_location:
1255 if (form == DW_FORM_data4 || form == DW_FORM_data8)
19e6b90e
L
1256 {
1257 /* Process location list. */
1258 unsigned int max = debug_info_p->max_loc_offsets;
1259 unsigned int num = debug_info_p->num_loc_offsets;
1260
1261 if (max == 0 || num >= max)
1262 {
1263 max += 1024;
1264 debug_info_p->loc_offsets
1265 = xcrealloc (debug_info_p->loc_offsets,
1266 max, sizeof (*debug_info_p->loc_offsets));
1267 debug_info_p->have_frame_base
1268 = xcrealloc (debug_info_p->have_frame_base,
1269 max, sizeof (*debug_info_p->have_frame_base));
1270 debug_info_p->max_loc_offsets = max;
1271 }
1272 debug_info_p->loc_offsets [num] = uvalue;
1273 debug_info_p->have_frame_base [num] = have_frame_base;
1274 debug_info_p->num_loc_offsets++;
1275 }
1276 break;
e2a0d921 1277
19e6b90e
L
1278 case DW_AT_low_pc:
1279 if (need_base_address)
1280 debug_info_p->base_address = uvalue;
1281 break;
1282
1283 case DW_AT_ranges:
1284 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1285 {
1286 /* Process range list. */
1287 unsigned int max = debug_info_p->max_range_lists;
1288 unsigned int num = debug_info_p->num_range_lists;
1289
1290 if (max == 0 || num >= max)
1291 {
1292 max += 1024;
1293 debug_info_p->range_lists
1294 = xcrealloc (debug_info_p->range_lists,
1295 max, sizeof (*debug_info_p->range_lists));
1296 debug_info_p->max_range_lists = max;
1297 }
1298 debug_info_p->range_lists [num] = uvalue;
1299 debug_info_p->num_range_lists++;
1300 }
1301 break;
1302
1303 default:
1304 break;
1305 }
1306 }
1307
1308 if (do_loc)
1309 return data;
1310
ec4d4525 1311 /* For some attributes we can display further information. */
19e6b90e
L
1312 printf ("\t");
1313
1314 switch (attribute)
1315 {
1316 case DW_AT_inline:
1317 switch (uvalue)
1318 {
1319 case DW_INL_not_inlined:
1320 printf (_("(not inlined)"));
1321 break;
1322 case DW_INL_inlined:
1323 printf (_("(inlined)"));
1324 break;
1325 case DW_INL_declared_not_inlined:
1326 printf (_("(declared as inline but ignored)"));
1327 break;
1328 case DW_INL_declared_inlined:
1329 printf (_("(declared as inline and inlined)"));
1330 break;
1331 default:
1332 printf (_(" (Unknown inline attribute value: %lx)"), uvalue);
1333 break;
1334 }
1335 break;
1336
1337 case DW_AT_language:
1338 switch (uvalue)
1339 {
4b78141a 1340 /* Ordered by the numeric value of these constants. */
19e6b90e 1341 case DW_LANG_C89: printf ("(ANSI C)"); break;
4b78141a
NC
1342 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1343 case DW_LANG_Ada83: printf ("(Ada)"); break;
19e6b90e 1344 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
4b78141a
NC
1345 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1346 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
19e6b90e
L
1347 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1348 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
19e6b90e 1349 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
4b78141a 1350 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
19e6b90e 1351 /* DWARF 2.1 values. */
4b78141a 1352 case DW_LANG_Java: printf ("(Java)"); break;
19e6b90e
L
1353 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1354 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1355 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
4b78141a
NC
1356 /* DWARF 3 values. */
1357 case DW_LANG_PLI: printf ("(PLI)"); break;
1358 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1359 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1360 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1361 case DW_LANG_D: printf ("(D)"); break;
19e6b90e
L
1362 /* MIPS extension. */
1363 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1364 /* UPC extension. */
1365 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1366 default:
4b78141a
NC
1367 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1368 printf ("(implementation defined: %lx)", uvalue);
1369 else
1370 printf ("(Unknown: %lx)", uvalue);
19e6b90e
L
1371 break;
1372 }
1373 break;
1374
1375 case DW_AT_encoding:
1376 switch (uvalue)
1377 {
1378 case DW_ATE_void: printf ("(void)"); break;
1379 case DW_ATE_address: printf ("(machine address)"); break;
1380 case DW_ATE_boolean: printf ("(boolean)"); break;
1381 case DW_ATE_complex_float: printf ("(complex float)"); break;
1382 case DW_ATE_float: printf ("(float)"); break;
1383 case DW_ATE_signed: printf ("(signed)"); break;
1384 case DW_ATE_signed_char: printf ("(signed char)"); break;
1385 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1386 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
e2a0d921 1387 /* DWARF 2.1 values: */
19e6b90e
L
1388 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1389 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
e2a0d921
NC
1390 /* DWARF 3 values: */
1391 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1392 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1393 case DW_ATE_edited: printf ("(edited)"); break;
1394 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1395 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1396 /* HP extensions: */
1397 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1398 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1399 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1400 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1401 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1402 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1403 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1404
19e6b90e
L
1405 default:
1406 if (uvalue >= DW_ATE_lo_user
1407 && uvalue <= DW_ATE_hi_user)
1408 printf ("(user defined type)");
1409 else
1410 printf ("(unknown type)");
1411 break;
1412 }
1413 break;
1414
1415 case DW_AT_accessibility:
1416 switch (uvalue)
1417 {
1418 case DW_ACCESS_public: printf ("(public)"); break;
1419 case DW_ACCESS_protected: printf ("(protected)"); break;
1420 case DW_ACCESS_private: printf ("(private)"); break;
1421 default:
1422 printf ("(unknown accessibility)");
1423 break;
1424 }
1425 break;
1426
1427 case DW_AT_visibility:
1428 switch (uvalue)
1429 {
1430 case DW_VIS_local: printf ("(local)"); break;
1431 case DW_VIS_exported: printf ("(exported)"); break;
1432 case DW_VIS_qualified: printf ("(qualified)"); break;
1433 default: printf ("(unknown visibility)"); break;
1434 }
1435 break;
1436
1437 case DW_AT_virtuality:
1438 switch (uvalue)
1439 {
1440 case DW_VIRTUALITY_none: printf ("(none)"); break;
1441 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1442 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1443 default: printf ("(unknown virtuality)"); break;
1444 }
1445 break;
1446
1447 case DW_AT_identifier_case:
1448 switch (uvalue)
1449 {
1450 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1451 case DW_ID_up_case: printf ("(up_case)"); break;
1452 case DW_ID_down_case: printf ("(down_case)"); break;
1453 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1454 default: printf ("(unknown case)"); break;
1455 }
1456 break;
1457
1458 case DW_AT_calling_convention:
1459 switch (uvalue)
1460 {
1461 case DW_CC_normal: printf ("(normal)"); break;
1462 case DW_CC_program: printf ("(program)"); break;
1463 case DW_CC_nocall: printf ("(nocall)"); break;
1464 default:
1465 if (uvalue >= DW_CC_lo_user
1466 && uvalue <= DW_CC_hi_user)
1467 printf ("(user defined)");
1468 else
1469 printf ("(unknown convention)");
1470 }
1471 break;
1472
1473 case DW_AT_ordering:
1474 switch (uvalue)
1475 {
1476 case -1: printf ("(undefined)"); break;
1477 case 0: printf ("(row major)"); break;
1478 case 1: printf ("(column major)"); break;
1479 }
1480 break;
1481
1482 case DW_AT_frame_base:
1483 have_frame_base = 1;
1484 case DW_AT_location:
e2a0d921
NC
1485 case DW_AT_string_length:
1486 case DW_AT_return_addr:
19e6b90e
L
1487 case DW_AT_data_member_location:
1488 case DW_AT_vtable_elem_location:
e2a0d921
NC
1489 case DW_AT_segment:
1490 case DW_AT_static_link:
1491 case DW_AT_use_location:
1492 if (form == DW_FORM_data4 || form == DW_FORM_data8)
1493 printf (_("(location list)"));
1494 /* Fall through. */
19e6b90e
L
1495 case DW_AT_allocated:
1496 case DW_AT_associated:
1497 case DW_AT_data_location:
1498 case DW_AT_stride:
1499 case DW_AT_upper_bound:
cecf136e 1500 case DW_AT_lower_bound:
19e6b90e
L
1501 if (block_start)
1502 {
1503 int need_frame_base;
1504
1505 printf ("(");
1506 need_frame_base = decode_location_expression (block_start,
1507 pointer_size,
1508 uvalue,
1509 cu_offset);
1510 printf (")");
1511 if (need_frame_base && !have_frame_base)
1512 printf (_(" [without DW_AT_frame_base]"));
1513 }
19e6b90e
L
1514 break;
1515
ec4d4525
NC
1516 case DW_AT_import:
1517 {
ec4d4525
NC
1518 if (form == DW_FORM_ref1
1519 || form == DW_FORM_ref2
1520 || form == DW_FORM_ref4)
1521 uvalue += cu_offset;
1522
6e3d6dc1
NC
1523 if (uvalue >= section->size)
1524 warn (_("Offset %lx used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
1525 uvalue, (long int)(orig_data - section->start));
1526 else
1527 {
1528 unsigned long abbrev_number;
1529 abbrev_entry * entry;
1530
1531 abbrev_number = read_leb128 (section->start + uvalue, NULL, 0);
cecf136e 1532
6e3d6dc1
NC
1533 printf ("[Abbrev Number: %ld", abbrev_number);
1534 for (entry = first_abbrev; entry != NULL; entry = entry->next)
1535 if (entry->entry == abbrev_number)
1536 break;
1537 if (entry != NULL)
1538 printf (" (%s)", get_TAG_name (entry->tag));
1539 printf ("]");
1540 }
ec4d4525
NC
1541 }
1542 break;
1543
19e6b90e
L
1544 default:
1545 break;
1546 }
1547
1548 return data;
1549}
1550
1551static char *
1552get_AT_name (unsigned long attribute)
1553{
1554 switch (attribute)
1555 {
1556 case DW_AT_sibling: return "DW_AT_sibling";
1557 case DW_AT_location: return "DW_AT_location";
1558 case DW_AT_name: return "DW_AT_name";
1559 case DW_AT_ordering: return "DW_AT_ordering";
1560 case DW_AT_subscr_data: return "DW_AT_subscr_data";
1561 case DW_AT_byte_size: return "DW_AT_byte_size";
1562 case DW_AT_bit_offset: return "DW_AT_bit_offset";
1563 case DW_AT_bit_size: return "DW_AT_bit_size";
1564 case DW_AT_element_list: return "DW_AT_element_list";
1565 case DW_AT_stmt_list: return "DW_AT_stmt_list";
1566 case DW_AT_low_pc: return "DW_AT_low_pc";
1567 case DW_AT_high_pc: return "DW_AT_high_pc";
1568 case DW_AT_language: return "DW_AT_language";
1569 case DW_AT_member: return "DW_AT_member";
1570 case DW_AT_discr: return "DW_AT_discr";
1571 case DW_AT_discr_value: return "DW_AT_discr_value";
1572 case DW_AT_visibility: return "DW_AT_visibility";
1573 case DW_AT_import: return "DW_AT_import";
1574 case DW_AT_string_length: return "DW_AT_string_length";
1575 case DW_AT_common_reference: return "DW_AT_common_reference";
1576 case DW_AT_comp_dir: return "DW_AT_comp_dir";
1577 case DW_AT_const_value: return "DW_AT_const_value";
1578 case DW_AT_containing_type: return "DW_AT_containing_type";
1579 case DW_AT_default_value: return "DW_AT_default_value";
1580 case DW_AT_inline: return "DW_AT_inline";
1581 case DW_AT_is_optional: return "DW_AT_is_optional";
1582 case DW_AT_lower_bound: return "DW_AT_lower_bound";
1583 case DW_AT_producer: return "DW_AT_producer";
1584 case DW_AT_prototyped: return "DW_AT_prototyped";
1585 case DW_AT_return_addr: return "DW_AT_return_addr";
1586 case DW_AT_start_scope: return "DW_AT_start_scope";
1587 case DW_AT_stride_size: return "DW_AT_stride_size";
1588 case DW_AT_upper_bound: return "DW_AT_upper_bound";
1589 case DW_AT_abstract_origin: return "DW_AT_abstract_origin";
1590 case DW_AT_accessibility: return "DW_AT_accessibility";
1591 case DW_AT_address_class: return "DW_AT_address_class";
1592 case DW_AT_artificial: return "DW_AT_artificial";
1593 case DW_AT_base_types: return "DW_AT_base_types";
1594 case DW_AT_calling_convention: return "DW_AT_calling_convention";
1595 case DW_AT_count: return "DW_AT_count";
1596 case DW_AT_data_member_location: return "DW_AT_data_member_location";
1597 case DW_AT_decl_column: return "DW_AT_decl_column";
1598 case DW_AT_decl_file: return "DW_AT_decl_file";
1599 case DW_AT_decl_line: return "DW_AT_decl_line";
1600 case DW_AT_declaration: return "DW_AT_declaration";
1601 case DW_AT_discr_list: return "DW_AT_discr_list";
1602 case DW_AT_encoding: return "DW_AT_encoding";
1603 case DW_AT_external: return "DW_AT_external";
1604 case DW_AT_frame_base: return "DW_AT_frame_base";
1605 case DW_AT_friend: return "DW_AT_friend";
1606 case DW_AT_identifier_case: return "DW_AT_identifier_case";
1607 case DW_AT_macro_info: return "DW_AT_macro_info";
1608 case DW_AT_namelist_items: return "DW_AT_namelist_items";
1609 case DW_AT_priority: return "DW_AT_priority";
1610 case DW_AT_segment: return "DW_AT_segment";
1611 case DW_AT_specification: return "DW_AT_specification";
1612 case DW_AT_static_link: return "DW_AT_static_link";
1613 case DW_AT_type: return "DW_AT_type";
1614 case DW_AT_use_location: return "DW_AT_use_location";
1615 case DW_AT_variable_parameter: return "DW_AT_variable_parameter";
1616 case DW_AT_virtuality: return "DW_AT_virtuality";
1617 case DW_AT_vtable_elem_location: return "DW_AT_vtable_elem_location";
1618 /* DWARF 2.1 values. */
1619 case DW_AT_allocated: return "DW_AT_allocated";
1620 case DW_AT_associated: return "DW_AT_associated";
1621 case DW_AT_data_location: return "DW_AT_data_location";
1622 case DW_AT_stride: return "DW_AT_stride";
1623 case DW_AT_entry_pc: return "DW_AT_entry_pc";
1624 case DW_AT_use_UTF8: return "DW_AT_use_UTF8";
1625 case DW_AT_extension: return "DW_AT_extension";
1626 case DW_AT_ranges: return "DW_AT_ranges";
1627 case DW_AT_trampoline: return "DW_AT_trampoline";
1628 case DW_AT_call_column: return "DW_AT_call_column";
1629 case DW_AT_call_file: return "DW_AT_call_file";
1630 case DW_AT_call_line: return "DW_AT_call_line";
e2a0d921
NC
1631 case DW_AT_description: return "DW_AT_description";
1632 case DW_AT_binary_scale: return "DW_AT_binary_scale";
1633 case DW_AT_decimal_scale: return "DW_AT_decimal_scale";
1634 case DW_AT_small: return "DW_AT_small";
1635 case DW_AT_decimal_sign: return "DW_AT_decimal_sign";
1636 case DW_AT_digit_count: return "DW_AT_digit_count";
1637 case DW_AT_picture_string: return "DW_AT_picture_string";
1638 case DW_AT_mutable: return "DW_AT_mutable";
1639 case DW_AT_threads_scaled: return "DW_AT_threads_scaled";
1640 case DW_AT_explicit: return "DW_AT_explicit";
1641 case DW_AT_object_pointer: return "DW_AT_object_pointer";
1642 case DW_AT_endianity: return "DW_AT_endianity";
1643 case DW_AT_elemental: return "DW_AT_elemental";
1644 case DW_AT_pure: return "DW_AT_pure";
1645 case DW_AT_recursive: return "DW_AT_recursive";
1646
1647 /* HP and SGI/MIPS extensions. */
1648 case DW_AT_MIPS_loop_begin: return "DW_AT_MIPS_loop_begin";
1649 case DW_AT_MIPS_tail_loop_begin: return "DW_AT_MIPS_tail_loop_begin";
1650 case DW_AT_MIPS_epilog_begin: return "DW_AT_MIPS_epilog_begin";
1651 case DW_AT_MIPS_loop_unroll_factor: return "DW_AT_MIPS_loop_unroll_factor";
1652 case DW_AT_MIPS_software_pipeline_depth: return "DW_AT_MIPS_software_pipeline_depth";
1653 case DW_AT_MIPS_linkage_name: return "DW_AT_MIPS_linkage_name";
1654 case DW_AT_MIPS_stride: return "DW_AT_MIPS_stride";
1655 case DW_AT_MIPS_abstract_name: return "DW_AT_MIPS_abstract_name";
1656 case DW_AT_MIPS_clone_origin: return "DW_AT_MIPS_clone_origin";
1657 case DW_AT_MIPS_has_inlines: return "DW_AT_MIPS_has_inlines";
1658
1659 /* HP Extensions. */
cecf136e 1660 case DW_AT_HP_block_index: return "DW_AT_HP_block_index";
e2a0d921
NC
1661 case DW_AT_HP_actuals_stmt_list: return "DW_AT_HP_actuals_stmt_list";
1662 case DW_AT_HP_proc_per_section: return "DW_AT_HP_proc_per_section";
1663 case DW_AT_HP_raw_data_ptr: return "DW_AT_HP_raw_data_ptr";
1664 case DW_AT_HP_pass_by_reference: return "DW_AT_HP_pass_by_reference";
1665 case DW_AT_HP_opt_level: return "DW_AT_HP_opt_level";
1666 case DW_AT_HP_prof_version_id: return "DW_AT_HP_prof_version_id";
1667 case DW_AT_HP_opt_flags: return "DW_AT_HP_opt_flags";
1668 case DW_AT_HP_cold_region_low_pc: return "DW_AT_HP_cold_region_low_pc";
1669 case DW_AT_HP_cold_region_high_pc: return "DW_AT_HP_cold_region_high_pc";
1670 case DW_AT_HP_all_variables_modifiable: return "DW_AT_HP_all_variables_modifiable";
1671 case DW_AT_HP_linkage_name: return "DW_AT_HP_linkage_name";
1672 case DW_AT_HP_prof_flags: return "DW_AT_HP_prof_flags";
1673
1674 /* One value is shared by the MIPS and HP extensions: */
1675 case DW_AT_MIPS_fde: return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
cecf136e 1676
19e6b90e
L
1677 /* GNU extensions. */
1678 case DW_AT_sf_names: return "DW_AT_sf_names";
1679 case DW_AT_src_info: return "DW_AT_src_info";
1680 case DW_AT_mac_info: return "DW_AT_mac_info";
1681 case DW_AT_src_coords: return "DW_AT_src_coords";
1682 case DW_AT_body_begin: return "DW_AT_body_begin";
1683 case DW_AT_body_end: return "DW_AT_body_end";
1684 case DW_AT_GNU_vector: return "DW_AT_GNU_vector";
e2a0d921 1685
19e6b90e
L
1686 /* UPC extension. */
1687 case DW_AT_upc_threads_scaled: return "DW_AT_upc_threads_scaled";
e2a0d921
NC
1688
1689 /* PGI (STMicroelectronics) extensions. */
1690 case DW_AT_PGI_lbase: return "DW_AT_PGI_lbase";
1691 case DW_AT_PGI_soffset: return "DW_AT_PGI_soffset";
1692 case DW_AT_PGI_lstride: return "DW_AT_PGI_lstride";
1693
19e6b90e
L
1694 default:
1695 {
1696 static char buffer[100];
1697
1698 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
1699 attribute);
1700 return buffer;
1701 }
1702 }
1703}
1704
1705static unsigned char *
6e3d6dc1
NC
1706read_and_display_attr (unsigned long attribute,
1707 unsigned long form,
ec4d4525 1708 unsigned char * data,
6e3d6dc1
NC
1709 unsigned long cu_offset,
1710 unsigned long pointer_size,
1711 unsigned long offset_size,
1712 int dwarf_version,
1713 debug_info * debug_info_p,
1714 int do_loc,
1715 struct dwarf_section * section)
19e6b90e
L
1716{
1717 if (!do_loc)
750f03b7 1718 printf (" %-18s:", get_AT_name (attribute));
19e6b90e
L
1719 data = read_and_display_attr_value (attribute, form, data, cu_offset,
1720 pointer_size, offset_size,
1721 dwarf_version, debug_info_p,
6e3d6dc1 1722 do_loc, section);
19e6b90e
L
1723 if (!do_loc)
1724 printf ("\n");
1725 return data;
1726}
1727
1728
1729/* Process the contents of a .debug_info section. If do_loc is non-zero
1730 then we are scanning for location lists and we do not want to display
1731 anything to the user. */
1732
1733static int
6e3d6dc1
NC
1734process_debug_info (struct dwarf_section *section,
1735 void *file,
19e6b90e
L
1736 int do_loc)
1737{
1738 unsigned char *start = section->start;
1739 unsigned char *end = start + section->size;
1740 unsigned char *section_begin;
1741 unsigned int unit;
1742 unsigned int num_units = 0;
1743
1744 if ((do_loc || do_debug_loc || do_debug_ranges)
1745 && num_debug_info_entries == 0)
1746 {
1747 unsigned long length;
1748
1749 /* First scan the section to get the number of comp units. */
1750 for (section_begin = start, num_units = 0; section_begin < end;
1751 num_units ++)
1752 {
1753 /* Read the first 4 bytes. For a 32-bit DWARF section, this
1754 will be the length. For a 64-bit DWARF section, it'll be
1755 the escape code 0xffffffff followed by an 8 byte length. */
1756 length = byte_get (section_begin, 4);
1757
1758 if (length == 0xffffffff)
1759 {
1760 length = byte_get (section_begin + 4, 8);
1761 section_begin += length + 12;
1762 }
ec4d4525
NC
1763 else if (length >= 0xfffffff0 && length < 0xffffffff)
1764 {
1765 warn (_("Reserved length value (%lx) found in section %s\n"), length, section->name);
1766 return 0;
1767 }
19e6b90e
L
1768 else
1769 section_begin += length + 4;
aca88567
NC
1770
1771 /* Negative values are illegal, they may even cause infinite
1772 looping. This can happen if we can't accurately apply
1773 relocations to an object file. */
1774 if ((signed long) length <= 0)
1775 {
1776 warn (_("Corrupt unit length (%lx) found in section %s\n"), length, section->name);
1777 return 0;
1778 }
19e6b90e
L
1779 }
1780
1781 if (num_units == 0)
1782 {
1783 error (_("No comp units in %s section ?"), section->name);
1784 return 0;
1785 }
1786
1787 /* Then allocate an array to hold the information. */
1788 debug_information = cmalloc (num_units,
1789 sizeof (* debug_information));
1790 if (debug_information == NULL)
1791 {
1792 error (_("Not enough memory for a debug info array of %u entries"),
1793 num_units);
1794 return 0;
1795 }
1796 }
1797
1798 if (!do_loc)
1799 {
1800 printf (_("The section %s contains:\n\n"), section->name);
1801
1802 load_debug_section (str, file);
1803 }
1804
1805 load_debug_section (abbrev, file);
1806 if (debug_displays [abbrev].section.start == NULL)
1807 {
1808 warn (_("Unable to locate %s section!\n"),
1809 debug_displays [abbrev].section.name);
1810 return 0;
1811 }
1812
1813 for (section_begin = start, unit = 0; start < end; unit++)
1814 {
1815 DWARF2_Internal_CompUnit compunit;
1816 unsigned char *hdrptr;
1817 unsigned char *cu_abbrev_offset_ptr;
1818 unsigned char *tags;
1819 int level;
1820 unsigned long cu_offset;
1821 int offset_size;
1822 int initial_length_size;
1823
1824 hdrptr = start;
1825
1826 compunit.cu_length = byte_get (hdrptr, 4);
1827 hdrptr += 4;
1828
1829 if (compunit.cu_length == 0xffffffff)
1830 {
1831 compunit.cu_length = byte_get (hdrptr, 8);
1832 hdrptr += 8;
1833 offset_size = 8;
1834 initial_length_size = 12;
1835 }
1836 else
1837 {
1838 offset_size = 4;
1839 initial_length_size = 4;
1840 }
1841
1842 compunit.cu_version = byte_get (hdrptr, 2);
1843 hdrptr += 2;
1844
1845 cu_offset = start - section_begin;
19e6b90e
L
1846
1847 cu_abbrev_offset_ptr = hdrptr;
1848 compunit.cu_abbrev_offset = byte_get (hdrptr, offset_size);
1849 hdrptr += offset_size;
1850
1851 compunit.cu_pointer_size = byte_get (hdrptr, 1);
1852 hdrptr += 1;
1853 if ((do_loc || do_debug_loc || do_debug_ranges)
1854 && num_debug_info_entries == 0)
1855 {
1856 debug_information [unit].cu_offset = cu_offset;
1857 debug_information [unit].pointer_size
1858 = compunit.cu_pointer_size;
1859 debug_information [unit].base_address = 0;
1860 debug_information [unit].loc_offsets = NULL;
1861 debug_information [unit].have_frame_base = NULL;
1862 debug_information [unit].max_loc_offsets = 0;
1863 debug_information [unit].num_loc_offsets = 0;
1864 debug_information [unit].range_lists = NULL;
1865 debug_information [unit].max_range_lists= 0;
1866 debug_information [unit].num_range_lists = 0;
1867 }
1868
19e6b90e
L
1869 if (!do_loc)
1870 {
1871 printf (_(" Compilation Unit @ offset 0x%lx:\n"), cu_offset);
cc86f28f
NC
1872 printf (_(" Length: 0x%lx (%s)\n"), compunit.cu_length,
1873 initial_length_size == 8 ? "64-bit" : "32-bit");
19e6b90e
L
1874 printf (_(" Version: %d\n"), compunit.cu_version);
1875 printf (_(" Abbrev Offset: %ld\n"), compunit.cu_abbrev_offset);
1876 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
1877 }
1878
460c89ff
NS
1879 if (cu_offset + compunit.cu_length + initial_length_size
1880 > section->size)
1881 {
ec4d4525
NC
1882 warn (_("Debug info is corrupted, length of CU at %lx extends beyond end of section (length = %lx)\n"),
1883 cu_offset, compunit.cu_length);
460c89ff
NS
1884 break;
1885 }
1886 tags = hdrptr;
1887 start += compunit.cu_length + initial_length_size;
1888
19e6b90e
L
1889 if (compunit.cu_version != 2 && compunit.cu_version != 3)
1890 {
1febe64d
NC
1891 warn (_("CU at offset %lx contains corrupt or unsupported version number: %d.\n"),
1892 cu_offset, compunit.cu_version);
19e6b90e
L
1893 continue;
1894 }
1895
1896 free_abbrevs ();
1897
bfe2612a
L
1898 /* Process the abbrevs used by this compilation unit. DWARF
1899 sections under Mach-O have non-zero addresses. */
460c89ff 1900 if (compunit.cu_abbrev_offset >= debug_displays [abbrev].section.size)
ec4d4525
NC
1901 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
1902 (unsigned long) compunit.cu_abbrev_offset,
1903 (unsigned long) debug_displays [abbrev].section.size);
460c89ff
NS
1904 else
1905 process_abbrev_section
1906 ((unsigned char *) debug_displays [abbrev].section.start
1907 + compunit.cu_abbrev_offset - debug_displays [abbrev].section.address,
1908 (unsigned char *) debug_displays [abbrev].section.start
1909 + debug_displays [abbrev].section.size);
19e6b90e
L
1910
1911 level = 0;
1912 while (tags < start)
1913 {
1914 unsigned int bytes_read;
1915 unsigned long abbrev_number;
ec4d4525 1916 unsigned long die_offset;
19e6b90e
L
1917 abbrev_entry *entry;
1918 abbrev_attr *attr;
1919
ec4d4525
NC
1920 die_offset = tags - section_begin;
1921
19e6b90e
L
1922 abbrev_number = read_leb128 (tags, & bytes_read, 0);
1923 tags += bytes_read;
1924
ec4d4525 1925 /* A null DIE marks the end of a list of siblings. */
19e6b90e
L
1926 if (abbrev_number == 0)
1927 {
1928 --level;
ec4d4525
NC
1929 if (level < 0)
1930 {
1931 static unsigned num_bogus_warns = 0;
1932
1933 if (num_bogus_warns < 3)
1934 {
1935 warn (_("Bogus end-of-siblings marker detected at offset %lx in .debug_info section\n"),
1936 die_offset);
1937 num_bogus_warns ++;
1938 if (num_bogus_warns == 3)
1939 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
1940 }
1941 }
19e6b90e
L
1942 continue;
1943 }
1944
4b78141a
NC
1945 if (!do_loc)
1946 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
ec4d4525 1947 level, die_offset, abbrev_number);
cecf136e 1948
19e6b90e
L
1949 /* Scan through the abbreviation list until we reach the
1950 correct entry. */
1951 for (entry = first_abbrev;
1952 entry && entry->entry != abbrev_number;
1953 entry = entry->next)
1954 continue;
1955
1956 if (entry == NULL)
1957 {
4b78141a
NC
1958 if (!do_loc)
1959 {
1960 printf ("\n");
1961 fflush (stdout);
1962 }
cc86f28f
NC
1963 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
1964 die_offset, abbrev_number);
19e6b90e
L
1965 return 0;
1966 }
1967
1968 if (!do_loc)
4b78141a 1969 printf (_(" (%s)\n"), get_TAG_name (entry->tag));
cecf136e 1970
19e6b90e
L
1971 switch (entry->tag)
1972 {
1973 default:
1974 need_base_address = 0;
1975 break;
1976 case DW_TAG_compile_unit:
1977 need_base_address = 1;
1978 break;
1979 case DW_TAG_entry_point:
19e6b90e
L
1980 case DW_TAG_subprogram:
1981 need_base_address = 0;
1982 /* Assuming that there is no DW_AT_frame_base. */
1983 have_frame_base = 0;
1984 break;
1985 }
1986
1987 for (attr = entry->first_attr; attr; attr = attr->next)
4b78141a
NC
1988 {
1989 if (! do_loc)
1990 /* Show the offset from where the tag was extracted. */
750f03b7 1991 printf (" <%2lx>", (unsigned long)(tags - section_begin));
4b78141a
NC
1992
1993 tags = read_and_display_attr (attr->attribute,
1994 attr->form,
1995 tags, cu_offset,
1996 compunit.cu_pointer_size,
1997 offset_size,
1998 compunit.cu_version,
ec4d4525 1999 debug_information + unit,
6e3d6dc1 2000 do_loc, section);
4b78141a 2001 }
cecf136e 2002
19e6b90e
L
2003 if (entry->children)
2004 ++level;
2005 }
2006 }
cecf136e 2007
19e6b90e
L
2008 /* Set num_debug_info_entries here so that it can be used to check if
2009 we need to process .debug_loc and .debug_ranges sections. */
2010 if ((do_loc || do_debug_loc || do_debug_ranges)
2011 && num_debug_info_entries == 0)
2012 num_debug_info_entries = num_units;
cecf136e 2013
19e6b90e
L
2014 if (!do_loc)
2015 {
2016 printf ("\n");
2017 }
cecf136e 2018
19e6b90e
L
2019 return 1;
2020}
2021
2022/* Locate and scan the .debug_info section in the file and record the pointer
2023 sizes and offsets for the compilation units in it. Usually an executable
2024 will have just one pointer size, but this is not guaranteed, and so we try
2025 not to make any assumptions. Returns zero upon failure, or the number of
2026 compilation units upon success. */
2027
2028static unsigned int
2029load_debug_info (void * file)
2030{
2031 /* Reset the last pointer size so that we can issue correct error
2032 messages if we are displaying the contents of more than one section. */
2033 last_pointer_size = 0;
2034 warned_about_missing_comp_units = FALSE;
2035
1febe64d
NC
2036 /* If we have already tried and failed to load the .debug_info
2037 section then do not bother to repear the task. */
cc86f28f 2038 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
1febe64d
NC
2039 return 0;
2040
19e6b90e
L
2041 /* If we already have the information there is nothing else to do. */
2042 if (num_debug_info_entries > 0)
2043 return num_debug_info_entries;
2044
2045 if (load_debug_section (info, file)
2046 && process_debug_info (&debug_displays [info].section, file, 1))
2047 return num_debug_info_entries;
1febe64d 2048
cc86f28f 2049 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
1febe64d 2050 return 0;
19e6b90e
L
2051}
2052
19e6b90e
L
2053static int
2054display_debug_lines (struct dwarf_section *section, void *file)
2055{
2056 unsigned char *start = section->start;
2057 unsigned char *data = start;
2058 unsigned char *end = start + section->size;
19e6b90e
L
2059
2060 printf (_("\nDump of debug contents of section %s:\n\n"),
2061 section->name);
2062
1febe64d
NC
2063 if (load_debug_info (file) == 0)
2064 {
2065 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2066 section->name);
2067 return 0;
2068 }
19e6b90e
L
2069
2070 while (data < end)
2071 {
2072 DWARF2_Internal_LineInfo info;
2073 unsigned char *standard_opcodes;
2074 unsigned char *end_of_sequence;
2075 unsigned char *hdrptr;
6523721c 2076 unsigned long hdroff;
19e6b90e
L
2077 int initial_length_size;
2078 int offset_size;
2079 int i;
2080
2081 hdrptr = data;
6523721c 2082 hdroff = hdrptr - start;
19e6b90e
L
2083
2084 /* Check the length of the block. */
2085 info.li_length = byte_get (hdrptr, 4);
2086 hdrptr += 4;
2087
2088 if (info.li_length == 0xffffffff)
2089 {
2090 /* This section is 64-bit DWARF 3. */
2091 info.li_length = byte_get (hdrptr, 8);
2092 hdrptr += 8;
2093 offset_size = 8;
2094 initial_length_size = 12;
2095 }
2096 else
2097 {
2098 offset_size = 4;
2099 initial_length_size = 4;
2100 }
2101
2102 if (info.li_length + initial_length_size > section->size)
2103 {
2104 warn
2105 (_("The line info appears to be corrupt - the section is too small\n"));
2106 return 0;
2107 }
2108
2109 /* Check its version number. */
2110 info.li_version = byte_get (hdrptr, 2);
2111 hdrptr += 2;
2112 if (info.li_version != 2 && info.li_version != 3)
2113 {
2114 warn (_("Only DWARF version 2 and 3 line info is currently supported.\n"));
2115 return 0;
2116 }
2117
2118 info.li_prologue_length = byte_get (hdrptr, offset_size);
2119 hdrptr += offset_size;
2120 info.li_min_insn_length = byte_get (hdrptr, 1);
2121 hdrptr++;
2122 info.li_default_is_stmt = byte_get (hdrptr, 1);
2123 hdrptr++;
2124 info.li_line_base = byte_get (hdrptr, 1);
2125 hdrptr++;
2126 info.li_line_range = byte_get (hdrptr, 1);
2127 hdrptr++;
2128 info.li_opcode_base = byte_get (hdrptr, 1);
2129 hdrptr++;
2130
2131 /* Sign extend the line base field. */
2132 info.li_line_base <<= 24;
2133 info.li_line_base >>= 24;
2134
6523721c 2135 printf (_(" Offset: 0x%lx\n"), hdroff);
19e6b90e
L
2136 printf (_(" Length: %ld\n"), info.li_length);
2137 printf (_(" DWARF Version: %d\n"), info.li_version);
2138 printf (_(" Prologue Length: %d\n"), info.li_prologue_length);
2139 printf (_(" Minimum Instruction Length: %d\n"), info.li_min_insn_length);
2140 printf (_(" Initial value of 'is_stmt': %d\n"), info.li_default_is_stmt);
2141 printf (_(" Line Base: %d\n"), info.li_line_base);
2142 printf (_(" Line Range: %d\n"), info.li_line_range);
2143 printf (_(" Opcode Base: %d\n"), info.li_opcode_base);
19e6b90e
L
2144
2145 end_of_sequence = data + info.li_length + initial_length_size;
2146
2147 reset_state_machine (info.li_default_is_stmt);
2148
2149 /* Display the contents of the Opcodes table. */
2150 standard_opcodes = hdrptr;
2151
2152 printf (_("\n Opcodes:\n"));
2153
2154 for (i = 1; i < info.li_opcode_base; i++)
2155 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2156
2157 /* Display the contents of the Directory table. */
2158 data = standard_opcodes + info.li_opcode_base - 1;
2159
2160 if (*data == 0)
2161 printf (_("\n The Directory Table is empty.\n"));
2162 else
2163 {
2164 printf (_("\n The Directory Table:\n"));
2165
2166 while (*data != 0)
2167 {
2168 printf (_(" %s\n"), data);
2169
2170 data += strlen ((char *) data) + 1;
2171 }
2172 }
2173
2174 /* Skip the NUL at the end of the table. */
2175 data++;
2176
2177 /* Display the contents of the File Name table. */
2178 if (*data == 0)
2179 printf (_("\n The File Name Table is empty.\n"));
2180 else
2181 {
2182 printf (_("\n The File Name Table:\n"));
2183 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2184
2185 while (*data != 0)
2186 {
2187 unsigned char *name;
2188 unsigned int bytes_read;
2189
2190 printf (_(" %d\t"), ++state_machine_regs.last_file_entry);
2191 name = data;
2192
2193 data += strlen ((char *) data) + 1;
2194
2195 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2196 data += bytes_read;
2197 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2198 data += bytes_read;
2199 printf (_("%lu\t"), read_leb128 (data, & bytes_read, 0));
2200 data += bytes_read;
2201 printf (_("%s\n"), name);
2202 }
2203 }
2204
2205 /* Skip the NUL at the end of the table. */
2206 data++;
2207
2208 /* Now display the statements. */
2209 printf (_("\n Line Number Statements:\n"));
2210
2211 while (data < end_of_sequence)
2212 {
2213 unsigned char op_code;
2214 int adv;
2215 unsigned long int uladv;
2216 unsigned int bytes_read;
2217
2218 op_code = *data++;
2219
2220 if (op_code >= info.li_opcode_base)
2221 {
2222 op_code -= info.li_opcode_base;
2223 uladv = (op_code / info.li_line_range) * info.li_min_insn_length;
2224 state_machine_regs.address += uladv;
2225 printf (_(" Special opcode %d: advance Address by %lu to 0x%lx"),
2226 op_code, uladv, state_machine_regs.address);
2227 adv = (op_code % info.li_line_range) + info.li_line_base;
2228 state_machine_regs.line += adv;
2229 printf (_(" and Line by %d to %d\n"),
2230 adv, state_machine_regs.line);
2231 }
2232 else switch (op_code)
2233 {
2234 case DW_LNS_extended_op:
1617e571 2235 data += process_extended_line_op (data, info.li_default_is_stmt);
19e6b90e
L
2236 break;
2237
2238 case DW_LNS_copy:
2239 printf (_(" Copy\n"));
2240 break;
2241
2242 case DW_LNS_advance_pc:
2243 uladv = read_leb128 (data, & bytes_read, 0);
2244 uladv *= info.li_min_insn_length;
2245 data += bytes_read;
2246 state_machine_regs.address += uladv;
2247 printf (_(" Advance PC by %lu to 0x%lx\n"), uladv,
2248 state_machine_regs.address);
2249 break;
2250
2251 case DW_LNS_advance_line:
2252 adv = read_leb128 (data, & bytes_read, 1);
2253 data += bytes_read;
2254 state_machine_regs.line += adv;
2255 printf (_(" Advance Line by %d to %d\n"), adv,
2256 state_machine_regs.line);
2257 break;
2258
2259 case DW_LNS_set_file:
2260 adv = read_leb128 (data, & bytes_read, 0);
2261 data += bytes_read;
2262 printf (_(" Set File Name to entry %d in the File Name Table\n"),
2263 adv);
2264 state_machine_regs.file = adv;
2265 break;
2266
2267 case DW_LNS_set_column:
2268 uladv = read_leb128 (data, & bytes_read, 0);
2269 data += bytes_read;
2270 printf (_(" Set column to %lu\n"), uladv);
2271 state_machine_regs.column = uladv;
2272 break;
2273
2274 case DW_LNS_negate_stmt:
2275 adv = state_machine_regs.is_stmt;
2276 adv = ! adv;
2277 printf (_(" Set is_stmt to %d\n"), adv);
2278 state_machine_regs.is_stmt = adv;
2279 break;
2280
2281 case DW_LNS_set_basic_block:
2282 printf (_(" Set basic block\n"));
2283 state_machine_regs.basic_block = 1;
2284 break;
2285
2286 case DW_LNS_const_add_pc:
2287 uladv = (((255 - info.li_opcode_base) / info.li_line_range)
2288 * info.li_min_insn_length);
2289 state_machine_regs.address += uladv;
2290 printf (_(" Advance PC by constant %lu to 0x%lx\n"), uladv,
2291 state_machine_regs.address);
2292 break;
2293
2294 case DW_LNS_fixed_advance_pc:
2295 uladv = byte_get (data, 2);
2296 data += 2;
2297 state_machine_regs.address += uladv;
2298 printf (_(" Advance PC by fixed size amount %lu to 0x%lx\n"),
2299 uladv, state_machine_regs.address);
2300 break;
2301
2302 case DW_LNS_set_prologue_end:
2303 printf (_(" Set prologue_end to true\n"));
2304 break;
2305
2306 case DW_LNS_set_epilogue_begin:
2307 printf (_(" Set epilogue_begin to true\n"));
2308 break;
2309
2310 case DW_LNS_set_isa:
2311 uladv = read_leb128 (data, & bytes_read, 0);
2312 data += bytes_read;
2313 printf (_(" Set ISA to %lu\n"), uladv);
2314 break;
2315
2316 default:
2317 printf (_(" Unknown opcode %d with operands: "), op_code);
2318
2319 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2320 {
2321 printf ("0x%lx%s", read_leb128 (data, &bytes_read, 0),
2322 i == 1 ? "" : ", ");
2323 data += bytes_read;
2324 }
2325 putchar ('\n');
2326 break;
2327 }
2328 }
2329 putchar ('\n');
2330 }
2331
2332 return 1;
2333}
2334
6e3d6dc1
NC
2335static debug_info *
2336find_debug_info_for_offset (unsigned long offset)
2337{
2338 unsigned int i;
2339
2340 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2341 return NULL;
2342
2343 for (i = 0; i < num_debug_info_entries; i++)
2344 if (debug_information[i].cu_offset == offset)
2345 return debug_information + i;
2346
2347 return NULL;
2348}
2349
19e6b90e
L
2350static int
2351display_debug_pubnames (struct dwarf_section *section,
2352 void *file ATTRIBUTE_UNUSED)
2353{
2354 DWARF2_Internal_PubNames pubnames;
2355 unsigned char *start = section->start;
2356 unsigned char *end = start + section->size;
2357
6e3d6dc1
NC
2358 /* It does not matter if this load fails,
2359 we test for that later on. */
2360 load_debug_info (file);
2361
19e6b90e
L
2362 printf (_("Contents of the %s section:\n\n"), section->name);
2363
2364 while (start < end)
2365 {
2366 unsigned char *data;
2367 unsigned long offset;
2368 int offset_size, initial_length_size;
2369
2370 data = start;
2371
2372 pubnames.pn_length = byte_get (data, 4);
2373 data += 4;
2374 if (pubnames.pn_length == 0xffffffff)
2375 {
2376 pubnames.pn_length = byte_get (data, 8);
2377 data += 8;
2378 offset_size = 8;
2379 initial_length_size = 12;
2380 }
2381 else
2382 {
2383 offset_size = 4;
2384 initial_length_size = 4;
2385 }
2386
2387 pubnames.pn_version = byte_get (data, 2);
2388 data += 2;
6e3d6dc1 2389
19e6b90e
L
2390 pubnames.pn_offset = byte_get (data, offset_size);
2391 data += offset_size;
6e3d6dc1
NC
2392
2393 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
2394 && num_debug_info_entries > 0
2395 && find_debug_info_for_offset (pubnames.pn_offset) == NULL)
2396 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2397 pubnames.pn_offset, section->name);
cecf136e 2398
19e6b90e
L
2399 pubnames.pn_size = byte_get (data, offset_size);
2400 data += offset_size;
2401
2402 start += pubnames.pn_length + initial_length_size;
2403
2404 if (pubnames.pn_version != 2 && pubnames.pn_version != 3)
2405 {
2406 static int warned = 0;
2407
2408 if (! warned)
2409 {
2410 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
2411 warned = 1;
2412 }
2413
2414 continue;
2415 }
2416
2417 printf (_(" Length: %ld\n"),
2418 pubnames.pn_length);
2419 printf (_(" Version: %d\n"),
2420 pubnames.pn_version);
6e3d6dc1 2421 printf (_(" Offset into .debug_info section: 0x%lx\n"),
19e6b90e
L
2422 pubnames.pn_offset);
2423 printf (_(" Size of area in .debug_info section: %ld\n"),
2424 pubnames.pn_size);
2425
2426 printf (_("\n Offset\tName\n"));
2427
2428 do
2429 {
2430 offset = byte_get (data, offset_size);
2431
2432 if (offset != 0)
2433 {
2434 data += offset_size;
2435 printf (" %-6ld\t\t%s\n", offset, data);
2436 data += strlen ((char *) data) + 1;
2437 }
2438 }
2439 while (offset != 0);
2440 }
2441
2442 printf ("\n");
2443 return 1;
2444}
2445
2446static int
2447display_debug_macinfo (struct dwarf_section *section,
2448 void *file ATTRIBUTE_UNUSED)
2449{
2450 unsigned char *start = section->start;
2451 unsigned char *end = start + section->size;
2452 unsigned char *curr = start;
2453 unsigned int bytes_read;
2454 enum dwarf_macinfo_record_type op;
2455
2456 printf (_("Contents of the %s section:\n\n"), section->name);
2457
2458 while (curr < end)
2459 {
2460 unsigned int lineno;
2461 const char *string;
2462
2463 op = *curr;
2464 curr++;
2465
2466 switch (op)
2467 {
2468 case DW_MACINFO_start_file:
2469 {
2470 unsigned int filenum;
2471
2472 lineno = read_leb128 (curr, & bytes_read, 0);
2473 curr += bytes_read;
2474 filenum = read_leb128 (curr, & bytes_read, 0);
2475 curr += bytes_read;
2476
2477 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
2478 lineno, filenum);
2479 }
2480 break;
2481
2482 case DW_MACINFO_end_file:
2483 printf (_(" DW_MACINFO_end_file\n"));
2484 break;
2485
2486 case DW_MACINFO_define:
2487 lineno = read_leb128 (curr, & bytes_read, 0);
2488 curr += bytes_read;
2489 string = (char *) curr;
2490 curr += strlen (string) + 1;
2491 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
2492 lineno, string);
2493 break;
2494
2495 case DW_MACINFO_undef:
2496 lineno = read_leb128 (curr, & bytes_read, 0);
2497 curr += bytes_read;
2498 string = (char *) curr;
2499 curr += strlen (string) + 1;
2500 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
2501 lineno, string);
2502 break;
2503
2504 case DW_MACINFO_vendor_ext:
2505 {
2506 unsigned int constant;
2507
2508 constant = read_leb128 (curr, & bytes_read, 0);
2509 curr += bytes_read;
2510 string = (char *) curr;
2511 curr += strlen (string) + 1;
2512 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
2513 constant, string);
2514 }
2515 break;
2516 }
2517 }
2518
2519 return 1;
2520}
2521
2522static int
2523display_debug_abbrev (struct dwarf_section *section,
2524 void *file ATTRIBUTE_UNUSED)
2525{
2526 abbrev_entry *entry;
2527 unsigned char *start = section->start;
2528 unsigned char *end = start + section->size;
2529
2530 printf (_("Contents of the %s section:\n\n"), section->name);
2531
2532 do
2533 {
2534 free_abbrevs ();
2535
2536 start = process_abbrev_section (start, end);
2537
2538 if (first_abbrev == NULL)
2539 continue;
2540
2541 printf (_(" Number TAG\n"));
2542
2543 for (entry = first_abbrev; entry; entry = entry->next)
2544 {
2545 abbrev_attr *attr;
2546
2547 printf (_(" %ld %s [%s]\n"),
2548 entry->entry,
2549 get_TAG_name (entry->tag),
2550 entry->children ? _("has children") : _("no children"));
2551
2552 for (attr = entry->first_attr; attr; attr = attr->next)
2553 printf (_(" %-18s %s\n"),
2554 get_AT_name (attr->attribute),
2555 get_FORM_name (attr->form));
2556 }
2557 }
2558 while (start);
2559
2560 printf ("\n");
2561
2562 return 1;
2563}
2564
2565static int
2566display_debug_loc (struct dwarf_section *section, void *file)
2567{
2568 unsigned char *start = section->start;
2569 unsigned char *section_end;
2570 unsigned long bytes;
2571 unsigned char *section_begin = start;
2572 unsigned int num_loc_list = 0;
2573 unsigned long last_offset = 0;
2574 unsigned int first = 0;
2575 unsigned int i;
2576 unsigned int j;
2577 int seen_first_offset = 0;
2578 int use_debug_info = 1;
2579 unsigned char *next;
2580
2581 bytes = section->size;
2582 section_end = start + bytes;
2583
2584 if (bytes == 0)
2585 {
2586 printf (_("\nThe %s section is empty.\n"), section->name);
2587 return 0;
2588 }
2589
1febe64d
NC
2590 if (load_debug_info (file) == 0)
2591 {
2592 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2593 section->name);
2594 return 0;
2595 }
19e6b90e
L
2596
2597 /* Check the order of location list in .debug_info section. If
2598 offsets of location lists are in the ascending order, we can
2599 use `debug_information' directly. */
2600 for (i = 0; i < num_debug_info_entries; i++)
2601 {
2602 unsigned int num;
2603
2604 num = debug_information [i].num_loc_offsets;
2605 num_loc_list += num;
2606
2607 /* Check if we can use `debug_information' directly. */
2608 if (use_debug_info && num != 0)
2609 {
2610 if (!seen_first_offset)
2611 {
2612 /* This is the first location list. */
2613 last_offset = debug_information [i].loc_offsets [0];
2614 first = i;
2615 seen_first_offset = 1;
2616 j = 1;
2617 }
2618 else
2619 j = 0;
2620
2621 for (; j < num; j++)
2622 {
2623 if (last_offset >
2624 debug_information [i].loc_offsets [j])
2625 {
2626 use_debug_info = 0;
2627 break;
2628 }
2629 last_offset = debug_information [i].loc_offsets [j];
2630 }
2631 }
2632 }
2633
2634 if (!use_debug_info)
2635 /* FIXME: Should we handle this case? */
2636 error (_("Location lists in .debug_info section aren't in ascending order!\n"));
2637
2638 if (!seen_first_offset)
2639 error (_("No location lists in .debug_info section!\n"));
2640
bfe2612a 2641 /* DWARF sections under Mach-O have non-zero addresses. */
d4bfc77b
AS
2642 if (debug_information [first].num_loc_offsets > 0
2643 && debug_information [first].loc_offsets [0] != section->address)
19e6b90e
L
2644 warn (_("Location lists in %s section start at 0x%lx\n"),
2645 section->name, debug_information [first].loc_offsets [0]);
2646
2647 printf (_("Contents of the %s section:\n\n"), section->name);
2648 printf (_(" Offset Begin End Expression\n"));
2649
2650 seen_first_offset = 0;
2651 for (i = first; i < num_debug_info_entries; i++)
2652 {
2d9472a2
NC
2653 dwarf_vma begin;
2654 dwarf_vma end;
19e6b90e
L
2655 unsigned short length;
2656 unsigned long offset;
2657 unsigned int pointer_size;
2658 unsigned long cu_offset;
2659 unsigned long base_address;
2660 int need_frame_base;
2661 int has_frame_base;
2662
2663 pointer_size = debug_information [i].pointer_size;
2664 cu_offset = debug_information [i].cu_offset;
2665
2666 for (j = 0; j < debug_information [i].num_loc_offsets; j++)
2667 {
2668 has_frame_base = debug_information [i].have_frame_base [j];
bfe2612a 2669 /* DWARF sections under Mach-O have non-zero addresses. */
cecf136e 2670 offset = debug_information [i].loc_offsets [j] - section->address;
19e6b90e
L
2671 next = section_begin + offset;
2672 base_address = debug_information [i].base_address;
2673
2674 if (!seen_first_offset)
2675 seen_first_offset = 1;
2676 else
2677 {
2678 if (start < next)
2679 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
2680 (long)(start - section_begin), (long)(next - section_begin));
2681 else if (start > next)
2682 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
2683 (long)(start - section_begin), (long)(next - section_begin));
2684 }
2685 start = next;
2686
2687 if (offset >= bytes)
2688 {
2689 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
2690 offset);
2691 continue;
2692 }
2693
2694 while (1)
2695 {
2696 if (start + 2 * pointer_size > section_end)
2697 {
2698 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2699 offset);
2700 break;
2701 }
2702
2d9472a2
NC
2703 /* Note: we use sign extension here in order to be sure that
2704 we can detect the -1 escape value. Sign extension into the
2705 top 32 bits of a 32-bit address will not affect the values
2706 that we display since we always show hex values, and always
cecf136e 2707 the bottom 32-bits. */
2d9472a2 2708 begin = byte_get_signed (start, pointer_size);
19e6b90e 2709 start += pointer_size;
2d9472a2 2710 end = byte_get_signed (start, pointer_size);
19e6b90e
L
2711 start += pointer_size;
2712
2d9472a2
NC
2713 printf (" %8.8lx ", offset);
2714
19e6b90e
L
2715 if (begin == 0 && end == 0)
2716 {
2d9472a2 2717 printf (_("<End of list>\n"));
19e6b90e
L
2718 break;
2719 }
2720
2721 /* Check base address specifiers. */
2d9472a2 2722 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
19e6b90e
L
2723 {
2724 base_address = end;
2d9472a2
NC
2725 print_dwarf_vma (begin, pointer_size);
2726 print_dwarf_vma (end, pointer_size);
2727 printf (_("(base address)\n"));
19e6b90e
L
2728 continue;
2729 }
2730
2731 if (start + 2 > section_end)
2732 {
2733 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2734 offset);
2735 break;
2736 }
2737
2738 length = byte_get (start, 2);
2739 start += 2;
2740
2741 if (start + length > section_end)
2742 {
2743 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
2744 offset);
2745 break;
2746 }
2747
2d9472a2
NC
2748 print_dwarf_vma (begin + base_address, pointer_size);
2749 print_dwarf_vma (end + base_address, pointer_size);
2750
2751 putchar ('(');
19e6b90e
L
2752 need_frame_base = decode_location_expression (start,
2753 pointer_size,
2754 length,
2755 cu_offset);
2756 putchar (')');
2757
2758 if (need_frame_base && !has_frame_base)
2759 printf (_(" [without DW_AT_frame_base]"));
2760
2761 if (begin == end)
2762 fputs (_(" (start == end)"), stdout);
2763 else if (begin > end)
2764 fputs (_(" (start > end)"), stdout);
2765
2766 putchar ('\n');
2767
2768 start += length;
2769 }
2770 }
2771 }
031cd65f
NC
2772
2773 if (start < section_end)
2774 warn (_("There are %ld unused bytes at the end of section %s\n"),
0eb090cb 2775 (long) (section_end - start), section->name);
19e6b90e
L
2776 return 1;
2777}
2778
2779static int
2780display_debug_str (struct dwarf_section *section,
2781 void *file ATTRIBUTE_UNUSED)
2782{
2783 unsigned char *start = section->start;
2784 unsigned long bytes = section->size;
2785 dwarf_vma addr = section->address;
2786
2787 if (bytes == 0)
2788 {
2789 printf (_("\nThe %s section is empty.\n"), section->name);
2790 return 0;
2791 }
2792
2793 printf (_("Contents of the %s section:\n\n"), section->name);
2794
2795 while (bytes)
2796 {
2797 int j;
2798 int k;
2799 int lbytes;
2800
2801 lbytes = (bytes > 16 ? 16 : bytes);
2802
2803 printf (" 0x%8.8lx ", (unsigned long) addr);
2804
2805 for (j = 0; j < 16; j++)
2806 {
2807 if (j < lbytes)
2808 printf ("%2.2x", start[j]);
2809 else
2810 printf (" ");
2811
2812 if ((j & 3) == 3)
2813 printf (" ");
2814 }
2815
2816 for (j = 0; j < lbytes; j++)
2817 {
2818 k = start[j];
2819 if (k >= ' ' && k < 0x80)
2820 printf ("%c", k);
2821 else
2822 printf (".");
2823 }
2824
2825 putchar ('\n');
2826
2827 start += lbytes;
2828 addr += lbytes;
2829 bytes -= lbytes;
2830 }
2831
2832 putchar ('\n');
2833
2834 return 1;
2835}
2836
19e6b90e
L
2837static int
2838display_debug_info (struct dwarf_section *section, void *file)
2839{
2840 return process_debug_info (section, file, 0);
2841}
2842
2843
2844static int
2845display_debug_aranges (struct dwarf_section *section,
2846 void *file ATTRIBUTE_UNUSED)
2847{
2848 unsigned char *start = section->start;
2849 unsigned char *end = start + section->size;
2850
2851 printf (_("The section %s contains:\n\n"), section->name);
2852
6e3d6dc1
NC
2853 /* It does not matter if this load fails,
2854 we test for that later on. */
2855 load_debug_info (file);
2856
19e6b90e
L
2857 while (start < end)
2858 {
2859 unsigned char *hdrptr;
2860 DWARF2_Internal_ARange arange;
2861 unsigned char *ranges;
2d9472a2
NC
2862 dwarf_vma length;
2863 dwarf_vma address;
53b8873b 2864 unsigned char address_size;
19e6b90e
L
2865 int excess;
2866 int offset_size;
2867 int initial_length_size;
2868
2869 hdrptr = start;
2870
2871 arange.ar_length = byte_get (hdrptr, 4);
2872 hdrptr += 4;
2873
2874 if (arange.ar_length == 0xffffffff)
2875 {
2876 arange.ar_length = byte_get (hdrptr, 8);
2877 hdrptr += 8;
2878 offset_size = 8;
2879 initial_length_size = 12;
2880 }
2881 else
2882 {
2883 offset_size = 4;
2884 initial_length_size = 4;
2885 }
2886
2887 arange.ar_version = byte_get (hdrptr, 2);
2888 hdrptr += 2;
2889
2890 arange.ar_info_offset = byte_get (hdrptr, offset_size);
2891 hdrptr += offset_size;
2892
6e3d6dc1
NC
2893 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
2894 && num_debug_info_entries > 0
2895 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
2896 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
2897 arange.ar_info_offset, section->name);
2898
19e6b90e
L
2899 arange.ar_pointer_size = byte_get (hdrptr, 1);
2900 hdrptr += 1;
2901
2902 arange.ar_segment_size = byte_get (hdrptr, 1);
2903 hdrptr += 1;
2904
2905 if (arange.ar_version != 2 && arange.ar_version != 3)
2906 {
2907 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
2908 break;
2909 }
2910
2911 printf (_(" Length: %ld\n"), arange.ar_length);
2912 printf (_(" Version: %d\n"), arange.ar_version);
6e3d6dc1 2913 printf (_(" Offset into .debug_info: 0x%lx\n"), arange.ar_info_offset);
19e6b90e
L
2914 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
2915 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
2916
53b8873b
NC
2917 address_size = arange.ar_pointer_size + arange.ar_segment_size;
2918
2919 /* The DWARF spec does not require that the address size be a power
2920 of two, but we do. This will have to change if we ever encounter
2921 an uneven architecture. */
2922 if ((address_size & (address_size - 1)) != 0)
2923 {
2924 warn (_("Pointer size + Segment size is not a power of two.\n"));
2925 break;
2926 }
cecf136e 2927
209c9a13
NC
2928 if (address_size > 4)
2929 printf (_("\n Address Length\n"));
2930 else
2931 printf (_("\n Address Length\n"));
19e6b90e
L
2932
2933 ranges = hdrptr;
2934
53b8873b
NC
2935 /* Must pad to an alignment boundary that is twice the address size. */
2936 excess = (hdrptr - start) % (2 * address_size);
19e6b90e 2937 if (excess)
53b8873b 2938 ranges += (2 * address_size) - excess;
19e6b90e 2939
1617e571
AM
2940 start += arange.ar_length + initial_length_size;
2941
53b8873b 2942 while (ranges + 2 * address_size <= start)
19e6b90e 2943 {
53b8873b 2944 address = byte_get (ranges, address_size);
19e6b90e 2945
53b8873b 2946 ranges += address_size;
19e6b90e 2947
53b8873b 2948 length = byte_get (ranges, address_size);
19e6b90e 2949
53b8873b 2950 ranges += address_size;
19e6b90e 2951
2d9472a2
NC
2952 print_dwarf_vma (address, address_size);
2953 print_dwarf_vma (length, address_size);
2954 putchar ('\n');
19e6b90e 2955 }
19e6b90e
L
2956 }
2957
2958 printf ("\n");
2959
2960 return 1;
2961}
2962
2963static int
2964display_debug_ranges (struct dwarf_section *section,
2965 void *file ATTRIBUTE_UNUSED)
2966{
2967 unsigned char *start = section->start;
2968 unsigned char *section_end;
2969 unsigned long bytes;
2970 unsigned char *section_begin = start;
2971 unsigned int num_range_list = 0;
2972 unsigned long last_offset = 0;
2973 unsigned int first = 0;
2974 unsigned int i;
2975 unsigned int j;
2976 int seen_first_offset = 0;
2977 int use_debug_info = 1;
2978 unsigned char *next;
2979
2980 bytes = section->size;
2981 section_end = start + bytes;
2982
2983 if (bytes == 0)
2984 {
2985 printf (_("\nThe %s section is empty.\n"), section->name);
2986 return 0;
2987 }
2988
1febe64d
NC
2989 if (load_debug_info (file) == 0)
2990 {
2991 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
2992 section->name);
2993 return 0;
2994 }
19e6b90e
L
2995
2996 /* Check the order of range list in .debug_info section. If
2997 offsets of range lists are in the ascending order, we can
2998 use `debug_information' directly. */
2999 for (i = 0; i < num_debug_info_entries; i++)
3000 {
3001 unsigned int num;
3002
3003 num = debug_information [i].num_range_lists;
3004 num_range_list += num;
3005
3006 /* Check if we can use `debug_information' directly. */
3007 if (use_debug_info && num != 0)
3008 {
3009 if (!seen_first_offset)
3010 {
3011 /* This is the first range list. */
3012 last_offset = debug_information [i].range_lists [0];
3013 first = i;
3014 seen_first_offset = 1;
3015 j = 1;
3016 }
3017 else
3018 j = 0;
3019
3020 for (; j < num; j++)
3021 {
3022 if (last_offset >
3023 debug_information [i].range_lists [j])
3024 {
3025 use_debug_info = 0;
3026 break;
3027 }
3028 last_offset = debug_information [i].range_lists [j];
3029 }
3030 }
3031 }
3032
3033 if (!use_debug_info)
3034 /* FIXME: Should we handle this case? */
3035 error (_("Range lists in .debug_info section aren't in ascending order!\n"));
3036
3037 if (!seen_first_offset)
3038 error (_("No range lists in .debug_info section!\n"));
3039
bfe2612a 3040 /* DWARF sections under Mach-O have non-zero addresses. */
d4bfc77b
AS
3041 if (debug_information [first].num_range_lists > 0
3042 && debug_information [first].range_lists [0] != section->address)
19e6b90e
L
3043 warn (_("Range lists in %s section start at 0x%lx\n"),
3044 section->name, debug_information [first].range_lists [0]);
3045
3046 printf (_("Contents of the %s section:\n\n"), section->name);
3047 printf (_(" Offset Begin End\n"));
3048
3049 seen_first_offset = 0;
3050 for (i = first; i < num_debug_info_entries; i++)
3051 {
2d9472a2
NC
3052 dwarf_vma begin;
3053 dwarf_vma end;
19e6b90e
L
3054 unsigned long offset;
3055 unsigned int pointer_size;
3056 unsigned long base_address;
3057
3058 pointer_size = debug_information [i].pointer_size;
cecf136e 3059
19e6b90e
L
3060 for (j = 0; j < debug_information [i].num_range_lists; j++)
3061 {
bfe2612a
L
3062 /* DWARF sections under Mach-O have non-zero addresses. */
3063 offset = debug_information [i].range_lists [j] - section->address;
19e6b90e
L
3064 next = section_begin + offset;
3065 base_address = debug_information [i].base_address;
3066
3067 if (!seen_first_offset)
3068 seen_first_offset = 1;
3069 else
3070 {
3071 if (start < next)
3072 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
3073 (long)(start - section_begin),
3074 (long)(next - section_begin), section->name);
3075 else if (start > next)
3076 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
3077 (long)(start - section_begin),
3078 (long)(next - section_begin), section->name);
3079 }
3080 start = next;
3081
3082 while (1)
3083 {
2d9472a2
NC
3084 /* Note: we use sign extension here in order to be sure that
3085 we can detect the -1 escape value. Sign extension into the
3086 top 32 bits of a 32-bit address will not affect the values
3087 that we display since we always show hex values, and always
cecf136e 3088 the bottom 32-bits. */
2d9472a2 3089 begin = byte_get_signed (start, pointer_size);
19e6b90e 3090 start += pointer_size;
2d9472a2 3091 end = byte_get_signed (start, pointer_size);
19e6b90e
L
3092 start += pointer_size;
3093
2d9472a2
NC
3094 printf (" %8.8lx ", offset);
3095
19e6b90e
L
3096 if (begin == 0 && end == 0)
3097 {
2d9472a2 3098 printf (_("<End of list>\n"));
19e6b90e
L
3099 break;
3100 }
3101
2d9472a2
NC
3102 print_dwarf_vma (begin, pointer_size);
3103 print_dwarf_vma (end, pointer_size);
3104
19e6b90e 3105 /* Check base address specifiers. */
2d9472a2 3106 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
19e6b90e
L
3107 {
3108 base_address = end;
2d9472a2 3109 printf ("(base address)\n");
19e6b90e
L
3110 continue;
3111 }
3112
19e6b90e 3113 if (begin == end)
2d9472a2 3114 fputs (_("(start == end)"), stdout);
19e6b90e 3115 else if (begin > end)
2d9472a2 3116 fputs (_("(start > end)"), stdout);
19e6b90e
L
3117
3118 putchar ('\n');
3119 }
3120 }
3121 }
3122 putchar ('\n');
3123 return 1;
3124}
3125
3126typedef struct Frame_Chunk
3127{
3128 struct Frame_Chunk *next;
3129 unsigned char *chunk_start;
3130 int ncols;
3131 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
3132 short int *col_type;
3133 int *col_offset;
3134 char *augmentation;
3135 unsigned int code_factor;
3136 int data_factor;
3137 unsigned long pc_begin;
3138 unsigned long pc_range;
3139 int cfa_reg;
3140 int cfa_offset;
3141 int ra;
3142 unsigned char fde_encoding;
3143 unsigned char cfa_exp;
3144}
3145Frame_Chunk;
3146
3147/* A marker for a col_type that means this column was never referenced
3148 in the frame info. */
3149#define DW_CFA_unreferenced (-1)
3150
3151static void
3152frame_need_space (Frame_Chunk *fc, int reg)
3153{
3154 int prev = fc->ncols;
3155
3156 if (reg < fc->ncols)
3157 return;
3158
3159 fc->ncols = reg + 1;
3160 fc->col_type = xcrealloc (fc->col_type, fc->ncols, sizeof (short int));
3161 fc->col_offset = xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
3162
3163 while (prev < fc->ncols)
3164 {
3165 fc->col_type[prev] = DW_CFA_unreferenced;
3166 fc->col_offset[prev] = 0;
3167 prev++;
3168 }
3169}
3170
2dc4cec1
L
3171static const char *const dwarf_regnames_i386[] =
3172{
3173 "eax", "ecx", "edx", "ebx",
3174 "esp", "ebp", "esi", "edi",
3175 "eip", "eflags", NULL,
3176 "st0", "st1", "st2", "st3",
3177 "st4", "st5", "st6", "st7",
3178 NULL, NULL,
3179 "xmm0", "xmm1", "xmm2", "xmm3",
3180 "xmm4", "xmm5", "xmm6", "xmm7",
3181 "mm0", "mm1", "mm2", "mm3",
3182 "mm4", "mm5", "mm6", "mm7",
3183 "fcw", "fsw", "mxcsr",
3184 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
c0f3af97
L
3185 "tr", "ldtr",
3186 NULL, NULL, NULL,
3187 "ymm0", "ymm1", "ymm2", "ymm3",
3188 "ymm4", "ymm5", "ymm6", "ymm7"
2dc4cec1
L
3189};
3190
3191static const char *const dwarf_regnames_x86_64[] =
3192{
3193 "rax", "rdx", "rcx", "rbx",
3194 "rsi", "rdi", "rbp", "rsp",
3195 "r8", "r9", "r10", "r11",
3196 "r12", "r13", "r14", "r15",
3197 "rip",
3198 "xmm0", "xmm1", "xmm2", "xmm3",
3199 "xmm4", "xmm5", "xmm6", "xmm7",
3200 "xmm8", "xmm9", "xmm10", "xmm11",
3201 "xmm12", "xmm13", "xmm14", "xmm15",
3202 "st0", "st1", "st2", "st3",
3203 "st4", "st5", "st6", "st7",
3204 "mm0", "mm1", "mm2", "mm3",
3205 "mm4", "mm5", "mm6", "mm7",
3206 "rflags",
3207 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
3208 "fs.base", "gs.base", NULL, NULL,
3209 "tr", "ldtr",
c0f3af97
L
3210 "mxcsr", "fcw", "fsw",
3211 NULL, NULL, NULL,
3212 "ymm0", "ymm1", "ymm2", "ymm3",
3213 "ymm4", "ymm5", "ymm6", "ymm7",
3214 "ymm8", "ymm9", "ymm10", "ymm11",
3215 "ymm12", "ymm13", "ymm14", "ymm15"
2dc4cec1
L
3216};
3217
3218static const char *const *dwarf_regnames;
3219static unsigned int dwarf_regnames_count;
3220
3221void
3222init_dwarf_regnames (unsigned int e_machine)
3223{
3224 switch (e_machine)
3225 {
3226 case EM_386:
3227 case EM_486:
3228 dwarf_regnames = dwarf_regnames_i386;
3229 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
3230 break;
3231
3232 case EM_X86_64:
3233 dwarf_regnames = dwarf_regnames_x86_64;
3234 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
3235 break;
3236
3237 default:
3238 break;
3239 }
3240}
3241
3242static const char *
3243regname (unsigned int regno, int row)
3244{
3245 static char reg[64];
3246 if (dwarf_regnames
3247 && regno < dwarf_regnames_count
3248 && dwarf_regnames [regno] != NULL)
3249 {
3250 if (row)
3251 return dwarf_regnames [regno];
3252 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
3253 dwarf_regnames [regno]);
3254 }
3255 else
3256 snprintf (reg, sizeof (reg), "r%d", regno);
3257 return reg;
3258}
3259
19e6b90e
L
3260static void
3261frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
3262{
3263 int r;
3264 char tmp[100];
3265
3266 if (*max_regs < fc->ncols)
3267 *max_regs = fc->ncols;
3268
3269 if (*need_col_headers)
3270 {
2dc4cec1
L
3271 static const char *loc = " LOC";
3272
19e6b90e
L
3273 *need_col_headers = 0;
3274
2dc4cec1 3275 printf ("%-*s CFA ", eh_addr_size * 2, loc);
19e6b90e
L
3276
3277 for (r = 0; r < *max_regs; r++)
3278 if (fc->col_type[r] != DW_CFA_unreferenced)
3279 {
3280 if (r == fc->ra)
2dc4cec1 3281 printf ("ra ");
19e6b90e 3282 else
2dc4cec1 3283 printf ("%-5s ", regname (r, 1));
19e6b90e
L
3284 }
3285
3286 printf ("\n");
3287 }
3288
2dc4cec1 3289 printf ("%0*lx ", eh_addr_size * 2, fc->pc_begin);
19e6b90e
L
3290 if (fc->cfa_exp)
3291 strcpy (tmp, "exp");
3292 else
2dc4cec1 3293 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
19e6b90e
L
3294 printf ("%-8s ", tmp);
3295
3296 for (r = 0; r < fc->ncols; r++)
3297 {
3298 if (fc->col_type[r] != DW_CFA_unreferenced)
3299 {
3300 switch (fc->col_type[r])
3301 {
3302 case DW_CFA_undefined:
3303 strcpy (tmp, "u");
3304 break;
3305 case DW_CFA_same_value:
3306 strcpy (tmp, "s");
3307 break;
3308 case DW_CFA_offset:
3309 sprintf (tmp, "c%+d", fc->col_offset[r]);
3310 break;
12eae2d3
JJ
3311 case DW_CFA_val_offset:
3312 sprintf (tmp, "v%+d", fc->col_offset[r]);
3313 break;
19e6b90e 3314 case DW_CFA_register:
2dc4cec1 3315 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
19e6b90e
L
3316 break;
3317 case DW_CFA_expression:
3318 strcpy (tmp, "exp");
3319 break;
12eae2d3
JJ
3320 case DW_CFA_val_expression:
3321 strcpy (tmp, "vexp");
3322 break;
19e6b90e
L
3323 default:
3324 strcpy (tmp, "n/a");
3325 break;
3326 }
2dc4cec1 3327 printf ("%-5s ", tmp);
19e6b90e
L
3328 }
3329 }
3330 printf ("\n");
3331}
3332
3333static int
3334size_of_encoded_value (int encoding)
3335{
3336 switch (encoding & 0x7)
3337 {
3338 default: /* ??? */
3339 case 0: return eh_addr_size;
3340 case 2: return 2;
3341 case 3: return 4;
3342 case 4: return 8;
3343 }
3344}
3345
3346static dwarf_vma
3347get_encoded_value (unsigned char *data, int encoding)
3348{
3349 int size = size_of_encoded_value (encoding);
53b8873b 3350
19e6b90e
L
3351 if (encoding & DW_EH_PE_signed)
3352 return byte_get_signed (data, size);
3353 else
3354 return byte_get (data, size);
3355}
3356
3357#define GET(N) byte_get (start, N); start += N
3358#define LEB() read_leb128 (start, & length_return, 0); start += length_return
3359#define SLEB() read_leb128 (start, & length_return, 1); start += length_return
3360
3361static int
3362display_debug_frames (struct dwarf_section *section,
3363 void *file ATTRIBUTE_UNUSED)
3364{
3365 unsigned char *start = section->start;
3366 unsigned char *end = start + section->size;
3367 unsigned char *section_start = start;
3368 Frame_Chunk *chunks = 0;
3369 Frame_Chunk *remembered_state = 0;
3370 Frame_Chunk *rs;
3371 int is_eh = strcmp (section->name, ".eh_frame") == 0;
3372 unsigned int length_return;
3373 int max_regs = 0;
3374
3375 printf (_("The section %s contains:\n"), section->name);
3376
3377 while (start < end)
3378 {
3379 unsigned char *saved_start;
3380 unsigned char *block_end;
3381 unsigned long length;
3382 unsigned long cie_id;
3383 Frame_Chunk *fc;
3384 Frame_Chunk *cie;
3385 int need_col_headers = 1;
3386 unsigned char *augmentation_data = NULL;
3387 unsigned long augmentation_data_len = 0;
3388 int encoded_ptr_size = eh_addr_size;
3389 int offset_size;
3390 int initial_length_size;
3391
3392 saved_start = start;
3393 length = byte_get (start, 4); start += 4;
3394
3395 if (length == 0)
3396 {
3397 printf ("\n%08lx ZERO terminator\n\n",
3398 (unsigned long)(saved_start - section_start));
b758e50f 3399 continue;
19e6b90e
L
3400 }
3401
3402 if (length == 0xffffffff)
3403 {
3404 length = byte_get (start, 8);
3405 start += 8;
3406 offset_size = 8;
3407 initial_length_size = 12;
3408 }
3409 else
3410 {
3411 offset_size = 4;
3412 initial_length_size = 4;
3413 }
3414
3415 block_end = saved_start + length + initial_length_size;
53b8873b
NC
3416 if (block_end > end)
3417 {
3418 warn ("Invalid length %#08lx in FDE at %#08lx\n",
3419 length, (unsigned long)(saved_start - section_start));
3420 block_end = end;
3421 }
19e6b90e
L
3422 cie_id = byte_get (start, offset_size); start += offset_size;
3423
3424 if (is_eh ? (cie_id == 0) : (cie_id == DW_CIE_ID))
3425 {
3426 int version;
3427
3428 fc = xmalloc (sizeof (Frame_Chunk));
3429 memset (fc, 0, sizeof (Frame_Chunk));
3430
3431 fc->next = chunks;
3432 chunks = fc;
3433 fc->chunk_start = saved_start;
3434 fc->ncols = 0;
3435 fc->col_type = xmalloc (sizeof (short int));
3436 fc->col_offset = xmalloc (sizeof (int));
cc86f28f 3437 frame_need_space (fc, max_regs - 1);
19e6b90e
L
3438
3439 version = *start++;
3440
3441 fc->augmentation = (char *) start;
3442 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
3443
3444 if (fc->augmentation[0] == 'z')
3445 {
3446 fc->code_factor = LEB ();
3447 fc->data_factor = SLEB ();
3448 if (version == 1)
3449 {
3450 fc->ra = GET (1);
3451 }
3452 else
3453 {
3454 fc->ra = LEB ();
3455 }
3456 augmentation_data_len = LEB ();
3457 augmentation_data = start;
3458 start += augmentation_data_len;
3459 }
3460 else if (strcmp (fc->augmentation, "eh") == 0)
3461 {
3462 start += eh_addr_size;
3463 fc->code_factor = LEB ();
3464 fc->data_factor = SLEB ();
3465 if (version == 1)
3466 {
3467 fc->ra = GET (1);
3468 }
3469 else
3470 {
3471 fc->ra = LEB ();
3472 }
3473 }
3474 else
3475 {
3476 fc->code_factor = LEB ();
3477 fc->data_factor = SLEB ();
3478 if (version == 1)
3479 {
3480 fc->ra = GET (1);
3481 }
3482 else
3483 {
3484 fc->ra = LEB ();
3485 }
3486 }
3487 cie = fc;
3488
3489 if (do_debug_frames_interp)
3490 printf ("\n%08lx %08lx %08lx CIE \"%s\" cf=%d df=%d ra=%d\n",
3491 (unsigned long)(saved_start - section_start), length, cie_id,
3492 fc->augmentation, fc->code_factor, fc->data_factor,
3493 fc->ra);
3494 else
3495 {
3496 printf ("\n%08lx %08lx %08lx CIE\n",
3497 (unsigned long)(saved_start - section_start), length, cie_id);
3498 printf (" Version: %d\n", version);
3499 printf (" Augmentation: \"%s\"\n", fc->augmentation);
3500 printf (" Code alignment factor: %u\n", fc->code_factor);
3501 printf (" Data alignment factor: %d\n", fc->data_factor);
3502 printf (" Return address column: %d\n", fc->ra);
3503
3504 if (augmentation_data_len)
3505 {
3506 unsigned long i;
3507 printf (" Augmentation data: ");
3508 for (i = 0; i < augmentation_data_len; ++i)
3509 printf (" %02x", augmentation_data[i]);
3510 putchar ('\n');
3511 }
3512 putchar ('\n');
3513 }
3514
3515 if (augmentation_data_len)
3516 {
3517 unsigned char *p, *q;
3518 p = (unsigned char *) fc->augmentation + 1;
3519 q = augmentation_data;
3520
3521 while (1)
3522 {
3523 if (*p == 'L')
3524 q++;
3525 else if (*p == 'P')
3526 q += 1 + size_of_encoded_value (*q);
3527 else if (*p == 'R')
3528 fc->fde_encoding = *q++;
3529 else
3530 break;
3531 p++;
3532 }
3533
3534 if (fc->fde_encoding)
3535 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3536 }
3537
3538 frame_need_space (fc, fc->ra);
3539 }
3540 else
3541 {
3542 unsigned char *look_for;
3543 static Frame_Chunk fde_fc;
3544
3545 fc = & fde_fc;
3546 memset (fc, 0, sizeof (Frame_Chunk));
3547
3548 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
3549
3550 for (cie = chunks; cie ; cie = cie->next)
3551 if (cie->chunk_start == look_for)
3552 break;
3553
3554 if (!cie)
3555 {
53b8873b 3556 warn ("Invalid CIE pointer %#08lx in FDE at %#08lx\n",
1617e571 3557 cie_id, (unsigned long)(saved_start - section_start));
19e6b90e
L
3558 fc->ncols = 0;
3559 fc->col_type = xmalloc (sizeof (short int));
3560 fc->col_offset = xmalloc (sizeof (int));
3561 frame_need_space (fc, max_regs - 1);
3562 cie = fc;
3563 fc->augmentation = "";
3564 fc->fde_encoding = 0;
3565 }
3566 else
3567 {
3568 fc->ncols = cie->ncols;
3569 fc->col_type = xcmalloc (fc->ncols, sizeof (short int));
3570 fc->col_offset = xcmalloc (fc->ncols, sizeof (int));
3571 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
3572 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
3573 fc->augmentation = cie->augmentation;
3574 fc->code_factor = cie->code_factor;
3575 fc->data_factor = cie->data_factor;
3576 fc->cfa_reg = cie->cfa_reg;
3577 fc->cfa_offset = cie->cfa_offset;
3578 fc->ra = cie->ra;
cc86f28f 3579 frame_need_space (fc, max_regs - 1);
19e6b90e
L
3580 fc->fde_encoding = cie->fde_encoding;
3581 }
3582
3583 if (fc->fde_encoding)
3584 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
3585
3586 fc->pc_begin = get_encoded_value (start, fc->fde_encoding);
41e92641 3587 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
19e6b90e
L
3588 fc->pc_begin += section->address + (start - section_start);
3589 start += encoded_ptr_size;
3590 fc->pc_range = byte_get (start, encoded_ptr_size);
3591 start += encoded_ptr_size;
3592
3593 if (cie->augmentation[0] == 'z')
3594 {
3595 augmentation_data_len = LEB ();
3596 augmentation_data = start;
3597 start += augmentation_data_len;
3598 }
3599
3600 printf ("\n%08lx %08lx %08lx FDE cie=%08lx pc=%08lx..%08lx\n",
3601 (unsigned long)(saved_start - section_start), length, cie_id,
3602 (unsigned long)(cie->chunk_start - section_start),
3603 fc->pc_begin, fc->pc_begin + fc->pc_range);
3604 if (! do_debug_frames_interp && augmentation_data_len)
3605 {
3606 unsigned long i;
3607
3608 printf (" Augmentation data: ");
3609 for (i = 0; i < augmentation_data_len; ++i)
3610 printf (" %02x", augmentation_data[i]);
3611 putchar ('\n');
3612 putchar ('\n');
3613 }
3614 }
3615
3616 /* At this point, fc is the current chunk, cie (if any) is set, and
3617 we're about to interpret instructions for the chunk. */
3618 /* ??? At present we need to do this always, since this sizes the
3619 fc->col_type and fc->col_offset arrays, which we write into always.
3620 We should probably split the interpreted and non-interpreted bits
3621 into two different routines, since there's so much that doesn't
3622 really overlap between them. */
3623 if (1 || do_debug_frames_interp)
3624 {
3625 /* Start by making a pass over the chunk, allocating storage
3626 and taking note of what registers are used. */
3627 unsigned char *tmp = start;
3628
3629 while (start < block_end)
3630 {
3631 unsigned op, opa;
3632 unsigned long reg, tmp;
3633
3634 op = *start++;
3635 opa = op & 0x3f;
3636 if (op & 0xc0)
3637 op &= 0xc0;
3638
3639 /* Warning: if you add any more cases to this switch, be
3640 sure to add them to the corresponding switch below. */
3641 switch (op)
3642 {
3643 case DW_CFA_advance_loc:
3644 break;
3645 case DW_CFA_offset:
3646 LEB ();
3647 frame_need_space (fc, opa);
3648 fc->col_type[opa] = DW_CFA_undefined;
3649 break;
3650 case DW_CFA_restore:
3651 frame_need_space (fc, opa);
3652 fc->col_type[opa] = DW_CFA_undefined;
3653 break;
3654 case DW_CFA_set_loc:
3655 start += encoded_ptr_size;
3656 break;
3657 case DW_CFA_advance_loc1:
3658 start += 1;
3659 break;
3660 case DW_CFA_advance_loc2:
3661 start += 2;
3662 break;
3663 case DW_CFA_advance_loc4:
3664 start += 4;
3665 break;
3666 case DW_CFA_offset_extended:
12eae2d3 3667 case DW_CFA_val_offset:
19e6b90e
L
3668 reg = LEB (); LEB ();
3669 frame_need_space (fc, reg);
3670 fc->col_type[reg] = DW_CFA_undefined;
3671 break;
3672 case DW_CFA_restore_extended:
3673 reg = LEB ();
3674 frame_need_space (fc, reg);
3675 fc->col_type[reg] = DW_CFA_undefined;
3676 break;
3677 case DW_CFA_undefined:
3678 reg = LEB ();
3679 frame_need_space (fc, reg);
3680 fc->col_type[reg] = DW_CFA_undefined;
3681 break;
3682 case DW_CFA_same_value:
3683 reg = LEB ();
3684 frame_need_space (fc, reg);
3685 fc->col_type[reg] = DW_CFA_undefined;
3686 break;
3687 case DW_CFA_register:
3688 reg = LEB (); LEB ();
3689 frame_need_space (fc, reg);
3690 fc->col_type[reg] = DW_CFA_undefined;
3691 break;
3692 case DW_CFA_def_cfa:
3693 LEB (); LEB ();
3694 break;
3695 case DW_CFA_def_cfa_register:
3696 LEB ();
3697 break;
3698 case DW_CFA_def_cfa_offset:
3699 LEB ();
3700 break;
3701 case DW_CFA_def_cfa_expression:
3702 tmp = LEB ();
3703 start += tmp;
3704 break;
3705 case DW_CFA_expression:
12eae2d3 3706 case DW_CFA_val_expression:
19e6b90e
L
3707 reg = LEB ();
3708 tmp = LEB ();
3709 start += tmp;
3710 frame_need_space (fc, reg);
3711 fc->col_type[reg] = DW_CFA_undefined;
3712 break;
3713 case DW_CFA_offset_extended_sf:
12eae2d3 3714 case DW_CFA_val_offset_sf:
19e6b90e
L
3715 reg = LEB (); SLEB ();
3716 frame_need_space (fc, reg);
3717 fc->col_type[reg] = DW_CFA_undefined;
3718 break;
3719 case DW_CFA_def_cfa_sf:
3720 LEB (); SLEB ();
3721 break;
3722 case DW_CFA_def_cfa_offset_sf:
3723 SLEB ();
3724 break;
3725 case DW_CFA_MIPS_advance_loc8:
3726 start += 8;
3727 break;
3728 case DW_CFA_GNU_args_size:
3729 LEB ();
3730 break;
3731 case DW_CFA_GNU_negative_offset_extended:
3732 reg = LEB (); LEB ();
3733 frame_need_space (fc, reg);
3734 fc->col_type[reg] = DW_CFA_undefined;
3735
3736 default:
3737 break;
3738 }
3739 }
3740 start = tmp;
3741 }
3742
3743 /* Now we know what registers are used, make a second pass over
3744 the chunk, this time actually printing out the info. */
3745
3746 while (start < block_end)
3747 {
3748 unsigned op, opa;
3749 unsigned long ul, reg, roffs;
3750 long l, ofs;
3751 dwarf_vma vma;
3752
3753 op = *start++;
3754 opa = op & 0x3f;
3755 if (op & 0xc0)
3756 op &= 0xc0;
3757
3758 /* Warning: if you add any more cases to this switch, be
3759 sure to add them to the corresponding switch above. */
3760 switch (op)
3761 {
3762 case DW_CFA_advance_loc:
3763 if (do_debug_frames_interp)
3764 frame_display_row (fc, &need_col_headers, &max_regs);
3765 else
3766 printf (" DW_CFA_advance_loc: %d to %08lx\n",
3767 opa * fc->code_factor,
3768 fc->pc_begin + opa * fc->code_factor);
3769 fc->pc_begin += opa * fc->code_factor;
3770 break;
3771
3772 case DW_CFA_offset:
3773 roffs = LEB ();
3774 if (! do_debug_frames_interp)
2dc4cec1
L
3775 printf (" DW_CFA_offset: %s at cfa%+ld\n",
3776 regname (opa, 0), roffs * fc->data_factor);
19e6b90e
L
3777 fc->col_type[opa] = DW_CFA_offset;
3778 fc->col_offset[opa] = roffs * fc->data_factor;
3779 break;
3780
3781 case DW_CFA_restore:
3782 if (! do_debug_frames_interp)
2dc4cec1 3783 printf (" DW_CFA_restore: %s\n", regname (opa, 0));
19e6b90e
L
3784 fc->col_type[opa] = cie->col_type[opa];
3785 fc->col_offset[opa] = cie->col_offset[opa];
3786 break;
3787
3788 case DW_CFA_set_loc:
3789 vma = get_encoded_value (start, fc->fde_encoding);
41e92641 3790 if ((fc->fde_encoding & 0x70) == DW_EH_PE_pcrel)
19e6b90e
L
3791 vma += section->address + (start - section_start);
3792 start += encoded_ptr_size;
3793 if (do_debug_frames_interp)
3794 frame_display_row (fc, &need_col_headers, &max_regs);
3795 else
3796 printf (" DW_CFA_set_loc: %08lx\n", (unsigned long)vma);
3797 fc->pc_begin = vma;
3798 break;
3799
3800 case DW_CFA_advance_loc1:
3801 ofs = byte_get (start, 1); start += 1;
3802 if (do_debug_frames_interp)
3803 frame_display_row (fc, &need_col_headers, &max_regs);
3804 else
3805 printf (" DW_CFA_advance_loc1: %ld to %08lx\n",
3806 ofs * fc->code_factor,
3807 fc->pc_begin + ofs * fc->code_factor);
3808 fc->pc_begin += ofs * fc->code_factor;
3809 break;
3810
3811 case DW_CFA_advance_loc2:
3812 ofs = byte_get (start, 2); start += 2;
3813 if (do_debug_frames_interp)
3814 frame_display_row (fc, &need_col_headers, &max_regs);
3815 else
3816 printf (" DW_CFA_advance_loc2: %ld to %08lx\n",
3817 ofs * fc->code_factor,
3818 fc->pc_begin + ofs * fc->code_factor);
3819 fc->pc_begin += ofs * fc->code_factor;
3820 break;
3821
3822 case DW_CFA_advance_loc4:
3823 ofs = byte_get (start, 4); start += 4;
3824 if (do_debug_frames_interp)
3825 frame_display_row (fc, &need_col_headers, &max_regs);
3826 else
3827 printf (" DW_CFA_advance_loc4: %ld to %08lx\n",
3828 ofs * fc->code_factor,
3829 fc->pc_begin + ofs * fc->code_factor);
3830 fc->pc_begin += ofs * fc->code_factor;
3831 break;
3832
3833 case DW_CFA_offset_extended:
3834 reg = LEB ();
3835 roffs = LEB ();
3836 if (! do_debug_frames_interp)
2dc4cec1
L
3837 printf (" DW_CFA_offset_extended: %s at cfa%+ld\n",
3838 regname (reg, 0), roffs * fc->data_factor);
19e6b90e
L
3839 fc->col_type[reg] = DW_CFA_offset;
3840 fc->col_offset[reg] = roffs * fc->data_factor;
3841 break;
3842
12eae2d3
JJ
3843 case DW_CFA_val_offset:
3844 reg = LEB ();
3845 roffs = LEB ();
3846 if (! do_debug_frames_interp)
2dc4cec1
L
3847 printf (" DW_CFA_val_offset: %s at cfa%+ld\n",
3848 regname (reg, 0), roffs * fc->data_factor);
12eae2d3
JJ
3849 fc->col_type[reg] = DW_CFA_val_offset;
3850 fc->col_offset[reg] = roffs * fc->data_factor;
3851 break;
3852
19e6b90e
L
3853 case DW_CFA_restore_extended:
3854 reg = LEB ();
3855 if (! do_debug_frames_interp)
2dc4cec1
L
3856 printf (" DW_CFA_restore_extended: %s\n",
3857 regname (reg, 0));
19e6b90e
L
3858 fc->col_type[reg] = cie->col_type[reg];
3859 fc->col_offset[reg] = cie->col_offset[reg];
3860 break;
3861
3862 case DW_CFA_undefined:
3863 reg = LEB ();
3864 if (! do_debug_frames_interp)
2dc4cec1 3865 printf (" DW_CFA_undefined: %s\n", regname (reg, 0));
19e6b90e
L
3866 fc->col_type[reg] = DW_CFA_undefined;
3867 fc->col_offset[reg] = 0;
3868 break;
3869
3870 case DW_CFA_same_value:
3871 reg = LEB ();
3872 if (! do_debug_frames_interp)
2dc4cec1 3873 printf (" DW_CFA_same_value: %s\n", regname (reg, 0));
19e6b90e
L
3874 fc->col_type[reg] = DW_CFA_same_value;
3875 fc->col_offset[reg] = 0;
3876 break;
3877
3878 case DW_CFA_register:
3879 reg = LEB ();
3880 roffs = LEB ();
3881 if (! do_debug_frames_interp)
2dc4cec1
L
3882 {
3883 printf (" DW_CFA_register: %s in ",
3884 regname (reg, 0));
3885 puts (regname (roffs, 0));
3886 }
19e6b90e
L
3887 fc->col_type[reg] = DW_CFA_register;
3888 fc->col_offset[reg] = roffs;
3889 break;
3890
3891 case DW_CFA_remember_state:
3892 if (! do_debug_frames_interp)
3893 printf (" DW_CFA_remember_state\n");
3894 rs = xmalloc (sizeof (Frame_Chunk));
3895 rs->ncols = fc->ncols;
3896 rs->col_type = xcmalloc (rs->ncols, sizeof (short int));
3897 rs->col_offset = xcmalloc (rs->ncols, sizeof (int));
3898 memcpy (rs->col_type, fc->col_type, rs->ncols);
3899 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (int));
3900 rs->next = remembered_state;
3901 remembered_state = rs;
3902 break;
3903
3904 case DW_CFA_restore_state:
3905 if (! do_debug_frames_interp)
3906 printf (" DW_CFA_restore_state\n");
3907 rs = remembered_state;
3908 if (rs)
3909 {
3910 remembered_state = rs->next;
cc86f28f 3911 frame_need_space (fc, rs->ncols - 1);
19e6b90e
L
3912 memcpy (fc->col_type, rs->col_type, rs->ncols);
3913 memcpy (fc->col_offset, rs->col_offset,
3914 rs->ncols * sizeof (int));
3915 free (rs->col_type);
3916 free (rs->col_offset);
3917 free (rs);
3918 }
3919 else if (do_debug_frames_interp)
3920 printf ("Mismatched DW_CFA_restore_state\n");
3921 break;
3922
3923 case DW_CFA_def_cfa:
3924 fc->cfa_reg = LEB ();
3925 fc->cfa_offset = LEB ();
3926 fc->cfa_exp = 0;
3927 if (! do_debug_frames_interp)
2dc4cec1
L
3928 printf (" DW_CFA_def_cfa: %s ofs %d\n",
3929 regname (fc->cfa_reg, 0), fc->cfa_offset);
19e6b90e
L
3930 break;
3931
3932 case DW_CFA_def_cfa_register:
3933 fc->cfa_reg = LEB ();
3934 fc->cfa_exp = 0;
3935 if (! do_debug_frames_interp)
2dc4cec1
L
3936 printf (" DW_CFA_def_cfa_register: %s\n",
3937 regname (fc->cfa_reg, 0));
19e6b90e
L
3938 break;
3939
3940 case DW_CFA_def_cfa_offset:
3941 fc->cfa_offset = LEB ();
3942 if (! do_debug_frames_interp)
3943 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
3944 break;
3945
3946 case DW_CFA_nop:
3947 if (! do_debug_frames_interp)
3948 printf (" DW_CFA_nop\n");
3949 break;
3950
3951 case DW_CFA_def_cfa_expression:
3952 ul = LEB ();
3953 if (! do_debug_frames_interp)
3954 {
3955 printf (" DW_CFA_def_cfa_expression (");
3956 decode_location_expression (start, eh_addr_size, ul, 0);
3957 printf (")\n");
3958 }
3959 fc->cfa_exp = 1;
3960 start += ul;
3961 break;
3962
3963 case DW_CFA_expression:
3964 reg = LEB ();
3965 ul = LEB ();
3966 if (! do_debug_frames_interp)
3967 {
2dc4cec1
L
3968 printf (" DW_CFA_expression: %s (",
3969 regname (reg, 0));
3970 decode_location_expression (start, eh_addr_size,
3971 ul, 0);
19e6b90e
L
3972 printf (")\n");
3973 }
3974 fc->col_type[reg] = DW_CFA_expression;
3975 start += ul;
3976 break;
3977
12eae2d3
JJ
3978 case DW_CFA_val_expression:
3979 reg = LEB ();
3980 ul = LEB ();
3981 if (! do_debug_frames_interp)
3982 {
2dc4cec1
L
3983 printf (" DW_CFA_val_expression: %s (",
3984 regname (reg, 0));
12eae2d3
JJ
3985 decode_location_expression (start, eh_addr_size, ul, 0);
3986 printf (")\n");
3987 }
3988 fc->col_type[reg] = DW_CFA_val_expression;
3989 start += ul;
3990 break;
3991
19e6b90e
L
3992 case DW_CFA_offset_extended_sf:
3993 reg = LEB ();
3994 l = SLEB ();
3995 frame_need_space (fc, reg);
3996 if (! do_debug_frames_interp)
2dc4cec1
L
3997 printf (" DW_CFA_offset_extended_sf: %s at cfa%+ld\n",
3998 regname (reg, 0), l * fc->data_factor);
19e6b90e
L
3999 fc->col_type[reg] = DW_CFA_offset;
4000 fc->col_offset[reg] = l * fc->data_factor;
4001 break;
4002
12eae2d3
JJ
4003 case DW_CFA_val_offset_sf:
4004 reg = LEB ();
4005 l = SLEB ();
4006 frame_need_space (fc, reg);
4007 if (! do_debug_frames_interp)
2dc4cec1
L
4008 printf (" DW_CFA_val_offset_sf: %s at cfa%+ld\n",
4009 regname (reg, 0), l * fc->data_factor);
12eae2d3
JJ
4010 fc->col_type[reg] = DW_CFA_val_offset;
4011 fc->col_offset[reg] = l * fc->data_factor;
4012 break;
4013
19e6b90e
L
4014 case DW_CFA_def_cfa_sf:
4015 fc->cfa_reg = LEB ();
4016 fc->cfa_offset = SLEB ();
4017 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
4018 fc->cfa_exp = 0;
4019 if (! do_debug_frames_interp)
2dc4cec1
L
4020 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
4021 regname (fc->cfa_reg, 0), fc->cfa_offset);
19e6b90e
L
4022 break;
4023
4024 case DW_CFA_def_cfa_offset_sf:
4025 fc->cfa_offset = SLEB ();
4026 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
4027 if (! do_debug_frames_interp)
4028 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
4029 break;
4030
4031 case DW_CFA_MIPS_advance_loc8:
4032 ofs = byte_get (start, 8); start += 8;
4033 if (do_debug_frames_interp)
4034 frame_display_row (fc, &need_col_headers, &max_regs);
4035 else
4036 printf (" DW_CFA_MIPS_advance_loc8: %ld to %08lx\n",
4037 ofs * fc->code_factor,
4038 fc->pc_begin + ofs * fc->code_factor);
4039 fc->pc_begin += ofs * fc->code_factor;
4040 break;
4041
4042 case DW_CFA_GNU_window_save:
4043 if (! do_debug_frames_interp)
4044 printf (" DW_CFA_GNU_window_save\n");
4045 break;
4046
4047 case DW_CFA_GNU_args_size:
4048 ul = LEB ();
4049 if (! do_debug_frames_interp)
4050 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
4051 break;
4052
4053 case DW_CFA_GNU_negative_offset_extended:
4054 reg = LEB ();
4055 l = - LEB ();
4056 frame_need_space (fc, reg);
4057 if (! do_debug_frames_interp)
2dc4cec1
L
4058 printf (" DW_CFA_GNU_negative_offset_extended: %s at cfa%+ld\n",
4059 regname (reg, 0), l * fc->data_factor);
19e6b90e
L
4060 fc->col_type[reg] = DW_CFA_offset;
4061 fc->col_offset[reg] = l * fc->data_factor;
4062 break;
4063
4064 default:
53b8873b
NC
4065 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
4066 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
4067 else
cecf136e 4068 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
19e6b90e
L
4069 start = block_end;
4070 }
4071 }
4072
4073 if (do_debug_frames_interp)
4074 frame_display_row (fc, &need_col_headers, &max_regs);
4075
4076 start = block_end;
4077 }
4078
4079 printf ("\n");
4080
4081 return 1;
4082}
4083
4084#undef GET
4085#undef LEB
4086#undef SLEB
4087
4088static int
4089display_debug_not_supported (struct dwarf_section *section,
4090 void *file ATTRIBUTE_UNUSED)
4091{
4092 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
4093 section->name);
4094
4095 return 1;
4096}
4097
4098void *
4099cmalloc (size_t nmemb, size_t size)
4100{
4101 /* Check for overflow. */
4102 if (nmemb >= ~(size_t) 0 / size)
4103 return NULL;
4104 else
4105 return malloc (nmemb * size);
4106}
4107
4108void *
4109xcmalloc (size_t nmemb, size_t size)
4110{
4111 /* Check for overflow. */
4112 if (nmemb >= ~(size_t) 0 / size)
4113 return NULL;
4114 else
4115 return xmalloc (nmemb * size);
4116}
4117
4118void *
4119xcrealloc (void *ptr, size_t nmemb, size_t size)
4120{
4121 /* Check for overflow. */
4122 if (nmemb >= ~(size_t) 0 / size)
4123 return NULL;
4124 else
4125 return xrealloc (ptr, nmemb * size);
4126}
4127
4128void
4129error (const char *message, ...)
4130{
4131 va_list args;
4132
4133 va_start (args, message);
4134 fprintf (stderr, _("%s: Error: "), program_name);
4135 vfprintf (stderr, message, args);
4136 va_end (args);
4137}
4138
4139void
4140warn (const char *message, ...)
4141{
4142 va_list args;
4143
4144 va_start (args, message);
4145 fprintf (stderr, _("%s: Warning: "), program_name);
4146 vfprintf (stderr, message, args);
4147 va_end (args);
4148}
4149
4150void
4151free_debug_memory (void)
4152{
4153 enum dwarf_section_display_enum i;
4154
4155 free_abbrevs ();
4156
4157 for (i = 0; i < max; i++)
4158 free_debug_section (i);
4159
cc86f28f 4160 if (debug_information != NULL)
19e6b90e 4161 {
cc86f28f 4162 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
19e6b90e 4163 {
cc86f28f 4164 for (i = 0; i < num_debug_info_entries; i++)
19e6b90e 4165 {
cc86f28f
NC
4166 if (!debug_information [i].max_loc_offsets)
4167 {
4168 free (debug_information [i].loc_offsets);
4169 free (debug_information [i].have_frame_base);
4170 }
4171 if (!debug_information [i].max_range_lists)
4172 free (debug_information [i].range_lists);
19e6b90e 4173 }
19e6b90e 4174 }
cc86f28f 4175
19e6b90e
L
4176 free (debug_information);
4177 debug_information = NULL;
4178 num_debug_info_entries = 0;
4179 }
19e6b90e
L
4180}
4181
4182struct dwarf_section_display debug_displays[] =
4183{
4184 { { ".debug_abbrev", NULL, 0, 0 },
4185 display_debug_abbrev, 0, 0 },
4186 { { ".debug_aranges", NULL, 0, 0 },
4187 display_debug_aranges, 0, 0 },
4188 { { ".debug_frame", NULL, 0, 0 },
4189 display_debug_frames, 1, 0 },
4190 { { ".debug_info", NULL, 0, 0 },
4191 display_debug_info, 1, 0 },
4192 { { ".debug_line", NULL, 0, 0 },
4193 display_debug_lines, 0, 0 },
4194 { { ".debug_pubnames", NULL, 0, 0 },
4195 display_debug_pubnames, 0, 0 },
4196 { { ".eh_frame", NULL, 0, 0 },
4197 display_debug_frames, 1, 1 },
4198 { { ".debug_macinfo", NULL, 0, 0 },
4199 display_debug_macinfo, 0, 0 },
4200 { { ".debug_str", NULL, 0, 0 },
4201 display_debug_str, 0, 0 },
4202 { { ".debug_loc", NULL, 0, 0 },
4203 display_debug_loc, 0, 0 },
4204 { { ".debug_pubtypes", NULL, 0, 0 },
4205 display_debug_pubnames, 0, 0 },
4206 { { ".debug_ranges", NULL, 0, 0 },
4207 display_debug_ranges, 0, 0 },
4208 { { ".debug_static_func", NULL, 0, 0 },
4209 display_debug_not_supported, 0, 0 },
4210 { { ".debug_static_vars", NULL, 0, 0 },
4211 display_debug_not_supported, 0, 0 },
4212 { { ".debug_types", NULL, 0, 0 },
4213 display_debug_not_supported, 0, 0 },
4214 { { ".debug_weaknames", NULL, 0, 0 },
4215 display_debug_not_supported, 0, 0 }
4216};
This page took 0.29992 seconds and 4 git commands to generate.