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