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