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