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