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