1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2022 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"
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>
44 #ifndef ENABLE_CHECKING
45 #define ENABLE_CHECKING 0
50 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 #define MIN(a, b) ((a) < (b) ? (a) : (b))
53 static const char *regname (unsigned int regno
, int row
);
54 static const char *regname_internal_by_table_only (unsigned int regno
);
56 static int have_frame_base
;
57 static int need_base_address
;
59 static unsigned int num_debug_info_entries
= 0;
60 static unsigned int alloc_num_debug_info_entries
= 0;
61 static debug_info
*debug_information
= NULL
;
62 /* Special value for num_debug_info_entries to indicate
63 that the .debug_info section could not be loaded/parsed. */
64 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
66 /* A .debug_info section can contain multiple links to separate
67 DWO object files. We use these structures to record these links. */
75 typedef struct dwo_info
80 struct dwo_info
* next
;
83 static dwo_info
*first_dwo_info
= NULL
;
84 static bool need_dwo_info
;
86 separate_info
* first_separate_info
= NULL
;
88 unsigned int eh_addr_size
;
93 int do_debug_pubnames
;
94 int do_debug_pubtypes
;
98 int do_debug_frames_interp
;
101 int do_debug_str_offsets
;
105 int do_trace_abbrevs
;
106 int do_trace_aranges
;
108 int do_debug_cu_index
;
111 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
112 #ifdef HAVE_LIBDEBUGINFOD
113 int use_debuginfod
= 1;
117 int dwarf_cutoff_level
= -1;
118 unsigned long dwarf_start_die
;
122 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
123 testing whether e.g. a locview list is present. */
124 static const dwarf_vma vm1
= -1;
126 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
127 sections. For version 1 package files, each set is stored in SHNDX_POOL
128 as a zero-terminated list of section indexes comprising one set of debug
129 sections from a .dwo file. */
131 static unsigned int *shndx_pool
= NULL
;
132 static unsigned int shndx_pool_size
= 0;
133 static unsigned int shndx_pool_used
= 0;
135 /* For version 2 package files, each set contains an array of section offsets
136 and an array of section sizes, giving the offset and size of the
137 contribution from a CU or TU within one of the debug sections.
138 When displaying debug info from a package file, we need to use these
139 tables to locate the corresponding contributions to each section. */
144 dwarf_vma section_offsets
[DW_SECT_MAX
];
145 size_t section_sizes
[DW_SECT_MAX
];
148 static int cu_count
= 0;
149 static int tu_count
= 0;
150 static struct cu_tu_set
*cu_sets
= NULL
;
151 static struct cu_tu_set
*tu_sets
= NULL
;
153 static bool load_cu_tu_indexes (void *);
155 /* An array that indicates for a given level of CU nesting whether
156 the latest DW_AT_type seen for that level was a signed type or
158 #define MAX_CU_NESTING (1 << 8)
159 static bool level_type_signed
[MAX_CU_NESTING
];
161 /* Values for do_debug_lines. */
162 #define FLAG_DEBUG_LINES_RAW 1
163 #define FLAG_DEBUG_LINES_DECODED 2
166 size_of_encoded_value (int encoding
)
168 switch (encoding
& 0x7)
171 case 0: return eh_addr_size
;
179 get_encoded_value (unsigned char **pdata
,
181 struct dwarf_section
*section
,
184 unsigned char * data
= * pdata
;
185 unsigned int size
= size_of_encoded_value (encoding
);
188 if (data
>= end
|| size
> (size_t) (end
- data
))
190 warn (_("Encoded value extends past end of section\n"));
195 /* PR 17512: file: 002-829853-0.004. */
198 warn (_("Encoded size of %d is too large to read\n"), size
);
203 /* PR 17512: file: 1085-5603-0.004. */
206 warn (_("Encoded size of 0 is too small to read\n"));
211 if (encoding
& DW_EH_PE_signed
)
212 val
= byte_get_signed (data
, size
);
214 val
= byte_get (data
, size
);
216 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
217 val
+= section
->address
+ (data
- section
->start
);
219 * pdata
= data
+ size
;
223 #if SIZEOF_LONG_LONG > SIZEOF_LONG
225 # define DWARF_VMA_FMT "ll"
226 # define DWARF_VMA_FMT_LONG "%16.16llx"
228 # define DWARF_VMA_FMT "I64"
229 # define DWARF_VMA_FMT_LONG "%016I64x"
232 # define DWARF_VMA_FMT "l"
233 # define DWARF_VMA_FMT_LONG "%16.16lx"
236 /* Convert a dwarf vma value into a string. Returns a pointer to a static
237 buffer containing the converted VALUE. The value is converted according
238 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
239 it specifies the maximum number of bytes to be displayed in the converted
240 value and FMTCH is ignored - hex is always used. */
243 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
245 /* As dwarf_vmatoa is used more then once in a printf call
246 for output, we are cycling through a fixed array of pointers
247 for return address. */
248 static int buf_pos
= 0;
249 static struct dwarf_vmatoa_buf
255 ret
= buf
[buf_pos
++].place
;
256 buf_pos
%= ARRAY_SIZE (buf
);
260 /* Printf does not have a way of specifying a maximum field width for an
261 integer value, so we print the full value into a buffer and then select
262 the precision we need. */
263 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
266 return ret
+ (16 - 2 * num_bytes
);
273 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
275 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
276 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
281 static inline const char *
282 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
284 return dwarf_vmatoa_1 (fmtch
, value
, 0);
287 /* Print a dwarf_vma value (typically an address, offset or length) in
288 hexadecimal format, followed by a space. The length of the VALUE (and
289 hence the precision displayed) is determined by the NUM_BYTES parameter. */
292 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
294 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
297 /* Print a view number in hexadecimal value, with the same width
298 print_dwarf_vma would have printed it with the same num_bytes.
299 Print blanks for zero view, unless force is nonzero. */
302 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
310 assert (value
== (unsigned long) value
);
312 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
314 printf ("%*s", len
+ 1, "");
317 /* Read in a LEB128 encoded value starting at address DATA.
318 If SIGN is true, return a signed LEB128 value.
319 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
320 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
321 terminating byte was not found and with bit 1 set if the value
322 overflows a dwarf_vma.
323 No bytes will be read at address END or beyond. */
326 read_leb128 (unsigned char *data
,
327 const unsigned char *const end
,
329 unsigned int *length_return
,
332 dwarf_vma result
= 0;
333 unsigned int num_read
= 0;
334 unsigned int shift
= 0;
339 unsigned char byte
= *data
++;
340 unsigned char lost
, mask
;
344 if (shift
< CHAR_BIT
* sizeof (result
))
346 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
347 /* These bits overflowed. */
348 lost
= byte
^ (result
>> shift
);
349 /* And this is the mask of possible overflow bits. */
350 mask
= 0x7f ^ ((dwarf_vma
) 0x7f << shift
>> shift
);
358 if ((lost
& mask
) != (sign
&& (dwarf_signed_vma
) result
< 0 ? mask
: 0))
361 if ((byte
& 0x80) == 0)
364 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
365 result
|= -((dwarf_vma
) 1 << shift
);
370 if (length_return
!= NULL
)
371 *length_return
= num_read
;
372 if (status_return
!= NULL
)
373 *status_return
= status
;
378 /* Read AMOUNT bytes from PTR and store them in VAL.
379 Checks to make sure that the read will not reach or pass END.
380 FUNC chooses whether the value read is unsigned or signed, and may
381 be either byte_get or byte_get_signed. If INC is true, PTR is
382 incremented after reading the value.
383 This macro cannot protect against PTR values derived from user input.
384 The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
385 pointers is undefined behaviour. */
386 #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
389 size_t amount = (AMOUNT); \
390 if (sizeof (VAL) < amount) \
392 error (ngettext ("internal error: attempt to read %d byte " \
393 "of data in to %d sized variable", \
394 "internal error: attempt to read %d bytes " \
395 "of data in to %d sized variable", \
397 (int) amount, (int) sizeof (VAL)); \
398 amount = sizeof (VAL); \
400 if (ENABLE_CHECKING) \
401 assert ((PTR) <= (END)); \
402 size_t avail = (END) - (PTR); \
405 if (amount > avail) \
410 (VAL) = (FUNC) ((PTR), amount); \
416 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
417 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
419 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
420 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
422 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
423 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
425 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
426 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
428 typedef struct State_Machine_Registers
437 unsigned char op_index
;
438 unsigned char end_sequence
;
439 /* This variable hold the number of the last entry seen
440 in the File Table. */
441 unsigned int last_file_entry
;
444 static SMR state_machine_regs
;
447 reset_state_machine (int is_stmt
)
449 state_machine_regs
.address
= 0;
450 state_machine_regs
.view
= 0;
451 state_machine_regs
.op_index
= 0;
452 state_machine_regs
.file
= 1;
453 state_machine_regs
.line
= 1;
454 state_machine_regs
.column
= 0;
455 state_machine_regs
.is_stmt
= is_stmt
;
456 state_machine_regs
.basic_block
= 0;
457 state_machine_regs
.end_sequence
= 0;
458 state_machine_regs
.last_file_entry
= 0;
461 /* Handled an extend line op.
462 Returns the number of bytes read. */
465 process_extended_line_op (unsigned char * data
,
469 unsigned char op_code
;
470 size_t len
, header_len
;
472 unsigned char *orig_data
= data
;
475 READ_ULEB (len
, data
, end
);
476 header_len
= data
- orig_data
;
478 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
480 warn (_("Badly formed extended line op encountered!\n"));
486 printf (_(" Extended opcode %d: "), op_code
);
490 case DW_LNE_end_sequence
:
491 printf (_("End of Sequence\n\n"));
492 reset_state_machine (is_stmt
);
495 case DW_LNE_set_address
:
496 /* PR 17512: file: 002-100480-0.004. */
499 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
500 (unsigned long) len
- 1);
504 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
505 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
506 state_machine_regs
.address
= adr
;
507 state_machine_regs
.view
= 0;
508 state_machine_regs
.op_index
= 0;
511 case DW_LNE_define_file
:
512 printf (_("define new File Table entry\n"));
513 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
514 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
520 l
= strnlen ((char *) data
, end
- data
);
524 READ_ULEB (val
, data
, end
);
525 printf ("%s\t", dwarf_vmatoa ("u", val
));
526 READ_ULEB (val
, data
, end
);
527 printf ("%s\t", dwarf_vmatoa ("u", val
));
528 READ_ULEB (val
, data
, end
);
529 printf ("%s\t", dwarf_vmatoa ("u", val
));
530 printf ("%.*s\n\n", (int) l
, name
);
533 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
534 warn (_("DW_LNE_define_file: Bad opcode length\n"));
537 case DW_LNE_set_discriminator
:
538 READ_ULEB (val
, data
, end
);
539 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
543 case DW_LNE_HP_negate_is_UV_update
:
544 printf ("DW_LNE_HP_negate_is_UV_update\n");
546 case DW_LNE_HP_push_context
:
547 printf ("DW_LNE_HP_push_context\n");
549 case DW_LNE_HP_pop_context
:
550 printf ("DW_LNE_HP_pop_context\n");
552 case DW_LNE_HP_set_file_line_column
:
553 printf ("DW_LNE_HP_set_file_line_column\n");
555 case DW_LNE_HP_set_routine_name
:
556 printf ("DW_LNE_HP_set_routine_name\n");
558 case DW_LNE_HP_set_sequence
:
559 printf ("DW_LNE_HP_set_sequence\n");
561 case DW_LNE_HP_negate_post_semantics
:
562 printf ("DW_LNE_HP_negate_post_semantics\n");
564 case DW_LNE_HP_negate_function_exit
:
565 printf ("DW_LNE_HP_negate_function_exit\n");
567 case DW_LNE_HP_negate_front_end_logical
:
568 printf ("DW_LNE_HP_negate_front_end_logical\n");
570 case DW_LNE_HP_define_proc
:
571 printf ("DW_LNE_HP_define_proc\n");
573 case DW_LNE_HP_source_file_correlation
:
575 unsigned char *edata
= data
+ len
- 1;
577 printf ("DW_LNE_HP_source_file_correlation\n");
583 READ_ULEB (opc
, data
, edata
);
587 case DW_LNE_HP_SFC_formfeed
:
588 printf (" DW_LNE_HP_SFC_formfeed\n");
590 case DW_LNE_HP_SFC_set_listing_line
:
591 READ_ULEB (val
, data
, edata
);
592 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
593 dwarf_vmatoa ("u", val
));
595 case DW_LNE_HP_SFC_associate
:
596 printf (" DW_LNE_HP_SFC_associate ");
597 READ_ULEB (val
, data
, edata
);
598 printf ("(%s", dwarf_vmatoa ("u", val
));
599 READ_ULEB (val
, data
, edata
);
600 printf (",%s", dwarf_vmatoa ("u", val
));
601 READ_ULEB (val
, data
, edata
);
602 printf (",%s)\n", dwarf_vmatoa ("u", val
));
605 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
615 unsigned int rlen
= len
- 1;
617 if (op_code
>= DW_LNE_lo_user
618 /* The test against DW_LNW_hi_user is redundant due to
619 the limited range of the unsigned char data type used
621 /*&& op_code <= DW_LNE_hi_user*/)
622 printf (_("user defined: "));
624 printf (_("UNKNOWN: "));
625 printf (_("length %d ["), rlen
);
627 printf (" %02x", *data
++);
633 return len
+ header_len
;
636 static const unsigned char *
637 fetch_indirect_string (dwarf_vma offset
)
639 struct dwarf_section
*section
= &debug_displays
[str
].section
;
640 const unsigned char * ret
;
642 if (section
->start
== NULL
)
643 return (const unsigned char *) _("<no .debug_str section>");
645 if (offset
>= section
->size
)
647 warn (_("DW_FORM_strp offset too big: 0x%s\n"),
648 dwarf_vmatoa ("x", offset
));
649 return (const unsigned char *) _("<offset is too big>");
652 ret
= section
->start
+ offset
;
653 /* Unfortunately we cannot rely upon the .debug_str section ending with a
654 NUL byte. Since our caller is expecting to receive a well formed C
655 string we test for the lack of a terminating byte here. */
656 if (strnlen ((const char *) ret
, section
->size
- offset
)
657 == section
->size
- offset
)
658 ret
= (const unsigned char *)
659 _("<no NUL byte at end of .debug_str section>");
664 static const unsigned char *
665 fetch_indirect_line_string (dwarf_vma offset
)
667 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
668 const unsigned char * ret
;
670 if (section
->start
== NULL
)
671 return (const unsigned char *) _("<no .debug_line_str section>");
673 if (offset
>= section
->size
)
675 warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
676 dwarf_vmatoa ("x", offset
));
677 return (const unsigned char *) _("<offset is too big>");
680 ret
= section
->start
+ offset
;
681 /* Unfortunately we cannot rely upon the .debug_line_str section ending
682 with a NUL byte. Since our caller is expecting to receive a well formed
683 C string we test for the lack of a terminating byte here. */
684 if (strnlen ((const char *) ret
, section
->size
- offset
)
685 == section
->size
- offset
)
686 ret
= (const unsigned char *)
687 _("<no NUL byte at end of .debug_line_str section>");
693 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
694 dwarf_vma offset_size
, bool dwo
)
696 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
697 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
698 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
699 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
700 dwarf_vma index_offset
;
701 dwarf_vma str_offset
;
703 unsigned char *curr
= index_section
->start
;
704 unsigned char *end
= curr
+ index_section
->size
;
707 if (index_section
->start
== NULL
)
708 return (dwo
? _("<no .debug_str_offsets.dwo section>")
709 : _("<no .debug_str_offsets section>"));
711 if (str_section
->start
== NULL
)
712 return (dwo
? _("<no .debug_str.dwo section>")
713 : _("<no .debug_str section>"));
715 /* FIXME: We should cache the length... */
716 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
717 if (length
== 0xffffffff)
719 if (offset_size
!= 8)
720 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
721 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
723 else if (offset_size
!= 4)
725 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
730 /* This is probably an old style .debug_str_offset section which
731 just contains offsets and no header (and the first offset is 0). */
732 curr
= index_section
->start
;
733 length
= index_section
->size
;
737 /* Skip the version and padding bytes.
738 We assume that they are correct. */
749 && this_set
->section_sizes
[DW_SECT_STR_OFFSETS
] < length
)
750 length
= this_set
->section_sizes
[DW_SECT_STR_OFFSETS
];
752 if (length
> (dwarf_vma
) (end
- curr
))
754 warn (_("index table size too large for section %s vs %s\n"),
755 dwarf_vmatoa ("x", length
),
756 dwarf_vmatoa ("x", index_section
->size
));
760 if (length
< offset_size
)
762 warn (_("index table size %s is too small\n"),
763 dwarf_vmatoa ("x", length
));
764 return _("<table too small>");
768 index_offset
= idx
* offset_size
;
770 if (this_set
!= NULL
)
771 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
773 if (index_offset
>= length
774 || length
- index_offset
< offset_size
)
776 warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
777 dwarf_vmatoa ("x", index_offset
),
778 dwarf_vmatoa ("x", length
));
779 return _("<index offset is too big>");
782 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
783 str_offset
-= str_section
->address
;
784 if (str_offset
>= str_section
->size
)
786 warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
787 dwarf_vmatoa ("x", str_offset
));
788 return _("<indirect index offset is too big>");
791 ret
= (const char *) str_section
->start
+ str_offset
;
792 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
793 Since our caller is expecting to receive a well formed C string we test
794 for the lack of a terminating byte here. */
795 if (strnlen (ret
, str_section
->size
- str_offset
)
796 == str_section
->size
- str_offset
)
797 ret
= (const char *) _("<no NUL byte at end of section>");
803 fetch_indexed_addr (dwarf_vma offset
, uint32_t num_bytes
)
805 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
807 if (section
->start
== NULL
)
809 warn (_("<no .debug_addr section>"));
813 if (offset
+ num_bytes
> section
->size
)
815 warn (_("Offset into section %s too big: 0x%s\n"),
816 section
->name
, dwarf_vmatoa ("x", offset
));
820 return byte_get (section
->start
+ offset
, num_bytes
);
823 /* Fetch a value from a debug section that has been indexed by
824 something in another section (eg DW_FORM_loclistx).
825 Returns 0 if the value could not be found. */
828 fetch_indexed_value (dwarf_vma idx
,
829 enum dwarf_section_display_enum sec_enum
)
831 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
833 if (section
->start
== NULL
)
835 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
839 uint32_t pointer_size
, bias
;
841 if (byte_get (section
->start
, 4) == 0xffffffff)
852 dwarf_vma offset
= idx
* pointer_size
;
854 /* Offsets are biased by the size of the section header. */
857 if (offset
+ pointer_size
> section
->size
)
859 warn (_("Offset into section %s too big: 0x%s\n"),
860 section
->name
, dwarf_vmatoa ("x", offset
));
864 return byte_get (section
->start
+ offset
, pointer_size
);
867 /* FIXME: There are better and more efficient ways to handle
868 these structures. For now though, I just want something that
869 is simple to implement. */
870 /* Records a single attribute in an abbrev. */
871 typedef struct abbrev_attr
873 unsigned long attribute
;
875 dwarf_signed_vma implicit_const
;
876 struct abbrev_attr
* next
;
880 /* Records a single abbrev. */
881 typedef struct abbrev_entry
883 unsigned long number
;
886 struct abbrev_attr
* first_attr
;
887 struct abbrev_attr
* last_attr
;
888 struct abbrev_entry
* next
;
892 /* Records a set of abbreviations. */
893 typedef struct abbrev_list
895 abbrev_entry
* first_abbrev
;
896 abbrev_entry
* last_abbrev
;
897 dwarf_vma abbrev_base
;
898 dwarf_vma abbrev_offset
;
899 struct abbrev_list
* next
;
900 unsigned char * start_of_next_abbrevs
;
904 /* Records all the abbrevs found so far. */
905 static struct abbrev_list
* abbrev_lists
= NULL
;
907 typedef struct abbrev_map
914 /* Maps between CU offsets and abbrev sets. */
915 static abbrev_map
* cu_abbrev_map
= NULL
;
916 static unsigned long num_abbrev_map_entries
= 0;
917 static unsigned long next_free_abbrev_map_entry
= 0;
919 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
920 #define ABBREV_MAP_ENTRIES_INCREMENT 8
923 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
925 if (cu_abbrev_map
== NULL
)
927 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
928 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
930 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
932 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
933 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
936 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
937 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
938 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
939 next_free_abbrev_map_entry
++;
943 free_all_abbrevs (void)
947 for (list
= abbrev_lists
; list
!= NULL
;)
949 abbrev_list
* next
= list
->next
;
950 abbrev_entry
* abbrv
;
952 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
954 abbrev_entry
* next_abbrev
= abbrv
->next
;
957 for (attr
= abbrv
->first_attr
; attr
;)
959 abbrev_attr
*next_attr
= attr
->next
;
977 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
979 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
981 list
->abbrev_base
= abbrev_base
;
982 list
->abbrev_offset
= abbrev_offset
;
984 list
->next
= abbrev_lists
;
991 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
992 dwarf_vma abbrev_offset
)
996 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
997 if (list
->abbrev_base
== abbrev_base
998 && list
->abbrev_offset
== abbrev_offset
)
1004 /* Find the abbreviation map for the CU that includes OFFSET.
1005 OFFSET is an absolute offset from the start of the .debug_info section. */
1006 /* FIXME: This function is going to slow down readelf & objdump.
1007 Consider using a better algorithm to mitigate this effect. */
1010 find_abbrev_map_by_offset (dwarf_vma offset
)
1014 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
1015 if (cu_abbrev_map
[i
].start
<= offset
1016 && cu_abbrev_map
[i
].end
> offset
)
1017 return cu_abbrev_map
+ i
;
1023 add_abbrev (unsigned long number
,
1028 abbrev_entry
* entry
;
1030 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
1032 entry
->number
= number
;
1034 entry
->children
= children
;
1035 entry
->first_attr
= NULL
;
1036 entry
->last_attr
= NULL
;
1039 assert (list
!= NULL
);
1041 if (list
->first_abbrev
== NULL
)
1042 list
->first_abbrev
= entry
;
1044 list
->last_abbrev
->next
= entry
;
1046 list
->last_abbrev
= entry
;
1050 add_abbrev_attr (unsigned long attribute
,
1052 dwarf_signed_vma implicit_const
,
1057 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1059 attr
->attribute
= attribute
;
1061 attr
->implicit_const
= implicit_const
;
1064 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1066 if (list
->last_abbrev
->first_attr
== NULL
)
1067 list
->last_abbrev
->first_attr
= attr
;
1069 list
->last_abbrev
->last_attr
->next
= attr
;
1071 list
->last_abbrev
->last_attr
= attr
;
1074 /* Processes the (partial) contents of a .debug_abbrev section.
1075 Returns NULL if the end of the section was encountered.
1076 Returns the address after the last byte read if the end of
1077 an abbreviation set was found. */
1079 static unsigned char *
1080 process_abbrev_set (struct dwarf_section
*section
,
1081 dwarf_vma abbrev_base
,
1082 dwarf_vma abbrev_size
,
1083 dwarf_vma abbrev_offset
,
1086 if (abbrev_base
>= section
->size
1087 || abbrev_size
> section
->size
- abbrev_base
)
1089 /* PR 17531: file:4bcd9ce9. */
1090 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
1091 "abbrev section size (%lx)\n"),
1092 (unsigned long) (abbrev_base
+ abbrev_size
),
1093 (unsigned long) section
->size
);
1096 if (abbrev_offset
>= abbrev_size
)
1098 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
1099 "abbrev section size (%lx)\n"),
1100 (unsigned long) abbrev_offset
,
1101 (unsigned long) abbrev_size
);
1105 unsigned char *start
= section
->start
+ abbrev_base
;
1106 unsigned char *end
= start
+ abbrev_size
;
1107 start
+= abbrev_offset
;
1110 unsigned long entry
;
1112 unsigned long attribute
;
1115 READ_ULEB (entry
, start
, end
);
1117 /* A single zero is supposed to end the set according
1118 to the standard. If there's more, then signal that to
1125 READ_ULEB (tag
, start
, end
);
1129 children
= *start
++;
1131 add_abbrev (entry
, tag
, children
, list
);
1136 /* Initialize it due to a false compiler warning. */
1137 dwarf_signed_vma implicit_const
= -1;
1139 READ_ULEB (attribute
, start
, end
);
1143 READ_ULEB (form
, start
, end
);
1147 if (form
== DW_FORM_implicit_const
)
1149 READ_SLEB (implicit_const
, start
, end
);
1154 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1156 while (attribute
!= 0);
1159 /* Report the missing single zero which ends the section. */
1160 error (_(".debug_abbrev section not zero terminated\n"));
1166 get_TAG_name (unsigned long tag
)
1168 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1172 static char buffer
[100];
1174 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1175 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1177 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1185 get_FORM_name (unsigned long form
)
1190 return "DW_FORM value: 0";
1192 name
= get_DW_FORM_name (form
);
1195 static char buffer
[100];
1197 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1205 get_IDX_name (unsigned long idx
)
1207 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1211 static char buffer
[100];
1213 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1220 static unsigned char *
1221 display_block (unsigned char *data
,
1223 const unsigned char * const end
, char delimiter
)
1227 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1229 return (unsigned char *) end
;
1231 maxlen
= (dwarf_vma
) (end
- data
);
1232 length
= length
> maxlen
? maxlen
: length
;
1235 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1241 decode_location_expression (unsigned char * data
,
1242 unsigned int pointer_size
,
1243 unsigned int offset_size
,
1246 dwarf_vma cu_offset
,
1247 struct dwarf_section
* section
)
1251 dwarf_signed_vma svalue
;
1252 unsigned char *end
= data
+ length
;
1253 int need_frame_base
= 0;
1262 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1263 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1266 printf ("DW_OP_deref");
1269 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1270 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1273 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1274 printf ("DW_OP_const1s: %ld", (long) svalue
);
1277 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1278 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1281 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1282 printf ("DW_OP_const2s: %ld", (long) svalue
);
1285 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1286 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1289 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1290 printf ("DW_OP_const4s: %ld", (long) svalue
);
1293 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1294 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1295 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1296 printf ("%lu", (unsigned long) uvalue
);
1299 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1300 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1301 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1302 printf ("%ld", (long) svalue
);
1305 READ_ULEB (uvalue
, data
, end
);
1306 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1309 READ_SLEB (svalue
, data
, end
);
1310 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1313 printf ("DW_OP_dup");
1316 printf ("DW_OP_drop");
1319 printf ("DW_OP_over");
1322 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1323 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1326 printf ("DW_OP_swap");
1329 printf ("DW_OP_rot");
1332 printf ("DW_OP_xderef");
1335 printf ("DW_OP_abs");
1338 printf ("DW_OP_and");
1341 printf ("DW_OP_div");
1344 printf ("DW_OP_minus");
1347 printf ("DW_OP_mod");
1350 printf ("DW_OP_mul");
1353 printf ("DW_OP_neg");
1356 printf ("DW_OP_not");
1359 printf ("DW_OP_or");
1362 printf ("DW_OP_plus");
1364 case DW_OP_plus_uconst
:
1365 READ_ULEB (uvalue
, data
, end
);
1366 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1369 printf ("DW_OP_shl");
1372 printf ("DW_OP_shr");
1375 printf ("DW_OP_shra");
1378 printf ("DW_OP_xor");
1381 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1382 printf ("DW_OP_bra: %ld", (long) svalue
);
1385 printf ("DW_OP_eq");
1388 printf ("DW_OP_ge");
1391 printf ("DW_OP_gt");
1394 printf ("DW_OP_le");
1397 printf ("DW_OP_lt");
1400 printf ("DW_OP_ne");
1403 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1404 printf ("DW_OP_skip: %ld", (long) svalue
);
1439 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1474 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1475 regname (op
- DW_OP_reg0
, 1));
1510 READ_SLEB (svalue
, data
, end
);
1511 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1512 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1516 READ_ULEB (uvalue
, data
, end
);
1517 printf ("DW_OP_regx: %s (%s)",
1518 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1521 need_frame_base
= 1;
1522 READ_SLEB (svalue
, data
, end
);
1523 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1526 READ_ULEB (uvalue
, data
, end
);
1527 READ_SLEB (svalue
, data
, end
);
1528 printf ("DW_OP_bregx: %s (%s) %s",
1529 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1530 dwarf_vmatoa ("d", svalue
));
1533 READ_ULEB (uvalue
, data
, end
);
1534 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1536 case DW_OP_deref_size
:
1537 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1538 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1540 case DW_OP_xderef_size
:
1541 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1542 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1545 printf ("DW_OP_nop");
1548 /* DWARF 3 extensions. */
1549 case DW_OP_push_object_address
:
1550 printf ("DW_OP_push_object_address");
1553 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1554 this ought to be an 8-byte wide computation. */
1555 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1556 printf ("DW_OP_call2: <0x%s>",
1557 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1560 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1561 this ought to be an 8-byte wide computation. */
1562 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1563 printf ("DW_OP_call4: <0x%s>",
1564 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1566 case DW_OP_call_ref
:
1567 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1568 this ought to be an 8-byte wide computation. */
1569 if (dwarf_version
== -1)
1571 printf (_("(DW_OP_call_ref in frame info)"));
1572 /* No way to tell where the next op is, so just bail. */
1573 return need_frame_base
;
1575 if (dwarf_version
== 2)
1577 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1581 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1583 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1585 case DW_OP_form_tls_address
:
1586 printf ("DW_OP_form_tls_address");
1588 case DW_OP_call_frame_cfa
:
1589 printf ("DW_OP_call_frame_cfa");
1591 case DW_OP_bit_piece
:
1592 printf ("DW_OP_bit_piece: ");
1593 READ_ULEB (uvalue
, data
, end
);
1594 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1595 READ_ULEB (uvalue
, data
, end
);
1596 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1599 /* DWARF 4 extensions. */
1600 case DW_OP_stack_value
:
1601 printf ("DW_OP_stack_value");
1604 case DW_OP_implicit_value
:
1605 printf ("DW_OP_implicit_value");
1606 READ_ULEB (uvalue
, data
, end
);
1607 data
= display_block (data
, uvalue
, end
, ' ');
1610 /* GNU extensions. */
1611 case DW_OP_GNU_push_tls_address
:
1612 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1614 case DW_OP_GNU_uninit
:
1615 printf ("DW_OP_GNU_uninit");
1616 /* FIXME: Is there data associated with this OP ? */
1618 case DW_OP_GNU_encoded_addr
:
1625 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1627 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1628 print_dwarf_vma (addr
, pointer_size
);
1631 case DW_OP_implicit_pointer
:
1632 case DW_OP_GNU_implicit_pointer
:
1633 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1634 this ought to be an 8-byte wide computation. */
1635 if (dwarf_version
== -1)
1637 printf (_("(%s in frame info)"),
1638 (op
== DW_OP_implicit_pointer
1639 ? "DW_OP_implicit_pointer"
1640 : "DW_OP_GNU_implicit_pointer"));
1641 /* No way to tell where the next op is, so just bail. */
1642 return need_frame_base
;
1644 if (dwarf_version
== 2)
1646 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1650 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1652 READ_SLEB (svalue
, data
, end
);
1653 printf ("%s: <0x%s> %s",
1654 (op
== DW_OP_implicit_pointer
1655 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1656 dwarf_vmatoa ("x", uvalue
),
1657 dwarf_vmatoa ("d", svalue
));
1659 case DW_OP_entry_value
:
1660 case DW_OP_GNU_entry_value
:
1661 READ_ULEB (uvalue
, data
, end
);
1662 /* PR 17531: file: 0cc9cd00. */
1663 if (uvalue
> (dwarf_vma
) (end
- data
))
1664 uvalue
= end
- data
;
1665 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1666 : "DW_OP_GNU_entry_value"));
1667 if (decode_location_expression (data
, pointer_size
, offset_size
,
1668 dwarf_version
, uvalue
,
1669 cu_offset
, section
))
1670 need_frame_base
= 1;
1674 case DW_OP_const_type
:
1675 case DW_OP_GNU_const_type
:
1676 READ_ULEB (uvalue
, data
, end
);
1677 printf ("%s: <0x%s> ",
1678 (op
== DW_OP_const_type
? "DW_OP_const_type"
1679 : "DW_OP_GNU_const_type"),
1680 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1681 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1682 data
= display_block (data
, uvalue
, end
, ' ');
1684 case DW_OP_regval_type
:
1685 case DW_OP_GNU_regval_type
:
1686 READ_ULEB (uvalue
, data
, end
);
1687 printf ("%s: %s (%s)",
1688 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1689 : "DW_OP_GNU_regval_type"),
1690 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1691 READ_ULEB (uvalue
, data
, end
);
1692 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1694 case DW_OP_deref_type
:
1695 case DW_OP_GNU_deref_type
:
1696 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1698 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1699 : "DW_OP_GNU_deref_type"),
1701 READ_ULEB (uvalue
, data
, end
);
1702 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1705 case DW_OP_GNU_convert
:
1706 READ_ULEB (uvalue
, data
, end
);
1707 printf ("%s <0x%s>",
1708 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1709 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1711 case DW_OP_reinterpret
:
1712 case DW_OP_GNU_reinterpret
:
1713 READ_ULEB (uvalue
, data
, end
);
1714 printf ("%s <0x%s>",
1715 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1716 : "DW_OP_GNU_reinterpret"),
1717 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1719 case DW_OP_GNU_parameter_ref
:
1720 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1721 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1722 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1724 case DW_OP_GNU_addr_index
:
1725 READ_ULEB (uvalue
, data
, end
);
1726 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1728 case DW_OP_GNU_const_index
:
1729 READ_ULEB (uvalue
, data
, end
);
1730 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1732 case DW_OP_GNU_variable_value
:
1733 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1734 this ought to be an 8-byte wide computation. */
1735 if (dwarf_version
== -1)
1737 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1738 /* No way to tell where the next op is, so just bail. */
1739 return need_frame_base
;
1741 if (dwarf_version
== 2)
1743 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1747 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1749 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1752 /* HP extensions. */
1753 case DW_OP_HP_is_value
:
1754 printf ("DW_OP_HP_is_value");
1755 /* FIXME: Is there data associated with this OP ? */
1757 case DW_OP_HP_fltconst4
:
1758 printf ("DW_OP_HP_fltconst4");
1759 /* FIXME: Is there data associated with this OP ? */
1761 case DW_OP_HP_fltconst8
:
1762 printf ("DW_OP_HP_fltconst8");
1763 /* FIXME: Is there data associated with this OP ? */
1765 case DW_OP_HP_mod_range
:
1766 printf ("DW_OP_HP_mod_range");
1767 /* FIXME: Is there data associated with this OP ? */
1769 case DW_OP_HP_unmod_range
:
1770 printf ("DW_OP_HP_unmod_range");
1771 /* FIXME: Is there data associated with this OP ? */
1774 printf ("DW_OP_HP_tls");
1775 /* FIXME: Is there data associated with this OP ? */
1778 /* PGI (STMicroelectronics) extensions. */
1779 case DW_OP_PGI_omp_thread_num
:
1780 /* Pushes the thread number for the current thread as it would be
1781 returned by the standard OpenMP library function:
1782 omp_get_thread_num(). The "current thread" is the thread for
1783 which the expression is being evaluated. */
1784 printf ("DW_OP_PGI_omp_thread_num");
1788 if (op
>= DW_OP_lo_user
1789 && op
<= DW_OP_hi_user
)
1790 printf (_("(User defined location op 0x%x)"), op
);
1792 printf (_("(Unknown location op 0x%x)"), op
);
1793 /* No way to tell where the next op is, so just bail. */
1794 return need_frame_base
;
1797 /* Separate the ops. */
1802 return need_frame_base
;
1805 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1806 This is used for DWARF package files. */
1808 static struct cu_tu_set
*
1809 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1811 struct cu_tu_set
*p
;
1813 unsigned int dw_sect
;
1819 dw_sect
= DW_SECT_TYPES
;
1825 dw_sect
= DW_SECT_INFO
;
1829 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1838 fetch_alt_indirect_string (dwarf_vma offset
)
1842 if (! do_follow_links
)
1845 if (first_separate_info
== NULL
)
1846 return _("<no links available>");
1848 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1850 struct dwarf_section
* section
;
1853 if (! load_debug_section (separate_debug_str
, i
->handle
))
1856 section
= &debug_displays
[separate_debug_str
].section
;
1858 if (section
->start
== NULL
)
1861 if (offset
>= section
->size
)
1864 ret
= (const char *) (section
->start
+ offset
);
1865 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1866 NUL byte. Since our caller is expecting to receive a well formed C
1867 string we test for the lack of a terminating byte here. */
1868 if (strnlen ((const char *) ret
, section
->size
- offset
)
1869 == section
->size
- offset
)
1870 return _("<no NUL byte at end of alt .debug_str section>");
1875 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1876 dwarf_vmatoa ("x", offset
));
1877 return _("<offset is too big>");
1881 get_AT_name (unsigned long attribute
)
1886 return "DW_AT value: 0";
1888 /* One value is shared by the MIPS and HP extensions: */
1889 if (attribute
== DW_AT_MIPS_fde
)
1890 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1892 name
= get_DW_AT_name (attribute
);
1896 static char buffer
[100];
1898 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1907 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1909 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1911 dwinfo
->type
= type
;
1912 dwinfo
->value
= value
;
1913 dwinfo
->cu_offset
= cu_offset
;
1914 dwinfo
->next
= first_dwo_info
;
1915 first_dwo_info
= dwinfo
;
1919 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1921 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1925 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1927 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1931 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1933 add_dwo_info (id
, cu_offset
, DWO_ID
);
1937 free_dwo_info (void)
1942 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1944 next
= dwinfo
->next
;
1947 first_dwo_info
= NULL
;
1950 /* Ensure that START + UVALUE is less than END.
1951 Return an adjusted UVALUE if necessary to ensure this relationship. */
1953 static inline dwarf_vma
1954 check_uvalue (const unsigned char * start
,
1956 const unsigned char * end
)
1958 dwarf_vma max_uvalue
= end
- start
;
1960 /* See PR 17512: file: 008-103549-0.001:0.1.
1961 and PR 24829 for examples of where these tests are triggered. */
1962 if (uvalue
> max_uvalue
)
1964 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1965 uvalue
= max_uvalue
;
1971 static unsigned char *
1972 skip_attr_bytes (unsigned long form
,
1973 unsigned char *data
,
1975 dwarf_vma pointer_size
,
1976 dwarf_vma offset_size
,
1978 dwarf_vma
*value_return
)
1980 dwarf_signed_vma svalue
;
1981 dwarf_vma uvalue
= 0;
1988 case DW_FORM_ref_addr
:
1989 if (dwarf_version
== 2)
1990 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1991 else if (dwarf_version
> 2)
1992 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1998 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2002 case DW_FORM_line_strp
:
2003 case DW_FORM_sec_offset
:
2004 case DW_FORM_GNU_ref_alt
:
2005 case DW_FORM_GNU_strp_alt
:
2006 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2009 case DW_FORM_flag_present
:
2017 case DW_FORM_addrx1
:
2018 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2022 case DW_FORM_addrx3
:
2023 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2029 case DW_FORM_addrx2
:
2030 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2036 case DW_FORM_addrx4
:
2037 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2041 READ_SLEB (svalue
, data
, end
);
2045 case DW_FORM_ref_udata
:
2047 case DW_FORM_GNU_str_index
:
2049 case DW_FORM_GNU_addr_index
:
2051 case DW_FORM_loclistx
:
2052 case DW_FORM_rnglistx
:
2053 READ_ULEB (uvalue
, data
, end
);
2057 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2061 case DW_FORM_ref_sig8
:
2065 case DW_FORM_data16
:
2069 case DW_FORM_string
:
2070 inc
= strnlen ((char *) data
, end
- data
) + 1;
2074 case DW_FORM_exprloc
:
2075 READ_ULEB (uvalue
, data
, end
);
2079 case DW_FORM_block1
:
2080 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2084 case DW_FORM_block2
:
2085 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2089 case DW_FORM_block4
:
2090 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2094 case DW_FORM_indirect
:
2095 READ_ULEB (form
, data
, end
);
2096 if (form
== DW_FORM_implicit_const
)
2097 SKIP_ULEB (data
, end
);
2098 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2099 dwarf_version
, value_return
);
2105 * value_return
= uvalue
;
2106 if (inc
<= (dwarf_vma
) (end
- data
))
2113 /* Given form FORM with value UVALUE, locate and return the abbreviation
2114 associated with it. */
2116 static abbrev_entry
*
2117 get_type_abbrev_from_form (unsigned long form
,
2118 unsigned long uvalue
,
2119 dwarf_vma cu_offset
,
2120 unsigned char *cu_end
,
2121 const struct dwarf_section
*section
,
2122 unsigned long *abbrev_num_return
,
2123 unsigned char **data_return
,
2124 abbrev_map
**map_return
)
2126 unsigned long abbrev_number
;
2128 abbrev_entry
* entry
;
2129 unsigned char * data
;
2131 if (abbrev_num_return
!= NULL
)
2132 * abbrev_num_return
= 0;
2133 if (data_return
!= NULL
)
2134 * data_return
= NULL
;
2138 case DW_FORM_GNU_ref_alt
:
2139 case DW_FORM_ref_sig8
:
2140 /* FIXME: We are unable to handle this form at the moment. */
2143 case DW_FORM_ref_addr
:
2144 if (uvalue
>= section
->size
)
2146 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2147 uvalue
, (long) section
->size
, section
->name
);
2152 case DW_FORM_ref_sup4
:
2153 case DW_FORM_ref_sup8
:
2160 case DW_FORM_ref_udata
:
2161 if (uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2163 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > CU size %lx\n"),
2164 uvalue
, (long) cu_offset
, (long) (cu_end
- section
->start
));
2167 uvalue
+= cu_offset
;
2170 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2173 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2177 data
= (unsigned char *) section
->start
+ uvalue
;
2178 map
= find_abbrev_map_by_offset (uvalue
);
2182 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2185 if (map
->list
== NULL
)
2187 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2191 if (map_return
!= NULL
)
2193 if (form
== DW_FORM_ref_addr
)
2199 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2201 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2202 if (entry
->number
== abbrev_number
)
2205 if (abbrev_num_return
!= NULL
)
2206 * abbrev_num_return
= abbrev_number
;
2208 if (data_return
!= NULL
)
2209 * data_return
= data
;
2212 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2217 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2218 can be determined to be a signed type. The data for ENTRY can be
2219 found starting at DATA. */
2222 get_type_signedness (abbrev_entry
*entry
,
2223 const struct dwarf_section
*section
,
2224 unsigned char *data
,
2226 dwarf_vma cu_offset
,
2227 dwarf_vma pointer_size
,
2228 dwarf_vma offset_size
,
2231 unsigned int nesting
)
2235 * is_signed
= false;
2237 #define MAX_NESTING 20
2238 if (nesting
> MAX_NESTING
)
2240 /* FIXME: Warn - or is this expected ?
2241 NB/ We need to avoid infinite recursion. */
2245 for (attr
= entry
->first_attr
;
2246 attr
!= NULL
&& attr
->attribute
;
2249 unsigned char * orig_data
= data
;
2250 dwarf_vma uvalue
= 0;
2252 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2253 offset_size
, dwarf_version
, & uvalue
);
2257 switch (attr
->attribute
)
2259 case DW_AT_linkage_name
:
2263 if (attr
->form
== DW_FORM_strp
)
2264 printf (", %s", fetch_indirect_string (uvalue
));
2265 else if (attr
->form
== DW_FORM_string
)
2266 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2273 abbrev_entry
*type_abbrev
;
2274 unsigned char *type_data
;
2277 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2282 NULL
/* abbrev num return */,
2285 if (type_abbrev
== NULL
)
2288 get_type_signedness (type_abbrev
, section
, type_data
,
2289 map
? section
->start
+ map
->end
: end
,
2290 map
? map
->start
: cu_offset
,
2291 pointer_size
, offset_size
, dwarf_version
,
2292 is_signed
, nesting
+ 1);
2296 case DW_AT_encoding
:
2297 /* Determine signness. */
2300 case DW_ATE_address
:
2301 /* FIXME - some architectures have signed addresses. */
2302 case DW_ATE_boolean
:
2303 case DW_ATE_unsigned
:
2304 case DW_ATE_unsigned_char
:
2305 case DW_ATE_unsigned_fixed
:
2306 * is_signed
= false;
2310 case DW_ATE_complex_float
:
2313 case DW_ATE_signed_char
:
2314 case DW_ATE_imaginary_float
:
2315 case DW_ATE_decimal_float
:
2316 case DW_ATE_signed_fixed
:
2326 read_and_print_leb128 (unsigned char *data
,
2327 unsigned int *bytes_read
,
2328 unsigned const char *end
,
2332 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2334 report_leb_status (status
);
2336 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2340 display_discr_list (unsigned long form
,
2342 unsigned char * data
,
2345 unsigned char *end
= data
;
2349 printf ("[default]");
2356 case DW_FORM_block1
:
2357 case DW_FORM_block2
:
2358 case DW_FORM_block4
:
2359 /* Move data pointer back to the start of the byte array. */
2363 printf ("<corrupt>\n");
2364 warn (_("corrupt discr_list - not using a block form\n"));
2370 printf ("<corrupt>\n");
2371 warn (_("corrupt discr_list - block not long enough\n"));
2375 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2376 ? level_type_signed
[level
- 1] : false);
2381 unsigned char discriminant
;
2382 unsigned int bytes_read
;
2384 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2386 switch (discriminant
)
2390 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2396 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2400 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2405 printf ("<corrupt>\n");
2406 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2416 printf (")(signed)");
2418 printf (")(unsigned)");
2421 static unsigned char *
2422 read_and_display_attr_value (unsigned long attribute
,
2424 dwarf_signed_vma implicit_const
,
2425 unsigned char * start
,
2426 unsigned char * data
,
2427 unsigned char * end
,
2428 dwarf_vma cu_offset
,
2429 dwarf_vma pointer_size
,
2430 dwarf_vma offset_size
,
2432 debug_info
* debug_info_p
,
2434 struct dwarf_section
* section
,
2435 struct cu_tu_set
* this_set
,
2439 dwarf_signed_vma svalue
;
2440 dwarf_vma uvalue
= 0;
2441 dwarf_vma uvalue_hi
= 0;
2442 unsigned char *block_start
= NULL
;
2443 unsigned char *orig_data
= data
;
2445 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2447 warn (_("Corrupt attribute\n"));
2451 if (do_wide
&& ! do_loc
)
2453 /* PR 26847: Display the name of the form. */
2454 const char * name
= get_FORM_name (form
);
2456 /* For convenience we skip the DW_FORM_ prefix to the name. */
2458 name
+= 8; /* strlen ("DW_FORM_") */
2459 printf ("%c(%s)", delimiter
, name
);
2464 case DW_FORM_ref_addr
:
2465 if (dwarf_version
== 2)
2466 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2467 else if (dwarf_version
> 2)
2468 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2470 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2474 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2477 case DW_FORM_strp_sup
:
2479 case DW_FORM_line_strp
:
2480 case DW_FORM_sec_offset
:
2481 case DW_FORM_GNU_ref_alt
:
2482 case DW_FORM_GNU_strp_alt
:
2483 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2486 case DW_FORM_flag_present
:
2494 case DW_FORM_addrx1
:
2495 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2501 case DW_FORM_addrx2
:
2502 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2506 case DW_FORM_addrx3
:
2507 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2510 case DW_FORM_ref_sup4
:
2514 case DW_FORM_addrx4
:
2515 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2518 case DW_FORM_ref_sup8
:
2521 case DW_FORM_ref_sig8
:
2522 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2525 case DW_FORM_data16
:
2526 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2527 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2528 if (byte_get
!= byte_get_little_endian
)
2530 dwarf_vma utmp
= uvalue
;
2537 READ_SLEB (svalue
, data
, end
);
2541 case DW_FORM_GNU_str_index
:
2543 case DW_FORM_ref_udata
:
2545 case DW_FORM_GNU_addr_index
:
2547 case DW_FORM_loclistx
:
2548 case DW_FORM_rnglistx
:
2549 READ_ULEB (uvalue
, data
, end
);
2552 case DW_FORM_indirect
:
2553 READ_ULEB (form
, data
, end
);
2555 printf ("%c%s", delimiter
, get_FORM_name (form
));
2556 if (form
== DW_FORM_implicit_const
)
2557 READ_SLEB (implicit_const
, data
, end
);
2558 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2560 cu_offset
, pointer_size
,
2561 offset_size
, dwarf_version
,
2562 debug_info_p
, do_loc
,
2563 section
, this_set
, delimiter
, level
);
2565 case DW_FORM_implicit_const
:
2566 uvalue
= implicit_const
;
2575 case DW_FORM_ref_addr
:
2577 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2580 case DW_FORM_GNU_ref_alt
:
2584 /* We have already printed the form name. */
2585 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2587 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2589 /* FIXME: Follow the reference... */
2595 case DW_FORM_ref_sup4
:
2596 case DW_FORM_ref_udata
:
2598 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2603 case DW_FORM_sec_offset
:
2605 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2608 case DW_FORM_flag_present
:
2615 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2618 case DW_FORM_implicit_const
:
2620 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2623 case DW_FORM_ref_sup8
:
2628 dwarf_vma utmp
= uvalue
;
2629 if (form
== DW_FORM_ref8
)
2631 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", utmp
));
2635 case DW_FORM_data16
:
2638 uvalue_hi
== 0 ? "" : dwarf_vmatoa ("x", uvalue_hi
),
2639 dwarf_vmatoa_1 ("x", uvalue
, uvalue_hi
== 0 ? 0 : 8));
2642 case DW_FORM_string
:
2644 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2645 data
+= strnlen ((char *) data
, end
- data
);
2651 case DW_FORM_exprloc
:
2652 READ_ULEB (uvalue
, data
, end
);
2655 if (block_start
>= end
)
2657 warn (_("Block ends prematurely\n"));
2662 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2665 data
= block_start
+ uvalue
;
2667 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2670 case DW_FORM_block1
:
2671 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2674 case DW_FORM_block2
:
2675 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2678 case DW_FORM_block4
:
2679 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2686 /* We have already displayed the form name. */
2687 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2688 dwarf_vmatoa ("x", uvalue
),
2689 fetch_indirect_string (uvalue
));
2691 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2692 dwarf_vmatoa ("x", uvalue
),
2693 fetch_indirect_string (uvalue
));
2697 case DW_FORM_line_strp
:
2701 /* We have already displayed the form name. */
2702 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2703 dwarf_vmatoa ("x", uvalue
),
2704 fetch_indirect_line_string (uvalue
));
2706 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2707 dwarf_vmatoa ("x", uvalue
),
2708 fetch_indirect_line_string (uvalue
));
2712 case DW_FORM_GNU_str_index
:
2720 const char *suffix
= strrchr (section
->name
, '.');
2721 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2724 /* We have already displayed the form name. */
2725 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2726 dwarf_vmatoa ("x", uvalue
),
2727 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2729 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2730 dwarf_vmatoa ("x", uvalue
),
2731 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2735 case DW_FORM_GNU_strp_alt
:
2739 /* We have already displayed the form name. */
2740 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2741 dwarf_vmatoa ("x", uvalue
),
2742 fetch_alt_indirect_string (uvalue
));
2744 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2745 dwarf_vmatoa ("x", uvalue
),
2746 fetch_alt_indirect_string (uvalue
));
2750 case DW_FORM_indirect
:
2751 /* Handled above. */
2754 case DW_FORM_ref_sig8
:
2756 printf ("%c%s: 0x%s", delimiter
, do_wide
? "" : "signature",
2757 dwarf_vmatoa ("x", uvalue
));
2760 case DW_FORM_GNU_addr_index
:
2762 case DW_FORM_addrx1
:
2763 case DW_FORM_addrx2
:
2764 case DW_FORM_addrx3
:
2765 case DW_FORM_addrx4
:
2766 case DW_FORM_loclistx
:
2767 case DW_FORM_rnglistx
:
2773 if (debug_info_p
== NULL
)
2775 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2778 base
= debug_info_p
->addr_base
;
2780 offset
= base
+ uvalue
* pointer_size
;
2783 /* We have already displayed the form name. */
2784 printf (_("%c(index: 0x%s): %s"), delimiter
,
2785 dwarf_vmatoa ("x", uvalue
),
2786 dwarf_vmatoa ("x", fetch_indexed_addr (offset
, pointer_size
)));
2788 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2789 dwarf_vmatoa ("x", uvalue
),
2790 dwarf_vmatoa ("x", fetch_indexed_addr (offset
, pointer_size
)));
2794 case DW_FORM_strp_sup
:
2796 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2800 warn (_("Unrecognized form: 0x%lx\n"), form
);
2801 /* What to do? Consume a byte maybe? */
2806 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2807 && num_debug_info_entries
== 0
2808 && debug_info_p
!= NULL
)
2812 case DW_AT_loclists_base
:
2813 if (debug_info_p
->loclists_base
)
2814 warn (_("CU @ 0x%s has multiple loclists_base values"),
2815 dwarf_vmatoa ("x", debug_info_p
->cu_offset
));
2816 debug_info_p
->loclists_base
= uvalue
;
2819 case DW_AT_frame_base
:
2820 have_frame_base
= 1;
2822 case DW_AT_location
:
2823 case DW_AT_GNU_locviews
:
2824 case DW_AT_string_length
:
2825 case DW_AT_return_addr
:
2826 case DW_AT_data_member_location
:
2827 case DW_AT_vtable_elem_location
:
2829 case DW_AT_static_link
:
2830 case DW_AT_use_location
:
2831 case DW_AT_call_value
:
2832 case DW_AT_GNU_call_site_value
:
2833 case DW_AT_call_data_value
:
2834 case DW_AT_GNU_call_site_data_value
:
2835 case DW_AT_call_target
:
2836 case DW_AT_GNU_call_site_target
:
2837 case DW_AT_call_target_clobbered
:
2838 case DW_AT_GNU_call_site_target_clobbered
:
2839 if ((dwarf_version
< 4
2840 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2841 || form
== DW_FORM_sec_offset
2842 || form
== DW_FORM_loclistx
)
2844 /* Process location list. */
2845 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2846 unsigned int num
= debug_info_p
->num_loc_offsets
;
2848 if (lmax
== 0 || num
>= lmax
)
2851 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2852 xcrealloc (debug_info_p
->loc_offsets
,
2853 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2854 debug_info_p
->loc_views
= (dwarf_vma
*)
2855 xcrealloc (debug_info_p
->loc_views
,
2856 lmax
, sizeof (*debug_info_p
->loc_views
));
2857 debug_info_p
->have_frame_base
= (int *)
2858 xcrealloc (debug_info_p
->have_frame_base
,
2859 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2860 debug_info_p
->max_loc_offsets
= lmax
;
2863 if (form
== DW_FORM_loclistx
)
2864 uvalue
= fetch_indexed_value (uvalue
, loclists
);
2865 else if (this_set
!= NULL
)
2866 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2868 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2869 if (attribute
!= DW_AT_GNU_locviews
)
2871 uvalue
+= debug_info_p
->loclists_base
;
2873 /* Corrupt DWARF info can produce more offsets than views.
2874 See PR 23062 for an example. */
2875 if (debug_info_p
->num_loc_offsets
2876 > debug_info_p
->num_loc_views
)
2877 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2880 debug_info_p
->loc_offsets
[num
] = uvalue
;
2881 debug_info_p
->num_loc_offsets
++;
2886 assert (debug_info_p
->num_loc_views
<= num
);
2887 num
= debug_info_p
->num_loc_views
;
2888 if (num
> debug_info_p
->num_loc_offsets
)
2889 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2892 debug_info_p
->loc_views
[num
] = uvalue
;
2893 debug_info_p
->num_loc_views
++;
2900 if (need_base_address
)
2901 debug_info_p
->base_address
= uvalue
;
2904 case DW_AT_GNU_addr_base
:
2905 case DW_AT_addr_base
:
2906 debug_info_p
->addr_base
= uvalue
;
2909 case DW_AT_GNU_ranges_base
:
2910 debug_info_p
->ranges_base
= uvalue
;
2914 if ((dwarf_version
< 4
2915 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2916 || form
== DW_FORM_sec_offset
2917 || form
== DW_FORM_rnglistx
)
2919 /* Process range list. */
2920 unsigned int lmax
= debug_info_p
->max_range_lists
;
2921 unsigned int num
= debug_info_p
->num_range_lists
;
2923 if (lmax
== 0 || num
>= lmax
)
2926 debug_info_p
->range_lists
= (dwarf_vma
*)
2927 xcrealloc (debug_info_p
->range_lists
,
2928 lmax
, sizeof (*debug_info_p
->range_lists
));
2929 debug_info_p
->max_range_lists
= lmax
;
2932 if (form
== DW_FORM_rnglistx
)
2933 uvalue
= fetch_indexed_value (uvalue
, rnglists
);
2935 debug_info_p
->range_lists
[num
] = uvalue
;
2936 debug_info_p
->num_range_lists
++;
2940 case DW_AT_GNU_dwo_name
:
2941 case DW_AT_dwo_name
:
2946 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2948 case DW_FORM_GNU_strp_alt
:
2949 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2951 case DW_FORM_GNU_str_index
:
2957 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2959 case DW_FORM_string
:
2960 add_dwo_name ((const char *) orig_data
, cu_offset
);
2963 warn (_("Unsupported form (%s) for attribute %s\n"),
2964 get_FORM_name (form
), get_AT_name (attribute
));
2969 case DW_AT_comp_dir
:
2970 /* FIXME: Also extract a build-id in a CU/TU. */
2975 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2977 case DW_FORM_GNU_strp_alt
:
2978 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2980 case DW_FORM_line_strp
:
2981 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2983 case DW_FORM_GNU_str_index
:
2989 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2991 case DW_FORM_string
:
2992 add_dwo_dir ((const char *) orig_data
, cu_offset
);
2995 warn (_("Unsupported form (%s) for attribute %s\n"),
2996 get_FORM_name (form
), get_AT_name (attribute
));
3001 case DW_AT_GNU_dwo_id
:
3006 /* FIXME: Record the length of the ID as well ? */
3007 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3010 warn (_("Unsupported form (%s) for attribute %s\n"),
3011 get_FORM_name (form
), get_AT_name (attribute
));
3021 if (do_loc
|| attribute
== 0)
3024 /* For some attributes we can display further information. */
3028 if (level
>= 0 && level
< MAX_CU_NESTING
3029 && uvalue
< (size_t) (end
- start
))
3031 bool is_signed
= false;
3032 abbrev_entry
*type_abbrev
;
3033 unsigned char *type_data
;
3036 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3040 if (type_abbrev
!= NULL
)
3042 get_type_signedness (type_abbrev
, section
, type_data
,
3043 map
? section
->start
+ map
->end
: end
,
3044 map
? map
->start
: cu_offset
,
3045 pointer_size
, offset_size
, dwarf_version
,
3048 level_type_signed
[level
] = is_signed
;
3056 case DW_INL_not_inlined
:
3057 printf (_("(not inlined)"));
3059 case DW_INL_inlined
:
3060 printf (_("(inlined)"));
3062 case DW_INL_declared_not_inlined
:
3063 printf (_("(declared as inline but ignored)"));
3065 case DW_INL_declared_inlined
:
3066 printf (_("(declared as inline and inlined)"));
3069 printf (_(" (Unknown inline attribute value: %s)"),
3070 dwarf_vmatoa ("x", uvalue
));
3075 case DW_AT_language
:
3079 /* Ordered by the numeric value of these constants. */
3080 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3081 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3082 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3083 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3084 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3085 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3086 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3087 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3088 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3089 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3090 /* DWARF 2.1 values. */
3091 case DW_LANG_Java
: printf ("(Java)"); break;
3092 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3093 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3094 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3095 /* DWARF 3 values. */
3096 case DW_LANG_PLI
: printf ("(PLI)"); break;
3097 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3098 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3099 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3100 case DW_LANG_D
: printf ("(D)"); break;
3101 /* DWARF 4 values. */
3102 case DW_LANG_Python
: printf ("(Python)"); break;
3103 /* DWARF 5 values. */
3104 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3105 case DW_LANG_Go
: printf ("(Go)"); break;
3106 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3107 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3108 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3109 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3110 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3111 case DW_LANG_Rust
: printf ("(Rust)"); break;
3112 case DW_LANG_C11
: printf ("(C11)"); break;
3113 case DW_LANG_Swift
: printf ("(Swift)"); break;
3114 case DW_LANG_Julia
: printf ("(Julia)"); break;
3115 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3116 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3117 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3118 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3119 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3120 /* MIPS extension. */
3121 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3122 /* UPC extension. */
3123 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3125 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3126 printf (_("(implementation defined: %s)"),
3127 dwarf_vmatoa ("x", uvalue
));
3129 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3134 case DW_AT_encoding
:
3138 case DW_ATE_void
: printf ("(void)"); break;
3139 case DW_ATE_address
: printf ("(machine address)"); break;
3140 case DW_ATE_boolean
: printf ("(boolean)"); break;
3141 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3142 case DW_ATE_float
: printf ("(float)"); break;
3143 case DW_ATE_signed
: printf ("(signed)"); break;
3144 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3145 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3146 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3147 /* DWARF 2.1 values: */
3148 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3149 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3150 /* DWARF 3 values: */
3151 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3152 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3153 case DW_ATE_edited
: printf ("(edited)"); break;
3154 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3155 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3156 /* DWARF 4 values: */
3157 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3158 /* DWARF 5 values: */
3159 case DW_ATE_UCS
: printf ("(UCS)"); break;
3160 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3162 /* HP extensions: */
3163 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3164 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3165 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3166 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3167 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3168 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3169 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3172 if (uvalue
>= DW_ATE_lo_user
3173 && uvalue
<= DW_ATE_hi_user
)
3174 printf (_("(user defined type)"));
3176 printf (_("(unknown type)"));
3181 case DW_AT_accessibility
:
3185 case DW_ACCESS_public
: printf ("(public)"); break;
3186 case DW_ACCESS_protected
: printf ("(protected)"); break;
3187 case DW_ACCESS_private
: printf ("(private)"); break;
3189 printf (_("(unknown accessibility)"));
3194 case DW_AT_visibility
:
3198 case DW_VIS_local
: printf ("(local)"); break;
3199 case DW_VIS_exported
: printf ("(exported)"); break;
3200 case DW_VIS_qualified
: printf ("(qualified)"); break;
3201 default: printf (_("(unknown visibility)")); break;
3205 case DW_AT_endianity
:
3209 case DW_END_default
: printf ("(default)"); break;
3210 case DW_END_big
: printf ("(big)"); break;
3211 case DW_END_little
: printf ("(little)"); break;
3213 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3214 printf (_("(user specified)"));
3216 printf (_("(unknown endianity)"));
3221 case DW_AT_virtuality
:
3225 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3226 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3227 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3228 default: printf (_("(unknown virtuality)")); break;
3232 case DW_AT_identifier_case
:
3236 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3237 case DW_ID_up_case
: printf ("(up_case)"); break;
3238 case DW_ID_down_case
: printf ("(down_case)"); break;
3239 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3240 default: printf (_("(unknown case)")); break;
3244 case DW_AT_calling_convention
:
3248 case DW_CC_normal
: printf ("(normal)"); break;
3249 case DW_CC_program
: printf ("(program)"); break;
3250 case DW_CC_nocall
: printf ("(nocall)"); break;
3251 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3252 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3253 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3254 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3256 if (uvalue
>= DW_CC_lo_user
3257 && uvalue
<= DW_CC_hi_user
)
3258 printf (_("(user defined)"));
3260 printf (_("(unknown convention)"));
3264 case DW_AT_ordering
:
3269 case -1: printf (_("(undefined)")); break;
3270 case 0: printf ("(row major)"); break;
3271 case 1: printf ("(column major)"); break;
3275 case DW_AT_decimal_sign
:
3279 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3280 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3281 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3282 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3283 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3284 default: printf (_("(unrecognised)")); break;
3288 case DW_AT_defaulted
:
3292 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3293 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3294 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3295 default: printf (_("(unrecognised)")); break;
3299 case DW_AT_discr_list
:
3301 display_discr_list (form
, uvalue
, data
, level
);
3304 case DW_AT_frame_base
:
3305 have_frame_base
= 1;
3307 case DW_AT_location
:
3308 case DW_AT_loclists_base
:
3309 case DW_AT_string_length
:
3310 case DW_AT_return_addr
:
3311 case DW_AT_data_member_location
:
3312 case DW_AT_vtable_elem_location
:
3314 case DW_AT_static_link
:
3315 case DW_AT_use_location
:
3316 case DW_AT_call_value
:
3317 case DW_AT_GNU_call_site_value
:
3318 case DW_AT_call_data_value
:
3319 case DW_AT_GNU_call_site_data_value
:
3320 case DW_AT_call_target
:
3321 case DW_AT_GNU_call_site_target
:
3322 case DW_AT_call_target_clobbered
:
3323 case DW_AT_GNU_call_site_target_clobbered
:
3324 if ((dwarf_version
< 4
3325 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3326 || form
== DW_FORM_sec_offset
3327 || form
== DW_FORM_loclistx
)
3328 printf (_(" (location list)"));
3330 case DW_AT_allocated
:
3331 case DW_AT_associated
:
3332 case DW_AT_data_location
:
3334 case DW_AT_upper_bound
:
3335 case DW_AT_lower_bound
:
3338 int need_frame_base
;
3341 need_frame_base
= decode_location_expression (block_start
,
3346 cu_offset
, section
);
3348 if (need_frame_base
&& !have_frame_base
)
3349 printf (_(" [without DW_AT_frame_base]"));
3353 case DW_AT_data_bit_offset
:
3354 case DW_AT_byte_size
:
3355 case DW_AT_bit_size
:
3356 case DW_AT_string_length_byte_size
:
3357 case DW_AT_string_length_bit_size
:
3358 case DW_AT_bit_stride
:
3359 if (form
== DW_FORM_exprloc
)
3362 (void) decode_location_expression (block_start
, pointer_size
,
3363 offset_size
, dwarf_version
,
3364 uvalue
, cu_offset
, section
);
3371 unsigned long abbrev_number
;
3372 abbrev_entry
*entry
;
3374 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3375 section
, & abbrev_number
, NULL
, NULL
);
3378 if (form
!= DW_FORM_GNU_ref_alt
)
3379 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3380 dwarf_vmatoa ("x", uvalue
),
3381 (unsigned long) (orig_data
- section
->start
));
3385 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3386 printf (" (%s)", get_TAG_name (entry
->tag
));
3399 static unsigned char *
3400 read_and_display_attr (unsigned long attribute
,
3402 dwarf_signed_vma implicit_const
,
3403 unsigned char * start
,
3404 unsigned char * data
,
3405 unsigned char * end
,
3406 dwarf_vma cu_offset
,
3407 dwarf_vma pointer_size
,
3408 dwarf_vma offset_size
,
3410 debug_info
* debug_info_p
,
3412 struct dwarf_section
* section
,
3413 struct cu_tu_set
* this_set
,
3417 printf (" %-18s:", get_AT_name (attribute
));
3418 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3420 cu_offset
, pointer_size
, offset_size
,
3421 dwarf_version
, debug_info_p
,
3422 do_loc
, section
, this_set
, ' ', level
);
3428 /* Like load_debug_section, but if the ordinary call fails, and we are
3429 following debug links, then attempt to load the requested section
3430 from one of the separate debug info files. */
3433 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3436 if (load_debug_section (sec_enum
, handle
))
3438 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3440 /* See if we can associate a filename with this section. */
3443 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3444 if (i
->handle
== handle
)
3446 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3454 if (do_follow_links
)
3458 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3460 if (load_debug_section (sec_enum
, i
->handle
))
3462 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3464 /* FIXME: We should check to see if any of the remaining debug info
3465 files also contain this section, and, umm, do something about it. */
3475 introduce (struct dwarf_section
* section
, bool raw
)
3479 if (do_follow_links
&& section
->filename
)
3480 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3481 section
->name
, section
->filename
);
3483 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3487 if (do_follow_links
&& section
->filename
)
3488 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3489 section
->name
, section
->filename
);
3491 printf (_("Contents of the %s section:\n\n"), section
->name
);
3495 /* Process the contents of a .debug_info section.
3496 If do_loc is TRUE then we are scanning for location lists and dwo tags
3497 and we do not want to display anything to the user.
3498 If do_types is TRUE, we are processing a .debug_types section instead of
3499 a .debug_info section.
3500 The information displayed is restricted by the values in DWARF_START_DIE
3501 and DWARF_CUTOFF_LEVEL.
3502 Returns TRUE upon success. Otherwise an error or warning message is
3503 printed and FALSE is returned. */
3506 process_debug_info (struct dwarf_section
* section
,
3508 enum dwarf_section_display_enum abbrev_sec
,
3512 unsigned char *start
= section
->start
;
3513 unsigned char *end
= start
+ section
->size
;
3514 unsigned char *section_begin
;
3516 unsigned int num_units
= 0;
3518 /* First scan the section to get the number of comp units.
3519 Length sanity checks are done here. */
3520 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3525 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3526 will be the length. For a 64-bit DWARF section, it'll be
3527 the escape code 0xffffffff followed by an 8 byte length. */
3528 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3530 if (length
== 0xffffffff)
3531 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3532 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3534 warn (_("Reserved length value (0x%s) found in section %s\n"),
3535 dwarf_vmatoa ("x", length
), section
->name
);
3539 /* Negative values are illegal, they may even cause infinite
3540 looping. This can happen if we can't accurately apply
3541 relocations to an object file, or if the file is corrupt. */
3542 if (length
> (size_t) (end
- section_begin
))
3544 warn (_("Corrupt unit length (got 0x%s expected at most 0x%s) in section %s\n"),
3545 dwarf_vmatoa ("x", length
),
3546 dwarf_vmatoa ("x", end
- section_begin
),
3550 section_begin
+= length
;
3555 error (_("No comp units in %s section ?\n"), section
->name
);
3559 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3560 && num_debug_info_entries
== 0
3564 /* Then allocate an array to hold the information. */
3565 debug_information
= (debug_info
*) cmalloc (num_units
,
3566 sizeof (* debug_information
));
3567 if (debug_information
== NULL
)
3569 error (_("Not enough memory for a debug info array of %u entries\n"),
3571 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3575 /* PR 17531: file: 92ca3797.
3576 We cannot rely upon the debug_information array being initialised
3577 before it is used. A corrupt file could easily contain references
3578 to a unit for which information has not been made available. So
3579 we ensure that the array is zeroed here. */
3580 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3582 alloc_num_debug_info_entries
= num_units
;
3587 load_debug_section_with_follow (str
, file
);
3588 load_debug_section_with_follow (line_str
, file
);
3589 load_debug_section_with_follow (str_dwo
, file
);
3590 load_debug_section_with_follow (str_index
, file
);
3591 load_debug_section_with_follow (str_index_dwo
, file
);
3592 load_debug_section_with_follow (debug_addr
, file
);
3595 load_debug_section_with_follow (abbrev_sec
, file
);
3596 load_debug_section_with_follow (loclists
, file
);
3597 load_debug_section_with_follow (rnglists
, file
);
3599 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3601 warn (_("Unable to locate %s section!\n"),
3602 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3606 if (!do_loc
&& dwarf_start_die
== 0)
3607 introduce (section
, false);
3609 free_all_abbrevs ();
3610 free (cu_abbrev_map
);
3611 cu_abbrev_map
= NULL
;
3612 next_free_abbrev_map_entry
= 0;
3614 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3615 to load *all* of the abbrevs for all CUs in this .debug_info
3616 section. This does effectively mean that we (partially) read
3617 every CU header twice. */
3618 for (section_begin
= start
; start
< end
;)
3620 DWARF2_Internal_CompUnit compunit
;
3621 unsigned char * hdrptr
;
3622 dwarf_vma abbrev_base
;
3624 dwarf_vma cu_offset
;
3625 unsigned int offset_size
;
3626 struct cu_tu_set
* this_set
;
3628 unsigned char *end_cu
;
3631 cu_offset
= start
- section_begin
;
3633 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3635 if (compunit
.cu_length
== 0xffffffff)
3637 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3642 end_cu
= hdrptr
+ compunit
.cu_length
;
3644 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3646 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3648 if (compunit
.cu_version
< 5)
3650 compunit
.cu_unit_type
= DW_UT_compile
;
3651 /* Initialize it due to a false compiler warning. */
3652 compunit
.cu_pointer_size
= -1;
3656 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3657 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3659 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3662 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3665 if (compunit
.cu_unit_type
== DW_UT_split_compile
3666 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3669 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3672 if (this_set
== NULL
)
3675 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3679 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3680 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3683 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3684 compunit
.cu_abbrev_offset
);
3687 unsigned char * next
;
3689 list
= new_abbrev_list (abbrev_base
,
3690 compunit
.cu_abbrev_offset
);
3691 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3692 abbrev_base
, abbrev_size
,
3693 compunit
.cu_abbrev_offset
, list
);
3694 list
->start_of_next_abbrevs
= next
;
3698 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3701 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3703 DWARF2_Internal_CompUnit compunit
;
3704 unsigned char *hdrptr
;
3705 unsigned char *tags
;
3706 int level
, last_level
, saved_level
;
3707 dwarf_vma cu_offset
;
3708 unsigned int offset_size
;
3709 dwarf_vma signature
= 0;
3710 dwarf_vma type_offset
= 0;
3711 struct cu_tu_set
*this_set
;
3712 dwarf_vma abbrev_base
;
3714 abbrev_list
* list
= NULL
;
3715 unsigned char *end_cu
;
3718 cu_offset
= start
- section_begin
;
3720 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3722 if (compunit
.cu_length
== 0xffffffff)
3724 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3729 end_cu
= hdrptr
+ compunit
.cu_length
;
3731 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3733 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3735 if (compunit
.cu_version
< 5)
3737 compunit
.cu_unit_type
= DW_UT_compile
;
3738 /* Initialize it due to a false compiler warning. */
3739 compunit
.cu_pointer_size
= -1;
3743 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3744 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3746 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3749 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3751 if (this_set
== NULL
)
3754 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3758 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3759 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3762 if (compunit
.cu_version
< 5)
3763 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3765 bool do_dwo_id
= false;
3766 uint64_t dwo_id
= 0;
3767 if (compunit
.cu_unit_type
== DW_UT_split_compile
3768 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3770 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3774 /* PR 17512: file: 001-108546-0.001:0.1. */
3775 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3777 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3778 compunit
.cu_pointer_size
, offset_size
);
3779 compunit
.cu_pointer_size
= offset_size
;
3784 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3785 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3788 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3794 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3795 && num_debug_info_entries
== 0
3796 && alloc_num_debug_info_entries
> unit
3799 debug_information
[unit
].cu_offset
= cu_offset
;
3800 debug_information
[unit
].pointer_size
3801 = compunit
.cu_pointer_size
;
3802 debug_information
[unit
].offset_size
= offset_size
;
3803 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3804 debug_information
[unit
].base_address
= 0;
3805 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3806 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3807 debug_information
[unit
].loc_offsets
= NULL
;
3808 debug_information
[unit
].have_frame_base
= NULL
;
3809 debug_information
[unit
].max_loc_offsets
= 0;
3810 debug_information
[unit
].num_loc_offsets
= 0;
3811 debug_information
[unit
].loclists_base
= 0;
3812 debug_information
[unit
].range_lists
= NULL
;
3813 debug_information
[unit
].max_range_lists
= 0;
3814 debug_information
[unit
].num_range_lists
= 0;
3817 if (!do_loc
&& dwarf_start_die
== 0)
3819 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3820 dwarf_vmatoa ("x", cu_offset
));
3821 printf (_(" Length: 0x%s (%s)\n"),
3822 dwarf_vmatoa ("x", compunit
.cu_length
),
3823 offset_size
== 8 ? "64-bit" : "32-bit");
3824 printf (_(" Version: %d\n"), compunit
.cu_version
);
3825 if (compunit
.cu_version
>= 5)
3827 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3829 printf (_(" Unit Type: %s (%x)\n"),
3830 name
? name
: "???",
3831 compunit
.cu_unit_type
);
3833 printf (_(" Abbrev Offset: 0x%s\n"),
3834 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3835 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3838 printf (_(" Signature: 0x%s\n"),
3839 dwarf_vmatoa ("x", signature
));
3840 printf (_(" Type Offset: 0x%s\n"),
3841 dwarf_vmatoa ("x", type_offset
));
3844 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3845 if (this_set
!= NULL
)
3847 dwarf_vma
*offsets
= this_set
->section_offsets
;
3848 size_t *sizes
= this_set
->section_sizes
;
3850 printf (_(" Section contributions:\n"));
3851 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3852 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3853 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3854 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3855 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3856 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3857 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3858 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3859 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3860 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3861 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3862 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3869 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3871 warn (_("CU at offset %s contains corrupt or "
3872 "unsupported version number: %d.\n"),
3873 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3877 if (compunit
.cu_unit_type
!= DW_UT_compile
3878 && compunit
.cu_unit_type
!= DW_UT_partial
3879 && compunit
.cu_unit_type
!= DW_UT_type
3880 && compunit
.cu_unit_type
!= DW_UT_split_compile
3881 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3883 warn (_("CU at offset %s contains corrupt or "
3884 "unsupported unit type: %d.\n"),
3885 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3889 /* Process the abbrevs used by this compilation unit. */
3890 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3891 compunit
.cu_abbrev_offset
);
3894 unsigned char *next
;
3896 list
= new_abbrev_list (abbrev_base
,
3897 compunit
.cu_abbrev_offset
);
3898 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3899 abbrev_base
, abbrev_size
,
3900 compunit
.cu_abbrev_offset
, list
);
3901 list
->start_of_next_abbrevs
= next
;
3907 while (tags
< start
)
3909 unsigned long abbrev_number
;
3910 unsigned long die_offset
;
3911 abbrev_entry
*entry
;
3913 int do_printing
= 1;
3915 die_offset
= tags
- section_begin
;
3917 READ_ULEB (abbrev_number
, tags
, start
);
3919 /* A null DIE marks the end of a list of siblings or it may also be
3920 a section padding. */
3921 if (abbrev_number
== 0)
3923 /* Check if it can be a section padding for the last CU. */
3924 if (level
== 0 && start
== end
)
3928 for (chk
= tags
; chk
< start
; chk
++)
3935 if (!do_loc
&& die_offset
>= dwarf_start_die
3936 && (dwarf_cutoff_level
== -1
3937 || level
< dwarf_cutoff_level
))
3938 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3944 static unsigned num_bogus_warns
= 0;
3946 if (num_bogus_warns
< 3)
3948 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3949 die_offset
, section
->name
);
3951 if (num_bogus_warns
== 3)
3952 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3955 if (dwarf_start_die
!= 0 && level
< saved_level
)
3962 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3966 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3967 saved_level
= level
;
3968 do_printing
= (dwarf_cutoff_level
== -1
3969 || level
< dwarf_cutoff_level
);
3971 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3972 level
, die_offset
, abbrev_number
);
3973 else if (dwarf_cutoff_level
== -1
3974 || last_level
< dwarf_cutoff_level
)
3975 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3980 /* Scan through the abbreviation list until we reach the
3985 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3986 if (entry
->number
== abbrev_number
)
3991 if (!do_loc
&& do_printing
)
3996 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3997 die_offset
, abbrev_number
);
4001 if (!do_loc
&& do_printing
)
4002 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4007 need_base_address
= 0;
4009 case DW_TAG_compile_unit
:
4010 need_base_address
= 1;
4011 need_dwo_info
= do_loc
;
4013 case DW_TAG_entry_point
:
4014 case DW_TAG_subprogram
:
4015 need_base_address
= 0;
4016 /* Assuming that there is no DW_AT_frame_base. */
4017 have_frame_base
= 0;
4021 debug_info
*debug_info_p
=
4022 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4023 ? debug_information
+ unit
: NULL
;
4025 assert (!debug_info_p
4026 || (debug_info_p
->num_loc_offsets
4027 == debug_info_p
->num_loc_views
));
4029 for (attr
= entry
->first_attr
;
4030 attr
&& attr
->attribute
;
4033 if (! do_loc
&& do_printing
)
4034 /* Show the offset from where the tag was extracted. */
4035 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
4036 tags
= read_and_display_attr (attr
->attribute
,
4038 attr
->implicit_const
,
4043 compunit
.cu_pointer_size
,
4045 compunit
.cu_version
,
4047 do_loc
|| ! do_printing
,
4053 /* If a locview attribute appears before a location one,
4054 make sure we don't associate it with an earlier
4057 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4060 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4061 debug_info_p
->num_loc_views
++;
4062 assert (debug_info_p
->num_loc_views
4063 == debug_info_p
->num_loc_offsets
);
4070 warn(_("DIE has locviews without loclist\n"));
4071 debug_info_p
->num_loc_views
--;
4078 if (entry
->children
)
4083 /* Set num_debug_info_entries here so that it can be used to check if
4084 we need to process .debug_loc and .debug_ranges sections. */
4085 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4086 && num_debug_info_entries
== 0
4089 if (num_units
> alloc_num_debug_info_entries
)
4090 num_debug_info_entries
= alloc_num_debug_info_entries
;
4092 num_debug_info_entries
= num_units
;
4101 /* Locate and scan the .debug_info section in the file and record the pointer
4102 sizes and offsets for the compilation units in it. Usually an executable
4103 will have just one pointer size, but this is not guaranteed, and so we try
4104 not to make any assumptions. Returns zero upon failure, or the number of
4105 compilation units upon success. */
4108 load_debug_info (void * file
)
4110 /* If we have already tried and failed to load the .debug_info
4111 section then do not bother to repeat the task. */
4112 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4115 /* If we already have the information there is nothing else to do. */
4116 if (num_debug_info_entries
> 0)
4117 return num_debug_info_entries
;
4119 /* If this is a DWARF package file, load the CU and TU indexes. */
4120 (void) load_cu_tu_indexes (file
);
4122 if (load_debug_section_with_follow (info
, file
)
4123 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4124 return num_debug_info_entries
;
4126 if (load_debug_section_with_follow (info_dwo
, file
)
4127 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4128 abbrev_dwo
, true, false))
4129 return num_debug_info_entries
;
4131 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4135 /* Read a DWARF .debug_line section header starting at DATA.
4136 Upon success returns an updated DATA pointer and the LINFO
4137 structure and the END_OF_SEQUENCE pointer will be filled in.
4138 Otherwise returns NULL. */
4140 static unsigned char *
4141 read_debug_line_header (struct dwarf_section
* section
,
4142 unsigned char * data
,
4143 unsigned char * end
,
4144 DWARF2_Internal_LineInfo
* linfo
,
4145 unsigned char ** end_of_sequence
)
4147 unsigned char *hdrptr
;
4149 /* Extract information from the Line Number Program Header.
4150 (section 6.2.4 in the Dwarf3 doc). */
4153 /* Get and check the length of the block. */
4154 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4156 if (linfo
->li_length
== 0xffffffff)
4158 /* This section is 64-bit DWARF 3. */
4159 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4160 linfo
->li_offset_size
= 8;
4163 linfo
->li_offset_size
= 4;
4165 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4167 /* If the length field has a relocation against it, then we should
4168 not complain if it is inaccurate (and probably negative). This
4169 happens in object files when the .debug_line section is actually
4170 comprised of several different .debug_line.* sections, (some of
4171 which may be removed by linker garbage collection), and a relocation
4172 is used to compute the correct length once that is done. */
4173 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4175 linfo
->li_length
= end
- hdrptr
;
4179 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4180 (long) linfo
->li_length
);
4184 end
= hdrptr
+ linfo
->li_length
;
4186 /* Get and check the version number. */
4187 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4189 if (linfo
->li_version
!= 2
4190 && linfo
->li_version
!= 3
4191 && linfo
->li_version
!= 4
4192 && linfo
->li_version
!= 5)
4194 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4195 "is currently supported.\n"));
4199 if (linfo
->li_version
>= 5)
4201 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4203 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4204 if (linfo
->li_segment_size
!= 0)
4206 warn (_("The %s section contains "
4207 "unsupported segment selector size: %d.\n"),
4208 section
->name
, linfo
->li_segment_size
);
4213 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4214 linfo
->li_offset_size
, end
);
4215 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4217 if (linfo
->li_version
>= 4)
4219 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4221 if (linfo
->li_max_ops_per_insn
== 0)
4223 warn (_("Invalid maximum operations per insn.\n"));
4228 linfo
->li_max_ops_per_insn
= 1;
4230 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4231 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4232 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4233 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4235 *end_of_sequence
= end
;
4239 static unsigned char *
4240 display_formatted_table (unsigned char *data
,
4241 unsigned char *start
,
4243 const DWARF2_Internal_LineInfo
*linfo
,
4244 struct dwarf_section
*section
,
4247 unsigned char *format_start
, format_count
, *format
, formati
;
4248 dwarf_vma data_count
, datai
;
4249 unsigned int namepass
, last_entry
= 0;
4250 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4252 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4253 if (do_checks
&& format_count
> 5)
4254 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4255 table_name
, format_count
);
4257 format_start
= data
;
4258 for (formati
= 0; formati
< format_count
; formati
++)
4260 SKIP_ULEB (data
, end
);
4261 SKIP_ULEB (data
, end
);
4264 warn (_("%s: Corrupt format description entry\n"), table_name
);
4269 READ_ULEB (data_count
, data
, end
);
4270 if (data_count
== 0)
4272 printf (_("\n The %s is empty.\n"), table_name
);
4275 else if (data
>= end
)
4277 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4278 table_name
, dwarf_vmatoa ("x", data_count
));
4282 else if (format_count
== 0)
4284 warn (_("%s: format count is zero, but the table is not empty\n"),
4289 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4290 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4293 printf (_(" Entry"));
4294 /* Delay displaying name as the last entry for better screen layout. */
4295 for (namepass
= 0; namepass
< 2; namepass
++)
4297 format
= format_start
;
4298 for (formati
= 0; formati
< format_count
; formati
++)
4300 dwarf_vma content_type
;
4302 READ_ULEB (content_type
, format
, end
);
4303 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4304 switch (content_type
)
4307 printf (_("\tName"));
4309 case DW_LNCT_directory_index
:
4310 printf (_("\tDir"));
4312 case DW_LNCT_timestamp
:
4313 printf (_("\tTime"));
4316 printf (_("\tSize"));
4319 printf (_("\tMD5\t\t\t"));
4322 printf (_("\t(Unknown format content type %s)"),
4323 dwarf_vmatoa ("u", content_type
));
4325 SKIP_ULEB (format
, end
);
4330 for (datai
= 0; datai
< data_count
; datai
++)
4332 unsigned char *datapass
= data
;
4334 printf (" %d", last_entry
++);
4335 /* Delay displaying name as the last entry for better screen layout. */
4336 for (namepass
= 0; namepass
< 2; namepass
++)
4338 format
= format_start
;
4340 for (formati
= 0; formati
< format_count
; formati
++)
4342 dwarf_vma content_type
, form
;
4344 READ_ULEB (content_type
, format
, end
);
4345 READ_ULEB (form
, format
, end
);
4346 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4347 0, 0, linfo
->li_offset_size
,
4348 linfo
->li_version
, NULL
,
4349 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4350 section
, NULL
, '\t', -1);
4354 if (data
>= end
&& (datai
< data_count
- 1))
4356 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4365 display_debug_sup (struct dwarf_section
* section
,
4366 void * file ATTRIBUTE_UNUSED
)
4368 unsigned char * start
= section
->start
;
4369 unsigned char * end
= section
->start
+ section
->size
;
4370 unsigned int version
;
4371 char is_supplementary
;
4372 const unsigned char * sup_filename
;
4373 size_t sup_filename_len
;
4374 unsigned int num_read
;
4376 dwarf_vma checksum_len
;
4379 introduce (section
, true);
4380 if (section
->size
< 4)
4382 error (_("corrupt .debug_sup section: size is too small\n"));
4386 /* Read the data. */
4387 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4389 warn (_("corrupt .debug_sup section: version < 5"));
4391 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4392 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4393 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4395 sup_filename
= start
;
4396 if (is_supplementary
&& sup_filename
[0] != 0)
4397 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4399 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4400 if (sup_filename_len
== (size_t) (end
- start
))
4402 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4405 start
+= sup_filename_len
+ 1;
4407 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4410 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4414 if (checksum_len
> (dwarf_vma
) (end
- start
))
4416 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4417 checksum_len
= end
- start
;
4419 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4421 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4422 (long) ((end
- start
) - checksum_len
));
4425 printf (_(" Version: %u\n"), version
);
4426 printf (_(" Is Supp: %u\n"), is_supplementary
);
4427 printf (_(" Filename: %s\n"), sup_filename
);
4428 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4429 if (checksum_len
> 0)
4431 printf (_(" Checksum: "));
4432 while (checksum_len
--)
4433 printf ("0x%x ", * start
++ );
4440 display_debug_lines_raw (struct dwarf_section
* section
,
4441 unsigned char * data
,
4442 unsigned char * end
,
4445 unsigned char *start
= section
->start
;
4446 int verbose_view
= 0;
4448 introduce (section
, true);
4452 static DWARF2_Internal_LineInfo saved_linfo
;
4453 DWARF2_Internal_LineInfo linfo
;
4454 unsigned char *standard_opcodes
;
4455 unsigned char *end_of_sequence
;
4458 if (startswith (section
->name
, ".debug_line.")
4459 /* Note: the following does not apply to .debug_line.dwo sections.
4460 These are full debug_line sections. */
4461 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4463 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4464 section containing just the Line Number Statements. They are
4465 created by the assembler and intended to be used alongside gcc's
4466 -ffunction-sections command line option. When the linker's
4467 garbage collection decides to discard a .text.<foo> section it
4468 can then also discard the line number information in .debug_line.<foo>.
4470 Since the section is a fragment it does not have the details
4471 needed to fill out a LineInfo structure, so instead we use the
4472 details from the last full debug_line section that we processed. */
4473 end_of_sequence
= end
;
4474 standard_opcodes
= NULL
;
4475 linfo
= saved_linfo
;
4476 /* PR 17531: file: 0522b371. */
4477 if (linfo
.li_line_range
== 0)
4479 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4482 reset_state_machine (linfo
.li_default_is_stmt
);
4486 unsigned char * hdrptr
;
4488 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4489 & end_of_sequence
)) == NULL
)
4492 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4493 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4494 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4495 if (linfo
.li_version
>= 5)
4497 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4498 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4500 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4501 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4502 if (linfo
.li_version
>= 4)
4503 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4504 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4505 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4506 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4507 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4509 /* PR 17512: file: 1665-6428-0.004. */
4510 if (linfo
.li_line_range
== 0)
4512 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4513 linfo
.li_line_range
= 1;
4516 reset_state_machine (linfo
.li_default_is_stmt
);
4518 /* Display the contents of the Opcodes table. */
4519 standard_opcodes
= hdrptr
;
4521 /* PR 17512: file: 002-417945-0.004. */
4522 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4524 warn (_("Line Base extends beyond end of section\n"));
4528 printf (_("\n Opcodes:\n"));
4530 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4531 printf (ngettext (" Opcode %d has %d arg\n",
4532 " Opcode %d has %d args\n",
4533 standard_opcodes
[i
- 1]),
4534 i
, standard_opcodes
[i
- 1]);
4536 /* Display the contents of the Directory table. */
4537 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4539 if (linfo
.li_version
>= 5)
4541 load_debug_section_with_follow (line_str
, file
);
4543 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4545 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4551 printf (_("\n The Directory Table is empty.\n"));
4554 unsigned int last_dir_entry
= 0;
4556 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4557 (long)(data
- start
));
4559 while (data
< end
&& *data
!= 0)
4561 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4563 data
+= strnlen ((char *) data
, end
- data
);
4568 /* PR 17512: file: 002-132094-0.004. */
4569 if (data
>= end
- 1)
4573 /* Skip the NUL at the end of the table. */
4577 /* Display the contents of the File Name table. */
4578 if (data
>= end
|| *data
== 0)
4579 printf (_("\n The File Name Table is empty.\n"));
4582 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4583 (long)(data
- start
));
4584 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4586 while (data
< end
&& *data
!= 0)
4588 unsigned char *name
;
4591 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4593 data
+= strnlen ((char *) data
, end
- data
);
4597 READ_ULEB (val
, data
, end
);
4598 printf ("%s\t", dwarf_vmatoa ("u", val
));
4599 READ_ULEB (val
, data
, end
);
4600 printf ("%s\t", dwarf_vmatoa ("u", val
));
4601 READ_ULEB (val
, data
, end
);
4602 printf ("%s\t", dwarf_vmatoa ("u", val
));
4603 printf ("%.*s\n", (int)(end
- name
), name
);
4607 warn (_("Corrupt file name table entry\n"));
4613 /* Skip the NUL at the end of the table. */
4619 saved_linfo
= linfo
;
4622 /* Now display the statements. */
4623 if (data
>= end_of_sequence
)
4624 printf (_(" No Line Number Statements.\n"));
4627 printf (_(" Line Number Statements:\n"));
4629 while (data
< end_of_sequence
)
4631 unsigned char op_code
;
4632 dwarf_signed_vma adv
;
4635 printf (" [0x%08lx]", (long)(data
- start
));
4639 if (op_code
>= linfo
.li_opcode_base
)
4641 op_code
-= linfo
.li_opcode_base
;
4642 uladv
= (op_code
/ linfo
.li_line_range
);
4643 if (linfo
.li_max_ops_per_insn
== 1)
4645 uladv
*= linfo
.li_min_insn_length
;
4646 state_machine_regs
.address
+= uladv
;
4648 state_machine_regs
.view
= 0;
4649 printf (_(" Special opcode %d: "
4650 "advance Address by %s to 0x%s%s"),
4651 op_code
, dwarf_vmatoa ("u", uladv
),
4652 dwarf_vmatoa ("x", state_machine_regs
.address
),
4653 verbose_view
&& uladv
4654 ? _(" (reset view)") : "");
4659 = ((state_machine_regs
.op_index
+ uladv
)
4660 / linfo
.li_max_ops_per_insn
)
4661 * linfo
.li_min_insn_length
;
4663 state_machine_regs
.address
+= addrdelta
;
4664 state_machine_regs
.op_index
4665 = (state_machine_regs
.op_index
+ uladv
)
4666 % linfo
.li_max_ops_per_insn
;
4668 state_machine_regs
.view
= 0;
4669 printf (_(" Special opcode %d: "
4670 "advance Address by %s to 0x%s[%d]%s"),
4671 op_code
, dwarf_vmatoa ("u", uladv
),
4672 dwarf_vmatoa ("x", state_machine_regs
.address
),
4673 state_machine_regs
.op_index
,
4674 verbose_view
&& addrdelta
4675 ? _(" (reset view)") : "");
4677 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4678 state_machine_regs
.line
+= adv
;
4679 printf (_(" and Line by %s to %d"),
4680 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4681 if (verbose_view
|| state_machine_regs
.view
)
4682 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4685 state_machine_regs
.view
++;
4690 case DW_LNS_extended_op
:
4691 data
+= process_extended_line_op (data
,
4692 linfo
.li_default_is_stmt
,
4697 printf (_(" Copy"));
4698 if (verbose_view
|| state_machine_regs
.view
)
4699 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4702 state_machine_regs
.view
++;
4705 case DW_LNS_advance_pc
:
4706 READ_ULEB (uladv
, data
, end
);
4707 if (linfo
.li_max_ops_per_insn
== 1)
4709 uladv
*= linfo
.li_min_insn_length
;
4710 state_machine_regs
.address
+= uladv
;
4712 state_machine_regs
.view
= 0;
4713 printf (_(" Advance PC by %s to 0x%s%s\n"),
4714 dwarf_vmatoa ("u", uladv
),
4715 dwarf_vmatoa ("x", state_machine_regs
.address
),
4716 verbose_view
&& uladv
4717 ? _(" (reset view)") : "");
4722 = ((state_machine_regs
.op_index
+ uladv
)
4723 / linfo
.li_max_ops_per_insn
)
4724 * linfo
.li_min_insn_length
;
4725 state_machine_regs
.address
4727 state_machine_regs
.op_index
4728 = (state_machine_regs
.op_index
+ uladv
)
4729 % linfo
.li_max_ops_per_insn
;
4731 state_machine_regs
.view
= 0;
4732 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4733 dwarf_vmatoa ("u", uladv
),
4734 dwarf_vmatoa ("x", state_machine_regs
.address
),
4735 state_machine_regs
.op_index
,
4736 verbose_view
&& addrdelta
4737 ? _(" (reset view)") : "");
4741 case DW_LNS_advance_line
:
4742 READ_SLEB (adv
, data
, end
);
4743 state_machine_regs
.line
+= adv
;
4744 printf (_(" Advance Line by %s to %d\n"),
4745 dwarf_vmatoa ("d", adv
),
4746 state_machine_regs
.line
);
4749 case DW_LNS_set_file
:
4750 READ_ULEB (uladv
, data
, end
);
4751 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4752 dwarf_vmatoa ("u", uladv
));
4753 state_machine_regs
.file
= uladv
;
4756 case DW_LNS_set_column
:
4757 READ_ULEB (uladv
, data
, end
);
4758 printf (_(" Set column to %s\n"),
4759 dwarf_vmatoa ("u", uladv
));
4760 state_machine_regs
.column
= uladv
;
4763 case DW_LNS_negate_stmt
:
4764 adv
= state_machine_regs
.is_stmt
;
4766 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4767 state_machine_regs
.is_stmt
= adv
;
4770 case DW_LNS_set_basic_block
:
4771 printf (_(" Set basic block\n"));
4772 state_machine_regs
.basic_block
= 1;
4775 case DW_LNS_const_add_pc
:
4776 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4777 if (linfo
.li_max_ops_per_insn
)
4779 uladv
*= linfo
.li_min_insn_length
;
4780 state_machine_regs
.address
+= uladv
;
4782 state_machine_regs
.view
= 0;
4783 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4784 dwarf_vmatoa ("u", uladv
),
4785 dwarf_vmatoa ("x", state_machine_regs
.address
),
4786 verbose_view
&& uladv
4787 ? _(" (reset view)") : "");
4792 = ((state_machine_regs
.op_index
+ uladv
)
4793 / linfo
.li_max_ops_per_insn
)
4794 * linfo
.li_min_insn_length
;
4795 state_machine_regs
.address
4797 state_machine_regs
.op_index
4798 = (state_machine_regs
.op_index
+ uladv
)
4799 % linfo
.li_max_ops_per_insn
;
4801 state_machine_regs
.view
= 0;
4802 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4803 dwarf_vmatoa ("u", uladv
),
4804 dwarf_vmatoa ("x", state_machine_regs
.address
),
4805 state_machine_regs
.op_index
,
4806 verbose_view
&& addrdelta
4807 ? _(" (reset view)") : "");
4811 case DW_LNS_fixed_advance_pc
:
4812 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4813 state_machine_regs
.address
+= uladv
;
4814 state_machine_regs
.op_index
= 0;
4815 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4816 dwarf_vmatoa ("u", uladv
),
4817 dwarf_vmatoa ("x", state_machine_regs
.address
));
4818 /* Do NOT reset view. */
4821 case DW_LNS_set_prologue_end
:
4822 printf (_(" Set prologue_end to true\n"));
4825 case DW_LNS_set_epilogue_begin
:
4826 printf (_(" Set epilogue_begin to true\n"));
4829 case DW_LNS_set_isa
:
4830 READ_ULEB (uladv
, data
, end
);
4831 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4835 printf (_(" Unknown opcode %d with operands: "), op_code
);
4837 if (standard_opcodes
!= NULL
)
4838 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4840 READ_ULEB (uladv
, data
, end
);
4841 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4842 i
== 1 ? "" : ", ");
4857 unsigned char *name
;
4858 unsigned int directory_index
;
4859 unsigned int modification_date
;
4860 unsigned int length
;
4863 /* Output a decoded representation of the .debug_line section. */
4866 display_debug_lines_decoded (struct dwarf_section
* section
,
4867 unsigned char * start
,
4868 unsigned char * data
,
4869 unsigned char * end
,
4872 static DWARF2_Internal_LineInfo saved_linfo
;
4874 introduce (section
, false);
4878 /* This loop amounts to one iteration per compilation unit. */
4879 DWARF2_Internal_LineInfo linfo
;
4880 unsigned char *standard_opcodes
;
4881 unsigned char *end_of_sequence
;
4883 File_Entry
*file_table
= NULL
;
4884 unsigned int n_files
= 0;
4885 unsigned char **directory_table
= NULL
;
4886 dwarf_vma n_directories
= 0;
4888 if (startswith (section
->name
, ".debug_line.")
4889 /* Note: the following does not apply to .debug_line.dwo sections.
4890 These are full debug_line sections. */
4891 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4893 /* See comment in display_debug_lines_raw(). */
4894 end_of_sequence
= end
;
4895 standard_opcodes
= NULL
;
4896 linfo
= saved_linfo
;
4897 /* PR 17531: file: 0522b371. */
4898 if (linfo
.li_line_range
== 0)
4900 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4903 reset_state_machine (linfo
.li_default_is_stmt
);
4907 unsigned char *hdrptr
;
4909 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4910 & end_of_sequence
)) == NULL
)
4913 /* PR 17531: file: 0522b371. */
4914 if (linfo
.li_line_range
== 0)
4916 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4917 linfo
.li_line_range
= 1;
4919 reset_state_machine (linfo
.li_default_is_stmt
);
4921 /* Save a pointer to the contents of the Opcodes table. */
4922 standard_opcodes
= hdrptr
;
4924 /* Traverse the Directory table just to count entries. */
4925 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4929 warn (_("opcode base of %d extends beyond end of section\n"),
4930 linfo
.li_opcode_base
);
4934 if (linfo
.li_version
>= 5)
4936 unsigned char *format_start
, format_count
, *format
;
4937 dwarf_vma formati
, entryi
;
4939 load_debug_section_with_follow (line_str
, fileptr
);
4941 /* Skip directories format. */
4942 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4943 if (do_checks
&& format_count
> 1)
4944 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4946 format_start
= data
;
4947 for (formati
= 0; formati
< format_count
; formati
++)
4949 SKIP_ULEB (data
, end
);
4950 SKIP_ULEB (data
, end
);
4953 READ_ULEB (n_directories
, data
, end
);
4956 warn (_("Corrupt directories list\n"));
4960 if (n_directories
== 0)
4961 directory_table
= NULL
;
4963 directory_table
= (unsigned char **)
4964 xmalloc (n_directories
* sizeof (unsigned char *));
4966 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4968 unsigned char **pathp
= &directory_table
[entryi
];
4970 format
= format_start
;
4971 for (formati
= 0; formati
< format_count
; formati
++)
4973 dwarf_vma content_type
, form
;
4976 READ_ULEB (content_type
, format
, end
);
4977 READ_ULEB (form
, format
, end
);
4980 warn (_("Corrupt directories list\n"));
4983 switch (content_type
)
4988 case DW_FORM_string
:
4991 case DW_FORM_line_strp
:
4992 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4994 /* Remove const by the cast. */
4995 *pathp
= (unsigned char *)
4996 fetch_indirect_line_string (uvalue
);
5001 data
= read_and_display_attr_value (0, form
, 0, start
,
5003 linfo
.li_offset_size
,
5010 warn (_("Corrupt directories list\n"));
5015 /* Skip files format. */
5016 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5017 if (do_checks
&& format_count
> 5)
5018 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5020 format_start
= data
;
5021 for (formati
= 0; formati
< format_count
; formati
++)
5023 SKIP_ULEB (data
, end
);
5024 SKIP_ULEB (data
, end
);
5027 READ_ULEB (n_files
, data
, end
);
5028 if (data
>= end
&& n_files
> 0)
5030 warn (_("Corrupt file name list\n"));
5037 file_table
= (File_Entry
*) xcalloc (1, n_files
5038 * sizeof (File_Entry
));
5040 for (entryi
= 0; entryi
< n_files
; entryi
++)
5042 File_Entry
*file
= &file_table
[entryi
];
5044 format
= format_start
;
5045 for (formati
= 0; formati
< format_count
; formati
++)
5047 dwarf_vma content_type
, form
;
5051 READ_ULEB (content_type
, format
, end
);
5052 READ_ULEB (form
, format
, end
);
5055 warn (_("Corrupt file name list\n"));
5058 switch (content_type
)
5063 case DW_FORM_string
:
5066 case DW_FORM_line_strp
:
5067 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5069 /* Remove const by the cast. */
5070 file
->name
= (unsigned char *)
5071 fetch_indirect_line_string (uvalue
);
5075 case DW_LNCT_directory_index
:
5079 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5083 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5088 READ_ULEB (file
->directory_index
, tmp
, end
);
5093 data
= read_and_display_attr_value (0, form
, 0, start
,
5095 linfo
.li_offset_size
,
5102 warn (_("Corrupt file name list\n"));
5111 unsigned char *ptr_directory_table
= data
;
5113 while (data
< end
&& *data
!= 0)
5115 data
+= strnlen ((char *) data
, end
- data
);
5124 warn (_("directory table ends unexpectedly\n"));
5129 /* Go through the directory table again to save the directories. */
5130 directory_table
= (unsigned char **)
5131 xmalloc (n_directories
* sizeof (unsigned char *));
5134 while (*ptr_directory_table
!= 0)
5136 directory_table
[i
] = ptr_directory_table
;
5138 += strlen ((char *) ptr_directory_table
) + 1;
5142 /* Skip the NUL at the end of the table. */
5145 /* Traverse the File Name table just to count the entries. */
5146 if (data
< end
&& *data
!= 0)
5148 unsigned char *ptr_file_name_table
= data
;
5150 while (data
< end
&& *data
!= 0)
5152 /* Skip Name, directory index, last modification
5153 time and length of file. */
5154 data
+= strnlen ((char *) data
, end
- data
);
5157 SKIP_ULEB (data
, end
);
5158 SKIP_ULEB (data
, end
);
5159 SKIP_ULEB (data
, end
);
5165 warn (_("file table ends unexpectedly\n"));
5170 /* Go through the file table again to save the strings. */
5171 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5174 while (*ptr_file_name_table
!= 0)
5176 file_table
[i
].name
= ptr_file_name_table
;
5178 += strlen ((char *) ptr_file_name_table
) + 1;
5180 /* We are not interested in directory, time or size. */
5181 READ_ULEB (file_table
[i
].directory_index
,
5182 ptr_file_name_table
, end
);
5183 READ_ULEB (file_table
[i
].modification_date
,
5184 ptr_file_name_table
, end
);
5185 READ_ULEB (file_table
[i
].length
,
5186 ptr_file_name_table
, end
);
5192 /* Skip the NUL at the end of the table. */
5196 /* Print the Compilation Unit's name and a header. */
5197 if (file_table
== NULL
)
5198 printf (_("CU: No directory table\n"));
5199 else if (directory_table
== NULL
)
5200 printf (_("CU: %s:\n"), file_table
[0].name
);
5203 unsigned int ix
= file_table
[0].directory_index
;
5204 const char *directory
;
5209 else if (n_directories
== 0)
5210 directory
= _("<unknown>");
5211 else if (ix
> n_directories
)
5213 warn (_("directory index %u > number of directories %s\n"),
5214 ix
, dwarf_vmatoa ("u", n_directories
));
5215 directory
= _("<corrupt>");
5218 directory
= (char *) directory_table
[ix
- 1];
5221 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5223 printf ("%s:\n", file_table
[0].name
);
5227 printf (_("File name Line number Starting address View Stmt\n"));
5229 printf (_("CU: Empty file name table\n"));
5230 saved_linfo
= linfo
;
5233 /* This loop iterates through the Dwarf Line Number Program. */
5234 while (data
< end_of_sequence
)
5236 unsigned char op_code
;
5239 unsigned long int uladv
;
5240 int is_special_opcode
= 0;
5245 if (op_code
>= linfo
.li_opcode_base
)
5247 op_code
-= linfo
.li_opcode_base
;
5248 uladv
= (op_code
/ linfo
.li_line_range
);
5249 if (linfo
.li_max_ops_per_insn
== 1)
5251 uladv
*= linfo
.li_min_insn_length
;
5252 state_machine_regs
.address
+= uladv
;
5254 state_machine_regs
.view
= 0;
5259 = ((state_machine_regs
.op_index
+ uladv
)
5260 / linfo
.li_max_ops_per_insn
)
5261 * linfo
.li_min_insn_length
;
5262 state_machine_regs
.address
5264 state_machine_regs
.op_index
5265 = (state_machine_regs
.op_index
+ uladv
)
5266 % linfo
.li_max_ops_per_insn
;
5268 state_machine_regs
.view
= 0;
5271 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5272 state_machine_regs
.line
+= adv
;
5273 is_special_opcode
= 1;
5274 /* Increment view after printing this row. */
5279 case DW_LNS_extended_op
:
5281 unsigned int ext_op_code_len
;
5282 unsigned char ext_op_code
;
5283 unsigned char *op_code_end
;
5284 unsigned char *op_code_data
= data
;
5286 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5287 op_code_end
= op_code_data
+ ext_op_code_len
;
5288 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5290 warn (_("Badly formed extended line op encountered!\n"));
5293 ext_op_code
= *op_code_data
++;
5297 switch (ext_op_code
)
5299 case DW_LNE_end_sequence
:
5300 /* Reset stuff after printing this row. */
5302 case DW_LNE_set_address
:
5303 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5305 op_code_end
- op_code_data
,
5307 state_machine_regs
.op_index
= 0;
5308 state_machine_regs
.view
= 0;
5310 case DW_LNE_define_file
:
5311 file_table
= (File_Entry
*) xrealloc
5312 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5314 ++state_machine_regs
.last_file_entry
;
5315 /* Source file name. */
5316 file_table
[n_files
].name
= op_code_data
;
5317 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5318 /* Directory index. */
5319 READ_ULEB (file_table
[n_files
].directory_index
,
5320 op_code_data
, op_code_end
);
5321 /* Last modification time. */
5322 READ_ULEB (file_table
[n_files
].modification_date
,
5323 op_code_data
, op_code_end
);
5325 READ_ULEB (file_table
[n_files
].length
,
5326 op_code_data
, op_code_end
);
5330 case DW_LNE_set_discriminator
:
5331 case DW_LNE_HP_set_sequence
:
5332 /* Simply ignored. */
5336 printf (_("UNKNOWN (%u): length %ld\n"),
5337 ext_op_code
, (long int) (op_code_data
- data
));
5344 /* Increment view after printing this row. */
5347 case DW_LNS_advance_pc
:
5348 READ_ULEB (uladv
, data
, end
);
5349 if (linfo
.li_max_ops_per_insn
== 1)
5351 uladv
*= linfo
.li_min_insn_length
;
5352 state_machine_regs
.address
+= uladv
;
5354 state_machine_regs
.view
= 0;
5359 = ((state_machine_regs
.op_index
+ uladv
)
5360 / linfo
.li_max_ops_per_insn
)
5361 * linfo
.li_min_insn_length
;
5362 state_machine_regs
.address
5364 state_machine_regs
.op_index
5365 = (state_machine_regs
.op_index
+ uladv
)
5366 % linfo
.li_max_ops_per_insn
;
5368 state_machine_regs
.view
= 0;
5372 case DW_LNS_advance_line
:
5373 READ_SLEB (adv
, data
, end
);
5374 state_machine_regs
.line
+= adv
;
5377 case DW_LNS_set_file
:
5378 READ_ULEB (uladv
, data
, end
);
5379 state_machine_regs
.file
= uladv
;
5382 unsigned file
= state_machine_regs
.file
;
5385 if (linfo
.li_version
< 5)
5387 if (file_table
== NULL
|| n_files
== 0)
5388 printf (_("\n [Use file table entry %d]\n"), file
);
5390 else if (file
>= n_files
)
5392 warn (_("file index %u > number of files %u\n"), file
, n_files
);
5393 printf (_("\n <over large file table index %u>"), file
);
5395 else if ((dir
= file_table
[file
].directory_index
) == 0)
5396 /* If directory index is 0, that means current directory. */
5397 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5398 else if (directory_table
== NULL
|| n_directories
== 0)
5399 printf (_("\n [Use file %s in directory table entry %d]\n"),
5400 file_table
[file
].name
, dir
);
5402 else if (dir
> n_directories
)
5404 warn (_("directory index %u > number of directories %s\n"),
5405 dir
, dwarf_vmatoa ("u", n_directories
));
5406 printf (_("\n <over large directory table entry %u>\n"), dir
);
5409 printf ("\n%s/%s:\n",
5410 /* The directory index starts counting at 1. */
5411 directory_table
[dir
- 1], file_table
[file
].name
);
5415 case DW_LNS_set_column
:
5416 READ_ULEB (uladv
, data
, end
);
5417 state_machine_regs
.column
= uladv
;
5420 case DW_LNS_negate_stmt
:
5421 adv
= state_machine_regs
.is_stmt
;
5423 state_machine_regs
.is_stmt
= adv
;
5426 case DW_LNS_set_basic_block
:
5427 state_machine_regs
.basic_block
= 1;
5430 case DW_LNS_const_add_pc
:
5431 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5432 if (linfo
.li_max_ops_per_insn
== 1)
5434 uladv
*= linfo
.li_min_insn_length
;
5435 state_machine_regs
.address
+= uladv
;
5437 state_machine_regs
.view
= 0;
5442 = ((state_machine_regs
.op_index
+ uladv
)
5443 / linfo
.li_max_ops_per_insn
)
5444 * linfo
.li_min_insn_length
;
5445 state_machine_regs
.address
5447 state_machine_regs
.op_index
5448 = (state_machine_regs
.op_index
+ uladv
)
5449 % linfo
.li_max_ops_per_insn
;
5451 state_machine_regs
.view
= 0;
5455 case DW_LNS_fixed_advance_pc
:
5456 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5457 state_machine_regs
.address
+= uladv
;
5458 state_machine_regs
.op_index
= 0;
5459 /* Do NOT reset view. */
5462 case DW_LNS_set_prologue_end
:
5465 case DW_LNS_set_epilogue_begin
:
5468 case DW_LNS_set_isa
:
5469 READ_ULEB (uladv
, data
, end
);
5470 printf (_(" Set ISA to %lu\n"), uladv
);
5474 printf (_(" Unknown opcode %d with operands: "), op_code
);
5476 if (standard_opcodes
!= NULL
)
5477 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5481 READ_ULEB (val
, data
, end
);
5482 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5483 i
== 1 ? "" : ", ");
5489 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5490 to the DWARF address/line matrix. */
5491 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5492 || (xop
== DW_LNS_copy
))
5494 const unsigned int MAX_FILENAME_LENGTH
= 35;
5496 char *newFileName
= NULL
;
5497 size_t fileNameLength
;
5501 unsigned indx
= state_machine_regs
.file
;
5503 if (linfo
.li_version
< 5)
5506 if (indx
>= n_files
)
5508 warn (_("corrupt file index %u encountered\n"), indx
);
5509 fileName
= _("<corrupt>");
5512 fileName
= (char *) file_table
[indx
].name
;
5515 fileName
= _("<unknown>");
5517 fileNameLength
= strlen (fileName
);
5518 newFileName
= fileName
;
5519 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5521 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5522 /* Truncate file name */
5523 memcpy (newFileName
,
5524 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5525 MAX_FILENAME_LENGTH
);
5526 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5529 /* A row with end_seq set to true has a meaningful address, but
5530 the other information in the same row is not significant.
5531 In such a row, print line as "-", and don't print
5533 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5535 if (linfo
.li_max_ops_per_insn
== 1)
5537 if (xop
== -DW_LNE_end_sequence
)
5538 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5540 state_machine_regs
.address
);
5542 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5543 newFileName
, state_machine_regs
.line
,
5544 state_machine_regs
.address
);
5548 if (xop
== -DW_LNE_end_sequence
)
5549 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5551 state_machine_regs
.address
,
5552 state_machine_regs
.op_index
);
5554 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5555 newFileName
, state_machine_regs
.line
,
5556 state_machine_regs
.address
,
5557 state_machine_regs
.op_index
);
5562 if (linfo
.li_max_ops_per_insn
== 1)
5564 if (xop
== -DW_LNE_end_sequence
)
5565 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5567 state_machine_regs
.address
);
5569 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5570 newFileName
, state_machine_regs
.line
,
5571 state_machine_regs
.address
);
5575 if (xop
== -DW_LNE_end_sequence
)
5576 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5578 state_machine_regs
.address
,
5579 state_machine_regs
.op_index
);
5581 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5582 newFileName
, state_machine_regs
.line
,
5583 state_machine_regs
.address
,
5584 state_machine_regs
.op_index
);
5588 if (xop
!= -DW_LNE_end_sequence
)
5590 if (state_machine_regs
.view
)
5591 printf (" %6u", state_machine_regs
.view
);
5595 if (state_machine_regs
.is_stmt
)
5600 state_machine_regs
.view
++;
5602 if (xop
== -DW_LNE_end_sequence
)
5604 reset_state_machine (linfo
.li_default_is_stmt
);
5608 if (newFileName
!= fileName
)
5620 if (directory_table
)
5622 free (directory_table
);
5623 directory_table
= NULL
;
5634 display_debug_lines (struct dwarf_section
*section
, void *file
)
5636 unsigned char *data
= section
->start
;
5637 unsigned char *end
= data
+ section
->size
;
5639 int retValDecoded
= 1;
5641 if (do_debug_lines
== 0)
5642 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5644 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5645 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5647 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5648 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5650 if (!retValRaw
|| !retValDecoded
)
5657 find_debug_info_for_offset (dwarf_vma offset
)
5661 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5664 for (i
= 0; i
< num_debug_info_entries
; i
++)
5665 if (debug_information
[i
].cu_offset
== offset
)
5666 return debug_information
+ i
;
5672 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5674 /* See gdb/gdb-index.h. */
5675 static const char * const kinds
[] =
5687 return _ (kinds
[kind
]);
5691 display_debug_pubnames_worker (struct dwarf_section
*section
,
5692 void *file ATTRIBUTE_UNUSED
,
5695 DWARF2_Internal_PubNames names
;
5696 unsigned char *start
= section
->start
;
5697 unsigned char *end
= start
+ section
->size
;
5699 /* It does not matter if this load fails,
5700 we test for that later on. */
5701 load_debug_info (file
);
5703 introduce (section
, false);
5707 unsigned char *data
;
5708 unsigned long sec_off
= start
- section
->start
;
5709 unsigned int offset_size
;
5711 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5712 if (names
.pn_length
== 0xffffffff)
5714 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5720 if (names
.pn_length
> (size_t) (end
- start
))
5722 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5725 dwarf_vmatoa ("x", names
.pn_length
));
5730 start
+= names
.pn_length
;
5732 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5733 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5735 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5736 && num_debug_info_entries
> 0
5737 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5738 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5739 (unsigned long) names
.pn_offset
, section
->name
);
5741 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5743 printf (_(" Length: %ld\n"),
5744 (long) names
.pn_length
);
5745 printf (_(" Version: %d\n"),
5747 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5748 (unsigned long) names
.pn_offset
);
5749 printf (_(" Size of area in .debug_info section: %ld\n"),
5750 (long) names
.pn_size
);
5752 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5754 static int warned
= 0;
5758 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5766 printf (_("\n Offset Kind Name\n"));
5768 printf (_("\n Offset\tName\n"));
5772 bfd_size_type maxprint
;
5775 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5782 maxprint
= (start
- data
) - 1;
5786 unsigned int kind_data
;
5787 gdb_index_symbol_kind kind
;
5788 const char *kind_name
;
5791 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5793 /* GCC computes the kind as the upper byte in the CU index
5794 word, and then right shifts it by the CU index size.
5795 Left shift KIND to where the gdb-index.h accessor macros
5797 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5798 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5799 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5800 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5801 printf (" %-6lx %s,%-10s %.*s\n",
5802 (unsigned long) offset
, is_static
? _("s") : _("g"),
5803 kind_name
, (int) maxprint
, data
);
5806 printf (" %-6lx\t%.*s\n",
5807 (unsigned long) offset
, (int) maxprint
, data
);
5809 data
+= strnlen ((char *) data
, maxprint
);
5822 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5824 return display_debug_pubnames_worker (section
, file
, 0);
5828 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5830 return display_debug_pubnames_worker (section
, file
, 1);
5834 display_debug_macinfo (struct dwarf_section
*section
,
5835 void *file ATTRIBUTE_UNUSED
)
5837 unsigned char *start
= section
->start
;
5838 unsigned char *end
= start
+ section
->size
;
5839 unsigned char *curr
= start
;
5840 enum dwarf_macinfo_record_type op
;
5842 introduce (section
, false);
5846 unsigned int lineno
;
5847 const unsigned char *string
;
5849 op
= (enum dwarf_macinfo_record_type
) *curr
;
5854 case DW_MACINFO_start_file
:
5856 unsigned int filenum
;
5858 READ_ULEB (lineno
, curr
, end
);
5859 READ_ULEB (filenum
, curr
, end
);
5860 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5865 case DW_MACINFO_end_file
:
5866 printf (_(" DW_MACINFO_end_file\n"));
5869 case DW_MACINFO_define
:
5870 READ_ULEB (lineno
, curr
, end
);
5872 curr
+= strnlen ((char *) string
, end
- string
);
5873 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5874 lineno
, (int) (curr
- string
), string
);
5879 case DW_MACINFO_undef
:
5880 READ_ULEB (lineno
, curr
, end
);
5882 curr
+= strnlen ((char *) string
, end
- string
);
5883 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5884 lineno
, (int) (curr
- string
), string
);
5889 case DW_MACINFO_vendor_ext
:
5891 unsigned int constant
;
5893 READ_ULEB (constant
, curr
, end
);
5895 curr
+= strnlen ((char *) string
, end
- string
);
5896 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5897 constant
, (int) (curr
- string
), string
);
5908 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5909 filename and dirname corresponding to file name table entry with index
5910 FILEIDX. Return NULL on failure. */
5912 static unsigned char *
5913 get_line_filename_and_dirname (dwarf_vma line_offset
,
5915 unsigned char **dir_name
)
5917 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5918 unsigned char *hdrptr
, *dirtable
, *file_name
;
5919 unsigned int offset_size
;
5920 unsigned int version
, opcode_base
;
5921 dwarf_vma length
, diridx
;
5922 const unsigned char * end
;
5925 if (section
->start
== NULL
5926 || line_offset
>= section
->size
5930 hdrptr
= section
->start
+ line_offset
;
5931 end
= section
->start
+ section
->size
;
5933 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5934 if (length
== 0xffffffff)
5936 /* This section is 64-bit DWARF 3. */
5937 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5943 if (length
> (size_t) (end
- hdrptr
)
5944 || length
< 2 + offset_size
+ 1 + 3 + 1)
5946 end
= hdrptr
+ length
;
5948 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5949 if (version
!= 2 && version
!= 3 && version
!= 4)
5951 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5953 hdrptr
++; /* Skip max_ops_per_insn. */
5954 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5956 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5957 if (opcode_base
== 0
5958 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
5961 hdrptr
+= opcode_base
- 1;
5964 /* Skip over dirname table. */
5965 while (*hdrptr
!= '\0')
5967 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5973 hdrptr
++; /* Skip the NUL at the end of the table. */
5975 /* Now skip over preceding filename table entries. */
5976 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5978 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5981 SKIP_ULEB (hdrptr
, end
);
5982 SKIP_ULEB (hdrptr
, end
);
5983 SKIP_ULEB (hdrptr
, end
);
5985 if (hdrptr
>= end
|| *hdrptr
== '\0')
5989 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5994 READ_ULEB (diridx
, hdrptr
, end
);
5997 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5999 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6003 if (dirtable
>= end
|| *dirtable
== '\0')
6005 *dir_name
= dirtable
;
6010 display_debug_macro (struct dwarf_section
*section
,
6013 unsigned char *start
= section
->start
;
6014 unsigned char *end
= start
+ section
->size
;
6015 unsigned char *curr
= start
;
6016 unsigned char *extended_op_buf
[256];
6017 bool is_dwo
= false;
6018 const char *suffix
= strrchr (section
->name
, '.');
6020 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6023 load_debug_section_with_follow (str
, file
);
6024 load_debug_section_with_follow (line
, file
);
6025 load_debug_section_with_follow (str_index
, file
);
6027 introduce (section
, false);
6031 unsigned int lineno
, version
, flags
;
6032 unsigned int offset_size
;
6033 const unsigned char *string
;
6034 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
6035 unsigned char **extended_ops
= NULL
;
6037 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6038 if (version
!= 4 && version
!= 5)
6040 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6041 section
->name
, version
);
6045 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6046 offset_size
= (flags
& 1) ? 8 : 4;
6047 printf (_(" Offset: 0x%lx\n"),
6048 (unsigned long) sec_offset
);
6049 printf (_(" Version: %d\n"), version
);
6050 printf (_(" Offset size: %d\n"), offset_size
);
6053 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6054 printf (_(" Offset into .debug_line: 0x%lx\n"),
6055 (unsigned long) line_offset
);
6059 unsigned int i
, count
, op
;
6062 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6064 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6065 extended_ops
= extended_op_buf
;
6068 printf (_(" Extension opcode arguments:\n"));
6069 for (i
= 0; i
< count
; i
++)
6071 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6072 extended_ops
[op
] = curr
;
6073 READ_ULEB (nargs
, curr
, end
);
6075 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6078 printf (_(" DW_MACRO_%02x arguments: "), op
);
6079 for (n
= 0; n
< nargs
; n
++)
6083 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6084 printf ("%s%s", get_FORM_name (form
),
6085 n
== nargs
- 1 ? "\n" : ", ");
6095 case DW_FORM_block1
:
6096 case DW_FORM_block2
:
6097 case DW_FORM_block4
:
6099 case DW_FORM_string
:
6101 case DW_FORM_sec_offset
:
6104 error (_("Invalid extension opcode form %s\n"),
6105 get_FORM_name (form
));
6121 error (_(".debug_macro section not zero terminated\n"));
6125 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6131 case DW_MACRO_define
:
6132 READ_ULEB (lineno
, curr
, end
);
6134 curr
+= strnlen ((char *) string
, end
- string
);
6135 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6136 lineno
, (int) (curr
- string
), string
);
6141 case DW_MACRO_undef
:
6142 READ_ULEB (lineno
, curr
, end
);
6144 curr
+= strnlen ((char *) string
, end
- string
);
6145 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6146 lineno
, (int) (curr
- string
), string
);
6151 case DW_MACRO_start_file
:
6153 unsigned int filenum
;
6154 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6156 READ_ULEB (lineno
, curr
, end
);
6157 READ_ULEB (filenum
, curr
, end
);
6159 if ((flags
& 2) == 0)
6160 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6163 = get_line_filename_and_dirname (line_offset
, filenum
,
6165 if (file_name
== NULL
)
6166 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6169 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6171 dir_name
!= NULL
? (const char *) dir_name
: "",
6172 dir_name
!= NULL
? "/" : "", file_name
);
6176 case DW_MACRO_end_file
:
6177 printf (_(" DW_MACRO_end_file\n"));
6180 case DW_MACRO_define_strp
:
6181 READ_ULEB (lineno
, curr
, end
);
6182 if (version
== 4 && is_dwo
)
6183 READ_ULEB (offset
, curr
, end
);
6185 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6186 string
= fetch_indirect_string (offset
);
6187 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6191 case DW_MACRO_undef_strp
:
6192 READ_ULEB (lineno
, curr
, end
);
6193 if (version
== 4 && is_dwo
)
6194 READ_ULEB (offset
, curr
, end
);
6196 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6197 string
= fetch_indirect_string (offset
);
6198 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6202 case DW_MACRO_import
:
6203 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6204 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6205 (unsigned long) offset
);
6208 case DW_MACRO_define_sup
:
6209 READ_ULEB (lineno
, curr
, end
);
6210 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6211 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6212 lineno
, (unsigned long) offset
);
6215 case DW_MACRO_undef_sup
:
6216 READ_ULEB (lineno
, curr
, end
);
6217 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6218 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6219 lineno
, (unsigned long) offset
);
6222 case DW_MACRO_import_sup
:
6223 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6224 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6225 (unsigned long) offset
);
6228 case DW_MACRO_define_strx
:
6229 case DW_MACRO_undef_strx
:
6230 READ_ULEB (lineno
, curr
, end
);
6231 READ_ULEB (offset
, curr
, end
);
6232 string
= (const unsigned char *)
6233 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6234 if (op
== DW_MACRO_define_strx
)
6235 printf (" DW_MACRO_define_strx ");
6237 printf (" DW_MACRO_undef_strx ");
6239 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6240 printf (_("lineno : %d macro : %s\n"),
6245 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6247 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6251 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6253 error (_(" Unknown macro opcode %02x seen\n"), op
);
6258 /* Skip over unhandled opcodes. */
6260 unsigned char *desc
= extended_ops
[op
];
6261 READ_ULEB (nargs
, desc
, end
);
6264 printf (_(" DW_MACRO_%02x\n"), op
);
6267 printf (_(" DW_MACRO_%02x -"), op
);
6268 for (n
= 0; n
< nargs
; n
++)
6272 /* DW_FORM_implicit_const is not expected here. */
6273 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6275 = read_and_display_attr_value (0, val
, 0,
6276 start
, curr
, end
, 0, 0, offset_size
,
6277 version
, NULL
, 0, NULL
,
6295 display_debug_abbrev (struct dwarf_section
*section
,
6296 void *file ATTRIBUTE_UNUSED
)
6298 abbrev_entry
*entry
;
6299 unsigned char *start
= section
->start
;
6301 introduce (section
, false);
6308 offset
= start
- section
->start
;
6309 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6312 list
= new_abbrev_list (0, offset
);
6313 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6314 list
->start_of_next_abbrevs
= start
;
6317 start
= list
->start_of_next_abbrevs
;
6319 if (list
->first_abbrev
== NULL
)
6322 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6324 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6328 printf (" %ld %s [%s]\n",
6330 get_TAG_name (entry
->tag
),
6331 entry
->children
? _("has children") : _("no children"));
6333 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6335 printf (" %-18s %s",
6336 get_AT_name (attr
->attribute
),
6337 get_FORM_name (attr
->form
));
6338 if (attr
->form
== DW_FORM_implicit_const
)
6339 printf (": %s", dwarf_vmatoa ("d", attr
->implicit_const
));
6351 /* Return true when ADDR is the maximum address, when addresses are
6352 POINTER_SIZE bytes long. */
6355 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6357 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6358 return ((addr
& mask
) == mask
);
6361 /* Display a view pair list starting at *VSTART_PTR and ending at
6362 VLISTEND within SECTION. */
6365 display_view_pair_list (struct dwarf_section
*section
,
6366 unsigned char **vstart_ptr
,
6367 unsigned int debug_info_entry
,
6368 unsigned char *vlistend
)
6370 unsigned char *vstart
= *vstart_ptr
;
6371 unsigned char *section_end
= section
->start
+ section
->size
;
6372 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6374 if (vlistend
< section_end
)
6375 section_end
= vlistend
;
6379 while (vstart
< section_end
)
6381 dwarf_vma off
= vstart
- section
->start
;
6382 dwarf_vma vbegin
, vend
;
6384 READ_ULEB (vbegin
, vstart
, section_end
);
6385 if (vstart
== section_end
)
6388 READ_ULEB (vend
, vstart
, section_end
);
6389 printf (" %8.8lx ", (unsigned long) off
);
6391 print_dwarf_view (vbegin
, pointer_size
, 1);
6392 print_dwarf_view (vend
, pointer_size
, 1);
6393 printf (_("location view pair\n"));
6397 *vstart_ptr
= vstart
;
6400 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6403 display_loc_list (struct dwarf_section
*section
,
6404 unsigned char **start_ptr
,
6405 unsigned int debug_info_entry
,
6407 dwarf_vma base_address
,
6408 unsigned char **vstart_ptr
,
6411 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6412 unsigned char *section_end
= section
->start
+ section
->size
;
6413 dwarf_vma cu_offset
;
6414 unsigned int pointer_size
;
6415 unsigned int offset_size
;
6419 unsigned short length
;
6420 int need_frame_base
;
6422 if (debug_info_entry
>= num_debug_info_entries
)
6424 warn (_("No debug information available for loc lists of entry: %u\n"),
6429 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6430 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6431 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6432 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6434 if (pointer_size
< 2 || pointer_size
> 8)
6436 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6437 pointer_size
, debug_info_entry
);
6443 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6444 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6446 if (2 * pointer_size
> (size_t) (section_end
- start
))
6448 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6449 (unsigned long) offset
);
6454 print_dwarf_vma (off
, 4);
6456 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6457 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6459 if (begin
== 0 && end
== 0)
6461 /* PR 18374: In a object file we can have a location list that
6462 starts with a begin and end of 0 because there are relocations
6463 that need to be applied to the addresses. Actually applying
6464 the relocations now does not help as they will probably resolve
6465 to 0, since the object file has not been fully linked. Real
6466 end of list markers will not have any relocations against them. */
6467 if (! reloc_at (section
, off
)
6468 && ! reloc_at (section
, off
+ pointer_size
))
6470 printf (_("<End of list>\n"));
6475 /* Check base address specifiers. */
6476 if (is_max_address (begin
, pointer_size
)
6477 && !is_max_address (end
, pointer_size
))
6480 print_dwarf_vma (begin
, pointer_size
);
6481 print_dwarf_vma (end
, pointer_size
);
6482 printf (_("(base address)\n"));
6488 off
= offset
+ (vstart
- *start_ptr
);
6490 READ_ULEB (vbegin
, vstart
, section_end
);
6491 print_dwarf_view (vbegin
, pointer_size
, 1);
6493 READ_ULEB (vend
, vstart
, section_end
);
6494 print_dwarf_view (vend
, pointer_size
, 1);
6496 printf (_("views at %8.8lx for:\n %*s "),
6497 (unsigned long) off
, 8, "");
6500 if (2 > (size_t) (section_end
- start
))
6502 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6503 (unsigned long) offset
);
6507 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6509 if (length
> (size_t) (section_end
- start
))
6511 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6512 (unsigned long) offset
);
6516 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6517 print_dwarf_vma (end
+ base_address
, pointer_size
);
6520 need_frame_base
= decode_location_expression (start
,
6525 cu_offset
, section
);
6528 if (need_frame_base
&& !has_frame_base
)
6529 printf (_(" [without DW_AT_frame_base]"));
6531 if (begin
== end
&& vbegin
== vend
)
6532 fputs (_(" (start == end)"), stdout
);
6533 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6534 fputs (_(" (start > end)"), stdout
);
6542 *vstart_ptr
= vstart
;
6545 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6548 display_loclists_list (struct dwarf_section
* section
,
6549 unsigned char ** start_ptr
,
6550 unsigned int debug_info_entry
,
6552 dwarf_vma base_address
,
6553 unsigned char ** vstart_ptr
,
6556 unsigned char * start
= *start_ptr
;
6557 unsigned char * vstart
= *vstart_ptr
;
6558 unsigned char * section_end
= section
->start
+ section
->size
;
6559 dwarf_vma cu_offset
;
6560 unsigned int pointer_size
;
6561 unsigned int offset_size
;
6562 unsigned int dwarf_version
;
6564 /* Initialize it due to a false compiler warning. */
6565 dwarf_vma begin
= -1, vbegin
= -1;
6566 dwarf_vma end
= -1, vend
= -1;
6568 int need_frame_base
;
6570 if (debug_info_entry
>= num_debug_info_entries
)
6572 warn (_("No debug information available for "
6573 "loclists lists of entry: %u\n"),
6578 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6579 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6580 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6581 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6583 if (pointer_size
< 2 || pointer_size
> 8)
6585 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6586 pointer_size
, debug_info_entry
);
6592 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6593 enum dwarf_location_list_entry_type llet
;
6595 if (start
+ 1 > section_end
)
6597 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6598 (unsigned long) offset
);
6603 print_dwarf_vma (off
, 4);
6605 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6607 if (vstart
&& (llet
== DW_LLE_offset_pair
6608 || llet
== DW_LLE_start_end
6609 || llet
== DW_LLE_start_length
))
6611 off
= offset
+ (vstart
- *start_ptr
);
6613 READ_ULEB (vbegin
, vstart
, section_end
);
6614 print_dwarf_view (vbegin
, pointer_size
, 1);
6616 READ_ULEB (vend
, vstart
, section_end
);
6617 print_dwarf_view (vend
, pointer_size
, 1);
6619 printf (_("views at %8.8lx for:\n %*s "),
6620 (unsigned long) off
, 8, "");
6625 case DW_LLE_end_of_list
:
6626 printf (_("<End of list>\n"));
6629 case DW_LLE_base_addressx
:
6630 READ_ULEB (base_address
, start
, section_end
);
6631 print_dwarf_vma (base_address
, pointer_size
);
6632 printf (_("(index into .debug_addr) "));
6633 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6634 print_dwarf_vma (base_address
, pointer_size
);
6635 printf (_("(base address)\n"));
6638 case DW_LLE_startx_endx
:
6639 READ_ULEB (begin
, start
, section_end
);
6640 begin
= fetch_indexed_addr (begin
, pointer_size
);
6641 READ_ULEB (end
, start
, section_end
);
6642 end
= fetch_indexed_addr (end
, pointer_size
);
6645 case DW_LLE_startx_length
:
6646 READ_ULEB (begin
, start
, section_end
);
6647 begin
= fetch_indexed_addr (begin
, pointer_size
);
6648 READ_ULEB (end
, start
, section_end
);
6652 case DW_LLE_default_location
:
6656 case DW_LLE_offset_pair
:
6657 READ_ULEB (begin
, start
, section_end
);
6658 begin
+= base_address
;
6659 READ_ULEB (end
, start
, section_end
);
6660 end
+= base_address
;
6663 case DW_LLE_base_address
:
6664 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6666 print_dwarf_vma (base_address
, pointer_size
);
6667 printf (_("(base address)\n"));
6670 case DW_LLE_start_end
:
6671 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6672 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6675 case DW_LLE_start_length
:
6676 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6677 READ_ULEB (end
, start
, section_end
);
6681 #ifdef DW_LLE_view_pair
6682 case DW_LLE_view_pair
:
6684 printf (_("View pair entry in loclist with locviews attribute\n"));
6685 READ_ULEB (vbegin
, start
, section_end
);
6686 print_dwarf_view (vbegin
, pointer_size
, 1);
6688 READ_ULEB (vend
, start
, section_end
);
6689 print_dwarf_view (vend
, pointer_size
, 1);
6691 printf (_("views for:\n"));
6696 error (_("Invalid location list entry type %d\n"), llet
);
6700 if (llet
== DW_LLE_end_of_list
)
6703 if (llet
== DW_LLE_base_address
6704 || llet
== DW_LLE_base_addressx
)
6707 if (start
== section_end
)
6709 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6710 (unsigned long) offset
);
6713 READ_ULEB (length
, start
, section_end
);
6715 if (length
> (size_t) (section_end
- start
))
6717 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6718 (unsigned long) offset
);
6722 print_dwarf_vma (begin
, pointer_size
);
6723 print_dwarf_vma (end
, pointer_size
);
6726 need_frame_base
= decode_location_expression (start
,
6731 cu_offset
, section
);
6734 if (need_frame_base
&& !has_frame_base
)
6735 printf (_(" [without DW_AT_frame_base]"));
6737 if (begin
== end
&& vbegin
== vend
)
6738 fputs (_(" (start == end)"), stdout
);
6739 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6740 fputs (_(" (start > end)"), stdout
);
6748 if (vbegin
!= vm1
|| vend
!= vm1
)
6749 printf (_("Trailing view pair not used in a range"));
6752 *vstart_ptr
= vstart
;
6755 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6756 right-adjusted in a field of length LEN, and followed by a space. */
6759 print_addr_index (unsigned int idx
, unsigned int len
)
6761 static char buf
[15];
6762 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6763 printf ("%*s ", len
, buf
);
6766 /* Display a location list from a .dwo section. It uses address indexes rather
6767 than embedded addresses. This code closely follows display_loc_list, but the
6768 two are sufficiently different that combining things is very ugly. */
6771 display_loc_list_dwo (struct dwarf_section
*section
,
6772 unsigned char **start_ptr
,
6773 unsigned int debug_info_entry
,
6775 unsigned char **vstart_ptr
,
6778 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6779 unsigned char *section_end
= section
->start
+ section
->size
;
6780 dwarf_vma cu_offset
;
6781 unsigned int pointer_size
;
6782 unsigned int offset_size
;
6785 unsigned short length
;
6786 int need_frame_base
;
6789 if (debug_info_entry
>= num_debug_info_entries
)
6791 warn (_("No debug information for loc lists of entry: %u\n"),
6796 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6797 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6798 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6799 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6801 if (pointer_size
< 2 || pointer_size
> 8)
6803 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6804 pointer_size
, debug_info_entry
);
6811 print_dwarf_vma (offset
+ (start
- *start_ptr
), 4);
6813 if (start
>= section_end
)
6815 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6816 (unsigned long) offset
);
6820 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6833 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6835 READ_ULEB (view
, vstart
, section_end
);
6836 print_dwarf_view (view
, 8, 1);
6838 READ_ULEB (view
, vstart
, section_end
);
6839 print_dwarf_view (view
, 8, 1);
6841 printf (_("views at %8.8lx for:\n %*s "),
6842 (unsigned long) off
, 8, "");
6850 case 0: /* A terminating entry. */
6852 *vstart_ptr
= vstart
;
6853 printf (_("<End of list>\n"));
6855 case 1: /* A base-address entry. */
6856 READ_ULEB (idx
, start
, section_end
);
6857 print_addr_index (idx
, 8);
6858 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6859 printf (_("(base address selection entry)\n"));
6861 case 2: /* A start/end entry. */
6862 READ_ULEB (idx
, start
, section_end
);
6863 print_addr_index (idx
, 8);
6864 READ_ULEB (idx
, start
, section_end
);
6865 print_addr_index (idx
, 8);
6867 case 3: /* A start/length entry. */
6868 READ_ULEB (idx
, start
, section_end
);
6869 print_addr_index (idx
, 8);
6870 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6871 printf ("%08x ", idx
);
6873 case 4: /* An offset pair entry. */
6874 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6875 printf ("%08x ", idx
);
6876 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6877 printf ("%08x ", idx
);
6880 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6882 *vstart_ptr
= vstart
;
6886 if (2 > (size_t) (section_end
- start
))
6888 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6889 (unsigned long) offset
);
6893 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6894 if (length
> (size_t) (section_end
- start
))
6896 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6897 (unsigned long) offset
);
6902 need_frame_base
= decode_location_expression (start
,
6907 cu_offset
, section
);
6910 if (need_frame_base
&& !has_frame_base
)
6911 printf (_(" [without DW_AT_frame_base]"));
6919 *vstart_ptr
= vstart
;
6922 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6925 static dwarf_vma
*loc_offsets
, *loc_views
;
6928 loc_offsets_compar (const void *ap
, const void *bp
)
6930 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6931 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6933 int ret
= (a
> b
) - (b
> a
);
6937 a
= loc_views
[*(const unsigned int *) ap
];
6938 b
= loc_views
[*(const unsigned int *) bp
];
6940 ret
= (a
> b
) - (b
> a
);
6946 display_offset_entry_loclists (struct dwarf_section
*section
)
6948 unsigned char * start
= section
->start
;
6949 unsigned char * const end
= start
+ section
->size
;
6951 introduce (section
, false);
6956 unsigned short version
;
6957 unsigned char address_size
;
6958 unsigned char segment_selector_size
;
6959 uint32_t offset_entry_count
;
6963 printf (_("Table at Offset 0x%lx\n"), (long)(start
- section
->start
));
6965 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
6966 if (length
== 0xffffffff)
6969 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
6974 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
6975 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
6976 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
6977 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
6979 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", length
));
6980 printf (_(" DWARF version: %u\n"), version
);
6981 printf (_(" Address size: %u\n"), address_size
);
6982 printf (_(" Segment size: %u\n"), segment_selector_size
);
6983 printf (_(" Offset entries: %u\n"), offset_entry_count
);
6987 warn (_("The %s section contains a corrupt or "
6988 "unsupported version number: %d.\n"),
6989 section
->name
, version
);
6993 if (segment_selector_size
!= 0)
6995 warn (_("The %s section contains an "
6996 "unsupported segment selector size: %d.\n"),
6997 section
->name
, segment_selector_size
);
7001 if (offset_entry_count
== 0)
7003 warn (_("The %s section contains a table without offset\n"),
7008 printf (_("\n Offset Entries starting at 0x%lx:\n"),
7009 (long)(start
- section
->start
));
7013 for (i
= 0; i
< offset_entry_count
; i
++)
7017 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, end
);
7018 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
7023 for (i
= 0; i
< offset_entry_count
; i
++)
7027 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, end
);
7028 printf (_(" [%6u] 0x%x\n"), i
, entry
);
7036 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7039 dwarf_vma base_address
= 0;
7042 dwarf_vma off
= start
- section
->start
;
7046 printf (_(" Offset Entry %u\n"), i
);
7051 print_dwarf_vma (off
, 4);
7053 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7057 case DW_LLE_end_of_list
:
7058 printf (_("<End of list>\n\n"));
7062 case DW_LLE_base_addressx
:
7063 READ_ULEB (base_address
, start
, end
);
7064 print_dwarf_vma (base_address
, address_size
);
7065 printf (_("(index into .debug_addr) "));
7066 base_address
= fetch_indexed_addr (base_address
, address_size
);
7067 print_dwarf_vma (base_address
, address_size
);
7068 printf (_("(base address)\n"));
7071 case DW_LLE_startx_endx
:
7072 READ_ULEB (begin
, start
, end
);
7073 begin
= fetch_indexed_addr (begin
, address_size
);
7074 READ_ULEB (finish
, start
, end
);
7075 finish
= fetch_indexed_addr (finish
, address_size
);
7078 case DW_LLE_startx_length
:
7079 READ_ULEB (begin
, start
, end
);
7080 begin
= fetch_indexed_addr (begin
, address_size
);
7081 READ_ULEB (finish
, start
, end
);
7085 case DW_LLE_offset_pair
:
7086 READ_ULEB (begin
, start
, end
);
7087 begin
+= base_address
;
7088 READ_ULEB (finish
, start
, end
);
7089 finish
+= base_address
;
7092 case DW_LLE_default_location
:
7096 case DW_LLE_base_address
:
7097 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7098 print_dwarf_vma (base_address
, address_size
);
7099 printf (_("(base address)\n"));
7102 case DW_LLE_start_end
:
7103 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7104 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7107 case DW_LLE_start_length
:
7108 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7109 READ_ULEB (finish
, start
, end
);
7114 error (_("Invalid location list entry type %d\n"), lle
);
7120 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7121 (unsigned long) off
);
7125 print_dwarf_vma (begin
, address_size
);
7126 print_dwarf_vma (finish
, address_size
);
7128 if (begin
== finish
)
7129 fputs (_(" (start == end)"), stdout
);
7130 else if (begin
> finish
)
7131 fputs (_(" (start > end)"), stdout
);
7133 /* Read the counted location descriptions. */
7134 READ_ULEB (length
, start
, end
);
7136 if (length
> (size_t) (end
- start
))
7138 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7139 (unsigned long) off
);
7144 (void) decode_location_expression (start
, address_size
, address_size
,
7145 version
, length
, 0, section
);
7152 while (start
< end
);
7158 display_debug_loc (struct dwarf_section
*section
, void *file
)
7160 unsigned char *start
= section
->start
, *vstart
= NULL
;
7162 unsigned char *section_begin
= start
;
7163 unsigned int num_loc_list
= 0;
7164 dwarf_vma last_offset
= 0;
7165 dwarf_vma last_view
= 0;
7166 unsigned int first
= 0;
7169 int seen_first_offset
= 0;
7170 int locs_sorted
= 1;
7171 unsigned char *next
= start
, *vnext
= vstart
;
7172 unsigned int *array
= NULL
;
7173 const char *suffix
= strrchr (section
->name
, '.');
7174 bool is_dwo
= false;
7175 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7176 dwarf_vma expected_start
= 0;
7178 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7181 bytes
= section
->size
;
7185 printf (_("\nThe %s section is empty.\n"), section
->name
);
7191 unsigned char *hdrptr
= section_begin
;
7192 dwarf_vma ll_length
;
7193 unsigned short ll_version
;
7194 unsigned char *end
= section_begin
+ section
->size
;
7195 unsigned char address_size
, segment_selector_size
;
7196 uint32_t offset_entry_count
;
7198 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7199 if (ll_length
== 0xffffffff)
7200 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7202 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7203 if (ll_version
!= 5)
7205 warn (_("The %s section contains corrupt or "
7206 "unsupported version number: %d.\n"),
7207 section
->name
, ll_version
);
7211 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7213 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7214 if (segment_selector_size
!= 0)
7216 warn (_("The %s section contains "
7217 "unsupported segment selector size: %d.\n"),
7218 section
->name
, segment_selector_size
);
7222 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7224 if (offset_entry_count
!= 0)
7225 return display_offset_entry_loclists (section
);
7227 expected_start
= hdrptr
- section_begin
;
7230 if (load_debug_info (file
) == 0)
7232 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7237 /* Check the order of location list in .debug_info section. If
7238 offsets of location lists are in the ascending order, we can
7239 use `debug_information' directly. */
7240 for (i
= 0; i
< num_debug_info_entries
; i
++)
7244 num
= debug_information
[i
].num_loc_offsets
;
7245 if (num
> num_loc_list
)
7248 /* Check if we can use `debug_information' directly. */
7249 if (locs_sorted
&& num
!= 0)
7251 if (!seen_first_offset
)
7253 /* This is the first location list. */
7254 last_offset
= debug_information
[i
].loc_offsets
[0];
7255 last_view
= debug_information
[i
].loc_views
[0];
7257 seen_first_offset
= 1;
7263 for (; j
< num
; j
++)
7266 debug_information
[i
].loc_offsets
[j
]
7267 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7268 && last_view
> debug_information
[i
].loc_views
[j
]))
7273 last_offset
= debug_information
[i
].loc_offsets
[j
];
7274 last_view
= debug_information
[i
].loc_views
[j
];
7279 if (!seen_first_offset
)
7280 error (_("No location lists in .debug_info section!\n"));
7282 if (debug_information
[first
].num_loc_offsets
> 0
7283 && debug_information
[first
].loc_offsets
[0] != expected_start
7284 && debug_information
[first
].loc_views
[0] != expected_start
)
7285 warn (_("Location lists in %s section start at 0x%s rather than 0x%s\n"),
7287 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]),
7288 dwarf_vmatoa ("x", expected_start
));
7291 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7293 introduce (section
, false);
7295 if (reloc_at (section
, 0))
7296 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7298 printf (_(" Offset Begin End Expression\n"));
7300 seen_first_offset
= 0;
7301 for (i
= first
; i
< num_debug_info_entries
; i
++)
7303 dwarf_vma offset
, voffset
;
7304 dwarf_vma base_address
;
7310 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7312 loc_offsets
= debug_information
[i
].loc_offsets
;
7313 loc_views
= debug_information
[i
].loc_views
;
7314 qsort (array
, debug_information
[i
].num_loc_offsets
,
7315 sizeof (*array
), loc_offsets_compar
);
7318 int adjacent_view_loclists
= 1;
7319 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7321 j
= locs_sorted
? k
: array
[k
];
7323 && (debug_information
[i
].loc_offsets
[locs_sorted
7324 ? k
- 1 : array
[k
- 1]]
7325 == debug_information
[i
].loc_offsets
[j
])
7326 && (debug_information
[i
].loc_views
[locs_sorted
7327 ? k
- 1 : array
[k
- 1]]
7328 == debug_information
[i
].loc_views
[j
]))
7330 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7331 offset
= debug_information
[i
].loc_offsets
[j
];
7332 next
= section_begin
+ offset
;
7333 voffset
= debug_information
[i
].loc_views
[j
];
7335 vnext
= section_begin
+ voffset
;
7338 base_address
= debug_information
[i
].base_address
;
7340 if (vnext
&& vnext
< next
)
7343 display_view_pair_list (section
, &vstart
, i
, next
);
7348 if (!seen_first_offset
|| !adjacent_view_loclists
)
7349 seen_first_offset
= 1;
7353 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7354 (unsigned long) (start
- section_begin
),
7355 (unsigned long) offset
,
7357 else if (start
> next
)
7358 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7359 (unsigned long) (start
- section_begin
),
7360 (unsigned long) offset
,
7366 if (offset
>= bytes
)
7368 warn (_("Offset 0x%lx is bigger than %s section size.\n"),
7369 (unsigned long) offset
,
7374 if (vnext
&& voffset
>= bytes
)
7376 warn (_("View Offset 0x%lx is bigger than %s section size.\n"),
7377 (unsigned long) voffset
,
7385 display_loc_list_dwo (section
, &start
, i
, offset
,
7386 &vstart
, has_frame_base
);
7388 display_loc_list (section
, &start
, i
, offset
, base_address
,
7389 &vstart
, has_frame_base
);
7394 warn (_("DWO is not yet supported.\n"));
7396 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7397 &vstart
, has_frame_base
);
7400 /* FIXME: this arrangement is quite simplistic. Nothing
7401 requires locview lists to be adjacent to corresponding
7402 loclists, and a single loclist could be augmented by
7403 different locview lists, and vice-versa, unlikely as it
7404 is that it would make sense to do so. Hopefully we'll
7405 have view pair support built into loclists before we ever
7406 need to address all these possibilities. */
7407 if (adjacent_view_loclists
&& vnext
7408 && vnext
!= start
&& vstart
!= next
)
7410 adjacent_view_loclists
= 0;
7411 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7414 if (vnext
&& vnext
== start
)
7415 display_view_pair_list (section
, &start
, i
, vstart
);
7419 if (start
< section
->start
+ section
->size
)
7420 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7421 "There are %ld unused bytes at the end of section %s\n",
7422 (long) (section
->start
+ section
->size
- start
)),
7423 (long) (section
->start
+ section
->size
- start
), section
->name
);
7430 display_debug_str (struct dwarf_section
*section
,
7431 void *file ATTRIBUTE_UNUSED
)
7433 unsigned char *start
= section
->start
;
7434 dwarf_vma bytes
= section
->size
;
7435 dwarf_vma addr
= section
->address
;
7439 printf (_("\nThe %s section is empty.\n"), section
->name
);
7443 introduce (section
, false);
7451 lbytes
= (bytes
> 16 ? 16 : bytes
);
7453 printf (" 0x%8.8lx ", (unsigned long) addr
);
7455 for (j
= 0; j
< 16; j
++)
7458 printf ("%2.2x", start
[j
]);
7466 for (j
= 0; j
< lbytes
; j
++)
7469 if (k
>= ' ' && k
< 0x80)
7488 display_debug_info (struct dwarf_section
*section
, void *file
)
7490 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7494 display_debug_types (struct dwarf_section
*section
, void *file
)
7496 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7500 display_trace_info (struct dwarf_section
*section
, void *file
)
7502 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7506 display_debug_aranges (struct dwarf_section
*section
,
7507 void *file ATTRIBUTE_UNUSED
)
7509 unsigned char *start
= section
->start
;
7510 unsigned char *end
= start
+ section
->size
;
7512 introduce (section
, false);
7514 /* It does not matter if this load fails,
7515 we test for that later on. */
7516 load_debug_info (file
);
7520 unsigned char *hdrptr
;
7521 DWARF2_Internal_ARange arange
;
7522 unsigned char *addr_ranges
;
7526 unsigned char address_size
;
7527 unsigned int offset_size
;
7528 unsigned char *end_ranges
;
7531 sec_off
= hdrptr
- section
->start
;
7533 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7534 if (arange
.ar_length
== 0xffffffff)
7536 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7542 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7544 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7546 (unsigned long) sec_off
,
7547 dwarf_vmatoa ("x", arange
.ar_length
));
7550 end_ranges
= hdrptr
+ arange
.ar_length
;
7552 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7553 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7556 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7557 && num_debug_info_entries
> 0
7558 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7559 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7560 (unsigned long) arange
.ar_info_offset
, section
->name
);
7562 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7563 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7565 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7567 /* PR 19872: A version number of 0 probably means that there is
7568 padding at the end of the .debug_aranges section. Gold puts
7569 it there when performing an incremental link, for example.
7570 So do not generate a warning in this case. */
7571 if (arange
.ar_version
)
7572 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7576 printf (_(" Length: %ld\n"),
7577 (long) arange
.ar_length
);
7578 printf (_(" Version: %d\n"), arange
.ar_version
);
7579 printf (_(" Offset into .debug_info: 0x%lx\n"),
7580 (unsigned long) arange
.ar_info_offset
);
7581 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7582 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7584 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7586 /* PR 17512: file: 001-108546-0.001:0.1. */
7587 if (address_size
== 0 || address_size
> 8)
7589 error (_("Invalid address size in %s section!\n"),
7594 /* The DWARF spec does not require that the address size be a power
7595 of two, but we do. This will have to change if we ever encounter
7596 an uneven architecture. */
7597 if ((address_size
& (address_size
- 1)) != 0)
7599 warn (_("Pointer size + Segment size is not a power of two.\n"));
7603 if (address_size
> 4)
7604 printf (_("\n Address Length\n"));
7606 printf (_("\n Address Length\n"));
7608 addr_ranges
= hdrptr
;
7610 /* Must pad to an alignment boundary that is twice the address size. */
7611 addr_ranges
+= (2 * address_size
- 1
7612 - (hdrptr
- start
- 1) % (2 * address_size
));
7614 while (2 * address_size
<= end_ranges
- addr_ranges
)
7616 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7618 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7621 print_dwarf_vma (address
, address_size
);
7622 print_dwarf_vma (length
, address_size
);
7634 /* Comparison function for qsort. */
7636 comp_addr_base (const void * v0
, const void * v1
)
7638 debug_info
*info0
= *(debug_info
**) v0
;
7639 debug_info
*info1
= *(debug_info
**) v1
;
7640 return info0
->addr_base
- info1
->addr_base
;
7643 /* Display the debug_addr section. */
7645 display_debug_addr (struct dwarf_section
*section
,
7648 debug_info
**debug_addr_info
;
7649 unsigned char *entry
;
7653 unsigned char * header
;
7655 if (section
->size
== 0)
7657 printf (_("\nThe %s section is empty.\n"), section
->name
);
7661 if (load_debug_info (file
) == 0)
7663 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7668 introduce (section
, false);
7670 /* PR 17531: file: cf38d01b.
7671 We use xcalloc because a corrupt file may not have initialised all of the
7672 fields in the debug_info structure, which means that the sort below might
7673 try to move uninitialised data. */
7674 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7675 sizeof (debug_info
*));
7678 for (i
= 0; i
< num_debug_info_entries
; i
++)
7679 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7681 /* PR 17531: file: cf38d01b. */
7682 if (debug_information
[i
].addr_base
>= section
->size
)
7683 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7684 (unsigned long) debug_information
[i
].addr_base
, i
);
7686 debug_addr_info
[count
++] = debug_information
+ i
;
7689 /* Add a sentinel to make iteration convenient. */
7690 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7691 debug_addr_info
[count
]->addr_base
= section
->size
;
7692 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7694 header
= section
->start
;
7695 for (i
= 0; i
< count
; i
++)
7698 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7700 printf (_(" For compilation unit at offset 0x%s:\n"),
7701 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7703 printf (_("\tIndex\tAddress\n"));
7704 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7705 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7707 size_t header_size
= entry
- header
;
7708 unsigned char * curr_header
= header
;
7711 int segment_selector_size
;
7713 if (header_size
!= 8 && header_size
!= 16)
7715 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7716 section
->name
, (long) header_size
);
7720 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7721 if (length
== 0xffffffff)
7722 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7723 end
= curr_header
+ length
;
7725 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7727 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7728 section
->name
, version
);
7730 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7731 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7732 address_size
+= segment_selector_size
;
7735 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7740 dwarf_vma base
= byte_get (entry
, address_size
);
7741 printf (_("\t%d:\t"), idx
);
7742 print_dwarf_vma (base
, address_size
);
7744 entry
+= address_size
;
7750 free (debug_addr_info
);
7754 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7757 display_debug_str_offsets (struct dwarf_section
*section
,
7758 void *file ATTRIBUTE_UNUSED
)
7762 if (section
->size
== 0)
7764 printf (_("\nThe %s section is empty.\n"), section
->name
);
7768 unsigned char *start
= section
->start
;
7769 unsigned char *end
= start
+ section
->size
;
7770 unsigned char *curr
= start
;
7772 const char *suffix
= strrchr (section
->name
, '.');
7773 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7776 load_debug_section_with_follow (str_dwo
, file
);
7778 load_debug_section_with_follow (str
, file
);
7780 introduce (section
, false);
7785 dwarf_vma entry_length
;
7787 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7788 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7789 if (length
== 0xffffffff)
7791 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7797 unsigned char *entries_end
;
7800 /* This is probably an old style .debug_str_offset section which
7801 just contains offsets and no header (and the first offset is 0). */
7802 length
= section
->size
;
7803 curr
= section
->start
;
7806 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7807 printf (_(" Index Offset [String]\n"));
7811 if (length
<= (dwarf_vma
) (end
- curr
))
7812 entries_end
= curr
+ length
;
7815 warn (_("Section %s is too small %#lx\n"),
7816 section
->name
, (unsigned long) section
->size
);
7821 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7823 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7826 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7828 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7830 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7831 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7832 printf (_(" Index Offset [String]\n"));
7835 for (idx
= 0; curr
< entries_end
; idx
++)
7838 const unsigned char * string
;
7840 if ((dwarf_vma
) (entries_end
- curr
) < entry_length
)
7841 /* Not enough space to read one entry_length, give up. */
7844 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7846 string
= (const unsigned char *)
7847 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7849 string
= fetch_indirect_string (offset
);
7851 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7859 /* Each debug_information[x].range_lists[y] gets this representation for
7860 sorting purposes. */
7864 /* The debug_information[x].range_lists[y] value. */
7865 dwarf_vma ranges_offset
;
7867 /* Original debug_information to find parameters of the data. */
7868 debug_info
*debug_info_p
;
7871 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7874 range_entry_compar (const void *ap
, const void *bp
)
7876 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7877 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7878 const dwarf_vma a
= a_re
->ranges_offset
;
7879 const dwarf_vma b
= b_re
->ranges_offset
;
7881 return (a
> b
) - (b
> a
);
7885 display_debug_ranges_list (unsigned char * start
,
7886 unsigned char * finish
,
7887 unsigned int pointer_size
,
7889 dwarf_vma base_address
)
7891 while (start
< finish
)
7896 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7897 if (start
>= finish
)
7899 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7902 print_dwarf_vma (offset
, 4);
7904 if (begin
== 0 && end
== 0)
7906 printf (_("<End of list>\n"));
7910 /* Check base address specifiers. */
7911 if (is_max_address (begin
, pointer_size
)
7912 && !is_max_address (end
, pointer_size
))
7915 print_dwarf_vma (begin
, pointer_size
);
7916 print_dwarf_vma (end
, pointer_size
);
7917 printf ("(base address)\n");
7921 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7922 print_dwarf_vma (end
+ base_address
, pointer_size
);
7925 fputs (_("(start == end)"), stdout
);
7926 else if (begin
> end
)
7927 fputs (_("(start > end)"), stdout
);
7934 display_debug_rnglists_list (unsigned char * start
,
7935 unsigned char * finish
,
7936 unsigned int pointer_size
,
7938 dwarf_vma base_address
)
7940 unsigned char *next
= start
;
7944 dwarf_vma off
= offset
+ (start
- next
);
7945 enum dwarf_range_list_entry rlet
;
7946 /* Initialize it due to a false compiler warning. */
7947 dwarf_vma begin
= -1, length
, end
= -1;
7949 if (start
>= finish
)
7951 warn (_("Range list starting at offset 0x%s is not terminated.\n"),
7952 dwarf_vmatoa ("x", offset
));
7957 print_dwarf_vma (off
, 4);
7959 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7963 case DW_RLE_end_of_list
:
7964 printf (_("<End of list>\n"));
7966 case DW_RLE_base_addressx
:
7967 READ_ULEB (base_address
, start
, finish
);
7968 print_dwarf_vma (base_address
, pointer_size
);
7969 printf (_("(base address index) "));
7970 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
7971 print_dwarf_vma (base_address
, pointer_size
);
7972 printf (_("(base address)\n"));
7974 case DW_RLE_startx_endx
:
7975 READ_ULEB (begin
, start
, finish
);
7976 READ_ULEB (end
, start
, finish
);
7977 begin
= fetch_indexed_addr (begin
, pointer_size
);
7978 end
= fetch_indexed_addr (begin
, pointer_size
);
7980 case DW_RLE_startx_length
:
7981 READ_ULEB (begin
, start
, finish
);
7982 READ_ULEB (length
, start
, finish
);
7983 begin
= fetch_indexed_addr (begin
, pointer_size
);
7984 end
= begin
+ length
;
7986 case DW_RLE_offset_pair
:
7987 READ_ULEB (begin
, start
, finish
);
7988 READ_ULEB (end
, start
, finish
);
7990 case DW_RLE_base_address
:
7991 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7992 print_dwarf_vma (base_address
, pointer_size
);
7993 printf (_("(base address)\n"));
7995 case DW_RLE_start_end
:
7996 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7997 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7999 case DW_RLE_start_length
:
8000 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8001 READ_ULEB (length
, start
, finish
);
8002 end
= begin
+ length
;
8005 error (_("Invalid range list entry type %d\n"), rlet
);
8006 rlet
= DW_RLE_end_of_list
;
8009 if (rlet
== DW_RLE_end_of_list
)
8011 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8014 /* Only a DW_RLE_offset_pair needs the base address added. */
8015 if (rlet
== DW_RLE_offset_pair
)
8017 begin
+= base_address
;
8018 end
+= base_address
;
8021 print_dwarf_vma (begin
, pointer_size
);
8022 print_dwarf_vma (end
, pointer_size
);
8025 fputs (_("(start == end)"), stdout
);
8026 else if (begin
> end
)
8027 fputs (_("(start > end)"), stdout
);
8034 display_debug_ranges (struct dwarf_section
*section
,
8035 void *file ATTRIBUTE_UNUSED
)
8037 unsigned char * start
= section
->start
;
8038 unsigned char * last_start
= start
;
8039 dwarf_vma bytes
= section
->size
;
8040 unsigned char * section_begin
= start
;
8041 unsigned char * finish
= start
+ bytes
;
8042 unsigned int num_range_list
, i
;
8043 struct range_entry
* range_entries
;
8044 struct range_entry
* range_entry_fill
;
8045 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8046 /* Initialize it due to a false compiler warning. */
8047 unsigned char address_size
= 0;
8048 dwarf_vma last_offset
= 0;
8052 printf (_("\nThe %s section is empty.\n"), section
->name
);
8056 introduce (section
, false);
8060 dwarf_vma initial_length
;
8061 unsigned char segment_selector_size
;
8062 unsigned int offset_size
, offset_entry_count
;
8063 unsigned short version
;
8065 /* Get and check the length of the block. */
8066 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8068 if (initial_length
== 0xffffffff)
8070 /* This section is 64-bit DWARF 3. */
8071 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8077 if (initial_length
> (size_t) (finish
- start
))
8079 /* If the length field has a relocation against it, then we should
8080 not complain if it is inaccurate (and probably negative).
8081 It is copied from .debug_line handling code. */
8082 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8084 initial_length
= finish
- start
;
8088 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
8089 (long) initial_length
);
8094 /* Get the other fields in the header. */
8095 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8096 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8097 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8098 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8100 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", initial_length
));
8101 printf (_(" DWARF version: %u\n"), version
);
8102 printf (_(" Address size: %u\n"), address_size
);
8103 printf (_(" Segment size: %u\n"), segment_selector_size
);
8104 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8106 /* Check the fields. */
8107 if (segment_selector_size
!= 0)
8109 warn (_("The %s section contains "
8110 "unsupported segment selector size: %d.\n"),
8111 section
->name
, segment_selector_size
);
8117 warn (_("Only DWARF version 5+ debug_rnglists info "
8118 "is currently supported.\n"));
8122 if (offset_entry_count
!= 0)
8124 printf (_("\n Offsets starting at 0x%lx:\n"), (long)(start
- section
->start
));
8125 if (offset_size
== 8)
8127 for (i
= 0; i
< offset_entry_count
; i
++)
8131 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, finish
);
8132 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
8137 for (i
= 0; i
< offset_entry_count
; i
++)
8141 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, finish
);
8142 printf (_(" [%6u] 0x%x\n"), i
, entry
);
8148 if (load_debug_info (file
) == 0)
8150 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8156 for (i
= 0; i
< num_debug_info_entries
; i
++)
8158 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
8159 /* Skip .debug_rnglists reference. */
8161 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
8162 /* Skip .debug_range reference. */
8164 num_range_list
+= debug_information
[i
].num_range_lists
;
8167 if (num_range_list
== 0)
8169 /* This can happen when the file was compiled with -gsplit-debug
8170 which removes references to range lists from the primary .o file. */
8171 printf (_("No range lists in .debug_info section.\n"));
8175 range_entries
= (struct range_entry
*)
8176 xmalloc (sizeof (*range_entries
) * num_range_list
);
8177 range_entry_fill
= range_entries
;
8179 for (i
= 0; i
< num_debug_info_entries
; i
++)
8181 debug_info
*debug_info_p
= &debug_information
[i
];
8184 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
8185 /* Skip .debug_rnglists reference. */
8187 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
8188 /* Skip .debug_range reference. */
8191 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8193 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8194 range_entry_fill
->debug_info_p
= debug_info_p
;
8199 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8200 range_entry_compar
);
8202 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8203 warn (_("Range lists in %s section start at 0x%lx\n"),
8204 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
8207 printf (_(" Offset Begin End\n"));
8209 for (i
= 0; i
< num_range_list
; i
++)
8211 struct range_entry
*range_entry
= &range_entries
[i
];
8212 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8213 unsigned int pointer_size
;
8215 unsigned char *next
;
8216 dwarf_vma base_address
;
8218 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8219 offset
= range_entry
->ranges_offset
;
8220 base_address
= debug_info_p
->base_address
;
8222 /* PR 17512: file: 001-101485-0.001:0.1. */
8223 if (pointer_size
< 2 || pointer_size
> 8)
8225 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
8226 pointer_size
, (unsigned long) offset
);
8230 if (offset
> (size_t) (finish
- section_begin
))
8232 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
8233 (unsigned long) offset
, i
);
8236 next
= section_begin
+ offset
;
8238 /* If multiple DWARF entities reference the same range then we will
8239 have multiple entries in the `range_entries' list for the same
8240 offset. Thanks to the sort above these will all be consecutive in
8241 the `range_entries' list, so we can easily ignore duplicates
8243 if (i
> 0 && last_offset
== offset
)
8245 last_offset
= offset
;
8247 if (dwarf_check
!= 0 && i
> 0)
8250 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
8251 (unsigned long) (start
- section_begin
),
8252 (unsigned long) (next
- section_begin
), section
->name
);
8253 else if (start
> next
)
8255 if (next
== last_start
)
8257 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
8258 (unsigned long) (start
- section_begin
),
8259 (unsigned long) (next
- section_begin
), section
->name
);
8267 display_debug_rnglists_list
8268 (start
, finish
, pointer_size
, offset
, base_address
);
8270 display_debug_ranges_list
8271 (start
, finish
, pointer_size
, offset
, base_address
);
8275 free (range_entries
);
8280 typedef struct Frame_Chunk
8282 struct Frame_Chunk
*next
;
8283 unsigned char *chunk_start
;
8285 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8286 short int *col_type
;
8289 unsigned int code_factor
;
8293 unsigned int cfa_reg
;
8294 dwarf_vma cfa_offset
;
8296 unsigned char fde_encoding
;
8297 unsigned char cfa_exp
;
8298 unsigned char ptr_size
;
8299 unsigned char segment_size
;
8303 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8304 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8305 static const char *const *dwarf_regnames
;
8306 static unsigned int dwarf_regnames_count
;
8309 /* A marker for a col_type that means this column was never referenced
8310 in the frame info. */
8311 #define DW_CFA_unreferenced (-1)
8313 /* Return 0 if no more space is needed, 1 if more space is needed,
8314 -1 for invalid reg. */
8317 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8319 unsigned int prev
= fc
->ncols
;
8321 if (reg
< (unsigned int) fc
->ncols
)
8324 if (dwarf_regnames_count
> 0
8325 && reg
> dwarf_regnames_count
)
8328 fc
->ncols
= reg
+ 1;
8329 /* PR 17512: file: 10450-2643-0.004.
8330 If reg == -1 then this can happen... */
8334 /* PR 17512: file: 2844a11d. */
8335 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8337 error (_("Unfeasibly large register number: %u\n"), reg
);
8339 /* FIXME: 1024 is an arbitrary limit. Increase it if
8340 we ever encounter a valid binary that exceeds it. */
8344 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
8345 sizeof (short int));
8346 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
8347 /* PR 17512: file:002-10025-0.005. */
8348 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8350 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8356 while (prev
< fc
->ncols
)
8358 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8359 fc
->col_offset
[prev
] = 0;
8365 static const char *const dwarf_regnames_i386
[] =
8367 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8368 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8369 "eip", "eflags", NULL
, /* 8 - 10 */
8370 "st0", "st1", "st2", "st3", /* 11 - 14 */
8371 "st4", "st5", "st6", "st7", /* 15 - 18 */
8372 NULL
, NULL
, /* 19 - 20 */
8373 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8374 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8375 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8376 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8377 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8378 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8379 "tr", "ldtr", /* 48 - 49 */
8380 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8381 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8382 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8383 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8384 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8385 NULL
, NULL
, NULL
, /* 90 - 92 */
8386 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8389 static const char *const dwarf_regnames_iamcu
[] =
8391 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8392 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8393 "eip", "eflags", NULL
, /* 8 - 10 */
8394 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8395 NULL
, NULL
, /* 19 - 20 */
8396 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8397 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8398 NULL
, NULL
, NULL
, /* 37 - 39 */
8399 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8400 "tr", "ldtr", /* 48 - 49 */
8401 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8402 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8403 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8404 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8405 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8406 NULL
, NULL
, NULL
, /* 90 - 92 */
8407 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8411 init_dwarf_regnames_i386 (void)
8413 dwarf_regnames
= dwarf_regnames_i386
;
8414 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8415 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8419 init_dwarf_regnames_iamcu (void)
8421 dwarf_regnames
= dwarf_regnames_iamcu
;
8422 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8423 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8426 static const char *const dwarf_regnames_x86_64
[] =
8428 "rax", "rdx", "rcx", "rbx",
8429 "rsi", "rdi", "rbp", "rsp",
8430 "r8", "r9", "r10", "r11",
8431 "r12", "r13", "r14", "r15",
8433 "xmm0", "xmm1", "xmm2", "xmm3",
8434 "xmm4", "xmm5", "xmm6", "xmm7",
8435 "xmm8", "xmm9", "xmm10", "xmm11",
8436 "xmm12", "xmm13", "xmm14", "xmm15",
8437 "st0", "st1", "st2", "st3",
8438 "st4", "st5", "st6", "st7",
8439 "mm0", "mm1", "mm2", "mm3",
8440 "mm4", "mm5", "mm6", "mm7",
8442 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8443 "fs.base", "gs.base", NULL
, NULL
,
8445 "mxcsr", "fcw", "fsw",
8446 "xmm16", "xmm17", "xmm18", "xmm19",
8447 "xmm20", "xmm21", "xmm22", "xmm23",
8448 "xmm24", "xmm25", "xmm26", "xmm27",
8449 "xmm28", "xmm29", "xmm30", "xmm31",
8450 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8451 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8452 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8453 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8454 NULL
, NULL
, NULL
, /* 115 - 117 */
8455 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8459 init_dwarf_regnames_x86_64 (void)
8461 dwarf_regnames
= dwarf_regnames_x86_64
;
8462 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8463 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8466 static const char *const dwarf_regnames_aarch64
[] =
8468 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8469 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8470 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8471 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8472 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8473 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8474 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8475 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8476 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8477 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8478 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8479 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8480 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8481 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8482 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8483 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8487 init_dwarf_regnames_aarch64 (void)
8489 dwarf_regnames
= dwarf_regnames_aarch64
;
8490 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8491 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8494 static const char *const dwarf_regnames_s390
[] =
8496 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8497 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8498 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8499 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8500 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8501 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8502 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8503 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8504 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8507 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8508 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8512 init_dwarf_regnames_s390 (void)
8514 dwarf_regnames
= dwarf_regnames_s390
;
8515 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8516 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8519 static const char *const dwarf_regnames_riscv
[] =
8521 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8522 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8523 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8524 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8525 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8526 "fs0", "fs1", /* 40 - 41 */
8527 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8528 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8529 "fs10", "fs11", /* 58 - 59 */
8530 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8533 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8534 the large number of CSRs. */
8537 regname_internal_riscv (unsigned int regno
)
8539 const char *name
= NULL
;
8541 /* Lookup in the table first, this covers GPR and FPR. */
8542 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8543 name
= dwarf_regnames_riscv
[regno
];
8544 else if (regno
>= 4096 && regno
<= 8191)
8546 /* This might be a CSR, these live in a sparse number space from 4096
8547 to 8191 These numbers are defined in the RISC-V ELF ABI
8551 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8552 case VALUE + 4096: name = #NAME; break;
8553 #include "opcode/riscv-opc.h"
8558 static char csr_name
[10];
8559 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8570 init_dwarf_regnames_riscv (void)
8572 dwarf_regnames
= NULL
;
8573 dwarf_regnames_count
= 8192;
8574 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8578 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8580 dwarf_regnames_lookup_func
= NULL
;
8585 init_dwarf_regnames_i386 ();
8589 init_dwarf_regnames_iamcu ();
8595 init_dwarf_regnames_x86_64 ();
8599 init_dwarf_regnames_aarch64 ();
8603 init_dwarf_regnames_s390 ();
8607 init_dwarf_regnames_riscv ();
8615 /* Initialize the DWARF register name lookup state based on the
8616 architecture and specific machine type of a BFD. */
8619 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8622 dwarf_regnames_lookup_func
= NULL
;
8629 case bfd_mach_x86_64
:
8630 case bfd_mach_x86_64_intel_syntax
:
8631 case bfd_mach_x64_32
:
8632 case bfd_mach_x64_32_intel_syntax
:
8633 init_dwarf_regnames_x86_64 ();
8637 init_dwarf_regnames_i386 ();
8642 case bfd_arch_iamcu
:
8643 init_dwarf_regnames_iamcu ();
8646 case bfd_arch_aarch64
:
8647 init_dwarf_regnames_aarch64();
8651 init_dwarf_regnames_s390 ();
8654 case bfd_arch_riscv
:
8655 init_dwarf_regnames_riscv ();
8664 regname_internal_by_table_only (unsigned int regno
)
8666 if (dwarf_regnames
!= NULL
8667 && regno
< dwarf_regnames_count
8668 && dwarf_regnames
[regno
] != NULL
)
8669 return dwarf_regnames
[regno
];
8675 regname (unsigned int regno
, int name_only_p
)
8677 static char reg
[64];
8679 const char *name
= NULL
;
8681 if (dwarf_regnames_lookup_func
!= NULL
)
8682 name
= dwarf_regnames_lookup_func (regno
);
8688 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8691 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8696 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8701 if (*max_regs
!= fc
->ncols
)
8702 *max_regs
= fc
->ncols
;
8704 if (*need_col_headers
)
8706 *need_col_headers
= 0;
8708 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8710 for (r
= 0; r
< *max_regs
; r
++)
8711 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8716 printf ("%-5s ", regname (r
, 1));
8722 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8724 strcpy (tmp
, "exp");
8726 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8727 printf ("%-8s ", tmp
);
8729 for (r
= 0; r
< fc
->ncols
; r
++)
8731 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8733 switch (fc
->col_type
[r
])
8735 case DW_CFA_undefined
:
8738 case DW_CFA_same_value
:
8742 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8744 case DW_CFA_val_offset
:
8745 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8747 case DW_CFA_register
:
8748 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8750 case DW_CFA_expression
:
8751 strcpy (tmp
, "exp");
8753 case DW_CFA_val_expression
:
8754 strcpy (tmp
, "vexp");
8757 strcpy (tmp
, "n/a");
8760 printf ("%-5s ", tmp
);
8766 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8768 static unsigned char *
8769 read_cie (unsigned char *start
, unsigned char *end
,
8770 Frame_Chunk
**p_cie
, int *p_version
,
8771 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8775 unsigned char *augmentation_data
= NULL
;
8776 bfd_size_type augmentation_data_len
= 0;
8779 /* PR 17512: file: 001-228113-0.004. */
8783 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8784 memset (fc
, 0, sizeof (Frame_Chunk
));
8786 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8787 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8791 fc
->augmentation
= (char *) start
;
8792 /* PR 17512: file: 001-228113-0.004.
8793 Skip past augmentation name, but avoid running off the end of the data. */
8795 if (* start
++ == '\0')
8799 warn (_("No terminator for augmentation name\n"));
8803 if (strcmp (fc
->augmentation
, "eh") == 0)
8805 if (eh_addr_size
> (size_t) (end
- start
))
8807 start
+= eh_addr_size
;
8812 if (2 > (size_t) (end
- start
))
8814 GET (fc
->ptr_size
, 1);
8815 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8817 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8821 GET (fc
->segment_size
, 1);
8822 /* PR 17512: file: e99d2804. */
8823 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8825 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8829 eh_addr_size
= fc
->ptr_size
;
8833 fc
->ptr_size
= eh_addr_size
;
8834 fc
->segment_size
= 0;
8837 READ_ULEB (fc
->code_factor
, start
, end
);
8838 READ_SLEB (fc
->data_factor
, start
, end
);
8849 READ_ULEB (fc
->ra
, start
, end
);
8852 if (fc
->augmentation
[0] == 'z')
8856 READ_ULEB (augmentation_data_len
, start
, end
);
8857 augmentation_data
= start
;
8858 /* PR 17512: file: 11042-2589-0.004. */
8859 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8861 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8862 dwarf_vmatoa ("x", augmentation_data_len
),
8863 (unsigned long) (end
- start
));
8866 start
+= augmentation_data_len
;
8869 if (augmentation_data_len
)
8873 unsigned char *qend
;
8875 p
= (unsigned char *) fc
->augmentation
+ 1;
8876 q
= augmentation_data
;
8877 qend
= q
+ augmentation_data_len
;
8879 while (p
< end
&& q
< qend
)
8884 q
+= 1 + size_of_encoded_value (*q
);
8886 fc
->fde_encoding
= *q
++;
8895 /* Note - it is OK if this loop terminates with q < qend.
8896 Padding may have been inserted to align the end of the CIE. */
8901 *p_version
= version
;
8904 *p_aug_len
= augmentation_data_len
;
8905 *p_aug
= augmentation_data
;
8910 free (fc
->col_offset
);
8911 free (fc
->col_type
);
8916 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8917 If do_wide is not enabled, then formats the output to fit into 80 columns.
8918 PRINTED contains the number of characters already written to the current
8922 display_data (bfd_size_type printed
,
8923 const unsigned char * data
,
8924 const bfd_size_type len
)
8926 if (do_wide
|| len
< ((80 - printed
) / 3))
8927 for (printed
= 0; printed
< len
; ++printed
)
8928 printf (" %02x", data
[printed
]);
8931 for (printed
= 0; printed
< len
; ++printed
)
8933 if (printed
% (80 / 3) == 0)
8935 printf (" %02x", data
[printed
]);
8940 /* Prints out the contents on the augmentation data array.
8941 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8944 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8948 i
= printf (_(" Augmentation data: "));
8949 display_data (i
, data
, len
);
8953 display_debug_frames (struct dwarf_section
*section
,
8954 void *file ATTRIBUTE_UNUSED
)
8956 unsigned char *start
= section
->start
;
8957 unsigned char *end
= start
+ section
->size
;
8958 unsigned char *section_start
= start
;
8959 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8960 Frame_Chunk
*remembered_state
= NULL
;
8962 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8963 unsigned int max_regs
= 0;
8964 const char *bad_reg
= _("bad register: ");
8965 unsigned int saved_eh_addr_size
= eh_addr_size
;
8967 introduce (section
, false);
8971 unsigned char *saved_start
;
8972 unsigned char *block_end
;
8977 int need_col_headers
= 1;
8978 unsigned char *augmentation_data
= NULL
;
8979 bfd_size_type augmentation_data_len
= 0;
8980 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8981 unsigned int offset_size
;
8983 static Frame_Chunk fde_fc
;
8985 saved_start
= start
;
8987 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8991 printf ("\n%08lx ZERO terminator\n\n",
8992 (unsigned long)(saved_start
- section_start
));
8993 /* Skip any zero terminators that directly follow.
8994 A corrupt section size could have loaded a whole
8995 slew of zero filled memory bytes. eg
8996 PR 17512: file: 070-19381-0.004. */
8997 while (start
< end
&& * start
== 0)
9002 if (length
== 0xffffffff)
9004 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9010 if (length
> (size_t) (end
- start
))
9012 warn ("Invalid length 0x%s in FDE at %#08lx\n",
9013 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
9014 (unsigned long) (saved_start
- section_start
));
9018 block_end
= start
+ length
;
9020 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9022 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9023 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9028 start
= read_cie (start
, block_end
, &cie
, &version
,
9029 &augmentation_data_len
, &augmentation_data
);
9030 /* PR 17512: file: 027-135133-0.005. */
9037 fc
->chunk_start
= saved_start
;
9038 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9041 if (frame_need_space (fc
, mreg
) < 0)
9043 if (fc
->fde_encoding
)
9044 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9046 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
9047 print_dwarf_vma (length
, fc
->ptr_size
);
9048 print_dwarf_vma (cie_id
, offset_size
);
9050 if (do_debug_frames_interp
)
9052 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9053 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9058 printf (" Version: %d\n", version
);
9059 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9062 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9063 printf (" Segment Size: %u\n", fc
->segment_size
);
9065 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9066 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9067 printf (" Return address column: %d\n", fc
->ra
);
9069 if (augmentation_data_len
)
9070 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9077 unsigned char *look_for
;
9078 unsigned long segment_selector
;
9084 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
9085 cie_off
= (cie_off
^ sign
) - sign
;
9086 cie_off
= start
- 4 - section_start
- cie_off
;
9089 look_for
= section_start
+ cie_off
;
9090 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
9092 for (cie
= chunks
; cie
; cie
= cie
->next
)
9093 if (cie
->chunk_start
== look_for
)
9096 else if (cie_off
>= section
->size
)
9100 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9101 if (cie
->chunk_start
== look_for
)
9105 unsigned int off_size
;
9106 unsigned char *cie_scan
;
9108 cie_scan
= look_for
;
9110 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9111 if (length
== 0xffffffff)
9113 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9116 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9119 unsigned char *cie_end
= cie_scan
+ length
;
9121 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9125 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9126 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9131 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9132 &augmentation_data_len
, &augmentation_data
);
9133 /* PR 17512: file: 3450-2098-0.004. */
9136 warn (_("Failed to read CIE information\n"));
9139 cie
->next
= forward_refs
;
9141 cie
->chunk_start
= look_for
;
9142 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9145 if (frame_need_space (cie
, mreg
) < 0)
9147 warn (_("Invalid max register\n"));
9150 if (cie
->fde_encoding
)
9152 = size_of_encoded_value (cie
->fde_encoding
);
9159 memset (fc
, 0, sizeof (Frame_Chunk
));
9164 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
9165 fc
->col_offset
= (int *) xmalloc (sizeof (int));
9166 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9168 warn (_("Invalid max register\n"));
9172 fc
->augmentation
= "";
9173 fc
->fde_encoding
= 0;
9174 fc
->ptr_size
= eh_addr_size
;
9175 fc
->segment_size
= 0;
9179 fc
->ncols
= cie
->ncols
;
9180 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
9181 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
9182 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
9183 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
9184 fc
->augmentation
= cie
->augmentation
;
9185 fc
->ptr_size
= cie
->ptr_size
;
9186 eh_addr_size
= cie
->ptr_size
;
9187 fc
->segment_size
= cie
->segment_size
;
9188 fc
->code_factor
= cie
->code_factor
;
9189 fc
->data_factor
= cie
->data_factor
;
9190 fc
->cfa_reg
= cie
->cfa_reg
;
9191 fc
->cfa_offset
= cie
->cfa_offset
;
9193 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9195 warn (_("Invalid max register\n"));
9198 fc
->fde_encoding
= cie
->fde_encoding
;
9201 if (fc
->fde_encoding
)
9202 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9204 segment_selector
= 0;
9205 if (fc
->segment_size
)
9207 if (fc
->segment_size
> sizeof (segment_selector
))
9209 /* PR 17512: file: 9e196b3e. */
9210 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9211 fc
->segment_size
= 4;
9213 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9214 fc
->segment_size
, block_end
);
9217 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9220 /* FIXME: It appears that sometimes the final pc_range value is
9221 encoded in less than encoded_ptr_size bytes. See the x86_64
9222 run of the "objcopy on compressed debug sections" test for an
9224 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9227 if (cie
->augmentation
[0] == 'z')
9229 READ_ULEB (augmentation_data_len
, start
, block_end
);
9230 augmentation_data
= start
;
9231 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9232 if (augmentation_data_len
> (bfd_size_type
) (block_end
- start
))
9234 warn (_("Augmentation data too long: 0x%s, "
9235 "expected at most %#lx\n"),
9236 dwarf_vmatoa ("x", augmentation_data_len
),
9237 (unsigned long) (block_end
- start
));
9239 augmentation_data
= NULL
;
9240 augmentation_data_len
= 0;
9242 start
+= augmentation_data_len
;
9245 printf ("\n%08lx %s %s FDE ",
9246 (unsigned long)(saved_start
- section_start
),
9247 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
9248 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
));
9250 if (cie
->chunk_start
)
9251 printf ("cie=%08lx",
9252 (unsigned long) (cie
->chunk_start
- section_start
));
9254 /* Ideally translate "invalid " to 8 chars, trailing space
9256 printf (_("cie=invalid "));
9259 if (fc
->segment_size
)
9260 printf ("%04lx:", segment_selector
);
9263 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
9264 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
9266 if (! do_debug_frames_interp
&& augmentation_data_len
)
9268 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9273 /* At this point, fc is the current chunk, cie (if any) is set, and
9274 we're about to interpret instructions for the chunk. */
9275 /* ??? At present we need to do this always, since this sizes the
9276 fc->col_type and fc->col_offset arrays, which we write into always.
9277 We should probably split the interpreted and non-interpreted bits
9278 into two different routines, since there's so much that doesn't
9279 really overlap between them. */
9280 if (1 || do_debug_frames_interp
)
9282 /* Start by making a pass over the chunk, allocating storage
9283 and taking note of what registers are used. */
9284 unsigned char *tmp
= start
;
9286 while (start
< block_end
)
9288 unsigned int reg
, op
, opa
;
9296 /* Warning: if you add any more cases to this switch, be
9297 sure to add them to the corresponding switch below. */
9300 case DW_CFA_advance_loc
:
9303 SKIP_ULEB (start
, block_end
);
9304 if (frame_need_space (fc
, opa
) >= 0)
9305 fc
->col_type
[opa
] = DW_CFA_undefined
;
9307 case DW_CFA_restore
:
9308 if (frame_need_space (fc
, opa
) >= 0)
9309 fc
->col_type
[opa
] = DW_CFA_undefined
;
9311 case DW_CFA_set_loc
:
9312 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9315 start
+= encoded_ptr_size
;
9317 case DW_CFA_advance_loc1
:
9318 if ((size_t) (block_end
- start
) < 1)
9323 case DW_CFA_advance_loc2
:
9324 if ((size_t) (block_end
- start
) < 2)
9329 case DW_CFA_advance_loc4
:
9330 if ((size_t) (block_end
- start
) < 4)
9335 case DW_CFA_offset_extended
:
9336 case DW_CFA_val_offset
:
9337 READ_ULEB (reg
, start
, block_end
);
9338 SKIP_ULEB (start
, block_end
);
9339 if (frame_need_space (fc
, reg
) >= 0)
9340 fc
->col_type
[reg
] = DW_CFA_undefined
;
9342 case DW_CFA_restore_extended
:
9343 READ_ULEB (reg
, start
, block_end
);
9344 if (frame_need_space (fc
, reg
) >= 0)
9345 fc
->col_type
[reg
] = DW_CFA_undefined
;
9347 case DW_CFA_undefined
:
9348 READ_ULEB (reg
, start
, block_end
);
9349 if (frame_need_space (fc
, reg
) >= 0)
9350 fc
->col_type
[reg
] = DW_CFA_undefined
;
9352 case DW_CFA_same_value
:
9353 READ_ULEB (reg
, start
, block_end
);
9354 if (frame_need_space (fc
, reg
) >= 0)
9355 fc
->col_type
[reg
] = DW_CFA_undefined
;
9357 case DW_CFA_register
:
9358 READ_ULEB (reg
, start
, block_end
);
9359 SKIP_ULEB (start
, block_end
);
9360 if (frame_need_space (fc
, reg
) >= 0)
9361 fc
->col_type
[reg
] = DW_CFA_undefined
;
9363 case DW_CFA_def_cfa
:
9364 SKIP_ULEB (start
, block_end
);
9365 SKIP_ULEB (start
, block_end
);
9367 case DW_CFA_def_cfa_register
:
9368 SKIP_ULEB (start
, block_end
);
9370 case DW_CFA_def_cfa_offset
:
9371 SKIP_ULEB (start
, block_end
);
9373 case DW_CFA_def_cfa_expression
:
9374 READ_ULEB (temp
, start
, block_end
);
9375 if ((size_t) (block_end
- start
) < temp
)
9380 case DW_CFA_expression
:
9381 case DW_CFA_val_expression
:
9382 READ_ULEB (reg
, start
, block_end
);
9383 READ_ULEB (temp
, start
, block_end
);
9384 if ((size_t) (block_end
- start
) < temp
)
9388 if (frame_need_space (fc
, reg
) >= 0)
9389 fc
->col_type
[reg
] = DW_CFA_undefined
;
9391 case DW_CFA_offset_extended_sf
:
9392 case DW_CFA_val_offset_sf
:
9393 READ_ULEB (reg
, start
, block_end
);
9394 SKIP_SLEB (start
, block_end
);
9395 if (frame_need_space (fc
, reg
) >= 0)
9396 fc
->col_type
[reg
] = DW_CFA_undefined
;
9398 case DW_CFA_def_cfa_sf
:
9399 SKIP_ULEB (start
, block_end
);
9400 SKIP_SLEB (start
, block_end
);
9402 case DW_CFA_def_cfa_offset_sf
:
9403 SKIP_SLEB (start
, block_end
);
9405 case DW_CFA_MIPS_advance_loc8
:
9406 if ((size_t) (block_end
- start
) < 8)
9411 case DW_CFA_GNU_args_size
:
9412 SKIP_ULEB (start
, block_end
);
9414 case DW_CFA_GNU_negative_offset_extended
:
9415 READ_ULEB (reg
, start
, block_end
);
9416 SKIP_ULEB (start
, block_end
);
9417 if (frame_need_space (fc
, reg
) >= 0)
9418 fc
->col_type
[reg
] = DW_CFA_undefined
;
9429 /* Now we know what registers are used, make a second pass over
9430 the chunk, this time actually printing out the info. */
9432 while (start
< block_end
)
9435 unsigned long ul
, roffs
;
9436 /* Note: It is tempting to use an unsigned long for 'reg' but there
9437 are various functions, notably frame_space_needed() that assume that
9438 reg is an unsigned int. */
9443 const char *reg_prefix
= "";
9450 /* Make a note if something other than DW_CFA_nop happens. */
9451 if (op
!= DW_CFA_nop
)
9454 /* Warning: if you add any more cases to this switch, be
9455 sure to add them to the corresponding switch above. */
9458 case DW_CFA_advance_loc
:
9459 if (do_debug_frames_interp
)
9460 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9462 printf (" DW_CFA_advance_loc: %d to %s\n",
9463 opa
* fc
->code_factor
,
9464 dwarf_vmatoa_1 (NULL
,
9465 fc
->pc_begin
+ opa
* fc
->code_factor
,
9467 fc
->pc_begin
+= opa
* fc
->code_factor
;
9471 READ_ULEB (roffs
, start
, block_end
);
9472 if (opa
>= (unsigned int) fc
->ncols
)
9473 reg_prefix
= bad_reg
;
9474 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9475 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9476 reg_prefix
, regname (opa
, 0),
9477 roffs
* fc
->data_factor
);
9478 if (*reg_prefix
== '\0')
9480 fc
->col_type
[opa
] = DW_CFA_offset
;
9481 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9485 case DW_CFA_restore
:
9486 if (opa
>= (unsigned int) fc
->ncols
)
9487 reg_prefix
= bad_reg
;
9488 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9489 printf (" DW_CFA_restore: %s%s\n",
9490 reg_prefix
, regname (opa
, 0));
9491 if (*reg_prefix
!= '\0')
9494 if (opa
>= (unsigned int) cie
->ncols
9495 || (do_debug_frames_interp
9496 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9498 fc
->col_type
[opa
] = DW_CFA_undefined
;
9499 fc
->col_offset
[opa
] = 0;
9503 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9504 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9508 case DW_CFA_set_loc
:
9509 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9511 if (do_debug_frames_interp
)
9512 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9514 printf (" DW_CFA_set_loc: %s\n",
9515 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9519 case DW_CFA_advance_loc1
:
9520 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9521 if (do_debug_frames_interp
)
9522 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9524 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9525 (unsigned long) (ofs
* fc
->code_factor
),
9526 dwarf_vmatoa_1 (NULL
,
9527 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9529 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9532 case DW_CFA_advance_loc2
:
9533 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9534 if (do_debug_frames_interp
)
9535 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9537 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9538 (unsigned long) (ofs
* fc
->code_factor
),
9539 dwarf_vmatoa_1 (NULL
,
9540 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9542 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9545 case DW_CFA_advance_loc4
:
9546 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9547 if (do_debug_frames_interp
)
9548 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9550 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9551 (unsigned long) (ofs
* fc
->code_factor
),
9552 dwarf_vmatoa_1 (NULL
,
9553 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9555 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9558 case DW_CFA_offset_extended
:
9559 READ_ULEB (reg
, start
, block_end
);
9560 READ_ULEB (roffs
, start
, block_end
);
9561 if (reg
>= (unsigned int) fc
->ncols
)
9562 reg_prefix
= bad_reg
;
9563 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9564 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9565 reg_prefix
, regname (reg
, 0),
9566 roffs
* fc
->data_factor
);
9567 if (*reg_prefix
== '\0')
9569 fc
->col_type
[reg
] = DW_CFA_offset
;
9570 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9574 case DW_CFA_val_offset
:
9575 READ_ULEB (reg
, start
, block_end
);
9576 READ_ULEB (roffs
, start
, block_end
);
9577 if (reg
>= (unsigned int) fc
->ncols
)
9578 reg_prefix
= bad_reg
;
9579 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9580 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9581 reg_prefix
, regname (reg
, 0),
9582 roffs
* fc
->data_factor
);
9583 if (*reg_prefix
== '\0')
9585 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9586 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9590 case DW_CFA_restore_extended
:
9591 READ_ULEB (reg
, start
, block_end
);
9592 if (reg
>= (unsigned int) fc
->ncols
)
9593 reg_prefix
= bad_reg
;
9594 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9595 printf (" DW_CFA_restore_extended: %s%s\n",
9596 reg_prefix
, regname (reg
, 0));
9597 if (*reg_prefix
!= '\0')
9600 if (reg
>= (unsigned int) cie
->ncols
)
9602 fc
->col_type
[reg
] = DW_CFA_undefined
;
9603 fc
->col_offset
[reg
] = 0;
9607 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9608 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9612 case DW_CFA_undefined
:
9613 READ_ULEB (reg
, start
, block_end
);
9614 if (reg
>= (unsigned int) fc
->ncols
)
9615 reg_prefix
= bad_reg
;
9616 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9617 printf (" DW_CFA_undefined: %s%s\n",
9618 reg_prefix
, regname (reg
, 0));
9619 if (*reg_prefix
== '\0')
9621 fc
->col_type
[reg
] = DW_CFA_undefined
;
9622 fc
->col_offset
[reg
] = 0;
9626 case DW_CFA_same_value
:
9627 READ_ULEB (reg
, start
, block_end
);
9628 if (reg
>= (unsigned int) fc
->ncols
)
9629 reg_prefix
= bad_reg
;
9630 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9631 printf (" DW_CFA_same_value: %s%s\n",
9632 reg_prefix
, regname (reg
, 0));
9633 if (*reg_prefix
== '\0')
9635 fc
->col_type
[reg
] = DW_CFA_same_value
;
9636 fc
->col_offset
[reg
] = 0;
9640 case DW_CFA_register
:
9641 READ_ULEB (reg
, start
, block_end
);
9642 READ_ULEB (roffs
, start
, block_end
);
9643 if (reg
>= (unsigned int) fc
->ncols
)
9644 reg_prefix
= bad_reg
;
9645 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9647 printf (" DW_CFA_register: %s%s in ",
9648 reg_prefix
, regname (reg
, 0));
9649 puts (regname (roffs
, 0));
9651 if (*reg_prefix
== '\0')
9653 fc
->col_type
[reg
] = DW_CFA_register
;
9654 fc
->col_offset
[reg
] = roffs
;
9658 case DW_CFA_remember_state
:
9659 if (! do_debug_frames_interp
)
9660 printf (" DW_CFA_remember_state\n");
9661 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9662 rs
->cfa_offset
= fc
->cfa_offset
;
9663 rs
->cfa_reg
= fc
->cfa_reg
;
9665 rs
->cfa_exp
= fc
->cfa_exp
;
9666 rs
->ncols
= fc
->ncols
;
9667 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9668 sizeof (* rs
->col_type
));
9669 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9670 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9671 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9672 rs
->next
= remembered_state
;
9673 remembered_state
= rs
;
9676 case DW_CFA_restore_state
:
9677 if (! do_debug_frames_interp
)
9678 printf (" DW_CFA_restore_state\n");
9679 rs
= remembered_state
;
9682 remembered_state
= rs
->next
;
9683 fc
->cfa_offset
= rs
->cfa_offset
;
9684 fc
->cfa_reg
= rs
->cfa_reg
;
9686 fc
->cfa_exp
= rs
->cfa_exp
;
9687 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9689 warn (_("Invalid column number in saved frame state\n"));
9693 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9694 memcpy (fc
->col_offset
, rs
->col_offset
,
9695 rs
->ncols
* sizeof (* rs
->col_offset
));
9696 free (rs
->col_type
);
9697 free (rs
->col_offset
);
9700 else if (do_debug_frames_interp
)
9701 printf ("Mismatched DW_CFA_restore_state\n");
9704 case DW_CFA_def_cfa
:
9705 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9706 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9708 if (! do_debug_frames_interp
)
9709 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9710 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9713 case DW_CFA_def_cfa_register
:
9714 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9716 if (! do_debug_frames_interp
)
9717 printf (" DW_CFA_def_cfa_register: %s\n",
9718 regname (fc
->cfa_reg
, 0));
9721 case DW_CFA_def_cfa_offset
:
9722 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9723 if (! do_debug_frames_interp
)
9724 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9728 if (! do_debug_frames_interp
)
9729 printf (" DW_CFA_nop\n");
9732 case DW_CFA_def_cfa_expression
:
9733 READ_ULEB (ul
, start
, block_end
);
9734 if (ul
> (size_t) (block_end
- start
))
9736 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9739 if (! do_debug_frames_interp
)
9741 printf (" DW_CFA_def_cfa_expression (");
9742 decode_location_expression (start
, eh_addr_size
, 0, -1,
9750 case DW_CFA_expression
:
9751 READ_ULEB (reg
, start
, block_end
);
9752 READ_ULEB (ul
, start
, block_end
);
9753 if (reg
>= (unsigned int) fc
->ncols
)
9754 reg_prefix
= bad_reg
;
9755 /* PR 17512: file: 069-133014-0.006. */
9756 /* PR 17512: file: 98c02eb4. */
9757 if (ul
> (size_t) (block_end
- start
))
9759 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9762 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9764 printf (" DW_CFA_expression: %s%s (",
9765 reg_prefix
, regname (reg
, 0));
9766 decode_location_expression (start
, eh_addr_size
, 0, -1,
9770 if (*reg_prefix
== '\0')
9771 fc
->col_type
[reg
] = DW_CFA_expression
;
9775 case DW_CFA_val_expression
:
9776 READ_ULEB (reg
, start
, block_end
);
9777 READ_ULEB (ul
, start
, block_end
);
9778 if (reg
>= (unsigned int) fc
->ncols
)
9779 reg_prefix
= bad_reg
;
9780 if (ul
> (size_t) (block_end
- start
))
9782 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9785 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9787 printf (" DW_CFA_val_expression: %s%s (",
9788 reg_prefix
, regname (reg
, 0));
9789 decode_location_expression (start
, eh_addr_size
, 0, -1,
9793 if (*reg_prefix
== '\0')
9794 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9798 case DW_CFA_offset_extended_sf
:
9799 READ_ULEB (reg
, start
, block_end
);
9800 READ_SLEB (l
, start
, block_end
);
9801 if (frame_need_space (fc
, reg
) < 0)
9802 reg_prefix
= bad_reg
;
9803 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9804 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9805 reg_prefix
, regname (reg
, 0),
9806 (long)(l
* fc
->data_factor
));
9807 if (*reg_prefix
== '\0')
9809 fc
->col_type
[reg
] = DW_CFA_offset
;
9810 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9814 case DW_CFA_val_offset_sf
:
9815 READ_ULEB (reg
, start
, block_end
);
9816 READ_SLEB (l
, start
, block_end
);
9817 if (frame_need_space (fc
, reg
) < 0)
9818 reg_prefix
= bad_reg
;
9819 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9820 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9821 reg_prefix
, regname (reg
, 0),
9822 (long)(l
* fc
->data_factor
));
9823 if (*reg_prefix
== '\0')
9825 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9826 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9830 case DW_CFA_def_cfa_sf
:
9831 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9832 READ_SLEB (l
, start
, block_end
);
9833 l
*= fc
->data_factor
;
9836 if (! do_debug_frames_interp
)
9837 printf (" DW_CFA_def_cfa_sf: %s ofs %ld\n",
9838 regname (fc
->cfa_reg
, 0), (long) l
);
9841 case DW_CFA_def_cfa_offset_sf
:
9842 READ_SLEB (l
, start
, block_end
);
9843 l
*= fc
->data_factor
;
9845 if (! do_debug_frames_interp
)
9846 printf (" DW_CFA_def_cfa_offset_sf: %ld\n", (long) l
);
9849 case DW_CFA_MIPS_advance_loc8
:
9850 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9851 if (do_debug_frames_interp
)
9852 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9854 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9855 (unsigned long) (ofs
* fc
->code_factor
),
9856 dwarf_vmatoa_1 (NULL
,
9857 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9859 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9862 case DW_CFA_GNU_window_save
:
9863 if (! do_debug_frames_interp
)
9864 printf (" DW_CFA_GNU_window_save\n");
9867 case DW_CFA_GNU_args_size
:
9868 READ_ULEB (ul
, start
, block_end
);
9869 if (! do_debug_frames_interp
)
9870 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9873 case DW_CFA_GNU_negative_offset_extended
:
9874 READ_ULEB (reg
, start
, block_end
);
9875 READ_SLEB (l
, start
, block_end
);
9877 if (frame_need_space (fc
, reg
) < 0)
9878 reg_prefix
= bad_reg
;
9879 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9880 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9881 reg_prefix
, regname (reg
, 0),
9882 (long)(l
* fc
->data_factor
));
9883 if (*reg_prefix
== '\0')
9885 fc
->col_type
[reg
] = DW_CFA_offset
;
9886 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9891 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9892 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9894 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9899 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9900 if (do_debug_frames_interp
&& ! all_nops
)
9901 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9903 if (fde_fc
.col_type
!= NULL
)
9905 free (fde_fc
.col_type
);
9906 fde_fc
.col_type
= NULL
;
9908 if (fde_fc
.col_offset
!= NULL
)
9910 free (fde_fc
.col_offset
);
9911 fde_fc
.col_offset
= NULL
;
9915 eh_addr_size
= saved_eh_addr_size
;
9920 while (remembered_state
!= NULL
)
9922 rs
= remembered_state
;
9923 remembered_state
= rs
->next
;
9924 free (rs
->col_type
);
9925 free (rs
->col_offset
);
9926 rs
->next
= NULL
; /* Paranoia. */
9930 while (chunks
!= NULL
)
9934 free (rs
->col_type
);
9935 free (rs
->col_offset
);
9936 rs
->next
= NULL
; /* Paranoia. */
9940 while (forward_refs
!= NULL
)
9943 forward_refs
= rs
->next
;
9944 free (rs
->col_type
);
9945 free (rs
->col_offset
);
9946 rs
->next
= NULL
; /* Paranoia. */
9956 display_debug_names (struct dwarf_section
*section
, void *file
)
9958 unsigned char *hdrptr
= section
->start
;
9959 dwarf_vma unit_length
;
9960 unsigned char *unit_start
;
9961 const unsigned char *const section_end
= section
->start
+ section
->size
;
9962 unsigned char *unit_end
;
9964 introduce (section
, false);
9966 load_debug_section_with_follow (str
, file
);
9968 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9970 unsigned int offset_size
;
9971 uint16_t dwarf_version
, padding
;
9972 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9973 uint64_t bucket_count
, name_count
, abbrev_table_size
;
9974 uint32_t augmentation_string_size
;
9976 bool augmentation_printable
;
9977 const char *augmentation_string
;
9980 unit_start
= hdrptr
;
9982 /* Get and check the length of the block. */
9983 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9985 if (unit_length
== 0xffffffff)
9987 /* This section is 64-bit DWARF. */
9988 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9994 if (unit_length
> (size_t) (section_end
- hdrptr
)
9995 || unit_length
< 2 + 2 + 4 * 7)
9998 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
10000 (unsigned long) (unit_start
- section
->start
),
10001 dwarf_vmatoa ("x", unit_length
));
10004 unit_end
= hdrptr
+ unit_length
;
10006 /* Get and check the version number. */
10007 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10008 printf (_("Version %ld\n"), (long) dwarf_version
);
10010 /* Prior versions did not exist, and future versions may not be
10011 backwards compatible. */
10012 if (dwarf_version
!= 5)
10014 warn (_("Only DWARF version 5 .debug_names "
10015 "is currently supported.\n"));
10019 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10021 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10024 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10025 if (comp_unit_count
== 0)
10026 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10028 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10029 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10030 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10031 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10032 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10034 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10035 if (augmentation_string_size
% 4 != 0)
10037 warn (_("Augmentation string length %u must be rounded up "
10038 "to a multiple of 4 in .debug_names.\n"),
10039 augmentation_string_size
);
10040 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10042 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10045 printf (_("Augmentation string:"));
10047 augmentation_printable
= true;
10048 augmentation_string
= (const char *) hdrptr
;
10050 for (i
= 0; i
< augmentation_string_size
; i
++)
10054 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10055 printf (" %02x", uc
);
10057 if (uc
!= 0 && !ISPRINT (uc
))
10058 augmentation_printable
= false;
10061 if (augmentation_printable
)
10065 i
< augmentation_string_size
&& augmentation_string
[i
];
10067 putchar (augmentation_string
[i
]);
10072 printf (_("CU table:\n"));
10073 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10074 || total
> (size_t) (unit_end
- hdrptr
))
10076 for (i
= 0; i
< comp_unit_count
; i
++)
10078 uint64_t cu_offset
;
10080 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10081 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
10085 printf (_("TU table:\n"));
10086 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10087 || total
> (size_t) (unit_end
- hdrptr
))
10089 for (i
= 0; i
< local_type_unit_count
; i
++)
10091 uint64_t tu_offset
;
10093 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10094 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
10098 printf (_("Foreign TU table:\n"));
10099 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10100 || total
> (size_t) (unit_end
- hdrptr
))
10102 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10104 uint64_t signature
;
10106 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10107 printf (_("[%3u] "), i
);
10108 print_dwarf_vma (signature
, 8);
10113 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10114 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10115 + abbrev_table_size
);
10116 if (xtra
> (size_t) (unit_end
- hdrptr
))
10118 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
10119 "for unit 0x%lx in the debug_names\n"),
10121 (long) (unit_end
- unit_start
),
10122 (long) (unit_start
- section
->start
));
10125 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10126 hdrptr
+= bucket_count
* sizeof (uint32_t);
10127 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10128 hdrptr
+= name_count
* sizeof (uint32_t);
10129 unsigned char *const name_table_string_offsets
= hdrptr
;
10130 hdrptr
+= name_count
* offset_size
;
10131 unsigned char *const name_table_entry_offsets
= hdrptr
;
10132 hdrptr
+= name_count
* offset_size
;
10133 unsigned char *const abbrev_table
= hdrptr
;
10134 hdrptr
+= abbrev_table_size
;
10135 const unsigned char *const abbrev_table_end
= hdrptr
;
10136 unsigned char *const entry_pool
= hdrptr
;
10138 size_t buckets_filled
= 0;
10140 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10142 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10147 printf (ngettext ("Used %zu of %lu bucket.\n",
10148 "Used %zu of %lu buckets.\n",
10150 buckets_filled
, (unsigned long) bucket_count
);
10152 uint32_t hash_prev
= 0;
10153 size_t hash_clash_count
= 0;
10154 size_t longest_clash
= 0;
10155 size_t this_length
= 0;
10157 for (hashi
= 0; hashi
< name_count
; hashi
++)
10159 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10163 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10165 ++hash_clash_count
;
10167 longest_clash
= MAX (longest_clash
, this_length
);
10172 hash_prev
= hash_this
;
10174 printf (_("Out of %lu items there are %zu bucket clashes"
10175 " (longest of %zu entries).\n"),
10176 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
10177 assert (name_count
== buckets_filled
+ hash_clash_count
);
10179 struct abbrev_lookup_entry
10181 dwarf_vma abbrev_tag
;
10182 unsigned char *abbrev_lookup_ptr
;
10184 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10185 size_t abbrev_lookup_used
= 0;
10186 size_t abbrev_lookup_allocated
= 0;
10188 unsigned char *abbrevptr
= abbrev_table
;
10191 dwarf_vma abbrev_tag
;
10193 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10194 if (abbrev_tag
== 0)
10196 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10198 abbrev_lookup_allocated
= MAX (0x100,
10199 abbrev_lookup_allocated
* 2);
10200 abbrev_lookup
= xrealloc (abbrev_lookup
,
10201 (abbrev_lookup_allocated
10202 * sizeof (*abbrev_lookup
)));
10204 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10205 struct abbrev_lookup_entry
*entry
;
10206 for (entry
= abbrev_lookup
;
10207 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10209 if (entry
->abbrev_tag
== abbrev_tag
)
10211 warn (_("Duplicate abbreviation tag %lu "
10212 "in unit 0x%lx in the debug_names\n"),
10213 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
10216 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10217 entry
->abbrev_tag
= abbrev_tag
;
10218 entry
->abbrev_lookup_ptr
= abbrevptr
;
10220 /* Skip DWARF tag. */
10221 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10224 dwarf_vma xindex
, form
;
10226 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10227 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10228 if (xindex
== 0 && form
== 0)
10233 printf (_("\nSymbol table:\n"));
10235 for (namei
= 0; namei
< name_count
; ++namei
)
10237 uint64_t string_offset
, entry_offset
;
10240 p
= name_table_string_offsets
+ namei
* offset_size
;
10241 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10242 p
= name_table_entry_offsets
+ namei
* offset_size
;
10243 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10245 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10246 fetch_indirect_string (string_offset
));
10248 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10250 /* We need to scan first whether there is a single or multiple
10251 entries. TAGNO is -2 for the first entry, it is -1 for the
10252 initial tag read of the second entry, then it becomes 0 for the
10253 first entry for real printing etc. */
10255 /* Initialize it due to a false compiler warning. */
10256 dwarf_vma second_abbrev_tag
= -1;
10259 dwarf_vma abbrev_tag
;
10260 dwarf_vma dwarf_tag
;
10261 const struct abbrev_lookup_entry
*entry
;
10263 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10266 second_abbrev_tag
= abbrev_tag
;
10268 entryptr
= entry_pool
+ entry_offset
;
10271 if (abbrev_tag
== 0)
10275 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10276 (unsigned long) abbrev_tag
);
10278 for (entry
= abbrev_lookup
;
10279 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10281 if (entry
->abbrev_tag
== abbrev_tag
)
10283 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10285 warn (_("Undefined abbreviation tag %lu "
10286 "in unit 0x%lx in the debug_names\n"),
10288 (long) (unit_start
- section
->start
));
10291 abbrevptr
= entry
->abbrev_lookup_ptr
;
10292 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10294 printf (" %s", get_TAG_name (dwarf_tag
));
10297 dwarf_vma xindex
, form
;
10299 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10300 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10301 if (xindex
== 0 && form
== 0)
10305 printf (" %s", get_IDX_name (xindex
));
10306 entryptr
= read_and_display_attr_value (0, form
, 0,
10307 unit_start
, entryptr
, unit_end
,
10309 dwarf_version
, NULL
,
10316 printf (_(" <no entries>"));
10320 free (abbrev_lookup
);
10327 display_debug_links (struct dwarf_section
* section
,
10328 void * file ATTRIBUTE_UNUSED
)
10330 const unsigned char * filename
;
10331 unsigned int filelen
;
10333 introduce (section
, false);
10335 /* The .gnu_debuglink section is formatted as:
10336 (c-string) Filename.
10337 (padding) If needed to reach a 4 byte boundary.
10338 (uint32_t) CRC32 value.
10340 The .gun_debugaltlink section is formatted as:
10341 (c-string) Filename.
10342 (binary) Build-ID. */
10344 filename
= section
->start
;
10345 filelen
= strnlen ((const char *) filename
, section
->size
);
10346 if (filelen
== section
->size
)
10348 warn (_("The debuglink filename is corrupt/missing\n"));
10352 printf (_(" Separate debug info file: %s\n"), filename
);
10354 if (startswith (section
->name
, ".gnu_debuglink"))
10356 unsigned int crc32
;
10357 unsigned int crc_offset
;
10359 crc_offset
= filelen
+ 1;
10360 crc_offset
= (crc_offset
+ 3) & ~3;
10361 if (crc_offset
+ 4 > section
->size
)
10363 warn (_("CRC offset missing/truncated\n"));
10367 crc32
= byte_get (filename
+ crc_offset
, 4);
10369 printf (_(" CRC value: %#x\n"), crc32
);
10371 if (crc_offset
+ 4 < section
->size
)
10373 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10374 (long)(section
->size
- (crc_offset
+ 4)));
10378 else /* startswith (section->name, ".gnu_debugaltlink") */
10380 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
10381 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
10382 bfd_size_type printed
;
10384 /* FIXME: Should we support smaller build-id notes ? */
10385 if (build_id_len
< 0x14)
10387 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
10391 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
10392 display_data (printed
, build_id
, build_id_len
);
10401 display_gdb_index (struct dwarf_section
*section
,
10402 void *file ATTRIBUTE_UNUSED
)
10404 unsigned char *start
= section
->start
;
10406 uint32_t cu_list_offset
, tu_list_offset
;
10407 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10408 unsigned int cu_list_elements
, tu_list_elements
;
10409 unsigned int address_table_size
, symbol_table_slots
;
10410 unsigned char *cu_list
, *tu_list
;
10411 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10414 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10416 introduce (section
, false);
10418 if (section
->size
< 6 * sizeof (uint32_t))
10420 warn (_("Truncated header in the %s section.\n"), section
->name
);
10424 version
= byte_get_little_endian (start
, 4);
10425 printf (_("Version %ld\n"), (long) version
);
10427 /* Prior versions are obsolete, and future versions may not be
10428 backwards compatible. */
10429 if (version
< 3 || version
> 8)
10431 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10435 warn (_("The address table data in version 3 may be wrong.\n"));
10437 warn (_("Version 4 does not support case insensitive lookups.\n"));
10439 warn (_("Version 5 does not include inlined functions.\n"));
10441 warn (_("Version 6 does not include symbol attributes.\n"));
10442 /* Version 7 indices generated by Gold have bad type unit references,
10443 PR binutils/15021. But we don't know if the index was generated by
10444 Gold or not, so to avoid worrying users with gdb-generated indices
10445 we say nothing for version 7 here. */
10447 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10448 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10449 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10450 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10451 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10453 if (cu_list_offset
> section
->size
10454 || tu_list_offset
> section
->size
10455 || address_table_offset
> section
->size
10456 || symbol_table_offset
> section
->size
10457 || constant_pool_offset
> section
->size
)
10459 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10463 /* PR 17531: file: 418d0a8a. */
10464 if (tu_list_offset
< cu_list_offset
)
10466 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10467 tu_list_offset
, cu_list_offset
);
10471 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
10473 if (address_table_offset
< tu_list_offset
)
10475 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10476 address_table_offset
, tu_list_offset
);
10480 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
10482 /* PR 17531: file: 18a47d3d. */
10483 if (symbol_table_offset
< address_table_offset
)
10485 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
10486 symbol_table_offset
, address_table_offset
);
10490 address_table_size
= symbol_table_offset
- address_table_offset
;
10492 if (constant_pool_offset
< symbol_table_offset
)
10494 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10495 constant_pool_offset
, symbol_table_offset
);
10499 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10501 cu_list
= start
+ cu_list_offset
;
10502 tu_list
= start
+ tu_list_offset
;
10503 address_table
= start
+ address_table_offset
;
10504 symbol_table
= start
+ symbol_table_offset
;
10505 constant_pool
= start
+ constant_pool_offset
;
10507 if (address_table_offset
+ address_table_size
> section
->size
)
10509 warn (_("Address table extends beyond end of section.\n"));
10513 printf (_("\nCU table:\n"));
10514 for (i
= 0; i
< cu_list_elements
; i
+= 2)
10516 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
10517 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
10519 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
10520 (unsigned long) cu_offset
,
10521 (unsigned long) (cu_offset
+ cu_length
- 1));
10524 printf (_("\nTU table:\n"));
10525 for (i
= 0; i
< tu_list_elements
; i
+= 3)
10527 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
10528 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
10529 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
10531 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
10532 (unsigned long) tu_offset
,
10533 (unsigned long) type_offset
);
10534 print_dwarf_vma (signature
, 8);
10538 printf (_("\nAddress table:\n"));
10539 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10542 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10543 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10544 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10546 print_dwarf_vma (low
, 8);
10547 print_dwarf_vma (high
, 8);
10548 printf (_("%lu\n"), (unsigned long) cu_index
);
10551 printf (_("\nSymbol table:\n"));
10552 for (i
= 0; i
< symbol_table_slots
; ++i
)
10554 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10555 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10556 uint32_t num_cus
, cu
;
10558 if (name_offset
!= 0
10559 || cu_vector_offset
!= 0)
10563 /* PR 17531: file: 5b7b07ad. */
10564 if (name_offset
>= section
->size
- constant_pool_offset
)
10566 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10567 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10571 printf ("[%3u] %.*s:", i
,
10572 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10573 constant_pool
+ name_offset
);
10575 if (section
->size
- constant_pool_offset
< 4
10576 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10578 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10579 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10580 cu_vector_offset
, i
);
10584 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10586 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10587 + cu_vector_offset
+ 4))
10589 printf ("<invalid number of CUs: %d>\n", num_cus
);
10590 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10598 for (j
= 0; j
< num_cus
; ++j
)
10601 gdb_index_symbol_kind kind
;
10603 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10604 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10605 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10606 cu
= GDB_INDEX_CU_VALUE (cu
);
10607 /* Convert to TU number if it's for a type unit. */
10608 if (cu
>= cu_list_elements
/ 2)
10609 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10610 (unsigned long) (cu
- cu_list_elements
/ 2));
10612 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10614 printf (" [%s, %s]",
10615 is_static
? _("static") : _("global"),
10616 get_gdb_index_symbol_kind_name (kind
));
10628 /* Pre-allocate enough space for the CU/TU sets needed. */
10631 prealloc_cu_tu_list (unsigned int nshndx
)
10633 if (shndx_pool
== NULL
)
10635 shndx_pool_size
= nshndx
;
10636 shndx_pool_used
= 0;
10637 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10638 sizeof (unsigned int));
10642 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10643 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10644 sizeof (unsigned int));
10649 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10651 if (shndx_pool_used
>= shndx_pool_size
)
10653 error (_("Internal error: out of space in the shndx pool.\n"));
10656 shndx_pool
[shndx_pool_used
++] = shndx
;
10660 end_cu_tu_entry (void)
10662 if (shndx_pool_used
>= shndx_pool_size
)
10664 error (_("Internal error: out of space in the shndx pool.\n"));
10667 shndx_pool
[shndx_pool_used
++] = 0;
10670 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10672 static const char *
10673 get_DW_SECT_short_name (unsigned int dw_sect
)
10675 static char buf
[16];
10681 case DW_SECT_TYPES
:
10683 case DW_SECT_ABBREV
:
10689 case DW_SECT_STR_OFFSETS
:
10691 case DW_SECT_MACINFO
:
10693 case DW_SECT_MACRO
:
10699 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10703 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10704 These sections are extensions for Fission.
10705 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10708 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10710 unsigned char *phdr
= section
->start
;
10711 unsigned char *limit
= phdr
+ section
->size
;
10712 unsigned char *phash
;
10713 unsigned char *pindex
;
10714 unsigned char *ppool
;
10715 unsigned int version
;
10716 unsigned int ncols
= 0;
10717 unsigned int nused
;
10718 unsigned int nslots
;
10721 dwarf_vma signature
;
10724 /* PR 17512: file: 002-168123-0.004. */
10727 warn (_("Section %s is empty\n"), section
->name
);
10730 /* PR 17512: file: 002-376-0.004. */
10731 if (section
->size
< 24)
10733 warn (_("Section %s is too small to contain a CU/TU header\n"),
10739 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10741 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10742 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10743 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10745 pindex
= phash
+ (size_t) nslots
* 8;
10746 ppool
= pindex
+ (size_t) nslots
* 4;
10750 introduce (section
, false);
10752 printf (_(" Version: %u\n"), version
);
10754 printf (_(" Number of columns: %u\n"), ncols
);
10755 printf (_(" Number of used entries: %u\n"), nused
);
10756 printf (_(" Number of slots: %u\n\n"), nslots
);
10759 /* PR 17531: file: 45d69832. */
10760 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10761 || total
> (size_t) (limit
- phash
))
10763 warn (ngettext ("Section %s is too small for %u slot\n",
10764 "Section %s is too small for %u slots\n",
10766 section
->name
, nslots
);
10773 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10774 for (i
= 0; i
< nslots
; i
++)
10776 unsigned char *shndx_list
;
10777 unsigned int shndx
;
10779 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10780 if (signature
!= 0)
10782 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10783 shndx_list
= ppool
+ j
* 4;
10784 /* PR 17531: file: 705e010d. */
10785 if (shndx_list
< ppool
)
10787 warn (_("Section index pool located before start of section\n"));
10792 printf (_(" [%3d] Signature: 0x%s Sections: "),
10793 i
, dwarf_vmatoa ("x", signature
));
10796 if (shndx_list
>= limit
)
10798 warn (_("Section %s too small for shndx pool\n"),
10802 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10806 printf (" %d", shndx
);
10808 add_shndx_to_cu_tu_entry (shndx
);
10814 end_cu_tu_entry ();
10820 else if (version
== 2)
10823 unsigned int dw_sect
;
10824 unsigned char *ph
= phash
;
10825 unsigned char *pi
= pindex
;
10826 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10827 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10829 struct cu_tu_set
*this_set
= NULL
;
10831 unsigned char *prow
;
10834 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10836 /* PR 17531: file: 0dd159bf.
10837 Check for integer overflow (can occur when size_t is 32-bit)
10838 with overlarge ncols or nused values. */
10840 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10841 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10842 || total
> (size_t) (limit
- ppool
))
10844 warn (_("Section %s too small for offset and size tables\n"),
10851 printf (_(" Offset table\n"));
10852 printf (" slot %-16s ",
10853 is_tu_index
? _("signature") : _("dwo_id"));
10860 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10861 this_set
= tu_sets
;
10866 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10867 this_set
= cu_sets
;
10873 for (j
= 0; j
< ncols
; j
++)
10875 unsigned char *p
= ppool
+ j
* 4;
10876 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10877 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10882 for (i
= 0; i
< nslots
; i
++)
10884 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10886 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10889 /* PR 17531: file: a05f6ab3. */
10892 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10899 size_t num_copy
= sizeof (uint64_t);
10901 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10904 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10906 printf (_(" [%3d] 0x%s"),
10907 i
, dwarf_vmatoa ("x", signature
));
10908 for (j
= 0; j
< ncols
; j
++)
10910 unsigned char *p
= prow
+ j
* 4;
10911 SAFE_BYTE_GET (val
, p
, 4, limit
);
10913 printf (" %8d", val
);
10917 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10919 /* PR 17531: file: 10796eb3. */
10920 if (dw_sect
>= DW_SECT_MAX
)
10921 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10923 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10939 printf (_(" Size table\n"));
10940 printf (" slot %-16s ",
10941 is_tu_index
? _("signature") : _("dwo_id"));
10944 for (j
= 0; j
< ncols
; j
++)
10946 unsigned char *p
= ppool
+ j
* 4;
10947 SAFE_BYTE_GET (val
, p
, 4, limit
);
10949 printf (" %8s", get_DW_SECT_short_name (val
));
10955 for (i
= 0; i
< nslots
; i
++)
10957 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10959 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10962 prow
= psizes
+ (row
- 1) * ncols
* 4;
10965 printf (_(" [%3d] 0x%s"),
10966 i
, dwarf_vmatoa ("x", signature
));
10968 for (j
= 0; j
< ncols
; j
++)
10970 unsigned char *p
= prow
+ j
* 4;
10972 /* PR 28645: Check for overflow. Since we do not know how
10973 many populated rows there will be, we cannot just
10974 perform a single check at the start of this function. */
10975 if (p
> (limit
- 4))
10979 warn (_("Too many rows/columns in DWARF index section %s\n"),
10984 SAFE_BYTE_GET (val
, p
, 4, limit
);
10987 printf (" %8d", val
);
10991 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10992 if (dw_sect
>= DW_SECT_MAX
)
10993 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10995 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11007 else if (do_display
)
11008 printf (_(" Unsupported version (%d)\n"), version
);
11016 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11018 /* Load the CU and TU indexes if present. This will build a list of
11019 section sets that we can use to associate a .debug_info.dwo section
11020 with its associated .debug_abbrev.dwo section in a .dwp file. */
11023 load_cu_tu_indexes (void *file
)
11025 /* If we have already loaded (or tried to load) the CU and TU indexes
11026 then do not bother to repeat the task. */
11027 if (cu_tu_indexes_read
== -1)
11029 cu_tu_indexes_read
= true;
11031 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11032 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11033 cu_tu_indexes_read
= false;
11035 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11036 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11037 cu_tu_indexes_read
= false;
11040 return (bool) cu_tu_indexes_read
;
11043 /* Find the set of sections that includes section SHNDX. */
11046 find_cu_tu_set (void *file
, unsigned int shndx
)
11050 if (! load_cu_tu_indexes (file
))
11053 /* Find SHNDX in the shndx pool. */
11054 for (i
= 0; i
< shndx_pool_used
; i
++)
11055 if (shndx_pool
[i
] == shndx
)
11058 if (i
>= shndx_pool_used
)
11061 /* Now backup to find the first entry in the set. */
11062 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11065 return shndx_pool
+ i
;
11068 /* Display a .debug_cu_index or .debug_tu_index section. */
11071 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11073 return process_cu_tu_index (section
, 1);
11077 display_debug_not_supported (struct dwarf_section
*section
,
11078 void *file ATTRIBUTE_UNUSED
)
11080 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11086 /* Like malloc, but takes two parameters like calloc.
11087 Verifies that the first parameter is not too large.
11088 Note: does *not* initialise the allocated memory to zero. */
11091 cmalloc (size_t nmemb
, size_t size
)
11093 /* Check for overflow. */
11094 if (nmemb
>= ~(size_t) 0 / size
)
11097 return xmalloc (nmemb
* size
);
11100 /* Like xmalloc, but takes two parameters like calloc.
11101 Verifies that the first parameter is not too large.
11102 Note: does *not* initialise the allocated memory to zero. */
11105 xcmalloc (size_t nmemb
, size_t size
)
11107 /* Check for overflow. */
11108 if (nmemb
>= ~(size_t) 0 / size
)
11111 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
11116 return xmalloc (nmemb
* size
);
11119 /* Like xrealloc, but takes three parameters.
11120 Verifies that the second parameter is not too large.
11121 Note: does *not* initialise any new memory to zero. */
11124 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
11126 /* Check for overflow. */
11127 if (nmemb
>= ~(size_t) 0 / size
)
11129 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
11134 return xrealloc (ptr
, nmemb
* size
);
11137 /* Like xcalloc, but verifies that the first parameter is not too large. */
11140 xcalloc2 (size_t nmemb
, size_t size
)
11142 /* Check for overflow. */
11143 if (nmemb
>= ~(size_t) 0 / size
)
11145 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
11150 return xcalloc (nmemb
, size
);
11153 static unsigned long
11154 calc_gnu_debuglink_crc32 (unsigned long crc
,
11155 const unsigned char * buf
,
11158 static const unsigned long crc32_table
[256] =
11160 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11161 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11162 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11163 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11164 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11165 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11166 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11167 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11168 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11169 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11170 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11171 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11172 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11173 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11174 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11175 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11176 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11177 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11178 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11179 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11180 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11181 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11182 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11183 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11184 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11185 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11186 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11187 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11188 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11189 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11190 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11191 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11192 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11193 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11194 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11195 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11196 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11197 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11198 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11199 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11200 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11201 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11202 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11203 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11204 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11205 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11206 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11207 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11208 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11209 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11210 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11213 const unsigned char *end
;
11215 crc
= ~crc
& 0xffffffff;
11216 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11217 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11218 return ~crc
& 0xffffffff;
11221 typedef bool (*check_func_type
) (const char *, void *);
11222 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11225 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11227 static unsigned char buffer
[8 * 1024];
11229 bfd_size_type count
;
11230 unsigned long crc
= 0;
11233 sep_data
= open_debug_file (pathname
);
11234 if (sep_data
== NULL
)
11237 /* Yes - we are opening the file twice... */
11238 f
= fopen (pathname
, "rb");
11241 /* Paranoia: This should never happen. */
11242 close_debug_file (sep_data
);
11243 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11247 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11248 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11252 if (crc
!= * (unsigned long *) crc_pointer
)
11254 close_debug_file (sep_data
);
11255 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11263 static const char *
11264 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11267 unsigned int crc_offset
;
11268 unsigned long * crc32
= (unsigned long *) data
;
11270 /* The name is first.
11271 The CRC value is stored after the filename, aligned up to 4 bytes. */
11272 name
= (const char *) section
->start
;
11274 crc_offset
= strnlen (name
, section
->size
) + 1;
11275 if (crc_offset
== 1)
11277 crc_offset
= (crc_offset
+ 3) & ~3;
11278 if (crc_offset
+ 4 > section
->size
)
11281 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11286 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11288 void * sep_data
= open_debug_file (filename
);
11290 if (sep_data
== NULL
)
11293 /* FIXME: We should now extract the build-id in the separate file
11299 typedef struct build_id_data
11302 const unsigned char * data
;
11305 static const char *
11306 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11309 bfd_size_type namelen
;
11310 bfd_size_type id_len
;
11311 Build_id_data
* build_id_data
;
11313 /* The name is first.
11314 The build-id follows immediately, with no padding, up to the section's end. */
11316 name
= (const char *) section
->start
;
11317 namelen
= strnlen (name
, section
->size
) + 1;
11320 if (namelen
>= section
->size
)
11323 id_len
= section
->size
- namelen
;
11327 build_id_data
= (Build_id_data
*) data
;
11328 build_id_data
->len
= id_len
;
11329 build_id_data
->data
= section
->start
+ namelen
;
11335 add_separate_debug_file (const char * filename
, void * handle
)
11337 separate_info
* i
= xmalloc (sizeof * i
);
11339 i
->filename
= filename
;
11340 i
->handle
= handle
;
11341 i
->next
= first_separate_info
;
11342 first_separate_info
= i
;
11345 #if HAVE_LIBDEBUGINFOD
11346 /* Query debuginfod servers for the target debuglink or debugaltlink
11347 file. If successful, store the path of the file in filename and
11348 return TRUE, otherwise return FALSE. */
11351 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11355 size_t build_id_len
;
11356 unsigned char * build_id
;
11358 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11360 /* Get the build-id of file. */
11361 build_id
= get_build_id (file
);
11364 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11366 /* Get the build-id of the debugaltlink file. */
11367 unsigned int filelen
;
11369 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11370 if (filelen
== section
->size
)
11371 /* Corrupt debugaltlink. */
11374 build_id
= section
->start
+ filelen
+ 1;
11375 build_id_len
= section
->size
- (filelen
+ 1);
11377 if (build_id_len
== 0)
11386 debuginfod_client
* client
;
11388 client
= debuginfod_begin ();
11389 if (client
== NULL
)
11392 /* Query debuginfod servers for the target file. If found its path
11393 will be stored in filename. */
11394 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11395 debuginfod_end (client
);
11397 /* Only free build_id if we allocated space for a hex string
11398 in get_build_id (). */
11399 if (build_id_len
== 0)
11404 /* File successfully retrieved. Close fd since we want to
11405 use open_debug_file () on filename instead. */
11413 #endif /* HAVE_LIBDEBUGINFOD */
11416 load_separate_debug_info (const char * main_filename
,
11417 struct dwarf_section
* xlink
,
11418 parse_func_type parse_func
,
11419 check_func_type check_func
,
11421 void * file ATTRIBUTE_UNUSED
)
11423 const char * separate_filename
;
11424 char * debug_filename
;
11426 size_t canon_dirlen
;
11428 char * canon_filename
;
11429 char * canon_debug_filename
;
11432 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11434 warn (_("Corrupt debuglink section: %s\n"),
11435 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11439 /* Attempt to locate the separate file.
11440 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11442 canon_filename
= lrealpath (main_filename
);
11443 canon_dir
= xstrdup (canon_filename
);
11445 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11446 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11448 canon_dir
[canon_dirlen
] = '\0';
11451 #define DEBUGDIR "/lib/debug"
11453 #ifndef EXTRA_DEBUG_ROOT1
11454 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11456 #ifndef EXTRA_DEBUG_ROOT2
11457 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11460 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11462 + strlen (".debug/")
11463 #ifdef EXTRA_DEBUG_ROOT1
11464 + strlen (EXTRA_DEBUG_ROOT1
)
11466 #ifdef EXTRA_DEBUG_ROOT2
11467 + strlen (EXTRA_DEBUG_ROOT2
)
11469 + strlen (separate_filename
)
11471 if (debug_filename
== NULL
)
11473 warn (_("Out of memory"));
11475 free (canon_filename
);
11479 /* First try in the current directory. */
11480 sprintf (debug_filename
, "%s", separate_filename
);
11481 if (check_func (debug_filename
, func_data
))
11484 /* Then try in a subdirectory called .debug. */
11485 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11486 if (check_func (debug_filename
, func_data
))
11489 /* Then try in the same directory as the original file. */
11490 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11491 if (check_func (debug_filename
, func_data
))
11494 /* And the .debug subdirectory of that directory. */
11495 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11496 if (check_func (debug_filename
, func_data
))
11499 #ifdef EXTRA_DEBUG_ROOT1
11500 /* Try the first extra debug file root. */
11501 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11502 if (check_func (debug_filename
, func_data
))
11505 /* Try the first extra debug file root. */
11506 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11507 if (check_func (debug_filename
, func_data
))
11511 #ifdef EXTRA_DEBUG_ROOT2
11512 /* Try the second extra debug file root. */
11513 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11514 if (check_func (debug_filename
, func_data
))
11518 /* Then try in the global debug_filename directory. */
11519 strcpy (debug_filename
, DEBUGDIR
);
11520 dirlen
= strlen (DEBUGDIR
) - 1;
11521 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11522 strcat (debug_filename
, "/");
11523 strcat (debug_filename
, (const char *) separate_filename
);
11525 if (check_func (debug_filename
, func_data
))
11528 #if HAVE_LIBDEBUGINFOD
11530 char * tmp_filename
;
11533 && debuginfod_fetch_separate_debug_info (xlink
,
11537 /* File successfully downloaded from server, replace
11538 debug_filename with the file's path. */
11539 free (debug_filename
);
11540 debug_filename
= tmp_filename
;
11546 if (do_debug_links
)
11548 /* Failed to find the file. */
11549 warn (_("could not find separate debug file '%s'\n"),
11550 separate_filename
);
11551 warn (_("tried: %s\n"), debug_filename
);
11553 #ifdef EXTRA_DEBUG_ROOT2
11554 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11555 separate_filename
);
11556 warn (_("tried: %s\n"), debug_filename
);
11559 #ifdef EXTRA_DEBUG_ROOT1
11560 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11561 canon_dir
, separate_filename
);
11562 warn (_("tried: %s\n"), debug_filename
);
11564 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11565 separate_filename
);
11566 warn (_("tried: %s\n"), debug_filename
);
11569 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11570 separate_filename
);
11571 warn (_("tried: %s\n"), debug_filename
);
11573 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11574 warn (_("tried: %s\n"), debug_filename
);
11576 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11577 warn (_("tried: %s\n"), debug_filename
);
11579 sprintf (debug_filename
, "%s", separate_filename
);
11580 warn (_("tried: %s\n"), debug_filename
);
11582 #if HAVE_LIBDEBUGINFOD
11583 if (use_debuginfod
)
11585 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11590 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11596 free (debug_filename
);
11597 free (canon_filename
);
11603 canon_debug_filename
= lrealpath (debug_filename
);
11604 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11605 free (canon_filename
);
11606 free (canon_debug_filename
);
11609 free (debug_filename
);
11613 void * debug_handle
;
11615 /* Now open the file.... */
11616 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11618 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11619 free (debug_filename
);
11623 /* FIXME: We do not check to see if there are any other separate debug info
11624 files that would also match. */
11626 if (do_debug_links
)
11627 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11628 add_separate_debug_file (debug_filename
, debug_handle
);
11630 /* Do not free debug_filename - it might be referenced inside
11631 the structure returned by open_debug_file(). */
11632 return debug_handle
;
11635 /* Attempt to load a separate dwarf object file. */
11638 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11640 char * separate_filename
;
11641 void * separate_handle
;
11643 if (IS_ABSOLUTE_PATH (name
))
11644 separate_filename
= strdup (name
);
11646 /* FIXME: Skip adding / if dwo_dir ends in /. */
11647 separate_filename
= concat (dir
, "/", name
, NULL
);
11648 if (separate_filename
== NULL
)
11650 warn (_("Out of memory allocating dwo filename\n"));
11654 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11656 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11657 free (separate_filename
);
11661 /* FIXME: We should check the dwo_id. */
11663 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11665 add_separate_debug_file (separate_filename
, separate_handle
);
11666 /* Note - separate_filename will be freed in free_debug_memory(). */
11667 return separate_handle
;
11671 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11673 char * f
= filename
;
11675 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11678 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11679 strcpy (f
, ".debug");
11681 return open_debug_file (filename
);
11684 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11687 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11689 if (! load_debug_section (note_gnu_build_id
, main_file
))
11690 return; /* No .note.gnu.build-id section. */
11692 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11693 if (section
== NULL
)
11695 warn (_("Unable to load the .note.gnu.build-id section\n"));
11699 if (section
->start
== NULL
|| section
->size
< 0x18)
11701 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11705 /* In theory we should extract the contents of the section into
11706 a note structure and then check the fields. For now though
11707 just use hard coded offsets instead:
11709 Field Bytes Contents
11712 Type 8..11 3 (NT_GNU_BUILD_ID)
11716 /* FIXME: Check the name size, name and type fields. */
11718 unsigned long build_id_size
;
11719 build_id_size
= byte_get (section
->start
+ 4, 4);
11720 if (build_id_size
< 8)
11722 warn (_(".note.gnu.build-id data size is too small\n"));
11726 if (build_id_size
> (section
->size
- 16))
11728 warn (_(".note.gnu.build-id data size is too bug\n"));
11733 filename
= xmalloc (strlen (".build-id/")
11734 + build_id_size
* 2 + 2
11735 + strlen (".debug")
11736 /* The next string should be the same as the longest
11737 name found in the prefixes[] array below. */
11738 + strlen ("/usrlib64/debug/usr")
11742 static const char * prefixes
[] =
11747 "/usr/lib/debug/usr/",
11748 "/usr/lib64/debug/",
11749 "/usr/lib64/debug/usr"
11751 long unsigned int i
;
11753 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11755 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11756 section
->start
+ 16, build_id_size
);
11757 if (handle
!= NULL
)
11760 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11761 if (handle
== NULL
)
11763 /* Failed to find a debug file associated with the build-id.
11764 This is not an error however, rather it just means that
11765 the debug info has probably not been loaded on the system,
11766 or that another method is being used to link to the debug
11772 add_separate_debug_file (filename
, handle
);
11775 /* Try to load a debug file pointed to by the .debug_sup section. */
11778 load_debug_sup_file (const char * main_filename
, void * file
)
11780 if (! load_debug_section (debug_sup
, file
))
11781 return; /* No .debug_sup section. */
11783 struct dwarf_section
* section
;
11784 section
= & debug_displays
[debug_sup
].section
;
11785 assert (section
!= NULL
);
11787 if (section
->start
== NULL
|| section
->size
< 5)
11789 warn (_(".debug_sup section is corrupt/empty\n"));
11793 if (section
->start
[2] != 0)
11794 return; /* This is a supplementary file. */
11796 const char * filename
= (const char *) section
->start
+ 3;
11797 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11799 warn (_("filename in .debug_sup section is corrupt\n"));
11803 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11808 new_len
= asprintf (& new_name
, "%.*s/%s",
11809 (int) (strrchr (main_filename
, '/') - main_filename
),
11814 warn (_("unable to construct path for supplementary debug file"));
11819 filename
= new_name
;
11823 /* PR 27796: Make sure that we pass a filename that can be free'd to
11824 add_separate_debug_file(). */
11825 filename
= strdup (filename
);
11826 if (filename
== NULL
)
11828 warn (_("out of memory constructing filename for .debug_sup link\n"));
11833 void * handle
= open_debug_file (filename
);
11834 if (handle
== NULL
)
11836 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11837 free ((void *) filename
);
11841 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11843 /* FIXME: Compare the checksums, if present. */
11844 add_separate_debug_file (filename
, handle
);
11847 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11848 Recursively check the loaded files for more of these sections.
11849 Also follow any links in .debug_sup sections.
11850 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11853 check_for_and_load_links (void * file
, const char * filename
)
11855 void * handle
= NULL
;
11857 if (load_debug_section (gnu_debugaltlink
, file
))
11859 Build_id_data build_id_data
;
11861 handle
= load_separate_debug_info (filename
,
11862 & debug_displays
[gnu_debugaltlink
].section
,
11863 parse_gnu_debugaltlink
,
11864 check_gnu_debugaltlink
,
11869 assert (handle
== first_separate_info
->handle
);
11870 check_for_and_load_links (first_separate_info
->handle
,
11871 first_separate_info
->filename
);
11875 if (load_debug_section (gnu_debuglink
, file
))
11877 unsigned long crc32
;
11879 handle
= load_separate_debug_info (filename
,
11880 & debug_displays
[gnu_debuglink
].section
,
11881 parse_gnu_debuglink
,
11882 check_gnu_debuglink
,
11887 assert (handle
== first_separate_info
->handle
);
11888 check_for_and_load_links (first_separate_info
->handle
,
11889 first_separate_info
->filename
);
11893 load_debug_sup_file (filename
, file
);
11895 load_build_id_debug_file (filename
, file
);
11898 /* Load the separate debug info file(s) attached to FILE, if any exist.
11899 Returns TRUE if any were found, FALSE otherwise.
11900 If TRUE is returned then the linked list starting at first_separate_info
11901 will be populated with open file handles. */
11904 load_separate_debug_files (void * file
, const char * filename
)
11906 /* Skip this operation if we are not interested in debug links. */
11907 if (! do_follow_links
&& ! do_debug_links
)
11910 /* See if there are any dwo links. */
11911 if (load_debug_section (str
, file
)
11912 && load_debug_section (abbrev
, file
)
11913 && load_debug_section (info
, file
))
11917 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11920 bool introduced
= false;
11922 const char *dir
= NULL
;
11923 const char *id
= NULL
;
11924 const char *name
= NULL
;
11926 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11928 /* Accumulate NAME, DIR and ID fields. */
11929 switch (dwinfo
->type
)
11933 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11934 name
= dwinfo
->value
;
11938 /* There can be multiple DW_AT_comp_dir entries in a CU,
11939 so do not complain. */
11940 dir
= dwinfo
->value
;
11945 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11946 id
= dwinfo
->value
;
11950 error (_("Unexpected DWO INFO type"));
11954 /* If we have reached the end of our list, or we are changing
11955 CUs, then display the information that we have accumulated
11958 && (dwinfo
->next
== NULL
11959 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11961 if (do_debug_links
)
11965 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11966 debug_displays
[info
].section
.uncompressed_name
);
11970 printf (_(" Name: %s\n"), name
);
11971 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11973 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11975 printf (_(" ID: <not specified>\n"));
11979 if (do_follow_links
)
11980 load_dwo_file (filename
, name
, dir
, id
);
11982 name
= dir
= id
= NULL
;
11988 if (! do_follow_links
)
11989 /* The other debug links will be displayed by display_debug_links()
11990 so we do not need to do any further processing here. */
11993 /* FIXME: We do not check for the presence of both link sections in the same file. */
11994 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11995 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11997 check_for_and_load_links (file
, filename
);
11998 if (first_separate_info
!= NULL
)
12001 do_follow_links
= 0;
12006 free_debug_memory (void)
12010 free_all_abbrevs ();
12012 free (cu_abbrev_map
);
12013 cu_abbrev_map
= NULL
;
12014 next_free_abbrev_map_entry
= 0;
12018 shndx_pool_size
= 0;
12019 shndx_pool_used
= 0;
12027 memset (level_type_signed
, 0, sizeof level_type_signed
);
12028 cu_tu_indexes_read
= -1;
12030 for (i
= 0; i
< max
; i
++)
12031 free_debug_section ((enum dwarf_section_display_enum
) i
);
12033 if (debug_information
!= NULL
)
12035 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12037 if (debug_information
[i
].max_loc_offsets
)
12039 free (debug_information
[i
].loc_offsets
);
12040 free (debug_information
[i
].have_frame_base
);
12042 if (debug_information
[i
].max_range_lists
)
12043 free (debug_information
[i
].range_lists
);
12045 free (debug_information
);
12046 debug_information
= NULL
;
12047 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12051 separate_info
* next
;
12053 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12055 close_debug_file (d
->handle
);
12056 free ((void *) d
->filename
);
12060 first_separate_info
= NULL
;
12066 dwarf_select_sections_by_names (const char *names
)
12070 const char * option
;
12074 debug_dump_long_opts
;
12076 static const debug_dump_long_opts opts_table
[] =
12078 /* Please keep this table alpha- sorted. */
12079 { "Ranges", & do_debug_ranges
, 1 },
12080 { "abbrev", & do_debug_abbrevs
, 1 },
12081 { "addr", & do_debug_addr
, 1 },
12082 { "aranges", & do_debug_aranges
, 1 },
12083 { "cu_index", & do_debug_cu_index
, 1 },
12084 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12085 #ifdef HAVE_LIBDEBUGINFOD
12086 { "do-not-use-debuginfod", & use_debuginfod
, 0 },
12088 { "follow-links", & do_follow_links
, 1 },
12089 { "frames", & do_debug_frames
, 1 },
12090 { "frames-interp", & do_debug_frames_interp
, 1 },
12091 /* The special .gdb_index section. */
12092 { "gdb_index", & do_gdb_index
, 1 },
12093 { "info", & do_debug_info
, 1 },
12094 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
12095 { "links", & do_debug_links
, 1 },
12096 { "loc", & do_debug_loc
, 1 },
12097 { "macro", & do_debug_macinfo
, 1 },
12098 { "no-follow-links", & do_follow_links
, 0 },
12099 { "pubnames", & do_debug_pubnames
, 1 },
12100 { "pubtypes", & do_debug_pubtypes
, 1 },
12101 /* This entry is for compatibility
12102 with earlier versions of readelf. */
12103 { "ranges", & do_debug_aranges
, 1 },
12104 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12105 { "str", & do_debug_str
, 1 },
12106 { "str-offsets", & do_debug_str_offsets
, 1 },
12107 /* These trace_* sections are used by Itanium VMS. */
12108 { "trace_abbrev", & do_trace_abbrevs
, 1 },
12109 { "trace_aranges", & do_trace_aranges
, 1 },
12110 { "trace_info", & do_trace_info
, 1 },
12111 #ifdef HAVE_LIBDEBUGINFOD
12112 { "use-debuginfod", & use_debuginfod
, 1 },
12122 const debug_dump_long_opts
* entry
;
12124 for (entry
= opts_table
; entry
->option
; entry
++)
12126 size_t len
= strlen (entry
->option
);
12128 if (strncmp (p
, entry
->option
, len
) == 0
12129 && (p
[len
] == ',' || p
[len
] == '\0'))
12131 * entry
->variable
= entry
->val
;
12133 /* The --debug-dump=frames-interp option also
12134 enables the --debug-dump=frames option. */
12135 if (do_debug_frames_interp
)
12136 do_debug_frames
= 1;
12143 if (entry
->option
== NULL
)
12145 warn (_("Unrecognized debug option '%s'\n"), p
);
12146 p
= strchr (p
, ',');
12157 dwarf_select_sections_by_letters (const char *letters
)
12159 unsigned int lindex
= 0;
12161 while (letters
[lindex
])
12162 switch (letters
[lindex
++])
12164 case 'A': do_debug_addr
= 1; break;
12165 case 'a': do_debug_abbrevs
= 1; break;
12166 case 'c': do_debug_cu_index
= 1; break;
12167 #ifdef HAVE_LIBDEBUGINFOD
12168 case 'D': use_debuginfod
= 1; break;
12169 case 'E': use_debuginfod
= 0; break;
12171 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
12172 case 'f': do_debug_frames
= 1; break;
12173 case 'g': do_gdb_index
= 1; break;
12174 case 'i': do_debug_info
= 1; break;
12175 case 'K': do_follow_links
= 1; break;
12176 case 'N': do_follow_links
= 0; break;
12177 case 'k': do_debug_links
= 1; break;
12178 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
12179 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
12180 case 'm': do_debug_macinfo
= 1; break;
12181 case 'O': do_debug_str_offsets
= 1; break;
12182 case 'o': do_debug_loc
= 1; break;
12183 case 'p': do_debug_pubnames
= 1; break;
12184 case 'R': do_debug_ranges
= 1; break;
12185 case 'r': do_debug_aranges
= 1; break;
12186 case 's': do_debug_str
= 1; break;
12187 case 'T': do_trace_aranges
= 1; break;
12188 case 't': do_debug_pubtypes
= 1; break;
12189 case 'U': do_trace_info
= 1; break;
12190 case 'u': do_trace_abbrevs
= 1; break;
12193 warn (_("Unrecognized debug option '%s'\n"), letters
);
12199 dwarf_select_sections_all (void)
12202 do_debug_abbrevs
= 1;
12203 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12204 do_debug_pubnames
= 1;
12205 do_debug_pubtypes
= 1;
12206 do_debug_aranges
= 1;
12207 do_debug_ranges
= 1;
12208 do_debug_frames
= 1;
12209 do_debug_macinfo
= 1;
12214 do_trace_abbrevs
= 1;
12215 do_trace_aranges
= 1;
12217 do_debug_cu_index
= 1;
12218 do_follow_links
= 1;
12219 do_debug_links
= 1;
12220 do_debug_str_offsets
= 1;
12223 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12224 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12226 /* N.B. The order here must match the order in section_display_enum. */
12228 struct dwarf_section_display debug_displays
[] =
12230 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12231 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12232 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12233 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12234 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12235 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12236 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12237 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12238 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12239 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12240 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12241 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12242 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12243 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12244 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12245 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12246 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12247 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12248 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12249 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12250 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12251 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12252 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12253 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12254 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12255 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12256 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12257 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12258 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12259 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12260 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12261 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12262 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12263 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12264 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12265 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12266 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12267 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12268 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12269 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12270 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12271 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12272 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12273 /* Separate debug info files can containt their own .debug_str section,
12274 and this might be in *addition* to a .debug_str section already present
12275 in the main file. Hence we need to have two entries for .debug_str. */
12276 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12277 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12280 /* A static assertion. */
12281 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];