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