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