Rename 'descr' field in regset structure to 'regmap'.
[deliverable/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 |= -1L << 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 && 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 if (do_loc)
1627 data = block_start + uvalue;
1628 else
1629 data = display_block (block_start, uvalue, end);
1630 break;
1631
1632 case DW_FORM_block1:
1633 SAFE_BYTE_GET (uvalue, data, 1, end);
1634 block_start = data + 1;
1635 if (do_loc)
1636 data = block_start + uvalue;
1637 else
1638 data = display_block (block_start, uvalue, end);
1639 break;
1640
1641 case DW_FORM_block2:
1642 SAFE_BYTE_GET (uvalue, data, 2, end);
1643 block_start = data + 2;
1644 if (do_loc)
1645 data = block_start + uvalue;
1646 else
1647 data = display_block (block_start, uvalue, end);
1648 break;
1649
1650 case DW_FORM_block4:
1651 SAFE_BYTE_GET (uvalue, data, 4, end);
1652 block_start = data + 4;
1653 if (do_loc)
1654 data = block_start + uvalue;
1655 else
1656 data = display_block (block_start, uvalue, end);
1657 break;
1658
1659 case DW_FORM_strp:
1660 if (!do_loc)
1661 printf (_(" (indirect string, offset: 0x%s): %s"),
1662 dwarf_vmatoa ("x", uvalue),
1663 fetch_indirect_string (uvalue));
1664 break;
1665
1666 case DW_FORM_GNU_str_index:
1667 if (!do_loc)
1668 {
1669 const char *suffix = strrchr (section->name, '.');
1670 int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0;
1671
1672 printf (_(" (indexed string: 0x%s): %s"),
1673 dwarf_vmatoa ("x", uvalue),
1674 fetch_indexed_string (uvalue, this_set, offset_size, dwo));
1675 }
1676 break;
1677
1678 case DW_FORM_GNU_strp_alt:
1679 if (!do_loc)
1680 printf (_(" (alt indirect string, offset: 0x%s)"),
1681 dwarf_vmatoa ("x", uvalue));
1682 break;
1683
1684 case DW_FORM_indirect:
1685 /* Handled above. */
1686 break;
1687
1688 case DW_FORM_ref_sig8:
1689 if (!do_loc)
1690 {
1691 dwarf_vma high_bits;
1692 char buf[64];
1693
1694 SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end);
1695 printf (" signature: 0x%s",
1696 dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
1697 }
1698 data += 8;
1699 break;
1700
1701 case DW_FORM_GNU_addr_index:
1702 if (!do_loc)
1703 printf (_(" (addr_index: 0x%s): %s"),
1704 dwarf_vmatoa ("x", uvalue),
1705 fetch_indexed_value (uvalue * pointer_size, pointer_size));
1706 break;
1707
1708 default:
1709 warn (_("Unrecognized form: %lu\n"), form);
1710 break;
1711 }
1712
1713 if ((do_loc || do_debug_loc || do_debug_ranges)
1714 && num_debug_info_entries == 0
1715 && debug_info_p != NULL)
1716 {
1717 switch (attribute)
1718 {
1719 case DW_AT_frame_base:
1720 have_frame_base = 1;
1721 case DW_AT_location:
1722 case DW_AT_string_length:
1723 case DW_AT_return_addr:
1724 case DW_AT_data_member_location:
1725 case DW_AT_vtable_elem_location:
1726 case DW_AT_segment:
1727 case DW_AT_static_link:
1728 case DW_AT_use_location:
1729 case DW_AT_GNU_call_site_value:
1730 case DW_AT_GNU_call_site_data_value:
1731 case DW_AT_GNU_call_site_target:
1732 case DW_AT_GNU_call_site_target_clobbered:
1733 if ((dwarf_version < 4
1734 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1735 || form == DW_FORM_sec_offset)
1736 {
1737 /* Process location list. */
1738 unsigned int lmax = debug_info_p->max_loc_offsets;
1739 unsigned int num = debug_info_p->num_loc_offsets;
1740
1741 if (lmax == 0 || num >= lmax)
1742 {
1743 lmax += 1024;
1744 debug_info_p->loc_offsets = (dwarf_vma *)
1745 xcrealloc (debug_info_p->loc_offsets,
1746 lmax, sizeof (*debug_info_p->loc_offsets));
1747 debug_info_p->have_frame_base = (int *)
1748 xcrealloc (debug_info_p->have_frame_base,
1749 lmax, sizeof (*debug_info_p->have_frame_base));
1750 debug_info_p->max_loc_offsets = lmax;
1751 }
1752 if (this_set != NULL)
1753 uvalue += this_set->section_offsets [DW_SECT_LOC];
1754 debug_info_p->loc_offsets [num] = uvalue;
1755 debug_info_p->have_frame_base [num] = have_frame_base;
1756 debug_info_p->num_loc_offsets++;
1757 }
1758 break;
1759
1760 case DW_AT_low_pc:
1761 if (need_base_address)
1762 debug_info_p->base_address = uvalue;
1763 break;
1764
1765 case DW_AT_GNU_addr_base:
1766 debug_info_p->addr_base = uvalue;
1767 break;
1768
1769 case DW_AT_GNU_ranges_base:
1770 debug_info_p->ranges_base = uvalue;
1771 break;
1772
1773 case DW_AT_ranges:
1774 if ((dwarf_version < 4
1775 && (form == DW_FORM_data4 || form == DW_FORM_data8))
1776 || form == DW_FORM_sec_offset)
1777 {
1778 /* Process range list. */
1779 unsigned int lmax = debug_info_p->max_range_lists;
1780 unsigned int num = debug_info_p->num_range_lists;
1781
1782 if (lmax == 0 || num >= lmax)
1783 {
1784 lmax += 1024;
1785 debug_info_p->range_lists = (dwarf_vma *)
1786 xcrealloc (debug_info_p->range_lists,
1787 lmax, sizeof (*debug_info_p->range_lists));
1788 debug_info_p->max_range_lists = lmax;
1789 }
1790 debug_info_p->range_lists [num] = uvalue;
1791 debug_info_p->num_range_lists++;
1792 }
1793 break;
1794
1795 default:
1796 break;
1797 }
1798 }
1799
1800 if (do_loc || attribute == 0)
1801 return data;
1802
1803 /* For some attributes we can display further information. */
1804 switch (attribute)
1805 {
1806 case DW_AT_inline:
1807 printf ("\t");
1808 switch (uvalue)
1809 {
1810 case DW_INL_not_inlined:
1811 printf (_("(not inlined)"));
1812 break;
1813 case DW_INL_inlined:
1814 printf (_("(inlined)"));
1815 break;
1816 case DW_INL_declared_not_inlined:
1817 printf (_("(declared as inline but ignored)"));
1818 break;
1819 case DW_INL_declared_inlined:
1820 printf (_("(declared as inline and inlined)"));
1821 break;
1822 default:
1823 printf (_(" (Unknown inline attribute value: %s)"),
1824 dwarf_vmatoa ("x", uvalue));
1825 break;
1826 }
1827 break;
1828
1829 case DW_AT_language:
1830 printf ("\t");
1831 switch (uvalue)
1832 {
1833 /* Ordered by the numeric value of these constants. */
1834 case DW_LANG_C89: printf ("(ANSI C)"); break;
1835 case DW_LANG_C: printf ("(non-ANSI C)"); break;
1836 case DW_LANG_Ada83: printf ("(Ada)"); break;
1837 case DW_LANG_C_plus_plus: printf ("(C++)"); break;
1838 case DW_LANG_Cobol74: printf ("(Cobol 74)"); break;
1839 case DW_LANG_Cobol85: printf ("(Cobol 85)"); break;
1840 case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break;
1841 case DW_LANG_Fortran90: printf ("(Fortran 90)"); break;
1842 case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break;
1843 case DW_LANG_Modula2: printf ("(Modula 2)"); break;
1844 /* DWARF 2.1 values. */
1845 case DW_LANG_Java: printf ("(Java)"); break;
1846 case DW_LANG_C99: printf ("(ANSI C99)"); break;
1847 case DW_LANG_Ada95: printf ("(ADA 95)"); break;
1848 case DW_LANG_Fortran95: printf ("(Fortran 95)"); break;
1849 /* DWARF 3 values. */
1850 case DW_LANG_PLI: printf ("(PLI)"); break;
1851 case DW_LANG_ObjC: printf ("(Objective C)"); break;
1852 case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break;
1853 case DW_LANG_UPC: printf ("(Unified Parallel C)"); break;
1854 case DW_LANG_D: printf ("(D)"); break;
1855 /* DWARF 4 values. */
1856 case DW_LANG_Python: printf ("(Python)"); break;
1857 /* DWARF 5 values. */
1858 case DW_LANG_Go: printf ("(Go)"); break;
1859 /* MIPS extension. */
1860 case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break;
1861 /* UPC extension. */
1862 case DW_LANG_Upc: printf ("(Unified Parallel C)"); break;
1863 default:
1864 if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user)
1865 printf (_("(implementation defined: %s)"),
1866 dwarf_vmatoa ("x", uvalue));
1867 else
1868 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue));
1869 break;
1870 }
1871 break;
1872
1873 case DW_AT_encoding:
1874 printf ("\t");
1875 switch (uvalue)
1876 {
1877 case DW_ATE_void: printf ("(void)"); break;
1878 case DW_ATE_address: printf ("(machine address)"); break;
1879 case DW_ATE_boolean: printf ("(boolean)"); break;
1880 case DW_ATE_complex_float: printf ("(complex float)"); break;
1881 case DW_ATE_float: printf ("(float)"); break;
1882 case DW_ATE_signed: printf ("(signed)"); break;
1883 case DW_ATE_signed_char: printf ("(signed char)"); break;
1884 case DW_ATE_unsigned: printf ("(unsigned)"); break;
1885 case DW_ATE_unsigned_char: printf ("(unsigned char)"); break;
1886 /* DWARF 2.1 values: */
1887 case DW_ATE_imaginary_float: printf ("(imaginary float)"); break;
1888 case DW_ATE_decimal_float: printf ("(decimal float)"); break;
1889 /* DWARF 3 values: */
1890 case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break;
1891 case DW_ATE_numeric_string: printf ("(numeric_string)"); break;
1892 case DW_ATE_edited: printf ("(edited)"); break;
1893 case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break;
1894 case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break;
1895 /* HP extensions: */
1896 case DW_ATE_HP_float80: printf ("(HP_float80)"); break;
1897 case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break;
1898 case DW_ATE_HP_float128: printf ("(HP_float128)"); break;
1899 case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break;
1900 case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break;
1901 case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break;
1902 case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break;
1903
1904 default:
1905 if (uvalue >= DW_ATE_lo_user
1906 && uvalue <= DW_ATE_hi_user)
1907 printf (_("(user defined type)"));
1908 else
1909 printf (_("(unknown type)"));
1910 break;
1911 }
1912 break;
1913
1914 case DW_AT_accessibility:
1915 printf ("\t");
1916 switch (uvalue)
1917 {
1918 case DW_ACCESS_public: printf ("(public)"); break;
1919 case DW_ACCESS_protected: printf ("(protected)"); break;
1920 case DW_ACCESS_private: printf ("(private)"); break;
1921 default:
1922 printf (_("(unknown accessibility)"));
1923 break;
1924 }
1925 break;
1926
1927 case DW_AT_visibility:
1928 printf ("\t");
1929 switch (uvalue)
1930 {
1931 case DW_VIS_local: printf ("(local)"); break;
1932 case DW_VIS_exported: printf ("(exported)"); break;
1933 case DW_VIS_qualified: printf ("(qualified)"); break;
1934 default: printf (_("(unknown visibility)")); break;
1935 }
1936 break;
1937
1938 case DW_AT_virtuality:
1939 printf ("\t");
1940 switch (uvalue)
1941 {
1942 case DW_VIRTUALITY_none: printf ("(none)"); break;
1943 case DW_VIRTUALITY_virtual: printf ("(virtual)"); break;
1944 case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break;
1945 default: printf (_("(unknown virtuality)")); break;
1946 }
1947 break;
1948
1949 case DW_AT_identifier_case:
1950 printf ("\t");
1951 switch (uvalue)
1952 {
1953 case DW_ID_case_sensitive: printf ("(case_sensitive)"); break;
1954 case DW_ID_up_case: printf ("(up_case)"); break;
1955 case DW_ID_down_case: printf ("(down_case)"); break;
1956 case DW_ID_case_insensitive: printf ("(case_insensitive)"); break;
1957 default: printf (_("(unknown case)")); break;
1958 }
1959 break;
1960
1961 case DW_AT_calling_convention:
1962 printf ("\t");
1963 switch (uvalue)
1964 {
1965 case DW_CC_normal: printf ("(normal)"); break;
1966 case DW_CC_program: printf ("(program)"); break;
1967 case DW_CC_nocall: printf ("(nocall)"); break;
1968 default:
1969 if (uvalue >= DW_CC_lo_user
1970 && uvalue <= DW_CC_hi_user)
1971 printf (_("(user defined)"));
1972 else
1973 printf (_("(unknown convention)"));
1974 }
1975 break;
1976
1977 case DW_AT_ordering:
1978 printf ("\t");
1979 switch (uvalue)
1980 {
1981 case -1: printf (_("(undefined)")); break;
1982 case 0: printf ("(row major)"); break;
1983 case 1: printf ("(column major)"); break;
1984 }
1985 break;
1986
1987 case DW_AT_frame_base:
1988 have_frame_base = 1;
1989 case DW_AT_location:
1990 case DW_AT_string_length:
1991 case DW_AT_return_addr:
1992 case DW_AT_data_member_location:
1993 case DW_AT_vtable_elem_location:
1994 case DW_AT_segment:
1995 case DW_AT_static_link:
1996 case DW_AT_use_location:
1997 case DW_AT_GNU_call_site_value:
1998 case DW_AT_GNU_call_site_data_value:
1999 case DW_AT_GNU_call_site_target:
2000 case DW_AT_GNU_call_site_target_clobbered:
2001 if ((dwarf_version < 4
2002 && (form == DW_FORM_data4 || form == DW_FORM_data8))
2003 || form == DW_FORM_sec_offset)
2004 printf (_(" (location list)"));
2005 /* Fall through. */
2006 case DW_AT_allocated:
2007 case DW_AT_associated:
2008 case DW_AT_data_location:
2009 case DW_AT_stride:
2010 case DW_AT_upper_bound:
2011 case DW_AT_lower_bound:
2012 if (block_start)
2013 {
2014 int need_frame_base;
2015
2016 printf ("\t(");
2017 need_frame_base = decode_location_expression (block_start,
2018 pointer_size,
2019 offset_size,
2020 dwarf_version,
2021 uvalue,
2022 cu_offset, section);
2023 printf (")");
2024 if (need_frame_base && !have_frame_base)
2025 printf (_(" [without DW_AT_frame_base]"));
2026 }
2027 break;
2028
2029 case DW_AT_import:
2030 {
2031 if (form == DW_FORM_ref_sig8
2032 || form == DW_FORM_GNU_ref_alt)
2033 break;
2034
2035 if (form == DW_FORM_ref1
2036 || form == DW_FORM_ref2
2037 || form == DW_FORM_ref4
2038 || form == DW_FORM_ref_udata)
2039 uvalue += cu_offset;
2040
2041 if (uvalue >= section->size)
2042 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset %lx is too big.\n"),
2043 dwarf_vmatoa ("x", uvalue),
2044 (unsigned long) (orig_data - section->start));
2045 else
2046 {
2047 unsigned long abbrev_number;
2048 abbrev_entry * entry;
2049
2050 abbrev_number = read_uleb128 (section->start + uvalue, NULL, end);
2051
2052 printf (_("\t[Abbrev Number: %ld"), abbrev_number);
2053 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2054 use different abbrev table, and we don't track .debug_info chunks
2055 yet. */
2056 if (form != DW_FORM_ref_addr)
2057 {
2058 for (entry = first_abbrev; entry != NULL; entry = entry->next)
2059 if (entry->entry == abbrev_number)
2060 break;
2061 if (entry != NULL)
2062 printf (" (%s)", get_TAG_name (entry->tag));
2063 }
2064 printf ("]");
2065 }
2066 }
2067 break;
2068
2069 default:
2070 break;
2071 }
2072
2073 return data;
2074 }
2075
2076 static const char *
2077 get_AT_name (unsigned long attribute)
2078 {
2079 const char *name;
2080
2081 if (attribute == 0)
2082 return "DW_AT value: 0";
2083
2084 /* One value is shared by the MIPS and HP extensions: */
2085 if (attribute == DW_AT_MIPS_fde)
2086 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2087
2088 name = get_DW_AT_name (attribute);
2089
2090 if (name == NULL)
2091 {
2092 static char buffer[100];
2093
2094 snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"),
2095 attribute);
2096 return buffer;
2097 }
2098
2099 return name;
2100 }
2101
2102 static unsigned char *
2103 read_and_display_attr (unsigned long attribute,
2104 unsigned long form,
2105 unsigned char * data,
2106 unsigned char * end,
2107 dwarf_vma cu_offset,
2108 dwarf_vma pointer_size,
2109 dwarf_vma offset_size,
2110 int dwarf_version,
2111 debug_info * debug_info_p,
2112 int do_loc,
2113 struct dwarf_section * section,
2114 struct cu_tu_set * this_set)
2115 {
2116 if (!do_loc)
2117 printf (" %-18s:", get_AT_name (attribute));
2118 data = read_and_display_attr_value (attribute, form, data, end,
2119 cu_offset, pointer_size, offset_size,
2120 dwarf_version, debug_info_p,
2121 do_loc, section, this_set);
2122 if (!do_loc)
2123 printf ("\n");
2124 return data;
2125 }
2126
2127 /* Process the contents of a .debug_info section. If do_loc is non-zero
2128 then we are scanning for location lists and we do not want to display
2129 anything to the user. If do_types is non-zero, we are processing
2130 a .debug_types section instead of a .debug_info section. */
2131
2132 static int
2133 process_debug_info (struct dwarf_section *section,
2134 void *file,
2135 enum dwarf_section_display_enum abbrev_sec,
2136 int do_loc,
2137 int do_types)
2138 {
2139 unsigned char *start = section->start;
2140 unsigned char *end = start + section->size;
2141 unsigned char *section_begin;
2142 unsigned int unit;
2143 unsigned int num_units = 0;
2144
2145 if ((do_loc || do_debug_loc || do_debug_ranges)
2146 && num_debug_info_entries == 0
2147 && ! do_types)
2148 {
2149 dwarf_vma length;
2150
2151 /* First scan the section to get the number of comp units. */
2152 for (section_begin = start, num_units = 0; section_begin < end;
2153 num_units ++)
2154 {
2155 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2156 will be the length. For a 64-bit DWARF section, it'll be
2157 the escape code 0xffffffff followed by an 8 byte length. */
2158 SAFE_BYTE_GET (length, section_begin, 4, end);
2159
2160 if (length == 0xffffffff)
2161 {
2162 SAFE_BYTE_GET (length, section_begin + 4, 8, end);
2163 section_begin += length + 12;
2164 }
2165 else if (length >= 0xfffffff0 && length < 0xffffffff)
2166 {
2167 warn (_("Reserved length value (0x%s) found in section %s\n"),
2168 dwarf_vmatoa ("x", length), section->name);
2169 return 0;
2170 }
2171 else
2172 section_begin += length + 4;
2173
2174 /* Negative values are illegal, they may even cause infinite
2175 looping. This can happen if we can't accurately apply
2176 relocations to an object file. */
2177 if ((signed long) length <= 0)
2178 {
2179 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2180 dwarf_vmatoa ("x", length), section->name);
2181 return 0;
2182 }
2183 }
2184
2185 if (num_units == 0)
2186 {
2187 error (_("No comp units in %s section ?"), section->name);
2188 return 0;
2189 }
2190
2191 /* Then allocate an array to hold the information. */
2192 debug_information = (debug_info *) cmalloc (num_units,
2193 sizeof (* debug_information));
2194 if (debug_information == NULL)
2195 {
2196 error (_("Not enough memory for a debug info array of %u entries"),
2197 num_units);
2198 return 0;
2199 }
2200 }
2201
2202 if (!do_loc)
2203 {
2204 if (dwarf_start_die == 0)
2205 printf (_("Contents of the %s section:\n\n"), section->name);
2206
2207 load_debug_section (str, file);
2208 load_debug_section (str_dwo, file);
2209 load_debug_section (str_index, file);
2210 load_debug_section (str_index_dwo, file);
2211 load_debug_section (debug_addr, file);
2212 }
2213
2214 load_debug_section (abbrev_sec, file);
2215 if (debug_displays [abbrev_sec].section.start == NULL)
2216 {
2217 warn (_("Unable to locate %s section!\n"),
2218 debug_displays [abbrev_sec].section.name);
2219 return 0;
2220 }
2221
2222 for (section_begin = start, unit = 0; start < end; unit++)
2223 {
2224 DWARF2_Internal_CompUnit compunit;
2225 unsigned char *hdrptr;
2226 unsigned char *tags;
2227 int level, last_level, saved_level;
2228 dwarf_vma cu_offset;
2229 unsigned int offset_size;
2230 int initial_length_size;
2231 dwarf_vma signature_high = 0;
2232 dwarf_vma signature_low = 0;
2233 dwarf_vma type_offset = 0;
2234 struct cu_tu_set *this_set;
2235 dwarf_vma abbrev_base;
2236 size_t abbrev_size;
2237
2238 hdrptr = start;
2239
2240 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end);
2241
2242 if (compunit.cu_length == 0xffffffff)
2243 {
2244 SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end);
2245 offset_size = 8;
2246 initial_length_size = 12;
2247 }
2248 else
2249 {
2250 offset_size = 4;
2251 initial_length_size = 4;
2252 }
2253
2254 SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end);
2255
2256 cu_offset = start - section_begin;
2257
2258 this_set = find_cu_tu_set_v2 (cu_offset, do_types);
2259
2260 SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end);
2261
2262 if (this_set == NULL)
2263 {
2264 abbrev_base = 0;
2265 abbrev_size = debug_displays [abbrev_sec].section.size;
2266 }
2267 else
2268 {
2269 abbrev_base = this_set->section_offsets [DW_SECT_ABBREV];
2270 abbrev_size = this_set->section_sizes [DW_SECT_ABBREV];
2271 }
2272
2273 SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end);
2274
2275 if (do_types)
2276 {
2277 SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end);
2278 hdrptr += 8;
2279 SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end);
2280 }
2281
2282 if ((do_loc || do_debug_loc || do_debug_ranges)
2283 && num_debug_info_entries == 0
2284 && ! do_types)
2285 {
2286 debug_information [unit].cu_offset = cu_offset;
2287 debug_information [unit].pointer_size
2288 = compunit.cu_pointer_size;
2289 debug_information [unit].offset_size = offset_size;
2290 debug_information [unit].dwarf_version = compunit.cu_version;
2291 debug_information [unit].base_address = 0;
2292 debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE;
2293 debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE;
2294 debug_information [unit].loc_offsets = NULL;
2295 debug_information [unit].have_frame_base = NULL;
2296 debug_information [unit].max_loc_offsets = 0;
2297 debug_information [unit].num_loc_offsets = 0;
2298 debug_information [unit].range_lists = NULL;
2299 debug_information [unit].max_range_lists= 0;
2300 debug_information [unit].num_range_lists = 0;
2301 }
2302
2303 if (!do_loc && dwarf_start_die == 0)
2304 {
2305 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2306 dwarf_vmatoa ("x", cu_offset));
2307 printf (_(" Length: 0x%s (%s)\n"),
2308 dwarf_vmatoa ("x", compunit.cu_length),
2309 offset_size == 8 ? "64-bit" : "32-bit");
2310 printf (_(" Version: %d\n"), compunit.cu_version);
2311 printf (_(" Abbrev Offset: 0x%s\n"),
2312 dwarf_vmatoa ("x", compunit.cu_abbrev_offset));
2313 printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size);
2314 if (do_types)
2315 {
2316 char buf[64];
2317
2318 printf (_(" Signature: 0x%s\n"),
2319 dwarf_vmatoa64 (signature_high, signature_low,
2320 buf, sizeof (buf)));
2321 printf (_(" Type Offset: 0x%s\n"),
2322 dwarf_vmatoa ("x", type_offset));
2323 }
2324 if (this_set != NULL)
2325 {
2326 dwarf_vma *offsets = this_set->section_offsets;
2327 size_t *sizes = this_set->section_sizes;
2328
2329 printf (_(" Section contributions:\n"));
2330 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2331 dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]),
2332 dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV]));
2333 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2334 dwarf_vmatoa ("x", offsets [DW_SECT_LINE]),
2335 dwarf_vmatoa ("x", sizes [DW_SECT_LINE]));
2336 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2337 dwarf_vmatoa ("x", offsets [DW_SECT_LOC]),
2338 dwarf_vmatoa ("x", sizes [DW_SECT_LOC]));
2339 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2340 dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]),
2341 dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS]));
2342 }
2343 }
2344
2345 if (cu_offset + compunit.cu_length + initial_length_size
2346 > section->size)
2347 {
2348 warn (_("Debug info is corrupted, length of CU at %s"
2349 " extends beyond end of section (length = %s)\n"),
2350 dwarf_vmatoa ("x", cu_offset),
2351 dwarf_vmatoa ("x", compunit.cu_length));
2352 break;
2353 }
2354 tags = hdrptr;
2355 start += compunit.cu_length + initial_length_size;
2356
2357 if (compunit.cu_version != 2
2358 && compunit.cu_version != 3
2359 && compunit.cu_version != 4)
2360 {
2361 warn (_("CU at offset %s contains corrupt or "
2362 "unsupported version number: %d.\n"),
2363 dwarf_vmatoa ("x", cu_offset), compunit.cu_version);
2364 continue;
2365 }
2366
2367 free_abbrevs ();
2368
2369 /* Process the abbrevs used by this compilation unit. */
2370 if (compunit.cu_abbrev_offset >= abbrev_size)
2371 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2372 (unsigned long) compunit.cu_abbrev_offset,
2373 (unsigned long) abbrev_size);
2374 else
2375 process_abbrev_section
2376 (((unsigned char *) debug_displays [abbrev_sec].section.start
2377 + abbrev_base + compunit.cu_abbrev_offset),
2378 ((unsigned char *) debug_displays [abbrev_sec].section.start
2379 + abbrev_base + abbrev_size));
2380
2381 level = 0;
2382 last_level = level;
2383 saved_level = -1;
2384 while (tags < start)
2385 {
2386 unsigned int bytes_read;
2387 unsigned long abbrev_number;
2388 unsigned long die_offset;
2389 abbrev_entry *entry;
2390 abbrev_attr *attr;
2391 int do_printing = 1;
2392
2393 die_offset = tags - section_begin;
2394
2395 abbrev_number = read_uleb128 (tags, & bytes_read, start);
2396 tags += bytes_read;
2397
2398 /* A null DIE marks the end of a list of siblings or it may also be
2399 a section padding. */
2400 if (abbrev_number == 0)
2401 {
2402 /* Check if it can be a section padding for the last CU. */
2403 if (level == 0 && start == end)
2404 {
2405 unsigned char *chk;
2406
2407 for (chk = tags; chk < start; chk++)
2408 if (*chk != 0)
2409 break;
2410 if (chk == start)
2411 break;
2412 }
2413
2414 if (!do_loc && die_offset >= dwarf_start_die
2415 && (dwarf_cutoff_level == -1
2416 || level < dwarf_cutoff_level))
2417 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2418 level, die_offset);
2419
2420 --level;
2421 if (level < 0)
2422 {
2423 static unsigned num_bogus_warns = 0;
2424
2425 if (num_bogus_warns < 3)
2426 {
2427 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2428 die_offset, section->name);
2429 num_bogus_warns ++;
2430 if (num_bogus_warns == 3)
2431 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2432 }
2433 }
2434 if (dwarf_start_die != 0 && level < saved_level)
2435 return 1;
2436 continue;
2437 }
2438
2439 if (!do_loc)
2440 {
2441 if (dwarf_start_die != 0 && die_offset < dwarf_start_die)
2442 do_printing = 0;
2443 else
2444 {
2445 if (dwarf_start_die != 0 && die_offset == dwarf_start_die)
2446 saved_level = level;
2447 do_printing = (dwarf_cutoff_level == -1
2448 || level < dwarf_cutoff_level);
2449 if (do_printing)
2450 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2451 level, die_offset, abbrev_number);
2452 else if (dwarf_cutoff_level == -1
2453 || last_level < dwarf_cutoff_level)
2454 printf (_(" <%d><%lx>: ...\n"), level, die_offset);
2455 last_level = level;
2456 }
2457 }
2458
2459 /* Scan through the abbreviation list until we reach the
2460 correct entry. */
2461 for (entry = first_abbrev;
2462 entry && entry->entry != abbrev_number;
2463 entry = entry->next)
2464 continue;
2465
2466 if (entry == NULL)
2467 {
2468 if (!do_loc && do_printing)
2469 {
2470 printf ("\n");
2471 fflush (stdout);
2472 }
2473 warn (_("DIE at offset %lx refers to abbreviation number %lu which does not exist\n"),
2474 die_offset, abbrev_number);
2475 return 0;
2476 }
2477
2478 if (!do_loc && do_printing)
2479 printf (" (%s)\n", get_TAG_name (entry->tag));
2480
2481 switch (entry->tag)
2482 {
2483 default:
2484 need_base_address = 0;
2485 break;
2486 case DW_TAG_compile_unit:
2487 need_base_address = 1;
2488 break;
2489 case DW_TAG_entry_point:
2490 case DW_TAG_subprogram:
2491 need_base_address = 0;
2492 /* Assuming that there is no DW_AT_frame_base. */
2493 have_frame_base = 0;
2494 break;
2495 }
2496
2497 for (attr = entry->first_attr;
2498 attr && attr->attribute;
2499 attr = attr->next)
2500 {
2501 debug_info *arg;
2502
2503 if (! do_loc && do_printing)
2504 /* Show the offset from where the tag was extracted. */
2505 printf (" <%lx>", (unsigned long)(tags - section_begin));
2506
2507 arg = debug_information;
2508 if (debug_information)
2509 arg += unit;
2510
2511 tags = read_and_display_attr (attr->attribute,
2512 attr->form,
2513 tags,
2514 end,
2515 cu_offset,
2516 compunit.cu_pointer_size,
2517 offset_size,
2518 compunit.cu_version,
2519 arg,
2520 do_loc || ! do_printing,
2521 section,
2522 this_set);
2523 }
2524
2525 if (entry->children)
2526 ++level;
2527 }
2528 }
2529
2530 /* Set num_debug_info_entries here so that it can be used to check if
2531 we need to process .debug_loc and .debug_ranges sections. */
2532 if ((do_loc || do_debug_loc || do_debug_ranges)
2533 && num_debug_info_entries == 0
2534 && ! do_types)
2535 num_debug_info_entries = num_units;
2536
2537 if (!do_loc)
2538 printf ("\n");
2539
2540 return 1;
2541 }
2542
2543 /* Locate and scan the .debug_info section in the file and record the pointer
2544 sizes and offsets for the compilation units in it. Usually an executable
2545 will have just one pointer size, but this is not guaranteed, and so we try
2546 not to make any assumptions. Returns zero upon failure, or the number of
2547 compilation units upon success. */
2548
2549 static unsigned int
2550 load_debug_info (void * file)
2551 {
2552 /* Reset the last pointer size so that we can issue correct error
2553 messages if we are displaying the contents of more than one section. */
2554 last_pointer_size = 0;
2555 warned_about_missing_comp_units = FALSE;
2556
2557 /* If we have already tried and failed to load the .debug_info
2558 section then do not bother to repeat the task. */
2559 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
2560 return 0;
2561
2562 /* If we already have the information there is nothing else to do. */
2563 if (num_debug_info_entries > 0)
2564 return num_debug_info_entries;
2565
2566 /* If this is a DWARF package file, load the CU and TU indexes. */
2567 load_cu_tu_indexes (file);
2568
2569 if (load_debug_section (info, file)
2570 && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0))
2571 return num_debug_info_entries;
2572 else if (load_debug_section (info_dwo, file)
2573 && process_debug_info (&debug_displays [info_dwo].section, file,
2574 abbrev_dwo, 1, 0))
2575 return num_debug_info_entries;
2576
2577 num_debug_info_entries = DEBUG_INFO_UNAVAILABLE;
2578 return 0;
2579 }
2580
2581 /* Read a DWARF .debug_line section header starting at DATA.
2582 Upon success returns an updated DATA pointer and the LINFO
2583 structure and the END_OF_SEQUENCE pointer will be filled in.
2584 Otherwise returns NULL. */
2585
2586 static unsigned char *
2587 read_debug_line_header (struct dwarf_section * section,
2588 unsigned char * data,
2589 unsigned char * end,
2590 DWARF2_Internal_LineInfo * linfo,
2591 unsigned char ** end_of_sequence)
2592 {
2593 unsigned char *hdrptr;
2594 unsigned int offset_size;
2595 unsigned int initial_length_size;
2596
2597 /* Extract information from the Line Number Program Header.
2598 (section 6.2.4 in the Dwarf3 doc). */
2599 hdrptr = data;
2600
2601 /* Get and check the length of the block. */
2602 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end);
2603
2604 if (linfo->li_length == 0xffffffff)
2605 {
2606 /* This section is 64-bit DWARF 3. */
2607 SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end);
2608 offset_size = 8;
2609 initial_length_size = 12;
2610 }
2611 else
2612 {
2613 offset_size = 4;
2614 initial_length_size = 4;
2615 }
2616
2617 if (linfo->li_length + initial_length_size > section->size)
2618 {
2619 /* If the length is just a bias against the initial_length_size then
2620 this means that the field has a relocation against it which has not
2621 been applied. (Ie we are dealing with an object file, not a linked
2622 binary). Do not complain but instead assume that the rest of the
2623 section applies to this particular header. */
2624 if (linfo->li_length == - initial_length_size)
2625 {
2626 linfo->li_length = section->size - initial_length_size;
2627 }
2628 else
2629 {
2630 warn (_("The line info appears to be corrupt - "
2631 "the section is too small\n"));
2632 return NULL;
2633 }
2634 }
2635
2636 /* Get and check the version number. */
2637 SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end);
2638
2639 if (linfo->li_version != 2
2640 && linfo->li_version != 3
2641 && linfo->li_version != 4)
2642 {
2643 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2644 return NULL;
2645 }
2646
2647 SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end);
2648 SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end);
2649
2650 if (linfo->li_version >= 4)
2651 {
2652 SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end);
2653
2654 if (linfo->li_max_ops_per_insn == 0)
2655 {
2656 warn (_("Invalid maximum operations per insn.\n"));
2657 return NULL;
2658 }
2659 }
2660 else
2661 linfo->li_max_ops_per_insn = 1;
2662
2663 SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end);
2664 SAFE_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end);
2665 SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end);
2666 SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end);
2667
2668 /* Sign extend the line base field. */
2669 linfo->li_line_base <<= 24;
2670 linfo->li_line_base >>= 24;
2671
2672 * end_of_sequence = data + linfo->li_length + initial_length_size;
2673 return hdrptr;
2674 }
2675
2676 static int
2677 display_debug_lines_raw (struct dwarf_section *section,
2678 unsigned char *data,
2679 unsigned char *end)
2680 {
2681 unsigned char *start = section->start;
2682
2683 printf (_("Raw dump of debug contents of section %s:\n\n"),
2684 section->name);
2685
2686 while (data < end)
2687 {
2688 static DWARF2_Internal_LineInfo saved_linfo;
2689 DWARF2_Internal_LineInfo linfo;
2690 unsigned char *standard_opcodes;
2691 unsigned char *end_of_sequence;
2692 unsigned int last_dir_entry = 0;
2693 int i;
2694
2695 if (const_strneq (section->name, ".debug_line.")
2696 /* Note: the following does not apply to .debug_line.dwo sections.
2697 These are full debug_line sections. */
2698 && strcmp (section->name, ".debug_line.dwo") != 0)
2699 {
2700 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2701 section containing just the Line Number Statements. They are
2702 created by the assembler and intended to be used alongside gcc's
2703 -ffunction-sections command line option. When the linker's
2704 garbage collection decides to discard a .text.<foo> section it
2705 can then also discard the line number information in .debug_line.<foo>.
2706
2707 Since the section is a fragment it does not have the details
2708 needed to fill out a LineInfo structure, so instead we use the
2709 details from the last full debug_line section that we processed. */
2710 end_of_sequence = end;
2711 standard_opcodes = NULL;
2712 linfo = saved_linfo;
2713 reset_state_machine (linfo.li_default_is_stmt);
2714 }
2715 else
2716 {
2717 unsigned char * hdrptr;
2718
2719 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
2720 & end_of_sequence)) == NULL)
2721 return 0;
2722
2723 printf (_(" Offset: 0x%lx\n"), (long)(data - start));
2724 printf (_(" Length: %ld\n"), (long) linfo.li_length);
2725 printf (_(" DWARF Version: %d\n"), linfo.li_version);
2726 printf (_(" Prologue Length: %d\n"), linfo.li_prologue_length);
2727 printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length);
2728 if (linfo.li_version >= 4)
2729 printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn);
2730 printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt);
2731 printf (_(" Line Base: %d\n"), linfo.li_line_base);
2732 printf (_(" Line Range: %d\n"), linfo.li_line_range);
2733 printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base);
2734
2735 reset_state_machine (linfo.li_default_is_stmt);
2736
2737 /* Display the contents of the Opcodes table. */
2738 standard_opcodes = hdrptr;
2739
2740 printf (_("\n Opcodes:\n"));
2741
2742 for (i = 1; i < linfo.li_opcode_base; i++)
2743 printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]);
2744
2745 /* Display the contents of the Directory table. */
2746 data = standard_opcodes + linfo.li_opcode_base - 1;
2747
2748 if (*data == 0)
2749 printf (_("\n The Directory Table is empty.\n"));
2750 else
2751 {
2752 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2753 (long)(data - start));
2754
2755 while (*data != 0)
2756 {
2757 printf (" %d\t%s\n", ++last_dir_entry, data);
2758
2759 data += strnlen ((char *) data, end - data) + 1;
2760 }
2761 }
2762
2763 /* Skip the NUL at the end of the table. */
2764 data++;
2765
2766 /* Display the contents of the File Name table. */
2767 if (*data == 0)
2768 printf (_("\n The File Name Table is empty.\n"));
2769 else
2770 {
2771 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2772 (long)(data - start));
2773 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2774
2775 while (*data != 0)
2776 {
2777 unsigned char *name;
2778 unsigned int bytes_read;
2779
2780 printf (" %d\t", ++state_machine_regs.last_file_entry);
2781 name = data;
2782 data += strnlen ((char *) data, end - data) + 1;
2783
2784 printf ("%s\t",
2785 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2786 data += bytes_read;
2787 printf ("%s\t",
2788 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2789 data += bytes_read;
2790 printf ("%s\t",
2791 dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end)));
2792 data += bytes_read;
2793 printf ("%s\n", name);
2794
2795 if (data == end)
2796 {
2797 warn (_("Corrupt file name table entry\n"));
2798 break;
2799 }
2800 }
2801 }
2802
2803 /* Skip the NUL at the end of the table. */
2804 data++;
2805 putchar ('\n');
2806 saved_linfo = linfo;
2807 }
2808
2809 /* Now display the statements. */
2810 if (data >= end_of_sequence)
2811 printf (_(" No Line Number Statements.\n"));
2812 else
2813 {
2814 printf (_(" Line Number Statements:\n"));
2815
2816 while (data < end_of_sequence)
2817 {
2818 unsigned char op_code;
2819 dwarf_signed_vma adv;
2820 dwarf_vma uladv;
2821 unsigned int bytes_read;
2822
2823 printf (" [0x%08lx]", (long)(data - start));
2824
2825 op_code = *data++;
2826
2827 if (op_code >= linfo.li_opcode_base)
2828 {
2829 op_code -= linfo.li_opcode_base;
2830 uladv = (op_code / linfo.li_line_range);
2831 if (linfo.li_max_ops_per_insn == 1)
2832 {
2833 uladv *= linfo.li_min_insn_length;
2834 state_machine_regs.address += uladv;
2835 printf (_(" Special opcode %d: "
2836 "advance Address by %s to 0x%s"),
2837 op_code, dwarf_vmatoa ("u", uladv),
2838 dwarf_vmatoa ("x", state_machine_regs.address));
2839 }
2840 else
2841 {
2842 state_machine_regs.address
2843 += ((state_machine_regs.op_index + uladv)
2844 / linfo.li_max_ops_per_insn)
2845 * linfo.li_min_insn_length;
2846 state_machine_regs.op_index
2847 = (state_machine_regs.op_index + uladv)
2848 % linfo.li_max_ops_per_insn;
2849 printf (_(" Special opcode %d: "
2850 "advance Address by %s to 0x%s[%d]"),
2851 op_code, dwarf_vmatoa ("u", uladv),
2852 dwarf_vmatoa ("x", state_machine_regs.address),
2853 state_machine_regs.op_index);
2854 }
2855 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
2856 state_machine_regs.line += adv;
2857 printf (_(" and Line by %s to %d\n"),
2858 dwarf_vmatoa ("d", adv), state_machine_regs.line);
2859 }
2860 else switch (op_code)
2861 {
2862 case DW_LNS_extended_op:
2863 data += process_extended_line_op (data, linfo.li_default_is_stmt, end);
2864 break;
2865
2866 case DW_LNS_copy:
2867 printf (_(" Copy\n"));
2868 break;
2869
2870 case DW_LNS_advance_pc:
2871 uladv = read_uleb128 (data, & bytes_read, end);
2872 data += bytes_read;
2873 if (linfo.li_max_ops_per_insn == 1)
2874 {
2875 uladv *= linfo.li_min_insn_length;
2876 state_machine_regs.address += uladv;
2877 printf (_(" Advance PC by %s to 0x%s\n"),
2878 dwarf_vmatoa ("u", uladv),
2879 dwarf_vmatoa ("x", state_machine_regs.address));
2880 }
2881 else
2882 {
2883 state_machine_regs.address
2884 += ((state_machine_regs.op_index + uladv)
2885 / linfo.li_max_ops_per_insn)
2886 * linfo.li_min_insn_length;
2887 state_machine_regs.op_index
2888 = (state_machine_regs.op_index + uladv)
2889 % linfo.li_max_ops_per_insn;
2890 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
2891 dwarf_vmatoa ("u", uladv),
2892 dwarf_vmatoa ("x", state_machine_regs.address),
2893 state_machine_regs.op_index);
2894 }
2895 break;
2896
2897 case DW_LNS_advance_line:
2898 adv = read_sleb128 (data, & bytes_read, end);
2899 data += bytes_read;
2900 state_machine_regs.line += adv;
2901 printf (_(" Advance Line by %s to %d\n"),
2902 dwarf_vmatoa ("d", adv),
2903 state_machine_regs.line);
2904 break;
2905
2906 case DW_LNS_set_file:
2907 adv = read_uleb128 (data, & bytes_read, end);
2908 data += bytes_read;
2909 printf (_(" Set File Name to entry %s in the File Name Table\n"),
2910 dwarf_vmatoa ("d", adv));
2911 state_machine_regs.file = adv;
2912 break;
2913
2914 case DW_LNS_set_column:
2915 uladv = read_uleb128 (data, & bytes_read, end);
2916 data += bytes_read;
2917 printf (_(" Set column to %s\n"),
2918 dwarf_vmatoa ("u", uladv));
2919 state_machine_regs.column = uladv;
2920 break;
2921
2922 case DW_LNS_negate_stmt:
2923 adv = state_machine_regs.is_stmt;
2924 adv = ! adv;
2925 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv));
2926 state_machine_regs.is_stmt = adv;
2927 break;
2928
2929 case DW_LNS_set_basic_block:
2930 printf (_(" Set basic block\n"));
2931 state_machine_regs.basic_block = 1;
2932 break;
2933
2934 case DW_LNS_const_add_pc:
2935 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
2936 if (linfo.li_max_ops_per_insn)
2937 {
2938 uladv *= linfo.li_min_insn_length;
2939 state_machine_regs.address += uladv;
2940 printf (_(" Advance PC by constant %s to 0x%s\n"),
2941 dwarf_vmatoa ("u", uladv),
2942 dwarf_vmatoa ("x", state_machine_regs.address));
2943 }
2944 else
2945 {
2946 state_machine_regs.address
2947 += ((state_machine_regs.op_index + uladv)
2948 / linfo.li_max_ops_per_insn)
2949 * linfo.li_min_insn_length;
2950 state_machine_regs.op_index
2951 = (state_machine_regs.op_index + uladv)
2952 % linfo.li_max_ops_per_insn;
2953 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
2954 dwarf_vmatoa ("u", uladv),
2955 dwarf_vmatoa ("x", state_machine_regs.address),
2956 state_machine_regs.op_index);
2957 }
2958 break;
2959
2960 case DW_LNS_fixed_advance_pc:
2961 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
2962 state_machine_regs.address += uladv;
2963 state_machine_regs.op_index = 0;
2964 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
2965 dwarf_vmatoa ("u", uladv),
2966 dwarf_vmatoa ("x", state_machine_regs.address));
2967 break;
2968
2969 case DW_LNS_set_prologue_end:
2970 printf (_(" Set prologue_end to true\n"));
2971 break;
2972
2973 case DW_LNS_set_epilogue_begin:
2974 printf (_(" Set epilogue_begin to true\n"));
2975 break;
2976
2977 case DW_LNS_set_isa:
2978 uladv = read_uleb128 (data, & bytes_read, end);
2979 data += bytes_read;
2980 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv));
2981 break;
2982
2983 default:
2984 printf (_(" Unknown opcode %d with operands: "), op_code);
2985
2986 if (standard_opcodes != NULL)
2987 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
2988 {
2989 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
2990 &bytes_read, end)),
2991 i == 1 ? "" : ", ");
2992 data += bytes_read;
2993 }
2994 putchar ('\n');
2995 break;
2996 }
2997 }
2998 putchar ('\n');
2999 }
3000 }
3001
3002 return 1;
3003 }
3004
3005 typedef struct
3006 {
3007 unsigned char *name;
3008 unsigned int directory_index;
3009 unsigned int modification_date;
3010 unsigned int length;
3011 } File_Entry;
3012
3013 /* Output a decoded representation of the .debug_line section. */
3014
3015 static int
3016 display_debug_lines_decoded (struct dwarf_section *section,
3017 unsigned char *data,
3018 unsigned char *end)
3019 {
3020 static DWARF2_Internal_LineInfo saved_linfo;
3021
3022 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3023 section->name);
3024
3025 while (data < end)
3026 {
3027 /* This loop amounts to one iteration per compilation unit. */
3028 DWARF2_Internal_LineInfo linfo;
3029 unsigned char *standard_opcodes;
3030 unsigned char *end_of_sequence;
3031 int i;
3032 File_Entry *file_table = NULL;
3033 unsigned int n_files = 0;
3034 unsigned char **directory_table = NULL;
3035 unsigned int n_directories = 0;
3036
3037 if (const_strneq (section->name, ".debug_line.")
3038 /* Note: the following does not apply to .debug_line.dwo sections.
3039 These are full debug_line sections. */
3040 && strcmp (section->name, ".debug_line.dwo") != 0)
3041 {
3042 /* See comment in display_debug_lines_raw(). */
3043 end_of_sequence = end;
3044 standard_opcodes = NULL;
3045 linfo = saved_linfo;
3046 reset_state_machine (linfo.li_default_is_stmt);
3047 }
3048 else
3049 {
3050 unsigned char *hdrptr;
3051
3052 if ((hdrptr = read_debug_line_header (section, data, end, & linfo,
3053 & end_of_sequence)) == NULL)
3054 return 0;
3055
3056 reset_state_machine (linfo.li_default_is_stmt);
3057
3058 /* Save a pointer to the contents of the Opcodes table. */
3059 standard_opcodes = hdrptr;
3060
3061 /* Traverse the Directory table just to count entries. */
3062 data = standard_opcodes + linfo.li_opcode_base - 1;
3063 if (*data != 0)
3064 {
3065 unsigned char *ptr_directory_table = data;
3066
3067 while (*data != 0)
3068 {
3069 data += strnlen ((char *) data, end - data) + 1;
3070 n_directories++;
3071 }
3072
3073 /* Go through the directory table again to save the directories. */
3074 directory_table = (unsigned char **)
3075 xmalloc (n_directories * sizeof (unsigned char *));
3076
3077 i = 0;
3078 while (*ptr_directory_table != 0)
3079 {
3080 directory_table[i] = ptr_directory_table;
3081 ptr_directory_table += strnlen ((char *) ptr_directory_table,
3082 ptr_directory_table - end) + 1;
3083 i++;
3084 }
3085 }
3086 /* Skip the NUL at the end of the table. */
3087 data++;
3088
3089 /* Traverse the File Name table just to count the entries. */
3090 if (*data != 0)
3091 {
3092 unsigned char *ptr_file_name_table = data;
3093
3094 while (*data != 0)
3095 {
3096 unsigned int bytes_read;
3097
3098 /* Skip Name, directory index, last modification time and length
3099 of file. */
3100 data += strnlen ((char *) data, end - data) + 1;
3101 read_uleb128 (data, & bytes_read, end);
3102 data += bytes_read;
3103 read_uleb128 (data, & bytes_read, end);
3104 data += bytes_read;
3105 read_uleb128 (data, & bytes_read, end);
3106 data += bytes_read;
3107
3108 n_files++;
3109 }
3110
3111 /* Go through the file table again to save the strings. */
3112 file_table = (File_Entry *) xmalloc (n_files * sizeof (File_Entry));
3113
3114 i = 0;
3115 while (*ptr_file_name_table != 0)
3116 {
3117 unsigned int bytes_read;
3118
3119 file_table[i].name = ptr_file_name_table;
3120 ptr_file_name_table += strnlen ((char *) ptr_file_name_table,
3121 end - ptr_file_name_table) + 1;
3122
3123 /* We are not interested in directory, time or size. */
3124 file_table[i].directory_index = read_uleb128 (ptr_file_name_table,
3125 & bytes_read, end);
3126 ptr_file_name_table += bytes_read;
3127 file_table[i].modification_date = read_uleb128 (ptr_file_name_table,
3128 & bytes_read, end);
3129 ptr_file_name_table += bytes_read;
3130 file_table[i].length = read_uleb128 (ptr_file_name_table, & bytes_read, end);
3131 ptr_file_name_table += bytes_read;
3132 i++;
3133 }
3134 i = 0;
3135
3136 /* Print the Compilation Unit's name and a header. */
3137 if (directory_table == NULL)
3138 {
3139 printf (_("CU: %s:\n"), file_table[0].name);
3140 printf (_("File name Line number Starting address\n"));
3141 }
3142 else
3143 {
3144 unsigned int ix = file_table[0].directory_index;
3145 const char *directory = ix ? (char *)directory_table[ix - 1] : ".";
3146
3147 if (do_wide || strlen (directory) < 76)
3148 printf (_("CU: %s/%s:\n"), directory, file_table[0].name);
3149 else
3150 printf ("%s:\n", file_table[0].name);
3151
3152 printf (_("File name Line number Starting address\n"));
3153 }
3154 }
3155
3156 /* Skip the NUL at the end of the table. */
3157 data++;
3158
3159 saved_linfo = linfo;
3160 }
3161
3162 /* This loop iterates through the Dwarf Line Number Program. */
3163 while (data < end_of_sequence)
3164 {
3165 unsigned char op_code;
3166 int adv;
3167 unsigned long int uladv;
3168 unsigned int bytes_read;
3169 int is_special_opcode = 0;
3170
3171 op_code = *data++;
3172
3173 if (op_code >= linfo.li_opcode_base)
3174 {
3175 op_code -= linfo.li_opcode_base;
3176 uladv = (op_code / linfo.li_line_range);
3177 if (linfo.li_max_ops_per_insn == 1)
3178 {
3179 uladv *= linfo.li_min_insn_length;
3180 state_machine_regs.address += uladv;
3181 }
3182 else
3183 {
3184 state_machine_regs.address
3185 += ((state_machine_regs.op_index + uladv)
3186 / linfo.li_max_ops_per_insn)
3187 * linfo.li_min_insn_length;
3188 state_machine_regs.op_index
3189 = (state_machine_regs.op_index + uladv)
3190 % linfo.li_max_ops_per_insn;
3191 }
3192
3193 adv = (op_code % linfo.li_line_range) + linfo.li_line_base;
3194 state_machine_regs.line += adv;
3195 is_special_opcode = 1;
3196 }
3197 else switch (op_code)
3198 {
3199 case DW_LNS_extended_op:
3200 {
3201 unsigned int ext_op_code_len;
3202 unsigned char ext_op_code;
3203 unsigned char *op_code_data = data;
3204
3205 ext_op_code_len = read_uleb128 (op_code_data, &bytes_read,
3206 end_of_sequence);
3207 op_code_data += bytes_read;
3208
3209 if (ext_op_code_len == 0)
3210 {
3211 warn (_("badly formed extended line op encountered!\n"));
3212 break;
3213 }
3214 ext_op_code_len += bytes_read;
3215 ext_op_code = *op_code_data++;
3216
3217 switch (ext_op_code)
3218 {
3219 case DW_LNE_end_sequence:
3220 reset_state_machine (linfo.li_default_is_stmt);
3221 break;
3222 case DW_LNE_set_address:
3223 SAFE_BYTE_GET_AND_INC (state_machine_regs.address,
3224 op_code_data,
3225 ext_op_code_len - bytes_read - 1,
3226 end);
3227 state_machine_regs.op_index = 0;
3228 break;
3229 case DW_LNE_define_file:
3230 {
3231 file_table = (File_Entry *) xrealloc
3232 (file_table, (n_files + 1) * sizeof (File_Entry));
3233
3234 ++state_machine_regs.last_file_entry;
3235 /* Source file name. */
3236 file_table[n_files].name = op_code_data;
3237 op_code_data += strlen ((char *) op_code_data) + 1;
3238 /* Directory index. */
3239 file_table[n_files].directory_index =
3240 read_uleb128 (op_code_data, & bytes_read,
3241 end_of_sequence);
3242 op_code_data += bytes_read;
3243 /* Last modification time. */
3244 file_table[n_files].modification_date =
3245 read_uleb128 (op_code_data, & bytes_read,
3246 end_of_sequence);
3247 op_code_data += bytes_read;
3248 /* File length. */
3249 file_table[n_files].length =
3250 read_uleb128 (op_code_data, & bytes_read,
3251 end_of_sequence);
3252
3253 n_files++;
3254 break;
3255 }
3256 case DW_LNE_set_discriminator:
3257 case DW_LNE_HP_set_sequence:
3258 /* Simply ignored. */
3259 break;
3260
3261 default:
3262 printf (_("UNKNOWN (%u): length %d\n"),
3263 ext_op_code, ext_op_code_len - bytes_read);
3264 break;
3265 }
3266 data += ext_op_code_len;
3267 break;
3268 }
3269 case DW_LNS_copy:
3270 break;
3271
3272 case DW_LNS_advance_pc:
3273 uladv = read_uleb128 (data, & bytes_read, end);
3274 data += bytes_read;
3275 if (linfo.li_max_ops_per_insn == 1)
3276 {
3277 uladv *= linfo.li_min_insn_length;
3278 state_machine_regs.address += uladv;
3279 }
3280 else
3281 {
3282 state_machine_regs.address
3283 += ((state_machine_regs.op_index + uladv)
3284 / linfo.li_max_ops_per_insn)
3285 * linfo.li_min_insn_length;
3286 state_machine_regs.op_index
3287 = (state_machine_regs.op_index + uladv)
3288 % linfo.li_max_ops_per_insn;
3289 }
3290 break;
3291
3292 case DW_LNS_advance_line:
3293 adv = read_sleb128 (data, & bytes_read, end);
3294 data += bytes_read;
3295 state_machine_regs.line += adv;
3296 break;
3297
3298 case DW_LNS_set_file:
3299 adv = read_uleb128 (data, & bytes_read, end);
3300 data += bytes_read;
3301 state_machine_regs.file = adv;
3302
3303 if (file_table == NULL)
3304 printf (_("\n [Use file table entry %d]\n"), state_machine_regs.file - 1);
3305 else if (file_table[state_machine_regs.file - 1].directory_index == 0)
3306 /* If directory index is 0, that means current directory. */
3307 printf ("\n./%s:[++]\n",
3308 file_table[state_machine_regs.file - 1].name);
3309 else if (directory_table == NULL)
3310 printf (_("\n [Use directory table entry %d]\n"),
3311 file_table[state_machine_regs.file - 1].directory_index - 1);
3312 else
3313 /* The directory index starts counting at 1. */
3314 printf ("\n%s/%s:\n",
3315 directory_table[file_table[state_machine_regs.file - 1].directory_index - 1],
3316 file_table[state_machine_regs.file - 1].name);
3317 break;
3318
3319 case DW_LNS_set_column:
3320 uladv = read_uleb128 (data, & bytes_read, end);
3321 data += bytes_read;
3322 state_machine_regs.column = uladv;
3323 break;
3324
3325 case DW_LNS_negate_stmt:
3326 adv = state_machine_regs.is_stmt;
3327 adv = ! adv;
3328 state_machine_regs.is_stmt = adv;
3329 break;
3330
3331 case DW_LNS_set_basic_block:
3332 state_machine_regs.basic_block = 1;
3333 break;
3334
3335 case DW_LNS_const_add_pc:
3336 uladv = ((255 - linfo.li_opcode_base) / linfo.li_line_range);
3337 if (linfo.li_max_ops_per_insn == 1)
3338 {
3339 uladv *= linfo.li_min_insn_length;
3340 state_machine_regs.address += uladv;
3341 }
3342 else
3343 {
3344 state_machine_regs.address
3345 += ((state_machine_regs.op_index + uladv)
3346 / linfo.li_max_ops_per_insn)
3347 * linfo.li_min_insn_length;
3348 state_machine_regs.op_index
3349 = (state_machine_regs.op_index + uladv)
3350 % linfo.li_max_ops_per_insn;
3351 }
3352 break;
3353
3354 case DW_LNS_fixed_advance_pc:
3355 SAFE_BYTE_GET_AND_INC (uladv, data, 2, end);
3356 state_machine_regs.address += uladv;
3357 state_machine_regs.op_index = 0;
3358 break;
3359
3360 case DW_LNS_set_prologue_end:
3361 break;
3362
3363 case DW_LNS_set_epilogue_begin:
3364 break;
3365
3366 case DW_LNS_set_isa:
3367 uladv = read_uleb128 (data, & bytes_read, end);
3368 data += bytes_read;
3369 printf (_(" Set ISA to %lu\n"), uladv);
3370 break;
3371
3372 default:
3373 printf (_(" Unknown opcode %d with operands: "), op_code);
3374
3375 if (standard_opcodes != NULL)
3376 for (i = standard_opcodes[op_code - 1]; i > 0 ; --i)
3377 {
3378 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data,
3379 &bytes_read, end)),
3380 i == 1 ? "" : ", ");
3381 data += bytes_read;
3382 }
3383 putchar ('\n');
3384 break;
3385 }
3386
3387 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3388 to the DWARF address/line matrix. */
3389 if ((is_special_opcode) || (op_code == DW_LNE_end_sequence)
3390 || (op_code == DW_LNS_copy))
3391 {
3392 const unsigned int MAX_FILENAME_LENGTH = 35;
3393 char *fileName;
3394 char *newFileName = NULL;
3395 size_t fileNameLength;
3396
3397 if (file_table)
3398 fileName = (char *) file_table[state_machine_regs.file - 1].name;
3399 else
3400 fileName = "<unknown>";
3401
3402 fileNameLength = strlen (fileName);
3403
3404 if ((fileNameLength > MAX_FILENAME_LENGTH) && (!do_wide))
3405 {
3406 newFileName = (char *) xmalloc (MAX_FILENAME_LENGTH + 1);
3407 /* Truncate file name */
3408 strncpy (newFileName,
3409 fileName + fileNameLength - MAX_FILENAME_LENGTH,
3410 MAX_FILENAME_LENGTH + 1);
3411 }
3412 else
3413 {
3414 newFileName = (char *) xmalloc (fileNameLength + 1);
3415 strncpy (newFileName, fileName, fileNameLength + 1);
3416 }
3417
3418 if (!do_wide || (fileNameLength <= MAX_FILENAME_LENGTH))
3419 {
3420 if (linfo.li_max_ops_per_insn == 1)
3421 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x\n",
3422 newFileName, state_machine_regs.line,
3423 state_machine_regs.address);
3424 else
3425 printf ("%-35s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3426 newFileName, state_machine_regs.line,
3427 state_machine_regs.address,
3428 state_machine_regs.op_index);
3429 }
3430 else
3431 {
3432 if (linfo.li_max_ops_per_insn == 1)
3433 printf ("%s %11d %#18" DWARF_VMA_FMT "x\n",
3434 newFileName, state_machine_regs.line,
3435 state_machine_regs.address);
3436 else
3437 printf ("%s %11d %#18" DWARF_VMA_FMT "x[%d]\n",
3438 newFileName, state_machine_regs.line,
3439 state_machine_regs.address,
3440 state_machine_regs.op_index);
3441 }
3442
3443 if (op_code == DW_LNE_end_sequence)
3444 printf ("\n");
3445
3446 free (newFileName);
3447 }
3448 }
3449
3450 if (file_table)
3451 {
3452 free (file_table);
3453 file_table = NULL;
3454 n_files = 0;
3455 }
3456
3457 if (directory_table)
3458 {
3459 free (directory_table);
3460 directory_table = NULL;
3461 n_directories = 0;
3462 }
3463
3464 putchar ('\n');
3465 }
3466
3467 return 1;
3468 }
3469
3470 static int
3471 display_debug_lines (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
3472 {
3473 unsigned char *data = section->start;
3474 unsigned char *end = data + section->size;
3475 int retValRaw = 1;
3476 int retValDecoded = 1;
3477
3478 if (do_debug_lines == 0)
3479 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
3480
3481 if (do_debug_lines & FLAG_DEBUG_LINES_RAW)
3482 retValRaw = display_debug_lines_raw (section, data, end);
3483
3484 if (do_debug_lines & FLAG_DEBUG_LINES_DECODED)
3485 retValDecoded = display_debug_lines_decoded (section, data, end);
3486
3487 if (!retValRaw || !retValDecoded)
3488 return 0;
3489
3490 return 1;
3491 }
3492
3493 static debug_info *
3494 find_debug_info_for_offset (unsigned long offset)
3495 {
3496 unsigned int i;
3497
3498 if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE)
3499 return NULL;
3500
3501 for (i = 0; i < num_debug_info_entries; i++)
3502 if (debug_information[i].cu_offset == offset)
3503 return debug_information + i;
3504
3505 return NULL;
3506 }
3507
3508 static const char *
3509 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind)
3510 {
3511 /* See gdb/gdb-index.h. */
3512 static const char * const kinds[] =
3513 {
3514 N_ ("no info"),
3515 N_ ("type"),
3516 N_ ("variable"),
3517 N_ ("function"),
3518 N_ ("other"),
3519 N_ ("unused5"),
3520 N_ ("unused6"),
3521 N_ ("unused7")
3522 };
3523
3524 return _ (kinds[kind]);
3525 }
3526
3527 static int
3528 display_debug_pubnames_worker (struct dwarf_section *section,
3529 void *file ATTRIBUTE_UNUSED,
3530 int is_gnu)
3531 {
3532 DWARF2_Internal_PubNames names;
3533 unsigned char *start = section->start;
3534 unsigned char *end = start + section->size;
3535
3536 /* It does not matter if this load fails,
3537 we test for that later on. */
3538 load_debug_info (file);
3539
3540 printf (_("Contents of the %s section:\n\n"), section->name);
3541
3542 while (start < end)
3543 {
3544 unsigned char *data;
3545 unsigned long offset;
3546 unsigned int offset_size, initial_length_size;
3547
3548 data = start;
3549
3550 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 4, end);
3551 if (names.pn_length == 0xffffffff)
3552 {
3553 SAFE_BYTE_GET_AND_INC (names.pn_length, data, 8, end);
3554 offset_size = 8;
3555 initial_length_size = 12;
3556 }
3557 else
3558 {
3559 offset_size = 4;
3560 initial_length_size = 4;
3561 }
3562
3563 SAFE_BYTE_GET_AND_INC (names.pn_version, data, 2, end);
3564 SAFE_BYTE_GET_AND_INC (names.pn_offset, data, offset_size, end);
3565
3566 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
3567 && num_debug_info_entries > 0
3568 && find_debug_info_for_offset (names.pn_offset) == NULL)
3569 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3570 (unsigned long) names.pn_offset, section->name);
3571
3572 SAFE_BYTE_GET_AND_INC (names.pn_size, data, offset_size, end);
3573
3574 start += names.pn_length + initial_length_size;
3575
3576 if (names.pn_version != 2 && names.pn_version != 3)
3577 {
3578 static int warned = 0;
3579
3580 if (! warned)
3581 {
3582 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3583 warned = 1;
3584 }
3585
3586 continue;
3587 }
3588
3589 printf (_(" Length: %ld\n"),
3590 (long) names.pn_length);
3591 printf (_(" Version: %d\n"),
3592 names.pn_version);
3593 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3594 (unsigned long) names.pn_offset);
3595 printf (_(" Size of area in .debug_info section: %ld\n"),
3596 (long) names.pn_size);
3597
3598 if (is_gnu)
3599 printf (_("\n Offset Kind Name\n"));
3600 else
3601 printf (_("\n Offset\tName\n"));
3602
3603 do
3604 {
3605 SAFE_BYTE_GET (offset, data, offset_size, end);
3606
3607 if (offset != 0)
3608 {
3609 data += offset_size;
3610 if (is_gnu)
3611 {
3612 unsigned int kind_data;
3613 gdb_index_symbol_kind kind;
3614 const char *kind_name;
3615 int is_static;
3616
3617 SAFE_BYTE_GET (kind_data, data, 1, end);
3618 data++;
3619 /* GCC computes the kind as the upper byte in the CU index
3620 word, and then right shifts it by the CU index size.
3621 Left shift KIND to where the gdb-index.h accessor macros
3622 can use it. */
3623 kind_data <<= GDB_INDEX_CU_BITSIZE;
3624 kind = GDB_INDEX_SYMBOL_KIND_VALUE (kind_data);
3625 kind_name = get_gdb_index_symbol_kind_name (kind);
3626 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data);
3627 printf (" %-6lx %s,%-10s %s\n",
3628 offset, is_static ? _("s") : _("g"),
3629 kind_name, data);
3630 }
3631 else
3632 printf (" %-6lx\t%s\n", offset, data);
3633 data += strnlen ((char *) data, end - data) + 1;
3634 }
3635 }
3636 while (offset != 0);
3637 }
3638
3639 printf ("\n");
3640 return 1;
3641 }
3642
3643 static int
3644 display_debug_pubnames (struct dwarf_section *section, void *file)
3645 {
3646 return display_debug_pubnames_worker (section, file, 0);
3647 }
3648
3649 static int
3650 display_debug_gnu_pubnames (struct dwarf_section *section, void *file)
3651 {
3652 return display_debug_pubnames_worker (section, file, 1);
3653 }
3654
3655 static int
3656 display_debug_macinfo (struct dwarf_section *section,
3657 void *file ATTRIBUTE_UNUSED)
3658 {
3659 unsigned char *start = section->start;
3660 unsigned char *end = start + section->size;
3661 unsigned char *curr = start;
3662 unsigned int bytes_read;
3663 enum dwarf_macinfo_record_type op;
3664
3665 printf (_("Contents of the %s section:\n\n"), section->name);
3666
3667 while (curr < end)
3668 {
3669 unsigned int lineno;
3670 const unsigned char *string;
3671
3672 op = (enum dwarf_macinfo_record_type) *curr;
3673 curr++;
3674
3675 switch (op)
3676 {
3677 case DW_MACINFO_start_file:
3678 {
3679 unsigned int filenum;
3680
3681 lineno = read_uleb128 (curr, & bytes_read, end);
3682 curr += bytes_read;
3683 filenum = read_uleb128 (curr, & bytes_read, end);
3684 curr += bytes_read;
3685
3686 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3687 lineno, filenum);
3688 }
3689 break;
3690
3691 case DW_MACINFO_end_file:
3692 printf (_(" DW_MACINFO_end_file\n"));
3693 break;
3694
3695 case DW_MACINFO_define:
3696 lineno = read_uleb128 (curr, & bytes_read, end);
3697 curr += bytes_read;
3698 string = curr;
3699 curr += strnlen ((char *) string, end - string) + 1;
3700 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3701 lineno, string);
3702 break;
3703
3704 case DW_MACINFO_undef:
3705 lineno = read_uleb128 (curr, & bytes_read, end);
3706 curr += bytes_read;
3707 string = curr;
3708 curr += strnlen ((char *) string, end - string) + 1;
3709 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3710 lineno, string);
3711 break;
3712
3713 case DW_MACINFO_vendor_ext:
3714 {
3715 unsigned int constant;
3716
3717 constant = read_uleb128 (curr, & bytes_read, end);
3718 curr += bytes_read;
3719 string = curr;
3720 curr += strnlen ((char *) string, end - string) + 1;
3721 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3722 constant, string);
3723 }
3724 break;
3725 }
3726 }
3727
3728 return 1;
3729 }
3730
3731 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3732 filename and dirname corresponding to file name table entry with index
3733 FILEIDX. Return NULL on failure. */
3734
3735 static unsigned char *
3736 get_line_filename_and_dirname (dwarf_vma line_offset,
3737 dwarf_vma fileidx,
3738 unsigned char **dir_name)
3739 {
3740 struct dwarf_section *section = &debug_displays [line].section;
3741 unsigned char *hdrptr, *dirtable, *file_name;
3742 unsigned int offset_size, initial_length_size;
3743 unsigned int version, opcode_base, bytes_read;
3744 dwarf_vma length, diridx;
3745 const unsigned char * end;
3746
3747 *dir_name = NULL;
3748 if (section->start == NULL
3749 || line_offset >= section->size
3750 || fileidx == 0)
3751 return NULL;
3752
3753 hdrptr = section->start + line_offset;
3754 end = section->start + section->size;
3755
3756 SAFE_BYTE_GET_AND_INC (length, hdrptr, 4, end);
3757 if (length == 0xffffffff)
3758 {
3759 /* This section is 64-bit DWARF 3. */
3760 SAFE_BYTE_GET_AND_INC (length, hdrptr, 8, end);
3761 offset_size = 8;
3762 initial_length_size = 12;
3763 }
3764 else
3765 {
3766 offset_size = 4;
3767 initial_length_size = 4;
3768 }
3769 if (length + initial_length_size > section->size)
3770 return NULL;
3771
3772 SAFE_BYTE_GET_AND_INC (version, hdrptr, 2, end);
3773 if (version != 2 && version != 3 && version != 4)
3774 return NULL;
3775 hdrptr += offset_size + 1;/* Skip prologue_length and min_insn_length. */
3776 if (version >= 4)
3777 hdrptr++; /* Skip max_ops_per_insn. */
3778 hdrptr += 3; /* Skip default_is_stmt, line_base, line_range. */
3779
3780 SAFE_BYTE_GET_AND_INC (opcode_base, hdrptr, 1, end);
3781 if (opcode_base == 0)
3782 return NULL;
3783
3784 hdrptr += opcode_base - 1;
3785 dirtable = hdrptr;
3786 /* Skip over dirname table. */
3787 while (*hdrptr != '\0')
3788 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3789 hdrptr++; /* Skip the NUL at the end of the table. */
3790 /* Now skip over preceding filename table entries. */
3791 for (; *hdrptr != '\0' && fileidx > 1; fileidx--)
3792 {
3793 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3794 read_uleb128 (hdrptr, &bytes_read, end);
3795 hdrptr += bytes_read;
3796 read_uleb128 (hdrptr, &bytes_read, end);
3797 hdrptr += bytes_read;
3798 read_uleb128 (hdrptr, &bytes_read, end);
3799 hdrptr += bytes_read;
3800 }
3801 if (hdrptr == end || *hdrptr == '\0')
3802 return NULL;
3803 file_name = hdrptr;
3804 hdrptr += strnlen ((char *) hdrptr, end - hdrptr) + 1;
3805 diridx = read_uleb128 (hdrptr, &bytes_read, end);
3806 if (diridx == 0)
3807 return file_name;
3808 for (; *dirtable != '\0' && diridx > 1; diridx--)
3809 dirtable += strnlen ((char *) dirtable, end - dirtable) + 1;
3810 if (*dirtable == '\0')
3811 return NULL;
3812 *dir_name = dirtable;
3813 return file_name;
3814 }
3815
3816 static int
3817 display_debug_macro (struct dwarf_section *section,
3818 void *file)
3819 {
3820 unsigned char *start = section->start;
3821 unsigned char *end = start + section->size;
3822 unsigned char *curr = start;
3823 unsigned char *extended_op_buf[256];
3824 unsigned int bytes_read;
3825
3826 load_debug_section (str, file);
3827 load_debug_section (line, file);
3828
3829 printf (_("Contents of the %s section:\n\n"), section->name);
3830
3831 while (curr < end)
3832 {
3833 unsigned int lineno, version, flags;
3834 unsigned int offset_size = 4;
3835 const unsigned char *string;
3836 dwarf_vma line_offset = 0, sec_offset = curr - start, offset;
3837 unsigned char **extended_ops = NULL;
3838
3839 SAFE_BYTE_GET_AND_INC (version, curr, 2, end);
3840 if (version != 4)
3841 {
3842 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
3843 section->name);
3844 return 0;
3845 }
3846
3847 SAFE_BYTE_GET_AND_INC (flags, curr, 1, end);
3848 if (flags & 1)
3849 offset_size = 8;
3850 printf (_(" Offset: 0x%lx\n"),
3851 (unsigned long) sec_offset);
3852 printf (_(" Version: %d\n"), version);
3853 printf (_(" Offset size: %d\n"), offset_size);
3854 if (flags & 2)
3855 {
3856 SAFE_BYTE_GET_AND_INC (line_offset, curr, offset_size, end);
3857 printf (_(" Offset into .debug_line: 0x%lx\n"),
3858 (unsigned long) line_offset);
3859 }
3860 if (flags & 4)
3861 {
3862 unsigned int i, count, op;
3863 dwarf_vma nargs, n;
3864
3865 SAFE_BYTE_GET_AND_INC (count, curr, 1, end);
3866
3867 memset (extended_op_buf, 0, sizeof (extended_op_buf));
3868 extended_ops = extended_op_buf;
3869 if (count)
3870 {
3871 printf (_(" Extension opcode arguments:\n"));
3872 for (i = 0; i < count; i++)
3873 {
3874 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
3875 extended_ops[op] = curr;
3876 nargs = read_uleb128 (curr, &bytes_read, end);
3877 curr += bytes_read;
3878 if (nargs == 0)
3879 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op);
3880 else
3881 {
3882 printf (_(" DW_MACRO_GNU_%02x arguments: "), op);
3883 for (n = 0; n < nargs; n++)
3884 {
3885 unsigned int form;
3886
3887 SAFE_BYTE_GET_AND_INC (form, curr, 1, end);
3888 printf ("%s%s", get_FORM_name (form),
3889 n == nargs - 1 ? "\n" : ", ");
3890 switch (form)
3891 {
3892 case DW_FORM_data1:
3893 case DW_FORM_data2:
3894 case DW_FORM_data4:
3895 case DW_FORM_data8:
3896 case DW_FORM_sdata:
3897 case DW_FORM_udata:
3898 case DW_FORM_block:
3899 case DW_FORM_block1:
3900 case DW_FORM_block2:
3901 case DW_FORM_block4:
3902 case DW_FORM_flag:
3903 case DW_FORM_string:
3904 case DW_FORM_strp:
3905 case DW_FORM_sec_offset:
3906 break;
3907 default:
3908 error (_("Invalid extension opcode form %s\n"),
3909 get_FORM_name (form));
3910 return 0;
3911 }
3912 }
3913 }
3914 }
3915 }
3916 }
3917 printf ("\n");
3918
3919 while (1)
3920 {
3921 unsigned int op;
3922
3923 if (curr >= end)
3924 {
3925 error (_(".debug_macro section not zero terminated\n"));
3926 return 0;
3927 }
3928
3929 SAFE_BYTE_GET_AND_INC (op, curr, 1, end);
3930 if (op == 0)
3931 break;
3932
3933 switch (op)
3934 {
3935 case DW_MACRO_GNU_start_file:
3936 {
3937 unsigned int filenum;
3938 unsigned char *file_name = NULL, *dir_name = NULL;
3939
3940 lineno = read_uleb128 (curr, &bytes_read, end);
3941 curr += bytes_read;
3942 filenum = read_uleb128 (curr, &bytes_read, end);
3943 curr += bytes_read;
3944
3945 if ((flags & 2) == 0)
3946 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
3947 else
3948 file_name
3949 = get_line_filename_and_dirname (line_offset, filenum,
3950 &dir_name);
3951 if (file_name == NULL)
3952 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
3953 lineno, filenum);
3954 else
3955 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
3956 lineno, filenum,
3957 dir_name != NULL ? (const char *) dir_name : "",
3958 dir_name != NULL ? "/" : "", file_name);
3959 }
3960 break;
3961
3962 case DW_MACRO_GNU_end_file:
3963 printf (_(" DW_MACRO_GNU_end_file\n"));
3964 break;
3965
3966 case DW_MACRO_GNU_define:
3967 lineno = read_uleb128 (curr, &bytes_read, end);
3968 curr += bytes_read;
3969 string = curr;
3970 curr += strnlen ((char *) string, end - string) + 1;
3971 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
3972 lineno, string);
3973 break;
3974
3975 case DW_MACRO_GNU_undef:
3976 lineno = read_uleb128 (curr, &bytes_read, end);
3977 curr += bytes_read;
3978 string = curr;
3979 curr += strnlen ((char *) string, end - string) + 1;
3980 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
3981 lineno, string);
3982 break;
3983
3984 case DW_MACRO_GNU_define_indirect:
3985 lineno = read_uleb128 (curr, &bytes_read, end);
3986 curr += bytes_read;
3987 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
3988 string = fetch_indirect_string (offset);
3989 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
3990 lineno, string);
3991 break;
3992
3993 case DW_MACRO_GNU_undef_indirect:
3994 lineno = read_uleb128 (curr, &bytes_read, end);
3995 curr += bytes_read;
3996 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
3997 string = fetch_indirect_string (offset);
3998 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
3999 lineno, string);
4000 break;
4001
4002 case DW_MACRO_GNU_transparent_include:
4003 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4004 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4005 (unsigned long) offset);
4006 break;
4007
4008 case DW_MACRO_GNU_define_indirect_alt:
4009 lineno = read_uleb128 (curr, &bytes_read, end);
4010 curr += bytes_read;
4011 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4012 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4013 lineno, (unsigned long) offset);
4014 break;
4015
4016 case DW_MACRO_GNU_undef_indirect_alt:
4017 lineno = read_uleb128 (curr, &bytes_read, end);
4018 curr += bytes_read;
4019 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4020 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4021 lineno, (unsigned long) offset);
4022 break;
4023
4024 case DW_MACRO_GNU_transparent_include_alt:
4025 SAFE_BYTE_GET_AND_INC (offset, curr, offset_size, end);
4026 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4027 (unsigned long) offset);
4028 break;
4029
4030 default:
4031 if (extended_ops == NULL || extended_ops[op] == NULL)
4032 {
4033 error (_(" Unknown macro opcode %02x seen\n"), op);
4034 return 0;
4035 }
4036 else
4037 {
4038 /* Skip over unhandled opcodes. */
4039 dwarf_vma nargs, n;
4040 unsigned char *desc = extended_ops[op];
4041 nargs = read_uleb128 (desc, &bytes_read, end);
4042 desc += bytes_read;
4043 if (nargs == 0)
4044 {
4045 printf (_(" DW_MACRO_GNU_%02x\n"), op);
4046 break;
4047 }
4048 printf (_(" DW_MACRO_GNU_%02x -"), op);
4049 for (n = 0; n < nargs; n++)
4050 {
4051 int val;
4052
4053 SAFE_BYTE_GET_AND_INC (val, desc, 1, end);
4054 curr
4055 = read_and_display_attr_value (0, val,
4056 curr, end, 0, 0, offset_size,
4057 version, NULL, 0, NULL,
4058 NULL);
4059 if (n != nargs - 1)
4060 printf (",");
4061 }
4062 printf ("\n");
4063 }
4064 break;
4065 }
4066 }
4067
4068 printf ("\n");
4069 }
4070
4071 return 1;
4072 }
4073
4074 static int
4075 display_debug_abbrev (struct dwarf_section *section,
4076 void *file ATTRIBUTE_UNUSED)
4077 {
4078 abbrev_entry *entry;
4079 unsigned char *start = section->start;
4080 unsigned char *end = start + section->size;
4081
4082 printf (_("Contents of the %s section:\n\n"), section->name);
4083
4084 do
4085 {
4086 unsigned char *last;
4087
4088 free_abbrevs ();
4089
4090 last = start;
4091 start = process_abbrev_section (start, end);
4092
4093 if (first_abbrev == NULL)
4094 continue;
4095
4096 printf (_(" Number TAG (0x%lx)\n"), (long) (last - section->start));
4097
4098 for (entry = first_abbrev; entry; entry = entry->next)
4099 {
4100 abbrev_attr *attr;
4101
4102 printf (" %ld %s [%s]\n",
4103 entry->entry,
4104 get_TAG_name (entry->tag),
4105 entry->children ? _("has children") : _("no children"));
4106
4107 for (attr = entry->first_attr; attr; attr = attr->next)
4108 printf (" %-18s %s\n",
4109 get_AT_name (attr->attribute),
4110 get_FORM_name (attr->form));
4111 }
4112 }
4113 while (start);
4114
4115 printf ("\n");
4116
4117 return 1;
4118 }
4119
4120 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4121
4122 static void
4123 display_loc_list (struct dwarf_section *section,
4124 unsigned char **start_ptr,
4125 int debug_info_entry,
4126 unsigned long offset,
4127 unsigned long base_address,
4128 int has_frame_base)
4129 {
4130 unsigned char *start = *start_ptr;
4131 unsigned char *section_end = section->start + section->size;
4132 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
4133 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
4134 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
4135 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
4136
4137 dwarf_vma begin;
4138 dwarf_vma end;
4139 unsigned short length;
4140 int need_frame_base;
4141
4142 while (1)
4143 {
4144 if (start + 2 * pointer_size > section_end)
4145 {
4146 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4147 offset);
4148 break;
4149 }
4150
4151 printf (" %8.8lx ", offset + (start - *start_ptr));
4152
4153 /* Note: we use sign extension here in order to be sure that we can detect
4154 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4155 address will not affect the values that we display since we always show
4156 hex values, and always the bottom 32-bits. */
4157 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, section_end);
4158 SAFE_BYTE_GET_AND_INC (end, start, pointer_size, section_end);
4159
4160 if (begin == 0 && end == 0)
4161 {
4162 printf (_("<End of list>\n"));
4163 break;
4164 }
4165
4166 /* Check base address specifiers. */
4167 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4168 {
4169 base_address = end;
4170 print_dwarf_vma (begin, pointer_size);
4171 print_dwarf_vma (end, pointer_size);
4172 printf (_("(base address)\n"));
4173 continue;
4174 }
4175
4176 if (start + 2 > section_end)
4177 {
4178 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4179 offset);
4180 break;
4181 }
4182
4183 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4184
4185 if (start + length > section_end)
4186 {
4187 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4188 offset);
4189 break;
4190 }
4191
4192 print_dwarf_vma (begin + base_address, pointer_size);
4193 print_dwarf_vma (end + base_address, pointer_size);
4194
4195 putchar ('(');
4196 need_frame_base = decode_location_expression (start,
4197 pointer_size,
4198 offset_size,
4199 dwarf_version,
4200 length,
4201 cu_offset, section);
4202 putchar (')');
4203
4204 if (need_frame_base && !has_frame_base)
4205 printf (_(" [without DW_AT_frame_base]"));
4206
4207 if (begin == end)
4208 fputs (_(" (start == end)"), stdout);
4209 else if (begin > end)
4210 fputs (_(" (start > end)"), stdout);
4211
4212 putchar ('\n');
4213
4214 start += length;
4215 }
4216
4217 *start_ptr = start;
4218 }
4219
4220 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4221 right-adjusted in a field of length LEN, and followed by a space. */
4222
4223 static void
4224 print_addr_index (unsigned int idx, unsigned int len)
4225 {
4226 static char buf[15];
4227 snprintf (buf, sizeof (buf), "[%d]", idx);
4228 printf ("%*s ", len, buf);
4229 }
4230
4231 /* Display a location list from a .dwo section. It uses address indexes rather
4232 than embedded addresses. This code closely follows display_loc_list, but the
4233 two are sufficiently different that combining things is very ugly. */
4234
4235 static void
4236 display_loc_list_dwo (struct dwarf_section *section,
4237 unsigned char **start_ptr,
4238 int debug_info_entry,
4239 unsigned long offset,
4240 int has_frame_base)
4241 {
4242 unsigned char *start = *start_ptr;
4243 unsigned char *section_end = section->start + section->size;
4244 unsigned long cu_offset = debug_information [debug_info_entry].cu_offset;
4245 unsigned int pointer_size = debug_information [debug_info_entry].pointer_size;
4246 unsigned int offset_size = debug_information [debug_info_entry].offset_size;
4247 int dwarf_version = debug_information [debug_info_entry].dwarf_version;
4248 int entry_type;
4249 unsigned short length;
4250 int need_frame_base;
4251 unsigned int idx;
4252 unsigned int bytes_read;
4253
4254 while (1)
4255 {
4256 printf (" %8.8lx ", offset + (start - *start_ptr));
4257
4258 if (start >= section_end)
4259 {
4260 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4261 offset);
4262 break;
4263 }
4264
4265 SAFE_BYTE_GET_AND_INC (entry_type, start, 1, section_end);
4266 switch (entry_type)
4267 {
4268 case 0: /* A terminating entry. */
4269 *start_ptr = start;
4270 printf (_("<End of list>\n"));
4271 return;
4272 case 1: /* A base-address entry. */
4273 idx = read_uleb128 (start, &bytes_read, section_end);
4274 start += bytes_read;
4275 print_addr_index (idx, 8);
4276 printf (" ");
4277 printf (_("(base address selection entry)\n"));
4278 continue;
4279 case 2: /* A start/end entry. */
4280 idx = read_uleb128 (start, &bytes_read, section_end);
4281 start += bytes_read;
4282 print_addr_index (idx, 8);
4283 idx = read_uleb128 (start, &bytes_read, section_end);
4284 start += bytes_read;
4285 print_addr_index (idx, 8);
4286 break;
4287 case 3: /* A start/length entry. */
4288 idx = read_uleb128 (start, &bytes_read, section_end);
4289 start += bytes_read;
4290 print_addr_index (idx, 8);
4291 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4292 printf ("%08x ", idx);
4293 break;
4294 case 4: /* An offset pair entry. */
4295 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4296 printf ("%08x ", idx);
4297 SAFE_BYTE_GET_AND_INC (idx, start, 4, section_end);
4298 printf ("%08x ", idx);
4299 break;
4300 default:
4301 warn (_("Unknown location list entry type 0x%x.\n"), entry_type);
4302 *start_ptr = start;
4303 return;
4304 }
4305
4306 if (start + 2 > section_end)
4307 {
4308 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4309 offset);
4310 break;
4311 }
4312
4313 SAFE_BYTE_GET_AND_INC (length, start, 2, section_end);
4314 if (start + length > section_end)
4315 {
4316 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4317 offset);
4318 break;
4319 }
4320
4321 putchar ('(');
4322 need_frame_base = decode_location_expression (start,
4323 pointer_size,
4324 offset_size,
4325 dwarf_version,
4326 length,
4327 cu_offset, section);
4328 putchar (')');
4329
4330 if (need_frame_base && !has_frame_base)
4331 printf (_(" [without DW_AT_frame_base]"));
4332
4333 putchar ('\n');
4334
4335 start += length;
4336 }
4337
4338 *start_ptr = start;
4339 }
4340
4341 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4342
4343 static dwarf_vma *loc_offsets;
4344
4345 static int
4346 loc_offsets_compar (const void *ap, const void *bp)
4347 {
4348 dwarf_vma a = loc_offsets[*(const unsigned int *) ap];
4349 dwarf_vma b = loc_offsets[*(const unsigned int *) bp];
4350
4351 return (a > b) - (b > a);
4352 }
4353
4354 static int
4355 display_debug_loc (struct dwarf_section *section, void *file)
4356 {
4357 unsigned char *start = section->start;
4358 unsigned long bytes;
4359 unsigned char *section_begin = start;
4360 unsigned int num_loc_list = 0;
4361 unsigned long last_offset = 0;
4362 unsigned int first = 0;
4363 unsigned int i;
4364 unsigned int j;
4365 unsigned int k;
4366 int seen_first_offset = 0;
4367 int locs_sorted = 1;
4368 unsigned char *next;
4369 unsigned int *array = NULL;
4370 const char *suffix = strrchr (section->name, '.');
4371 int is_dwo = 0;
4372
4373 if (suffix && strcmp (suffix, ".dwo") == 0)
4374 is_dwo = 1;
4375
4376 bytes = section->size;
4377
4378 if (bytes == 0)
4379 {
4380 printf (_("\nThe %s section is empty.\n"), section->name);
4381 return 0;
4382 }
4383
4384 if (load_debug_info (file) == 0)
4385 {
4386 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4387 section->name);
4388 return 0;
4389 }
4390
4391 /* Check the order of location list in .debug_info section. If
4392 offsets of location lists are in the ascending order, we can
4393 use `debug_information' directly. */
4394 for (i = 0; i < num_debug_info_entries; i++)
4395 {
4396 unsigned int num;
4397
4398 num = debug_information [i].num_loc_offsets;
4399 if (num > num_loc_list)
4400 num_loc_list = num;
4401
4402 /* Check if we can use `debug_information' directly. */
4403 if (locs_sorted && num != 0)
4404 {
4405 if (!seen_first_offset)
4406 {
4407 /* This is the first location list. */
4408 last_offset = debug_information [i].loc_offsets [0];
4409 first = i;
4410 seen_first_offset = 1;
4411 j = 1;
4412 }
4413 else
4414 j = 0;
4415
4416 for (; j < num; j++)
4417 {
4418 if (last_offset >
4419 debug_information [i].loc_offsets [j])
4420 {
4421 locs_sorted = 0;
4422 break;
4423 }
4424 last_offset = debug_information [i].loc_offsets [j];
4425 }
4426 }
4427 }
4428
4429 if (!seen_first_offset)
4430 error (_("No location lists in .debug_info section!\n"));
4431
4432 if (debug_information [first].num_loc_offsets > 0
4433 && debug_information [first].loc_offsets [0] != 0)
4434 warn (_("Location lists in %s section start at 0x%s\n"),
4435 section->name,
4436 dwarf_vmatoa ("x", debug_information [first].loc_offsets [0]));
4437
4438 if (!locs_sorted)
4439 array = (unsigned int *) xcmalloc (num_loc_list, sizeof (unsigned int));
4440 printf (_("Contents of the %s section:\n\n"), section->name);
4441 printf (_(" Offset Begin End Expression\n"));
4442
4443 seen_first_offset = 0;
4444 for (i = first; i < num_debug_info_entries; i++)
4445 {
4446 unsigned long offset;
4447 unsigned long base_address;
4448 int has_frame_base;
4449
4450 if (!locs_sorted)
4451 {
4452 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4453 array[k] = k;
4454 loc_offsets = debug_information [i].loc_offsets;
4455 qsort (array, debug_information [i].num_loc_offsets,
4456 sizeof (*array), loc_offsets_compar);
4457 }
4458
4459 for (k = 0; k < debug_information [i].num_loc_offsets; k++)
4460 {
4461 j = locs_sorted ? k : array[k];
4462 if (k
4463 && debug_information [i].loc_offsets [locs_sorted
4464 ? k - 1 : array [k - 1]]
4465 == debug_information [i].loc_offsets [j])
4466 continue;
4467 has_frame_base = debug_information [i].have_frame_base [j];
4468 offset = debug_information [i].loc_offsets [j];
4469 next = section_begin + offset;
4470 base_address = debug_information [i].base_address;
4471
4472 if (!seen_first_offset)
4473 seen_first_offset = 1;
4474 else
4475 {
4476 if (start < next)
4477 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4478 (unsigned long) (start - section_begin),
4479 (unsigned long) (next - section_begin));
4480 else if (start > next)
4481 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4482 (unsigned long) (start - section_begin),
4483 (unsigned long) (next - section_begin));
4484 }
4485 start = next;
4486
4487 if (offset >= bytes)
4488 {
4489 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4490 offset);
4491 continue;
4492 }
4493
4494 if (is_dwo)
4495 display_loc_list_dwo (section, &start, i, offset, has_frame_base);
4496 else
4497 display_loc_list (section, &start, i, offset, base_address,
4498 has_frame_base);
4499 }
4500 }
4501
4502 if (start < section->start + section->size)
4503 warn (_("There are %ld unused bytes at the end of section %s\n"),
4504 (long) (section->start + section->size - start), section->name);
4505 putchar ('\n');
4506 free (array);
4507 return 1;
4508 }
4509
4510 static int
4511 display_debug_str (struct dwarf_section *section,
4512 void *file ATTRIBUTE_UNUSED)
4513 {
4514 unsigned char *start = section->start;
4515 unsigned long bytes = section->size;
4516 dwarf_vma addr = section->address;
4517
4518 if (bytes == 0)
4519 {
4520 printf (_("\nThe %s section is empty.\n"), section->name);
4521 return 0;
4522 }
4523
4524 printf (_("Contents of the %s section:\n\n"), section->name);
4525
4526 while (bytes)
4527 {
4528 int j;
4529 int k;
4530 int lbytes;
4531
4532 lbytes = (bytes > 16 ? 16 : bytes);
4533
4534 printf (" 0x%8.8lx ", (unsigned long) addr);
4535
4536 for (j = 0; j < 16; j++)
4537 {
4538 if (j < lbytes)
4539 printf ("%2.2x", start[j]);
4540 else
4541 printf (" ");
4542
4543 if ((j & 3) == 3)
4544 printf (" ");
4545 }
4546
4547 for (j = 0; j < lbytes; j++)
4548 {
4549 k = start[j];
4550 if (k >= ' ' && k < 0x80)
4551 printf ("%c", k);
4552 else
4553 printf (".");
4554 }
4555
4556 putchar ('\n');
4557
4558 start += lbytes;
4559 addr += lbytes;
4560 bytes -= lbytes;
4561 }
4562
4563 putchar ('\n');
4564
4565 return 1;
4566 }
4567
4568 static int
4569 display_debug_info (struct dwarf_section *section, void *file)
4570 {
4571 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4572 }
4573
4574 static int
4575 display_debug_types (struct dwarf_section *section, void *file)
4576 {
4577 return process_debug_info (section, file, section->abbrev_sec, 0, 1);
4578 }
4579
4580 static int
4581 display_trace_info (struct dwarf_section *section, void *file)
4582 {
4583 return process_debug_info (section, file, section->abbrev_sec, 0, 0);
4584 }
4585
4586 static int
4587 display_debug_aranges (struct dwarf_section *section,
4588 void *file ATTRIBUTE_UNUSED)
4589 {
4590 unsigned char *start = section->start;
4591 unsigned char *end = start + section->size;
4592
4593 printf (_("Contents of the %s section:\n\n"), section->name);
4594
4595 /* It does not matter if this load fails,
4596 we test for that later on. */
4597 load_debug_info (file);
4598
4599 while (start < end)
4600 {
4601 unsigned char *hdrptr;
4602 DWARF2_Internal_ARange arange;
4603 unsigned char *addr_ranges;
4604 dwarf_vma length;
4605 dwarf_vma address;
4606 unsigned char address_size;
4607 int excess;
4608 unsigned int offset_size;
4609 unsigned int initial_length_size;
4610
4611 hdrptr = start;
4612
4613 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 4, end);
4614 if (arange.ar_length == 0xffffffff)
4615 {
4616 SAFE_BYTE_GET_AND_INC (arange.ar_length, hdrptr, 8, end);
4617 offset_size = 8;
4618 initial_length_size = 12;
4619 }
4620 else
4621 {
4622 offset_size = 4;
4623 initial_length_size = 4;
4624 }
4625
4626 SAFE_BYTE_GET_AND_INC (arange.ar_version, hdrptr, 2, end);
4627 SAFE_BYTE_GET_AND_INC (arange.ar_info_offset, hdrptr, offset_size, end);
4628
4629 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE
4630 && num_debug_info_entries > 0
4631 && find_debug_info_for_offset (arange.ar_info_offset) == NULL)
4632 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4633 (unsigned long) arange.ar_info_offset, section->name);
4634
4635 SAFE_BYTE_GET_AND_INC (arange.ar_pointer_size, hdrptr, 1, end);
4636 SAFE_BYTE_GET_AND_INC (arange.ar_segment_size, hdrptr, 1, end);
4637
4638 if (arange.ar_version != 2 && arange.ar_version != 3)
4639 {
4640 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4641 break;
4642 }
4643
4644 printf (_(" Length: %ld\n"),
4645 (long) arange.ar_length);
4646 printf (_(" Version: %d\n"), arange.ar_version);
4647 printf (_(" Offset into .debug_info: 0x%lx\n"),
4648 (unsigned long) arange.ar_info_offset);
4649 printf (_(" Pointer Size: %d\n"), arange.ar_pointer_size);
4650 printf (_(" Segment Size: %d\n"), arange.ar_segment_size);
4651
4652 address_size = arange.ar_pointer_size + arange.ar_segment_size;
4653
4654 if (address_size == 0)
4655 {
4656 error (_("Invalid address size in %s section!\n"),
4657 section->name);
4658 break;
4659 }
4660
4661 /* The DWARF spec does not require that the address size be a power
4662 of two, but we do. This will have to change if we ever encounter
4663 an uneven architecture. */
4664 if ((address_size & (address_size - 1)) != 0)
4665 {
4666 warn (_("Pointer size + Segment size is not a power of two.\n"));
4667 break;
4668 }
4669
4670 if (address_size > 4)
4671 printf (_("\n Address Length\n"));
4672 else
4673 printf (_("\n Address Length\n"));
4674
4675 addr_ranges = hdrptr;
4676
4677 /* Must pad to an alignment boundary that is twice the address size. */
4678 excess = (hdrptr - start) % (2 * address_size);
4679 if (excess)
4680 addr_ranges += (2 * address_size) - excess;
4681
4682 start += arange.ar_length + initial_length_size;
4683
4684 while (addr_ranges + 2 * address_size <= start)
4685 {
4686 SAFE_BYTE_GET_AND_INC (address, addr_ranges, address_size, end);
4687 SAFE_BYTE_GET_AND_INC (length, addr_ranges, address_size, end);
4688
4689 printf (" ");
4690 print_dwarf_vma (address, address_size);
4691 print_dwarf_vma (length, address_size);
4692 putchar ('\n');
4693 }
4694 }
4695
4696 printf ("\n");
4697
4698 return 1;
4699 }
4700
4701 /* Comparison function for qsort. */
4702 static int
4703 comp_addr_base (const void * v0, const void * v1)
4704 {
4705 debug_info * info0 = (debug_info *) v0;
4706 debug_info * info1 = (debug_info *) v1;
4707 return info0->addr_base - info1->addr_base;
4708 }
4709
4710 /* Display the debug_addr section. */
4711 static int
4712 display_debug_addr (struct dwarf_section *section,
4713 void *file)
4714 {
4715 debug_info **debug_addr_info;
4716 unsigned char *entry;
4717 unsigned char *end;
4718 unsigned int i;
4719 unsigned int count;
4720
4721 if (section->size == 0)
4722 {
4723 printf (_("\nThe %s section is empty.\n"), section->name);
4724 return 0;
4725 }
4726
4727 if (load_debug_info (file) == 0)
4728 {
4729 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4730 section->name);
4731 return 0;
4732 }
4733
4734 printf (_("Contents of the %s section:\n\n"), section->name);
4735
4736 debug_addr_info = (debug_info **) xmalloc ((num_debug_info_entries + 1)
4737 * sizeof (debug_info *));
4738
4739 count = 0;
4740 for (i = 0; i < num_debug_info_entries; i++)
4741 {
4742 if (debug_information [i].addr_base != DEBUG_INFO_UNAVAILABLE)
4743 debug_addr_info [count++] = &debug_information [i];
4744 }
4745
4746 /* Add a sentinel to make iteration convenient. */
4747 debug_addr_info [count] = (debug_info *) xmalloc (sizeof (debug_info));
4748 debug_addr_info [count]->addr_base = section->size;
4749
4750 qsort (debug_addr_info, count, sizeof (debug_info *), comp_addr_base);
4751 for (i = 0; i < count; i++)
4752 {
4753 unsigned int idx;
4754 unsigned int address_size = debug_addr_info [i]->pointer_size;
4755
4756 printf (_(" For compilation unit at offset 0x%s:\n"),
4757 dwarf_vmatoa ("x", debug_addr_info [i]->cu_offset));
4758
4759 printf (_("\tIndex\tAddress\n"));
4760 entry = section->start + debug_addr_info [i]->addr_base;
4761 end = section->start + debug_addr_info [i + 1]->addr_base;
4762 idx = 0;
4763 while (entry < end)
4764 {
4765 dwarf_vma base = byte_get (entry, address_size);
4766 printf (_("\t%d:\t"), idx);
4767 print_dwarf_vma (base, address_size);
4768 printf ("\n");
4769 entry += address_size;
4770 idx++;
4771 }
4772 }
4773 printf ("\n");
4774
4775 free (debug_addr_info);
4776 return 1;
4777 }
4778
4779 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
4780 static int
4781 display_debug_str_offsets (struct dwarf_section *section,
4782 void *file ATTRIBUTE_UNUSED)
4783 {
4784 if (section->size == 0)
4785 {
4786 printf (_("\nThe %s section is empty.\n"), section->name);
4787 return 0;
4788 }
4789 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
4790 what the offset size is for this section. */
4791 return 1;
4792 }
4793
4794 /* Each debug_information[x].range_lists[y] gets this representation for
4795 sorting purposes. */
4796
4797 struct range_entry
4798 {
4799 /* The debug_information[x].range_lists[y] value. */
4800 unsigned long ranges_offset;
4801
4802 /* Original debug_information to find parameters of the data. */
4803 debug_info *debug_info_p;
4804 };
4805
4806 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
4807
4808 static int
4809 range_entry_compar (const void *ap, const void *bp)
4810 {
4811 const struct range_entry *a_re = (const struct range_entry *) ap;
4812 const struct range_entry *b_re = (const struct range_entry *) bp;
4813 const unsigned long a = a_re->ranges_offset;
4814 const unsigned long b = b_re->ranges_offset;
4815
4816 return (a > b) - (b > a);
4817 }
4818
4819 static int
4820 display_debug_ranges (struct dwarf_section *section,
4821 void *file ATTRIBUTE_UNUSED)
4822 {
4823 unsigned char *start = section->start;
4824 unsigned char *last_start = start;
4825 unsigned long bytes = section->size;
4826 unsigned char *section_begin = start;
4827 unsigned char *finish = start + bytes;
4828 unsigned int num_range_list, i;
4829 struct range_entry *range_entries, *range_entry_fill;
4830
4831 if (bytes == 0)
4832 {
4833 printf (_("\nThe %s section is empty.\n"), section->name);
4834 return 0;
4835 }
4836
4837 if (load_debug_info (file) == 0)
4838 {
4839 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4840 section->name);
4841 return 0;
4842 }
4843
4844 num_range_list = 0;
4845 for (i = 0; i < num_debug_info_entries; i++)
4846 num_range_list += debug_information [i].num_range_lists;
4847
4848 if (num_range_list == 0)
4849 {
4850 /* This can happen when the file was compiled with -gsplit-debug
4851 which removes references to range lists from the primary .o file. */
4852 printf (_("No range lists in .debug_info section.\n"));
4853 return 1;
4854 }
4855
4856 range_entries = (struct range_entry *)
4857 xmalloc (sizeof (*range_entries) * num_range_list);
4858 range_entry_fill = range_entries;
4859
4860 for (i = 0; i < num_debug_info_entries; i++)
4861 {
4862 debug_info *debug_info_p = &debug_information[i];
4863 unsigned int j;
4864
4865 for (j = 0; j < debug_info_p->num_range_lists; j++)
4866 {
4867 range_entry_fill->ranges_offset = debug_info_p->range_lists[j];
4868 range_entry_fill->debug_info_p = debug_info_p;
4869 range_entry_fill++;
4870 }
4871 }
4872
4873 qsort (range_entries, num_range_list, sizeof (*range_entries),
4874 range_entry_compar);
4875
4876 if (dwarf_check != 0 && range_entries[0].ranges_offset != 0)
4877 warn (_("Range lists in %s section start at 0x%lx\n"),
4878 section->name, range_entries[0].ranges_offset);
4879
4880 printf (_("Contents of the %s section:\n\n"), section->name);
4881 printf (_(" Offset Begin End\n"));
4882
4883 for (i = 0; i < num_range_list; i++)
4884 {
4885 struct range_entry *range_entry = &range_entries[i];
4886 debug_info *debug_info_p = range_entry->debug_info_p;
4887 unsigned int pointer_size;
4888 unsigned long offset;
4889 unsigned char *next;
4890 unsigned long base_address;
4891
4892 pointer_size = debug_info_p->pointer_size;
4893
4894 offset = range_entry->ranges_offset;
4895 next = section_begin + offset;
4896 base_address = debug_info_p->base_address;
4897
4898 if (dwarf_check != 0 && i > 0)
4899 {
4900 if (start < next)
4901 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
4902 (unsigned long) (start - section_begin),
4903 (unsigned long) (next - section_begin), section->name);
4904 else if (start > next)
4905 {
4906 if (next == last_start)
4907 continue;
4908 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
4909 (unsigned long) (start - section_begin),
4910 (unsigned long) (next - section_begin), section->name);
4911 }
4912 }
4913 start = next;
4914 last_start = next;
4915
4916 while (start < finish)
4917 {
4918 dwarf_vma begin;
4919 dwarf_vma end;
4920
4921 /* Note: we use sign extension here in order to be sure that
4922 we can detect the -1 escape value. Sign extension into the
4923 top 32 bits of a 32-bit address will not affect the values
4924 that we display since we always show hex values, and always
4925 the bottom 32-bits. */
4926 SAFE_BYTE_GET_AND_INC (begin, start, pointer_size, finish);
4927 if (start >= finish)
4928 break;
4929 SAFE_SIGNED_BYTE_GET_AND_INC (end, start, pointer_size, finish);
4930
4931 printf (" %8.8lx ", offset);
4932
4933 if (begin == 0 && end == 0)
4934 {
4935 printf (_("<End of list>\n"));
4936 break;
4937 }
4938
4939 /* Check base address specifiers. */
4940 if (begin == (dwarf_vma) -1 && end != (dwarf_vma) -1)
4941 {
4942 base_address = end;
4943 print_dwarf_vma (begin, pointer_size);
4944 print_dwarf_vma (end, pointer_size);
4945 printf ("(base address)\n");
4946 continue;
4947 }
4948
4949 print_dwarf_vma (begin + base_address, pointer_size);
4950 print_dwarf_vma (end + base_address, pointer_size);
4951
4952 if (begin == end)
4953 fputs (_("(start == end)"), stdout);
4954 else if (begin > end)
4955 fputs (_("(start > end)"), stdout);
4956
4957 putchar ('\n');
4958 }
4959 }
4960 putchar ('\n');
4961
4962 free (range_entries);
4963
4964 return 1;
4965 }
4966
4967 typedef struct Frame_Chunk
4968 {
4969 struct Frame_Chunk *next;
4970 unsigned char *chunk_start;
4971 int ncols;
4972 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
4973 short int *col_type;
4974 int *col_offset;
4975 char *augmentation;
4976 unsigned int code_factor;
4977 int data_factor;
4978 dwarf_vma pc_begin;
4979 dwarf_vma pc_range;
4980 int cfa_reg;
4981 int cfa_offset;
4982 int ra;
4983 unsigned char fde_encoding;
4984 unsigned char cfa_exp;
4985 unsigned char ptr_size;
4986 unsigned char segment_size;
4987 }
4988 Frame_Chunk;
4989
4990 static const char *const *dwarf_regnames;
4991 static unsigned int dwarf_regnames_count;
4992
4993 /* A marker for a col_type that means this column was never referenced
4994 in the frame info. */
4995 #define DW_CFA_unreferenced (-1)
4996
4997 /* Return 0 if not more space is needed, 1 if more space is needed,
4998 -1 for invalid reg. */
4999
5000 static int
5001 frame_need_space (Frame_Chunk *fc, unsigned int reg)
5002 {
5003 int prev = fc->ncols;
5004
5005 if (reg < (unsigned int) fc->ncols)
5006 return 0;
5007
5008 if (dwarf_regnames_count
5009 && reg > dwarf_regnames_count)
5010 return -1;
5011
5012 fc->ncols = reg + 1;
5013 fc->col_type = (short int *) xcrealloc (fc->col_type, fc->ncols,
5014 sizeof (short int));
5015 fc->col_offset = (int *) xcrealloc (fc->col_offset, fc->ncols, sizeof (int));
5016
5017 while (prev < fc->ncols)
5018 {
5019 fc->col_type[prev] = DW_CFA_unreferenced;
5020 fc->col_offset[prev] = 0;
5021 prev++;
5022 }
5023 return 1;
5024 }
5025
5026 static const char *const dwarf_regnames_i386[] =
5027 {
5028 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5029 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5030 "eip", "eflags", NULL, /* 8 - 10 */
5031 "st0", "st1", "st2", "st3", /* 11 - 14 */
5032 "st4", "st5", "st6", "st7", /* 15 - 18 */
5033 NULL, NULL, /* 19 - 20 */
5034 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5035 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5036 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5037 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5038 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5039 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL, /* 40 - 47 */
5040 "tr", "ldtr", /* 48 - 49 */
5041 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 50 - 57 */
5042 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 58 - 65 */
5043 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 66 - 73 */
5044 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 74 - 81 */
5045 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 82 - 89 */
5046 NULL, NULL, NULL, /* 90 - 92 */
5047 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5048 };
5049
5050 void
5051 init_dwarf_regnames_i386 (void)
5052 {
5053 dwarf_regnames = dwarf_regnames_i386;
5054 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_i386);
5055 }
5056
5057 static const char *const dwarf_regnames_x86_64[] =
5058 {
5059 "rax", "rdx", "rcx", "rbx",
5060 "rsi", "rdi", "rbp", "rsp",
5061 "r8", "r9", "r10", "r11",
5062 "r12", "r13", "r14", "r15",
5063 "rip",
5064 "xmm0", "xmm1", "xmm2", "xmm3",
5065 "xmm4", "xmm5", "xmm6", "xmm7",
5066 "xmm8", "xmm9", "xmm10", "xmm11",
5067 "xmm12", "xmm13", "xmm14", "xmm15",
5068 "st0", "st1", "st2", "st3",
5069 "st4", "st5", "st6", "st7",
5070 "mm0", "mm1", "mm2", "mm3",
5071 "mm4", "mm5", "mm6", "mm7",
5072 "rflags",
5073 "es", "cs", "ss", "ds", "fs", "gs", NULL, NULL,
5074 "fs.base", "gs.base", NULL, NULL,
5075 "tr", "ldtr",
5076 "mxcsr", "fcw", "fsw",
5077 "xmm16", "xmm17", "xmm18", "xmm19",
5078 "xmm20", "xmm21", "xmm22", "xmm23",
5079 "xmm24", "xmm25", "xmm26", "xmm27",
5080 "xmm28", "xmm29", "xmm30", "xmm31",
5081 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 83 - 90 */
5082 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 91 - 98 */
5083 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 99 - 106 */
5084 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, /* 107 - 114 */
5085 NULL, NULL, NULL, /* 115 - 117 */
5086 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5087 };
5088
5089 void
5090 init_dwarf_regnames_x86_64 (void)
5091 {
5092 dwarf_regnames = dwarf_regnames_x86_64;
5093 dwarf_regnames_count = ARRAY_SIZE (dwarf_regnames_x86_64);
5094 }
5095
5096 void
5097 init_dwarf_regnames (unsigned int e_machine)
5098 {
5099 switch (e_machine)
5100 {
5101 case EM_386:
5102 case EM_486:
5103 init_dwarf_regnames_i386 ();
5104 break;
5105
5106 case EM_X86_64:
5107 case EM_L1OM:
5108 case EM_K1OM:
5109 init_dwarf_regnames_x86_64 ();
5110 break;
5111
5112 default:
5113 break;
5114 }
5115 }
5116
5117 static const char *
5118 regname (unsigned int regno, int row)
5119 {
5120 static char reg[64];
5121 if (dwarf_regnames
5122 && regno < dwarf_regnames_count
5123 && dwarf_regnames [regno] != NULL)
5124 {
5125 if (row)
5126 return dwarf_regnames [regno];
5127 snprintf (reg, sizeof (reg), "r%d (%s)", regno,
5128 dwarf_regnames [regno]);
5129 }
5130 else
5131 snprintf (reg, sizeof (reg), "r%d", regno);
5132 return reg;
5133 }
5134
5135 static void
5136 frame_display_row (Frame_Chunk *fc, int *need_col_headers, int *max_regs)
5137 {
5138 int r;
5139 char tmp[100];
5140
5141 if (*max_regs < fc->ncols)
5142 *max_regs = fc->ncols;
5143
5144 if (*need_col_headers)
5145 {
5146 static const char *sloc = " LOC";
5147
5148 *need_col_headers = 0;
5149
5150 printf ("%-*s CFA ", eh_addr_size * 2, sloc);
5151
5152 for (r = 0; r < *max_regs; r++)
5153 if (fc->col_type[r] != DW_CFA_unreferenced)
5154 {
5155 if (r == fc->ra)
5156 printf ("ra ");
5157 else
5158 printf ("%-5s ", regname (r, 1));
5159 }
5160
5161 printf ("\n");
5162 }
5163
5164 print_dwarf_vma (fc->pc_begin, eh_addr_size);
5165 if (fc->cfa_exp)
5166 strcpy (tmp, "exp");
5167 else
5168 sprintf (tmp, "%s%+d", regname (fc->cfa_reg, 1), fc->cfa_offset);
5169 printf ("%-8s ", tmp);
5170
5171 for (r = 0; r < fc->ncols; r++)
5172 {
5173 if (fc->col_type[r] != DW_CFA_unreferenced)
5174 {
5175 switch (fc->col_type[r])
5176 {
5177 case DW_CFA_undefined:
5178 strcpy (tmp, "u");
5179 break;
5180 case DW_CFA_same_value:
5181 strcpy (tmp, "s");
5182 break;
5183 case DW_CFA_offset:
5184 sprintf (tmp, "c%+d", fc->col_offset[r]);
5185 break;
5186 case DW_CFA_val_offset:
5187 sprintf (tmp, "v%+d", fc->col_offset[r]);
5188 break;
5189 case DW_CFA_register:
5190 sprintf (tmp, "%s", regname (fc->col_offset[r], 0));
5191 break;
5192 case DW_CFA_expression:
5193 strcpy (tmp, "exp");
5194 break;
5195 case DW_CFA_val_expression:
5196 strcpy (tmp, "vexp");
5197 break;
5198 default:
5199 strcpy (tmp, "n/a");
5200 break;
5201 }
5202 printf ("%-5s ", tmp);
5203 }
5204 }
5205 printf ("\n");
5206 }
5207
5208 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end);
5209 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5210 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5211
5212 static int
5213 display_debug_frames (struct dwarf_section *section,
5214 void *file ATTRIBUTE_UNUSED)
5215 {
5216 unsigned char *start = section->start;
5217 unsigned char *end = start + section->size;
5218 unsigned char *section_start = start;
5219 Frame_Chunk *chunks = 0;
5220 Frame_Chunk *remembered_state = 0;
5221 Frame_Chunk *rs;
5222 int is_eh = strcmp (section->name, ".eh_frame") == 0;
5223 unsigned int length_return;
5224 int max_regs = 0;
5225 const char *bad_reg = _("bad register: ");
5226 int saved_eh_addr_size = eh_addr_size;
5227
5228 printf (_("Contents of the %s section:\n"), section->name);
5229
5230 while (start < end)
5231 {
5232 unsigned char *saved_start;
5233 unsigned char *block_end;
5234 dwarf_vma length;
5235 dwarf_vma cie_id;
5236 Frame_Chunk *fc;
5237 Frame_Chunk *cie;
5238 int need_col_headers = 1;
5239 unsigned char *augmentation_data = NULL;
5240 unsigned long augmentation_data_len = 0;
5241 unsigned int encoded_ptr_size = saved_eh_addr_size;
5242 unsigned int offset_size;
5243 unsigned int initial_length_size;
5244
5245 saved_start = start;
5246
5247 SAFE_BYTE_GET_AND_INC (length, start, 4, end);
5248 if (length == 0)
5249 {
5250 printf ("\n%08lx ZERO terminator\n\n",
5251 (unsigned long)(saved_start - section_start));
5252 continue;
5253 }
5254
5255 if (length == 0xffffffff)
5256 {
5257 SAFE_BYTE_GET_AND_INC (length, start, 8, end);
5258 offset_size = 8;
5259 initial_length_size = 12;
5260 }
5261 else
5262 {
5263 offset_size = 4;
5264 initial_length_size = 4;
5265 }
5266
5267 block_end = saved_start + length + initial_length_size;
5268 if (block_end > end)
5269 {
5270 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5271 dwarf_vmatoa_1 (NULL, length, offset_size),
5272 (unsigned long) (saved_start - section_start));
5273 block_end = end;
5274 }
5275
5276 SAFE_BYTE_GET_AND_INC (cie_id, start, offset_size, end);
5277
5278 if (is_eh ? (cie_id == 0) : ((offset_size == 4 && cie_id == DW_CIE_ID)
5279 || (offset_size == 8 && cie_id == DW64_CIE_ID)))
5280 {
5281 int version;
5282
5283 fc = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5284 memset (fc, 0, sizeof (Frame_Chunk));
5285
5286 fc->next = chunks;
5287 chunks = fc;
5288 fc->chunk_start = saved_start;
5289 fc->ncols = 0;
5290 fc->col_type = (short int *) xmalloc (sizeof (short int));
5291 fc->col_offset = (int *) xmalloc (sizeof (int));
5292 frame_need_space (fc, max_regs - 1);
5293
5294 version = *start++;
5295
5296 fc->augmentation = (char *) start;
5297 start = (unsigned char *) strchr ((char *) start, '\0') + 1;
5298
5299 if (strcmp (fc->augmentation, "eh") == 0)
5300 start += eh_addr_size;
5301
5302 if (version >= 4)
5303 {
5304 GET (fc->ptr_size, 1);
5305 GET (fc->segment_size, 1);
5306 eh_addr_size = fc->ptr_size;
5307 }
5308 else
5309 {
5310 fc->ptr_size = eh_addr_size;
5311 fc->segment_size = 0;
5312 }
5313 fc->code_factor = LEB ();
5314 fc->data_factor = SLEB ();
5315 if (version == 1)
5316 {
5317 GET (fc->ra, 1);
5318 }
5319 else
5320 {
5321 fc->ra = LEB ();
5322 }
5323
5324 if (fc->augmentation[0] == 'z')
5325 {
5326 augmentation_data_len = LEB ();
5327 augmentation_data = start;
5328 start += augmentation_data_len;
5329 }
5330 cie = fc;
5331
5332 printf ("\n%08lx ", (unsigned long) (saved_start - section_start));
5333 print_dwarf_vma (length, fc->ptr_size);
5334 print_dwarf_vma (cie_id, offset_size);
5335
5336 if (do_debug_frames_interp)
5337 {
5338 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc->augmentation,
5339 fc->code_factor, fc->data_factor, fc->ra);
5340 }
5341 else
5342 {
5343 printf ("CIE\n");
5344 printf (" Version: %d\n", version);
5345 printf (" Augmentation: \"%s\"\n", fc->augmentation);
5346 if (version >= 4)
5347 {
5348 printf (" Pointer Size: %u\n", fc->ptr_size);
5349 printf (" Segment Size: %u\n", fc->segment_size);
5350 }
5351 printf (" Code alignment factor: %u\n", fc->code_factor);
5352 printf (" Data alignment factor: %d\n", fc->data_factor);
5353 printf (" Return address column: %d\n", fc->ra);
5354
5355 if (augmentation_data_len)
5356 {
5357 unsigned long i;
5358 printf (" Augmentation data: ");
5359 for (i = 0; i < augmentation_data_len; ++i)
5360 printf (" %02x", augmentation_data[i]);
5361 putchar ('\n');
5362 }
5363 putchar ('\n');
5364 }
5365
5366 if (augmentation_data_len)
5367 {
5368 unsigned char *p, *q;
5369 p = (unsigned char *) fc->augmentation + 1;
5370 q = augmentation_data;
5371
5372 while (1)
5373 {
5374 if (*p == 'L')
5375 q++;
5376 else if (*p == 'P')
5377 q += 1 + size_of_encoded_value (*q);
5378 else if (*p == 'R')
5379 fc->fde_encoding = *q++;
5380 else if (*p == 'S')
5381 ;
5382 else
5383 break;
5384 p++;
5385 }
5386
5387 if (fc->fde_encoding)
5388 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5389 }
5390
5391 frame_need_space (fc, fc->ra);
5392 }
5393 else
5394 {
5395 unsigned char *look_for;
5396 static Frame_Chunk fde_fc;
5397 unsigned long segment_selector;
5398
5399 fc = & fde_fc;
5400 memset (fc, 0, sizeof (Frame_Chunk));
5401
5402 look_for = is_eh ? start - 4 - cie_id : section_start + cie_id;
5403
5404 for (cie = chunks; cie ; cie = cie->next)
5405 if (cie->chunk_start == look_for)
5406 break;
5407
5408 if (!cie)
5409 {
5410 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
5411 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5412 (unsigned long) (saved_start - section_start));
5413 fc->ncols = 0;
5414 fc->col_type = (short int *) xmalloc (sizeof (short int));
5415 fc->col_offset = (int *) xmalloc (sizeof (int));
5416 frame_need_space (fc, max_regs - 1);
5417 cie = fc;
5418 fc->augmentation = "";
5419 fc->fde_encoding = 0;
5420 fc->ptr_size = eh_addr_size;
5421 fc->segment_size = 0;
5422 }
5423 else
5424 {
5425 fc->ncols = cie->ncols;
5426 fc->col_type = (short int *) xcmalloc (fc->ncols, sizeof (short int));
5427 fc->col_offset = (int *) xcmalloc (fc->ncols, sizeof (int));
5428 memcpy (fc->col_type, cie->col_type, fc->ncols * sizeof (short int));
5429 memcpy (fc->col_offset, cie->col_offset, fc->ncols * sizeof (int));
5430 fc->augmentation = cie->augmentation;
5431 fc->ptr_size = cie->ptr_size;
5432 eh_addr_size = cie->ptr_size;
5433 fc->segment_size = cie->segment_size;
5434 fc->code_factor = cie->code_factor;
5435 fc->data_factor = cie->data_factor;
5436 fc->cfa_reg = cie->cfa_reg;
5437 fc->cfa_offset = cie->cfa_offset;
5438 fc->ra = cie->ra;
5439 frame_need_space (fc, max_regs - 1);
5440 fc->fde_encoding = cie->fde_encoding;
5441 }
5442
5443 if (fc->fde_encoding)
5444 encoded_ptr_size = size_of_encoded_value (fc->fde_encoding);
5445
5446 segment_selector = 0;
5447 if (fc->segment_size)
5448 {
5449 SAFE_BYTE_GET_AND_INC (segment_selector, start, fc->segment_size, end);
5450 }
5451 fc->pc_begin = get_encoded_value (start, fc->fde_encoding, section);
5452 start += encoded_ptr_size;
5453
5454 /* FIXME: It appears that sometimes the final pc_range value is
5455 encoded in less than encoded_ptr_size bytes. See the x86_64
5456 run of the "objcopy on compressed debug sections" test for an
5457 example of this. */
5458 SAFE_BYTE_GET_AND_INC (fc->pc_range, start, encoded_ptr_size, end);
5459
5460 if (cie->augmentation[0] == 'z')
5461 {
5462 augmentation_data_len = LEB ();
5463 augmentation_data = start;
5464 start += augmentation_data_len;
5465 }
5466
5467 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
5468 (unsigned long)(saved_start - section_start),
5469 dwarf_vmatoa_1 (NULL, length, fc->ptr_size),
5470 dwarf_vmatoa_1 (NULL, cie_id, offset_size),
5471 (unsigned long)(cie->chunk_start - section_start));
5472
5473 if (fc->segment_size)
5474 printf ("%04lx:", segment_selector);
5475
5476 printf ("%s..%s\n",
5477 dwarf_vmatoa_1 (NULL, fc->pc_begin, fc->ptr_size),
5478 dwarf_vmatoa_1 (NULL, fc->pc_begin + fc->pc_range, fc->ptr_size));
5479
5480 if (! do_debug_frames_interp && augmentation_data_len)
5481 {
5482 unsigned long i;
5483
5484 printf (" Augmentation data: ");
5485 for (i = 0; i < augmentation_data_len; ++i)
5486 printf (" %02x", augmentation_data[i]);
5487 putchar ('\n');
5488 putchar ('\n');
5489 }
5490 }
5491
5492 /* At this point, fc is the current chunk, cie (if any) is set, and
5493 we're about to interpret instructions for the chunk. */
5494 /* ??? At present we need to do this always, since this sizes the
5495 fc->col_type and fc->col_offset arrays, which we write into always.
5496 We should probably split the interpreted and non-interpreted bits
5497 into two different routines, since there's so much that doesn't
5498 really overlap between them. */
5499 if (1 || do_debug_frames_interp)
5500 {
5501 /* Start by making a pass over the chunk, allocating storage
5502 and taking note of what registers are used. */
5503 unsigned char *tmp = start;
5504
5505 while (start < block_end)
5506 {
5507 unsigned op, opa;
5508 unsigned long reg, temp;
5509
5510 op = *start++;
5511 opa = op & 0x3f;
5512 if (op & 0xc0)
5513 op &= 0xc0;
5514
5515 /* Warning: if you add any more cases to this switch, be
5516 sure to add them to the corresponding switch below. */
5517 switch (op)
5518 {
5519 case DW_CFA_advance_loc:
5520 break;
5521 case DW_CFA_offset:
5522 LEB ();
5523 if (frame_need_space (fc, opa) >= 0)
5524 fc->col_type[opa] = DW_CFA_undefined;
5525 break;
5526 case DW_CFA_restore:
5527 if (frame_need_space (fc, opa) >= 0)
5528 fc->col_type[opa] = DW_CFA_undefined;
5529 break;
5530 case DW_CFA_set_loc:
5531 start += encoded_ptr_size;
5532 break;
5533 case DW_CFA_advance_loc1:
5534 start += 1;
5535 break;
5536 case DW_CFA_advance_loc2:
5537 start += 2;
5538 break;
5539 case DW_CFA_advance_loc4:
5540 start += 4;
5541 break;
5542 case DW_CFA_offset_extended:
5543 case DW_CFA_val_offset:
5544 reg = LEB (); LEB ();
5545 if (frame_need_space (fc, reg) >= 0)
5546 fc->col_type[reg] = DW_CFA_undefined;
5547 break;
5548 case DW_CFA_restore_extended:
5549 reg = LEB ();
5550 frame_need_space (fc, reg);
5551 if (frame_need_space (fc, reg) >= 0)
5552 fc->col_type[reg] = DW_CFA_undefined;
5553 break;
5554 case DW_CFA_undefined:
5555 reg = LEB ();
5556 if (frame_need_space (fc, reg) >= 0)
5557 fc->col_type[reg] = DW_CFA_undefined;
5558 break;
5559 case DW_CFA_same_value:
5560 reg = LEB ();
5561 if (frame_need_space (fc, reg) >= 0)
5562 fc->col_type[reg] = DW_CFA_undefined;
5563 break;
5564 case DW_CFA_register:
5565 reg = LEB (); LEB ();
5566 if (frame_need_space (fc, reg) >= 0)
5567 fc->col_type[reg] = DW_CFA_undefined;
5568 break;
5569 case DW_CFA_def_cfa:
5570 LEB (); LEB ();
5571 break;
5572 case DW_CFA_def_cfa_register:
5573 LEB ();
5574 break;
5575 case DW_CFA_def_cfa_offset:
5576 LEB ();
5577 break;
5578 case DW_CFA_def_cfa_expression:
5579 temp = LEB ();
5580 start += temp;
5581 break;
5582 case DW_CFA_expression:
5583 case DW_CFA_val_expression:
5584 reg = LEB ();
5585 temp = LEB ();
5586 start += temp;
5587 if (frame_need_space (fc, reg) >= 0)
5588 fc->col_type[reg] = DW_CFA_undefined;
5589 break;
5590 case DW_CFA_offset_extended_sf:
5591 case DW_CFA_val_offset_sf:
5592 reg = LEB (); SLEB ();
5593 if (frame_need_space (fc, reg) >= 0)
5594 fc->col_type[reg] = DW_CFA_undefined;
5595 break;
5596 case DW_CFA_def_cfa_sf:
5597 LEB (); SLEB ();
5598 break;
5599 case DW_CFA_def_cfa_offset_sf:
5600 SLEB ();
5601 break;
5602 case DW_CFA_MIPS_advance_loc8:
5603 start += 8;
5604 break;
5605 case DW_CFA_GNU_args_size:
5606 LEB ();
5607 break;
5608 case DW_CFA_GNU_negative_offset_extended:
5609 reg = LEB (); LEB ();
5610 if (frame_need_space (fc, reg) >= 0)
5611 fc->col_type[reg] = DW_CFA_undefined;
5612 break;
5613 default:
5614 break;
5615 }
5616 }
5617 start = tmp;
5618 }
5619
5620 /* Now we know what registers are used, make a second pass over
5621 the chunk, this time actually printing out the info. */
5622
5623 while (start < block_end)
5624 {
5625 unsigned op, opa;
5626 unsigned long ul, reg, roffs;
5627 long l;
5628 dwarf_vma ofs;
5629 dwarf_vma vma;
5630 const char *reg_prefix = "";
5631
5632 op = *start++;
5633 opa = op & 0x3f;
5634 if (op & 0xc0)
5635 op &= 0xc0;
5636
5637 /* Warning: if you add any more cases to this switch, be
5638 sure to add them to the corresponding switch above. */
5639 switch (op)
5640 {
5641 case DW_CFA_advance_loc:
5642 if (do_debug_frames_interp)
5643 frame_display_row (fc, &need_col_headers, &max_regs);
5644 else
5645 printf (" DW_CFA_advance_loc: %d to %s\n",
5646 opa * fc->code_factor,
5647 dwarf_vmatoa_1 (NULL,
5648 fc->pc_begin + opa * fc->code_factor,
5649 fc->ptr_size));
5650 fc->pc_begin += opa * fc->code_factor;
5651 break;
5652
5653 case DW_CFA_offset:
5654 roffs = LEB ();
5655 if (opa >= (unsigned int) fc->ncols)
5656 reg_prefix = bad_reg;
5657 if (! do_debug_frames_interp || *reg_prefix != '\0')
5658 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
5659 reg_prefix, regname (opa, 0),
5660 roffs * fc->data_factor);
5661 if (*reg_prefix == '\0')
5662 {
5663 fc->col_type[opa] = DW_CFA_offset;
5664 fc->col_offset[opa] = roffs * fc->data_factor;
5665 }
5666 break;
5667
5668 case DW_CFA_restore:
5669 if (opa >= (unsigned int) cie->ncols
5670 || opa >= (unsigned int) fc->ncols)
5671 reg_prefix = bad_reg;
5672 if (! do_debug_frames_interp || *reg_prefix != '\0')
5673 printf (" DW_CFA_restore: %s%s\n",
5674 reg_prefix, regname (opa, 0));
5675 if (*reg_prefix == '\0')
5676 {
5677 fc->col_type[opa] = cie->col_type[opa];
5678 fc->col_offset[opa] = cie->col_offset[opa];
5679 if (do_debug_frames_interp
5680 && fc->col_type[opa] == DW_CFA_unreferenced)
5681 fc->col_type[opa] = DW_CFA_undefined;
5682 }
5683 break;
5684
5685 case DW_CFA_set_loc:
5686 vma = get_encoded_value (start, fc->fde_encoding, section);
5687 start += encoded_ptr_size;
5688 if (do_debug_frames_interp)
5689 frame_display_row (fc, &need_col_headers, &max_regs);
5690 else
5691 printf (" DW_CFA_set_loc: %s\n",
5692 dwarf_vmatoa_1 (NULL, vma, fc->ptr_size));
5693 fc->pc_begin = vma;
5694 break;
5695
5696 case DW_CFA_advance_loc1:
5697 SAFE_BYTE_GET_AND_INC (ofs, start, 1, end);
5698 if (do_debug_frames_interp)
5699 frame_display_row (fc, &need_col_headers, &max_regs);
5700 else
5701 printf (" DW_CFA_advance_loc1: %ld to %s\n",
5702 (unsigned long) (ofs * fc->code_factor),
5703 dwarf_vmatoa_1 (NULL,
5704 fc->pc_begin + ofs * fc->code_factor,
5705 fc->ptr_size));
5706 fc->pc_begin += ofs * fc->code_factor;
5707 break;
5708
5709 case DW_CFA_advance_loc2:
5710 SAFE_BYTE_GET_AND_INC (ofs, start, 2, end);
5711 if (do_debug_frames_interp)
5712 frame_display_row (fc, &need_col_headers, &max_regs);
5713 else
5714 printf (" DW_CFA_advance_loc2: %ld to %s\n",
5715 (unsigned long) (ofs * fc->code_factor),
5716 dwarf_vmatoa_1 (NULL,
5717 fc->pc_begin + ofs * fc->code_factor,
5718 fc->ptr_size));
5719 fc->pc_begin += ofs * fc->code_factor;
5720 break;
5721
5722 case DW_CFA_advance_loc4:
5723 SAFE_BYTE_GET_AND_INC (ofs, start, 4, end);
5724 if (do_debug_frames_interp)
5725 frame_display_row (fc, &need_col_headers, &max_regs);
5726 else
5727 printf (" DW_CFA_advance_loc4: %ld to %s\n",
5728 (unsigned long) (ofs * fc->code_factor),
5729 dwarf_vmatoa_1 (NULL,
5730 fc->pc_begin + ofs * fc->code_factor,
5731 fc->ptr_size));
5732 fc->pc_begin += ofs * fc->code_factor;
5733 break;
5734
5735 case DW_CFA_offset_extended:
5736 reg = LEB ();
5737 roffs = LEB ();
5738 if (reg >= (unsigned int) fc->ncols)
5739 reg_prefix = bad_reg;
5740 if (! do_debug_frames_interp || *reg_prefix != '\0')
5741 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
5742 reg_prefix, regname (reg, 0),
5743 roffs * fc->data_factor);
5744 if (*reg_prefix == '\0')
5745 {
5746 fc->col_type[reg] = DW_CFA_offset;
5747 fc->col_offset[reg] = roffs * fc->data_factor;
5748 }
5749 break;
5750
5751 case DW_CFA_val_offset:
5752 reg = LEB ();
5753 roffs = LEB ();
5754 if (reg >= (unsigned int) fc->ncols)
5755 reg_prefix = bad_reg;
5756 if (! do_debug_frames_interp || *reg_prefix != '\0')
5757 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
5758 reg_prefix, regname (reg, 0),
5759 roffs * fc->data_factor);
5760 if (*reg_prefix == '\0')
5761 {
5762 fc->col_type[reg] = DW_CFA_val_offset;
5763 fc->col_offset[reg] = roffs * fc->data_factor;
5764 }
5765 break;
5766
5767 case DW_CFA_restore_extended:
5768 reg = LEB ();
5769 if (reg >= (unsigned int) cie->ncols
5770 || reg >= (unsigned int) fc->ncols)
5771 reg_prefix = bad_reg;
5772 if (! do_debug_frames_interp || *reg_prefix != '\0')
5773 printf (" DW_CFA_restore_extended: %s%s\n",
5774 reg_prefix, regname (reg, 0));
5775 if (*reg_prefix == '\0')
5776 {
5777 fc->col_type[reg] = cie->col_type[reg];
5778 fc->col_offset[reg] = cie->col_offset[reg];
5779 }
5780 break;
5781
5782 case DW_CFA_undefined:
5783 reg = LEB ();
5784 if (reg >= (unsigned int) fc->ncols)
5785 reg_prefix = bad_reg;
5786 if (! do_debug_frames_interp || *reg_prefix != '\0')
5787 printf (" DW_CFA_undefined: %s%s\n",
5788 reg_prefix, regname (reg, 0));
5789 if (*reg_prefix == '\0')
5790 {
5791 fc->col_type[reg] = DW_CFA_undefined;
5792 fc->col_offset[reg] = 0;
5793 }
5794 break;
5795
5796 case DW_CFA_same_value:
5797 reg = LEB ();
5798 if (reg >= (unsigned int) fc->ncols)
5799 reg_prefix = bad_reg;
5800 if (! do_debug_frames_interp || *reg_prefix != '\0')
5801 printf (" DW_CFA_same_value: %s%s\n",
5802 reg_prefix, regname (reg, 0));
5803 if (*reg_prefix == '\0')
5804 {
5805 fc->col_type[reg] = DW_CFA_same_value;
5806 fc->col_offset[reg] = 0;
5807 }
5808 break;
5809
5810 case DW_CFA_register:
5811 reg = LEB ();
5812 roffs = LEB ();
5813 if (reg >= (unsigned int) fc->ncols)
5814 reg_prefix = bad_reg;
5815 if (! do_debug_frames_interp || *reg_prefix != '\0')
5816 {
5817 printf (" DW_CFA_register: %s%s in ",
5818 reg_prefix, regname (reg, 0));
5819 puts (regname (roffs, 0));
5820 }
5821 if (*reg_prefix == '\0')
5822 {
5823 fc->col_type[reg] = DW_CFA_register;
5824 fc->col_offset[reg] = roffs;
5825 }
5826 break;
5827
5828 case DW_CFA_remember_state:
5829 if (! do_debug_frames_interp)
5830 printf (" DW_CFA_remember_state\n");
5831 rs = (Frame_Chunk *) xmalloc (sizeof (Frame_Chunk));
5832 rs->cfa_offset = fc->cfa_offset;
5833 rs->cfa_reg = fc->cfa_reg;
5834 rs->ra = fc->ra;
5835 rs->cfa_exp = fc->cfa_exp;
5836 rs->ncols = fc->ncols;
5837 rs->col_type = (short int *) xcmalloc (rs->ncols,
5838 sizeof (* rs->col_type));
5839 rs->col_offset = (int *) xcmalloc (rs->ncols, sizeof (* rs->col_offset));
5840 memcpy (rs->col_type, fc->col_type, rs->ncols * sizeof (* fc->col_type));
5841 memcpy (rs->col_offset, fc->col_offset, rs->ncols * sizeof (* fc->col_offset));
5842 rs->next = remembered_state;
5843 remembered_state = rs;
5844 break;
5845
5846 case DW_CFA_restore_state:
5847 if (! do_debug_frames_interp)
5848 printf (" DW_CFA_restore_state\n");
5849 rs = remembered_state;
5850 if (rs)
5851 {
5852 remembered_state = rs->next;
5853 fc->cfa_offset = rs->cfa_offset;
5854 fc->cfa_reg = rs->cfa_reg;
5855 fc->ra = rs->ra;
5856 fc->cfa_exp = rs->cfa_exp;
5857 frame_need_space (fc, rs->ncols - 1);
5858 memcpy (fc->col_type, rs->col_type, rs->ncols * sizeof (* rs->col_type));
5859 memcpy (fc->col_offset, rs->col_offset,
5860 rs->ncols * sizeof (* rs->col_offset));
5861 free (rs->col_type);
5862 free (rs->col_offset);
5863 free (rs);
5864 }
5865 else if (do_debug_frames_interp)
5866 printf ("Mismatched DW_CFA_restore_state\n");
5867 break;
5868
5869 case DW_CFA_def_cfa:
5870 fc->cfa_reg = LEB ();
5871 fc->cfa_offset = LEB ();
5872 fc->cfa_exp = 0;
5873 if (! do_debug_frames_interp)
5874 printf (" DW_CFA_def_cfa: %s ofs %d\n",
5875 regname (fc->cfa_reg, 0), fc->cfa_offset);
5876 break;
5877
5878 case DW_CFA_def_cfa_register:
5879 fc->cfa_reg = LEB ();
5880 fc->cfa_exp = 0;
5881 if (! do_debug_frames_interp)
5882 printf (" DW_CFA_def_cfa_register: %s\n",
5883 regname (fc->cfa_reg, 0));
5884 break;
5885
5886 case DW_CFA_def_cfa_offset:
5887 fc->cfa_offset = LEB ();
5888 if (! do_debug_frames_interp)
5889 printf (" DW_CFA_def_cfa_offset: %d\n", fc->cfa_offset);
5890 break;
5891
5892 case DW_CFA_nop:
5893 if (! do_debug_frames_interp)
5894 printf (" DW_CFA_nop\n");
5895 break;
5896
5897 case DW_CFA_def_cfa_expression:
5898 ul = LEB ();
5899 if (! do_debug_frames_interp)
5900 {
5901 printf (" DW_CFA_def_cfa_expression (");
5902 decode_location_expression (start, eh_addr_size, 0, -1,
5903 ul, 0, section);
5904 printf (")\n");
5905 }
5906 fc->cfa_exp = 1;
5907 start += ul;
5908 break;
5909
5910 case DW_CFA_expression:
5911 reg = LEB ();
5912 ul = LEB ();
5913 if (reg >= (unsigned int) fc->ncols)
5914 reg_prefix = bad_reg;
5915 if (! do_debug_frames_interp || *reg_prefix != '\0')
5916 {
5917 printf (" DW_CFA_expression: %s%s (",
5918 reg_prefix, regname (reg, 0));
5919 decode_location_expression (start, eh_addr_size, 0, -1,
5920 ul, 0, section);
5921 printf (")\n");
5922 }
5923 if (*reg_prefix == '\0')
5924 fc->col_type[reg] = DW_CFA_expression;
5925 start += ul;
5926 break;
5927
5928 case DW_CFA_val_expression:
5929 reg = LEB ();
5930 ul = LEB ();
5931 if (reg >= (unsigned int) fc->ncols)
5932 reg_prefix = bad_reg;
5933 if (! do_debug_frames_interp || *reg_prefix != '\0')
5934 {
5935 printf (" DW_CFA_val_expression: %s%s (",
5936 reg_prefix, regname (reg, 0));
5937 decode_location_expression (start, eh_addr_size, 0, -1,
5938 ul, 0, section);
5939 printf (")\n");
5940 }
5941 if (*reg_prefix == '\0')
5942 fc->col_type[reg] = DW_CFA_val_expression;
5943 start += ul;
5944 break;
5945
5946 case DW_CFA_offset_extended_sf:
5947 reg = LEB ();
5948 l = SLEB ();
5949 if (frame_need_space (fc, reg) < 0)
5950 reg_prefix = bad_reg;
5951 if (! do_debug_frames_interp || *reg_prefix != '\0')
5952 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
5953 reg_prefix, regname (reg, 0),
5954 l * fc->data_factor);
5955 if (*reg_prefix == '\0')
5956 {
5957 fc->col_type[reg] = DW_CFA_offset;
5958 fc->col_offset[reg] = l * fc->data_factor;
5959 }
5960 break;
5961
5962 case DW_CFA_val_offset_sf:
5963 reg = LEB ();
5964 l = SLEB ();
5965 if (frame_need_space (fc, reg) < 0)
5966 reg_prefix = bad_reg;
5967 if (! do_debug_frames_interp || *reg_prefix != '\0')
5968 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
5969 reg_prefix, regname (reg, 0),
5970 l * fc->data_factor);
5971 if (*reg_prefix == '\0')
5972 {
5973 fc->col_type[reg] = DW_CFA_val_offset;
5974 fc->col_offset[reg] = l * fc->data_factor;
5975 }
5976 break;
5977
5978 case DW_CFA_def_cfa_sf:
5979 fc->cfa_reg = LEB ();
5980 fc->cfa_offset = SLEB ();
5981 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5982 fc->cfa_exp = 0;
5983 if (! do_debug_frames_interp)
5984 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
5985 regname (fc->cfa_reg, 0), fc->cfa_offset);
5986 break;
5987
5988 case DW_CFA_def_cfa_offset_sf:
5989 fc->cfa_offset = SLEB ();
5990 fc->cfa_offset = fc->cfa_offset * fc->data_factor;
5991 if (! do_debug_frames_interp)
5992 printf (" DW_CFA_def_cfa_offset_sf: %d\n", fc->cfa_offset);
5993 break;
5994
5995 case DW_CFA_MIPS_advance_loc8:
5996 SAFE_BYTE_GET_AND_INC (ofs, start, 8, end);
5997 if (do_debug_frames_interp)
5998 frame_display_row (fc, &need_col_headers, &max_regs);
5999 else
6000 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
6001 (unsigned long) (ofs * fc->code_factor),
6002 dwarf_vmatoa_1 (NULL,
6003 fc->pc_begin + ofs * fc->code_factor,
6004 fc->ptr_size));
6005 fc->pc_begin += ofs * fc->code_factor;
6006 break;
6007
6008 case DW_CFA_GNU_window_save:
6009 if (! do_debug_frames_interp)
6010 printf (" DW_CFA_GNU_window_save\n");
6011 break;
6012
6013 case DW_CFA_GNU_args_size:
6014 ul = LEB ();
6015 if (! do_debug_frames_interp)
6016 printf (" DW_CFA_GNU_args_size: %ld\n", ul);
6017 break;
6018
6019 case DW_CFA_GNU_negative_offset_extended:
6020 reg = LEB ();
6021 l = - LEB ();
6022 if (frame_need_space (fc, reg) < 0)
6023 reg_prefix = bad_reg;
6024 if (! do_debug_frames_interp || *reg_prefix != '\0')
6025 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6026 reg_prefix, regname (reg, 0),
6027 l * fc->data_factor);
6028 if (*reg_prefix == '\0')
6029 {
6030 fc->col_type[reg] = DW_CFA_offset;
6031 fc->col_offset[reg] = l * fc->data_factor;
6032 }
6033 break;
6034
6035 default:
6036 if (op >= DW_CFA_lo_user && op <= DW_CFA_hi_user)
6037 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op);
6038 else
6039 warn (_("unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op);
6040 start = block_end;
6041 }
6042 }
6043
6044 if (do_debug_frames_interp)
6045 frame_display_row (fc, &need_col_headers, &max_regs);
6046
6047 start = block_end;
6048 eh_addr_size = saved_eh_addr_size;
6049 }
6050
6051 printf ("\n");
6052
6053 return 1;
6054 }
6055
6056 #undef GET
6057 #undef LEB
6058 #undef SLEB
6059
6060 static int
6061 display_gdb_index (struct dwarf_section *section,
6062 void *file ATTRIBUTE_UNUSED)
6063 {
6064 unsigned char *start = section->start;
6065 uint32_t version;
6066 uint32_t cu_list_offset, tu_list_offset;
6067 uint32_t address_table_offset, symbol_table_offset, constant_pool_offset;
6068 unsigned int cu_list_elements, tu_list_elements;
6069 unsigned int address_table_size, symbol_table_slots;
6070 unsigned char *cu_list, *tu_list;
6071 unsigned char *address_table, *symbol_table, *constant_pool;
6072 unsigned int i;
6073
6074 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6075
6076 printf (_("Contents of the %s section:\n"), section->name);
6077
6078 if (section->size < 6 * sizeof (uint32_t))
6079 {
6080 warn (_("Truncated header in the %s section.\n"), section->name);
6081 return 0;
6082 }
6083
6084 version = byte_get_little_endian (start, 4);
6085 printf (_("Version %ld\n"), (long) version);
6086
6087 /* Prior versions are obsolete, and future versions may not be
6088 backwards compatible. */
6089 if (version < 3 || version > 8)
6090 {
6091 warn (_("Unsupported version %lu.\n"), (unsigned long) version);
6092 return 0;
6093 }
6094 if (version < 4)
6095 warn (_("The address table data in version 3 may be wrong.\n"));
6096 if (version < 5)
6097 warn (_("Version 4 does not support case insensitive lookups.\n"));
6098 if (version < 6)
6099 warn (_("Version 5 does not include inlined functions.\n"));
6100 if (version < 7)
6101 warn (_("Version 6 does not include symbol attributes.\n"));
6102 /* Version 7 indices generated by Gold have bad type unit references,
6103 PR binutils/15021. But we don't know if the index was generated by
6104 Gold or not, so to avoid worrying users with gdb-generated indices
6105 we say nothing for version 7 here. */
6106
6107 cu_list_offset = byte_get_little_endian (start + 4, 4);
6108 tu_list_offset = byte_get_little_endian (start + 8, 4);
6109 address_table_offset = byte_get_little_endian (start + 12, 4);
6110 symbol_table_offset = byte_get_little_endian (start + 16, 4);
6111 constant_pool_offset = byte_get_little_endian (start + 20, 4);
6112
6113 if (cu_list_offset > section->size
6114 || tu_list_offset > section->size
6115 || address_table_offset > section->size
6116 || symbol_table_offset > section->size
6117 || constant_pool_offset > section->size)
6118 {
6119 warn (_("Corrupt header in the %s section.\n"), section->name);
6120 return 0;
6121 }
6122
6123 cu_list_elements = (tu_list_offset - cu_list_offset) / 8;
6124 tu_list_elements = (address_table_offset - tu_list_offset) / 8;
6125 address_table_size = symbol_table_offset - address_table_offset;
6126 symbol_table_slots = (constant_pool_offset - symbol_table_offset) / 8;
6127
6128 cu_list = start + cu_list_offset;
6129 tu_list = start + tu_list_offset;
6130 address_table = start + address_table_offset;
6131 symbol_table = start + symbol_table_offset;
6132 constant_pool = start + constant_pool_offset;
6133
6134 printf (_("\nCU table:\n"));
6135 for (i = 0; i < cu_list_elements; i += 2)
6136 {
6137 uint64_t cu_offset = byte_get_little_endian (cu_list + i * 8, 8);
6138 uint64_t cu_length = byte_get_little_endian (cu_list + i * 8 + 8, 8);
6139
6140 printf (_("[%3u] 0x%lx - 0x%lx\n"), i / 2,
6141 (unsigned long) cu_offset,
6142 (unsigned long) (cu_offset + cu_length - 1));
6143 }
6144
6145 printf (_("\nTU table:\n"));
6146 for (i = 0; i < tu_list_elements; i += 3)
6147 {
6148 uint64_t tu_offset = byte_get_little_endian (tu_list + i * 8, 8);
6149 uint64_t type_offset = byte_get_little_endian (tu_list + i * 8 + 8, 8);
6150 uint64_t signature = byte_get_little_endian (tu_list + i * 8 + 16, 8);
6151
6152 printf (_("[%3u] 0x%lx 0x%lx "), i / 3,
6153 (unsigned long) tu_offset,
6154 (unsigned long) type_offset);
6155 print_dwarf_vma (signature, 8);
6156 printf ("\n");
6157 }
6158
6159 printf (_("\nAddress table:\n"));
6160 for (i = 0; i < address_table_size; i += 2 * 8 + 4)
6161 {
6162 uint64_t low = byte_get_little_endian (address_table + i, 8);
6163 uint64_t high = byte_get_little_endian (address_table + i + 8, 8);
6164 uint32_t cu_index = byte_get_little_endian (address_table + i + 16, 4);
6165
6166 print_dwarf_vma (low, 8);
6167 print_dwarf_vma (high, 8);
6168 printf (_("%lu\n"), (unsigned long) cu_index);
6169 }
6170
6171 printf (_("\nSymbol table:\n"));
6172 for (i = 0; i < symbol_table_slots; ++i)
6173 {
6174 uint32_t name_offset = byte_get_little_endian (symbol_table + i * 8, 4);
6175 uint32_t cu_vector_offset = byte_get_little_endian (symbol_table + i * 8 + 4, 4);
6176 uint32_t num_cus, cu;
6177
6178 if (name_offset != 0
6179 || cu_vector_offset != 0)
6180 {
6181 unsigned int j;
6182
6183 printf ("[%3u] %s:", i, constant_pool + name_offset);
6184 num_cus = byte_get_little_endian (constant_pool + cu_vector_offset, 4);
6185 if (num_cus > 1)
6186 printf ("\n");
6187 for (j = 0; j < num_cus; ++j)
6188 {
6189 int is_static;
6190 gdb_index_symbol_kind kind;
6191
6192 cu = byte_get_little_endian (constant_pool + cu_vector_offset + 4 + j * 4, 4);
6193 is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu);
6194 kind = GDB_INDEX_SYMBOL_KIND_VALUE (cu);
6195 cu = GDB_INDEX_CU_VALUE (cu);
6196 /* Convert to TU number if it's for a type unit. */
6197 if (cu >= cu_list_elements / 2)
6198 printf ("%cT%lu", num_cus > 1 ? '\t' : ' ',
6199 (unsigned long) (cu - cu_list_elements / 2));
6200 else
6201 printf ("%c%lu", num_cus > 1 ? '\t' : ' ', (unsigned long) cu);
6202
6203 printf (" [%s, %s]",
6204 is_static ? _("static") : _("global"),
6205 get_gdb_index_symbol_kind_name (kind));
6206 if (num_cus > 1)
6207 printf ("\n");
6208 }
6209 if (num_cus <= 1)
6210 printf ("\n");
6211 }
6212 }
6213
6214 return 1;
6215 }
6216
6217 /* Pre-allocate enough space for the CU/TU sets needed. */
6218
6219 static void
6220 prealloc_cu_tu_list (unsigned int nshndx)
6221 {
6222 if (shndx_pool == NULL)
6223 {
6224 shndx_pool_size = nshndx;
6225 shndx_pool_used = 0;
6226 shndx_pool = (unsigned int *) xcmalloc (shndx_pool_size,
6227 sizeof (unsigned int));
6228 }
6229 else
6230 {
6231 shndx_pool_size = shndx_pool_used + nshndx;
6232 shndx_pool = (unsigned int *) xcrealloc (shndx_pool, shndx_pool_size,
6233 sizeof (unsigned int));
6234 }
6235 }
6236
6237 static void
6238 add_shndx_to_cu_tu_entry (unsigned int shndx)
6239 {
6240 if (shndx_pool_used >= shndx_pool_size)
6241 {
6242 error (_("Internal error: out of space in the shndx pool.\n"));
6243 return;
6244 }
6245 shndx_pool [shndx_pool_used++] = shndx;
6246 }
6247
6248 static void
6249 end_cu_tu_entry (void)
6250 {
6251 if (shndx_pool_used >= shndx_pool_size)
6252 {
6253 error (_("Internal error: out of space in the shndx pool.\n"));
6254 return;
6255 }
6256 shndx_pool [shndx_pool_used++] = 0;
6257 }
6258
6259 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6260
6261 static const char *
6262 get_DW_SECT_short_name (unsigned int dw_sect)
6263 {
6264 static char buf[16];
6265
6266 switch (dw_sect)
6267 {
6268 case DW_SECT_INFO:
6269 return "info";
6270 case DW_SECT_TYPES:
6271 return "types";
6272 case DW_SECT_ABBREV:
6273 return "abbrev";
6274 case DW_SECT_LINE:
6275 return "line";
6276 case DW_SECT_LOC:
6277 return "loc";
6278 case DW_SECT_STR_OFFSETS:
6279 return "str_off";
6280 case DW_SECT_MACINFO:
6281 return "macinfo";
6282 case DW_SECT_MACRO:
6283 return "macro";
6284 default:
6285 break;
6286 }
6287
6288 snprintf (buf, sizeof (buf), "%d", dw_sect);
6289 return buf;
6290 }
6291
6292 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6293 These sections are extensions for Fission.
6294 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6295
6296 static int
6297 process_cu_tu_index (struct dwarf_section *section, int do_display)
6298 {
6299 unsigned char *phdr = section->start;
6300 unsigned char *limit = phdr + section->size;
6301 unsigned char *phash;
6302 unsigned char *pindex;
6303 unsigned char *ppool;
6304 unsigned int version;
6305 unsigned int ncols = 0;
6306 unsigned int nused;
6307 unsigned int nslots;
6308 unsigned int i;
6309 unsigned int j;
6310 dwarf_vma signature_high;
6311 dwarf_vma signature_low;
6312 char buf[64];
6313
6314 version = byte_get (phdr, 4);
6315 if (version >= 2)
6316 ncols = byte_get (phdr + 4, 4);
6317 nused = byte_get (phdr + 8, 4);
6318 nslots = byte_get (phdr + 12, 4);
6319 phash = phdr + 16;
6320 pindex = phash + nslots * 8;
6321 ppool = pindex + nslots * 4;
6322
6323 if (do_display)
6324 {
6325 printf (_("Contents of the %s section:\n\n"), section->name);
6326 printf (_(" Version: %d\n"), version);
6327 if (version >= 2)
6328 printf (_(" Number of columns: %d\n"), ncols);
6329 printf (_(" Number of used entries: %d\n"), nused);
6330 printf (_(" Number of slots: %d\n\n"), nslots);
6331 }
6332
6333 if (ppool > limit)
6334 {
6335 warn (_("Section %s too small for %d hash table entries\n"),
6336 section->name, nslots);
6337 return 0;
6338 }
6339
6340 if (version == 1)
6341 {
6342 if (!do_display)
6343 prealloc_cu_tu_list ((limit - ppool) / 4);
6344 for (i = 0; i < nslots; i++)
6345 {
6346 unsigned char *shndx_list;
6347 unsigned int shndx;
6348
6349 byte_get_64 (phash, &signature_high, &signature_low);
6350 if (signature_high != 0 || signature_low != 0)
6351 {
6352 j = byte_get (pindex, 4);
6353 shndx_list = ppool + j * 4;
6354 if (do_display)
6355 printf (_(" [%3d] Signature: 0x%s Sections: "),
6356 i, dwarf_vmatoa64 (signature_high, signature_low,
6357 buf, sizeof (buf)));
6358 for (;;)
6359 {
6360 if (shndx_list >= limit)
6361 {
6362 warn (_("Section %s too small for shndx pool\n"),
6363 section->name);
6364 return 0;
6365 }
6366 shndx = byte_get (shndx_list, 4);
6367 if (shndx == 0)
6368 break;
6369 if (do_display)
6370 printf (" %d", shndx);
6371 else
6372 add_shndx_to_cu_tu_entry (shndx);
6373 shndx_list += 4;
6374 }
6375 if (do_display)
6376 printf ("\n");
6377 else
6378 end_cu_tu_entry ();
6379 }
6380 phash += 8;
6381 pindex += 4;
6382 }
6383 }
6384 else if (version == 2)
6385 {
6386 unsigned int val;
6387 unsigned int dw_sect;
6388 unsigned char *ph = phash;
6389 unsigned char *pi = pindex;
6390 unsigned char *poffsets = ppool + ncols * 4;
6391 unsigned char *psizes = poffsets + nused * ncols * 4;
6392 unsigned char *pend = psizes + nused * ncols * 4;
6393 bfd_boolean is_tu_index;
6394 struct cu_tu_set *this_set = NULL;
6395 unsigned int row;
6396 unsigned char *prow;
6397
6398 is_tu_index = strcmp (section->name, ".debug_tu_index") == 0;
6399
6400 if (pend > limit)
6401 {
6402 warn (_("Section %s too small for offset and size tables\n"),
6403 section->name);
6404 return 0;
6405 }
6406
6407 if (do_display)
6408 {
6409 printf (_(" Offset table\n"));
6410 printf (" slot %-16s ",
6411 is_tu_index ? _("signature") : _("dwo_id"));
6412 }
6413 else
6414 {
6415 if (is_tu_index)
6416 {
6417 tu_count = nused;
6418 tu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6419 this_set = tu_sets;
6420 }
6421 else
6422 {
6423 cu_count = nused;
6424 cu_sets = xcmalloc (nused, sizeof (struct cu_tu_set));
6425 this_set = cu_sets;
6426 }
6427 }
6428 if (do_display)
6429 {
6430 for (j = 0; j < ncols; j++)
6431 {
6432 dw_sect = byte_get (ppool + j * 4, 4);
6433 printf (" %8s", get_DW_SECT_short_name (dw_sect));
6434 }
6435 printf ("\n");
6436 }
6437 for (i = 0; i < nslots; i++)
6438 {
6439 byte_get_64 (ph, &signature_high, &signature_low);
6440 row = byte_get (pi, 4);
6441 if (row != 0)
6442 {
6443 if (!do_display)
6444 memcpy (&this_set[row - 1].signature, ph, sizeof (uint64_t));
6445 prow = poffsets + (row - 1) * ncols * 4;
6446 if (do_display)
6447 printf (_(" [%3d] 0x%s"),
6448 i, dwarf_vmatoa64 (signature_high, signature_low,
6449 buf, sizeof (buf)));
6450 for (j = 0; j < ncols; j++)
6451 {
6452 val = byte_get (prow + j * 4, 4);
6453 if (do_display)
6454 printf (" %8d", val);
6455 else
6456 {
6457 dw_sect = byte_get (ppool + j * 4, 4);
6458 this_set [row - 1].section_offsets [dw_sect] = val;
6459 }
6460 }
6461 if (do_display)
6462 printf ("\n");
6463 }
6464 ph += 8;
6465 pi += 4;
6466 }
6467
6468 ph = phash;
6469 pi = pindex;
6470 if (do_display)
6471 {
6472 printf ("\n");
6473 printf (_(" Size table\n"));
6474 printf (" slot %-16s ",
6475 is_tu_index ? _("signature") : _("dwo_id"));
6476 }
6477 for (j = 0; j < ncols; j++)
6478 {
6479 val = byte_get (ppool + j * 4, 4);
6480 if (do_display)
6481 printf (" %8s", get_DW_SECT_short_name (val));
6482 }
6483 if (do_display)
6484 printf ("\n");
6485 for (i = 0; i < nslots; i++)
6486 {
6487 byte_get_64 (ph, &signature_high, &signature_low);
6488 row = byte_get (pi, 4);
6489 if (row != 0)
6490 {
6491 prow = psizes + (row - 1) * ncols * 4;
6492 if (do_display)
6493 printf (_(" [%3d] 0x%s"),
6494 i, dwarf_vmatoa64 (signature_high, signature_low,
6495 buf, sizeof (buf)));
6496 for (j = 0; j < ncols; j++)
6497 {
6498 val = byte_get (prow + j * 4, 4);
6499 if (do_display)
6500 printf (" %8d", val);
6501 else
6502 {
6503 dw_sect = byte_get (ppool + j * 4, 4);
6504 this_set [row - 1].section_sizes [dw_sect] = val;
6505 }
6506 }
6507 if (do_display)
6508 printf ("\n");
6509 }
6510 ph += 8;
6511 pi += 4;
6512 }
6513 }
6514 else if (do_display)
6515 printf (_(" Unsupported version\n"));
6516
6517 if (do_display)
6518 printf ("\n");
6519
6520 return 1;
6521 }
6522
6523 /* Load the CU and TU indexes if present. This will build a list of
6524 section sets that we can use to associate a .debug_info.dwo section
6525 with its associated .debug_abbrev.dwo section in a .dwp file. */
6526
6527 static void
6528 load_cu_tu_indexes (void *file)
6529 {
6530 /* If we have already loaded (or tried to load) the CU and TU indexes
6531 then do not bother to repeat the task. */
6532 if (cu_tu_indexes_read)
6533 return;
6534
6535 if (load_debug_section (dwp_cu_index, file))
6536 process_cu_tu_index (&debug_displays [dwp_cu_index].section, 0);
6537
6538 if (load_debug_section (dwp_tu_index, file))
6539 process_cu_tu_index (&debug_displays [dwp_tu_index].section, 0);
6540
6541 cu_tu_indexes_read = 1;
6542 }
6543
6544 /* Find the set of sections that includes section SHNDX. */
6545
6546 unsigned int *
6547 find_cu_tu_set (void *file, unsigned int shndx)
6548 {
6549 unsigned int i;
6550
6551 load_cu_tu_indexes (file);
6552
6553 /* Find SHNDX in the shndx pool. */
6554 for (i = 0; i < shndx_pool_used; i++)
6555 if (shndx_pool [i] == shndx)
6556 break;
6557
6558 if (i >= shndx_pool_used)
6559 return NULL;
6560
6561 /* Now backup to find the first entry in the set. */
6562 while (i > 0 && shndx_pool [i - 1] != 0)
6563 i--;
6564
6565 return shndx_pool + i;
6566 }
6567
6568 /* Display a .debug_cu_index or .debug_tu_index section. */
6569
6570 static int
6571 display_cu_index (struct dwarf_section *section, void *file ATTRIBUTE_UNUSED)
6572 {
6573 return process_cu_tu_index (section, 1);
6574 }
6575
6576 static int
6577 display_debug_not_supported (struct dwarf_section *section,
6578 void *file ATTRIBUTE_UNUSED)
6579 {
6580 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
6581 section->name);
6582
6583 return 1;
6584 }
6585
6586 void *
6587 cmalloc (size_t nmemb, size_t size)
6588 {
6589 /* Check for overflow. */
6590 if (nmemb >= ~(size_t) 0 / size)
6591 return NULL;
6592 else
6593 return malloc (nmemb * size);
6594 }
6595
6596 void *
6597 xcmalloc (size_t nmemb, size_t size)
6598 {
6599 /* Check for overflow. */
6600 if (nmemb >= ~(size_t) 0 / size)
6601 return NULL;
6602 else
6603 return xmalloc (nmemb * size);
6604 }
6605
6606 void *
6607 xcrealloc (void *ptr, size_t nmemb, size_t size)
6608 {
6609 /* Check for overflow. */
6610 if (nmemb >= ~(size_t) 0 / size)
6611 return NULL;
6612 else
6613 return xrealloc (ptr, nmemb * size);
6614 }
6615
6616 void
6617 free_debug_memory (void)
6618 {
6619 unsigned int i;
6620
6621 free_abbrevs ();
6622
6623 for (i = 0; i < max; i++)
6624 free_debug_section ((enum dwarf_section_display_enum) i);
6625
6626 if (debug_information != NULL)
6627 {
6628 if (num_debug_info_entries != DEBUG_INFO_UNAVAILABLE)
6629 {
6630 for (i = 0; i < num_debug_info_entries; i++)
6631 {
6632 if (!debug_information [i].max_loc_offsets)
6633 {
6634 free (debug_information [i].loc_offsets);
6635 free (debug_information [i].have_frame_base);
6636 }
6637 if (!debug_information [i].max_range_lists)
6638 free (debug_information [i].range_lists);
6639 }
6640 }
6641
6642 free (debug_information);
6643 debug_information = NULL;
6644 num_debug_info_entries = 0;
6645 }
6646 }
6647
6648 void
6649 dwarf_select_sections_by_names (const char *names)
6650 {
6651 typedef struct
6652 {
6653 const char * option;
6654 int * variable;
6655 int val;
6656 }
6657 debug_dump_long_opts;
6658
6659 static const debug_dump_long_opts opts_table [] =
6660 {
6661 /* Please keep this table alpha- sorted. */
6662 { "Ranges", & do_debug_ranges, 1 },
6663 { "abbrev", & do_debug_abbrevs, 1 },
6664 { "addr", & do_debug_addr, 1 },
6665 { "aranges", & do_debug_aranges, 1 },
6666 { "cu_index", & do_debug_cu_index, 1 },
6667 { "decodedline", & do_debug_lines, FLAG_DEBUG_LINES_DECODED },
6668 { "frames", & do_debug_frames, 1 },
6669 { "frames-interp", & do_debug_frames_interp, 1 },
6670 /* The special .gdb_index section. */
6671 { "gdb_index", & do_gdb_index, 1 },
6672 { "info", & do_debug_info, 1 },
6673 { "line", & do_debug_lines, FLAG_DEBUG_LINES_RAW }, /* For backwards compatibility. */
6674 { "loc", & do_debug_loc, 1 },
6675 { "macro", & do_debug_macinfo, 1 },
6676 { "pubnames", & do_debug_pubnames, 1 },
6677 { "pubtypes", & do_debug_pubtypes, 1 },
6678 /* This entry is for compatability
6679 with earlier versions of readelf. */
6680 { "ranges", & do_debug_aranges, 1 },
6681 { "rawline", & do_debug_lines, FLAG_DEBUG_LINES_RAW },
6682 { "str", & do_debug_str, 1 },
6683 /* These trace_* sections are used by Itanium VMS. */
6684 { "trace_abbrev", & do_trace_abbrevs, 1 },
6685 { "trace_aranges", & do_trace_aranges, 1 },
6686 { "trace_info", & do_trace_info, 1 },
6687 { NULL, NULL, 0 }
6688 };
6689
6690 const char *p;
6691
6692 p = names;
6693 while (*p)
6694 {
6695 const debug_dump_long_opts * entry;
6696
6697 for (entry = opts_table; entry->option; entry++)
6698 {
6699 size_t len = strlen (entry->option);
6700
6701 if (strncmp (p, entry->option, len) == 0
6702 && (p[len] == ',' || p[len] == '\0'))
6703 {
6704 * entry->variable |= entry->val;
6705
6706 /* The --debug-dump=frames-interp option also
6707 enables the --debug-dump=frames option. */
6708 if (do_debug_frames_interp)
6709 do_debug_frames = 1;
6710
6711 p += len;
6712 break;
6713 }
6714 }
6715
6716 if (entry->option == NULL)
6717 {
6718 warn (_("Unrecognized debug option '%s'\n"), p);
6719 p = strchr (p, ',');
6720 if (p == NULL)
6721 break;
6722 }
6723
6724 if (*p == ',')
6725 p++;
6726 }
6727 }
6728
6729 void
6730 dwarf_select_sections_by_letters (const char *letters)
6731 {
6732 unsigned int lindex = 0;
6733
6734 while (letters[lindex])
6735 switch (letters[lindex++])
6736 {
6737 case 'i':
6738 do_debug_info = 1;
6739 break;
6740
6741 case 'a':
6742 do_debug_abbrevs = 1;
6743 break;
6744
6745 case 'l':
6746 do_debug_lines |= FLAG_DEBUG_LINES_RAW;
6747 break;
6748
6749 case 'L':
6750 do_debug_lines |= FLAG_DEBUG_LINES_DECODED;
6751 break;
6752
6753 case 'p':
6754 do_debug_pubnames = 1;
6755 break;
6756
6757 case 't':
6758 do_debug_pubtypes = 1;
6759 break;
6760
6761 case 'r':
6762 do_debug_aranges = 1;
6763 break;
6764
6765 case 'R':
6766 do_debug_ranges = 1;
6767 break;
6768
6769 case 'F':
6770 do_debug_frames_interp = 1;
6771 case 'f':
6772 do_debug_frames = 1;
6773 break;
6774
6775 case 'm':
6776 do_debug_macinfo = 1;
6777 break;
6778
6779 case 's':
6780 do_debug_str = 1;
6781 break;
6782
6783 case 'o':
6784 do_debug_loc = 1;
6785 break;
6786
6787 default:
6788 warn (_("Unrecognized debug option '%s'\n"), optarg);
6789 break;
6790 }
6791 }
6792
6793 void
6794 dwarf_select_sections_all (void)
6795 {
6796 do_debug_info = 1;
6797 do_debug_abbrevs = 1;
6798 do_debug_lines = FLAG_DEBUG_LINES_RAW;
6799 do_debug_pubnames = 1;
6800 do_debug_pubtypes = 1;
6801 do_debug_aranges = 1;
6802 do_debug_ranges = 1;
6803 do_debug_frames = 1;
6804 do_debug_macinfo = 1;
6805 do_debug_str = 1;
6806 do_debug_loc = 1;
6807 do_gdb_index = 1;
6808 do_trace_info = 1;
6809 do_trace_abbrevs = 1;
6810 do_trace_aranges = 1;
6811 do_debug_addr = 1;
6812 do_debug_cu_index = 1;
6813 }
6814
6815 struct dwarf_section_display debug_displays[] =
6816 {
6817 { { ".debug_abbrev", ".zdebug_abbrev", NULL, NULL, 0, 0, 0 },
6818 display_debug_abbrev, &do_debug_abbrevs, 0 },
6819 { { ".debug_aranges", ".zdebug_aranges", NULL, NULL, 0, 0, 0 },
6820 display_debug_aranges, &do_debug_aranges, 1 },
6821 { { ".debug_frame", ".zdebug_frame", NULL, NULL, 0, 0, 0 },
6822 display_debug_frames, &do_debug_frames, 1 },
6823 { { ".debug_info", ".zdebug_info", NULL, NULL, 0, 0, abbrev },
6824 display_debug_info, &do_debug_info, 1 },
6825 { { ".debug_line", ".zdebug_line", NULL, NULL, 0, 0, 0 },
6826 display_debug_lines, &do_debug_lines, 1 },
6827 { { ".debug_pubnames", ".zdebug_pubnames", NULL, NULL, 0, 0, 0 },
6828 display_debug_pubnames, &do_debug_pubnames, 0 },
6829 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL, NULL, 0, 0, 0 },
6830 display_debug_gnu_pubnames, &do_debug_pubnames, 0 },
6831 { { ".eh_frame", "", NULL, NULL, 0, 0, 0 },
6832 display_debug_frames, &do_debug_frames, 1 },
6833 { { ".debug_macinfo", ".zdebug_macinfo", NULL, NULL, 0, 0, 0 },
6834 display_debug_macinfo, &do_debug_macinfo, 0 },
6835 { { ".debug_macro", ".zdebug_macro", NULL, NULL, 0, 0, 0 },
6836 display_debug_macro, &do_debug_macinfo, 1 },
6837 { { ".debug_str", ".zdebug_str", NULL, NULL, 0, 0, 0 },
6838 display_debug_str, &do_debug_str, 0 },
6839 { { ".debug_loc", ".zdebug_loc", NULL, NULL, 0, 0, 0 },
6840 display_debug_loc, &do_debug_loc, 1 },
6841 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL, NULL, 0, 0, 0 },
6842 display_debug_pubnames, &do_debug_pubtypes, 0 },
6843 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL, NULL, 0, 0, 0 },
6844 display_debug_gnu_pubnames, &do_debug_pubtypes, 0 },
6845 { { ".debug_ranges", ".zdebug_ranges", NULL, NULL, 0, 0, 0 },
6846 display_debug_ranges, &do_debug_ranges, 1 },
6847 { { ".debug_static_func", ".zdebug_static_func", NULL, NULL, 0, 0, 0 },
6848 display_debug_not_supported, NULL, 0 },
6849 { { ".debug_static_vars", ".zdebug_static_vars", NULL, NULL, 0, 0, 0 },
6850 display_debug_not_supported, NULL, 0 },
6851 { { ".debug_types", ".zdebug_types", NULL, NULL, 0, 0, abbrev },
6852 display_debug_types, &do_debug_info, 1 },
6853 { { ".debug_weaknames", ".zdebug_weaknames", NULL, NULL, 0, 0, 0 },
6854 display_debug_not_supported, NULL, 0 },
6855 { { ".gdb_index", "", NULL, NULL, 0, 0, 0 },
6856 display_gdb_index, &do_gdb_index, 0 },
6857 { { ".trace_info", "", NULL, NULL, 0, 0, trace_abbrev },
6858 display_trace_info, &do_trace_info, 1 },
6859 { { ".trace_abbrev", "", NULL, NULL, 0, 0, 0 },
6860 display_debug_abbrev, &do_trace_abbrevs, 0 },
6861 { { ".trace_aranges", "", NULL, NULL, 0, 0, 0 },
6862 display_debug_aranges, &do_trace_aranges, 0 },
6863 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6864 display_debug_info, &do_debug_info, 1 },
6865 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL, NULL, 0, 0, 0 },
6866 display_debug_abbrev, &do_debug_abbrevs, 0 },
6867 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL, NULL, 0, 0, abbrev_dwo },
6868 display_debug_types, &do_debug_info, 1 },
6869 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL, NULL, 0, 0, 0 },
6870 display_debug_lines, &do_debug_lines, 1 },
6871 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL, NULL, 0, 0, 0 },
6872 display_debug_loc, &do_debug_loc, 1 },
6873 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL, NULL, 0, 0, 0 },
6874 display_debug_macro, &do_debug_macinfo, 1 },
6875 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL, NULL, 0, 0, 0 },
6876 display_debug_macinfo, &do_debug_macinfo, 0 },
6877 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL, NULL, 0, 0, 0 },
6878 display_debug_str, &do_debug_str, 1 },
6879 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL, NULL, 0, 0, 0 },
6880 display_debug_str_offsets, NULL, 0 },
6881 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL, NULL, 0, 0, 0 },
6882 display_debug_str_offsets, NULL, 0 },
6883 { { ".debug_addr", ".zdebug_addr", NULL, NULL, 0, 0, 0 },
6884 display_debug_addr, &do_debug_addr, 1 },
6885 { { ".debug_cu_index", "", NULL, NULL, 0, 0, 0 },
6886 display_cu_index, &do_debug_cu_index, 0 },
6887 { { ".debug_tu_index", "", NULL, NULL, 0, 0, 0 },
6888 display_cu_index, &do_debug_cu_index, 0 },
6889 };
This page took 0.176268 seconds and 4 git commands to generate.