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