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