Fix memory access violations triggered by running objdump compiled with out-of-bounds...
[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 alloc_num_debug_info_entries = num_units;
2308 }
2309
2310 if (!do_loc)
2311 {
2312 if (dwarf_start_die == 0)
2313 printf (_("Contents of the %s section:\n\n"), section->name);
2314
2315 load_debug_section (str, file);
2316 load_debug_section (str_dwo, file);
2317 load_debug_section (str_index, file);
2318 load_debug_section (str_index_dwo, file);
2319 load_debug_section (debug_addr, file);
2320 }
2321
2322 load_debug_section (abbrev_sec, file);
2323 if (debug_displays [abbrev_sec].section.start == NULL)
2324 {
2325 warn (_("Unable to locate %s section!\n"),
2326 debug_displays [abbrev_sec].section.name);
2327 return 0;
2328 }
2329
2330 for (section_begin = start, unit = 0; start < end; unit++)
2331 {
2332 DWARF2_Internal_CompUnit compunit;
2333 unsigned char *hdrptr;
2334 unsigned char *tags;
2335 int level, last_level, saved_level;
2336 dwarf_vma cu_offset;
2337 unsigned int offset_size;
2338 int initial_length_size;
2339 dwarf_vma signature_high = 0;
2340 dwarf_vma signature_low = 0;
2341 dwarf_vma type_offset = 0;
2342 struct cu_tu_set *this_set;
2343 dwarf_vma abbrev_base;
2344 size_t abbrev_size;
2345
2346 hdrptr = start;
2347
2348 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2349
2350 if (compunit.cu_length == 0xffffffff)
2351 {
2352 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2353 offset_size = 8;
2354 initial_length_size = 12;
2355 }
2356 else
2357 {
2358 offset_size = 4;
2359 initial_length_size = 4;
2360 }
2361
2362 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2363
2364 cu_offset = start - section_begin;
2365
2366 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2367
2368 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2369
2370 if (this_set == NULL)
2371 {
2372 abbrev_base = 0;
2373 abbrev_size = debug_displays [abbrev_sec].section.size;
2374 }
2375 else
2376 {
2377 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2378 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2379 }
2380
2381 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2382 /* PR 17512: file: 001-108546-0.001:0.1. */
2383 if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8)
2384 {
2385 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2386 compunit.cu_pointer_size, offset_size);
2387 compunit.cu_pointer_size = offset_size;
2388 }
2389
2390 if (do_types)
2391 {
2392 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2393 hdrptr += 8;
2394 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2395 }
2396
2397 if ((do_loc || do_debug_loc || do_debug_ranges)
2398 && num_debug_info_entries == 0
2399 && ! do_types)
2400 {
2401 debug_information [unit].cu_offset = cu_offset;
2402 debug_information [unit].pointer_size
2403 = compunit.cu_pointer_size;
2404 debug_information [unit].offset_size = offset_size;
2405 debug_information [unit].dwarf_version = compunit.cu_version;
2406 debug_information [unit].base_address = 0;
2407 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2408 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2409 debug_information [unit].loc_offsets = NULL;
2410 debug_information [unit].have_frame_base = NULL;
2411 debug_information [unit].max_loc_offsets = 0;
2412 debug_information [unit].num_loc_offsets = 0;
2413 debug_information [unit].range_lists = NULL;
2414 debug_information [unit].max_range_lists= 0;
2415 debug_information [unit].num_range_lists = 0;
2416 }
2417
2418 if (!do_loc && dwarf_start_die == 0)
2419 {
2420 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2421 dwarf_vmatoa ("x", cu_offset));
2422 printf (_(" Length: 0x%s (%s)\n"),
2423 dwarf_vmatoa ("x", compunit.cu_length),
2424 offset_size == 8 ? "64-bit" : "32-bit");
2425 printf (_(" Version: %d\n"), compunit.cu_version);
2426 printf (_(" Abbrev Offset: 0x%s\n"),
2427 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2428 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2429 if (do_types)
2430 {
2431 char buf[64];
2432
2433 printf (_(" Signature: 0x%s\n"),
2434 dwarf_vmatoa64 (signature_high, signature_low,
2435 buf, sizeof (buf)));
2436 printf (_(" Type Offset: 0x%s\n"),
2437 dwarf_vmatoa ("x", type_offset));
2438 }
2439 if (this_set != NULL)
2440 {
2441 dwarf_vma *offsets = this_set->section_offsets;
2442 size_t *sizes = this_set->section_sizes;
2443
2444 printf (_(" Section contributions:\n"));
2445 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2446 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2447 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2448 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2449 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2450 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2451 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2452 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2453 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2454 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2455 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2456 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2457 }
2458 }
2459
2460 if (cu_offset + compunit.cu_length + initial_length_size
2461 > section->size)
2462 {
2463 warn (_("Debug info is corrupted, length of CU at %s"
2464 " extends beyond end of section (length = %s)\n"),
2465 dwarf_vmatoa ("x", cu_offset),
2466 dwarf_vmatoa ("x", compunit.cu_length));
2467 num_units = unit;
2468 break;
2469 }
2470 tags = hdrptr;
2471 start += compunit.cu_length + initial_length_size;
2472
2473 if (start > end)
2474 {
2475 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2476 dwarf_vmatoa ("x", cu_offset));
2477 start = end;
2478 }
2479
2480 if (compunit.cu_version != 2
2481 && compunit.cu_version != 3
2482 && compunit.cu_version != 4)
2483 {
2484 warn (_("CU at offset %s contains corrupt or "
2485 "unsupported version number: %d.\n"),
2486 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2487 continue;
2488 }
2489
2490 free_abbrevs ();
2491
2492 /* Process the abbrevs used by this compilation unit. */
2493 if (compunit.cu_abbrev_offset >= abbrev_size)
2494 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2495 (unsigned long) compunit.cu_abbrev_offset,
2496 (unsigned long) abbrev_size);
2497 /* PR 17531: file:4bcd9ce9. */
2498 else if ((abbrev_base + abbrev_size)
2499 > debug_displays [abbrev_sec].section.size)
2500 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2501 (unsigned long) abbrev_base + abbrev_size,
2502 (unsigned long) debug_displays [abbrev_sec].section.size);
2503 else
2504 process_abbrev_section
2505 (((unsigned char *) debug_displays [abbrev_sec].section.start
2506 + abbrev_base + compunit.cu_abbrev_offset),
2507 ((unsigned char *) debug_displays [abbrev_sec].section.start
2508 + abbrev_base + abbrev_size));
2509
2510 level = 0;
2511 last_level = level;
2512 saved_level = -1;
2513 while (tags < start)
2514 {
2515 unsigned int bytes_read;
2516 unsigned long abbrev_number;
2517 unsigned long die_offset;
2518 abbrev_entry *entry;
2519 abbrev_attr *attr;
2520 int do_printing = 1;
2521
2522 die_offset = tags - section_begin;
2523
2524 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2525 tags += bytes_read;
2526
2527 /* A null DIE marks the end of a list of siblings or it may also be
2528 a section padding. */
2529 if (abbrev_number == 0)
2530 {
2531 /* Check if it can be a section padding for the last CU. */
2532 if (level == 0 && start == end)
2533 {
2534 unsigned char *chk;
2535
2536 for (chk = tags; chk < start; chk++)
2537 if (*chk != 0)
2538 break;
2539 if (chk == start)
2540 break;
2541 }
2542
2543 if (!do_loc && die_offset >= dwarf_start_die
2544 && (dwarf_cutoff_level == -1
2545 || level < dwarf_cutoff_level))
2546 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2547 level, die_offset);
2548
2549 --level;
2550 if (level < 0)
2551 {
2552 static unsigned num_bogus_warns = 0;
2553
2554 if (num_bogus_warns < 3)
2555 {
2556 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2557 die_offset, section->name);
2558 num_bogus_warns ++;
2559 if (num_bogus_warns == 3)
2560 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2561 }
2562 }
2563 if (dwarf_start_die != 0 && level < saved_level)
2564 return 1;
2565 continue;
2566 }
2567
2568 if (!do_loc)
2569 {
2570 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2571 do_printing = 0;
2572 else
2573 {
2574 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2575 saved_level = level;
2576 do_printing = (dwarf_cutoff_level == -1
2577 || level < dwarf_cutoff_level);
2578 if (do_printing)
2579 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2580 level, die_offset, abbrev_number);
2581 else if (dwarf_cutoff_level == -1
2582 || last_level < dwarf_cutoff_level)
2583 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2584 last_level = level;
2585 }
2586 }
2587
2588 /* Scan through the abbreviation list until we reach the
2589 correct entry. */
2590 for (entry = first_abbrev;
2591 entry && entry->entry != abbrev_number;
2592 entry = entry->next)
2593 continue;
2594
2595 if (entry == NULL)
2596 {
2597 if (!do_loc && do_printing)
2598 {
2599 printf ("\n");
2600 fflush (stdout);
2601 }
2602 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2603 die_offset, abbrev_number);
2604 return 0;
2605 }
2606
2607 if (!do_loc && do_printing)
2608 printf (" (%s)\n", get_TAG_name (entry->tag));
2609
2610 switch (entry->tag)
2611 {
2612 default:
2613 need_base_address = 0;
2614 break;
2615 case DW_TAG_compile_unit:
2616 need_base_address = 1;
2617 break;
2618 case DW_TAG_entry_point:
2619 case DW_TAG_subprogram:
2620 need_base_address = 0;
2621 /* Assuming that there is no DW_AT_frame_base. */
2622 have_frame_base = 0;
2623 break;
2624 }
2625
2626 for (attr = entry->first_attr;
2627 attr && attr->attribute;
2628 attr = attr->next)
2629 {
2630 debug_info *arg;
2631
2632 if (! do_loc && do_printing)
2633 /* Show the offset from where the tag was extracted. */
2634 printf (" <%lx>", (unsigned long)(tags - section_begin));
2635
2636 if (debug_information && unit < alloc_num_debug_info_entries)
2637 arg = debug_information + unit;
2638 else
2639 arg = NULL;
2640
2641 tags = read_and_display_attr (attr->attribute,
2642 attr->form,
2643 tags,
2644 end,
2645 cu_offset,
2646 compunit.cu_pointer_size,
2647 offset_size,
2648 compunit.cu_version,
2649 arg,
2650 do_loc || ! do_printing,
2651 section,
2652 this_set);
2653 }
2654
2655 if (entry->children)
2656 ++level;
2657 }
2658 }
2659
2660 /* Set num_debug_info_entries here so that it can be used to check if
2661 we need to process .debug_loc and .debug_ranges sections. */
2662 if ((do_loc || do_debug_loc || do_debug_ranges)
2663 && num_debug_info_entries == 0
2664 && ! do_types)
2665 {
2666 if (num_units > alloc_num_debug_info_entries)
2667 num_debug_info_entries = alloc_num_debug_info_entries;
2668 else
2669 num_debug_info_entries = num_units;
2670 }
2671
2672 if (!do_loc)
2673 printf ("\n");
2674
2675 return 1;
2676 }
2677
2678 /* Locate and scan the .debug_info section in the file and record the pointer
2679 sizes and offsets for the compilation units in it. Usually an executable
2680 will have just one pointer size, but this is not guaranteed, and so we try
2681 not to make any assumptions. Returns zero upon failure, or the number of
2682 compilation units upon success. */
2683
2684 static unsigned int
2685 load_debug_info (void * file)
2686 {
2687 /* Reset the last pointer size so that we can issue correct error
2688 messages if we are displaying the contents of more than one section. */
2689 last_pointer_size = 0;
2690 warned_about_missing_comp_units = FALSE;
2691
2692 /* If we have already tried and failed to load the .debug_info
2693 section then do not bother to repeat the task. */
2694 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2695 return 0;
2696
2697 /* If we already have the information there is nothing else to do. */
2698 if (num_debug_info_entries > 0)
2699 return num_debug_info_entries;
2700
2701 /* If this is a DWARF package file, load the CU and TU indexes. */
2702 load_cu_tu_indexes (file);
2703
2704 if (load_debug_section (info, file)
2705 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2706 return num_debug_info_entries;
2707
2708 if (load_debug_section (info_dwo, file)
2709 && process_debug_info (&debug_displays [info_dwo].section, file,
2710 abbrev_dwo, 1, 0))
2711 return num_debug_info_entries;
2712
2713 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2714 return 0;
2715 }
2716
2717 /* Read a DWARF .debug_line section header starting at DATA.
2718 Upon success returns an updated DATA pointer and the LINFO
2719 structure and the END_OF_SEQUENCE pointer will be filled in.
2720 Otherwise returns NULL. */
2721
2722 static unsigned char *
2723 read_debug_line_header (struct dwarf_section * section,
2724 unsigned char * data,
2725 unsigned char * end,
2726 DWARF2_Internal_LineInfo * linfo,
2727 unsigned char ** end_of_sequence)
2728 {
2729 unsigned char *hdrptr;
2730 unsigned int offset_size;
2731 unsigned int initial_length_size;
2732
2733 /* Extract information from the Line Number Program Header.
2734 (section 6.2.4 in the Dwarf3 doc). */
2735 hdrptr = data;
2736
2737 /* Get and check the length of the block. */
2738 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2739
2740 if (linfo->li_length == 0xffffffff)
2741 {
2742 /* This section is 64-bit DWARF 3. */
2743 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2744 offset_size = 8;
2745 initial_length_size = 12;
2746 }
2747 else
2748 {
2749 offset_size = 4;
2750 initial_length_size = 4;
2751 }
2752
2753 if (linfo->li_length + initial_length_size > section->size)
2754 {
2755 /* If the length is just a bias against the initial_length_size then
2756 this means that the field has a relocation against it which has not
2757 been applied. (Ie we are dealing with an object file, not a linked
2758 binary). Do not complain but instead assume that the rest of the
2759 section applies to this particular header. */
2760 if (linfo->li_length == - initial_length_size)
2761 {
2762 linfo->li_length = section->size - initial_length_size;
2763 }
2764 else
2765 {
2766 warn (_("The line info appears to be corrupt - the section is too small\n"));
2767 return NULL;
2768 }
2769 }
2770
2771 /* Get and check the version number. */
2772 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
2773
2774 if (linfo->li_version != 2
2775 && linfo->li_version != 3
2776 && linfo->li_version != 4)
2777 {
2778 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2779 return NULL;
2780 }
2781
2782 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end);
2783 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
2784
2785 if (linfo->li_version >= 4)
2786 {
2787 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
2788
2789 if (linfo->li_max_ops_per_insn == 0)
2790 {
2791 warn (_("Invalid maximum operations per insn.\n"));
2792 return NULL;
2793 }
2794 }
2795 else
2796 linfo->li_max_ops_per_insn = 1;
2797
2798 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
2799 SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
2800 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
2801 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
2802
2803 * end_of_sequence = data + linfo->li_length + initial_length_size;
2804 /* PR 17512: file:002-117414-0.004. */
2805 if (* end_of_sequence > end)
2806 {
2807 warn (_("Line length %s extends beyond end of section\n"),
2808 dwarf_vmatoa ("u", linfo->li_length));
2809 * end_of_sequence = end;
2810 return NULL;
2811 }
2812
2813 return hdrptr;
2814 }
2815
2816 static int
2817 display_debug_lines_raw (struct dwarf_section *section,
2818 unsigned char *data,
2819 unsigned char *end)
2820 {
2821 unsigned char *start = section->start;
2822
2823 printf (_("Raw dump of debug contents of section %s:\n\n"),
2824 section->name);
2825
2826 while (data < end)
2827 {
2828 static DWARF2_Internal_LineInfo saved_linfo;
2829 DWARF2_Internal_LineInfo linfo;
2830 unsigned char *standard_opcodes;
2831 unsigned char *end_of_sequence;
2832 unsigned int last_dir_entry = 0;
2833 int i;
2834
2835 if (const_strneq (section->name, ".debug_line.")
2836 /* Note: the following does not apply to .debug_line.dwo sections.
2837 These are full debug_line sections. */
2838 && strcmp (section->name, ".debug_line.dwo") != 0)
2839 {
2840 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2841 section containing just the Line Number Statements. They are
2842 created by the assembler and intended to be used alongside gcc's
2843 -ffunction-sections command line option. When the linker's
2844 garbage collection decides to discard a .text.<foo> section it
2845 can then also discard the line number information in .debug_line.<foo>.
2846
2847 Since the section is a fragment it does not have the details
2848 needed to fill out a LineInfo structure, so instead we use the
2849 details from the last full debug_line section that we processed. */
2850 end_of_sequence = end;
2851 standard_opcodes = NULL;
2852 linfo = saved_linfo;
2853 /* PR 17531: file: 0522b371. */
2854 if (linfo.li_line_range == 0)
2855 {
2856 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
2857 return 0;
2858 }
2859 reset_state_machine (linfo.li_default_is_stmt);
2860 }
2861 else
2862 {
2863 unsigned char * hdrptr;
2864
2865 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
2866 & end_of_sequence)) == NULL)
2867 return 0;
2868
2869 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
2870 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2871 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2872 printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length);
2873 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2874 if (linfo.li_version >= 4)
2875 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2876 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2877 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2878 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2879 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2880
2881 /* PR 17512: file: 1665-6428-0.004. */
2882 if (linfo.li_line_range == 0)
2883 {
2884 warn (_("Line range of 0 is invalid, using 1 instead\n"));
2885 linfo.li_line_range = 1;
2886 }
2887
2888 reset_state_machine (linfo.li_default_is_stmt);
2889
2890 /* Display the contents of the Opcodes table. */
2891 standard_opcodes = hdrptr;
2892
2893 /* PR 17512: file: 002-417945-0.004. */
2894 if (standard_opcodes + linfo.li_opcode_base >= end)
2895 {
2896 warn (_("Line Base extends beyond end of section\n"));
2897 return 0;
2898 }
2899
2900 printf (_("\n Opcodes:\n"));
2901
2902 for (i = 1; i < linfo.li_opcode_base; i++)
2903 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2904
2905 /* Display the contents of the Directory table. */
2906 data = standard_opcodes + linfo.li_opcode_base - 1;
2907
2908 if (*data == 0)
2909 printf (_("\n The Directory Table is empty.\n"));
2910 else
2911 {
2912 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2913 (long)(data - start));
2914
2915 while (data < end && *data != 0)
2916 {
2917 printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data);
2918
2919 data += strnlen ((char *) data, end - data) + 1;
2920 }
2921
2922 /* PR 17512: file: 002-132094-0.004. */
2923 if (data >= end - 1)
2924 break;
2925 }
2926
2927 /* Skip the NUL at the end of the table. */
2928 data++;
2929
2930 /* Display the contents of the File Name table. */
2931 if (*data == 0)
2932 printf (_("\n The File Name Table is empty.\n"));
2933 else
2934 {
2935 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2936 (long)(data - start));
2937 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2938
2939 while (data < end && *data != 0)
2940 {
2941 unsigned char *name;
2942 unsigned int bytes_read;
2943
2944 printf (" %d\t", ++state_machine_regs.last_file_entry);
2945 name = data;
2946 data += strnlen ((char *) data, end - data) + 1;
2947
2948 printf ("%s\t",
2949 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2950 data += bytes_read;
2951 printf ("%s\t",
2952 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2953 data += bytes_read;
2954 printf ("%s\t",
2955 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2956 data += bytes_read;
2957 printf ("%.*s\n", (int)(end - name), name);
2958
2959 if (data == end)
2960 {
2961 warn (_("Corrupt file name table entry\n"));
2962 break;
2963 }
2964 }
2965 }
2966
2967 /* Skip the NUL at the end of the table. */
2968 data++;
2969 putchar ('\n');
2970 saved_linfo = linfo;
2971 }
2972
2973 /* Now display the statements. */
2974 if (data >= end_of_sequence)
2975 printf (_(" No Line Number Statements.\n"));
2976 else
2977 {
2978 printf (_(" Line Number Statements:\n"));
2979
2980 while (data < end_of_sequence)
2981 {
2982 unsigned char op_code;
2983 dwarf_signed_vma adv;
2984 dwarf_vma uladv;
2985 unsigned int bytes_read;
2986
2987 printf (" [0x%08lx]", (long)(data - start));
2988
2989 op_code = *data++;
2990
2991 if (op_code >= linfo.li_opcode_base)
2992 {
2993 op_code -= linfo.li_opcode_base;
2994 uladv = (op_code / linfo.li_line_range);
2995 if (linfo.li_max_ops_per_insn == 1)
2996 {
2997 uladv *= linfo.li_min_insn_length;
2998 state_machine_regs.address += uladv;
2999 printf (_(" Special opcode %d: "
3000 "advance Address by %s to 0x%s"),
3001 op_code, dwarf_vmatoa ("u", uladv),
3002 dwarf_vmatoa ("x", state_machine_regs.address));
3003 }
3004 else
3005 {
3006 state_machine_regs.address
3007 += ((state_machine_regs.op_index + uladv)
3008 / linfo.li_max_ops_per_insn)
3009 * linfo.li_min_insn_length;
3010 state_machine_regs.op_index
3011 = (state_machine_regs.op_index + uladv)
3012 % linfo.li_max_ops_per_insn;
3013 printf (_(" Special opcode %d: "
3014 "advance Address by %s to 0x%s[%d]"),
3015 op_code, dwarf_vmatoa ("u", uladv),
3016 dwarf_vmatoa ("x", state_machine_regs.address),
3017 state_machine_regs.op_index);
3018 }
3019 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3020 state_machine_regs.line += adv;
3021 printf (_(" and Line by %s to %d\n"),
3022 dwarf_vmatoa ("d", adv), state_machine_regs.line);
3023 }
3024 else switch (op_code)
3025 {
3026 case DW_LNS_extended_op:
3027 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
3028 break;
3029
3030 case DW_LNS_copy:
3031 printf (_(" Copy\n"));
3032 break;
3033
3034 case DW_LNS_advance_pc:
3035 uladv = read_uleb128 (data, & bytes_read, end);
3036 data += bytes_read;
3037 if (linfo.li_max_ops_per_insn == 1)
3038 {
3039 uladv *= linfo.li_min_insn_length;
3040 state_machine_regs.address += uladv;
3041 printf (_(" Advance PC by %s to 0x%s\n"),
3042 dwarf_vmatoa ("u", uladv),
3043 dwarf_vmatoa ("x", state_machine_regs.address));
3044 }
3045 else
3046 {
3047 state_machine_regs.address
3048 += ((state_machine_regs.op_index + uladv)
3049 / linfo.li_max_ops_per_insn)
3050 * linfo.li_min_insn_length;
3051 state_machine_regs.op_index
3052 = (state_machine_regs.op_index + uladv)
3053 % linfo.li_max_ops_per_insn;
3054 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3055 dwarf_vmatoa ("u", uladv),
3056 dwarf_vmatoa ("x", state_machine_regs.address),
3057 state_machine_regs.op_index);
3058 }
3059 break;
3060
3061 case DW_LNS_advance_line:
3062 adv = read_sleb128 (data, & bytes_read, end);
3063 data += bytes_read;
3064 state_machine_regs.line += adv;
3065 printf (_(" Advance Line by %s to %d\n"),
3066 dwarf_vmatoa ("d", adv),
3067 state_machine_regs.line);
3068 break;
3069
3070 case DW_LNS_set_file:
3071 adv = read_uleb128 (data, & bytes_read, end);
3072 data += bytes_read;
3073 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3074 dwarf_vmatoa ("d", adv));
3075 state_machine_regs.file = adv;
3076 break;
3077
3078 case DW_LNS_set_column:
3079 uladv = read_uleb128 (data, & bytes_read, end);
3080 data += bytes_read;
3081 printf (_(" Set column to %s\n"),
3082 dwarf_vmatoa ("u", uladv));
3083 state_machine_regs.column = uladv;
3084 break;
3085
3086 case DW_LNS_negate_stmt:
3087 adv = state_machine_regs.is_stmt;
3088 adv = ! adv;
3089 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
3090 state_machine_regs.is_stmt = adv;
3091 break;
3092
3093 case DW_LNS_set_basic_block:
3094 printf (_(" Set basic block\n"));
3095 state_machine_regs.basic_block = 1;
3096 break;
3097
3098 case DW_LNS_const_add_pc:
3099 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3100 if (linfo.li_max_ops_per_insn)
3101 {
3102 uladv *= linfo.li_min_insn_length;
3103 state_machine_regs.address += uladv;
3104 printf (_(" Advance PC by constant %s to 0x%s\n"),
3105 dwarf_vmatoa ("u", uladv),
3106 dwarf_vmatoa ("x", state_machine_regs.address));
3107 }
3108 else
3109 {
3110 state_machine_regs.address
3111 += ((state_machine_regs.op_index + uladv)
3112 / linfo.li_max_ops_per_insn)
3113 * linfo.li_min_insn_length;
3114 state_machine_regs.op_index
3115 = (state_machine_regs.op_index + uladv)
3116 % linfo.li_max_ops_per_insn;
3117 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3118 dwarf_vmatoa ("u", uladv),
3119 dwarf_vmatoa ("x", state_machine_regs.address),
3120 state_machine_regs.op_index);
3121 }
3122 break;
3123
3124 case DW_LNS_fixed_advance_pc:
3125 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3126 state_machine_regs.address += uladv;
3127 state_machine_regs.op_index = 0;
3128 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3129 dwarf_vmatoa ("u", uladv),
3130 dwarf_vmatoa ("x", state_machine_regs.address));
3131 break;
3132
3133 case DW_LNS_set_prologue_end:
3134 printf (_(" Set prologue_end to true\n"));
3135 break;
3136
3137 case DW_LNS_set_epilogue_begin:
3138 printf (_(" Set epilogue_begin to true\n"));
3139 break;
3140
3141 case DW_LNS_set_isa:
3142 uladv = read_uleb128 (data, & bytes_read, end);
3143 data += bytes_read;
3144 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
3145 break;
3146
3147 default:
3148 printf (_(" Unknown opcode %d with operands: "), op_code);
3149
3150 if (standard_opcodes != NULL)
3151 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3152 {
3153 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3154 &bytes_read, end)),
3155 i == 1 ? "" : ", ");
3156 data += bytes_read;
3157 }
3158 putchar ('\n');
3159 break;
3160 }
3161 }
3162 putchar ('\n');
3163 }
3164 }
3165
3166 return 1;
3167 }
3168
3169 typedef struct
3170 {
3171 unsigned char *name;
3172 unsigned int directory_index;
3173 unsigned int modification_date;
3174 unsigned int length;
3175 } File_Entry;
3176
3177 /* Output a decoded representation of the .debug_line section. */
3178
3179 static int
3180 display_debug_lines_decoded (struct dwarf_section *section,
3181 unsigned char *data,
3182 unsigned char *end)
3183 {
3184 static DWARF2_Internal_LineInfo saved_linfo;
3185
3186 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3187 section->name);
3188
3189 while (data < end)
3190 {
3191 /* This loop amounts to one iteration per compilation unit. */
3192 DWARF2_Internal_LineInfo linfo;
3193 unsigned char *standard_opcodes;
3194 unsigned char *end_of_sequence;
3195 int i;
3196 File_Entry *file_table = NULL;
3197 unsigned int n_files = 0;
3198 unsigned char **directory_table = NULL;
3199 unsigned int n_directories = 0;
3200
3201 if (const_strneq (section->name, ".debug_line.")
3202 /* Note: the following does not apply to .debug_line.dwo sections.
3203 These are full debug_line sections. */
3204 && strcmp (section->name, ".debug_line.dwo") != 0)
3205 {
3206 /* See comment in display_debug_lines_raw(). */
3207 end_of_sequence = end;
3208 standard_opcodes = NULL;
3209 linfo = saved_linfo;
3210 /* PR 17531: file: 0522b371. */
3211 if (linfo.li_line_range == 0)
3212 {
3213 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3214 return 0;
3215 }
3216 reset_state_machine (linfo.li_default_is_stmt);
3217 }
3218 else
3219 {
3220 unsigned char *hdrptr;
3221
3222 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3223 & end_of_sequence)) == NULL)
3224 return 0;
3225
3226 /* PR 17531: file: 0522b371. */
3227 if (linfo.li_line_range == 0)
3228 {
3229 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3230 linfo.li_line_range = 1;
3231 }
3232 reset_state_machine (linfo.li_default_is_stmt);
3233
3234 /* Save a pointer to the contents of the Opcodes table. */
3235 standard_opcodes = hdrptr;
3236
3237 /* Traverse the Directory table just to count entries. */
3238 data = standard_opcodes + linfo.li_opcode_base - 1;
3239 if (*data != 0)
3240 {
3241 unsigned char *ptr_directory_table = data;
3242
3243 while (*data != 0)
3244 {
3245 data += strnlen ((char *) data, end - data) + 1;
3246 n_directories++;
3247 }
3248
3249 /* Go through the directory table again to save the directories. */
3250 directory_table = (unsigned char **)
3251 xmalloc (n_directories * sizeof (unsigned char *));
3252
3253 i = 0;
3254 while (*ptr_directory_table != 0)
3255 {
3256 directory_table[i] = ptr_directory_table;
3257 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3258 ptr_directory_table - end) + 1;
3259 i++;
3260 }
3261 }
3262 /* Skip the NUL at the end of the table. */
3263 data++;
3264
3265 /* Traverse the File Name table just to count the entries. */
3266 if (*data != 0)
3267 {
3268 unsigned char *ptr_file_name_table = data;
3269
3270 while (*data != 0)
3271 {
3272 unsigned int bytes_read;
3273
3274 /* Skip Name, directory index, last modification time and length
3275 of file. */
3276 data += strnlen ((char *) data, end - data) + 1;
3277 read_uleb128 (data, & bytes_read, end);
3278 data += bytes_read;
3279 read_uleb128 (data, & bytes_read, end);
3280 data += bytes_read;
3281 read_uleb128 (data, & bytes_read, end);
3282 data += bytes_read;
3283
3284 n_files++;
3285 }
3286
3287 /* Go through the file table again to save the strings. */
3288 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3289
3290 i = 0;
3291 while (*ptr_file_name_table != 0)
3292 {
3293 unsigned int bytes_read;
3294
3295 file_table[i].name = ptr_file_name_table;
3296 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3297 end - ptr_file_name_table) + 1;
3298
3299 /* We are not interested in directory, time or size. */
3300 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3301 & bytes_read, end);
3302 ptr_file_name_table += bytes_read;
3303 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3304 & bytes_read, end);
3305 ptr_file_name_table += bytes_read;
3306 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3307 ptr_file_name_table += bytes_read;
3308 i++;
3309 }
3310 i = 0;
3311
3312 /* Print the Compilation Unit's name and a header. */
3313 if (directory_table == NULL)
3314 {
3315 printf (_("CU: %s:\n"), file_table[0].name);
3316 printf (_("File name Line number Starting address\n"));
3317 }
3318 else
3319 {
3320 unsigned int ix = file_table[0].directory_index;
3321 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
3322
3323 if (do_wide || strlen (directory) < 76)
3324 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3325 else
3326 printf ("%s:\n", file_table[0].name);
3327
3328 printf (_("File name Line number Starting address\n"));
3329 }
3330 }
3331
3332 /* Skip the NUL at the end of the table. */
3333 data++;
3334
3335 saved_linfo = linfo;
3336 }
3337
3338 /* This loop iterates through the Dwarf Line Number Program. */
3339 while (data < end_of_sequence)
3340 {
3341 unsigned char op_code;
3342 int adv;
3343 unsigned long int uladv;
3344 unsigned int bytes_read;
3345 int is_special_opcode = 0;
3346
3347 op_code = *data++;
3348
3349 if (op_code >= linfo.li_opcode_base)
3350 {
3351 op_code -= linfo.li_opcode_base;
3352 uladv = (op_code / linfo.li_line_range);
3353 if (linfo.li_max_ops_per_insn == 1)
3354 {
3355 uladv *= linfo.li_min_insn_length;
3356 state_machine_regs.address += uladv;
3357 }
3358 else
3359 {
3360 state_machine_regs.address
3361 += ((state_machine_regs.op_index + uladv)
3362 / linfo.li_max_ops_per_insn)
3363 * linfo.li_min_insn_length;
3364 state_machine_regs.op_index
3365 = (state_machine_regs.op_index + uladv)
3366 % linfo.li_max_ops_per_insn;
3367 }
3368
3369 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3370 state_machine_regs.line += adv;
3371 is_special_opcode = 1;
3372 }
3373 else switch (op_code)
3374 {
3375 case DW_LNS_extended_op:
3376 {
3377 unsigned int ext_op_code_len;
3378 unsigned char ext_op_code;
3379 unsigned char *op_code_data = data;
3380
3381 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3382 end_of_sequence);
3383 op_code_data += bytes_read;
3384
3385 if (ext_op_code_len == 0)
3386 {
3387 warn (_("Badly formed extended line op encountered!\n"));
3388 break;
3389 }
3390 ext_op_code_len += bytes_read;
3391 ext_op_code = *op_code_data++;
3392
3393 switch (ext_op_code)
3394 {
3395 case DW_LNE_end_sequence:
3396 reset_state_machine (linfo.li_default_is_stmt);
3397 break;
3398 case DW_LNE_set_address:
3399 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3400 op_code_data,
3401 ext_op_code_len - bytes_read - 1,
3402 end);
3403 state_machine_regs.op_index = 0;
3404 break;
3405 case DW_LNE_define_file:
3406 {
3407 file_table = (File_Entry *) xrealloc
3408 (file_table, (n_files + 1) * sizeof (File_Entry));
3409
3410 ++state_machine_regs.last_file_entry;
3411 /* Source file name. */
3412 file_table[n_files].name = op_code_data;
3413 op_code_data += strlen ((char *) op_code_data) + 1;
3414 /* Directory index. */
3415 file_table[n_files].directory_index =
3416 read_uleb128 (op_code_data, & bytes_read,
3417 end_of_sequence);
3418 op_code_data += bytes_read;
3419 /* Last modification time. */
3420 file_table[n_files].modification_date =
3421 read_uleb128 (op_code_data, & bytes_read,
3422 end_of_sequence);
3423 op_code_data += bytes_read;
3424 /* File length. */
3425 file_table[n_files].length =
3426 read_uleb128 (op_code_data, & bytes_read,
3427 end_of_sequence);
3428
3429 n_files++;
3430 break;
3431 }
3432 case DW_LNE_set_discriminator:
3433 case DW_LNE_HP_set_sequence:
3434 /* Simply ignored. */
3435 break;
3436
3437 default:
3438 printf (_("UNKNOWN (%u): length %d\n"),
3439 ext_op_code, ext_op_code_len - bytes_read);
3440 break;
3441 }
3442 data += ext_op_code_len;
3443 break;
3444 }
3445 case DW_LNS_copy:
3446 break;
3447
3448 case DW_LNS_advance_pc:
3449 uladv = read_uleb128 (data, & bytes_read, end);
3450 data += bytes_read;
3451 if (linfo.li_max_ops_per_insn == 1)
3452 {
3453 uladv *= linfo.li_min_insn_length;
3454 state_machine_regs.address += uladv;
3455 }
3456 else
3457 {
3458 state_machine_regs.address
3459 += ((state_machine_regs.op_index + uladv)
3460 / linfo.li_max_ops_per_insn)
3461 * linfo.li_min_insn_length;
3462 state_machine_regs.op_index
3463 = (state_machine_regs.op_index + uladv)
3464 % linfo.li_max_ops_per_insn;
3465 }
3466 break;
3467
3468 case DW_LNS_advance_line:
3469 adv = read_sleb128 (data, & bytes_read, end);
3470 data += bytes_read;
3471 state_machine_regs.line += adv;
3472 break;
3473
3474 case DW_LNS_set_file:
3475 adv = read_uleb128 (data, & bytes_read, end);
3476 data += bytes_read;
3477 state_machine_regs.file = adv;
3478
3479 if (file_table == NULL)
3480 printf (_("\n [Use file table entry %d]\n"), state_machine_regs.file - 1);
3481 else if (file_table[state_machine_regs.file - 1].directory_index == 0)
3482 /* If directory index is 0, that means current directory. */
3483 printf ("\n./%s:[++]\n",
3484 file_table[state_machine_regs.file - 1].name);
3485 else if (directory_table == NULL)
3486 printf (_("\n [Use directory table entry %d]\n"),
3487 file_table[state_machine_regs.file - 1].directory_index - 1);
3488 else
3489 /* The directory index starts counting at 1. */
3490 printf ("\n%s/%s:\n",
3491 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3492 file_table[state_machine_regs.file - 1].name);
3493 break;
3494
3495 case DW_LNS_set_column:
3496 uladv = read_uleb128 (data, & bytes_read, end);
3497 data += bytes_read;
3498 state_machine_regs.column = uladv;
3499 break;
3500
3501 case DW_LNS_negate_stmt:
3502 adv = state_machine_regs.is_stmt;
3503 adv = ! adv;
3504 state_machine_regs.is_stmt = adv;
3505 break;
3506
3507 case DW_LNS_set_basic_block:
3508 state_machine_regs.basic_block = 1;
3509 break;
3510
3511 case DW_LNS_const_add_pc:
3512 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3513 if (linfo.li_max_ops_per_insn == 1)
3514 {
3515 uladv *= linfo.li_min_insn_length;
3516 state_machine_regs.address += uladv;
3517 }
3518 else
3519 {
3520 state_machine_regs.address
3521 += ((state_machine_regs.op_index + uladv)
3522 / linfo.li_max_ops_per_insn)
3523 * linfo.li_min_insn_length;
3524 state_machine_regs.op_index
3525 = (state_machine_regs.op_index + uladv)
3526 % linfo.li_max_ops_per_insn;
3527 }
3528 break;
3529
3530 case DW_LNS_fixed_advance_pc:
3531 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3532 state_machine_regs.address += uladv;
3533 state_machine_regs.op_index = 0;
3534 break;
3535
3536 case DW_LNS_set_prologue_end:
3537 break;
3538
3539 case DW_LNS_set_epilogue_begin:
3540 break;
3541
3542 case DW_LNS_set_isa:
3543 uladv = read_uleb128 (data, & bytes_read, end);
3544 data += bytes_read;
3545 printf (_(" Set ISA to %lu\n"), uladv);
3546 break;
3547
3548 default:
3549 printf (_(" Unknown opcode %d with operands: "), op_code);
3550
3551 if (standard_opcodes != NULL)
3552 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3553 {
3554 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3555 &bytes_read, end)),
3556 i == 1 ? "" : ", ");
3557 data += bytes_read;
3558 }
3559 putchar ('\n');
3560 break;
3561 }
3562
3563 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3564 to the DWARF address/line matrix. */
3565 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3566 || (op_code == DW_LNS_copy))
3567 {
3568 const unsigned int MAX_FILENAME_LENGTH = 35;
3569 char *fileName;
3570 char *newFileName = NULL;
3571 size_t fileNameLength;
3572
3573 if (file_table)
3574 fileName = (char *) file_table[state_machine_regs.file - 1].name;
3575 else
3576 fileName = "<unknown>";
3577
3578 fileNameLength = strlen (fileName);
3579
3580 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3581 {
3582 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3583 /* Truncate file name */
3584 strncpy (newFileName,
3585 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3586 MAX_FILENAME_LENGTH + 1);
3587 }
3588 else
3589 {
3590 newFileName = (char *) xmalloc (fileNameLength + 1);
3591 strncpy (newFileName, fileName, fileNameLength + 1);
3592 }
3593
3594 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3595 {
3596 if (linfo.li_max_ops_per_insn == 1)
3597 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3598 newFileName, state_machine_regs.line,
3599 state_machine_regs.address);
3600 else
3601 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3602 newFileName, state_machine_regs.line,
3603 state_machine_regs.address,
3604 state_machine_regs.op_index);
3605 }
3606 else
3607 {
3608 if (linfo.li_max_ops_per_insn == 1)
3609 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3610 newFileName, state_machine_regs.line,
3611 state_machine_regs.address);
3612 else
3613 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3614 newFileName, state_machine_regs.line,
3615 state_machine_regs.address,
3616 state_machine_regs.op_index);
3617 }
3618
3619 if (op_code == DW_LNE_end_sequence)
3620 printf ("\n");
3621
3622 free (newFileName);
3623 }
3624 }
3625
3626 if (file_table)
3627 {
3628 free (file_table);
3629 file_table = NULL;
3630 n_files = 0;
3631 }
3632
3633 if (directory_table)
3634 {
3635 free (directory_table);
3636 directory_table = NULL;
3637 n_directories = 0;
3638 }
3639
3640 putchar ('\n');
3641 }
3642
3643 return 1;
3644 }
3645
3646 static int
3647 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3648 {
3649 unsigned char *data = section->start;
3650 unsigned char *end = data + section->size;
3651 int retValRaw = 1;
3652 int retValDecoded = 1;
3653
3654 if (do_debug_lines == 0)
3655 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3656
3657 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3658 retValRaw = display_debug_lines_raw (section, data, end);
3659
3660 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3661 retValDecoded = display_debug_lines_decoded (section, data, end);
3662
3663 if (!retValRaw || !retValDecoded)
3664 return 0;
3665
3666 return 1;
3667 }
3668
3669 static debug_info *
3670 find_debug_info_for_offset (unsigned long offset)
3671 {
3672 unsigned int i;
3673
3674 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3675 return NULL;
3676
3677 for (i = 0; i < num_debug_info_entries; i++)
3678 if (debug_information[i].cu_offset == offset)
3679 return debug_information + i;
3680
3681 return NULL;
3682 }
3683
3684 static const char *
3685 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
3686 {
3687 /* See gdb/gdb-index.h. */
3688 static const char * const kinds[] =
3689 {
3690 N_ ("no info"),
3691 N_ ("type"),
3692 N_ ("variable"),
3693 N_ ("function"),
3694 N_ ("other"),
3695 N_ ("unused5"),
3696 N_ ("unused6"),
3697 N_ ("unused7")
3698 };
3699
3700 return _ (kinds[kind]);
3701 }
3702
3703 static int
3704 display_debug_pubnames_worker (struct dwarf_section *section,
3705 void *file ATTRIBUTE_UNUSED,
3706 int is_gnu)
3707 {
3708 DWARF2_Internal_PubNames names;
3709 unsigned char *start = section->start;
3710 unsigned char *end = start + section->size;
3711
3712 /* It does not matter if this load fails,
3713 we test for that later on. */
3714 load_debug_info (file);
3715
3716 printf (_("Contents of the %s section:\n\n"), section->name);
3717
3718 while (start < end)
3719 {
3720 unsigned char *data;
3721 unsigned long offset;
3722 unsigned int offset_size, initial_length_size;
3723
3724 data = start;
3725
3726 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
3727 if (names.pn_length == 0xffffffff)
3728 {
3729 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
3730 offset_size = 8;
3731 initial_length_size = 12;
3732 }
3733 else
3734 {
3735 offset_size = 4;
3736 initial_length_size = 4;
3737 }
3738
3739 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
3740 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
3741
3742 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3743 && num_debug_info_entries > 0
3744 && find_debug_info_for_offset (names.pn_offset) == NULL)
3745 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3746 (unsigned long) names.pn_offset, section->name);
3747
3748 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
3749
3750 /* PR 17531: file: 7615b6b2. */
3751 if ((dwarf_signed_vma) names.pn_length < 0
3752 /* PR 17531: file: a5dbeaa7. */
3753 || start + names.pn_length + initial_length_size < start)
3754 {
3755 warn (_("Negative length for public name: 0x%lx\n"), (long) names.pn_length);
3756 start = end;
3757 }
3758 else
3759 start += names.pn_length + initial_length_size;
3760
3761 printf (_(" Length: %ld\n"),
3762 (long) names.pn_length);
3763 printf (_(" Version: %d\n"),
3764 names.pn_version);
3765 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3766 (unsigned long) names.pn_offset);
3767 printf (_(" Size of area in .debug_info section: %ld\n"),
3768 (long) names.pn_size);
3769
3770 if (names.pn_version != 2 && names.pn_version != 3)
3771 {
3772 static int warned = 0;
3773
3774 if (! warned)
3775 {
3776 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3777 warned = 1;
3778 }
3779
3780 continue;
3781 }
3782
3783 if (is_gnu)
3784 printf (_("\n Offset Kind Name\n"));
3785 else
3786 printf (_("\n Offset\tName\n"));
3787
3788 do
3789 {
3790 bfd_size_type maxprint;
3791
3792 SAFE_BYTE_GET (offset, data, offset_size, end);
3793
3794 if (offset != 0)
3795 {
3796 data += offset_size;
3797 if (data >= end)
3798 break;
3799 maxprint = (end - data) - 1;
3800
3801 if (is_gnu)
3802 {
3803 unsigned int kind_data;
3804 gdb_index_symbol_kind kind;
3805 const char *kind_name;
3806 int is_static;
3807
3808 SAFE_BYTE_GET (kind_data, data, 1, end);
3809 data++;
3810 maxprint --;
3811 /* GCC computes the kind as the upper byte in the CU index
3812 word, and then right shifts it by the CU index size.
3813 Left shift KIND to where the gdb-index.h accessor macros
3814 can use it. */
3815 kind_data <<= GDB_INDEX_CU_BITSIZE;
3816 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
3817 kind_name = get_gdb_index_symbol_kind_name (kind);
3818 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
3819 printf (" %-6lx %s,%-10s %.*s\n",
3820 offset, is_static ? _("s") : _("g"),
3821 kind_name, (int) maxprint, data);
3822 }
3823 else
3824 printf (" %-6lx\t%.*s\n", offset, (int) maxprint, data);
3825
3826 data += strnlen ((char *) data, maxprint) + 1;
3827 if (data >= end)
3828 break;
3829 }
3830 }
3831 while (offset != 0);
3832 }
3833
3834 printf ("\n");
3835 return 1;
3836 }
3837
3838 static int
3839 display_debug_pubnames (struct dwarf_section *section, void *file)
3840 {
3841 return display_debug_pubnames_worker (section, file, 0);
3842 }
3843
3844 static int
3845 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
3846 {
3847 return display_debug_pubnames_worker (section, file, 1);
3848 }
3849
3850 static int
3851 display_debug_macinfo (struct dwarf_section *section,
3852 void *file ATTRIBUTE_UNUSED)
3853 {
3854 unsigned char *start = section->start;
3855 unsigned char *end = start + section->size;
3856 unsigned char *curr = start;
3857 unsigned int bytes_read;
3858 enum dwarf_macinfo_record_type op;
3859
3860 printf (_("Contents of the %s section:\n\n"), section->name);
3861
3862 while (curr < end)
3863 {
3864 unsigned int lineno;
3865 const unsigned char *string;
3866
3867 op = (enum dwarf_macinfo_record_type) *curr;
3868 curr++;
3869
3870 switch (op)
3871 {
3872 case DW_MACINFO_start_file:
3873 {
3874 unsigned int filenum;
3875
3876 lineno = read_uleb128 (curr, & bytes_read, end);
3877 curr += bytes_read;
3878 filenum = read_uleb128 (curr, & bytes_read, end);
3879 curr += bytes_read;
3880
3881 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3882 lineno, filenum);
3883 }
3884 break;
3885
3886 case DW_MACINFO_end_file:
3887 printf (_(" DW_MACINFO_end_file\n"));
3888 break;
3889
3890 case DW_MACINFO_define:
3891 lineno = read_uleb128 (curr, & bytes_read, end);
3892 curr += bytes_read;
3893 string = curr;
3894 curr += strnlen ((char *) string, end - string) + 1;
3895 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3896 lineno, string);
3897 break;
3898
3899 case DW_MACINFO_undef:
3900 lineno = read_uleb128 (curr, & bytes_read, end);
3901 curr += bytes_read;
3902 string = curr;
3903 curr += strnlen ((char *) string, end - string) + 1;
3904 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3905 lineno, string);
3906 break;
3907
3908 case DW_MACINFO_vendor_ext:
3909 {
3910 unsigned int constant;
3911
3912 constant = read_uleb128 (curr, & bytes_read, end);
3913 curr += bytes_read;
3914 string = curr;
3915 curr += strnlen ((char *) string, end - string) + 1;
3916 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3917 constant, string);
3918 }
3919 break;
3920 }
3921 }
3922
3923 return 1;
3924 }
3925
3926 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3927 filename and dirname corresponding to file name table entry with index
3928 FILEIDX. Return NULL on failure. */
3929
3930 static unsigned char *
3931 get_line_filename_and_dirname (dwarf_vma line_offset,
3932 dwarf_vma fileidx,
3933 unsigned char **dir_name)
3934 {
3935 struct dwarf_section *section = &debug_displays [line].section;
3936 unsigned char *hdrptr, *dirtable, *file_name;
3937 unsigned int offset_size, initial_length_size;
3938 unsigned int version, opcode_base, bytes_read;
3939 dwarf_vma length, diridx;
3940 const unsigned char * end;
3941
3942 *dir_name = NULL;
3943 if (section->start == NULL
3944 || line_offset >= section->size
3945 || fileidx == 0)
3946 return NULL;
3947
3948 hdrptr = section->start + line_offset;
3949 end = section->start + section->size;
3950
3951 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
3952 if (length == 0xffffffff)
3953 {
3954 /* This section is 64-bit DWARF 3. */
3955 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
3956 offset_size = 8;
3957 initial_length_size = 12;
3958 }
3959 else
3960 {
3961 offset_size = 4;
3962 initial_length_size = 4;
3963 }
3964 if (length + initial_length_size > section->size)
3965 return NULL;
3966
3967 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
3968 if (version != 2 && version != 3 && version != 4)
3969 return NULL;
3970 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3971 if (version >= 4)
3972 hdrptr++; /* Skip max_ops_per_insn. */
3973 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3974
3975 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
3976 if (opcode_base == 0)
3977 return NULL;
3978
3979 hdrptr += opcode_base - 1;
3980 dirtable = hdrptr;
3981 /* Skip over dirname table. */
3982 while (*hdrptr != '\0')
3983 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3984 hdrptr++; /* Skip the NUL at the end of the table. */
3985 /* Now skip over preceding filename table entries. */
3986 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3987 {
3988 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3989 read_uleb128 (hdrptr, &bytes_read, end);
3990 hdrptr += bytes_read;
3991 read_uleb128 (hdrptr, &bytes_read, end);
3992 hdrptr += bytes_read;
3993 read_uleb128 (hdrptr, &bytes_read, end);
3994 hdrptr += bytes_read;
3995 }
3996 if (hdrptr == end || *hdrptr == '\0')
3997 return NULL;
3998 file_name = hdrptr;
3999 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
4000 diridx = read_uleb128 (hdrptr, &bytes_read, end);
4001 if (diridx == 0)
4002 return file_name;
4003 for (; *dirtable != '\0' && diridx > 1; diridx--)
4004 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
4005 if (*dirtable == '\0')
4006 return NULL;
4007 *dir_name = dirtable;
4008 return file_name;
4009 }
4010
4011 static int
4012 display_debug_macro (struct dwarf_section *section,
4013 void *file)
4014 {
4015 unsigned char *start = section->start;
4016 unsigned char *end = start + section->size;
4017 unsigned char *curr = start;
4018 unsigned char *extended_op_buf[256];
4019 unsigned int bytes_read;
4020
4021 load_debug_section (str, file);
4022 load_debug_section (line, file);
4023
4024 printf (_("Contents of the %s section:\n\n"), section->name);
4025
4026 while (curr < end)
4027 {
4028 unsigned int lineno, version, flags;
4029 unsigned int offset_size = 4;
4030 const unsigned char *string;
4031 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
4032 unsigned char **extended_ops = NULL;
4033
4034 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
4035 if (version != 4)
4036 {
4037 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
4038 section->name);
4039 return 0;
4040 }
4041
4042 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
4043 if (flags & 1)
4044 offset_size = 8;
4045 printf (_(" Offset: 0x%lx\n"),
4046 (unsigned long) sec_offset);
4047 printf (_(" Version: %d\n"), version);
4048 printf (_(" Offset size: %d\n"), offset_size);
4049 if (flags & 2)
4050 {
4051 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
4052 printf (_(" Offset into .debug_line: 0x%lx\n"),
4053 (unsigned long) line_offset);
4054 }
4055 if (flags & 4)
4056 {
4057 unsigned int i, count, op;
4058 dwarf_vma nargs, n;
4059
4060 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
4061
4062 memset (extended_op_buf, 0, sizeof (extended_op_buf));
4063 extended_ops = extended_op_buf;
4064 if (count)
4065 {
4066 printf (_(" Extension opcode arguments:\n"));
4067 for (i = 0; i < count; i++)
4068 {
4069 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4070 extended_ops[op] = curr;
4071 nargs = read_uleb128 (curr, &bytes_read, end);
4072 curr += bytes_read;
4073 if (nargs == 0)
4074 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
4075 else
4076 {
4077 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
4078 for (n = 0; n < nargs; n++)
4079 {
4080 unsigned int form;
4081
4082 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
4083 printf ("%s%s", get_FORM_name (form),
4084 n == nargs - 1 ? "\n" : ", ");
4085 switch (form)
4086 {
4087 case DW_FORM_data1:
4088 case DW_FORM_data2:
4089 case DW_FORM_data4:
4090 case DW_FORM_data8:
4091 case DW_FORM_sdata:
4092 case DW_FORM_udata:
4093 case DW_FORM_block:
4094 case DW_FORM_block1:
4095 case DW_FORM_block2:
4096 case DW_FORM_block4:
4097 case DW_FORM_flag:
4098 case DW_FORM_string:
4099 case DW_FORM_strp:
4100 case DW_FORM_sec_offset:
4101 break;
4102 default:
4103 error (_("Invalid extension opcode form %s\n"),
4104 get_FORM_name (form));
4105 return 0;
4106 }
4107 }
4108 }
4109 }
4110 }
4111 }
4112 printf ("\n");
4113
4114 while (1)
4115 {
4116 unsigned int op;
4117
4118 if (curr >= end)
4119 {
4120 error (_(".debug_macro section not zero terminated\n"));
4121 return 0;
4122 }
4123
4124 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
4125 if (op == 0)
4126 break;
4127
4128 switch (op)
4129 {
4130 case DW_MACRO_GNU_start_file:
4131 {
4132 unsigned int filenum;
4133 unsigned char *file_name = NULL, *dir_name = NULL;
4134
4135 lineno = read_uleb128 (curr, &bytes_read, end);
4136 curr += bytes_read;
4137 filenum = read_uleb128 (curr, &bytes_read, end);
4138 curr += bytes_read;
4139
4140 if ((flags & 2) == 0)
4141 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
4142 else
4143 file_name
4144 = get_line_filename_and_dirname (line_offset, filenum,
4145 &dir_name);
4146 if (file_name == NULL)
4147 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
4148 lineno, filenum);
4149 else
4150 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4151 lineno, filenum,
4152 dir_name != NULL ? (const char *) dir_name : "",
4153 dir_name != NULL ? "/" : "", file_name);
4154 }
4155 break;
4156
4157 case DW_MACRO_GNU_end_file:
4158 printf (_(" DW_MACRO_GNU_end_file\n"));
4159 break;
4160
4161 case DW_MACRO_GNU_define:
4162 lineno = read_uleb128 (curr, &bytes_read, end);
4163 curr += bytes_read;
4164 string = curr;
4165 curr += strnlen ((char *) string, end - string) + 1;
4166 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
4167 lineno, string);
4168 break;
4169
4170 case DW_MACRO_GNU_undef:
4171 lineno = read_uleb128 (curr, &bytes_read, end);
4172 curr += bytes_read;
4173 string = curr;
4174 curr += strnlen ((char *) string, end - string) + 1;
4175 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
4176 lineno, string);
4177 break;
4178
4179 case DW_MACRO_GNU_define_indirect:
4180 lineno = read_uleb128 (curr, &bytes_read, end);
4181 curr += bytes_read;
4182 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4183 string = fetch_indirect_string (offset);
4184 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
4185 lineno, string);
4186 break;
4187
4188 case DW_MACRO_GNU_undef_indirect:
4189 lineno = read_uleb128 (curr, &bytes_read, end);
4190 curr += bytes_read;
4191 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4192 string = fetch_indirect_string (offset);
4193 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4194 lineno, string);
4195 break;
4196
4197 case DW_MACRO_GNU_transparent_include:
4198 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4199 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4200 (unsigned long) offset);
4201 break;
4202
4203 case DW_MACRO_GNU_define_indirect_alt:
4204 lineno = read_uleb128 (curr, &bytes_read, end);
4205 curr += bytes_read;
4206 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4207 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4208 lineno, (unsigned long) offset);
4209 break;
4210
4211 case DW_MACRO_GNU_undef_indirect_alt:
4212 lineno = read_uleb128 (curr, &bytes_read, end);
4213 curr += bytes_read;
4214 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4215 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4216 lineno, (unsigned long) offset);
4217 break;
4218
4219 case DW_MACRO_GNU_transparent_include_alt:
4220 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4221 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4222 (unsigned long) offset);
4223 break;
4224
4225 default:
4226 if (extended_ops == NULL || extended_ops[op] == NULL)
4227 {
4228 error (_(" Unknown macro opcode %02x seen\n"), op);
4229 return 0;
4230 }
4231 else
4232 {
4233 /* Skip over unhandled opcodes. */
4234 dwarf_vma nargs, n;
4235 unsigned char *desc = extended_ops[op];
4236 nargs = read_uleb128 (desc, &bytes_read, end);
4237 desc += bytes_read;
4238 if (nargs == 0)
4239 {
4240 printf (_(" DW_MACRO_GNU_%02x\n"), op);
4241 break;
4242 }
4243 printf (_(" DW_MACRO_GNU_%02x -"), op);
4244 for (n = 0; n < nargs; n++)
4245 {
4246 int val;
4247
4248 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4249 curr
4250 = read_and_display_attr_value (0, val,
4251 curr, end, 0, 0, offset_size,
4252 version, NULL, 0, NULL,
4253 NULL);
4254 if (n != nargs - 1)
4255 printf (",");
4256 }
4257 printf ("\n");
4258 }
4259 break;
4260 }
4261 }
4262
4263 printf ("\n");
4264 }
4265
4266 return 1;
4267 }
4268
4269 static int
4270 display_debug_abbrev (struct dwarf_section *section,
4271 void *file ATTRIBUTE_UNUSED)
4272 {
4273 abbrev_entry *entry;
4274 unsigned char *start = section->start;
4275 unsigned char *end = start + section->size;
4276
4277 printf (_("Contents of the %s section:\n\n"), section->name);
4278
4279 do
4280 {
4281 unsigned char *last;
4282
4283 free_abbrevs ();
4284
4285 last = start;
4286 start = process_abbrev_section (start, end);
4287
4288 if (first_abbrev == NULL)
4289 continue;
4290
4291 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4292
4293 for (entry = first_abbrev; entry; entry = entry->next)
4294 {
4295 abbrev_attr *attr;
4296
4297 printf (" %ld %s [%s]\n",
4298 entry->entry,
4299 get_TAG_name (entry->tag),
4300 entry->children ? _("has children") : _("no children"));
4301
4302 for (attr = entry->first_attr; attr; attr = attr->next)
4303 printf (" %-18s %s\n",
4304 get_AT_name (attr->attribute),
4305 get_FORM_name (attr->form));
4306 }
4307 }
4308 while (start);
4309
4310 printf ("\n");
4311
4312 return 1;
4313 }
4314
4315 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4316
4317 static void
4318 display_loc_list (struct dwarf_section *section,
4319 unsigned char **start_ptr,
4320 unsigned int debug_info_entry,
4321 unsigned long offset,
4322 unsigned long base_address,
4323 int has_frame_base)
4324 {
4325 unsigned char *start = *start_ptr;
4326 unsigned char *section_end = section->start + section->size;
4327 unsigned long cu_offset;
4328 unsigned int pointer_size;
4329 unsigned int offset_size;
4330 int dwarf_version;
4331
4332 dwarf_vma begin;
4333 dwarf_vma end;
4334 unsigned short length;
4335 int need_frame_base;
4336
4337 if (debug_info_entry >= num_debug_info_entries)
4338 {
4339 warn (_("No debug information available for loc lists of entry: %u\n"),
4340 debug_info_entry);
4341 return;
4342 }
4343
4344 cu_offset = debug_information [debug_info_entry].cu_offset;
4345 pointer_size = debug_information [debug_info_entry].pointer_size;
4346 offset_size = debug_information [debug_info_entry].offset_size;
4347 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4348
4349 if (pointer_size < 2 || pointer_size > 8)
4350 {
4351 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4352 pointer_size, debug_info_entry);
4353 return;
4354 }
4355
4356 while (1)
4357 {
4358 if (start + 2 * pointer_size > section_end)
4359 {
4360 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4361 offset);
4362 break;
4363 }
4364
4365 printf (" %8.8lx ", offset + (start - *start_ptr));
4366
4367 /* Note: we use sign extension here in order to be sure that we can detect
4368 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4369 address will not affect the values that we display since we always show
4370 hex values, and always the bottom 32-bits. */
4371 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4372 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4373
4374 if (begin == 0 && end == 0)
4375 {
4376 printf (_("<End of list>\n"));
4377 break;
4378 }
4379
4380 /* Check base address specifiers. */
4381 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4382 {
4383 base_address = end;
4384 print_dwarf_vma (begin, pointer_size);
4385 print_dwarf_vma (end, pointer_size);
4386 printf (_("(base address)\n"));
4387 continue;
4388 }
4389
4390 if (start + 2 > section_end)
4391 {
4392 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4393 offset);
4394 break;
4395 }
4396
4397 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4398
4399 if (start + length > section_end)
4400 {
4401 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4402 offset);
4403 break;
4404 }
4405
4406 print_dwarf_vma (begin + base_address, pointer_size);
4407 print_dwarf_vma (end + base_address, pointer_size);
4408
4409 putchar ('(');
4410 need_frame_base = decode_location_expression (start,
4411 pointer_size,
4412 offset_size,
4413 dwarf_version,
4414 length,
4415 cu_offset, section);
4416 putchar (')');
4417
4418 if (need_frame_base && !has_frame_base)
4419 printf (_(" [without DW_AT_frame_base]"));
4420
4421 if (begin == end)
4422 fputs (_(" (start == end)"), stdout);
4423 else if (begin > end)
4424 fputs (_(" (start > end)"), stdout);
4425
4426 putchar ('\n');
4427
4428 start += length;
4429 }
4430
4431 *start_ptr = start;
4432 }
4433
4434 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4435 right-adjusted in a field of length LEN, and followed by a space. */
4436
4437 static void
4438 print_addr_index (unsigned int idx, unsigned int len)
4439 {
4440 static char buf[15];
4441 snprintf (buf, sizeof (buf), "[%d]", idx);
4442 printf ("%*s ", len, buf);
4443 }
4444
4445 /* Display a location list from a .dwo section. It uses address indexes rather
4446 than embedded addresses. This code closely follows display_loc_list, but the
4447 two are sufficiently different that combining things is very ugly. */
4448
4449 static void
4450 display_loc_list_dwo (struct dwarf_section *section,
4451 unsigned char **start_ptr,
4452 unsigned int debug_info_entry,
4453 unsigned long offset,
4454 int has_frame_base)
4455 {
4456 unsigned char *start = *start_ptr;
4457 unsigned char *section_end = section->start + section->size;
4458 unsigned long cu_offset;
4459 unsigned int pointer_size;
4460 unsigned int offset_size;
4461 int dwarf_version;
4462 int entry_type;
4463 unsigned short length;
4464 int need_frame_base;
4465 unsigned int idx;
4466 unsigned int bytes_read;
4467
4468 if (debug_info_entry >= num_debug_info_entries)
4469 {
4470 warn (_("No debug information for loc lists of entry: %u\n"),
4471 debug_info_entry);
4472 return;
4473 }
4474
4475 cu_offset = debug_information [debug_info_entry].cu_offset;
4476 pointer_size = debug_information [debug_info_entry].pointer_size;
4477 offset_size = debug_information [debug_info_entry].offset_size;
4478 dwarf_version = debug_information [debug_info_entry].dwarf_version;
4479
4480 if (pointer_size < 2 || pointer_size > 8)
4481 {
4482 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4483 pointer_size, debug_info_entry);
4484 return;
4485 }
4486
4487 while (1)
4488 {
4489 printf (" %8.8lx ", offset + (start - *start_ptr));
4490
4491 if (start >= section_end)
4492 {
4493 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4494 offset);
4495 break;
4496 }
4497
4498 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
4499 switch (entry_type)
4500 {
4501 case 0: /* A terminating entry. */
4502 *start_ptr = start;
4503 printf (_("<End of list>\n"));
4504 return;
4505 case 1: /* A base-address entry. */
4506 idx = read_uleb128 (start, &bytes_read, section_end);
4507 start += bytes_read;
4508 print_addr_index (idx, 8);
4509 printf (" ");
4510 printf (_("(base address selection entry)\n"));
4511 continue;
4512 case 2: /* A start/end entry. */
4513 idx = read_uleb128 (start, &bytes_read, section_end);
4514 start += bytes_read;
4515 print_addr_index (idx, 8);
4516 idx = read_uleb128 (start, &bytes_read, section_end);
4517 start += bytes_read;
4518 print_addr_index (idx, 8);
4519 break;
4520 case 3: /* A start/length entry. */
4521 idx = read_uleb128 (start, &bytes_read, section_end);
4522 start += bytes_read;
4523 print_addr_index (idx, 8);
4524 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4525 printf ("%08x ", idx);
4526 break;
4527 case 4: /* An offset pair entry. */
4528 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4529 printf ("%08x ", idx);
4530 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4531 printf ("%08x ", idx);
4532 break;
4533 default:
4534 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
4535 *start_ptr = start;
4536 return;
4537 }
4538
4539 if (start + 2 > section_end)
4540 {
4541 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4542 offset);
4543 break;
4544 }
4545
4546 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4547 if (start + length > section_end)
4548 {
4549 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4550 offset);
4551 break;
4552 }
4553
4554 putchar ('(');
4555 need_frame_base = decode_location_expression (start,
4556 pointer_size,
4557 offset_size,
4558 dwarf_version,
4559 length,
4560 cu_offset, section);
4561 putchar (')');
4562
4563 if (need_frame_base && !has_frame_base)
4564 printf (_(" [without DW_AT_frame_base]"));
4565
4566 putchar ('\n');
4567
4568 start += length;
4569 }
4570
4571 *start_ptr = start;
4572 }
4573
4574 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4575
4576 static dwarf_vma *loc_offsets;
4577
4578 static int
4579 loc_offsets_compar (const void *ap, const void *bp)
4580 {
4581 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
4582 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
4583
4584 return (a > b) - (b > a);
4585 }
4586
4587 static int
4588 display_debug_loc (struct dwarf_section *section, void *file)
4589 {
4590 unsigned char *start = section->start;
4591 unsigned long bytes;
4592 unsigned char *section_begin = start;
4593 unsigned int num_loc_list = 0;
4594 unsigned long last_offset = 0;
4595 unsigned int first = 0;
4596 unsigned int i;
4597 unsigned int j;
4598 unsigned int k;
4599 int seen_first_offset = 0;
4600 int locs_sorted = 1;
4601 unsigned char *next;
4602 unsigned int *array = NULL;
4603 const char *suffix = strrchr (section->name, '.');
4604 int is_dwo = 0;
4605
4606 if (suffix && strcmp (suffix, ".dwo") == 0)
4607 is_dwo = 1;
4608
4609 bytes = section->size;
4610
4611 if (bytes == 0)
4612 {
4613 printf (_("\nThe %s section is empty.\n"), section->name);
4614 return 0;
4615 }
4616
4617 if (load_debug_info (file) == 0)
4618 {
4619 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4620 section->name);
4621 return 0;
4622 }
4623
4624 /* Check the order of location list in .debug_info section. If
4625 offsets of location lists are in the ascending order, we can
4626 use `debug_information' directly. */
4627 for (i = 0; i < num_debug_info_entries; i++)
4628 {
4629 unsigned int num;
4630
4631 num = debug_information [i].num_loc_offsets;
4632 if (num > num_loc_list)
4633 num_loc_list = num;
4634
4635 /* Check if we can use `debug_information' directly. */
4636 if (locs_sorted && num != 0)
4637 {
4638 if (!seen_first_offset)
4639 {
4640 /* This is the first location list. */
4641 last_offset = debug_information [i].loc_offsets [0];
4642 first = i;
4643 seen_first_offset = 1;
4644 j = 1;
4645 }
4646 else
4647 j = 0;
4648
4649 for (; j < num; j++)
4650 {
4651 if (last_offset >
4652 debug_information [i].loc_offsets [j])
4653 {
4654 locs_sorted = 0;
4655 break;
4656 }
4657 last_offset = debug_information [i].loc_offsets [j];
4658 }
4659 }
4660 }
4661
4662 if (!seen_first_offset)
4663 error (_("No location lists in .debug_info section!\n"));
4664
4665 if (debug_information [first].num_loc_offsets > 0
4666 && debug_information [first].loc_offsets [0] != 0)
4667 warn (_("Location lists in %s section start at 0x%s\n"),
4668 section->name,
4669 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4670
4671 if (!locs_sorted)
4672 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4673 printf (_("Contents of the %s section:\n\n"), section->name);
4674 printf (_(" Offset Begin End Expression\n"));
4675
4676 seen_first_offset = 0;
4677 for (i = first; i < num_debug_info_entries; i++)
4678 {
4679 unsigned long offset;
4680 unsigned long base_address;
4681 int has_frame_base;
4682
4683 if (!locs_sorted)
4684 {
4685 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4686 array[k] = k;
4687 loc_offsets = debug_information [i].loc_offsets;
4688 qsort (array, debug_information [i].num_loc_offsets,
4689 sizeof (*array), loc_offsets_compar);
4690 }
4691
4692 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4693 {
4694 j = locs_sorted ? k : array[k];
4695 if (k
4696 && debug_information [i].loc_offsets [locs_sorted
4697 ? k - 1 : array [k - 1]]
4698 == debug_information [i].loc_offsets [j])
4699 continue;
4700 has_frame_base = debug_information [i].have_frame_base [j];
4701 offset = debug_information [i].loc_offsets [j];
4702 next = section_begin + offset;
4703 base_address = debug_information [i].base_address;
4704
4705 if (!seen_first_offset)
4706 seen_first_offset = 1;
4707 else
4708 {
4709 if (start < next)
4710 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4711 (unsigned long) (start - section_begin),
4712 (unsigned long) (next - section_begin));
4713 else if (start > next)
4714 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4715 (unsigned long) (start - section_begin),
4716 (unsigned long) (next - section_begin));
4717 }
4718 start = next;
4719
4720 if (offset >= bytes)
4721 {
4722 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4723 offset);
4724 continue;
4725 }
4726
4727 if (is_dwo)
4728 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4729 else
4730 display_loc_list (section, &start, i, offset, base_address,
4731 has_frame_base);
4732 }
4733 }
4734
4735 if (start < section->start + section->size)
4736 warn (_("There are %ld unused bytes at the end of section %s\n"),
4737 (long) (section->start + section->size - start), section->name);
4738 putchar ('\n');
4739 free (array);
4740 return 1;
4741 }
4742
4743 static int
4744 display_debug_str (struct dwarf_section *section,
4745 void *file ATTRIBUTE_UNUSED)
4746 {
4747 unsigned char *start = section->start;
4748 unsigned long bytes = section->size;
4749 dwarf_vma addr = section->address;
4750
4751 if (bytes == 0)
4752 {
4753 printf (_("\nThe %s section is empty.\n"), section->name);
4754 return 0;
4755 }
4756
4757 printf (_("Contents of the %s section:\n\n"), section->name);
4758
4759 while (bytes)
4760 {
4761 int j;
4762 int k;
4763 int lbytes;
4764
4765 lbytes = (bytes > 16 ? 16 : bytes);
4766
4767 printf (" 0x%8.8lx ", (unsigned long) addr);
4768
4769 for (j = 0; j < 16; j++)
4770 {
4771 if (j < lbytes)
4772 printf ("%2.2x", start[j]);
4773 else
4774 printf (" ");
4775
4776 if ((j & 3) == 3)
4777 printf (" ");
4778 }
4779
4780 for (j = 0; j < lbytes; j++)
4781 {
4782 k = start[j];
4783 if (k >= ' ' && k < 0x80)
4784 printf ("%c", k);
4785 else
4786 printf (".");
4787 }
4788
4789 putchar ('\n');
4790
4791 start += lbytes;
4792 addr += lbytes;
4793 bytes -= lbytes;
4794 }
4795
4796 putchar ('\n');
4797
4798 return 1;
4799 }
4800
4801 static int
4802 display_debug_info (struct dwarf_section *section, void *file)
4803 {
4804 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4805 }
4806
4807 static int
4808 display_debug_types (struct dwarf_section *section, void *file)
4809 {
4810 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4811 }
4812
4813 static int
4814 display_trace_info (struct dwarf_section *section, void *file)
4815 {
4816 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4817 }
4818
4819 static int
4820 display_debug_aranges (struct dwarf_section *section,
4821 void *file ATTRIBUTE_UNUSED)
4822 {
4823 unsigned char *start = section->start;
4824 unsigned char *end = start + section->size;
4825
4826 printf (_("Contents of the %s section:\n\n"), section->name);
4827
4828 /* It does not matter if this load fails,
4829 we test for that later on. */
4830 load_debug_info (file);
4831
4832 while (start < end)
4833 {
4834 unsigned char *hdrptr;
4835 DWARF2_Internal_ARange arange;
4836 unsigned char *addr_ranges;
4837 dwarf_vma length;
4838 dwarf_vma address;
4839 unsigned char address_size;
4840 int excess;
4841 unsigned int offset_size;
4842 unsigned int initial_length_size;
4843
4844 hdrptr = start;
4845
4846 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
4847 if (arange.ar_length == 0xffffffff)
4848 {
4849 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
4850 offset_size = 8;
4851 initial_length_size = 12;
4852 }
4853 else
4854 {
4855 offset_size = 4;
4856 initial_length_size = 4;
4857 }
4858
4859 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
4860 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
4861
4862 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4863 && num_debug_info_entries > 0
4864 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4865 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4866 (unsigned long) arange.ar_info_offset, section->name);
4867
4868 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
4869 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
4870
4871 if (arange.ar_version != 2 && arange.ar_version != 3)
4872 {
4873 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4874 break;
4875 }
4876
4877 printf (_(" Length: %ld\n"),
4878 (long) arange.ar_length);
4879 printf (_(" Version: %d\n"), arange.ar_version);
4880 printf (_(" Offset into .debug_info: 0x%lx\n"),
4881 (unsigned long) arange.ar_info_offset);
4882 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4883 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4884
4885 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4886
4887 /* PR 17512: file: 001-108546-0.001:0.1. */
4888 if (address_size == 0 || address_size > 8)
4889 {
4890 error (_("Invalid address size in %s section!\n"),
4891 section->name);
4892 break;
4893 }
4894
4895 /* The DWARF spec does not require that the address size be a power
4896 of two, but we do. This will have to change if we ever encounter
4897 an uneven architecture. */
4898 if ((address_size & (address_size - 1)) != 0)
4899 {
4900 warn (_("Pointer size + Segment size is not a power of two.\n"));
4901 break;
4902 }
4903
4904 if (address_size > 4)
4905 printf (_("\n Address Length\n"));
4906 else
4907 printf (_("\n Address Length\n"));
4908
4909 addr_ranges = hdrptr;
4910
4911 /* Must pad to an alignment boundary that is twice the address size. */
4912 excess = (hdrptr - start) % (2 * address_size);
4913 if (excess)
4914 addr_ranges += (2 * address_size) - excess;
4915
4916 start += arange.ar_length + initial_length_size;
4917
4918 while (addr_ranges + 2 * address_size <= start)
4919 {
4920 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
4921 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
4922
4923 printf (" ");
4924 print_dwarf_vma (address, address_size);
4925 print_dwarf_vma (length, address_size);
4926 putchar ('\n');
4927 }
4928 }
4929
4930 printf ("\n");
4931
4932 return 1;
4933 }
4934
4935 /* Comparison function for qsort. */
4936 static int
4937 comp_addr_base (const void * v0, const void * v1)
4938 {
4939 debug_info * info0 = (debug_info *) v0;
4940 debug_info * info1 = (debug_info *) v1;
4941 return info0->addr_base - info1->addr_base;
4942 }
4943
4944 /* Display the debug_addr section. */
4945 static int
4946 display_debug_addr (struct dwarf_section *section,
4947 void *file)
4948 {
4949 debug_info **debug_addr_info;
4950 unsigned char *entry;
4951 unsigned char *end;
4952 unsigned int i;
4953 unsigned int count;
4954
4955 if (section->size == 0)
4956 {
4957 printf (_("\nThe %s section is empty.\n"), section->name);
4958 return 0;
4959 }
4960
4961 if (load_debug_info (file) == 0)
4962 {
4963 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4964 section->name);
4965 return 0;
4966 }
4967
4968 printf (_("Contents of the %s section:\n\n"), section->name);
4969
4970 /* PR 17531: file: cf38d01b.
4971 We use xcalloc because a corrupt file may not have initialised all of the
4972 fields in the debug_info structure, which means that the sort below might
4973 try to move uninitialised data. */
4974 debug_addr_info = (debug_info **) xcalloc ((num_debug_info_entries + 1),
4975 sizeof (debug_info *));
4976
4977 count = 0;
4978 for (i = 0; i < num_debug_info_entries; i++)
4979 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4980 {
4981 /* PR 17531: file: cf38d01b. */
4982 if (debug_information[i].addr_base >= section->size)
4983 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
4984 (unsigned long) debug_information[i].addr_base, i);
4985 else
4986 debug_addr_info [count++] = debug_information + i;
4987 }
4988
4989 /* Add a sentinel to make iteration convenient. */
4990 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4991 debug_addr_info [count]->addr_base = section->size;
4992 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4993
4994 for (i = 0; i < count; i++)
4995 {
4996 unsigned int idx;
4997 unsigned int address_size = debug_addr_info [i]->pointer_size;
4998
4999 printf (_(" For compilation unit at offset 0x%s:\n"),
5000 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
5001
5002 printf (_("\tIndex\tAddress\n"));
5003 entry = section->start + debug_addr_info [i]->addr_base;
5004 end = section->start + debug_addr_info [i + 1]->addr_base;
5005 idx = 0;
5006 while (entry < end)
5007 {
5008 dwarf_vma base = byte_get (entry, address_size);
5009 printf (_("\t%d:\t"), idx);
5010 print_dwarf_vma (base, address_size);
5011 printf ("\n");
5012 entry += address_size;
5013 idx++;
5014 }
5015 }
5016 printf ("\n");
5017
5018 free (debug_addr_info);
5019 return 1;
5020 }
5021
5022 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5023 static int
5024 display_debug_str_offsets (struct dwarf_section *section,
5025 void *file ATTRIBUTE_UNUSED)
5026 {
5027 if (section->size == 0)
5028 {
5029 printf (_("\nThe %s section is empty.\n"), section->name);
5030 return 0;
5031 }
5032 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5033 what the offset size is for this section. */
5034 return 1;
5035 }
5036
5037 /* Each debug_information[x].range_lists[y] gets this representation for
5038 sorting purposes. */
5039
5040 struct range_entry
5041 {
5042 /* The debug_information[x].range_lists[y] value. */
5043 unsigned long ranges_offset;
5044
5045 /* Original debug_information to find parameters of the data. */
5046 debug_info *debug_info_p;
5047 };
5048
5049 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5050
5051 static int
5052 range_entry_compar (const void *ap, const void *bp)
5053 {
5054 const struct range_entry *a_re = (const struct range_entry *) ap;
5055 const struct range_entry *b_re = (const struct range_entry *) bp;
5056 const unsigned long a = a_re->ranges_offset;
5057 const unsigned long b = b_re->ranges_offset;
5058
5059 return (a > b) - (b > a);
5060 }
5061
5062 static int
5063 display_debug_ranges (struct dwarf_section *section,
5064 void *file ATTRIBUTE_UNUSED)
5065 {
5066 unsigned char *start = section->start;
5067 unsigned char *last_start = start;
5068 unsigned long bytes = section->size;
5069 unsigned char *section_begin = start;
5070 unsigned char *finish = start + bytes;
5071 unsigned int num_range_list, i;
5072 struct range_entry *range_entries, *range_entry_fill;
5073
5074 if (bytes == 0)
5075 {
5076 printf (_("\nThe %s section is empty.\n"), section->name);
5077 return 0;
5078 }
5079
5080 if (load_debug_info (file) == 0)
5081 {
5082 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5083 section->name);
5084 return 0;
5085 }
5086
5087 num_range_list = 0;
5088 for (i = 0; i < num_debug_info_entries; i++)
5089 num_range_list += debug_information [i].num_range_lists;
5090
5091 if (num_range_list == 0)
5092 {
5093 /* This can happen when the file was compiled with -gsplit-debug
5094 which removes references to range lists from the primary .o file. */
5095 printf (_("No range lists in .debug_info section.\n"));
5096 return 1;
5097 }
5098
5099 range_entries = (struct range_entry *)
5100 xmalloc (sizeof (*range_entries) * num_range_list);
5101 range_entry_fill = range_entries;
5102
5103 for (i = 0; i < num_debug_info_entries; i++)
5104 {
5105 debug_info *debug_info_p = &debug_information[i];
5106 unsigned int j;
5107
5108 for (j = 0; j < debug_info_p->num_range_lists; j++)
5109 {
5110 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
5111 range_entry_fill->debug_info_p = debug_info_p;
5112 range_entry_fill++;
5113 }
5114 }
5115
5116 qsort (range_entries, num_range_list, sizeof (*range_entries),
5117 range_entry_compar);
5118
5119 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
5120 warn (_("Range lists in %s section start at 0x%lx\n"),
5121 section->name, range_entries[0].ranges_offset);
5122
5123 printf (_("Contents of the %s section:\n\n"), section->name);
5124 printf (_(" Offset Begin End\n"));
5125
5126 for (i = 0; i < num_range_list; i++)
5127 {
5128 struct range_entry *range_entry = &range_entries[i];
5129 debug_info *debug_info_p = range_entry->debug_info_p;
5130 unsigned int pointer_size;
5131 unsigned long offset;
5132 unsigned char *next;
5133 unsigned long base_address;
5134
5135 pointer_size = debug_info_p->pointer_size;
5136 offset = range_entry->ranges_offset;
5137 next = section_begin + offset;
5138 base_address = debug_info_p->base_address;
5139
5140 /* PR 17512: file: 001-101485-0.001:0.1. */
5141 if (pointer_size < 2 || pointer_size > 8)
5142 {
5143 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
5144 pointer_size, offset);
5145 continue;
5146 }
5147
5148 if (dwarf_check != 0 && i > 0)
5149 {
5150 if (start < next)
5151 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
5152 (unsigned long) (start - section_begin),
5153 (unsigned long) (next - section_begin), section->name);
5154 else if (start > next)
5155 {
5156 if (next == last_start)
5157 continue;
5158 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
5159 (unsigned long) (start - section_begin),
5160 (unsigned long) (next - section_begin), section->name);
5161 }
5162 }
5163 start = next;
5164 last_start = next;
5165
5166 while (start < finish)
5167 {
5168 dwarf_vma begin;
5169 dwarf_vma end;
5170
5171 /* Note: we use sign extension here in order to be sure that
5172 we can detect the -1 escape value. Sign extension into the
5173 top 32 bits of a 32-bit address will not affect the values
5174 that we display since we always show hex values, and always
5175 the bottom 32-bits. */
5176 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
5177 if (start >= finish)
5178 break;
5179 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
5180
5181 printf (" %8.8lx ", offset);
5182
5183 if (begin == 0 && end == 0)
5184 {
5185 printf (_("<End of list>\n"));
5186 break;
5187 }
5188
5189 /* Check base address specifiers. */
5190 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
5191 {
5192 base_address = end;
5193 print_dwarf_vma (begin, pointer_size);
5194 print_dwarf_vma (end, pointer_size);
5195 printf ("(base address)\n");
5196 continue;
5197 }
5198
5199 print_dwarf_vma (begin + base_address, pointer_size);
5200 print_dwarf_vma (end + base_address, pointer_size);
5201
5202 if (begin == end)
5203 fputs (_("(start == end)"), stdout);
5204 else if (begin > end)
5205 fputs (_("(start > end)"), stdout);
5206
5207 putchar ('\n');
5208 }
5209 }
5210 putchar ('\n');
5211
5212 free (range_entries);
5213
5214 return 1;
5215 }
5216
5217 typedef struct Frame_Chunk
5218 {
5219 struct Frame_Chunk *next;
5220 unsigned char *chunk_start;
5221 unsigned int ncols;
5222 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
5223 short int *col_type;
5224 int *col_offset;
5225 char *augmentation;
5226 unsigned int code_factor;
5227 int data_factor;
5228 dwarf_vma pc_begin;
5229 dwarf_vma pc_range;
5230 int cfa_reg;
5231 int cfa_offset;
5232 unsigned int ra;
5233 unsigned char fde_encoding;
5234 unsigned char cfa_exp;
5235 unsigned char ptr_size;
5236 unsigned char segment_size;
5237 }
5238 Frame_Chunk;
5239
5240 static const char *const *dwarf_regnames;
5241 static unsigned int dwarf_regnames_count;
5242
5243 /* A marker for a col_type that means this column was never referenced
5244 in the frame info. */
5245 #define DW_CFA_unreferenced (-1)
5246
5247 /* Return 0 if no more space is needed, 1 if more space is needed,
5248 -1 for invalid reg. */
5249
5250 static int
5251 frame_need_space (Frame_Chunk *fc, unsigned int reg)
5252 {
5253 unsigned int prev = fc->ncols;
5254
5255 if (reg < (unsigned int) fc->ncols)
5256 return 0;
5257
5258 if (dwarf_regnames_count
5259 && reg > dwarf_regnames_count)
5260 return -1;
5261
5262 fc->ncols = reg + 1;
5263 /* PR 17512: file: 10450-2643-0.004.
5264 If reg == -1 then this can happen... */
5265 if (fc->ncols == 0)
5266 return -1;
5267
5268 /* PR 17512: file: 2844a11d. */
5269 if (fc->ncols > 1024)
5270 {
5271 error (_("Unfeasibly large register number: %u\n"), reg);
5272 fc->ncols = 0;
5273 /* FIXME: 1024 is an arbitrary limit. Increase it if
5274 we ever encounter a valid binary that exceeds it. */
5275 return -1;
5276 }
5277
5278 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
5279 sizeof (short int));
5280 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
5281 /* PR 17512: file:002-10025-0.005. */
5282 if (fc->col_type == NULL || fc->col_offset == NULL)
5283 {
5284 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
5285 fc->ncols);
5286 fc->ncols = 0;
5287 return -1;
5288 }
5289
5290 while (prev < fc->ncols)
5291 {
5292 fc->col_type[prev] = DW_CFA_unreferenced;
5293 fc->col_offset[prev] = 0;
5294 prev++;
5295 }
5296 return 1;
5297 }
5298
5299 static const char *const dwarf_regnames_i386[] =
5300 {
5301 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5302 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5303 "eip", "eflags", NULL, /* 8 - 10 */
5304 "st0", "st1", "st2", "st3", /* 11 - 14 */
5305 "st4", "st5", "st6", "st7", /* 15 - 18 */
5306 NULL, NULL, /* 19 - 20 */
5307 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5308 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5309 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5310 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5311 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5312 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
5313 "tr", "ldtr", /* 48 - 49 */
5314 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
5315 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
5316 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
5317 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
5318 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
5319 NULL, NULL, NULL, /* 90 - 92 */
5320 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5321 };
5322
5323 void
5324 init_dwarf_regnames_i386 (void)
5325 {
5326 dwarf_regnames = dwarf_regnames_i386;
5327 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
5328 }
5329
5330 static const char *const dwarf_regnames_x86_64[] =
5331 {
5332 "rax", "rdx", "rcx", "rbx",
5333 "rsi", "rdi", "rbp", "rsp",
5334 "r8", "r9", "r10", "r11",
5335 "r12", "r13", "r14", "r15",
5336 "rip",
5337 "xmm0", "xmm1", "xmm2", "xmm3",
5338 "xmm4", "xmm5", "xmm6", "xmm7",
5339 "xmm8", "xmm9", "xmm10", "xmm11",
5340 "xmm12", "xmm13", "xmm14", "xmm15",
5341 "st0", "st1", "st2", "st3",
5342 "st4", "st5", "st6", "st7",
5343 "mm0", "mm1", "mm2", "mm3",
5344 "mm4", "mm5", "mm6", "mm7",
5345 "rflags",
5346 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
5347 "fs.base", "gs.base", NULL, NULL,
5348 "tr", "ldtr",
5349 "mxcsr", "fcw", "fsw",
5350 "xmm16", "xmm17", "xmm18", "xmm19",
5351 "xmm20", "xmm21", "xmm22", "xmm23",
5352 "xmm24", "xmm25", "xmm26", "xmm27",
5353 "xmm28", "xmm29", "xmm30", "xmm31",
5354 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
5355 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
5356 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
5357 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
5358 NULL, NULL, NULL, /* 115 - 117 */
5359 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5360 };
5361
5362 void
5363 init_dwarf_regnames_x86_64 (void)
5364 {
5365 dwarf_regnames = dwarf_regnames_x86_64;
5366 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
5367 }
5368
5369 static const char *const dwarf_regnames_aarch64[] =
5370 {
5371 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
5372 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
5373 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
5374 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
5375 NULL, "elr", NULL, NULL, NULL, NULL, NULL, NULL,
5376 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5377 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5378 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
5379 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
5380 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
5381 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
5382 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
5383 };
5384
5385 void
5386 init_dwarf_regnames_aarch64 (void)
5387 {
5388 dwarf_regnames = dwarf_regnames_aarch64;
5389 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_aarch64);
5390 }
5391
5392 void
5393 init_dwarf_regnames (unsigned int e_machine)
5394 {
5395 switch (e_machine)
5396 {
5397 case EM_386:
5398 case EM_486:
5399 init_dwarf_regnames_i386 ();
5400 break;
5401
5402 case EM_X86_64:
5403 case EM_L1OM:
5404 case EM_K1OM:
5405 init_dwarf_regnames_x86_64 ();
5406 break;
5407
5408 case EM_AARCH64:
5409 init_dwarf_regnames_aarch64 ();
5410 break;
5411
5412 default:
5413 break;
5414 }
5415 }
5416
5417 static const char *
5418 regname (unsigned int regno, int row)
5419 {
5420 static char reg[64];
5421 if (dwarf_regnames
5422 && regno < dwarf_regnames_count
5423 && dwarf_regnames [regno] != NULL)
5424 {
5425 if (row)
5426 return dwarf_regnames [regno];
5427 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
5428 dwarf_regnames [regno]);
5429 }
5430 else
5431 snprintf (reg, sizeof (reg), "r%d", regno);
5432 return reg;
5433 }
5434
5435 static void
5436 frame_display_row (Frame_Chunk *fc, int *need_col_headers, unsigned int *max_regs)
5437 {
5438 unsigned int r;
5439 char tmp[100];
5440
5441 if (*max_regs < fc->ncols)
5442 *max_regs = fc->ncols;
5443
5444 if (*need_col_headers)
5445 {
5446 static const char *sloc = " LOC";
5447
5448 *need_col_headers = 0;
5449
5450 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
5451
5452 for (r = 0; r < *max_regs; r++)
5453 if (fc->col_type[r] != DW_CFA_unreferenced)
5454 {
5455 if (r == fc->ra)
5456 printf ("ra ");
5457 else
5458 printf ("%-5s ", regname (r, 1));
5459 }
5460
5461 printf ("\n");
5462 }
5463
5464 print_dwarf_vma (fc->pc_begin, eh_addr_size);
5465 if (fc->cfa_exp)
5466 strcpy (tmp, "exp");
5467 else
5468 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
5469 printf ("%-8s ", tmp);
5470
5471 for (r = 0; r < fc->ncols; r++)
5472 {
5473 if (fc->col_type[r] != DW_CFA_unreferenced)
5474 {
5475 switch (fc->col_type[r])
5476 {
5477 case DW_CFA_undefined:
5478 strcpy (tmp, "u");
5479 break;
5480 case DW_CFA_same_value:
5481 strcpy (tmp, "s");
5482 break;
5483 case DW_CFA_offset:
5484 sprintf (tmp, "c%+d", fc->col_offset[r]);
5485 break;
5486 case DW_CFA_val_offset:
5487 sprintf (tmp, "v%+d", fc->col_offset[r]);
5488 break;
5489 case DW_CFA_register:
5490 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
5491 break;
5492 case DW_CFA_expression:
5493 strcpy (tmp, "exp");
5494 break;
5495 case DW_CFA_val_expression:
5496 strcpy (tmp, "vexp");
5497 break;
5498 default:
5499 strcpy (tmp, "n/a");
5500 break;
5501 }
5502 printf ("%-5s ", tmp);
5503 }
5504 }
5505 printf ("\n");
5506 }
5507
5508 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
5509 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5510 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5511
5512 static unsigned char *
5513 read_cie (unsigned char *start, unsigned char *end,
5514 Frame_Chunk **p_cie, int *p_version,
5515 unsigned long *p_aug_len, unsigned char **p_aug)
5516 {
5517 int version;
5518 Frame_Chunk *fc;
5519 unsigned int length_return;
5520 unsigned char *augmentation_data = NULL;
5521 unsigned long augmentation_data_len = 0;
5522
5523 * p_cie = NULL;
5524 /* PR 17512: file: 001-228113-0.004. */
5525 if (start >= end)
5526 return end;
5527
5528 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5529 memset (fc, 0, sizeof (Frame_Chunk));
5530
5531 fc->col_type = (short int *) xmalloc (sizeof (short int));
5532 fc->col_offset = (int *) xmalloc (sizeof (int));
5533
5534 version = *start++;
5535
5536 fc->augmentation = (char *) start;
5537 /* PR 17512: file: 001-228113-0.004.
5538 Skip past augmentation name, but avoid running off the end of the data. */
5539 while (start < end)
5540 if (* start ++ == '\0')
5541 break;
5542 if (start == end)
5543 {
5544 warn (_("No terminator for augmentation name\n"));
5545 return start;
5546 }
5547
5548 if (strcmp (fc->augmentation, "eh") == 0)
5549 start += eh_addr_size;
5550
5551 if (version >= 4)
5552 {
5553 GET (fc->ptr_size, 1);
5554 if (fc->ptr_size < 1 || fc->ptr_size > 8)
5555 {
5556 warn (_("Invalid pointer size (%d) in CIE data\n"), fc->ptr_size);
5557 return end;
5558 }
5559
5560 GET (fc->segment_size, 1);
5561 /* PR 17512: file: e99d2804. */
5562 if (fc->segment_size > 8 || fc->segment_size + fc->ptr_size > 8)
5563 {
5564 warn (_("Invalid segment size (%d) in CIE data\n"), fc->segment_size);
5565 return end;
5566 }
5567
5568 eh_addr_size = fc->ptr_size;
5569 }
5570 else
5571 {
5572 fc->ptr_size = eh_addr_size;
5573 fc->segment_size = 0;
5574 }
5575 fc->code_factor = LEB ();
5576 fc->data_factor = SLEB ();
5577 if (version == 1)
5578 {
5579 GET (fc->ra, 1);
5580 }
5581 else
5582 {
5583 fc->ra = LEB ();
5584 }
5585
5586 if (fc->augmentation[0] == 'z')
5587 {
5588 augmentation_data_len = LEB ();
5589 augmentation_data = start;
5590 start += augmentation_data_len;
5591 /* PR 17512: file: 11042-2589-0.004. */
5592 if (start > end)
5593 {
5594 warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len);
5595 return end;
5596 }
5597 }
5598
5599 if (augmentation_data_len)
5600 {
5601 unsigned char *p;
5602 unsigned char *q;
5603 unsigned char *qend;
5604
5605 p = (unsigned char *) fc->augmentation + 1;
5606 q = augmentation_data;
5607 qend = q + augmentation_data_len;
5608
5609 /* PR 17531: file: 015adfaa. */
5610 if (qend < q)
5611 {
5612 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len);
5613 augmentation_data_len = 0;
5614 }
5615
5616 while (p < end && q < augmentation_data + augmentation_data_len)
5617 {
5618 if (*p == 'L')
5619 q++;
5620 else if (*p == 'P')
5621 q += 1 + size_of_encoded_value (*q);
5622 else if (*p == 'R')
5623 fc->fde_encoding = *q++;
5624 else if (*p == 'S')
5625 ;
5626 else
5627 break;
5628 p++;
5629 }
5630 /* Note - it is OK if this loop terminates with q < qend.
5631 Padding may have been inserted to align the end of the CIE. */
5632 }
5633
5634 *p_cie = fc;
5635 if (p_version)
5636 *p_version = version;
5637 if (p_aug_len)
5638 {
5639 *p_aug_len = augmentation_data_len;
5640 *p_aug = augmentation_data;
5641 }
5642 return start;
5643 }
5644
5645 static int
5646 display_debug_frames (struct dwarf_section *section,
5647 void *file ATTRIBUTE_UNUSED)
5648 {
5649 unsigned char *start = section->start;
5650 unsigned char *end = start + section->size;
5651 unsigned char *section_start = start;
5652 Frame_Chunk *chunks = 0, *forward_refs = 0;
5653 Frame_Chunk *remembered_state = 0;
5654 Frame_Chunk *rs;
5655 int is_eh = strcmp (section->name, ".eh_frame") == 0;
5656 unsigned int length_return;
5657 unsigned int max_regs = 0;
5658 const char *bad_reg = _("bad register: ");
5659 unsigned int saved_eh_addr_size = eh_addr_size;
5660
5661 printf (_("Contents of the %s section:\n"), section->name);
5662
5663 while (start < end)
5664 {
5665 unsigned char *saved_start;
5666 unsigned char *block_end;
5667 dwarf_vma length;
5668 dwarf_vma cie_id;
5669 Frame_Chunk *fc;
5670 Frame_Chunk *cie;
5671 int need_col_headers = 1;
5672 unsigned char *augmentation_data = NULL;
5673 unsigned long augmentation_data_len = 0;
5674 unsigned int encoded_ptr_size = saved_eh_addr_size;
5675 unsigned int offset_size;
5676 unsigned int initial_length_size;
5677
5678 saved_start = start;
5679
5680 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
5681
5682 if (length == 0)
5683 {
5684 printf ("\n%08lx ZERO terminator\n\n",
5685 (unsigned long)(saved_start - section_start));
5686 /* Skip any zero terminators that directly follow.
5687 A corrupt section size could have loaded a whole
5688 slew of zero filled memory bytes. eg
5689 PR 17512: file: 070-19381-0.004. */
5690 while (start < end && * start == 0)
5691 ++ start;
5692 continue;
5693 }
5694
5695 if (length == 0xffffffff)
5696 {
5697 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
5698 offset_size = 8;
5699 initial_length_size = 12;
5700 }
5701 else
5702 {
5703 offset_size = 4;
5704 initial_length_size = 4;
5705 }
5706
5707 block_end = saved_start + length + initial_length_size;
5708 if (block_end > end || block_end < start)
5709 {
5710 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5711 dwarf_vmatoa_1 (NULL, length, offset_size),
5712 (unsigned long) (saved_start - section_start));
5713 block_end = end;
5714 }
5715
5716 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
5717
5718 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
5719 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
5720 {
5721 int version;
5722 unsigned int mreg;
5723
5724 start = read_cie (start, end, &cie, &version,
5725 &augmentation_data_len, &augmentation_data);
5726 /* PR 17512: file: 027-135133-0.005. */
5727 if (cie == NULL)
5728 break;
5729
5730 fc = cie;
5731 fc->next = chunks;
5732 chunks = fc;
5733 fc->chunk_start = saved_start;
5734 mreg = max_regs > 0 ? max_regs - 1 : 0;
5735 if (mreg < fc->ra)
5736 mreg = fc->ra;
5737 if (frame_need_space (fc, mreg) < 0)
5738 break;
5739 if (fc->fde_encoding)
5740 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5741
5742 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
5743 print_dwarf_vma (length, fc->ptr_size);
5744 print_dwarf_vma (cie_id, offset_size);
5745
5746 if (do_debug_frames_interp)
5747 {
5748 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
5749 fc->code_factor, fc->data_factor, fc->ra);
5750 }
5751 else
5752 {
5753 printf ("CIE\n");
5754 printf (" Version: %d\n", version);
5755 printf (" Augmentation: \"%s\"\n", fc->augmentation);
5756 if (version >= 4)
5757 {
5758 printf (" Pointer Size: %u\n", fc->ptr_size);
5759 printf (" Segment Size: %u\n", fc->segment_size);
5760 }
5761 printf (" Code alignment factor: %u\n", fc->code_factor);
5762 printf (" Data alignment factor: %d\n", fc->data_factor);
5763 printf (" Return address column: %d\n", fc->ra);
5764
5765 if (augmentation_data_len)
5766 {
5767 unsigned long i;
5768
5769 printf (" Augmentation data: ");
5770 for (i = 0; i < augmentation_data_len; ++i)
5771 /* FIXME: If do_wide is FALSE, then we should
5772 add carriage returns at 80 columns... */
5773 printf (" %02x", augmentation_data[i]);
5774 putchar ('\n');
5775 }
5776 putchar ('\n');
5777 }
5778 }
5779 else
5780 {
5781 unsigned char *look_for;
5782 static Frame_Chunk fde_fc;
5783 unsigned long segment_selector;
5784
5785 if (is_eh)
5786 {
5787 dwarf_vma sign = (dwarf_vma) 1 << (offset_size * 8 - 1);
5788 look_for = start - 4 - ((cie_id ^ sign) - sign);
5789 }
5790 else
5791 look_for = section_start + cie_id;
5792
5793 if (look_for <= saved_start)
5794 {
5795 for (cie = chunks; cie ; cie = cie->next)
5796 if (cie->chunk_start == look_for)
5797 break;
5798 }
5799 else
5800 {
5801 for (cie = forward_refs; cie ; cie = cie->next)
5802 if (cie->chunk_start == look_for)
5803 break;
5804 if (!cie)
5805 {
5806 unsigned int off_size;
5807 unsigned char *cie_scan;
5808
5809 cie_scan = look_for;
5810 off_size = 4;
5811 SAFE_BYTE_GET_AND_INC (length, cie_scan, 4, end);
5812 if (length == 0xffffffff)
5813 {
5814 SAFE_BYTE_GET_AND_INC (length, cie_scan, 8, end);
5815 off_size = 8;
5816 }
5817 if (length != 0)
5818 {
5819 dwarf_vma c_id;
5820
5821 SAFE_BYTE_GET_AND_INC (c_id, cie_scan, off_size, end);
5822 if (is_eh
5823 ? c_id == 0
5824 : ((off_size == 4 && c_id == DW_CIE_ID)
5825 || (off_size == 8 && c_id == DW64_CIE_ID)))
5826 {
5827 int version;
5828 unsigned int mreg;
5829
5830 read_cie (cie_scan, end, &cie, &version,
5831 &augmentation_data_len, &augmentation_data);
5832 /* PR 17512: file: 3450-2098-0.004. */
5833 if (cie == NULL)
5834 {
5835 warn (_("Failed to read CIE information\n"));
5836 break;
5837 }
5838 cie->next = forward_refs;
5839 forward_refs = cie;
5840 cie->chunk_start = look_for;
5841 mreg = max_regs > 0 ? max_regs - 1 : 0;
5842 if (mreg < cie->ra)
5843 mreg = cie->ra;
5844 if (frame_need_space (cie, mreg) < 0)
5845 {
5846 warn (_("Invalid max register\n"));
5847 break;
5848 }
5849 if (cie->fde_encoding)
5850 encoded_ptr_size
5851 = size_of_encoded_value (cie->fde_encoding);
5852 }
5853 }
5854 }
5855 }
5856
5857 fc = &fde_fc;
5858 memset (fc, 0, sizeof (Frame_Chunk));
5859
5860 if (!cie)
5861 {
5862 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
5863 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5864 (unsigned long) (saved_start - section_start));
5865 fc->ncols = 0;
5866 fc->col_type = (short int *) xmalloc (sizeof (short int));
5867 fc->col_offset = (int *) xmalloc (sizeof (int));
5868 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1 : 0) < 0)
5869 {
5870 warn (_("Invalid max register\n"));
5871 break;
5872 }
5873 cie = fc;
5874 fc->augmentation = "";
5875 fc->fde_encoding = 0;
5876 fc->ptr_size = eh_addr_size;
5877 fc->segment_size = 0;
5878 }
5879 else
5880 {
5881 fc->ncols = cie->ncols;
5882 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5883 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5884 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5885 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5886 fc->augmentation = cie->augmentation;
5887 fc->ptr_size = cie->ptr_size;
5888 eh_addr_size = cie->ptr_size;
5889 fc->segment_size = cie->segment_size;
5890 fc->code_factor = cie->code_factor;
5891 fc->data_factor = cie->data_factor;
5892 fc->cfa_reg = cie->cfa_reg;
5893 fc->cfa_offset = cie->cfa_offset;
5894 fc->ra = cie->ra;
5895 if (frame_need_space (fc, max_regs > 0 ? max_regs - 1: 0) < 0)
5896 {
5897 warn (_("Invalid max register\n"));
5898 break;
5899 }
5900 fc->fde_encoding = cie->fde_encoding;
5901 }
5902
5903 if (fc->fde_encoding)
5904 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5905
5906 segment_selector = 0;
5907 if (fc->segment_size)
5908 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
5909
5910 fc->pc_begin = get_encoded_value (&start, fc->fde_encoding, section, end);
5911
5912 /* FIXME: It appears that sometimes the final pc_range value is
5913 encoded in less than encoded_ptr_size bytes. See the x86_64
5914 run of the "objcopy on compressed debug sections" test for an
5915 example of this. */
5916 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
5917
5918 if (cie->augmentation[0] == 'z')
5919 {
5920 augmentation_data_len = LEB ();
5921 augmentation_data = start;
5922 start += augmentation_data_len;
5923 /* PR 17512: file: 722-8446-0.004. */
5924 if (start >= end || ((signed long) augmentation_data_len) < 0)
5925 {
5926 warn (_("Corrupt augmentation data length: %lx\n"),
5927 augmentation_data_len);
5928 start = end;
5929 augmentation_data = NULL;
5930 augmentation_data_len = 0;
5931 }
5932 }
5933
5934 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
5935 (unsigned long)(saved_start - section_start),
5936 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
5937 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5938 (unsigned long)(cie->chunk_start - section_start));
5939
5940 if (fc->segment_size)
5941 printf ("%04lx:", segment_selector);
5942
5943 printf ("%s..%s\n",
5944 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
5945 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
5946
5947 if (! do_debug_frames_interp && augmentation_data_len)
5948 {
5949 unsigned long i;
5950
5951 printf (" Augmentation data: ");
5952 for (i = 0; i < augmentation_data_len; ++i)
5953 printf (" %02x", augmentation_data[i]);
5954 putchar ('\n');
5955 putchar ('\n');
5956 }
5957 }
5958
5959 /* At this point, fc is the current chunk, cie (if any) is set, and
5960 we're about to interpret instructions for the chunk. */
5961 /* ??? At present we need to do this always, since this sizes the
5962 fc->col_type and fc->col_offset arrays, which we write into always.
5963 We should probably split the interpreted and non-interpreted bits
5964 into two different routines, since there's so much that doesn't
5965 really overlap between them. */
5966 if (1 || do_debug_frames_interp)
5967 {
5968 /* Start by making a pass over the chunk, allocating storage
5969 and taking note of what registers are used. */
5970 unsigned char *tmp = start;
5971
5972 while (start < block_end)
5973 {
5974 unsigned int reg, op, opa;
5975 unsigned long temp;
5976 unsigned char * new_start;
5977
5978 op = *start++;
5979 opa = op & 0x3f;
5980 if (op & 0xc0)
5981 op &= 0xc0;
5982
5983 /* Warning: if you add any more cases to this switch, be
5984 sure to add them to the corresponding switch below. */
5985 switch (op)
5986 {
5987 case DW_CFA_advance_loc:
5988 break;
5989 case DW_CFA_offset:
5990 LEB ();
5991 if (frame_need_space (fc, opa) >= 0)
5992 fc->col_type[opa] = DW_CFA_undefined;
5993 break;
5994 case DW_CFA_restore:
5995 if (frame_need_space (fc, opa) >= 0)
5996 fc->col_type[opa] = DW_CFA_undefined;
5997 break;
5998 case DW_CFA_set_loc:
5999 start += encoded_ptr_size;
6000 break;
6001 case DW_CFA_advance_loc1:
6002 start += 1;
6003 break;
6004 case DW_CFA_advance_loc2:
6005 start += 2;
6006 break;
6007 case DW_CFA_advance_loc4:
6008 start += 4;
6009 break;
6010 case DW_CFA_offset_extended:
6011 case DW_CFA_val_offset:
6012 reg = LEB (); LEB ();
6013 if (frame_need_space (fc, reg) >= 0)
6014 fc->col_type[reg] = DW_CFA_undefined;
6015 break;
6016 case DW_CFA_restore_extended:
6017 reg = LEB ();
6018 if (frame_need_space (fc, reg) >= 0)
6019 fc->col_type[reg] = DW_CFA_undefined;
6020 break;
6021 case DW_CFA_undefined:
6022 reg = LEB ();
6023 if (frame_need_space (fc, reg) >= 0)
6024 fc->col_type[reg] = DW_CFA_undefined;
6025 break;
6026 case DW_CFA_same_value:
6027 reg = LEB ();
6028 if (frame_need_space (fc, reg) >= 0)
6029 fc->col_type[reg] = DW_CFA_undefined;
6030 break;
6031 case DW_CFA_register:
6032 reg = LEB (); LEB ();
6033 if (frame_need_space (fc, reg) >= 0)
6034 fc->col_type[reg] = DW_CFA_undefined;
6035 break;
6036 case DW_CFA_def_cfa:
6037 LEB (); LEB ();
6038 break;
6039 case DW_CFA_def_cfa_register:
6040 LEB ();
6041 break;
6042 case DW_CFA_def_cfa_offset:
6043 LEB ();
6044 break;
6045 case DW_CFA_def_cfa_expression:
6046 temp = LEB ();
6047 new_start = start + temp;
6048 if (new_start < start)
6049 {
6050 warn (_("Corrupt CFA_def expression value: %lu\n"), temp);
6051 start = block_end;
6052 }
6053 else
6054 start = new_start;
6055 break;
6056 case DW_CFA_expression:
6057 case DW_CFA_val_expression:
6058 reg = LEB ();
6059 temp = LEB ();
6060 new_start = start + temp;
6061 if (new_start < start)
6062 {
6063 /* PR 17512: file:306-192417-0.005. */
6064 warn (_("Corrupt CFA expression value: %lu\n"), temp);
6065 start = block_end;
6066 }
6067 else
6068 start = new_start;
6069 if (frame_need_space (fc, reg) >= 0)
6070 fc->col_type[reg] = DW_CFA_undefined;
6071 break;
6072 case DW_CFA_offset_extended_sf:
6073 case DW_CFA_val_offset_sf:
6074 reg = LEB (); SLEB ();
6075 if (frame_need_space (fc, reg) >= 0)
6076 fc->col_type[reg] = DW_CFA_undefined;
6077 break;
6078 case DW_CFA_def_cfa_sf:
6079 LEB (); SLEB ();
6080 break;
6081 case DW_CFA_def_cfa_offset_sf:
6082 SLEB ();
6083 break;
6084 case DW_CFA_MIPS_advance_loc8:
6085 start += 8;
6086 break;
6087 case DW_CFA_GNU_args_size:
6088 LEB ();
6089 break;
6090 case DW_CFA_GNU_negative_offset_extended:
6091 reg = LEB (); LEB ();
6092 if (frame_need_space (fc, reg) >= 0)
6093 fc->col_type[reg] = DW_CFA_undefined;
6094 break;
6095 default:
6096 break;
6097 }
6098 }
6099 start = tmp;
6100 }
6101
6102 /* Now we know what registers are used, make a second pass over
6103 the chunk, this time actually printing out the info. */
6104
6105 while (start < block_end)
6106 {
6107 unsigned op, opa;
6108 unsigned long ul, reg, roffs;
6109 long l;
6110 dwarf_vma ofs;
6111 dwarf_vma vma;
6112 const char *reg_prefix = "";
6113
6114 op = *start++;
6115 opa = op & 0x3f;
6116 if (op & 0xc0)
6117 op &= 0xc0;
6118
6119 /* Warning: if you add any more cases to this switch, be
6120 sure to add them to the corresponding switch above. */
6121 switch (op)
6122 {
6123 case DW_CFA_advance_loc:
6124 if (do_debug_frames_interp)
6125 frame_display_row (fc, &need_col_headers, &max_regs);
6126 else
6127 printf (" DW_CFA_advance_loc: %d to %s\n",
6128 opa * fc->code_factor,
6129 dwarf_vmatoa_1 (NULL,
6130 fc->pc_begin + opa * fc->code_factor,
6131 fc->ptr_size));
6132 fc->pc_begin += opa * fc->code_factor;
6133 break;
6134
6135 case DW_CFA_offset:
6136 roffs = LEB ();
6137 if (opa >= (unsigned int) fc->ncols)
6138 reg_prefix = bad_reg;
6139 if (! do_debug_frames_interp || *reg_prefix != '\0')
6140 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
6141 reg_prefix, regname (opa, 0),
6142 roffs * fc->data_factor);
6143 if (*reg_prefix == '\0')
6144 {
6145 fc->col_type[opa] = DW_CFA_offset;
6146 fc->col_offset[opa] = roffs * fc->data_factor;
6147 }
6148 break;
6149
6150 case DW_CFA_restore:
6151 if (opa >= (unsigned int) cie->ncols
6152 || opa >= (unsigned int) fc->ncols)
6153 reg_prefix = bad_reg;
6154 if (! do_debug_frames_interp || *reg_prefix != '\0')
6155 printf (" DW_CFA_restore: %s%s\n",
6156 reg_prefix, regname (opa, 0));
6157 if (*reg_prefix == '\0')
6158 {
6159 fc->col_type[opa] = cie->col_type[opa];
6160 fc->col_offset[opa] = cie->col_offset[opa];
6161 if (do_debug_frames_interp
6162 && fc->col_type[opa] == DW_CFA_unreferenced)
6163 fc->col_type[opa] = DW_CFA_undefined;
6164 }
6165 break;
6166
6167 case DW_CFA_set_loc:
6168 vma = get_encoded_value (&start, fc->fde_encoding, section, block_end);
6169 if (do_debug_frames_interp)
6170 frame_display_row (fc, &need_col_headers, &max_regs);
6171 else
6172 printf (" DW_CFA_set_loc: %s\n",
6173 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
6174 fc->pc_begin = vma;
6175 break;
6176
6177 case DW_CFA_advance_loc1:
6178 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
6179 if (do_debug_frames_interp)
6180 frame_display_row (fc, &need_col_headers, &max_regs);
6181 else
6182 printf (" DW_CFA_advance_loc1: %ld to %s\n",
6183 (unsigned long) (ofs * fc->code_factor),
6184 dwarf_vmatoa_1 (NULL,
6185 fc->pc_begin + ofs * fc->code_factor,
6186 fc->ptr_size));
6187 fc->pc_begin += ofs * fc->code_factor;
6188 break;
6189
6190 case DW_CFA_advance_loc2:
6191 SAFE_BYTE_GET_AND_INC (ofs, start, 2, block_end);
6192 if (do_debug_frames_interp)
6193 frame_display_row (fc, &need_col_headers, &max_regs);
6194 else
6195 printf (" DW_CFA_advance_loc2: %ld to %s\n",
6196 (unsigned long) (ofs * fc->code_factor),
6197 dwarf_vmatoa_1 (NULL,
6198 fc->pc_begin + ofs * fc->code_factor,
6199 fc->ptr_size));
6200 fc->pc_begin += ofs * fc->code_factor;
6201 break;
6202
6203 case DW_CFA_advance_loc4:
6204 SAFE_BYTE_GET_AND_INC (ofs, start, 4, block_end);
6205 if (do_debug_frames_interp)
6206 frame_display_row (fc, &need_col_headers, &max_regs);
6207 else
6208 printf (" DW_CFA_advance_loc4: %ld to %s\n",
6209 (unsigned long) (ofs * fc->code_factor),
6210 dwarf_vmatoa_1 (NULL,
6211 fc->pc_begin + ofs * fc->code_factor,
6212 fc->ptr_size));
6213 fc->pc_begin += ofs * fc->code_factor;
6214 break;
6215
6216 case DW_CFA_offset_extended:
6217 reg = LEB ();
6218 roffs = LEB ();
6219 if (reg >= (unsigned int) fc->ncols)
6220 reg_prefix = bad_reg;
6221 if (! do_debug_frames_interp || *reg_prefix != '\0')
6222 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
6223 reg_prefix, regname (reg, 0),
6224 roffs * fc->data_factor);
6225 if (*reg_prefix == '\0')
6226 {
6227 fc->col_type[reg] = DW_CFA_offset;
6228 fc->col_offset[reg] = roffs * fc->data_factor;
6229 }
6230 break;
6231
6232 case DW_CFA_val_offset:
6233 reg = LEB ();
6234 roffs = LEB ();
6235 if (reg >= (unsigned int) fc->ncols)
6236 reg_prefix = bad_reg;
6237 if (! do_debug_frames_interp || *reg_prefix != '\0')
6238 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
6239 reg_prefix, regname (reg, 0),
6240 roffs * fc->data_factor);
6241 if (*reg_prefix == '\0')
6242 {
6243 fc->col_type[reg] = DW_CFA_val_offset;
6244 fc->col_offset[reg] = roffs * fc->data_factor;
6245 }
6246 break;
6247
6248 case DW_CFA_restore_extended:
6249 reg = LEB ();
6250 if (reg >= (unsigned int) cie->ncols
6251 || reg >= (unsigned int) fc->ncols)
6252 reg_prefix = bad_reg;
6253 if (! do_debug_frames_interp || *reg_prefix != '\0')
6254 printf (" DW_CFA_restore_extended: %s%s\n",
6255 reg_prefix, regname (reg, 0));
6256 if (*reg_prefix == '\0')
6257 {
6258 fc->col_type[reg] = cie->col_type[reg];
6259 fc->col_offset[reg] = cie->col_offset[reg];
6260 }
6261 break;
6262
6263 case DW_CFA_undefined:
6264 reg = LEB ();
6265 if (reg >= (unsigned int) fc->ncols)
6266 reg_prefix = bad_reg;
6267 if (! do_debug_frames_interp || *reg_prefix != '\0')
6268 printf (" DW_CFA_undefined: %s%s\n",
6269 reg_prefix, regname (reg, 0));
6270 if (*reg_prefix == '\0')
6271 {
6272 fc->col_type[reg] = DW_CFA_undefined;
6273 fc->col_offset[reg] = 0;
6274 }
6275 break;
6276
6277 case DW_CFA_same_value:
6278 reg = LEB ();
6279 if (reg >= (unsigned int) fc->ncols)
6280 reg_prefix = bad_reg;
6281 if (! do_debug_frames_interp || *reg_prefix != '\0')
6282 printf (" DW_CFA_same_value: %s%s\n",
6283 reg_prefix, regname (reg, 0));
6284 if (*reg_prefix == '\0')
6285 {
6286 fc->col_type[reg] = DW_CFA_same_value;
6287 fc->col_offset[reg] = 0;
6288 }
6289 break;
6290
6291 case DW_CFA_register:
6292 reg = LEB ();
6293 roffs = LEB ();
6294 if (reg >= (unsigned int) fc->ncols)
6295 reg_prefix = bad_reg;
6296 if (! do_debug_frames_interp || *reg_prefix != '\0')
6297 {
6298 printf (" DW_CFA_register: %s%s in ",
6299 reg_prefix, regname (reg, 0));
6300 puts (regname (roffs, 0));
6301 }
6302 if (*reg_prefix == '\0')
6303 {
6304 fc->col_type[reg] = DW_CFA_register;
6305 fc->col_offset[reg] = roffs;
6306 }
6307 break;
6308
6309 case DW_CFA_remember_state:
6310 if (! do_debug_frames_interp)
6311 printf (" DW_CFA_remember_state\n");
6312 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
6313 rs->cfa_offset = fc->cfa_offset;
6314 rs->cfa_reg = fc->cfa_reg;
6315 rs->ra = fc->ra;
6316 rs->cfa_exp = fc->cfa_exp;
6317 rs->ncols = fc->ncols;
6318 rs->col_type = (short int *) xcmalloc (rs->ncols,
6319 sizeof (* rs->col_type));
6320 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
6321 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
6322 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
6323 rs->next = remembered_state;
6324 remembered_state = rs;
6325 break;
6326
6327 case DW_CFA_restore_state:
6328 if (! do_debug_frames_interp)
6329 printf (" DW_CFA_restore_state\n");
6330 rs = remembered_state;
6331 if (rs)
6332 {
6333 remembered_state = rs->next;
6334 fc->cfa_offset = rs->cfa_offset;
6335 fc->cfa_reg = rs->cfa_reg;
6336 fc->ra = rs->ra;
6337 fc->cfa_exp = rs->cfa_exp;
6338 if (frame_need_space (fc, rs->ncols - 1) < 0)
6339 {
6340 warn (_("Invalid column number in saved frame state\n"));
6341 fc->ncols = 0;
6342 break;
6343 }
6344 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
6345 memcpy (fc->col_offset, rs->col_offset,
6346 rs->ncols * sizeof (* rs->col_offset));
6347 free (rs->col_type);
6348 free (rs->col_offset);
6349 free (rs);
6350 }
6351 else if (do_debug_frames_interp)
6352 printf ("Mismatched DW_CFA_restore_state\n");
6353 break;
6354
6355 case DW_CFA_def_cfa:
6356 fc->cfa_reg = LEB ();
6357 fc->cfa_offset = LEB ();
6358 fc->cfa_exp = 0;
6359 if (! do_debug_frames_interp)
6360 printf (" DW_CFA_def_cfa: %s ofs %d\n",
6361 regname (fc->cfa_reg, 0), fc->cfa_offset);
6362 break;
6363
6364 case DW_CFA_def_cfa_register:
6365 fc->cfa_reg = LEB ();
6366 fc->cfa_exp = 0;
6367 if (! do_debug_frames_interp)
6368 printf (" DW_CFA_def_cfa_register: %s\n",
6369 regname (fc->cfa_reg, 0));
6370 break;
6371
6372 case DW_CFA_def_cfa_offset:
6373 fc->cfa_offset = LEB ();
6374 if (! do_debug_frames_interp)
6375 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
6376 break;
6377
6378 case DW_CFA_nop:
6379 if (! do_debug_frames_interp)
6380 printf (" DW_CFA_nop\n");
6381 break;
6382
6383 case DW_CFA_def_cfa_expression:
6384 ul = LEB ();
6385 if (start >= block_end || start + ul > block_end || start + ul < start)
6386 {
6387 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul);
6388 break;
6389 }
6390 if (! do_debug_frames_interp)
6391 {
6392 printf (" DW_CFA_def_cfa_expression (");
6393 decode_location_expression (start, eh_addr_size, 0, -1,
6394 ul, 0, section);
6395 printf (")\n");
6396 }
6397 fc->cfa_exp = 1;
6398 start += ul;
6399 break;
6400
6401 case DW_CFA_expression:
6402 reg = LEB ();
6403 ul = LEB ();
6404 if (reg >= (unsigned int) fc->ncols)
6405 reg_prefix = bad_reg;
6406 /* PR 17512: file: 069-133014-0.006. */
6407 /* PR 17512: file: 98c02eb4. */
6408 if (start >= block_end || start + ul > block_end || start + ul < start)
6409 {
6410 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul);
6411 break;
6412 }
6413 if (! do_debug_frames_interp || *reg_prefix != '\0')
6414 {
6415 printf (" DW_CFA_expression: %s%s (",
6416 reg_prefix, regname (reg, 0));
6417 decode_location_expression (start, eh_addr_size, 0, -1,
6418 ul, 0, section);
6419 printf (")\n");
6420 }
6421 if (*reg_prefix == '\0')
6422 fc->col_type[reg] = DW_CFA_expression;
6423 start += ul;
6424 break;
6425
6426 case DW_CFA_val_expression:
6427 reg = LEB ();
6428 ul = LEB ();
6429 if (reg >= (unsigned int) fc->ncols)
6430 reg_prefix = bad_reg;
6431 if (start >= block_end || start + ul > block_end || start + ul < start)
6432 {
6433 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul);
6434 break;
6435 }
6436 if (! do_debug_frames_interp || *reg_prefix != '\0')
6437 {
6438 printf (" DW_CFA_val_expression: %s%s (",
6439 reg_prefix, regname (reg, 0));
6440 decode_location_expression (start, eh_addr_size, 0, -1,
6441 ul, 0, section);
6442 printf (")\n");
6443 }
6444 if (*reg_prefix == '\0')
6445 fc->col_type[reg] = DW_CFA_val_expression;
6446 start += ul;
6447 break;
6448
6449 case DW_CFA_offset_extended_sf:
6450 reg = LEB ();
6451 l = SLEB ();
6452 if (frame_need_space (fc, reg) < 0)
6453 reg_prefix = bad_reg;
6454 if (! do_debug_frames_interp || *reg_prefix != '\0')
6455 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
6456 reg_prefix, regname (reg, 0),
6457 l * fc->data_factor);
6458 if (*reg_prefix == '\0')
6459 {
6460 fc->col_type[reg] = DW_CFA_offset;
6461 fc->col_offset[reg] = l * fc->data_factor;
6462 }
6463 break;
6464
6465 case DW_CFA_val_offset_sf:
6466 reg = LEB ();
6467 l = SLEB ();
6468 if (frame_need_space (fc, reg) < 0)
6469 reg_prefix = bad_reg;
6470 if (! do_debug_frames_interp || *reg_prefix != '\0')
6471 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
6472 reg_prefix, regname (reg, 0),
6473 l * fc->data_factor);
6474 if (*reg_prefix == '\0')
6475 {
6476 fc->col_type[reg] = DW_CFA_val_offset;
6477 fc->col_offset[reg] = l * fc->data_factor;
6478 }
6479 break;
6480
6481 case DW_CFA_def_cfa_sf:
6482 fc->cfa_reg = LEB ();
6483 fc->cfa_offset = SLEB ();
6484 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
6485 fc->cfa_exp = 0;
6486 if (! do_debug_frames_interp)
6487 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
6488 regname (fc->cfa_reg, 0), fc->cfa_offset);
6489 break;
6490
6491 case DW_CFA_def_cfa_offset_sf:
6492 fc->cfa_offset = SLEB ();
6493 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
6494 if (! do_debug_frames_interp)
6495 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
6496 break;
6497
6498 case DW_CFA_MIPS_advance_loc8:
6499 SAFE_BYTE_GET_AND_INC (ofs, start, 8, block_end);
6500 if (do_debug_frames_interp)
6501 frame_display_row (fc, &need_col_headers, &max_regs);
6502 else
6503 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
6504 (unsigned long) (ofs * fc->code_factor),
6505 dwarf_vmatoa_1 (NULL,
6506 fc->pc_begin + ofs * fc->code_factor,
6507 fc->ptr_size));
6508 fc->pc_begin += ofs * fc->code_factor;
6509 break;
6510
6511 case DW_CFA_GNU_window_save:
6512 if (! do_debug_frames_interp)
6513 printf (" DW_CFA_GNU_window_save\n");
6514 break;
6515
6516 case DW_CFA_GNU_args_size:
6517 ul = LEB ();
6518 if (! do_debug_frames_interp)
6519 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
6520 break;
6521
6522 case DW_CFA_GNU_negative_offset_extended:
6523 reg = LEB ();
6524 l = - LEB ();
6525 if (frame_need_space (fc, reg) < 0)
6526 reg_prefix = bad_reg;
6527 if (! do_debug_frames_interp || *reg_prefix != '\0')
6528 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6529 reg_prefix, regname (reg, 0),
6530 l * fc->data_factor);
6531 if (*reg_prefix == '\0')
6532 {
6533 fc->col_type[reg] = DW_CFA_offset;
6534 fc->col_offset[reg] = l * fc->data_factor;
6535 }
6536 break;
6537
6538 default:
6539 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
6540 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
6541 else
6542 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
6543 start = block_end;
6544 }
6545 }
6546
6547 if (do_debug_frames_interp)
6548 frame_display_row (fc, &need_col_headers, &max_regs);
6549
6550 start = block_end;
6551 eh_addr_size = saved_eh_addr_size;
6552 }
6553
6554 printf ("\n");
6555
6556 return 1;
6557 }
6558
6559 #undef GET
6560 #undef LEB
6561 #undef SLEB
6562
6563 static int
6564 display_gdb_index (struct dwarf_section *section,
6565 void *file ATTRIBUTE_UNUSED)
6566 {
6567 unsigned char *start = section->start;
6568 uint32_t version;
6569 uint32_t cu_list_offset, tu_list_offset;
6570 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
6571 unsigned int cu_list_elements, tu_list_elements;
6572 unsigned int address_table_size, symbol_table_slots;
6573 unsigned char *cu_list, *tu_list;
6574 unsigned char *address_table, *symbol_table, *constant_pool;
6575 unsigned int i;
6576
6577 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6578
6579 printf (_("Contents of the %s section:\n"), section->name);
6580
6581 if (section->size < 6 * sizeof (uint32_t))
6582 {
6583 warn (_("Truncated header in the %s section.\n"), section->name);
6584 return 0;
6585 }
6586
6587 version = byte_get_little_endian (start, 4);
6588 printf (_("Version %ld\n"), (long) version);
6589
6590 /* Prior versions are obsolete, and future versions may not be
6591 backwards compatible. */
6592 if (version < 3 || version > 8)
6593 {
6594 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
6595 return 0;
6596 }
6597 if (version < 4)
6598 warn (_("The address table data in version 3 may be wrong.\n"));
6599 if (version < 5)
6600 warn (_("Version 4 does not support case insensitive lookups.\n"));
6601 if (version < 6)
6602 warn (_("Version 5 does not include inlined functions.\n"));
6603 if (version < 7)
6604 warn (_("Version 6 does not include symbol attributes.\n"));
6605 /* Version 7 indices generated by Gold have bad type unit references,
6606 PR binutils/15021. But we don't know if the index was generated by
6607 Gold or not, so to avoid worrying users with gdb-generated indices
6608 we say nothing for version 7 here. */
6609
6610 cu_list_offset = byte_get_little_endian (start + 4, 4);
6611 tu_list_offset = byte_get_little_endian (start + 8, 4);
6612 address_table_offset = byte_get_little_endian (start + 12, 4);
6613 symbol_table_offset = byte_get_little_endian (start + 16, 4);
6614 constant_pool_offset = byte_get_little_endian (start + 20, 4);
6615
6616 if (cu_list_offset > section->size
6617 || tu_list_offset > section->size
6618 || address_table_offset > section->size
6619 || symbol_table_offset > section->size
6620 || constant_pool_offset > section->size)
6621 {
6622 warn (_("Corrupt header in the %s section.\n"), section->name);
6623 return 0;
6624 }
6625
6626 /* PR 17531: file: 418d0a8a. */
6627 if (tu_list_offset < cu_list_offset)
6628 {
6629 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
6630 tu_list_offset, cu_list_offset);
6631 return 0;
6632 }
6633
6634 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
6635
6636 if (address_table_offset < tu_list_offset)
6637 {
6638 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
6639 address_table_offset, tu_list_offset);
6640 return 0;
6641 }
6642
6643 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
6644
6645 /* PR 17531: file: 18a47d3d. */
6646 if (symbol_table_offset < address_table_offset)
6647 {
6648 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
6649 symbol_table_offset, address_table_offset);
6650 return 0;
6651 }
6652
6653 address_table_size = symbol_table_offset - address_table_offset;
6654
6655 if (constant_pool_offset < symbol_table_offset)
6656 {
6657 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
6658 constant_pool_offset, symbol_table_offset);
6659 return 0;
6660 }
6661
6662 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
6663
6664 cu_list = start + cu_list_offset;
6665 tu_list = start + tu_list_offset;
6666 address_table = start + address_table_offset;
6667 symbol_table = start + symbol_table_offset;
6668 constant_pool = start + constant_pool_offset;
6669
6670 if (address_table + address_table_size * (2 + 8 + 4) > section->start + section->size)
6671 {
6672 warn (_("Address table extends beyond end of section.\n"));
6673 return 0;
6674 }
6675
6676 printf (_("\nCU table:\n"));
6677 for (i = 0; i < cu_list_elements; i += 2)
6678 {
6679 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
6680 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
6681
6682 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
6683 (unsigned long) cu_offset,
6684 (unsigned long) (cu_offset + cu_length - 1));
6685 }
6686
6687 printf (_("\nTU table:\n"));
6688 for (i = 0; i < tu_list_elements; i += 3)
6689 {
6690 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
6691 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
6692 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
6693
6694 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
6695 (unsigned long) tu_offset,
6696 (unsigned long) type_offset);
6697 print_dwarf_vma (signature, 8);
6698 printf ("\n");
6699 }
6700
6701 printf (_("\nAddress table:\n"));
6702 for (i = 0; i < address_table_size && i <= address_table_size - (2 * 8 + 4);
6703 i += 2 * 8 + 4)
6704 {
6705 uint64_t low = byte_get_little_endian (address_table + i, 8);
6706 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
6707 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
6708
6709 print_dwarf_vma (low, 8);
6710 print_dwarf_vma (high, 8);
6711 printf (_("%lu\n"), (unsigned long) cu_index);
6712 }
6713
6714 printf (_("\nSymbol table:\n"));
6715 for (i = 0; i < symbol_table_slots; ++i)
6716 {
6717 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
6718 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
6719 uint32_t num_cus, cu;
6720
6721 if (name_offset != 0
6722 || cu_vector_offset != 0)
6723 {
6724 unsigned int j;
6725
6726 /* PR 17531: file: 5b7b07ad. */
6727 if (constant_pool + name_offset < constant_pool
6728 || constant_pool + name_offset >= section->start + section->size)
6729 {
6730 printf (_("[%3u] <corrupt offset: %x>"), i, name_offset);
6731 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
6732 name_offset, i);
6733 }
6734 else
6735 printf ("[%3u] %.*s:", i,
6736 (int) (section->size - (constant_pool_offset + name_offset)),
6737 constant_pool + name_offset);
6738
6739 if (constant_pool + cu_vector_offset < constant_pool
6740 || constant_pool + cu_vector_offset >= section->start + section->size - 3)
6741 {
6742 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset);
6743 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
6744 cu_vector_offset, i);
6745 continue;
6746 }
6747
6748 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
6749
6750 if (num_cus * 4 < num_cus
6751 || constant_pool + cu_vector_offset + 4 + num_cus * 4
6752 >= section->start + section->size
6753 || (constant_pool + cu_vector_offset + 4 + num_cus * 4) < constant_pool)
6754 {
6755 printf ("<invalid number of CUs: %d>\n", num_cus);
6756 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
6757 num_cus, i);
6758 continue;
6759 }
6760
6761 if (num_cus > 1)
6762 printf ("\n");
6763
6764 for (j = 0; j < num_cus; ++j)
6765 {
6766 int is_static;
6767 gdb_index_symbol_kind kind;
6768
6769 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
6770 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
6771 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
6772 cu = GDB_INDEX_CU_VALUE (cu);
6773 /* Convert to TU number if it's for a type unit. */
6774 if (cu >= cu_list_elements / 2)
6775 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
6776 (unsigned long) (cu - cu_list_elements / 2));
6777 else
6778 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
6779
6780 printf (" [%s, %s]",
6781 is_static ? _("static") : _("global"),
6782 get_gdb_index_symbol_kind_name (kind));
6783 if (num_cus > 1)
6784 printf ("\n");
6785 }
6786 if (num_cus <= 1)
6787 printf ("\n");
6788 }
6789 }
6790
6791 return 1;
6792 }
6793
6794 /* Pre-allocate enough space for the CU/TU sets needed. */
6795
6796 static void
6797 prealloc_cu_tu_list (unsigned int nshndx)
6798 {
6799 if (shndx_pool == NULL)
6800 {
6801 shndx_pool_size = nshndx;
6802 shndx_pool_used = 0;
6803 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
6804 sizeof (unsigned int));
6805 }
6806 else
6807 {
6808 shndx_pool_size = shndx_pool_used + nshndx;
6809 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
6810 sizeof (unsigned int));
6811 }
6812 }
6813
6814 static void
6815 add_shndx_to_cu_tu_entry (unsigned int shndx)
6816 {
6817 if (shndx_pool_used >= shndx_pool_size)
6818 {
6819 error (_("Internal error: out of space in the shndx pool.\n"));
6820 return;
6821 }
6822 shndx_pool [shndx_pool_used++] = shndx;
6823 }
6824
6825 static void
6826 end_cu_tu_entry (void)
6827 {
6828 if (shndx_pool_used >= shndx_pool_size)
6829 {
6830 error (_("Internal error: out of space in the shndx pool.\n"));
6831 return;
6832 }
6833 shndx_pool [shndx_pool_used++] = 0;
6834 }
6835
6836 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6837
6838 static const char *
6839 get_DW_SECT_short_name (unsigned int dw_sect)
6840 {
6841 static char buf[16];
6842
6843 switch (dw_sect)
6844 {
6845 case DW_SECT_INFO:
6846 return "info";
6847 case DW_SECT_TYPES:
6848 return "types";
6849 case DW_SECT_ABBREV:
6850 return "abbrev";
6851 case DW_SECT_LINE:
6852 return "line";
6853 case DW_SECT_LOC:
6854 return "loc";
6855 case DW_SECT_STR_OFFSETS:
6856 return "str_off";
6857 case DW_SECT_MACINFO:
6858 return "macinfo";
6859 case DW_SECT_MACRO:
6860 return "macro";
6861 default:
6862 break;
6863 }
6864
6865 snprintf (buf, sizeof (buf), "%d", dw_sect);
6866 return buf;
6867 }
6868
6869 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6870 These sections are extensions for Fission.
6871 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6872
6873 static int
6874 process_cu_tu_index (struct dwarf_section *section, int do_display)
6875 {
6876 unsigned char *phdr = section->start;
6877 unsigned char *limit = phdr + section->size;
6878 unsigned char *phash;
6879 unsigned char *pindex;
6880 unsigned char *ppool;
6881 unsigned int version;
6882 unsigned int ncols = 0;
6883 unsigned int nused;
6884 unsigned int nslots;
6885 unsigned int i;
6886 unsigned int j;
6887 dwarf_vma signature_high;
6888 dwarf_vma signature_low;
6889 char buf[64];
6890
6891 /* PR 17512: file: 002-168123-0.004. */
6892 if (phdr == NULL)
6893 {
6894 warn (_("Section %s is empty\n"), section->name);
6895 return 0;
6896 }
6897 /* PR 17512: file: 002-376-0.004. */
6898 if (section->size < 24)
6899 {
6900 warn (_("Section %s is too small to contain a CU/TU header\n"),
6901 section->name);
6902 return 0;
6903 }
6904
6905 SAFE_BYTE_GET (version, phdr, 4, limit);
6906 if (version >= 2)
6907 SAFE_BYTE_GET (ncols, phdr + 4, 4, limit);
6908 SAFE_BYTE_GET (nused, phdr + 8, 4, limit);
6909 SAFE_BYTE_GET (nslots, phdr + 12, 4, limit);
6910
6911 phash = phdr + 16;
6912 pindex = phash + nslots * 8;
6913 ppool = pindex + nslots * 4;
6914
6915 /* PR 17531: file: 45d69832. */
6916 if (pindex < phash || ppool < phdr)
6917 {
6918 warn (_("Section %s is too small for %d slots\n"),
6919 section->name, nslots);
6920 return 0;
6921 }
6922
6923 if (do_display)
6924 {
6925 printf (_("Contents of the %s section:\n\n"), section->name);
6926 printf (_(" Version: %d\n"), version);
6927 if (version >= 2)
6928 printf (_(" Number of columns: %d\n"), ncols);
6929 printf (_(" Number of used entries: %d\n"), nused);
6930 printf (_(" Number of slots: %d\n\n"), nslots);
6931 }
6932
6933 if (ppool > limit)
6934 {
6935 warn (_("Section %s too small for %d hash table entries\n"),
6936 section->name, nslots);
6937 return 0;
6938 }
6939
6940 if (version == 1)
6941 {
6942 if (!do_display)
6943 prealloc_cu_tu_list ((limit - ppool) / 4);
6944 for (i = 0; i < nslots; i++)
6945 {
6946 unsigned char *shndx_list;
6947 unsigned int shndx;
6948
6949 SAFE_BYTE_GET64 (phash, &signature_high, &signature_low, limit);
6950 if (signature_high != 0 || signature_low != 0)
6951 {
6952 SAFE_BYTE_GET (j, pindex, 4, limit);
6953 shndx_list = ppool + j * 4;
6954 /* PR 17531: file: 705e010d. */
6955 if (shndx_list < ppool)
6956 {
6957 warn (_("Section index pool located before start of section\n"));
6958 return 0;
6959 }
6960
6961 if (do_display)
6962 printf (_(" [%3d] Signature: 0x%s Sections: "),
6963 i, dwarf_vmatoa64 (signature_high, signature_low,
6964 buf, sizeof (buf)));
6965 for (;;)
6966 {
6967 if (shndx_list >= limit)
6968 {
6969 warn (_("Section %s too small for shndx pool\n"),
6970 section->name);
6971 return 0;
6972 }
6973 SAFE_BYTE_GET (shndx, shndx_list, 4, limit);
6974 if (shndx == 0)
6975 break;
6976 if (do_display)
6977 printf (" %d", shndx);
6978 else
6979 add_shndx_to_cu_tu_entry (shndx);
6980 shndx_list += 4;
6981 }
6982 if (do_display)
6983 printf ("\n");
6984 else
6985 end_cu_tu_entry ();
6986 }
6987 phash += 8;
6988 pindex += 4;
6989 }
6990 }
6991 else if (version == 2)
6992 {
6993 unsigned int val;
6994 unsigned int dw_sect;
6995 unsigned char *ph = phash;
6996 unsigned char *pi = pindex;
6997 unsigned char *poffsets = ppool + ncols * 4;
6998 unsigned char *psizes = poffsets + nused * ncols * 4;
6999 unsigned char *pend = psizes + nused * ncols * 4;
7000 bfd_boolean is_tu_index;
7001 struct cu_tu_set *this_set = NULL;
7002 unsigned int row;
7003 unsigned char *prow;
7004
7005 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
7006
7007 if (pend > limit)
7008 {
7009 warn (_("Section %s too small for offset and size tables\n"),
7010 section->name);
7011 return 0;
7012 }
7013
7014 if (do_display)
7015 {
7016 printf (_(" Offset table\n"));
7017 printf (" slot %-16s ",
7018 is_tu_index ? _("signature") : _("dwo_id"));
7019 }
7020 else
7021 {
7022 if (is_tu_index)
7023 {
7024 tu_count = nused;
7025 tu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
7026 this_set = tu_sets;
7027 }
7028 else
7029 {
7030 cu_count = nused;
7031 cu_sets = xcalloc2 (nused, sizeof (struct cu_tu_set));
7032 this_set = cu_sets;
7033 }
7034 }
7035
7036 if (do_display)
7037 {
7038 for (j = 0; j < ncols; j++)
7039 {
7040 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7041 printf (" %8s", get_DW_SECT_short_name (dw_sect));
7042 }
7043 printf ("\n");
7044 }
7045
7046 for (i = 0; i < nslots; i++)
7047 {
7048 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
7049
7050 SAFE_BYTE_GET (row, pi, 4, limit);
7051 if (row != 0)
7052 {
7053 /* PR 17531: file: a05f6ab3. */
7054 if (row > nused)
7055 {
7056 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
7057 row, nused);
7058 return 0;
7059 }
7060
7061 if (!do_display)
7062 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
7063
7064 prow = poffsets + (row - 1) * ncols * 4;
7065
7066 if (do_display)
7067 printf (_(" [%3d] 0x%s"),
7068 i, dwarf_vmatoa64 (signature_high, signature_low,
7069 buf, sizeof (buf)));
7070 for (j = 0; j < ncols; j++)
7071 {
7072 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
7073 if (do_display)
7074 printf (" %8d", val);
7075 else
7076 {
7077 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7078
7079 /* PR 17531: file: 10796eb3. */
7080 if (dw_sect >= DW_SECT_MAX)
7081 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
7082 else
7083 this_set [row - 1].section_offsets [dw_sect] = val;
7084 }
7085 }
7086
7087 if (do_display)
7088 printf ("\n");
7089 }
7090 ph += 8;
7091 pi += 4;
7092 }
7093
7094 ph = phash;
7095 pi = pindex;
7096 if (do_display)
7097 {
7098 printf ("\n");
7099 printf (_(" Size table\n"));
7100 printf (" slot %-16s ",
7101 is_tu_index ? _("signature") : _("dwo_id"));
7102 }
7103
7104 for (j = 0; j < ncols; j++)
7105 {
7106 SAFE_BYTE_GET (val, ppool + j * 4, 4, limit);
7107 if (do_display)
7108 printf (" %8s", get_DW_SECT_short_name (val));
7109 }
7110
7111 if (do_display)
7112 printf ("\n");
7113
7114 for (i = 0; i < nslots; i++)
7115 {
7116 SAFE_BYTE_GET64 (ph, &signature_high, &signature_low, limit);
7117
7118 SAFE_BYTE_GET (row, pi, 4, limit);
7119 if (row != 0)
7120 {
7121 prow = psizes + (row - 1) * ncols * 4;
7122
7123 if (do_display)
7124 printf (_(" [%3d] 0x%s"),
7125 i, dwarf_vmatoa64 (signature_high, signature_low,
7126 buf, sizeof (buf)));
7127
7128 for (j = 0; j < ncols; j++)
7129 {
7130 SAFE_BYTE_GET (val, prow + j * 4, 4, limit);
7131 if (do_display)
7132 printf (" %8d", val);
7133 else
7134 {
7135 SAFE_BYTE_GET (dw_sect, ppool + j * 4, 4, limit);
7136 if (dw_sect >= DW_SECT_MAX)
7137 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect);
7138 else
7139 this_set [row - 1].section_sizes [dw_sect] = val;
7140 }
7141 }
7142
7143 if (do_display)
7144 printf ("\n");
7145 }
7146
7147 ph += 8;
7148 pi += 4;
7149 }
7150 }
7151 else if (do_display)
7152 printf (_(" Unsupported version (%d)\n"), version);
7153
7154 if (do_display)
7155 printf ("\n");
7156
7157 return 1;
7158 }
7159
7160 /* Load the CU and TU indexes if present. This will build a list of
7161 section sets that we can use to associate a .debug_info.dwo section
7162 with its associated .debug_abbrev.dwo section in a .dwp file. */
7163
7164 static void
7165 load_cu_tu_indexes (void *file)
7166 {
7167 /* If we have already loaded (or tried to load) the CU and TU indexes
7168 then do not bother to repeat the task. */
7169 if (cu_tu_indexes_read)
7170 return;
7171
7172 if (load_debug_section (dwp_cu_index, file))
7173 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
7174
7175 if (load_debug_section (dwp_tu_index, file))
7176 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
7177
7178 cu_tu_indexes_read = 1;
7179 }
7180
7181 /* Find the set of sections that includes section SHNDX. */
7182
7183 unsigned int *
7184 find_cu_tu_set (void *file, unsigned int shndx)
7185 {
7186 unsigned int i;
7187
7188 load_cu_tu_indexes (file);
7189
7190 /* Find SHNDX in the shndx pool. */
7191 for (i = 0; i < shndx_pool_used; i++)
7192 if (shndx_pool [i] == shndx)
7193 break;
7194
7195 if (i >= shndx_pool_used)
7196 return NULL;
7197
7198 /* Now backup to find the first entry in the set. */
7199 while (i > 0 && shndx_pool [i - 1] != 0)
7200 i--;
7201
7202 return shndx_pool + i;
7203 }
7204
7205 /* Display a .debug_cu_index or .debug_tu_index section. */
7206
7207 static int
7208 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
7209 {
7210 return process_cu_tu_index (section, 1);
7211 }
7212
7213 static int
7214 display_debug_not_supported (struct dwarf_section *section,
7215 void *file ATTRIBUTE_UNUSED)
7216 {
7217 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7218 section->name);
7219
7220 return 1;
7221 }
7222
7223 /* Like malloc, but takes two parameters like calloc.
7224 Verifies that the first parameter is not too large.
7225 Note: does *not* initialise the allocated memory to zero. */
7226 void *
7227 cmalloc (size_t nmemb, size_t size)
7228 {
7229 /* Check for overflow. */
7230 if (nmemb >= ~(size_t) 0 / size)
7231 return NULL;
7232
7233 return xmalloc (nmemb * size);
7234 }
7235
7236 /* Like xmalloc, but takes two parameters like calloc.
7237 Verifies that the first parameter is not too large.
7238 Note: does *not* initialise the allocated memory to zero. */
7239 void *
7240 xcmalloc (size_t nmemb, size_t size)
7241 {
7242 /* Check for overflow. */
7243 if (nmemb >= ~(size_t) 0 / size)
7244 {
7245 fprintf (stderr,
7246 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
7247 (long) nmemb);
7248 xexit (1);
7249 }
7250
7251 return xmalloc (nmemb * size);
7252 }
7253
7254 /* Like xrealloc, but takes three parameters.
7255 Verifies that the second parameter is not too large.
7256 Note: does *not* initialise any new memory to zero. */
7257 void *
7258 xcrealloc (void *ptr, size_t nmemb, size_t size)
7259 {
7260 /* Check for overflow. */
7261 if (nmemb >= ~(size_t) 0 / size)
7262 {
7263 fprintf (stderr,
7264 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
7265 (long) nmemb);
7266 xexit (1);
7267 }
7268
7269 return xrealloc (ptr, nmemb * size);
7270 }
7271
7272 /* Like xcalloc, but verifies that the first parameter is not too large. */
7273 void *
7274 xcalloc2 (size_t nmemb, size_t size)
7275 {
7276 /* Check for overflow. */
7277 if (nmemb >= ~(size_t) 0 / size)
7278 {
7279 fprintf (stderr,
7280 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
7281 (long) nmemb);
7282 xexit (1);
7283 }
7284
7285 return xcalloc (nmemb, size);
7286 }
7287
7288 void
7289 free_debug_memory (void)
7290 {
7291 unsigned int i;
7292
7293 free_abbrevs ();
7294
7295 for (i = 0; i < max; i++)
7296 free_debug_section ((enum dwarf_section_display_enum) i);
7297
7298 if (debug_information != NULL)
7299 {
7300 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
7301 {
7302 for (i = 0; i < num_debug_info_entries; i++)
7303 {
7304 if (!debug_information [i].max_loc_offsets)
7305 {
7306 free (debug_information [i].loc_offsets);
7307 free (debug_information [i].have_frame_base);
7308 }
7309 if (!debug_information [i].max_range_lists)
7310 free (debug_information [i].range_lists);
7311 }
7312 }
7313 free (debug_information);
7314 debug_information = NULL;
7315 alloc_num_debug_info_entries = num_debug_info_entries = 0;
7316 }
7317 }
7318
7319 void
7320 dwarf_select_sections_by_names (const char *names)
7321 {
7322 typedef struct
7323 {
7324 const char * option;
7325 int * variable;
7326 int val;
7327 }
7328 debug_dump_long_opts;
7329
7330 static const debug_dump_long_opts opts_table [] =
7331 {
7332 /* Please keep this table alpha- sorted. */
7333 { "Ranges", & do_debug_ranges, 1 },
7334 { "abbrev", & do_debug_abbrevs, 1 },
7335 { "addr", & do_debug_addr, 1 },
7336 { "aranges", & do_debug_aranges, 1 },
7337 { "cu_index", & do_debug_cu_index, 1 },
7338 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
7339 { "frames", & do_debug_frames, 1 },
7340 { "frames-interp", & do_debug_frames_interp, 1 },
7341 /* The special .gdb_index section. */
7342 { "gdb_index", & do_gdb_index, 1 },
7343 { "info", & do_debug_info, 1 },
7344 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
7345 { "loc", & do_debug_loc, 1 },
7346 { "macro", & do_debug_macinfo, 1 },
7347 { "pubnames", & do_debug_pubnames, 1 },
7348 { "pubtypes", & do_debug_pubtypes, 1 },
7349 /* This entry is for compatability
7350 with earlier versions of readelf. */
7351 { "ranges", & do_debug_aranges, 1 },
7352 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
7353 { "str", & do_debug_str, 1 },
7354 /* These trace_* sections are used by Itanium VMS. */
7355 { "trace_abbrev", & do_trace_abbrevs, 1 },
7356 { "trace_aranges", & do_trace_aranges, 1 },
7357 { "trace_info", & do_trace_info, 1 },
7358 { NULL, NULL, 0 }
7359 };
7360
7361 const char *p;
7362
7363 p = names;
7364 while (*p)
7365 {
7366 const debug_dump_long_opts * entry;
7367
7368 for (entry = opts_table; entry->option; entry++)
7369 {
7370 size_t len = strlen (entry->option);
7371
7372 if (strncmp (p, entry->option, len) == 0
7373 && (p[len] == ',' || p[len] == '\0'))
7374 {
7375 * entry->variable |= entry->val;
7376
7377 /* The --debug-dump=frames-interp option also
7378 enables the --debug-dump=frames option. */
7379 if (do_debug_frames_interp)
7380 do_debug_frames = 1;
7381
7382 p += len;
7383 break;
7384 }
7385 }
7386
7387 if (entry->option == NULL)
7388 {
7389 warn (_("Unrecognized debug option '%s'\n"), p);
7390 p = strchr (p, ',');
7391 if (p == NULL)
7392 break;
7393 }
7394
7395 if (*p == ',')
7396 p++;
7397 }
7398 }
7399
7400 void
7401 dwarf_select_sections_by_letters (const char *letters)
7402 {
7403 unsigned int lindex = 0;
7404
7405 while (letters[lindex])
7406 switch (letters[lindex++])
7407 {
7408 case 'i':
7409 do_debug_info = 1;
7410 break;
7411
7412 case 'a':
7413 do_debug_abbrevs = 1;
7414 break;
7415
7416 case 'l':
7417 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
7418 break;
7419
7420 case 'L':
7421 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
7422 break;
7423
7424 case 'p':
7425 do_debug_pubnames = 1;
7426 break;
7427
7428 case 't':
7429 do_debug_pubtypes = 1;
7430 break;
7431
7432 case 'r':
7433 do_debug_aranges = 1;
7434 break;
7435
7436 case 'R':
7437 do_debug_ranges = 1;
7438 break;
7439
7440 case 'F':
7441 do_debug_frames_interp = 1;
7442 case 'f':
7443 do_debug_frames = 1;
7444 break;
7445
7446 case 'm':
7447 do_debug_macinfo = 1;
7448 break;
7449
7450 case 's':
7451 do_debug_str = 1;
7452 break;
7453
7454 case 'o':
7455 do_debug_loc = 1;
7456 break;
7457
7458 default:
7459 warn (_("Unrecognized debug option '%s'\n"), letters);
7460 break;
7461 }
7462 }
7463
7464 void
7465 dwarf_select_sections_all (void)
7466 {
7467 do_debug_info = 1;
7468 do_debug_abbrevs = 1;
7469 do_debug_lines = FLAG_DEBUG_LINES_RAW;
7470 do_debug_pubnames = 1;
7471 do_debug_pubtypes = 1;
7472 do_debug_aranges = 1;
7473 do_debug_ranges = 1;
7474 do_debug_frames = 1;
7475 do_debug_macinfo = 1;
7476 do_debug_str = 1;
7477 do_debug_loc = 1;
7478 do_gdb_index = 1;
7479 do_trace_info = 1;
7480 do_trace_abbrevs = 1;
7481 do_trace_aranges = 1;
7482 do_debug_addr = 1;
7483 do_debug_cu_index = 1;
7484 }
7485
7486 struct dwarf_section_display debug_displays[] =
7487 {
7488 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0, NULL },
7489 display_debug_abbrev, &do_debug_abbrevs, 0 },
7490 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0, NULL },
7491 display_debug_aranges, &do_debug_aranges, 1 },
7492 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0, NULL },
7493 display_debug_frames, &do_debug_frames, 1 },
7494 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev, NULL },
7495 display_debug_info, &do_debug_info, 1 },
7496 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0, NULL },
7497 display_debug_lines, &do_debug_lines, 1 },
7498 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0, NULL },
7499 display_debug_pubnames, &do_debug_pubnames, 0 },
7500 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0, NULL },
7501 display_debug_gnu_pubnames, &do_debug_pubnames, 0 },
7502 { { ".eh_frame", "", NULL, NULL, 0, 0, 0, NULL },
7503 display_debug_frames, &do_debug_frames, 1 },
7504 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0, NULL },
7505 display_debug_macinfo, &do_debug_macinfo, 0 },
7506 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0, NULL },
7507 display_debug_macro, &do_debug_macinfo, 1 },
7508 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0, NULL },
7509 display_debug_str, &do_debug_str, 0 },
7510 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0, NULL },
7511 display_debug_loc, &do_debug_loc, 1 },
7512 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0, NULL },
7513 display_debug_pubnames, &do_debug_pubtypes, 0 },
7514 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0, NULL },
7515 display_debug_gnu_pubnames, &do_debug_pubtypes, 0 },
7516 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0, NULL },
7517 display_debug_ranges, &do_debug_ranges, 1 },
7518 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0, NULL },
7519 display_debug_not_supported, NULL, 0 },
7520 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0, NULL },
7521 display_debug_not_supported, NULL, 0 },
7522 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev, NULL },
7523 display_debug_types, &do_debug_info, 1 },
7524 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0, NULL },
7525 display_debug_not_supported, NULL, 0 },
7526 { { ".gdb_index", "", NULL, NULL, 0, 0, 0, NULL },
7527 display_gdb_index, &do_gdb_index, 0 },
7528 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev, NULL },
7529 display_trace_info, &do_trace_info, 1 },
7530 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0, NULL },
7531 display_debug_abbrev, &do_trace_abbrevs, 0 },
7532 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0, NULL },
7533 display_debug_aranges, &do_trace_aranges, 0 },
7534 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL },
7535 display_debug_info, &do_debug_info, 1 },
7536 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0, NULL },
7537 display_debug_abbrev, &do_debug_abbrevs, 0 },
7538 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo, NULL },
7539 display_debug_types, &do_debug_info, 1 },
7540 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0, NULL },
7541 display_debug_lines, &do_debug_lines, 1 },
7542 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0, NULL },
7543 display_debug_loc, &do_debug_loc, 1 },
7544 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0, NULL },
7545 display_debug_macro, &do_debug_macinfo, 1 },
7546 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0, NULL },
7547 display_debug_macinfo, &do_debug_macinfo, 0 },
7548 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0, NULL },
7549 display_debug_str, &do_debug_str, 1 },
7550 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0, NULL },
7551 display_debug_str_offsets, NULL, 0 },
7552 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0, NULL },
7553 display_debug_str_offsets, NULL, 0 },
7554 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0, NULL },
7555 display_debug_addr, &do_debug_addr, 1 },
7556 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0, NULL },
7557 display_cu_index, &do_debug_cu_index, 0 },
7558 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0, NULL },
7559 display_cu_index, &do_debug_cu_index, 0 },
7560 };
This page took 0.175777 seconds and 5 git commands to generate.