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