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