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