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