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
));
1725 READ_ULEB (uvalue
, data
, end
);
1726 printf ("DW_OP_addrx <0x%s>", dwarf_vmatoa ("x", uvalue
));
1728 case DW_OP_GNU_addr_index
:
1729 READ_ULEB (uvalue
, data
, end
);
1730 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1732 case DW_OP_GNU_const_index
:
1733 READ_ULEB (uvalue
, data
, end
);
1734 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1736 case DW_OP_GNU_variable_value
:
1737 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1738 this ought to be an 8-byte wide computation. */
1739 if (dwarf_version
== -1)
1741 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1742 /* No way to tell where the next op is, so just bail. */
1743 return need_frame_base
;
1745 if (dwarf_version
== 2)
1747 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1751 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1753 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1756 /* HP extensions. */
1757 case DW_OP_HP_is_value
:
1758 printf ("DW_OP_HP_is_value");
1759 /* FIXME: Is there data associated with this OP ? */
1761 case DW_OP_HP_fltconst4
:
1762 printf ("DW_OP_HP_fltconst4");
1763 /* FIXME: Is there data associated with this OP ? */
1765 case DW_OP_HP_fltconst8
:
1766 printf ("DW_OP_HP_fltconst8");
1767 /* FIXME: Is there data associated with this OP ? */
1769 case DW_OP_HP_mod_range
:
1770 printf ("DW_OP_HP_mod_range");
1771 /* FIXME: Is there data associated with this OP ? */
1773 case DW_OP_HP_unmod_range
:
1774 printf ("DW_OP_HP_unmod_range");
1775 /* FIXME: Is there data associated with this OP ? */
1778 printf ("DW_OP_HP_tls");
1779 /* FIXME: Is there data associated with this OP ? */
1782 /* PGI (STMicroelectronics) extensions. */
1783 case DW_OP_PGI_omp_thread_num
:
1784 /* Pushes the thread number for the current thread as it would be
1785 returned by the standard OpenMP library function:
1786 omp_get_thread_num(). The "current thread" is the thread for
1787 which the expression is being evaluated. */
1788 printf ("DW_OP_PGI_omp_thread_num");
1792 if (op
>= DW_OP_lo_user
1793 && op
<= DW_OP_hi_user
)
1794 printf (_("(User defined location op 0x%x)"), op
);
1796 printf (_("(Unknown location op 0x%x)"), op
);
1797 /* No way to tell where the next op is, so just bail. */
1798 return need_frame_base
;
1801 /* Separate the ops. */
1806 return need_frame_base
;
1809 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1810 This is used for DWARF package files. */
1812 static struct cu_tu_set
*
1813 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1815 struct cu_tu_set
*p
;
1817 unsigned int dw_sect
;
1823 dw_sect
= DW_SECT_TYPES
;
1829 dw_sect
= DW_SECT_INFO
;
1833 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1842 fetch_alt_indirect_string (dwarf_vma offset
)
1846 if (! do_follow_links
)
1849 if (first_separate_info
== NULL
)
1850 return _("<no links available>");
1852 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1854 struct dwarf_section
* section
;
1857 if (! load_debug_section (separate_debug_str
, i
->handle
))
1860 section
= &debug_displays
[separate_debug_str
].section
;
1862 if (section
->start
== NULL
)
1865 if (offset
>= section
->size
)
1868 ret
= (const char *) (section
->start
+ offset
);
1869 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1870 NUL byte. Since our caller is expecting to receive a well formed C
1871 string we test for the lack of a terminating byte here. */
1872 if (strnlen ((const char *) ret
, section
->size
- offset
)
1873 == section
->size
- offset
)
1874 return _("<no NUL byte at end of alt .debug_str section>");
1879 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1880 dwarf_vmatoa ("x", offset
));
1881 return _("<offset is too big>");
1885 get_AT_name (unsigned long attribute
)
1890 return "DW_AT value: 0";
1892 /* One value is shared by the MIPS and HP extensions: */
1893 if (attribute
== DW_AT_MIPS_fde
)
1894 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1896 name
= get_DW_AT_name (attribute
);
1900 static char buffer
[100];
1902 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1911 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1913 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1915 dwinfo
->type
= type
;
1916 dwinfo
->value
= value
;
1917 dwinfo
->cu_offset
= cu_offset
;
1918 dwinfo
->next
= first_dwo_info
;
1919 first_dwo_info
= dwinfo
;
1923 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1925 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1929 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1931 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1935 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1937 add_dwo_info (id
, cu_offset
, DWO_ID
);
1941 free_dwo_info (void)
1946 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1948 next
= dwinfo
->next
;
1951 first_dwo_info
= NULL
;
1954 /* Ensure that START + UVALUE is less than END.
1955 Return an adjusted UVALUE if necessary to ensure this relationship. */
1957 static inline dwarf_vma
1958 check_uvalue (const unsigned char * start
,
1960 const unsigned char * end
)
1962 dwarf_vma max_uvalue
= end
- start
;
1964 /* See PR 17512: file: 008-103549-0.001:0.1.
1965 and PR 24829 for examples of where these tests are triggered. */
1966 if (uvalue
> max_uvalue
)
1968 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1969 uvalue
= max_uvalue
;
1975 static unsigned char *
1976 skip_attr_bytes (unsigned long form
,
1977 unsigned char *data
,
1979 dwarf_vma pointer_size
,
1980 dwarf_vma offset_size
,
1982 dwarf_vma
*value_return
)
1984 dwarf_signed_vma svalue
;
1985 dwarf_vma uvalue
= 0;
1992 case DW_FORM_ref_addr
:
1993 if (dwarf_version
== 2)
1994 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1995 else if (dwarf_version
> 2)
1996 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2002 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2006 case DW_FORM_line_strp
:
2007 case DW_FORM_sec_offset
:
2008 case DW_FORM_GNU_ref_alt
:
2009 case DW_FORM_GNU_strp_alt
:
2010 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2013 case DW_FORM_flag_present
:
2021 case DW_FORM_addrx1
:
2022 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2026 case DW_FORM_addrx3
:
2027 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2033 case DW_FORM_addrx2
:
2034 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2040 case DW_FORM_addrx4
:
2041 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2045 READ_SLEB (svalue
, data
, end
);
2049 case DW_FORM_ref_udata
:
2051 case DW_FORM_GNU_str_index
:
2053 case DW_FORM_GNU_addr_index
:
2055 case DW_FORM_loclistx
:
2056 case DW_FORM_rnglistx
:
2057 READ_ULEB (uvalue
, data
, end
);
2061 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2065 case DW_FORM_ref_sig8
:
2069 case DW_FORM_data16
:
2073 case DW_FORM_string
:
2074 inc
= strnlen ((char *) data
, end
- data
) + 1;
2078 case DW_FORM_exprloc
:
2079 READ_ULEB (uvalue
, data
, end
);
2083 case DW_FORM_block1
:
2084 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2088 case DW_FORM_block2
:
2089 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2093 case DW_FORM_block4
:
2094 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2098 case DW_FORM_indirect
:
2099 READ_ULEB (form
, data
, end
);
2100 if (form
== DW_FORM_implicit_const
)
2101 SKIP_ULEB (data
, end
);
2102 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2103 dwarf_version
, value_return
);
2109 * value_return
= uvalue
;
2110 if (inc
<= (dwarf_vma
) (end
- data
))
2117 /* Given form FORM with value UVALUE, locate and return the abbreviation
2118 associated with it. */
2120 static abbrev_entry
*
2121 get_type_abbrev_from_form (unsigned long form
,
2122 unsigned long uvalue
,
2123 dwarf_vma cu_offset
,
2124 unsigned char *cu_end
,
2125 const struct dwarf_section
*section
,
2126 unsigned long *abbrev_num_return
,
2127 unsigned char **data_return
,
2128 abbrev_map
**map_return
)
2130 unsigned long abbrev_number
;
2132 abbrev_entry
* entry
;
2133 unsigned char * data
;
2135 if (abbrev_num_return
!= NULL
)
2136 * abbrev_num_return
= 0;
2137 if (data_return
!= NULL
)
2138 * data_return
= NULL
;
2142 case DW_FORM_GNU_ref_alt
:
2143 case DW_FORM_ref_sig8
:
2144 /* FIXME: We are unable to handle this form at the moment. */
2147 case DW_FORM_ref_addr
:
2148 if (uvalue
>= section
->size
)
2150 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2151 uvalue
, (long) section
->size
, section
->name
);
2156 case DW_FORM_ref_sup4
:
2157 case DW_FORM_ref_sup8
:
2164 case DW_FORM_ref_udata
:
2165 if (uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2167 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > CU size %lx\n"),
2168 uvalue
, (long) cu_offset
, (long) (cu_end
- section
->start
));
2171 uvalue
+= cu_offset
;
2174 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2177 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2181 data
= (unsigned char *) section
->start
+ uvalue
;
2182 map
= find_abbrev_map_by_offset (uvalue
);
2186 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2189 if (map
->list
== NULL
)
2191 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2195 if (map_return
!= NULL
)
2197 if (form
== DW_FORM_ref_addr
)
2203 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2205 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2206 if (entry
->number
== abbrev_number
)
2209 if (abbrev_num_return
!= NULL
)
2210 * abbrev_num_return
= abbrev_number
;
2212 if (data_return
!= NULL
)
2213 * data_return
= data
;
2216 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2221 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2222 can be determined to be a signed type. The data for ENTRY can be
2223 found starting at DATA. */
2226 get_type_signedness (abbrev_entry
*entry
,
2227 const struct dwarf_section
*section
,
2228 unsigned char *data
,
2230 dwarf_vma cu_offset
,
2231 dwarf_vma pointer_size
,
2232 dwarf_vma offset_size
,
2235 unsigned int nesting
)
2239 * is_signed
= false;
2241 #define MAX_NESTING 20
2242 if (nesting
> MAX_NESTING
)
2244 /* FIXME: Warn - or is this expected ?
2245 NB/ We need to avoid infinite recursion. */
2249 for (attr
= entry
->first_attr
;
2250 attr
!= NULL
&& attr
->attribute
;
2253 unsigned char * orig_data
= data
;
2254 dwarf_vma uvalue
= 0;
2256 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2257 offset_size
, dwarf_version
, & uvalue
);
2261 switch (attr
->attribute
)
2263 case DW_AT_linkage_name
:
2267 if (attr
->form
== DW_FORM_strp
)
2268 printf (", %s", fetch_indirect_string (uvalue
));
2269 else if (attr
->form
== DW_FORM_string
)
2270 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2277 abbrev_entry
*type_abbrev
;
2278 unsigned char *type_data
;
2281 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2286 NULL
/* abbrev num return */,
2289 if (type_abbrev
== NULL
)
2292 get_type_signedness (type_abbrev
, section
, type_data
,
2293 map
? section
->start
+ map
->end
: end
,
2294 map
? map
->start
: cu_offset
,
2295 pointer_size
, offset_size
, dwarf_version
,
2296 is_signed
, nesting
+ 1);
2300 case DW_AT_encoding
:
2301 /* Determine signness. */
2304 case DW_ATE_address
:
2305 /* FIXME - some architectures have signed addresses. */
2306 case DW_ATE_boolean
:
2307 case DW_ATE_unsigned
:
2308 case DW_ATE_unsigned_char
:
2309 case DW_ATE_unsigned_fixed
:
2310 * is_signed
= false;
2314 case DW_ATE_complex_float
:
2317 case DW_ATE_signed_char
:
2318 case DW_ATE_imaginary_float
:
2319 case DW_ATE_decimal_float
:
2320 case DW_ATE_signed_fixed
:
2330 read_and_print_leb128 (unsigned char *data
,
2331 unsigned int *bytes_read
,
2332 unsigned const char *end
,
2336 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2338 report_leb_status (status
);
2340 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2344 display_discr_list (unsigned long form
,
2346 unsigned char * data
,
2349 unsigned char *end
= data
;
2353 printf ("[default]");
2360 case DW_FORM_block1
:
2361 case DW_FORM_block2
:
2362 case DW_FORM_block4
:
2363 /* Move data pointer back to the start of the byte array. */
2367 printf ("<corrupt>\n");
2368 warn (_("corrupt discr_list - not using a block form\n"));
2374 printf ("<corrupt>\n");
2375 warn (_("corrupt discr_list - block not long enough\n"));
2379 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2380 ? level_type_signed
[level
- 1] : false);
2385 unsigned char discriminant
;
2386 unsigned int bytes_read
;
2388 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2390 switch (discriminant
)
2394 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2400 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2404 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2409 printf ("<corrupt>\n");
2410 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2420 printf (")(signed)");
2422 printf (")(unsigned)");
2425 static unsigned char *
2426 read_and_display_attr_value (unsigned long attribute
,
2428 dwarf_signed_vma implicit_const
,
2429 unsigned char * start
,
2430 unsigned char * data
,
2431 unsigned char * end
,
2432 dwarf_vma cu_offset
,
2433 dwarf_vma pointer_size
,
2434 dwarf_vma offset_size
,
2436 debug_info
* debug_info_p
,
2438 struct dwarf_section
* section
,
2439 struct cu_tu_set
* this_set
,
2443 dwarf_signed_vma svalue
;
2444 dwarf_vma uvalue
= 0;
2445 dwarf_vma uvalue_hi
= 0;
2446 unsigned char *block_start
= NULL
;
2447 unsigned char *orig_data
= data
;
2449 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2451 warn (_("Corrupt attribute\n"));
2455 if (do_wide
&& ! do_loc
)
2457 /* PR 26847: Display the name of the form. */
2458 const char * name
= get_FORM_name (form
);
2460 /* For convenience we skip the DW_FORM_ prefix to the name. */
2462 name
+= 8; /* strlen ("DW_FORM_") */
2463 printf ("%c(%s)", delimiter
, name
);
2468 case DW_FORM_ref_addr
:
2469 if (dwarf_version
== 2)
2470 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2471 else if (dwarf_version
> 2)
2472 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2474 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2478 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2481 case DW_FORM_strp_sup
:
2483 case DW_FORM_line_strp
:
2484 case DW_FORM_sec_offset
:
2485 case DW_FORM_GNU_ref_alt
:
2486 case DW_FORM_GNU_strp_alt
:
2487 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2490 case DW_FORM_flag_present
:
2498 case DW_FORM_addrx1
:
2499 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2505 case DW_FORM_addrx2
:
2506 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2510 case DW_FORM_addrx3
:
2511 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2514 case DW_FORM_ref_sup4
:
2518 case DW_FORM_addrx4
:
2519 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2522 case DW_FORM_ref_sup8
:
2525 case DW_FORM_ref_sig8
:
2526 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2529 case DW_FORM_data16
:
2530 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2531 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2532 if (byte_get
!= byte_get_little_endian
)
2534 dwarf_vma utmp
= uvalue
;
2541 READ_SLEB (svalue
, data
, end
);
2545 case DW_FORM_GNU_str_index
:
2547 case DW_FORM_ref_udata
:
2549 case DW_FORM_GNU_addr_index
:
2551 case DW_FORM_loclistx
:
2552 case DW_FORM_rnglistx
:
2553 READ_ULEB (uvalue
, data
, end
);
2556 case DW_FORM_indirect
:
2557 READ_ULEB (form
, data
, end
);
2559 printf ("%c%s", delimiter
, get_FORM_name (form
));
2560 if (form
== DW_FORM_implicit_const
)
2561 READ_SLEB (implicit_const
, data
, end
);
2562 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2564 cu_offset
, pointer_size
,
2565 offset_size
, dwarf_version
,
2566 debug_info_p
, do_loc
,
2567 section
, this_set
, delimiter
, level
);
2569 case DW_FORM_implicit_const
:
2570 uvalue
= implicit_const
;
2579 case DW_FORM_ref_addr
:
2581 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2584 case DW_FORM_GNU_ref_alt
:
2588 /* We have already printed the form name. */
2589 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2591 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2593 /* FIXME: Follow the reference... */
2599 case DW_FORM_ref_sup4
:
2600 case DW_FORM_ref_udata
:
2602 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2607 case DW_FORM_sec_offset
:
2609 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2612 case DW_FORM_flag_present
:
2619 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2622 case DW_FORM_implicit_const
:
2624 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2627 case DW_FORM_ref_sup8
:
2632 dwarf_vma utmp
= uvalue
;
2633 if (form
== DW_FORM_ref8
)
2635 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", utmp
));
2639 case DW_FORM_data16
:
2642 uvalue_hi
== 0 ? "" : dwarf_vmatoa ("x", uvalue_hi
),
2643 dwarf_vmatoa_1 ("x", uvalue
, uvalue_hi
== 0 ? 0 : 8));
2646 case DW_FORM_string
:
2648 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2649 data
+= strnlen ((char *) data
, end
- data
);
2655 case DW_FORM_exprloc
:
2656 READ_ULEB (uvalue
, data
, end
);
2659 if (block_start
>= end
)
2661 warn (_("Block ends prematurely\n"));
2666 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2668 data
= block_start
+ uvalue
;
2673 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2674 if (op
!= DW_OP_addrx
)
2675 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2679 case DW_FORM_block1
:
2680 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2683 case DW_FORM_block2
:
2684 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2687 case DW_FORM_block4
:
2688 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2695 /* We have already displayed the form name. */
2696 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2697 dwarf_vmatoa ("x", uvalue
),
2698 fetch_indirect_string (uvalue
));
2700 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2701 dwarf_vmatoa ("x", uvalue
),
2702 fetch_indirect_string (uvalue
));
2706 case DW_FORM_line_strp
:
2710 /* We have already displayed the form name. */
2711 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2712 dwarf_vmatoa ("x", uvalue
),
2713 fetch_indirect_line_string (uvalue
));
2715 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2716 dwarf_vmatoa ("x", uvalue
),
2717 fetch_indirect_line_string (uvalue
));
2721 case DW_FORM_GNU_str_index
:
2729 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2730 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2733 /* We have already displayed the form name. */
2734 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2735 dwarf_vmatoa ("x", uvalue
),
2736 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2738 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2739 dwarf_vmatoa ("x", uvalue
),
2740 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2744 case DW_FORM_GNU_strp_alt
:
2748 /* We have already displayed the form name. */
2749 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2750 dwarf_vmatoa ("x", uvalue
),
2751 fetch_alt_indirect_string (uvalue
));
2753 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2754 dwarf_vmatoa ("x", uvalue
),
2755 fetch_alt_indirect_string (uvalue
));
2759 case DW_FORM_indirect
:
2760 /* Handled above. */
2763 case DW_FORM_ref_sig8
:
2765 printf ("%c%s: 0x%s", delimiter
, do_wide
? "" : "signature",
2766 dwarf_vmatoa ("x", uvalue
));
2769 case DW_FORM_GNU_addr_index
:
2771 case DW_FORM_addrx1
:
2772 case DW_FORM_addrx2
:
2773 case DW_FORM_addrx3
:
2774 case DW_FORM_addrx4
:
2775 case DW_FORM_loclistx
:
2776 case DW_FORM_rnglistx
:
2782 if (debug_info_p
== NULL
)
2784 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2787 base
= debug_info_p
->addr_base
;
2789 offset
= base
+ uvalue
* pointer_size
;
2792 /* We have already displayed the form name. */
2793 printf (_("%c(index: 0x%s): %s"), delimiter
,
2794 dwarf_vmatoa ("x", uvalue
),
2795 dwarf_vmatoa ("x", fetch_indexed_addr (offset
, pointer_size
)));
2797 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2798 dwarf_vmatoa ("x", uvalue
),
2799 dwarf_vmatoa ("x", fetch_indexed_addr (offset
, pointer_size
)));
2803 case DW_FORM_strp_sup
:
2805 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2809 warn (_("Unrecognized form: 0x%lx\n"), form
);
2810 /* What to do? Consume a byte maybe? */
2815 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2816 && num_debug_info_entries
== 0
2817 && debug_info_p
!= NULL
)
2821 case DW_AT_loclists_base
:
2822 if (debug_info_p
->loclists_base
)
2823 warn (_("CU @ 0x%s has multiple loclists_base values"),
2824 dwarf_vmatoa ("x", debug_info_p
->cu_offset
));
2825 debug_info_p
->loclists_base
= uvalue
;
2828 case DW_AT_frame_base
:
2829 have_frame_base
= 1;
2831 case DW_AT_location
:
2832 case DW_AT_GNU_locviews
:
2833 case DW_AT_string_length
:
2834 case DW_AT_return_addr
:
2835 case DW_AT_data_member_location
:
2836 case DW_AT_vtable_elem_location
:
2838 case DW_AT_static_link
:
2839 case DW_AT_use_location
:
2840 case DW_AT_call_value
:
2841 case DW_AT_GNU_call_site_value
:
2842 case DW_AT_call_data_value
:
2843 case DW_AT_GNU_call_site_data_value
:
2844 case DW_AT_call_target
:
2845 case DW_AT_GNU_call_site_target
:
2846 case DW_AT_call_target_clobbered
:
2847 case DW_AT_GNU_call_site_target_clobbered
:
2848 if ((dwarf_version
< 4
2849 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2850 || form
== DW_FORM_sec_offset
2851 || form
== DW_FORM_loclistx
)
2853 /* Process location list. */
2854 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2855 unsigned int num
= debug_info_p
->num_loc_offsets
;
2857 if (lmax
== 0 || num
>= lmax
)
2860 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2861 xcrealloc (debug_info_p
->loc_offsets
,
2862 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2863 debug_info_p
->loc_views
= (dwarf_vma
*)
2864 xcrealloc (debug_info_p
->loc_views
,
2865 lmax
, sizeof (*debug_info_p
->loc_views
));
2866 debug_info_p
->have_frame_base
= (int *)
2867 xcrealloc (debug_info_p
->have_frame_base
,
2868 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2869 debug_info_p
->max_loc_offsets
= lmax
;
2872 if (form
== DW_FORM_loclistx
)
2873 uvalue
= fetch_indexed_value (uvalue
, loclists
);
2874 else if (this_set
!= NULL
)
2875 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2877 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2878 if (attribute
!= DW_AT_GNU_locviews
)
2880 uvalue
+= debug_info_p
->loclists_base
;
2882 /* Corrupt DWARF info can produce more offsets than views.
2883 See PR 23062 for an example. */
2884 if (debug_info_p
->num_loc_offsets
2885 > debug_info_p
->num_loc_views
)
2886 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2889 debug_info_p
->loc_offsets
[num
] = uvalue
;
2890 debug_info_p
->num_loc_offsets
++;
2895 assert (debug_info_p
->num_loc_views
<= num
);
2896 num
= debug_info_p
->num_loc_views
;
2897 if (num
> debug_info_p
->num_loc_offsets
)
2898 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2901 debug_info_p
->loc_views
[num
] = uvalue
;
2902 debug_info_p
->num_loc_views
++;
2909 if (need_base_address
)
2910 debug_info_p
->base_address
= uvalue
;
2913 case DW_AT_GNU_addr_base
:
2914 case DW_AT_addr_base
:
2915 debug_info_p
->addr_base
= uvalue
;
2918 case DW_AT_GNU_ranges_base
:
2919 debug_info_p
->ranges_base
= uvalue
;
2923 if ((dwarf_version
< 4
2924 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2925 || form
== DW_FORM_sec_offset
2926 || form
== DW_FORM_rnglistx
)
2928 /* Process range list. */
2929 unsigned int lmax
= debug_info_p
->max_range_lists
;
2930 unsigned int num
= debug_info_p
->num_range_lists
;
2932 if (lmax
== 0 || num
>= lmax
)
2935 debug_info_p
->range_lists
= (dwarf_vma
*)
2936 xcrealloc (debug_info_p
->range_lists
,
2937 lmax
, sizeof (*debug_info_p
->range_lists
));
2938 debug_info_p
->max_range_lists
= lmax
;
2941 if (form
== DW_FORM_rnglistx
)
2942 uvalue
= fetch_indexed_value (uvalue
, rnglists
);
2944 debug_info_p
->range_lists
[num
] = uvalue
;
2945 debug_info_p
->num_range_lists
++;
2949 case DW_AT_GNU_dwo_name
:
2950 case DW_AT_dwo_name
:
2955 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2957 case DW_FORM_GNU_strp_alt
:
2958 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2960 case DW_FORM_GNU_str_index
:
2966 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2968 case DW_FORM_string
:
2969 add_dwo_name ((const char *) orig_data
, cu_offset
);
2972 warn (_("Unsupported form (%s) for attribute %s\n"),
2973 get_FORM_name (form
), get_AT_name (attribute
));
2978 case DW_AT_comp_dir
:
2979 /* FIXME: Also extract a build-id in a CU/TU. */
2984 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2986 case DW_FORM_GNU_strp_alt
:
2987 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2989 case DW_FORM_line_strp
:
2990 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2992 case DW_FORM_GNU_str_index
:
2998 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
3000 case DW_FORM_string
:
3001 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3004 warn (_("Unsupported form (%s) for attribute %s\n"),
3005 get_FORM_name (form
), get_AT_name (attribute
));
3010 case DW_AT_GNU_dwo_id
:
3015 /* FIXME: Record the length of the ID as well ? */
3016 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3019 warn (_("Unsupported form (%s) for attribute %s\n"),
3020 get_FORM_name (form
), get_AT_name (attribute
));
3030 if (do_loc
|| attribute
== 0)
3033 /* For some attributes we can display further information. */
3037 if (level
>= 0 && level
< MAX_CU_NESTING
3038 && uvalue
< (size_t) (end
- start
))
3040 bool is_signed
= false;
3041 abbrev_entry
*type_abbrev
;
3042 unsigned char *type_data
;
3045 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3049 if (type_abbrev
!= NULL
)
3051 get_type_signedness (type_abbrev
, section
, type_data
,
3052 map
? section
->start
+ map
->end
: end
,
3053 map
? map
->start
: cu_offset
,
3054 pointer_size
, offset_size
, dwarf_version
,
3057 level_type_signed
[level
] = is_signed
;
3065 case DW_INL_not_inlined
:
3066 printf (_("(not inlined)"));
3068 case DW_INL_inlined
:
3069 printf (_("(inlined)"));
3071 case DW_INL_declared_not_inlined
:
3072 printf (_("(declared as inline but ignored)"));
3074 case DW_INL_declared_inlined
:
3075 printf (_("(declared as inline and inlined)"));
3078 printf (_(" (Unknown inline attribute value: %s)"),
3079 dwarf_vmatoa ("x", uvalue
));
3084 case DW_AT_language
:
3088 /* Ordered by the numeric value of these constants. */
3089 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3090 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3091 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3092 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3093 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3094 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3095 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3096 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3097 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3098 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3099 /* DWARF 2.1 values. */
3100 case DW_LANG_Java
: printf ("(Java)"); break;
3101 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3102 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3103 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3104 /* DWARF 3 values. */
3105 case DW_LANG_PLI
: printf ("(PLI)"); break;
3106 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3107 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3108 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3109 case DW_LANG_D
: printf ("(D)"); break;
3110 /* DWARF 4 values. */
3111 case DW_LANG_Python
: printf ("(Python)"); break;
3112 /* DWARF 5 values. */
3113 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3114 case DW_LANG_Go
: printf ("(Go)"); break;
3115 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3116 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3117 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3118 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3119 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3120 case DW_LANG_Rust
: printf ("(Rust)"); break;
3121 case DW_LANG_C11
: printf ("(C11)"); break;
3122 case DW_LANG_Swift
: printf ("(Swift)"); break;
3123 case DW_LANG_Julia
: printf ("(Julia)"); break;
3124 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3125 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3126 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3127 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3128 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3129 /* MIPS extension. */
3130 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3131 /* UPC extension. */
3132 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3134 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3135 printf (_("(implementation defined: %s)"),
3136 dwarf_vmatoa ("x", uvalue
));
3138 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3143 case DW_AT_encoding
:
3147 case DW_ATE_void
: printf ("(void)"); break;
3148 case DW_ATE_address
: printf ("(machine address)"); break;
3149 case DW_ATE_boolean
: printf ("(boolean)"); break;
3150 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3151 case DW_ATE_float
: printf ("(float)"); break;
3152 case DW_ATE_signed
: printf ("(signed)"); break;
3153 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3154 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3155 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3156 /* DWARF 2.1 values: */
3157 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3158 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3159 /* DWARF 3 values: */
3160 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3161 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3162 case DW_ATE_edited
: printf ("(edited)"); break;
3163 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3164 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3165 /* DWARF 4 values: */
3166 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3167 /* DWARF 5 values: */
3168 case DW_ATE_UCS
: printf ("(UCS)"); break;
3169 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3171 /* HP extensions: */
3172 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3173 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3174 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3175 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3176 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3177 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3178 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3181 if (uvalue
>= DW_ATE_lo_user
3182 && uvalue
<= DW_ATE_hi_user
)
3183 printf (_("(user defined type)"));
3185 printf (_("(unknown type)"));
3190 case DW_AT_accessibility
:
3194 case DW_ACCESS_public
: printf ("(public)"); break;
3195 case DW_ACCESS_protected
: printf ("(protected)"); break;
3196 case DW_ACCESS_private
: printf ("(private)"); break;
3198 printf (_("(unknown accessibility)"));
3203 case DW_AT_visibility
:
3207 case DW_VIS_local
: printf ("(local)"); break;
3208 case DW_VIS_exported
: printf ("(exported)"); break;
3209 case DW_VIS_qualified
: printf ("(qualified)"); break;
3210 default: printf (_("(unknown visibility)")); break;
3214 case DW_AT_endianity
:
3218 case DW_END_default
: printf ("(default)"); break;
3219 case DW_END_big
: printf ("(big)"); break;
3220 case DW_END_little
: printf ("(little)"); break;
3222 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3223 printf (_("(user specified)"));
3225 printf (_("(unknown endianity)"));
3230 case DW_AT_virtuality
:
3234 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3235 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3236 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3237 default: printf (_("(unknown virtuality)")); break;
3241 case DW_AT_identifier_case
:
3245 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3246 case DW_ID_up_case
: printf ("(up_case)"); break;
3247 case DW_ID_down_case
: printf ("(down_case)"); break;
3248 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3249 default: printf (_("(unknown case)")); break;
3253 case DW_AT_calling_convention
:
3257 case DW_CC_normal
: printf ("(normal)"); break;
3258 case DW_CC_program
: printf ("(program)"); break;
3259 case DW_CC_nocall
: printf ("(nocall)"); break;
3260 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3261 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3262 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3263 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3265 if (uvalue
>= DW_CC_lo_user
3266 && uvalue
<= DW_CC_hi_user
)
3267 printf (_("(user defined)"));
3269 printf (_("(unknown convention)"));
3273 case DW_AT_ordering
:
3278 case -1: printf (_("(undefined)")); break;
3279 case 0: printf ("(row major)"); break;
3280 case 1: printf ("(column major)"); break;
3284 case DW_AT_decimal_sign
:
3288 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3289 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3290 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3291 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3292 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3293 default: printf (_("(unrecognised)")); break;
3297 case DW_AT_defaulted
:
3301 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3302 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3303 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3304 default: printf (_("(unrecognised)")); break;
3308 case DW_AT_discr_list
:
3310 display_discr_list (form
, uvalue
, data
, level
);
3313 case DW_AT_frame_base
:
3314 have_frame_base
= 1;
3316 case DW_AT_location
:
3317 case DW_AT_loclists_base
:
3318 case DW_AT_string_length
:
3319 case DW_AT_return_addr
:
3320 case DW_AT_data_member_location
:
3321 case DW_AT_vtable_elem_location
:
3323 case DW_AT_static_link
:
3324 case DW_AT_use_location
:
3325 case DW_AT_call_value
:
3326 case DW_AT_GNU_call_site_value
:
3327 case DW_AT_call_data_value
:
3328 case DW_AT_GNU_call_site_data_value
:
3329 case DW_AT_call_target
:
3330 case DW_AT_GNU_call_site_target
:
3331 case DW_AT_call_target_clobbered
:
3332 case DW_AT_GNU_call_site_target_clobbered
:
3333 if ((dwarf_version
< 4
3334 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3335 || form
== DW_FORM_sec_offset
3336 || form
== DW_FORM_loclistx
)
3337 printf (_(" (location list)"));
3339 case DW_AT_allocated
:
3340 case DW_AT_associated
:
3341 case DW_AT_data_location
:
3343 case DW_AT_upper_bound
:
3344 case DW_AT_lower_bound
:
3347 int need_frame_base
;
3350 need_frame_base
= decode_location_expression (block_start
,
3355 cu_offset
, section
);
3357 if (need_frame_base
&& !have_frame_base
)
3358 printf (_(" [without DW_AT_frame_base]"));
3362 case DW_AT_data_bit_offset
:
3363 case DW_AT_byte_size
:
3364 case DW_AT_bit_size
:
3365 case DW_AT_string_length_byte_size
:
3366 case DW_AT_string_length_bit_size
:
3367 case DW_AT_bit_stride
:
3368 if (form
== DW_FORM_exprloc
)
3371 (void) decode_location_expression (block_start
, pointer_size
,
3372 offset_size
, dwarf_version
,
3373 uvalue
, cu_offset
, section
);
3380 unsigned long abbrev_number
;
3381 abbrev_entry
*entry
;
3383 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3384 section
, & abbrev_number
, NULL
, NULL
);
3387 if (form
!= DW_FORM_GNU_ref_alt
)
3388 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3389 dwarf_vmatoa ("x", uvalue
),
3390 (unsigned long) (orig_data
- section
->start
));
3394 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3395 printf (" (%s)", get_TAG_name (entry
->tag
));
3408 static unsigned char *
3409 read_and_display_attr (unsigned long attribute
,
3411 dwarf_signed_vma implicit_const
,
3412 unsigned char * start
,
3413 unsigned char * data
,
3414 unsigned char * end
,
3415 dwarf_vma cu_offset
,
3416 dwarf_vma pointer_size
,
3417 dwarf_vma offset_size
,
3419 debug_info
* debug_info_p
,
3421 struct dwarf_section
* section
,
3422 struct cu_tu_set
* this_set
,
3426 printf (" %-18s:", get_AT_name (attribute
));
3427 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3429 cu_offset
, pointer_size
, offset_size
,
3430 dwarf_version
, debug_info_p
,
3431 do_loc
, section
, this_set
, ' ', level
);
3437 /* Like load_debug_section, but if the ordinary call fails, and we are
3438 following debug links, then attempt to load the requested section
3439 from one of the separate debug info files. */
3442 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3445 if (load_debug_section (sec_enum
, handle
))
3447 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3449 /* See if we can associate a filename with this section. */
3452 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3453 if (i
->handle
== handle
)
3455 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3463 if (do_follow_links
)
3467 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3469 if (load_debug_section (sec_enum
, i
->handle
))
3471 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3473 /* FIXME: We should check to see if any of the remaining debug info
3474 files also contain this section, and, umm, do something about it. */
3484 introduce (struct dwarf_section
* section
, bool raw
)
3488 if (do_follow_links
&& section
->filename
)
3489 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3490 section
->name
, section
->filename
);
3492 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3496 if (do_follow_links
&& section
->filename
)
3497 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3498 section
->name
, section
->filename
);
3500 printf (_("Contents of the %s section:\n\n"), section
->name
);
3504 /* Process the contents of a .debug_info section.
3505 If do_loc is TRUE then we are scanning for location lists and dwo tags
3506 and we do not want to display anything to the user.
3507 If do_types is TRUE, we are processing a .debug_types section instead of
3508 a .debug_info section.
3509 The information displayed is restricted by the values in DWARF_START_DIE
3510 and DWARF_CUTOFF_LEVEL.
3511 Returns TRUE upon success. Otherwise an error or warning message is
3512 printed and FALSE is returned. */
3515 process_debug_info (struct dwarf_section
* section
,
3517 enum dwarf_section_display_enum abbrev_sec
,
3521 unsigned char *start
= section
->start
;
3522 unsigned char *end
= start
+ section
->size
;
3523 unsigned char *section_begin
;
3525 unsigned int num_units
= 0;
3527 /* First scan the section to get the number of comp units.
3528 Length sanity checks are done here. */
3529 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3534 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3535 will be the length. For a 64-bit DWARF section, it'll be
3536 the escape code 0xffffffff followed by an 8 byte length. */
3537 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3539 if (length
== 0xffffffff)
3540 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3541 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3543 warn (_("Reserved length value (0x%s) found in section %s\n"),
3544 dwarf_vmatoa ("x", length
), section
->name
);
3548 /* Negative values are illegal, they may even cause infinite
3549 looping. This can happen if we can't accurately apply
3550 relocations to an object file, or if the file is corrupt. */
3551 if (length
> (size_t) (end
- section_begin
))
3553 warn (_("Corrupt unit length (got 0x%s expected at most 0x%s) in section %s\n"),
3554 dwarf_vmatoa ("x", length
),
3555 dwarf_vmatoa ("x", end
- section_begin
),
3559 section_begin
+= length
;
3564 error (_("No comp units in %s section ?\n"), section
->name
);
3568 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3569 && num_debug_info_entries
== 0
3573 /* Then allocate an array to hold the information. */
3574 debug_information
= (debug_info
*) cmalloc (num_units
,
3575 sizeof (* debug_information
));
3576 if (debug_information
== NULL
)
3578 error (_("Not enough memory for a debug info array of %u entries\n"),
3580 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3584 /* PR 17531: file: 92ca3797.
3585 We cannot rely upon the debug_information array being initialised
3586 before it is used. A corrupt file could easily contain references
3587 to a unit for which information has not been made available. So
3588 we ensure that the array is zeroed here. */
3589 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3591 alloc_num_debug_info_entries
= num_units
;
3596 load_debug_section_with_follow (str
, file
);
3597 load_debug_section_with_follow (line_str
, file
);
3598 load_debug_section_with_follow (str_dwo
, file
);
3599 load_debug_section_with_follow (str_index
, file
);
3600 load_debug_section_with_follow (str_index_dwo
, file
);
3601 load_debug_section_with_follow (debug_addr
, file
);
3604 load_debug_section_with_follow (abbrev_sec
, file
);
3605 load_debug_section_with_follow (loclists
, file
);
3606 load_debug_section_with_follow (rnglists
, file
);
3608 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3610 warn (_("Unable to locate %s section!\n"),
3611 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3615 if (!do_loc
&& dwarf_start_die
== 0)
3616 introduce (section
, false);
3618 free_all_abbrevs ();
3619 free (cu_abbrev_map
);
3620 cu_abbrev_map
= NULL
;
3621 next_free_abbrev_map_entry
= 0;
3623 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3624 to load *all* of the abbrevs for all CUs in this .debug_info
3625 section. This does effectively mean that we (partially) read
3626 every CU header twice. */
3627 for (section_begin
= start
; start
< end
;)
3629 DWARF2_Internal_CompUnit compunit
;
3630 unsigned char * hdrptr
;
3631 dwarf_vma abbrev_base
;
3633 dwarf_vma cu_offset
;
3634 unsigned int offset_size
;
3635 struct cu_tu_set
* this_set
;
3637 unsigned char *end_cu
;
3640 cu_offset
= start
- section_begin
;
3642 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3644 if (compunit
.cu_length
== 0xffffffff)
3646 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3651 end_cu
= hdrptr
+ compunit
.cu_length
;
3653 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3655 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3657 if (compunit
.cu_version
< 5)
3659 compunit
.cu_unit_type
= DW_UT_compile
;
3660 /* Initialize it due to a false compiler warning. */
3661 compunit
.cu_pointer_size
= -1;
3665 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3666 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3668 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3671 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3674 if (compunit
.cu_unit_type
== DW_UT_split_compile
3675 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3678 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3681 if (this_set
== NULL
)
3684 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3688 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3689 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3692 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3693 compunit
.cu_abbrev_offset
);
3696 unsigned char * next
;
3698 list
= new_abbrev_list (abbrev_base
,
3699 compunit
.cu_abbrev_offset
);
3700 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3701 abbrev_base
, abbrev_size
,
3702 compunit
.cu_abbrev_offset
, list
);
3703 list
->start_of_next_abbrevs
= next
;
3707 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3710 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3712 DWARF2_Internal_CompUnit compunit
;
3713 unsigned char *hdrptr
;
3714 unsigned char *tags
;
3715 int level
, last_level
, saved_level
;
3716 dwarf_vma cu_offset
;
3717 unsigned int offset_size
;
3718 dwarf_vma signature
= 0;
3719 dwarf_vma type_offset
= 0;
3720 struct cu_tu_set
*this_set
;
3721 dwarf_vma abbrev_base
;
3723 abbrev_list
* list
= NULL
;
3724 unsigned char *end_cu
;
3727 cu_offset
= start
- section_begin
;
3729 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3731 if (compunit
.cu_length
== 0xffffffff)
3733 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3738 end_cu
= hdrptr
+ compunit
.cu_length
;
3740 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3742 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3744 if (compunit
.cu_version
< 5)
3746 compunit
.cu_unit_type
= DW_UT_compile
;
3747 /* Initialize it due to a false compiler warning. */
3748 compunit
.cu_pointer_size
= -1;
3752 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3753 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3755 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3758 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3760 if (this_set
== NULL
)
3763 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3767 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3768 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3771 if (compunit
.cu_version
< 5)
3772 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3774 bool do_dwo_id
= false;
3775 uint64_t dwo_id
= 0;
3776 if (compunit
.cu_unit_type
== DW_UT_split_compile
3777 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3779 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3783 /* PR 17512: file: 001-108546-0.001:0.1. */
3784 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3786 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3787 compunit
.cu_pointer_size
, offset_size
);
3788 compunit
.cu_pointer_size
= offset_size
;
3793 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3794 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3797 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3803 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3804 && num_debug_info_entries
== 0
3805 && alloc_num_debug_info_entries
> unit
3808 debug_information
[unit
].cu_offset
= cu_offset
;
3809 debug_information
[unit
].pointer_size
3810 = compunit
.cu_pointer_size
;
3811 debug_information
[unit
].offset_size
= offset_size
;
3812 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3813 debug_information
[unit
].base_address
= 0;
3814 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3815 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3816 debug_information
[unit
].loc_offsets
= NULL
;
3817 debug_information
[unit
].have_frame_base
= NULL
;
3818 debug_information
[unit
].max_loc_offsets
= 0;
3819 debug_information
[unit
].num_loc_offsets
= 0;
3820 debug_information
[unit
].loclists_base
= 0;
3821 debug_information
[unit
].range_lists
= NULL
;
3822 debug_information
[unit
].max_range_lists
= 0;
3823 debug_information
[unit
].num_range_lists
= 0;
3826 if (!do_loc
&& dwarf_start_die
== 0)
3828 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3829 dwarf_vmatoa ("x", cu_offset
));
3830 printf (_(" Length: 0x%s (%s)\n"),
3831 dwarf_vmatoa ("x", compunit
.cu_length
),
3832 offset_size
== 8 ? "64-bit" : "32-bit");
3833 printf (_(" Version: %d\n"), compunit
.cu_version
);
3834 if (compunit
.cu_version
>= 5)
3836 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3838 printf (_(" Unit Type: %s (%x)\n"),
3839 name
? name
: "???",
3840 compunit
.cu_unit_type
);
3842 printf (_(" Abbrev Offset: 0x%s\n"),
3843 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3844 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3847 printf (_(" Signature: 0x%s\n"),
3848 dwarf_vmatoa ("x", signature
));
3849 printf (_(" Type Offset: 0x%s\n"),
3850 dwarf_vmatoa ("x", type_offset
));
3853 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3854 if (this_set
!= NULL
)
3856 dwarf_vma
*offsets
= this_set
->section_offsets
;
3857 size_t *sizes
= this_set
->section_sizes
;
3859 printf (_(" Section contributions:\n"));
3860 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3861 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3862 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3863 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3864 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3865 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3866 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3867 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3868 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3869 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3870 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3871 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3878 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3880 warn (_("CU at offset %s contains corrupt or "
3881 "unsupported version number: %d.\n"),
3882 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3886 if (compunit
.cu_unit_type
!= DW_UT_compile
3887 && compunit
.cu_unit_type
!= DW_UT_partial
3888 && compunit
.cu_unit_type
!= DW_UT_type
3889 && compunit
.cu_unit_type
!= DW_UT_split_compile
3890 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3892 warn (_("CU at offset %s contains corrupt or "
3893 "unsupported unit type: %d.\n"),
3894 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3898 /* Process the abbrevs used by this compilation unit. */
3899 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3900 compunit
.cu_abbrev_offset
);
3903 unsigned char *next
;
3905 list
= new_abbrev_list (abbrev_base
,
3906 compunit
.cu_abbrev_offset
);
3907 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3908 abbrev_base
, abbrev_size
,
3909 compunit
.cu_abbrev_offset
, list
);
3910 list
->start_of_next_abbrevs
= next
;
3916 while (tags
< start
)
3918 unsigned long abbrev_number
;
3919 unsigned long die_offset
;
3920 abbrev_entry
*entry
;
3922 int do_printing
= 1;
3924 die_offset
= tags
- section_begin
;
3926 READ_ULEB (abbrev_number
, tags
, start
);
3928 /* A null DIE marks the end of a list of siblings or it may also be
3929 a section padding. */
3930 if (abbrev_number
== 0)
3932 /* Check if it can be a section padding for the last CU. */
3933 if (level
== 0 && start
== end
)
3937 for (chk
= tags
; chk
< start
; chk
++)
3944 if (!do_loc
&& die_offset
>= dwarf_start_die
3945 && (dwarf_cutoff_level
== -1
3946 || level
< dwarf_cutoff_level
))
3947 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3953 static unsigned num_bogus_warns
= 0;
3955 if (num_bogus_warns
< 3)
3957 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3958 die_offset
, section
->name
);
3960 if (num_bogus_warns
== 3)
3961 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3964 if (dwarf_start_die
!= 0 && level
< saved_level
)
3971 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3975 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3976 saved_level
= level
;
3977 do_printing
= (dwarf_cutoff_level
== -1
3978 || level
< dwarf_cutoff_level
);
3980 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3981 level
, die_offset
, abbrev_number
);
3982 else if (dwarf_cutoff_level
== -1
3983 || last_level
< dwarf_cutoff_level
)
3984 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3989 /* Scan through the abbreviation list until we reach the
3994 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3995 if (entry
->number
== abbrev_number
)
4000 if (!do_loc
&& do_printing
)
4005 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
4006 die_offset
, abbrev_number
);
4010 if (!do_loc
&& do_printing
)
4011 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4016 need_base_address
= 0;
4018 case DW_TAG_compile_unit
:
4019 need_base_address
= 1;
4020 need_dwo_info
= do_loc
;
4022 case DW_TAG_entry_point
:
4023 case DW_TAG_subprogram
:
4024 need_base_address
= 0;
4025 /* Assuming that there is no DW_AT_frame_base. */
4026 have_frame_base
= 0;
4030 debug_info
*debug_info_p
=
4031 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4032 ? debug_information
+ unit
: NULL
;
4034 assert (!debug_info_p
4035 || (debug_info_p
->num_loc_offsets
4036 == debug_info_p
->num_loc_views
));
4038 for (attr
= entry
->first_attr
;
4039 attr
&& attr
->attribute
;
4042 if (! do_loc
&& do_printing
)
4043 /* Show the offset from where the tag was extracted. */
4044 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
4045 tags
= read_and_display_attr (attr
->attribute
,
4047 attr
->implicit_const
,
4052 compunit
.cu_pointer_size
,
4054 compunit
.cu_version
,
4056 do_loc
|| ! do_printing
,
4062 /* If a locview attribute appears before a location one,
4063 make sure we don't associate it with an earlier
4066 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4069 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4070 debug_info_p
->num_loc_views
++;
4071 assert (debug_info_p
->num_loc_views
4072 == debug_info_p
->num_loc_offsets
);
4079 warn(_("DIE has locviews without loclist\n"));
4080 debug_info_p
->num_loc_views
--;
4087 if (entry
->children
)
4092 /* Set num_debug_info_entries here so that it can be used to check if
4093 we need to process .debug_loc and .debug_ranges sections. */
4094 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4095 && num_debug_info_entries
== 0
4098 if (num_units
> alloc_num_debug_info_entries
)
4099 num_debug_info_entries
= alloc_num_debug_info_entries
;
4101 num_debug_info_entries
= num_units
;
4110 /* Locate and scan the .debug_info section in the file and record the pointer
4111 sizes and offsets for the compilation units in it. Usually an executable
4112 will have just one pointer size, but this is not guaranteed, and so we try
4113 not to make any assumptions. Returns zero upon failure, or the number of
4114 compilation units upon success. */
4117 load_debug_info (void * file
)
4119 /* If we have already tried and failed to load the .debug_info
4120 section then do not bother to repeat the task. */
4121 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4124 /* If we already have the information there is nothing else to do. */
4125 if (num_debug_info_entries
> 0)
4126 return num_debug_info_entries
;
4128 /* If this is a DWARF package file, load the CU and TU indexes. */
4129 (void) load_cu_tu_indexes (file
);
4131 if (load_debug_section_with_follow (info
, file
)
4132 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4133 return num_debug_info_entries
;
4135 if (load_debug_section_with_follow (info_dwo
, file
)
4136 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4137 abbrev_dwo
, true, false))
4138 return num_debug_info_entries
;
4140 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4144 /* Read a DWARF .debug_line section header starting at DATA.
4145 Upon success returns an updated DATA pointer and the LINFO
4146 structure and the END_OF_SEQUENCE pointer will be filled in.
4147 Otherwise returns NULL. */
4149 static unsigned char *
4150 read_debug_line_header (struct dwarf_section
* section
,
4151 unsigned char * data
,
4152 unsigned char * end
,
4153 DWARF2_Internal_LineInfo
* linfo
,
4154 unsigned char ** end_of_sequence
)
4156 unsigned char *hdrptr
;
4158 /* Extract information from the Line Number Program Header.
4159 (section 6.2.4 in the Dwarf3 doc). */
4162 /* Get and check the length of the block. */
4163 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4165 if (linfo
->li_length
== 0xffffffff)
4167 /* This section is 64-bit DWARF 3. */
4168 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4169 linfo
->li_offset_size
= 8;
4172 linfo
->li_offset_size
= 4;
4174 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4176 /* If the length field has a relocation against it, then we should
4177 not complain if it is inaccurate (and probably negative). This
4178 happens in object files when the .debug_line section is actually
4179 comprised of several different .debug_line.* sections, (some of
4180 which may be removed by linker garbage collection), and a relocation
4181 is used to compute the correct length once that is done. */
4182 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4184 linfo
->li_length
= end
- hdrptr
;
4188 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4189 (long) linfo
->li_length
);
4193 end
= hdrptr
+ linfo
->li_length
;
4195 /* Get and check the version number. */
4196 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4198 if (linfo
->li_version
!= 2
4199 && linfo
->li_version
!= 3
4200 && linfo
->li_version
!= 4
4201 && linfo
->li_version
!= 5)
4203 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4204 "is currently supported.\n"));
4208 if (linfo
->li_version
>= 5)
4210 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4212 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4213 if (linfo
->li_segment_size
!= 0)
4215 warn (_("The %s section contains "
4216 "unsupported segment selector size: %d.\n"),
4217 section
->name
, linfo
->li_segment_size
);
4222 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4223 linfo
->li_offset_size
, end
);
4224 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4226 if (linfo
->li_version
>= 4)
4228 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4230 if (linfo
->li_max_ops_per_insn
== 0)
4232 warn (_("Invalid maximum operations per insn.\n"));
4237 linfo
->li_max_ops_per_insn
= 1;
4239 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4240 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4241 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4242 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4244 *end_of_sequence
= end
;
4248 static unsigned char *
4249 display_formatted_table (unsigned char *data
,
4250 unsigned char *start
,
4252 const DWARF2_Internal_LineInfo
*linfo
,
4253 struct dwarf_section
*section
,
4256 unsigned char *format_start
, format_count
, *format
, formati
;
4257 dwarf_vma data_count
, datai
;
4258 unsigned int namepass
, last_entry
= 0;
4259 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4261 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4262 if (do_checks
&& format_count
> 5)
4263 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4264 table_name
, format_count
);
4266 format_start
= data
;
4267 for (formati
= 0; formati
< format_count
; formati
++)
4269 SKIP_ULEB (data
, end
);
4270 SKIP_ULEB (data
, end
);
4273 warn (_("%s: Corrupt format description entry\n"), table_name
);
4278 READ_ULEB (data_count
, data
, end
);
4279 if (data_count
== 0)
4281 printf (_("\n The %s is empty.\n"), table_name
);
4284 else if (data
>= end
)
4286 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4287 table_name
, dwarf_vmatoa ("x", data_count
));
4291 else if (format_count
== 0)
4293 warn (_("%s: format count is zero, but the table is not empty\n"),
4298 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4299 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4302 printf (_(" Entry"));
4303 /* Delay displaying name as the last entry for better screen layout. */
4304 for (namepass
= 0; namepass
< 2; namepass
++)
4306 format
= format_start
;
4307 for (formati
= 0; formati
< format_count
; formati
++)
4309 dwarf_vma content_type
;
4311 READ_ULEB (content_type
, format
, end
);
4312 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4313 switch (content_type
)
4316 printf (_("\tName"));
4318 case DW_LNCT_directory_index
:
4319 printf (_("\tDir"));
4321 case DW_LNCT_timestamp
:
4322 printf (_("\tTime"));
4325 printf (_("\tSize"));
4328 printf (_("\tMD5\t\t\t"));
4331 printf (_("\t(Unknown format content type %s)"),
4332 dwarf_vmatoa ("u", content_type
));
4334 SKIP_ULEB (format
, end
);
4339 for (datai
= 0; datai
< data_count
; datai
++)
4341 unsigned char *datapass
= data
;
4343 printf (" %d", last_entry
++);
4344 /* Delay displaying name as the last entry for better screen layout. */
4345 for (namepass
= 0; namepass
< 2; namepass
++)
4347 format
= format_start
;
4349 for (formati
= 0; formati
< format_count
; formati
++)
4351 dwarf_vma content_type
, form
;
4353 READ_ULEB (content_type
, format
, end
);
4354 READ_ULEB (form
, format
, end
);
4355 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4356 0, 0, linfo
->li_offset_size
,
4357 linfo
->li_version
, NULL
,
4358 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4359 section
, NULL
, '\t', -1);
4363 if (data
>= end
&& (datai
< data_count
- 1))
4365 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4374 display_debug_sup (struct dwarf_section
* section
,
4375 void * file ATTRIBUTE_UNUSED
)
4377 unsigned char * start
= section
->start
;
4378 unsigned char * end
= section
->start
+ section
->size
;
4379 unsigned int version
;
4380 char is_supplementary
;
4381 const unsigned char * sup_filename
;
4382 size_t sup_filename_len
;
4383 unsigned int num_read
;
4385 dwarf_vma checksum_len
;
4388 introduce (section
, true);
4389 if (section
->size
< 4)
4391 error (_("corrupt .debug_sup section: size is too small\n"));
4395 /* Read the data. */
4396 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4398 warn (_("corrupt .debug_sup section: version < 5"));
4400 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4401 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4402 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4404 sup_filename
= start
;
4405 if (is_supplementary
&& sup_filename
[0] != 0)
4406 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4408 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4409 if (sup_filename_len
== (size_t) (end
- start
))
4411 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4414 start
+= sup_filename_len
+ 1;
4416 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4419 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4423 if (checksum_len
> (dwarf_vma
) (end
- start
))
4425 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4426 checksum_len
= end
- start
;
4428 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4430 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4431 (long) ((end
- start
) - checksum_len
));
4434 printf (_(" Version: %u\n"), version
);
4435 printf (_(" Is Supp: %u\n"), is_supplementary
);
4436 printf (_(" Filename: %s\n"), sup_filename
);
4437 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4438 if (checksum_len
> 0)
4440 printf (_(" Checksum: "));
4441 while (checksum_len
--)
4442 printf ("0x%x ", * start
++ );
4449 display_debug_lines_raw (struct dwarf_section
* section
,
4450 unsigned char * data
,
4451 unsigned char * end
,
4454 unsigned char *start
= section
->start
;
4455 int verbose_view
= 0;
4457 introduce (section
, true);
4461 static DWARF2_Internal_LineInfo saved_linfo
;
4462 DWARF2_Internal_LineInfo linfo
;
4463 unsigned char *standard_opcodes
;
4464 unsigned char *end_of_sequence
;
4467 if (startswith (section
->name
, ".debug_line.")
4468 /* Note: the following does not apply to .debug_line.dwo sections.
4469 These are full debug_line sections. */
4470 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4472 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4473 section containing just the Line Number Statements. They are
4474 created by the assembler and intended to be used alongside gcc's
4475 -ffunction-sections command line option. When the linker's
4476 garbage collection decides to discard a .text.<foo> section it
4477 can then also discard the line number information in .debug_line.<foo>.
4479 Since the section is a fragment it does not have the details
4480 needed to fill out a LineInfo structure, so instead we use the
4481 details from the last full debug_line section that we processed. */
4482 end_of_sequence
= end
;
4483 standard_opcodes
= NULL
;
4484 linfo
= saved_linfo
;
4485 /* PR 17531: file: 0522b371. */
4486 if (linfo
.li_line_range
== 0)
4488 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4491 reset_state_machine (linfo
.li_default_is_stmt
);
4495 unsigned char * hdrptr
;
4497 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4498 & end_of_sequence
)) == NULL
)
4501 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4502 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4503 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4504 if (linfo
.li_version
>= 5)
4506 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4507 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4509 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4510 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4511 if (linfo
.li_version
>= 4)
4512 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4513 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4514 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4515 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4516 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4518 /* PR 17512: file: 1665-6428-0.004. */
4519 if (linfo
.li_line_range
== 0)
4521 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4522 linfo
.li_line_range
= 1;
4525 reset_state_machine (linfo
.li_default_is_stmt
);
4527 /* Display the contents of the Opcodes table. */
4528 standard_opcodes
= hdrptr
;
4530 /* PR 17512: file: 002-417945-0.004. */
4531 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4533 warn (_("Line Base extends beyond end of section\n"));
4537 printf (_("\n Opcodes:\n"));
4539 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4540 printf (ngettext (" Opcode %d has %d arg\n",
4541 " Opcode %d has %d args\n",
4542 standard_opcodes
[i
- 1]),
4543 i
, standard_opcodes
[i
- 1]);
4545 /* Display the contents of the Directory table. */
4546 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4548 if (linfo
.li_version
>= 5)
4550 load_debug_section_with_follow (line_str
, file
);
4552 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4554 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4560 printf (_("\n The Directory Table is empty.\n"));
4563 unsigned int last_dir_entry
= 0;
4565 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4566 (long)(data
- start
));
4568 while (data
< end
&& *data
!= 0)
4570 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4572 data
+= strnlen ((char *) data
, end
- data
);
4577 /* PR 17512: file: 002-132094-0.004. */
4578 if (data
>= end
- 1)
4582 /* Skip the NUL at the end of the table. */
4586 /* Display the contents of the File Name table. */
4587 if (data
>= end
|| *data
== 0)
4588 printf (_("\n The File Name Table is empty.\n"));
4591 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4592 (long)(data
- start
));
4593 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4595 while (data
< end
&& *data
!= 0)
4597 unsigned char *name
;
4600 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4602 data
+= strnlen ((char *) data
, end
- data
);
4606 READ_ULEB (val
, data
, end
);
4607 printf ("%s\t", dwarf_vmatoa ("u", val
));
4608 READ_ULEB (val
, data
, end
);
4609 printf ("%s\t", dwarf_vmatoa ("u", val
));
4610 READ_ULEB (val
, data
, end
);
4611 printf ("%s\t", dwarf_vmatoa ("u", val
));
4612 printf ("%.*s\n", (int)(end
- name
), name
);
4616 warn (_("Corrupt file name table entry\n"));
4622 /* Skip the NUL at the end of the table. */
4628 saved_linfo
= linfo
;
4631 /* Now display the statements. */
4632 if (data
>= end_of_sequence
)
4633 printf (_(" No Line Number Statements.\n"));
4636 printf (_(" Line Number Statements:\n"));
4638 while (data
< end_of_sequence
)
4640 unsigned char op_code
;
4641 dwarf_signed_vma adv
;
4644 printf (" [0x%08lx]", (long)(data
- start
));
4648 if (op_code
>= linfo
.li_opcode_base
)
4650 op_code
-= linfo
.li_opcode_base
;
4651 uladv
= (op_code
/ linfo
.li_line_range
);
4652 if (linfo
.li_max_ops_per_insn
== 1)
4654 uladv
*= linfo
.li_min_insn_length
;
4655 state_machine_regs
.address
+= uladv
;
4657 state_machine_regs
.view
= 0;
4658 printf (_(" Special opcode %d: "
4659 "advance Address by %s to 0x%s%s"),
4660 op_code
, dwarf_vmatoa ("u", uladv
),
4661 dwarf_vmatoa ("x", state_machine_regs
.address
),
4662 verbose_view
&& uladv
4663 ? _(" (reset view)") : "");
4668 = ((state_machine_regs
.op_index
+ uladv
)
4669 / linfo
.li_max_ops_per_insn
)
4670 * linfo
.li_min_insn_length
;
4672 state_machine_regs
.address
+= addrdelta
;
4673 state_machine_regs
.op_index
4674 = (state_machine_regs
.op_index
+ uladv
)
4675 % linfo
.li_max_ops_per_insn
;
4677 state_machine_regs
.view
= 0;
4678 printf (_(" Special opcode %d: "
4679 "advance Address by %s to 0x%s[%d]%s"),
4680 op_code
, dwarf_vmatoa ("u", uladv
),
4681 dwarf_vmatoa ("x", state_machine_regs
.address
),
4682 state_machine_regs
.op_index
,
4683 verbose_view
&& addrdelta
4684 ? _(" (reset view)") : "");
4686 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4687 state_machine_regs
.line
+= adv
;
4688 printf (_(" and Line by %s to %d"),
4689 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4690 if (verbose_view
|| state_machine_regs
.view
)
4691 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4694 state_machine_regs
.view
++;
4699 case DW_LNS_extended_op
:
4700 data
+= process_extended_line_op (data
,
4701 linfo
.li_default_is_stmt
,
4706 printf (_(" Copy"));
4707 if (verbose_view
|| state_machine_regs
.view
)
4708 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4711 state_machine_regs
.view
++;
4714 case DW_LNS_advance_pc
:
4715 READ_ULEB (uladv
, data
, end
);
4716 if (linfo
.li_max_ops_per_insn
== 1)
4718 uladv
*= linfo
.li_min_insn_length
;
4719 state_machine_regs
.address
+= uladv
;
4721 state_machine_regs
.view
= 0;
4722 printf (_(" Advance PC by %s to 0x%s%s\n"),
4723 dwarf_vmatoa ("u", uladv
),
4724 dwarf_vmatoa ("x", state_machine_regs
.address
),
4725 verbose_view
&& uladv
4726 ? _(" (reset view)") : "");
4731 = ((state_machine_regs
.op_index
+ uladv
)
4732 / linfo
.li_max_ops_per_insn
)
4733 * linfo
.li_min_insn_length
;
4734 state_machine_regs
.address
4736 state_machine_regs
.op_index
4737 = (state_machine_regs
.op_index
+ uladv
)
4738 % linfo
.li_max_ops_per_insn
;
4740 state_machine_regs
.view
= 0;
4741 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4742 dwarf_vmatoa ("u", uladv
),
4743 dwarf_vmatoa ("x", state_machine_regs
.address
),
4744 state_machine_regs
.op_index
,
4745 verbose_view
&& addrdelta
4746 ? _(" (reset view)") : "");
4750 case DW_LNS_advance_line
:
4751 READ_SLEB (adv
, data
, end
);
4752 state_machine_regs
.line
+= adv
;
4753 printf (_(" Advance Line by %s to %d\n"),
4754 dwarf_vmatoa ("d", adv
),
4755 state_machine_regs
.line
);
4758 case DW_LNS_set_file
:
4759 READ_ULEB (uladv
, data
, end
);
4760 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4761 dwarf_vmatoa ("u", uladv
));
4762 state_machine_regs
.file
= uladv
;
4765 case DW_LNS_set_column
:
4766 READ_ULEB (uladv
, data
, end
);
4767 printf (_(" Set column to %s\n"),
4768 dwarf_vmatoa ("u", uladv
));
4769 state_machine_regs
.column
= uladv
;
4772 case DW_LNS_negate_stmt
:
4773 adv
= state_machine_regs
.is_stmt
;
4775 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4776 state_machine_regs
.is_stmt
= adv
;
4779 case DW_LNS_set_basic_block
:
4780 printf (_(" Set basic block\n"));
4781 state_machine_regs
.basic_block
= 1;
4784 case DW_LNS_const_add_pc
:
4785 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4786 if (linfo
.li_max_ops_per_insn
)
4788 uladv
*= linfo
.li_min_insn_length
;
4789 state_machine_regs
.address
+= uladv
;
4791 state_machine_regs
.view
= 0;
4792 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4793 dwarf_vmatoa ("u", uladv
),
4794 dwarf_vmatoa ("x", state_machine_regs
.address
),
4795 verbose_view
&& uladv
4796 ? _(" (reset view)") : "");
4801 = ((state_machine_regs
.op_index
+ uladv
)
4802 / linfo
.li_max_ops_per_insn
)
4803 * linfo
.li_min_insn_length
;
4804 state_machine_regs
.address
4806 state_machine_regs
.op_index
4807 = (state_machine_regs
.op_index
+ uladv
)
4808 % linfo
.li_max_ops_per_insn
;
4810 state_machine_regs
.view
= 0;
4811 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4812 dwarf_vmatoa ("u", uladv
),
4813 dwarf_vmatoa ("x", state_machine_regs
.address
),
4814 state_machine_regs
.op_index
,
4815 verbose_view
&& addrdelta
4816 ? _(" (reset view)") : "");
4820 case DW_LNS_fixed_advance_pc
:
4821 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4822 state_machine_regs
.address
+= uladv
;
4823 state_machine_regs
.op_index
= 0;
4824 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4825 dwarf_vmatoa ("u", uladv
),
4826 dwarf_vmatoa ("x", state_machine_regs
.address
));
4827 /* Do NOT reset view. */
4830 case DW_LNS_set_prologue_end
:
4831 printf (_(" Set prologue_end to true\n"));
4834 case DW_LNS_set_epilogue_begin
:
4835 printf (_(" Set epilogue_begin to true\n"));
4838 case DW_LNS_set_isa
:
4839 READ_ULEB (uladv
, data
, end
);
4840 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4844 printf (_(" Unknown opcode %d with operands: "), op_code
);
4846 if (standard_opcodes
!= NULL
)
4847 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4849 READ_ULEB (uladv
, data
, end
);
4850 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4851 i
== 1 ? "" : ", ");
4866 unsigned char *name
;
4867 unsigned int directory_index
;
4868 unsigned int modification_date
;
4869 unsigned int length
;
4872 /* Output a decoded representation of the .debug_line section. */
4875 display_debug_lines_decoded (struct dwarf_section
* section
,
4876 unsigned char * start
,
4877 unsigned char * data
,
4878 unsigned char * end
,
4881 static DWARF2_Internal_LineInfo saved_linfo
;
4883 introduce (section
, false);
4887 /* This loop amounts to one iteration per compilation unit. */
4888 DWARF2_Internal_LineInfo linfo
;
4889 unsigned char *standard_opcodes
;
4890 unsigned char *end_of_sequence
;
4892 File_Entry
*file_table
= NULL
;
4893 unsigned int n_files
= 0;
4894 unsigned char **directory_table
= NULL
;
4895 dwarf_vma n_directories
= 0;
4897 if (startswith (section
->name
, ".debug_line.")
4898 /* Note: the following does not apply to .debug_line.dwo sections.
4899 These are full debug_line sections. */
4900 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4902 /* See comment in display_debug_lines_raw(). */
4903 end_of_sequence
= end
;
4904 standard_opcodes
= NULL
;
4905 linfo
= saved_linfo
;
4906 /* PR 17531: file: 0522b371. */
4907 if (linfo
.li_line_range
== 0)
4909 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4912 reset_state_machine (linfo
.li_default_is_stmt
);
4916 unsigned char *hdrptr
;
4918 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4919 & end_of_sequence
)) == NULL
)
4922 /* PR 17531: file: 0522b371. */
4923 if (linfo
.li_line_range
== 0)
4925 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4926 linfo
.li_line_range
= 1;
4928 reset_state_machine (linfo
.li_default_is_stmt
);
4930 /* Save a pointer to the contents of the Opcodes table. */
4931 standard_opcodes
= hdrptr
;
4933 /* Traverse the Directory table just to count entries. */
4934 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4938 warn (_("opcode base of %d extends beyond end of section\n"),
4939 linfo
.li_opcode_base
);
4943 if (linfo
.li_version
>= 5)
4945 unsigned char *format_start
, format_count
, *format
;
4946 dwarf_vma formati
, entryi
;
4948 load_debug_section_with_follow (line_str
, fileptr
);
4950 /* Skip directories format. */
4951 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4952 if (do_checks
&& format_count
> 1)
4953 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4955 format_start
= data
;
4956 for (formati
= 0; formati
< format_count
; formati
++)
4958 SKIP_ULEB (data
, end
);
4959 SKIP_ULEB (data
, end
);
4962 READ_ULEB (n_directories
, data
, end
);
4965 warn (_("Corrupt directories list\n"));
4969 if (n_directories
== 0)
4970 directory_table
= NULL
;
4972 directory_table
= (unsigned char **)
4973 xmalloc (n_directories
* sizeof (unsigned char *));
4975 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4977 unsigned char **pathp
= &directory_table
[entryi
];
4979 format
= format_start
;
4980 for (formati
= 0; formati
< format_count
; formati
++)
4982 dwarf_vma content_type
, form
;
4985 READ_ULEB (content_type
, format
, end
);
4986 READ_ULEB (form
, format
, end
);
4989 warn (_("Corrupt directories list\n"));
4992 switch (content_type
)
4997 case DW_FORM_string
:
5000 case DW_FORM_line_strp
:
5001 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5003 /* Remove const by the cast. */
5004 *pathp
= (unsigned char *)
5005 fetch_indirect_line_string (uvalue
);
5010 data
= read_and_display_attr_value (0, form
, 0, start
,
5012 linfo
.li_offset_size
,
5019 warn (_("Corrupt directories list\n"));
5024 /* Skip files format. */
5025 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5026 if (do_checks
&& format_count
> 5)
5027 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5029 format_start
= data
;
5030 for (formati
= 0; formati
< format_count
; formati
++)
5032 SKIP_ULEB (data
, end
);
5033 SKIP_ULEB (data
, end
);
5036 READ_ULEB (n_files
, data
, end
);
5037 if (data
>= end
&& n_files
> 0)
5039 warn (_("Corrupt file name list\n"));
5046 file_table
= (File_Entry
*) xcalloc (1, n_files
5047 * sizeof (File_Entry
));
5049 for (entryi
= 0; entryi
< n_files
; entryi
++)
5051 File_Entry
*file
= &file_table
[entryi
];
5053 format
= format_start
;
5054 for (formati
= 0; formati
< format_count
; formati
++)
5056 dwarf_vma content_type
, form
;
5060 READ_ULEB (content_type
, format
, end
);
5061 READ_ULEB (form
, format
, end
);
5064 warn (_("Corrupt file name list\n"));
5067 switch (content_type
)
5072 case DW_FORM_string
:
5075 case DW_FORM_line_strp
:
5076 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5078 /* Remove const by the cast. */
5079 file
->name
= (unsigned char *)
5080 fetch_indirect_line_string (uvalue
);
5084 case DW_LNCT_directory_index
:
5088 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5092 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5097 READ_ULEB (file
->directory_index
, tmp
, end
);
5102 data
= read_and_display_attr_value (0, form
, 0, start
,
5104 linfo
.li_offset_size
,
5111 warn (_("Corrupt file name list\n"));
5120 unsigned char *ptr_directory_table
= data
;
5122 while (data
< end
&& *data
!= 0)
5124 data
+= strnlen ((char *) data
, end
- data
);
5133 warn (_("directory table ends unexpectedly\n"));
5138 /* Go through the directory table again to save the directories. */
5139 directory_table
= (unsigned char **)
5140 xmalloc (n_directories
* sizeof (unsigned char *));
5143 while (*ptr_directory_table
!= 0)
5145 directory_table
[i
] = ptr_directory_table
;
5147 += strlen ((char *) ptr_directory_table
) + 1;
5151 /* Skip the NUL at the end of the table. */
5154 /* Traverse the File Name table just to count the entries. */
5155 if (data
< end
&& *data
!= 0)
5157 unsigned char *ptr_file_name_table
= data
;
5159 while (data
< end
&& *data
!= 0)
5161 /* Skip Name, directory index, last modification
5162 time and length of file. */
5163 data
+= strnlen ((char *) data
, end
- data
);
5166 SKIP_ULEB (data
, end
);
5167 SKIP_ULEB (data
, end
);
5168 SKIP_ULEB (data
, end
);
5174 warn (_("file table ends unexpectedly\n"));
5179 /* Go through the file table again to save the strings. */
5180 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5183 while (*ptr_file_name_table
!= 0)
5185 file_table
[i
].name
= ptr_file_name_table
;
5187 += strlen ((char *) ptr_file_name_table
) + 1;
5189 /* We are not interested in directory, time or size. */
5190 READ_ULEB (file_table
[i
].directory_index
,
5191 ptr_file_name_table
, end
);
5192 READ_ULEB (file_table
[i
].modification_date
,
5193 ptr_file_name_table
, end
);
5194 READ_ULEB (file_table
[i
].length
,
5195 ptr_file_name_table
, end
);
5201 /* Skip the NUL at the end of the table. */
5205 /* Print the Compilation Unit's name and a header. */
5206 if (file_table
== NULL
)
5207 printf (_("CU: No directory table\n"));
5208 else if (directory_table
== NULL
)
5209 printf (_("CU: %s:\n"), file_table
[0].name
);
5212 unsigned int ix
= file_table
[0].directory_index
;
5213 const char *directory
;
5218 else if (n_directories
== 0)
5219 directory
= _("<unknown>");
5220 else if (ix
> n_directories
)
5222 warn (_("directory index %u > number of directories %s\n"),
5223 ix
, dwarf_vmatoa ("u", n_directories
));
5224 directory
= _("<corrupt>");
5227 directory
= (char *) directory_table
[ix
- 1];
5230 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5232 printf ("%s:\n", file_table
[0].name
);
5236 printf (_("File name Line number Starting address View Stmt\n"));
5238 printf (_("CU: Empty file name table\n"));
5239 saved_linfo
= linfo
;
5242 /* This loop iterates through the Dwarf Line Number Program. */
5243 while (data
< end_of_sequence
)
5245 unsigned char op_code
;
5248 unsigned long int uladv
;
5249 int is_special_opcode
= 0;
5254 if (op_code
>= linfo
.li_opcode_base
)
5256 op_code
-= linfo
.li_opcode_base
;
5257 uladv
= (op_code
/ linfo
.li_line_range
);
5258 if (linfo
.li_max_ops_per_insn
== 1)
5260 uladv
*= linfo
.li_min_insn_length
;
5261 state_machine_regs
.address
+= uladv
;
5263 state_machine_regs
.view
= 0;
5268 = ((state_machine_regs
.op_index
+ uladv
)
5269 / linfo
.li_max_ops_per_insn
)
5270 * linfo
.li_min_insn_length
;
5271 state_machine_regs
.address
5273 state_machine_regs
.op_index
5274 = (state_machine_regs
.op_index
+ uladv
)
5275 % linfo
.li_max_ops_per_insn
;
5277 state_machine_regs
.view
= 0;
5280 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5281 state_machine_regs
.line
+= adv
;
5282 is_special_opcode
= 1;
5283 /* Increment view after printing this row. */
5288 case DW_LNS_extended_op
:
5290 unsigned int ext_op_code_len
;
5291 unsigned char ext_op_code
;
5292 unsigned char *op_code_end
;
5293 unsigned char *op_code_data
= data
;
5295 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5296 op_code_end
= op_code_data
+ ext_op_code_len
;
5297 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5299 warn (_("Badly formed extended line op encountered!\n"));
5302 ext_op_code
= *op_code_data
++;
5306 switch (ext_op_code
)
5308 case DW_LNE_end_sequence
:
5309 /* Reset stuff after printing this row. */
5311 case DW_LNE_set_address
:
5312 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5314 op_code_end
- op_code_data
,
5316 state_machine_regs
.op_index
= 0;
5317 state_machine_regs
.view
= 0;
5319 case DW_LNE_define_file
:
5320 file_table
= (File_Entry
*) xrealloc
5321 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5323 ++state_machine_regs
.last_file_entry
;
5324 /* Source file name. */
5325 file_table
[n_files
].name
= op_code_data
;
5326 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5327 /* Directory index. */
5328 READ_ULEB (file_table
[n_files
].directory_index
,
5329 op_code_data
, op_code_end
);
5330 /* Last modification time. */
5331 READ_ULEB (file_table
[n_files
].modification_date
,
5332 op_code_data
, op_code_end
);
5334 READ_ULEB (file_table
[n_files
].length
,
5335 op_code_data
, op_code_end
);
5339 case DW_LNE_set_discriminator
:
5340 case DW_LNE_HP_set_sequence
:
5341 /* Simply ignored. */
5345 printf (_("UNKNOWN (%u): length %ld\n"),
5346 ext_op_code
, (long int) (op_code_data
- data
));
5353 /* Increment view after printing this row. */
5356 case DW_LNS_advance_pc
:
5357 READ_ULEB (uladv
, data
, end
);
5358 if (linfo
.li_max_ops_per_insn
== 1)
5360 uladv
*= linfo
.li_min_insn_length
;
5361 state_machine_regs
.address
+= uladv
;
5363 state_machine_regs
.view
= 0;
5368 = ((state_machine_regs
.op_index
+ uladv
)
5369 / linfo
.li_max_ops_per_insn
)
5370 * linfo
.li_min_insn_length
;
5371 state_machine_regs
.address
5373 state_machine_regs
.op_index
5374 = (state_machine_regs
.op_index
+ uladv
)
5375 % linfo
.li_max_ops_per_insn
;
5377 state_machine_regs
.view
= 0;
5381 case DW_LNS_advance_line
:
5382 READ_SLEB (adv
, data
, end
);
5383 state_machine_regs
.line
+= adv
;
5386 case DW_LNS_set_file
:
5387 READ_ULEB (uladv
, data
, end
);
5388 state_machine_regs
.file
= uladv
;
5391 unsigned file
= state_machine_regs
.file
;
5394 if (linfo
.li_version
< 5)
5396 if (file_table
== NULL
|| n_files
== 0)
5397 printf (_("\n [Use file table entry %d]\n"), file
);
5399 else if (file
>= n_files
)
5401 warn (_("file index %u > number of files %u\n"), file
, n_files
);
5402 printf (_("\n <over large file table index %u>"), file
);
5404 else if ((dir
= file_table
[file
].directory_index
) == 0)
5405 /* If directory index is 0, that means current directory. */
5406 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5407 else if (directory_table
== NULL
|| n_directories
== 0)
5408 printf (_("\n [Use file %s in directory table entry %d]\n"),
5409 file_table
[file
].name
, dir
);
5411 else if (dir
> n_directories
)
5413 warn (_("directory index %u > number of directories %s\n"),
5414 dir
, dwarf_vmatoa ("u", n_directories
));
5415 printf (_("\n <over large directory table entry %u>\n"), dir
);
5418 printf ("\n%s/%s:\n",
5419 /* The directory index starts counting at 1. */
5420 directory_table
[dir
- 1], file_table
[file
].name
);
5424 case DW_LNS_set_column
:
5425 READ_ULEB (uladv
, data
, end
);
5426 state_machine_regs
.column
= uladv
;
5429 case DW_LNS_negate_stmt
:
5430 adv
= state_machine_regs
.is_stmt
;
5432 state_machine_regs
.is_stmt
= adv
;
5435 case DW_LNS_set_basic_block
:
5436 state_machine_regs
.basic_block
= 1;
5439 case DW_LNS_const_add_pc
:
5440 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5441 if (linfo
.li_max_ops_per_insn
== 1)
5443 uladv
*= linfo
.li_min_insn_length
;
5444 state_machine_regs
.address
+= uladv
;
5446 state_machine_regs
.view
= 0;
5451 = ((state_machine_regs
.op_index
+ uladv
)
5452 / linfo
.li_max_ops_per_insn
)
5453 * linfo
.li_min_insn_length
;
5454 state_machine_regs
.address
5456 state_machine_regs
.op_index
5457 = (state_machine_regs
.op_index
+ uladv
)
5458 % linfo
.li_max_ops_per_insn
;
5460 state_machine_regs
.view
= 0;
5464 case DW_LNS_fixed_advance_pc
:
5465 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5466 state_machine_regs
.address
+= uladv
;
5467 state_machine_regs
.op_index
= 0;
5468 /* Do NOT reset view. */
5471 case DW_LNS_set_prologue_end
:
5474 case DW_LNS_set_epilogue_begin
:
5477 case DW_LNS_set_isa
:
5478 READ_ULEB (uladv
, data
, end
);
5479 printf (_(" Set ISA to %lu\n"), uladv
);
5483 printf (_(" Unknown opcode %d with operands: "), op_code
);
5485 if (standard_opcodes
!= NULL
)
5486 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5490 READ_ULEB (val
, data
, end
);
5491 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5492 i
== 1 ? "" : ", ");
5498 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5499 to the DWARF address/line matrix. */
5500 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5501 || (xop
== DW_LNS_copy
))
5503 const unsigned int MAX_FILENAME_LENGTH
= 35;
5505 char *newFileName
= NULL
;
5506 size_t fileNameLength
;
5510 unsigned indx
= state_machine_regs
.file
;
5512 if (linfo
.li_version
< 5)
5515 if (indx
>= n_files
)
5517 warn (_("corrupt file index %u encountered\n"), indx
);
5518 fileName
= _("<corrupt>");
5521 fileName
= (char *) file_table
[indx
].name
;
5524 fileName
= _("<unknown>");
5526 fileNameLength
= strlen (fileName
);
5527 newFileName
= fileName
;
5528 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5530 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5531 /* Truncate file name */
5532 memcpy (newFileName
,
5533 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5534 MAX_FILENAME_LENGTH
);
5535 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5538 /* A row with end_seq set to true has a meaningful address, but
5539 the other information in the same row is not significant.
5540 In such a row, print line as "-", and don't print
5542 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5544 if (linfo
.li_max_ops_per_insn
== 1)
5546 if (xop
== -DW_LNE_end_sequence
)
5547 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5549 state_machine_regs
.address
);
5551 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5552 newFileName
, state_machine_regs
.line
,
5553 state_machine_regs
.address
);
5557 if (xop
== -DW_LNE_end_sequence
)
5558 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5560 state_machine_regs
.address
,
5561 state_machine_regs
.op_index
);
5563 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5564 newFileName
, state_machine_regs
.line
,
5565 state_machine_regs
.address
,
5566 state_machine_regs
.op_index
);
5571 if (linfo
.li_max_ops_per_insn
== 1)
5573 if (xop
== -DW_LNE_end_sequence
)
5574 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5576 state_machine_regs
.address
);
5578 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5579 newFileName
, state_machine_regs
.line
,
5580 state_machine_regs
.address
);
5584 if (xop
== -DW_LNE_end_sequence
)
5585 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5587 state_machine_regs
.address
,
5588 state_machine_regs
.op_index
);
5590 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5591 newFileName
, state_machine_regs
.line
,
5592 state_machine_regs
.address
,
5593 state_machine_regs
.op_index
);
5597 if (xop
!= -DW_LNE_end_sequence
)
5599 if (state_machine_regs
.view
)
5600 printf (" %6u", state_machine_regs
.view
);
5604 if (state_machine_regs
.is_stmt
)
5609 state_machine_regs
.view
++;
5611 if (xop
== -DW_LNE_end_sequence
)
5613 reset_state_machine (linfo
.li_default_is_stmt
);
5617 if (newFileName
!= fileName
)
5629 if (directory_table
)
5631 free (directory_table
);
5632 directory_table
= NULL
;
5643 display_debug_lines (struct dwarf_section
*section
, void *file
)
5645 unsigned char *data
= section
->start
;
5646 unsigned char *end
= data
+ section
->size
;
5648 int retValDecoded
= 1;
5650 if (do_debug_lines
== 0)
5651 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5653 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5654 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5656 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5657 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5659 if (!retValRaw
|| !retValDecoded
)
5666 find_debug_info_for_offset (dwarf_vma offset
)
5670 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5673 for (i
= 0; i
< num_debug_info_entries
; i
++)
5674 if (debug_information
[i
].cu_offset
== offset
)
5675 return debug_information
+ i
;
5681 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5683 /* See gdb/gdb-index.h. */
5684 static const char * const kinds
[] =
5696 return _ (kinds
[kind
]);
5700 display_debug_pubnames_worker (struct dwarf_section
*section
,
5701 void *file ATTRIBUTE_UNUSED
,
5704 DWARF2_Internal_PubNames names
;
5705 unsigned char *start
= section
->start
;
5706 unsigned char *end
= start
+ section
->size
;
5708 /* It does not matter if this load fails,
5709 we test for that later on. */
5710 load_debug_info (file
);
5712 introduce (section
, false);
5716 unsigned char *data
;
5717 unsigned long sec_off
= start
- section
->start
;
5718 unsigned int offset_size
;
5720 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5721 if (names
.pn_length
== 0xffffffff)
5723 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5729 if (names
.pn_length
> (size_t) (end
- start
))
5731 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5734 dwarf_vmatoa ("x", names
.pn_length
));
5739 start
+= names
.pn_length
;
5741 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5742 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5744 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5745 && num_debug_info_entries
> 0
5746 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5747 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5748 (unsigned long) names
.pn_offset
, section
->name
);
5750 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5752 printf (_(" Length: %ld\n"),
5753 (long) names
.pn_length
);
5754 printf (_(" Version: %d\n"),
5756 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5757 (unsigned long) names
.pn_offset
);
5758 printf (_(" Size of area in .debug_info section: %ld\n"),
5759 (long) names
.pn_size
);
5761 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5763 static int warned
= 0;
5767 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5775 printf (_("\n Offset Kind Name\n"));
5777 printf (_("\n Offset\tName\n"));
5781 bfd_size_type maxprint
;
5784 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5791 maxprint
= (start
- data
) - 1;
5795 unsigned int kind_data
;
5796 gdb_index_symbol_kind kind
;
5797 const char *kind_name
;
5800 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5802 /* GCC computes the kind as the upper byte in the CU index
5803 word, and then right shifts it by the CU index size.
5804 Left shift KIND to where the gdb-index.h accessor macros
5806 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5807 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5808 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5809 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5810 printf (" %-6lx %s,%-10s %.*s\n",
5811 (unsigned long) offset
, is_static
? _("s") : _("g"),
5812 kind_name
, (int) maxprint
, data
);
5815 printf (" %-6lx\t%.*s\n",
5816 (unsigned long) offset
, (int) maxprint
, data
);
5818 data
+= strnlen ((char *) data
, maxprint
);
5831 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5833 return display_debug_pubnames_worker (section
, file
, 0);
5837 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5839 return display_debug_pubnames_worker (section
, file
, 1);
5843 display_debug_macinfo (struct dwarf_section
*section
,
5844 void *file ATTRIBUTE_UNUSED
)
5846 unsigned char *start
= section
->start
;
5847 unsigned char *end
= start
+ section
->size
;
5848 unsigned char *curr
= start
;
5849 enum dwarf_macinfo_record_type op
;
5851 introduce (section
, false);
5855 unsigned int lineno
;
5856 const unsigned char *string
;
5858 op
= (enum dwarf_macinfo_record_type
) *curr
;
5863 case DW_MACINFO_start_file
:
5865 unsigned int filenum
;
5867 READ_ULEB (lineno
, curr
, end
);
5868 READ_ULEB (filenum
, curr
, end
);
5869 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5874 case DW_MACINFO_end_file
:
5875 printf (_(" DW_MACINFO_end_file\n"));
5878 case DW_MACINFO_define
:
5879 READ_ULEB (lineno
, curr
, end
);
5881 curr
+= strnlen ((char *) string
, end
- string
);
5882 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5883 lineno
, (int) (curr
- string
), string
);
5888 case DW_MACINFO_undef
:
5889 READ_ULEB (lineno
, curr
, end
);
5891 curr
+= strnlen ((char *) string
, end
- string
);
5892 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5893 lineno
, (int) (curr
- string
), string
);
5898 case DW_MACINFO_vendor_ext
:
5900 unsigned int constant
;
5902 READ_ULEB (constant
, curr
, end
);
5904 curr
+= strnlen ((char *) string
, end
- string
);
5905 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5906 constant
, (int) (curr
- string
), string
);
5917 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5918 filename and dirname corresponding to file name table entry with index
5919 FILEIDX. Return NULL on failure. */
5921 static unsigned char *
5922 get_line_filename_and_dirname (dwarf_vma line_offset
,
5924 unsigned char **dir_name
)
5926 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5927 unsigned char *hdrptr
, *dirtable
, *file_name
;
5928 unsigned int offset_size
;
5929 unsigned int version
, opcode_base
;
5930 dwarf_vma length
, diridx
;
5931 const unsigned char * end
;
5934 if (section
->start
== NULL
5935 || line_offset
>= section
->size
5939 hdrptr
= section
->start
+ line_offset
;
5940 end
= section
->start
+ section
->size
;
5942 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5943 if (length
== 0xffffffff)
5945 /* This section is 64-bit DWARF 3. */
5946 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5952 if (length
> (size_t) (end
- hdrptr
)
5953 || length
< 2 + offset_size
+ 1 + 3 + 1)
5955 end
= hdrptr
+ length
;
5957 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5958 if (version
!= 2 && version
!= 3 && version
!= 4)
5960 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5962 hdrptr
++; /* Skip max_ops_per_insn. */
5963 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5965 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5966 if (opcode_base
== 0
5967 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
5970 hdrptr
+= opcode_base
- 1;
5973 /* Skip over dirname table. */
5974 while (*hdrptr
!= '\0')
5976 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5982 hdrptr
++; /* Skip the NUL at the end of the table. */
5984 /* Now skip over preceding filename table entries. */
5985 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5987 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5990 SKIP_ULEB (hdrptr
, end
);
5991 SKIP_ULEB (hdrptr
, end
);
5992 SKIP_ULEB (hdrptr
, end
);
5994 if (hdrptr
>= end
|| *hdrptr
== '\0')
5998 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6003 READ_ULEB (diridx
, hdrptr
, end
);
6006 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6008 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6012 if (dirtable
>= end
|| *dirtable
== '\0')
6014 *dir_name
= dirtable
;
6019 display_debug_macro (struct dwarf_section
*section
,
6022 unsigned char *start
= section
->start
;
6023 unsigned char *end
= start
+ section
->size
;
6024 unsigned char *curr
= start
;
6025 unsigned char *extended_op_buf
[256];
6026 bool is_dwo
= false;
6027 const char *suffix
= strrchr (section
->name
, '.');
6029 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6032 load_debug_section_with_follow (str
, file
);
6033 load_debug_section_with_follow (line
, file
);
6034 load_debug_section_with_follow (str_index
, file
);
6036 introduce (section
, false);
6040 unsigned int lineno
, version
, flags
;
6041 unsigned int offset_size
;
6042 const unsigned char *string
;
6043 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
6044 unsigned char **extended_ops
= NULL
;
6046 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6047 if (version
!= 4 && version
!= 5)
6049 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6050 section
->name
, version
);
6054 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6055 offset_size
= (flags
& 1) ? 8 : 4;
6056 printf (_(" Offset: 0x%lx\n"),
6057 (unsigned long) sec_offset
);
6058 printf (_(" Version: %d\n"), version
);
6059 printf (_(" Offset size: %d\n"), offset_size
);
6062 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6063 printf (_(" Offset into .debug_line: 0x%lx\n"),
6064 (unsigned long) line_offset
);
6068 unsigned int i
, count
, op
;
6071 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6073 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6074 extended_ops
= extended_op_buf
;
6077 printf (_(" Extension opcode arguments:\n"));
6078 for (i
= 0; i
< count
; i
++)
6080 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6081 extended_ops
[op
] = curr
;
6082 READ_ULEB (nargs
, curr
, end
);
6084 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6087 printf (_(" DW_MACRO_%02x arguments: "), op
);
6088 for (n
= 0; n
< nargs
; n
++)
6092 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6093 printf ("%s%s", get_FORM_name (form
),
6094 n
== nargs
- 1 ? "\n" : ", ");
6104 case DW_FORM_block1
:
6105 case DW_FORM_block2
:
6106 case DW_FORM_block4
:
6108 case DW_FORM_string
:
6110 case DW_FORM_sec_offset
:
6113 error (_("Invalid extension opcode form %s\n"),
6114 get_FORM_name (form
));
6130 error (_(".debug_macro section not zero terminated\n"));
6134 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6140 case DW_MACRO_define
:
6141 READ_ULEB (lineno
, curr
, end
);
6143 curr
+= strnlen ((char *) string
, end
- string
);
6144 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6145 lineno
, (int) (curr
- string
), string
);
6150 case DW_MACRO_undef
:
6151 READ_ULEB (lineno
, curr
, end
);
6153 curr
+= strnlen ((char *) string
, end
- string
);
6154 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6155 lineno
, (int) (curr
- string
), string
);
6160 case DW_MACRO_start_file
:
6162 unsigned int filenum
;
6163 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6165 READ_ULEB (lineno
, curr
, end
);
6166 READ_ULEB (filenum
, curr
, end
);
6168 if ((flags
& 2) == 0)
6169 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6172 = get_line_filename_and_dirname (line_offset
, filenum
,
6174 if (file_name
== NULL
)
6175 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6178 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6180 dir_name
!= NULL
? (const char *) dir_name
: "",
6181 dir_name
!= NULL
? "/" : "", file_name
);
6185 case DW_MACRO_end_file
:
6186 printf (_(" DW_MACRO_end_file\n"));
6189 case DW_MACRO_define_strp
:
6190 READ_ULEB (lineno
, curr
, end
);
6191 if (version
== 4 && is_dwo
)
6192 READ_ULEB (offset
, curr
, end
);
6194 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6195 string
= fetch_indirect_string (offset
);
6196 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6200 case DW_MACRO_undef_strp
:
6201 READ_ULEB (lineno
, curr
, end
);
6202 if (version
== 4 && is_dwo
)
6203 READ_ULEB (offset
, curr
, end
);
6205 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6206 string
= fetch_indirect_string (offset
);
6207 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6211 case DW_MACRO_import
:
6212 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6213 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6214 (unsigned long) offset
);
6217 case DW_MACRO_define_sup
:
6218 READ_ULEB (lineno
, curr
, end
);
6219 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6220 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6221 lineno
, (unsigned long) offset
);
6224 case DW_MACRO_undef_sup
:
6225 READ_ULEB (lineno
, curr
, end
);
6226 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6227 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6228 lineno
, (unsigned long) offset
);
6231 case DW_MACRO_import_sup
:
6232 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6233 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6234 (unsigned long) offset
);
6237 case DW_MACRO_define_strx
:
6238 case DW_MACRO_undef_strx
:
6239 READ_ULEB (lineno
, curr
, end
);
6240 READ_ULEB (offset
, curr
, end
);
6241 string
= (const unsigned char *)
6242 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6243 if (op
== DW_MACRO_define_strx
)
6244 printf (" DW_MACRO_define_strx ");
6246 printf (" DW_MACRO_undef_strx ");
6248 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6249 printf (_("lineno : %d macro : %s\n"),
6254 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6256 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6260 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6262 error (_(" Unknown macro opcode %02x seen\n"), op
);
6267 /* Skip over unhandled opcodes. */
6269 unsigned char *desc
= extended_ops
[op
];
6270 READ_ULEB (nargs
, desc
, end
);
6273 printf (_(" DW_MACRO_%02x\n"), op
);
6276 printf (_(" DW_MACRO_%02x -"), op
);
6277 for (n
= 0; n
< nargs
; n
++)
6281 /* DW_FORM_implicit_const is not expected here. */
6282 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6284 = read_and_display_attr_value (0, val
, 0,
6285 start
, curr
, end
, 0, 0,
6286 offset_size
, version
,
6305 display_debug_abbrev (struct dwarf_section
*section
,
6306 void *file ATTRIBUTE_UNUSED
)
6308 abbrev_entry
*entry
;
6309 unsigned char *start
= section
->start
;
6311 introduce (section
, false);
6318 offset
= start
- section
->start
;
6319 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6322 list
= new_abbrev_list (0, offset
);
6323 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6324 list
->start_of_next_abbrevs
= start
;
6327 start
= list
->start_of_next_abbrevs
;
6329 if (list
->first_abbrev
== NULL
)
6332 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6334 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6338 printf (" %ld %s [%s]\n",
6340 get_TAG_name (entry
->tag
),
6341 entry
->children
? _("has children") : _("no children"));
6343 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6345 printf (" %-18s %s",
6346 get_AT_name (attr
->attribute
),
6347 get_FORM_name (attr
->form
));
6348 if (attr
->form
== DW_FORM_implicit_const
)
6349 printf (": %s", dwarf_vmatoa ("d", attr
->implicit_const
));
6361 /* Return true when ADDR is the maximum address, when addresses are
6362 POINTER_SIZE bytes long. */
6365 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6367 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6368 return ((addr
& mask
) == mask
);
6371 /* Display a view pair list starting at *VSTART_PTR and ending at
6372 VLISTEND within SECTION. */
6375 display_view_pair_list (struct dwarf_section
*section
,
6376 unsigned char **vstart_ptr
,
6377 unsigned int debug_info_entry
,
6378 unsigned char *vlistend
)
6380 unsigned char *vstart
= *vstart_ptr
;
6381 unsigned char *section_end
= section
->start
+ section
->size
;
6382 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6384 if (vlistend
< section_end
)
6385 section_end
= vlistend
;
6389 while (vstart
< section_end
)
6391 dwarf_vma off
= vstart
- section
->start
;
6392 dwarf_vma vbegin
, vend
;
6394 READ_ULEB (vbegin
, vstart
, section_end
);
6395 if (vstart
== section_end
)
6398 READ_ULEB (vend
, vstart
, section_end
);
6399 printf (" %8.8lx ", (unsigned long) off
);
6401 print_dwarf_view (vbegin
, pointer_size
, 1);
6402 print_dwarf_view (vend
, pointer_size
, 1);
6403 printf (_("location view pair\n"));
6407 *vstart_ptr
= vstart
;
6410 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6413 display_loc_list (struct dwarf_section
*section
,
6414 unsigned char **start_ptr
,
6415 unsigned int debug_info_entry
,
6417 dwarf_vma base_address
,
6418 unsigned char **vstart_ptr
,
6421 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6422 unsigned char *section_end
= section
->start
+ section
->size
;
6423 dwarf_vma cu_offset
;
6424 unsigned int pointer_size
;
6425 unsigned int offset_size
;
6429 unsigned short length
;
6430 int need_frame_base
;
6432 if (debug_info_entry
>= num_debug_info_entries
)
6434 warn (_("No debug information available for loc lists of entry: %u\n"),
6439 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6440 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6441 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6442 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6444 if (pointer_size
< 2 || pointer_size
> 8)
6446 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6447 pointer_size
, debug_info_entry
);
6453 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6454 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6456 if (2 * pointer_size
> (size_t) (section_end
- start
))
6458 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6459 (unsigned long) offset
);
6464 print_dwarf_vma (off
, 4);
6466 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6467 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6469 if (begin
== 0 && end
== 0)
6471 /* PR 18374: In a object file we can have a location list that
6472 starts with a begin and end of 0 because there are relocations
6473 that need to be applied to the addresses. Actually applying
6474 the relocations now does not help as they will probably resolve
6475 to 0, since the object file has not been fully linked. Real
6476 end of list markers will not have any relocations against them. */
6477 if (! reloc_at (section
, off
)
6478 && ! reloc_at (section
, off
+ pointer_size
))
6480 printf (_("<End of list>\n"));
6485 /* Check base address specifiers. */
6486 if (is_max_address (begin
, pointer_size
)
6487 && !is_max_address (end
, pointer_size
))
6490 print_dwarf_vma (begin
, pointer_size
);
6491 print_dwarf_vma (end
, pointer_size
);
6492 printf (_("(base address)\n"));
6498 off
= offset
+ (vstart
- *start_ptr
);
6500 READ_ULEB (vbegin
, vstart
, section_end
);
6501 print_dwarf_view (vbegin
, pointer_size
, 1);
6503 READ_ULEB (vend
, vstart
, section_end
);
6504 print_dwarf_view (vend
, pointer_size
, 1);
6506 printf (_("views at %8.8lx for:\n %*s "),
6507 (unsigned long) off
, 8, "");
6510 if (2 > (size_t) (section_end
- start
))
6512 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6513 (unsigned long) offset
);
6517 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6519 if (length
> (size_t) (section_end
- start
))
6521 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6522 (unsigned long) offset
);
6526 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6527 print_dwarf_vma (end
+ base_address
, pointer_size
);
6530 need_frame_base
= decode_location_expression (start
,
6535 cu_offset
, section
);
6538 if (need_frame_base
&& !has_frame_base
)
6539 printf (_(" [without DW_AT_frame_base]"));
6541 if (begin
== end
&& vbegin
== vend
)
6542 fputs (_(" (start == end)"), stdout
);
6543 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6544 fputs (_(" (start > end)"), stdout
);
6552 *vstart_ptr
= vstart
;
6555 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6558 display_loclists_list (struct dwarf_section
* section
,
6559 unsigned char ** start_ptr
,
6560 unsigned int debug_info_entry
,
6562 dwarf_vma base_address
,
6563 unsigned char ** vstart_ptr
,
6566 unsigned char * start
= *start_ptr
;
6567 unsigned char * vstart
= *vstart_ptr
;
6568 unsigned char * section_end
= section
->start
+ section
->size
;
6569 dwarf_vma cu_offset
;
6570 unsigned int pointer_size
;
6571 unsigned int offset_size
;
6572 unsigned int dwarf_version
;
6574 /* Initialize it due to a false compiler warning. */
6575 dwarf_vma begin
= -1, vbegin
= -1;
6576 dwarf_vma end
= -1, vend
= -1;
6578 int need_frame_base
;
6580 if (debug_info_entry
>= num_debug_info_entries
)
6582 warn (_("No debug information available for "
6583 "loclists lists of entry: %u\n"),
6588 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6589 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6590 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6591 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6593 if (pointer_size
< 2 || pointer_size
> 8)
6595 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6596 pointer_size
, debug_info_entry
);
6602 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6603 enum dwarf_location_list_entry_type llet
;
6605 if (start
+ 1 > section_end
)
6607 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6608 (unsigned long) offset
);
6613 print_dwarf_vma (off
, 4);
6615 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6617 if (vstart
&& (llet
== DW_LLE_offset_pair
6618 || llet
== DW_LLE_start_end
6619 || llet
== DW_LLE_start_length
))
6621 off
= offset
+ (vstart
- *start_ptr
);
6623 READ_ULEB (vbegin
, vstart
, section_end
);
6624 print_dwarf_view (vbegin
, pointer_size
, 1);
6626 READ_ULEB (vend
, vstart
, section_end
);
6627 print_dwarf_view (vend
, pointer_size
, 1);
6629 printf (_("views at %8.8lx for:\n %*s "),
6630 (unsigned long) off
, 8, "");
6635 case DW_LLE_end_of_list
:
6636 printf (_("<End of list>\n"));
6639 case DW_LLE_base_addressx
:
6640 READ_ULEB (base_address
, start
, section_end
);
6641 print_dwarf_vma (base_address
, pointer_size
);
6642 printf (_("(index into .debug_addr) "));
6643 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6644 print_dwarf_vma (base_address
, pointer_size
);
6645 printf (_("(base address)\n"));
6648 case DW_LLE_startx_endx
:
6649 READ_ULEB (begin
, start
, section_end
);
6650 begin
= fetch_indexed_addr (begin
, pointer_size
);
6651 READ_ULEB (end
, start
, section_end
);
6652 end
= fetch_indexed_addr (end
, pointer_size
);
6655 case DW_LLE_startx_length
:
6656 READ_ULEB (begin
, start
, section_end
);
6657 begin
= fetch_indexed_addr (begin
, pointer_size
);
6658 READ_ULEB (end
, start
, section_end
);
6662 case DW_LLE_default_location
:
6666 case DW_LLE_offset_pair
:
6667 READ_ULEB (begin
, start
, section_end
);
6668 begin
+= base_address
;
6669 READ_ULEB (end
, start
, section_end
);
6670 end
+= base_address
;
6673 case DW_LLE_base_address
:
6674 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6676 print_dwarf_vma (base_address
, pointer_size
);
6677 printf (_("(base address)\n"));
6680 case DW_LLE_start_end
:
6681 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6682 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6685 case DW_LLE_start_length
:
6686 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6687 READ_ULEB (end
, start
, section_end
);
6691 #ifdef DW_LLE_view_pair
6692 case DW_LLE_view_pair
:
6694 printf (_("View pair entry in loclist with locviews attribute\n"));
6695 READ_ULEB (vbegin
, start
, section_end
);
6696 print_dwarf_view (vbegin
, pointer_size
, 1);
6698 READ_ULEB (vend
, start
, section_end
);
6699 print_dwarf_view (vend
, pointer_size
, 1);
6701 printf (_("views for:\n"));
6706 error (_("Invalid location list entry type %d\n"), llet
);
6710 if (llet
== DW_LLE_end_of_list
)
6713 if (llet
== DW_LLE_base_address
6714 || llet
== DW_LLE_base_addressx
)
6717 if (start
== section_end
)
6719 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6720 (unsigned long) offset
);
6723 READ_ULEB (length
, start
, section_end
);
6725 if (length
> (size_t) (section_end
- start
))
6727 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6728 (unsigned long) offset
);
6732 print_dwarf_vma (begin
, pointer_size
);
6733 print_dwarf_vma (end
, pointer_size
);
6736 need_frame_base
= decode_location_expression (start
,
6741 cu_offset
, section
);
6744 if (need_frame_base
&& !has_frame_base
)
6745 printf (_(" [without DW_AT_frame_base]"));
6747 if (begin
== end
&& vbegin
== vend
)
6748 fputs (_(" (start == end)"), stdout
);
6749 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6750 fputs (_(" (start > end)"), stdout
);
6758 if (vbegin
!= vm1
|| vend
!= vm1
)
6759 printf (_("Trailing view pair not used in a range"));
6762 *vstart_ptr
= vstart
;
6765 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6766 right-adjusted in a field of length LEN, and followed by a space. */
6769 print_addr_index (unsigned int idx
, unsigned int len
)
6771 static char buf
[15];
6772 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6773 printf ("%*s ", len
, buf
);
6776 /* Display a location list from a .dwo section. It uses address indexes rather
6777 than embedded addresses. This code closely follows display_loc_list, but the
6778 two are sufficiently different that combining things is very ugly. */
6781 display_loc_list_dwo (struct dwarf_section
*section
,
6782 unsigned char **start_ptr
,
6783 unsigned int debug_info_entry
,
6785 unsigned char **vstart_ptr
,
6788 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6789 unsigned char *section_end
= section
->start
+ section
->size
;
6790 dwarf_vma cu_offset
;
6791 unsigned int pointer_size
;
6792 unsigned int offset_size
;
6795 unsigned short length
;
6796 int need_frame_base
;
6799 if (debug_info_entry
>= num_debug_info_entries
)
6801 warn (_("No debug information for loc lists of entry: %u\n"),
6806 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6807 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6808 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6809 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6811 if (pointer_size
< 2 || pointer_size
> 8)
6813 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6814 pointer_size
, debug_info_entry
);
6821 print_dwarf_vma (offset
+ (start
- *start_ptr
), 4);
6823 if (start
>= section_end
)
6825 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6826 (unsigned long) offset
);
6830 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6843 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6845 READ_ULEB (view
, vstart
, section_end
);
6846 print_dwarf_view (view
, 8, 1);
6848 READ_ULEB (view
, vstart
, section_end
);
6849 print_dwarf_view (view
, 8, 1);
6851 printf (_("views at %8.8lx for:\n %*s "),
6852 (unsigned long) off
, 8, "");
6860 case 0: /* A terminating entry. */
6862 *vstart_ptr
= vstart
;
6863 printf (_("<End of list>\n"));
6865 case 1: /* A base-address entry. */
6866 READ_ULEB (idx
, start
, section_end
);
6867 print_addr_index (idx
, 8);
6868 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6869 printf (_("(base address selection entry)\n"));
6871 case 2: /* A start/end entry. */
6872 READ_ULEB (idx
, start
, section_end
);
6873 print_addr_index (idx
, 8);
6874 READ_ULEB (idx
, start
, section_end
);
6875 print_addr_index (idx
, 8);
6877 case 3: /* A start/length entry. */
6878 READ_ULEB (idx
, start
, section_end
);
6879 print_addr_index (idx
, 8);
6880 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6881 printf ("%08x ", idx
);
6883 case 4: /* An offset pair entry. */
6884 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6885 printf ("%08x ", idx
);
6886 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6887 printf ("%08x ", idx
);
6890 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6892 *vstart_ptr
= vstart
;
6896 if (2 > (size_t) (section_end
- start
))
6898 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6899 (unsigned long) offset
);
6903 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6904 if (length
> (size_t) (section_end
- start
))
6906 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6907 (unsigned long) offset
);
6912 need_frame_base
= decode_location_expression (start
,
6917 cu_offset
, section
);
6920 if (need_frame_base
&& !has_frame_base
)
6921 printf (_(" [without DW_AT_frame_base]"));
6929 *vstart_ptr
= vstart
;
6932 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6935 static dwarf_vma
*loc_offsets
, *loc_views
;
6938 loc_offsets_compar (const void *ap
, const void *bp
)
6940 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6941 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6943 int ret
= (a
> b
) - (b
> a
);
6947 a
= loc_views
[*(const unsigned int *) ap
];
6948 b
= loc_views
[*(const unsigned int *) bp
];
6950 ret
= (a
> b
) - (b
> a
);
6956 display_offset_entry_loclists (struct dwarf_section
*section
)
6958 unsigned char * start
= section
->start
;
6959 unsigned char * const end
= start
+ section
->size
;
6961 introduce (section
, false);
6966 unsigned short version
;
6967 unsigned char address_size
;
6968 unsigned char segment_selector_size
;
6969 uint32_t offset_entry_count
;
6973 printf (_("Table at Offset 0x%lx\n"), (long)(start
- section
->start
));
6975 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
6976 if (length
== 0xffffffff)
6979 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
6984 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
6985 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
6986 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
6987 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
6989 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", length
));
6990 printf (_(" DWARF version: %u\n"), version
);
6991 printf (_(" Address size: %u\n"), address_size
);
6992 printf (_(" Segment size: %u\n"), segment_selector_size
);
6993 printf (_(" Offset entries: %u\n"), offset_entry_count
);
6997 warn (_("The %s section contains a corrupt or "
6998 "unsupported version number: %d.\n"),
6999 section
->name
, version
);
7003 if (segment_selector_size
!= 0)
7005 warn (_("The %s section contains an "
7006 "unsupported segment selector size: %d.\n"),
7007 section
->name
, segment_selector_size
);
7011 if (offset_entry_count
== 0)
7013 warn (_("The %s section contains a table without offset\n"),
7018 printf (_("\n Offset Entries starting at 0x%lx:\n"),
7019 (long)(start
- section
->start
));
7023 for (i
= 0; i
< offset_entry_count
; i
++)
7027 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, end
);
7028 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
7033 for (i
= 0; i
< offset_entry_count
; i
++)
7037 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, end
);
7038 printf (_(" [%6u] 0x%x\n"), i
, entry
);
7046 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7049 dwarf_vma base_address
= 0;
7052 dwarf_vma off
= start
- section
->start
;
7056 printf (_(" Offset Entry %u\n"), i
);
7061 print_dwarf_vma (off
, 4);
7063 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7067 case DW_LLE_end_of_list
:
7068 printf (_("<End of list>\n\n"));
7072 case DW_LLE_base_addressx
:
7073 READ_ULEB (base_address
, start
, end
);
7074 print_dwarf_vma (base_address
, address_size
);
7075 printf (_("(index into .debug_addr) "));
7076 base_address
= fetch_indexed_addr (base_address
, address_size
);
7077 print_dwarf_vma (base_address
, address_size
);
7078 printf (_("(base address)\n"));
7081 case DW_LLE_startx_endx
:
7082 READ_ULEB (begin
, start
, end
);
7083 begin
= fetch_indexed_addr (begin
, address_size
);
7084 READ_ULEB (finish
, start
, end
);
7085 finish
= fetch_indexed_addr (finish
, address_size
);
7088 case DW_LLE_startx_length
:
7089 READ_ULEB (begin
, start
, end
);
7090 begin
= fetch_indexed_addr (begin
, address_size
);
7091 READ_ULEB (finish
, start
, end
);
7095 case DW_LLE_offset_pair
:
7096 READ_ULEB (begin
, start
, end
);
7097 begin
+= base_address
;
7098 READ_ULEB (finish
, start
, end
);
7099 finish
+= base_address
;
7102 case DW_LLE_default_location
:
7106 case DW_LLE_base_address
:
7107 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7108 print_dwarf_vma (base_address
, address_size
);
7109 printf (_("(base address)\n"));
7112 case DW_LLE_start_end
:
7113 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7114 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7117 case DW_LLE_start_length
:
7118 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7119 READ_ULEB (finish
, start
, end
);
7124 error (_("Invalid location list entry type %d\n"), lle
);
7130 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7131 (unsigned long) off
);
7135 print_dwarf_vma (begin
, address_size
);
7136 print_dwarf_vma (finish
, address_size
);
7138 if (begin
== finish
)
7139 fputs (_(" (start == end)"), stdout
);
7140 else if (begin
> finish
)
7141 fputs (_(" (start > end)"), stdout
);
7143 /* Read the counted location descriptions. */
7144 READ_ULEB (length
, start
, end
);
7146 if (length
> (size_t) (end
- start
))
7148 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7149 (unsigned long) off
);
7154 (void) decode_location_expression (start
, address_size
, address_size
,
7155 version
, length
, 0, section
);
7162 while (start
< end
);
7168 display_debug_loc (struct dwarf_section
*section
, void *file
)
7170 unsigned char *start
= section
->start
, *vstart
= NULL
;
7172 unsigned char *section_begin
= start
;
7173 unsigned int num_loc_list
= 0;
7174 dwarf_vma last_offset
= 0;
7175 dwarf_vma last_view
= 0;
7176 unsigned int first
= 0;
7179 int seen_first_offset
= 0;
7180 int locs_sorted
= 1;
7181 unsigned char *next
= start
, *vnext
= vstart
;
7182 unsigned int *array
= NULL
;
7183 const char *suffix
= strrchr (section
->name
, '.');
7184 bool is_dwo
= false;
7185 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7186 dwarf_vma expected_start
= 0;
7188 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7191 bytes
= section
->size
;
7195 printf (_("\nThe %s section is empty.\n"), section
->name
);
7201 unsigned char *hdrptr
= section_begin
;
7202 dwarf_vma ll_length
;
7203 unsigned short ll_version
;
7204 unsigned char *end
= section_begin
+ section
->size
;
7205 unsigned char address_size
, segment_selector_size
;
7206 uint32_t offset_entry_count
;
7208 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7209 if (ll_length
== 0xffffffff)
7210 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7212 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7213 if (ll_version
!= 5)
7215 warn (_("The %s section contains corrupt or "
7216 "unsupported version number: %d.\n"),
7217 section
->name
, ll_version
);
7221 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7223 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7224 if (segment_selector_size
!= 0)
7226 warn (_("The %s section contains "
7227 "unsupported segment selector size: %d.\n"),
7228 section
->name
, segment_selector_size
);
7232 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7234 if (offset_entry_count
!= 0)
7235 return display_offset_entry_loclists (section
);
7237 expected_start
= hdrptr
- section_begin
;
7240 if (load_debug_info (file
) == 0)
7242 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7247 /* Check the order of location list in .debug_info section. If
7248 offsets of location lists are in the ascending order, we can
7249 use `debug_information' directly. */
7250 for (i
= 0; i
< num_debug_info_entries
; i
++)
7254 num
= debug_information
[i
].num_loc_offsets
;
7255 if (num
> num_loc_list
)
7258 /* Check if we can use `debug_information' directly. */
7259 if (locs_sorted
&& num
!= 0)
7261 if (!seen_first_offset
)
7263 /* This is the first location list. */
7264 last_offset
= debug_information
[i
].loc_offsets
[0];
7265 last_view
= debug_information
[i
].loc_views
[0];
7267 seen_first_offset
= 1;
7273 for (; j
< num
; j
++)
7276 debug_information
[i
].loc_offsets
[j
]
7277 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7278 && last_view
> debug_information
[i
].loc_views
[j
]))
7283 last_offset
= debug_information
[i
].loc_offsets
[j
];
7284 last_view
= debug_information
[i
].loc_views
[j
];
7289 if (!seen_first_offset
)
7290 error (_("No location lists in .debug_info section!\n"));
7292 if (debug_information
[first
].num_loc_offsets
> 0
7293 && debug_information
[first
].loc_offsets
[0] != expected_start
7294 && debug_information
[first
].loc_views
[0] != expected_start
)
7295 warn (_("Location lists in %s section start at 0x%s rather than 0x%s\n"),
7297 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]),
7298 dwarf_vmatoa ("x", expected_start
));
7301 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7303 introduce (section
, false);
7305 if (reloc_at (section
, 0))
7306 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7308 printf (_(" Offset Begin End Expression\n"));
7310 seen_first_offset
= 0;
7311 for (i
= first
; i
< num_debug_info_entries
; i
++)
7313 dwarf_vma offset
, voffset
;
7314 dwarf_vma base_address
;
7320 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7322 loc_offsets
= debug_information
[i
].loc_offsets
;
7323 loc_views
= debug_information
[i
].loc_views
;
7324 qsort (array
, debug_information
[i
].num_loc_offsets
,
7325 sizeof (*array
), loc_offsets_compar
);
7328 int adjacent_view_loclists
= 1;
7329 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7331 j
= locs_sorted
? k
: array
[k
];
7333 && (debug_information
[i
].loc_offsets
[locs_sorted
7334 ? k
- 1 : array
[k
- 1]]
7335 == debug_information
[i
].loc_offsets
[j
])
7336 && (debug_information
[i
].loc_views
[locs_sorted
7337 ? k
- 1 : array
[k
- 1]]
7338 == debug_information
[i
].loc_views
[j
]))
7340 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7341 offset
= debug_information
[i
].loc_offsets
[j
];
7342 next
= section_begin
+ offset
;
7343 voffset
= debug_information
[i
].loc_views
[j
];
7345 vnext
= section_begin
+ voffset
;
7348 base_address
= debug_information
[i
].base_address
;
7350 if (vnext
&& vnext
< next
)
7353 display_view_pair_list (section
, &vstart
, i
, next
);
7358 if (!seen_first_offset
|| !adjacent_view_loclists
)
7359 seen_first_offset
= 1;
7363 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7364 (unsigned long) (start
- section_begin
),
7365 (unsigned long) offset
,
7367 else if (start
> next
)
7368 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7369 (unsigned long) (start
- section_begin
),
7370 (unsigned long) offset
,
7376 if (offset
>= bytes
)
7378 warn (_("Offset 0x%lx is bigger than %s section size.\n"),
7379 (unsigned long) offset
,
7384 if (vnext
&& voffset
>= bytes
)
7386 warn (_("View Offset 0x%lx is bigger than %s section size.\n"),
7387 (unsigned long) voffset
,
7395 display_loc_list_dwo (section
, &start
, i
, offset
,
7396 &vstart
, has_frame_base
);
7398 display_loc_list (section
, &start
, i
, offset
, base_address
,
7399 &vstart
, has_frame_base
);
7404 warn (_("DWO is not yet supported.\n"));
7406 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7407 &vstart
, has_frame_base
);
7410 /* FIXME: this arrangement is quite simplistic. Nothing
7411 requires locview lists to be adjacent to corresponding
7412 loclists, and a single loclist could be augmented by
7413 different locview lists, and vice-versa, unlikely as it
7414 is that it would make sense to do so. Hopefully we'll
7415 have view pair support built into loclists before we ever
7416 need to address all these possibilities. */
7417 if (adjacent_view_loclists
&& vnext
7418 && vnext
!= start
&& vstart
!= next
)
7420 adjacent_view_loclists
= 0;
7421 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7424 if (vnext
&& vnext
== start
)
7425 display_view_pair_list (section
, &start
, i
, vstart
);
7429 if (start
< section
->start
+ section
->size
)
7430 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7431 "There are %ld unused bytes at the end of section %s\n",
7432 (long) (section
->start
+ section
->size
- start
)),
7433 (long) (section
->start
+ section
->size
- start
), section
->name
);
7440 display_debug_str (struct dwarf_section
*section
,
7441 void *file ATTRIBUTE_UNUSED
)
7443 unsigned char *start
= section
->start
;
7444 dwarf_vma bytes
= section
->size
;
7445 dwarf_vma addr
= section
->address
;
7449 printf (_("\nThe %s section is empty.\n"), section
->name
);
7453 introduce (section
, false);
7461 lbytes
= (bytes
> 16 ? 16 : bytes
);
7463 printf (" 0x%8.8lx ", (unsigned long) addr
);
7465 for (j
= 0; j
< 16; j
++)
7468 printf ("%2.2x", start
[j
]);
7476 for (j
= 0; j
< lbytes
; j
++)
7479 if (k
>= ' ' && k
< 0x80)
7498 display_debug_info (struct dwarf_section
*section
, void *file
)
7500 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7504 display_debug_types (struct dwarf_section
*section
, void *file
)
7506 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7510 display_trace_info (struct dwarf_section
*section
, void *file
)
7512 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7516 display_debug_aranges (struct dwarf_section
*section
,
7517 void *file ATTRIBUTE_UNUSED
)
7519 unsigned char *start
= section
->start
;
7520 unsigned char *end
= start
+ section
->size
;
7522 introduce (section
, false);
7524 /* It does not matter if this load fails,
7525 we test for that later on. */
7526 load_debug_info (file
);
7530 unsigned char *hdrptr
;
7531 DWARF2_Internal_ARange arange
;
7532 unsigned char *addr_ranges
;
7536 unsigned char address_size
;
7537 unsigned int offset_size
;
7538 unsigned char *end_ranges
;
7541 sec_off
= hdrptr
- section
->start
;
7543 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7544 if (arange
.ar_length
== 0xffffffff)
7546 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7552 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7554 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7556 (unsigned long) sec_off
,
7557 dwarf_vmatoa ("x", arange
.ar_length
));
7560 end_ranges
= hdrptr
+ arange
.ar_length
;
7562 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7563 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7566 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7567 && num_debug_info_entries
> 0
7568 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7569 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7570 (unsigned long) arange
.ar_info_offset
, section
->name
);
7572 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7573 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7575 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7577 /* PR 19872: A version number of 0 probably means that there is
7578 padding at the end of the .debug_aranges section. Gold puts
7579 it there when performing an incremental link, for example.
7580 So do not generate a warning in this case. */
7581 if (arange
.ar_version
)
7582 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7586 printf (_(" Length: %ld\n"),
7587 (long) arange
.ar_length
);
7588 printf (_(" Version: %d\n"), arange
.ar_version
);
7589 printf (_(" Offset into .debug_info: 0x%lx\n"),
7590 (unsigned long) arange
.ar_info_offset
);
7591 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7592 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7594 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7596 /* PR 17512: file: 001-108546-0.001:0.1. */
7597 if (address_size
== 0 || address_size
> 8)
7599 error (_("Invalid address size in %s section!\n"),
7604 /* The DWARF spec does not require that the address size be a power
7605 of two, but we do. This will have to change if we ever encounter
7606 an uneven architecture. */
7607 if ((address_size
& (address_size
- 1)) != 0)
7609 warn (_("Pointer size + Segment size is not a power of two.\n"));
7613 if (address_size
> 4)
7614 printf (_("\n Address Length\n"));
7616 printf (_("\n Address Length\n"));
7618 addr_ranges
= hdrptr
;
7620 /* Must pad to an alignment boundary that is twice the address size. */
7621 addr_ranges
+= (2 * address_size
- 1
7622 - (hdrptr
- start
- 1) % (2 * address_size
));
7624 while (2 * address_size
<= end_ranges
- addr_ranges
)
7626 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7628 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7631 print_dwarf_vma (address
, address_size
);
7632 print_dwarf_vma (length
, address_size
);
7644 /* Comparison function for qsort. */
7646 comp_addr_base (const void * v0
, const void * v1
)
7648 debug_info
*info0
= *(debug_info
**) v0
;
7649 debug_info
*info1
= *(debug_info
**) v1
;
7650 return info0
->addr_base
- info1
->addr_base
;
7653 /* Display the debug_addr section. */
7655 display_debug_addr (struct dwarf_section
*section
,
7658 debug_info
**debug_addr_info
;
7659 unsigned char *entry
;
7663 unsigned char * header
;
7665 if (section
->size
== 0)
7667 printf (_("\nThe %s section is empty.\n"), section
->name
);
7671 if (load_debug_info (file
) == 0)
7673 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7678 introduce (section
, false);
7680 /* PR 17531: file: cf38d01b.
7681 We use xcalloc because a corrupt file may not have initialised all of the
7682 fields in the debug_info structure, which means that the sort below might
7683 try to move uninitialised data. */
7684 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7685 sizeof (debug_info
*));
7688 for (i
= 0; i
< num_debug_info_entries
; i
++)
7689 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7691 /* PR 17531: file: cf38d01b. */
7692 if (debug_information
[i
].addr_base
>= section
->size
)
7693 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7694 (unsigned long) debug_information
[i
].addr_base
, i
);
7696 debug_addr_info
[count
++] = debug_information
+ i
;
7699 /* Add a sentinel to make iteration convenient. */
7700 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7701 debug_addr_info
[count
]->addr_base
= section
->size
;
7702 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7704 header
= section
->start
;
7705 for (i
= 0; i
< count
; i
++)
7708 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7710 printf (_(" For compilation unit at offset 0x%s:\n"),
7711 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7713 printf (_("\tIndex\tAddress\n"));
7714 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7715 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7717 size_t header_size
= entry
- header
;
7718 unsigned char * curr_header
= header
;
7721 int segment_selector_size
;
7723 if (header_size
!= 8 && header_size
!= 16)
7725 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7726 section
->name
, (long) header_size
);
7730 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7731 if (length
== 0xffffffff)
7732 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7733 end
= curr_header
+ length
;
7735 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7737 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7738 section
->name
, version
);
7740 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7741 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7742 address_size
+= segment_selector_size
;
7745 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7750 dwarf_vma base
= byte_get (entry
, address_size
);
7751 printf (_("\t%d:\t"), idx
);
7752 print_dwarf_vma (base
, address_size
);
7754 entry
+= address_size
;
7760 free (debug_addr_info
);
7764 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7767 display_debug_str_offsets (struct dwarf_section
*section
,
7768 void *file ATTRIBUTE_UNUSED
)
7772 if (section
->size
== 0)
7774 printf (_("\nThe %s section is empty.\n"), section
->name
);
7778 unsigned char *start
= section
->start
;
7779 unsigned char *end
= start
+ section
->size
;
7780 unsigned char *curr
= start
;
7782 const char *suffix
= strrchr (section
->name
, '.');
7783 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7786 load_debug_section_with_follow (str_dwo
, file
);
7788 load_debug_section_with_follow (str
, file
);
7790 introduce (section
, false);
7795 dwarf_vma entry_length
;
7797 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7798 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7799 if (length
== 0xffffffff)
7801 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7807 unsigned char *entries_end
;
7810 /* This is probably an old style .debug_str_offset section which
7811 just contains offsets and no header (and the first offset is 0). */
7812 length
= section
->size
;
7813 curr
= section
->start
;
7816 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7817 printf (_(" Index Offset [String]\n"));
7821 if (length
<= (dwarf_vma
) (end
- curr
))
7822 entries_end
= curr
+ length
;
7825 warn (_("Section %s is too small %#lx\n"),
7826 section
->name
, (unsigned long) section
->size
);
7831 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7833 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7836 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7838 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7840 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7841 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7842 printf (_(" Index Offset [String]\n"));
7845 for (idx
= 0; curr
< entries_end
; idx
++)
7848 const unsigned char * string
;
7850 if ((dwarf_vma
) (entries_end
- curr
) < entry_length
)
7851 /* Not enough space to read one entry_length, give up. */
7854 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7856 string
= (const unsigned char *)
7857 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7859 string
= fetch_indirect_string (offset
);
7861 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7869 /* Each debug_information[x].range_lists[y] gets this representation for
7870 sorting purposes. */
7874 /* The debug_information[x].range_lists[y] value. */
7875 dwarf_vma ranges_offset
;
7877 /* Original debug_information to find parameters of the data. */
7878 debug_info
*debug_info_p
;
7881 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7884 range_entry_compar (const void *ap
, const void *bp
)
7886 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7887 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7888 const dwarf_vma a
= a_re
->ranges_offset
;
7889 const dwarf_vma b
= b_re
->ranges_offset
;
7891 return (a
> b
) - (b
> a
);
7895 display_debug_ranges_list (unsigned char * start
,
7896 unsigned char * finish
,
7897 unsigned int pointer_size
,
7899 dwarf_vma base_address
)
7901 while (start
< finish
)
7906 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7907 if (start
>= finish
)
7909 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7912 print_dwarf_vma (offset
, 4);
7914 if (begin
== 0 && end
== 0)
7916 printf (_("<End of list>\n"));
7920 /* Check base address specifiers. */
7921 if (is_max_address (begin
, pointer_size
)
7922 && !is_max_address (end
, pointer_size
))
7925 print_dwarf_vma (begin
, pointer_size
);
7926 print_dwarf_vma (end
, pointer_size
);
7927 printf ("(base address)\n");
7931 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7932 print_dwarf_vma (end
+ base_address
, pointer_size
);
7935 fputs (_("(start == end)"), stdout
);
7936 else if (begin
> end
)
7937 fputs (_("(start > end)"), stdout
);
7944 display_debug_rnglists_list (unsigned char * start
,
7945 unsigned char * finish
,
7946 unsigned int pointer_size
,
7948 dwarf_vma base_address
)
7950 unsigned char *next
= start
;
7954 dwarf_vma off
= offset
+ (start
- next
);
7955 enum dwarf_range_list_entry rlet
;
7956 /* Initialize it due to a false compiler warning. */
7957 dwarf_vma begin
= -1, length
, end
= -1;
7959 if (start
>= finish
)
7961 warn (_("Range list starting at offset 0x%s is not terminated.\n"),
7962 dwarf_vmatoa ("x", offset
));
7967 print_dwarf_vma (off
, 4);
7969 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7973 case DW_RLE_end_of_list
:
7974 printf (_("<End of list>\n"));
7976 case DW_RLE_base_addressx
:
7977 READ_ULEB (base_address
, start
, finish
);
7978 print_dwarf_vma (base_address
, pointer_size
);
7979 printf (_("(base address index) "));
7980 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
7981 print_dwarf_vma (base_address
, pointer_size
);
7982 printf (_("(base address)\n"));
7984 case DW_RLE_startx_endx
:
7985 READ_ULEB (begin
, start
, finish
);
7986 READ_ULEB (end
, start
, finish
);
7987 begin
= fetch_indexed_addr (begin
, pointer_size
);
7988 end
= fetch_indexed_addr (begin
, pointer_size
);
7990 case DW_RLE_startx_length
:
7991 READ_ULEB (begin
, start
, finish
);
7992 READ_ULEB (length
, start
, finish
);
7993 begin
= fetch_indexed_addr (begin
, pointer_size
);
7994 end
= begin
+ length
;
7996 case DW_RLE_offset_pair
:
7997 READ_ULEB (begin
, start
, finish
);
7998 READ_ULEB (end
, start
, finish
);
8000 case DW_RLE_base_address
:
8001 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8002 print_dwarf_vma (base_address
, pointer_size
);
8003 printf (_("(base address)\n"));
8005 case DW_RLE_start_end
:
8006 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8007 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8009 case DW_RLE_start_length
:
8010 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8011 READ_ULEB (length
, start
, finish
);
8012 end
= begin
+ length
;
8015 error (_("Invalid range list entry type %d\n"), rlet
);
8016 rlet
= DW_RLE_end_of_list
;
8019 if (rlet
== DW_RLE_end_of_list
)
8021 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8024 /* Only a DW_RLE_offset_pair needs the base address added. */
8025 if (rlet
== DW_RLE_offset_pair
)
8027 begin
+= base_address
;
8028 end
+= base_address
;
8031 print_dwarf_vma (begin
, pointer_size
);
8032 print_dwarf_vma (end
, pointer_size
);
8035 fputs (_("(start == end)"), stdout
);
8036 else if (begin
> end
)
8037 fputs (_("(start > end)"), stdout
);
8044 display_debug_ranges (struct dwarf_section
*section
,
8045 void *file ATTRIBUTE_UNUSED
)
8047 unsigned char * start
= section
->start
;
8048 unsigned char * last_start
= start
;
8049 dwarf_vma bytes
= section
->size
;
8050 unsigned char * section_begin
= start
;
8051 unsigned char * finish
= start
+ bytes
;
8052 unsigned int num_range_list
, i
;
8053 struct range_entry
* range_entries
;
8054 struct range_entry
* range_entry_fill
;
8055 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8056 /* Initialize it due to a false compiler warning. */
8057 unsigned char address_size
= 0;
8058 dwarf_vma last_offset
= 0;
8062 printf (_("\nThe %s section is empty.\n"), section
->name
);
8066 introduce (section
, false);
8070 dwarf_vma initial_length
;
8071 unsigned char segment_selector_size
;
8072 unsigned int offset_size
, offset_entry_count
;
8073 unsigned short version
;
8075 /* Get and check the length of the block. */
8076 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8078 if (initial_length
== 0xffffffff)
8080 /* This section is 64-bit DWARF 3. */
8081 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8087 if (initial_length
> (size_t) (finish
- start
))
8089 /* If the length field has a relocation against it, then we should
8090 not complain if it is inaccurate (and probably negative).
8091 It is copied from .debug_line handling code. */
8092 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8094 initial_length
= finish
- start
;
8098 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
8099 (long) initial_length
);
8104 /* Get the other fields in the header. */
8105 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8106 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8107 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8108 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8110 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", initial_length
));
8111 printf (_(" DWARF version: %u\n"), version
);
8112 printf (_(" Address size: %u\n"), address_size
);
8113 printf (_(" Segment size: %u\n"), segment_selector_size
);
8114 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8116 /* Check the fields. */
8117 if (segment_selector_size
!= 0)
8119 warn (_("The %s section contains "
8120 "unsupported segment selector size: %d.\n"),
8121 section
->name
, segment_selector_size
);
8127 warn (_("Only DWARF version 5+ debug_rnglists info "
8128 "is currently supported.\n"));
8132 if (offset_entry_count
!= 0)
8134 printf (_("\n Offsets starting at 0x%lx:\n"), (long)(start
- section
->start
));
8135 if (offset_size
== 8)
8137 for (i
= 0; i
< offset_entry_count
; i
++)
8141 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, finish
);
8142 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
8147 for (i
= 0; i
< offset_entry_count
; i
++)
8151 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, finish
);
8152 printf (_(" [%6u] 0x%x\n"), i
, entry
);
8158 if (load_debug_info (file
) == 0)
8160 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8166 for (i
= 0; i
< num_debug_info_entries
; i
++)
8168 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
8169 /* Skip .debug_rnglists reference. */
8171 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
8172 /* Skip .debug_range reference. */
8174 num_range_list
+= debug_information
[i
].num_range_lists
;
8177 if (num_range_list
== 0)
8179 /* This can happen when the file was compiled with -gsplit-debug
8180 which removes references to range lists from the primary .o file. */
8181 printf (_("No range lists in .debug_info section.\n"));
8185 range_entries
= (struct range_entry
*)
8186 xmalloc (sizeof (*range_entries
) * num_range_list
);
8187 range_entry_fill
= range_entries
;
8189 for (i
= 0; i
< num_debug_info_entries
; i
++)
8191 debug_info
*debug_info_p
= &debug_information
[i
];
8194 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
8195 /* Skip .debug_rnglists reference. */
8197 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
8198 /* Skip .debug_range reference. */
8201 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8203 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8204 range_entry_fill
->debug_info_p
= debug_info_p
;
8209 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8210 range_entry_compar
);
8212 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8213 warn (_("Range lists in %s section start at 0x%lx\n"),
8214 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
8217 printf (_(" Offset Begin End\n"));
8219 for (i
= 0; i
< num_range_list
; i
++)
8221 struct range_entry
*range_entry
= &range_entries
[i
];
8222 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8223 unsigned int pointer_size
;
8225 unsigned char *next
;
8226 dwarf_vma base_address
;
8228 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8229 offset
= range_entry
->ranges_offset
;
8230 base_address
= debug_info_p
->base_address
;
8232 /* PR 17512: file: 001-101485-0.001:0.1. */
8233 if (pointer_size
< 2 || pointer_size
> 8)
8235 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
8236 pointer_size
, (unsigned long) offset
);
8240 if (offset
> (size_t) (finish
- section_begin
))
8242 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
8243 (unsigned long) offset
, i
);
8246 next
= section_begin
+ offset
;
8248 /* If multiple DWARF entities reference the same range then we will
8249 have multiple entries in the `range_entries' list for the same
8250 offset. Thanks to the sort above these will all be consecutive in
8251 the `range_entries' list, so we can easily ignore duplicates
8253 if (i
> 0 && last_offset
== offset
)
8255 last_offset
= offset
;
8257 if (dwarf_check
!= 0 && i
> 0)
8260 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
8261 (unsigned long) (start
- section_begin
),
8262 (unsigned long) (next
- section_begin
), section
->name
);
8263 else if (start
> next
)
8265 if (next
== last_start
)
8267 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
8268 (unsigned long) (start
- section_begin
),
8269 (unsigned long) (next
- section_begin
), section
->name
);
8277 display_debug_rnglists_list
8278 (start
, finish
, pointer_size
, offset
, base_address
);
8280 display_debug_ranges_list
8281 (start
, finish
, pointer_size
, offset
, base_address
);
8285 free (range_entries
);
8290 typedef struct Frame_Chunk
8292 struct Frame_Chunk
*next
;
8293 unsigned char *chunk_start
;
8295 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8296 short int *col_type
;
8299 unsigned int code_factor
;
8303 unsigned int cfa_reg
;
8304 dwarf_vma cfa_offset
;
8306 unsigned char fde_encoding
;
8307 unsigned char cfa_exp
;
8308 unsigned char ptr_size
;
8309 unsigned char segment_size
;
8313 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8314 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8315 static const char *const *dwarf_regnames
;
8316 static unsigned int dwarf_regnames_count
;
8319 /* A marker for a col_type that means this column was never referenced
8320 in the frame info. */
8321 #define DW_CFA_unreferenced (-1)
8323 /* Return 0 if no more space is needed, 1 if more space is needed,
8324 -1 for invalid reg. */
8327 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8329 unsigned int prev
= fc
->ncols
;
8331 if (reg
< (unsigned int) fc
->ncols
)
8334 if (dwarf_regnames_count
> 0
8335 && reg
> dwarf_regnames_count
)
8338 fc
->ncols
= reg
+ 1;
8339 /* PR 17512: file: 10450-2643-0.004.
8340 If reg == -1 then this can happen... */
8344 /* PR 17512: file: 2844a11d. */
8345 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8347 error (_("Unfeasibly large register number: %u\n"), reg
);
8349 /* FIXME: 1024 is an arbitrary limit. Increase it if
8350 we ever encounter a valid binary that exceeds it. */
8354 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
8355 sizeof (short int));
8356 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
8357 /* PR 17512: file:002-10025-0.005. */
8358 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8360 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8366 while (prev
< fc
->ncols
)
8368 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8369 fc
->col_offset
[prev
] = 0;
8375 static const char *const dwarf_regnames_i386
[] =
8377 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8378 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8379 "eip", "eflags", NULL
, /* 8 - 10 */
8380 "st0", "st1", "st2", "st3", /* 11 - 14 */
8381 "st4", "st5", "st6", "st7", /* 15 - 18 */
8382 NULL
, NULL
, /* 19 - 20 */
8383 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8384 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8385 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8386 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8387 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8388 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8389 "tr", "ldtr", /* 48 - 49 */
8390 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8391 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8392 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8393 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8394 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8395 NULL
, NULL
, NULL
, /* 90 - 92 */
8396 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8399 static const char *const dwarf_regnames_iamcu
[] =
8401 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8402 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8403 "eip", "eflags", NULL
, /* 8 - 10 */
8404 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8405 NULL
, NULL
, /* 19 - 20 */
8406 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8407 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8408 NULL
, NULL
, NULL
, /* 37 - 39 */
8409 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8410 "tr", "ldtr", /* 48 - 49 */
8411 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8412 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8413 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8414 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8415 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8416 NULL
, NULL
, NULL
, /* 90 - 92 */
8417 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8421 init_dwarf_regnames_i386 (void)
8423 dwarf_regnames
= dwarf_regnames_i386
;
8424 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8425 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8429 init_dwarf_regnames_iamcu (void)
8431 dwarf_regnames
= dwarf_regnames_iamcu
;
8432 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8433 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8436 static const char *const dwarf_regnames_x86_64
[] =
8438 "rax", "rdx", "rcx", "rbx",
8439 "rsi", "rdi", "rbp", "rsp",
8440 "r8", "r9", "r10", "r11",
8441 "r12", "r13", "r14", "r15",
8443 "xmm0", "xmm1", "xmm2", "xmm3",
8444 "xmm4", "xmm5", "xmm6", "xmm7",
8445 "xmm8", "xmm9", "xmm10", "xmm11",
8446 "xmm12", "xmm13", "xmm14", "xmm15",
8447 "st0", "st1", "st2", "st3",
8448 "st4", "st5", "st6", "st7",
8449 "mm0", "mm1", "mm2", "mm3",
8450 "mm4", "mm5", "mm6", "mm7",
8452 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8453 "fs.base", "gs.base", NULL
, NULL
,
8455 "mxcsr", "fcw", "fsw",
8456 "xmm16", "xmm17", "xmm18", "xmm19",
8457 "xmm20", "xmm21", "xmm22", "xmm23",
8458 "xmm24", "xmm25", "xmm26", "xmm27",
8459 "xmm28", "xmm29", "xmm30", "xmm31",
8460 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8461 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8462 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8463 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8464 NULL
, NULL
, NULL
, /* 115 - 117 */
8465 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8469 init_dwarf_regnames_x86_64 (void)
8471 dwarf_regnames
= dwarf_regnames_x86_64
;
8472 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8473 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8476 static const char *const dwarf_regnames_aarch64
[] =
8478 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8479 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8480 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8481 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8482 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8483 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8484 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8485 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8486 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8487 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8488 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8489 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8490 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8491 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8492 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8493 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8497 init_dwarf_regnames_aarch64 (void)
8499 dwarf_regnames
= dwarf_regnames_aarch64
;
8500 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8501 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8504 static const char *const dwarf_regnames_s390
[] =
8506 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8507 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8508 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8509 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8510 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8511 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8512 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8513 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8514 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8517 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8518 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8522 init_dwarf_regnames_s390 (void)
8524 dwarf_regnames
= dwarf_regnames_s390
;
8525 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8526 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8529 static const char *const dwarf_regnames_riscv
[] =
8531 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8532 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8533 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8534 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8535 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8536 "fs0", "fs1", /* 40 - 41 */
8537 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8538 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8539 "fs10", "fs11", /* 58 - 59 */
8540 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8543 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8544 the large number of CSRs. */
8547 regname_internal_riscv (unsigned int regno
)
8549 const char *name
= NULL
;
8551 /* Lookup in the table first, this covers GPR and FPR. */
8552 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8553 name
= dwarf_regnames_riscv
[regno
];
8554 else if (regno
>= 4096 && regno
<= 8191)
8556 /* This might be a CSR, these live in a sparse number space from 4096
8557 to 8191 These numbers are defined in the RISC-V ELF ABI
8561 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8562 case VALUE + 4096: name = #NAME; break;
8563 #include "opcode/riscv-opc.h"
8568 static char csr_name
[10];
8569 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8580 init_dwarf_regnames_riscv (void)
8582 dwarf_regnames
= NULL
;
8583 dwarf_regnames_count
= 8192;
8584 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8588 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8590 dwarf_regnames_lookup_func
= NULL
;
8595 init_dwarf_regnames_i386 ();
8599 init_dwarf_regnames_iamcu ();
8605 init_dwarf_regnames_x86_64 ();
8609 init_dwarf_regnames_aarch64 ();
8613 init_dwarf_regnames_s390 ();
8617 init_dwarf_regnames_riscv ();
8625 /* Initialize the DWARF register name lookup state based on the
8626 architecture and specific machine type of a BFD. */
8629 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8632 dwarf_regnames_lookup_func
= NULL
;
8639 case bfd_mach_x86_64
:
8640 case bfd_mach_x86_64_intel_syntax
:
8641 case bfd_mach_x64_32
:
8642 case bfd_mach_x64_32_intel_syntax
:
8643 init_dwarf_regnames_x86_64 ();
8647 init_dwarf_regnames_i386 ();
8652 case bfd_arch_iamcu
:
8653 init_dwarf_regnames_iamcu ();
8656 case bfd_arch_aarch64
:
8657 init_dwarf_regnames_aarch64();
8661 init_dwarf_regnames_s390 ();
8664 case bfd_arch_riscv
:
8665 init_dwarf_regnames_riscv ();
8674 regname_internal_by_table_only (unsigned int regno
)
8676 if (dwarf_regnames
!= NULL
8677 && regno
< dwarf_regnames_count
8678 && dwarf_regnames
[regno
] != NULL
)
8679 return dwarf_regnames
[regno
];
8685 regname (unsigned int regno
, int name_only_p
)
8687 static char reg
[64];
8689 const char *name
= NULL
;
8691 if (dwarf_regnames_lookup_func
!= NULL
)
8692 name
= dwarf_regnames_lookup_func (regno
);
8698 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8701 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8706 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8711 if (*max_regs
!= fc
->ncols
)
8712 *max_regs
= fc
->ncols
;
8714 if (*need_col_headers
)
8716 *need_col_headers
= 0;
8718 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8720 for (r
= 0; r
< *max_regs
; r
++)
8721 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8726 printf ("%-5s ", regname (r
, 1));
8732 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8734 strcpy (tmp
, "exp");
8736 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8737 printf ("%-8s ", tmp
);
8739 for (r
= 0; r
< fc
->ncols
; r
++)
8741 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8743 switch (fc
->col_type
[r
])
8745 case DW_CFA_undefined
:
8748 case DW_CFA_same_value
:
8752 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8754 case DW_CFA_val_offset
:
8755 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8757 case DW_CFA_register
:
8758 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8760 case DW_CFA_expression
:
8761 strcpy (tmp
, "exp");
8763 case DW_CFA_val_expression
:
8764 strcpy (tmp
, "vexp");
8767 strcpy (tmp
, "n/a");
8770 printf ("%-5s ", tmp
);
8776 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8778 static unsigned char *
8779 read_cie (unsigned char *start
, unsigned char *end
,
8780 Frame_Chunk
**p_cie
, int *p_version
,
8781 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8785 unsigned char *augmentation_data
= NULL
;
8786 bfd_size_type augmentation_data_len
= 0;
8789 /* PR 17512: file: 001-228113-0.004. */
8793 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8794 memset (fc
, 0, sizeof (Frame_Chunk
));
8796 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8797 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8801 fc
->augmentation
= (char *) start
;
8802 /* PR 17512: file: 001-228113-0.004.
8803 Skip past augmentation name, but avoid running off the end of the data. */
8805 if (* start
++ == '\0')
8809 warn (_("No terminator for augmentation name\n"));
8813 if (strcmp (fc
->augmentation
, "eh") == 0)
8815 if (eh_addr_size
> (size_t) (end
- start
))
8817 start
+= eh_addr_size
;
8822 if (2 > (size_t) (end
- start
))
8824 GET (fc
->ptr_size
, 1);
8825 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8827 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8831 GET (fc
->segment_size
, 1);
8832 /* PR 17512: file: e99d2804. */
8833 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8835 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8839 eh_addr_size
= fc
->ptr_size
;
8843 fc
->ptr_size
= eh_addr_size
;
8844 fc
->segment_size
= 0;
8847 READ_ULEB (fc
->code_factor
, start
, end
);
8848 READ_SLEB (fc
->data_factor
, start
, end
);
8859 READ_ULEB (fc
->ra
, start
, end
);
8862 if (fc
->augmentation
[0] == 'z')
8866 READ_ULEB (augmentation_data_len
, start
, end
);
8867 augmentation_data
= start
;
8868 /* PR 17512: file: 11042-2589-0.004. */
8869 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8871 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8872 dwarf_vmatoa ("x", augmentation_data_len
),
8873 (unsigned long) (end
- start
));
8876 start
+= augmentation_data_len
;
8879 if (augmentation_data_len
)
8883 unsigned char *qend
;
8885 p
= (unsigned char *) fc
->augmentation
+ 1;
8886 q
= augmentation_data
;
8887 qend
= q
+ augmentation_data_len
;
8889 while (p
< end
&& q
< qend
)
8894 q
+= 1 + size_of_encoded_value (*q
);
8896 fc
->fde_encoding
= *q
++;
8905 /* Note - it is OK if this loop terminates with q < qend.
8906 Padding may have been inserted to align the end of the CIE. */
8911 *p_version
= version
;
8914 *p_aug_len
= augmentation_data_len
;
8915 *p_aug
= augmentation_data
;
8920 free (fc
->col_offset
);
8921 free (fc
->col_type
);
8926 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8927 If do_wide is not enabled, then formats the output to fit into 80 columns.
8928 PRINTED contains the number of characters already written to the current
8932 display_data (bfd_size_type printed
,
8933 const unsigned char * data
,
8934 const bfd_size_type len
)
8936 if (do_wide
|| len
< ((80 - printed
) / 3))
8937 for (printed
= 0; printed
< len
; ++printed
)
8938 printf (" %02x", data
[printed
]);
8941 for (printed
= 0; printed
< len
; ++printed
)
8943 if (printed
% (80 / 3) == 0)
8945 printf (" %02x", data
[printed
]);
8950 /* Prints out the contents on the augmentation data array.
8951 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8954 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8958 i
= printf (_(" Augmentation data: "));
8959 display_data (i
, data
, len
);
8963 display_debug_frames (struct dwarf_section
*section
,
8964 void *file ATTRIBUTE_UNUSED
)
8966 unsigned char *start
= section
->start
;
8967 unsigned char *end
= start
+ section
->size
;
8968 unsigned char *section_start
= start
;
8969 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8970 Frame_Chunk
*remembered_state
= NULL
;
8972 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8973 unsigned int max_regs
= 0;
8974 const char *bad_reg
= _("bad register: ");
8975 unsigned int saved_eh_addr_size
= eh_addr_size
;
8977 introduce (section
, false);
8981 unsigned char *saved_start
;
8982 unsigned char *block_end
;
8987 int need_col_headers
= 1;
8988 unsigned char *augmentation_data
= NULL
;
8989 bfd_size_type augmentation_data_len
= 0;
8990 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8991 unsigned int offset_size
;
8993 static Frame_Chunk fde_fc
;
8995 saved_start
= start
;
8997 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9001 printf ("\n%08lx ZERO terminator\n\n",
9002 (unsigned long)(saved_start
- section_start
));
9003 /* Skip any zero terminators that directly follow.
9004 A corrupt section size could have loaded a whole
9005 slew of zero filled memory bytes. eg
9006 PR 17512: file: 070-19381-0.004. */
9007 while (start
< end
&& * start
== 0)
9012 if (length
== 0xffffffff)
9014 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9020 if (length
> (size_t) (end
- start
))
9022 warn ("Invalid length 0x%s in FDE at %#08lx\n",
9023 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
9024 (unsigned long) (saved_start
- section_start
));
9028 block_end
= start
+ length
;
9030 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9032 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9033 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9038 start
= read_cie (start
, block_end
, &cie
, &version
,
9039 &augmentation_data_len
, &augmentation_data
);
9040 /* PR 17512: file: 027-135133-0.005. */
9047 fc
->chunk_start
= saved_start
;
9048 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9051 if (frame_need_space (fc
, mreg
) < 0)
9053 if (fc
->fde_encoding
)
9054 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9056 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
9057 print_dwarf_vma (length
, fc
->ptr_size
);
9058 print_dwarf_vma (cie_id
, offset_size
);
9060 if (do_debug_frames_interp
)
9062 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9063 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9068 printf (" Version: %d\n", version
);
9069 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9072 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9073 printf (" Segment Size: %u\n", fc
->segment_size
);
9075 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9076 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9077 printf (" Return address column: %d\n", fc
->ra
);
9079 if (augmentation_data_len
)
9080 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9087 unsigned char *look_for
;
9088 unsigned long segment_selector
;
9094 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
9095 cie_off
= (cie_off
^ sign
) - sign
;
9096 cie_off
= start
- 4 - section_start
- cie_off
;
9099 look_for
= section_start
+ cie_off
;
9100 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
9102 for (cie
= chunks
; cie
; cie
= cie
->next
)
9103 if (cie
->chunk_start
== look_for
)
9106 else if (cie_off
>= section
->size
)
9110 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9111 if (cie
->chunk_start
== look_for
)
9115 unsigned int off_size
;
9116 unsigned char *cie_scan
;
9118 cie_scan
= look_for
;
9120 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9121 if (length
== 0xffffffff)
9123 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9126 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9129 unsigned char *cie_end
= cie_scan
+ length
;
9131 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9135 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9136 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9141 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9142 &augmentation_data_len
, &augmentation_data
);
9143 /* PR 17512: file: 3450-2098-0.004. */
9146 warn (_("Failed to read CIE information\n"));
9149 cie
->next
= forward_refs
;
9151 cie
->chunk_start
= look_for
;
9152 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9155 if (frame_need_space (cie
, mreg
) < 0)
9157 warn (_("Invalid max register\n"));
9160 if (cie
->fde_encoding
)
9162 = size_of_encoded_value (cie
->fde_encoding
);
9169 memset (fc
, 0, sizeof (Frame_Chunk
));
9174 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
9175 fc
->col_offset
= (int *) xmalloc (sizeof (int));
9176 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9178 warn (_("Invalid max register\n"));
9182 fc
->augmentation
= "";
9183 fc
->fde_encoding
= 0;
9184 fc
->ptr_size
= eh_addr_size
;
9185 fc
->segment_size
= 0;
9189 fc
->ncols
= cie
->ncols
;
9190 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
9191 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
9192 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
9193 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
9194 fc
->augmentation
= cie
->augmentation
;
9195 fc
->ptr_size
= cie
->ptr_size
;
9196 eh_addr_size
= cie
->ptr_size
;
9197 fc
->segment_size
= cie
->segment_size
;
9198 fc
->code_factor
= cie
->code_factor
;
9199 fc
->data_factor
= cie
->data_factor
;
9200 fc
->cfa_reg
= cie
->cfa_reg
;
9201 fc
->cfa_offset
= cie
->cfa_offset
;
9203 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9205 warn (_("Invalid max register\n"));
9208 fc
->fde_encoding
= cie
->fde_encoding
;
9211 if (fc
->fde_encoding
)
9212 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9214 segment_selector
= 0;
9215 if (fc
->segment_size
)
9217 if (fc
->segment_size
> sizeof (segment_selector
))
9219 /* PR 17512: file: 9e196b3e. */
9220 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9221 fc
->segment_size
= 4;
9223 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9224 fc
->segment_size
, block_end
);
9227 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9230 /* FIXME: It appears that sometimes the final pc_range value is
9231 encoded in less than encoded_ptr_size bytes. See the x86_64
9232 run of the "objcopy on compressed debug sections" test for an
9234 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9237 if (cie
->augmentation
[0] == 'z')
9239 READ_ULEB (augmentation_data_len
, start
, block_end
);
9240 augmentation_data
= start
;
9241 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9242 if (augmentation_data_len
> (bfd_size_type
) (block_end
- start
))
9244 warn (_("Augmentation data too long: 0x%s, "
9245 "expected at most %#lx\n"),
9246 dwarf_vmatoa ("x", augmentation_data_len
),
9247 (unsigned long) (block_end
- start
));
9249 augmentation_data
= NULL
;
9250 augmentation_data_len
= 0;
9252 start
+= augmentation_data_len
;
9255 printf ("\n%08lx %s %s FDE ",
9256 (unsigned long)(saved_start
- section_start
),
9257 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
9258 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
));
9260 if (cie
->chunk_start
)
9261 printf ("cie=%08lx",
9262 (unsigned long) (cie
->chunk_start
- section_start
));
9264 /* Ideally translate "invalid " to 8 chars, trailing space
9266 printf (_("cie=invalid "));
9269 if (fc
->segment_size
)
9270 printf ("%04lx:", segment_selector
);
9273 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
9274 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
9276 if (! do_debug_frames_interp
&& augmentation_data_len
)
9278 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9283 /* At this point, fc is the current chunk, cie (if any) is set, and
9284 we're about to interpret instructions for the chunk. */
9285 /* ??? At present we need to do this always, since this sizes the
9286 fc->col_type and fc->col_offset arrays, which we write into always.
9287 We should probably split the interpreted and non-interpreted bits
9288 into two different routines, since there's so much that doesn't
9289 really overlap between them. */
9290 if (1 || do_debug_frames_interp
)
9292 /* Start by making a pass over the chunk, allocating storage
9293 and taking note of what registers are used. */
9294 unsigned char *tmp
= start
;
9296 while (start
< block_end
)
9298 unsigned int reg
, op
, opa
;
9306 /* Warning: if you add any more cases to this switch, be
9307 sure to add them to the corresponding switch below. */
9310 case DW_CFA_advance_loc
:
9313 SKIP_ULEB (start
, block_end
);
9314 if (frame_need_space (fc
, opa
) >= 0)
9315 fc
->col_type
[opa
] = DW_CFA_undefined
;
9317 case DW_CFA_restore
:
9318 if (frame_need_space (fc
, opa
) >= 0)
9319 fc
->col_type
[opa
] = DW_CFA_undefined
;
9321 case DW_CFA_set_loc
:
9322 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9325 start
+= encoded_ptr_size
;
9327 case DW_CFA_advance_loc1
:
9328 if ((size_t) (block_end
- start
) < 1)
9333 case DW_CFA_advance_loc2
:
9334 if ((size_t) (block_end
- start
) < 2)
9339 case DW_CFA_advance_loc4
:
9340 if ((size_t) (block_end
- start
) < 4)
9345 case DW_CFA_offset_extended
:
9346 case DW_CFA_val_offset
:
9347 READ_ULEB (reg
, start
, block_end
);
9348 SKIP_ULEB (start
, block_end
);
9349 if (frame_need_space (fc
, reg
) >= 0)
9350 fc
->col_type
[reg
] = DW_CFA_undefined
;
9352 case DW_CFA_restore_extended
:
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_undefined
:
9358 READ_ULEB (reg
, start
, block_end
);
9359 if (frame_need_space (fc
, reg
) >= 0)
9360 fc
->col_type
[reg
] = DW_CFA_undefined
;
9362 case DW_CFA_same_value
:
9363 READ_ULEB (reg
, start
, block_end
);
9364 if (frame_need_space (fc
, reg
) >= 0)
9365 fc
->col_type
[reg
] = DW_CFA_undefined
;
9367 case DW_CFA_register
:
9368 READ_ULEB (reg
, start
, block_end
);
9369 SKIP_ULEB (start
, block_end
);
9370 if (frame_need_space (fc
, reg
) >= 0)
9371 fc
->col_type
[reg
] = DW_CFA_undefined
;
9373 case DW_CFA_def_cfa
:
9374 SKIP_ULEB (start
, block_end
);
9375 SKIP_ULEB (start
, block_end
);
9377 case DW_CFA_def_cfa_register
:
9378 SKIP_ULEB (start
, block_end
);
9380 case DW_CFA_def_cfa_offset
:
9381 SKIP_ULEB (start
, block_end
);
9383 case DW_CFA_def_cfa_expression
:
9384 READ_ULEB (temp
, start
, block_end
);
9385 if ((size_t) (block_end
- start
) < temp
)
9390 case DW_CFA_expression
:
9391 case DW_CFA_val_expression
:
9392 READ_ULEB (reg
, start
, block_end
);
9393 READ_ULEB (temp
, start
, block_end
);
9394 if ((size_t) (block_end
- start
) < temp
)
9398 if (frame_need_space (fc
, reg
) >= 0)
9399 fc
->col_type
[reg
] = DW_CFA_undefined
;
9401 case DW_CFA_offset_extended_sf
:
9402 case DW_CFA_val_offset_sf
:
9403 READ_ULEB (reg
, start
, block_end
);
9404 SKIP_SLEB (start
, block_end
);
9405 if (frame_need_space (fc
, reg
) >= 0)
9406 fc
->col_type
[reg
] = DW_CFA_undefined
;
9408 case DW_CFA_def_cfa_sf
:
9409 SKIP_ULEB (start
, block_end
);
9410 SKIP_SLEB (start
, block_end
);
9412 case DW_CFA_def_cfa_offset_sf
:
9413 SKIP_SLEB (start
, block_end
);
9415 case DW_CFA_MIPS_advance_loc8
:
9416 if ((size_t) (block_end
- start
) < 8)
9421 case DW_CFA_GNU_args_size
:
9422 SKIP_ULEB (start
, block_end
);
9424 case DW_CFA_GNU_negative_offset_extended
:
9425 READ_ULEB (reg
, start
, block_end
);
9426 SKIP_ULEB (start
, block_end
);
9427 if (frame_need_space (fc
, reg
) >= 0)
9428 fc
->col_type
[reg
] = DW_CFA_undefined
;
9439 /* Now we know what registers are used, make a second pass over
9440 the chunk, this time actually printing out the info. */
9442 while (start
< block_end
)
9445 unsigned long ul
, roffs
;
9446 /* Note: It is tempting to use an unsigned long for 'reg' but there
9447 are various functions, notably frame_space_needed() that assume that
9448 reg is an unsigned int. */
9453 const char *reg_prefix
= "";
9460 /* Make a note if something other than DW_CFA_nop happens. */
9461 if (op
!= DW_CFA_nop
)
9464 /* Warning: if you add any more cases to this switch, be
9465 sure to add them to the corresponding switch above. */
9468 case DW_CFA_advance_loc
:
9469 if (do_debug_frames_interp
)
9470 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9472 printf (" DW_CFA_advance_loc: %d to %s\n",
9473 opa
* fc
->code_factor
,
9474 dwarf_vmatoa_1 (NULL
,
9475 fc
->pc_begin
+ opa
* fc
->code_factor
,
9477 fc
->pc_begin
+= opa
* fc
->code_factor
;
9481 READ_ULEB (roffs
, start
, block_end
);
9482 if (opa
>= (unsigned int) fc
->ncols
)
9483 reg_prefix
= bad_reg
;
9484 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9485 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9486 reg_prefix
, regname (opa
, 0),
9487 roffs
* fc
->data_factor
);
9488 if (*reg_prefix
== '\0')
9490 fc
->col_type
[opa
] = DW_CFA_offset
;
9491 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9495 case DW_CFA_restore
:
9496 if (opa
>= (unsigned int) fc
->ncols
)
9497 reg_prefix
= bad_reg
;
9498 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9499 printf (" DW_CFA_restore: %s%s\n",
9500 reg_prefix
, regname (opa
, 0));
9501 if (*reg_prefix
!= '\0')
9504 if (opa
>= (unsigned int) cie
->ncols
9505 || (do_debug_frames_interp
9506 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9508 fc
->col_type
[opa
] = DW_CFA_undefined
;
9509 fc
->col_offset
[opa
] = 0;
9513 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9514 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9518 case DW_CFA_set_loc
:
9519 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9521 if (do_debug_frames_interp
)
9522 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9524 printf (" DW_CFA_set_loc: %s\n",
9525 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9529 case DW_CFA_advance_loc1
:
9530 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9531 if (do_debug_frames_interp
)
9532 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9534 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9535 (unsigned long) (ofs
* fc
->code_factor
),
9536 dwarf_vmatoa_1 (NULL
,
9537 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9539 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9542 case DW_CFA_advance_loc2
:
9543 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9544 if (do_debug_frames_interp
)
9545 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9547 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9548 (unsigned long) (ofs
* fc
->code_factor
),
9549 dwarf_vmatoa_1 (NULL
,
9550 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9552 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9555 case DW_CFA_advance_loc4
:
9556 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9557 if (do_debug_frames_interp
)
9558 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9560 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9561 (unsigned long) (ofs
* fc
->code_factor
),
9562 dwarf_vmatoa_1 (NULL
,
9563 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9565 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9568 case DW_CFA_offset_extended
:
9569 READ_ULEB (reg
, start
, block_end
);
9570 READ_ULEB (roffs
, start
, block_end
);
9571 if (reg
>= (unsigned int) fc
->ncols
)
9572 reg_prefix
= bad_reg
;
9573 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9574 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9575 reg_prefix
, regname (reg
, 0),
9576 roffs
* fc
->data_factor
);
9577 if (*reg_prefix
== '\0')
9579 fc
->col_type
[reg
] = DW_CFA_offset
;
9580 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9584 case DW_CFA_val_offset
:
9585 READ_ULEB (reg
, start
, block_end
);
9586 READ_ULEB (roffs
, start
, block_end
);
9587 if (reg
>= (unsigned int) fc
->ncols
)
9588 reg_prefix
= bad_reg
;
9589 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9590 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9591 reg_prefix
, regname (reg
, 0),
9592 roffs
* fc
->data_factor
);
9593 if (*reg_prefix
== '\0')
9595 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9596 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9600 case DW_CFA_restore_extended
:
9601 READ_ULEB (reg
, start
, block_end
);
9602 if (reg
>= (unsigned int) fc
->ncols
)
9603 reg_prefix
= bad_reg
;
9604 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9605 printf (" DW_CFA_restore_extended: %s%s\n",
9606 reg_prefix
, regname (reg
, 0));
9607 if (*reg_prefix
!= '\0')
9610 if (reg
>= (unsigned int) cie
->ncols
)
9612 fc
->col_type
[reg
] = DW_CFA_undefined
;
9613 fc
->col_offset
[reg
] = 0;
9617 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9618 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9622 case DW_CFA_undefined
:
9623 READ_ULEB (reg
, start
, block_end
);
9624 if (reg
>= (unsigned int) fc
->ncols
)
9625 reg_prefix
= bad_reg
;
9626 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9627 printf (" DW_CFA_undefined: %s%s\n",
9628 reg_prefix
, regname (reg
, 0));
9629 if (*reg_prefix
== '\0')
9631 fc
->col_type
[reg
] = DW_CFA_undefined
;
9632 fc
->col_offset
[reg
] = 0;
9636 case DW_CFA_same_value
:
9637 READ_ULEB (reg
, start
, block_end
);
9638 if (reg
>= (unsigned int) fc
->ncols
)
9639 reg_prefix
= bad_reg
;
9640 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9641 printf (" DW_CFA_same_value: %s%s\n",
9642 reg_prefix
, regname (reg
, 0));
9643 if (*reg_prefix
== '\0')
9645 fc
->col_type
[reg
] = DW_CFA_same_value
;
9646 fc
->col_offset
[reg
] = 0;
9650 case DW_CFA_register
:
9651 READ_ULEB (reg
, start
, block_end
);
9652 READ_ULEB (roffs
, start
, block_end
);
9653 if (reg
>= (unsigned int) fc
->ncols
)
9654 reg_prefix
= bad_reg
;
9655 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9657 printf (" DW_CFA_register: %s%s in ",
9658 reg_prefix
, regname (reg
, 0));
9659 puts (regname (roffs
, 0));
9661 if (*reg_prefix
== '\0')
9663 fc
->col_type
[reg
] = DW_CFA_register
;
9664 fc
->col_offset
[reg
] = roffs
;
9668 case DW_CFA_remember_state
:
9669 if (! do_debug_frames_interp
)
9670 printf (" DW_CFA_remember_state\n");
9671 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9672 rs
->cfa_offset
= fc
->cfa_offset
;
9673 rs
->cfa_reg
= fc
->cfa_reg
;
9675 rs
->cfa_exp
= fc
->cfa_exp
;
9676 rs
->ncols
= fc
->ncols
;
9677 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9678 sizeof (* rs
->col_type
));
9679 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9680 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9681 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9682 rs
->next
= remembered_state
;
9683 remembered_state
= rs
;
9686 case DW_CFA_restore_state
:
9687 if (! do_debug_frames_interp
)
9688 printf (" DW_CFA_restore_state\n");
9689 rs
= remembered_state
;
9692 remembered_state
= rs
->next
;
9693 fc
->cfa_offset
= rs
->cfa_offset
;
9694 fc
->cfa_reg
= rs
->cfa_reg
;
9696 fc
->cfa_exp
= rs
->cfa_exp
;
9697 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9699 warn (_("Invalid column number in saved frame state\n"));
9703 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9704 memcpy (fc
->col_offset
, rs
->col_offset
,
9705 rs
->ncols
* sizeof (* rs
->col_offset
));
9706 free (rs
->col_type
);
9707 free (rs
->col_offset
);
9710 else if (do_debug_frames_interp
)
9711 printf ("Mismatched DW_CFA_restore_state\n");
9714 case DW_CFA_def_cfa
:
9715 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9716 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9718 if (! do_debug_frames_interp
)
9719 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9720 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9723 case DW_CFA_def_cfa_register
:
9724 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9726 if (! do_debug_frames_interp
)
9727 printf (" DW_CFA_def_cfa_register: %s\n",
9728 regname (fc
->cfa_reg
, 0));
9731 case DW_CFA_def_cfa_offset
:
9732 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9733 if (! do_debug_frames_interp
)
9734 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9738 if (! do_debug_frames_interp
)
9739 printf (" DW_CFA_nop\n");
9742 case DW_CFA_def_cfa_expression
:
9743 READ_ULEB (ul
, start
, block_end
);
9744 if (ul
> (size_t) (block_end
- start
))
9746 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9749 if (! do_debug_frames_interp
)
9751 printf (" DW_CFA_def_cfa_expression (");
9752 decode_location_expression (start
, eh_addr_size
, 0, -1,
9760 case DW_CFA_expression
:
9761 READ_ULEB (reg
, start
, block_end
);
9762 READ_ULEB (ul
, start
, block_end
);
9763 if (reg
>= (unsigned int) fc
->ncols
)
9764 reg_prefix
= bad_reg
;
9765 /* PR 17512: file: 069-133014-0.006. */
9766 /* PR 17512: file: 98c02eb4. */
9767 if (ul
> (size_t) (block_end
- start
))
9769 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9772 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9774 printf (" DW_CFA_expression: %s%s (",
9775 reg_prefix
, regname (reg
, 0));
9776 decode_location_expression (start
, eh_addr_size
, 0, -1,
9780 if (*reg_prefix
== '\0')
9781 fc
->col_type
[reg
] = DW_CFA_expression
;
9785 case DW_CFA_val_expression
:
9786 READ_ULEB (reg
, start
, block_end
);
9787 READ_ULEB (ul
, start
, block_end
);
9788 if (reg
>= (unsigned int) fc
->ncols
)
9789 reg_prefix
= bad_reg
;
9790 if (ul
> (size_t) (block_end
- start
))
9792 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9795 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9797 printf (" DW_CFA_val_expression: %s%s (",
9798 reg_prefix
, regname (reg
, 0));
9799 decode_location_expression (start
, eh_addr_size
, 0, -1,
9803 if (*reg_prefix
== '\0')
9804 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9808 case DW_CFA_offset_extended_sf
:
9809 READ_ULEB (reg
, start
, block_end
);
9810 READ_SLEB (l
, start
, block_end
);
9811 if (frame_need_space (fc
, reg
) < 0)
9812 reg_prefix
= bad_reg
;
9813 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9814 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9815 reg_prefix
, regname (reg
, 0),
9816 (long)(l
* fc
->data_factor
));
9817 if (*reg_prefix
== '\0')
9819 fc
->col_type
[reg
] = DW_CFA_offset
;
9820 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9824 case DW_CFA_val_offset_sf
:
9825 READ_ULEB (reg
, start
, block_end
);
9826 READ_SLEB (l
, start
, block_end
);
9827 if (frame_need_space (fc
, reg
) < 0)
9828 reg_prefix
= bad_reg
;
9829 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9830 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9831 reg_prefix
, regname (reg
, 0),
9832 (long)(l
* fc
->data_factor
));
9833 if (*reg_prefix
== '\0')
9835 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9836 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9840 case DW_CFA_def_cfa_sf
:
9841 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9842 READ_SLEB (l
, start
, block_end
);
9843 l
*= fc
->data_factor
;
9846 if (! do_debug_frames_interp
)
9847 printf (" DW_CFA_def_cfa_sf: %s ofs %ld\n",
9848 regname (fc
->cfa_reg
, 0), (long) l
);
9851 case DW_CFA_def_cfa_offset_sf
:
9852 READ_SLEB (l
, start
, block_end
);
9853 l
*= fc
->data_factor
;
9855 if (! do_debug_frames_interp
)
9856 printf (" DW_CFA_def_cfa_offset_sf: %ld\n", (long) l
);
9859 case DW_CFA_MIPS_advance_loc8
:
9860 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9861 if (do_debug_frames_interp
)
9862 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9864 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9865 (unsigned long) (ofs
* fc
->code_factor
),
9866 dwarf_vmatoa_1 (NULL
,
9867 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9869 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9872 case DW_CFA_GNU_window_save
:
9873 if (! do_debug_frames_interp
)
9874 printf (" DW_CFA_GNU_window_save\n");
9877 case DW_CFA_GNU_args_size
:
9878 READ_ULEB (ul
, start
, block_end
);
9879 if (! do_debug_frames_interp
)
9880 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9883 case DW_CFA_GNU_negative_offset_extended
:
9884 READ_ULEB (reg
, start
, block_end
);
9885 READ_SLEB (l
, start
, block_end
);
9887 if (frame_need_space (fc
, reg
) < 0)
9888 reg_prefix
= bad_reg
;
9889 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9890 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9891 reg_prefix
, regname (reg
, 0),
9892 (long)(l
* fc
->data_factor
));
9893 if (*reg_prefix
== '\0')
9895 fc
->col_type
[reg
] = DW_CFA_offset
;
9896 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9901 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9902 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9904 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9909 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9910 if (do_debug_frames_interp
&& ! all_nops
)
9911 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9913 if (fde_fc
.col_type
!= NULL
)
9915 free (fde_fc
.col_type
);
9916 fde_fc
.col_type
= NULL
;
9918 if (fde_fc
.col_offset
!= NULL
)
9920 free (fde_fc
.col_offset
);
9921 fde_fc
.col_offset
= NULL
;
9925 eh_addr_size
= saved_eh_addr_size
;
9930 while (remembered_state
!= NULL
)
9932 rs
= remembered_state
;
9933 remembered_state
= rs
->next
;
9934 free (rs
->col_type
);
9935 free (rs
->col_offset
);
9936 rs
->next
= NULL
; /* Paranoia. */
9940 while (chunks
!= NULL
)
9944 free (rs
->col_type
);
9945 free (rs
->col_offset
);
9946 rs
->next
= NULL
; /* Paranoia. */
9950 while (forward_refs
!= NULL
)
9953 forward_refs
= rs
->next
;
9954 free (rs
->col_type
);
9955 free (rs
->col_offset
);
9956 rs
->next
= NULL
; /* Paranoia. */
9966 display_debug_names (struct dwarf_section
*section
, void *file
)
9968 unsigned char *hdrptr
= section
->start
;
9969 dwarf_vma unit_length
;
9970 unsigned char *unit_start
;
9971 const unsigned char *const section_end
= section
->start
+ section
->size
;
9972 unsigned char *unit_end
;
9974 introduce (section
, false);
9976 load_debug_section_with_follow (str
, file
);
9978 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9980 unsigned int offset_size
;
9981 uint16_t dwarf_version
, padding
;
9982 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9983 uint64_t bucket_count
, name_count
, abbrev_table_size
;
9984 uint32_t augmentation_string_size
;
9986 bool augmentation_printable
;
9987 const char *augmentation_string
;
9990 unit_start
= hdrptr
;
9992 /* Get and check the length of the block. */
9993 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9995 if (unit_length
== 0xffffffff)
9997 /* This section is 64-bit DWARF. */
9998 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10004 if (unit_length
> (size_t) (section_end
- hdrptr
)
10005 || unit_length
< 2 + 2 + 4 * 7)
10008 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
10010 (unsigned long) (unit_start
- section
->start
),
10011 dwarf_vmatoa ("x", unit_length
));
10014 unit_end
= hdrptr
+ unit_length
;
10016 /* Get and check the version number. */
10017 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10018 printf (_("Version %ld\n"), (long) dwarf_version
);
10020 /* Prior versions did not exist, and future versions may not be
10021 backwards compatible. */
10022 if (dwarf_version
!= 5)
10024 warn (_("Only DWARF version 5 .debug_names "
10025 "is currently supported.\n"));
10029 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10031 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10034 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10035 if (comp_unit_count
== 0)
10036 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10038 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10039 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10040 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10041 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10042 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10044 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10045 if (augmentation_string_size
% 4 != 0)
10047 warn (_("Augmentation string length %u must be rounded up "
10048 "to a multiple of 4 in .debug_names.\n"),
10049 augmentation_string_size
);
10050 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10052 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10055 printf (_("Augmentation string:"));
10057 augmentation_printable
= true;
10058 augmentation_string
= (const char *) hdrptr
;
10060 for (i
= 0; i
< augmentation_string_size
; i
++)
10064 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10065 printf (" %02x", uc
);
10067 if (uc
!= 0 && !ISPRINT (uc
))
10068 augmentation_printable
= false;
10071 if (augmentation_printable
)
10075 i
< augmentation_string_size
&& augmentation_string
[i
];
10077 putchar (augmentation_string
[i
]);
10082 printf (_("CU table:\n"));
10083 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10084 || total
> (size_t) (unit_end
- hdrptr
))
10086 for (i
= 0; i
< comp_unit_count
; i
++)
10088 uint64_t cu_offset
;
10090 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10091 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
10095 printf (_("TU table:\n"));
10096 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10097 || total
> (size_t) (unit_end
- hdrptr
))
10099 for (i
= 0; i
< local_type_unit_count
; i
++)
10101 uint64_t tu_offset
;
10103 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10104 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
10108 printf (_("Foreign TU table:\n"));
10109 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10110 || total
> (size_t) (unit_end
- hdrptr
))
10112 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10114 uint64_t signature
;
10116 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10117 printf (_("[%3u] "), i
);
10118 print_dwarf_vma (signature
, 8);
10123 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10124 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10125 + abbrev_table_size
);
10126 if (xtra
> (size_t) (unit_end
- hdrptr
))
10128 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
10129 "for unit 0x%lx in the debug_names\n"),
10131 (long) (unit_end
- unit_start
),
10132 (long) (unit_start
- section
->start
));
10135 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10136 hdrptr
+= bucket_count
* sizeof (uint32_t);
10137 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10138 hdrptr
+= name_count
* sizeof (uint32_t);
10139 unsigned char *const name_table_string_offsets
= hdrptr
;
10140 hdrptr
+= name_count
* offset_size
;
10141 unsigned char *const name_table_entry_offsets
= hdrptr
;
10142 hdrptr
+= name_count
* offset_size
;
10143 unsigned char *const abbrev_table
= hdrptr
;
10144 hdrptr
+= abbrev_table_size
;
10145 const unsigned char *const abbrev_table_end
= hdrptr
;
10146 unsigned char *const entry_pool
= hdrptr
;
10148 size_t buckets_filled
= 0;
10150 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10152 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10157 printf (ngettext ("Used %zu of %lu bucket.\n",
10158 "Used %zu of %lu buckets.\n",
10160 buckets_filled
, (unsigned long) bucket_count
);
10162 if (bucket_count
!= 0)
10164 uint32_t hash_prev
= 0;
10165 size_t hash_clash_count
= 0;
10166 size_t longest_clash
= 0;
10167 size_t this_length
= 0;
10169 for (hashi
= 0; hashi
< name_count
; hashi
++)
10171 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10175 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10177 ++hash_clash_count
;
10179 longest_clash
= MAX (longest_clash
, this_length
);
10184 hash_prev
= hash_this
;
10186 printf (_("Out of %lu items there are %zu bucket clashes"
10187 " (longest of %zu entries).\n"),
10188 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
10189 assert (name_count
== buckets_filled
+ hash_clash_count
);
10192 struct abbrev_lookup_entry
10194 dwarf_vma abbrev_tag
;
10195 unsigned char *abbrev_lookup_ptr
;
10197 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10198 size_t abbrev_lookup_used
= 0;
10199 size_t abbrev_lookup_allocated
= 0;
10201 unsigned char *abbrevptr
= abbrev_table
;
10204 dwarf_vma abbrev_tag
;
10206 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10207 if (abbrev_tag
== 0)
10209 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10211 abbrev_lookup_allocated
= MAX (0x100,
10212 abbrev_lookup_allocated
* 2);
10213 abbrev_lookup
= xrealloc (abbrev_lookup
,
10214 (abbrev_lookup_allocated
10215 * sizeof (*abbrev_lookup
)));
10217 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10218 struct abbrev_lookup_entry
*entry
;
10219 for (entry
= abbrev_lookup
;
10220 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10222 if (entry
->abbrev_tag
== abbrev_tag
)
10224 warn (_("Duplicate abbreviation tag %lu "
10225 "in unit 0x%lx in the debug_names\n"),
10226 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
10229 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10230 entry
->abbrev_tag
= abbrev_tag
;
10231 entry
->abbrev_lookup_ptr
= abbrevptr
;
10233 /* Skip DWARF tag. */
10234 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10237 dwarf_vma xindex
, form
;
10239 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10240 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10241 if (xindex
== 0 && form
== 0)
10246 printf (_("\nSymbol table:\n"));
10248 for (namei
= 0; namei
< name_count
; ++namei
)
10250 uint64_t string_offset
, entry_offset
;
10253 p
= name_table_string_offsets
+ namei
* offset_size
;
10254 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10255 p
= name_table_entry_offsets
+ namei
* offset_size
;
10256 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10258 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10259 fetch_indirect_string (string_offset
));
10261 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10263 /* We need to scan first whether there is a single or multiple
10264 entries. TAGNO is -2 for the first entry, it is -1 for the
10265 initial tag read of the second entry, then it becomes 0 for the
10266 first entry for real printing etc. */
10268 /* Initialize it due to a false compiler warning. */
10269 dwarf_vma second_abbrev_tag
= -1;
10272 dwarf_vma abbrev_tag
;
10273 dwarf_vma dwarf_tag
;
10274 const struct abbrev_lookup_entry
*entry
;
10276 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10279 second_abbrev_tag
= abbrev_tag
;
10281 entryptr
= entry_pool
+ entry_offset
;
10284 if (abbrev_tag
== 0)
10288 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10289 (unsigned long) abbrev_tag
);
10291 for (entry
= abbrev_lookup
;
10292 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10294 if (entry
->abbrev_tag
== abbrev_tag
)
10296 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10298 warn (_("Undefined abbreviation tag %lu "
10299 "in unit 0x%lx in the debug_names\n"),
10301 (long) (unit_start
- section
->start
));
10304 abbrevptr
= entry
->abbrev_lookup_ptr
;
10305 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10307 printf (" %s", get_TAG_name (dwarf_tag
));
10310 dwarf_vma xindex
, form
;
10312 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10313 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10314 if (xindex
== 0 && form
== 0)
10318 printf (" %s", get_IDX_name (xindex
));
10319 entryptr
= read_and_display_attr_value (0, form
, 0,
10320 unit_start
, entryptr
, unit_end
,
10322 dwarf_version
, NULL
,
10323 (tagno
< 0), section
,
10329 printf (_(" <no entries>"));
10333 free (abbrev_lookup
);
10340 display_debug_links (struct dwarf_section
* section
,
10341 void * file ATTRIBUTE_UNUSED
)
10343 const unsigned char * filename
;
10344 unsigned int filelen
;
10346 introduce (section
, false);
10348 /* The .gnu_debuglink section is formatted as:
10349 (c-string) Filename.
10350 (padding) If needed to reach a 4 byte boundary.
10351 (uint32_t) CRC32 value.
10353 The .gun_debugaltlink section is formatted as:
10354 (c-string) Filename.
10355 (binary) Build-ID. */
10357 filename
= section
->start
;
10358 filelen
= strnlen ((const char *) filename
, section
->size
);
10359 if (filelen
== section
->size
)
10361 warn (_("The debuglink filename is corrupt/missing\n"));
10365 printf (_(" Separate debug info file: %s\n"), filename
);
10367 if (startswith (section
->name
, ".gnu_debuglink"))
10369 unsigned int crc32
;
10370 unsigned int crc_offset
;
10372 crc_offset
= filelen
+ 1;
10373 crc_offset
= (crc_offset
+ 3) & ~3;
10374 if (crc_offset
+ 4 > section
->size
)
10376 warn (_("CRC offset missing/truncated\n"));
10380 crc32
= byte_get (filename
+ crc_offset
, 4);
10382 printf (_(" CRC value: %#x\n"), crc32
);
10384 if (crc_offset
+ 4 < section
->size
)
10386 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10387 (long)(section
->size
- (crc_offset
+ 4)));
10391 else /* startswith (section->name, ".gnu_debugaltlink") */
10393 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
10394 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
10395 bfd_size_type printed
;
10397 /* FIXME: Should we support smaller build-id notes ? */
10398 if (build_id_len
< 0x14)
10400 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
10404 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
10405 display_data (printed
, build_id
, build_id_len
);
10414 display_gdb_index (struct dwarf_section
*section
,
10415 void *file ATTRIBUTE_UNUSED
)
10417 unsigned char *start
= section
->start
;
10419 uint32_t cu_list_offset
, tu_list_offset
;
10420 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10421 unsigned int cu_list_elements
, tu_list_elements
;
10422 unsigned int address_table_elements
, symbol_table_slots
;
10423 unsigned char *cu_list
, *tu_list
;
10424 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10427 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10429 introduce (section
, false);
10431 if (section
->size
< 6 * sizeof (uint32_t))
10433 warn (_("Truncated header in the %s section.\n"), section
->name
);
10437 version
= byte_get_little_endian (start
, 4);
10438 printf (_("Version %ld\n"), (long) version
);
10440 /* Prior versions are obsolete, and future versions may not be
10441 backwards compatible. */
10442 if (version
< 3 || version
> 8)
10444 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10448 warn (_("The address table data in version 3 may be wrong.\n"));
10450 warn (_("Version 4 does not support case insensitive lookups.\n"));
10452 warn (_("Version 5 does not include inlined functions.\n"));
10454 warn (_("Version 6 does not include symbol attributes.\n"));
10455 /* Version 7 indices generated by Gold have bad type unit references,
10456 PR binutils/15021. But we don't know if the index was generated by
10457 Gold or not, so to avoid worrying users with gdb-generated indices
10458 we say nothing for version 7 here. */
10460 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10461 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10462 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10463 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10464 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10466 if (cu_list_offset
> section
->size
10467 || tu_list_offset
> section
->size
10468 || address_table_offset
> section
->size
10469 || symbol_table_offset
> section
->size
10470 || constant_pool_offset
> section
->size
10471 || tu_list_offset
< cu_list_offset
10472 || address_table_offset
< tu_list_offset
10473 || symbol_table_offset
< address_table_offset
10474 || constant_pool_offset
< symbol_table_offset
)
10476 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10480 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10481 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10482 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10483 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10485 cu_list
= start
+ cu_list_offset
;
10486 tu_list
= start
+ tu_list_offset
;
10487 address_table
= start
+ address_table_offset
;
10488 symbol_table
= start
+ symbol_table_offset
;
10489 constant_pool
= start
+ constant_pool_offset
;
10491 printf (_("\nCU table:\n"));
10492 for (i
= 0; i
< cu_list_elements
; i
++)
10494 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10495 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10497 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
,
10498 (unsigned long) cu_offset
,
10499 (unsigned long) (cu_offset
+ cu_length
- 1));
10502 printf (_("\nTU table:\n"));
10503 for (i
= 0; i
< tu_list_elements
; i
++)
10505 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10506 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10507 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10509 printf (_("[%3u] 0x%lx 0x%lx "), i
,
10510 (unsigned long) tu_offset
,
10511 (unsigned long) type_offset
);
10512 print_dwarf_vma (signature
, 8);
10516 printf (_("\nAddress table:\n"));
10517 for (i
= 0; i
< address_table_elements
; i
++)
10519 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10520 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10521 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 20 + 16, 4);
10523 print_dwarf_vma (low
, 8);
10524 print_dwarf_vma (high
, 8);
10525 printf (_("%lu\n"), (unsigned long) cu_index
);
10528 printf (_("\nSymbol table:\n"));
10529 for (i
= 0; i
< symbol_table_slots
; ++i
)
10531 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10532 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10533 uint32_t num_cus
, cu
;
10535 if (name_offset
!= 0
10536 || cu_vector_offset
!= 0)
10540 /* PR 17531: file: 5b7b07ad. */
10541 if (name_offset
>= section
->size
- constant_pool_offset
)
10543 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10544 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10548 printf ("[%3u] %.*s:", i
,
10549 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10550 constant_pool
+ name_offset
);
10552 if (section
->size
- constant_pool_offset
< 4
10553 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10555 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10556 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10557 cu_vector_offset
, i
);
10561 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10563 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10564 + cu_vector_offset
+ 4))
10566 printf ("<invalid number of CUs: %d>\n", num_cus
);
10567 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10575 for (j
= 0; j
< num_cus
; ++j
)
10578 gdb_index_symbol_kind kind
;
10580 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10581 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10582 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10583 cu
= GDB_INDEX_CU_VALUE (cu
);
10584 /* Convert to TU number if it's for a type unit. */
10585 if (cu
>= cu_list_elements
/ 2)
10586 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10587 (unsigned long) (cu
- cu_list_elements
/ 2));
10589 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10591 printf (" [%s, %s]",
10592 is_static
? _("static") : _("global"),
10593 get_gdb_index_symbol_kind_name (kind
));
10605 /* Pre-allocate enough space for the CU/TU sets needed. */
10608 prealloc_cu_tu_list (unsigned int nshndx
)
10610 if (shndx_pool
== NULL
)
10612 shndx_pool_size
= nshndx
;
10613 shndx_pool_used
= 0;
10614 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10615 sizeof (unsigned int));
10619 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10620 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10621 sizeof (unsigned int));
10626 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10628 if (shndx_pool_used
>= shndx_pool_size
)
10630 error (_("Internal error: out of space in the shndx pool.\n"));
10633 shndx_pool
[shndx_pool_used
++] = shndx
;
10637 end_cu_tu_entry (void)
10639 if (shndx_pool_used
>= shndx_pool_size
)
10641 error (_("Internal error: out of space in the shndx pool.\n"));
10644 shndx_pool
[shndx_pool_used
++] = 0;
10647 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10649 static const char *
10650 get_DW_SECT_short_name (unsigned int dw_sect
)
10652 static char buf
[16];
10658 case DW_SECT_TYPES
:
10660 case DW_SECT_ABBREV
:
10666 case DW_SECT_STR_OFFSETS
:
10668 case DW_SECT_MACINFO
:
10670 case DW_SECT_MACRO
:
10676 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10680 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10681 These sections are extensions for Fission.
10682 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10685 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10687 unsigned char *phdr
= section
->start
;
10688 unsigned char *limit
= phdr
+ section
->size
;
10689 unsigned char *phash
;
10690 unsigned char *pindex
;
10691 unsigned char *ppool
;
10692 unsigned int version
;
10693 unsigned int ncols
= 0;
10694 unsigned int nused
;
10695 unsigned int nslots
;
10698 dwarf_vma signature
;
10701 /* PR 17512: file: 002-168123-0.004. */
10704 warn (_("Section %s is empty\n"), section
->name
);
10707 /* PR 17512: file: 002-376-0.004. */
10708 if (section
->size
< 24)
10710 warn (_("Section %s is too small to contain a CU/TU header\n"),
10716 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10718 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10719 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10720 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10722 pindex
= phash
+ (size_t) nslots
* 8;
10723 ppool
= pindex
+ (size_t) nslots
* 4;
10727 introduce (section
, false);
10729 printf (_(" Version: %u\n"), version
);
10731 printf (_(" Number of columns: %u\n"), ncols
);
10732 printf (_(" Number of used entries: %u\n"), nused
);
10733 printf (_(" Number of slots: %u\n\n"), nslots
);
10736 /* PR 17531: file: 45d69832. */
10737 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10738 || total
> (size_t) (limit
- phash
))
10740 warn (ngettext ("Section %s is too small for %u slot\n",
10741 "Section %s is too small for %u slots\n",
10743 section
->name
, nslots
);
10750 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10751 for (i
= 0; i
< nslots
; i
++)
10753 unsigned char *shndx_list
;
10754 unsigned int shndx
;
10756 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10757 if (signature
!= 0)
10759 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10760 shndx_list
= ppool
+ j
* 4;
10761 /* PR 17531: file: 705e010d. */
10762 if (shndx_list
< ppool
)
10764 warn (_("Section index pool located before start of section\n"));
10769 printf (_(" [%3d] Signature: 0x%s Sections: "),
10770 i
, dwarf_vmatoa ("x", signature
));
10773 if (shndx_list
>= limit
)
10775 warn (_("Section %s too small for shndx pool\n"),
10779 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10783 printf (" %d", shndx
);
10785 add_shndx_to_cu_tu_entry (shndx
);
10791 end_cu_tu_entry ();
10797 else if (version
== 2)
10800 unsigned int dw_sect
;
10801 unsigned char *ph
= phash
;
10802 unsigned char *pi
= pindex
;
10803 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10804 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10806 struct cu_tu_set
*this_set
= NULL
;
10808 unsigned char *prow
;
10811 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10813 /* PR 17531: file: 0dd159bf.
10814 Check for integer overflow (can occur when size_t is 32-bit)
10815 with overlarge ncols or nused values. */
10817 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10818 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10819 || total
> (size_t) (limit
- ppool
))
10821 warn (_("Section %s too small for offset and size tables\n"),
10828 printf (_(" Offset table\n"));
10829 printf (" slot %-16s ",
10830 is_tu_index
? _("signature") : _("dwo_id"));
10837 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10838 this_set
= tu_sets
;
10843 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10844 this_set
= cu_sets
;
10850 for (j
= 0; j
< ncols
; j
++)
10852 unsigned char *p
= ppool
+ j
* 4;
10853 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10854 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10859 for (i
= 0; i
< nslots
; i
++)
10861 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10863 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10866 /* PR 17531: file: a05f6ab3. */
10869 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10876 size_t num_copy
= sizeof (uint64_t);
10878 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10881 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10883 printf (_(" [%3d] 0x%s"),
10884 i
, dwarf_vmatoa ("x", signature
));
10885 for (j
= 0; j
< ncols
; j
++)
10887 unsigned char *p
= prow
+ j
* 4;
10888 SAFE_BYTE_GET (val
, p
, 4, limit
);
10890 printf (" %8d", val
);
10894 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10896 /* PR 17531: file: 10796eb3. */
10897 if (dw_sect
>= DW_SECT_MAX
)
10898 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10900 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10916 printf (_(" Size table\n"));
10917 printf (" slot %-16s ",
10918 is_tu_index
? _("signature") : _("dwo_id"));
10921 for (j
= 0; j
< ncols
; j
++)
10923 unsigned char *p
= ppool
+ j
* 4;
10924 SAFE_BYTE_GET (val
, p
, 4, limit
);
10926 printf (" %8s", get_DW_SECT_short_name (val
));
10932 for (i
= 0; i
< nslots
; i
++)
10934 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10936 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10939 prow
= psizes
+ (row
- 1) * ncols
* 4;
10942 printf (_(" [%3d] 0x%s"),
10943 i
, dwarf_vmatoa ("x", signature
));
10945 for (j
= 0; j
< ncols
; j
++)
10947 unsigned char *p
= prow
+ j
* 4;
10949 /* PR 28645: Check for overflow. Since we do not know how
10950 many populated rows there will be, we cannot just
10951 perform a single check at the start of this function. */
10952 if (p
> (limit
- 4))
10956 warn (_("Too many rows/columns in DWARF index section %s\n"),
10961 SAFE_BYTE_GET (val
, p
, 4, limit
);
10964 printf (" %8d", val
);
10968 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10969 if (dw_sect
>= DW_SECT_MAX
)
10970 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10972 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10984 else if (do_display
)
10985 printf (_(" Unsupported version (%d)\n"), version
);
10993 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10995 /* Load the CU and TU indexes if present. This will build a list of
10996 section sets that we can use to associate a .debug_info.dwo section
10997 with its associated .debug_abbrev.dwo section in a .dwp file. */
11000 load_cu_tu_indexes (void *file
)
11002 /* If we have already loaded (or tried to load) the CU and TU indexes
11003 then do not bother to repeat the task. */
11004 if (cu_tu_indexes_read
== -1)
11006 cu_tu_indexes_read
= true;
11008 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11009 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11010 cu_tu_indexes_read
= false;
11012 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11013 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11014 cu_tu_indexes_read
= false;
11017 return (bool) cu_tu_indexes_read
;
11020 /* Find the set of sections that includes section SHNDX. */
11023 find_cu_tu_set (void *file
, unsigned int shndx
)
11027 if (! load_cu_tu_indexes (file
))
11030 /* Find SHNDX in the shndx pool. */
11031 for (i
= 0; i
< shndx_pool_used
; i
++)
11032 if (shndx_pool
[i
] == shndx
)
11035 if (i
>= shndx_pool_used
)
11038 /* Now backup to find the first entry in the set. */
11039 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11042 return shndx_pool
+ i
;
11045 /* Display a .debug_cu_index or .debug_tu_index section. */
11048 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11050 return process_cu_tu_index (section
, 1);
11054 display_debug_not_supported (struct dwarf_section
*section
,
11055 void *file ATTRIBUTE_UNUSED
)
11057 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11063 /* Like malloc, but takes two parameters like calloc.
11064 Verifies that the first parameter is not too large.
11065 Note: does *not* initialise the allocated memory to zero. */
11068 cmalloc (size_t nmemb
, size_t size
)
11070 /* Check for overflow. */
11071 if (nmemb
>= ~(size_t) 0 / size
)
11074 return xmalloc (nmemb
* size
);
11077 /* Like xmalloc, but takes two parameters like calloc.
11078 Verifies that the first parameter is not too large.
11079 Note: does *not* initialise the allocated memory to zero. */
11082 xcmalloc (size_t nmemb
, size_t size
)
11084 /* Check for overflow. */
11085 if (nmemb
>= ~(size_t) 0 / size
)
11088 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
11093 return xmalloc (nmemb
* size
);
11096 /* Like xrealloc, but takes three parameters.
11097 Verifies that the second parameter is not too large.
11098 Note: does *not* initialise any new memory to zero. */
11101 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
11103 /* Check for overflow. */
11104 if (nmemb
>= ~(size_t) 0 / size
)
11106 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
11111 return xrealloc (ptr
, nmemb
* size
);
11114 /* Like xcalloc, but verifies that the first parameter is not too large. */
11117 xcalloc2 (size_t nmemb
, size_t size
)
11119 /* Check for overflow. */
11120 if (nmemb
>= ~(size_t) 0 / size
)
11122 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
11127 return xcalloc (nmemb
, size
);
11130 static unsigned long
11131 calc_gnu_debuglink_crc32 (unsigned long crc
,
11132 const unsigned char * buf
,
11135 static const unsigned long crc32_table
[256] =
11137 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11138 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11139 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11140 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11141 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11142 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11143 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11144 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11145 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11146 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11147 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11148 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11149 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11150 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11151 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11152 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11153 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11154 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11155 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11156 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11157 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11158 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11159 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11160 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11161 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11162 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11163 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11164 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11165 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11166 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11167 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11168 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11169 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11170 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11171 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11172 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11173 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11174 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11175 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11176 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11177 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11178 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11179 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11180 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11181 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11182 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11183 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11184 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11185 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11186 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11187 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11190 const unsigned char *end
;
11192 crc
= ~crc
& 0xffffffff;
11193 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11194 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11195 return ~crc
& 0xffffffff;
11198 typedef bool (*check_func_type
) (const char *, void *);
11199 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11202 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11204 static unsigned char buffer
[8 * 1024];
11206 bfd_size_type count
;
11207 unsigned long crc
= 0;
11210 sep_data
= open_debug_file (pathname
);
11211 if (sep_data
== NULL
)
11214 /* Yes - we are opening the file twice... */
11215 f
= fopen (pathname
, "rb");
11218 /* Paranoia: This should never happen. */
11219 close_debug_file (sep_data
);
11220 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11224 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11225 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11229 if (crc
!= * (unsigned long *) crc_pointer
)
11231 close_debug_file (sep_data
);
11232 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11240 static const char *
11241 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11244 unsigned int crc_offset
;
11245 unsigned long * crc32
= (unsigned long *) data
;
11247 /* The name is first.
11248 The CRC value is stored after the filename, aligned up to 4 bytes. */
11249 name
= (const char *) section
->start
;
11251 crc_offset
= strnlen (name
, section
->size
) + 1;
11252 if (crc_offset
== 1)
11254 crc_offset
= (crc_offset
+ 3) & ~3;
11255 if (crc_offset
+ 4 > section
->size
)
11258 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11263 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11265 void * sep_data
= open_debug_file (filename
);
11267 if (sep_data
== NULL
)
11270 /* FIXME: We should now extract the build-id in the separate file
11276 typedef struct build_id_data
11279 const unsigned char * data
;
11282 static const char *
11283 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11286 bfd_size_type namelen
;
11287 bfd_size_type id_len
;
11288 Build_id_data
* build_id_data
;
11290 /* The name is first.
11291 The build-id follows immediately, with no padding, up to the section's end. */
11293 name
= (const char *) section
->start
;
11294 namelen
= strnlen (name
, section
->size
) + 1;
11297 if (namelen
>= section
->size
)
11300 id_len
= section
->size
- namelen
;
11304 build_id_data
= (Build_id_data
*) data
;
11305 build_id_data
->len
= id_len
;
11306 build_id_data
->data
= section
->start
+ namelen
;
11312 add_separate_debug_file (const char * filename
, void * handle
)
11314 separate_info
* i
= xmalloc (sizeof * i
);
11316 i
->filename
= filename
;
11317 i
->handle
= handle
;
11318 i
->next
= first_separate_info
;
11319 first_separate_info
= i
;
11322 #if HAVE_LIBDEBUGINFOD
11323 /* Query debuginfod servers for the target debuglink or debugaltlink
11324 file. If successful, store the path of the file in filename and
11325 return TRUE, otherwise return FALSE. */
11328 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11332 size_t build_id_len
;
11333 unsigned char * build_id
;
11335 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11337 /* Get the build-id of file. */
11338 build_id
= get_build_id (file
);
11341 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11343 /* Get the build-id of the debugaltlink file. */
11344 unsigned int filelen
;
11346 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11347 if (filelen
== section
->size
)
11348 /* Corrupt debugaltlink. */
11351 build_id
= section
->start
+ filelen
+ 1;
11352 build_id_len
= section
->size
- (filelen
+ 1);
11354 if (build_id_len
== 0)
11363 debuginfod_client
* client
;
11365 client
= debuginfod_begin ();
11366 if (client
== NULL
)
11369 /* Query debuginfod servers for the target file. If found its path
11370 will be stored in filename. */
11371 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11372 debuginfod_end (client
);
11374 /* Only free build_id if we allocated space for a hex string
11375 in get_build_id (). */
11376 if (build_id_len
== 0)
11381 /* File successfully retrieved. Close fd since we want to
11382 use open_debug_file () on filename instead. */
11390 #endif /* HAVE_LIBDEBUGINFOD */
11393 load_separate_debug_info (const char * main_filename
,
11394 struct dwarf_section
* xlink
,
11395 parse_func_type parse_func
,
11396 check_func_type check_func
,
11398 void * file ATTRIBUTE_UNUSED
)
11400 const char * separate_filename
;
11401 char * debug_filename
;
11403 size_t canon_dirlen
;
11405 char * canon_filename
;
11406 char * canon_debug_filename
;
11409 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11411 warn (_("Corrupt debuglink section: %s\n"),
11412 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11416 /* Attempt to locate the separate file.
11417 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11419 canon_filename
= lrealpath (main_filename
);
11420 canon_dir
= xstrdup (canon_filename
);
11422 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11423 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11425 canon_dir
[canon_dirlen
] = '\0';
11428 #define DEBUGDIR "/lib/debug"
11430 #ifndef EXTRA_DEBUG_ROOT1
11431 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11433 #ifndef EXTRA_DEBUG_ROOT2
11434 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11437 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11439 + strlen (".debug/")
11440 #ifdef EXTRA_DEBUG_ROOT1
11441 + strlen (EXTRA_DEBUG_ROOT1
)
11443 #ifdef EXTRA_DEBUG_ROOT2
11444 + strlen (EXTRA_DEBUG_ROOT2
)
11446 + strlen (separate_filename
)
11448 if (debug_filename
== NULL
)
11450 warn (_("Out of memory"));
11452 free (canon_filename
);
11456 /* First try in the current directory. */
11457 sprintf (debug_filename
, "%s", separate_filename
);
11458 if (check_func (debug_filename
, func_data
))
11461 /* Then try in a subdirectory called .debug. */
11462 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11463 if (check_func (debug_filename
, func_data
))
11466 /* Then try in the same directory as the original file. */
11467 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11468 if (check_func (debug_filename
, func_data
))
11471 /* And the .debug subdirectory of that directory. */
11472 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11473 if (check_func (debug_filename
, func_data
))
11476 #ifdef EXTRA_DEBUG_ROOT1
11477 /* Try the first extra debug file root. */
11478 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11479 if (check_func (debug_filename
, func_data
))
11482 /* Try the first extra debug file root. */
11483 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11484 if (check_func (debug_filename
, func_data
))
11488 #ifdef EXTRA_DEBUG_ROOT2
11489 /* Try the second extra debug file root. */
11490 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11491 if (check_func (debug_filename
, func_data
))
11495 /* Then try in the global debug_filename directory. */
11496 strcpy (debug_filename
, DEBUGDIR
);
11497 dirlen
= strlen (DEBUGDIR
) - 1;
11498 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11499 strcat (debug_filename
, "/");
11500 strcat (debug_filename
, (const char *) separate_filename
);
11502 if (check_func (debug_filename
, func_data
))
11505 #if HAVE_LIBDEBUGINFOD
11507 char * tmp_filename
;
11510 && debuginfod_fetch_separate_debug_info (xlink
,
11514 /* File successfully downloaded from server, replace
11515 debug_filename with the file's path. */
11516 free (debug_filename
);
11517 debug_filename
= tmp_filename
;
11523 if (do_debug_links
)
11525 /* Failed to find the file. */
11526 warn (_("could not find separate debug file '%s'\n"),
11527 separate_filename
);
11528 warn (_("tried: %s\n"), debug_filename
);
11530 #ifdef EXTRA_DEBUG_ROOT2
11531 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11532 separate_filename
);
11533 warn (_("tried: %s\n"), debug_filename
);
11536 #ifdef EXTRA_DEBUG_ROOT1
11537 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11538 canon_dir
, separate_filename
);
11539 warn (_("tried: %s\n"), debug_filename
);
11541 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11542 separate_filename
);
11543 warn (_("tried: %s\n"), debug_filename
);
11546 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11547 separate_filename
);
11548 warn (_("tried: %s\n"), debug_filename
);
11550 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11551 warn (_("tried: %s\n"), debug_filename
);
11553 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11554 warn (_("tried: %s\n"), debug_filename
);
11556 sprintf (debug_filename
, "%s", separate_filename
);
11557 warn (_("tried: %s\n"), debug_filename
);
11559 #if HAVE_LIBDEBUGINFOD
11560 if (use_debuginfod
)
11562 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11567 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11573 free (debug_filename
);
11574 free (canon_filename
);
11580 canon_debug_filename
= lrealpath (debug_filename
);
11581 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11582 free (canon_filename
);
11583 free (canon_debug_filename
);
11586 free (debug_filename
);
11590 void * debug_handle
;
11592 /* Now open the file.... */
11593 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11595 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11596 free (debug_filename
);
11600 /* FIXME: We do not check to see if there are any other separate debug info
11601 files that would also match. */
11603 if (do_debug_links
)
11604 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11605 add_separate_debug_file (debug_filename
, debug_handle
);
11607 /* Do not free debug_filename - it might be referenced inside
11608 the structure returned by open_debug_file(). */
11609 return debug_handle
;
11612 /* Attempt to load a separate dwarf object file. */
11615 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11617 char * separate_filename
;
11618 void * separate_handle
;
11620 if (IS_ABSOLUTE_PATH (name
))
11621 separate_filename
= strdup (name
);
11623 /* FIXME: Skip adding / if dwo_dir ends in /. */
11624 separate_filename
= concat (dir
, "/", name
, NULL
);
11625 if (separate_filename
== NULL
)
11627 warn (_("Out of memory allocating dwo filename\n"));
11631 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11633 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11634 free (separate_filename
);
11638 /* FIXME: We should check the dwo_id. */
11640 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11642 add_separate_debug_file (separate_filename
, separate_handle
);
11643 /* Note - separate_filename will be freed in free_debug_memory(). */
11644 return separate_handle
;
11648 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11650 char * f
= filename
;
11652 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11655 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11656 strcpy (f
, ".debug");
11658 return open_debug_file (filename
);
11661 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11664 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11666 if (! load_debug_section (note_gnu_build_id
, main_file
))
11667 return; /* No .note.gnu.build-id section. */
11669 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11670 if (section
== NULL
)
11672 warn (_("Unable to load the .note.gnu.build-id section\n"));
11676 if (section
->start
== NULL
|| section
->size
< 0x18)
11678 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11682 /* In theory we should extract the contents of the section into
11683 a note structure and then check the fields. For now though
11684 just use hard coded offsets instead:
11686 Field Bytes Contents
11689 Type 8..11 3 (NT_GNU_BUILD_ID)
11693 /* FIXME: Check the name size, name and type fields. */
11695 unsigned long build_id_size
;
11696 build_id_size
= byte_get (section
->start
+ 4, 4);
11697 if (build_id_size
< 8)
11699 warn (_(".note.gnu.build-id data size is too small\n"));
11703 if (build_id_size
> (section
->size
- 16))
11705 warn (_(".note.gnu.build-id data size is too bug\n"));
11710 filename
= xmalloc (strlen (".build-id/")
11711 + build_id_size
* 2 + 2
11712 + strlen (".debug")
11713 /* The next string should be the same as the longest
11714 name found in the prefixes[] array below. */
11715 + strlen ("/usrlib64/debug/usr")
11719 static const char * prefixes
[] =
11724 "/usr/lib/debug/usr/",
11725 "/usr/lib64/debug/",
11726 "/usr/lib64/debug/usr"
11728 long unsigned int i
;
11730 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11732 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11733 section
->start
+ 16, build_id_size
);
11734 if (handle
!= NULL
)
11737 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11738 if (handle
== NULL
)
11740 /* Failed to find a debug file associated with the build-id.
11741 This is not an error however, rather it just means that
11742 the debug info has probably not been loaded on the system,
11743 or that another method is being used to link to the debug
11749 add_separate_debug_file (filename
, handle
);
11752 /* Try to load a debug file pointed to by the .debug_sup section. */
11755 load_debug_sup_file (const char * main_filename
, void * file
)
11757 if (! load_debug_section (debug_sup
, file
))
11758 return; /* No .debug_sup section. */
11760 struct dwarf_section
* section
;
11761 section
= & debug_displays
[debug_sup
].section
;
11762 assert (section
!= NULL
);
11764 if (section
->start
== NULL
|| section
->size
< 5)
11766 warn (_(".debug_sup section is corrupt/empty\n"));
11770 if (section
->start
[2] != 0)
11771 return; /* This is a supplementary file. */
11773 const char * filename
= (const char *) section
->start
+ 3;
11774 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11776 warn (_("filename in .debug_sup section is corrupt\n"));
11780 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11785 new_len
= asprintf (& new_name
, "%.*s/%s",
11786 (int) (strrchr (main_filename
, '/') - main_filename
),
11791 warn (_("unable to construct path for supplementary debug file"));
11796 filename
= new_name
;
11800 /* PR 27796: Make sure that we pass a filename that can be free'd to
11801 add_separate_debug_file(). */
11802 filename
= strdup (filename
);
11803 if (filename
== NULL
)
11805 warn (_("out of memory constructing filename for .debug_sup link\n"));
11810 void * handle
= open_debug_file (filename
);
11811 if (handle
== NULL
)
11813 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11814 free ((void *) filename
);
11818 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11820 /* FIXME: Compare the checksums, if present. */
11821 add_separate_debug_file (filename
, handle
);
11824 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11825 Recursively check the loaded files for more of these sections.
11826 Also follow any links in .debug_sup sections.
11827 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11830 check_for_and_load_links (void * file
, const char * filename
)
11832 void * handle
= NULL
;
11834 if (load_debug_section (gnu_debugaltlink
, file
))
11836 Build_id_data build_id_data
;
11838 handle
= load_separate_debug_info (filename
,
11839 & debug_displays
[gnu_debugaltlink
].section
,
11840 parse_gnu_debugaltlink
,
11841 check_gnu_debugaltlink
,
11846 assert (handle
== first_separate_info
->handle
);
11847 check_for_and_load_links (first_separate_info
->handle
,
11848 first_separate_info
->filename
);
11852 if (load_debug_section (gnu_debuglink
, file
))
11854 unsigned long crc32
;
11856 handle
= load_separate_debug_info (filename
,
11857 & debug_displays
[gnu_debuglink
].section
,
11858 parse_gnu_debuglink
,
11859 check_gnu_debuglink
,
11864 assert (handle
== first_separate_info
->handle
);
11865 check_for_and_load_links (first_separate_info
->handle
,
11866 first_separate_info
->filename
);
11870 load_debug_sup_file (filename
, file
);
11872 load_build_id_debug_file (filename
, file
);
11875 /* Load the separate debug info file(s) attached to FILE, if any exist.
11876 Returns TRUE if any were found, FALSE otherwise.
11877 If TRUE is returned then the linked list starting at first_separate_info
11878 will be populated with open file handles. */
11881 load_separate_debug_files (void * file
, const char * filename
)
11883 /* Skip this operation if we are not interested in debug links. */
11884 if (! do_follow_links
&& ! do_debug_links
)
11887 /* See if there are any dwo links. */
11888 if (load_debug_section (str
, file
)
11889 && load_debug_section (abbrev
, file
)
11890 && load_debug_section (info
, file
))
11894 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11897 bool introduced
= false;
11899 const char *dir
= NULL
;
11900 const char *id
= NULL
;
11901 const char *name
= NULL
;
11903 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11905 /* Accumulate NAME, DIR and ID fields. */
11906 switch (dwinfo
->type
)
11910 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11911 name
= dwinfo
->value
;
11915 /* There can be multiple DW_AT_comp_dir entries in a CU,
11916 so do not complain. */
11917 dir
= dwinfo
->value
;
11922 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11923 id
= dwinfo
->value
;
11927 error (_("Unexpected DWO INFO type"));
11931 /* If we have reached the end of our list, or we are changing
11932 CUs, then display the information that we have accumulated
11935 && (dwinfo
->next
== NULL
11936 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11938 if (do_debug_links
)
11942 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11943 debug_displays
[info
].section
.uncompressed_name
);
11947 printf (_(" Name: %s\n"), name
);
11948 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11950 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11952 printf (_(" ID: <not specified>\n"));
11956 if (do_follow_links
)
11957 load_dwo_file (filename
, name
, dir
, id
);
11959 name
= dir
= id
= NULL
;
11965 if (! do_follow_links
)
11966 /* The other debug links will be displayed by display_debug_links()
11967 so we do not need to do any further processing here. */
11970 /* FIXME: We do not check for the presence of both link sections in the same file. */
11971 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11972 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11974 check_for_and_load_links (file
, filename
);
11975 if (first_separate_info
!= NULL
)
11978 do_follow_links
= 0;
11983 free_debug_memory (void)
11987 free_all_abbrevs ();
11989 free (cu_abbrev_map
);
11990 cu_abbrev_map
= NULL
;
11991 next_free_abbrev_map_entry
= 0;
11995 shndx_pool_size
= 0;
11996 shndx_pool_used
= 0;
12004 memset (level_type_signed
, 0, sizeof level_type_signed
);
12005 cu_tu_indexes_read
= -1;
12007 for (i
= 0; i
< max
; i
++)
12008 free_debug_section ((enum dwarf_section_display_enum
) i
);
12010 if (debug_information
!= NULL
)
12012 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12014 if (debug_information
[i
].max_loc_offsets
)
12016 free (debug_information
[i
].loc_offsets
);
12017 free (debug_information
[i
].have_frame_base
);
12019 if (debug_information
[i
].max_range_lists
)
12020 free (debug_information
[i
].range_lists
);
12022 free (debug_information
);
12023 debug_information
= NULL
;
12024 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12028 separate_info
* next
;
12030 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12032 close_debug_file (d
->handle
);
12033 free ((void *) d
->filename
);
12037 first_separate_info
= NULL
;
12042 /* Enable display of specific DWARF sections as determined by the comma
12043 separated strings in NAMES. Returns non-zero if any displaying was
12047 dwarf_select_sections_by_names (const char *names
)
12051 const char * option
;
12055 debug_dump_long_opts
;
12057 static const debug_dump_long_opts opts_table
[] =
12059 /* Please keep this table alpha- sorted. */
12060 { "Ranges", & do_debug_ranges
, 1 },
12061 { "abbrev", & do_debug_abbrevs
, 1 },
12062 { "addr", & do_debug_addr
, 1 },
12063 { "aranges", & do_debug_aranges
, 1 },
12064 { "cu_index", & do_debug_cu_index
, 1 },
12065 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12066 #ifdef HAVE_LIBDEBUGINFOD
12067 { "do-not-use-debuginfod", & use_debuginfod
, 0 },
12069 { "follow-links", & do_follow_links
, 1 },
12070 { "frames", & do_debug_frames
, 1 },
12071 { "frames-interp", & do_debug_frames_interp
, 1 },
12072 /* The special .gdb_index section. */
12073 { "gdb_index", & do_gdb_index
, 1 },
12074 { "info", & do_debug_info
, 1 },
12075 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
12076 { "links", & do_debug_links
, 1 },
12077 { "loc", & do_debug_loc
, 1 },
12078 { "macro", & do_debug_macinfo
, 1 },
12079 { "no-follow-links", & do_follow_links
, 0 },
12080 { "pubnames", & do_debug_pubnames
, 1 },
12081 { "pubtypes", & do_debug_pubtypes
, 1 },
12082 /* This entry is for compatibility
12083 with earlier versions of readelf. */
12084 { "ranges", & do_debug_aranges
, 1 },
12085 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12086 { "str", & do_debug_str
, 1 },
12087 { "str-offsets", & do_debug_str_offsets
, 1 },
12088 /* These trace_* sections are used by Itanium VMS. */
12089 { "trace_abbrev", & do_trace_abbrevs
, 1 },
12090 { "trace_aranges", & do_trace_aranges
, 1 },
12091 { "trace_info", & do_trace_info
, 1 },
12092 #ifdef HAVE_LIBDEBUGINFOD
12093 { "use-debuginfod", & use_debuginfod
, 1 },
12104 const debug_dump_long_opts
* entry
;
12106 for (entry
= opts_table
; entry
->option
; entry
++)
12108 size_t len
= strlen (entry
->option
);
12110 if (strncmp (p
, entry
->option
, len
) == 0
12111 && (p
[len
] == ',' || p
[len
] == '\0'))
12113 * entry
->variable
= entry
->val
;
12114 result
|= entry
->val
;
12116 /* The --debug-dump=frames-interp option also
12117 enables the --debug-dump=frames option. */
12118 if (do_debug_frames_interp
)
12119 do_debug_frames
= 1;
12126 if (entry
->option
== NULL
)
12128 warn (_("Unrecognized debug option '%s'\n"), p
);
12129 p
= strchr (p
, ',');
12141 /* Enable display of specific DWARF sections as determined by the characters
12142 in LETTERS. Returns non-zero if any displaying was enabled. */
12145 dwarf_select_sections_by_letters (const char *letters
)
12154 debug_dump_letter_opts
;
12156 static const debug_dump_letter_opts letter_table
[] =
12158 { 'A', & do_debug_addr
, 1, false},
12159 { 'a', & do_debug_abbrevs
, 1, false },
12160 { 'c', & do_debug_cu_index
, 1, false },
12161 #ifdef HAVE_LIBDEBUGINFOD
12162 { 'D', & use_debuginfod
, 1, false },
12163 { 'E', & use_debuginfod
, 0, false },
12165 { 'F', & do_debug_frames_interp
, 1, true }, /* Note the fall through. */
12166 { 'f', & do_debug_frames
, 1, false },
12167 { 'g', & do_gdb_index
, 1, false },
12168 { 'i', & do_debug_info
, 1, false },
12169 { 'K', & do_follow_links
, 1, false },
12170 { 'k', & do_debug_links
, 1, false },
12171 { 'L', & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
, false },
12172 { 'l', & do_debug_lines
, FLAG_DEBUG_LINES_RAW
, false },
12173 { 'm', & do_debug_macinfo
, 1, false },
12174 { 'N', & do_follow_links
, 0, false },
12175 { 'O', & do_debug_str_offsets
, 1, false },
12176 { 'o', & do_debug_loc
, 1, false },
12177 { 'p', & do_debug_pubnames
, 1, false },
12178 { 'R', & do_debug_ranges
, 1, false },
12179 { 'r', & do_debug_aranges
, 1, false },
12180 { 's', & do_debug_str
, 1, false },
12181 { 'T', & do_trace_aranges
, 1, false },
12182 { 't', & do_debug_pubtypes
, 1, false },
12183 { 'U', & do_trace_info
, 1, false },
12184 { 'u', & do_trace_abbrevs
, 1, false },
12185 { 0, NULL
, 0, false }
12192 const debug_dump_letter_opts
* entry
;
12194 for (entry
= letter_table
; entry
->letter
; entry
++)
12196 if (entry
->letter
== * letters
)
12198 * entry
->variable
|= entry
->val
;
12199 result
|= entry
->val
;
12206 if (entry
->letter
== 0)
12207 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12216 dwarf_select_sections_all (void)
12219 do_debug_abbrevs
= 1;
12220 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12221 do_debug_pubnames
= 1;
12222 do_debug_pubtypes
= 1;
12223 do_debug_aranges
= 1;
12224 do_debug_ranges
= 1;
12225 do_debug_frames
= 1;
12226 do_debug_macinfo
= 1;
12231 do_trace_abbrevs
= 1;
12232 do_trace_aranges
= 1;
12234 do_debug_cu_index
= 1;
12235 do_follow_links
= 1;
12236 do_debug_links
= 1;
12237 do_debug_str_offsets
= 1;
12240 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12241 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12243 /* N.B. The order here must match the order in section_display_enum. */
12245 struct dwarf_section_display debug_displays
[] =
12247 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12248 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12249 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12250 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12251 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12252 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12253 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12254 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12255 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12256 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12257 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12258 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12259 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12260 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12261 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12262 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12263 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12264 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12265 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12266 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12267 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12268 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12269 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12270 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12271 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12272 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12273 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12274 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12275 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12276 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12277 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12278 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12279 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12280 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12281 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12282 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12283 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12284 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12285 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12286 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12287 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12288 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12289 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12290 /* Separate debug info files can containt their own .debug_str section,
12291 and this might be in *addition* to a .debug_str section already present
12292 in the main file. Hence we need to have two entries for .debug_str. */
12293 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12294 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12297 /* A static assertion. */
12298 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];