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