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