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