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