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