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