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