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