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