1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2021 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
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>
46 #define MAX(a, b) ((a) > (b) ? (a) : (b))
47 #define MIN(a, b) ((a) < (b) ? (a) : (b))
49 static const char *regname (unsigned int regno
, int row
);
50 static const char *regname_internal_by_table_only (unsigned int regno
);
52 static int have_frame_base
;
53 static int need_base_address
;
55 static unsigned int num_debug_info_entries
= 0;
56 static unsigned int alloc_num_debug_info_entries
= 0;
57 static debug_info
*debug_information
= NULL
;
58 /* Special value for num_debug_info_entries to indicate
59 that the .debug_info section could not be loaded/parsed. */
60 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
62 /* A .debug_info section can contain multiple links to separate
63 DWO object files. We use these structures to record these links. */
71 typedef struct dwo_info
76 struct dwo_info
* next
;
79 static dwo_info
*first_dwo_info
= NULL
;
80 static bool need_dwo_info
;
82 separate_info
* first_separate_info
= NULL
;
84 unsigned int eh_addr_size
;
89 int do_debug_pubnames
;
90 int do_debug_pubtypes
;
94 int do_debug_frames_interp
;
97 int do_debug_str_offsets
;
101 int do_trace_abbrevs
;
102 int do_trace_aranges
;
104 int do_debug_cu_index
;
107 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
110 int dwarf_cutoff_level
= -1;
111 unsigned long dwarf_start_die
;
115 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
116 testing whether e.g. a locview list is present. */
117 static const dwarf_vma vm1
= -1;
119 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
120 sections. For version 1 package files, each set is stored in SHNDX_POOL
121 as a zero-terminated list of section indexes comprising one set of debug
122 sections from a .dwo file. */
124 static unsigned int *shndx_pool
= NULL
;
125 static unsigned int shndx_pool_size
= 0;
126 static unsigned int shndx_pool_used
= 0;
128 /* For version 2 package files, each set contains an array of section offsets
129 and an array of section sizes, giving the offset and size of the
130 contribution from a CU or TU within one of the debug sections.
131 When displaying debug info from a package file, we need to use these
132 tables to locate the corresponding contributions to each section. */
137 dwarf_vma section_offsets
[DW_SECT_MAX
];
138 size_t section_sizes
[DW_SECT_MAX
];
141 static int cu_count
= 0;
142 static int tu_count
= 0;
143 static struct cu_tu_set
*cu_sets
= NULL
;
144 static struct cu_tu_set
*tu_sets
= NULL
;
146 static bool load_cu_tu_indexes (void *);
148 /* An array that indicates for a given level of CU nesting whether
149 the latest DW_AT_type seen for that level was a signed type or
151 #define MAX_CU_NESTING (1 << 8)
152 static bool level_type_signed
[MAX_CU_NESTING
];
154 /* Values for do_debug_lines. */
155 #define FLAG_DEBUG_LINES_RAW 1
156 #define FLAG_DEBUG_LINES_DECODED 2
159 size_of_encoded_value (int encoding
)
161 switch (encoding
& 0x7)
164 case 0: return eh_addr_size
;
172 get_encoded_value (unsigned char **pdata
,
174 struct dwarf_section
*section
,
177 unsigned char * data
= * pdata
;
178 unsigned int size
= size_of_encoded_value (encoding
);
181 if (data
+ size
>= end
)
183 warn (_("Encoded value extends past end of section\n"));
188 /* PR 17512: file: 002-829853-0.004. */
191 warn (_("Encoded size of %d is too large to read\n"), size
);
196 /* PR 17512: file: 1085-5603-0.004. */
199 warn (_("Encoded size of 0 is too small to read\n"));
204 if (encoding
& DW_EH_PE_signed
)
205 val
= byte_get_signed (data
, size
);
207 val
= byte_get (data
, size
);
209 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
210 val
+= section
->address
+ (data
- section
->start
);
212 * pdata
= data
+ size
;
216 #if SIZEOF_LONG_LONG > SIZEOF_LONG
218 # define DWARF_VMA_FMT "ll"
219 # define DWARF_VMA_FMT_LONG "%16.16llx"
221 # define DWARF_VMA_FMT "I64"
222 # define DWARF_VMA_FMT_LONG "%016I64x"
225 # define DWARF_VMA_FMT "l"
226 # define DWARF_VMA_FMT_LONG "%16.16lx"
229 /* Convert a dwarf vma value into a string. Returns a pointer to a static
230 buffer containing the converted VALUE. The value is converted according
231 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
232 it specifies the maximum number of bytes to be displayed in the converted
233 value and FMTCH is ignored - hex is always used. */
236 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
238 /* As dwarf_vmatoa is used more then once in a printf call
239 for output, we are cycling through an fixed array of pointers
240 for return address. */
241 static int buf_pos
= 0;
242 static struct dwarf_vmatoa_buf
248 ret
= buf
[buf_pos
++].place
;
249 buf_pos
%= ARRAY_SIZE (buf
);
253 /* Printf does not have a way of specifying a maximum field width for an
254 integer value, so we print the full value into a buffer and then select
255 the precision we need. */
256 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
259 return ret
+ (16 - 2 * num_bytes
);
266 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
268 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
269 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
274 static inline const char *
275 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
277 return dwarf_vmatoa_1 (fmtch
, value
, 0);
280 /* Print a dwarf_vma value (typically an address, offset or length) in
281 hexadecimal format, followed by a space. The length of the VALUE (and
282 hence the precision displayed) is determined by the NUM_BYTES parameter. */
285 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
287 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
290 /* Print a view number in hexadecimal value, with the same width
291 print_dwarf_vma would have printed it with the same num_bytes.
292 Print blanks for zero view, unless force is nonzero. */
295 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
303 assert (value
== (unsigned long) value
);
305 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
307 printf ("%*s", len
+ 1, "");
310 /* Format a 64-bit value, given as two 32-bit values, in hex.
311 For reentrancy, this uses a buffer provided by the caller. */
314 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
315 unsigned int buf_len
)
320 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
323 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
324 snprintf (buf
+ len
, buf_len
- len
,
325 "%08" DWARF_VMA_FMT
"x", lvalue
);
331 /* Read in a LEB128 encoded value starting at address DATA.
332 If SIGN is true, return a signed LEB128 value.
333 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
334 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
335 terminating byte was not found and with bit 1 set if the value
336 overflows a dwarf_vma.
337 No bytes will be read at address END or beyond. */
340 read_leb128 (unsigned char *data
,
341 const unsigned char *const end
,
343 unsigned int *length_return
,
346 dwarf_vma result
= 0;
347 unsigned int num_read
= 0;
348 unsigned int shift
= 0;
353 unsigned char byte
= *data
++;
354 unsigned char lost
, mask
;
358 if (shift
< CHAR_BIT
* sizeof (result
))
360 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
361 /* These bits overflowed. */
362 lost
= byte
^ (result
>> shift
);
363 /* And this is the mask of possible overflow bits. */
364 mask
= 0x7f ^ ((dwarf_vma
) 0x7f << shift
>> shift
);
372 if ((lost
& mask
) != (sign
&& (dwarf_signed_vma
) result
< 0 ? mask
: 0))
375 if ((byte
& 0x80) == 0)
378 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
379 result
|= -((dwarf_vma
) 1 << shift
);
384 if (length_return
!= NULL
)
385 *length_return
= num_read
;
386 if (status_return
!= NULL
)
387 *status_return
= status
;
392 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
393 Checks to make sure that the read will not reach or pass END
394 and that VAL is big enough to hold AMOUNT bytes. */
395 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
398 unsigned int amount = (AMOUNT); \
399 if (sizeof (VAL) < amount) \
401 error (ngettext ("internal error: attempt to read %d byte " \
402 "of data in to %d sized variable", \
403 "internal error: attempt to read %d bytes " \
404 "of data in to %d sized variable", \
406 amount, (int) sizeof (VAL)); \
407 amount = sizeof (VAL); \
409 if ((PTR) >= (END) - amount) \
412 amount = (END) - (PTR); \
416 if (amount == 0 || amount > 8) \
419 VAL = byte_get ((PTR), amount); \
423 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
424 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
427 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
432 /* Like SAFE_BYTE_GET, but reads a signed value. */
433 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
436 unsigned int amount = (AMOUNT); \
437 if ((PTR) >= (END) - amount) \
440 amount = (END) - (PTR); \
445 VAL = byte_get_signed ((PTR), amount); \
451 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
452 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
455 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
460 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
463 if ((PTR) <= (END) - 8) \
465 byte_get_64 ((PTR), (HIGH), (LOW)); \
469 * (LOW) = * (HIGH) = 0; \
474 typedef struct State_Machine_Registers
483 unsigned char op_index
;
484 unsigned char end_sequence
;
485 /* This variable hold the number of the last entry seen
486 in the File Table. */
487 unsigned int last_file_entry
;
490 static SMR state_machine_regs
;
493 reset_state_machine (int is_stmt
)
495 state_machine_regs
.address
= 0;
496 state_machine_regs
.view
= 0;
497 state_machine_regs
.op_index
= 0;
498 state_machine_regs
.file
= 1;
499 state_machine_regs
.line
= 1;
500 state_machine_regs
.column
= 0;
501 state_machine_regs
.is_stmt
= is_stmt
;
502 state_machine_regs
.basic_block
= 0;
503 state_machine_regs
.end_sequence
= 0;
504 state_machine_regs
.last_file_entry
= 0;
507 /* Handled an extend line op.
508 Returns the number of bytes read. */
511 process_extended_line_op (unsigned char * data
,
515 unsigned char op_code
;
516 size_t len
, header_len
;
518 unsigned char *orig_data
= data
;
521 READ_ULEB (len
, data
, end
);
522 header_len
= data
- orig_data
;
524 if (len
== 0 || data
== end
|| len
> (size_t) (end
- data
))
526 warn (_("Badly formed extended line op encountered!\n"));
532 printf (_(" Extended opcode %d: "), op_code
);
536 case DW_LNE_end_sequence
:
537 printf (_("End of Sequence\n\n"));
538 reset_state_machine (is_stmt
);
541 case DW_LNE_set_address
:
542 /* PR 17512: file: 002-100480-0.004. */
545 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
546 (unsigned long) len
- 1);
550 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
551 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
552 state_machine_regs
.address
= adr
;
553 state_machine_regs
.view
= 0;
554 state_machine_regs
.op_index
= 0;
557 case DW_LNE_define_file
:
558 printf (_("define new File Table entry\n"));
559 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
560 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
566 l
= strnlen ((char *) data
, end
- data
);
568 READ_ULEB (val
, data
, end
);
569 printf ("%s\t", dwarf_vmatoa ("u", val
));
570 READ_ULEB (val
, data
, end
);
571 printf ("%s\t", dwarf_vmatoa ("u", val
));
572 READ_ULEB (val
, data
, end
);
573 printf ("%s\t", dwarf_vmatoa ("u", val
));
574 printf ("%.*s\n\n", (int) l
, name
);
577 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
== end
)
578 warn (_("DW_LNE_define_file: Bad opcode length\n"));
581 case DW_LNE_set_discriminator
:
582 READ_ULEB (val
, data
, end
);
583 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
587 case DW_LNE_HP_negate_is_UV_update
:
588 printf ("DW_LNE_HP_negate_is_UV_update\n");
590 case DW_LNE_HP_push_context
:
591 printf ("DW_LNE_HP_push_context\n");
593 case DW_LNE_HP_pop_context
:
594 printf ("DW_LNE_HP_pop_context\n");
596 case DW_LNE_HP_set_file_line_column
:
597 printf ("DW_LNE_HP_set_file_line_column\n");
599 case DW_LNE_HP_set_routine_name
:
600 printf ("DW_LNE_HP_set_routine_name\n");
602 case DW_LNE_HP_set_sequence
:
603 printf ("DW_LNE_HP_set_sequence\n");
605 case DW_LNE_HP_negate_post_semantics
:
606 printf ("DW_LNE_HP_negate_post_semantics\n");
608 case DW_LNE_HP_negate_function_exit
:
609 printf ("DW_LNE_HP_negate_function_exit\n");
611 case DW_LNE_HP_negate_front_end_logical
:
612 printf ("DW_LNE_HP_negate_front_end_logical\n");
614 case DW_LNE_HP_define_proc
:
615 printf ("DW_LNE_HP_define_proc\n");
617 case DW_LNE_HP_source_file_correlation
:
619 unsigned char *edata
= data
+ len
- 1;
621 printf ("DW_LNE_HP_source_file_correlation\n");
627 READ_ULEB (opc
, data
, edata
);
631 case DW_LNE_HP_SFC_formfeed
:
632 printf (" DW_LNE_HP_SFC_formfeed\n");
634 case DW_LNE_HP_SFC_set_listing_line
:
635 READ_ULEB (val
, data
, edata
);
636 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
637 dwarf_vmatoa ("u", val
));
639 case DW_LNE_HP_SFC_associate
:
640 printf (" DW_LNE_HP_SFC_associate ");
641 READ_ULEB (val
, data
, edata
);
642 printf ("(%s", dwarf_vmatoa ("u", val
));
643 READ_ULEB (val
, data
, edata
);
644 printf (",%s", dwarf_vmatoa ("u", val
));
645 READ_ULEB (val
, data
, edata
);
646 printf (",%s)\n", dwarf_vmatoa ("u", val
));
649 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
659 unsigned int rlen
= len
- 1;
661 if (op_code
>= DW_LNE_lo_user
662 /* The test against DW_LNW_hi_user is redundant due to
663 the limited range of the unsigned char data type used
665 /*&& op_code <= DW_LNE_hi_user*/)
666 printf (_("user defined: "));
668 printf (_("UNKNOWN: "));
669 printf (_("length %d ["), rlen
);
671 printf (" %02x", *data
++);
677 return len
+ header_len
;
680 static const unsigned char *
681 fetch_indirect_string (dwarf_vma offset
)
683 struct dwarf_section
*section
= &debug_displays
[str
].section
;
684 const unsigned char * ret
;
686 if (section
->start
== NULL
)
687 return (const unsigned char *) _("<no .debug_str section>");
689 if (offset
>= section
->size
)
691 warn (_("DW_FORM_strp offset too big: 0x%s\n"),
692 dwarf_vmatoa ("x", offset
));
693 return (const unsigned char *) _("<offset is too big>");
696 ret
= section
->start
+ offset
;
697 /* Unfortunately we cannot rely upon the .debug_str section ending with a
698 NUL byte. Since our caller is expecting to receive a well formed C
699 string we test for the lack of a terminating byte here. */
700 if (strnlen ((const char *) ret
, section
->size
- offset
)
701 == section
->size
- offset
)
702 ret
= (const unsigned char *)
703 _("<no NUL byte at end of .debug_str section>");
708 static const unsigned char *
709 fetch_indirect_line_string (dwarf_vma offset
)
711 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
712 const unsigned char * ret
;
714 if (section
->start
== NULL
)
715 return (const unsigned char *) _("<no .debug_line_str section>");
717 if (offset
>= section
->size
)
719 warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
720 dwarf_vmatoa ("x", offset
));
721 return (const unsigned char *) _("<offset is too big>");
724 ret
= section
->start
+ offset
;
725 /* Unfortunately we cannot rely upon the .debug_line_str section ending
726 with a NUL byte. Since our caller is expecting to receive a well formed
727 C string we test for the lack of a terminating byte here. */
728 if (strnlen ((const char *) ret
, section
->size
- offset
)
729 == section
->size
- offset
)
730 ret
= (const unsigned char *)
731 _("<no NUL byte at end of .debug_line_str section>");
737 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
738 dwarf_vma offset_size
, bool dwo
)
740 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
741 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
742 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
743 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
744 dwarf_vma index_offset
;
745 dwarf_vma str_offset
;
747 unsigned char *curr
= index_section
->start
;
748 const unsigned char *end
= curr
+ index_section
->size
;
751 if (index_section
->start
== NULL
)
752 return (dwo
? _("<no .debug_str_offsets.dwo section>")
753 : _("<no .debug_str_offsets section>"));
755 if (str_section
->start
== NULL
)
756 return (dwo
? _("<no .debug_str.dwo section>")
757 : _("<no .debug_str section>"));
759 /* FIXME: We should cache the length... */
760 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
761 if (length
== 0xffffffff)
763 if (offset_size
!= 8)
764 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
765 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
767 else if (offset_size
!= 4)
769 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
774 /* This is probably an old style .debug_str_offset section which
775 just contains offsets and no header (and the first offset is 0). */
776 curr
= index_section
->start
;
777 length
= index_section
->size
;
781 /* Skip the version and padding bytes.
782 We assume that they are correct. */
785 /* FIXME: The code below assumes that there is only one table
786 in the .debug_str_offsets section, so check that now. */
787 if ((offset_size
== 4 && curr
+ length
< (end
- 8))
788 || (offset_size
== 8 && curr
+ length
< (end
- 16)))
790 warn (_("index table size is too small %s vs %s\n"),
791 dwarf_vmatoa ("x", length
),
792 dwarf_vmatoa ("x", index_section
->size
));
793 return _("<table too small>");
797 index_offset
= idx
* offset_size
;
799 if (this_set
!= NULL
)
800 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
802 if (index_offset
>= length
)
804 warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
805 dwarf_vmatoa ("x", index_offset
),
806 dwarf_vmatoa ("x", length
));
807 return _("<index offset is too big>");
810 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
811 str_offset
-= str_section
->address
;
812 if (str_offset
>= str_section
->size
)
814 warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
815 dwarf_vmatoa ("x", str_offset
));
816 return _("<indirect index offset is too big>");
819 ret
= (const char *) str_section
->start
+ str_offset
;
820 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
821 Since our caller is expecting to receive a well formed C string we test
822 for the lack of a terminating byte here. */
823 if (strnlen (ret
, str_section
->size
- str_offset
)
824 == str_section
->size
- str_offset
)
825 ret
= (const char *) _("<no NUL byte at end of section>");
831 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
833 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
835 if (section
->start
== NULL
)
836 return (_("<no .debug_addr section>"));
838 if (offset
+ bytes
> section
->size
)
840 warn (_("Offset into section %s too big: 0x%s\n"),
841 section
->name
, dwarf_vmatoa ("x", offset
));
842 return "<offset too big>";
845 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
849 /* FIXME: There are better and more efficient ways to handle
850 these structures. For now though, I just want something that
851 is simple to implement. */
852 /* Records a single attribute in an abbrev. */
853 typedef struct abbrev_attr
855 unsigned long attribute
;
857 bfd_signed_vma implicit_const
;
858 struct abbrev_attr
* next
;
862 /* Records a single abbrev. */
863 typedef struct abbrev_entry
865 unsigned long number
;
868 struct abbrev_attr
* first_attr
;
869 struct abbrev_attr
* last_attr
;
870 struct abbrev_entry
* next
;
874 /* Records a set of abbreviations. */
875 typedef struct abbrev_list
877 abbrev_entry
* first_abbrev
;
878 abbrev_entry
* last_abbrev
;
879 dwarf_vma abbrev_base
;
880 dwarf_vma abbrev_offset
;
881 struct abbrev_list
* next
;
882 unsigned char * start_of_next_abbrevs
;
886 /* Records all the abbrevs found so far. */
887 static struct abbrev_list
* abbrev_lists
= NULL
;
889 typedef struct abbrev_map
896 /* Maps between CU offsets and abbrev sets. */
897 static abbrev_map
* cu_abbrev_map
= NULL
;
898 static unsigned long num_abbrev_map_entries
= 0;
899 static unsigned long next_free_abbrev_map_entry
= 0;
901 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
902 #define ABBREV_MAP_ENTRIES_INCREMENT 8
905 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
907 if (cu_abbrev_map
== NULL
)
909 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
910 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
912 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
914 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
915 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
918 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
919 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
920 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
921 next_free_abbrev_map_entry
++;
925 free_all_abbrevs (void)
929 for (list
= abbrev_lists
; list
!= NULL
;)
931 abbrev_list
* next
= list
->next
;
932 abbrev_entry
* abbrv
;
934 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
936 abbrev_entry
* next_abbrev
= abbrv
->next
;
939 for (attr
= abbrv
->first_attr
; attr
;)
941 abbrev_attr
*next_attr
= attr
->next
;
959 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
961 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
963 list
->abbrev_base
= abbrev_base
;
964 list
->abbrev_offset
= abbrev_offset
;
966 list
->next
= abbrev_lists
;
973 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
974 dwarf_vma abbrev_offset
)
978 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
979 if (list
->abbrev_base
== abbrev_base
980 && list
->abbrev_offset
== abbrev_offset
)
986 /* Find the abbreviation map for the CU that includes OFFSET.
987 OFFSET is an absolute offset from the start of the .debug_info section. */
988 /* FIXME: This function is going to slow down readelf & objdump.
989 Consider using a better algorithm to mitigate this effect. */
992 find_abbrev_map_by_offset (dwarf_vma offset
)
996 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
997 if (cu_abbrev_map
[i
].start
<= offset
998 && cu_abbrev_map
[i
].end
> offset
)
999 return cu_abbrev_map
+ i
;
1005 add_abbrev (unsigned long number
,
1010 abbrev_entry
* entry
;
1012 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
1014 entry
->number
= number
;
1016 entry
->children
= children
;
1017 entry
->first_attr
= NULL
;
1018 entry
->last_attr
= NULL
;
1021 assert (list
!= NULL
);
1023 if (list
->first_abbrev
== NULL
)
1024 list
->first_abbrev
= entry
;
1026 list
->last_abbrev
->next
= entry
;
1028 list
->last_abbrev
= entry
;
1032 add_abbrev_attr (unsigned long attribute
,
1034 bfd_signed_vma implicit_const
,
1039 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1041 attr
->attribute
= attribute
;
1043 attr
->implicit_const
= implicit_const
;
1046 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1048 if (list
->last_abbrev
->first_attr
== NULL
)
1049 list
->last_abbrev
->first_attr
= attr
;
1051 list
->last_abbrev
->last_attr
->next
= attr
;
1053 list
->last_abbrev
->last_attr
= attr
;
1056 /* Processes the (partial) contents of a .debug_abbrev section.
1057 Returns NULL if the end of the section was encountered.
1058 Returns the address after the last byte read if the end of
1059 an abbreviation set was found. */
1061 static unsigned char *
1062 process_abbrev_set (struct dwarf_section
*section
,
1063 dwarf_vma abbrev_base
,
1064 dwarf_vma abbrev_size
,
1065 dwarf_vma abbrev_offset
,
1068 if (abbrev_base
>= section
->size
1069 || abbrev_size
> section
->size
- abbrev_base
)
1071 /* PR 17531: file:4bcd9ce9. */
1072 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
1073 "abbrev section size (%lx)\n"),
1074 (unsigned long) abbrev_base
+ abbrev_size
,
1075 (unsigned long) section
->size
);
1078 if (abbrev_offset
>= abbrev_size
)
1080 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
1081 "abbrev section size (%lx)\n"),
1082 (unsigned long) abbrev_offset
,
1083 (unsigned long) abbrev_size
);
1087 unsigned char *start
= section
->start
+ abbrev_base
;
1088 unsigned char *end
= start
+ abbrev_size
;
1089 start
+= abbrev_offset
;
1092 unsigned long entry
;
1094 unsigned long attribute
;
1097 READ_ULEB (entry
, start
, end
);
1099 /* A single zero is supposed to end the set according
1100 to the standard. If there's more, then signal that to
1107 READ_ULEB (tag
, start
, end
);
1111 children
= *start
++;
1113 add_abbrev (entry
, tag
, children
, list
);
1118 /* Initialize it due to a false compiler warning. */
1119 bfd_signed_vma implicit_const
= -1;
1121 READ_ULEB (attribute
, start
, end
);
1125 READ_ULEB (form
, start
, end
);
1129 if (form
== DW_FORM_implicit_const
)
1131 READ_SLEB (implicit_const
, start
, end
);
1136 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1138 while (attribute
!= 0);
1141 /* Report the missing single zero which ends the section. */
1142 error (_(".debug_abbrev section not zero terminated\n"));
1148 get_TAG_name (unsigned long tag
)
1150 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1154 static char buffer
[100];
1156 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1157 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1159 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1167 get_FORM_name (unsigned long form
)
1172 return "DW_FORM value: 0";
1174 name
= get_DW_FORM_name (form
);
1177 static char buffer
[100];
1179 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1187 get_IDX_name (unsigned long idx
)
1189 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1193 static char buffer
[100];
1195 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1202 static unsigned char *
1203 display_block (unsigned char *data
,
1205 const unsigned char * const end
, char delimiter
)
1209 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1211 return (unsigned char *) end
;
1213 maxlen
= (dwarf_vma
) (end
- data
);
1214 length
= length
> maxlen
? maxlen
: length
;
1217 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1223 decode_location_expression (unsigned char * data
,
1224 unsigned int pointer_size
,
1225 unsigned int offset_size
,
1228 dwarf_vma cu_offset
,
1229 struct dwarf_section
* section
)
1233 dwarf_signed_vma svalue
;
1234 unsigned char *end
= data
+ length
;
1235 int need_frame_base
= 0;
1244 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1245 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1248 printf ("DW_OP_deref");
1251 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1252 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1255 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1256 printf ("DW_OP_const1s: %ld", (long) svalue
);
1259 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1260 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1263 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1264 printf ("DW_OP_const2s: %ld", (long) svalue
);
1267 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1268 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1271 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1272 printf ("DW_OP_const4s: %ld", (long) svalue
);
1275 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1276 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1277 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1278 printf ("%lu", (unsigned long) uvalue
);
1281 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1282 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1283 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1284 printf ("%ld", (long) svalue
);
1287 READ_ULEB (uvalue
, data
, end
);
1288 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1291 READ_SLEB (svalue
, data
, end
);
1292 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1295 printf ("DW_OP_dup");
1298 printf ("DW_OP_drop");
1301 printf ("DW_OP_over");
1304 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1305 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1308 printf ("DW_OP_swap");
1311 printf ("DW_OP_rot");
1314 printf ("DW_OP_xderef");
1317 printf ("DW_OP_abs");
1320 printf ("DW_OP_and");
1323 printf ("DW_OP_div");
1326 printf ("DW_OP_minus");
1329 printf ("DW_OP_mod");
1332 printf ("DW_OP_mul");
1335 printf ("DW_OP_neg");
1338 printf ("DW_OP_not");
1341 printf ("DW_OP_or");
1344 printf ("DW_OP_plus");
1346 case DW_OP_plus_uconst
:
1347 READ_ULEB (uvalue
, data
, end
);
1348 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1351 printf ("DW_OP_shl");
1354 printf ("DW_OP_shr");
1357 printf ("DW_OP_shra");
1360 printf ("DW_OP_xor");
1363 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1364 printf ("DW_OP_bra: %ld", (long) svalue
);
1367 printf ("DW_OP_eq");
1370 printf ("DW_OP_ge");
1373 printf ("DW_OP_gt");
1376 printf ("DW_OP_le");
1379 printf ("DW_OP_lt");
1382 printf ("DW_OP_ne");
1385 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1386 printf ("DW_OP_skip: %ld", (long) svalue
);
1421 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1456 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1457 regname (op
- DW_OP_reg0
, 1));
1492 READ_SLEB (svalue
, data
, end
);
1493 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1494 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1498 READ_ULEB (uvalue
, data
, end
);
1499 printf ("DW_OP_regx: %s (%s)",
1500 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1503 need_frame_base
= 1;
1504 READ_SLEB (svalue
, data
, end
);
1505 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1508 READ_ULEB (uvalue
, data
, end
);
1509 READ_SLEB (svalue
, data
, end
);
1510 printf ("DW_OP_bregx: %s (%s) %s",
1511 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1512 dwarf_vmatoa ("d", svalue
));
1515 READ_ULEB (uvalue
, data
, end
);
1516 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1518 case DW_OP_deref_size
:
1519 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1520 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1522 case DW_OP_xderef_size
:
1523 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1524 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1527 printf ("DW_OP_nop");
1530 /* DWARF 3 extensions. */
1531 case DW_OP_push_object_address
:
1532 printf ("DW_OP_push_object_address");
1535 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1536 this ought to be an 8-byte wide computation. */
1537 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1538 printf ("DW_OP_call2: <0x%s>",
1539 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1542 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1543 this ought to be an 8-byte wide computation. */
1544 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1545 printf ("DW_OP_call4: <0x%s>",
1546 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1548 case DW_OP_call_ref
:
1549 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1550 this ought to be an 8-byte wide computation. */
1551 if (dwarf_version
== -1)
1553 printf (_("(DW_OP_call_ref in frame info)"));
1554 /* No way to tell where the next op is, so just bail. */
1555 return need_frame_base
;
1557 if (dwarf_version
== 2)
1559 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1563 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1565 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1567 case DW_OP_form_tls_address
:
1568 printf ("DW_OP_form_tls_address");
1570 case DW_OP_call_frame_cfa
:
1571 printf ("DW_OP_call_frame_cfa");
1573 case DW_OP_bit_piece
:
1574 printf ("DW_OP_bit_piece: ");
1575 READ_ULEB (uvalue
, data
, end
);
1576 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1577 READ_ULEB (uvalue
, data
, end
);
1578 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1581 /* DWARF 4 extensions. */
1582 case DW_OP_stack_value
:
1583 printf ("DW_OP_stack_value");
1586 case DW_OP_implicit_value
:
1587 printf ("DW_OP_implicit_value");
1588 READ_ULEB (uvalue
, data
, end
);
1589 data
= display_block (data
, uvalue
, end
, ' ');
1592 /* GNU extensions. */
1593 case DW_OP_GNU_push_tls_address
:
1594 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1596 case DW_OP_GNU_uninit
:
1597 printf ("DW_OP_GNU_uninit");
1598 /* FIXME: Is there data associated with this OP ? */
1600 case DW_OP_GNU_encoded_addr
:
1607 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1609 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1610 print_dwarf_vma (addr
, pointer_size
);
1613 case DW_OP_implicit_pointer
:
1614 case DW_OP_GNU_implicit_pointer
:
1615 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1616 this ought to be an 8-byte wide computation. */
1617 if (dwarf_version
== -1)
1619 printf (_("(%s in frame info)"),
1620 (op
== DW_OP_implicit_pointer
1621 ? "DW_OP_implicit_pointer"
1622 : "DW_OP_GNU_implicit_pointer"));
1623 /* No way to tell where the next op is, so just bail. */
1624 return need_frame_base
;
1626 if (dwarf_version
== 2)
1628 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1632 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1634 READ_SLEB (svalue
, data
, end
);
1635 printf ("%s: <0x%s> %s",
1636 (op
== DW_OP_implicit_pointer
1637 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1638 dwarf_vmatoa ("x", uvalue
),
1639 dwarf_vmatoa ("d", svalue
));
1641 case DW_OP_entry_value
:
1642 case DW_OP_GNU_entry_value
:
1643 READ_ULEB (uvalue
, data
, end
);
1644 /* PR 17531: file: 0cc9cd00. */
1645 if (uvalue
> (dwarf_vma
) (end
- data
))
1646 uvalue
= end
- data
;
1647 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1648 : "DW_OP_GNU_entry_value"));
1649 if (decode_location_expression (data
, pointer_size
, offset_size
,
1650 dwarf_version
, uvalue
,
1651 cu_offset
, section
))
1652 need_frame_base
= 1;
1658 case DW_OP_const_type
:
1659 case DW_OP_GNU_const_type
:
1660 READ_ULEB (uvalue
, data
, end
);
1661 printf ("%s: <0x%s> ",
1662 (op
== DW_OP_const_type
? "DW_OP_const_type"
1663 : "DW_OP_GNU_const_type"),
1664 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1665 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1666 data
= display_block (data
, uvalue
, end
, ' ');
1668 case DW_OP_regval_type
:
1669 case DW_OP_GNU_regval_type
:
1670 READ_ULEB (uvalue
, data
, end
);
1671 printf ("%s: %s (%s)",
1672 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1673 : "DW_OP_GNU_regval_type"),
1674 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1675 READ_ULEB (uvalue
, data
, end
);
1676 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1678 case DW_OP_deref_type
:
1679 case DW_OP_GNU_deref_type
:
1680 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1682 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1683 : "DW_OP_GNU_deref_type"),
1685 READ_ULEB (uvalue
, data
, end
);
1686 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1689 case DW_OP_GNU_convert
:
1690 READ_ULEB (uvalue
, data
, end
);
1691 printf ("%s <0x%s>",
1692 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1693 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1695 case DW_OP_reinterpret
:
1696 case DW_OP_GNU_reinterpret
:
1697 READ_ULEB (uvalue
, data
, end
);
1698 printf ("%s <0x%s>",
1699 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1700 : "DW_OP_GNU_reinterpret"),
1701 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1703 case DW_OP_GNU_parameter_ref
:
1704 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1705 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1706 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1708 case DW_OP_GNU_addr_index
:
1709 READ_ULEB (uvalue
, data
, end
);
1710 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1712 case DW_OP_GNU_const_index
:
1713 READ_ULEB (uvalue
, data
, end
);
1714 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1716 case DW_OP_GNU_variable_value
:
1717 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1718 this ought to be an 8-byte wide computation. */
1719 if (dwarf_version
== -1)
1721 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1722 /* No way to tell where the next op is, so just bail. */
1723 return need_frame_base
;
1725 if (dwarf_version
== 2)
1727 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1731 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1733 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1736 /* HP extensions. */
1737 case DW_OP_HP_is_value
:
1738 printf ("DW_OP_HP_is_value");
1739 /* FIXME: Is there data associated with this OP ? */
1741 case DW_OP_HP_fltconst4
:
1742 printf ("DW_OP_HP_fltconst4");
1743 /* FIXME: Is there data associated with this OP ? */
1745 case DW_OP_HP_fltconst8
:
1746 printf ("DW_OP_HP_fltconst8");
1747 /* FIXME: Is there data associated with this OP ? */
1749 case DW_OP_HP_mod_range
:
1750 printf ("DW_OP_HP_mod_range");
1751 /* FIXME: Is there data associated with this OP ? */
1753 case DW_OP_HP_unmod_range
:
1754 printf ("DW_OP_HP_unmod_range");
1755 /* FIXME: Is there data associated with this OP ? */
1758 printf ("DW_OP_HP_tls");
1759 /* FIXME: Is there data associated with this OP ? */
1762 /* PGI (STMicroelectronics) extensions. */
1763 case DW_OP_PGI_omp_thread_num
:
1764 /* Pushes the thread number for the current thread as it would be
1765 returned by the standard OpenMP library function:
1766 omp_get_thread_num(). The "current thread" is the thread for
1767 which the expression is being evaluated. */
1768 printf ("DW_OP_PGI_omp_thread_num");
1772 if (op
>= DW_OP_lo_user
1773 && op
<= DW_OP_hi_user
)
1774 printf (_("(User defined location op 0x%x)"), op
);
1776 printf (_("(Unknown location op 0x%x)"), op
);
1777 /* No way to tell where the next op is, so just bail. */
1778 return need_frame_base
;
1781 /* Separate the ops. */
1786 return need_frame_base
;
1789 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1790 This is used for DWARF package files. */
1792 static struct cu_tu_set
*
1793 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1795 struct cu_tu_set
*p
;
1797 unsigned int dw_sect
;
1803 dw_sect
= DW_SECT_TYPES
;
1809 dw_sect
= DW_SECT_INFO
;
1813 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1821 /* Add INC to HIGH_BITS:LOW_BITS. */
1823 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1825 dwarf_vma tmp
= * low_bits
;
1829 /* FIXME: There is probably a better way of handling this:
1831 We need to cope with dwarf_vma being a 32-bit or 64-bit
1832 type. Plus regardless of its size LOW_BITS is meant to
1833 only hold 32-bits, so if there is overflow or wrap around
1834 we must propagate into HIGH_BITS. */
1835 if (tmp
< * low_bits
)
1839 else if (sizeof (tmp
) > 8
1850 fetch_alt_indirect_string (dwarf_vma offset
)
1854 if (! do_follow_links
)
1857 if (first_separate_info
== NULL
)
1858 return _("<no links available>");
1860 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1862 struct dwarf_section
* section
;
1865 if (! load_debug_section (separate_debug_str
, i
->handle
))
1868 section
= &debug_displays
[separate_debug_str
].section
;
1870 if (section
->start
== NULL
)
1873 if (offset
>= section
->size
)
1876 ret
= (const char *) (section
->start
+ offset
);
1877 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1878 NUL byte. Since our caller is expecting to receive a well formed C
1879 string we test for the lack of a terminating byte here. */
1880 if (strnlen ((const char *) ret
, section
->size
- offset
)
1881 == section
->size
- offset
)
1882 return _("<no NUL byte at end of alt .debug_str section>");
1887 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1888 dwarf_vmatoa ("x", offset
));
1889 return _("<offset is too big>");
1893 get_AT_name (unsigned long attribute
)
1898 return "DW_AT value: 0";
1900 /* One value is shared by the MIPS and HP extensions: */
1901 if (attribute
== DW_AT_MIPS_fde
)
1902 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1904 name
= get_DW_AT_name (attribute
);
1908 static char buffer
[100];
1910 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1919 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1921 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1923 dwinfo
->type
= type
;
1924 dwinfo
->value
= value
;
1925 dwinfo
->cu_offset
= cu_offset
;
1926 dwinfo
->next
= first_dwo_info
;
1927 first_dwo_info
= dwinfo
;
1931 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1933 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1937 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1939 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1943 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1945 add_dwo_info (id
, cu_offset
, DWO_ID
);
1949 free_dwo_info (void)
1954 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1956 next
= dwinfo
->next
;
1959 first_dwo_info
= NULL
;
1962 /* Ensure that START + UVALUE is less than END.
1963 Return an adjusted UVALUE if necessary to ensure this relationship. */
1965 static inline dwarf_vma
1966 check_uvalue (const unsigned char * start
,
1968 const unsigned char * end
)
1970 dwarf_vma max_uvalue
= end
- start
;
1972 /* See PR 17512: file: 008-103549-0.001:0.1.
1973 and PR 24829 for examples of where these tests are triggered. */
1974 if (uvalue
> max_uvalue
)
1976 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1977 uvalue
= max_uvalue
;
1983 static unsigned char *
1984 skip_attr_bytes (unsigned long form
,
1985 unsigned char * data
,
1986 unsigned const char * end
,
1987 dwarf_vma pointer_size
,
1988 dwarf_vma offset_size
,
1990 dwarf_vma
* value_return
)
1992 dwarf_signed_vma svalue
;
1993 dwarf_vma uvalue
= 0;
1999 case DW_FORM_ref_addr
:
2000 if (dwarf_version
== 2)
2001 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2002 else if (dwarf_version
> 2)
2003 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2009 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2013 case DW_FORM_line_strp
:
2014 case DW_FORM_sec_offset
:
2015 case DW_FORM_GNU_ref_alt
:
2016 case DW_FORM_GNU_strp_alt
:
2017 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2020 case DW_FORM_flag_present
:
2028 case DW_FORM_addrx1
:
2029 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2033 case DW_FORM_addrx3
:
2034 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2040 case DW_FORM_addrx2
:
2041 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2047 case DW_FORM_addrx4
:
2048 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2052 READ_SLEB (svalue
, data
, end
);
2056 case DW_FORM_ref_udata
:
2058 case DW_FORM_GNU_str_index
:
2060 case DW_FORM_GNU_addr_index
:
2062 READ_ULEB (uvalue
, data
, end
);
2067 dwarf_vma high_bits
;
2069 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2071 if (sizeof (uvalue
) > 4)
2072 uvalue
+= high_bits
<< 32;
2073 else if (high_bits
!= 0)
2075 /* FIXME: What to do ? */
2082 case DW_FORM_ref_sig8
:
2086 case DW_FORM_data16
:
2090 case DW_FORM_string
:
2091 data
+= strnlen ((char *) data
, end
- data
) + 1;
2095 case DW_FORM_exprloc
:
2096 READ_ULEB (uvalue
, data
, end
);
2100 case DW_FORM_block1
:
2101 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
2105 case DW_FORM_block2
:
2106 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2110 case DW_FORM_block4
:
2111 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2115 case DW_FORM_indirect
:
2116 READ_ULEB (form
, data
, end
);
2117 if (form
== DW_FORM_implicit_const
)
2118 SKIP_ULEB (data
, end
);
2119 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
, value_return
);
2125 * value_return
= uvalue
;
2127 data
= (unsigned char *) end
;
2131 /* Given form FORM with value UVALUE, locate and return the abbreviation
2132 associated with it. */
2134 static abbrev_entry
*
2135 get_type_abbrev_from_form (unsigned long form
,
2136 unsigned long uvalue
,
2137 dwarf_vma cu_offset
,
2138 const struct dwarf_section
* section
,
2139 unsigned long * abbrev_num_return
,
2140 unsigned char ** data_return
,
2141 unsigned long * cu_offset_return
)
2143 unsigned long abbrev_number
;
2145 abbrev_entry
* entry
;
2146 unsigned char * data
;
2148 if (abbrev_num_return
!= NULL
)
2149 * abbrev_num_return
= 0;
2150 if (data_return
!= NULL
)
2151 * data_return
= NULL
;
2155 case DW_FORM_GNU_ref_alt
:
2156 case DW_FORM_ref_sig8
:
2157 /* FIXME: We are unable to handle this form at the moment. */
2160 case DW_FORM_ref_addr
:
2161 if (uvalue
>= section
->size
)
2163 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2164 uvalue
, (long) section
->size
, section
->name
);
2169 case DW_FORM_ref_sup4
:
2170 case DW_FORM_ref_sup8
:
2177 case DW_FORM_ref_udata
:
2178 if (uvalue
+ cu_offset
> section
->size
)
2180 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2181 uvalue
, (long) cu_offset
, (long) section
->size
);
2184 uvalue
+= cu_offset
;
2187 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2190 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2194 data
= (unsigned char *) section
->start
+ uvalue
;
2195 map
= find_abbrev_map_by_offset (uvalue
);
2199 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2202 if (map
->list
== NULL
)
2204 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2208 if (cu_offset_return
!= NULL
)
2210 if (form
== DW_FORM_ref_addr
)
2211 * cu_offset_return
= map
->start
;
2213 * cu_offset_return
= cu_offset
;
2216 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2218 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2219 if (entry
->number
== abbrev_number
)
2222 if (abbrev_num_return
!= NULL
)
2223 * abbrev_num_return
= abbrev_number
;
2225 if (data_return
!= NULL
)
2226 * data_return
= data
;
2229 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2234 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2235 can be determined to be a signed type. The data for ENTRY can be
2236 found starting at DATA. */
2239 get_type_signedness (abbrev_entry
*entry
,
2240 const struct dwarf_section
*section
,
2241 unsigned char *data
,
2242 unsigned const char *end
,
2243 dwarf_vma cu_offset
,
2244 dwarf_vma pointer_size
,
2245 dwarf_vma offset_size
,
2248 unsigned int nesting
)
2252 * is_signed
= false;
2254 #define MAX_NESTING 20
2255 if (nesting
> MAX_NESTING
)
2257 /* FIXME: Warn - or is this expected ?
2258 NB/ We need to avoid infinite recursion. */
2262 for (attr
= entry
->first_attr
;
2263 attr
!= NULL
&& attr
->attribute
;
2266 unsigned char * orig_data
= data
;
2267 dwarf_vma uvalue
= 0;
2269 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2270 offset_size
, dwarf_version
, & uvalue
);
2274 switch (attr
->attribute
)
2276 case DW_AT_linkage_name
:
2280 if (attr
->form
== DW_FORM_strp
)
2281 printf (", %s", fetch_indirect_string (uvalue
));
2282 else if (attr
->form
== DW_FORM_string
)
2283 printf (", %s", orig_data
);
2290 abbrev_entry
* type_abbrev
;
2291 unsigned char * type_data
;
2292 unsigned long type_cu_offset
;
2294 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2298 NULL
/* abbrev num return */,
2301 if (type_abbrev
== NULL
)
2304 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2305 pointer_size
, offset_size
, dwarf_version
,
2306 is_signed
, nesting
+ 1);
2310 case DW_AT_encoding
:
2311 /* Determine signness. */
2314 case DW_ATE_address
:
2315 /* FIXME - some architectures have signed addresses. */
2316 case DW_ATE_boolean
:
2317 case DW_ATE_unsigned
:
2318 case DW_ATE_unsigned_char
:
2319 case DW_ATE_unsigned_fixed
:
2320 * is_signed
= false;
2324 case DW_ATE_complex_float
:
2327 case DW_ATE_signed_char
:
2328 case DW_ATE_imaginary_float
:
2329 case DW_ATE_decimal_float
:
2330 case DW_ATE_signed_fixed
:
2340 read_and_print_leb128 (unsigned char *data
,
2341 unsigned int *bytes_read
,
2342 unsigned const char *end
,
2346 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2348 report_leb_status (status
, __FILE__
, __LINE__
);
2350 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2354 display_discr_list (unsigned long form
,
2356 unsigned char * data
,
2357 unsigned const char * end
,
2362 printf ("[default]");
2369 case DW_FORM_block1
:
2370 case DW_FORM_block2
:
2371 case DW_FORM_block4
:
2372 /* Move data pointer back to the start of the byte array. */
2376 printf ("<corrupt>\n");
2377 warn (_("corrupt discr_list - not using a block form\n"));
2383 printf ("<corrupt>\n");
2384 warn (_("corrupt discr_list - block not long enough\n"));
2389 (level
> 0 && level
<= MAX_CU_NESTING
)
2390 ? level_type_signed
[level
- 1] : false;
2395 unsigned char discriminant
;
2396 unsigned int bytes_read
;
2398 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2402 assert (uvalue
> 0);
2403 switch (discriminant
)
2407 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2408 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2409 uvalue
-= bytes_read
;
2415 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2416 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2417 uvalue
-= bytes_read
;
2421 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2422 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2423 uvalue
-= bytes_read
;
2428 printf ("<corrupt>\n");
2429 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2439 printf (")(signed)");
2441 printf (")(unsigned)");
2444 static unsigned char *
2445 read_and_display_attr_value (unsigned long attribute
,
2447 dwarf_signed_vma implicit_const
,
2448 unsigned char * start
,
2449 unsigned char * data
,
2450 unsigned char * end
,
2451 dwarf_vma cu_offset
,
2452 dwarf_vma pointer_size
,
2453 dwarf_vma offset_size
,
2455 debug_info
* debug_info_p
,
2457 struct dwarf_section
* section
,
2458 struct cu_tu_set
* this_set
,
2462 dwarf_signed_vma svalue
;
2463 dwarf_vma uvalue
= 0;
2464 unsigned char * block_start
= NULL
;
2465 unsigned char * orig_data
= data
;
2467 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2469 warn (_("Corrupt attribute\n"));
2473 if (do_wide
&& ! do_loc
)
2475 /* PR 26847: Display the name of the form. */
2476 const char * name
= get_FORM_name (form
);
2478 /* For convenience we skip the DW_FORM_ prefix to the name. */
2480 name
+= 8; /* strlen ("DW_FORM_") */
2481 printf ("%c(%s)", delimiter
, name
);
2489 case DW_FORM_ref_addr
:
2490 if (dwarf_version
== 2)
2491 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2492 else if (dwarf_version
> 2)
2493 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2495 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2499 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2502 case DW_FORM_strp_sup
:
2504 case DW_FORM_line_strp
:
2505 case DW_FORM_sec_offset
:
2506 case DW_FORM_GNU_ref_alt
:
2507 case DW_FORM_GNU_strp_alt
:
2508 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2511 case DW_FORM_flag_present
:
2519 case DW_FORM_addrx1
:
2520 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2526 case DW_FORM_addrx2
:
2527 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2531 case DW_FORM_addrx3
:
2532 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2535 case DW_FORM_ref_sup4
:
2539 case DW_FORM_addrx4
:
2540 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2544 READ_SLEB (svalue
, data
, end
);
2548 case DW_FORM_GNU_str_index
:
2550 case DW_FORM_ref_udata
:
2552 case DW_FORM_GNU_addr_index
:
2554 READ_ULEB (uvalue
, data
, end
);
2557 case DW_FORM_indirect
:
2558 READ_ULEB (form
, data
, end
);
2560 printf ("%c%s", delimiter
, get_FORM_name (form
));
2561 if (form
== DW_FORM_implicit_const
)
2562 READ_SLEB (implicit_const
, data
, end
);
2563 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2565 cu_offset
, pointer_size
,
2566 offset_size
, dwarf_version
,
2567 debug_info_p
, do_loc
,
2568 section
, this_set
, delimiter
, level
);
2573 case DW_FORM_ref_addr
:
2575 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2578 case DW_FORM_GNU_ref_alt
:
2582 /* We have already printed the form name. */
2583 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2585 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2587 /* FIXME: Follow the reference... */
2593 case DW_FORM_ref_sup4
:
2594 case DW_FORM_ref_udata
:
2596 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2601 case DW_FORM_sec_offset
:
2603 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2606 case DW_FORM_flag_present
:
2613 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2616 case DW_FORM_implicit_const
:
2618 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2621 case DW_FORM_ref_sup8
:
2626 dwarf_vma high_bits
;
2630 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2632 if (form
== DW_FORM_ref8
)
2633 add64 (& high_bits
, & utmp
, cu_offset
);
2634 printf ("%c0x%s", delimiter
,
2635 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2638 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2639 && num_debug_info_entries
== 0)
2641 if (sizeof (uvalue
) == 8)
2642 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2644 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2650 case DW_FORM_data16
:
2653 dwarf_vma left_high_bits
, left_low_bits
;
2654 dwarf_vma right_high_bits
, right_low_bits
;
2656 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2657 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2658 if (byte_get
== byte_get_little_endian
)
2661 left_high_bits
^= right_high_bits
;
2662 right_high_bits
^= left_high_bits
;
2663 left_high_bits
^= right_high_bits
;
2664 left_low_bits
^= right_low_bits
;
2665 right_low_bits
^= left_low_bits
;
2666 left_low_bits
^= right_low_bits
;
2668 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2669 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2670 left_high_bits
, left_low_bits
, right_high_bits
,
2676 case DW_FORM_string
:
2678 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2679 data
+= strnlen ((char *) data
, end
- data
) + 1;
2683 case DW_FORM_exprloc
:
2684 READ_ULEB (uvalue
, data
, end
);
2687 if (block_start
>= end
)
2689 warn (_("Block ends prematurely\n"));
2694 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2697 data
= block_start
+ uvalue
;
2699 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2702 case DW_FORM_block1
:
2703 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2706 case DW_FORM_block2
:
2707 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2710 case DW_FORM_block4
:
2711 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2718 /* We have already displayed the form name. */
2719 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2720 dwarf_vmatoa ("x", uvalue
),
2721 fetch_indirect_string (uvalue
));
2723 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2724 dwarf_vmatoa ("x", uvalue
),
2725 fetch_indirect_string (uvalue
));
2729 case DW_FORM_line_strp
:
2733 /* We have already displayed the form name. */
2734 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2735 dwarf_vmatoa ("x", uvalue
),
2736 fetch_indirect_line_string (uvalue
));
2738 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2739 dwarf_vmatoa ("x", uvalue
),
2740 fetch_indirect_line_string (uvalue
));
2744 case DW_FORM_GNU_str_index
:
2752 const char *suffix
= strrchr (section
->name
, '.');
2753 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2756 /* We have already displayed the form name. */
2757 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2758 dwarf_vmatoa ("x", uvalue
),
2759 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2761 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2762 dwarf_vmatoa ("x", uvalue
),
2763 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2767 case DW_FORM_GNU_strp_alt
:
2771 /* We have already displayed the form name. */
2772 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2773 dwarf_vmatoa ("x", uvalue
),
2774 fetch_alt_indirect_string (uvalue
));
2776 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2777 dwarf_vmatoa ("x", uvalue
),
2778 fetch_alt_indirect_string (uvalue
));
2782 case DW_FORM_indirect
:
2783 /* Handled above. */
2786 case DW_FORM_ref_sig8
:
2789 dwarf_vma high_bits
;
2792 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2794 /* We have already displayed the form name. */
2795 printf ("%c: 0x%s", delimiter
,
2796 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2798 printf ("%csignature: 0x%s", delimiter
,
2799 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2804 case DW_FORM_GNU_addr_index
:
2806 case DW_FORM_addrx1
:
2807 case DW_FORM_addrx2
:
2808 case DW_FORM_addrx3
:
2809 case DW_FORM_addrx4
:
2815 if (debug_info_p
== NULL
)
2817 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2820 base
= debug_info_p
->addr_base
;
2822 offset
= base
+ uvalue
* pointer_size
;
2825 /* We have already displayed the form name. */
2826 printf (_("%c(index: 0x%s): %s"), delimiter
,
2827 dwarf_vmatoa ("x", uvalue
),
2828 fetch_indexed_value (offset
, pointer_size
));
2830 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2831 dwarf_vmatoa ("x", uvalue
),
2832 fetch_indexed_value (offset
, pointer_size
));
2836 case DW_FORM_strp_sup
:
2838 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2842 warn (_("Unrecognized form: 0x%lx\n"), form
);
2846 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2847 && num_debug_info_entries
== 0
2848 && debug_info_p
!= NULL
)
2852 case DW_AT_frame_base
:
2853 have_frame_base
= 1;
2855 case DW_AT_location
:
2856 case DW_AT_GNU_locviews
:
2857 case DW_AT_string_length
:
2858 case DW_AT_return_addr
:
2859 case DW_AT_data_member_location
:
2860 case DW_AT_vtable_elem_location
:
2862 case DW_AT_static_link
:
2863 case DW_AT_use_location
:
2864 case DW_AT_call_value
:
2865 case DW_AT_GNU_call_site_value
:
2866 case DW_AT_call_data_value
:
2867 case DW_AT_GNU_call_site_data_value
:
2868 case DW_AT_call_target
:
2869 case DW_AT_GNU_call_site_target
:
2870 case DW_AT_call_target_clobbered
:
2871 case DW_AT_GNU_call_site_target_clobbered
:
2872 if ((dwarf_version
< 4
2873 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2874 || form
== DW_FORM_sec_offset
)
2876 /* Process location list. */
2877 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2878 unsigned int num
= debug_info_p
->num_loc_offsets
;
2880 if (lmax
== 0 || num
>= lmax
)
2883 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2884 xcrealloc (debug_info_p
->loc_offsets
,
2885 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2886 debug_info_p
->loc_views
= (dwarf_vma
*)
2887 xcrealloc (debug_info_p
->loc_views
,
2888 lmax
, sizeof (*debug_info_p
->loc_views
));
2889 debug_info_p
->have_frame_base
= (int *)
2890 xcrealloc (debug_info_p
->have_frame_base
,
2891 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2892 debug_info_p
->max_loc_offsets
= lmax
;
2894 if (this_set
!= NULL
)
2895 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2896 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2897 if (attribute
!= DW_AT_GNU_locviews
)
2899 /* Corrupt DWARF info can produce more offsets than views.
2900 See PR 23062 for an example. */
2901 if (debug_info_p
->num_loc_offsets
2902 > debug_info_p
->num_loc_views
)
2903 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2906 debug_info_p
->loc_offsets
[num
] = uvalue
;
2907 debug_info_p
->num_loc_offsets
++;
2912 assert (debug_info_p
->num_loc_views
<= num
);
2913 num
= debug_info_p
->num_loc_views
;
2914 if (num
> debug_info_p
->num_loc_offsets
)
2915 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2918 debug_info_p
->loc_views
[num
] = uvalue
;
2919 debug_info_p
->num_loc_views
++;
2926 if (need_base_address
)
2927 debug_info_p
->base_address
= uvalue
;
2930 case DW_AT_GNU_addr_base
:
2931 case DW_AT_addr_base
:
2932 debug_info_p
->addr_base
= uvalue
;
2935 case DW_AT_GNU_ranges_base
:
2936 debug_info_p
->ranges_base
= uvalue
;
2940 if ((dwarf_version
< 4
2941 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2942 || form
== DW_FORM_sec_offset
)
2944 /* Process range list. */
2945 unsigned int lmax
= debug_info_p
->max_range_lists
;
2946 unsigned int num
= debug_info_p
->num_range_lists
;
2948 if (lmax
== 0 || num
>= lmax
)
2951 debug_info_p
->range_lists
= (dwarf_vma
*)
2952 xcrealloc (debug_info_p
->range_lists
,
2953 lmax
, sizeof (*debug_info_p
->range_lists
));
2954 debug_info_p
->max_range_lists
= lmax
;
2956 debug_info_p
->range_lists
[num
] = uvalue
;
2957 debug_info_p
->num_range_lists
++;
2961 case DW_AT_GNU_dwo_name
:
2962 case DW_AT_dwo_name
:
2967 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2969 case DW_FORM_GNU_strp_alt
:
2970 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2972 case DW_FORM_GNU_str_index
:
2978 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2980 case DW_FORM_string
:
2981 add_dwo_name ((const char *) orig_data
, cu_offset
);
2984 warn (_("Unsupported form (%s) for attribute %s\n"),
2985 get_FORM_name (form
), get_AT_name (attribute
));
2990 case DW_AT_comp_dir
:
2991 /* FIXME: Also extract a build-id in a CU/TU. */
2996 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2998 case DW_FORM_GNU_strp_alt
:
2999 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3001 case DW_FORM_line_strp
:
3002 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3004 case DW_FORM_GNU_str_index
:
3010 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
3012 case DW_FORM_string
:
3013 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3016 warn (_("Unsupported form (%s) for attribute %s\n"),
3017 get_FORM_name (form
), get_AT_name (attribute
));
3022 case DW_AT_GNU_dwo_id
:
3027 /* FIXME: Record the length of the ID as well ? */
3028 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3031 warn (_("Unsupported form (%s) for attribute %s\n"),
3032 get_FORM_name (form
), get_AT_name (attribute
));
3042 if (do_loc
|| attribute
== 0)
3045 /* For some attributes we can display further information. */
3049 if (level
>= 0 && level
< MAX_CU_NESTING
3050 && uvalue
< (size_t) (end
- start
))
3052 bool is_signed
= false;
3053 abbrev_entry
*type_abbrev
;
3054 unsigned char *type_data
;
3055 unsigned long type_cu_offset
;
3057 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3058 section
, NULL
, & type_data
, & type_cu_offset
);
3059 if (type_abbrev
!= NULL
)
3061 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
3062 pointer_size
, offset_size
, dwarf_version
,
3065 level_type_signed
[level
] = is_signed
;
3073 case DW_INL_not_inlined
:
3074 printf (_("(not inlined)"));
3076 case DW_INL_inlined
:
3077 printf (_("(inlined)"));
3079 case DW_INL_declared_not_inlined
:
3080 printf (_("(declared as inline but ignored)"));
3082 case DW_INL_declared_inlined
:
3083 printf (_("(declared as inline and inlined)"));
3086 printf (_(" (Unknown inline attribute value: %s)"),
3087 dwarf_vmatoa ("x", uvalue
));
3092 case DW_AT_language
:
3096 /* Ordered by the numeric value of these constants. */
3097 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3098 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3099 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3100 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3101 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3102 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3103 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3104 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3105 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3106 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3107 /* DWARF 2.1 values. */
3108 case DW_LANG_Java
: printf ("(Java)"); break;
3109 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3110 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3111 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3112 /* DWARF 3 values. */
3113 case DW_LANG_PLI
: printf ("(PLI)"); break;
3114 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3115 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3116 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3117 case DW_LANG_D
: printf ("(D)"); break;
3118 /* DWARF 4 values. */
3119 case DW_LANG_Python
: printf ("(Python)"); break;
3120 /* DWARF 5 values. */
3121 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3122 case DW_LANG_Go
: printf ("(Go)"); break;
3123 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3124 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3125 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3126 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3127 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3128 case DW_LANG_Rust
: printf ("(Rust)"); break;
3129 case DW_LANG_C11
: printf ("(C11)"); break;
3130 case DW_LANG_Swift
: printf ("(Swift)"); break;
3131 case DW_LANG_Julia
: printf ("(Julia)"); break;
3132 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3133 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3134 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3135 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3136 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3137 /* MIPS extension. */
3138 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3139 /* UPC extension. */
3140 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3142 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3143 printf (_("(implementation defined: %s)"),
3144 dwarf_vmatoa ("x", uvalue
));
3146 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3151 case DW_AT_encoding
:
3155 case DW_ATE_void
: printf ("(void)"); break;
3156 case DW_ATE_address
: printf ("(machine address)"); break;
3157 case DW_ATE_boolean
: printf ("(boolean)"); break;
3158 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3159 case DW_ATE_float
: printf ("(float)"); break;
3160 case DW_ATE_signed
: printf ("(signed)"); break;
3161 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3162 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3163 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3164 /* DWARF 2.1 values: */
3165 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3166 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3167 /* DWARF 3 values: */
3168 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3169 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3170 case DW_ATE_edited
: printf ("(edited)"); break;
3171 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3172 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3173 /* DWARF 4 values: */
3174 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3175 /* DWARF 5 values: */
3176 case DW_ATE_UCS
: printf ("(UCS)"); break;
3177 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3179 /* HP extensions: */
3180 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3181 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3182 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3183 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3184 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3185 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3186 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3189 if (uvalue
>= DW_ATE_lo_user
3190 && uvalue
<= DW_ATE_hi_user
)
3191 printf (_("(user defined type)"));
3193 printf (_("(unknown type)"));
3198 case DW_AT_accessibility
:
3202 case DW_ACCESS_public
: printf ("(public)"); break;
3203 case DW_ACCESS_protected
: printf ("(protected)"); break;
3204 case DW_ACCESS_private
: printf ("(private)"); break;
3206 printf (_("(unknown accessibility)"));
3211 case DW_AT_visibility
:
3215 case DW_VIS_local
: printf ("(local)"); break;
3216 case DW_VIS_exported
: printf ("(exported)"); break;
3217 case DW_VIS_qualified
: printf ("(qualified)"); break;
3218 default: printf (_("(unknown visibility)")); break;
3222 case DW_AT_endianity
:
3226 case DW_END_default
: printf ("(default)"); break;
3227 case DW_END_big
: printf ("(big)"); break;
3228 case DW_END_little
: printf ("(little)"); break;
3230 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3231 printf (_("(user specified)"));
3233 printf (_("(unknown endianity)"));
3238 case DW_AT_virtuality
:
3242 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3243 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3244 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3245 default: printf (_("(unknown virtuality)")); break;
3249 case DW_AT_identifier_case
:
3253 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3254 case DW_ID_up_case
: printf ("(up_case)"); break;
3255 case DW_ID_down_case
: printf ("(down_case)"); break;
3256 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3257 default: printf (_("(unknown case)")); break;
3261 case DW_AT_calling_convention
:
3265 case DW_CC_normal
: printf ("(normal)"); break;
3266 case DW_CC_program
: printf ("(program)"); break;
3267 case DW_CC_nocall
: printf ("(nocall)"); break;
3268 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3269 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3270 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3271 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3273 if (uvalue
>= DW_CC_lo_user
3274 && uvalue
<= DW_CC_hi_user
)
3275 printf (_("(user defined)"));
3277 printf (_("(unknown convention)"));
3281 case DW_AT_ordering
:
3286 case -1: printf (_("(undefined)")); break;
3287 case 0: printf ("(row major)"); break;
3288 case 1: printf ("(column major)"); break;
3292 case DW_AT_decimal_sign
:
3296 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3297 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3298 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3299 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3300 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3301 default: printf (_("(unrecognised)")); break;
3305 case DW_AT_defaulted
:
3309 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3310 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3311 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3312 default: printf (_("(unrecognised)")); break;
3316 case DW_AT_discr_list
:
3318 display_discr_list (form
, uvalue
, data
, end
, level
);
3321 case DW_AT_frame_base
:
3322 have_frame_base
= 1;
3324 case DW_AT_location
:
3325 case DW_AT_string_length
:
3326 case DW_AT_return_addr
:
3327 case DW_AT_data_member_location
:
3328 case DW_AT_vtable_elem_location
:
3330 case DW_AT_static_link
:
3331 case DW_AT_use_location
:
3332 case DW_AT_call_value
:
3333 case DW_AT_GNU_call_site_value
:
3334 case DW_AT_call_data_value
:
3335 case DW_AT_GNU_call_site_data_value
:
3336 case DW_AT_call_target
:
3337 case DW_AT_GNU_call_site_target
:
3338 case DW_AT_call_target_clobbered
:
3339 case DW_AT_GNU_call_site_target_clobbered
:
3340 if ((dwarf_version
< 4
3341 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3342 || form
== DW_FORM_sec_offset
)
3343 printf (_(" (location list)"));
3345 case DW_AT_allocated
:
3346 case DW_AT_associated
:
3347 case DW_AT_data_location
:
3349 case DW_AT_upper_bound
:
3350 case DW_AT_lower_bound
:
3353 int need_frame_base
;
3356 need_frame_base
= decode_location_expression (block_start
,
3361 cu_offset
, section
);
3363 if (need_frame_base
&& !have_frame_base
)
3364 printf (_(" [without DW_AT_frame_base]"));
3368 case DW_AT_data_bit_offset
:
3369 case DW_AT_byte_size
:
3370 case DW_AT_bit_size
:
3371 case DW_AT_string_length_byte_size
:
3372 case DW_AT_string_length_bit_size
:
3373 case DW_AT_bit_stride
:
3374 if (form
== DW_FORM_exprloc
)
3377 (void) decode_location_expression (block_start
, pointer_size
,
3378 offset_size
, dwarf_version
,
3379 uvalue
, cu_offset
, section
);
3386 unsigned long abbrev_number
;
3387 abbrev_entry
*entry
;
3389 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3390 section
, & abbrev_number
, NULL
, NULL
);
3393 if (form
!= DW_FORM_GNU_ref_alt
)
3394 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3395 dwarf_vmatoa ("x", uvalue
),
3396 (unsigned long) (orig_data
- section
->start
));
3400 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3401 printf (" (%s)", get_TAG_name (entry
->tag
));
3414 static unsigned char *
3415 read_and_display_attr (unsigned long attribute
,
3417 dwarf_signed_vma implicit_const
,
3418 unsigned char * start
,
3419 unsigned char * data
,
3420 unsigned char * end
,
3421 dwarf_vma cu_offset
,
3422 dwarf_vma pointer_size
,
3423 dwarf_vma offset_size
,
3425 debug_info
* debug_info_p
,
3427 struct dwarf_section
* section
,
3428 struct cu_tu_set
* this_set
,
3432 printf (" %-18s:", get_AT_name (attribute
));
3433 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3435 cu_offset
, pointer_size
, offset_size
,
3436 dwarf_version
, debug_info_p
,
3437 do_loc
, section
, this_set
, ' ', level
);
3443 /* Like load_debug_section, but if the ordinary call fails, and we are
3444 following debug links, then attempt to load the requested section
3445 from one of the separate debug info files. */
3448 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3451 if (load_debug_section (sec_enum
, handle
))
3453 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3455 /* See if we can associate a filename with this section. */
3458 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3459 if (i
->handle
== handle
)
3461 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3469 if (do_follow_links
)
3473 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3475 if (load_debug_section (sec_enum
, i
->handle
))
3477 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3479 /* FIXME: We should check to see if any of the remaining debug info
3480 files also contain this section, and, umm, do something about it. */
3490 introduce (struct dwarf_section
* section
, bool raw
)
3494 if (do_follow_links
&& section
->filename
)
3495 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3496 section
->name
, section
->filename
);
3498 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3502 if (do_follow_links
&& section
->filename
)
3503 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3504 section
->name
, section
->filename
);
3506 printf (_("Contents of the %s section:\n\n"), section
->name
);
3510 /* Process the contents of a .debug_info section.
3511 If do_loc is TRUE then we are scanning for location lists and dwo tags
3512 and we do not want to display anything to the user.
3513 If do_types is TRUE, we are processing a .debug_types section instead of
3514 a .debug_info section.
3515 The information displayed is restricted by the values in DWARF_START_DIE
3516 and DWARF_CUTOFF_LEVEL.
3517 Returns TRUE upon success. Otherwise an error or warning message is
3518 printed and FALSE is returned. */
3521 process_debug_info (struct dwarf_section
* section
,
3523 enum dwarf_section_display_enum abbrev_sec
,
3527 unsigned char *start
= section
->start
;
3528 unsigned char *end
= start
+ section
->size
;
3529 unsigned char *section_begin
;
3531 unsigned int num_units
= 0;
3533 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3534 && num_debug_info_entries
== 0
3539 /* First scan the section to get the number of comp units. */
3540 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3543 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3544 will be the length. For a 64-bit DWARF section, it'll be
3545 the escape code 0xffffffff followed by an 8 byte length. */
3546 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3548 if (length
== 0xffffffff)
3550 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3551 section_begin
+= length
+ 12;
3553 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3555 warn (_("Reserved length value (0x%s) found in section %s\n"),
3556 dwarf_vmatoa ("x", length
), section
->name
);
3560 section_begin
+= length
+ 4;
3562 /* Negative values are illegal, they may even cause infinite
3563 looping. This can happen if we can't accurately apply
3564 relocations to an object file, or if the file is corrupt. */
3565 if ((signed long) length
<= 0 || section_begin
< start
)
3567 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3568 dwarf_vmatoa ("x", length
), section
->name
);
3575 error (_("No comp units in %s section ?\n"), section
->name
);
3579 /* Then allocate an array to hold the information. */
3580 debug_information
= (debug_info
*) cmalloc (num_units
,
3581 sizeof (* debug_information
));
3582 if (debug_information
== NULL
)
3584 error (_("Not enough memory for a debug info array of %u entries\n"),
3586 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3590 /* PR 17531: file: 92ca3797.
3591 We cannot rely upon the debug_information array being initialised
3592 before it is used. A corrupt file could easily contain references
3593 to a unit for which information has not been made available. So
3594 we ensure that the array is zeroed here. */
3595 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3597 alloc_num_debug_info_entries
= num_units
;
3602 load_debug_section_with_follow (str
, file
);
3603 load_debug_section_with_follow (line_str
, file
);
3604 load_debug_section_with_follow (str_dwo
, file
);
3605 load_debug_section_with_follow (str_index
, file
);
3606 load_debug_section_with_follow (str_index_dwo
, file
);
3607 load_debug_section_with_follow (debug_addr
, file
);
3610 load_debug_section_with_follow (abbrev_sec
, file
);
3611 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3613 warn (_("Unable to locate %s section!\n"),
3614 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3618 if (!do_loc
&& dwarf_start_die
== 0)
3619 introduce (section
, false);
3621 free_all_abbrevs ();
3622 free (cu_abbrev_map
);
3623 cu_abbrev_map
= NULL
;
3624 next_free_abbrev_map_entry
= 0;
3626 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3627 to load *all* of the abbrevs for all CUs in this .debug_info
3628 section. This does effectively mean that we (partially) read
3629 every CU header twice. */
3630 for (section_begin
= start
; start
< end
;)
3632 DWARF2_Internal_CompUnit compunit
;
3633 unsigned char * hdrptr
;
3634 dwarf_vma abbrev_base
;
3636 dwarf_vma cu_offset
;
3637 unsigned int offset_size
;
3638 unsigned int initial_length_size
;
3639 struct cu_tu_set
* this_set
;
3644 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3646 if (compunit
.cu_length
== 0xffffffff)
3648 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3650 initial_length_size
= 12;
3655 initial_length_size
= 4;
3658 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3660 cu_offset
= start
- section_begin
;
3662 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3664 if (compunit
.cu_version
< 5)
3666 compunit
.cu_unit_type
= DW_UT_compile
;
3667 /* Initialize it due to a false compiler warning. */
3668 compunit
.cu_pointer_size
= -1;
3672 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3673 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3675 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3678 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3680 if (compunit
.cu_unit_type
== DW_UT_split_compile
3681 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3684 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3687 if (this_set
== NULL
)
3690 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3694 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3695 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3698 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3699 compunit
.cu_abbrev_offset
);
3702 unsigned char * next
;
3704 list
= new_abbrev_list (abbrev_base
,
3705 compunit
.cu_abbrev_offset
);
3706 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3707 abbrev_base
, abbrev_size
,
3708 compunit
.cu_abbrev_offset
, list
);
3709 list
->start_of_next_abbrevs
= next
;
3712 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3713 + initial_length_size
;
3714 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3717 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3719 DWARF2_Internal_CompUnit compunit
;
3720 unsigned char *hdrptr
;
3721 unsigned char *tags
;
3722 int level
, last_level
, saved_level
;
3723 dwarf_vma cu_offset
;
3724 unsigned long sec_off
;
3725 unsigned int offset_size
;
3726 unsigned int initial_length_size
;
3727 dwarf_vma signature_high
= 0;
3728 dwarf_vma signature_low
= 0;
3729 dwarf_vma type_offset
= 0;
3730 struct cu_tu_set
*this_set
;
3731 dwarf_vma abbrev_base
;
3733 abbrev_list
* list
= NULL
;
3737 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3739 if (compunit
.cu_length
== 0xffffffff)
3741 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3743 initial_length_size
= 12;
3748 initial_length_size
= 4;
3751 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3753 cu_offset
= start
- section_begin
;
3755 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3757 if (compunit
.cu_version
< 5)
3759 compunit
.cu_unit_type
= DW_UT_compile
;
3760 /* Initialize it due to a false compiler warning. */
3761 compunit
.cu_pointer_size
= -1;
3765 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3766 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3768 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3771 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3773 if (this_set
== NULL
)
3776 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3780 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3781 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3784 if (compunit
.cu_version
< 5)
3785 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3787 bool do_dwo_id
= false;
3788 uint64_t dwo_id
= 0;
3789 if (compunit
.cu_unit_type
== DW_UT_split_compile
3790 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3792 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3796 /* PR 17512: file: 001-108546-0.001:0.1. */
3797 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3799 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3800 compunit
.cu_pointer_size
, offset_size
);
3801 compunit
.cu_pointer_size
= offset_size
;
3806 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3808 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3811 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3812 + initial_length_size
))
3814 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3815 + initial_length_size
;
3819 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3820 && num_debug_info_entries
== 0
3821 && alloc_num_debug_info_entries
> unit
3824 debug_information
[unit
].cu_offset
= cu_offset
;
3825 debug_information
[unit
].pointer_size
3826 = compunit
.cu_pointer_size
;
3827 debug_information
[unit
].offset_size
= offset_size
;
3828 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3829 debug_information
[unit
].base_address
= 0;
3830 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3831 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3832 debug_information
[unit
].loc_offsets
= NULL
;
3833 debug_information
[unit
].have_frame_base
= NULL
;
3834 debug_information
[unit
].max_loc_offsets
= 0;
3835 debug_information
[unit
].num_loc_offsets
= 0;
3836 debug_information
[unit
].range_lists
= NULL
;
3837 debug_information
[unit
].max_range_lists
= 0;
3838 debug_information
[unit
].num_range_lists
= 0;
3841 if (!do_loc
&& dwarf_start_die
== 0)
3843 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3844 dwarf_vmatoa ("x", cu_offset
));
3845 printf (_(" Length: 0x%s (%s)\n"),
3846 dwarf_vmatoa ("x", compunit
.cu_length
),
3847 offset_size
== 8 ? "64-bit" : "32-bit");
3848 printf (_(" Version: %d\n"), compunit
.cu_version
);
3849 if (compunit
.cu_version
>= 5)
3851 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3853 printf (_(" Unit Type: %s (%x)\n"),
3854 name
? name
: "???",
3855 compunit
.cu_unit_type
);
3857 printf (_(" Abbrev Offset: 0x%s\n"),
3858 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3859 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3864 printf (_(" Signature: 0x%s\n"),
3865 dwarf_vmatoa64 (signature_high
, signature_low
,
3866 buf
, sizeof (buf
)));
3867 printf (_(" Type Offset: 0x%s\n"),
3868 dwarf_vmatoa ("x", type_offset
));
3871 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3872 if (this_set
!= NULL
)
3874 dwarf_vma
*offsets
= this_set
->section_offsets
;
3875 size_t *sizes
= this_set
->section_sizes
;
3877 printf (_(" Section contributions:\n"));
3878 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3879 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3880 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3881 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3882 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3883 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3884 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3885 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3886 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3887 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3888 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3889 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3893 sec_off
= cu_offset
+ initial_length_size
;
3894 if (sec_off
+ compunit
.cu_length
< sec_off
3895 || sec_off
+ compunit
.cu_length
> section
->size
)
3897 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3899 (unsigned long) cu_offset
,
3900 dwarf_vmatoa ("x", compunit
.cu_length
));
3906 start
+= compunit
.cu_length
+ initial_length_size
;
3908 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3910 warn (_("CU at offset %s contains corrupt or "
3911 "unsupported version number: %d.\n"),
3912 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3916 if (compunit
.cu_unit_type
!= DW_UT_compile
3917 && compunit
.cu_unit_type
!= DW_UT_partial
3918 && compunit
.cu_unit_type
!= DW_UT_type
3919 && compunit
.cu_unit_type
!= DW_UT_split_compile
3920 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3922 warn (_("CU at offset %s contains corrupt or "
3923 "unsupported unit type: %d.\n"),
3924 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3928 /* Process the abbrevs used by this compilation unit. */
3929 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3930 compunit
.cu_abbrev_offset
);
3933 unsigned char *next
;
3935 list
= new_abbrev_list (abbrev_base
,
3936 compunit
.cu_abbrev_offset
);
3937 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3938 abbrev_base
, abbrev_size
,
3939 compunit
.cu_abbrev_offset
, list
);
3940 list
->start_of_next_abbrevs
= next
;
3946 while (tags
< start
)
3948 unsigned long abbrev_number
;
3949 unsigned long die_offset
;
3950 abbrev_entry
*entry
;
3952 int do_printing
= 1;
3954 die_offset
= tags
- section_begin
;
3956 READ_ULEB (abbrev_number
, tags
, start
);
3958 /* A null DIE marks the end of a list of siblings or it may also be
3959 a section padding. */
3960 if (abbrev_number
== 0)
3962 /* Check if it can be a section padding for the last CU. */
3963 if (level
== 0 && start
== end
)
3967 for (chk
= tags
; chk
< start
; chk
++)
3974 if (!do_loc
&& die_offset
>= dwarf_start_die
3975 && (dwarf_cutoff_level
== -1
3976 || level
< dwarf_cutoff_level
))
3977 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3983 static unsigned num_bogus_warns
= 0;
3985 if (num_bogus_warns
< 3)
3987 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3988 die_offset
, section
->name
);
3990 if (num_bogus_warns
== 3)
3991 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3994 if (dwarf_start_die
!= 0 && level
< saved_level
)
4001 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4005 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4006 saved_level
= level
;
4007 do_printing
= (dwarf_cutoff_level
== -1
4008 || level
< dwarf_cutoff_level
);
4010 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4011 level
, die_offset
, abbrev_number
);
4012 else if (dwarf_cutoff_level
== -1
4013 || last_level
< dwarf_cutoff_level
)
4014 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4019 /* Scan through the abbreviation list until we reach the
4024 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4025 if (entry
->number
== abbrev_number
)
4030 if (!do_loc
&& do_printing
)
4035 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
4036 die_offset
, abbrev_number
);
4040 if (!do_loc
&& do_printing
)
4041 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4046 need_base_address
= 0;
4048 case DW_TAG_compile_unit
:
4049 need_base_address
= 1;
4050 need_dwo_info
= do_loc
;
4052 case DW_TAG_entry_point
:
4053 case DW_TAG_subprogram
:
4054 need_base_address
= 0;
4055 /* Assuming that there is no DW_AT_frame_base. */
4056 have_frame_base
= 0;
4060 debug_info
*debug_info_p
=
4061 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4062 ? debug_information
+ unit
: NULL
;
4064 assert (!debug_info_p
4065 || (debug_info_p
->num_loc_offsets
4066 == debug_info_p
->num_loc_views
));
4068 for (attr
= entry
->first_attr
;
4069 attr
&& attr
->attribute
;
4072 if (! do_loc
&& do_printing
)
4073 /* Show the offset from where the tag was extracted. */
4074 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
4075 tags
= read_and_display_attr (attr
->attribute
,
4077 attr
->implicit_const
,
4082 compunit
.cu_pointer_size
,
4084 compunit
.cu_version
,
4086 do_loc
|| ! do_printing
,
4092 /* If a locview attribute appears before a location one,
4093 make sure we don't associate it with an earlier
4096 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4099 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4100 debug_info_p
->num_loc_views
++;
4101 assert (debug_info_p
->num_loc_views
4102 == debug_info_p
->num_loc_offsets
);
4109 warn(_("DIE has locviews without loclist\n"));
4110 debug_info_p
->num_loc_views
--;
4117 if (entry
->children
)
4122 /* Set num_debug_info_entries here so that it can be used to check if
4123 we need to process .debug_loc and .debug_ranges sections. */
4124 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4125 && num_debug_info_entries
== 0
4128 if (num_units
> alloc_num_debug_info_entries
)
4129 num_debug_info_entries
= alloc_num_debug_info_entries
;
4131 num_debug_info_entries
= num_units
;
4140 /* Locate and scan the .debug_info section in the file and record the pointer
4141 sizes and offsets for the compilation units in it. Usually an executable
4142 will have just one pointer size, but this is not guaranteed, and so we try
4143 not to make any assumptions. Returns zero upon failure, or the number of
4144 compilation units upon success. */
4147 load_debug_info (void * file
)
4149 /* If we have already tried and failed to load the .debug_info
4150 section then do not bother to repeat the task. */
4151 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4154 /* If we already have the information there is nothing else to do. */
4155 if (num_debug_info_entries
> 0)
4156 return num_debug_info_entries
;
4158 /* If this is a DWARF package file, load the CU and TU indexes. */
4159 (void) load_cu_tu_indexes (file
);
4161 if (load_debug_section_with_follow (info
, file
)
4162 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4163 return num_debug_info_entries
;
4165 if (load_debug_section_with_follow (info_dwo
, file
)
4166 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4167 abbrev_dwo
, true, false))
4168 return num_debug_info_entries
;
4170 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4174 /* Read a DWARF .debug_line section header starting at DATA.
4175 Upon success returns an updated DATA pointer and the LINFO
4176 structure and the END_OF_SEQUENCE pointer will be filled in.
4177 Otherwise returns NULL. */
4179 static unsigned char *
4180 read_debug_line_header (struct dwarf_section
* section
,
4181 unsigned char * data
,
4182 unsigned char * end
,
4183 DWARF2_Internal_LineInfo
* linfo
,
4184 unsigned char ** end_of_sequence
)
4186 unsigned char *hdrptr
;
4187 unsigned int initial_length_size
;
4189 /* Extract information from the Line Number Program Header.
4190 (section 6.2.4 in the Dwarf3 doc). */
4193 /* Get and check the length of the block. */
4194 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4196 if (linfo
->li_length
== 0xffffffff)
4198 /* This section is 64-bit DWARF 3. */
4199 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4200 linfo
->li_offset_size
= 8;
4201 initial_length_size
= 12;
4205 linfo
->li_offset_size
= 4;
4206 initial_length_size
= 4;
4209 if (linfo
->li_length
+ initial_length_size
> section
->size
)
4211 /* If the length field has a relocation against it, then we should
4212 not complain if it is inaccurate (and probably negative). This
4213 happens in object files when the .debug_line section is actually
4214 comprised of several different .debug_line.* sections, (some of
4215 which may be removed by linker garbage collection), and a relocation
4216 is used to compute the correct length once that is done. */
4217 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4219 linfo
->li_length
= (end
- data
) - initial_length_size
;
4223 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4224 (long) linfo
->li_length
);
4229 /* Get and check the version number. */
4230 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4232 if (linfo
->li_version
!= 2
4233 && linfo
->li_version
!= 3
4234 && linfo
->li_version
!= 4
4235 && linfo
->li_version
!= 5)
4237 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4238 "is currently supported.\n"));
4242 if (linfo
->li_version
>= 5)
4244 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4246 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4247 if (linfo
->li_segment_size
!= 0)
4249 warn (_("The %s section contains "
4250 "unsupported segment selector size: %d.\n"),
4251 section
->name
, linfo
->li_segment_size
);
4256 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4257 linfo
->li_offset_size
, end
);
4258 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4260 if (linfo
->li_version
>= 4)
4262 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4264 if (linfo
->li_max_ops_per_insn
== 0)
4266 warn (_("Invalid maximum operations per insn.\n"));
4271 linfo
->li_max_ops_per_insn
= 1;
4273 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4274 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4275 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4276 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4278 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
4279 /* PR 17512: file:002-117414-0.004. */
4280 if (* end_of_sequence
> end
)
4282 warn (_("Line length %s extends beyond end of section\n"),
4283 dwarf_vmatoa ("u", linfo
->li_length
));
4284 * end_of_sequence
= end
;
4291 static unsigned char *
4292 display_formatted_table (unsigned char *data
,
4293 unsigned char *start
,
4295 const DWARF2_Internal_LineInfo
*linfo
,
4296 struct dwarf_section
*section
,
4299 unsigned char *format_start
, format_count
, *format
, formati
;
4300 dwarf_vma data_count
, datai
;
4301 unsigned int namepass
, last_entry
= 0;
4302 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4304 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4305 if (do_checks
&& format_count
> 5)
4306 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4307 table_name
, format_count
);
4309 format_start
= data
;
4310 for (formati
= 0; formati
< format_count
; formati
++)
4312 SKIP_ULEB (data
, end
);
4313 SKIP_ULEB (data
, end
);
4316 warn (_("%s: Corrupt format description entry\n"), table_name
);
4321 READ_ULEB (data_count
, data
, end
);
4322 if (data_count
== 0)
4324 printf (_("\n The %s is empty.\n"), table_name
);
4327 else if (data
== end
)
4329 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4330 table_name
, dwarf_vmatoa ("x", data_count
));
4334 else if (format_count
== 0)
4336 warn (_("%s: format count is zero, but the table is not empty\n"),
4341 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4342 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4345 printf (_(" Entry"));
4346 /* Delay displaying name as the last entry for better screen layout. */
4347 for (namepass
= 0; namepass
< 2; namepass
++)
4349 format
= format_start
;
4350 for (formati
= 0; formati
< format_count
; formati
++)
4352 dwarf_vma content_type
;
4354 READ_ULEB (content_type
, format
, end
);
4355 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4356 switch (content_type
)
4359 printf (_("\tName"));
4361 case DW_LNCT_directory_index
:
4362 printf (_("\tDir"));
4364 case DW_LNCT_timestamp
:
4365 printf (_("\tTime"));
4368 printf (_("\tSize"));
4371 printf (_("\tMD5\t\t\t"));
4374 printf (_("\t(Unknown format content type %s)"),
4375 dwarf_vmatoa ("u", content_type
));
4377 SKIP_ULEB (format
, end
);
4382 for (datai
= 0; datai
< data_count
; datai
++)
4384 unsigned char *datapass
= data
;
4386 printf (" %d", last_entry
++);
4387 /* Delay displaying name as the last entry for better screen layout. */
4388 for (namepass
= 0; namepass
< 2; namepass
++)
4390 format
= format_start
;
4392 for (formati
= 0; formati
< format_count
; formati
++)
4394 dwarf_vma content_type
, form
;
4396 READ_ULEB (content_type
, format
, end
);
4397 READ_ULEB (form
, format
, end
);
4398 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4399 0, 0, linfo
->li_offset_size
,
4400 linfo
->li_version
, NULL
,
4401 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4402 section
, NULL
, '\t', -1);
4406 if (data
== end
&& (datai
< data_count
- 1))
4408 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4417 display_debug_sup (struct dwarf_section
* section
,
4418 void * file ATTRIBUTE_UNUSED
)
4420 unsigned char * start
= section
->start
;
4421 unsigned char * end
= section
->start
+ section
->size
;
4422 unsigned int version
;
4423 char is_supplementary
;
4424 const unsigned char * sup_filename
;
4425 size_t sup_filename_len
;
4426 unsigned int num_read
;
4428 dwarf_vma checksum_len
;
4431 introduce (section
, true);
4432 if (section
->size
< 4)
4434 error (_("corrupt .debug_sup section: size is too small\n"));
4438 /* Read the data. */
4439 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4441 warn (_("corrupt .debug_sup section: version < 5"));
4443 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4444 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4445 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4447 sup_filename
= start
;
4448 if (is_supplementary
&& sup_filename
[0] != 0)
4449 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4451 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4452 if (sup_filename_len
== (size_t) (end
- start
))
4454 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4457 start
+= sup_filename_len
+ 1;
4459 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4462 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4466 if (checksum_len
> (dwarf_vma
) (end
- start
))
4468 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4469 checksum_len
= end
- start
;
4471 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4473 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4474 (long) ((end
- start
) - checksum_len
));
4477 printf (_(" Version: %u\n"), version
);
4478 printf (_(" Is Supp: %u\n"), is_supplementary
);
4479 printf (_(" Filename: %s\n"), sup_filename
);
4480 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4481 if (checksum_len
> 0)
4483 printf (_(" Checksum: "));
4484 while (checksum_len
--)
4485 printf ("0x%x ", * start
++ );
4492 display_debug_lines_raw (struct dwarf_section
* section
,
4493 unsigned char * data
,
4494 unsigned char * end
,
4497 unsigned char *start
= section
->start
;
4498 int verbose_view
= 0;
4500 introduce (section
, true);
4504 static DWARF2_Internal_LineInfo saved_linfo
;
4505 DWARF2_Internal_LineInfo linfo
;
4506 unsigned char *standard_opcodes
;
4507 unsigned char *end_of_sequence
;
4510 if (startswith (section
->name
, ".debug_line.")
4511 /* Note: the following does not apply to .debug_line.dwo sections.
4512 These are full debug_line sections. */
4513 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4515 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4516 section containing just the Line Number Statements. They are
4517 created by the assembler and intended to be used alongside gcc's
4518 -ffunction-sections command line option. When the linker's
4519 garbage collection decides to discard a .text.<foo> section it
4520 can then also discard the line number information in .debug_line.<foo>.
4522 Since the section is a fragment it does not have the details
4523 needed to fill out a LineInfo structure, so instead we use the
4524 details from the last full debug_line section that we processed. */
4525 end_of_sequence
= end
;
4526 standard_opcodes
= NULL
;
4527 linfo
= saved_linfo
;
4528 /* PR 17531: file: 0522b371. */
4529 if (linfo
.li_line_range
== 0)
4531 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4534 reset_state_machine (linfo
.li_default_is_stmt
);
4538 unsigned char * hdrptr
;
4540 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4541 & end_of_sequence
)) == NULL
)
4544 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4545 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4546 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4547 if (linfo
.li_version
>= 5)
4549 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4550 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4552 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4553 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4554 if (linfo
.li_version
>= 4)
4555 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4556 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4557 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4558 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4559 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4561 /* PR 17512: file: 1665-6428-0.004. */
4562 if (linfo
.li_line_range
== 0)
4564 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4565 linfo
.li_line_range
= 1;
4568 reset_state_machine (linfo
.li_default_is_stmt
);
4570 /* Display the contents of the Opcodes table. */
4571 standard_opcodes
= hdrptr
;
4573 /* PR 17512: file: 002-417945-0.004. */
4574 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4576 warn (_("Line Base extends beyond end of section\n"));
4580 printf (_("\n Opcodes:\n"));
4582 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4583 printf (ngettext (" Opcode %d has %d arg\n",
4584 " Opcode %d has %d args\n",
4585 standard_opcodes
[i
- 1]),
4586 i
, standard_opcodes
[i
- 1]);
4588 /* Display the contents of the Directory table. */
4589 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4591 if (linfo
.li_version
>= 5)
4593 load_debug_section_with_follow (line_str
, file
);
4595 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4597 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4603 printf (_("\n The Directory Table is empty.\n"));
4606 unsigned int last_dir_entry
= 0;
4608 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4609 (long)(data
- start
));
4611 while (data
< end
&& *data
!= 0)
4613 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4615 data
+= strnlen ((char *) data
, end
- data
) + 1;
4618 /* PR 17512: file: 002-132094-0.004. */
4619 if (data
>= end
- 1)
4623 /* Skip the NUL at the end of the table. */
4626 /* Display the contents of the File Name table. */
4628 printf (_("\n The File Name Table is empty.\n"));
4631 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4632 (long)(data
- start
));
4633 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4635 while (data
< end
&& *data
!= 0)
4637 unsigned char *name
;
4640 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4642 data
+= strnlen ((char *) data
, end
- data
) + 1;
4644 READ_ULEB (val
, data
, end
);
4645 printf ("%s\t", dwarf_vmatoa ("u", val
));
4646 READ_ULEB (val
, data
, end
);
4647 printf ("%s\t", dwarf_vmatoa ("u", val
));
4648 READ_ULEB (val
, data
, end
);
4649 printf ("%s\t", dwarf_vmatoa ("u", val
));
4650 printf ("%.*s\n", (int)(end
- name
), name
);
4654 warn (_("Corrupt file name table entry\n"));
4660 /* Skip the NUL at the end of the table. */
4665 saved_linfo
= linfo
;
4668 /* Now display the statements. */
4669 if (data
>= end_of_sequence
)
4670 printf (_(" No Line Number Statements.\n"));
4673 printf (_(" Line Number Statements:\n"));
4675 while (data
< end_of_sequence
)
4677 unsigned char op_code
;
4678 dwarf_signed_vma adv
;
4681 printf (" [0x%08lx]", (long)(data
- start
));
4685 if (op_code
>= linfo
.li_opcode_base
)
4687 op_code
-= linfo
.li_opcode_base
;
4688 uladv
= (op_code
/ linfo
.li_line_range
);
4689 if (linfo
.li_max_ops_per_insn
== 1)
4691 uladv
*= linfo
.li_min_insn_length
;
4692 state_machine_regs
.address
+= uladv
;
4694 state_machine_regs
.view
= 0;
4695 printf (_(" Special opcode %d: "
4696 "advance Address by %s to 0x%s%s"),
4697 op_code
, dwarf_vmatoa ("u", uladv
),
4698 dwarf_vmatoa ("x", state_machine_regs
.address
),
4699 verbose_view
&& uladv
4700 ? _(" (reset view)") : "");
4705 = ((state_machine_regs
.op_index
+ uladv
)
4706 / linfo
.li_max_ops_per_insn
)
4707 * linfo
.li_min_insn_length
;
4709 state_machine_regs
.address
+= addrdelta
;
4710 state_machine_regs
.op_index
4711 = (state_machine_regs
.op_index
+ uladv
)
4712 % linfo
.li_max_ops_per_insn
;
4714 state_machine_regs
.view
= 0;
4715 printf (_(" Special opcode %d: "
4716 "advance Address by %s to 0x%s[%d]%s"),
4717 op_code
, dwarf_vmatoa ("u", uladv
),
4718 dwarf_vmatoa ("x", state_machine_regs
.address
),
4719 state_machine_regs
.op_index
,
4720 verbose_view
&& addrdelta
4721 ? _(" (reset view)") : "");
4723 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4724 state_machine_regs
.line
+= adv
;
4725 printf (_(" and Line by %s to %d"),
4726 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4727 if (verbose_view
|| state_machine_regs
.view
)
4728 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4731 state_machine_regs
.view
++;
4736 case DW_LNS_extended_op
:
4737 data
+= process_extended_line_op (data
,
4738 linfo
.li_default_is_stmt
,
4743 printf (_(" Copy"));
4744 if (verbose_view
|| state_machine_regs
.view
)
4745 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4748 state_machine_regs
.view
++;
4751 case DW_LNS_advance_pc
:
4752 READ_ULEB (uladv
, data
, end
);
4753 if (linfo
.li_max_ops_per_insn
== 1)
4755 uladv
*= linfo
.li_min_insn_length
;
4756 state_machine_regs
.address
+= uladv
;
4758 state_machine_regs
.view
= 0;
4759 printf (_(" Advance PC by %s to 0x%s%s\n"),
4760 dwarf_vmatoa ("u", uladv
),
4761 dwarf_vmatoa ("x", state_machine_regs
.address
),
4762 verbose_view
&& uladv
4763 ? _(" (reset view)") : "");
4768 = ((state_machine_regs
.op_index
+ uladv
)
4769 / linfo
.li_max_ops_per_insn
)
4770 * linfo
.li_min_insn_length
;
4771 state_machine_regs
.address
4773 state_machine_regs
.op_index
4774 = (state_machine_regs
.op_index
+ uladv
)
4775 % linfo
.li_max_ops_per_insn
;
4777 state_machine_regs
.view
= 0;
4778 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4779 dwarf_vmatoa ("u", uladv
),
4780 dwarf_vmatoa ("x", state_machine_regs
.address
),
4781 state_machine_regs
.op_index
,
4782 verbose_view
&& addrdelta
4783 ? _(" (reset view)") : "");
4787 case DW_LNS_advance_line
:
4788 READ_SLEB (adv
, data
, end
);
4789 state_machine_regs
.line
+= adv
;
4790 printf (_(" Advance Line by %s to %d\n"),
4791 dwarf_vmatoa ("d", adv
),
4792 state_machine_regs
.line
);
4795 case DW_LNS_set_file
:
4796 READ_ULEB (uladv
, data
, end
);
4797 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4798 dwarf_vmatoa ("u", uladv
));
4799 state_machine_regs
.file
= uladv
;
4802 case DW_LNS_set_column
:
4803 READ_ULEB (uladv
, data
, end
);
4804 printf (_(" Set column to %s\n"),
4805 dwarf_vmatoa ("u", uladv
));
4806 state_machine_regs
.column
= uladv
;
4809 case DW_LNS_negate_stmt
:
4810 adv
= state_machine_regs
.is_stmt
;
4812 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4813 state_machine_regs
.is_stmt
= adv
;
4816 case DW_LNS_set_basic_block
:
4817 printf (_(" Set basic block\n"));
4818 state_machine_regs
.basic_block
= 1;
4821 case DW_LNS_const_add_pc
:
4822 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4823 if (linfo
.li_max_ops_per_insn
)
4825 uladv
*= linfo
.li_min_insn_length
;
4826 state_machine_regs
.address
+= uladv
;
4828 state_machine_regs
.view
= 0;
4829 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4830 dwarf_vmatoa ("u", uladv
),
4831 dwarf_vmatoa ("x", state_machine_regs
.address
),
4832 verbose_view
&& uladv
4833 ? _(" (reset view)") : "");
4838 = ((state_machine_regs
.op_index
+ uladv
)
4839 / linfo
.li_max_ops_per_insn
)
4840 * linfo
.li_min_insn_length
;
4841 state_machine_regs
.address
4843 state_machine_regs
.op_index
4844 = (state_machine_regs
.op_index
+ uladv
)
4845 % linfo
.li_max_ops_per_insn
;
4847 state_machine_regs
.view
= 0;
4848 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4849 dwarf_vmatoa ("u", uladv
),
4850 dwarf_vmatoa ("x", state_machine_regs
.address
),
4851 state_machine_regs
.op_index
,
4852 verbose_view
&& addrdelta
4853 ? _(" (reset view)") : "");
4857 case DW_LNS_fixed_advance_pc
:
4858 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4859 state_machine_regs
.address
+= uladv
;
4860 state_machine_regs
.op_index
= 0;
4861 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4862 dwarf_vmatoa ("u", uladv
),
4863 dwarf_vmatoa ("x", state_machine_regs
.address
));
4864 /* Do NOT reset view. */
4867 case DW_LNS_set_prologue_end
:
4868 printf (_(" Set prologue_end to true\n"));
4871 case DW_LNS_set_epilogue_begin
:
4872 printf (_(" Set epilogue_begin to true\n"));
4875 case DW_LNS_set_isa
:
4876 READ_ULEB (uladv
, data
, end
);
4877 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4881 printf (_(" Unknown opcode %d with operands: "), op_code
);
4883 if (standard_opcodes
!= NULL
)
4884 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4886 READ_ULEB (uladv
, data
, end
);
4887 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4888 i
== 1 ? "" : ", ");
4903 unsigned char *name
;
4904 unsigned int directory_index
;
4905 unsigned int modification_date
;
4906 unsigned int length
;
4909 /* Output a decoded representation of the .debug_line section. */
4912 display_debug_lines_decoded (struct dwarf_section
* section
,
4913 unsigned char * start
,
4914 unsigned char * data
,
4915 unsigned char * end
,
4918 static DWARF2_Internal_LineInfo saved_linfo
;
4920 introduce (section
, false);
4924 /* This loop amounts to one iteration per compilation unit. */
4925 DWARF2_Internal_LineInfo linfo
;
4926 unsigned char *standard_opcodes
;
4927 unsigned char *end_of_sequence
;
4929 File_Entry
*file_table
= NULL
;
4930 unsigned int n_files
= 0;
4931 unsigned char **directory_table
= NULL
;
4932 dwarf_vma n_directories
= 0;
4934 if (startswith (section
->name
, ".debug_line.")
4935 /* Note: the following does not apply to .debug_line.dwo sections.
4936 These are full debug_line sections. */
4937 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4939 /* See comment in display_debug_lines_raw(). */
4940 end_of_sequence
= end
;
4941 standard_opcodes
= NULL
;
4942 linfo
= saved_linfo
;
4943 /* PR 17531: file: 0522b371. */
4944 if (linfo
.li_line_range
== 0)
4946 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4949 reset_state_machine (linfo
.li_default_is_stmt
);
4953 unsigned char *hdrptr
;
4955 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4956 & end_of_sequence
)) == NULL
)
4959 /* PR 17531: file: 0522b371. */
4960 if (linfo
.li_line_range
== 0)
4962 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4963 linfo
.li_line_range
= 1;
4965 reset_state_machine (linfo
.li_default_is_stmt
);
4967 /* Save a pointer to the contents of the Opcodes table. */
4968 standard_opcodes
= hdrptr
;
4970 /* Traverse the Directory table just to count entries. */
4971 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4975 warn (_("opcode base of %d extends beyond end of section\n"),
4976 linfo
.li_opcode_base
);
4980 if (linfo
.li_version
>= 5)
4982 unsigned char *format_start
, format_count
, *format
;
4983 dwarf_vma formati
, entryi
;
4985 load_debug_section_with_follow (line_str
, fileptr
);
4987 /* Skip directories format. */
4988 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4989 if (do_checks
&& format_count
> 1)
4990 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4992 format_start
= data
;
4993 for (formati
= 0; formati
< format_count
; formati
++)
4995 SKIP_ULEB (data
, end
);
4996 SKIP_ULEB (data
, end
);
4999 READ_ULEB (n_directories
, data
, end
);
5002 warn (_("Corrupt directories list\n"));
5006 if (n_directories
== 0)
5007 directory_table
= NULL
;
5009 directory_table
= (unsigned char **)
5010 xmalloc (n_directories
* sizeof (unsigned char *));
5012 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5014 unsigned char **pathp
= &directory_table
[entryi
];
5016 format
= format_start
;
5017 for (formati
= 0; formati
< format_count
; formati
++)
5019 dwarf_vma content_type
, form
;
5022 READ_ULEB (content_type
, format
, end
);
5023 READ_ULEB (form
, format
, end
);
5026 warn (_("Corrupt directories list\n"));
5029 switch (content_type
)
5034 case DW_FORM_string
:
5037 case DW_FORM_line_strp
:
5038 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5040 /* Remove const by the cast. */
5041 *pathp
= (unsigned char *)
5042 fetch_indirect_line_string (uvalue
);
5047 data
= read_and_display_attr_value (0, form
, 0, start
,
5049 linfo
.li_offset_size
,
5056 warn (_("Corrupt directories list\n"));
5061 /* Skip files format. */
5062 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5063 if (do_checks
&& format_count
> 5)
5064 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5066 format_start
= data
;
5067 for (formati
= 0; formati
< format_count
; formati
++)
5069 SKIP_ULEB (data
, end
);
5070 SKIP_ULEB (data
, end
);
5073 READ_ULEB (n_files
, data
, end
);
5074 if (data
== end
&& n_files
> 0)
5076 warn (_("Corrupt file name list\n"));
5083 file_table
= (File_Entry
*) xcalloc (1, n_files
5084 * sizeof (File_Entry
));
5086 for (entryi
= 0; entryi
< n_files
; entryi
++)
5088 File_Entry
*file
= &file_table
[entryi
];
5090 format
= format_start
;
5091 for (formati
= 0; formati
< format_count
; formati
++)
5093 dwarf_vma content_type
, form
;
5097 READ_ULEB (content_type
, format
, end
);
5098 READ_ULEB (form
, format
, end
);
5101 warn (_("Corrupt file name list\n"));
5104 switch (content_type
)
5109 case DW_FORM_string
:
5112 case DW_FORM_line_strp
:
5113 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5115 /* Remove const by the cast. */
5116 file
->name
= (unsigned char *)
5117 fetch_indirect_line_string (uvalue
);
5121 case DW_LNCT_directory_index
:
5125 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5129 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5134 READ_ULEB (file
->directory_index
, tmp
, end
);
5139 data
= read_and_display_attr_value (0, form
, 0, start
,
5141 linfo
.li_offset_size
,
5148 warn (_("Corrupt file name list\n"));
5157 unsigned char *ptr_directory_table
= data
;
5159 while (data
< end
&& *data
!= 0)
5161 data
+= strnlen ((char *) data
, end
- data
) + 1;
5168 warn (_("directory table ends unexpectedly\n"));
5173 /* Go through the directory table again to save the directories. */
5174 directory_table
= (unsigned char **)
5175 xmalloc (n_directories
* sizeof (unsigned char *));
5178 while (*ptr_directory_table
!= 0)
5180 directory_table
[i
] = ptr_directory_table
;
5181 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
5182 ptr_directory_table
- end
) + 1;
5186 /* Skip the NUL at the end of the table. */
5189 /* Traverse the File Name table just to count the entries. */
5190 if (data
< end
&& *data
!= 0)
5192 unsigned char *ptr_file_name_table
= data
;
5194 while (data
< end
&& *data
!= 0)
5196 /* Skip Name, directory index, last modification
5197 time and length of file. */
5198 data
+= strnlen ((char *) data
, end
- data
) + 1;
5199 SKIP_ULEB (data
, end
);
5200 SKIP_ULEB (data
, end
);
5201 SKIP_ULEB (data
, end
);
5207 warn (_("file table ends unexpectedly\n"));
5212 /* Go through the file table again to save the strings. */
5213 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5216 while (*ptr_file_name_table
!= 0)
5218 file_table
[i
].name
= ptr_file_name_table
;
5219 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
5220 end
- ptr_file_name_table
) + 1;
5222 /* We are not interested in directory, time or size. */
5223 READ_ULEB (file_table
[i
].directory_index
,
5224 ptr_file_name_table
, end
);
5225 READ_ULEB (file_table
[i
].modification_date
,
5226 ptr_file_name_table
, end
);
5227 READ_ULEB (file_table
[i
].length
,
5228 ptr_file_name_table
, end
);
5234 /* Skip the NUL at the end of the table. */
5238 /* Print the Compilation Unit's name and a header. */
5239 if (file_table
== NULL
)
5240 printf (_("CU: No directory table\n"));
5241 else if (directory_table
== NULL
)
5242 printf (_("CU: %s:\n"), file_table
[0].name
);
5245 unsigned int ix
= file_table
[0].directory_index
;
5246 const char *directory
;
5251 else if (n_directories
== 0)
5252 directory
= _("<unknown>");
5253 else if (ix
> n_directories
)
5255 warn (_("directory index %u > number of directories %s\n"),
5256 ix
, dwarf_vmatoa ("u", n_directories
));
5257 directory
= _("<corrupt>");
5260 directory
= (char *) directory_table
[ix
- 1];
5262 if (do_wide
|| strlen (directory
) < 76)
5263 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5265 printf ("%s:\n", file_table
[0].name
);
5269 printf (_("File name Line number Starting address View Stmt\n"));
5271 printf (_("CU: Empty file name table\n"));
5272 saved_linfo
= linfo
;
5275 /* This loop iterates through the Dwarf Line Number Program. */
5276 while (data
< end_of_sequence
)
5278 unsigned char op_code
;
5281 unsigned long int uladv
;
5282 int is_special_opcode
= 0;
5287 if (op_code
>= linfo
.li_opcode_base
)
5289 op_code
-= linfo
.li_opcode_base
;
5290 uladv
= (op_code
/ linfo
.li_line_range
);
5291 if (linfo
.li_max_ops_per_insn
== 1)
5293 uladv
*= linfo
.li_min_insn_length
;
5294 state_machine_regs
.address
+= uladv
;
5296 state_machine_regs
.view
= 0;
5301 = ((state_machine_regs
.op_index
+ uladv
)
5302 / linfo
.li_max_ops_per_insn
)
5303 * linfo
.li_min_insn_length
;
5304 state_machine_regs
.address
5306 state_machine_regs
.op_index
5307 = (state_machine_regs
.op_index
+ uladv
)
5308 % linfo
.li_max_ops_per_insn
;
5310 state_machine_regs
.view
= 0;
5313 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5314 state_machine_regs
.line
+= adv
;
5315 is_special_opcode
= 1;
5316 /* Increment view after printing this row. */
5321 case DW_LNS_extended_op
:
5323 unsigned int ext_op_code_len
;
5324 unsigned char ext_op_code
;
5325 unsigned char *op_code_end
;
5326 unsigned char *op_code_data
= data
;
5328 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5329 op_code_end
= op_code_data
+ ext_op_code_len
;
5330 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5332 warn (_("Badly formed extended line op encountered!\n"));
5335 ext_op_code
= *op_code_data
++;
5339 switch (ext_op_code
)
5341 case DW_LNE_end_sequence
:
5342 /* Reset stuff after printing this row. */
5344 case DW_LNE_set_address
:
5345 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5347 op_code_end
- op_code_data
,
5349 state_machine_regs
.op_index
= 0;
5350 state_machine_regs
.view
= 0;
5352 case DW_LNE_define_file
:
5353 file_table
= (File_Entry
*) xrealloc
5354 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5356 ++state_machine_regs
.last_file_entry
;
5357 /* Source file name. */
5358 file_table
[n_files
].name
= op_code_data
;
5359 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5360 /* Directory index. */
5361 READ_ULEB (file_table
[n_files
].directory_index
,
5362 op_code_data
, op_code_end
);
5363 /* Last modification time. */
5364 READ_ULEB (file_table
[n_files
].modification_date
,
5365 op_code_data
, op_code_end
);
5367 READ_ULEB (file_table
[n_files
].length
,
5368 op_code_data
, op_code_end
);
5372 case DW_LNE_set_discriminator
:
5373 case DW_LNE_HP_set_sequence
:
5374 /* Simply ignored. */
5378 printf (_("UNKNOWN (%u): length %ld\n"),
5379 ext_op_code
, (long int) (op_code_data
- data
));
5386 /* Increment view after printing this row. */
5389 case DW_LNS_advance_pc
:
5390 READ_ULEB (uladv
, data
, end
);
5391 if (linfo
.li_max_ops_per_insn
== 1)
5393 uladv
*= linfo
.li_min_insn_length
;
5394 state_machine_regs
.address
+= uladv
;
5396 state_machine_regs
.view
= 0;
5401 = ((state_machine_regs
.op_index
+ uladv
)
5402 / linfo
.li_max_ops_per_insn
)
5403 * linfo
.li_min_insn_length
;
5404 state_machine_regs
.address
5406 state_machine_regs
.op_index
5407 = (state_machine_regs
.op_index
+ uladv
)
5408 % linfo
.li_max_ops_per_insn
;
5410 state_machine_regs
.view
= 0;
5414 case DW_LNS_advance_line
:
5415 READ_SLEB (adv
, data
, end
);
5416 state_machine_regs
.line
+= adv
;
5419 case DW_LNS_set_file
:
5420 READ_ULEB (uladv
, data
, end
);
5421 state_machine_regs
.file
= uladv
;
5424 unsigned file
= state_machine_regs
.file
- 1;
5427 if (file_table
== NULL
|| n_files
== 0)
5428 printf (_("\n [Use file table entry %d]\n"), file
);
5430 else if (file
>= n_files
)
5432 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
5433 printf (_("\n <over large file table index %u>"), file
);
5435 else if ((dir
= file_table
[file
].directory_index
) == 0)
5436 /* If directory index is 0, that means current directory. */
5437 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5438 else if (directory_table
== NULL
|| n_directories
== 0)
5439 printf (_("\n [Use file %s in directory table entry %d]\n"),
5440 file_table
[file
].name
, dir
);
5442 else if (dir
> n_directories
)
5444 warn (_("directory index %u > number of directories %s\n"),
5445 dir
, dwarf_vmatoa ("u", n_directories
));
5446 printf (_("\n <over large directory table entry %u>\n"), dir
);
5449 printf ("\n%s/%s:\n",
5450 /* The directory index starts counting at 1. */
5451 directory_table
[dir
- 1], file_table
[file
].name
);
5455 case DW_LNS_set_column
:
5456 READ_ULEB (uladv
, data
, end
);
5457 state_machine_regs
.column
= uladv
;
5460 case DW_LNS_negate_stmt
:
5461 adv
= state_machine_regs
.is_stmt
;
5463 state_machine_regs
.is_stmt
= adv
;
5466 case DW_LNS_set_basic_block
:
5467 state_machine_regs
.basic_block
= 1;
5470 case DW_LNS_const_add_pc
:
5471 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5472 if (linfo
.li_max_ops_per_insn
== 1)
5474 uladv
*= linfo
.li_min_insn_length
;
5475 state_machine_regs
.address
+= uladv
;
5477 state_machine_regs
.view
= 0;
5482 = ((state_machine_regs
.op_index
+ uladv
)
5483 / linfo
.li_max_ops_per_insn
)
5484 * linfo
.li_min_insn_length
;
5485 state_machine_regs
.address
5487 state_machine_regs
.op_index
5488 = (state_machine_regs
.op_index
+ uladv
)
5489 % linfo
.li_max_ops_per_insn
;
5491 state_machine_regs
.view
= 0;
5495 case DW_LNS_fixed_advance_pc
:
5496 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5497 state_machine_regs
.address
+= uladv
;
5498 state_machine_regs
.op_index
= 0;
5499 /* Do NOT reset view. */
5502 case DW_LNS_set_prologue_end
:
5505 case DW_LNS_set_epilogue_begin
:
5508 case DW_LNS_set_isa
:
5509 READ_ULEB (uladv
, data
, end
);
5510 printf (_(" Set ISA to %lu\n"), uladv
);
5514 printf (_(" Unknown opcode %d with operands: "), op_code
);
5516 if (standard_opcodes
!= NULL
)
5517 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5521 READ_ULEB (val
, data
, end
);
5522 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5523 i
== 1 ? "" : ", ");
5529 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5530 to the DWARF address/line matrix. */
5531 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5532 || (xop
== DW_LNS_copy
))
5534 const unsigned int MAX_FILENAME_LENGTH
= 35;
5536 char *newFileName
= NULL
;
5537 size_t fileNameLength
;
5541 unsigned indx
= state_machine_regs
.file
- 1;
5543 if (indx
>= n_files
)
5545 warn (_("corrupt file index %u encountered\n"), indx
);
5546 fileName
= _("<corrupt>");
5549 fileName
= (char *) file_table
[indx
].name
;
5552 fileName
= _("<unknown>");
5554 fileNameLength
= strlen (fileName
);
5556 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5558 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5559 /* Truncate file name */
5560 strncpy (newFileName
,
5561 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5562 MAX_FILENAME_LENGTH
+ 1);
5563 /* FIXME: This is to pacify gcc-10 which can warn that the
5564 strncpy above might leave a non-NUL terminated string
5565 in newFileName. It won't, but gcc's analysis doesn't
5566 quite go far enough to discover this. */
5567 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5571 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5572 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5575 /* A row with end_seq set to true has a meaningful address, but
5576 the other information in the same row is not significant.
5577 In such a row, print line as "-", and don't print
5579 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5581 if (linfo
.li_max_ops_per_insn
== 1)
5583 if (xop
== -DW_LNE_end_sequence
)
5584 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5586 state_machine_regs
.address
);
5588 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5589 newFileName
, state_machine_regs
.line
,
5590 state_machine_regs
.address
);
5594 if (xop
== -DW_LNE_end_sequence
)
5595 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5597 state_machine_regs
.address
,
5598 state_machine_regs
.op_index
);
5600 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5601 newFileName
, state_machine_regs
.line
,
5602 state_machine_regs
.address
,
5603 state_machine_regs
.op_index
);
5608 if (linfo
.li_max_ops_per_insn
== 1)
5610 if (xop
== -DW_LNE_end_sequence
)
5611 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5613 state_machine_regs
.address
);
5615 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5616 newFileName
, state_machine_regs
.line
,
5617 state_machine_regs
.address
);
5621 if (xop
== -DW_LNE_end_sequence
)
5622 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5624 state_machine_regs
.address
,
5625 state_machine_regs
.op_index
);
5627 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5628 newFileName
, state_machine_regs
.line
,
5629 state_machine_regs
.address
,
5630 state_machine_regs
.op_index
);
5634 if (xop
!= -DW_LNE_end_sequence
)
5636 if (state_machine_regs
.view
)
5637 printf (" %6u", state_machine_regs
.view
);
5641 if (state_machine_regs
.is_stmt
)
5646 state_machine_regs
.view
++;
5648 if (xop
== -DW_LNE_end_sequence
)
5650 reset_state_machine (linfo
.li_default_is_stmt
);
5665 if (directory_table
)
5667 free (directory_table
);
5668 directory_table
= NULL
;
5679 display_debug_lines (struct dwarf_section
*section
, void *file
)
5681 unsigned char *data
= section
->start
;
5682 unsigned char *end
= data
+ section
->size
;
5684 int retValDecoded
= 1;
5686 if (do_debug_lines
== 0)
5687 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5689 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5690 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5692 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5693 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5695 if (!retValRaw
|| !retValDecoded
)
5702 find_debug_info_for_offset (unsigned long offset
)
5706 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5709 for (i
= 0; i
< num_debug_info_entries
; i
++)
5710 if (debug_information
[i
].cu_offset
== offset
)
5711 return debug_information
+ i
;
5717 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5719 /* See gdb/gdb-index.h. */
5720 static const char * const kinds
[] =
5732 return _ (kinds
[kind
]);
5736 display_debug_pubnames_worker (struct dwarf_section
*section
,
5737 void *file ATTRIBUTE_UNUSED
,
5740 DWARF2_Internal_PubNames names
;
5741 unsigned char *start
= section
->start
;
5742 unsigned char *end
= start
+ section
->size
;
5744 /* It does not matter if this load fails,
5745 we test for that later on. */
5746 load_debug_info (file
);
5748 introduce (section
, false);
5752 unsigned char *data
;
5753 unsigned long sec_off
;
5754 unsigned int offset_size
, initial_length_size
;
5756 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5757 if (names
.pn_length
== 0xffffffff)
5759 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5761 initial_length_size
= 12;
5766 initial_length_size
= 4;
5769 sec_off
= start
- section
->start
;
5770 if (sec_off
+ names
.pn_length
< sec_off
5771 || sec_off
+ names
.pn_length
> section
->size
)
5773 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5775 sec_off
- initial_length_size
,
5776 dwarf_vmatoa ("x", names
.pn_length
));
5781 start
+= names
.pn_length
;
5783 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5784 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5786 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5787 && num_debug_info_entries
> 0
5788 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5789 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5790 (unsigned long) names
.pn_offset
, section
->name
);
5792 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5794 printf (_(" Length: %ld\n"),
5795 (long) names
.pn_length
);
5796 printf (_(" Version: %d\n"),
5798 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5799 (unsigned long) names
.pn_offset
);
5800 printf (_(" Size of area in .debug_info section: %ld\n"),
5801 (long) names
.pn_size
);
5803 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5805 static int warned
= 0;
5809 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5817 printf (_("\n Offset Kind Name\n"));
5819 printf (_("\n Offset\tName\n"));
5823 bfd_size_type maxprint
;
5826 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5831 data
+= offset_size
;
5834 maxprint
= (end
- data
) - 1;
5838 unsigned int kind_data
;
5839 gdb_index_symbol_kind kind
;
5840 const char *kind_name
;
5843 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5846 /* GCC computes the kind as the upper byte in the CU index
5847 word, and then right shifts it by the CU index size.
5848 Left shift KIND to where the gdb-index.h accessor macros
5850 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5851 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5852 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5853 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5854 printf (" %-6lx %s,%-10s %.*s\n",
5855 (unsigned long) offset
, is_static
? _("s") : _("g"),
5856 kind_name
, (int) maxprint
, data
);
5859 printf (" %-6lx\t%.*s\n",
5860 (unsigned long) offset
, (int) maxprint
, data
);
5862 data
+= strnlen ((char *) data
, maxprint
) + 1;
5873 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5875 return display_debug_pubnames_worker (section
, file
, 0);
5879 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5881 return display_debug_pubnames_worker (section
, file
, 1);
5885 display_debug_macinfo (struct dwarf_section
*section
,
5886 void *file ATTRIBUTE_UNUSED
)
5888 unsigned char *start
= section
->start
;
5889 unsigned char *end
= start
+ section
->size
;
5890 unsigned char *curr
= start
;
5891 enum dwarf_macinfo_record_type op
;
5893 introduce (section
, false);
5897 unsigned int lineno
;
5898 const unsigned char *string
;
5900 op
= (enum dwarf_macinfo_record_type
) *curr
;
5905 case DW_MACINFO_start_file
:
5907 unsigned int filenum
;
5909 READ_ULEB (lineno
, curr
, end
);
5910 READ_ULEB (filenum
, curr
, end
);
5911 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5916 case DW_MACINFO_end_file
:
5917 printf (_(" DW_MACINFO_end_file\n"));
5920 case DW_MACINFO_define
:
5921 READ_ULEB (lineno
, curr
, end
);
5923 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5924 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5928 case DW_MACINFO_undef
:
5929 READ_ULEB (lineno
, curr
, end
);
5931 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5932 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5936 case DW_MACINFO_vendor_ext
:
5938 unsigned int constant
;
5940 READ_ULEB (constant
, curr
, end
);
5942 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5943 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5953 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5954 filename and dirname corresponding to file name table entry with index
5955 FILEIDX. Return NULL on failure. */
5957 static unsigned char *
5958 get_line_filename_and_dirname (dwarf_vma line_offset
,
5960 unsigned char **dir_name
)
5962 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5963 unsigned char *hdrptr
, *dirtable
, *file_name
;
5964 unsigned int offset_size
, initial_length_size
;
5965 unsigned int version
, opcode_base
;
5966 dwarf_vma length
, diridx
;
5967 const unsigned char * end
;
5970 if (section
->start
== NULL
5971 || line_offset
>= section
->size
5975 hdrptr
= section
->start
+ line_offset
;
5976 end
= section
->start
+ section
->size
;
5978 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5979 if (length
== 0xffffffff)
5981 /* This section is 64-bit DWARF 3. */
5982 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5984 initial_length_size
= 12;
5989 initial_length_size
= 4;
5991 if (length
+ initial_length_size
< length
5992 || length
+ initial_length_size
> section
->size
)
5995 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5996 if (version
!= 2 && version
!= 3 && version
!= 4)
5998 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6000 hdrptr
++; /* Skip max_ops_per_insn. */
6001 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6003 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6004 if (opcode_base
== 0)
6007 hdrptr
+= opcode_base
- 1;
6012 /* Skip over dirname table. */
6013 while (*hdrptr
!= '\0')
6015 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
6019 hdrptr
++; /* Skip the NUL at the end of the table. */
6021 /* Now skip over preceding filename table entries. */
6022 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6024 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
6025 SKIP_ULEB (hdrptr
, end
);
6026 SKIP_ULEB (hdrptr
, end
);
6027 SKIP_ULEB (hdrptr
, end
);
6029 if (hdrptr
>= end
|| *hdrptr
== '\0')
6033 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
6036 READ_ULEB (diridx
, hdrptr
, end
);
6039 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6040 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
6041 if (dirtable
>= end
|| *dirtable
== '\0')
6043 *dir_name
= dirtable
;
6048 display_debug_macro (struct dwarf_section
*section
,
6051 unsigned char *start
= section
->start
;
6052 unsigned char *end
= start
+ section
->size
;
6053 unsigned char *curr
= start
;
6054 unsigned char *extended_op_buf
[256];
6055 bool is_dwo
= false;
6056 const char *suffix
= strrchr (section
->name
, '.');
6058 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6061 load_debug_section_with_follow (str
, file
);
6062 load_debug_section_with_follow (line
, file
);
6063 load_debug_section_with_follow (str_index
, file
);
6065 introduce (section
, false);
6069 unsigned int lineno
, version
, flags
;
6070 unsigned int offset_size
;
6071 const unsigned char *string
;
6072 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
6073 unsigned char **extended_ops
= NULL
;
6075 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6076 if (version
!= 4 && version
!= 5)
6078 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6079 section
->name
, version
);
6083 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6084 offset_size
= (flags
& 1) ? 8 : 4;
6085 printf (_(" Offset: 0x%lx\n"),
6086 (unsigned long) sec_offset
);
6087 printf (_(" Version: %d\n"), version
);
6088 printf (_(" Offset size: %d\n"), offset_size
);
6091 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6092 printf (_(" Offset into .debug_line: 0x%lx\n"),
6093 (unsigned long) line_offset
);
6097 unsigned int i
, count
, op
;
6100 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6102 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6103 extended_ops
= extended_op_buf
;
6106 printf (_(" Extension opcode arguments:\n"));
6107 for (i
= 0; i
< count
; i
++)
6109 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6110 extended_ops
[op
] = curr
;
6111 READ_ULEB (nargs
, curr
, end
);
6113 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6116 printf (_(" DW_MACRO_%02x arguments: "), op
);
6117 for (n
= 0; n
< nargs
; n
++)
6121 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6122 printf ("%s%s", get_FORM_name (form
),
6123 n
== nargs
- 1 ? "\n" : ", ");
6133 case DW_FORM_block1
:
6134 case DW_FORM_block2
:
6135 case DW_FORM_block4
:
6137 case DW_FORM_string
:
6139 case DW_FORM_sec_offset
:
6142 error (_("Invalid extension opcode form %s\n"),
6143 get_FORM_name (form
));
6159 error (_(".debug_macro section not zero terminated\n"));
6163 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6169 case DW_MACRO_define
:
6170 READ_ULEB (lineno
, curr
, end
);
6172 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6173 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
6177 case DW_MACRO_undef
:
6178 READ_ULEB (lineno
, curr
, end
);
6180 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6181 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
6185 case DW_MACRO_start_file
:
6187 unsigned int filenum
;
6188 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6190 READ_ULEB (lineno
, curr
, end
);
6191 READ_ULEB (filenum
, curr
, end
);
6193 if ((flags
& 2) == 0)
6194 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6197 = get_line_filename_and_dirname (line_offset
, filenum
,
6199 if (file_name
== NULL
)
6200 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6203 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6205 dir_name
!= NULL
? (const char *) dir_name
: "",
6206 dir_name
!= NULL
? "/" : "", file_name
);
6210 case DW_MACRO_end_file
:
6211 printf (_(" DW_MACRO_end_file\n"));
6214 case DW_MACRO_define_strp
:
6215 READ_ULEB (lineno
, curr
, end
);
6216 if (version
== 4 && is_dwo
)
6217 READ_ULEB (offset
, curr
, end
);
6219 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6220 string
= fetch_indirect_string (offset
);
6221 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6225 case DW_MACRO_undef_strp
:
6226 READ_ULEB (lineno
, curr
, end
);
6227 if (version
== 4 && is_dwo
)
6228 READ_ULEB (offset
, curr
, end
);
6230 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6231 string
= fetch_indirect_string (offset
);
6232 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6236 case DW_MACRO_import
:
6237 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6238 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6239 (unsigned long) offset
);
6242 case DW_MACRO_define_sup
:
6243 READ_ULEB (lineno
, curr
, end
);
6244 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6245 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6246 lineno
, (unsigned long) offset
);
6249 case DW_MACRO_undef_sup
:
6250 READ_ULEB (lineno
, curr
, end
);
6251 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6252 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6253 lineno
, (unsigned long) offset
);
6256 case DW_MACRO_import_sup
:
6257 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6258 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6259 (unsigned long) offset
);
6262 case DW_MACRO_define_strx
:
6263 case DW_MACRO_undef_strx
:
6264 READ_ULEB (lineno
, curr
, end
);
6265 READ_ULEB (offset
, curr
, end
);
6266 string
= (const unsigned char *)
6267 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6268 if (op
== DW_MACRO_define_strx
)
6269 printf (" DW_MACRO_define_strx ");
6271 printf (" DW_MACRO_undef_strx ");
6273 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6274 printf (_("lineno : %d macro : %s\n"),
6279 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6281 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6285 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6287 error (_(" Unknown macro opcode %02x seen\n"), op
);
6292 /* Skip over unhandled opcodes. */
6294 unsigned char *desc
= extended_ops
[op
];
6295 READ_ULEB (nargs
, desc
, end
);
6298 printf (_(" DW_MACRO_%02x\n"), op
);
6301 printf (_(" DW_MACRO_%02x -"), op
);
6302 for (n
= 0; n
< nargs
; n
++)
6306 /* DW_FORM_implicit_const is not expected here. */
6307 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6309 = read_and_display_attr_value (0, val
, 0,
6310 start
, curr
, end
, 0, 0, offset_size
,
6311 version
, NULL
, 0, NULL
,
6329 display_debug_abbrev (struct dwarf_section
*section
,
6330 void *file ATTRIBUTE_UNUSED
)
6332 abbrev_entry
*entry
;
6333 unsigned char *start
= section
->start
;
6335 introduce (section
, false);
6342 offset
= start
- section
->start
;
6343 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6346 list
= new_abbrev_list (0, offset
);
6347 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6348 list
->start_of_next_abbrevs
= start
;
6351 start
= list
->start_of_next_abbrevs
;
6353 if (list
->first_abbrev
== NULL
)
6356 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6358 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6362 printf (" %ld %s [%s]\n",
6364 get_TAG_name (entry
->tag
),
6365 entry
->children
? _("has children") : _("no children"));
6367 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6369 printf (" %-18s %s",
6370 get_AT_name (attr
->attribute
),
6371 get_FORM_name (attr
->form
));
6372 if (attr
->form
== DW_FORM_implicit_const
)
6373 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
6385 /* Return true when ADDR is the maximum address, when addresses are
6386 POINTER_SIZE bytes long. */
6389 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6391 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6392 return ((addr
& mask
) == mask
);
6395 /* Display a view pair list starting at *VSTART_PTR and ending at
6396 VLISTEND within SECTION. */
6399 display_view_pair_list (struct dwarf_section
*section
,
6400 unsigned char **vstart_ptr
,
6401 unsigned int debug_info_entry
,
6402 unsigned char *vlistend
)
6404 unsigned char *vstart
= *vstart_ptr
;
6405 unsigned char *section_end
= section
->start
+ section
->size
;
6406 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6408 if (vlistend
< section_end
)
6409 section_end
= vlistend
;
6413 while (vstart
< section_end
)
6415 dwarf_vma off
= vstart
- section
->start
;
6416 dwarf_vma vbegin
, vend
;
6418 READ_ULEB (vbegin
, vstart
, section_end
);
6419 if (vstart
== section_end
)
6422 READ_ULEB (vend
, vstart
, section_end
);
6423 printf (" %8.8lx ", (unsigned long) off
);
6425 print_dwarf_view (vbegin
, pointer_size
, 1);
6426 print_dwarf_view (vend
, pointer_size
, 1);
6427 printf (_("location view pair\n"));
6431 *vstart_ptr
= vstart
;
6434 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6437 display_loc_list (struct dwarf_section
*section
,
6438 unsigned char **start_ptr
,
6439 unsigned int debug_info_entry
,
6441 dwarf_vma base_address
,
6442 unsigned char **vstart_ptr
,
6445 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6446 unsigned char *section_end
= section
->start
+ section
->size
;
6447 unsigned long cu_offset
;
6448 unsigned int pointer_size
;
6449 unsigned int offset_size
;
6454 unsigned short length
;
6455 int need_frame_base
;
6457 if (debug_info_entry
>= num_debug_info_entries
)
6459 warn (_("No debug information available for loc lists of entry: %u\n"),
6464 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6465 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6466 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6467 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6469 if (pointer_size
< 2 || pointer_size
> 8)
6471 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6472 pointer_size
, debug_info_entry
);
6478 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6479 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6481 if (start
+ 2 * pointer_size
> section_end
)
6483 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6484 (unsigned long) offset
);
6488 printf (" %8.8lx ", (unsigned long) off
);
6490 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6491 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6493 if (begin
== 0 && end
== 0)
6495 /* PR 18374: In a object file we can have a location list that
6496 starts with a begin and end of 0 because there are relocations
6497 that need to be applied to the addresses. Actually applying
6498 the relocations now does not help as they will probably resolve
6499 to 0, since the object file has not been fully linked. Real
6500 end of list markers will not have any relocations against them. */
6501 if (! reloc_at (section
, off
)
6502 && ! reloc_at (section
, off
+ pointer_size
))
6504 printf (_("<End of list>\n"));
6509 /* Check base address specifiers. */
6510 if (is_max_address (begin
, pointer_size
)
6511 && !is_max_address (end
, pointer_size
))
6514 print_dwarf_vma (begin
, pointer_size
);
6515 print_dwarf_vma (end
, pointer_size
);
6516 printf (_("(base address)\n"));
6522 off
= offset
+ (vstart
- *start_ptr
);
6524 READ_ULEB (vbegin
, vstart
, section_end
);
6525 print_dwarf_view (vbegin
, pointer_size
, 1);
6527 READ_ULEB (vend
, vstart
, section_end
);
6528 print_dwarf_view (vend
, pointer_size
, 1);
6530 printf (_("views at %8.8lx for:\n %*s "),
6531 (unsigned long) off
, 8, "");
6534 if (start
+ 2 > section_end
)
6536 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6537 (unsigned long) offset
);
6541 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6543 if (start
+ length
> section_end
)
6545 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6546 (unsigned long) offset
);
6550 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6551 print_dwarf_vma (end
+ base_address
, pointer_size
);
6554 need_frame_base
= decode_location_expression (start
,
6559 cu_offset
, section
);
6562 if (need_frame_base
&& !has_frame_base
)
6563 printf (_(" [without DW_AT_frame_base]"));
6565 if (begin
== end
&& vbegin
== vend
)
6566 fputs (_(" (start == end)"), stdout
);
6567 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6568 fputs (_(" (start > end)"), stdout
);
6576 *vstart_ptr
= vstart
;
6579 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6582 display_loclists_list (struct dwarf_section
*section
,
6583 unsigned char **start_ptr
,
6584 unsigned int debug_info_entry
,
6586 dwarf_vma base_address
,
6587 unsigned char **vstart_ptr
,
6590 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6591 unsigned char *section_end
= section
->start
+ section
->size
;
6592 unsigned long cu_offset
;
6593 unsigned int pointer_size
;
6594 unsigned int offset_size
;
6597 /* Initialize it due to a false compiler warning. */
6598 dwarf_vma begin
= -1, vbegin
= -1;
6599 dwarf_vma end
= -1, vend
= -1;
6601 int need_frame_base
;
6603 if (debug_info_entry
>= num_debug_info_entries
)
6605 warn (_("No debug information available for "
6606 "loclists lists of entry: %u\n"),
6611 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6612 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6613 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6614 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6616 if (pointer_size
< 2 || pointer_size
> 8)
6618 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6619 pointer_size
, debug_info_entry
);
6625 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6626 enum dwarf_location_list_entry_type llet
;
6628 if (start
+ 1 > section_end
)
6630 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6631 (unsigned long) offset
);
6635 printf (" %8.8lx ", (unsigned long) off
);
6637 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6639 if (vstart
&& (llet
== DW_LLE_offset_pair
6640 || llet
== DW_LLE_start_end
6641 || llet
== DW_LLE_start_length
))
6643 off
= offset
+ (vstart
- *start_ptr
);
6645 READ_ULEB (vbegin
, vstart
, section_end
);
6646 print_dwarf_view (vbegin
, pointer_size
, 1);
6648 READ_ULEB (vend
, vstart
, section_end
);
6649 print_dwarf_view (vend
, pointer_size
, 1);
6651 printf (_("views at %8.8lx for:\n %*s "),
6652 (unsigned long) off
, 8, "");
6657 case DW_LLE_end_of_list
:
6658 printf (_("<End of list>\n"));
6660 case DW_LLE_offset_pair
:
6661 READ_ULEB (begin
, start
, section_end
);
6662 begin
+= base_address
;
6663 READ_ULEB (end
, start
, section_end
);
6664 end
+= base_address
;
6666 case DW_LLE_start_end
:
6667 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6668 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6670 case DW_LLE_start_length
:
6671 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6672 READ_ULEB (end
, start
, section_end
);
6675 case DW_LLE_base_address
:
6676 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6678 print_dwarf_vma (base_address
, pointer_size
);
6679 printf (_("(base address)\n"));
6681 #ifdef DW_LLE_view_pair
6682 case DW_LLE_view_pair
:
6684 printf (_("View pair entry in loclist with locviews attribute\n"));
6685 READ_ULEB (vbegin
, start
, section_end
);
6686 print_dwarf_view (vbegin
, pointer_size
, 1);
6688 READ_ULEB (vend
, start
, section_end
);
6689 print_dwarf_view (vend
, pointer_size
, 1);
6691 printf (_("views for:\n"));
6695 error (_("Invalid location list entry type %d\n"), llet
);
6698 if (llet
== DW_LLE_end_of_list
)
6700 if (llet
!= DW_LLE_offset_pair
6701 && llet
!= DW_LLE_start_end
6702 && llet
!= DW_LLE_start_length
)
6705 if (start
+ 2 > section_end
)
6707 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6708 (unsigned long) offset
);
6712 READ_ULEB (length
, start
, section_end
);
6714 print_dwarf_vma (begin
, pointer_size
);
6715 print_dwarf_vma (end
, pointer_size
);
6718 need_frame_base
= decode_location_expression (start
,
6723 cu_offset
, section
);
6726 if (need_frame_base
&& !has_frame_base
)
6727 printf (_(" [without DW_AT_frame_base]"));
6729 if (begin
== end
&& vbegin
== vend
)
6730 fputs (_(" (start == end)"), stdout
);
6731 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6732 fputs (_(" (start > end)"), stdout
);
6740 if (vbegin
!= vm1
|| vend
!= vm1
)
6741 printf (_("Trailing view pair not used in a range"));
6744 *vstart_ptr
= vstart
;
6747 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6748 right-adjusted in a field of length LEN, and followed by a space. */
6751 print_addr_index (unsigned int idx
, unsigned int len
)
6753 static char buf
[15];
6754 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6755 printf ("%*s ", len
, buf
);
6758 /* Display a location list from a .dwo section. It uses address indexes rather
6759 than embedded addresses. This code closely follows display_loc_list, but the
6760 two are sufficiently different that combining things is very ugly. */
6763 display_loc_list_dwo (struct dwarf_section
*section
,
6764 unsigned char **start_ptr
,
6765 unsigned int debug_info_entry
,
6767 unsigned char **vstart_ptr
,
6770 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6771 unsigned char *section_end
= section
->start
+ section
->size
;
6772 unsigned long cu_offset
;
6773 unsigned int pointer_size
;
6774 unsigned int offset_size
;
6777 unsigned short length
;
6778 int need_frame_base
;
6781 if (debug_info_entry
>= num_debug_info_entries
)
6783 warn (_("No debug information for loc lists of entry: %u\n"),
6788 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6789 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6790 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6791 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6793 if (pointer_size
< 2 || pointer_size
> 8)
6795 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6796 pointer_size
, debug_info_entry
);
6802 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6804 if (start
>= section_end
)
6806 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6807 (unsigned long) offset
);
6811 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6824 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6826 READ_ULEB (view
, vstart
, section_end
);
6827 print_dwarf_view (view
, 8, 1);
6829 READ_ULEB (view
, vstart
, section_end
);
6830 print_dwarf_view (view
, 8, 1);
6832 printf (_("views at %8.8lx for:\n %*s "),
6833 (unsigned long) off
, 8, "");
6841 case 0: /* A terminating entry. */
6843 *vstart_ptr
= vstart
;
6844 printf (_("<End of list>\n"));
6846 case 1: /* A base-address entry. */
6847 READ_ULEB (idx
, start
, section_end
);
6848 print_addr_index (idx
, 8);
6849 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6850 printf (_("(base address selection entry)\n"));
6852 case 2: /* A start/end entry. */
6853 READ_ULEB (idx
, start
, section_end
);
6854 print_addr_index (idx
, 8);
6855 READ_ULEB (idx
, start
, section_end
);
6856 print_addr_index (idx
, 8);
6858 case 3: /* A start/length entry. */
6859 READ_ULEB (idx
, start
, section_end
);
6860 print_addr_index (idx
, 8);
6861 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6862 printf ("%08x ", idx
);
6864 case 4: /* An offset pair entry. */
6865 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6866 printf ("%08x ", idx
);
6867 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6868 printf ("%08x ", idx
);
6871 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6873 *vstart_ptr
= vstart
;
6877 if (start
+ 2 > section_end
)
6879 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6880 (unsigned long) offset
);
6884 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6885 if (start
+ length
> section_end
)
6887 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6888 (unsigned long) offset
);
6893 need_frame_base
= decode_location_expression (start
,
6898 cu_offset
, section
);
6901 if (need_frame_base
&& !has_frame_base
)
6902 printf (_(" [without DW_AT_frame_base]"));
6910 *vstart_ptr
= vstart
;
6913 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6916 static dwarf_vma
*loc_offsets
, *loc_views
;
6919 loc_offsets_compar (const void *ap
, const void *bp
)
6921 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6922 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6924 int ret
= (a
> b
) - (b
> a
);
6928 a
= loc_views
[*(const unsigned int *) ap
];
6929 b
= loc_views
[*(const unsigned int *) bp
];
6931 ret
= (a
> b
) - (b
> a
);
6937 display_debug_loc (struct dwarf_section
*section
, void *file
)
6939 unsigned char *start
= section
->start
, *vstart
= NULL
;
6940 unsigned long bytes
;
6941 unsigned char *section_begin
= start
;
6942 unsigned int num_loc_list
= 0;
6943 unsigned long last_offset
= 0;
6944 unsigned long last_view
= 0;
6945 unsigned int first
= 0;
6948 int seen_first_offset
= 0;
6949 int locs_sorted
= 1;
6950 unsigned char *next
= start
, *vnext
= vstart
;
6951 unsigned int *array
= NULL
;
6952 const char *suffix
= strrchr (section
->name
, '.');
6953 bool is_dwo
= false;
6954 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6955 dwarf_vma expected_start
= 0;
6957 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6960 bytes
= section
->size
;
6964 printf (_("\nThe %s section is empty.\n"), section
->name
);
6970 unsigned char *hdrptr
= section_begin
;
6971 dwarf_vma ll_length
;
6972 unsigned short ll_version
;
6973 unsigned char *end
= section_begin
+ section
->size
;
6974 unsigned char address_size
, segment_selector_size
;
6975 uint32_t offset_entry_count
;
6977 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6978 if (ll_length
== 0xffffffff)
6979 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6981 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6982 if (ll_version
!= 5)
6984 warn (_("The %s section contains corrupt or "
6985 "unsupported version number: %d.\n"),
6986 section
->name
, ll_version
);
6990 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6992 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6993 if (segment_selector_size
!= 0)
6995 warn (_("The %s section contains "
6996 "unsupported segment selector size: %d.\n"),
6997 section
->name
, segment_selector_size
);
7001 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7002 if (offset_entry_count
!= 0)
7004 warn (_("The %s section contains "
7005 "unsupported offset entry count: %d.\n"),
7006 section
->name
, offset_entry_count
);
7010 expected_start
= hdrptr
- section_begin
;
7013 if (load_debug_info (file
) == 0)
7015 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7020 /* Check the order of location list in .debug_info section. If
7021 offsets of location lists are in the ascending order, we can
7022 use `debug_information' directly. */
7023 for (i
= 0; i
< num_debug_info_entries
; i
++)
7027 num
= debug_information
[i
].num_loc_offsets
;
7028 if (num
> num_loc_list
)
7031 /* Check if we can use `debug_information' directly. */
7032 if (locs_sorted
&& num
!= 0)
7034 if (!seen_first_offset
)
7036 /* This is the first location list. */
7037 last_offset
= debug_information
[i
].loc_offsets
[0];
7038 last_view
= debug_information
[i
].loc_views
[0];
7040 seen_first_offset
= 1;
7046 for (; j
< num
; j
++)
7049 debug_information
[i
].loc_offsets
[j
]
7050 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7051 && last_view
> debug_information
[i
].loc_views
[j
]))
7056 last_offset
= debug_information
[i
].loc_offsets
[j
];
7057 last_view
= debug_information
[i
].loc_views
[j
];
7062 if (!seen_first_offset
)
7063 error (_("No location lists in .debug_info section!\n"));
7065 if (debug_information
[first
].num_loc_offsets
> 0
7066 && debug_information
[first
].loc_offsets
[0] != expected_start
7067 && debug_information
[first
].loc_views
[0] != expected_start
)
7068 warn (_("Location lists in %s section start at 0x%s\n"),
7070 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
7073 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7075 introduce (section
, false);
7077 if (reloc_at (section
, 0))
7078 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7080 printf (_(" Offset Begin End Expression\n"));
7082 seen_first_offset
= 0;
7083 for (i
= first
; i
< num_debug_info_entries
; i
++)
7085 dwarf_vma offset
, voffset
;
7086 dwarf_vma base_address
;
7092 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7094 loc_offsets
= debug_information
[i
].loc_offsets
;
7095 loc_views
= debug_information
[i
].loc_views
;
7096 qsort (array
, debug_information
[i
].num_loc_offsets
,
7097 sizeof (*array
), loc_offsets_compar
);
7100 int adjacent_view_loclists
= 1;
7101 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7103 j
= locs_sorted
? k
: array
[k
];
7105 && (debug_information
[i
].loc_offsets
[locs_sorted
7106 ? k
- 1 : array
[k
- 1]]
7107 == debug_information
[i
].loc_offsets
[j
])
7108 && (debug_information
[i
].loc_views
[locs_sorted
7109 ? k
- 1 : array
[k
- 1]]
7110 == debug_information
[i
].loc_views
[j
]))
7112 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7113 offset
= debug_information
[i
].loc_offsets
[j
];
7114 next
= section_begin
+ offset
;
7115 voffset
= debug_information
[i
].loc_views
[j
];
7117 vnext
= section_begin
+ voffset
;
7120 base_address
= debug_information
[i
].base_address
;
7122 if (vnext
&& vnext
< next
)
7125 display_view_pair_list (section
, &vstart
, i
, next
);
7130 if (!seen_first_offset
|| !adjacent_view_loclists
)
7131 seen_first_offset
= 1;
7135 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
7136 (unsigned long) (start
- section_begin
),
7137 (unsigned long) offset
);
7138 else if (start
> next
)
7139 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
7140 (unsigned long) (start
- section_begin
),
7141 (unsigned long) offset
);
7146 if (offset
>= bytes
)
7148 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
7149 (unsigned long) offset
);
7153 if (vnext
&& voffset
>= bytes
)
7155 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
7156 (unsigned long) voffset
);
7163 display_loc_list_dwo (section
, &start
, i
, offset
,
7164 &vstart
, has_frame_base
);
7166 display_loc_list (section
, &start
, i
, offset
, base_address
,
7167 &vstart
, has_frame_base
);
7172 warn (_("DWO is not yet supported.\n"));
7174 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7175 &vstart
, has_frame_base
);
7178 /* FIXME: this arrangement is quite simplistic. Nothing
7179 requires locview lists to be adjacent to corresponding
7180 loclists, and a single loclist could be augmented by
7181 different locview lists, and vice-versa, unlikely as it
7182 is that it would make sense to do so. Hopefully we'll
7183 have view pair support built into loclists before we ever
7184 need to address all these possibilities. */
7185 if (adjacent_view_loclists
&& vnext
7186 && vnext
!= start
&& vstart
!= next
)
7188 adjacent_view_loclists
= 0;
7189 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7192 if (vnext
&& vnext
== start
)
7193 display_view_pair_list (section
, &start
, i
, vstart
);
7197 if (start
< section
->start
+ section
->size
)
7198 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7199 "There are %ld unused bytes at the end of section %s\n",
7200 (long) (section
->start
+ section
->size
- start
)),
7201 (long) (section
->start
+ section
->size
- start
), section
->name
);
7208 display_debug_str (struct dwarf_section
*section
,
7209 void *file ATTRIBUTE_UNUSED
)
7211 unsigned char *start
= section
->start
;
7212 unsigned long bytes
= section
->size
;
7213 dwarf_vma addr
= section
->address
;
7217 printf (_("\nThe %s section is empty.\n"), section
->name
);
7221 introduce (section
, false);
7229 lbytes
= (bytes
> 16 ? 16 : bytes
);
7231 printf (" 0x%8.8lx ", (unsigned long) addr
);
7233 for (j
= 0; j
< 16; j
++)
7236 printf ("%2.2x", start
[j
]);
7244 for (j
= 0; j
< lbytes
; j
++)
7247 if (k
>= ' ' && k
< 0x80)
7266 display_debug_info (struct dwarf_section
*section
, void *file
)
7268 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7272 display_debug_types (struct dwarf_section
*section
, void *file
)
7274 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7278 display_trace_info (struct dwarf_section
*section
, void *file
)
7280 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7284 display_debug_aranges (struct dwarf_section
*section
,
7285 void *file ATTRIBUTE_UNUSED
)
7287 unsigned char *start
= section
->start
;
7288 unsigned char *end
= start
+ section
->size
;
7290 introduce (section
, false);
7292 /* It does not matter if this load fails,
7293 we test for that later on. */
7294 load_debug_info (file
);
7298 unsigned char *hdrptr
;
7299 DWARF2_Internal_ARange arange
;
7300 unsigned char *addr_ranges
;
7303 unsigned long sec_off
;
7304 unsigned char address_size
;
7306 unsigned int offset_size
;
7307 unsigned int initial_length_size
;
7311 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7312 if (arange
.ar_length
== 0xffffffff)
7314 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7316 initial_length_size
= 12;
7321 initial_length_size
= 4;
7324 sec_off
= hdrptr
- section
->start
;
7325 if (sec_off
+ arange
.ar_length
< sec_off
7326 || sec_off
+ arange
.ar_length
> section
->size
)
7328 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7330 sec_off
- initial_length_size
,
7331 dwarf_vmatoa ("x", arange
.ar_length
));
7335 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
7336 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
7338 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7339 && num_debug_info_entries
> 0
7340 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7341 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7342 (unsigned long) arange
.ar_info_offset
, section
->name
);
7344 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
7345 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
7347 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7349 /* PR 19872: A version number of 0 probably means that there is
7350 padding at the end of the .debug_aranges section. Gold puts
7351 it there when performing an incremental link, for example.
7352 So do not generate a warning in this case. */
7353 if (arange
.ar_version
)
7354 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7358 printf (_(" Length: %ld\n"),
7359 (long) arange
.ar_length
);
7360 printf (_(" Version: %d\n"), arange
.ar_version
);
7361 printf (_(" Offset into .debug_info: 0x%lx\n"),
7362 (unsigned long) arange
.ar_info_offset
);
7363 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7364 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7366 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7368 /* PR 17512: file: 001-108546-0.001:0.1. */
7369 if (address_size
== 0 || address_size
> 8)
7371 error (_("Invalid address size in %s section!\n"),
7376 /* The DWARF spec does not require that the address size be a power
7377 of two, but we do. This will have to change if we ever encounter
7378 an uneven architecture. */
7379 if ((address_size
& (address_size
- 1)) != 0)
7381 warn (_("Pointer size + Segment size is not a power of two.\n"));
7385 if (address_size
> 4)
7386 printf (_("\n Address Length\n"));
7388 printf (_("\n Address Length\n"));
7390 addr_ranges
= hdrptr
;
7392 /* Must pad to an alignment boundary that is twice the address size. */
7393 excess
= (hdrptr
- start
) % (2 * address_size
);
7395 addr_ranges
+= (2 * address_size
) - excess
;
7397 start
+= arange
.ar_length
+ initial_length_size
;
7399 while (addr_ranges
+ 2 * address_size
<= start
)
7401 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
7402 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
7405 print_dwarf_vma (address
, address_size
);
7406 print_dwarf_vma (length
, address_size
);
7416 /* Comparison function for qsort. */
7418 comp_addr_base (const void * v0
, const void * v1
)
7420 debug_info
*info0
= *(debug_info
**) v0
;
7421 debug_info
*info1
= *(debug_info
**) v1
;
7422 return info0
->addr_base
- info1
->addr_base
;
7425 /* Display the debug_addr section. */
7427 display_debug_addr (struct dwarf_section
*section
,
7430 debug_info
**debug_addr_info
;
7431 unsigned char *entry
;
7435 unsigned char * header
;
7437 if (section
->size
== 0)
7439 printf (_("\nThe %s section is empty.\n"), section
->name
);
7443 if (load_debug_info (file
) == 0)
7445 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7450 introduce (section
, false);
7452 /* PR 17531: file: cf38d01b.
7453 We use xcalloc because a corrupt file may not have initialised all of the
7454 fields in the debug_info structure, which means that the sort below might
7455 try to move uninitialised data. */
7456 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7457 sizeof (debug_info
*));
7460 for (i
= 0; i
< num_debug_info_entries
; i
++)
7461 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7463 /* PR 17531: file: cf38d01b. */
7464 if (debug_information
[i
].addr_base
>= section
->size
)
7465 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7466 (unsigned long) debug_information
[i
].addr_base
, i
);
7468 debug_addr_info
[count
++] = debug_information
+ i
;
7471 /* Add a sentinel to make iteration convenient. */
7472 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7473 debug_addr_info
[count
]->addr_base
= section
->size
;
7474 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7476 header
= section
->start
;
7477 for (i
= 0; i
< count
; i
++)
7480 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7482 printf (_(" For compilation unit at offset 0x%s:\n"),
7483 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7485 printf (_("\tIndex\tAddress\n"));
7486 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7487 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7489 size_t header_size
= entry
- header
;
7490 unsigned char * curr_header
= header
;
7493 int segment_selector_size
;
7495 if (header_size
!= 8 && header_size
!= 16)
7497 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7498 section
->name
, (long) header_size
);
7502 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7503 if (length
== 0xffffffff)
7504 SAFE_BYTE_GET (length
, curr_header
, 8, entry
);
7505 end
= curr_header
+ length
;
7507 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7509 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7510 section
->name
, version
);
7512 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7513 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7514 address_size
+= segment_selector_size
;
7517 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7522 dwarf_vma base
= byte_get (entry
, address_size
);
7523 printf (_("\t%d:\t"), idx
);
7524 print_dwarf_vma (base
, address_size
);
7526 entry
+= address_size
;
7532 free (debug_addr_info
);
7536 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7539 display_debug_str_offsets (struct dwarf_section
*section
,
7540 void *file ATTRIBUTE_UNUSED
)
7544 if (section
->size
== 0)
7546 printf (_("\nThe %s section is empty.\n"), section
->name
);
7550 unsigned char *start
= section
->start
;
7551 unsigned char *end
= start
+ section
->size
;
7552 unsigned char *curr
= start
;
7554 const char *suffix
= strrchr (section
->name
, '.');
7555 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7558 load_debug_section_with_follow (str_dwo
, file
);
7560 load_debug_section_with_follow (str
, file
);
7562 introduce (section
, false);
7567 dwarf_vma entry_length
;
7569 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7570 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7571 if (length
== 0xffffffff)
7573 SAFE_BYTE_GET (length
, curr
, 8, end
);
7579 unsigned char *entries_end
;
7582 /* This is probably an old style .debug_str_offset section which
7583 just contains offsets and no header (and the first offset is 0). */
7584 length
= section
->size
;
7585 curr
= section
->start
;
7588 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7589 printf (_(" Index Offset [String]\n"));
7593 entries_end
= curr
+ length
;
7596 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
7598 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7601 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
7603 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7605 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7606 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7607 printf (_(" Index Offset [String]\n"));
7610 for (idx
= 0; curr
< entries_end
; idx
++)
7613 const unsigned char * string
;
7615 if (curr
+ entry_length
> entries_end
)
7616 /* Not enough space to read one entry_length, give up. */
7619 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
7621 string
= (const unsigned char *)
7622 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7624 string
= fetch_indirect_string (offset
);
7626 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7634 /* Each debug_information[x].range_lists[y] gets this representation for
7635 sorting purposes. */
7639 /* The debug_information[x].range_lists[y] value. */
7640 dwarf_vma ranges_offset
;
7642 /* Original debug_information to find parameters of the data. */
7643 debug_info
*debug_info_p
;
7646 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7649 range_entry_compar (const void *ap
, const void *bp
)
7651 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7652 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7653 const dwarf_vma a
= a_re
->ranges_offset
;
7654 const dwarf_vma b
= b_re
->ranges_offset
;
7656 return (a
> b
) - (b
> a
);
7660 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7661 unsigned int pointer_size
, unsigned long offset
,
7662 unsigned long base_address
)
7664 while (start
< finish
)
7669 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7670 if (start
>= finish
)
7672 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7674 printf (" %8.8lx ", offset
);
7676 if (begin
== 0 && end
== 0)
7678 printf (_("<End of list>\n"));
7682 /* Check base address specifiers. */
7683 if (is_max_address (begin
, pointer_size
)
7684 && !is_max_address (end
, pointer_size
))
7687 print_dwarf_vma (begin
, pointer_size
);
7688 print_dwarf_vma (end
, pointer_size
);
7689 printf ("(base address)\n");
7693 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7694 print_dwarf_vma (end
+ base_address
, pointer_size
);
7697 fputs (_("(start == end)"), stdout
);
7698 else if (begin
> end
)
7699 fputs (_("(start > end)"), stdout
);
7706 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7707 unsigned int pointer_size
, unsigned long offset
,
7708 unsigned long base_address
)
7710 unsigned char *next
= start
;
7714 unsigned long off
= offset
+ (start
- next
);
7715 enum dwarf_range_list_entry rlet
;
7716 /* Initialize it due to a false compiler warning. */
7717 dwarf_vma begin
= -1, length
, end
= -1;
7719 if (start
+ 1 > finish
)
7721 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7726 printf (" %8.8lx ", off
);
7728 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7732 case DW_RLE_end_of_list
:
7733 printf (_("<End of list>\n"));
7735 case DW_RLE_base_address
:
7736 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7737 print_dwarf_vma (base_address
, pointer_size
);
7738 printf (_("(base address)\n"));
7740 case DW_RLE_start_length
:
7741 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7742 READ_ULEB (length
, start
, finish
);
7743 end
= begin
+ length
;
7745 case DW_RLE_offset_pair
:
7746 READ_ULEB (begin
, start
, finish
);
7747 READ_ULEB (end
, start
, finish
);
7749 case DW_RLE_start_end
:
7750 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7751 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7754 error (_("Invalid range list entry type %d\n"), rlet
);
7755 rlet
= DW_RLE_end_of_list
;
7758 if (rlet
== DW_RLE_end_of_list
)
7760 if (rlet
== DW_RLE_base_address
)
7763 /* Only a DW_RLE_offset_pair needs the base address added. */
7764 if (rlet
== DW_RLE_offset_pair
)
7766 begin
+= base_address
;
7767 end
+= base_address
;
7770 print_dwarf_vma (begin
, pointer_size
);
7771 print_dwarf_vma (end
, pointer_size
);
7774 fputs (_("(start == end)"), stdout
);
7775 else if (begin
> end
)
7776 fputs (_("(start > end)"), stdout
);
7783 display_debug_ranges (struct dwarf_section
*section
,
7784 void *file ATTRIBUTE_UNUSED
)
7786 unsigned char *start
= section
->start
;
7787 unsigned char *last_start
= start
;
7788 unsigned long bytes
= section
->size
;
7789 unsigned char *section_begin
= start
;
7790 unsigned char *finish
= start
+ bytes
;
7791 unsigned int num_range_list
, i
;
7792 struct range_entry
*range_entries
, *range_entry_fill
;
7793 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7794 /* Initialize it due to a false compiler warning. */
7795 unsigned char address_size
= 0;
7796 dwarf_vma last_offset
= 0;
7800 printf (_("\nThe %s section is empty.\n"), section
->name
);
7806 dwarf_vma initial_length
;
7807 unsigned int initial_length_size
;
7808 unsigned char segment_selector_size
;
7809 unsigned int offset_size
, offset_entry_count
;
7810 unsigned short version
;
7812 /* Get and check the length of the block. */
7813 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7815 if (initial_length
== 0xffffffff)
7817 /* This section is 64-bit DWARF 3. */
7818 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7820 initial_length_size
= 12;
7825 initial_length_size
= 4;
7828 if (initial_length
+ initial_length_size
> section
->size
)
7830 /* If the length field has a relocation against it, then we should
7831 not complain if it is inaccurate (and probably negative).
7832 It is copied from .debug_line handling code. */
7833 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7835 initial_length
= (finish
- start
) - initial_length_size
;
7839 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7840 (long) initial_length
);
7845 /* Get and check the version number. */
7846 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7850 warn (_("Only DWARF version 5 debug_rnglists info "
7851 "is currently supported.\n"));
7855 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7857 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7858 if (segment_selector_size
!= 0)
7860 warn (_("The %s section contains "
7861 "unsupported segment selector size: %d.\n"),
7862 section
->name
, segment_selector_size
);
7866 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7867 if (offset_entry_count
!= 0)
7869 warn (_("The %s section contains "
7870 "unsupported offset entry count: %u.\n"),
7871 section
->name
, offset_entry_count
);
7876 if (load_debug_info (file
) == 0)
7878 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7884 for (i
= 0; i
< num_debug_info_entries
; i
++)
7886 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7887 /* Skip .debug_rnglists reference. */
7889 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7890 /* Skip .debug_range reference. */
7892 num_range_list
+= debug_information
[i
].num_range_lists
;
7895 if (num_range_list
== 0)
7897 /* This can happen when the file was compiled with -gsplit-debug
7898 which removes references to range lists from the primary .o file. */
7899 printf (_("No range lists in .debug_info section.\n"));
7903 range_entries
= (struct range_entry
*)
7904 xmalloc (sizeof (*range_entries
) * num_range_list
);
7905 range_entry_fill
= range_entries
;
7907 for (i
= 0; i
< num_debug_info_entries
; i
++)
7909 debug_info
*debug_info_p
= &debug_information
[i
];
7912 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7913 /* Skip .debug_rnglists reference. */
7915 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7916 /* Skip .debug_range reference. */
7919 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7921 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7922 range_entry_fill
->debug_info_p
= debug_info_p
;
7927 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7928 range_entry_compar
);
7930 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7931 warn (_("Range lists in %s section start at 0x%lx\n"),
7932 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7934 introduce (section
, false);
7936 printf (_(" Offset Begin End\n"));
7938 for (i
= 0; i
< num_range_list
; i
++)
7940 struct range_entry
*range_entry
= &range_entries
[i
];
7941 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7942 unsigned int pointer_size
;
7944 unsigned char *next
;
7945 dwarf_vma base_address
;
7947 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7948 offset
= range_entry
->ranges_offset
;
7949 next
= section_begin
+ offset
;
7950 base_address
= debug_info_p
->base_address
;
7952 /* PR 17512: file: 001-101485-0.001:0.1. */
7953 if (pointer_size
< 2 || pointer_size
> 8)
7955 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7956 pointer_size
, (unsigned long) offset
);
7960 if (next
< section_begin
|| next
>= finish
)
7962 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7963 (unsigned long) offset
, i
);
7967 /* If multiple DWARF entities reference the same range then we will
7968 have multiple entries in the `range_entries' list for the same
7969 offset. Thanks to the sort above these will all be consecutive in
7970 the `range_entries' list, so we can easily ignore duplicates
7972 if (i
> 0 && last_offset
== offset
)
7974 last_offset
= offset
;
7976 if (dwarf_check
!= 0 && i
> 0)
7979 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7980 (unsigned long) (start
- section_begin
),
7981 (unsigned long) (next
- section_begin
), section
->name
);
7982 else if (start
> next
)
7984 if (next
== last_start
)
7986 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7987 (unsigned long) (start
- section_begin
),
7988 (unsigned long) (next
- section_begin
), section
->name
);
7995 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7996 (start
, finish
, pointer_size
, offset
, base_address
);
8000 free (range_entries
);
8005 typedef struct Frame_Chunk
8007 struct Frame_Chunk
*next
;
8008 unsigned char *chunk_start
;
8010 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8011 short int *col_type
;
8014 unsigned int code_factor
;
8018 unsigned int cfa_reg
;
8019 dwarf_vma cfa_offset
;
8021 unsigned char fde_encoding
;
8022 unsigned char cfa_exp
;
8023 unsigned char ptr_size
;
8024 unsigned char segment_size
;
8028 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8029 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8030 static const char *const *dwarf_regnames
;
8031 static unsigned int dwarf_regnames_count
;
8034 /* A marker for a col_type that means this column was never referenced
8035 in the frame info. */
8036 #define DW_CFA_unreferenced (-1)
8038 /* Return 0 if no more space is needed, 1 if more space is needed,
8039 -1 for invalid reg. */
8042 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8044 unsigned int prev
= fc
->ncols
;
8046 if (reg
< (unsigned int) fc
->ncols
)
8049 if (dwarf_regnames_count
> 0
8050 && reg
> dwarf_regnames_count
)
8053 fc
->ncols
= reg
+ 1;
8054 /* PR 17512: file: 10450-2643-0.004.
8055 If reg == -1 then this can happen... */
8059 /* PR 17512: file: 2844a11d. */
8060 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8062 error (_("Unfeasibly large register number: %u\n"), reg
);
8064 /* FIXME: 1024 is an arbitrary limit. Increase it if
8065 we ever encounter a valid binary that exceeds it. */
8069 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
8070 sizeof (short int));
8071 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
8072 /* PR 17512: file:002-10025-0.005. */
8073 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8075 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8081 while (prev
< fc
->ncols
)
8083 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8084 fc
->col_offset
[prev
] = 0;
8090 static const char *const dwarf_regnames_i386
[] =
8092 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8093 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8094 "eip", "eflags", NULL
, /* 8 - 10 */
8095 "st0", "st1", "st2", "st3", /* 11 - 14 */
8096 "st4", "st5", "st6", "st7", /* 15 - 18 */
8097 NULL
, NULL
, /* 19 - 20 */
8098 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8099 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8100 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8101 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8102 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8103 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8104 "tr", "ldtr", /* 48 - 49 */
8105 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8106 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8107 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8108 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8109 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8110 NULL
, NULL
, NULL
, /* 90 - 92 */
8111 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8114 static const char *const dwarf_regnames_iamcu
[] =
8116 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8117 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8118 "eip", "eflags", NULL
, /* 8 - 10 */
8119 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8120 NULL
, NULL
, /* 19 - 20 */
8121 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8122 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8123 NULL
, NULL
, NULL
, /* 37 - 39 */
8124 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8125 "tr", "ldtr", /* 48 - 49 */
8126 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8127 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8128 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8129 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8130 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8131 NULL
, NULL
, NULL
, /* 90 - 92 */
8132 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8136 init_dwarf_regnames_i386 (void)
8138 dwarf_regnames
= dwarf_regnames_i386
;
8139 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8140 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8144 init_dwarf_regnames_iamcu (void)
8146 dwarf_regnames
= dwarf_regnames_iamcu
;
8147 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8148 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8151 static const char *const dwarf_regnames_x86_64
[] =
8153 "rax", "rdx", "rcx", "rbx",
8154 "rsi", "rdi", "rbp", "rsp",
8155 "r8", "r9", "r10", "r11",
8156 "r12", "r13", "r14", "r15",
8158 "xmm0", "xmm1", "xmm2", "xmm3",
8159 "xmm4", "xmm5", "xmm6", "xmm7",
8160 "xmm8", "xmm9", "xmm10", "xmm11",
8161 "xmm12", "xmm13", "xmm14", "xmm15",
8162 "st0", "st1", "st2", "st3",
8163 "st4", "st5", "st6", "st7",
8164 "mm0", "mm1", "mm2", "mm3",
8165 "mm4", "mm5", "mm6", "mm7",
8167 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8168 "fs.base", "gs.base", NULL
, NULL
,
8170 "mxcsr", "fcw", "fsw",
8171 "xmm16", "xmm17", "xmm18", "xmm19",
8172 "xmm20", "xmm21", "xmm22", "xmm23",
8173 "xmm24", "xmm25", "xmm26", "xmm27",
8174 "xmm28", "xmm29", "xmm30", "xmm31",
8175 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8176 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8177 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8178 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8179 NULL
, NULL
, NULL
, /* 115 - 117 */
8180 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8184 init_dwarf_regnames_x86_64 (void)
8186 dwarf_regnames
= dwarf_regnames_x86_64
;
8187 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8188 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8191 static const char *const dwarf_regnames_aarch64
[] =
8193 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8194 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8195 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8196 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8197 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8198 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8199 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8200 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8201 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8202 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8203 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8204 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8205 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8206 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8207 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8208 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8212 init_dwarf_regnames_aarch64 (void)
8214 dwarf_regnames
= dwarf_regnames_aarch64
;
8215 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8216 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8219 static const char *const dwarf_regnames_s390
[] =
8221 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8222 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8223 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8224 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8225 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8226 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8227 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8228 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8229 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8232 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8233 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8237 init_dwarf_regnames_s390 (void)
8239 dwarf_regnames
= dwarf_regnames_s390
;
8240 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8241 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8244 static const char *const dwarf_regnames_riscv
[] =
8246 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8247 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8248 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8249 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8250 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8251 "fs0", "fs1", /* 40 - 41 */
8252 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8253 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8254 "fs10", "fs11", /* 58 - 59 */
8255 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8258 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8259 the large number of CSRs. */
8262 regname_internal_riscv (unsigned int regno
)
8264 const char *name
= NULL
;
8266 /* Lookup in the table first, this covers GPR and FPR. */
8267 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8268 name
= dwarf_regnames_riscv
[regno
];
8269 else if (regno
>= 4096 && regno
<= 8191)
8271 /* This might be a CSR, these live in a sparse number space from 4096
8272 to 8191 These numbers are defined in the RISC-V ELF ABI
8276 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8277 case VALUE + 4096: name = #NAME; break;
8278 #include "opcode/riscv-opc.h"
8283 static char csr_name
[10];
8284 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8295 init_dwarf_regnames_riscv (void)
8297 dwarf_regnames
= NULL
;
8298 dwarf_regnames_count
= 8192;
8299 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8303 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8305 dwarf_regnames_lookup_func
= NULL
;
8310 init_dwarf_regnames_i386 ();
8314 init_dwarf_regnames_iamcu ();
8320 init_dwarf_regnames_x86_64 ();
8324 init_dwarf_regnames_aarch64 ();
8328 init_dwarf_regnames_s390 ();
8332 init_dwarf_regnames_riscv ();
8340 /* Initialize the DWARF register name lookup state based on the
8341 architecture and specific machine type of a BFD. */
8344 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8347 dwarf_regnames_lookup_func
= NULL
;
8354 case bfd_mach_x86_64
:
8355 case bfd_mach_x86_64_intel_syntax
:
8356 case bfd_mach_x64_32
:
8357 case bfd_mach_x64_32_intel_syntax
:
8358 init_dwarf_regnames_x86_64 ();
8362 init_dwarf_regnames_i386 ();
8367 case bfd_arch_iamcu
:
8368 init_dwarf_regnames_iamcu ();
8371 case bfd_arch_aarch64
:
8372 init_dwarf_regnames_aarch64();
8376 init_dwarf_regnames_s390 ();
8379 case bfd_arch_riscv
:
8380 init_dwarf_regnames_riscv ();
8389 regname_internal_by_table_only (unsigned int regno
)
8391 if (dwarf_regnames
!= NULL
8392 && regno
< dwarf_regnames_count
8393 && dwarf_regnames
[regno
] != NULL
)
8394 return dwarf_regnames
[regno
];
8400 regname (unsigned int regno
, int name_only_p
)
8402 static char reg
[64];
8404 const char *name
= NULL
;
8406 if (dwarf_regnames_lookup_func
!= NULL
)
8407 name
= dwarf_regnames_lookup_func (regno
);
8413 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8416 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8421 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8426 if (*max_regs
!= fc
->ncols
)
8427 *max_regs
= fc
->ncols
;
8429 if (*need_col_headers
)
8431 *need_col_headers
= 0;
8433 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8435 for (r
= 0; r
< *max_regs
; r
++)
8436 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8441 printf ("%-5s ", regname (r
, 1));
8447 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8449 strcpy (tmp
, "exp");
8451 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8452 printf ("%-8s ", tmp
);
8454 for (r
= 0; r
< fc
->ncols
; r
++)
8456 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8458 switch (fc
->col_type
[r
])
8460 case DW_CFA_undefined
:
8463 case DW_CFA_same_value
:
8467 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8469 case DW_CFA_val_offset
:
8470 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8472 case DW_CFA_register
:
8473 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8475 case DW_CFA_expression
:
8476 strcpy (tmp
, "exp");
8478 case DW_CFA_val_expression
:
8479 strcpy (tmp
, "vexp");
8482 strcpy (tmp
, "n/a");
8485 printf ("%-5s ", tmp
);
8491 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8493 static unsigned char *
8494 read_cie (unsigned char *start
, unsigned char *end
,
8495 Frame_Chunk
**p_cie
, int *p_version
,
8496 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8500 unsigned char *augmentation_data
= NULL
;
8501 bfd_size_type augmentation_data_len
= 0;
8504 /* PR 17512: file: 001-228113-0.004. */
8508 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8509 memset (fc
, 0, sizeof (Frame_Chunk
));
8511 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8512 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8516 fc
->augmentation
= (char *) start
;
8517 /* PR 17512: file: 001-228113-0.004.
8518 Skip past augmentation name, but avoid running off the end of the data. */
8520 if (* start
++ == '\0')
8524 warn (_("No terminator for augmentation name\n"));
8528 if (strcmp (fc
->augmentation
, "eh") == 0)
8529 start
+= eh_addr_size
;
8533 GET (fc
->ptr_size
, 1);
8534 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8536 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8540 GET (fc
->segment_size
, 1);
8541 /* PR 17512: file: e99d2804. */
8542 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8544 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8548 eh_addr_size
= fc
->ptr_size
;
8552 fc
->ptr_size
= eh_addr_size
;
8553 fc
->segment_size
= 0;
8556 READ_ULEB (fc
->code_factor
, start
, end
);
8557 READ_SLEB (fc
->data_factor
, start
, end
);
8565 READ_ULEB (fc
->ra
, start
, end
);
8568 if (fc
->augmentation
[0] == 'z')
8570 READ_ULEB (augmentation_data_len
, start
, end
);
8571 augmentation_data
= start
;
8572 /* PR 17512: file: 11042-2589-0.004. */
8573 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8575 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8576 dwarf_vmatoa ("x", augmentation_data_len
),
8577 (unsigned long) (end
- start
));
8580 start
+= augmentation_data_len
;
8583 if (augmentation_data_len
)
8587 unsigned char *qend
;
8589 p
= (unsigned char *) fc
->augmentation
+ 1;
8590 q
= augmentation_data
;
8591 qend
= q
+ augmentation_data_len
;
8593 while (p
< end
&& q
< qend
)
8598 q
+= 1 + size_of_encoded_value (*q
);
8600 fc
->fde_encoding
= *q
++;
8609 /* Note - it is OK if this loop terminates with q < qend.
8610 Padding may have been inserted to align the end of the CIE. */
8615 *p_version
= version
;
8618 *p_aug_len
= augmentation_data_len
;
8619 *p_aug
= augmentation_data
;
8624 free (fc
->col_offset
);
8625 free (fc
->col_type
);
8630 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8631 If do_wide is not enabled, then formats the output to fit into 80 columns.
8632 PRINTED contains the number of characters already written to the current
8636 display_data (bfd_size_type printed
,
8637 const unsigned char * data
,
8638 const bfd_size_type len
)
8640 if (do_wide
|| len
< ((80 - printed
) / 3))
8641 for (printed
= 0; printed
< len
; ++printed
)
8642 printf (" %02x", data
[printed
]);
8645 for (printed
= 0; printed
< len
; ++printed
)
8647 if (printed
% (80 / 3) == 0)
8649 printf (" %02x", data
[printed
]);
8654 /* Prints out the contents on the augmentation data array.
8655 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8658 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8662 i
= printf (_(" Augmentation data: "));
8663 display_data (i
, data
, len
);
8667 display_debug_frames (struct dwarf_section
*section
,
8668 void *file ATTRIBUTE_UNUSED
)
8670 unsigned char *start
= section
->start
;
8671 unsigned char *end
= start
+ section
->size
;
8672 unsigned char *section_start
= start
;
8673 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8674 Frame_Chunk
*remembered_state
= NULL
;
8676 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8677 unsigned int max_regs
= 0;
8678 const char *bad_reg
= _("bad register: ");
8679 unsigned int saved_eh_addr_size
= eh_addr_size
;
8681 introduce (section
, false);
8685 unsigned char *saved_start
;
8686 unsigned char *block_end
;
8691 int need_col_headers
= 1;
8692 unsigned char *augmentation_data
= NULL
;
8693 bfd_size_type augmentation_data_len
= 0;
8694 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8695 unsigned int offset_size
;
8696 unsigned int initial_length_size
;
8698 static Frame_Chunk fde_fc
;
8700 saved_start
= start
;
8702 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8706 printf ("\n%08lx ZERO terminator\n\n",
8707 (unsigned long)(saved_start
- section_start
));
8708 /* Skip any zero terminators that directly follow.
8709 A corrupt section size could have loaded a whole
8710 slew of zero filled memory bytes. eg
8711 PR 17512: file: 070-19381-0.004. */
8712 while (start
< end
&& * start
== 0)
8717 if (length
== 0xffffffff)
8719 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8721 initial_length_size
= 12;
8726 initial_length_size
= 4;
8729 block_end
= saved_start
+ length
+ initial_length_size
;
8730 if (block_end
> end
|| block_end
< start
)
8732 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8733 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8734 (unsigned long) (saved_start
- section_start
));
8738 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8740 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8741 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8746 start
= read_cie (start
, end
, &cie
, &version
,
8747 &augmentation_data_len
, &augmentation_data
);
8748 /* PR 17512: file: 027-135133-0.005. */
8755 fc
->chunk_start
= saved_start
;
8756 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8759 if (frame_need_space (fc
, mreg
) < 0)
8761 if (fc
->fde_encoding
)
8762 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8764 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8765 print_dwarf_vma (length
, fc
->ptr_size
);
8766 print_dwarf_vma (cie_id
, offset_size
);
8768 if (do_debug_frames_interp
)
8770 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8771 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8776 printf (" Version: %d\n", version
);
8777 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8780 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8781 printf (" Segment Size: %u\n", fc
->segment_size
);
8783 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8784 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8785 printf (" Return address column: %d\n", fc
->ra
);
8787 if (augmentation_data_len
)
8788 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8795 unsigned char *look_for
;
8796 unsigned long segment_selector
;
8800 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8801 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8804 look_for
= section_start
+ cie_id
;
8806 if (look_for
<= saved_start
)
8808 for (cie
= chunks
; cie
; cie
= cie
->next
)
8809 if (cie
->chunk_start
== look_for
)
8814 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8815 if (cie
->chunk_start
== look_for
)
8819 unsigned int off_size
;
8820 unsigned char *cie_scan
;
8822 cie_scan
= look_for
;
8824 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8825 if (length
== 0xffffffff)
8827 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8834 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8837 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8838 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8843 read_cie (cie_scan
, end
, &cie
, &version
,
8844 &augmentation_data_len
, &augmentation_data
);
8845 /* PR 17512: file: 3450-2098-0.004. */
8848 warn (_("Failed to read CIE information\n"));
8851 cie
->next
= forward_refs
;
8853 cie
->chunk_start
= look_for
;
8854 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8857 if (frame_need_space (cie
, mreg
) < 0)
8859 warn (_("Invalid max register\n"));
8862 if (cie
->fde_encoding
)
8864 = size_of_encoded_value (cie
->fde_encoding
);
8871 memset (fc
, 0, sizeof (Frame_Chunk
));
8875 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8876 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8877 (unsigned long) (saved_start
- section_start
));
8879 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8880 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8881 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8883 warn (_("Invalid max register\n"));
8887 fc
->augmentation
= "";
8888 fc
->fde_encoding
= 0;
8889 fc
->ptr_size
= eh_addr_size
;
8890 fc
->segment_size
= 0;
8894 fc
->ncols
= cie
->ncols
;
8895 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8896 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8897 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8898 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8899 fc
->augmentation
= cie
->augmentation
;
8900 fc
->ptr_size
= cie
->ptr_size
;
8901 eh_addr_size
= cie
->ptr_size
;
8902 fc
->segment_size
= cie
->segment_size
;
8903 fc
->code_factor
= cie
->code_factor
;
8904 fc
->data_factor
= cie
->data_factor
;
8905 fc
->cfa_reg
= cie
->cfa_reg
;
8906 fc
->cfa_offset
= cie
->cfa_offset
;
8908 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8910 warn (_("Invalid max register\n"));
8913 fc
->fde_encoding
= cie
->fde_encoding
;
8916 if (fc
->fde_encoding
)
8917 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8919 segment_selector
= 0;
8920 if (fc
->segment_size
)
8922 if (fc
->segment_size
> sizeof (segment_selector
))
8924 /* PR 17512: file: 9e196b3e. */
8925 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8926 fc
->segment_size
= 4;
8928 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8931 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8933 /* FIXME: It appears that sometimes the final pc_range value is
8934 encoded in less than encoded_ptr_size bytes. See the x86_64
8935 run of the "objcopy on compressed debug sections" test for an
8937 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8939 if (cie
->augmentation
[0] == 'z')
8941 READ_ULEB (augmentation_data_len
, start
, end
);
8942 augmentation_data
= start
;
8943 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8944 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8946 warn (_("Augmentation data too long: 0x%s, "
8947 "expected at most %#lx\n"),
8948 dwarf_vmatoa ("x", augmentation_data_len
),
8949 (unsigned long) (end
- start
));
8951 augmentation_data
= NULL
;
8952 augmentation_data_len
= 0;
8954 start
+= augmentation_data_len
;
8957 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8958 (unsigned long)(saved_start
- section_start
),
8959 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8960 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8961 (unsigned long)(cie
->chunk_start
- section_start
));
8963 if (fc
->segment_size
)
8964 printf ("%04lx:", segment_selector
);
8967 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8968 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8970 if (! do_debug_frames_interp
&& augmentation_data_len
)
8972 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8977 /* At this point, fc is the current chunk, cie (if any) is set, and
8978 we're about to interpret instructions for the chunk. */
8979 /* ??? At present we need to do this always, since this sizes the
8980 fc->col_type and fc->col_offset arrays, which we write into always.
8981 We should probably split the interpreted and non-interpreted bits
8982 into two different routines, since there's so much that doesn't
8983 really overlap between them. */
8984 if (1 || do_debug_frames_interp
)
8986 /* Start by making a pass over the chunk, allocating storage
8987 and taking note of what registers are used. */
8988 unsigned char *tmp
= start
;
8990 while (start
< block_end
)
8992 unsigned int reg
, op
, opa
;
8994 unsigned char * new_start
;
9001 /* Warning: if you add any more cases to this switch, be
9002 sure to add them to the corresponding switch below. */
9005 case DW_CFA_advance_loc
:
9008 SKIP_ULEB (start
, end
);
9009 if (frame_need_space (fc
, opa
) >= 0)
9010 fc
->col_type
[opa
] = DW_CFA_undefined
;
9012 case DW_CFA_restore
:
9013 if (frame_need_space (fc
, opa
) >= 0)
9014 fc
->col_type
[opa
] = DW_CFA_undefined
;
9016 case DW_CFA_set_loc
:
9017 start
+= encoded_ptr_size
;
9019 case DW_CFA_advance_loc1
:
9022 case DW_CFA_advance_loc2
:
9025 case DW_CFA_advance_loc4
:
9028 case DW_CFA_offset_extended
:
9029 case DW_CFA_val_offset
:
9030 READ_ULEB (reg
, start
, end
);
9031 SKIP_ULEB (start
, end
);
9032 if (frame_need_space (fc
, reg
) >= 0)
9033 fc
->col_type
[reg
] = DW_CFA_undefined
;
9035 case DW_CFA_restore_extended
:
9036 READ_ULEB (reg
, start
, end
);
9037 if (frame_need_space (fc
, reg
) >= 0)
9038 fc
->col_type
[reg
] = DW_CFA_undefined
;
9040 case DW_CFA_undefined
:
9041 READ_ULEB (reg
, start
, end
);
9042 if (frame_need_space (fc
, reg
) >= 0)
9043 fc
->col_type
[reg
] = DW_CFA_undefined
;
9045 case DW_CFA_same_value
:
9046 READ_ULEB (reg
, start
, end
);
9047 if (frame_need_space (fc
, reg
) >= 0)
9048 fc
->col_type
[reg
] = DW_CFA_undefined
;
9050 case DW_CFA_register
:
9051 READ_ULEB (reg
, start
, end
);
9052 SKIP_ULEB (start
, end
);
9053 if (frame_need_space (fc
, reg
) >= 0)
9054 fc
->col_type
[reg
] = DW_CFA_undefined
;
9056 case DW_CFA_def_cfa
:
9057 SKIP_ULEB (start
, end
);
9058 SKIP_ULEB (start
, end
);
9060 case DW_CFA_def_cfa_register
:
9061 SKIP_ULEB (start
, end
);
9063 case DW_CFA_def_cfa_offset
:
9064 SKIP_ULEB (start
, end
);
9066 case DW_CFA_def_cfa_expression
:
9067 READ_ULEB (temp
, start
, end
);
9068 new_start
= start
+ temp
;
9069 if (new_start
< start
)
9071 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
9077 case DW_CFA_expression
:
9078 case DW_CFA_val_expression
:
9079 READ_ULEB (reg
, start
, end
);
9080 READ_ULEB (temp
, start
, end
);
9081 new_start
= start
+ temp
;
9082 if (new_start
< start
)
9084 /* PR 17512: file:306-192417-0.005. */
9085 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
9090 if (frame_need_space (fc
, reg
) >= 0)
9091 fc
->col_type
[reg
] = DW_CFA_undefined
;
9093 case DW_CFA_offset_extended_sf
:
9094 case DW_CFA_val_offset_sf
:
9095 READ_ULEB (reg
, start
, end
);
9096 SKIP_SLEB (start
, end
);
9097 if (frame_need_space (fc
, reg
) >= 0)
9098 fc
->col_type
[reg
] = DW_CFA_undefined
;
9100 case DW_CFA_def_cfa_sf
:
9101 SKIP_ULEB (start
, end
);
9102 SKIP_SLEB (start
, end
);
9104 case DW_CFA_def_cfa_offset_sf
:
9105 SKIP_SLEB (start
, end
);
9107 case DW_CFA_MIPS_advance_loc8
:
9110 case DW_CFA_GNU_args_size
:
9111 SKIP_ULEB (start
, end
);
9113 case DW_CFA_GNU_negative_offset_extended
:
9114 READ_ULEB (reg
, start
, end
);
9115 SKIP_ULEB (start
, end
);
9116 if (frame_need_space (fc
, reg
) >= 0)
9117 fc
->col_type
[reg
] = DW_CFA_undefined
;
9128 /* Now we know what registers are used, make a second pass over
9129 the chunk, this time actually printing out the info. */
9131 while (start
< block_end
)
9133 unsigned char * tmp
;
9135 unsigned long ul
, roffs
;
9136 /* Note: It is tempting to use an unsigned long for 'reg' but there
9137 are various functions, notably frame_space_needed() that assume that
9138 reg is an unsigned int. */
9143 const char *reg_prefix
= "";
9150 /* Make a note if something other than DW_CFA_nop happens. */
9151 if (op
!= DW_CFA_nop
)
9154 /* Warning: if you add any more cases to this switch, be
9155 sure to add them to the corresponding switch above. */
9158 case DW_CFA_advance_loc
:
9159 if (do_debug_frames_interp
)
9160 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9162 printf (" DW_CFA_advance_loc: %d to %s\n",
9163 opa
* fc
->code_factor
,
9164 dwarf_vmatoa_1 (NULL
,
9165 fc
->pc_begin
+ opa
* fc
->code_factor
,
9167 fc
->pc_begin
+= opa
* fc
->code_factor
;
9171 READ_ULEB (roffs
, start
, end
);
9172 if (opa
>= (unsigned int) fc
->ncols
)
9173 reg_prefix
= bad_reg
;
9174 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9175 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9176 reg_prefix
, regname (opa
, 0),
9177 roffs
* fc
->data_factor
);
9178 if (*reg_prefix
== '\0')
9180 fc
->col_type
[opa
] = DW_CFA_offset
;
9181 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9185 case DW_CFA_restore
:
9186 if (opa
>= (unsigned int) fc
->ncols
)
9187 reg_prefix
= bad_reg
;
9188 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9189 printf (" DW_CFA_restore: %s%s\n",
9190 reg_prefix
, regname (opa
, 0));
9191 if (*reg_prefix
!= '\0')
9194 if (opa
>= (unsigned int) cie
->ncols
9195 || (do_debug_frames_interp
9196 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9198 fc
->col_type
[opa
] = DW_CFA_undefined
;
9199 fc
->col_offset
[opa
] = 0;
9203 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9204 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9208 case DW_CFA_set_loc
:
9209 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
9210 if (do_debug_frames_interp
)
9211 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9213 printf (" DW_CFA_set_loc: %s\n",
9214 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9218 case DW_CFA_advance_loc1
:
9219 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
9220 if (do_debug_frames_interp
)
9221 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9223 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9224 (unsigned long) (ofs
* fc
->code_factor
),
9225 dwarf_vmatoa_1 (NULL
,
9226 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9228 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9231 case DW_CFA_advance_loc2
:
9232 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9233 if (do_debug_frames_interp
)
9234 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9236 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9237 (unsigned long) (ofs
* fc
->code_factor
),
9238 dwarf_vmatoa_1 (NULL
,
9239 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9241 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9244 case DW_CFA_advance_loc4
:
9245 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9246 if (do_debug_frames_interp
)
9247 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9249 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9250 (unsigned long) (ofs
* fc
->code_factor
),
9251 dwarf_vmatoa_1 (NULL
,
9252 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9254 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9257 case DW_CFA_offset_extended
:
9258 READ_ULEB (reg
, start
, end
);
9259 READ_ULEB (roffs
, start
, end
);
9260 if (reg
>= (unsigned int) fc
->ncols
)
9261 reg_prefix
= bad_reg
;
9262 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9263 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9264 reg_prefix
, regname (reg
, 0),
9265 roffs
* fc
->data_factor
);
9266 if (*reg_prefix
== '\0')
9268 fc
->col_type
[reg
] = DW_CFA_offset
;
9269 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9273 case DW_CFA_val_offset
:
9274 READ_ULEB (reg
, start
, end
);
9275 READ_ULEB (roffs
, start
, end
);
9276 if (reg
>= (unsigned int) fc
->ncols
)
9277 reg_prefix
= bad_reg
;
9278 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9279 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9280 reg_prefix
, regname (reg
, 0),
9281 roffs
* fc
->data_factor
);
9282 if (*reg_prefix
== '\0')
9284 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9285 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9289 case DW_CFA_restore_extended
:
9290 READ_ULEB (reg
, start
, end
);
9291 if (reg
>= (unsigned int) fc
->ncols
)
9292 reg_prefix
= bad_reg
;
9293 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9294 printf (" DW_CFA_restore_extended: %s%s\n",
9295 reg_prefix
, regname (reg
, 0));
9296 if (*reg_prefix
!= '\0')
9299 if (reg
>= (unsigned int) cie
->ncols
)
9301 fc
->col_type
[reg
] = DW_CFA_undefined
;
9302 fc
->col_offset
[reg
] = 0;
9306 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9307 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9311 case DW_CFA_undefined
:
9312 READ_ULEB (reg
, start
, end
);
9313 if (reg
>= (unsigned int) fc
->ncols
)
9314 reg_prefix
= bad_reg
;
9315 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9316 printf (" DW_CFA_undefined: %s%s\n",
9317 reg_prefix
, regname (reg
, 0));
9318 if (*reg_prefix
== '\0')
9320 fc
->col_type
[reg
] = DW_CFA_undefined
;
9321 fc
->col_offset
[reg
] = 0;
9325 case DW_CFA_same_value
:
9326 READ_ULEB (reg
, start
, end
);
9327 if (reg
>= (unsigned int) fc
->ncols
)
9328 reg_prefix
= bad_reg
;
9329 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9330 printf (" DW_CFA_same_value: %s%s\n",
9331 reg_prefix
, regname (reg
, 0));
9332 if (*reg_prefix
== '\0')
9334 fc
->col_type
[reg
] = DW_CFA_same_value
;
9335 fc
->col_offset
[reg
] = 0;
9339 case DW_CFA_register
:
9340 READ_ULEB (reg
, start
, end
);
9341 READ_ULEB (roffs
, start
, end
);
9342 if (reg
>= (unsigned int) fc
->ncols
)
9343 reg_prefix
= bad_reg
;
9344 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9346 printf (" DW_CFA_register: %s%s in ",
9347 reg_prefix
, regname (reg
, 0));
9348 puts (regname (roffs
, 0));
9350 if (*reg_prefix
== '\0')
9352 fc
->col_type
[reg
] = DW_CFA_register
;
9353 fc
->col_offset
[reg
] = roffs
;
9357 case DW_CFA_remember_state
:
9358 if (! do_debug_frames_interp
)
9359 printf (" DW_CFA_remember_state\n");
9360 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9361 rs
->cfa_offset
= fc
->cfa_offset
;
9362 rs
->cfa_reg
= fc
->cfa_reg
;
9364 rs
->cfa_exp
= fc
->cfa_exp
;
9365 rs
->ncols
= fc
->ncols
;
9366 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9367 sizeof (* rs
->col_type
));
9368 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9369 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9370 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9371 rs
->next
= remembered_state
;
9372 remembered_state
= rs
;
9375 case DW_CFA_restore_state
:
9376 if (! do_debug_frames_interp
)
9377 printf (" DW_CFA_restore_state\n");
9378 rs
= remembered_state
;
9381 remembered_state
= rs
->next
;
9382 fc
->cfa_offset
= rs
->cfa_offset
;
9383 fc
->cfa_reg
= rs
->cfa_reg
;
9385 fc
->cfa_exp
= rs
->cfa_exp
;
9386 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9388 warn (_("Invalid column number in saved frame state\n"));
9392 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9393 memcpy (fc
->col_offset
, rs
->col_offset
,
9394 rs
->ncols
* sizeof (* rs
->col_offset
));
9395 free (rs
->col_type
);
9396 free (rs
->col_offset
);
9399 else if (do_debug_frames_interp
)
9400 printf ("Mismatched DW_CFA_restore_state\n");
9403 case DW_CFA_def_cfa
:
9404 READ_ULEB (fc
->cfa_reg
, start
, end
);
9405 READ_ULEB (fc
->cfa_offset
, start
, end
);
9407 if (! do_debug_frames_interp
)
9408 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9409 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9412 case DW_CFA_def_cfa_register
:
9413 READ_ULEB (fc
->cfa_reg
, start
, end
);
9415 if (! do_debug_frames_interp
)
9416 printf (" DW_CFA_def_cfa_register: %s\n",
9417 regname (fc
->cfa_reg
, 0));
9420 case DW_CFA_def_cfa_offset
:
9421 READ_ULEB (fc
->cfa_offset
, start
, end
);
9422 if (! do_debug_frames_interp
)
9423 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9427 if (! do_debug_frames_interp
)
9428 printf (" DW_CFA_nop\n");
9431 case DW_CFA_def_cfa_expression
:
9432 READ_ULEB (ul
, start
, end
);
9433 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
9435 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9438 if (! do_debug_frames_interp
)
9440 printf (" DW_CFA_def_cfa_expression (");
9441 decode_location_expression (start
, eh_addr_size
, 0, -1,
9449 case DW_CFA_expression
:
9450 READ_ULEB (reg
, start
, end
);
9451 READ_ULEB (ul
, start
, end
);
9452 if (reg
>= (unsigned int) fc
->ncols
)
9453 reg_prefix
= bad_reg
;
9454 /* PR 17512: file: 069-133014-0.006. */
9455 /* PR 17512: file: 98c02eb4. */
9457 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9459 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9462 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9464 printf (" DW_CFA_expression: %s%s (",
9465 reg_prefix
, regname (reg
, 0));
9466 decode_location_expression (start
, eh_addr_size
, 0, -1,
9470 if (*reg_prefix
== '\0')
9471 fc
->col_type
[reg
] = DW_CFA_expression
;
9475 case DW_CFA_val_expression
:
9476 READ_ULEB (reg
, start
, end
);
9477 READ_ULEB (ul
, start
, end
);
9478 if (reg
>= (unsigned int) fc
->ncols
)
9479 reg_prefix
= bad_reg
;
9481 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9483 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9486 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9488 printf (" DW_CFA_val_expression: %s%s (",
9489 reg_prefix
, regname (reg
, 0));
9490 decode_location_expression (start
, eh_addr_size
, 0, -1,
9494 if (*reg_prefix
== '\0')
9495 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9499 case DW_CFA_offset_extended_sf
:
9500 READ_ULEB (reg
, start
, end
);
9501 READ_SLEB (l
, start
, end
);
9502 if (frame_need_space (fc
, reg
) < 0)
9503 reg_prefix
= bad_reg
;
9504 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9505 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9506 reg_prefix
, regname (reg
, 0),
9507 (long)(l
* fc
->data_factor
));
9508 if (*reg_prefix
== '\0')
9510 fc
->col_type
[reg
] = DW_CFA_offset
;
9511 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9515 case DW_CFA_val_offset_sf
:
9516 READ_ULEB (reg
, start
, end
);
9517 READ_SLEB (l
, start
, end
);
9518 if (frame_need_space (fc
, reg
) < 0)
9519 reg_prefix
= bad_reg
;
9520 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9521 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9522 reg_prefix
, regname (reg
, 0),
9523 (long)(l
* fc
->data_factor
));
9524 if (*reg_prefix
== '\0')
9526 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9527 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9531 case DW_CFA_def_cfa_sf
:
9532 READ_ULEB (fc
->cfa_reg
, start
, end
);
9533 READ_ULEB (fc
->cfa_offset
, start
, end
);
9534 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9536 if (! do_debug_frames_interp
)
9537 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9538 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9541 case DW_CFA_def_cfa_offset_sf
:
9542 READ_ULEB (fc
->cfa_offset
, start
, end
);
9543 fc
->cfa_offset
*= fc
->data_factor
;
9544 if (! do_debug_frames_interp
)
9545 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9548 case DW_CFA_MIPS_advance_loc8
:
9549 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9550 if (do_debug_frames_interp
)
9551 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9553 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9554 (unsigned long) (ofs
* fc
->code_factor
),
9555 dwarf_vmatoa_1 (NULL
,
9556 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9558 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9561 case DW_CFA_GNU_window_save
:
9562 if (! do_debug_frames_interp
)
9563 printf (" DW_CFA_GNU_window_save\n");
9566 case DW_CFA_GNU_args_size
:
9567 READ_ULEB (ul
, start
, end
);
9568 if (! do_debug_frames_interp
)
9569 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9572 case DW_CFA_GNU_negative_offset_extended
:
9573 READ_ULEB (reg
, start
, end
);
9574 READ_SLEB (l
, start
, end
);
9576 if (frame_need_space (fc
, reg
) < 0)
9577 reg_prefix
= bad_reg
;
9578 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9579 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9580 reg_prefix
, regname (reg
, 0),
9581 (long)(l
* fc
->data_factor
));
9582 if (*reg_prefix
== '\0')
9584 fc
->col_type
[reg
] = DW_CFA_offset
;
9585 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9590 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9591 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9593 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9598 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9599 if (do_debug_frames_interp
&& ! all_nops
)
9600 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9602 if (fde_fc
.col_type
!= NULL
)
9604 free (fde_fc
.col_type
);
9605 fde_fc
.col_type
= NULL
;
9607 if (fde_fc
.col_offset
!= NULL
)
9609 free (fde_fc
.col_offset
);
9610 fde_fc
.col_offset
= NULL
;
9614 eh_addr_size
= saved_eh_addr_size
;
9619 while (remembered_state
!= NULL
)
9621 rs
= remembered_state
;
9622 remembered_state
= rs
->next
;
9623 free (rs
->col_type
);
9624 free (rs
->col_offset
);
9625 rs
->next
= NULL
; /* Paranoia. */
9629 while (chunks
!= NULL
)
9633 free (rs
->col_type
);
9634 free (rs
->col_offset
);
9635 rs
->next
= NULL
; /* Paranoia. */
9639 while (forward_refs
!= NULL
)
9642 forward_refs
= rs
->next
;
9643 free (rs
->col_type
);
9644 free (rs
->col_offset
);
9645 rs
->next
= NULL
; /* Paranoia. */
9655 display_debug_names (struct dwarf_section
*section
, void *file
)
9657 unsigned char *hdrptr
= section
->start
;
9658 dwarf_vma unit_length
;
9659 unsigned char *unit_start
;
9660 const unsigned char *const section_end
= section
->start
+ section
->size
;
9661 unsigned char *unit_end
;
9663 introduce (section
, false);
9665 load_debug_section_with_follow (str
, file
);
9667 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9669 unsigned int offset_size
;
9670 uint16_t dwarf_version
, padding
;
9671 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9672 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9673 uint32_t augmentation_string_size
;
9675 unsigned long sec_off
;
9676 bool augmentation_printable
;
9677 const char *augmentation_string
;
9679 unit_start
= hdrptr
;
9681 /* Get and check the length of the block. */
9682 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9684 if (unit_length
== 0xffffffff)
9686 /* This section is 64-bit DWARF. */
9687 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9692 unit_end
= hdrptr
+ unit_length
;
9694 sec_off
= hdrptr
- section
->start
;
9695 if (sec_off
+ unit_length
< sec_off
9696 || sec_off
+ unit_length
> section
->size
)
9698 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9700 (unsigned long) (unit_start
- section
->start
),
9701 dwarf_vmatoa ("x", unit_length
));
9705 /* Get and check the version number. */
9706 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9707 printf (_("Version %ld\n"), (long) dwarf_version
);
9709 /* Prior versions did not exist, and future versions may not be
9710 backwards compatible. */
9711 if (dwarf_version
!= 5)
9713 warn (_("Only DWARF version 5 .debug_names "
9714 "is currently supported.\n"));
9718 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9720 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9723 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9724 if (comp_unit_count
== 0)
9725 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9727 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9728 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9729 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9730 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9731 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9733 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9734 if (augmentation_string_size
% 4 != 0)
9736 warn (_("Augmentation string length %u must be rounded up "
9737 "to a multiple of 4 in .debug_names.\n"),
9738 augmentation_string_size
);
9739 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9742 printf (_("Augmentation string:"));
9744 augmentation_printable
= true;
9745 augmentation_string
= (const char *) hdrptr
;
9747 for (i
= 0; i
< augmentation_string_size
; i
++)
9751 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9752 printf (" %02x", uc
);
9754 if (uc
!= 0 && !ISPRINT (uc
))
9755 augmentation_printable
= false;
9758 if (augmentation_printable
)
9762 i
< augmentation_string_size
&& augmentation_string
[i
];
9764 putchar (augmentation_string
[i
]);
9769 printf (_("CU table:\n"));
9770 for (i
= 0; i
< comp_unit_count
; i
++)
9774 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9775 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9779 printf (_("TU table:\n"));
9780 for (i
= 0; i
< local_type_unit_count
; i
++)
9784 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9785 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9789 printf (_("Foreign TU table:\n"));
9790 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9794 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9795 printf (_("[%3u] "), i
);
9796 print_dwarf_vma (signature
, 8);
9801 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9802 hdrptr
+= bucket_count
* sizeof (uint32_t);
9803 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9804 hdrptr
+= name_count
* sizeof (uint32_t);
9805 unsigned char *const name_table_string_offsets
= hdrptr
;
9806 hdrptr
+= name_count
* offset_size
;
9807 unsigned char *const name_table_entry_offsets
= hdrptr
;
9808 hdrptr
+= name_count
* offset_size
;
9809 unsigned char *const abbrev_table
= hdrptr
;
9810 hdrptr
+= abbrev_table_size
;
9811 const unsigned char *const abbrev_table_end
= hdrptr
;
9812 unsigned char *const entry_pool
= hdrptr
;
9813 if (hdrptr
> unit_end
)
9815 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9816 "for unit 0x%lx in the debug_names\n"),
9817 (long) (hdrptr
- section
->start
),
9818 (long) (unit_end
- section
->start
),
9819 (long) (unit_start
- section
->start
));
9823 size_t buckets_filled
= 0;
9825 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9827 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9832 printf (ngettext ("Used %zu of %lu bucket.\n",
9833 "Used %zu of %lu buckets.\n",
9835 buckets_filled
, (unsigned long) bucket_count
);
9837 uint32_t hash_prev
= 0;
9838 size_t hash_clash_count
= 0;
9839 size_t longest_clash
= 0;
9840 size_t this_length
= 0;
9842 for (hashi
= 0; hashi
< name_count
; hashi
++)
9844 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9848 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9852 longest_clash
= MAX (longest_clash
, this_length
);
9857 hash_prev
= hash_this
;
9859 printf (_("Out of %lu items there are %zu bucket clashes"
9860 " (longest of %zu entries).\n"),
9861 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9862 assert (name_count
== buckets_filled
+ hash_clash_count
);
9864 struct abbrev_lookup_entry
9866 dwarf_vma abbrev_tag
;
9867 unsigned char *abbrev_lookup_ptr
;
9869 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9870 size_t abbrev_lookup_used
= 0;
9871 size_t abbrev_lookup_allocated
= 0;
9873 unsigned char *abbrevptr
= abbrev_table
;
9876 dwarf_vma abbrev_tag
;
9878 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9879 if (abbrev_tag
== 0)
9881 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9883 abbrev_lookup_allocated
= MAX (0x100,
9884 abbrev_lookup_allocated
* 2);
9885 abbrev_lookup
= xrealloc (abbrev_lookup
,
9886 (abbrev_lookup_allocated
9887 * sizeof (*abbrev_lookup
)));
9889 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9890 struct abbrev_lookup_entry
*entry
;
9891 for (entry
= abbrev_lookup
;
9892 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9894 if (entry
->abbrev_tag
== abbrev_tag
)
9896 warn (_("Duplicate abbreviation tag %lu "
9897 "in unit 0x%lx in the debug_names\n"),
9898 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9901 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9902 entry
->abbrev_tag
= abbrev_tag
;
9903 entry
->abbrev_lookup_ptr
= abbrevptr
;
9905 /* Skip DWARF tag. */
9906 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9909 dwarf_vma xindex
, form
;
9911 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9912 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9913 if (xindex
== 0 && form
== 0)
9918 printf (_("\nSymbol table:\n"));
9920 for (namei
= 0; namei
< name_count
; ++namei
)
9922 uint64_t string_offset
, entry_offset
;
9924 SAFE_BYTE_GET (string_offset
,
9925 name_table_string_offsets
+ namei
* offset_size
,
9926 offset_size
, unit_end
);
9927 SAFE_BYTE_GET (entry_offset
,
9928 name_table_entry_offsets
+ namei
* offset_size
,
9929 offset_size
, unit_end
);
9931 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9932 fetch_indirect_string (string_offset
));
9934 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9936 /* We need to scan first whether there is a single or multiple
9937 entries. TAGNO is -2 for the first entry, it is -1 for the
9938 initial tag read of the second entry, then it becomes 0 for the
9939 first entry for real printing etc. */
9941 /* Initialize it due to a false compiler warning. */
9942 dwarf_vma second_abbrev_tag
= -1;
9945 dwarf_vma abbrev_tag
;
9946 dwarf_vma dwarf_tag
;
9947 const struct abbrev_lookup_entry
*entry
;
9949 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9952 second_abbrev_tag
= abbrev_tag
;
9954 entryptr
= entry_pool
+ entry_offset
;
9957 if (abbrev_tag
== 0)
9961 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9962 (unsigned long) abbrev_tag
);
9964 for (entry
= abbrev_lookup
;
9965 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9967 if (entry
->abbrev_tag
== abbrev_tag
)
9969 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9971 warn (_("Undefined abbreviation tag %lu "
9972 "in unit 0x%lx in the debug_names\n"),
9974 (long) (unit_start
- section
->start
));
9977 abbrevptr
= entry
->abbrev_lookup_ptr
;
9978 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9980 printf (" %s", get_TAG_name (dwarf_tag
));
9983 dwarf_vma xindex
, form
;
9985 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9986 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9987 if (xindex
== 0 && form
== 0)
9991 printf (" %s", get_IDX_name (xindex
));
9992 entryptr
= read_and_display_attr_value (0, form
, 0,
9993 unit_start
, entryptr
, unit_end
,
9995 dwarf_version
, NULL
,
10002 printf (_(" <no entries>"));
10006 free (abbrev_lookup
);
10013 display_debug_links (struct dwarf_section
* section
,
10014 void * file ATTRIBUTE_UNUSED
)
10016 const unsigned char * filename
;
10017 unsigned int filelen
;
10019 introduce (section
, false);
10021 /* The .gnu_debuglink section is formatted as:
10022 (c-string) Filename.
10023 (padding) If needed to reach a 4 byte boundary.
10024 (uint32_t) CRC32 value.
10026 The .gun_debugaltlink section is formatted as:
10027 (c-string) Filename.
10028 (binary) Build-ID. */
10030 filename
= section
->start
;
10031 filelen
= strnlen ((const char *) filename
, section
->size
);
10032 if (filelen
== section
->size
)
10034 warn (_("The debuglink filename is corrupt/missing\n"));
10038 printf (_(" Separate debug info file: %s\n"), filename
);
10040 if (startswith (section
->name
, ".gnu_debuglink"))
10042 unsigned int crc32
;
10043 unsigned int crc_offset
;
10045 crc_offset
= filelen
+ 1;
10046 crc_offset
= (crc_offset
+ 3) & ~3;
10047 if (crc_offset
+ 4 > section
->size
)
10049 warn (_("CRC offset missing/truncated\n"));
10053 crc32
= byte_get (filename
+ crc_offset
, 4);
10055 printf (_(" CRC value: %#x\n"), crc32
);
10057 if (crc_offset
+ 4 < section
->size
)
10059 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10060 (long)(section
->size
- (crc_offset
+ 4)));
10064 else /* startswith (section->name, ".gnu_debugaltlink") */
10066 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
10067 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
10068 bfd_size_type printed
;
10070 /* FIXME: Should we support smaller build-id notes ? */
10071 if (build_id_len
< 0x14)
10073 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
10077 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
10078 display_data (printed
, build_id
, build_id_len
);
10087 display_gdb_index (struct dwarf_section
*section
,
10088 void *file ATTRIBUTE_UNUSED
)
10090 unsigned char *start
= section
->start
;
10092 uint32_t cu_list_offset
, tu_list_offset
;
10093 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10094 unsigned int cu_list_elements
, tu_list_elements
;
10095 unsigned int address_table_size
, symbol_table_slots
;
10096 unsigned char *cu_list
, *tu_list
;
10097 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10100 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10102 introduce (section
, false);
10104 if (section
->size
< 6 * sizeof (uint32_t))
10106 warn (_("Truncated header in the %s section.\n"), section
->name
);
10110 version
= byte_get_little_endian (start
, 4);
10111 printf (_("Version %ld\n"), (long) version
);
10113 /* Prior versions are obsolete, and future versions may not be
10114 backwards compatible. */
10115 if (version
< 3 || version
> 8)
10117 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10121 warn (_("The address table data in version 3 may be wrong.\n"));
10123 warn (_("Version 4 does not support case insensitive lookups.\n"));
10125 warn (_("Version 5 does not include inlined functions.\n"));
10127 warn (_("Version 6 does not include symbol attributes.\n"));
10128 /* Version 7 indices generated by Gold have bad type unit references,
10129 PR binutils/15021. But we don't know if the index was generated by
10130 Gold or not, so to avoid worrying users with gdb-generated indices
10131 we say nothing for version 7 here. */
10133 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10134 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10135 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10136 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10137 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10139 if (cu_list_offset
> section
->size
10140 || tu_list_offset
> section
->size
10141 || address_table_offset
> section
->size
10142 || symbol_table_offset
> section
->size
10143 || constant_pool_offset
> section
->size
)
10145 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10149 /* PR 17531: file: 418d0a8a. */
10150 if (tu_list_offset
< cu_list_offset
)
10152 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10153 tu_list_offset
, cu_list_offset
);
10157 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
10159 if (address_table_offset
< tu_list_offset
)
10161 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10162 address_table_offset
, tu_list_offset
);
10166 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
10168 /* PR 17531: file: 18a47d3d. */
10169 if (symbol_table_offset
< address_table_offset
)
10171 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
10172 symbol_table_offset
, address_table_offset
);
10176 address_table_size
= symbol_table_offset
- address_table_offset
;
10178 if (constant_pool_offset
< symbol_table_offset
)
10180 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10181 constant_pool_offset
, symbol_table_offset
);
10185 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10187 cu_list
= start
+ cu_list_offset
;
10188 tu_list
= start
+ tu_list_offset
;
10189 address_table
= start
+ address_table_offset
;
10190 symbol_table
= start
+ symbol_table_offset
;
10191 constant_pool
= start
+ constant_pool_offset
;
10193 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
10195 warn (_("Address table extends beyond end of section.\n"));
10199 printf (_("\nCU table:\n"));
10200 for (i
= 0; i
< cu_list_elements
; i
+= 2)
10202 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
10203 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
10205 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
10206 (unsigned long) cu_offset
,
10207 (unsigned long) (cu_offset
+ cu_length
- 1));
10210 printf (_("\nTU table:\n"));
10211 for (i
= 0; i
< tu_list_elements
; i
+= 3)
10213 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
10214 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
10215 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
10217 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
10218 (unsigned long) tu_offset
,
10219 (unsigned long) type_offset
);
10220 print_dwarf_vma (signature
, 8);
10224 printf (_("\nAddress table:\n"));
10225 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10228 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10229 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10230 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10232 print_dwarf_vma (low
, 8);
10233 print_dwarf_vma (high
, 8);
10234 printf (_("%lu\n"), (unsigned long) cu_index
);
10237 printf (_("\nSymbol table:\n"));
10238 for (i
= 0; i
< symbol_table_slots
; ++i
)
10240 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10241 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10242 uint32_t num_cus
, cu
;
10244 if (name_offset
!= 0
10245 || cu_vector_offset
!= 0)
10248 unsigned char * adr
;
10250 adr
= constant_pool
+ name_offset
;
10251 /* PR 17531: file: 5b7b07ad. */
10252 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
10254 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10255 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10259 printf ("[%3u] %.*s:", i
,
10260 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10261 constant_pool
+ name_offset
);
10263 adr
= constant_pool
+ cu_vector_offset
;
10264 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
10266 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10267 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10268 cu_vector_offset
, i
);
10272 num_cus
= byte_get_little_endian (adr
, 4);
10274 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
10275 if (num_cus
* 4 < num_cus
10276 || adr
>= section
->start
+ section
->size
10277 || adr
< constant_pool
)
10279 printf ("<invalid number of CUs: %d>\n", num_cus
);
10280 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10288 for (j
= 0; j
< num_cus
; ++j
)
10291 gdb_index_symbol_kind kind
;
10293 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10294 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10295 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10296 cu
= GDB_INDEX_CU_VALUE (cu
);
10297 /* Convert to TU number if it's for a type unit. */
10298 if (cu
>= cu_list_elements
/ 2)
10299 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10300 (unsigned long) (cu
- cu_list_elements
/ 2));
10302 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10304 printf (" [%s, %s]",
10305 is_static
? _("static") : _("global"),
10306 get_gdb_index_symbol_kind_name (kind
));
10318 /* Pre-allocate enough space for the CU/TU sets needed. */
10321 prealloc_cu_tu_list (unsigned int nshndx
)
10323 if (shndx_pool
== NULL
)
10325 shndx_pool_size
= nshndx
;
10326 shndx_pool_used
= 0;
10327 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10328 sizeof (unsigned int));
10332 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10333 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10334 sizeof (unsigned int));
10339 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10341 if (shndx_pool_used
>= shndx_pool_size
)
10343 error (_("Internal error: out of space in the shndx pool.\n"));
10346 shndx_pool
[shndx_pool_used
++] = shndx
;
10350 end_cu_tu_entry (void)
10352 if (shndx_pool_used
>= shndx_pool_size
)
10354 error (_("Internal error: out of space in the shndx pool.\n"));
10357 shndx_pool
[shndx_pool_used
++] = 0;
10360 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10362 static const char *
10363 get_DW_SECT_short_name (unsigned int dw_sect
)
10365 static char buf
[16];
10371 case DW_SECT_TYPES
:
10373 case DW_SECT_ABBREV
:
10379 case DW_SECT_STR_OFFSETS
:
10381 case DW_SECT_MACINFO
:
10383 case DW_SECT_MACRO
:
10389 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10393 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10394 These sections are extensions for Fission.
10395 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10398 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10400 unsigned char *phdr
= section
->start
;
10401 unsigned char *limit
= phdr
+ section
->size
;
10402 unsigned char *phash
;
10403 unsigned char *pindex
;
10404 unsigned char *ppool
;
10405 unsigned int version
;
10406 unsigned int ncols
= 0;
10407 unsigned int nused
;
10408 unsigned int nslots
;
10411 dwarf_vma signature_high
;
10412 dwarf_vma signature_low
;
10415 /* PR 17512: file: 002-168123-0.004. */
10418 warn (_("Section %s is empty\n"), section
->name
);
10421 /* PR 17512: file: 002-376-0.004. */
10422 if (section
->size
< 24)
10424 warn (_("Section %s is too small to contain a CU/TU header\n"),
10429 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
10431 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
10432 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
10433 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
10436 pindex
= phash
+ (size_t) nslots
* 8;
10437 ppool
= pindex
+ (size_t) nslots
* 4;
10441 introduce (section
, false);
10443 printf (_(" Version: %u\n"), version
);
10445 printf (_(" Number of columns: %u\n"), ncols
);
10446 printf (_(" Number of used entries: %u\n"), nused
);
10447 printf (_(" Number of slots: %u\n\n"), nslots
);
10450 /* PR 17531: file: 45d69832. */
10451 if ((size_t) nslots
* 8 / 8 != nslots
10452 || phash
< phdr
|| phash
> limit
10453 || pindex
< phash
|| pindex
> limit
10454 || ppool
< pindex
|| ppool
> limit
)
10456 warn (ngettext ("Section %s is too small for %u slot\n",
10457 "Section %s is too small for %u slots\n",
10459 section
->name
, nslots
);
10466 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10467 for (i
= 0; i
< nslots
; i
++)
10469 unsigned char *shndx_list
;
10470 unsigned int shndx
;
10472 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
10473 if (signature_high
!= 0 || signature_low
!= 0)
10475 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10476 shndx_list
= ppool
+ j
* 4;
10477 /* PR 17531: file: 705e010d. */
10478 if (shndx_list
< ppool
)
10480 warn (_("Section index pool located before start of section\n"));
10485 printf (_(" [%3d] Signature: 0x%s Sections: "),
10486 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10487 buf
, sizeof (buf
)));
10490 if (shndx_list
>= limit
)
10492 warn (_("Section %s too small for shndx pool\n"),
10496 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10500 printf (" %d", shndx
);
10502 add_shndx_to_cu_tu_entry (shndx
);
10508 end_cu_tu_entry ();
10514 else if (version
== 2)
10517 unsigned int dw_sect
;
10518 unsigned char *ph
= phash
;
10519 unsigned char *pi
= pindex
;
10520 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10521 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10522 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10524 struct cu_tu_set
*this_set
= NULL
;
10526 unsigned char *prow
;
10528 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10530 /* PR 17531: file: 0dd159bf.
10531 Check for integer overflow (can occur when size_t is 32-bit)
10532 with overlarge ncols or nused values. */
10534 && ((size_t) ncols
* 4 / 4 != ncols
10535 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10536 || poffsets
< ppool
|| poffsets
> limit
10537 || psizes
< poffsets
|| psizes
> limit
10538 || pend
< psizes
|| pend
> limit
))
10540 warn (_("Section %s too small for offset and size tables\n"),
10547 printf (_(" Offset table\n"));
10548 printf (" slot %-16s ",
10549 is_tu_index
? _("signature") : _("dwo_id"));
10556 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10557 this_set
= tu_sets
;
10562 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10563 this_set
= cu_sets
;
10569 for (j
= 0; j
< ncols
; j
++)
10571 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10572 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10577 for (i
= 0; i
< nslots
; i
++)
10579 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10581 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10584 /* PR 17531: file: a05f6ab3. */
10587 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10594 size_t num_copy
= sizeof (uint64_t);
10596 /* PR 23064: Beware of buffer overflow. */
10597 if (ph
+ num_copy
< limit
)
10598 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10601 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10606 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10607 /* PR 17531: file: b8ce60a8. */
10608 if (prow
< poffsets
|| prow
> limit
)
10610 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10616 printf (_(" [%3d] 0x%s"),
10617 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10618 buf
, sizeof (buf
)));
10619 for (j
= 0; j
< ncols
; j
++)
10621 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10623 printf (" %8d", val
);
10626 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10628 /* PR 17531: file: 10796eb3. */
10629 if (dw_sect
>= DW_SECT_MAX
)
10630 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10632 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10648 printf (_(" Size table\n"));
10649 printf (" slot %-16s ",
10650 is_tu_index
? _("signature") : _("dwo_id"));
10653 for (j
= 0; j
< ncols
; j
++)
10655 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
10657 printf (" %8s", get_DW_SECT_short_name (val
));
10663 for (i
= 0; i
< nslots
; i
++)
10665 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10667 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10670 prow
= psizes
+ (row
- 1) * ncols
* 4;
10673 printf (_(" [%3d] 0x%s"),
10674 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10675 buf
, sizeof (buf
)));
10677 for (j
= 0; j
< ncols
; j
++)
10679 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10681 printf (" %8d", val
);
10684 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10685 if (dw_sect
>= DW_SECT_MAX
)
10686 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10688 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10700 else if (do_display
)
10701 printf (_(" Unsupported version (%d)\n"), version
);
10709 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10711 /* Load the CU and TU indexes if present. This will build a list of
10712 section sets that we can use to associate a .debug_info.dwo section
10713 with its associated .debug_abbrev.dwo section in a .dwp file. */
10716 load_cu_tu_indexes (void *file
)
10718 /* If we have already loaded (or tried to load) the CU and TU indexes
10719 then do not bother to repeat the task. */
10720 if (cu_tu_indexes_read
== -1)
10722 cu_tu_indexes_read
= true;
10724 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10725 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10726 cu_tu_indexes_read
= false;
10728 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10729 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10730 cu_tu_indexes_read
= false;
10733 return (bool) cu_tu_indexes_read
;
10736 /* Find the set of sections that includes section SHNDX. */
10739 find_cu_tu_set (void *file
, unsigned int shndx
)
10743 if (! load_cu_tu_indexes (file
))
10746 /* Find SHNDX in the shndx pool. */
10747 for (i
= 0; i
< shndx_pool_used
; i
++)
10748 if (shndx_pool
[i
] == shndx
)
10751 if (i
>= shndx_pool_used
)
10754 /* Now backup to find the first entry in the set. */
10755 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10758 return shndx_pool
+ i
;
10761 /* Display a .debug_cu_index or .debug_tu_index section. */
10764 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10766 return process_cu_tu_index (section
, 1);
10770 display_debug_not_supported (struct dwarf_section
*section
,
10771 void *file ATTRIBUTE_UNUSED
)
10773 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10779 /* Like malloc, but takes two parameters like calloc.
10780 Verifies that the first parameter is not too large.
10781 Note: does *not* initialise the allocated memory to zero. */
10784 cmalloc (size_t nmemb
, size_t size
)
10786 /* Check for overflow. */
10787 if (nmemb
>= ~(size_t) 0 / size
)
10790 return xmalloc (nmemb
* size
);
10793 /* Like xmalloc, but takes two parameters like calloc.
10794 Verifies that the first parameter is not too large.
10795 Note: does *not* initialise the allocated memory to zero. */
10798 xcmalloc (size_t nmemb
, size_t size
)
10800 /* Check for overflow. */
10801 if (nmemb
>= ~(size_t) 0 / size
)
10804 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10809 return xmalloc (nmemb
* size
);
10812 /* Like xrealloc, but takes three parameters.
10813 Verifies that the second parameter is not too large.
10814 Note: does *not* initialise any new memory to zero. */
10817 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10819 /* Check for overflow. */
10820 if (nmemb
>= ~(size_t) 0 / size
)
10822 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10827 return xrealloc (ptr
, nmemb
* size
);
10830 /* Like xcalloc, but verifies that the first parameter is not too large. */
10833 xcalloc2 (size_t nmemb
, size_t size
)
10835 /* Check for overflow. */
10836 if (nmemb
>= ~(size_t) 0 / size
)
10838 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10843 return xcalloc (nmemb
, size
);
10846 static unsigned long
10847 calc_gnu_debuglink_crc32 (unsigned long crc
,
10848 const unsigned char * buf
,
10851 static const unsigned long crc32_table
[256] =
10853 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10854 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10855 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10856 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10857 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10858 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10859 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10860 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10861 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10862 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10863 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10864 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10865 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10866 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10867 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10868 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10869 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10870 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10871 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10872 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10873 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10874 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10875 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10876 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10877 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10878 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10879 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10880 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10881 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10882 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10883 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10884 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10885 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10886 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10887 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10888 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10889 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10890 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10891 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10892 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10893 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10894 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10895 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10896 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10897 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10898 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10899 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10900 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10901 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10902 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10903 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10906 const unsigned char *end
;
10908 crc
= ~crc
& 0xffffffff;
10909 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10910 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10911 return ~crc
& 0xffffffff;
10914 typedef bool (*check_func_type
) (const char *, void *);
10915 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
10918 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10920 static unsigned char buffer
[8 * 1024];
10922 bfd_size_type count
;
10923 unsigned long crc
= 0;
10926 sep_data
= open_debug_file (pathname
);
10927 if (sep_data
== NULL
)
10930 /* Yes - we are opening the file twice... */
10931 f
= fopen (pathname
, "rb");
10934 /* Paranoia: This should never happen. */
10935 close_debug_file (sep_data
);
10936 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10940 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10941 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10945 if (crc
!= * (unsigned long *) crc_pointer
)
10947 close_debug_file (sep_data
);
10948 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10956 static const char *
10957 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10960 unsigned int crc_offset
;
10961 unsigned long * crc32
= (unsigned long *) data
;
10963 /* The name is first.
10964 The CRC value is stored after the filename, aligned up to 4 bytes. */
10965 name
= (const char *) section
->start
;
10967 crc_offset
= strnlen (name
, section
->size
) + 1;
10968 if (crc_offset
== 1)
10970 crc_offset
= (crc_offset
+ 3) & ~3;
10971 if (crc_offset
+ 4 > section
->size
)
10974 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10979 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10981 void * sep_data
= open_debug_file (filename
);
10983 if (sep_data
== NULL
)
10986 /* FIXME: We should now extract the build-id in the separate file
10992 typedef struct build_id_data
10995 const unsigned char * data
;
10998 static const char *
10999 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11002 bfd_size_type namelen
;
11003 bfd_size_type id_len
;
11004 Build_id_data
* build_id_data
;
11006 /* The name is first.
11007 The build-id follows immediately, with no padding, up to the section's end. */
11009 name
= (const char *) section
->start
;
11010 namelen
= strnlen (name
, section
->size
) + 1;
11013 if (namelen
>= section
->size
)
11016 id_len
= section
->size
- namelen
;
11020 build_id_data
= (Build_id_data
*) data
;
11021 build_id_data
->len
= id_len
;
11022 build_id_data
->data
= section
->start
+ namelen
;
11028 add_separate_debug_file (const char * filename
, void * handle
)
11030 separate_info
* i
= xmalloc (sizeof * i
);
11032 i
->filename
= filename
;
11033 i
->handle
= handle
;
11034 i
->next
= first_separate_info
;
11035 first_separate_info
= i
;
11038 #if HAVE_LIBDEBUGINFOD
11039 /* Query debuginfod servers for the target debuglink or debugaltlink
11040 file. If successful, store the path of the file in filename and
11041 return TRUE, otherwise return FALSE. */
11044 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11048 size_t build_id_len
;
11049 unsigned char * build_id
;
11051 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11053 /* Get the build-id of file. */
11054 build_id
= get_build_id (file
);
11057 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11059 /* Get the build-id of the debugaltlink file. */
11060 unsigned int filelen
;
11062 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11063 if (filelen
== section
->size
)
11064 /* Corrupt debugaltlink. */
11067 build_id
= section
->start
+ filelen
+ 1;
11068 build_id_len
= section
->size
- (filelen
+ 1);
11070 if (build_id_len
== 0)
11079 debuginfod_client
* client
;
11081 client
= debuginfod_begin ();
11082 if (client
== NULL
)
11085 /* Query debuginfod servers for the target file. If found its path
11086 will be stored in filename. */
11087 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11088 debuginfod_end (client
);
11090 /* Only free build_id if we allocated space for a hex string
11091 in get_build_id (). */
11092 if (build_id_len
== 0)
11097 /* File successfully retrieved. Close fd since we want to
11098 use open_debug_file () on filename instead. */
11109 load_separate_debug_info (const char * main_filename
,
11110 struct dwarf_section
* xlink
,
11111 parse_func_type parse_func
,
11112 check_func_type check_func
,
11114 void * file ATTRIBUTE_UNUSED
)
11116 const char * separate_filename
;
11117 char * debug_filename
;
11119 size_t canon_dirlen
;
11122 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11124 warn (_("Corrupt debuglink section: %s\n"),
11125 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11129 /* Attempt to locate the separate file.
11130 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11132 canon_dir
= lrealpath (main_filename
);
11134 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11135 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11137 canon_dir
[canon_dirlen
] = '\0';
11140 #define DEBUGDIR "/lib/debug"
11142 #ifndef EXTRA_DEBUG_ROOT1
11143 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11145 #ifndef EXTRA_DEBUG_ROOT2
11146 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11149 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11151 + strlen (".debug/")
11152 #ifdef EXTRA_DEBUG_ROOT1
11153 + strlen (EXTRA_DEBUG_ROOT1
)
11155 #ifdef EXTRA_DEBUG_ROOT2
11156 + strlen (EXTRA_DEBUG_ROOT2
)
11158 + strlen (separate_filename
)
11160 if (debug_filename
== NULL
)
11162 warn (_("Out of memory"));
11167 /* First try in the current directory. */
11168 sprintf (debug_filename
, "%s", separate_filename
);
11169 if (check_func (debug_filename
, func_data
))
11172 /* Then try in a subdirectory called .debug. */
11173 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11174 if (check_func (debug_filename
, func_data
))
11177 /* Then try in the same directory as the original file. */
11178 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11179 if (check_func (debug_filename
, func_data
))
11182 /* And the .debug subdirectory of that directory. */
11183 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11184 if (check_func (debug_filename
, func_data
))
11187 #ifdef EXTRA_DEBUG_ROOT1
11188 /* Try the first extra debug file root. */
11189 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11190 if (check_func (debug_filename
, func_data
))
11193 /* Try the first extra debug file root. */
11194 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11195 if (check_func (debug_filename
, func_data
))
11199 #ifdef EXTRA_DEBUG_ROOT2
11200 /* Try the second extra debug file root. */
11201 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11202 if (check_func (debug_filename
, func_data
))
11206 /* Then try in the global debug_filename directory. */
11207 strcpy (debug_filename
, DEBUGDIR
);
11208 dirlen
= strlen (DEBUGDIR
) - 1;
11209 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11210 strcat (debug_filename
, "/");
11211 strcat (debug_filename
, (const char *) separate_filename
);
11213 if (check_func (debug_filename
, func_data
))
11216 #if HAVE_LIBDEBUGINFOD
11218 char * tmp_filename
;
11220 if (debuginfod_fetch_separate_debug_info (xlink
,
11224 /* File successfully downloaded from server, replace
11225 debug_filename with the file's path. */
11226 free (debug_filename
);
11227 debug_filename
= tmp_filename
;
11233 if (do_debug_links
)
11235 /* Failed to find the file. */
11236 warn (_("could not find separate debug file '%s'\n"),
11237 separate_filename
);
11238 warn (_("tried: %s\n"), debug_filename
);
11240 #ifdef EXTRA_DEBUG_ROOT2
11241 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11242 separate_filename
);
11243 warn (_("tried: %s\n"), debug_filename
);
11246 #ifdef EXTRA_DEBUG_ROOT1
11247 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11248 canon_dir
, separate_filename
);
11249 warn (_("tried: %s\n"), debug_filename
);
11251 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11252 separate_filename
);
11253 warn (_("tried: %s\n"), debug_filename
);
11256 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11257 separate_filename
);
11258 warn (_("tried: %s\n"), debug_filename
);
11260 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11261 warn (_("tried: %s\n"), debug_filename
);
11263 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11264 warn (_("tried: %s\n"), debug_filename
);
11266 sprintf (debug_filename
, "%s", separate_filename
);
11267 warn (_("tried: %s\n"), debug_filename
);
11269 #if HAVE_LIBDEBUGINFOD
11271 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11275 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11281 free (debug_filename
);
11287 void * debug_handle
;
11289 /* Now open the file.... */
11290 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11292 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11293 free (debug_filename
);
11297 /* FIXME: We do not check to see if there are any other separate debug info
11298 files that would also match. */
11300 if (do_debug_links
)
11301 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11302 add_separate_debug_file (debug_filename
, debug_handle
);
11304 /* Do not free debug_filename - it might be referenced inside
11305 the structure returned by open_debug_file(). */
11306 return debug_handle
;
11309 /* Attempt to load a separate dwarf object file. */
11312 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11314 char * separate_filename
;
11315 void * separate_handle
;
11317 if (IS_ABSOLUTE_PATH (name
))
11318 separate_filename
= strdup (name
);
11320 /* FIXME: Skip adding / if dwo_dir ends in /. */
11321 separate_filename
= concat (dir
, "/", name
, NULL
);
11322 if (separate_filename
== NULL
)
11324 warn (_("Out of memory allocating dwo filename\n"));
11328 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11330 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11331 free (separate_filename
);
11335 /* FIXME: We should check the dwo_id. */
11337 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11339 add_separate_debug_file (separate_filename
, separate_handle
);
11340 /* Note - separate_filename will be freed in free_debug_memory(). */
11341 return separate_handle
;
11345 load_debug_sup_file (const char * main_filename
, void * file
)
11347 if (! load_debug_section (debug_sup
, file
))
11348 return; /* No .debug_sup section. */
11350 struct dwarf_section
* section
;
11351 section
= & debug_displays
[debug_sup
].section
;
11352 assert (section
!= NULL
);
11354 if (section
->start
== NULL
|| section
->size
< 5)
11356 warn (_(".debug_sup section is corrupt/empty\n"));
11360 if (section
->start
[2] != 0)
11361 return; /* This is a supplementary file. */
11363 const char * filename
= (const char *) section
->start
+ 3;
11364 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11366 warn (_("filename in .debug_sup section is corrupt\n"));
11370 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11375 new_len
= asprintf (& new_name
, "%.*s/%s",
11376 (int) (strrchr (main_filename
, '/') - main_filename
),
11381 warn (_("unable to construct path for supplementary debug file"));
11386 filename
= new_name
;
11390 /* PR 27796: Make sure that we pass a filename that can be free'd to
11391 add_separate_debug_file(). */
11392 filename
= strdup (filename
);
11393 if (filename
== NULL
)
11395 warn (_("out of memory constructing filename for .debug_sup link\n"));
11400 void * handle
= open_debug_file (filename
);
11401 if (handle
== NULL
)
11403 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11404 free ((void *) filename
);
11408 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11410 /* FIXME: Compare the checksums, if present. */
11411 add_separate_debug_file (filename
, handle
);
11414 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11415 Recursively check the loaded files for more of these sections.
11416 Also follow any links in .debug_sup sections.
11417 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11420 check_for_and_load_links (void * file
, const char * filename
)
11422 void * handle
= NULL
;
11424 if (load_debug_section (gnu_debugaltlink
, file
))
11426 Build_id_data build_id_data
;
11428 handle
= load_separate_debug_info (filename
,
11429 & debug_displays
[gnu_debugaltlink
].section
,
11430 parse_gnu_debugaltlink
,
11431 check_gnu_debugaltlink
,
11436 assert (handle
== first_separate_info
->handle
);
11437 check_for_and_load_links (first_separate_info
->handle
,
11438 first_separate_info
->filename
);
11442 if (load_debug_section (gnu_debuglink
, file
))
11444 unsigned long crc32
;
11446 handle
= load_separate_debug_info (filename
,
11447 & debug_displays
[gnu_debuglink
].section
,
11448 parse_gnu_debuglink
,
11449 check_gnu_debuglink
,
11454 assert (handle
== first_separate_info
->handle
);
11455 check_for_and_load_links (first_separate_info
->handle
,
11456 first_separate_info
->filename
);
11460 load_debug_sup_file (filename
, file
);
11463 /* Load the separate debug info file(s) attached to FILE, if any exist.
11464 Returns TRUE if any were found, FALSE otherwise.
11465 If TRUE is returned then the linked list starting at first_separate_info
11466 will be populated with open file handles. */
11469 load_separate_debug_files (void * file
, const char * filename
)
11471 /* Skip this operation if we are not interested in debug links. */
11472 if (! do_follow_links
&& ! do_debug_links
)
11475 /* See if there are any dwo links. */
11476 if (load_debug_section (str
, file
)
11477 && load_debug_section (abbrev
, file
)
11478 && load_debug_section (info
, file
))
11482 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11485 bool introduced
= false;
11487 const char *dir
= NULL
;
11488 const char *id
= NULL
;
11489 const char *name
= NULL
;
11491 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11493 /* Accumulate NAME, DIR and ID fields. */
11494 switch (dwinfo
->type
)
11498 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11499 name
= dwinfo
->value
;
11503 /* There can be multiple DW_AT_comp_dir entries in a CU,
11504 so do not complain. */
11505 dir
= dwinfo
->value
;
11510 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11511 id
= dwinfo
->value
;
11515 error (_("Unexpected DWO INFO type"));
11519 /* If we have reached the end of our list, or we are changing
11520 CUs, then display the information that we have accumulated
11523 && (dwinfo
->next
== NULL
11524 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11526 if (do_debug_links
)
11530 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11531 debug_displays
[info
].section
.uncompressed_name
);
11535 printf (_(" Name: %s\n"), name
);
11536 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11538 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11540 printf (_(" ID: <not specified>\n"));
11544 if (do_follow_links
)
11545 load_dwo_file (filename
, name
, dir
, id
);
11547 name
= dir
= id
= NULL
;
11553 if (! do_follow_links
)
11554 /* The other debug links will be displayed by display_debug_links()
11555 so we do not need to do any further processing here. */
11558 /* FIXME: We do not check for the presence of both link sections in the same file. */
11559 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11560 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11562 check_for_and_load_links (file
, filename
);
11563 if (first_separate_info
!= NULL
)
11566 do_follow_links
= 0;
11571 free_debug_memory (void)
11575 free_all_abbrevs ();
11577 free (cu_abbrev_map
);
11578 cu_abbrev_map
= NULL
;
11579 next_free_abbrev_map_entry
= 0;
11583 shndx_pool_size
= 0;
11584 shndx_pool_used
= 0;
11592 memset (level_type_signed
, 0, sizeof level_type_signed
);
11593 cu_tu_indexes_read
= -1;
11595 for (i
= 0; i
< max
; i
++)
11596 free_debug_section ((enum dwarf_section_display_enum
) i
);
11598 if (debug_information
!= NULL
)
11600 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11602 if (debug_information
[i
].max_loc_offsets
)
11604 free (debug_information
[i
].loc_offsets
);
11605 free (debug_information
[i
].have_frame_base
);
11607 if (debug_information
[i
].max_range_lists
)
11608 free (debug_information
[i
].range_lists
);
11610 free (debug_information
);
11611 debug_information
= NULL
;
11612 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11616 separate_info
* next
;
11618 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11620 close_debug_file (d
->handle
);
11621 free ((void *) d
->filename
);
11625 first_separate_info
= NULL
;
11631 dwarf_select_sections_by_names (const char *names
)
11635 const char * option
;
11639 debug_dump_long_opts
;
11641 static const debug_dump_long_opts opts_table
[] =
11643 /* Please keep this table alpha- sorted. */
11644 { "Ranges", & do_debug_ranges
, 1 },
11645 { "abbrev", & do_debug_abbrevs
, 1 },
11646 { "addr", & do_debug_addr
, 1 },
11647 { "aranges", & do_debug_aranges
, 1 },
11648 { "cu_index", & do_debug_cu_index
, 1 },
11649 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11650 { "follow-links", & do_follow_links
, 1 },
11651 { "frames", & do_debug_frames
, 1 },
11652 { "frames-interp", & do_debug_frames_interp
, 1 },
11653 /* The special .gdb_index section. */
11654 { "gdb_index", & do_gdb_index
, 1 },
11655 { "info", & do_debug_info
, 1 },
11656 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11657 { "links", & do_debug_links
, 1 },
11658 { "loc", & do_debug_loc
, 1 },
11659 { "macro", & do_debug_macinfo
, 1 },
11660 { "no-follow-links", & do_follow_links
, 0 },
11661 { "pubnames", & do_debug_pubnames
, 1 },
11662 { "pubtypes", & do_debug_pubtypes
, 1 },
11663 /* This entry is for compatibility
11664 with earlier versions of readelf. */
11665 { "ranges", & do_debug_aranges
, 1 },
11666 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11667 { "str", & do_debug_str
, 1 },
11668 { "str-offsets", & do_debug_str_offsets
, 1 },
11669 /* These trace_* sections are used by Itanium VMS. */
11670 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11671 { "trace_aranges", & do_trace_aranges
, 1 },
11672 { "trace_info", & do_trace_info
, 1 },
11681 const debug_dump_long_opts
* entry
;
11683 for (entry
= opts_table
; entry
->option
; entry
++)
11685 size_t len
= strlen (entry
->option
);
11687 if (strncmp (p
, entry
->option
, len
) == 0
11688 && (p
[len
] == ',' || p
[len
] == '\0'))
11690 * entry
->variable
= entry
->val
;
11692 /* The --debug-dump=frames-interp option also
11693 enables the --debug-dump=frames option. */
11694 if (do_debug_frames_interp
)
11695 do_debug_frames
= 1;
11702 if (entry
->option
== NULL
)
11704 warn (_("Unrecognized debug option '%s'\n"), p
);
11705 p
= strchr (p
, ',');
11716 dwarf_select_sections_by_letters (const char *letters
)
11718 unsigned int lindex
= 0;
11720 while (letters
[lindex
])
11721 switch (letters
[lindex
++])
11723 case 'A': do_debug_addr
= 1; break;
11724 case 'a': do_debug_abbrevs
= 1; break;
11725 case 'c': do_debug_cu_index
= 1; break;
11726 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11727 case 'f': do_debug_frames
= 1; break;
11728 case 'g': do_gdb_index
= 1; break;
11729 case 'i': do_debug_info
= 1; break;
11730 case 'K': do_follow_links
= 1; break;
11731 case 'N': do_follow_links
= 0; break;
11732 case 'k': do_debug_links
= 1; break;
11733 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11734 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11735 case 'm': do_debug_macinfo
= 1; break;
11736 case 'O': do_debug_str_offsets
= 1; break;
11737 case 'o': do_debug_loc
= 1; break;
11738 case 'p': do_debug_pubnames
= 1; break;
11739 case 'R': do_debug_ranges
= 1; break;
11740 case 'r': do_debug_aranges
= 1; break;
11741 case 's': do_debug_str
= 1; break;
11742 case 'T': do_trace_aranges
= 1; break;
11743 case 't': do_debug_pubtypes
= 1; break;
11744 case 'U': do_trace_info
= 1; break;
11745 case 'u': do_trace_abbrevs
= 1; break;
11748 warn (_("Unrecognized debug option '%s'\n"), letters
);
11754 dwarf_select_sections_all (void)
11757 do_debug_abbrevs
= 1;
11758 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11759 do_debug_pubnames
= 1;
11760 do_debug_pubtypes
= 1;
11761 do_debug_aranges
= 1;
11762 do_debug_ranges
= 1;
11763 do_debug_frames
= 1;
11764 do_debug_macinfo
= 1;
11769 do_trace_abbrevs
= 1;
11770 do_trace_aranges
= 1;
11772 do_debug_cu_index
= 1;
11773 do_follow_links
= 1;
11774 do_debug_links
= 1;
11775 do_debug_str_offsets
= 1;
11778 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
11779 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
11781 /* N.B. The order here must match the order in section_display_enum. */
11783 struct dwarf_section_display debug_displays
[] =
11785 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11786 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
11787 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11788 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
11789 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11790 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
11791 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
11792 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11793 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11794 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11795 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11796 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11797 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11798 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11799 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
11800 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
11801 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11802 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11803 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11804 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11805 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
11806 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11807 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
11808 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
11809 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
11810 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
11811 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
11812 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
11813 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11814 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
11815 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11816 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11817 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11818 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11819 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
11820 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11821 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11822 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
11823 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11824 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11825 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11826 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11827 { { ".debug_sup", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
11828 /* Separate debug info files can containt their own .debug_str section,
11829 and this might be in *addition* to a .debug_str section already present
11830 in the main file. Hence we need to have two entries for .debug_str. */
11831 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11834 /* A static assertion. */
11835 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];