1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
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.
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.
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
22 #include "libiberty.h"
24 #include "bfd_stdint.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
41 #define MAX(a, b) ((a) > (b) ? (a) : (b))
42 #define MIN(a, b) ((a) < (b) ? (a) : (b))
44 static const char *regname (unsigned int regno
, int row
);
45 static const char *regname_internal_by_table_only (unsigned int regno
);
47 static int have_frame_base
;
48 static int need_base_address
;
50 static unsigned int num_debug_info_entries
= 0;
51 static unsigned int alloc_num_debug_info_entries
= 0;
52 static debug_info
*debug_information
= NULL
;
53 /* Special value for num_debug_info_entries to indicate
54 that the .debug_info section could not be loaded/parsed. */
55 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
57 /* A .debug_info section can contain multiple links to separate
58 DWO object files. We use these structures to record these links. */
66 typedef struct dwo_info
71 struct dwo_info
* next
;
74 static dwo_info
* first_dwo_info
= NULL
;
75 static bfd_boolean need_dwo_info
;
77 separate_info
* first_separate_info
= NULL
;
79 unsigned int eh_addr_size
;
84 int do_debug_pubnames
;
85 int do_debug_pubtypes
;
89 int do_debug_frames_interp
;
92 int do_debug_str_offsets
;
99 int do_debug_cu_index
;
103 bfd_boolean do_checks
;
105 int dwarf_cutoff_level
= -1;
106 unsigned long dwarf_start_die
;
110 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
111 testing whether e.g. a locview list is present. */
112 static const dwarf_vma vm1
= -1;
114 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
115 sections. For version 1 package files, each set is stored in SHNDX_POOL
116 as a zero-terminated list of section indexes comprising one set of debug
117 sections from a .dwo file. */
119 static unsigned int *shndx_pool
= NULL
;
120 static unsigned int shndx_pool_size
= 0;
121 static unsigned int shndx_pool_used
= 0;
123 /* For version 2 package files, each set contains an array of section offsets
124 and an array of section sizes, giving the offset and size of the
125 contribution from a CU or TU within one of the debug sections.
126 When displaying debug info from a package file, we need to use these
127 tables to locate the corresponding contributions to each section. */
132 dwarf_vma section_offsets
[DW_SECT_MAX
];
133 size_t section_sizes
[DW_SECT_MAX
];
136 static int cu_count
= 0;
137 static int tu_count
= 0;
138 static struct cu_tu_set
*cu_sets
= NULL
;
139 static struct cu_tu_set
*tu_sets
= NULL
;
141 static bfd_boolean
load_cu_tu_indexes (void *);
143 /* An array that indicates for a given level of CU nesting whether
144 the latest DW_AT_type seen for that level was a signed type or
146 #define MAX_CU_NESTING (1 << 8)
147 static bfd_boolean level_type_signed
[MAX_CU_NESTING
];
149 /* Values for do_debug_lines. */
150 #define FLAG_DEBUG_LINES_RAW 1
151 #define FLAG_DEBUG_LINES_DECODED 2
154 size_of_encoded_value (int encoding
)
156 switch (encoding
& 0x7)
159 case 0: return eh_addr_size
;
167 get_encoded_value (unsigned char **pdata
,
169 struct dwarf_section
*section
,
172 unsigned char * data
= * pdata
;
173 unsigned int size
= size_of_encoded_value (encoding
);
176 if (data
+ size
>= end
)
178 warn (_("Encoded value extends past end of section\n"));
183 /* PR 17512: file: 002-829853-0.004. */
186 warn (_("Encoded size of %d is too large to read\n"), size
);
191 /* PR 17512: file: 1085-5603-0.004. */
194 warn (_("Encoded size of 0 is too small to read\n"));
199 if (encoding
& DW_EH_PE_signed
)
200 val
= byte_get_signed (data
, size
);
202 val
= byte_get (data
, size
);
204 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
205 val
+= section
->address
+ (data
- section
->start
);
207 * pdata
= data
+ size
;
211 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
213 # define DWARF_VMA_FMT "ll"
214 # define DWARF_VMA_FMT_LONG "%16.16llx"
216 # define DWARF_VMA_FMT "I64"
217 # define DWARF_VMA_FMT_LONG "%016I64x"
220 # define DWARF_VMA_FMT "l"
221 # define DWARF_VMA_FMT_LONG "%16.16lx"
224 /* Convert a dwarf vma value into a string. Returns a pointer to a static
225 buffer containing the converted VALUE. The value is converted according
226 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
227 it specifies the maximum number of bytes to be displayed in the converted
228 value and FMTCH is ignored - hex is always used. */
231 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
233 /* As dwarf_vmatoa is used more then once in a printf call
234 for output, we are cycling through an fixed array of pointers
235 for return address. */
236 static int buf_pos
= 0;
237 static struct dwarf_vmatoa_buf
243 ret
= buf
[buf_pos
++].place
;
244 buf_pos
%= ARRAY_SIZE (buf
);
248 /* Printf does not have a way of specifying a maximum field width for an
249 integer value, so we print the full value into a buffer and then select
250 the precision we need. */
251 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
254 return ret
+ (16 - 2 * num_bytes
);
261 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
263 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
264 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
269 static inline const char *
270 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
272 return dwarf_vmatoa_1 (fmtch
, value
, 0);
275 /* Print a dwarf_vma value (typically an address, offset or length) in
276 hexadecimal format, followed by a space. The length of the VALUE (and
277 hence the precision displayed) is determined by the NUM_BYTES parameter. */
280 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
282 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
285 /* Print a view number in hexadecimal value, with the same width
286 print_dwarf_vma would have printed it with the same num_bytes.
287 Print blanks for zero view, unless force is nonzero. */
290 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
298 assert (value
== (unsigned long) value
);
300 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
302 printf ("%*s", len
+ 1, "");
305 /* Format a 64-bit value, given as two 32-bit values, in hex.
306 For reentrancy, this uses a buffer provided by the caller. */
309 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
310 unsigned int buf_len
)
315 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
318 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
319 snprintf (buf
+ len
, buf_len
- len
,
320 "%08" DWARF_VMA_FMT
"x", lvalue
);
326 /* Read in a LEB128 encoded value starting at address DATA.
327 If SIGN is true, return a signed LEB128 value.
328 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
329 If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the
330 terminating byte was not found and with bit 1 set if the value
331 overflows a dwarf_vma.
332 No bytes will be read at address END or beyond. */
335 read_leb128 (unsigned char *data
,
336 const unsigned char *const end
,
338 unsigned int *length_return
,
341 dwarf_vma result
= 0;
342 unsigned int num_read
= 0;
343 unsigned int shift
= 0;
348 unsigned char byte
= *data
++;
349 bfd_boolean cont
= (byte
& 0x80) ? TRUE
: FALSE
;
354 if (shift
< sizeof (result
) * 8)
356 result
|= ((dwarf_vma
) byte
) << shift
;
359 if ((((dwarf_signed_vma
) result
>> shift
) & 0x7f) != byte
)
363 else if ((result
>> shift
) != byte
)
379 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
380 result
|= -((dwarf_vma
) 1 << shift
);
385 if (length_return
!= NULL
)
386 *length_return
= num_read
;
387 if (status_return
!= NULL
)
388 *status_return
= status
;
393 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
394 Checks to make sure that the read will not reach or pass END
395 and that VAL is big enough to hold AMOUNT bytes. */
396 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
399 unsigned int amount = (AMOUNT); \
400 if (sizeof (VAL) < amount) \
402 error (ngettext ("internal error: attempt to read %d byte " \
403 "of data in to %d sized variable", \
404 "internal error: attempt to read %d bytes " \
405 "of data in to %d sized variable", \
407 amount, (int) sizeof (VAL)); \
408 amount = sizeof (VAL); \
410 if (((PTR) + amount) >= (END)) \
413 amount = (END) - (PTR); \
417 if (amount == 0 || amount > 8) \
420 VAL = byte_get ((PTR), amount); \
424 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
425 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
428 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
433 /* Like SAFE_BYTE_GET, but reads a signed value. */
434 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
437 unsigned int amount = (AMOUNT); \
438 if (((PTR) + amount) >= (END)) \
441 amount = (END) - (PTR); \
446 VAL = byte_get_signed ((PTR), amount); \
452 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
453 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
456 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
461 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
464 if (((PTR) + 8) <= (END)) \
466 byte_get_64 ((PTR), (HIGH), (LOW)); \
470 * (LOW) = * (HIGH) = 0; \
475 typedef struct State_Machine_Registers
484 unsigned char op_index
;
485 unsigned char end_sequence
;
486 /* This variable hold the number of the last entry seen
487 in the File Table. */
488 unsigned int last_file_entry
;
491 static SMR state_machine_regs
;
494 reset_state_machine (int is_stmt
)
496 state_machine_regs
.address
= 0;
497 state_machine_regs
.view
= 0;
498 state_machine_regs
.op_index
= 0;
499 state_machine_regs
.file
= 1;
500 state_machine_regs
.line
= 1;
501 state_machine_regs
.column
= 0;
502 state_machine_regs
.is_stmt
= is_stmt
;
503 state_machine_regs
.basic_block
= 0;
504 state_machine_regs
.end_sequence
= 0;
505 state_machine_regs
.last_file_entry
= 0;
508 /* Handled an extend line op.
509 Returns the number of bytes read. */
512 process_extended_line_op (unsigned char * data
,
516 unsigned char op_code
;
517 size_t len
, header_len
;
519 unsigned char *orig_data
= data
;
522 READ_ULEB (len
, data
, end
);
523 header_len
= data
- orig_data
;
525 if (len
== 0 || data
== end
|| len
> (size_t) (end
- data
))
527 warn (_("Badly formed extended line op encountered!\n"));
533 printf (_(" Extended opcode %d: "), op_code
);
537 case DW_LNE_end_sequence
:
538 printf (_("End of Sequence\n\n"));
539 reset_state_machine (is_stmt
);
542 case DW_LNE_set_address
:
543 /* PR 17512: file: 002-100480-0.004. */
546 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
547 (unsigned long) len
- 1);
551 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
552 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
553 state_machine_regs
.address
= adr
;
554 state_machine_regs
.view
= 0;
555 state_machine_regs
.op_index
= 0;
558 case DW_LNE_define_file
:
559 printf (_("define new File Table entry\n"));
560 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
561 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
567 l
= strnlen ((char *) data
, end
- data
);
569 READ_ULEB (val
, data
, end
);
570 printf ("%s\t", dwarf_vmatoa ("u", val
));
571 READ_ULEB (val
, data
, end
);
572 printf ("%s\t", dwarf_vmatoa ("u", val
));
573 READ_ULEB (val
, data
, end
);
574 printf ("%s\t", dwarf_vmatoa ("u", val
));
575 printf ("%.*s\n\n", (int) l
, name
);
578 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
== end
)
579 warn (_("DW_LNE_define_file: Bad opcode length\n"));
582 case DW_LNE_set_discriminator
:
583 READ_ULEB (val
, data
, end
);
584 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
588 case DW_LNE_HP_negate_is_UV_update
:
589 printf ("DW_LNE_HP_negate_is_UV_update\n");
591 case DW_LNE_HP_push_context
:
592 printf ("DW_LNE_HP_push_context\n");
594 case DW_LNE_HP_pop_context
:
595 printf ("DW_LNE_HP_pop_context\n");
597 case DW_LNE_HP_set_file_line_column
:
598 printf ("DW_LNE_HP_set_file_line_column\n");
600 case DW_LNE_HP_set_routine_name
:
601 printf ("DW_LNE_HP_set_routine_name\n");
603 case DW_LNE_HP_set_sequence
:
604 printf ("DW_LNE_HP_set_sequence\n");
606 case DW_LNE_HP_negate_post_semantics
:
607 printf ("DW_LNE_HP_negate_post_semantics\n");
609 case DW_LNE_HP_negate_function_exit
:
610 printf ("DW_LNE_HP_negate_function_exit\n");
612 case DW_LNE_HP_negate_front_end_logical
:
613 printf ("DW_LNE_HP_negate_front_end_logical\n");
615 case DW_LNE_HP_define_proc
:
616 printf ("DW_LNE_HP_define_proc\n");
618 case DW_LNE_HP_source_file_correlation
:
620 unsigned char *edata
= data
+ len
- 1;
622 printf ("DW_LNE_HP_source_file_correlation\n");
628 READ_ULEB (opc
, data
, edata
);
632 case DW_LNE_HP_SFC_formfeed
:
633 printf (" DW_LNE_HP_SFC_formfeed\n");
635 case DW_LNE_HP_SFC_set_listing_line
:
636 READ_ULEB (val
, data
, edata
);
637 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
638 dwarf_vmatoa ("u", val
));
640 case DW_LNE_HP_SFC_associate
:
641 printf (" DW_LNE_HP_SFC_associate ");
642 READ_ULEB (val
, data
, edata
);
643 printf ("(%s", dwarf_vmatoa ("u", val
));
644 READ_ULEB (val
, data
, edata
);
645 printf (",%s", dwarf_vmatoa ("u", val
));
646 READ_ULEB (val
, data
, edata
);
647 printf (",%s)\n", dwarf_vmatoa ("u", val
));
650 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
660 unsigned int rlen
= len
- 1;
662 if (op_code
>= DW_LNE_lo_user
663 /* The test against DW_LNW_hi_user is redundant due to
664 the limited range of the unsigned char data type used
666 /*&& op_code <= DW_LNE_hi_user*/)
667 printf (_("user defined: "));
669 printf (_("UNKNOWN: "));
670 printf (_("length %d ["), rlen
);
672 printf (" %02x", *data
++);
678 return len
+ header_len
;
681 static const unsigned char *
682 fetch_indirect_string (dwarf_vma offset
)
684 struct dwarf_section
*section
= &debug_displays
[str
].section
;
685 const unsigned char * ret
;
687 if (section
->start
== NULL
)
688 return (const unsigned char *) _("<no .debug_str section>");
690 if (offset
>= section
->size
)
692 warn (_("DW_FORM_strp offset too big: %s\n"),
693 dwarf_vmatoa ("x", offset
));
694 return (const unsigned char *) _("<offset is too big>");
697 ret
= section
->start
+ offset
;
698 /* Unfortunately we cannot rely upon the .debug_str section ending with a
699 NUL byte. Since our caller is expecting to receive a well formed C
700 string we test for the lack of a terminating byte here. */
701 if (strnlen ((const char *) ret
, section
->size
- offset
)
702 == section
->size
- offset
)
703 ret
= (const unsigned char *)
704 _("<no NUL byte at end of .debug_str section>");
709 static const unsigned char *
710 fetch_indirect_line_string (dwarf_vma offset
)
712 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
713 const unsigned char * ret
;
715 if (section
->start
== NULL
)
716 return (const unsigned char *) _("<no .debug_line_str section>");
718 if (offset
>= section
->size
)
720 warn (_("DW_FORM_line_strp offset too big: %s\n"),
721 dwarf_vmatoa ("x", offset
));
722 return (const unsigned char *) _("<offset is too big>");
725 ret
= section
->start
+ offset
;
726 /* Unfortunately we cannot rely upon the .debug_line_str section ending
727 with a NUL byte. Since our caller is expecting to receive a well formed
728 C string we test for the lack of a terminating byte here. */
729 if (strnlen ((const char *) ret
, section
->size
- offset
)
730 == section
->size
- offset
)
731 ret
= (const unsigned char *)
732 _("<no NUL byte at end of .debug_line_str section>");
738 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
739 dwarf_vma offset_size
, bfd_boolean dwo
)
741 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
742 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
743 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
744 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
745 dwarf_vma index_offset
;
746 dwarf_vma str_offset
;
748 unsigned char *curr
= index_section
->start
;
749 const unsigned char *end
= curr
+ index_section
->size
;
752 if (index_section
->start
== NULL
)
753 return (dwo
? _("<no .debug_str_offsets.dwo section>")
754 : _("<no .debug_str_offsets section>"));
756 if (str_section
->start
== NULL
)
757 return (dwo
? _("<no .debug_str.dwo section>")
758 : _("<no .debug_str section>"));
760 /* FIXME: We should cache the length... */
761 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
762 if (length
== 0xffffffff)
764 if (offset_size
!= 8)
765 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
766 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
768 else if (offset_size
!= 4)
770 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
775 /* This is probably an old style .debug_str_offset section which
776 just contains offsets and no header (and the first offset is 0). */
777 curr
= index_section
->start
;
778 length
= index_section
->size
;
782 /* Skip the version and padding bytes.
783 We assume that they are correct. */
786 /* FIXME: The code below assumes that there is only one table
787 in the .debug_str_offsets section, so check that now. */
788 if ((offset_size
== 4 && curr
+ length
< (end
- 8))
789 || (offset_size
== 8 && curr
+ length
< (end
- 16)))
791 warn (_("index table size is too small %s vs %s\n"),
792 dwarf_vmatoa ("x", length
),
793 dwarf_vmatoa ("x", index_section
->size
));
794 return _("<table too small>");
798 index_offset
= idx
* offset_size
;
800 if (this_set
!= NULL
)
801 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
803 if (index_offset
>= length
)
805 warn (_("DW_FORM_GNU_str_index offset too big: %s vs %s\n"),
806 dwarf_vmatoa ("x", index_offset
),
807 dwarf_vmatoa ("x", length
));
808 return _("<index offset is too big>");
811 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
812 str_offset
-= str_section
->address
;
813 if (str_offset
>= str_section
->size
)
815 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
816 dwarf_vmatoa ("x", str_offset
));
817 return _("<indirect index offset is too big>");
820 ret
= (const char *) str_section
->start
+ str_offset
;
821 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
822 Since our caller is expecting to receive a well formed C string we test
823 for the lack of a terminating byte here. */
824 if (strnlen (ret
, str_section
->size
- str_offset
)
825 == str_section
->size
- str_offset
)
826 ret
= (const char *) _("<no NUL byte at end of section>");
832 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
834 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
836 if (section
->start
== NULL
)
837 return (_("<no .debug_addr section>"));
839 if (offset
+ bytes
> section
->size
)
841 warn (_("Offset into section %s too big: %s\n"),
842 section
->name
, dwarf_vmatoa ("x", offset
));
843 return "<offset too big>";
846 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
850 /* FIXME: There are better and more efficient ways to handle
851 these structures. For now though, I just want something that
852 is simple to implement. */
853 /* Records a single attribute in an abbrev. */
854 typedef struct abbrev_attr
856 unsigned long attribute
;
858 bfd_signed_vma implicit_const
;
859 struct abbrev_attr
* next
;
863 /* Records a single abbrev. */
864 typedef struct abbrev_entry
866 unsigned long number
;
869 struct abbrev_attr
* first_attr
;
870 struct abbrev_attr
* last_attr
;
871 struct abbrev_entry
* next
;
875 /* Records a set of abbreviations. */
876 typedef struct abbrev_list
878 abbrev_entry
* first_abbrev
;
879 abbrev_entry
* last_abbrev
;
880 dwarf_vma abbrev_base
;
881 dwarf_vma abbrev_offset
;
882 struct abbrev_list
* next
;
883 unsigned char * start_of_next_abbrevs
;
887 /* Records all the abbrevs found so far. */
888 static struct abbrev_list
* abbrev_lists
= NULL
;
890 typedef struct abbrev_map
897 /* Maps between CU offsets and abbrev sets. */
898 static abbrev_map
* cu_abbrev_map
= NULL
;
899 static unsigned long num_abbrev_map_entries
= 0;
900 static unsigned long next_free_abbrev_map_entry
= 0;
902 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
903 #define ABBREV_MAP_ENTRIES_INCREMENT 8
906 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
908 if (cu_abbrev_map
== NULL
)
910 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
911 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
913 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
915 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
916 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
919 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
920 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
921 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
922 next_free_abbrev_map_entry
++;
926 free_all_abbrevs (void)
930 for (list
= abbrev_lists
; list
!= NULL
;)
932 abbrev_list
* next
= list
->next
;
933 abbrev_entry
* abbrv
;
935 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
937 abbrev_entry
* next_abbrev
= abbrv
->next
;
940 for (attr
= abbrv
->first_attr
; attr
;)
942 abbrev_attr
*next_attr
= attr
->next
;
960 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
962 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
964 list
->abbrev_base
= abbrev_base
;
965 list
->abbrev_offset
= abbrev_offset
;
967 list
->next
= abbrev_lists
;
974 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
975 dwarf_vma abbrev_offset
)
979 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
980 if (list
->abbrev_base
== abbrev_base
981 && list
->abbrev_offset
== abbrev_offset
)
987 /* Find the abbreviation map for the CU that includes OFFSET.
988 OFFSET is an absolute offset from the start of the .debug_info section. */
989 /* FIXME: This function is going to slow down readelf & objdump.
990 Consider using a better algorithm to mitigate this effect. */
993 find_abbrev_map_by_offset (dwarf_vma offset
)
997 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
998 if (cu_abbrev_map
[i
].start
<= offset
999 && cu_abbrev_map
[i
].end
> offset
)
1000 return cu_abbrev_map
+ i
;
1006 add_abbrev (unsigned long number
,
1011 abbrev_entry
* entry
;
1013 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
1015 entry
->number
= number
;
1017 entry
->children
= children
;
1018 entry
->first_attr
= NULL
;
1019 entry
->last_attr
= NULL
;
1022 assert (list
!= NULL
);
1024 if (list
->first_abbrev
== NULL
)
1025 list
->first_abbrev
= entry
;
1027 list
->last_abbrev
->next
= entry
;
1029 list
->last_abbrev
= entry
;
1033 add_abbrev_attr (unsigned long attribute
,
1035 bfd_signed_vma implicit_const
,
1040 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1042 attr
->attribute
= attribute
;
1044 attr
->implicit_const
= implicit_const
;
1047 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1049 if (list
->last_abbrev
->first_attr
== NULL
)
1050 list
->last_abbrev
->first_attr
= attr
;
1052 list
->last_abbrev
->last_attr
->next
= attr
;
1054 list
->last_abbrev
->last_attr
= attr
;
1057 /* Processes the (partial) contents of a .debug_abbrev section.
1058 Returns NULL if the end of the section was encountered.
1059 Returns the address after the last byte read if the end of
1060 an abbreviation set was found. */
1062 static unsigned char *
1063 process_abbrev_set (unsigned char * start
,
1064 const unsigned char * end
,
1069 unsigned long entry
;
1071 unsigned long attribute
;
1074 READ_ULEB (entry
, start
, end
);
1076 /* A single zero is supposed to end the set according
1077 to the standard. If there's more, then signal that to
1084 READ_ULEB (tag
, start
, end
);
1088 children
= *start
++;
1090 add_abbrev (entry
, tag
, children
, list
);
1095 /* Initialize it due to a false compiler warning. */
1096 bfd_signed_vma implicit_const
= -1;
1098 READ_ULEB (attribute
, start
, end
);
1102 READ_ULEB (form
, start
, end
);
1106 if (form
== DW_FORM_implicit_const
)
1108 READ_SLEB (implicit_const
, start
, end
);
1113 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1115 while (attribute
!= 0);
1118 /* Report the missing single zero which ends the section. */
1119 error (_(".debug_abbrev section not zero terminated\n"));
1125 get_TAG_name (unsigned long tag
)
1127 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1131 static char buffer
[100];
1133 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1134 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1136 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1144 get_FORM_name (unsigned long form
)
1149 return "DW_FORM value: 0";
1151 name
= get_DW_FORM_name (form
);
1154 static char buffer
[100];
1156 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1164 get_IDX_name (unsigned long idx
)
1166 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1170 static char buffer
[100];
1172 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1179 static unsigned char *
1180 display_block (unsigned char *data
,
1182 const unsigned char * const end
, char delimiter
)
1186 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1188 return (unsigned char *) end
;
1190 maxlen
= (dwarf_vma
) (end
- data
);
1191 length
= length
> maxlen
? maxlen
: length
;
1194 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1200 decode_location_expression (unsigned char * data
,
1201 unsigned int pointer_size
,
1202 unsigned int offset_size
,
1205 dwarf_vma cu_offset
,
1206 struct dwarf_section
* section
)
1210 dwarf_signed_vma svalue
;
1211 unsigned char *end
= data
+ length
;
1212 int need_frame_base
= 0;
1221 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1222 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1225 printf ("DW_OP_deref");
1228 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1229 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1232 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1233 printf ("DW_OP_const1s: %ld", (long) svalue
);
1236 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1237 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1240 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1241 printf ("DW_OP_const2s: %ld", (long) svalue
);
1244 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1245 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1248 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1249 printf ("DW_OP_const4s: %ld", (long) svalue
);
1252 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1253 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1254 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1255 printf ("%lu", (unsigned long) uvalue
);
1258 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1259 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1260 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1261 printf ("%ld", (long) svalue
);
1264 READ_ULEB (uvalue
, data
, end
);
1265 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1268 READ_SLEB (svalue
, data
, end
);
1269 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1272 printf ("DW_OP_dup");
1275 printf ("DW_OP_drop");
1278 printf ("DW_OP_over");
1281 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1282 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1285 printf ("DW_OP_swap");
1288 printf ("DW_OP_rot");
1291 printf ("DW_OP_xderef");
1294 printf ("DW_OP_abs");
1297 printf ("DW_OP_and");
1300 printf ("DW_OP_div");
1303 printf ("DW_OP_minus");
1306 printf ("DW_OP_mod");
1309 printf ("DW_OP_mul");
1312 printf ("DW_OP_neg");
1315 printf ("DW_OP_not");
1318 printf ("DW_OP_or");
1321 printf ("DW_OP_plus");
1323 case DW_OP_plus_uconst
:
1324 READ_ULEB (uvalue
, data
, end
);
1325 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1328 printf ("DW_OP_shl");
1331 printf ("DW_OP_shr");
1334 printf ("DW_OP_shra");
1337 printf ("DW_OP_xor");
1340 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1341 printf ("DW_OP_bra: %ld", (long) svalue
);
1344 printf ("DW_OP_eq");
1347 printf ("DW_OP_ge");
1350 printf ("DW_OP_gt");
1353 printf ("DW_OP_le");
1356 printf ("DW_OP_lt");
1359 printf ("DW_OP_ne");
1362 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1363 printf ("DW_OP_skip: %ld", (long) svalue
);
1398 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1433 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1434 regname (op
- DW_OP_reg0
, 1));
1469 READ_SLEB (svalue
, data
, end
);
1470 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1471 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1475 READ_ULEB (uvalue
, data
, end
);
1476 printf ("DW_OP_regx: %s (%s)",
1477 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1480 need_frame_base
= 1;
1481 READ_SLEB (svalue
, data
, end
);
1482 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1485 READ_ULEB (uvalue
, data
, end
);
1486 READ_SLEB (svalue
, data
, end
);
1487 printf ("DW_OP_bregx: %s (%s) %s",
1488 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1489 dwarf_vmatoa ("d", svalue
));
1492 READ_ULEB (uvalue
, data
, end
);
1493 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1495 case DW_OP_deref_size
:
1496 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1497 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1499 case DW_OP_xderef_size
:
1500 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1501 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1504 printf ("DW_OP_nop");
1507 /* DWARF 3 extensions. */
1508 case DW_OP_push_object_address
:
1509 printf ("DW_OP_push_object_address");
1512 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1513 this ought to be an 8-byte wide computation. */
1514 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1515 printf ("DW_OP_call2: <0x%s>",
1516 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1519 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1520 this ought to be an 8-byte wide computation. */
1521 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1522 printf ("DW_OP_call4: <0x%s>",
1523 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1525 case DW_OP_call_ref
:
1526 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1527 this ought to be an 8-byte wide computation. */
1528 if (dwarf_version
== -1)
1530 printf (_("(DW_OP_call_ref in frame info)"));
1531 /* No way to tell where the next op is, so just bail. */
1532 return need_frame_base
;
1534 if (dwarf_version
== 2)
1536 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1540 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1542 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1544 case DW_OP_form_tls_address
:
1545 printf ("DW_OP_form_tls_address");
1547 case DW_OP_call_frame_cfa
:
1548 printf ("DW_OP_call_frame_cfa");
1550 case DW_OP_bit_piece
:
1551 printf ("DW_OP_bit_piece: ");
1552 READ_ULEB (uvalue
, data
, end
);
1553 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1554 READ_ULEB (uvalue
, data
, end
);
1555 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1558 /* DWARF 4 extensions. */
1559 case DW_OP_stack_value
:
1560 printf ("DW_OP_stack_value");
1563 case DW_OP_implicit_value
:
1564 printf ("DW_OP_implicit_value");
1565 READ_ULEB (uvalue
, data
, end
);
1566 data
= display_block (data
, uvalue
, end
, ' ');
1569 /* GNU extensions. */
1570 case DW_OP_GNU_push_tls_address
:
1571 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1573 case DW_OP_GNU_uninit
:
1574 printf ("DW_OP_GNU_uninit");
1575 /* FIXME: Is there data associated with this OP ? */
1577 case DW_OP_GNU_encoded_addr
:
1584 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1586 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1587 print_dwarf_vma (addr
, pointer_size
);
1590 case DW_OP_implicit_pointer
:
1591 case DW_OP_GNU_implicit_pointer
:
1592 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1593 this ought to be an 8-byte wide computation. */
1594 if (dwarf_version
== -1)
1596 printf (_("(%s in frame info)"),
1597 (op
== DW_OP_implicit_pointer
1598 ? "DW_OP_implicit_pointer"
1599 : "DW_OP_GNU_implicit_pointer"));
1600 /* No way to tell where the next op is, so just bail. */
1601 return need_frame_base
;
1603 if (dwarf_version
== 2)
1605 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1609 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1611 READ_SLEB (svalue
, data
, end
);
1612 printf ("%s: <0x%s> %s",
1613 (op
== DW_OP_implicit_pointer
1614 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1615 dwarf_vmatoa ("x", uvalue
),
1616 dwarf_vmatoa ("d", svalue
));
1618 case DW_OP_entry_value
:
1619 case DW_OP_GNU_entry_value
:
1620 READ_ULEB (uvalue
, data
, end
);
1621 /* PR 17531: file: 0cc9cd00. */
1622 if (uvalue
> (dwarf_vma
) (end
- data
))
1623 uvalue
= end
- data
;
1624 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1625 : "DW_OP_GNU_entry_value"));
1626 if (decode_location_expression (data
, pointer_size
, offset_size
,
1627 dwarf_version
, uvalue
,
1628 cu_offset
, section
))
1629 need_frame_base
= 1;
1635 case DW_OP_const_type
:
1636 case DW_OP_GNU_const_type
:
1637 READ_ULEB (uvalue
, data
, end
);
1638 printf ("%s: <0x%s> ",
1639 (op
== DW_OP_const_type
? "DW_OP_const_type"
1640 : "DW_OP_GNU_const_type"),
1641 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1642 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1643 data
= display_block (data
, uvalue
, end
, ' ');
1645 case DW_OP_regval_type
:
1646 case DW_OP_GNU_regval_type
:
1647 READ_ULEB (uvalue
, data
, end
);
1648 printf ("%s: %s (%s)",
1649 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1650 : "DW_OP_GNU_regval_type"),
1651 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1652 READ_ULEB (uvalue
, data
, end
);
1653 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1655 case DW_OP_deref_type
:
1656 case DW_OP_GNU_deref_type
:
1657 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1659 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1660 : "DW_OP_GNU_deref_type"),
1662 READ_ULEB (uvalue
, data
, end
);
1663 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1666 case DW_OP_GNU_convert
:
1667 READ_ULEB (uvalue
, data
, end
);
1668 printf ("%s <0x%s>",
1669 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1670 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1672 case DW_OP_reinterpret
:
1673 case DW_OP_GNU_reinterpret
:
1674 READ_ULEB (uvalue
, data
, end
);
1675 printf ("%s <0x%s>",
1676 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1677 : "DW_OP_GNU_reinterpret"),
1678 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1680 case DW_OP_GNU_parameter_ref
:
1681 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1682 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1683 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1685 case DW_OP_GNU_addr_index
:
1686 READ_ULEB (uvalue
, data
, end
);
1687 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1689 case DW_OP_GNU_const_index
:
1690 READ_ULEB (uvalue
, data
, end
);
1691 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1693 case DW_OP_GNU_variable_value
:
1694 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1695 this ought to be an 8-byte wide computation. */
1696 if (dwarf_version
== -1)
1698 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1699 /* No way to tell where the next op is, so just bail. */
1700 return need_frame_base
;
1702 if (dwarf_version
== 2)
1704 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1708 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1710 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1713 /* HP extensions. */
1714 case DW_OP_HP_is_value
:
1715 printf ("DW_OP_HP_is_value");
1716 /* FIXME: Is there data associated with this OP ? */
1718 case DW_OP_HP_fltconst4
:
1719 printf ("DW_OP_HP_fltconst4");
1720 /* FIXME: Is there data associated with this OP ? */
1722 case DW_OP_HP_fltconst8
:
1723 printf ("DW_OP_HP_fltconst8");
1724 /* FIXME: Is there data associated with this OP ? */
1726 case DW_OP_HP_mod_range
:
1727 printf ("DW_OP_HP_mod_range");
1728 /* FIXME: Is there data associated with this OP ? */
1730 case DW_OP_HP_unmod_range
:
1731 printf ("DW_OP_HP_unmod_range");
1732 /* FIXME: Is there data associated with this OP ? */
1735 printf ("DW_OP_HP_tls");
1736 /* FIXME: Is there data associated with this OP ? */
1739 /* PGI (STMicroelectronics) extensions. */
1740 case DW_OP_PGI_omp_thread_num
:
1741 /* Pushes the thread number for the current thread as it would be
1742 returned by the standard OpenMP library function:
1743 omp_get_thread_num(). The "current thread" is the thread for
1744 which the expression is being evaluated. */
1745 printf ("DW_OP_PGI_omp_thread_num");
1749 if (op
>= DW_OP_lo_user
1750 && op
<= DW_OP_hi_user
)
1751 printf (_("(User defined location op 0x%x)"), op
);
1753 printf (_("(Unknown location op 0x%x)"), op
);
1754 /* No way to tell where the next op is, so just bail. */
1755 return need_frame_base
;
1758 /* Separate the ops. */
1763 return need_frame_base
;
1766 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1767 This is used for DWARF package files. */
1769 static struct cu_tu_set
*
1770 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1772 struct cu_tu_set
*p
;
1774 unsigned int dw_sect
;
1780 dw_sect
= DW_SECT_TYPES
;
1786 dw_sect
= DW_SECT_INFO
;
1790 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1798 /* Add INC to HIGH_BITS:LOW_BITS. */
1800 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1802 dwarf_vma tmp
= * low_bits
;
1806 /* FIXME: There is probably a better way of handling this:
1808 We need to cope with dwarf_vma being a 32-bit or 64-bit
1809 type. Plus regardless of its size LOW_BITS is meant to
1810 only hold 32-bits, so if there is overflow or wrap around
1811 we must propagate into HIGH_BITS. */
1812 if (tmp
< * low_bits
)
1816 else if (sizeof (tmp
) > 8
1827 fetch_alt_indirect_string (dwarf_vma offset
)
1831 if (! do_follow_links
)
1834 if (first_separate_info
== NULL
)
1835 return _("<no links available>");
1837 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1839 struct dwarf_section
* section
;
1842 if (! load_debug_section (separate_debug_str
, i
->handle
))
1845 section
= &debug_displays
[separate_debug_str
].section
;
1847 if (section
->start
== NULL
)
1850 if (offset
>= section
->size
)
1853 ret
= (const char *) (section
->start
+ offset
);
1854 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1855 NUL byte. Since our caller is expecting to receive a well formed C
1856 string we test for the lack of a terminating byte here. */
1857 if (strnlen ((const char *) ret
, section
->size
- offset
)
1858 == section
->size
- offset
)
1859 return _("<no NUL byte at end of alt .debug_str section>");
1864 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1865 dwarf_vmatoa ("x", offset
));
1866 return _("<offset is too big>");
1870 get_AT_name (unsigned long attribute
)
1875 return "DW_AT value: 0";
1877 /* One value is shared by the MIPS and HP extensions: */
1878 if (attribute
== DW_AT_MIPS_fde
)
1879 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1881 name
= get_DW_AT_name (attribute
);
1885 static char buffer
[100];
1887 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1896 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1898 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1900 dwinfo
->type
= type
;
1901 dwinfo
->value
= value
;
1902 dwinfo
->cu_offset
= cu_offset
;
1903 dwinfo
->next
= first_dwo_info
;
1904 first_dwo_info
= dwinfo
;
1908 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1910 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1914 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1916 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1920 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1922 add_dwo_info (id
, cu_offset
, DWO_ID
);
1926 free_dwo_info (void)
1931 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1933 next
= dwinfo
->next
;
1936 first_dwo_info
= NULL
;
1939 /* Ensure that START + UVALUE is less than END.
1940 Return an adjusted UVALUE if necessary to ensure this relationship. */
1942 static inline dwarf_vma
1943 check_uvalue (const unsigned char * start
,
1945 const unsigned char * end
)
1947 dwarf_vma max_uvalue
= end
- start
;
1949 /* See PR 17512: file: 008-103549-0.001:0.1.
1950 and PR 24829 for examples of where these tests are triggered. */
1951 if (uvalue
> max_uvalue
)
1953 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1954 uvalue
= max_uvalue
;
1960 static unsigned char *
1961 skip_attr_bytes (unsigned long form
,
1962 unsigned char * data
,
1963 unsigned const char * end
,
1964 dwarf_vma pointer_size
,
1965 dwarf_vma offset_size
,
1967 dwarf_vma
* value_return
)
1969 dwarf_signed_vma svalue
;
1970 dwarf_vma uvalue
= 0;
1976 case DW_FORM_ref_addr
:
1977 if (dwarf_version
== 2)
1978 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1979 else if (dwarf_version
> 2)
1980 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1986 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1990 case DW_FORM_line_strp
:
1991 case DW_FORM_sec_offset
:
1992 case DW_FORM_GNU_ref_alt
:
1993 case DW_FORM_GNU_strp_alt
:
1994 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1997 case DW_FORM_flag_present
:
2004 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2009 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2014 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2018 READ_SLEB (svalue
, data
, end
);
2022 case DW_FORM_ref_udata
:
2024 case DW_FORM_GNU_str_index
:
2025 case DW_FORM_GNU_addr_index
:
2026 READ_ULEB (uvalue
, data
, end
);
2031 dwarf_vma high_bits
;
2033 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2035 if (sizeof (uvalue
) > 4)
2036 uvalue
+= high_bits
<< 32;
2037 else if (high_bits
!= 0)
2039 /* FIXME: What to do ? */
2046 case DW_FORM_ref_sig8
:
2050 case DW_FORM_data16
:
2054 case DW_FORM_string
:
2055 data
+= strnlen ((char *) data
, end
- data
) + 1;
2059 case DW_FORM_exprloc
:
2060 READ_ULEB (uvalue
, data
, end
);
2064 case DW_FORM_block1
:
2065 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
2069 case DW_FORM_block2
:
2070 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2074 case DW_FORM_block4
:
2075 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2079 case DW_FORM_indirect
:
2080 READ_ULEB (form
, data
, end
);
2081 if (form
== DW_FORM_implicit_const
)
2082 SKIP_ULEB (data
, end
);
2083 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
, value_return
);
2089 * value_return
= uvalue
;
2091 data
= (unsigned char *) end
;
2095 /* Given form FORM with value UVALUE, locate and return the abbreviation
2096 associated with it. */
2098 static abbrev_entry
*
2099 get_type_abbrev_from_form (unsigned long form
,
2100 unsigned long uvalue
,
2101 dwarf_vma cu_offset
,
2102 const struct dwarf_section
* section
,
2103 unsigned long * abbrev_num_return
,
2104 unsigned char ** data_return
,
2105 unsigned long * cu_offset_return
)
2107 unsigned long abbrev_number
;
2109 abbrev_entry
* entry
;
2110 unsigned char * data
;
2112 if (abbrev_num_return
!= NULL
)
2113 * abbrev_num_return
= 0;
2114 if (data_return
!= NULL
)
2115 * data_return
= NULL
;
2119 case DW_FORM_GNU_ref_alt
:
2120 case DW_FORM_ref_sig8
:
2121 /* FIXME: We are unable to handle this form at the moment. */
2124 case DW_FORM_ref_addr
:
2125 if (uvalue
>= section
->size
)
2127 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2128 uvalue
, (long) section
->size
, section
->name
);
2137 case DW_FORM_ref_udata
:
2138 if (uvalue
+ cu_offset
> section
->size
)
2140 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2141 uvalue
, (long) cu_offset
, (long) section
->size
);
2144 uvalue
+= cu_offset
;
2147 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2150 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2154 data
= (unsigned char *) section
->start
+ uvalue
;
2155 map
= find_abbrev_map_by_offset (uvalue
);
2159 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2162 if (map
->list
== NULL
)
2164 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2168 if (cu_offset_return
!= NULL
)
2170 if (form
== DW_FORM_ref_addr
)
2171 * cu_offset_return
= map
->start
;
2173 * cu_offset_return
= cu_offset
;
2176 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2178 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2179 if (entry
->number
== abbrev_number
)
2182 if (abbrev_num_return
!= NULL
)
2183 * abbrev_num_return
= abbrev_number
;
2185 if (data_return
!= NULL
)
2186 * data_return
= data
;
2189 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2194 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2195 can be determined to be a signed type. The data for ENTRY can be
2196 found starting at DATA. */
2199 get_type_signedness (abbrev_entry
* entry
,
2200 const struct dwarf_section
* section
,
2201 unsigned char * data
,
2202 unsigned const char * end
,
2203 dwarf_vma cu_offset
,
2204 dwarf_vma pointer_size
,
2205 dwarf_vma offset_size
,
2207 bfd_boolean
* is_signed
,
2208 unsigned int nesting
)
2212 * is_signed
= FALSE
;
2214 #define MAX_NESTING 20
2215 if (nesting
> MAX_NESTING
)
2217 /* FIXME: Warn - or is this expected ?
2218 NB/ We need to avoid infinite recursion. */
2222 for (attr
= entry
->first_attr
;
2223 attr
!= NULL
&& attr
->attribute
;
2226 unsigned char * orig_data
= data
;
2227 dwarf_vma uvalue
= 0;
2229 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2230 offset_size
, dwarf_version
, & uvalue
);
2234 switch (attr
->attribute
)
2236 case DW_AT_linkage_name
:
2240 if (attr
->form
== DW_FORM_strp
)
2241 printf (", %s", fetch_indirect_string (uvalue
));
2242 else if (attr
->form
== DW_FORM_string
)
2243 printf (", %s", orig_data
);
2250 abbrev_entry
* type_abbrev
;
2251 unsigned char * type_data
;
2252 unsigned long type_cu_offset
;
2254 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2258 NULL
/* abbrev num return */,
2261 if (type_abbrev
== NULL
)
2264 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2265 pointer_size
, offset_size
, dwarf_version
,
2266 is_signed
, nesting
+ 1);
2270 case DW_AT_encoding
:
2271 /* Determine signness. */
2274 case DW_ATE_address
:
2275 /* FIXME - some architectures have signed addresses. */
2276 case DW_ATE_boolean
:
2277 case DW_ATE_unsigned
:
2278 case DW_ATE_unsigned_char
:
2279 case DW_ATE_unsigned_fixed
:
2280 * is_signed
= FALSE
;
2284 case DW_ATE_complex_float
:
2287 case DW_ATE_signed_char
:
2288 case DW_ATE_imaginary_float
:
2289 case DW_ATE_decimal_float
:
2290 case DW_ATE_signed_fixed
:
2300 read_and_print_leb128 (unsigned char * data
,
2301 unsigned int * bytes_read
,
2302 unsigned const char * end
,
2303 bfd_boolean is_signed
)
2306 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2308 report_leb_status (status
, __FILE__
, __LINE__
);
2310 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2314 display_discr_list (unsigned long form
,
2316 unsigned char * data
,
2317 unsigned const char * end
,
2322 printf ("[default]");
2329 case DW_FORM_block1
:
2330 case DW_FORM_block2
:
2331 case DW_FORM_block4
:
2332 /* Move data pointer back to the start of the byte array. */
2336 printf ("<corrupt>\n");
2337 warn (_("corrupt discr_list - not using a block form\n"));
2343 printf ("<corrupt>\n");
2344 warn (_("corrupt discr_list - block not long enough\n"));
2348 bfd_boolean is_signed
=
2349 (level
> 0 && level
<= MAX_CU_NESTING
)
2350 ? level_type_signed
[level
- 1] : FALSE
;
2355 unsigned char discriminant
;
2356 unsigned int bytes_read
;
2358 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2362 assert (uvalue
> 0);
2363 switch (discriminant
)
2367 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2368 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2369 uvalue
-= bytes_read
;
2375 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2376 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2377 uvalue
-= bytes_read
;
2381 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2382 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2383 uvalue
-= bytes_read
;
2388 printf ("<corrupt>\n");
2389 warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"),
2399 printf (")(signed)");
2401 printf (")(unsigned)");
2404 static unsigned char *
2405 read_and_display_attr_value (unsigned long attribute
,
2407 dwarf_signed_vma implicit_const
,
2408 unsigned char * start
,
2409 unsigned char * data
,
2410 unsigned char * end
,
2411 dwarf_vma cu_offset
,
2412 dwarf_vma pointer_size
,
2413 dwarf_vma offset_size
,
2415 debug_info
* debug_info_p
,
2417 struct dwarf_section
* section
,
2418 struct cu_tu_set
* this_set
,
2422 dwarf_signed_vma svalue
;
2423 dwarf_vma uvalue
= 0;
2424 unsigned char * block_start
= NULL
;
2425 unsigned char * orig_data
= data
;
2427 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2429 warn (_("Corrupt attribute\n"));
2433 if (do_wide
&& ! do_loc
)
2435 /* PR 26847: Display the name of the form. */
2436 const char * name
= get_FORM_name (form
);
2438 /* For convenience we skip the DW_FORM_ prefix to the name. */
2440 name
+= 8; /* strlen ("DW_FORM_") */
2441 printf ("%c(%s)", delimiter
, name
);
2449 case DW_FORM_ref_addr
:
2450 if (dwarf_version
== 2)
2451 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2452 else if (dwarf_version
> 2)
2453 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2455 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2459 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2463 case DW_FORM_line_strp
:
2464 case DW_FORM_sec_offset
:
2465 case DW_FORM_GNU_ref_alt
:
2466 case DW_FORM_GNU_strp_alt
:
2467 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2470 case DW_FORM_flag_present
:
2477 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2482 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2487 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2491 READ_SLEB (svalue
, data
, end
);
2495 case DW_FORM_GNU_str_index
:
2496 case DW_FORM_ref_udata
:
2498 case DW_FORM_GNU_addr_index
:
2499 READ_ULEB (uvalue
, data
, end
);
2502 case DW_FORM_indirect
:
2503 READ_ULEB (form
, data
, end
);
2505 printf ("%c%s", delimiter
, get_FORM_name (form
));
2506 if (form
== DW_FORM_implicit_const
)
2507 READ_SLEB (implicit_const
, data
, end
);
2508 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2510 cu_offset
, pointer_size
,
2511 offset_size
, dwarf_version
,
2512 debug_info_p
, do_loc
,
2513 section
, this_set
, delimiter
, level
);
2518 case DW_FORM_ref_addr
:
2520 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2523 case DW_FORM_GNU_ref_alt
:
2527 /* We have already printed the form name. */
2528 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2530 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2532 /* FIXME: Follow the reference... */
2538 case DW_FORM_ref_udata
:
2540 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2545 case DW_FORM_sec_offset
:
2547 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2550 case DW_FORM_flag_present
:
2557 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2560 case DW_FORM_implicit_const
:
2562 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2569 dwarf_vma high_bits
;
2573 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2575 if (form
== DW_FORM_ref8
)
2576 add64 (& high_bits
, & utmp
, cu_offset
);
2577 printf ("%c0x%s", delimiter
,
2578 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2581 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2582 && num_debug_info_entries
== 0)
2584 if (sizeof (uvalue
) == 8)
2585 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2587 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2593 case DW_FORM_data16
:
2596 dwarf_vma left_high_bits
, left_low_bits
;
2597 dwarf_vma right_high_bits
, right_low_bits
;
2599 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2600 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2601 if (byte_get
== byte_get_little_endian
)
2604 left_high_bits
^= right_high_bits
;
2605 right_high_bits
^= left_high_bits
;
2606 left_high_bits
^= right_high_bits
;
2607 left_low_bits
^= right_low_bits
;
2608 right_low_bits
^= left_low_bits
;
2609 left_low_bits
^= right_low_bits
;
2611 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2612 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2613 left_high_bits
, left_low_bits
, right_high_bits
,
2619 case DW_FORM_string
:
2621 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2622 data
+= strnlen ((char *) data
, end
- data
) + 1;
2626 case DW_FORM_exprloc
:
2627 READ_ULEB (uvalue
, data
, end
);
2630 if (block_start
>= end
)
2632 warn (_("Block ends prematurely\n"));
2637 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2640 data
= block_start
+ uvalue
;
2642 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2645 case DW_FORM_block1
:
2646 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2649 case DW_FORM_block2
:
2650 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2653 case DW_FORM_block4
:
2654 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2661 /* We have already displayed the form name. */
2662 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2663 dwarf_vmatoa ("x", uvalue
),
2664 fetch_indirect_string (uvalue
));
2666 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2667 dwarf_vmatoa ("x", uvalue
),
2668 fetch_indirect_string (uvalue
));
2672 case DW_FORM_line_strp
:
2676 /* We have already displayed the form name. */
2677 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2678 dwarf_vmatoa ("x", uvalue
),
2679 fetch_indirect_line_string (uvalue
));
2681 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2682 dwarf_vmatoa ("x", uvalue
),
2683 fetch_indirect_line_string (uvalue
));
2687 case DW_FORM_GNU_str_index
:
2690 const char * suffix
= strrchr (section
->name
, '.');
2691 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
2694 /* We have already displayed the form name. */
2695 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2696 dwarf_vmatoa ("x", uvalue
),
2697 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2699 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2700 dwarf_vmatoa ("x", uvalue
),
2701 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2705 case DW_FORM_GNU_strp_alt
:
2709 /* We have already displayed the form name. */
2710 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2711 dwarf_vmatoa ("x", uvalue
),
2712 fetch_alt_indirect_string (uvalue
));
2714 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2715 dwarf_vmatoa ("x", uvalue
),
2716 fetch_alt_indirect_string (uvalue
));
2720 case DW_FORM_indirect
:
2721 /* Handled above. */
2724 case DW_FORM_ref_sig8
:
2727 dwarf_vma high_bits
;
2730 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2732 /* We have already displayed the form name. */
2733 printf ("%c: 0x%s", delimiter
,
2734 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2736 printf ("%csignature: 0x%s", delimiter
,
2737 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2742 case DW_FORM_GNU_addr_index
:
2746 /* We have already displayed the form name. */
2747 printf (_("%c(index: 0x%s): %s"), delimiter
,
2748 dwarf_vmatoa ("x", uvalue
),
2749 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2751 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2752 dwarf_vmatoa ("x", uvalue
),
2753 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2758 warn (_("Unrecognized form: %lu\n"), form
);
2762 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2763 && num_debug_info_entries
== 0
2764 && debug_info_p
!= NULL
)
2768 case DW_AT_frame_base
:
2769 have_frame_base
= 1;
2771 case DW_AT_location
:
2772 case DW_AT_GNU_locviews
:
2773 case DW_AT_string_length
:
2774 case DW_AT_return_addr
:
2775 case DW_AT_data_member_location
:
2776 case DW_AT_vtable_elem_location
:
2778 case DW_AT_static_link
:
2779 case DW_AT_use_location
:
2780 case DW_AT_call_value
:
2781 case DW_AT_GNU_call_site_value
:
2782 case DW_AT_call_data_value
:
2783 case DW_AT_GNU_call_site_data_value
:
2784 case DW_AT_call_target
:
2785 case DW_AT_GNU_call_site_target
:
2786 case DW_AT_call_target_clobbered
:
2787 case DW_AT_GNU_call_site_target_clobbered
:
2788 if ((dwarf_version
< 4
2789 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2790 || form
== DW_FORM_sec_offset
)
2792 /* Process location list. */
2793 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2794 unsigned int num
= debug_info_p
->num_loc_offsets
;
2796 if (lmax
== 0 || num
>= lmax
)
2799 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2800 xcrealloc (debug_info_p
->loc_offsets
,
2801 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2802 debug_info_p
->loc_views
= (dwarf_vma
*)
2803 xcrealloc (debug_info_p
->loc_views
,
2804 lmax
, sizeof (*debug_info_p
->loc_views
));
2805 debug_info_p
->have_frame_base
= (int *)
2806 xcrealloc (debug_info_p
->have_frame_base
,
2807 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2808 debug_info_p
->max_loc_offsets
= lmax
;
2810 if (this_set
!= NULL
)
2811 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2812 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2813 if (attribute
!= DW_AT_GNU_locviews
)
2815 /* Corrupt DWARF info can produce more offsets than views.
2816 See PR 23062 for an example. */
2817 if (debug_info_p
->num_loc_offsets
2818 > debug_info_p
->num_loc_views
)
2819 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2822 debug_info_p
->loc_offsets
[num
] = uvalue
;
2823 debug_info_p
->num_loc_offsets
++;
2828 assert (debug_info_p
->num_loc_views
<= num
);
2829 num
= debug_info_p
->num_loc_views
;
2830 if (num
> debug_info_p
->num_loc_offsets
)
2831 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2834 debug_info_p
->loc_views
[num
] = uvalue
;
2835 debug_info_p
->num_loc_views
++;
2842 if (need_base_address
)
2843 debug_info_p
->base_address
= uvalue
;
2846 case DW_AT_GNU_addr_base
:
2847 debug_info_p
->addr_base
= uvalue
;
2850 case DW_AT_GNU_ranges_base
:
2851 debug_info_p
->ranges_base
= uvalue
;
2855 if ((dwarf_version
< 4
2856 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2857 || form
== DW_FORM_sec_offset
)
2859 /* Process range list. */
2860 unsigned int lmax
= debug_info_p
->max_range_lists
;
2861 unsigned int num
= debug_info_p
->num_range_lists
;
2863 if (lmax
== 0 || num
>= lmax
)
2866 debug_info_p
->range_lists
= (dwarf_vma
*)
2867 xcrealloc (debug_info_p
->range_lists
,
2868 lmax
, sizeof (*debug_info_p
->range_lists
));
2869 debug_info_p
->max_range_lists
= lmax
;
2871 debug_info_p
->range_lists
[num
] = uvalue
;
2872 debug_info_p
->num_range_lists
++;
2876 case DW_AT_GNU_dwo_name
:
2877 case DW_AT_dwo_name
:
2882 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2884 case DW_FORM_GNU_strp_alt
:
2885 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2887 case DW_FORM_GNU_str_index
:
2888 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
), cu_offset
);
2890 case DW_FORM_string
:
2891 add_dwo_name ((const char *) orig_data
, cu_offset
);
2894 warn (_("Unsupported form (%s) for attribute %s\n"),
2895 get_FORM_name (form
), get_AT_name (attribute
));
2900 case DW_AT_comp_dir
:
2901 /* FIXME: Also extract a build-id in a CU/TU. */
2906 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2908 case DW_FORM_GNU_strp_alt
:
2909 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2911 case DW_FORM_line_strp
:
2912 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2914 case DW_FORM_GNU_str_index
:
2915 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
), cu_offset
);
2917 case DW_FORM_string
:
2918 add_dwo_dir ((const char *) orig_data
, cu_offset
);
2921 warn (_("Unsupported form (%s) for attribute %s\n"),
2922 get_FORM_name (form
), get_AT_name (attribute
));
2927 case DW_AT_GNU_dwo_id
:
2932 /* FIXME: Record the length of the ID as well ? */
2933 add_dwo_id ((const char *) (data
- 8), cu_offset
);
2936 warn (_("Unsupported form (%s) for attribute %s\n"),
2937 get_FORM_name (form
), get_AT_name (attribute
));
2947 if (do_loc
|| attribute
== 0)
2950 /* For some attributes we can display further information. */
2954 if (level
>= 0 && level
< MAX_CU_NESTING
2955 && uvalue
< (size_t) (end
- start
))
2957 bfd_boolean is_signed
= FALSE
;
2958 abbrev_entry
* type_abbrev
;
2959 unsigned char * type_data
;
2960 unsigned long type_cu_offset
;
2962 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
2963 section
, NULL
, & type_data
, & type_cu_offset
);
2964 if (type_abbrev
!= NULL
)
2966 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2967 pointer_size
, offset_size
, dwarf_version
,
2970 level_type_signed
[level
] = is_signed
;
2978 case DW_INL_not_inlined
:
2979 printf (_("(not inlined)"));
2981 case DW_INL_inlined
:
2982 printf (_("(inlined)"));
2984 case DW_INL_declared_not_inlined
:
2985 printf (_("(declared as inline but ignored)"));
2987 case DW_INL_declared_inlined
:
2988 printf (_("(declared as inline and inlined)"));
2991 printf (_(" (Unknown inline attribute value: %s)"),
2992 dwarf_vmatoa ("x", uvalue
));
2997 case DW_AT_language
:
3001 /* Ordered by the numeric value of these constants. */
3002 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3003 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3004 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3005 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3006 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3007 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3008 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3009 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3010 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3011 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3012 /* DWARF 2.1 values. */
3013 case DW_LANG_Java
: printf ("(Java)"); break;
3014 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3015 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3016 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3017 /* DWARF 3 values. */
3018 case DW_LANG_PLI
: printf ("(PLI)"); break;
3019 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3020 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3021 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3022 case DW_LANG_D
: printf ("(D)"); break;
3023 /* DWARF 4 values. */
3024 case DW_LANG_Python
: printf ("(Python)"); break;
3025 /* DWARF 5 values. */
3026 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3027 case DW_LANG_Go
: printf ("(Go)"); break;
3028 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3029 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3030 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3031 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3032 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3033 case DW_LANG_Rust
: printf ("(Rust)"); break;
3034 case DW_LANG_C11
: printf ("(C11)"); break;
3035 case DW_LANG_Swift
: printf ("(Swift)"); break;
3036 case DW_LANG_Julia
: printf ("(Julia)"); break;
3037 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3038 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3039 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3040 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3041 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3042 /* MIPS extension. */
3043 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3044 /* UPC extension. */
3045 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3047 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3048 printf (_("(implementation defined: %s)"),
3049 dwarf_vmatoa ("x", uvalue
));
3051 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3056 case DW_AT_encoding
:
3060 case DW_ATE_void
: printf ("(void)"); break;
3061 case DW_ATE_address
: printf ("(machine address)"); break;
3062 case DW_ATE_boolean
: printf ("(boolean)"); break;
3063 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3064 case DW_ATE_float
: printf ("(float)"); break;
3065 case DW_ATE_signed
: printf ("(signed)"); break;
3066 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3067 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3068 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3069 /* DWARF 2.1 values: */
3070 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3071 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3072 /* DWARF 3 values: */
3073 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3074 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3075 case DW_ATE_edited
: printf ("(edited)"); break;
3076 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3077 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3078 /* DWARF 4 values: */
3079 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3080 /* DWARF 5 values: */
3081 case DW_ATE_UCS
: printf ("(UCS)"); break;
3082 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3084 /* HP extensions: */
3085 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3086 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3087 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3088 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3089 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3090 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3091 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3094 if (uvalue
>= DW_ATE_lo_user
3095 && uvalue
<= DW_ATE_hi_user
)
3096 printf (_("(user defined type)"));
3098 printf (_("(unknown type)"));
3103 case DW_AT_accessibility
:
3107 case DW_ACCESS_public
: printf ("(public)"); break;
3108 case DW_ACCESS_protected
: printf ("(protected)"); break;
3109 case DW_ACCESS_private
: printf ("(private)"); break;
3111 printf (_("(unknown accessibility)"));
3116 case DW_AT_visibility
:
3120 case DW_VIS_local
: printf ("(local)"); break;
3121 case DW_VIS_exported
: printf ("(exported)"); break;
3122 case DW_VIS_qualified
: printf ("(qualified)"); break;
3123 default: printf (_("(unknown visibility)")); break;
3127 case DW_AT_endianity
:
3131 case DW_END_default
: printf ("(default)"); break;
3132 case DW_END_big
: printf ("(big)"); break;
3133 case DW_END_little
: printf ("(little)"); break;
3135 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3136 printf (_("(user specified)"));
3138 printf (_("(unknown endianity)"));
3143 case DW_AT_virtuality
:
3147 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3148 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3149 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3150 default: printf (_("(unknown virtuality)")); break;
3154 case DW_AT_identifier_case
:
3158 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3159 case DW_ID_up_case
: printf ("(up_case)"); break;
3160 case DW_ID_down_case
: printf ("(down_case)"); break;
3161 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3162 default: printf (_("(unknown case)")); break;
3166 case DW_AT_calling_convention
:
3170 case DW_CC_normal
: printf ("(normal)"); break;
3171 case DW_CC_program
: printf ("(program)"); break;
3172 case DW_CC_nocall
: printf ("(nocall)"); break;
3173 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3174 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3175 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3176 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3178 if (uvalue
>= DW_CC_lo_user
3179 && uvalue
<= DW_CC_hi_user
)
3180 printf (_("(user defined)"));
3182 printf (_("(unknown convention)"));
3186 case DW_AT_ordering
:
3191 case -1: printf (_("(undefined)")); break;
3192 case 0: printf ("(row major)"); break;
3193 case 1: printf ("(column major)"); break;
3197 case DW_AT_decimal_sign
:
3201 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3202 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3203 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3204 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3205 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3206 default: printf (_("(unrecognised)")); break;
3210 case DW_AT_defaulted
:
3214 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3215 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3216 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3217 default: printf (_("(unrecognised)")); break;
3221 case DW_AT_discr_list
:
3223 display_discr_list (form
, uvalue
, data
, end
, level
);
3226 case DW_AT_frame_base
:
3227 have_frame_base
= 1;
3229 case DW_AT_location
:
3230 case DW_AT_string_length
:
3231 case DW_AT_return_addr
:
3232 case DW_AT_data_member_location
:
3233 case DW_AT_vtable_elem_location
:
3235 case DW_AT_static_link
:
3236 case DW_AT_use_location
:
3237 case DW_AT_call_value
:
3238 case DW_AT_GNU_call_site_value
:
3239 case DW_AT_call_data_value
:
3240 case DW_AT_GNU_call_site_data_value
:
3241 case DW_AT_call_target
:
3242 case DW_AT_GNU_call_site_target
:
3243 case DW_AT_call_target_clobbered
:
3244 case DW_AT_GNU_call_site_target_clobbered
:
3245 if ((dwarf_version
< 4
3246 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3247 || form
== DW_FORM_sec_offset
)
3248 printf (_(" (location list)"));
3250 case DW_AT_allocated
:
3251 case DW_AT_associated
:
3252 case DW_AT_data_location
:
3254 case DW_AT_upper_bound
:
3255 case DW_AT_lower_bound
:
3258 int need_frame_base
;
3261 need_frame_base
= decode_location_expression (block_start
,
3266 cu_offset
, section
);
3268 if (need_frame_base
&& !have_frame_base
)
3269 printf (_(" [without DW_AT_frame_base]"));
3273 case DW_AT_data_bit_offset
:
3274 case DW_AT_byte_size
:
3275 case DW_AT_bit_size
:
3276 case DW_AT_string_length_byte_size
:
3277 case DW_AT_string_length_bit_size
:
3278 case DW_AT_bit_stride
:
3279 if (form
== DW_FORM_exprloc
)
3282 (void) decode_location_expression (block_start
, pointer_size
,
3283 offset_size
, dwarf_version
,
3284 uvalue
, cu_offset
, section
);
3291 unsigned long abbrev_number
;
3292 abbrev_entry
*entry
;
3294 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3295 section
, & abbrev_number
, NULL
, NULL
);
3298 if (form
!= DW_FORM_GNU_ref_alt
)
3299 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3300 dwarf_vmatoa ("x", uvalue
),
3301 (unsigned long) (orig_data
- section
->start
));
3305 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3306 printf (" (%s)", get_TAG_name (entry
->tag
));
3319 static unsigned char *
3320 read_and_display_attr (unsigned long attribute
,
3322 dwarf_signed_vma implicit_const
,
3323 unsigned char * start
,
3324 unsigned char * data
,
3325 unsigned char * end
,
3326 dwarf_vma cu_offset
,
3327 dwarf_vma pointer_size
,
3328 dwarf_vma offset_size
,
3330 debug_info
* debug_info_p
,
3332 struct dwarf_section
* section
,
3333 struct cu_tu_set
* this_set
,
3337 printf (" %-18s:", get_AT_name (attribute
));
3338 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3340 cu_offset
, pointer_size
, offset_size
,
3341 dwarf_version
, debug_info_p
,
3342 do_loc
, section
, this_set
, ' ', level
);
3348 /* Like load_debug_section, but if the ordinary call fails, and we are
3349 following debug links, then attempt to load the requested section
3350 from one of the separate debug info files. */
3353 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3356 if (load_debug_section (sec_enum
, handle
))
3358 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3360 /* See if we can associate a filename with this section. */
3363 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3364 if (i
->handle
== handle
)
3366 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3374 if (do_follow_links
)
3378 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3380 if (load_debug_section (sec_enum
, i
->handle
))
3382 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3384 /* FIXME: We should check to see if any of the remaining debug info
3385 files also contain this section, and, umm, do something about it. */
3395 introduce (struct dwarf_section
* section
, bfd_boolean raw
)
3399 if (do_follow_links
&& section
->filename
)
3400 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3401 section
->name
, section
->filename
);
3403 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3407 if (do_follow_links
&& section
->filename
)
3408 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3409 section
->name
, section
->filename
);
3411 printf (_("Contents of the %s section:\n\n"), section
->name
);
3415 /* Process the contents of a .debug_info section.
3416 If do_loc is TRUE then we are scanning for location lists and dwo tags
3417 and we do not want to display anything to the user.
3418 If do_types is TRUE, we are processing a .debug_types section instead of
3419 a .debug_info section.
3420 The information displayed is restricted by the values in DWARF_START_DIE
3421 and DWARF_CUTOFF_LEVEL.
3422 Returns TRUE upon success. Otherwise an error or warning message is
3423 printed and FALSE is returned. */
3426 process_debug_info (struct dwarf_section
* section
,
3428 enum dwarf_section_display_enum abbrev_sec
,
3430 bfd_boolean do_types
)
3432 unsigned char *start
= section
->start
;
3433 unsigned char *end
= start
+ section
->size
;
3434 unsigned char *section_begin
;
3436 unsigned int num_units
= 0;
3438 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3439 && num_debug_info_entries
== 0
3444 /* First scan the section to get the number of comp units. */
3445 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3448 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3449 will be the length. For a 64-bit DWARF section, it'll be
3450 the escape code 0xffffffff followed by an 8 byte length. */
3451 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3453 if (length
== 0xffffffff)
3455 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3456 section_begin
+= length
+ 12;
3458 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3460 warn (_("Reserved length value (0x%s) found in section %s\n"),
3461 dwarf_vmatoa ("x", length
), section
->name
);
3465 section_begin
+= length
+ 4;
3467 /* Negative values are illegal, they may even cause infinite
3468 looping. This can happen if we can't accurately apply
3469 relocations to an object file, or if the file is corrupt. */
3470 if ((signed long) length
<= 0 || section_begin
< start
)
3472 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3473 dwarf_vmatoa ("x", length
), section
->name
);
3480 error (_("No comp units in %s section ?\n"), section
->name
);
3484 /* Then allocate an array to hold the information. */
3485 debug_information
= (debug_info
*) cmalloc (num_units
,
3486 sizeof (* debug_information
));
3487 if (debug_information
== NULL
)
3489 error (_("Not enough memory for a debug info array of %u entries\n"),
3491 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3495 /* PR 17531: file: 92ca3797.
3496 We cannot rely upon the debug_information array being initialised
3497 before it is used. A corrupt file could easily contain references
3498 to a unit for which information has not been made available. So
3499 we ensure that the array is zeroed here. */
3500 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3502 alloc_num_debug_info_entries
= num_units
;
3507 load_debug_section_with_follow (str
, file
);
3508 load_debug_section_with_follow (line_str
, file
);
3509 load_debug_section_with_follow (str_dwo
, file
);
3510 load_debug_section_with_follow (str_index
, file
);
3511 load_debug_section_with_follow (str_index_dwo
, file
);
3512 load_debug_section_with_follow (debug_addr
, file
);
3515 load_debug_section_with_follow (abbrev_sec
, file
);
3516 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3518 warn (_("Unable to locate %s section!\n"),
3519 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3523 if (!do_loc
&& dwarf_start_die
== 0)
3524 introduce (section
, FALSE
);
3526 free_all_abbrevs ();
3527 free (cu_abbrev_map
);
3528 cu_abbrev_map
= NULL
;
3529 next_free_abbrev_map_entry
= 0;
3531 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3532 to load *all* of the abbrevs for all CUs in this .debug_info
3533 section. This does effectively mean that we (partially) read
3534 every CU header twice. */
3535 for (section_begin
= start
; start
< end
;)
3537 DWARF2_Internal_CompUnit compunit
;
3538 unsigned char * hdrptr
;
3539 dwarf_vma abbrev_base
;
3541 dwarf_vma cu_offset
;
3542 unsigned int offset_size
;
3543 unsigned int initial_length_size
;
3544 struct cu_tu_set
* this_set
;
3549 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3551 if (compunit
.cu_length
== 0xffffffff)
3553 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3555 initial_length_size
= 12;
3560 initial_length_size
= 4;
3563 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3565 cu_offset
= start
- section_begin
;
3567 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3569 if (compunit
.cu_version
< 5)
3571 compunit
.cu_unit_type
= DW_UT_compile
;
3572 /* Initialize it due to a false compiler warning. */
3573 compunit
.cu_pointer_size
= -1;
3577 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3578 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3580 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3583 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3585 if (compunit
.cu_unit_type
== DW_UT_split_compile
3586 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3589 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3592 if (this_set
== NULL
)
3595 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3599 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3600 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3603 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3604 compunit
.cu_abbrev_offset
);
3607 unsigned char * next
;
3609 list
= new_abbrev_list (abbrev_base
,
3610 compunit
.cu_abbrev_offset
);
3611 next
= process_abbrev_set
3612 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3613 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3614 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3615 + abbrev_base
+ abbrev_size
),
3617 list
->start_of_next_abbrevs
= next
;
3620 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3621 + initial_length_size
;
3622 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3625 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3627 DWARF2_Internal_CompUnit compunit
;
3628 unsigned char *hdrptr
;
3629 unsigned char *tags
;
3630 int level
, last_level
, saved_level
;
3631 dwarf_vma cu_offset
;
3632 unsigned long sec_off
;
3633 unsigned int offset_size
;
3634 unsigned int initial_length_size
;
3635 dwarf_vma signature_high
= 0;
3636 dwarf_vma signature_low
= 0;
3637 dwarf_vma type_offset
= 0;
3638 struct cu_tu_set
*this_set
;
3639 dwarf_vma abbrev_base
;
3641 abbrev_list
* list
= NULL
;
3645 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3647 if (compunit
.cu_length
== 0xffffffff)
3649 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3651 initial_length_size
= 12;
3656 initial_length_size
= 4;
3659 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3661 cu_offset
= start
- section_begin
;
3663 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3665 if (compunit
.cu_version
< 5)
3667 compunit
.cu_unit_type
= DW_UT_compile
;
3668 /* Initialize it due to a false compiler warning. */
3669 compunit
.cu_pointer_size
= -1;
3673 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3674 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3676 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3679 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3681 if (this_set
== NULL
)
3684 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3688 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3689 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3692 if (compunit
.cu_version
< 5)
3693 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3695 if (compunit
.cu_unit_type
== DW_UT_split_compile
3696 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3699 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3702 /* PR 17512: file: 001-108546-0.001:0.1. */
3703 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3705 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3706 compunit
.cu_pointer_size
, offset_size
);
3707 compunit
.cu_pointer_size
= offset_size
;
3712 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3714 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3717 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3718 + initial_length_size
))
3720 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3721 + initial_length_size
;
3725 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3726 && num_debug_info_entries
== 0
3727 && alloc_num_debug_info_entries
> unit
3730 debug_information
[unit
].cu_offset
= cu_offset
;
3731 debug_information
[unit
].pointer_size
3732 = compunit
.cu_pointer_size
;
3733 debug_information
[unit
].offset_size
= offset_size
;
3734 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3735 debug_information
[unit
].base_address
= 0;
3736 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3737 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3738 debug_information
[unit
].loc_offsets
= NULL
;
3739 debug_information
[unit
].have_frame_base
= NULL
;
3740 debug_information
[unit
].max_loc_offsets
= 0;
3741 debug_information
[unit
].num_loc_offsets
= 0;
3742 debug_information
[unit
].range_lists
= NULL
;
3743 debug_information
[unit
].max_range_lists
= 0;
3744 debug_information
[unit
].num_range_lists
= 0;
3747 if (!do_loc
&& dwarf_start_die
== 0)
3749 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3750 dwarf_vmatoa ("x", cu_offset
));
3751 printf (_(" Length: 0x%s (%s)\n"),
3752 dwarf_vmatoa ("x", compunit
.cu_length
),
3753 offset_size
== 8 ? "64-bit" : "32-bit");
3754 printf (_(" Version: %d\n"), compunit
.cu_version
);
3755 if (compunit
.cu_version
>= 5)
3756 printf (_(" Unit Type: %s (%x)\n"),
3757 get_DW_UT_name (compunit
.cu_unit_type
) ?: "???",
3758 compunit
.cu_unit_type
);
3759 printf (_(" Abbrev Offset: 0x%s\n"),
3760 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3761 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3766 printf (_(" Signature: 0x%s\n"),
3767 dwarf_vmatoa64 (signature_high
, signature_low
,
3768 buf
, sizeof (buf
)));
3769 printf (_(" Type Offset: 0x%s\n"),
3770 dwarf_vmatoa ("x", type_offset
));
3772 if (this_set
!= NULL
)
3774 dwarf_vma
*offsets
= this_set
->section_offsets
;
3775 size_t *sizes
= this_set
->section_sizes
;
3777 printf (_(" Section contributions:\n"));
3778 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3779 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3780 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3781 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3782 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3783 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3784 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3785 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3786 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3787 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3788 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3789 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3793 sec_off
= cu_offset
+ initial_length_size
;
3794 if (sec_off
+ compunit
.cu_length
< sec_off
3795 || sec_off
+ compunit
.cu_length
> section
->size
)
3797 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3799 (unsigned long) cu_offset
,
3800 dwarf_vmatoa ("x", compunit
.cu_length
));
3806 start
+= compunit
.cu_length
+ initial_length_size
;
3808 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3810 warn (_("CU at offset %s contains corrupt or "
3811 "unsupported version number: %d.\n"),
3812 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3816 if (compunit
.cu_unit_type
!= DW_UT_compile
3817 && compunit
.cu_unit_type
!= DW_UT_partial
3818 && compunit
.cu_unit_type
!= DW_UT_type
3819 && compunit
.cu_unit_type
!= DW_UT_split_compile
3820 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3822 warn (_("CU at offset %s contains corrupt or "
3823 "unsupported unit type: %d.\n"),
3824 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3828 /* Process the abbrevs used by this compilation unit. */
3829 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3830 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3831 (unsigned long) compunit
.cu_abbrev_offset
,
3832 (unsigned long) abbrev_size
);
3833 /* PR 17531: file:4bcd9ce9. */
3834 else if ((abbrev_base
+ abbrev_size
)
3835 > debug_displays
[abbrev_sec
].section
.size
)
3836 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3837 (unsigned long) abbrev_base
+ abbrev_size
,
3838 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3841 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3842 compunit
.cu_abbrev_offset
);
3845 unsigned char * next
;
3847 list
= new_abbrev_list (abbrev_base
,
3848 compunit
.cu_abbrev_offset
);
3849 next
= process_abbrev_set
3850 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3851 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3852 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3853 + abbrev_base
+ abbrev_size
),
3855 list
->start_of_next_abbrevs
= next
;
3862 while (tags
< start
)
3864 unsigned long abbrev_number
;
3865 unsigned long die_offset
;
3866 abbrev_entry
*entry
;
3868 int do_printing
= 1;
3870 die_offset
= tags
- section_begin
;
3872 READ_ULEB (abbrev_number
, tags
, start
);
3874 /* A null DIE marks the end of a list of siblings or it may also be
3875 a section padding. */
3876 if (abbrev_number
== 0)
3878 /* Check if it can be a section padding for the last CU. */
3879 if (level
== 0 && start
== end
)
3883 for (chk
= tags
; chk
< start
; chk
++)
3890 if (!do_loc
&& die_offset
>= dwarf_start_die
3891 && (dwarf_cutoff_level
== -1
3892 || level
< dwarf_cutoff_level
))
3893 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3899 static unsigned num_bogus_warns
= 0;
3901 if (num_bogus_warns
< 3)
3903 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3904 die_offset
, section
->name
);
3906 if (num_bogus_warns
== 3)
3907 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3910 if (dwarf_start_die
!= 0 && level
< saved_level
)
3917 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3921 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3922 saved_level
= level
;
3923 do_printing
= (dwarf_cutoff_level
== -1
3924 || level
< dwarf_cutoff_level
);
3926 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3927 level
, die_offset
, abbrev_number
);
3928 else if (dwarf_cutoff_level
== -1
3929 || last_level
< dwarf_cutoff_level
)
3930 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3935 /* Scan through the abbreviation list until we reach the
3940 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3941 if (entry
->number
== abbrev_number
)
3946 if (!do_loc
&& do_printing
)
3951 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3952 die_offset
, abbrev_number
);
3956 if (!do_loc
&& do_printing
)
3957 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3962 need_base_address
= 0;
3964 case DW_TAG_compile_unit
:
3965 need_base_address
= 1;
3966 need_dwo_info
= do_loc
;
3968 case DW_TAG_entry_point
:
3969 case DW_TAG_subprogram
:
3970 need_base_address
= 0;
3971 /* Assuming that there is no DW_AT_frame_base. */
3972 have_frame_base
= 0;
3976 debug_info
*debug_info_p
=
3977 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3978 ? debug_information
+ unit
: NULL
;
3980 assert (!debug_info_p
3981 || (debug_info_p
->num_loc_offsets
3982 == debug_info_p
->num_loc_views
));
3984 for (attr
= entry
->first_attr
;
3985 attr
&& attr
->attribute
;
3988 if (! do_loc
&& do_printing
)
3989 /* Show the offset from where the tag was extracted. */
3990 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3991 tags
= read_and_display_attr (attr
->attribute
,
3993 attr
->implicit_const
,
3998 compunit
.cu_pointer_size
,
4000 compunit
.cu_version
,
4002 do_loc
|| ! do_printing
,
4008 /* If a locview attribute appears before a location one,
4009 make sure we don't associate it with an earlier
4012 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4015 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4016 debug_info_p
->num_loc_views
++;
4017 assert (debug_info_p
->num_loc_views
4018 == debug_info_p
->num_loc_offsets
);
4025 warn(_("DIE has locviews without loclist\n"));
4026 debug_info_p
->num_loc_views
--;
4033 if (entry
->children
)
4038 /* Set num_debug_info_entries here so that it can be used to check if
4039 we need to process .debug_loc and .debug_ranges sections. */
4040 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4041 && num_debug_info_entries
== 0
4044 if (num_units
> alloc_num_debug_info_entries
)
4045 num_debug_info_entries
= alloc_num_debug_info_entries
;
4047 num_debug_info_entries
= num_units
;
4056 /* Locate and scan the .debug_info section in the file and record the pointer
4057 sizes and offsets for the compilation units in it. Usually an executable
4058 will have just one pointer size, but this is not guaranteed, and so we try
4059 not to make any assumptions. Returns zero upon failure, or the number of
4060 compilation units upon success. */
4063 load_debug_info (void * file
)
4065 /* If we have already tried and failed to load the .debug_info
4066 section then do not bother to repeat the task. */
4067 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4070 /* If we already have the information there is nothing else to do. */
4071 if (num_debug_info_entries
> 0)
4072 return num_debug_info_entries
;
4074 /* If this is a DWARF package file, load the CU and TU indexes. */
4075 (void) load_cu_tu_indexes (file
);
4077 if (load_debug_section_with_follow (info
, file
)
4078 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
4079 return num_debug_info_entries
;
4081 if (load_debug_section_with_follow (info_dwo
, file
)
4082 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4083 abbrev_dwo
, TRUE
, FALSE
))
4084 return num_debug_info_entries
;
4086 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4090 /* Read a DWARF .debug_line section header starting at DATA.
4091 Upon success returns an updated DATA pointer and the LINFO
4092 structure and the END_OF_SEQUENCE pointer will be filled in.
4093 Otherwise returns NULL. */
4095 static unsigned char *
4096 read_debug_line_header (struct dwarf_section
* section
,
4097 unsigned char * data
,
4098 unsigned char * end
,
4099 DWARF2_Internal_LineInfo
* linfo
,
4100 unsigned char ** end_of_sequence
)
4102 unsigned char *hdrptr
;
4103 unsigned int initial_length_size
;
4105 /* Extract information from the Line Number Program Header.
4106 (section 6.2.4 in the Dwarf3 doc). */
4109 /* Get and check the length of the block. */
4110 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4112 if (linfo
->li_length
== 0xffffffff)
4114 /* This section is 64-bit DWARF 3. */
4115 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4116 linfo
->li_offset_size
= 8;
4117 initial_length_size
= 12;
4121 linfo
->li_offset_size
= 4;
4122 initial_length_size
= 4;
4125 if (linfo
->li_length
+ initial_length_size
> section
->size
)
4127 /* If the length field has a relocation against it, then we should
4128 not complain if it is inaccurate (and probably negative). This
4129 happens in object files when the .debug_line section is actually
4130 comprised of several different .debug_line.* sections, (some of
4131 which may be removed by linker garbage collection), and a relocation
4132 is used to compute the correct length once that is done. */
4133 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4135 linfo
->li_length
= (end
- data
) - initial_length_size
;
4139 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4140 (long) linfo
->li_length
);
4145 /* Get and check the version number. */
4146 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4148 if (linfo
->li_version
!= 2
4149 && linfo
->li_version
!= 3
4150 && linfo
->li_version
!= 4
4151 && linfo
->li_version
!= 5)
4153 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4154 "is currently supported.\n"));
4158 if (linfo
->li_version
>= 5)
4160 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4162 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4163 if (linfo
->li_segment_size
!= 0)
4165 warn (_("The %s section contains "
4166 "unsupported segment selector size: %d.\n"),
4167 section
->name
, linfo
->li_segment_size
);
4172 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4173 linfo
->li_offset_size
, end
);
4174 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4176 if (linfo
->li_version
>= 4)
4178 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4180 if (linfo
->li_max_ops_per_insn
== 0)
4182 warn (_("Invalid maximum operations per insn.\n"));
4187 linfo
->li_max_ops_per_insn
= 1;
4189 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4190 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4191 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4192 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4194 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
4195 /* PR 17512: file:002-117414-0.004. */
4196 if (* end_of_sequence
> end
)
4198 warn (_("Line length %s extends beyond end of section\n"),
4199 dwarf_vmatoa ("u", linfo
->li_length
));
4200 * end_of_sequence
= end
;
4207 static unsigned char *
4208 display_formatted_table (unsigned char * data
,
4209 unsigned char * start
,
4210 unsigned char * end
,
4211 const DWARF2_Internal_LineInfo
* linfo
,
4212 struct dwarf_section
* section
,
4215 unsigned char *format_start
, format_count
, *format
, formati
;
4216 dwarf_vma data_count
, datai
;
4217 unsigned int namepass
, last_entry
= 0;
4218 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4220 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4221 if (do_checks
&& format_count
> 5)
4222 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4223 table_name
, format_count
);
4225 format_start
= data
;
4226 for (formati
= 0; formati
< format_count
; formati
++)
4228 SKIP_ULEB (data
, end
);
4229 SKIP_ULEB (data
, end
);
4232 warn (_("%s: Corrupt format description entry\n"), table_name
);
4237 READ_ULEB (data_count
, data
, end
);
4238 if (data_count
== 0)
4240 printf (_("\n The %s is empty.\n"), table_name
);
4243 else if (data
== end
)
4245 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4246 table_name
, dwarf_vmatoa ("x", data_count
));
4250 else if (format_count
== 0)
4252 warn (_("%s: format count is zero, but the table is not empty\n"),
4257 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4258 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4261 printf (_(" Entry"));
4262 /* Delay displaying name as the last entry for better screen layout. */
4263 for (namepass
= 0; namepass
< 2; namepass
++)
4265 format
= format_start
;
4266 for (formati
= 0; formati
< format_count
; formati
++)
4268 dwarf_vma content_type
;
4270 READ_ULEB (content_type
, format
, end
);
4271 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4272 switch (content_type
)
4275 printf (_("\tName"));
4277 case DW_LNCT_directory_index
:
4278 printf (_("\tDir"));
4280 case DW_LNCT_timestamp
:
4281 printf (_("\tTime"));
4284 printf (_("\tSize"));
4287 printf (_("\tMD5\t\t\t"));
4290 printf (_("\t(Unknown format content type %s)"),
4291 dwarf_vmatoa ("u", content_type
));
4293 SKIP_ULEB (format
, end
);
4298 for (datai
= 0; datai
< data_count
; datai
++)
4300 unsigned char *datapass
= data
;
4302 printf (" %d", last_entry
++);
4303 /* Delay displaying name as the last entry for better screen layout. */
4304 for (namepass
= 0; namepass
< 2; namepass
++)
4306 format
= format_start
;
4308 for (formati
= 0; formati
< format_count
; formati
++)
4310 dwarf_vma content_type
, form
;
4312 READ_ULEB (content_type
, format
, end
);
4313 READ_ULEB (form
, format
, end
);
4314 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4315 0, 0, linfo
->li_offset_size
,
4316 linfo
->li_version
, NULL
,
4317 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4318 section
, NULL
, '\t', -1);
4322 if (data
== end
&& (datai
< data_count
- 1))
4324 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4333 display_debug_lines_raw (struct dwarf_section
* section
,
4334 unsigned char * data
,
4335 unsigned char * end
,
4338 unsigned char *start
= section
->start
;
4339 int verbose_view
= 0;
4341 introduce (section
, TRUE
);
4345 static DWARF2_Internal_LineInfo saved_linfo
;
4346 DWARF2_Internal_LineInfo linfo
;
4347 unsigned char *standard_opcodes
;
4348 unsigned char *end_of_sequence
;
4351 if (const_strneq (section
->name
, ".debug_line.")
4352 /* Note: the following does not apply to .debug_line.dwo sections.
4353 These are full debug_line sections. */
4354 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4356 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4357 section containing just the Line Number Statements. They are
4358 created by the assembler and intended to be used alongside gcc's
4359 -ffunction-sections command line option. When the linker's
4360 garbage collection decides to discard a .text.<foo> section it
4361 can then also discard the line number information in .debug_line.<foo>.
4363 Since the section is a fragment it does not have the details
4364 needed to fill out a LineInfo structure, so instead we use the
4365 details from the last full debug_line section that we processed. */
4366 end_of_sequence
= end
;
4367 standard_opcodes
= NULL
;
4368 linfo
= saved_linfo
;
4369 /* PR 17531: file: 0522b371. */
4370 if (linfo
.li_line_range
== 0)
4372 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4375 reset_state_machine (linfo
.li_default_is_stmt
);
4379 unsigned char * hdrptr
;
4381 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4382 & end_of_sequence
)) == NULL
)
4385 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4386 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4387 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4388 if (linfo
.li_version
>= 5)
4390 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4391 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4393 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4394 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4395 if (linfo
.li_version
>= 4)
4396 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4397 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4398 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4399 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4400 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4402 /* PR 17512: file: 1665-6428-0.004. */
4403 if (linfo
.li_line_range
== 0)
4405 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4406 linfo
.li_line_range
= 1;
4409 reset_state_machine (linfo
.li_default_is_stmt
);
4411 /* Display the contents of the Opcodes table. */
4412 standard_opcodes
= hdrptr
;
4414 /* PR 17512: file: 002-417945-0.004. */
4415 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4417 warn (_("Line Base extends beyond end of section\n"));
4421 printf (_("\n Opcodes:\n"));
4423 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4424 printf (ngettext (" Opcode %d has %d arg\n",
4425 " Opcode %d has %d args\n",
4426 standard_opcodes
[i
- 1]),
4427 i
, standard_opcodes
[i
- 1]);
4429 /* Display the contents of the Directory table. */
4430 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4432 if (linfo
.li_version
>= 5)
4434 load_debug_section_with_follow (line_str
, file
);
4436 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4438 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4444 printf (_("\n The Directory Table is empty.\n"));
4447 unsigned int last_dir_entry
= 0;
4449 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4450 (long)(data
- start
));
4452 while (data
< end
&& *data
!= 0)
4454 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4456 data
+= strnlen ((char *) data
, end
- data
) + 1;
4459 /* PR 17512: file: 002-132094-0.004. */
4460 if (data
>= end
- 1)
4464 /* Skip the NUL at the end of the table. */
4467 /* Display the contents of the File Name table. */
4469 printf (_("\n The File Name Table is empty.\n"));
4472 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4473 (long)(data
- start
));
4474 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4476 while (data
< end
&& *data
!= 0)
4478 unsigned char *name
;
4481 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4483 data
+= strnlen ((char *) data
, end
- data
) + 1;
4485 READ_ULEB (val
, data
, end
);
4486 printf ("%s\t", dwarf_vmatoa ("u", val
));
4487 READ_ULEB (val
, data
, end
);
4488 printf ("%s\t", dwarf_vmatoa ("u", val
));
4489 READ_ULEB (val
, data
, end
);
4490 printf ("%s\t", dwarf_vmatoa ("u", val
));
4491 printf ("%.*s\n", (int)(end
- name
), name
);
4495 warn (_("Corrupt file name table entry\n"));
4501 /* Skip the NUL at the end of the table. */
4506 saved_linfo
= linfo
;
4509 /* Now display the statements. */
4510 if (data
>= end_of_sequence
)
4511 printf (_(" No Line Number Statements.\n"));
4514 printf (_(" Line Number Statements:\n"));
4516 while (data
< end_of_sequence
)
4518 unsigned char op_code
;
4519 dwarf_signed_vma adv
;
4522 printf (" [0x%08lx]", (long)(data
- start
));
4526 if (op_code
>= linfo
.li_opcode_base
)
4528 op_code
-= linfo
.li_opcode_base
;
4529 uladv
= (op_code
/ linfo
.li_line_range
);
4530 if (linfo
.li_max_ops_per_insn
== 1)
4532 uladv
*= linfo
.li_min_insn_length
;
4533 state_machine_regs
.address
+= uladv
;
4535 state_machine_regs
.view
= 0;
4536 printf (_(" Special opcode %d: "
4537 "advance Address by %s to 0x%s%s"),
4538 op_code
, dwarf_vmatoa ("u", uladv
),
4539 dwarf_vmatoa ("x", state_machine_regs
.address
),
4540 verbose_view
&& uladv
4541 ? _(" (reset view)") : "");
4546 = ((state_machine_regs
.op_index
+ uladv
)
4547 / linfo
.li_max_ops_per_insn
)
4548 * linfo
.li_min_insn_length
;
4550 state_machine_regs
.address
+= addrdelta
;
4551 state_machine_regs
.op_index
4552 = (state_machine_regs
.op_index
+ uladv
)
4553 % linfo
.li_max_ops_per_insn
;
4555 state_machine_regs
.view
= 0;
4556 printf (_(" Special opcode %d: "
4557 "advance Address by %s to 0x%s[%d]%s"),
4558 op_code
, dwarf_vmatoa ("u", uladv
),
4559 dwarf_vmatoa ("x", state_machine_regs
.address
),
4560 state_machine_regs
.op_index
,
4561 verbose_view
&& addrdelta
4562 ? _(" (reset view)") : "");
4564 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4565 state_machine_regs
.line
+= adv
;
4566 printf (_(" and Line by %s to %d"),
4567 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4568 if (verbose_view
|| state_machine_regs
.view
)
4569 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4572 state_machine_regs
.view
++;
4577 case DW_LNS_extended_op
:
4578 data
+= process_extended_line_op (data
,
4579 linfo
.li_default_is_stmt
,
4584 printf (_(" Copy"));
4585 if (verbose_view
|| state_machine_regs
.view
)
4586 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4589 state_machine_regs
.view
++;
4592 case DW_LNS_advance_pc
:
4593 READ_ULEB (uladv
, data
, end
);
4594 if (linfo
.li_max_ops_per_insn
== 1)
4596 uladv
*= linfo
.li_min_insn_length
;
4597 state_machine_regs
.address
+= uladv
;
4599 state_machine_regs
.view
= 0;
4600 printf (_(" Advance PC by %s to 0x%s%s\n"),
4601 dwarf_vmatoa ("u", uladv
),
4602 dwarf_vmatoa ("x", state_machine_regs
.address
),
4603 verbose_view
&& uladv
4604 ? _(" (reset view)") : "");
4609 = ((state_machine_regs
.op_index
+ uladv
)
4610 / linfo
.li_max_ops_per_insn
)
4611 * linfo
.li_min_insn_length
;
4612 state_machine_regs
.address
4614 state_machine_regs
.op_index
4615 = (state_machine_regs
.op_index
+ uladv
)
4616 % linfo
.li_max_ops_per_insn
;
4618 state_machine_regs
.view
= 0;
4619 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4620 dwarf_vmatoa ("u", uladv
),
4621 dwarf_vmatoa ("x", state_machine_regs
.address
),
4622 state_machine_regs
.op_index
,
4623 verbose_view
&& addrdelta
4624 ? _(" (reset view)") : "");
4628 case DW_LNS_advance_line
:
4629 READ_SLEB (adv
, data
, end
);
4630 state_machine_regs
.line
+= adv
;
4631 printf (_(" Advance Line by %s to %d\n"),
4632 dwarf_vmatoa ("d", adv
),
4633 state_machine_regs
.line
);
4636 case DW_LNS_set_file
:
4637 READ_ULEB (uladv
, data
, end
);
4638 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4639 dwarf_vmatoa ("u", uladv
));
4640 state_machine_regs
.file
= uladv
;
4643 case DW_LNS_set_column
:
4644 READ_ULEB (uladv
, data
, end
);
4645 printf (_(" Set column to %s\n"),
4646 dwarf_vmatoa ("u", uladv
));
4647 state_machine_regs
.column
= uladv
;
4650 case DW_LNS_negate_stmt
:
4651 adv
= state_machine_regs
.is_stmt
;
4653 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4654 state_machine_regs
.is_stmt
= adv
;
4657 case DW_LNS_set_basic_block
:
4658 printf (_(" Set basic block\n"));
4659 state_machine_regs
.basic_block
= 1;
4662 case DW_LNS_const_add_pc
:
4663 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4664 if (linfo
.li_max_ops_per_insn
)
4666 uladv
*= linfo
.li_min_insn_length
;
4667 state_machine_regs
.address
+= uladv
;
4669 state_machine_regs
.view
= 0;
4670 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4671 dwarf_vmatoa ("u", uladv
),
4672 dwarf_vmatoa ("x", state_machine_regs
.address
),
4673 verbose_view
&& uladv
4674 ? _(" (reset view)") : "");
4679 = ((state_machine_regs
.op_index
+ uladv
)
4680 / linfo
.li_max_ops_per_insn
)
4681 * linfo
.li_min_insn_length
;
4682 state_machine_regs
.address
4684 state_machine_regs
.op_index
4685 = (state_machine_regs
.op_index
+ uladv
)
4686 % linfo
.li_max_ops_per_insn
;
4688 state_machine_regs
.view
= 0;
4689 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4690 dwarf_vmatoa ("u", uladv
),
4691 dwarf_vmatoa ("x", state_machine_regs
.address
),
4692 state_machine_regs
.op_index
,
4693 verbose_view
&& addrdelta
4694 ? _(" (reset view)") : "");
4698 case DW_LNS_fixed_advance_pc
:
4699 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4700 state_machine_regs
.address
+= uladv
;
4701 state_machine_regs
.op_index
= 0;
4702 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4703 dwarf_vmatoa ("u", uladv
),
4704 dwarf_vmatoa ("x", state_machine_regs
.address
));
4705 /* Do NOT reset view. */
4708 case DW_LNS_set_prologue_end
:
4709 printf (_(" Set prologue_end to true\n"));
4712 case DW_LNS_set_epilogue_begin
:
4713 printf (_(" Set epilogue_begin to true\n"));
4716 case DW_LNS_set_isa
:
4717 READ_ULEB (uladv
, data
, end
);
4718 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4722 printf (_(" Unknown opcode %d with operands: "), op_code
);
4724 if (standard_opcodes
!= NULL
)
4725 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4727 READ_ULEB (uladv
, data
, end
);
4728 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4729 i
== 1 ? "" : ", ");
4744 unsigned char *name
;
4745 unsigned int directory_index
;
4746 unsigned int modification_date
;
4747 unsigned int length
;
4750 /* Output a decoded representation of the .debug_line section. */
4753 display_debug_lines_decoded (struct dwarf_section
* section
,
4754 unsigned char * start
,
4755 unsigned char * data
,
4756 unsigned char * end
,
4759 static DWARF2_Internal_LineInfo saved_linfo
;
4761 introduce (section
, FALSE
);
4765 /* This loop amounts to one iteration per compilation unit. */
4766 DWARF2_Internal_LineInfo linfo
;
4767 unsigned char *standard_opcodes
;
4768 unsigned char *end_of_sequence
;
4770 File_Entry
*file_table
= NULL
;
4771 unsigned int n_files
= 0;
4772 unsigned char **directory_table
= NULL
;
4773 dwarf_vma n_directories
= 0;
4775 if (const_strneq (section
->name
, ".debug_line.")
4776 /* Note: the following does not apply to .debug_line.dwo sections.
4777 These are full debug_line sections. */
4778 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4780 /* See comment in display_debug_lines_raw(). */
4781 end_of_sequence
= end
;
4782 standard_opcodes
= NULL
;
4783 linfo
= saved_linfo
;
4784 /* PR 17531: file: 0522b371. */
4785 if (linfo
.li_line_range
== 0)
4787 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4790 reset_state_machine (linfo
.li_default_is_stmt
);
4794 unsigned char *hdrptr
;
4796 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4797 & end_of_sequence
)) == NULL
)
4800 /* PR 17531: file: 0522b371. */
4801 if (linfo
.li_line_range
== 0)
4803 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4804 linfo
.li_line_range
= 1;
4806 reset_state_machine (linfo
.li_default_is_stmt
);
4808 /* Save a pointer to the contents of the Opcodes table. */
4809 standard_opcodes
= hdrptr
;
4811 /* Traverse the Directory table just to count entries. */
4812 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4816 warn (_("opcode base of %d extends beyond end of section\n"),
4817 linfo
.li_opcode_base
);
4821 if (linfo
.li_version
>= 5)
4823 unsigned char *format_start
, format_count
, *format
;
4824 dwarf_vma formati
, entryi
;
4826 load_debug_section_with_follow (line_str
, fileptr
);
4828 /* Skip directories format. */
4829 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4830 if (do_checks
&& format_count
> 1)
4831 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4833 format_start
= data
;
4834 for (formati
= 0; formati
< format_count
; formati
++)
4836 SKIP_ULEB (data
, end
);
4837 SKIP_ULEB (data
, end
);
4840 READ_ULEB (n_directories
, data
, end
);
4843 warn (_("Corrupt directories list\n"));
4847 if (n_directories
== 0)
4848 directory_table
= NULL
;
4850 directory_table
= (unsigned char **)
4851 xmalloc (n_directories
* sizeof (unsigned char *));
4853 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4855 unsigned char **pathp
= &directory_table
[entryi
];
4857 format
= format_start
;
4858 for (formati
= 0; formati
< format_count
; formati
++)
4860 dwarf_vma content_type
, form
;
4863 READ_ULEB (content_type
, format
, end
);
4864 READ_ULEB (form
, format
, end
);
4867 warn (_("Corrupt directories list\n"));
4870 switch (content_type
)
4875 case DW_FORM_string
:
4878 case DW_FORM_line_strp
:
4879 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4881 /* Remove const by the cast. */
4882 *pathp
= (unsigned char *)
4883 fetch_indirect_line_string (uvalue
);
4888 data
= read_and_display_attr_value (0, form
, 0, start
,
4890 linfo
.li_offset_size
,
4897 warn (_("Corrupt directories list\n"));
4902 /* Skip files format. */
4903 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4904 if (do_checks
&& format_count
> 5)
4905 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
4907 format_start
= data
;
4908 for (formati
= 0; formati
< format_count
; formati
++)
4910 SKIP_ULEB (data
, end
);
4911 SKIP_ULEB (data
, end
);
4914 READ_ULEB (n_files
, data
, end
);
4915 if (data
== end
&& n_files
> 0)
4917 warn (_("Corrupt file name list\n"));
4924 file_table
= (File_Entry
*) xcalloc (1, n_files
4925 * sizeof (File_Entry
));
4927 for (entryi
= 0; entryi
< n_files
; entryi
++)
4929 File_Entry
*file
= &file_table
[entryi
];
4931 format
= format_start
;
4932 for (formati
= 0; formati
< format_count
; formati
++)
4934 dwarf_vma content_type
, form
;
4938 READ_ULEB (content_type
, format
, end
);
4939 READ_ULEB (form
, format
, end
);
4942 warn (_("Corrupt file name list\n"));
4945 switch (content_type
)
4950 case DW_FORM_string
:
4953 case DW_FORM_line_strp
:
4954 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4956 /* Remove const by the cast. */
4957 file
->name
= (unsigned char *)
4958 fetch_indirect_line_string (uvalue
);
4962 case DW_LNCT_directory_index
:
4966 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4970 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4975 READ_ULEB (file
->directory_index
, tmp
, end
);
4980 data
= read_and_display_attr_value (0, form
, 0, start
,
4982 linfo
.li_offset_size
,
4989 warn (_("Corrupt file name list\n"));
4998 unsigned char *ptr_directory_table
= data
;
5000 while (data
< end
&& *data
!= 0)
5002 data
+= strnlen ((char *) data
, end
- data
) + 1;
5009 warn (_("directory table ends unexpectedly\n"));
5014 /* Go through the directory table again to save the directories. */
5015 directory_table
= (unsigned char **)
5016 xmalloc (n_directories
* sizeof (unsigned char *));
5019 while (*ptr_directory_table
!= 0)
5021 directory_table
[i
] = ptr_directory_table
;
5022 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
5023 ptr_directory_table
- end
) + 1;
5027 /* Skip the NUL at the end of the table. */
5030 /* Traverse the File Name table just to count the entries. */
5031 if (data
< end
&& *data
!= 0)
5033 unsigned char *ptr_file_name_table
= data
;
5035 while (data
< end
&& *data
!= 0)
5037 /* Skip Name, directory index, last modification
5038 time and length of file. */
5039 data
+= strnlen ((char *) data
, end
- data
) + 1;
5040 SKIP_ULEB (data
, end
);
5041 SKIP_ULEB (data
, end
);
5042 SKIP_ULEB (data
, end
);
5048 warn (_("file table ends unexpectedly\n"));
5053 /* Go through the file table again to save the strings. */
5054 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5057 while (*ptr_file_name_table
!= 0)
5059 file_table
[i
].name
= ptr_file_name_table
;
5060 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
5061 end
- ptr_file_name_table
) + 1;
5063 /* We are not interested in directory, time or size. */
5064 READ_ULEB (file_table
[i
].directory_index
,
5065 ptr_file_name_table
, end
);
5066 READ_ULEB (file_table
[i
].modification_date
,
5067 ptr_file_name_table
, end
);
5068 READ_ULEB (file_table
[i
].length
,
5069 ptr_file_name_table
, end
);
5075 /* Skip the NUL at the end of the table. */
5079 /* Print the Compilation Unit's name and a header. */
5080 if (file_table
== NULL
)
5081 printf (_("CU: No directory table\n"));
5082 else if (directory_table
== NULL
)
5083 printf (_("CU: %s:\n"), file_table
[0].name
);
5086 unsigned int ix
= file_table
[0].directory_index
;
5087 const char *directory
;
5092 else if (n_directories
== 0)
5093 directory
= _("<unknown>");
5094 else if (ix
> n_directories
)
5096 warn (_("directory index %u > number of directories %s\n"),
5097 ix
, dwarf_vmatoa ("u", n_directories
));
5098 directory
= _("<corrupt>");
5101 directory
= (char *) directory_table
[ix
- 1];
5103 if (do_wide
|| strlen (directory
) < 76)
5104 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5106 printf ("%s:\n", file_table
[0].name
);
5110 printf (_("File name Line number Starting address View Stmt\n"));
5112 printf (_("CU: Empty file name table\n"));
5113 saved_linfo
= linfo
;
5116 /* This loop iterates through the Dwarf Line Number Program. */
5117 while (data
< end_of_sequence
)
5119 unsigned char op_code
;
5122 unsigned long int uladv
;
5123 int is_special_opcode
= 0;
5128 if (op_code
>= linfo
.li_opcode_base
)
5130 op_code
-= linfo
.li_opcode_base
;
5131 uladv
= (op_code
/ linfo
.li_line_range
);
5132 if (linfo
.li_max_ops_per_insn
== 1)
5134 uladv
*= linfo
.li_min_insn_length
;
5135 state_machine_regs
.address
+= uladv
;
5137 state_machine_regs
.view
= 0;
5142 = ((state_machine_regs
.op_index
+ uladv
)
5143 / linfo
.li_max_ops_per_insn
)
5144 * linfo
.li_min_insn_length
;
5145 state_machine_regs
.address
5147 state_machine_regs
.op_index
5148 = (state_machine_regs
.op_index
+ uladv
)
5149 % linfo
.li_max_ops_per_insn
;
5151 state_machine_regs
.view
= 0;
5154 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5155 state_machine_regs
.line
+= adv
;
5156 is_special_opcode
= 1;
5157 /* Increment view after printing this row. */
5162 case DW_LNS_extended_op
:
5164 unsigned int ext_op_code_len
;
5165 unsigned char ext_op_code
;
5166 unsigned char *op_code_end
;
5167 unsigned char *op_code_data
= data
;
5169 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5170 op_code_end
= op_code_data
+ ext_op_code_len
;
5171 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5173 warn (_("Badly formed extended line op encountered!\n"));
5176 ext_op_code
= *op_code_data
++;
5180 switch (ext_op_code
)
5182 case DW_LNE_end_sequence
:
5183 /* Reset stuff after printing this row. */
5185 case DW_LNE_set_address
:
5186 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5188 op_code_end
- op_code_data
,
5190 state_machine_regs
.op_index
= 0;
5191 state_machine_regs
.view
= 0;
5193 case DW_LNE_define_file
:
5194 file_table
= (File_Entry
*) xrealloc
5195 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5197 ++state_machine_regs
.last_file_entry
;
5198 /* Source file name. */
5199 file_table
[n_files
].name
= op_code_data
;
5200 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5201 /* Directory index. */
5202 READ_ULEB (file_table
[n_files
].directory_index
,
5203 op_code_data
, op_code_end
);
5204 /* Last modification time. */
5205 READ_ULEB (file_table
[n_files
].modification_date
,
5206 op_code_data
, op_code_end
);
5208 READ_ULEB (file_table
[n_files
].length
,
5209 op_code_data
, op_code_end
);
5213 case DW_LNE_set_discriminator
:
5214 case DW_LNE_HP_set_sequence
:
5215 /* Simply ignored. */
5219 printf (_("UNKNOWN (%u): length %ld\n"),
5220 ext_op_code
, (long int) (op_code_data
- data
));
5227 /* Increment view after printing this row. */
5230 case DW_LNS_advance_pc
:
5231 READ_ULEB (uladv
, data
, end
);
5232 if (linfo
.li_max_ops_per_insn
== 1)
5234 uladv
*= linfo
.li_min_insn_length
;
5235 state_machine_regs
.address
+= uladv
;
5237 state_machine_regs
.view
= 0;
5242 = ((state_machine_regs
.op_index
+ uladv
)
5243 / linfo
.li_max_ops_per_insn
)
5244 * linfo
.li_min_insn_length
;
5245 state_machine_regs
.address
5247 state_machine_regs
.op_index
5248 = (state_machine_regs
.op_index
+ uladv
)
5249 % linfo
.li_max_ops_per_insn
;
5251 state_machine_regs
.view
= 0;
5255 case DW_LNS_advance_line
:
5256 READ_SLEB (adv
, data
, end
);
5257 state_machine_regs
.line
+= adv
;
5260 case DW_LNS_set_file
:
5261 READ_ULEB (uladv
, data
, end
);
5262 state_machine_regs
.file
= uladv
;
5265 unsigned file
= state_machine_regs
.file
- 1;
5268 if (file_table
== NULL
|| n_files
== 0)
5269 printf (_("\n [Use file table entry %d]\n"), file
);
5271 else if (file
>= n_files
)
5273 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
5274 printf (_("\n <over large file table index %u>"), file
);
5276 else if ((dir
= file_table
[file
].directory_index
) == 0)
5277 /* If directory index is 0, that means current directory. */
5278 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5279 else if (directory_table
== NULL
|| n_directories
== 0)
5280 printf (_("\n [Use file %s in directory table entry %d]\n"),
5281 file_table
[file
].name
, dir
);
5283 else if (dir
> n_directories
)
5285 warn (_("directory index %u > number of directories %s\n"),
5286 dir
, dwarf_vmatoa ("u", n_directories
));
5287 printf (_("\n <over large directory table entry %u>\n"), dir
);
5290 printf ("\n%s/%s:\n",
5291 /* The directory index starts counting at 1. */
5292 directory_table
[dir
- 1], file_table
[file
].name
);
5296 case DW_LNS_set_column
:
5297 READ_ULEB (uladv
, data
, end
);
5298 state_machine_regs
.column
= uladv
;
5301 case DW_LNS_negate_stmt
:
5302 adv
= state_machine_regs
.is_stmt
;
5304 state_machine_regs
.is_stmt
= adv
;
5307 case DW_LNS_set_basic_block
:
5308 state_machine_regs
.basic_block
= 1;
5311 case DW_LNS_const_add_pc
:
5312 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5313 if (linfo
.li_max_ops_per_insn
== 1)
5315 uladv
*= linfo
.li_min_insn_length
;
5316 state_machine_regs
.address
+= uladv
;
5318 state_machine_regs
.view
= 0;
5323 = ((state_machine_regs
.op_index
+ uladv
)
5324 / linfo
.li_max_ops_per_insn
)
5325 * linfo
.li_min_insn_length
;
5326 state_machine_regs
.address
5328 state_machine_regs
.op_index
5329 = (state_machine_regs
.op_index
+ uladv
)
5330 % linfo
.li_max_ops_per_insn
;
5332 state_machine_regs
.view
= 0;
5336 case DW_LNS_fixed_advance_pc
:
5337 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5338 state_machine_regs
.address
+= uladv
;
5339 state_machine_regs
.op_index
= 0;
5340 /* Do NOT reset view. */
5343 case DW_LNS_set_prologue_end
:
5346 case DW_LNS_set_epilogue_begin
:
5349 case DW_LNS_set_isa
:
5350 READ_ULEB (uladv
, data
, end
);
5351 printf (_(" Set ISA to %lu\n"), uladv
);
5355 printf (_(" Unknown opcode %d with operands: "), op_code
);
5357 if (standard_opcodes
!= NULL
)
5358 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5362 READ_ULEB (val
, data
, end
);
5363 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5364 i
== 1 ? "" : ", ");
5370 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5371 to the DWARF address/line matrix. */
5372 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5373 || (xop
== DW_LNS_copy
))
5375 const unsigned int MAX_FILENAME_LENGTH
= 35;
5377 char *newFileName
= NULL
;
5378 size_t fileNameLength
;
5382 unsigned indx
= state_machine_regs
.file
- 1;
5384 if (indx
>= n_files
)
5386 warn (_("corrupt file index %u encountered\n"), indx
);
5387 fileName
= _("<corrupt>");
5390 fileName
= (char *) file_table
[indx
].name
;
5393 fileName
= _("<unknown>");
5395 fileNameLength
= strlen (fileName
);
5397 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5399 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5400 /* Truncate file name */
5401 strncpy (newFileName
,
5402 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5403 MAX_FILENAME_LENGTH
+ 1);
5404 /* FIXME: This is to pacify gcc-10 which can warn that the
5405 strncpy above might leave a non-NUL terminated string
5406 in newFileName. It won't, but gcc's analysis doesn't
5407 quite go far enough to discover this. */
5408 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5412 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5413 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5416 /* A row with end_seq set to true has a meaningful address, but
5417 the other information in the same row is not significant.
5418 In such a row, print line as "-", and don't print
5420 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5422 if (linfo
.li_max_ops_per_insn
== 1)
5424 if (xop
== -DW_LNE_end_sequence
)
5425 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5427 state_machine_regs
.address
);
5429 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5430 newFileName
, state_machine_regs
.line
,
5431 state_machine_regs
.address
);
5435 if (xop
== -DW_LNE_end_sequence
)
5436 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5438 state_machine_regs
.address
,
5439 state_machine_regs
.op_index
);
5441 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5442 newFileName
, state_machine_regs
.line
,
5443 state_machine_regs
.address
,
5444 state_machine_regs
.op_index
);
5449 if (linfo
.li_max_ops_per_insn
== 1)
5451 if (xop
== -DW_LNE_end_sequence
)
5452 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5454 state_machine_regs
.address
);
5456 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5457 newFileName
, state_machine_regs
.line
,
5458 state_machine_regs
.address
);
5462 if (xop
== -DW_LNE_end_sequence
)
5463 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5465 state_machine_regs
.address
,
5466 state_machine_regs
.op_index
);
5468 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5469 newFileName
, state_machine_regs
.line
,
5470 state_machine_regs
.address
,
5471 state_machine_regs
.op_index
);
5475 if (xop
!= -DW_LNE_end_sequence
)
5477 if (state_machine_regs
.view
)
5478 printf (" %6u", state_machine_regs
.view
);
5482 if (state_machine_regs
.is_stmt
)
5487 state_machine_regs
.view
++;
5489 if (xop
== -DW_LNE_end_sequence
)
5491 reset_state_machine (linfo
.li_default_is_stmt
);
5506 if (directory_table
)
5508 free (directory_table
);
5509 directory_table
= NULL
;
5520 display_debug_lines (struct dwarf_section
*section
, void *file
)
5522 unsigned char *data
= section
->start
;
5523 unsigned char *end
= data
+ section
->size
;
5525 int retValDecoded
= 1;
5527 if (do_debug_lines
== 0)
5528 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5530 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5531 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5533 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5534 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5536 if (!retValRaw
|| !retValDecoded
)
5543 find_debug_info_for_offset (unsigned long offset
)
5547 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5550 for (i
= 0; i
< num_debug_info_entries
; i
++)
5551 if (debug_information
[i
].cu_offset
== offset
)
5552 return debug_information
+ i
;
5558 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5560 /* See gdb/gdb-index.h. */
5561 static const char * const kinds
[] =
5573 return _ (kinds
[kind
]);
5577 display_debug_pubnames_worker (struct dwarf_section
*section
,
5578 void *file ATTRIBUTE_UNUSED
,
5581 DWARF2_Internal_PubNames names
;
5582 unsigned char *start
= section
->start
;
5583 unsigned char *end
= start
+ section
->size
;
5585 /* It does not matter if this load fails,
5586 we test for that later on. */
5587 load_debug_info (file
);
5589 introduce (section
, FALSE
);
5593 unsigned char *data
;
5594 unsigned long sec_off
;
5595 unsigned int offset_size
, initial_length_size
;
5597 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5598 if (names
.pn_length
== 0xffffffff)
5600 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5602 initial_length_size
= 12;
5607 initial_length_size
= 4;
5610 sec_off
= start
- section
->start
;
5611 if (sec_off
+ names
.pn_length
< sec_off
5612 || sec_off
+ names
.pn_length
> section
->size
)
5614 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5616 sec_off
- initial_length_size
,
5617 dwarf_vmatoa ("x", names
.pn_length
));
5622 start
+= names
.pn_length
;
5624 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5625 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5627 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5628 && num_debug_info_entries
> 0
5629 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5630 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5631 (unsigned long) names
.pn_offset
, section
->name
);
5633 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5635 printf (_(" Length: %ld\n"),
5636 (long) names
.pn_length
);
5637 printf (_(" Version: %d\n"),
5639 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5640 (unsigned long) names
.pn_offset
);
5641 printf (_(" Size of area in .debug_info section: %ld\n"),
5642 (long) names
.pn_size
);
5644 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5646 static int warned
= 0;
5650 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5658 printf (_("\n Offset Kind Name\n"));
5660 printf (_("\n Offset\tName\n"));
5664 bfd_size_type maxprint
;
5667 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5672 data
+= offset_size
;
5675 maxprint
= (end
- data
) - 1;
5679 unsigned int kind_data
;
5680 gdb_index_symbol_kind kind
;
5681 const char *kind_name
;
5684 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5687 /* GCC computes the kind as the upper byte in the CU index
5688 word, and then right shifts it by the CU index size.
5689 Left shift KIND to where the gdb-index.h accessor macros
5691 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5692 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5693 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5694 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5695 printf (" %-6lx %s,%-10s %.*s\n",
5696 (unsigned long) offset
, is_static
? _("s") : _("g"),
5697 kind_name
, (int) maxprint
, data
);
5700 printf (" %-6lx\t%.*s\n",
5701 (unsigned long) offset
, (int) maxprint
, data
);
5703 data
+= strnlen ((char *) data
, maxprint
) + 1;
5714 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5716 return display_debug_pubnames_worker (section
, file
, 0);
5720 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5722 return display_debug_pubnames_worker (section
, file
, 1);
5726 display_debug_macinfo (struct dwarf_section
*section
,
5727 void *file ATTRIBUTE_UNUSED
)
5729 unsigned char *start
= section
->start
;
5730 unsigned char *end
= start
+ section
->size
;
5731 unsigned char *curr
= start
;
5732 enum dwarf_macinfo_record_type op
;
5734 introduce (section
, FALSE
);
5738 unsigned int lineno
;
5739 const unsigned char *string
;
5741 op
= (enum dwarf_macinfo_record_type
) *curr
;
5746 case DW_MACINFO_start_file
:
5748 unsigned int filenum
;
5750 READ_ULEB (lineno
, curr
, end
);
5751 READ_ULEB (filenum
, curr
, end
);
5752 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5757 case DW_MACINFO_end_file
:
5758 printf (_(" DW_MACINFO_end_file\n"));
5761 case DW_MACINFO_define
:
5762 READ_ULEB (lineno
, curr
, end
);
5764 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5765 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5769 case DW_MACINFO_undef
:
5770 READ_ULEB (lineno
, curr
, end
);
5772 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5773 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5777 case DW_MACINFO_vendor_ext
:
5779 unsigned int constant
;
5781 READ_ULEB (constant
, curr
, end
);
5783 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5784 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5794 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5795 filename and dirname corresponding to file name table entry with index
5796 FILEIDX. Return NULL on failure. */
5798 static unsigned char *
5799 get_line_filename_and_dirname (dwarf_vma line_offset
,
5801 unsigned char **dir_name
)
5803 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5804 unsigned char *hdrptr
, *dirtable
, *file_name
;
5805 unsigned int offset_size
, initial_length_size
;
5806 unsigned int version
, opcode_base
;
5807 dwarf_vma length
, diridx
;
5808 const unsigned char * end
;
5811 if (section
->start
== NULL
5812 || line_offset
>= section
->size
5816 hdrptr
= section
->start
+ line_offset
;
5817 end
= section
->start
+ section
->size
;
5819 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5820 if (length
== 0xffffffff)
5822 /* This section is 64-bit DWARF 3. */
5823 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5825 initial_length_size
= 12;
5830 initial_length_size
= 4;
5832 if (length
+ initial_length_size
< length
5833 || length
+ initial_length_size
> section
->size
)
5836 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5837 if (version
!= 2 && version
!= 3 && version
!= 4)
5839 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5841 hdrptr
++; /* Skip max_ops_per_insn. */
5842 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5844 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5845 if (opcode_base
== 0)
5848 hdrptr
+= opcode_base
- 1;
5853 /* Skip over dirname table. */
5854 while (*hdrptr
!= '\0')
5856 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5860 hdrptr
++; /* Skip the NUL at the end of the table. */
5862 /* Now skip over preceding filename table entries. */
5863 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5865 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5866 SKIP_ULEB (hdrptr
, end
);
5867 SKIP_ULEB (hdrptr
, end
);
5868 SKIP_ULEB (hdrptr
, end
);
5870 if (hdrptr
>= end
|| *hdrptr
== '\0')
5874 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5877 READ_ULEB (diridx
, hdrptr
, end
);
5880 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5881 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5882 if (dirtable
>= end
|| *dirtable
== '\0')
5884 *dir_name
= dirtable
;
5889 display_debug_macro (struct dwarf_section
*section
,
5892 unsigned char *start
= section
->start
;
5893 unsigned char *end
= start
+ section
->size
;
5894 unsigned char *curr
= start
;
5895 unsigned char *extended_op_buf
[256];
5897 load_debug_section_with_follow (str
, file
);
5898 load_debug_section_with_follow (line
, file
);
5899 load_debug_section_with_follow (str_index
, file
);
5901 introduce (section
, FALSE
);
5905 unsigned int lineno
, version
, flags
;
5906 unsigned int offset_size
= 4;
5907 const unsigned char *string
;
5908 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5909 unsigned char **extended_ops
= NULL
;
5911 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5912 if (version
!= 4 && version
!= 5)
5914 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5919 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5922 printf (_(" Offset: 0x%lx\n"),
5923 (unsigned long) sec_offset
);
5924 printf (_(" Version: %d\n"), version
);
5925 printf (_(" Offset size: %d\n"), offset_size
);
5928 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5929 printf (_(" Offset into .debug_line: 0x%lx\n"),
5930 (unsigned long) line_offset
);
5934 unsigned int i
, count
, op
;
5937 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5939 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5940 extended_ops
= extended_op_buf
;
5943 printf (_(" Extension opcode arguments:\n"));
5944 for (i
= 0; i
< count
; i
++)
5946 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5947 extended_ops
[op
] = curr
;
5948 READ_ULEB (nargs
, curr
, end
);
5950 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5953 printf (_(" DW_MACRO_%02x arguments: "), op
);
5954 for (n
= 0; n
< nargs
; n
++)
5958 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5959 printf ("%s%s", get_FORM_name (form
),
5960 n
== nargs
- 1 ? "\n" : ", ");
5970 case DW_FORM_block1
:
5971 case DW_FORM_block2
:
5972 case DW_FORM_block4
:
5974 case DW_FORM_string
:
5976 case DW_FORM_sec_offset
:
5979 error (_("Invalid extension opcode form %s\n"),
5980 get_FORM_name (form
));
5996 error (_(".debug_macro section not zero terminated\n"));
6000 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6006 case DW_MACRO_define
:
6007 READ_ULEB (lineno
, curr
, end
);
6009 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6010 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
6014 case DW_MACRO_undef
:
6015 READ_ULEB (lineno
, curr
, end
);
6017 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6018 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
6022 case DW_MACRO_start_file
:
6024 unsigned int filenum
;
6025 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6027 READ_ULEB (lineno
, curr
, end
);
6028 READ_ULEB (filenum
, curr
, end
);
6030 if ((flags
& 2) == 0)
6031 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6034 = get_line_filename_and_dirname (line_offset
, filenum
,
6036 if (file_name
== NULL
)
6037 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6040 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6042 dir_name
!= NULL
? (const char *) dir_name
: "",
6043 dir_name
!= NULL
? "/" : "", file_name
);
6047 case DW_MACRO_end_file
:
6048 printf (_(" DW_MACRO_end_file\n"));
6051 case DW_MACRO_define_strp
:
6052 READ_ULEB (lineno
, curr
, end
);
6053 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6054 string
= fetch_indirect_string (offset
);
6055 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6059 case DW_MACRO_undef_strp
:
6060 READ_ULEB (lineno
, curr
, end
);
6061 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6062 string
= fetch_indirect_string (offset
);
6063 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6067 case DW_MACRO_import
:
6068 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6069 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6070 (unsigned long) offset
);
6073 case DW_MACRO_define_sup
:
6074 READ_ULEB (lineno
, curr
, end
);
6075 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6076 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6077 lineno
, (unsigned long) offset
);
6080 case DW_MACRO_undef_sup
:
6081 READ_ULEB (lineno
, curr
, end
);
6082 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6083 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6084 lineno
, (unsigned long) offset
);
6087 case DW_MACRO_import_sup
:
6088 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6089 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6090 (unsigned long) offset
);
6093 case DW_MACRO_define_strx
:
6094 case DW_MACRO_undef_strx
:
6095 READ_ULEB (lineno
, curr
, end
);
6096 READ_ULEB (offset
, curr
, end
);
6097 string
= (const unsigned char *)
6098 fetch_indexed_string (offset
, NULL
, offset_size
, FALSE
);
6099 if (op
== DW_MACRO_define_strx
)
6100 printf (" DW_MACRO_define_strx ");
6102 printf (" DW_MACRO_undef_strx ");
6104 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6105 printf (_("lineno : %d macro : %s\n"),
6110 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6112 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6116 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6118 error (_(" Unknown macro opcode %02x seen\n"), op
);
6123 /* Skip over unhandled opcodes. */
6125 unsigned char *desc
= extended_ops
[op
];
6126 READ_ULEB (nargs
, desc
, end
);
6129 printf (_(" DW_MACRO_%02x\n"), op
);
6132 printf (_(" DW_MACRO_%02x -"), op
);
6133 for (n
= 0; n
< nargs
; n
++)
6137 /* DW_FORM_implicit_const is not expected here. */
6138 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6140 = read_and_display_attr_value (0, val
, 0,
6141 start
, curr
, end
, 0, 0, offset_size
,
6142 version
, NULL
, 0, NULL
,
6160 display_debug_abbrev (struct dwarf_section
*section
,
6161 void *file ATTRIBUTE_UNUSED
)
6163 abbrev_entry
*entry
;
6164 unsigned char *start
= section
->start
;
6165 const unsigned char *end
= start
+ section
->size
;
6167 introduce (section
, FALSE
);
6174 offset
= start
- section
->start
;
6175 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6178 list
= new_abbrev_list (0, offset
);
6179 start
= process_abbrev_set (start
, end
, list
);
6180 list
->start_of_next_abbrevs
= start
;
6183 start
= list
->start_of_next_abbrevs
;
6185 if (list
->first_abbrev
== NULL
)
6188 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6190 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6194 printf (" %ld %s [%s]\n",
6196 get_TAG_name (entry
->tag
),
6197 entry
->children
? _("has children") : _("no children"));
6199 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6201 printf (" %-18s %s",
6202 get_AT_name (attr
->attribute
),
6203 get_FORM_name (attr
->form
));
6204 if (attr
->form
== DW_FORM_implicit_const
)
6205 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
6217 /* Return true when ADDR is the maximum address, when addresses are
6218 POINTER_SIZE bytes long. */
6221 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6223 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6224 return ((addr
& mask
) == mask
);
6227 /* Display a view pair list starting at *VSTART_PTR and ending at
6228 VLISTEND within SECTION. */
6231 display_view_pair_list (struct dwarf_section
*section
,
6232 unsigned char **vstart_ptr
,
6233 unsigned int debug_info_entry
,
6234 unsigned char *vlistend
)
6236 unsigned char *vstart
= *vstart_ptr
;
6237 unsigned char *section_end
= section
->start
+ section
->size
;
6238 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6240 if (vlistend
< section_end
)
6241 section_end
= vlistend
;
6245 while (vstart
< section_end
)
6247 dwarf_vma off
= vstart
- section
->start
;
6248 dwarf_vma vbegin
, vend
;
6250 READ_ULEB (vbegin
, vstart
, section_end
);
6251 if (vstart
== section_end
)
6254 READ_ULEB (vend
, vstart
, section_end
);
6255 printf (" %8.8lx ", (unsigned long) off
);
6257 print_dwarf_view (vbegin
, pointer_size
, 1);
6258 print_dwarf_view (vend
, pointer_size
, 1);
6259 printf (_("location view pair\n"));
6263 *vstart_ptr
= vstart
;
6266 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6269 display_loc_list (struct dwarf_section
*section
,
6270 unsigned char **start_ptr
,
6271 unsigned int debug_info_entry
,
6273 dwarf_vma base_address
,
6274 unsigned char **vstart_ptr
,
6277 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6278 unsigned char *section_end
= section
->start
+ section
->size
;
6279 unsigned long cu_offset
;
6280 unsigned int pointer_size
;
6281 unsigned int offset_size
;
6286 unsigned short length
;
6287 int need_frame_base
;
6289 if (debug_info_entry
>= num_debug_info_entries
)
6291 warn (_("No debug information available for loc lists of entry: %u\n"),
6296 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6297 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6298 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6299 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6301 if (pointer_size
< 2 || pointer_size
> 8)
6303 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6304 pointer_size
, debug_info_entry
);
6310 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6311 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6313 if (start
+ 2 * pointer_size
> section_end
)
6315 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6316 (unsigned long) offset
);
6320 printf (" %8.8lx ", (unsigned long) off
);
6322 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6323 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6325 if (begin
== 0 && end
== 0)
6327 /* PR 18374: In a object file we can have a location list that
6328 starts with a begin and end of 0 because there are relocations
6329 that need to be applied to the addresses. Actually applying
6330 the relocations now does not help as they will probably resolve
6331 to 0, since the object file has not been fully linked. Real
6332 end of list markers will not have any relocations against them. */
6333 if (! reloc_at (section
, off
)
6334 && ! reloc_at (section
, off
+ pointer_size
))
6336 printf (_("<End of list>\n"));
6341 /* Check base address specifiers. */
6342 if (is_max_address (begin
, pointer_size
)
6343 && !is_max_address (end
, pointer_size
))
6346 print_dwarf_vma (begin
, pointer_size
);
6347 print_dwarf_vma (end
, pointer_size
);
6348 printf (_("(base address)\n"));
6354 off
= offset
+ (vstart
- *start_ptr
);
6356 READ_ULEB (vbegin
, vstart
, section_end
);
6357 print_dwarf_view (vbegin
, pointer_size
, 1);
6359 READ_ULEB (vend
, vstart
, section_end
);
6360 print_dwarf_view (vend
, pointer_size
, 1);
6362 printf (_("views at %8.8lx for:\n %*s "),
6363 (unsigned long) off
, 8, "");
6366 if (start
+ 2 > section_end
)
6368 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6369 (unsigned long) offset
);
6373 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6375 if (start
+ length
> section_end
)
6377 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6378 (unsigned long) offset
);
6382 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6383 print_dwarf_vma (end
+ base_address
, pointer_size
);
6386 need_frame_base
= decode_location_expression (start
,
6391 cu_offset
, section
);
6394 if (need_frame_base
&& !has_frame_base
)
6395 printf (_(" [without DW_AT_frame_base]"));
6397 if (begin
== end
&& vbegin
== vend
)
6398 fputs (_(" (start == end)"), stdout
);
6399 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6400 fputs (_(" (start > end)"), stdout
);
6408 *vstart_ptr
= vstart
;
6411 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6414 display_loclists_list (struct dwarf_section
*section
,
6415 unsigned char **start_ptr
,
6416 unsigned int debug_info_entry
,
6418 dwarf_vma base_address
,
6419 unsigned char **vstart_ptr
,
6422 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6423 unsigned char *section_end
= section
->start
+ section
->size
;
6424 unsigned long cu_offset
;
6425 unsigned int pointer_size
;
6426 unsigned int offset_size
;
6429 /* Initialize it due to a false compiler warning. */
6430 dwarf_vma begin
= -1, vbegin
= -1;
6431 dwarf_vma end
= -1, vend
= -1;
6433 int need_frame_base
;
6435 if (debug_info_entry
>= num_debug_info_entries
)
6437 warn (_("No debug information available for "
6438 "loclists lists of entry: %u\n"),
6443 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6444 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6445 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6446 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6448 if (pointer_size
< 2 || pointer_size
> 8)
6450 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6451 pointer_size
, debug_info_entry
);
6457 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6458 enum dwarf_location_list_entry_type llet
;
6460 if (start
+ 1 > section_end
)
6462 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6463 (unsigned long) offset
);
6467 printf (" %8.8lx ", (unsigned long) off
);
6469 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6471 if (vstart
&& (llet
== DW_LLE_offset_pair
6472 || llet
== DW_LLE_start_end
6473 || llet
== DW_LLE_start_length
))
6475 off
= offset
+ (vstart
- *start_ptr
);
6477 READ_ULEB (vbegin
, vstart
, section_end
);
6478 print_dwarf_view (vbegin
, pointer_size
, 1);
6480 READ_ULEB (vend
, vstart
, section_end
);
6481 print_dwarf_view (vend
, pointer_size
, 1);
6483 printf (_("views at %8.8lx for:\n %*s "),
6484 (unsigned long) off
, 8, "");
6489 case DW_LLE_end_of_list
:
6490 printf (_("<End of list>\n"));
6492 case DW_LLE_offset_pair
:
6493 READ_ULEB (begin
, start
, section_end
);
6494 begin
+= base_address
;
6495 READ_ULEB (end
, start
, section_end
);
6496 end
+= base_address
;
6498 case DW_LLE_start_end
:
6499 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6500 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6502 case DW_LLE_start_length
:
6503 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6504 READ_ULEB (end
, start
, section_end
);
6507 case DW_LLE_base_address
:
6508 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6510 print_dwarf_vma (base_address
, pointer_size
);
6511 printf (_("(base address)\n"));
6513 #ifdef DW_LLE_view_pair
6514 case DW_LLE_view_pair
:
6516 printf (_("View pair entry in loclist with locviews attribute\n"));
6517 READ_ULEB (vbegin
, start
, section_end
);
6518 print_dwarf_view (vbegin
, pointer_size
, 1);
6520 READ_ULEB (vend
, start
, section_end
);
6521 print_dwarf_view (vend
, pointer_size
, 1);
6523 printf (_("views for:\n"));
6527 error (_("Invalid location list entry type %d\n"), llet
);
6530 if (llet
== DW_LLE_end_of_list
)
6532 if (llet
!= DW_LLE_offset_pair
6533 && llet
!= DW_LLE_start_end
6534 && llet
!= DW_LLE_start_length
)
6537 if (start
+ 2 > section_end
)
6539 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6540 (unsigned long) offset
);
6544 READ_ULEB (length
, start
, section_end
);
6546 print_dwarf_vma (begin
, pointer_size
);
6547 print_dwarf_vma (end
, pointer_size
);
6550 need_frame_base
= decode_location_expression (start
,
6555 cu_offset
, section
);
6558 if (need_frame_base
&& !has_frame_base
)
6559 printf (_(" [without DW_AT_frame_base]"));
6561 if (begin
== end
&& vbegin
== vend
)
6562 fputs (_(" (start == end)"), stdout
);
6563 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6564 fputs (_(" (start > end)"), stdout
);
6572 if (vbegin
!= vm1
|| vend
!= vm1
)
6573 printf (_("Trailing view pair not used in a range"));
6576 *vstart_ptr
= vstart
;
6579 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6580 right-adjusted in a field of length LEN, and followed by a space. */
6583 print_addr_index (unsigned int idx
, unsigned int len
)
6585 static char buf
[15];
6586 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6587 printf ("%*s ", len
, buf
);
6590 /* Display a location list from a .dwo section. It uses address indexes rather
6591 than embedded addresses. This code closely follows display_loc_list, but the
6592 two are sufficiently different that combining things is very ugly. */
6595 display_loc_list_dwo (struct dwarf_section
*section
,
6596 unsigned char **start_ptr
,
6597 unsigned int debug_info_entry
,
6599 unsigned char **vstart_ptr
,
6602 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6603 unsigned char *section_end
= section
->start
+ section
->size
;
6604 unsigned long cu_offset
;
6605 unsigned int pointer_size
;
6606 unsigned int offset_size
;
6609 unsigned short length
;
6610 int need_frame_base
;
6613 if (debug_info_entry
>= num_debug_info_entries
)
6615 warn (_("No debug information for loc lists of entry: %u\n"),
6620 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6621 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6622 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6623 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6625 if (pointer_size
< 2 || pointer_size
> 8)
6627 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6628 pointer_size
, debug_info_entry
);
6634 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6636 if (start
>= section_end
)
6638 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6639 (unsigned long) offset
);
6643 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6656 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6658 READ_ULEB (view
, vstart
, section_end
);
6659 print_dwarf_view (view
, 8, 1);
6661 READ_ULEB (view
, vstart
, section_end
);
6662 print_dwarf_view (view
, 8, 1);
6664 printf (_("views at %8.8lx for:\n %*s "),
6665 (unsigned long) off
, 8, "");
6673 case 0: /* A terminating entry. */
6675 *vstart_ptr
= vstart
;
6676 printf (_("<End of list>\n"));
6678 case 1: /* A base-address entry. */
6679 READ_ULEB (idx
, start
, section_end
);
6680 print_addr_index (idx
, 8);
6681 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6682 printf (_("(base address selection entry)\n"));
6684 case 2: /* A start/end entry. */
6685 READ_ULEB (idx
, start
, section_end
);
6686 print_addr_index (idx
, 8);
6687 READ_ULEB (idx
, start
, section_end
);
6688 print_addr_index (idx
, 8);
6690 case 3: /* A start/length entry. */
6691 READ_ULEB (idx
, start
, section_end
);
6692 print_addr_index (idx
, 8);
6693 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6694 printf ("%08x ", idx
);
6696 case 4: /* An offset pair entry. */
6697 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6698 printf ("%08x ", idx
);
6699 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6700 printf ("%08x ", idx
);
6703 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6705 *vstart_ptr
= vstart
;
6709 if (start
+ 2 > section_end
)
6711 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6712 (unsigned long) offset
);
6716 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6717 if (start
+ length
> section_end
)
6719 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6720 (unsigned long) offset
);
6725 need_frame_base
= decode_location_expression (start
,
6730 cu_offset
, section
);
6733 if (need_frame_base
&& !has_frame_base
)
6734 printf (_(" [without DW_AT_frame_base]"));
6742 *vstart_ptr
= vstart
;
6745 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6748 static dwarf_vma
*loc_offsets
, *loc_views
;
6751 loc_offsets_compar (const void *ap
, const void *bp
)
6753 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6754 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6756 int ret
= (a
> b
) - (b
> a
);
6760 a
= loc_views
[*(const unsigned int *) ap
];
6761 b
= loc_views
[*(const unsigned int *) bp
];
6763 ret
= (a
> b
) - (b
> a
);
6769 display_debug_loc (struct dwarf_section
*section
, void *file
)
6771 unsigned char *start
= section
->start
, *vstart
= NULL
;
6772 unsigned long bytes
;
6773 unsigned char *section_begin
= start
;
6774 unsigned int num_loc_list
= 0;
6775 unsigned long last_offset
= 0;
6776 unsigned long last_view
= 0;
6777 unsigned int first
= 0;
6780 int seen_first_offset
= 0;
6781 int locs_sorted
= 1;
6782 unsigned char *next
= start
, *vnext
= vstart
;
6783 unsigned int *array
= NULL
;
6784 const char *suffix
= strrchr (section
->name
, '.');
6785 bfd_boolean is_dwo
= FALSE
;
6786 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6787 dwarf_vma expected_start
= 0;
6789 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6792 bytes
= section
->size
;
6796 printf (_("\nThe %s section is empty.\n"), section
->name
);
6802 unsigned char *hdrptr
= section_begin
;
6803 dwarf_vma ll_length
;
6804 unsigned short ll_version
;
6805 unsigned char *end
= section_begin
+ section
->size
;
6806 unsigned char address_size
, segment_selector_size
;
6807 uint32_t offset_entry_count
;
6809 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6810 if (ll_length
== 0xffffffff)
6811 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6813 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6814 if (ll_version
!= 5)
6816 warn (_("The %s section contains corrupt or "
6817 "unsupported version number: %d.\n"),
6818 section
->name
, ll_version
);
6822 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6824 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6825 if (segment_selector_size
!= 0)
6827 warn (_("The %s section contains "
6828 "unsupported segment selector size: %d.\n"),
6829 section
->name
, segment_selector_size
);
6833 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6834 if (offset_entry_count
!= 0)
6836 warn (_("The %s section contains "
6837 "unsupported offset entry count: %d.\n"),
6838 section
->name
, offset_entry_count
);
6842 expected_start
= hdrptr
- section_begin
;
6845 if (load_debug_info (file
) == 0)
6847 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6852 /* Check the order of location list in .debug_info section. If
6853 offsets of location lists are in the ascending order, we can
6854 use `debug_information' directly. */
6855 for (i
= 0; i
< num_debug_info_entries
; i
++)
6859 num
= debug_information
[i
].num_loc_offsets
;
6860 if (num
> num_loc_list
)
6863 /* Check if we can use `debug_information' directly. */
6864 if (locs_sorted
&& num
!= 0)
6866 if (!seen_first_offset
)
6868 /* This is the first location list. */
6869 last_offset
= debug_information
[i
].loc_offsets
[0];
6870 last_view
= debug_information
[i
].loc_views
[0];
6872 seen_first_offset
= 1;
6878 for (; j
< num
; j
++)
6881 debug_information
[i
].loc_offsets
[j
]
6882 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6883 && last_view
> debug_information
[i
].loc_views
[j
]))
6888 last_offset
= debug_information
[i
].loc_offsets
[j
];
6889 last_view
= debug_information
[i
].loc_views
[j
];
6894 if (!seen_first_offset
)
6895 error (_("No location lists in .debug_info section!\n"));
6897 if (debug_information
[first
].num_loc_offsets
> 0
6898 && debug_information
[first
].loc_offsets
[0] != expected_start
6899 && debug_information
[first
].loc_views
[0] != expected_start
)
6900 warn (_("Location lists in %s section start at 0x%s\n"),
6902 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6905 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6907 introduce (section
, FALSE
);
6909 if (reloc_at (section
, 0))
6910 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6912 printf (_(" Offset Begin End Expression\n"));
6914 seen_first_offset
= 0;
6915 for (i
= first
; i
< num_debug_info_entries
; i
++)
6917 dwarf_vma offset
, voffset
;
6918 dwarf_vma base_address
;
6924 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6926 loc_offsets
= debug_information
[i
].loc_offsets
;
6927 loc_views
= debug_information
[i
].loc_views
;
6928 qsort (array
, debug_information
[i
].num_loc_offsets
,
6929 sizeof (*array
), loc_offsets_compar
);
6932 int adjacent_view_loclists
= 1;
6933 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6935 j
= locs_sorted
? k
: array
[k
];
6937 && (debug_information
[i
].loc_offsets
[locs_sorted
6938 ? k
- 1 : array
[k
- 1]]
6939 == debug_information
[i
].loc_offsets
[j
])
6940 && (debug_information
[i
].loc_views
[locs_sorted
6941 ? k
- 1 : array
[k
- 1]]
6942 == debug_information
[i
].loc_views
[j
]))
6944 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6945 offset
= debug_information
[i
].loc_offsets
[j
];
6946 next
= section_begin
+ offset
;
6947 voffset
= debug_information
[i
].loc_views
[j
];
6949 vnext
= section_begin
+ voffset
;
6952 base_address
= debug_information
[i
].base_address
;
6954 if (vnext
&& vnext
< next
)
6957 display_view_pair_list (section
, &vstart
, i
, next
);
6962 if (!seen_first_offset
|| !adjacent_view_loclists
)
6963 seen_first_offset
= 1;
6967 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6968 (unsigned long) (start
- section_begin
),
6969 (unsigned long) offset
);
6970 else if (start
> next
)
6971 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6972 (unsigned long) (start
- section_begin
),
6973 (unsigned long) offset
);
6978 if (offset
>= bytes
)
6980 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6981 (unsigned long) offset
);
6985 if (vnext
&& voffset
>= bytes
)
6987 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6988 (unsigned long) voffset
);
6995 display_loc_list_dwo (section
, &start
, i
, offset
,
6996 &vstart
, has_frame_base
);
6998 display_loc_list (section
, &start
, i
, offset
, base_address
,
6999 &vstart
, has_frame_base
);
7004 warn (_("DWO is not yet supported.\n"));
7006 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7007 &vstart
, has_frame_base
);
7010 /* FIXME: this arrangement is quite simplistic. Nothing
7011 requires locview lists to be adjacent to corresponding
7012 loclists, and a single loclist could be augmented by
7013 different locview lists, and vice-versa, unlikely as it
7014 is that it would make sense to do so. Hopefully we'll
7015 have view pair support built into loclists before we ever
7016 need to address all these possibilities. */
7017 if (adjacent_view_loclists
&& vnext
7018 && vnext
!= start
&& vstart
!= next
)
7020 adjacent_view_loclists
= 0;
7021 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7024 if (vnext
&& vnext
== start
)
7025 display_view_pair_list (section
, &start
, i
, vstart
);
7029 if (start
< section
->start
+ section
->size
)
7030 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7031 "There are %ld unused bytes at the end of section %s\n",
7032 (long) (section
->start
+ section
->size
- start
)),
7033 (long) (section
->start
+ section
->size
- start
), section
->name
);
7040 display_debug_str (struct dwarf_section
*section
,
7041 void *file ATTRIBUTE_UNUSED
)
7043 unsigned char *start
= section
->start
;
7044 unsigned long bytes
= section
->size
;
7045 dwarf_vma addr
= section
->address
;
7049 printf (_("\nThe %s section is empty.\n"), section
->name
);
7053 introduce (section
, FALSE
);
7061 lbytes
= (bytes
> 16 ? 16 : bytes
);
7063 printf (" 0x%8.8lx ", (unsigned long) addr
);
7065 for (j
= 0; j
< 16; j
++)
7068 printf ("%2.2x", start
[j
]);
7076 for (j
= 0; j
< lbytes
; j
++)
7079 if (k
>= ' ' && k
< 0x80)
7098 display_debug_info (struct dwarf_section
*section
, void *file
)
7100 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, FALSE
);
7104 display_debug_types (struct dwarf_section
*section
, void *file
)
7106 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
7110 display_trace_info (struct dwarf_section
*section
, void *file
)
7112 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
7116 display_debug_aranges (struct dwarf_section
*section
,
7117 void *file ATTRIBUTE_UNUSED
)
7119 unsigned char *start
= section
->start
;
7120 unsigned char *end
= start
+ section
->size
;
7122 introduce (section
, FALSE
);
7124 /* It does not matter if this load fails,
7125 we test for that later on. */
7126 load_debug_info (file
);
7130 unsigned char *hdrptr
;
7131 DWARF2_Internal_ARange arange
;
7132 unsigned char *addr_ranges
;
7135 unsigned long sec_off
;
7136 unsigned char address_size
;
7138 unsigned int offset_size
;
7139 unsigned int initial_length_size
;
7143 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7144 if (arange
.ar_length
== 0xffffffff)
7146 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7148 initial_length_size
= 12;
7153 initial_length_size
= 4;
7156 sec_off
= hdrptr
- section
->start
;
7157 if (sec_off
+ arange
.ar_length
< sec_off
7158 || sec_off
+ arange
.ar_length
> section
->size
)
7160 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7162 sec_off
- initial_length_size
,
7163 dwarf_vmatoa ("x", arange
.ar_length
));
7167 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
7168 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
7170 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7171 && num_debug_info_entries
> 0
7172 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7173 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7174 (unsigned long) arange
.ar_info_offset
, section
->name
);
7176 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
7177 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
7179 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7181 /* PR 19872: A version number of 0 probably means that there is
7182 padding at the end of the .debug_aranges section. Gold puts
7183 it there when performing an incremental link, for example.
7184 So do not generate a warning in this case. */
7185 if (arange
.ar_version
)
7186 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7190 printf (_(" Length: %ld\n"),
7191 (long) arange
.ar_length
);
7192 printf (_(" Version: %d\n"), arange
.ar_version
);
7193 printf (_(" Offset into .debug_info: 0x%lx\n"),
7194 (unsigned long) arange
.ar_info_offset
);
7195 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7196 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7198 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7200 /* PR 17512: file: 001-108546-0.001:0.1. */
7201 if (address_size
== 0 || address_size
> 8)
7203 error (_("Invalid address size in %s section!\n"),
7208 /* The DWARF spec does not require that the address size be a power
7209 of two, but we do. This will have to change if we ever encounter
7210 an uneven architecture. */
7211 if ((address_size
& (address_size
- 1)) != 0)
7213 warn (_("Pointer size + Segment size is not a power of two.\n"));
7217 if (address_size
> 4)
7218 printf (_("\n Address Length\n"));
7220 printf (_("\n Address Length\n"));
7222 addr_ranges
= hdrptr
;
7224 /* Must pad to an alignment boundary that is twice the address size. */
7225 excess
= (hdrptr
- start
) % (2 * address_size
);
7227 addr_ranges
+= (2 * address_size
) - excess
;
7229 start
+= arange
.ar_length
+ initial_length_size
;
7231 while (addr_ranges
+ 2 * address_size
<= start
)
7233 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
7234 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
7237 print_dwarf_vma (address
, address_size
);
7238 print_dwarf_vma (length
, address_size
);
7248 /* Comparison function for qsort. */
7250 comp_addr_base (const void * v0
, const void * v1
)
7252 debug_info
*info0
= *(debug_info
**) v0
;
7253 debug_info
*info1
= *(debug_info
**) v1
;
7254 return info0
->addr_base
- info1
->addr_base
;
7257 /* Display the debug_addr section. */
7259 display_debug_addr (struct dwarf_section
*section
,
7262 debug_info
**debug_addr_info
;
7263 unsigned char *entry
;
7268 if (section
->size
== 0)
7270 printf (_("\nThe %s section is empty.\n"), section
->name
);
7274 if (load_debug_info (file
) == 0)
7276 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7281 introduce (section
, FALSE
);
7283 /* PR 17531: file: cf38d01b.
7284 We use xcalloc because a corrupt file may not have initialised all of the
7285 fields in the debug_info structure, which means that the sort below might
7286 try to move uninitialised data. */
7287 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7288 sizeof (debug_info
*));
7291 for (i
= 0; i
< num_debug_info_entries
; i
++)
7292 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7294 /* PR 17531: file: cf38d01b. */
7295 if (debug_information
[i
].addr_base
>= section
->size
)
7296 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7297 (unsigned long) debug_information
[i
].addr_base
, i
);
7299 debug_addr_info
[count
++] = debug_information
+ i
;
7302 /* Add a sentinel to make iteration convenient. */
7303 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7304 debug_addr_info
[count
]->addr_base
= section
->size
;
7305 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7307 for (i
= 0; i
< count
; i
++)
7310 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7312 printf (_(" For compilation unit at offset 0x%s:\n"),
7313 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7315 printf (_("\tIndex\tAddress\n"));
7316 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7317 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7321 dwarf_vma base
= byte_get (entry
, address_size
);
7322 printf (_("\t%d:\t"), idx
);
7323 print_dwarf_vma (base
, address_size
);
7325 entry
+= address_size
;
7331 free (debug_addr_info
);
7335 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7338 display_debug_str_offsets (struct dwarf_section
*section
,
7339 void *file ATTRIBUTE_UNUSED
)
7343 if (section
->size
== 0)
7345 printf (_("\nThe %s section is empty.\n"), section
->name
);
7349 unsigned char *start
= section
->start
;
7350 unsigned char *end
= start
+ section
->size
;
7351 unsigned char *curr
= start
;
7353 const char * suffix
= strrchr (section
->name
, '.');
7354 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
7357 load_debug_section_with_follow (str_dwo
, file
);
7359 load_debug_section_with_follow (str
, file
);
7361 introduce (section
, FALSE
);
7366 dwarf_vma entry_length
;
7368 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7369 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7370 if (length
== 0xffffffff)
7372 SAFE_BYTE_GET (length
, curr
, 8, end
);
7380 /* This is probably an old style .debug_str_offset section which
7381 just contains offsets and no header (and the first offset is 0). */
7382 length
= section
->size
;
7383 curr
= section
->start
;
7385 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7386 printf (_(" Index Offset [String]\n"));
7391 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
7393 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7396 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
7398 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7400 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7401 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7402 printf (_(" Index Offset [String]\n"));
7405 for (idx
= 0; length
>= entry_length
&& curr
< end
; idx
++)
7408 const unsigned char * string
;
7410 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
7412 string
= (const unsigned char *)
7413 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7415 string
= fetch_indirect_string (offset
);
7417 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7425 /* Each debug_information[x].range_lists[y] gets this representation for
7426 sorting purposes. */
7430 /* The debug_information[x].range_lists[y] value. */
7431 dwarf_vma ranges_offset
;
7433 /* Original debug_information to find parameters of the data. */
7434 debug_info
*debug_info_p
;
7437 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7440 range_entry_compar (const void *ap
, const void *bp
)
7442 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7443 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7444 const dwarf_vma a
= a_re
->ranges_offset
;
7445 const dwarf_vma b
= b_re
->ranges_offset
;
7447 return (a
> b
) - (b
> a
);
7451 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7452 unsigned int pointer_size
, unsigned long offset
,
7453 unsigned long base_address
)
7455 while (start
< finish
)
7460 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7461 if (start
>= finish
)
7463 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7465 printf (" %8.8lx ", offset
);
7467 if (begin
== 0 && end
== 0)
7469 printf (_("<End of list>\n"));
7473 /* Check base address specifiers. */
7474 if (is_max_address (begin
, pointer_size
)
7475 && !is_max_address (end
, pointer_size
))
7478 print_dwarf_vma (begin
, pointer_size
);
7479 print_dwarf_vma (end
, pointer_size
);
7480 printf ("(base address)\n");
7484 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7485 print_dwarf_vma (end
+ base_address
, pointer_size
);
7488 fputs (_("(start == end)"), stdout
);
7489 else if (begin
> end
)
7490 fputs (_("(start > end)"), stdout
);
7497 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7498 unsigned int pointer_size
, unsigned long offset
,
7499 unsigned long base_address
)
7501 unsigned char *next
= start
;
7505 unsigned long off
= offset
+ (start
- next
);
7506 enum dwarf_range_list_entry rlet
;
7507 /* Initialize it due to a false compiler warning. */
7508 dwarf_vma begin
= -1, length
, end
= -1;
7510 if (start
+ 1 > finish
)
7512 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7517 printf (" %8.8lx ", off
);
7519 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7523 case DW_RLE_end_of_list
:
7524 printf (_("<End of list>\n"));
7526 case DW_RLE_base_address
:
7527 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7528 print_dwarf_vma (base_address
, pointer_size
);
7529 printf (_("(base address)\n"));
7531 case DW_RLE_start_length
:
7532 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7533 READ_ULEB (length
, start
, finish
);
7534 end
= begin
+ length
;
7536 case DW_RLE_offset_pair
:
7537 READ_ULEB (begin
, start
, finish
);
7538 READ_ULEB (end
, start
, finish
);
7540 case DW_RLE_start_end
:
7541 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7542 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7545 error (_("Invalid range list entry type %d\n"), rlet
);
7546 rlet
= DW_RLE_end_of_list
;
7549 if (rlet
== DW_RLE_end_of_list
)
7551 if (rlet
== DW_RLE_base_address
)
7554 /* Only a DW_RLE_offset_pair needs the base address added. */
7555 if (rlet
== DW_RLE_offset_pair
)
7557 begin
+= base_address
;
7558 end
+= base_address
;
7561 print_dwarf_vma (begin
, pointer_size
);
7562 print_dwarf_vma (end
, pointer_size
);
7565 fputs (_("(start == end)"), stdout
);
7566 else if (begin
> end
)
7567 fputs (_("(start > end)"), stdout
);
7574 display_debug_ranges (struct dwarf_section
*section
,
7575 void *file ATTRIBUTE_UNUSED
)
7577 unsigned char *start
= section
->start
;
7578 unsigned char *last_start
= start
;
7579 unsigned long bytes
= section
->size
;
7580 unsigned char *section_begin
= start
;
7581 unsigned char *finish
= start
+ bytes
;
7582 unsigned int num_range_list
, i
;
7583 struct range_entry
*range_entries
, *range_entry_fill
;
7584 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7585 /* Initialize it due to a false compiler warning. */
7586 unsigned char address_size
= 0;
7587 dwarf_vma last_offset
= 0;
7591 printf (_("\nThe %s section is empty.\n"), section
->name
);
7597 dwarf_vma initial_length
;
7598 unsigned int initial_length_size
;
7599 unsigned char segment_selector_size
;
7600 unsigned int offset_size
, offset_entry_count
;
7601 unsigned short version
;
7603 /* Get and check the length of the block. */
7604 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7606 if (initial_length
== 0xffffffff)
7608 /* This section is 64-bit DWARF 3. */
7609 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7611 initial_length_size
= 12;
7616 initial_length_size
= 4;
7619 if (initial_length
+ initial_length_size
> section
->size
)
7621 /* If the length field has a relocation against it, then we should
7622 not complain if it is inaccurate (and probably negative).
7623 It is copied from .debug_line handling code. */
7624 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7626 initial_length
= (finish
- start
) - initial_length_size
;
7630 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7631 (long) initial_length
);
7636 /* Get and check the version number. */
7637 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7641 warn (_("Only DWARF version 5 debug_rnglists info "
7642 "is currently supported.\n"));
7646 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7648 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7649 if (segment_selector_size
!= 0)
7651 warn (_("The %s section contains "
7652 "unsupported segment selector size: %d.\n"),
7653 section
->name
, segment_selector_size
);
7657 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7658 if (offset_entry_count
!= 0)
7660 warn (_("The %s section contains "
7661 "unsupported offset entry count: %u.\n"),
7662 section
->name
, offset_entry_count
);
7667 if (load_debug_info (file
) == 0)
7669 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7675 for (i
= 0; i
< num_debug_info_entries
; i
++)
7676 num_range_list
+= debug_information
[i
].num_range_lists
;
7678 if (num_range_list
== 0)
7680 /* This can happen when the file was compiled with -gsplit-debug
7681 which removes references to range lists from the primary .o file. */
7682 printf (_("No range lists in .debug_info section.\n"));
7686 range_entries
= (struct range_entry
*)
7687 xmalloc (sizeof (*range_entries
) * num_range_list
);
7688 range_entry_fill
= range_entries
;
7690 for (i
= 0; i
< num_debug_info_entries
; i
++)
7692 debug_info
*debug_info_p
= &debug_information
[i
];
7695 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7697 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7698 range_entry_fill
->debug_info_p
= debug_info_p
;
7703 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7704 range_entry_compar
);
7706 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7707 warn (_("Range lists in %s section start at 0x%lx\n"),
7708 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7710 introduce (section
, FALSE
);
7712 printf (_(" Offset Begin End\n"));
7714 for (i
= 0; i
< num_range_list
; i
++)
7716 struct range_entry
*range_entry
= &range_entries
[i
];
7717 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7718 unsigned int pointer_size
;
7720 unsigned char *next
;
7721 dwarf_vma base_address
;
7723 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7724 offset
= range_entry
->ranges_offset
;
7725 next
= section_begin
+ offset
;
7726 base_address
= debug_info_p
->base_address
;
7728 /* PR 17512: file: 001-101485-0.001:0.1. */
7729 if (pointer_size
< 2 || pointer_size
> 8)
7731 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7732 pointer_size
, (unsigned long) offset
);
7736 if (next
< section_begin
|| next
>= finish
)
7738 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7739 (unsigned long) offset
, i
);
7743 /* If multiple DWARF entities reference the same range then we will
7744 have multiple entries in the `range_entries' list for the same
7745 offset. Thanks to the sort above these will all be consecutive in
7746 the `range_entries' list, so we can easily ignore duplicates
7748 if (i
> 0 && last_offset
== offset
)
7750 last_offset
= offset
;
7752 if (dwarf_check
!= 0 && i
> 0)
7755 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7756 (unsigned long) (start
- section_begin
),
7757 (unsigned long) (next
- section_begin
), section
->name
);
7758 else if (start
> next
)
7760 if (next
== last_start
)
7762 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7763 (unsigned long) (start
- section_begin
),
7764 (unsigned long) (next
- section_begin
), section
->name
);
7771 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7772 (start
, finish
, pointer_size
, offset
, base_address
);
7776 free (range_entries
);
7781 typedef struct Frame_Chunk
7783 struct Frame_Chunk
*next
;
7784 unsigned char *chunk_start
;
7786 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7787 short int *col_type
;
7790 unsigned int code_factor
;
7794 unsigned int cfa_reg
;
7795 dwarf_vma cfa_offset
;
7797 unsigned char fde_encoding
;
7798 unsigned char cfa_exp
;
7799 unsigned char ptr_size
;
7800 unsigned char segment_size
;
7804 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7805 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7806 static const char *const *dwarf_regnames
;
7807 static unsigned int dwarf_regnames_count
;
7810 /* A marker for a col_type that means this column was never referenced
7811 in the frame info. */
7812 #define DW_CFA_unreferenced (-1)
7814 /* Return 0 if no more space is needed, 1 if more space is needed,
7815 -1 for invalid reg. */
7818 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7820 unsigned int prev
= fc
->ncols
;
7822 if (reg
< (unsigned int) fc
->ncols
)
7825 if (dwarf_regnames_count
> 0
7826 && reg
> dwarf_regnames_count
)
7829 fc
->ncols
= reg
+ 1;
7830 /* PR 17512: file: 10450-2643-0.004.
7831 If reg == -1 then this can happen... */
7835 /* PR 17512: file: 2844a11d. */
7836 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7838 error (_("Unfeasibly large register number: %u\n"), reg
);
7840 /* FIXME: 1024 is an arbitrary limit. Increase it if
7841 we ever encounter a valid binary that exceeds it. */
7845 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7846 sizeof (short int));
7847 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7848 /* PR 17512: file:002-10025-0.005. */
7849 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7851 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7857 while (prev
< fc
->ncols
)
7859 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7860 fc
->col_offset
[prev
] = 0;
7866 static const char *const dwarf_regnames_i386
[] =
7868 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7869 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7870 "eip", "eflags", NULL
, /* 8 - 10 */
7871 "st0", "st1", "st2", "st3", /* 11 - 14 */
7872 "st4", "st5", "st6", "st7", /* 15 - 18 */
7873 NULL
, NULL
, /* 19 - 20 */
7874 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7875 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7876 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7877 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7878 "fcw", "fsw", "mxcsr", /* 37 - 39 */
7879 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7880 "tr", "ldtr", /* 48 - 49 */
7881 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7882 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7883 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7884 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7885 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7886 NULL
, NULL
, NULL
, /* 90 - 92 */
7887 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
7890 static const char *const dwarf_regnames_iamcu
[] =
7892 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7893 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7894 "eip", "eflags", NULL
, /* 8 - 10 */
7895 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
7896 NULL
, NULL
, /* 19 - 20 */
7897 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
7898 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
7899 NULL
, NULL
, NULL
, /* 37 - 39 */
7900 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7901 "tr", "ldtr", /* 48 - 49 */
7902 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7903 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7904 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7905 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7906 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7907 NULL
, NULL
, NULL
, /* 90 - 92 */
7908 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
7912 init_dwarf_regnames_i386 (void)
7914 dwarf_regnames
= dwarf_regnames_i386
;
7915 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
7916 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7920 init_dwarf_regnames_iamcu (void)
7922 dwarf_regnames
= dwarf_regnames_iamcu
;
7923 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
7924 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7927 static const char *const dwarf_regnames_x86_64
[] =
7929 "rax", "rdx", "rcx", "rbx",
7930 "rsi", "rdi", "rbp", "rsp",
7931 "r8", "r9", "r10", "r11",
7932 "r12", "r13", "r14", "r15",
7934 "xmm0", "xmm1", "xmm2", "xmm3",
7935 "xmm4", "xmm5", "xmm6", "xmm7",
7936 "xmm8", "xmm9", "xmm10", "xmm11",
7937 "xmm12", "xmm13", "xmm14", "xmm15",
7938 "st0", "st1", "st2", "st3",
7939 "st4", "st5", "st6", "st7",
7940 "mm0", "mm1", "mm2", "mm3",
7941 "mm4", "mm5", "mm6", "mm7",
7943 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
7944 "fs.base", "gs.base", NULL
, NULL
,
7946 "mxcsr", "fcw", "fsw",
7947 "xmm16", "xmm17", "xmm18", "xmm19",
7948 "xmm20", "xmm21", "xmm22", "xmm23",
7949 "xmm24", "xmm25", "xmm26", "xmm27",
7950 "xmm28", "xmm29", "xmm30", "xmm31",
7951 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
7952 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
7953 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
7954 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
7955 NULL
, NULL
, NULL
, /* 115 - 117 */
7956 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7960 init_dwarf_regnames_x86_64 (void)
7962 dwarf_regnames
= dwarf_regnames_x86_64
;
7963 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
7964 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7967 static const char *const dwarf_regnames_aarch64
[] =
7969 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7970 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7971 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7972 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7973 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7974 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
7975 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
7976 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
7977 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7978 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7979 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7980 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7981 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
7982 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
7983 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
7984 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
7988 init_dwarf_regnames_aarch64 (void)
7990 dwarf_regnames
= dwarf_regnames_aarch64
;
7991 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
7992 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7995 static const char *const dwarf_regnames_s390
[] =
7997 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7998 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7999 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8000 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8001 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8002 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8003 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8004 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8005 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8008 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8009 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8013 init_dwarf_regnames_s390 (void)
8015 dwarf_regnames
= dwarf_regnames_s390
;
8016 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8017 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8020 static const char *const dwarf_regnames_riscv
[] =
8022 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8023 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8024 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8025 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8026 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8027 "fs0", "fs1", /* 40 - 41 */
8028 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8029 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8030 "fs10", "fs11", /* 58 - 59 */
8031 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8034 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8035 the large number of CSRs. */
8038 regname_internal_riscv (unsigned int regno
)
8040 const char *name
= NULL
;
8042 /* Lookup in the table first, this covers GPR and FPR. */
8043 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8044 name
= dwarf_regnames_riscv
[regno
];
8045 else if (regno
>= 4096 && regno
<= 8191)
8047 /* This might be a CSR, these live in a sparse number space from 4096
8048 to 8191 These numbers are defined in the RISC-V ELF ABI
8052 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8053 case VALUE + 4096: name = #NAME; break;
8054 #include "opcode/riscv-opc.h"
8059 static char csr_name
[10];
8060 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8071 init_dwarf_regnames_riscv (void)
8073 dwarf_regnames
= NULL
;
8074 dwarf_regnames_count
= 8192;
8075 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8079 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8081 dwarf_regnames_lookup_func
= NULL
;
8086 init_dwarf_regnames_i386 ();
8090 init_dwarf_regnames_iamcu ();
8096 init_dwarf_regnames_x86_64 ();
8100 init_dwarf_regnames_aarch64 ();
8104 init_dwarf_regnames_s390 ();
8108 init_dwarf_regnames_riscv ();
8116 /* Initialize the DWARF register name lookup state based on the
8117 architecture and specific machine type of a BFD. */
8120 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8123 dwarf_regnames_lookup_func
= NULL
;
8130 case bfd_mach_x86_64
:
8131 case bfd_mach_x86_64_intel_syntax
:
8132 case bfd_mach_x64_32
:
8133 case bfd_mach_x64_32_intel_syntax
:
8134 init_dwarf_regnames_x86_64 ();
8138 init_dwarf_regnames_i386 ();
8143 case bfd_arch_iamcu
:
8144 init_dwarf_regnames_iamcu ();
8147 case bfd_arch_aarch64
:
8148 init_dwarf_regnames_aarch64();
8152 init_dwarf_regnames_s390 ();
8155 case bfd_arch_riscv
:
8156 init_dwarf_regnames_riscv ();
8165 regname_internal_by_table_only (unsigned int regno
)
8167 if (dwarf_regnames
!= NULL
8168 && regno
< dwarf_regnames_count
8169 && dwarf_regnames
[regno
] != NULL
)
8170 return dwarf_regnames
[regno
];
8176 regname (unsigned int regno
, int name_only_p
)
8178 static char reg
[64];
8180 const char *name
= NULL
;
8182 if (dwarf_regnames_lookup_func
!= NULL
)
8183 name
= dwarf_regnames_lookup_func (regno
);
8189 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8192 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8197 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8202 if (*max_regs
!= fc
->ncols
)
8203 *max_regs
= fc
->ncols
;
8205 if (*need_col_headers
)
8207 *need_col_headers
= 0;
8209 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8211 for (r
= 0; r
< *max_regs
; r
++)
8212 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8217 printf ("%-5s ", regname (r
, 1));
8223 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8225 strcpy (tmp
, "exp");
8227 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8228 printf ("%-8s ", tmp
);
8230 for (r
= 0; r
< fc
->ncols
; r
++)
8232 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8234 switch (fc
->col_type
[r
])
8236 case DW_CFA_undefined
:
8239 case DW_CFA_same_value
:
8243 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8245 case DW_CFA_val_offset
:
8246 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8248 case DW_CFA_register
:
8249 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8251 case DW_CFA_expression
:
8252 strcpy (tmp
, "exp");
8254 case DW_CFA_val_expression
:
8255 strcpy (tmp
, "vexp");
8258 strcpy (tmp
, "n/a");
8261 printf ("%-5s ", tmp
);
8267 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8269 static unsigned char *
8270 read_cie (unsigned char *start
, unsigned char *end
,
8271 Frame_Chunk
**p_cie
, int *p_version
,
8272 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8276 unsigned char *augmentation_data
= NULL
;
8277 bfd_size_type augmentation_data_len
= 0;
8280 /* PR 17512: file: 001-228113-0.004. */
8284 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8285 memset (fc
, 0, sizeof (Frame_Chunk
));
8287 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8288 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8292 fc
->augmentation
= (char *) start
;
8293 /* PR 17512: file: 001-228113-0.004.
8294 Skip past augmentation name, but avoid running off the end of the data. */
8296 if (* start
++ == '\0')
8300 warn (_("No terminator for augmentation name\n"));
8304 if (strcmp (fc
->augmentation
, "eh") == 0)
8305 start
+= eh_addr_size
;
8309 GET (fc
->ptr_size
, 1);
8310 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8312 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8316 GET (fc
->segment_size
, 1);
8317 /* PR 17512: file: e99d2804. */
8318 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8320 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8324 eh_addr_size
= fc
->ptr_size
;
8328 fc
->ptr_size
= eh_addr_size
;
8329 fc
->segment_size
= 0;
8332 READ_ULEB (fc
->code_factor
, start
, end
);
8333 READ_SLEB (fc
->data_factor
, start
, end
);
8341 READ_ULEB (fc
->ra
, start
, end
);
8344 if (fc
->augmentation
[0] == 'z')
8346 READ_ULEB (augmentation_data_len
, start
, end
);
8347 augmentation_data
= start
;
8348 /* PR 17512: file: 11042-2589-0.004. */
8349 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8351 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8352 dwarf_vmatoa ("x", augmentation_data_len
),
8353 (unsigned long) (end
- start
));
8356 start
+= augmentation_data_len
;
8359 if (augmentation_data_len
)
8363 unsigned char *qend
;
8365 p
= (unsigned char *) fc
->augmentation
+ 1;
8366 q
= augmentation_data
;
8367 qend
= q
+ augmentation_data_len
;
8369 while (p
< end
&& q
< qend
)
8374 q
+= 1 + size_of_encoded_value (*q
);
8376 fc
->fde_encoding
= *q
++;
8385 /* Note - it is OK if this loop terminates with q < qend.
8386 Padding may have been inserted to align the end of the CIE. */
8391 *p_version
= version
;
8394 *p_aug_len
= augmentation_data_len
;
8395 *p_aug
= augmentation_data
;
8400 free (fc
->col_offset
);
8401 free (fc
->col_type
);
8406 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8407 If do_wide is not enabled, then formats the output to fit into 80 columns.
8408 PRINTED contains the number of characters already written to the current
8412 display_data (bfd_size_type printed
,
8413 const unsigned char * data
,
8414 const bfd_size_type len
)
8416 if (do_wide
|| len
< ((80 - printed
) / 3))
8417 for (printed
= 0; printed
< len
; ++printed
)
8418 printf (" %02x", data
[printed
]);
8421 for (printed
= 0; printed
< len
; ++printed
)
8423 if (printed
% (80 / 3) == 0)
8425 printf (" %02x", data
[printed
]);
8430 /* Prints out the contents on the augmentation data array.
8431 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8434 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8438 i
= printf (_(" Augmentation data: "));
8439 display_data (i
, data
, len
);
8443 display_debug_frames (struct dwarf_section
*section
,
8444 void *file ATTRIBUTE_UNUSED
)
8446 unsigned char *start
= section
->start
;
8447 unsigned char *end
= start
+ section
->size
;
8448 unsigned char *section_start
= start
;
8449 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8450 Frame_Chunk
*remembered_state
= NULL
;
8452 bfd_boolean is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8453 unsigned int max_regs
= 0;
8454 const char *bad_reg
= _("bad register: ");
8455 unsigned int saved_eh_addr_size
= eh_addr_size
;
8457 introduce (section
, FALSE
);
8461 unsigned char *saved_start
;
8462 unsigned char *block_end
;
8467 int need_col_headers
= 1;
8468 unsigned char *augmentation_data
= NULL
;
8469 bfd_size_type augmentation_data_len
= 0;
8470 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8471 unsigned int offset_size
;
8472 unsigned int initial_length_size
;
8473 bfd_boolean all_nops
;
8474 static Frame_Chunk fde_fc
;
8476 saved_start
= start
;
8478 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8482 printf ("\n%08lx ZERO terminator\n\n",
8483 (unsigned long)(saved_start
- section_start
));
8484 /* Skip any zero terminators that directly follow.
8485 A corrupt section size could have loaded a whole
8486 slew of zero filled memory bytes. eg
8487 PR 17512: file: 070-19381-0.004. */
8488 while (start
< end
&& * start
== 0)
8493 if (length
== 0xffffffff)
8495 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8497 initial_length_size
= 12;
8502 initial_length_size
= 4;
8505 block_end
= saved_start
+ length
+ initial_length_size
;
8506 if (block_end
> end
|| block_end
< start
)
8508 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8509 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8510 (unsigned long) (saved_start
- section_start
));
8514 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8516 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8517 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8522 start
= read_cie (start
, end
, &cie
, &version
,
8523 &augmentation_data_len
, &augmentation_data
);
8524 /* PR 17512: file: 027-135133-0.005. */
8531 fc
->chunk_start
= saved_start
;
8532 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8535 if (frame_need_space (fc
, mreg
) < 0)
8537 if (fc
->fde_encoding
)
8538 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8540 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8541 print_dwarf_vma (length
, fc
->ptr_size
);
8542 print_dwarf_vma (cie_id
, offset_size
);
8544 if (do_debug_frames_interp
)
8546 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8547 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8552 printf (" Version: %d\n", version
);
8553 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8556 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8557 printf (" Segment Size: %u\n", fc
->segment_size
);
8559 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8560 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8561 printf (" Return address column: %d\n", fc
->ra
);
8563 if (augmentation_data_len
)
8564 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8571 unsigned char *look_for
;
8572 unsigned long segment_selector
;
8576 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8577 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8580 look_for
= section_start
+ cie_id
;
8582 if (look_for
<= saved_start
)
8584 for (cie
= chunks
; cie
; cie
= cie
->next
)
8585 if (cie
->chunk_start
== look_for
)
8590 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8591 if (cie
->chunk_start
== look_for
)
8595 unsigned int off_size
;
8596 unsigned char *cie_scan
;
8598 cie_scan
= look_for
;
8600 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8601 if (length
== 0xffffffff)
8603 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8610 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8613 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8614 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8619 read_cie (cie_scan
, end
, &cie
, &version
,
8620 &augmentation_data_len
, &augmentation_data
);
8621 /* PR 17512: file: 3450-2098-0.004. */
8624 warn (_("Failed to read CIE information\n"));
8627 cie
->next
= forward_refs
;
8629 cie
->chunk_start
= look_for
;
8630 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8633 if (frame_need_space (cie
, mreg
) < 0)
8635 warn (_("Invalid max register\n"));
8638 if (cie
->fde_encoding
)
8640 = size_of_encoded_value (cie
->fde_encoding
);
8647 memset (fc
, 0, sizeof (Frame_Chunk
));
8651 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8652 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8653 (unsigned long) (saved_start
- section_start
));
8655 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8656 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8657 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8659 warn (_("Invalid max register\n"));
8663 fc
->augmentation
= "";
8664 fc
->fde_encoding
= 0;
8665 fc
->ptr_size
= eh_addr_size
;
8666 fc
->segment_size
= 0;
8670 fc
->ncols
= cie
->ncols
;
8671 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8672 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8673 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8674 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8675 fc
->augmentation
= cie
->augmentation
;
8676 fc
->ptr_size
= cie
->ptr_size
;
8677 eh_addr_size
= cie
->ptr_size
;
8678 fc
->segment_size
= cie
->segment_size
;
8679 fc
->code_factor
= cie
->code_factor
;
8680 fc
->data_factor
= cie
->data_factor
;
8681 fc
->cfa_reg
= cie
->cfa_reg
;
8682 fc
->cfa_offset
= cie
->cfa_offset
;
8684 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8686 warn (_("Invalid max register\n"));
8689 fc
->fde_encoding
= cie
->fde_encoding
;
8692 if (fc
->fde_encoding
)
8693 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8695 segment_selector
= 0;
8696 if (fc
->segment_size
)
8698 if (fc
->segment_size
> sizeof (segment_selector
))
8700 /* PR 17512: file: 9e196b3e. */
8701 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8702 fc
->segment_size
= 4;
8704 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8707 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8709 /* FIXME: It appears that sometimes the final pc_range value is
8710 encoded in less than encoded_ptr_size bytes. See the x86_64
8711 run of the "objcopy on compressed debug sections" test for an
8713 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8715 if (cie
->augmentation
[0] == 'z')
8717 READ_ULEB (augmentation_data_len
, start
, end
);
8718 augmentation_data
= start
;
8719 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8720 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8722 warn (_("Augmentation data too long: 0x%s, "
8723 "expected at most %#lx\n"),
8724 dwarf_vmatoa ("x", augmentation_data_len
),
8725 (unsigned long) (end
- start
));
8727 augmentation_data
= NULL
;
8728 augmentation_data_len
= 0;
8730 start
+= augmentation_data_len
;
8733 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8734 (unsigned long)(saved_start
- section_start
),
8735 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8736 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8737 (unsigned long)(cie
->chunk_start
- section_start
));
8739 if (fc
->segment_size
)
8740 printf ("%04lx:", segment_selector
);
8743 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8744 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8746 if (! do_debug_frames_interp
&& augmentation_data_len
)
8748 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8753 /* At this point, fc is the current chunk, cie (if any) is set, and
8754 we're about to interpret instructions for the chunk. */
8755 /* ??? At present we need to do this always, since this sizes the
8756 fc->col_type and fc->col_offset arrays, which we write into always.
8757 We should probably split the interpreted and non-interpreted bits
8758 into two different routines, since there's so much that doesn't
8759 really overlap between them. */
8760 if (1 || do_debug_frames_interp
)
8762 /* Start by making a pass over the chunk, allocating storage
8763 and taking note of what registers are used. */
8764 unsigned char *tmp
= start
;
8766 while (start
< block_end
)
8768 unsigned int reg
, op
, opa
;
8770 unsigned char * new_start
;
8777 /* Warning: if you add any more cases to this switch, be
8778 sure to add them to the corresponding switch below. */
8781 case DW_CFA_advance_loc
:
8784 SKIP_ULEB (start
, end
);
8785 if (frame_need_space (fc
, opa
) >= 0)
8786 fc
->col_type
[opa
] = DW_CFA_undefined
;
8788 case DW_CFA_restore
:
8789 if (frame_need_space (fc
, opa
) >= 0)
8790 fc
->col_type
[opa
] = DW_CFA_undefined
;
8792 case DW_CFA_set_loc
:
8793 start
+= encoded_ptr_size
;
8795 case DW_CFA_advance_loc1
:
8798 case DW_CFA_advance_loc2
:
8801 case DW_CFA_advance_loc4
:
8804 case DW_CFA_offset_extended
:
8805 case DW_CFA_val_offset
:
8806 READ_ULEB (reg
, start
, end
);
8807 SKIP_ULEB (start
, end
);
8808 if (frame_need_space (fc
, reg
) >= 0)
8809 fc
->col_type
[reg
] = DW_CFA_undefined
;
8811 case DW_CFA_restore_extended
:
8812 READ_ULEB (reg
, start
, end
);
8813 if (frame_need_space (fc
, reg
) >= 0)
8814 fc
->col_type
[reg
] = DW_CFA_undefined
;
8816 case DW_CFA_undefined
:
8817 READ_ULEB (reg
, start
, end
);
8818 if (frame_need_space (fc
, reg
) >= 0)
8819 fc
->col_type
[reg
] = DW_CFA_undefined
;
8821 case DW_CFA_same_value
:
8822 READ_ULEB (reg
, start
, end
);
8823 if (frame_need_space (fc
, reg
) >= 0)
8824 fc
->col_type
[reg
] = DW_CFA_undefined
;
8826 case DW_CFA_register
:
8827 READ_ULEB (reg
, start
, end
);
8828 SKIP_ULEB (start
, end
);
8829 if (frame_need_space (fc
, reg
) >= 0)
8830 fc
->col_type
[reg
] = DW_CFA_undefined
;
8832 case DW_CFA_def_cfa
:
8833 SKIP_ULEB (start
, end
);
8834 SKIP_ULEB (start
, end
);
8836 case DW_CFA_def_cfa_register
:
8837 SKIP_ULEB (start
, end
);
8839 case DW_CFA_def_cfa_offset
:
8840 SKIP_ULEB (start
, end
);
8842 case DW_CFA_def_cfa_expression
:
8843 READ_ULEB (temp
, start
, end
);
8844 new_start
= start
+ temp
;
8845 if (new_start
< start
)
8847 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8853 case DW_CFA_expression
:
8854 case DW_CFA_val_expression
:
8855 READ_ULEB (reg
, start
, end
);
8856 READ_ULEB (temp
, start
, end
);
8857 new_start
= start
+ temp
;
8858 if (new_start
< start
)
8860 /* PR 17512: file:306-192417-0.005. */
8861 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8866 if (frame_need_space (fc
, reg
) >= 0)
8867 fc
->col_type
[reg
] = DW_CFA_undefined
;
8869 case DW_CFA_offset_extended_sf
:
8870 case DW_CFA_val_offset_sf
:
8871 READ_ULEB (reg
, start
, end
);
8872 SKIP_SLEB (start
, end
);
8873 if (frame_need_space (fc
, reg
) >= 0)
8874 fc
->col_type
[reg
] = DW_CFA_undefined
;
8876 case DW_CFA_def_cfa_sf
:
8877 SKIP_ULEB (start
, end
);
8878 SKIP_SLEB (start
, end
);
8880 case DW_CFA_def_cfa_offset_sf
:
8881 SKIP_SLEB (start
, end
);
8883 case DW_CFA_MIPS_advance_loc8
:
8886 case DW_CFA_GNU_args_size
:
8887 SKIP_ULEB (start
, end
);
8889 case DW_CFA_GNU_negative_offset_extended
:
8890 READ_ULEB (reg
, start
, end
);
8891 SKIP_ULEB (start
, end
);
8892 if (frame_need_space (fc
, reg
) >= 0)
8893 fc
->col_type
[reg
] = DW_CFA_undefined
;
8904 /* Now we know what registers are used, make a second pass over
8905 the chunk, this time actually printing out the info. */
8907 while (start
< block_end
)
8909 unsigned char * tmp
;
8911 unsigned long ul
, roffs
;
8912 /* Note: It is tempting to use an unsigned long for 'reg' but there
8913 are various functions, notably frame_space_needed() that assume that
8914 reg is an unsigned int. */
8919 const char *reg_prefix
= "";
8926 /* Make a note if something other than DW_CFA_nop happens. */
8927 if (op
!= DW_CFA_nop
)
8930 /* Warning: if you add any more cases to this switch, be
8931 sure to add them to the corresponding switch above. */
8934 case DW_CFA_advance_loc
:
8935 if (do_debug_frames_interp
)
8936 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8938 printf (" DW_CFA_advance_loc: %d to %s\n",
8939 opa
* fc
->code_factor
,
8940 dwarf_vmatoa_1 (NULL
,
8941 fc
->pc_begin
+ opa
* fc
->code_factor
,
8943 fc
->pc_begin
+= opa
* fc
->code_factor
;
8947 READ_ULEB (roffs
, start
, end
);
8948 if (opa
>= (unsigned int) fc
->ncols
)
8949 reg_prefix
= bad_reg
;
8950 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8951 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
8952 reg_prefix
, regname (opa
, 0),
8953 roffs
* fc
->data_factor
);
8954 if (*reg_prefix
== '\0')
8956 fc
->col_type
[opa
] = DW_CFA_offset
;
8957 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8961 case DW_CFA_restore
:
8962 if (opa
>= (unsigned int) fc
->ncols
)
8963 reg_prefix
= bad_reg
;
8964 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8965 printf (" DW_CFA_restore: %s%s\n",
8966 reg_prefix
, regname (opa
, 0));
8967 if (*reg_prefix
!= '\0')
8970 if (opa
>= (unsigned int) cie
->ncols
8971 || (do_debug_frames_interp
8972 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
8974 fc
->col_type
[opa
] = DW_CFA_undefined
;
8975 fc
->col_offset
[opa
] = 0;
8979 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8980 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8984 case DW_CFA_set_loc
:
8985 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
8986 if (do_debug_frames_interp
)
8987 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8989 printf (" DW_CFA_set_loc: %s\n",
8990 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
8994 case DW_CFA_advance_loc1
:
8995 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
8996 if (do_debug_frames_interp
)
8997 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8999 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9000 (unsigned long) (ofs
* fc
->code_factor
),
9001 dwarf_vmatoa_1 (NULL
,
9002 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9004 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9007 case DW_CFA_advance_loc2
:
9008 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9009 if (do_debug_frames_interp
)
9010 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9012 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9013 (unsigned long) (ofs
* fc
->code_factor
),
9014 dwarf_vmatoa_1 (NULL
,
9015 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9017 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9020 case DW_CFA_advance_loc4
:
9021 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9022 if (do_debug_frames_interp
)
9023 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9025 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9026 (unsigned long) (ofs
* fc
->code_factor
),
9027 dwarf_vmatoa_1 (NULL
,
9028 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9030 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9033 case DW_CFA_offset_extended
:
9034 READ_ULEB (reg
, start
, end
);
9035 READ_ULEB (roffs
, start
, end
);
9036 if (reg
>= (unsigned int) fc
->ncols
)
9037 reg_prefix
= bad_reg
;
9038 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9039 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9040 reg_prefix
, regname (reg
, 0),
9041 roffs
* fc
->data_factor
);
9042 if (*reg_prefix
== '\0')
9044 fc
->col_type
[reg
] = DW_CFA_offset
;
9045 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9049 case DW_CFA_val_offset
:
9050 READ_ULEB (reg
, start
, end
);
9051 READ_ULEB (roffs
, start
, end
);
9052 if (reg
>= (unsigned int) fc
->ncols
)
9053 reg_prefix
= bad_reg
;
9054 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9055 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9056 reg_prefix
, regname (reg
, 0),
9057 roffs
* fc
->data_factor
);
9058 if (*reg_prefix
== '\0')
9060 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9061 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9065 case DW_CFA_restore_extended
:
9066 READ_ULEB (reg
, start
, end
);
9067 if (reg
>= (unsigned int) fc
->ncols
)
9068 reg_prefix
= bad_reg
;
9069 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9070 printf (" DW_CFA_restore_extended: %s%s\n",
9071 reg_prefix
, regname (reg
, 0));
9072 if (*reg_prefix
!= '\0')
9075 if (reg
>= (unsigned int) cie
->ncols
)
9077 fc
->col_type
[reg
] = DW_CFA_undefined
;
9078 fc
->col_offset
[reg
] = 0;
9082 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9083 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9087 case DW_CFA_undefined
:
9088 READ_ULEB (reg
, start
, end
);
9089 if (reg
>= (unsigned int) fc
->ncols
)
9090 reg_prefix
= bad_reg
;
9091 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9092 printf (" DW_CFA_undefined: %s%s\n",
9093 reg_prefix
, regname (reg
, 0));
9094 if (*reg_prefix
== '\0')
9096 fc
->col_type
[reg
] = DW_CFA_undefined
;
9097 fc
->col_offset
[reg
] = 0;
9101 case DW_CFA_same_value
:
9102 READ_ULEB (reg
, start
, end
);
9103 if (reg
>= (unsigned int) fc
->ncols
)
9104 reg_prefix
= bad_reg
;
9105 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9106 printf (" DW_CFA_same_value: %s%s\n",
9107 reg_prefix
, regname (reg
, 0));
9108 if (*reg_prefix
== '\0')
9110 fc
->col_type
[reg
] = DW_CFA_same_value
;
9111 fc
->col_offset
[reg
] = 0;
9115 case DW_CFA_register
:
9116 READ_ULEB (reg
, start
, end
);
9117 READ_ULEB (roffs
, start
, end
);
9118 if (reg
>= (unsigned int) fc
->ncols
)
9119 reg_prefix
= bad_reg
;
9120 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9122 printf (" DW_CFA_register: %s%s in ",
9123 reg_prefix
, regname (reg
, 0));
9124 puts (regname (roffs
, 0));
9126 if (*reg_prefix
== '\0')
9128 fc
->col_type
[reg
] = DW_CFA_register
;
9129 fc
->col_offset
[reg
] = roffs
;
9133 case DW_CFA_remember_state
:
9134 if (! do_debug_frames_interp
)
9135 printf (" DW_CFA_remember_state\n");
9136 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9137 rs
->cfa_offset
= fc
->cfa_offset
;
9138 rs
->cfa_reg
= fc
->cfa_reg
;
9140 rs
->cfa_exp
= fc
->cfa_exp
;
9141 rs
->ncols
= fc
->ncols
;
9142 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9143 sizeof (* rs
->col_type
));
9144 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9145 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9146 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9147 rs
->next
= remembered_state
;
9148 remembered_state
= rs
;
9151 case DW_CFA_restore_state
:
9152 if (! do_debug_frames_interp
)
9153 printf (" DW_CFA_restore_state\n");
9154 rs
= remembered_state
;
9157 remembered_state
= rs
->next
;
9158 fc
->cfa_offset
= rs
->cfa_offset
;
9159 fc
->cfa_reg
= rs
->cfa_reg
;
9161 fc
->cfa_exp
= rs
->cfa_exp
;
9162 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9164 warn (_("Invalid column number in saved frame state\n"));
9168 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9169 memcpy (fc
->col_offset
, rs
->col_offset
,
9170 rs
->ncols
* sizeof (* rs
->col_offset
));
9171 free (rs
->col_type
);
9172 free (rs
->col_offset
);
9175 else if (do_debug_frames_interp
)
9176 printf ("Mismatched DW_CFA_restore_state\n");
9179 case DW_CFA_def_cfa
:
9180 READ_ULEB (fc
->cfa_reg
, start
, end
);
9181 READ_ULEB (fc
->cfa_offset
, start
, end
);
9183 if (! do_debug_frames_interp
)
9184 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9185 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9188 case DW_CFA_def_cfa_register
:
9189 READ_ULEB (fc
->cfa_reg
, start
, end
);
9191 if (! do_debug_frames_interp
)
9192 printf (" DW_CFA_def_cfa_register: %s\n",
9193 regname (fc
->cfa_reg
, 0));
9196 case DW_CFA_def_cfa_offset
:
9197 READ_ULEB (fc
->cfa_offset
, start
, end
);
9198 if (! do_debug_frames_interp
)
9199 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9203 if (! do_debug_frames_interp
)
9204 printf (" DW_CFA_nop\n");
9207 case DW_CFA_def_cfa_expression
:
9208 READ_ULEB (ul
, start
, end
);
9209 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
9211 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9214 if (! do_debug_frames_interp
)
9216 printf (" DW_CFA_def_cfa_expression (");
9217 decode_location_expression (start
, eh_addr_size
, 0, -1,
9225 case DW_CFA_expression
:
9226 READ_ULEB (reg
, start
, end
);
9227 READ_ULEB (ul
, start
, end
);
9228 if (reg
>= (unsigned int) fc
->ncols
)
9229 reg_prefix
= bad_reg
;
9230 /* PR 17512: file: 069-133014-0.006. */
9231 /* PR 17512: file: 98c02eb4. */
9233 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9235 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9238 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9240 printf (" DW_CFA_expression: %s%s (",
9241 reg_prefix
, regname (reg
, 0));
9242 decode_location_expression (start
, eh_addr_size
, 0, -1,
9246 if (*reg_prefix
== '\0')
9247 fc
->col_type
[reg
] = DW_CFA_expression
;
9251 case DW_CFA_val_expression
:
9252 READ_ULEB (reg
, start
, end
);
9253 READ_ULEB (ul
, start
, end
);
9254 if (reg
>= (unsigned int) fc
->ncols
)
9255 reg_prefix
= bad_reg
;
9257 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9259 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9262 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9264 printf (" DW_CFA_val_expression: %s%s (",
9265 reg_prefix
, regname (reg
, 0));
9266 decode_location_expression (start
, eh_addr_size
, 0, -1,
9270 if (*reg_prefix
== '\0')
9271 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9275 case DW_CFA_offset_extended_sf
:
9276 READ_ULEB (reg
, start
, end
);
9277 READ_SLEB (l
, start
, end
);
9278 if (frame_need_space (fc
, reg
) < 0)
9279 reg_prefix
= bad_reg
;
9280 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9281 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9282 reg_prefix
, regname (reg
, 0),
9283 (long)(l
* fc
->data_factor
));
9284 if (*reg_prefix
== '\0')
9286 fc
->col_type
[reg
] = DW_CFA_offset
;
9287 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9291 case DW_CFA_val_offset_sf
:
9292 READ_ULEB (reg
, start
, end
);
9293 READ_SLEB (l
, start
, end
);
9294 if (frame_need_space (fc
, reg
) < 0)
9295 reg_prefix
= bad_reg
;
9296 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9297 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9298 reg_prefix
, regname (reg
, 0),
9299 (long)(l
* fc
->data_factor
));
9300 if (*reg_prefix
== '\0')
9302 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9303 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9307 case DW_CFA_def_cfa_sf
:
9308 READ_ULEB (fc
->cfa_reg
, start
, end
);
9309 READ_ULEB (fc
->cfa_offset
, start
, end
);
9310 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9312 if (! do_debug_frames_interp
)
9313 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9314 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9317 case DW_CFA_def_cfa_offset_sf
:
9318 READ_ULEB (fc
->cfa_offset
, start
, end
);
9319 fc
->cfa_offset
*= fc
->data_factor
;
9320 if (! do_debug_frames_interp
)
9321 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9324 case DW_CFA_MIPS_advance_loc8
:
9325 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9326 if (do_debug_frames_interp
)
9327 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9329 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9330 (unsigned long) (ofs
* fc
->code_factor
),
9331 dwarf_vmatoa_1 (NULL
,
9332 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9334 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9337 case DW_CFA_GNU_window_save
:
9338 if (! do_debug_frames_interp
)
9339 printf (" DW_CFA_GNU_window_save\n");
9342 case DW_CFA_GNU_args_size
:
9343 READ_ULEB (ul
, start
, end
);
9344 if (! do_debug_frames_interp
)
9345 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9348 case DW_CFA_GNU_negative_offset_extended
:
9349 READ_ULEB (reg
, start
, end
);
9350 READ_SLEB (l
, start
, end
);
9352 if (frame_need_space (fc
, reg
) < 0)
9353 reg_prefix
= bad_reg
;
9354 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9355 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9356 reg_prefix
, regname (reg
, 0),
9357 (long)(l
* fc
->data_factor
));
9358 if (*reg_prefix
== '\0')
9360 fc
->col_type
[reg
] = DW_CFA_offset
;
9361 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9366 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9367 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9369 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9374 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9375 if (do_debug_frames_interp
&& ! all_nops
)
9376 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9378 if (fde_fc
.col_type
!= NULL
)
9380 free (fde_fc
.col_type
);
9381 fde_fc
.col_type
= NULL
;
9383 if (fde_fc
.col_offset
!= NULL
)
9385 free (fde_fc
.col_offset
);
9386 fde_fc
.col_offset
= NULL
;
9390 eh_addr_size
= saved_eh_addr_size
;
9395 while (remembered_state
!= NULL
)
9397 rs
= remembered_state
;
9398 remembered_state
= rs
->next
;
9399 free (rs
->col_type
);
9400 free (rs
->col_offset
);
9401 rs
->next
= NULL
; /* Paranoia. */
9405 while (chunks
!= NULL
)
9409 free (rs
->col_type
);
9410 free (rs
->col_offset
);
9411 rs
->next
= NULL
; /* Paranoia. */
9415 while (forward_refs
!= NULL
)
9418 forward_refs
= rs
->next
;
9419 free (rs
->col_type
);
9420 free (rs
->col_offset
);
9421 rs
->next
= NULL
; /* Paranoia. */
9431 display_debug_names (struct dwarf_section
*section
, void *file
)
9433 unsigned char *hdrptr
= section
->start
;
9434 dwarf_vma unit_length
;
9435 unsigned char *unit_start
;
9436 const unsigned char *const section_end
= section
->start
+ section
->size
;
9437 unsigned char *unit_end
;
9439 introduce (section
, FALSE
);
9441 load_debug_section_with_follow (str
, file
);
9443 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9445 unsigned int offset_size
;
9446 uint16_t dwarf_version
, padding
;
9447 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9448 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9449 uint32_t augmentation_string_size
;
9451 unsigned long sec_off
;
9452 bfd_boolean augmentation_printable
;
9453 const char *augmentation_string
;
9455 unit_start
= hdrptr
;
9457 /* Get and check the length of the block. */
9458 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9460 if (unit_length
== 0xffffffff)
9462 /* This section is 64-bit DWARF. */
9463 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9468 unit_end
= hdrptr
+ unit_length
;
9470 sec_off
= hdrptr
- section
->start
;
9471 if (sec_off
+ unit_length
< sec_off
9472 || sec_off
+ unit_length
> section
->size
)
9474 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9476 (unsigned long) (unit_start
- section
->start
),
9477 dwarf_vmatoa ("x", unit_length
));
9481 /* Get and check the version number. */
9482 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9483 printf (_("Version %ld\n"), (long) dwarf_version
);
9485 /* Prior versions did not exist, and future versions may not be
9486 backwards compatible. */
9487 if (dwarf_version
!= 5)
9489 warn (_("Only DWARF version 5 .debug_names "
9490 "is currently supported.\n"));
9494 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9496 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9499 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9500 if (comp_unit_count
== 0)
9501 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9503 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9504 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9505 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9506 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9507 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9509 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9510 if (augmentation_string_size
% 4 != 0)
9512 warn (_("Augmentation string length %u must be rounded up "
9513 "to a multiple of 4 in .debug_names.\n"),
9514 augmentation_string_size
);
9515 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9518 printf (_("Augmentation string:"));
9520 augmentation_printable
= TRUE
;
9521 augmentation_string
= (const char *) hdrptr
;
9523 for (i
= 0; i
< augmentation_string_size
; i
++)
9527 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9528 printf (" %02x", uc
);
9530 if (uc
!= 0 && !ISPRINT (uc
))
9531 augmentation_printable
= FALSE
;
9534 if (augmentation_printable
)
9538 i
< augmentation_string_size
&& augmentation_string
[i
];
9540 putchar (augmentation_string
[i
]);
9545 printf (_("CU table:\n"));
9546 for (i
= 0; i
< comp_unit_count
; i
++)
9550 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9551 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9555 printf (_("TU table:\n"));
9556 for (i
= 0; i
< local_type_unit_count
; i
++)
9560 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9561 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9565 printf (_("Foreign TU table:\n"));
9566 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9570 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9571 printf (_("[%3u] "), i
);
9572 print_dwarf_vma (signature
, 8);
9577 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9578 hdrptr
+= bucket_count
* sizeof (uint32_t);
9579 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9580 hdrptr
+= name_count
* sizeof (uint32_t);
9581 unsigned char *const name_table_string_offsets
= hdrptr
;
9582 hdrptr
+= name_count
* offset_size
;
9583 unsigned char *const name_table_entry_offsets
= hdrptr
;
9584 hdrptr
+= name_count
* offset_size
;
9585 unsigned char *const abbrev_table
= hdrptr
;
9586 hdrptr
+= abbrev_table_size
;
9587 const unsigned char *const abbrev_table_end
= hdrptr
;
9588 unsigned char *const entry_pool
= hdrptr
;
9589 if (hdrptr
> unit_end
)
9591 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9592 "for unit 0x%lx in the debug_names\n"),
9593 (long) (hdrptr
- section
->start
),
9594 (long) (unit_end
- section
->start
),
9595 (long) (unit_start
- section
->start
));
9599 size_t buckets_filled
= 0;
9601 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9603 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9608 printf (ngettext ("Used %zu of %lu bucket.\n",
9609 "Used %zu of %lu buckets.\n",
9611 buckets_filled
, (unsigned long) bucket_count
);
9613 uint32_t hash_prev
= 0;
9614 size_t hash_clash_count
= 0;
9615 size_t longest_clash
= 0;
9616 size_t this_length
= 0;
9618 for (hashi
= 0; hashi
< name_count
; hashi
++)
9620 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9624 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9628 longest_clash
= MAX (longest_clash
, this_length
);
9633 hash_prev
= hash_this
;
9635 printf (_("Out of %lu items there are %zu bucket clashes"
9636 " (longest of %zu entries).\n"),
9637 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9638 assert (name_count
== buckets_filled
+ hash_clash_count
);
9640 struct abbrev_lookup_entry
9642 dwarf_vma abbrev_tag
;
9643 unsigned char *abbrev_lookup_ptr
;
9645 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9646 size_t abbrev_lookup_used
= 0;
9647 size_t abbrev_lookup_allocated
= 0;
9649 unsigned char *abbrevptr
= abbrev_table
;
9652 dwarf_vma abbrev_tag
;
9654 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9655 if (abbrev_tag
== 0)
9657 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9659 abbrev_lookup_allocated
= MAX (0x100,
9660 abbrev_lookup_allocated
* 2);
9661 abbrev_lookup
= xrealloc (abbrev_lookup
,
9662 (abbrev_lookup_allocated
9663 * sizeof (*abbrev_lookup
)));
9665 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9666 struct abbrev_lookup_entry
*entry
;
9667 for (entry
= abbrev_lookup
;
9668 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9670 if (entry
->abbrev_tag
== abbrev_tag
)
9672 warn (_("Duplicate abbreviation tag %lu "
9673 "in unit 0x%lx in the debug_names\n"),
9674 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9677 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9678 entry
->abbrev_tag
= abbrev_tag
;
9679 entry
->abbrev_lookup_ptr
= abbrevptr
;
9681 /* Skip DWARF tag. */
9682 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9685 dwarf_vma xindex
, form
;
9687 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9688 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9689 if (xindex
== 0 && form
== 0)
9694 printf (_("\nSymbol table:\n"));
9696 for (namei
= 0; namei
< name_count
; ++namei
)
9698 uint64_t string_offset
, entry_offset
;
9700 SAFE_BYTE_GET (string_offset
,
9701 name_table_string_offsets
+ namei
* offset_size
,
9702 offset_size
, unit_end
);
9703 SAFE_BYTE_GET (entry_offset
,
9704 name_table_entry_offsets
+ namei
* offset_size
,
9705 offset_size
, unit_end
);
9707 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9708 fetch_indirect_string (string_offset
));
9710 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9712 /* We need to scan first whether there is a single or multiple
9713 entries. TAGNO is -2 for the first entry, it is -1 for the
9714 initial tag read of the second entry, then it becomes 0 for the
9715 first entry for real printing etc. */
9717 /* Initialize it due to a false compiler warning. */
9718 dwarf_vma second_abbrev_tag
= -1;
9721 dwarf_vma abbrev_tag
;
9722 dwarf_vma dwarf_tag
;
9723 const struct abbrev_lookup_entry
*entry
;
9725 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9728 second_abbrev_tag
= abbrev_tag
;
9730 entryptr
= entry_pool
+ entry_offset
;
9733 if (abbrev_tag
== 0)
9737 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9738 (unsigned long) abbrev_tag
);
9740 for (entry
= abbrev_lookup
;
9741 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9743 if (entry
->abbrev_tag
== abbrev_tag
)
9745 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9747 warn (_("Undefined abbreviation tag %lu "
9748 "in unit 0x%lx in the debug_names\n"),
9750 (long) (unit_start
- section
->start
));
9753 abbrevptr
= entry
->abbrev_lookup_ptr
;
9754 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9756 printf (" %s", get_TAG_name (dwarf_tag
));
9759 dwarf_vma xindex
, form
;
9761 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9762 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9763 if (xindex
== 0 && form
== 0)
9767 printf (" %s", get_IDX_name (xindex
));
9768 entryptr
= read_and_display_attr_value (0, form
, 0,
9769 unit_start
, entryptr
, unit_end
,
9771 dwarf_version
, NULL
,
9778 printf (_(" <no entries>"));
9782 free (abbrev_lookup
);
9789 display_debug_links (struct dwarf_section
* section
,
9790 void * file ATTRIBUTE_UNUSED
)
9792 const unsigned char * filename
;
9793 unsigned int filelen
;
9795 introduce (section
, FALSE
);
9797 /* The .gnu_debuglink section is formatted as:
9798 (c-string) Filename.
9799 (padding) If needed to reach a 4 byte boundary.
9800 (uint32_t) CRC32 value.
9802 The .gun_debugaltlink section is formatted as:
9803 (c-string) Filename.
9804 (binary) Build-ID. */
9806 filename
= section
->start
;
9807 filelen
= strnlen ((const char *) filename
, section
->size
);
9808 if (filelen
== section
->size
)
9810 warn (_("The debuglink filename is corrupt/missing\n"));
9814 printf (_(" Separate debug info file: %s\n"), filename
);
9816 if (const_strneq (section
->name
, ".gnu_debuglink"))
9819 unsigned int crc_offset
;
9821 crc_offset
= filelen
+ 1;
9822 crc_offset
= (crc_offset
+ 3) & ~3;
9823 if (crc_offset
+ 4 > section
->size
)
9825 warn (_("CRC offset missing/truncated\n"));
9829 crc32
= byte_get (filename
+ crc_offset
, 4);
9831 printf (_(" CRC value: %#x\n"), crc32
);
9833 if (crc_offset
+ 4 < section
->size
)
9835 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9836 (long)(section
->size
- (crc_offset
+ 4)));
9840 else /* const_strneq (section->name, ".gnu_debugaltlink") */
9842 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9843 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9844 bfd_size_type printed
;
9846 /* FIXME: Should we support smaller build-id notes ? */
9847 if (build_id_len
< 0x14)
9849 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9853 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9854 display_data (printed
, build_id
, build_id_len
);
9863 display_gdb_index (struct dwarf_section
*section
,
9864 void *file ATTRIBUTE_UNUSED
)
9866 unsigned char *start
= section
->start
;
9868 uint32_t cu_list_offset
, tu_list_offset
;
9869 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
9870 unsigned int cu_list_elements
, tu_list_elements
;
9871 unsigned int address_table_size
, symbol_table_slots
;
9872 unsigned char *cu_list
, *tu_list
;
9873 unsigned char *address_table
, *symbol_table
, *constant_pool
;
9876 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
9878 introduce (section
, FALSE
);
9880 if (section
->size
< 6 * sizeof (uint32_t))
9882 warn (_("Truncated header in the %s section.\n"), section
->name
);
9886 version
= byte_get_little_endian (start
, 4);
9887 printf (_("Version %ld\n"), (long) version
);
9889 /* Prior versions are obsolete, and future versions may not be
9890 backwards compatible. */
9891 if (version
< 3 || version
> 8)
9893 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
9897 warn (_("The address table data in version 3 may be wrong.\n"));
9899 warn (_("Version 4 does not support case insensitive lookups.\n"));
9901 warn (_("Version 5 does not include inlined functions.\n"));
9903 warn (_("Version 6 does not include symbol attributes.\n"));
9904 /* Version 7 indices generated by Gold have bad type unit references,
9905 PR binutils/15021. But we don't know if the index was generated by
9906 Gold or not, so to avoid worrying users with gdb-generated indices
9907 we say nothing for version 7 here. */
9909 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
9910 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
9911 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
9912 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
9913 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
9915 if (cu_list_offset
> section
->size
9916 || tu_list_offset
> section
->size
9917 || address_table_offset
> section
->size
9918 || symbol_table_offset
> section
->size
9919 || constant_pool_offset
> section
->size
)
9921 warn (_("Corrupt header in the %s section.\n"), section
->name
);
9925 /* PR 17531: file: 418d0a8a. */
9926 if (tu_list_offset
< cu_list_offset
)
9928 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
9929 tu_list_offset
, cu_list_offset
);
9933 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
9935 if (address_table_offset
< tu_list_offset
)
9937 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
9938 address_table_offset
, tu_list_offset
);
9942 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
9944 /* PR 17531: file: 18a47d3d. */
9945 if (symbol_table_offset
< address_table_offset
)
9947 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
9948 symbol_table_offset
, address_table_offset
);
9952 address_table_size
= symbol_table_offset
- address_table_offset
;
9954 if (constant_pool_offset
< symbol_table_offset
)
9956 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
9957 constant_pool_offset
, symbol_table_offset
);
9961 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
9963 cu_list
= start
+ cu_list_offset
;
9964 tu_list
= start
+ tu_list_offset
;
9965 address_table
= start
+ address_table_offset
;
9966 symbol_table
= start
+ symbol_table_offset
;
9967 constant_pool
= start
+ constant_pool_offset
;
9969 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
9971 warn (_("Address table extends beyond end of section.\n"));
9975 printf (_("\nCU table:\n"));
9976 for (i
= 0; i
< cu_list_elements
; i
+= 2)
9978 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
9979 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
9981 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
9982 (unsigned long) cu_offset
,
9983 (unsigned long) (cu_offset
+ cu_length
- 1));
9986 printf (_("\nTU table:\n"));
9987 for (i
= 0; i
< tu_list_elements
; i
+= 3)
9989 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
9990 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
9991 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
9993 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
9994 (unsigned long) tu_offset
,
9995 (unsigned long) type_offset
);
9996 print_dwarf_vma (signature
, 8);
10000 printf (_("\nAddress table:\n"));
10001 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10004 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10005 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10006 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10008 print_dwarf_vma (low
, 8);
10009 print_dwarf_vma (high
, 8);
10010 printf (_("%lu\n"), (unsigned long) cu_index
);
10013 printf (_("\nSymbol table:\n"));
10014 for (i
= 0; i
< symbol_table_slots
; ++i
)
10016 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10017 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10018 uint32_t num_cus
, cu
;
10020 if (name_offset
!= 0
10021 || cu_vector_offset
!= 0)
10024 unsigned char * adr
;
10026 adr
= constant_pool
+ name_offset
;
10027 /* PR 17531: file: 5b7b07ad. */
10028 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
10030 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10031 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10035 printf ("[%3u] %.*s:", i
,
10036 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10037 constant_pool
+ name_offset
);
10039 adr
= constant_pool
+ cu_vector_offset
;
10040 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
10042 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10043 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10044 cu_vector_offset
, i
);
10048 num_cus
= byte_get_little_endian (adr
, 4);
10050 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
10051 if (num_cus
* 4 < num_cus
10052 || adr
>= section
->start
+ section
->size
10053 || adr
< constant_pool
)
10055 printf ("<invalid number of CUs: %d>\n", num_cus
);
10056 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10064 for (j
= 0; j
< num_cus
; ++j
)
10067 gdb_index_symbol_kind kind
;
10069 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10070 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10071 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10072 cu
= GDB_INDEX_CU_VALUE (cu
);
10073 /* Convert to TU number if it's for a type unit. */
10074 if (cu
>= cu_list_elements
/ 2)
10075 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10076 (unsigned long) (cu
- cu_list_elements
/ 2));
10078 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10080 printf (" [%s, %s]",
10081 is_static
? _("static") : _("global"),
10082 get_gdb_index_symbol_kind_name (kind
));
10094 /* Pre-allocate enough space for the CU/TU sets needed. */
10097 prealloc_cu_tu_list (unsigned int nshndx
)
10099 if (shndx_pool
== NULL
)
10101 shndx_pool_size
= nshndx
;
10102 shndx_pool_used
= 0;
10103 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10104 sizeof (unsigned int));
10108 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10109 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10110 sizeof (unsigned int));
10115 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10117 if (shndx_pool_used
>= shndx_pool_size
)
10119 error (_("Internal error: out of space in the shndx pool.\n"));
10122 shndx_pool
[shndx_pool_used
++] = shndx
;
10126 end_cu_tu_entry (void)
10128 if (shndx_pool_used
>= shndx_pool_size
)
10130 error (_("Internal error: out of space in the shndx pool.\n"));
10133 shndx_pool
[shndx_pool_used
++] = 0;
10136 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10138 static const char *
10139 get_DW_SECT_short_name (unsigned int dw_sect
)
10141 static char buf
[16];
10147 case DW_SECT_TYPES
:
10149 case DW_SECT_ABBREV
:
10155 case DW_SECT_STR_OFFSETS
:
10157 case DW_SECT_MACINFO
:
10159 case DW_SECT_MACRO
:
10165 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10169 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10170 These sections are extensions for Fission.
10171 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10174 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10176 unsigned char *phdr
= section
->start
;
10177 unsigned char *limit
= phdr
+ section
->size
;
10178 unsigned char *phash
;
10179 unsigned char *pindex
;
10180 unsigned char *ppool
;
10181 unsigned int version
;
10182 unsigned int ncols
= 0;
10183 unsigned int nused
;
10184 unsigned int nslots
;
10187 dwarf_vma signature_high
;
10188 dwarf_vma signature_low
;
10191 /* PR 17512: file: 002-168123-0.004. */
10194 warn (_("Section %s is empty\n"), section
->name
);
10197 /* PR 17512: file: 002-376-0.004. */
10198 if (section
->size
< 24)
10200 warn (_("Section %s is too small to contain a CU/TU header\n"),
10205 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
10207 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
10208 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
10209 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
10212 pindex
= phash
+ (size_t) nslots
* 8;
10213 ppool
= pindex
+ (size_t) nslots
* 4;
10217 introduce (section
, FALSE
);
10219 printf (_(" Version: %u\n"), version
);
10221 printf (_(" Number of columns: %u\n"), ncols
);
10222 printf (_(" Number of used entries: %u\n"), nused
);
10223 printf (_(" Number of slots: %u\n\n"), nslots
);
10226 /* PR 17531: file: 45d69832. */
10227 if ((size_t) nslots
* 8 / 8 != nslots
10228 || phash
< phdr
|| phash
> limit
10229 || pindex
< phash
|| pindex
> limit
10230 || ppool
< pindex
|| ppool
> limit
)
10232 warn (ngettext ("Section %s is too small for %u slot\n",
10233 "Section %s is too small for %u slots\n",
10235 section
->name
, nslots
);
10242 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10243 for (i
= 0; i
< nslots
; i
++)
10245 unsigned char *shndx_list
;
10246 unsigned int shndx
;
10248 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
10249 if (signature_high
!= 0 || signature_low
!= 0)
10251 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10252 shndx_list
= ppool
+ j
* 4;
10253 /* PR 17531: file: 705e010d. */
10254 if (shndx_list
< ppool
)
10256 warn (_("Section index pool located before start of section\n"));
10261 printf (_(" [%3d] Signature: 0x%s Sections: "),
10262 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10263 buf
, sizeof (buf
)));
10266 if (shndx_list
>= limit
)
10268 warn (_("Section %s too small for shndx pool\n"),
10272 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10276 printf (" %d", shndx
);
10278 add_shndx_to_cu_tu_entry (shndx
);
10284 end_cu_tu_entry ();
10290 else if (version
== 2)
10293 unsigned int dw_sect
;
10294 unsigned char *ph
= phash
;
10295 unsigned char *pi
= pindex
;
10296 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10297 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10298 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10299 bfd_boolean is_tu_index
;
10300 struct cu_tu_set
*this_set
= NULL
;
10302 unsigned char *prow
;
10304 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10306 /* PR 17531: file: 0dd159bf.
10307 Check for integer overflow (can occur when size_t is 32-bit)
10308 with overlarge ncols or nused values. */
10310 && ((size_t) ncols
* 4 / 4 != ncols
10311 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10312 || poffsets
< ppool
|| poffsets
> limit
10313 || psizes
< poffsets
|| psizes
> limit
10314 || pend
< psizes
|| pend
> limit
))
10316 warn (_("Section %s too small for offset and size tables\n"),
10323 printf (_(" Offset table\n"));
10324 printf (" slot %-16s ",
10325 is_tu_index
? _("signature") : _("dwo_id"));
10332 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10333 this_set
= tu_sets
;
10338 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10339 this_set
= cu_sets
;
10345 for (j
= 0; j
< ncols
; j
++)
10347 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10348 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10353 for (i
= 0; i
< nslots
; i
++)
10355 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10357 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10360 /* PR 17531: file: a05f6ab3. */
10363 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10370 size_t num_copy
= sizeof (uint64_t);
10372 /* PR 23064: Beware of buffer overflow. */
10373 if (ph
+ num_copy
< limit
)
10374 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10377 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10382 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10383 /* PR 17531: file: b8ce60a8. */
10384 if (prow
< poffsets
|| prow
> limit
)
10386 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10392 printf (_(" [%3d] 0x%s"),
10393 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10394 buf
, sizeof (buf
)));
10395 for (j
= 0; j
< ncols
; j
++)
10397 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10399 printf (" %8d", val
);
10402 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10404 /* PR 17531: file: 10796eb3. */
10405 if (dw_sect
>= DW_SECT_MAX
)
10406 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10408 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10424 printf (_(" Size table\n"));
10425 printf (" slot %-16s ",
10426 is_tu_index
? _("signature") : _("dwo_id"));
10429 for (j
= 0; j
< ncols
; j
++)
10431 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
10433 printf (" %8s", get_DW_SECT_short_name (val
));
10439 for (i
= 0; i
< nslots
; i
++)
10441 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10443 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10446 prow
= psizes
+ (row
- 1) * ncols
* 4;
10449 printf (_(" [%3d] 0x%s"),
10450 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10451 buf
, sizeof (buf
)));
10453 for (j
= 0; j
< ncols
; j
++)
10455 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10457 printf (" %8d", val
);
10460 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10461 if (dw_sect
>= DW_SECT_MAX
)
10462 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10464 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10476 else if (do_display
)
10477 printf (_(" Unsupported version (%d)\n"), version
);
10485 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10487 /* Load the CU and TU indexes if present. This will build a list of
10488 section sets that we can use to associate a .debug_info.dwo section
10489 with its associated .debug_abbrev.dwo section in a .dwp file. */
10492 load_cu_tu_indexes (void *file
)
10494 /* If we have already loaded (or tried to load) the CU and TU indexes
10495 then do not bother to repeat the task. */
10496 if (cu_tu_indexes_read
== -1)
10498 cu_tu_indexes_read
= TRUE
;
10500 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10501 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10502 cu_tu_indexes_read
= FALSE
;
10504 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10505 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10506 cu_tu_indexes_read
= FALSE
;
10509 return (bfd_boolean
) cu_tu_indexes_read
;
10512 /* Find the set of sections that includes section SHNDX. */
10515 find_cu_tu_set (void *file
, unsigned int shndx
)
10519 if (! load_cu_tu_indexes (file
))
10522 /* Find SHNDX in the shndx pool. */
10523 for (i
= 0; i
< shndx_pool_used
; i
++)
10524 if (shndx_pool
[i
] == shndx
)
10527 if (i
>= shndx_pool_used
)
10530 /* Now backup to find the first entry in the set. */
10531 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10534 return shndx_pool
+ i
;
10537 /* Display a .debug_cu_index or .debug_tu_index section. */
10540 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10542 return process_cu_tu_index (section
, 1);
10546 display_debug_not_supported (struct dwarf_section
*section
,
10547 void *file ATTRIBUTE_UNUSED
)
10549 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10555 /* Like malloc, but takes two parameters like calloc.
10556 Verifies that the first parameter is not too large.
10557 Note: does *not* initialise the allocated memory to zero. */
10560 cmalloc (size_t nmemb
, size_t size
)
10562 /* Check for overflow. */
10563 if (nmemb
>= ~(size_t) 0 / size
)
10566 return xmalloc (nmemb
* size
);
10569 /* Like xmalloc, but takes two parameters like calloc.
10570 Verifies that the first parameter is not too large.
10571 Note: does *not* initialise the allocated memory to zero. */
10574 xcmalloc (size_t nmemb
, size_t size
)
10576 /* Check for overflow. */
10577 if (nmemb
>= ~(size_t) 0 / size
)
10580 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10585 return xmalloc (nmemb
* size
);
10588 /* Like xrealloc, but takes three parameters.
10589 Verifies that the second parameter is not too large.
10590 Note: does *not* initialise any new memory to zero. */
10593 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10595 /* Check for overflow. */
10596 if (nmemb
>= ~(size_t) 0 / size
)
10598 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10603 return xrealloc (ptr
, nmemb
* size
);
10606 /* Like xcalloc, but verifies that the first parameter is not too large. */
10609 xcalloc2 (size_t nmemb
, size_t size
)
10611 /* Check for overflow. */
10612 if (nmemb
>= ~(size_t) 0 / size
)
10614 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10619 return xcalloc (nmemb
, size
);
10622 static unsigned long
10623 calc_gnu_debuglink_crc32 (unsigned long crc
,
10624 const unsigned char * buf
,
10627 static const unsigned long crc32_table
[256] =
10629 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10630 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10631 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10632 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10633 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10634 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10635 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10636 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10637 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10638 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10639 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10640 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10641 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10642 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10643 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10644 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10645 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10646 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10647 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10648 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10649 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10650 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10651 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10652 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10653 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10654 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10655 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10656 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10657 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10658 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10659 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10660 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10661 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10662 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10663 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10664 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10665 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10666 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10667 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10668 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10669 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10670 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10671 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10672 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10673 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10674 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10675 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10676 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10677 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10678 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10679 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10682 const unsigned char *end
;
10684 crc
= ~crc
& 0xffffffff;
10685 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10686 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10687 return ~crc
& 0xffffffff;
10690 typedef bfd_boolean (* check_func_type
) (const char *, void *);
10691 typedef const char * (* parse_func_type
) (struct dwarf_section
*, void *);
10694 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10696 static unsigned char buffer
[8 * 1024];
10698 bfd_size_type count
;
10699 unsigned long crc
= 0;
10702 sep_data
= open_debug_file (pathname
);
10703 if (sep_data
== NULL
)
10706 /* Yes - we are opening the file twice... */
10707 f
= fopen (pathname
, "rb");
10710 /* Paranoia: This should never happen. */
10711 close_debug_file (sep_data
);
10712 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10716 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10717 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10721 if (crc
!= * (unsigned long *) crc_pointer
)
10723 close_debug_file (sep_data
);
10724 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10732 static const char *
10733 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10736 unsigned int crc_offset
;
10737 unsigned long * crc32
= (unsigned long *) data
;
10739 /* The name is first.
10740 The CRC value is stored after the filename, aligned up to 4 bytes. */
10741 name
= (const char *) section
->start
;
10743 crc_offset
= strnlen (name
, section
->size
) + 1;
10744 crc_offset
= (crc_offset
+ 3) & ~3;
10745 if (crc_offset
+ 4 > section
->size
)
10748 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10753 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10755 void * sep_data
= open_debug_file (filename
);
10757 if (sep_data
== NULL
)
10760 /* FIXME: We should now extract the build-id in the separate file
10766 typedef struct build_id_data
10769 const unsigned char * data
;
10772 static const char *
10773 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10776 bfd_size_type namelen
;
10777 bfd_size_type id_len
;
10778 Build_id_data
* build_id_data
;
10780 /* The name is first.
10781 The build-id follows immediately, with no padding, up to the section's end. */
10783 name
= (const char *) section
->start
;
10784 namelen
= strnlen (name
, section
->size
) + 1;
10785 if (namelen
>= section
->size
)
10788 id_len
= section
->size
- namelen
;
10792 build_id_data
= (Build_id_data
*) data
;
10793 build_id_data
->len
= id_len
;
10794 build_id_data
->data
= section
->start
+ namelen
;
10800 add_separate_debug_file (const char * filename
, void * handle
)
10802 separate_info
* i
= xmalloc (sizeof * i
);
10804 i
->filename
= filename
;
10805 i
->handle
= handle
;
10806 i
->next
= first_separate_info
;
10807 first_separate_info
= i
;
10810 #if HAVE_LIBDEBUGINFOD
10811 /* Query debuginfod servers for the target debuglink or debugaltlink
10812 file. If successful, store the path of the file in filename and
10813 return TRUE, otherwise return FALSE. */
10816 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10820 size_t build_id_len
;
10821 unsigned char * build_id
;
10823 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10825 /* Get the build-id of file. */
10826 build_id
= get_build_id (file
);
10829 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10831 /* Get the build-id of the debugaltlink file. */
10832 unsigned int filelen
;
10834 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10835 if (filelen
== section
->size
)
10836 /* Corrupt debugaltlink. */
10839 build_id
= section
->start
+ filelen
+ 1;
10840 build_id_len
= section
->size
- (filelen
+ 1);
10842 if (build_id_len
== 0)
10851 debuginfod_client
* client
;
10853 client
= debuginfod_begin ();
10854 if (client
== NULL
)
10857 /* Query debuginfod servers for the target file. If found its path
10858 will be stored in filename. */
10859 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
10860 debuginfod_end (client
);
10862 /* Only free build_id if we allocated space for a hex string
10863 in get_build_id (). */
10864 if (build_id_len
== 0)
10869 /* File successfully retrieved. Close fd since we want to
10870 use open_debug_file () on filename instead. */
10881 load_separate_debug_info (const char * main_filename
,
10882 struct dwarf_section
* xlink
,
10883 parse_func_type parse_func
,
10884 check_func_type check_func
,
10886 void * file ATTRIBUTE_UNUSED
)
10888 const char * separate_filename
;
10889 char * debug_filename
;
10891 size_t canon_dirlen
;
10894 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
10896 warn (_("Corrupt debuglink section: %s\n"),
10897 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
10901 /* Attempt to locate the separate file.
10902 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
10904 canon_dir
= lrealpath (main_filename
);
10906 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
10907 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
10909 canon_dir
[canon_dirlen
] = '\0';
10912 #define DEBUGDIR "/lib/debug"
10914 #ifndef EXTRA_DEBUG_ROOT1
10915 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
10917 #ifndef EXTRA_DEBUG_ROOT2
10918 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
10921 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
10923 + strlen (".debug/")
10924 #ifdef EXTRA_DEBUG_ROOT1
10925 + strlen (EXTRA_DEBUG_ROOT1
)
10927 #ifdef EXTRA_DEBUG_ROOT2
10928 + strlen (EXTRA_DEBUG_ROOT2
)
10930 + strlen (separate_filename
)
10932 if (debug_filename
== NULL
)
10934 warn (_("Out of memory"));
10939 /* First try in the current directory. */
10940 sprintf (debug_filename
, "%s", separate_filename
);
10941 if (check_func (debug_filename
, func_data
))
10944 /* Then try in a subdirectory called .debug. */
10945 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10946 if (check_func (debug_filename
, func_data
))
10949 /* Then try in the same directory as the original file. */
10950 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10951 if (check_func (debug_filename
, func_data
))
10954 /* And the .debug subdirectory of that directory. */
10955 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10956 if (check_func (debug_filename
, func_data
))
10959 #ifdef EXTRA_DEBUG_ROOT1
10960 /* Try the first extra debug file root. */
10961 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10962 if (check_func (debug_filename
, func_data
))
10965 /* Try the first extra debug file root. */
10966 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10967 if (check_func (debug_filename
, func_data
))
10971 #ifdef EXTRA_DEBUG_ROOT2
10972 /* Try the second extra debug file root. */
10973 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10974 if (check_func (debug_filename
, func_data
))
10978 /* Then try in the global debug_filename directory. */
10979 strcpy (debug_filename
, DEBUGDIR
);
10980 dirlen
= strlen (DEBUGDIR
) - 1;
10981 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
10982 strcat (debug_filename
, "/");
10983 strcat (debug_filename
, (const char *) separate_filename
);
10985 if (check_func (debug_filename
, func_data
))
10988 #if HAVE_LIBDEBUGINFOD
10990 char * tmp_filename
;
10992 if (debuginfod_fetch_separate_debug_info (xlink
,
10996 /* File successfully downloaded from server, replace
10997 debug_filename with the file's path. */
10998 free (debug_filename
);
10999 debug_filename
= tmp_filename
;
11005 /* Failed to find the file. */
11006 warn (_("could not find separate debug file '%s'\n"), separate_filename
);
11007 warn (_("tried: %s\n"), debug_filename
);
11009 #ifdef EXTRA_DEBUG_ROOT2
11010 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11011 warn (_("tried: %s\n"), debug_filename
);
11014 #ifdef EXTRA_DEBUG_ROOT1
11015 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11016 warn (_("tried: %s\n"), debug_filename
);
11018 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11019 warn (_("tried: %s\n"), debug_filename
);
11022 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11023 warn (_("tried: %s\n"), debug_filename
);
11025 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11026 warn (_("tried: %s\n"), debug_filename
);
11028 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11029 warn (_("tried: %s\n"), debug_filename
);
11031 sprintf (debug_filename
, "%s", separate_filename
);
11032 warn (_("tried: %s\n"), debug_filename
);
11034 #if HAVE_LIBDEBUGINFOD
11036 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11040 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11045 free (debug_filename
);
11051 void * debug_handle
;
11053 /* Now open the file.... */
11054 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11056 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11057 free (debug_filename
);
11061 /* FIXME: We do not check to see if there are any other separate debug info
11062 files that would also match. */
11064 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename
, debug_filename
);
11065 add_separate_debug_file (debug_filename
, debug_handle
);
11067 /* Do not free debug_filename - it might be referenced inside
11068 the structure returned by open_debug_file(). */
11069 return debug_handle
;
11072 /* Attempt to load a separate dwarf object file. */
11075 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11077 char * separate_filename
;
11078 void * separate_handle
;
11080 /* FIXME: Skip adding / if dwo_dir ends in /. */
11081 separate_filename
= concat (dir
, "/", name
, NULL
);
11082 if (separate_filename
== NULL
)
11084 warn (_("Out of memory allocating dwo filename\n"));
11088 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11090 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11091 free (separate_filename
);
11095 /* FIXME: We should check the dwo_id. */
11097 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11098 add_separate_debug_file (separate_filename
, separate_handle
);
11099 /* Note - separate_filename will be freed in free_debug_memory(). */
11100 return separate_handle
;
11103 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11104 Recursively check the loaded files for more of these sections.
11105 FIXME: Should also check for DWO_* entries in the newlu loaded files. */
11108 check_for_and_load_links (void * file
, const char * filename
)
11110 void * handle
= NULL
;
11112 if (load_debug_section (gnu_debugaltlink
, file
))
11114 Build_id_data build_id_data
;
11116 handle
= load_separate_debug_info (filename
,
11117 & debug_displays
[gnu_debugaltlink
].section
,
11118 parse_gnu_debugaltlink
,
11119 check_gnu_debugaltlink
,
11124 assert (handle
== first_separate_info
->handle
);
11125 check_for_and_load_links (first_separate_info
->handle
,
11126 first_separate_info
->filename
);
11130 if (load_debug_section (gnu_debuglink
, file
))
11132 unsigned long crc32
;
11134 handle
= load_separate_debug_info (filename
,
11135 & debug_displays
[gnu_debuglink
].section
,
11136 parse_gnu_debuglink
,
11137 check_gnu_debuglink
,
11142 assert (handle
== first_separate_info
->handle
);
11143 check_for_and_load_links (first_separate_info
->handle
,
11144 first_separate_info
->filename
);
11149 /* Load the separate debug info file(s) attached to FILE, if any exist.
11150 Returns TRUE if any were found, FALSE otherwise.
11151 If TRUE is returned then the linked list starting at first_separate_info
11152 will be populated with open file handles. */
11155 load_separate_debug_files (void * file
, const char * filename
)
11157 /* Skip this operation if we are not interested in debug links. */
11158 if (! do_follow_links
&& ! do_debug_links
)
11161 /* See if there are any dwo links. */
11162 if (load_debug_section (str
, file
)
11163 && load_debug_section (abbrev
, file
)
11164 && load_debug_section (info
, file
))
11168 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11171 bfd_boolean introduced
= FALSE
;
11173 const char * dir
= NULL
;
11174 const char * id
= NULL
;
11175 const char * name
= NULL
;
11177 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11179 /* Accumulate NAME, DIR and ID fields. */
11180 switch (dwinfo
->type
)
11184 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11185 name
= dwinfo
->value
;
11189 /* There can be multiple DW_AT_comp_dir entries in a CU,
11190 so do not complain. */
11191 dir
= dwinfo
->value
;
11196 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11197 id
= dwinfo
->value
;
11201 error (_("Unexpected DWO INFO type"));
11205 /* If we have reached the end of our list, or we are changing
11206 CUs, then display the information that we have accumulated
11209 && (dwinfo
->next
== NULL
11210 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11212 if (do_debug_links
)
11216 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11217 debug_displays
[info
].section
.uncompressed_name
);
11221 printf (_(" Name: %s\n"), name
);
11222 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11224 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11226 printf (_(" ID: <not specified>\n"));
11230 if (do_follow_links
)
11231 load_dwo_file (filename
, name
, dir
, id
);
11233 name
= dir
= id
= NULL
;
11239 if (! do_follow_links
)
11240 /* The other debug links will be displayed by display_debug_links()
11241 so we do not need to do any further processing here. */
11244 /* FIXME: We do not check for the presence of both link sections in the same file. */
11245 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11246 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11248 check_for_and_load_links (file
, filename
);
11249 if (first_separate_info
!= NULL
)
11252 do_follow_links
= 0;
11257 free_debug_memory (void)
11261 free_all_abbrevs ();
11263 free (cu_abbrev_map
);
11264 cu_abbrev_map
= NULL
;
11265 next_free_abbrev_map_entry
= 0;
11269 shndx_pool_size
= 0;
11270 shndx_pool_used
= 0;
11278 memset (level_type_signed
, 0, sizeof level_type_signed
);
11279 cu_tu_indexes_read
= -1;
11281 for (i
= 0; i
< max
; i
++)
11282 free_debug_section ((enum dwarf_section_display_enum
) i
);
11284 if (debug_information
!= NULL
)
11286 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11288 if (debug_information
[i
].max_loc_offsets
)
11290 free (debug_information
[i
].loc_offsets
);
11291 free (debug_information
[i
].have_frame_base
);
11293 if (debug_information
[i
].max_range_lists
)
11294 free (debug_information
[i
].range_lists
);
11296 free (debug_information
);
11297 debug_information
= NULL
;
11298 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11302 separate_info
* next
;
11304 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11306 close_debug_file (d
->handle
);
11307 free ((void *) d
->filename
);
11311 first_separate_info
= NULL
;
11317 dwarf_select_sections_by_names (const char *names
)
11321 const char * option
;
11325 debug_dump_long_opts
;
11327 static const debug_dump_long_opts opts_table
[] =
11329 /* Please keep this table alpha- sorted. */
11330 { "Ranges", & do_debug_ranges
, 1 },
11331 { "abbrev", & do_debug_abbrevs
, 1 },
11332 { "addr", & do_debug_addr
, 1 },
11333 { "aranges", & do_debug_aranges
, 1 },
11334 { "cu_index", & do_debug_cu_index
, 1 },
11335 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11336 { "follow-links", & do_follow_links
, 1 },
11337 { "frames", & do_debug_frames
, 1 },
11338 { "frames-interp", & do_debug_frames_interp
, 1 },
11339 /* The special .gdb_index section. */
11340 { "gdb_index", & do_gdb_index
, 1 },
11341 { "info", & do_debug_info
, 1 },
11342 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11343 { "links", & do_debug_links
, 1 },
11344 { "loc", & do_debug_loc
, 1 },
11345 { "macro", & do_debug_macinfo
, 1 },
11346 { "pubnames", & do_debug_pubnames
, 1 },
11347 { "pubtypes", & do_debug_pubtypes
, 1 },
11348 /* This entry is for compatibility
11349 with earlier versions of readelf. */
11350 { "ranges", & do_debug_aranges
, 1 },
11351 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11352 { "str", & do_debug_str
, 1 },
11353 { "str-offsets", & do_debug_str_offsets
, 1 },
11354 /* These trace_* sections are used by Itanium VMS. */
11355 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11356 { "trace_aranges", & do_trace_aranges
, 1 },
11357 { "trace_info", & do_trace_info
, 1 },
11366 const debug_dump_long_opts
* entry
;
11368 for (entry
= opts_table
; entry
->option
; entry
++)
11370 size_t len
= strlen (entry
->option
);
11372 if (strncmp (p
, entry
->option
, len
) == 0
11373 && (p
[len
] == ',' || p
[len
] == '\0'))
11375 * entry
->variable
|= entry
->val
;
11377 /* The --debug-dump=frames-interp option also
11378 enables the --debug-dump=frames option. */
11379 if (do_debug_frames_interp
)
11380 do_debug_frames
= 1;
11387 if (entry
->option
== NULL
)
11389 warn (_("Unrecognized debug option '%s'\n"), p
);
11390 p
= strchr (p
, ',');
11401 dwarf_select_sections_by_letters (const char *letters
)
11403 unsigned int lindex
= 0;
11405 while (letters
[lindex
])
11406 switch (letters
[lindex
++])
11408 case 'A': do_debug_addr
= 1; break;
11409 case 'a': do_debug_abbrevs
= 1; break;
11410 case 'c': do_debug_cu_index
= 1; break;
11411 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11412 case 'f': do_debug_frames
= 1; break;
11413 case 'g': do_gdb_index
= 1; break;
11414 case 'i': do_debug_info
= 1; break;
11415 case 'K': do_follow_links
= 1; break;
11416 case 'k': do_debug_links
= 1; break;
11417 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11418 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11419 case 'm': do_debug_macinfo
= 1; break;
11420 case 'O': do_debug_str_offsets
= 1; break;
11421 case 'o': do_debug_loc
= 1; break;
11422 case 'p': do_debug_pubnames
= 1; break;
11423 case 'R': do_debug_ranges
= 1; break;
11424 case 'r': do_debug_aranges
= 1; break;
11425 case 's': do_debug_str
= 1; break;
11426 case 'T': do_trace_aranges
= 1; break;
11427 case 't': do_debug_pubtypes
= 1; break;
11428 case 'U': do_trace_info
= 1; break;
11429 case 'u': do_trace_abbrevs
= 1; break;
11432 warn (_("Unrecognized debug option '%s'\n"), letters
);
11438 dwarf_select_sections_all (void)
11441 do_debug_abbrevs
= 1;
11442 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11443 do_debug_pubnames
= 1;
11444 do_debug_pubtypes
= 1;
11445 do_debug_aranges
= 1;
11446 do_debug_ranges
= 1;
11447 do_debug_frames
= 1;
11448 do_debug_macinfo
= 1;
11453 do_trace_abbrevs
= 1;
11454 do_trace_aranges
= 1;
11456 do_debug_cu_index
= 1;
11457 do_follow_links
= 1;
11458 do_debug_links
= 1;
11459 do_debug_str_offsets
= 1;
11462 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
11463 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
11465 /* N.B. The order here must match the order in section_display_enum. */
11467 struct dwarf_section_display debug_displays
[] =
11469 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
11470 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, TRUE
},
11471 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
11472 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, TRUE
},
11473 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
11474 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
11475 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
11476 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
11477 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
11478 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
11479 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11480 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11481 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11482 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11483 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
11484 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
11485 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
11486 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
11487 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
11488 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
11489 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, TRUE
},
11490 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
11491 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, FALSE
},
11492 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, FALSE
},
11493 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, TRUE
},
11494 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
11495 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, FALSE
},
11496 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, TRUE
},
11497 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
11498 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, TRUE
},
11499 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
11500 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11501 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
11502 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
11503 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, TRUE
},
11504 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
11505 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
11506 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, TRUE
},
11507 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
11508 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
11509 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
11510 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
11511 /* Separate debug info files can containt their own .debug_str section,
11512 and this might be in *addition* to a .debug_str section already present
11513 in the main file. Hence we need to have two entries for .debug_str. */
11514 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11517 /* A static assertion. */
11518 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];