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