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