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