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