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