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