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