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