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