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