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