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