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) + amount) >= (END)) \
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) + amount) >= (END)) \
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) + 8) <= (END)) \
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 (unsigned char * start
,
1063 const unsigned char * end
,
1068 unsigned long entry
;
1070 unsigned long attribute
;
1073 READ_ULEB (entry
, start
, end
);
1075 /* A single zero is supposed to end the set according
1076 to the standard. If there's more, then signal that to
1083 READ_ULEB (tag
, start
, end
);
1087 children
= *start
++;
1089 add_abbrev (entry
, tag
, children
, list
);
1094 /* Initialize it due to a false compiler warning. */
1095 bfd_signed_vma implicit_const
= -1;
1097 READ_ULEB (attribute
, start
, end
);
1101 READ_ULEB (form
, start
, end
);
1105 if (form
== DW_FORM_implicit_const
)
1107 READ_SLEB (implicit_const
, start
, end
);
1112 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1114 while (attribute
!= 0);
1117 /* Report the missing single zero which ends the section. */
1118 error (_(".debug_abbrev section not zero terminated\n"));
1124 get_TAG_name (unsigned long tag
)
1126 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1130 static char buffer
[100];
1132 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1133 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1135 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1143 get_FORM_name (unsigned long form
)
1148 return "DW_FORM value: 0";
1150 name
= get_DW_FORM_name (form
);
1153 static char buffer
[100];
1155 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1163 get_IDX_name (unsigned long idx
)
1165 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1169 static char buffer
[100];
1171 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1178 static unsigned char *
1179 display_block (unsigned char *data
,
1181 const unsigned char * const end
, char delimiter
)
1185 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1187 return (unsigned char *) end
;
1189 maxlen
= (dwarf_vma
) (end
- data
);
1190 length
= length
> maxlen
? maxlen
: length
;
1193 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1199 decode_location_expression (unsigned char * data
,
1200 unsigned int pointer_size
,
1201 unsigned int offset_size
,
1204 dwarf_vma cu_offset
,
1205 struct dwarf_section
* section
)
1209 dwarf_signed_vma svalue
;
1210 unsigned char *end
= data
+ length
;
1211 int need_frame_base
= 0;
1220 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1221 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1224 printf ("DW_OP_deref");
1227 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1228 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1231 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1232 printf ("DW_OP_const1s: %ld", (long) svalue
);
1235 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1236 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1239 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1240 printf ("DW_OP_const2s: %ld", (long) svalue
);
1243 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1244 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1247 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1248 printf ("DW_OP_const4s: %ld", (long) svalue
);
1251 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1252 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1253 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1254 printf ("%lu", (unsigned long) uvalue
);
1257 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1258 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1259 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1260 printf ("%ld", (long) svalue
);
1263 READ_ULEB (uvalue
, data
, end
);
1264 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1267 READ_SLEB (svalue
, data
, end
);
1268 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1271 printf ("DW_OP_dup");
1274 printf ("DW_OP_drop");
1277 printf ("DW_OP_over");
1280 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1281 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1284 printf ("DW_OP_swap");
1287 printf ("DW_OP_rot");
1290 printf ("DW_OP_xderef");
1293 printf ("DW_OP_abs");
1296 printf ("DW_OP_and");
1299 printf ("DW_OP_div");
1302 printf ("DW_OP_minus");
1305 printf ("DW_OP_mod");
1308 printf ("DW_OP_mul");
1311 printf ("DW_OP_neg");
1314 printf ("DW_OP_not");
1317 printf ("DW_OP_or");
1320 printf ("DW_OP_plus");
1322 case DW_OP_plus_uconst
:
1323 READ_ULEB (uvalue
, data
, end
);
1324 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1327 printf ("DW_OP_shl");
1330 printf ("DW_OP_shr");
1333 printf ("DW_OP_shra");
1336 printf ("DW_OP_xor");
1339 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1340 printf ("DW_OP_bra: %ld", (long) svalue
);
1343 printf ("DW_OP_eq");
1346 printf ("DW_OP_ge");
1349 printf ("DW_OP_gt");
1352 printf ("DW_OP_le");
1355 printf ("DW_OP_lt");
1358 printf ("DW_OP_ne");
1361 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1362 printf ("DW_OP_skip: %ld", (long) svalue
);
1397 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1432 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1433 regname (op
- DW_OP_reg0
, 1));
1468 READ_SLEB (svalue
, data
, end
);
1469 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1470 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1474 READ_ULEB (uvalue
, data
, end
);
1475 printf ("DW_OP_regx: %s (%s)",
1476 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1479 need_frame_base
= 1;
1480 READ_SLEB (svalue
, data
, end
);
1481 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1484 READ_ULEB (uvalue
, data
, end
);
1485 READ_SLEB (svalue
, data
, end
);
1486 printf ("DW_OP_bregx: %s (%s) %s",
1487 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1488 dwarf_vmatoa ("d", svalue
));
1491 READ_ULEB (uvalue
, data
, end
);
1492 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1494 case DW_OP_deref_size
:
1495 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1496 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1498 case DW_OP_xderef_size
:
1499 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1500 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1503 printf ("DW_OP_nop");
1506 /* DWARF 3 extensions. */
1507 case DW_OP_push_object_address
:
1508 printf ("DW_OP_push_object_address");
1511 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1512 this ought to be an 8-byte wide computation. */
1513 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1514 printf ("DW_OP_call2: <0x%s>",
1515 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1518 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1519 this ought to be an 8-byte wide computation. */
1520 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1521 printf ("DW_OP_call4: <0x%s>",
1522 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1524 case DW_OP_call_ref
:
1525 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1526 this ought to be an 8-byte wide computation. */
1527 if (dwarf_version
== -1)
1529 printf (_("(DW_OP_call_ref in frame info)"));
1530 /* No way to tell where the next op is, so just bail. */
1531 return need_frame_base
;
1533 if (dwarf_version
== 2)
1535 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1539 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1541 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1543 case DW_OP_form_tls_address
:
1544 printf ("DW_OP_form_tls_address");
1546 case DW_OP_call_frame_cfa
:
1547 printf ("DW_OP_call_frame_cfa");
1549 case DW_OP_bit_piece
:
1550 printf ("DW_OP_bit_piece: ");
1551 READ_ULEB (uvalue
, data
, end
);
1552 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1553 READ_ULEB (uvalue
, data
, end
);
1554 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1557 /* DWARF 4 extensions. */
1558 case DW_OP_stack_value
:
1559 printf ("DW_OP_stack_value");
1562 case DW_OP_implicit_value
:
1563 printf ("DW_OP_implicit_value");
1564 READ_ULEB (uvalue
, data
, end
);
1565 data
= display_block (data
, uvalue
, end
, ' ');
1568 /* GNU extensions. */
1569 case DW_OP_GNU_push_tls_address
:
1570 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1572 case DW_OP_GNU_uninit
:
1573 printf ("DW_OP_GNU_uninit");
1574 /* FIXME: Is there data associated with this OP ? */
1576 case DW_OP_GNU_encoded_addr
:
1583 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1585 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1586 print_dwarf_vma (addr
, pointer_size
);
1589 case DW_OP_implicit_pointer
:
1590 case DW_OP_GNU_implicit_pointer
:
1591 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1592 this ought to be an 8-byte wide computation. */
1593 if (dwarf_version
== -1)
1595 printf (_("(%s in frame info)"),
1596 (op
== DW_OP_implicit_pointer
1597 ? "DW_OP_implicit_pointer"
1598 : "DW_OP_GNU_implicit_pointer"));
1599 /* No way to tell where the next op is, so just bail. */
1600 return need_frame_base
;
1602 if (dwarf_version
== 2)
1604 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1608 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1610 READ_SLEB (svalue
, data
, end
);
1611 printf ("%s: <0x%s> %s",
1612 (op
== DW_OP_implicit_pointer
1613 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1614 dwarf_vmatoa ("x", uvalue
),
1615 dwarf_vmatoa ("d", svalue
));
1617 case DW_OP_entry_value
:
1618 case DW_OP_GNU_entry_value
:
1619 READ_ULEB (uvalue
, data
, end
);
1620 /* PR 17531: file: 0cc9cd00. */
1621 if (uvalue
> (dwarf_vma
) (end
- data
))
1622 uvalue
= end
- data
;
1623 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1624 : "DW_OP_GNU_entry_value"));
1625 if (decode_location_expression (data
, pointer_size
, offset_size
,
1626 dwarf_version
, uvalue
,
1627 cu_offset
, section
))
1628 need_frame_base
= 1;
1634 case DW_OP_const_type
:
1635 case DW_OP_GNU_const_type
:
1636 READ_ULEB (uvalue
, data
, end
);
1637 printf ("%s: <0x%s> ",
1638 (op
== DW_OP_const_type
? "DW_OP_const_type"
1639 : "DW_OP_GNU_const_type"),
1640 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1641 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1642 data
= display_block (data
, uvalue
, end
, ' ');
1644 case DW_OP_regval_type
:
1645 case DW_OP_GNU_regval_type
:
1646 READ_ULEB (uvalue
, data
, end
);
1647 printf ("%s: %s (%s)",
1648 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1649 : "DW_OP_GNU_regval_type"),
1650 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1651 READ_ULEB (uvalue
, data
, end
);
1652 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1654 case DW_OP_deref_type
:
1655 case DW_OP_GNU_deref_type
:
1656 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1658 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1659 : "DW_OP_GNU_deref_type"),
1661 READ_ULEB (uvalue
, data
, end
);
1662 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1665 case DW_OP_GNU_convert
:
1666 READ_ULEB (uvalue
, data
, end
);
1667 printf ("%s <0x%s>",
1668 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1669 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1671 case DW_OP_reinterpret
:
1672 case DW_OP_GNU_reinterpret
:
1673 READ_ULEB (uvalue
, data
, end
);
1674 printf ("%s <0x%s>",
1675 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1676 : "DW_OP_GNU_reinterpret"),
1677 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1679 case DW_OP_GNU_parameter_ref
:
1680 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1681 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1682 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1684 case DW_OP_GNU_addr_index
:
1685 READ_ULEB (uvalue
, data
, end
);
1686 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1688 case DW_OP_GNU_const_index
:
1689 READ_ULEB (uvalue
, data
, end
);
1690 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1692 case DW_OP_GNU_variable_value
:
1693 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1694 this ought to be an 8-byte wide computation. */
1695 if (dwarf_version
== -1)
1697 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1698 /* No way to tell where the next op is, so just bail. */
1699 return need_frame_base
;
1701 if (dwarf_version
== 2)
1703 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1707 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1709 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1712 /* HP extensions. */
1713 case DW_OP_HP_is_value
:
1714 printf ("DW_OP_HP_is_value");
1715 /* FIXME: Is there data associated with this OP ? */
1717 case DW_OP_HP_fltconst4
:
1718 printf ("DW_OP_HP_fltconst4");
1719 /* FIXME: Is there data associated with this OP ? */
1721 case DW_OP_HP_fltconst8
:
1722 printf ("DW_OP_HP_fltconst8");
1723 /* FIXME: Is there data associated with this OP ? */
1725 case DW_OP_HP_mod_range
:
1726 printf ("DW_OP_HP_mod_range");
1727 /* FIXME: Is there data associated with this OP ? */
1729 case DW_OP_HP_unmod_range
:
1730 printf ("DW_OP_HP_unmod_range");
1731 /* FIXME: Is there data associated with this OP ? */
1734 printf ("DW_OP_HP_tls");
1735 /* FIXME: Is there data associated with this OP ? */
1738 /* PGI (STMicroelectronics) extensions. */
1739 case DW_OP_PGI_omp_thread_num
:
1740 /* Pushes the thread number for the current thread as it would be
1741 returned by the standard OpenMP library function:
1742 omp_get_thread_num(). The "current thread" is the thread for
1743 which the expression is being evaluated. */
1744 printf ("DW_OP_PGI_omp_thread_num");
1748 if (op
>= DW_OP_lo_user
1749 && op
<= DW_OP_hi_user
)
1750 printf (_("(User defined location op 0x%x)"), op
);
1752 printf (_("(Unknown location op 0x%x)"), op
);
1753 /* No way to tell where the next op is, so just bail. */
1754 return need_frame_base
;
1757 /* Separate the ops. */
1762 return need_frame_base
;
1765 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1766 This is used for DWARF package files. */
1768 static struct cu_tu_set
*
1769 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1771 struct cu_tu_set
*p
;
1773 unsigned int dw_sect
;
1779 dw_sect
= DW_SECT_TYPES
;
1785 dw_sect
= DW_SECT_INFO
;
1789 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1797 /* Add INC to HIGH_BITS:LOW_BITS. */
1799 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1801 dwarf_vma tmp
= * low_bits
;
1805 /* FIXME: There is probably a better way of handling this:
1807 We need to cope with dwarf_vma being a 32-bit or 64-bit
1808 type. Plus regardless of its size LOW_BITS is meant to
1809 only hold 32-bits, so if there is overflow or wrap around
1810 we must propagate into HIGH_BITS. */
1811 if (tmp
< * low_bits
)
1815 else if (sizeof (tmp
) > 8
1826 fetch_alt_indirect_string (dwarf_vma offset
)
1830 if (! do_follow_links
)
1833 if (first_separate_info
== NULL
)
1834 return _("<no links available>");
1836 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1838 struct dwarf_section
* section
;
1841 if (! load_debug_section (separate_debug_str
, i
->handle
))
1844 section
= &debug_displays
[separate_debug_str
].section
;
1846 if (section
->start
== NULL
)
1849 if (offset
>= section
->size
)
1852 ret
= (const char *) (section
->start
+ offset
);
1853 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1854 NUL byte. Since our caller is expecting to receive a well formed C
1855 string we test for the lack of a terminating byte here. */
1856 if (strnlen ((const char *) ret
, section
->size
- offset
)
1857 == section
->size
- offset
)
1858 return _("<no NUL byte at end of alt .debug_str section>");
1863 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1864 dwarf_vmatoa ("x", offset
));
1865 return _("<offset is too big>");
1869 get_AT_name (unsigned long attribute
)
1874 return "DW_AT value: 0";
1876 /* One value is shared by the MIPS and HP extensions: */
1877 if (attribute
== DW_AT_MIPS_fde
)
1878 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1880 name
= get_DW_AT_name (attribute
);
1884 static char buffer
[100];
1886 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1895 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1897 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1899 dwinfo
->type
= type
;
1900 dwinfo
->value
= value
;
1901 dwinfo
->cu_offset
= cu_offset
;
1902 dwinfo
->next
= first_dwo_info
;
1903 first_dwo_info
= dwinfo
;
1907 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1909 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1913 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1915 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1919 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1921 add_dwo_info (id
, cu_offset
, DWO_ID
);
1925 free_dwo_info (void)
1930 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1932 next
= dwinfo
->next
;
1935 first_dwo_info
= NULL
;
1938 /* Ensure that START + UVALUE is less than END.
1939 Return an adjusted UVALUE if necessary to ensure this relationship. */
1941 static inline dwarf_vma
1942 check_uvalue (const unsigned char * start
,
1944 const unsigned char * end
)
1946 dwarf_vma max_uvalue
= end
- start
;
1948 /* See PR 17512: file: 008-103549-0.001:0.1.
1949 and PR 24829 for examples of where these tests are triggered. */
1950 if (uvalue
> max_uvalue
)
1952 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1953 uvalue
= max_uvalue
;
1959 static unsigned char *
1960 skip_attr_bytes (unsigned long form
,
1961 unsigned char * data
,
1962 unsigned const char * end
,
1963 dwarf_vma pointer_size
,
1964 dwarf_vma offset_size
,
1966 dwarf_vma
* value_return
)
1968 dwarf_signed_vma svalue
;
1969 dwarf_vma uvalue
= 0;
1975 case DW_FORM_ref_addr
:
1976 if (dwarf_version
== 2)
1977 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1978 else if (dwarf_version
> 2)
1979 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1985 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1989 case DW_FORM_line_strp
:
1990 case DW_FORM_sec_offset
:
1991 case DW_FORM_GNU_ref_alt
:
1992 case DW_FORM_GNU_strp_alt
:
1993 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1996 case DW_FORM_flag_present
:
2004 case DW_FORM_addrx1
:
2005 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2009 case DW_FORM_addrx3
:
2010 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2016 case DW_FORM_addrx2
:
2017 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2023 case DW_FORM_addrx4
:
2024 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2028 READ_SLEB (svalue
, data
, end
);
2032 case DW_FORM_ref_udata
:
2034 case DW_FORM_GNU_str_index
:
2036 case DW_FORM_GNU_addr_index
:
2038 READ_ULEB (uvalue
, data
, end
);
2043 dwarf_vma high_bits
;
2045 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2047 if (sizeof (uvalue
) > 4)
2048 uvalue
+= high_bits
<< 32;
2049 else if (high_bits
!= 0)
2051 /* FIXME: What to do ? */
2058 case DW_FORM_ref_sig8
:
2062 case DW_FORM_data16
:
2066 case DW_FORM_string
:
2067 data
+= strnlen ((char *) data
, end
- data
) + 1;
2071 case DW_FORM_exprloc
:
2072 READ_ULEB (uvalue
, data
, end
);
2076 case DW_FORM_block1
:
2077 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
2081 case DW_FORM_block2
:
2082 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2086 case DW_FORM_block4
:
2087 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2091 case DW_FORM_indirect
:
2092 READ_ULEB (form
, data
, end
);
2093 if (form
== DW_FORM_implicit_const
)
2094 SKIP_ULEB (data
, end
);
2095 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
, value_return
);
2101 * value_return
= uvalue
;
2103 data
= (unsigned char *) end
;
2107 /* Given form FORM with value UVALUE, locate and return the abbreviation
2108 associated with it. */
2110 static abbrev_entry
*
2111 get_type_abbrev_from_form (unsigned long form
,
2112 unsigned long uvalue
,
2113 dwarf_vma cu_offset
,
2114 const struct dwarf_section
* section
,
2115 unsigned long * abbrev_num_return
,
2116 unsigned char ** data_return
,
2117 unsigned long * cu_offset_return
)
2119 unsigned long abbrev_number
;
2121 abbrev_entry
* entry
;
2122 unsigned char * data
;
2124 if (abbrev_num_return
!= NULL
)
2125 * abbrev_num_return
= 0;
2126 if (data_return
!= NULL
)
2127 * data_return
= NULL
;
2131 case DW_FORM_GNU_ref_alt
:
2132 case DW_FORM_ref_sig8
:
2133 /* FIXME: We are unable to handle this form at the moment. */
2136 case DW_FORM_ref_addr
:
2137 if (uvalue
>= section
->size
)
2139 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2140 uvalue
, (long) section
->size
, section
->name
);
2145 case DW_FORM_ref_sup4
:
2146 case DW_FORM_ref_sup8
:
2153 case DW_FORM_ref_udata
:
2154 if (uvalue
+ cu_offset
> section
->size
)
2156 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2157 uvalue
, (long) cu_offset
, (long) section
->size
);
2160 uvalue
+= cu_offset
;
2163 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2166 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2170 data
= (unsigned char *) section
->start
+ uvalue
;
2171 map
= find_abbrev_map_by_offset (uvalue
);
2175 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2178 if (map
->list
== NULL
)
2180 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2184 if (cu_offset_return
!= NULL
)
2186 if (form
== DW_FORM_ref_addr
)
2187 * cu_offset_return
= map
->start
;
2189 * cu_offset_return
= cu_offset
;
2192 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2194 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2195 if (entry
->number
== abbrev_number
)
2198 if (abbrev_num_return
!= NULL
)
2199 * abbrev_num_return
= abbrev_number
;
2201 if (data_return
!= NULL
)
2202 * data_return
= data
;
2205 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2210 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2211 can be determined to be a signed type. The data for ENTRY can be
2212 found starting at DATA. */
2215 get_type_signedness (abbrev_entry
*entry
,
2216 const struct dwarf_section
*section
,
2217 unsigned char *data
,
2218 unsigned const char *end
,
2219 dwarf_vma cu_offset
,
2220 dwarf_vma pointer_size
,
2221 dwarf_vma offset_size
,
2224 unsigned int nesting
)
2228 * is_signed
= false;
2230 #define MAX_NESTING 20
2231 if (nesting
> MAX_NESTING
)
2233 /* FIXME: Warn - or is this expected ?
2234 NB/ We need to avoid infinite recursion. */
2238 for (attr
= entry
->first_attr
;
2239 attr
!= NULL
&& attr
->attribute
;
2242 unsigned char * orig_data
= data
;
2243 dwarf_vma uvalue
= 0;
2245 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2246 offset_size
, dwarf_version
, & uvalue
);
2250 switch (attr
->attribute
)
2252 case DW_AT_linkage_name
:
2256 if (attr
->form
== DW_FORM_strp
)
2257 printf (", %s", fetch_indirect_string (uvalue
));
2258 else if (attr
->form
== DW_FORM_string
)
2259 printf (", %s", orig_data
);
2266 abbrev_entry
* type_abbrev
;
2267 unsigned char * type_data
;
2268 unsigned long type_cu_offset
;
2270 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2274 NULL
/* abbrev num return */,
2277 if (type_abbrev
== NULL
)
2280 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2281 pointer_size
, offset_size
, dwarf_version
,
2282 is_signed
, nesting
+ 1);
2286 case DW_AT_encoding
:
2287 /* Determine signness. */
2290 case DW_ATE_address
:
2291 /* FIXME - some architectures have signed addresses. */
2292 case DW_ATE_boolean
:
2293 case DW_ATE_unsigned
:
2294 case DW_ATE_unsigned_char
:
2295 case DW_ATE_unsigned_fixed
:
2296 * is_signed
= false;
2300 case DW_ATE_complex_float
:
2303 case DW_ATE_signed_char
:
2304 case DW_ATE_imaginary_float
:
2305 case DW_ATE_decimal_float
:
2306 case DW_ATE_signed_fixed
:
2316 read_and_print_leb128 (unsigned char *data
,
2317 unsigned int *bytes_read
,
2318 unsigned const char *end
,
2322 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2324 report_leb_status (status
, __FILE__
, __LINE__
);
2326 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2330 display_discr_list (unsigned long form
,
2332 unsigned char * data
,
2333 unsigned const char * end
,
2338 printf ("[default]");
2345 case DW_FORM_block1
:
2346 case DW_FORM_block2
:
2347 case DW_FORM_block4
:
2348 /* Move data pointer back to the start of the byte array. */
2352 printf ("<corrupt>\n");
2353 warn (_("corrupt discr_list - not using a block form\n"));
2359 printf ("<corrupt>\n");
2360 warn (_("corrupt discr_list - block not long enough\n"));
2365 (level
> 0 && level
<= MAX_CU_NESTING
)
2366 ? level_type_signed
[level
- 1] : false;
2371 unsigned char discriminant
;
2372 unsigned int bytes_read
;
2374 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2378 assert (uvalue
> 0);
2379 switch (discriminant
)
2383 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2384 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2385 uvalue
-= bytes_read
;
2391 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2392 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2393 uvalue
-= bytes_read
;
2397 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2398 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2399 uvalue
-= bytes_read
;
2404 printf ("<corrupt>\n");
2405 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2415 printf (")(signed)");
2417 printf (")(unsigned)");
2420 static unsigned char *
2421 read_and_display_attr_value (unsigned long attribute
,
2423 dwarf_signed_vma implicit_const
,
2424 unsigned char * start
,
2425 unsigned char * data
,
2426 unsigned char * end
,
2427 dwarf_vma cu_offset
,
2428 dwarf_vma pointer_size
,
2429 dwarf_vma offset_size
,
2431 debug_info
* debug_info_p
,
2433 struct dwarf_section
* section
,
2434 struct cu_tu_set
* this_set
,
2438 dwarf_signed_vma svalue
;
2439 dwarf_vma uvalue
= 0;
2440 unsigned char * block_start
= NULL
;
2441 unsigned char * orig_data
= data
;
2443 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2445 warn (_("Corrupt attribute\n"));
2449 if (do_wide
&& ! do_loc
)
2451 /* PR 26847: Display the name of the form. */
2452 const char * name
= get_FORM_name (form
);
2454 /* For convenience we skip the DW_FORM_ prefix to the name. */
2456 name
+= 8; /* strlen ("DW_FORM_") */
2457 printf ("%c(%s)", delimiter
, name
);
2465 case DW_FORM_ref_addr
:
2466 if (dwarf_version
== 2)
2467 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2468 else if (dwarf_version
> 2)
2469 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2471 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2475 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2478 case DW_FORM_strp_sup
:
2480 case DW_FORM_line_strp
:
2481 case DW_FORM_sec_offset
:
2482 case DW_FORM_GNU_ref_alt
:
2483 case DW_FORM_GNU_strp_alt
:
2484 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2487 case DW_FORM_flag_present
:
2495 case DW_FORM_addrx1
:
2496 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2502 case DW_FORM_addrx2
:
2503 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2507 case DW_FORM_addrx3
:
2508 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2511 case DW_FORM_ref_sup4
:
2515 case DW_FORM_addrx4
:
2516 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2520 READ_SLEB (svalue
, data
, end
);
2524 case DW_FORM_GNU_str_index
:
2526 case DW_FORM_ref_udata
:
2528 case DW_FORM_GNU_addr_index
:
2530 READ_ULEB (uvalue
, data
, end
);
2533 case DW_FORM_indirect
:
2534 READ_ULEB (form
, data
, end
);
2536 printf ("%c%s", delimiter
, get_FORM_name (form
));
2537 if (form
== DW_FORM_implicit_const
)
2538 READ_SLEB (implicit_const
, data
, end
);
2539 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2541 cu_offset
, pointer_size
,
2542 offset_size
, dwarf_version
,
2543 debug_info_p
, do_loc
,
2544 section
, this_set
, delimiter
, level
);
2549 case DW_FORM_ref_addr
:
2551 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2554 case DW_FORM_GNU_ref_alt
:
2558 /* We have already printed the form name. */
2559 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2561 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2563 /* FIXME: Follow the reference... */
2569 case DW_FORM_ref_sup4
:
2570 case DW_FORM_ref_udata
:
2572 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2577 case DW_FORM_sec_offset
:
2579 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2582 case DW_FORM_flag_present
:
2589 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2592 case DW_FORM_implicit_const
:
2594 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2597 case DW_FORM_ref_sup8
:
2602 dwarf_vma high_bits
;
2606 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2608 if (form
== DW_FORM_ref8
)
2609 add64 (& high_bits
, & utmp
, cu_offset
);
2610 printf ("%c0x%s", delimiter
,
2611 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2614 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2615 && num_debug_info_entries
== 0)
2617 if (sizeof (uvalue
) == 8)
2618 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2620 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2626 case DW_FORM_data16
:
2629 dwarf_vma left_high_bits
, left_low_bits
;
2630 dwarf_vma right_high_bits
, right_low_bits
;
2632 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2633 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2634 if (byte_get
== byte_get_little_endian
)
2637 left_high_bits
^= right_high_bits
;
2638 right_high_bits
^= left_high_bits
;
2639 left_high_bits
^= right_high_bits
;
2640 left_low_bits
^= right_low_bits
;
2641 right_low_bits
^= left_low_bits
;
2642 left_low_bits
^= right_low_bits
;
2644 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2645 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2646 left_high_bits
, left_low_bits
, right_high_bits
,
2652 case DW_FORM_string
:
2654 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2655 data
+= strnlen ((char *) data
, end
- data
) + 1;
2659 case DW_FORM_exprloc
:
2660 READ_ULEB (uvalue
, data
, end
);
2663 if (block_start
>= end
)
2665 warn (_("Block ends prematurely\n"));
2670 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2673 data
= block_start
+ uvalue
;
2675 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2678 case DW_FORM_block1
:
2679 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2682 case DW_FORM_block2
:
2683 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2686 case DW_FORM_block4
:
2687 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2694 /* We have already displayed the form name. */
2695 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2696 dwarf_vmatoa ("x", uvalue
),
2697 fetch_indirect_string (uvalue
));
2699 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2700 dwarf_vmatoa ("x", uvalue
),
2701 fetch_indirect_string (uvalue
));
2705 case DW_FORM_line_strp
:
2709 /* We have already displayed the form name. */
2710 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2711 dwarf_vmatoa ("x", uvalue
),
2712 fetch_indirect_line_string (uvalue
));
2714 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2715 dwarf_vmatoa ("x", uvalue
),
2716 fetch_indirect_line_string (uvalue
));
2720 case DW_FORM_GNU_str_index
:
2728 const char *suffix
= strrchr (section
->name
, '.');
2729 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2732 /* We have already displayed the form name. */
2733 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2734 dwarf_vmatoa ("x", uvalue
),
2735 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2737 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2738 dwarf_vmatoa ("x", uvalue
),
2739 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2743 case DW_FORM_GNU_strp_alt
:
2747 /* We have already displayed the form name. */
2748 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2749 dwarf_vmatoa ("x", uvalue
),
2750 fetch_alt_indirect_string (uvalue
));
2752 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2753 dwarf_vmatoa ("x", uvalue
),
2754 fetch_alt_indirect_string (uvalue
));
2758 case DW_FORM_indirect
:
2759 /* Handled above. */
2762 case DW_FORM_ref_sig8
:
2765 dwarf_vma high_bits
;
2768 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2770 /* We have already displayed the form name. */
2771 printf ("%c: 0x%s", delimiter
,
2772 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2774 printf ("%csignature: 0x%s", delimiter
,
2775 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2780 case DW_FORM_GNU_addr_index
:
2782 case DW_FORM_addrx1
:
2783 case DW_FORM_addrx2
:
2784 case DW_FORM_addrx3
:
2785 case DW_FORM_addrx4
:
2791 if (debug_info_p
== NULL
)
2793 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2796 base
= debug_info_p
->addr_base
;
2798 offset
= base
+ uvalue
* pointer_size
;
2801 /* We have already displayed the form name. */
2802 printf (_("%c(index: 0x%s): %s"), delimiter
,
2803 dwarf_vmatoa ("x", uvalue
),
2804 fetch_indexed_value (offset
, pointer_size
));
2806 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2807 dwarf_vmatoa ("x", uvalue
),
2808 fetch_indexed_value (offset
, pointer_size
));
2812 case DW_FORM_strp_sup
:
2814 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2818 warn (_("Unrecognized form: 0x%lx\n"), form
);
2822 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2823 && num_debug_info_entries
== 0
2824 && debug_info_p
!= NULL
)
2828 case DW_AT_frame_base
:
2829 have_frame_base
= 1;
2831 case DW_AT_location
:
2832 case DW_AT_GNU_locviews
:
2833 case DW_AT_string_length
:
2834 case DW_AT_return_addr
:
2835 case DW_AT_data_member_location
:
2836 case DW_AT_vtable_elem_location
:
2838 case DW_AT_static_link
:
2839 case DW_AT_use_location
:
2840 case DW_AT_call_value
:
2841 case DW_AT_GNU_call_site_value
:
2842 case DW_AT_call_data_value
:
2843 case DW_AT_GNU_call_site_data_value
:
2844 case DW_AT_call_target
:
2845 case DW_AT_GNU_call_site_target
:
2846 case DW_AT_call_target_clobbered
:
2847 case DW_AT_GNU_call_site_target_clobbered
:
2848 if ((dwarf_version
< 4
2849 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2850 || form
== DW_FORM_sec_offset
)
2852 /* Process location list. */
2853 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2854 unsigned int num
= debug_info_p
->num_loc_offsets
;
2856 if (lmax
== 0 || num
>= lmax
)
2859 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2860 xcrealloc (debug_info_p
->loc_offsets
,
2861 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2862 debug_info_p
->loc_views
= (dwarf_vma
*)
2863 xcrealloc (debug_info_p
->loc_views
,
2864 lmax
, sizeof (*debug_info_p
->loc_views
));
2865 debug_info_p
->have_frame_base
= (int *)
2866 xcrealloc (debug_info_p
->have_frame_base
,
2867 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2868 debug_info_p
->max_loc_offsets
= lmax
;
2870 if (this_set
!= NULL
)
2871 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2872 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2873 if (attribute
!= DW_AT_GNU_locviews
)
2875 /* Corrupt DWARF info can produce more offsets than views.
2876 See PR 23062 for an example. */
2877 if (debug_info_p
->num_loc_offsets
2878 > debug_info_p
->num_loc_views
)
2879 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2882 debug_info_p
->loc_offsets
[num
] = uvalue
;
2883 debug_info_p
->num_loc_offsets
++;
2888 assert (debug_info_p
->num_loc_views
<= num
);
2889 num
= debug_info_p
->num_loc_views
;
2890 if (num
> debug_info_p
->num_loc_offsets
)
2891 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2894 debug_info_p
->loc_views
[num
] = uvalue
;
2895 debug_info_p
->num_loc_views
++;
2902 if (need_base_address
)
2903 debug_info_p
->base_address
= uvalue
;
2906 case DW_AT_GNU_addr_base
:
2907 case DW_AT_addr_base
:
2908 debug_info_p
->addr_base
= uvalue
;
2911 case DW_AT_GNU_ranges_base
:
2912 debug_info_p
->ranges_base
= uvalue
;
2916 if ((dwarf_version
< 4
2917 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2918 || form
== DW_FORM_sec_offset
)
2920 /* Process range list. */
2921 unsigned int lmax
= debug_info_p
->max_range_lists
;
2922 unsigned int num
= debug_info_p
->num_range_lists
;
2924 if (lmax
== 0 || num
>= lmax
)
2927 debug_info_p
->range_lists
= (dwarf_vma
*)
2928 xcrealloc (debug_info_p
->range_lists
,
2929 lmax
, sizeof (*debug_info_p
->range_lists
));
2930 debug_info_p
->max_range_lists
= lmax
;
2932 debug_info_p
->range_lists
[num
] = uvalue
;
2933 debug_info_p
->num_range_lists
++;
2937 case DW_AT_GNU_dwo_name
:
2938 case DW_AT_dwo_name
:
2943 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2945 case DW_FORM_GNU_strp_alt
:
2946 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2948 case DW_FORM_GNU_str_index
:
2954 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2956 case DW_FORM_string
:
2957 add_dwo_name ((const char *) orig_data
, cu_offset
);
2960 warn (_("Unsupported form (%s) for attribute %s\n"),
2961 get_FORM_name (form
), get_AT_name (attribute
));
2966 case DW_AT_comp_dir
:
2967 /* FIXME: Also extract a build-id in a CU/TU. */
2972 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2974 case DW_FORM_GNU_strp_alt
:
2975 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2977 case DW_FORM_line_strp
:
2978 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2980 case DW_FORM_GNU_str_index
:
2986 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2988 case DW_FORM_string
:
2989 add_dwo_dir ((const char *) orig_data
, cu_offset
);
2992 warn (_("Unsupported form (%s) for attribute %s\n"),
2993 get_FORM_name (form
), get_AT_name (attribute
));
2998 case DW_AT_GNU_dwo_id
:
3003 /* FIXME: Record the length of the ID as well ? */
3004 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3007 warn (_("Unsupported form (%s) for attribute %s\n"),
3008 get_FORM_name (form
), get_AT_name (attribute
));
3018 if (do_loc
|| attribute
== 0)
3021 /* For some attributes we can display further information. */
3025 if (level
>= 0 && level
< MAX_CU_NESTING
3026 && uvalue
< (size_t) (end
- start
))
3028 bool is_signed
= false;
3029 abbrev_entry
*type_abbrev
;
3030 unsigned char *type_data
;
3031 unsigned long type_cu_offset
;
3033 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3034 section
, NULL
, & type_data
, & type_cu_offset
);
3035 if (type_abbrev
!= NULL
)
3037 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
3038 pointer_size
, offset_size
, dwarf_version
,
3041 level_type_signed
[level
] = is_signed
;
3049 case DW_INL_not_inlined
:
3050 printf (_("(not inlined)"));
3052 case DW_INL_inlined
:
3053 printf (_("(inlined)"));
3055 case DW_INL_declared_not_inlined
:
3056 printf (_("(declared as inline but ignored)"));
3058 case DW_INL_declared_inlined
:
3059 printf (_("(declared as inline and inlined)"));
3062 printf (_(" (Unknown inline attribute value: %s)"),
3063 dwarf_vmatoa ("x", uvalue
));
3068 case DW_AT_language
:
3072 /* Ordered by the numeric value of these constants. */
3073 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3074 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3075 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3076 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3077 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3078 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3079 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3080 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3081 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3082 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3083 /* DWARF 2.1 values. */
3084 case DW_LANG_Java
: printf ("(Java)"); break;
3085 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3086 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3087 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3088 /* DWARF 3 values. */
3089 case DW_LANG_PLI
: printf ("(PLI)"); break;
3090 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3091 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3092 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3093 case DW_LANG_D
: printf ("(D)"); break;
3094 /* DWARF 4 values. */
3095 case DW_LANG_Python
: printf ("(Python)"); break;
3096 /* DWARF 5 values. */
3097 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3098 case DW_LANG_Go
: printf ("(Go)"); break;
3099 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3100 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3101 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3102 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3103 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3104 case DW_LANG_Rust
: printf ("(Rust)"); break;
3105 case DW_LANG_C11
: printf ("(C11)"); break;
3106 case DW_LANG_Swift
: printf ("(Swift)"); break;
3107 case DW_LANG_Julia
: printf ("(Julia)"); break;
3108 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3109 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3110 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3111 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3112 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3113 /* MIPS extension. */
3114 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3115 /* UPC extension. */
3116 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3118 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3119 printf (_("(implementation defined: %s)"),
3120 dwarf_vmatoa ("x", uvalue
));
3122 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3127 case DW_AT_encoding
:
3131 case DW_ATE_void
: printf ("(void)"); break;
3132 case DW_ATE_address
: printf ("(machine address)"); break;
3133 case DW_ATE_boolean
: printf ("(boolean)"); break;
3134 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3135 case DW_ATE_float
: printf ("(float)"); break;
3136 case DW_ATE_signed
: printf ("(signed)"); break;
3137 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3138 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3139 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3140 /* DWARF 2.1 values: */
3141 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3142 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3143 /* DWARF 3 values: */
3144 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3145 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3146 case DW_ATE_edited
: printf ("(edited)"); break;
3147 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3148 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3149 /* DWARF 4 values: */
3150 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3151 /* DWARF 5 values: */
3152 case DW_ATE_UCS
: printf ("(UCS)"); break;
3153 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3155 /* HP extensions: */
3156 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3157 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3158 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3159 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3160 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3161 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3162 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3165 if (uvalue
>= DW_ATE_lo_user
3166 && uvalue
<= DW_ATE_hi_user
)
3167 printf (_("(user defined type)"));
3169 printf (_("(unknown type)"));
3174 case DW_AT_accessibility
:
3178 case DW_ACCESS_public
: printf ("(public)"); break;
3179 case DW_ACCESS_protected
: printf ("(protected)"); break;
3180 case DW_ACCESS_private
: printf ("(private)"); break;
3182 printf (_("(unknown accessibility)"));
3187 case DW_AT_visibility
:
3191 case DW_VIS_local
: printf ("(local)"); break;
3192 case DW_VIS_exported
: printf ("(exported)"); break;
3193 case DW_VIS_qualified
: printf ("(qualified)"); break;
3194 default: printf (_("(unknown visibility)")); break;
3198 case DW_AT_endianity
:
3202 case DW_END_default
: printf ("(default)"); break;
3203 case DW_END_big
: printf ("(big)"); break;
3204 case DW_END_little
: printf ("(little)"); break;
3206 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3207 printf (_("(user specified)"));
3209 printf (_("(unknown endianity)"));
3214 case DW_AT_virtuality
:
3218 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3219 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3220 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3221 default: printf (_("(unknown virtuality)")); break;
3225 case DW_AT_identifier_case
:
3229 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3230 case DW_ID_up_case
: printf ("(up_case)"); break;
3231 case DW_ID_down_case
: printf ("(down_case)"); break;
3232 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3233 default: printf (_("(unknown case)")); break;
3237 case DW_AT_calling_convention
:
3241 case DW_CC_normal
: printf ("(normal)"); break;
3242 case DW_CC_program
: printf ("(program)"); break;
3243 case DW_CC_nocall
: printf ("(nocall)"); break;
3244 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3245 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3246 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3247 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3249 if (uvalue
>= DW_CC_lo_user
3250 && uvalue
<= DW_CC_hi_user
)
3251 printf (_("(user defined)"));
3253 printf (_("(unknown convention)"));
3257 case DW_AT_ordering
:
3262 case -1: printf (_("(undefined)")); break;
3263 case 0: printf ("(row major)"); break;
3264 case 1: printf ("(column major)"); break;
3268 case DW_AT_decimal_sign
:
3272 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3273 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3274 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3275 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3276 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3277 default: printf (_("(unrecognised)")); break;
3281 case DW_AT_defaulted
:
3285 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3286 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3287 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3288 default: printf (_("(unrecognised)")); break;
3292 case DW_AT_discr_list
:
3294 display_discr_list (form
, uvalue
, data
, end
, level
);
3297 case DW_AT_frame_base
:
3298 have_frame_base
= 1;
3300 case DW_AT_location
:
3301 case DW_AT_string_length
:
3302 case DW_AT_return_addr
:
3303 case DW_AT_data_member_location
:
3304 case DW_AT_vtable_elem_location
:
3306 case DW_AT_static_link
:
3307 case DW_AT_use_location
:
3308 case DW_AT_call_value
:
3309 case DW_AT_GNU_call_site_value
:
3310 case DW_AT_call_data_value
:
3311 case DW_AT_GNU_call_site_data_value
:
3312 case DW_AT_call_target
:
3313 case DW_AT_GNU_call_site_target
:
3314 case DW_AT_call_target_clobbered
:
3315 case DW_AT_GNU_call_site_target_clobbered
:
3316 if ((dwarf_version
< 4
3317 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3318 || form
== DW_FORM_sec_offset
)
3319 printf (_(" (location list)"));
3321 case DW_AT_allocated
:
3322 case DW_AT_associated
:
3323 case DW_AT_data_location
:
3325 case DW_AT_upper_bound
:
3326 case DW_AT_lower_bound
:
3329 int need_frame_base
;
3332 need_frame_base
= decode_location_expression (block_start
,
3337 cu_offset
, section
);
3339 if (need_frame_base
&& !have_frame_base
)
3340 printf (_(" [without DW_AT_frame_base]"));
3344 case DW_AT_data_bit_offset
:
3345 case DW_AT_byte_size
:
3346 case DW_AT_bit_size
:
3347 case DW_AT_string_length_byte_size
:
3348 case DW_AT_string_length_bit_size
:
3349 case DW_AT_bit_stride
:
3350 if (form
== DW_FORM_exprloc
)
3353 (void) decode_location_expression (block_start
, pointer_size
,
3354 offset_size
, dwarf_version
,
3355 uvalue
, cu_offset
, section
);
3362 unsigned long abbrev_number
;
3363 abbrev_entry
*entry
;
3365 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3366 section
, & abbrev_number
, NULL
, NULL
);
3369 if (form
!= DW_FORM_GNU_ref_alt
)
3370 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3371 dwarf_vmatoa ("x", uvalue
),
3372 (unsigned long) (orig_data
- section
->start
));
3376 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3377 printf (" (%s)", get_TAG_name (entry
->tag
));
3390 static unsigned char *
3391 read_and_display_attr (unsigned long attribute
,
3393 dwarf_signed_vma implicit_const
,
3394 unsigned char * start
,
3395 unsigned char * data
,
3396 unsigned char * end
,
3397 dwarf_vma cu_offset
,
3398 dwarf_vma pointer_size
,
3399 dwarf_vma offset_size
,
3401 debug_info
* debug_info_p
,
3403 struct dwarf_section
* section
,
3404 struct cu_tu_set
* this_set
,
3408 printf (" %-18s:", get_AT_name (attribute
));
3409 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3411 cu_offset
, pointer_size
, offset_size
,
3412 dwarf_version
, debug_info_p
,
3413 do_loc
, section
, this_set
, ' ', level
);
3419 /* Like load_debug_section, but if the ordinary call fails, and we are
3420 following debug links, then attempt to load the requested section
3421 from one of the separate debug info files. */
3424 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3427 if (load_debug_section (sec_enum
, handle
))
3429 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3431 /* See if we can associate a filename with this section. */
3434 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3435 if (i
->handle
== handle
)
3437 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3445 if (do_follow_links
)
3449 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3451 if (load_debug_section (sec_enum
, i
->handle
))
3453 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3455 /* FIXME: We should check to see if any of the remaining debug info
3456 files also contain this section, and, umm, do something about it. */
3466 introduce (struct dwarf_section
* section
, bool raw
)
3470 if (do_follow_links
&& section
->filename
)
3471 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3472 section
->name
, section
->filename
);
3474 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3478 if (do_follow_links
&& section
->filename
)
3479 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3480 section
->name
, section
->filename
);
3482 printf (_("Contents of the %s section:\n\n"), section
->name
);
3486 /* Process the contents of a .debug_info section.
3487 If do_loc is TRUE then we are scanning for location lists and dwo tags
3488 and we do not want to display anything to the user.
3489 If do_types is TRUE, we are processing a .debug_types section instead of
3490 a .debug_info section.
3491 The information displayed is restricted by the values in DWARF_START_DIE
3492 and DWARF_CUTOFF_LEVEL.
3493 Returns TRUE upon success. Otherwise an error or warning message is
3494 printed and FALSE is returned. */
3497 process_debug_info (struct dwarf_section
* section
,
3499 enum dwarf_section_display_enum abbrev_sec
,
3503 unsigned char *start
= section
->start
;
3504 unsigned char *end
= start
+ section
->size
;
3505 unsigned char *section_begin
;
3507 unsigned int num_units
= 0;
3509 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3510 && num_debug_info_entries
== 0
3515 /* First scan the section to get the number of comp units. */
3516 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3519 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3520 will be the length. For a 64-bit DWARF section, it'll be
3521 the escape code 0xffffffff followed by an 8 byte length. */
3522 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3524 if (length
== 0xffffffff)
3526 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3527 section_begin
+= length
+ 12;
3529 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3531 warn (_("Reserved length value (0x%s) found in section %s\n"),
3532 dwarf_vmatoa ("x", length
), section
->name
);
3536 section_begin
+= length
+ 4;
3538 /* Negative values are illegal, they may even cause infinite
3539 looping. This can happen if we can't accurately apply
3540 relocations to an object file, or if the file is corrupt. */
3541 if ((signed long) length
<= 0 || section_begin
< start
)
3543 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3544 dwarf_vmatoa ("x", length
), section
->name
);
3551 error (_("No comp units in %s section ?\n"), section
->name
);
3555 /* Then allocate an array to hold the information. */
3556 debug_information
= (debug_info
*) cmalloc (num_units
,
3557 sizeof (* debug_information
));
3558 if (debug_information
== NULL
)
3560 error (_("Not enough memory for a debug info array of %u entries\n"),
3562 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3566 /* PR 17531: file: 92ca3797.
3567 We cannot rely upon the debug_information array being initialised
3568 before it is used. A corrupt file could easily contain references
3569 to a unit for which information has not been made available. So
3570 we ensure that the array is zeroed here. */
3571 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3573 alloc_num_debug_info_entries
= num_units
;
3578 load_debug_section_with_follow (str
, file
);
3579 load_debug_section_with_follow (line_str
, file
);
3580 load_debug_section_with_follow (str_dwo
, file
);
3581 load_debug_section_with_follow (str_index
, file
);
3582 load_debug_section_with_follow (str_index_dwo
, file
);
3583 load_debug_section_with_follow (debug_addr
, file
);
3586 load_debug_section_with_follow (abbrev_sec
, file
);
3587 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3589 warn (_("Unable to locate %s section!\n"),
3590 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3594 if (!do_loc
&& dwarf_start_die
== 0)
3595 introduce (section
, false);
3597 free_all_abbrevs ();
3598 free (cu_abbrev_map
);
3599 cu_abbrev_map
= NULL
;
3600 next_free_abbrev_map_entry
= 0;
3602 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3603 to load *all* of the abbrevs for all CUs in this .debug_info
3604 section. This does effectively mean that we (partially) read
3605 every CU header twice. */
3606 for (section_begin
= start
; start
< end
;)
3608 DWARF2_Internal_CompUnit compunit
;
3609 unsigned char * hdrptr
;
3610 dwarf_vma abbrev_base
;
3612 dwarf_vma cu_offset
;
3613 unsigned int offset_size
;
3614 unsigned int initial_length_size
;
3615 struct cu_tu_set
* this_set
;
3620 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3622 if (compunit
.cu_length
== 0xffffffff)
3624 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3626 initial_length_size
= 12;
3631 initial_length_size
= 4;
3634 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3636 cu_offset
= start
- section_begin
;
3638 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3640 if (compunit
.cu_version
< 5)
3642 compunit
.cu_unit_type
= DW_UT_compile
;
3643 /* Initialize it due to a false compiler warning. */
3644 compunit
.cu_pointer_size
= -1;
3648 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3649 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3651 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3654 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3656 if (compunit
.cu_unit_type
== DW_UT_split_compile
3657 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3660 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3663 if (this_set
== NULL
)
3666 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3670 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3671 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3674 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3675 compunit
.cu_abbrev_offset
);
3678 unsigned char * next
;
3680 list
= new_abbrev_list (abbrev_base
,
3681 compunit
.cu_abbrev_offset
);
3682 next
= process_abbrev_set
3683 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3684 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3685 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3686 + abbrev_base
+ abbrev_size
),
3688 list
->start_of_next_abbrevs
= next
;
3691 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3692 + initial_length_size
;
3693 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3696 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3698 DWARF2_Internal_CompUnit compunit
;
3699 unsigned char *hdrptr
;
3700 unsigned char *tags
;
3701 int level
, last_level
, saved_level
;
3702 dwarf_vma cu_offset
;
3703 unsigned long sec_off
;
3704 unsigned int offset_size
;
3705 unsigned int initial_length_size
;
3706 dwarf_vma signature_high
= 0;
3707 dwarf_vma signature_low
= 0;
3708 dwarf_vma type_offset
= 0;
3709 struct cu_tu_set
*this_set
;
3710 dwarf_vma abbrev_base
;
3712 abbrev_list
* list
= NULL
;
3716 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3718 if (compunit
.cu_length
== 0xffffffff)
3720 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3722 initial_length_size
= 12;
3727 initial_length_size
= 4;
3730 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3732 cu_offset
= start
- section_begin
;
3734 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3736 if (compunit
.cu_version
< 5)
3738 compunit
.cu_unit_type
= DW_UT_compile
;
3739 /* Initialize it due to a false compiler warning. */
3740 compunit
.cu_pointer_size
= -1;
3744 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3745 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3747 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3750 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3752 if (this_set
== NULL
)
3755 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3759 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3760 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3763 if (compunit
.cu_version
< 5)
3764 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3766 bool do_dwo_id
= false;
3767 uint64_t dwo_id
= 0;
3768 if (compunit
.cu_unit_type
== DW_UT_split_compile
3769 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3771 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end
);
3775 /* PR 17512: file: 001-108546-0.001:0.1. */
3776 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3778 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3779 compunit
.cu_pointer_size
, offset_size
);
3780 compunit
.cu_pointer_size
= offset_size
;
3785 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3787 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3790 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3791 + initial_length_size
))
3793 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3794 + initial_length_size
;
3798 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3799 && num_debug_info_entries
== 0
3800 && alloc_num_debug_info_entries
> unit
3803 debug_information
[unit
].cu_offset
= cu_offset
;
3804 debug_information
[unit
].pointer_size
3805 = compunit
.cu_pointer_size
;
3806 debug_information
[unit
].offset_size
= offset_size
;
3807 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3808 debug_information
[unit
].base_address
= 0;
3809 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3810 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3811 debug_information
[unit
].loc_offsets
= NULL
;
3812 debug_information
[unit
].have_frame_base
= NULL
;
3813 debug_information
[unit
].max_loc_offsets
= 0;
3814 debug_information
[unit
].num_loc_offsets
= 0;
3815 debug_information
[unit
].range_lists
= NULL
;
3816 debug_information
[unit
].max_range_lists
= 0;
3817 debug_information
[unit
].num_range_lists
= 0;
3820 if (!do_loc
&& dwarf_start_die
== 0)
3822 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3823 dwarf_vmatoa ("x", cu_offset
));
3824 printf (_(" Length: 0x%s (%s)\n"),
3825 dwarf_vmatoa ("x", compunit
.cu_length
),
3826 offset_size
== 8 ? "64-bit" : "32-bit");
3827 printf (_(" Version: %d\n"), compunit
.cu_version
);
3828 if (compunit
.cu_version
>= 5)
3829 printf (_(" Unit Type: %s (%x)\n"),
3830 get_DW_UT_name (compunit
.cu_unit_type
) ?: "???",
3831 compunit
.cu_unit_type
);
3832 printf (_(" Abbrev Offset: 0x%s\n"),
3833 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3834 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3839 printf (_(" Signature: 0x%s\n"),
3840 dwarf_vmatoa64 (signature_high
, signature_low
,
3841 buf
, sizeof (buf
)));
3842 printf (_(" Type Offset: 0x%s\n"),
3843 dwarf_vmatoa ("x", type_offset
));
3846 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3847 if (this_set
!= NULL
)
3849 dwarf_vma
*offsets
= this_set
->section_offsets
;
3850 size_t *sizes
= this_set
->section_sizes
;
3852 printf (_(" Section contributions:\n"));
3853 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3854 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3855 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3856 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3857 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3858 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3859 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3860 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3861 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3862 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3863 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3864 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3868 sec_off
= cu_offset
+ initial_length_size
;
3869 if (sec_off
+ compunit
.cu_length
< sec_off
3870 || sec_off
+ compunit
.cu_length
> section
->size
)
3872 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3874 (unsigned long) cu_offset
,
3875 dwarf_vmatoa ("x", compunit
.cu_length
));
3881 start
+= compunit
.cu_length
+ initial_length_size
;
3883 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3885 warn (_("CU at offset %s contains corrupt or "
3886 "unsupported version number: %d.\n"),
3887 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3891 if (compunit
.cu_unit_type
!= DW_UT_compile
3892 && compunit
.cu_unit_type
!= DW_UT_partial
3893 && compunit
.cu_unit_type
!= DW_UT_type
3894 && compunit
.cu_unit_type
!= DW_UT_split_compile
3895 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3897 warn (_("CU at offset %s contains corrupt or "
3898 "unsupported unit type: %d.\n"),
3899 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3903 /* Process the abbrevs used by this compilation unit. */
3904 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3905 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3906 (unsigned long) compunit
.cu_abbrev_offset
,
3907 (unsigned long) abbrev_size
);
3908 /* PR 17531: file:4bcd9ce9. */
3909 else if ((abbrev_base
+ abbrev_size
)
3910 > debug_displays
[abbrev_sec
].section
.size
)
3911 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3912 (unsigned long) abbrev_base
+ abbrev_size
,
3913 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3916 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3917 compunit
.cu_abbrev_offset
);
3920 unsigned char * next
;
3922 list
= new_abbrev_list (abbrev_base
,
3923 compunit
.cu_abbrev_offset
);
3924 next
= process_abbrev_set
3925 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3926 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3927 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3928 + abbrev_base
+ abbrev_size
),
3930 list
->start_of_next_abbrevs
= next
;
3937 while (tags
< start
)
3939 unsigned long abbrev_number
;
3940 unsigned long die_offset
;
3941 abbrev_entry
*entry
;
3943 int do_printing
= 1;
3945 die_offset
= tags
- section_begin
;
3947 READ_ULEB (abbrev_number
, tags
, start
);
3949 /* A null DIE marks the end of a list of siblings or it may also be
3950 a section padding. */
3951 if (abbrev_number
== 0)
3953 /* Check if it can be a section padding for the last CU. */
3954 if (level
== 0 && start
== end
)
3958 for (chk
= tags
; chk
< start
; chk
++)
3965 if (!do_loc
&& die_offset
>= dwarf_start_die
3966 && (dwarf_cutoff_level
== -1
3967 || level
< dwarf_cutoff_level
))
3968 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3974 static unsigned num_bogus_warns
= 0;
3976 if (num_bogus_warns
< 3)
3978 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3979 die_offset
, section
->name
);
3981 if (num_bogus_warns
== 3)
3982 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3985 if (dwarf_start_die
!= 0 && level
< saved_level
)
3992 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3996 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3997 saved_level
= level
;
3998 do_printing
= (dwarf_cutoff_level
== -1
3999 || level
< dwarf_cutoff_level
);
4001 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4002 level
, die_offset
, abbrev_number
);
4003 else if (dwarf_cutoff_level
== -1
4004 || last_level
< dwarf_cutoff_level
)
4005 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4010 /* Scan through the abbreviation list until we reach the
4015 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4016 if (entry
->number
== abbrev_number
)
4021 if (!do_loc
&& do_printing
)
4026 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
4027 die_offset
, abbrev_number
);
4031 if (!do_loc
&& do_printing
)
4032 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4037 need_base_address
= 0;
4039 case DW_TAG_compile_unit
:
4040 need_base_address
= 1;
4041 need_dwo_info
= do_loc
;
4043 case DW_TAG_entry_point
:
4044 case DW_TAG_subprogram
:
4045 need_base_address
= 0;
4046 /* Assuming that there is no DW_AT_frame_base. */
4047 have_frame_base
= 0;
4051 debug_info
*debug_info_p
=
4052 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4053 ? debug_information
+ unit
: NULL
;
4055 assert (!debug_info_p
4056 || (debug_info_p
->num_loc_offsets
4057 == debug_info_p
->num_loc_views
));
4059 for (attr
= entry
->first_attr
;
4060 attr
&& attr
->attribute
;
4063 if (! do_loc
&& do_printing
)
4064 /* Show the offset from where the tag was extracted. */
4065 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
4066 tags
= read_and_display_attr (attr
->attribute
,
4068 attr
->implicit_const
,
4073 compunit
.cu_pointer_size
,
4075 compunit
.cu_version
,
4077 do_loc
|| ! do_printing
,
4083 /* If a locview attribute appears before a location one,
4084 make sure we don't associate it with an earlier
4087 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4090 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4091 debug_info_p
->num_loc_views
++;
4092 assert (debug_info_p
->num_loc_views
4093 == debug_info_p
->num_loc_offsets
);
4100 warn(_("DIE has locviews without loclist\n"));
4101 debug_info_p
->num_loc_views
--;
4108 if (entry
->children
)
4113 /* Set num_debug_info_entries here so that it can be used to check if
4114 we need to process .debug_loc and .debug_ranges sections. */
4115 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4116 && num_debug_info_entries
== 0
4119 if (num_units
> alloc_num_debug_info_entries
)
4120 num_debug_info_entries
= alloc_num_debug_info_entries
;
4122 num_debug_info_entries
= num_units
;
4131 /* Locate and scan the .debug_info section in the file and record the pointer
4132 sizes and offsets for the compilation units in it. Usually an executable
4133 will have just one pointer size, but this is not guaranteed, and so we try
4134 not to make any assumptions. Returns zero upon failure, or the number of
4135 compilation units upon success. */
4138 load_debug_info (void * file
)
4140 /* If we have already tried and failed to load the .debug_info
4141 section then do not bother to repeat the task. */
4142 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4145 /* If we already have the information there is nothing else to do. */
4146 if (num_debug_info_entries
> 0)
4147 return num_debug_info_entries
;
4149 /* If this is a DWARF package file, load the CU and TU indexes. */
4150 (void) load_cu_tu_indexes (file
);
4152 if (load_debug_section_with_follow (info
, file
)
4153 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4154 return num_debug_info_entries
;
4156 if (load_debug_section_with_follow (info_dwo
, file
)
4157 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4158 abbrev_dwo
, true, false))
4159 return num_debug_info_entries
;
4161 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4165 /* Read a DWARF .debug_line section header starting at DATA.
4166 Upon success returns an updated DATA pointer and the LINFO
4167 structure and the END_OF_SEQUENCE pointer will be filled in.
4168 Otherwise returns NULL. */
4170 static unsigned char *
4171 read_debug_line_header (struct dwarf_section
* section
,
4172 unsigned char * data
,
4173 unsigned char * end
,
4174 DWARF2_Internal_LineInfo
* linfo
,
4175 unsigned char ** end_of_sequence
)
4177 unsigned char *hdrptr
;
4178 unsigned int initial_length_size
;
4180 /* Extract information from the Line Number Program Header.
4181 (section 6.2.4 in the Dwarf3 doc). */
4184 /* Get and check the length of the block. */
4185 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4187 if (linfo
->li_length
== 0xffffffff)
4189 /* This section is 64-bit DWARF 3. */
4190 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4191 linfo
->li_offset_size
= 8;
4192 initial_length_size
= 12;
4196 linfo
->li_offset_size
= 4;
4197 initial_length_size
= 4;
4200 if (linfo
->li_length
+ initial_length_size
> section
->size
)
4202 /* If the length field has a relocation against it, then we should
4203 not complain if it is inaccurate (and probably negative). This
4204 happens in object files when the .debug_line section is actually
4205 comprised of several different .debug_line.* sections, (some of
4206 which may be removed by linker garbage collection), and a relocation
4207 is used to compute the correct length once that is done. */
4208 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4210 linfo
->li_length
= (end
- data
) - initial_length_size
;
4214 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4215 (long) linfo
->li_length
);
4220 /* Get and check the version number. */
4221 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4223 if (linfo
->li_version
!= 2
4224 && linfo
->li_version
!= 3
4225 && linfo
->li_version
!= 4
4226 && linfo
->li_version
!= 5)
4228 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4229 "is currently supported.\n"));
4233 if (linfo
->li_version
>= 5)
4235 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4237 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4238 if (linfo
->li_segment_size
!= 0)
4240 warn (_("The %s section contains "
4241 "unsupported segment selector size: %d.\n"),
4242 section
->name
, linfo
->li_segment_size
);
4247 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4248 linfo
->li_offset_size
, end
);
4249 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4251 if (linfo
->li_version
>= 4)
4253 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4255 if (linfo
->li_max_ops_per_insn
== 0)
4257 warn (_("Invalid maximum operations per insn.\n"));
4262 linfo
->li_max_ops_per_insn
= 1;
4264 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4265 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4266 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4267 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4269 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
4270 /* PR 17512: file:002-117414-0.004. */
4271 if (* end_of_sequence
> end
)
4273 warn (_("Line length %s extends beyond end of section\n"),
4274 dwarf_vmatoa ("u", linfo
->li_length
));
4275 * end_of_sequence
= end
;
4282 static unsigned char *
4283 display_formatted_table (unsigned char *data
,
4284 unsigned char *start
,
4286 const DWARF2_Internal_LineInfo
*linfo
,
4287 struct dwarf_section
*section
,
4290 unsigned char *format_start
, format_count
, *format
, formati
;
4291 dwarf_vma data_count
, datai
;
4292 unsigned int namepass
, last_entry
= 0;
4293 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4295 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4296 if (do_checks
&& format_count
> 5)
4297 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4298 table_name
, format_count
);
4300 format_start
= data
;
4301 for (formati
= 0; formati
< format_count
; formati
++)
4303 SKIP_ULEB (data
, end
);
4304 SKIP_ULEB (data
, end
);
4307 warn (_("%s: Corrupt format description entry\n"), table_name
);
4312 READ_ULEB (data_count
, data
, end
);
4313 if (data_count
== 0)
4315 printf (_("\n The %s is empty.\n"), table_name
);
4318 else if (data
== end
)
4320 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4321 table_name
, dwarf_vmatoa ("x", data_count
));
4325 else if (format_count
== 0)
4327 warn (_("%s: format count is zero, but the table is not empty\n"),
4332 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4333 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4336 printf (_(" Entry"));
4337 /* Delay displaying name as the last entry for better screen layout. */
4338 for (namepass
= 0; namepass
< 2; namepass
++)
4340 format
= format_start
;
4341 for (formati
= 0; formati
< format_count
; formati
++)
4343 dwarf_vma content_type
;
4345 READ_ULEB (content_type
, format
, end
);
4346 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4347 switch (content_type
)
4350 printf (_("\tName"));
4352 case DW_LNCT_directory_index
:
4353 printf (_("\tDir"));
4355 case DW_LNCT_timestamp
:
4356 printf (_("\tTime"));
4359 printf (_("\tSize"));
4362 printf (_("\tMD5\t\t\t"));
4365 printf (_("\t(Unknown format content type %s)"),
4366 dwarf_vmatoa ("u", content_type
));
4368 SKIP_ULEB (format
, end
);
4373 for (datai
= 0; datai
< data_count
; datai
++)
4375 unsigned char *datapass
= data
;
4377 printf (" %d", last_entry
++);
4378 /* Delay displaying name as the last entry for better screen layout. */
4379 for (namepass
= 0; namepass
< 2; namepass
++)
4381 format
= format_start
;
4383 for (formati
= 0; formati
< format_count
; formati
++)
4385 dwarf_vma content_type
, form
;
4387 READ_ULEB (content_type
, format
, end
);
4388 READ_ULEB (form
, format
, end
);
4389 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4390 0, 0, linfo
->li_offset_size
,
4391 linfo
->li_version
, NULL
,
4392 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4393 section
, NULL
, '\t', -1);
4397 if (data
== end
&& (datai
< data_count
- 1))
4399 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4408 display_debug_sup (struct dwarf_section
* section
,
4409 void * file ATTRIBUTE_UNUSED
)
4411 unsigned char * start
= section
->start
;
4412 unsigned char * end
= section
->start
+ section
->size
;
4413 unsigned int version
;
4414 char is_supplementary
;
4415 const unsigned char * sup_filename
;
4416 size_t sup_filename_len
;
4417 unsigned int num_read
;
4419 dwarf_vma checksum_len
;
4422 introduce (section
, true);
4423 if (section
->size
< 4)
4425 error (_("corrupt .debug_sup section: size is too small\n"));
4429 /* Read the data. */
4430 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4432 warn (_("corrupt .debug_sup section: version < 5"));
4434 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4435 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4436 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4438 sup_filename
= start
;
4439 if (is_supplementary
&& sup_filename
[0] != 0)
4440 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4442 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4443 if (sup_filename_len
== (size_t) (end
- start
))
4445 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4448 start
+= sup_filename_len
+ 1;
4450 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4453 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4457 if (checksum_len
> (dwarf_vma
) (end
- start
))
4459 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4460 checksum_len
= end
- start
;
4462 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4464 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4465 (long) ((end
- start
) - checksum_len
));
4468 printf (_(" Version: %u\n"), version
);
4469 printf (_(" Is Supp: %u\n"), is_supplementary
);
4470 printf (_(" Filename: %s\n"), sup_filename
);
4471 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4472 if (checksum_len
> 0)
4474 printf (_(" Checksum: "));
4475 while (checksum_len
--)
4476 printf ("0x%x ", * start
++ );
4483 display_debug_lines_raw (struct dwarf_section
* section
,
4484 unsigned char * data
,
4485 unsigned char * end
,
4488 unsigned char *start
= section
->start
;
4489 int verbose_view
= 0;
4491 introduce (section
, true);
4495 static DWARF2_Internal_LineInfo saved_linfo
;
4496 DWARF2_Internal_LineInfo linfo
;
4497 unsigned char *standard_opcodes
;
4498 unsigned char *end_of_sequence
;
4501 if (startswith (section
->name
, ".debug_line.")
4502 /* Note: the following does not apply to .debug_line.dwo sections.
4503 These are full debug_line sections. */
4504 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4506 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4507 section containing just the Line Number Statements. They are
4508 created by the assembler and intended to be used alongside gcc's
4509 -ffunction-sections command line option. When the linker's
4510 garbage collection decides to discard a .text.<foo> section it
4511 can then also discard the line number information in .debug_line.<foo>.
4513 Since the section is a fragment it does not have the details
4514 needed to fill out a LineInfo structure, so instead we use the
4515 details from the last full debug_line section that we processed. */
4516 end_of_sequence
= end
;
4517 standard_opcodes
= NULL
;
4518 linfo
= saved_linfo
;
4519 /* PR 17531: file: 0522b371. */
4520 if (linfo
.li_line_range
== 0)
4522 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4525 reset_state_machine (linfo
.li_default_is_stmt
);
4529 unsigned char * hdrptr
;
4531 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4532 & end_of_sequence
)) == NULL
)
4535 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4536 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4537 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4538 if (linfo
.li_version
>= 5)
4540 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4541 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4543 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4544 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4545 if (linfo
.li_version
>= 4)
4546 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4547 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4548 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4549 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4550 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4552 /* PR 17512: file: 1665-6428-0.004. */
4553 if (linfo
.li_line_range
== 0)
4555 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4556 linfo
.li_line_range
= 1;
4559 reset_state_machine (linfo
.li_default_is_stmt
);
4561 /* Display the contents of the Opcodes table. */
4562 standard_opcodes
= hdrptr
;
4564 /* PR 17512: file: 002-417945-0.004. */
4565 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4567 warn (_("Line Base extends beyond end of section\n"));
4571 printf (_("\n Opcodes:\n"));
4573 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4574 printf (ngettext (" Opcode %d has %d arg\n",
4575 " Opcode %d has %d args\n",
4576 standard_opcodes
[i
- 1]),
4577 i
, standard_opcodes
[i
- 1]);
4579 /* Display the contents of the Directory table. */
4580 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4582 if (linfo
.li_version
>= 5)
4584 load_debug_section_with_follow (line_str
, file
);
4586 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4588 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4594 printf (_("\n The Directory Table is empty.\n"));
4597 unsigned int last_dir_entry
= 0;
4599 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4600 (long)(data
- start
));
4602 while (data
< end
&& *data
!= 0)
4604 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4606 data
+= strnlen ((char *) data
, end
- data
) + 1;
4609 /* PR 17512: file: 002-132094-0.004. */
4610 if (data
>= end
- 1)
4614 /* Skip the NUL at the end of the table. */
4617 /* Display the contents of the File Name table. */
4619 printf (_("\n The File Name Table is empty.\n"));
4622 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4623 (long)(data
- start
));
4624 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4626 while (data
< end
&& *data
!= 0)
4628 unsigned char *name
;
4631 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4633 data
+= strnlen ((char *) data
, end
- data
) + 1;
4635 READ_ULEB (val
, data
, end
);
4636 printf ("%s\t", dwarf_vmatoa ("u", val
));
4637 READ_ULEB (val
, data
, end
);
4638 printf ("%s\t", dwarf_vmatoa ("u", val
));
4639 READ_ULEB (val
, data
, end
);
4640 printf ("%s\t", dwarf_vmatoa ("u", val
));
4641 printf ("%.*s\n", (int)(end
- name
), name
);
4645 warn (_("Corrupt file name table entry\n"));
4651 /* Skip the NUL at the end of the table. */
4656 saved_linfo
= linfo
;
4659 /* Now display the statements. */
4660 if (data
>= end_of_sequence
)
4661 printf (_(" No Line Number Statements.\n"));
4664 printf (_(" Line Number Statements:\n"));
4666 while (data
< end_of_sequence
)
4668 unsigned char op_code
;
4669 dwarf_signed_vma adv
;
4672 printf (" [0x%08lx]", (long)(data
- start
));
4676 if (op_code
>= linfo
.li_opcode_base
)
4678 op_code
-= linfo
.li_opcode_base
;
4679 uladv
= (op_code
/ linfo
.li_line_range
);
4680 if (linfo
.li_max_ops_per_insn
== 1)
4682 uladv
*= linfo
.li_min_insn_length
;
4683 state_machine_regs
.address
+= uladv
;
4685 state_machine_regs
.view
= 0;
4686 printf (_(" Special opcode %d: "
4687 "advance Address by %s to 0x%s%s"),
4688 op_code
, dwarf_vmatoa ("u", uladv
),
4689 dwarf_vmatoa ("x", state_machine_regs
.address
),
4690 verbose_view
&& uladv
4691 ? _(" (reset view)") : "");
4696 = ((state_machine_regs
.op_index
+ uladv
)
4697 / linfo
.li_max_ops_per_insn
)
4698 * linfo
.li_min_insn_length
;
4700 state_machine_regs
.address
+= addrdelta
;
4701 state_machine_regs
.op_index
4702 = (state_machine_regs
.op_index
+ uladv
)
4703 % linfo
.li_max_ops_per_insn
;
4705 state_machine_regs
.view
= 0;
4706 printf (_(" Special opcode %d: "
4707 "advance Address by %s to 0x%s[%d]%s"),
4708 op_code
, dwarf_vmatoa ("u", uladv
),
4709 dwarf_vmatoa ("x", state_machine_regs
.address
),
4710 state_machine_regs
.op_index
,
4711 verbose_view
&& addrdelta
4712 ? _(" (reset view)") : "");
4714 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4715 state_machine_regs
.line
+= adv
;
4716 printf (_(" and Line by %s to %d"),
4717 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4718 if (verbose_view
|| state_machine_regs
.view
)
4719 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4722 state_machine_regs
.view
++;
4727 case DW_LNS_extended_op
:
4728 data
+= process_extended_line_op (data
,
4729 linfo
.li_default_is_stmt
,
4734 printf (_(" Copy"));
4735 if (verbose_view
|| state_machine_regs
.view
)
4736 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4739 state_machine_regs
.view
++;
4742 case DW_LNS_advance_pc
:
4743 READ_ULEB (uladv
, data
, end
);
4744 if (linfo
.li_max_ops_per_insn
== 1)
4746 uladv
*= linfo
.li_min_insn_length
;
4747 state_machine_regs
.address
+= uladv
;
4749 state_machine_regs
.view
= 0;
4750 printf (_(" Advance PC by %s to 0x%s%s\n"),
4751 dwarf_vmatoa ("u", uladv
),
4752 dwarf_vmatoa ("x", state_machine_regs
.address
),
4753 verbose_view
&& uladv
4754 ? _(" (reset view)") : "");
4759 = ((state_machine_regs
.op_index
+ uladv
)
4760 / linfo
.li_max_ops_per_insn
)
4761 * linfo
.li_min_insn_length
;
4762 state_machine_regs
.address
4764 state_machine_regs
.op_index
4765 = (state_machine_regs
.op_index
+ uladv
)
4766 % linfo
.li_max_ops_per_insn
;
4768 state_machine_regs
.view
= 0;
4769 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4770 dwarf_vmatoa ("u", uladv
),
4771 dwarf_vmatoa ("x", state_machine_regs
.address
),
4772 state_machine_regs
.op_index
,
4773 verbose_view
&& addrdelta
4774 ? _(" (reset view)") : "");
4778 case DW_LNS_advance_line
:
4779 READ_SLEB (adv
, data
, end
);
4780 state_machine_regs
.line
+= adv
;
4781 printf (_(" Advance Line by %s to %d\n"),
4782 dwarf_vmatoa ("d", adv
),
4783 state_machine_regs
.line
);
4786 case DW_LNS_set_file
:
4787 READ_ULEB (uladv
, data
, end
);
4788 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4789 dwarf_vmatoa ("u", uladv
));
4790 state_machine_regs
.file
= uladv
;
4793 case DW_LNS_set_column
:
4794 READ_ULEB (uladv
, data
, end
);
4795 printf (_(" Set column to %s\n"),
4796 dwarf_vmatoa ("u", uladv
));
4797 state_machine_regs
.column
= uladv
;
4800 case DW_LNS_negate_stmt
:
4801 adv
= state_machine_regs
.is_stmt
;
4803 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4804 state_machine_regs
.is_stmt
= adv
;
4807 case DW_LNS_set_basic_block
:
4808 printf (_(" Set basic block\n"));
4809 state_machine_regs
.basic_block
= 1;
4812 case DW_LNS_const_add_pc
:
4813 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4814 if (linfo
.li_max_ops_per_insn
)
4816 uladv
*= linfo
.li_min_insn_length
;
4817 state_machine_regs
.address
+= uladv
;
4819 state_machine_regs
.view
= 0;
4820 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4821 dwarf_vmatoa ("u", uladv
),
4822 dwarf_vmatoa ("x", state_machine_regs
.address
),
4823 verbose_view
&& uladv
4824 ? _(" (reset view)") : "");
4829 = ((state_machine_regs
.op_index
+ uladv
)
4830 / linfo
.li_max_ops_per_insn
)
4831 * linfo
.li_min_insn_length
;
4832 state_machine_regs
.address
4834 state_machine_regs
.op_index
4835 = (state_machine_regs
.op_index
+ uladv
)
4836 % linfo
.li_max_ops_per_insn
;
4838 state_machine_regs
.view
= 0;
4839 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4840 dwarf_vmatoa ("u", uladv
),
4841 dwarf_vmatoa ("x", state_machine_regs
.address
),
4842 state_machine_regs
.op_index
,
4843 verbose_view
&& addrdelta
4844 ? _(" (reset view)") : "");
4848 case DW_LNS_fixed_advance_pc
:
4849 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4850 state_machine_regs
.address
+= uladv
;
4851 state_machine_regs
.op_index
= 0;
4852 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4853 dwarf_vmatoa ("u", uladv
),
4854 dwarf_vmatoa ("x", state_machine_regs
.address
));
4855 /* Do NOT reset view. */
4858 case DW_LNS_set_prologue_end
:
4859 printf (_(" Set prologue_end to true\n"));
4862 case DW_LNS_set_epilogue_begin
:
4863 printf (_(" Set epilogue_begin to true\n"));
4866 case DW_LNS_set_isa
:
4867 READ_ULEB (uladv
, data
, end
);
4868 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4872 printf (_(" Unknown opcode %d with operands: "), op_code
);
4874 if (standard_opcodes
!= NULL
)
4875 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4877 READ_ULEB (uladv
, data
, end
);
4878 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4879 i
== 1 ? "" : ", ");
4894 unsigned char *name
;
4895 unsigned int directory_index
;
4896 unsigned int modification_date
;
4897 unsigned int length
;
4900 /* Output a decoded representation of the .debug_line section. */
4903 display_debug_lines_decoded (struct dwarf_section
* section
,
4904 unsigned char * start
,
4905 unsigned char * data
,
4906 unsigned char * end
,
4909 static DWARF2_Internal_LineInfo saved_linfo
;
4911 introduce (section
, false);
4915 /* This loop amounts to one iteration per compilation unit. */
4916 DWARF2_Internal_LineInfo linfo
;
4917 unsigned char *standard_opcodes
;
4918 unsigned char *end_of_sequence
;
4920 File_Entry
*file_table
= NULL
;
4921 unsigned int n_files
= 0;
4922 unsigned char **directory_table
= NULL
;
4923 dwarf_vma n_directories
= 0;
4925 if (startswith (section
->name
, ".debug_line.")
4926 /* Note: the following does not apply to .debug_line.dwo sections.
4927 These are full debug_line sections. */
4928 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4930 /* See comment in display_debug_lines_raw(). */
4931 end_of_sequence
= end
;
4932 standard_opcodes
= NULL
;
4933 linfo
= saved_linfo
;
4934 /* PR 17531: file: 0522b371. */
4935 if (linfo
.li_line_range
== 0)
4937 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4940 reset_state_machine (linfo
.li_default_is_stmt
);
4944 unsigned char *hdrptr
;
4946 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4947 & end_of_sequence
)) == NULL
)
4950 /* PR 17531: file: 0522b371. */
4951 if (linfo
.li_line_range
== 0)
4953 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4954 linfo
.li_line_range
= 1;
4956 reset_state_machine (linfo
.li_default_is_stmt
);
4958 /* Save a pointer to the contents of the Opcodes table. */
4959 standard_opcodes
= hdrptr
;
4961 /* Traverse the Directory table just to count entries. */
4962 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4966 warn (_("opcode base of %d extends beyond end of section\n"),
4967 linfo
.li_opcode_base
);
4971 if (linfo
.li_version
>= 5)
4973 unsigned char *format_start
, format_count
, *format
;
4974 dwarf_vma formati
, entryi
;
4976 load_debug_section_with_follow (line_str
, fileptr
);
4978 /* Skip directories format. */
4979 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4980 if (do_checks
&& format_count
> 1)
4981 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4983 format_start
= data
;
4984 for (formati
= 0; formati
< format_count
; formati
++)
4986 SKIP_ULEB (data
, end
);
4987 SKIP_ULEB (data
, end
);
4990 READ_ULEB (n_directories
, data
, end
);
4993 warn (_("Corrupt directories list\n"));
4997 if (n_directories
== 0)
4998 directory_table
= NULL
;
5000 directory_table
= (unsigned char **)
5001 xmalloc (n_directories
* sizeof (unsigned char *));
5003 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5005 unsigned char **pathp
= &directory_table
[entryi
];
5007 format
= format_start
;
5008 for (formati
= 0; formati
< format_count
; formati
++)
5010 dwarf_vma content_type
, form
;
5013 READ_ULEB (content_type
, format
, end
);
5014 READ_ULEB (form
, format
, end
);
5017 warn (_("Corrupt directories list\n"));
5020 switch (content_type
)
5025 case DW_FORM_string
:
5028 case DW_FORM_line_strp
:
5029 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5031 /* Remove const by the cast. */
5032 *pathp
= (unsigned char *)
5033 fetch_indirect_line_string (uvalue
);
5038 data
= read_and_display_attr_value (0, form
, 0, start
,
5040 linfo
.li_offset_size
,
5047 warn (_("Corrupt directories list\n"));
5052 /* Skip files format. */
5053 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5054 if (do_checks
&& format_count
> 5)
5055 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5057 format_start
= data
;
5058 for (formati
= 0; formati
< format_count
; formati
++)
5060 SKIP_ULEB (data
, end
);
5061 SKIP_ULEB (data
, end
);
5064 READ_ULEB (n_files
, data
, end
);
5065 if (data
== end
&& n_files
> 0)
5067 warn (_("Corrupt file name list\n"));
5074 file_table
= (File_Entry
*) xcalloc (1, n_files
5075 * sizeof (File_Entry
));
5077 for (entryi
= 0; entryi
< n_files
; entryi
++)
5079 File_Entry
*file
= &file_table
[entryi
];
5081 format
= format_start
;
5082 for (formati
= 0; formati
< format_count
; formati
++)
5084 dwarf_vma content_type
, form
;
5088 READ_ULEB (content_type
, format
, end
);
5089 READ_ULEB (form
, format
, end
);
5092 warn (_("Corrupt file name list\n"));
5095 switch (content_type
)
5100 case DW_FORM_string
:
5103 case DW_FORM_line_strp
:
5104 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5106 /* Remove const by the cast. */
5107 file
->name
= (unsigned char *)
5108 fetch_indirect_line_string (uvalue
);
5112 case DW_LNCT_directory_index
:
5116 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5120 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5125 READ_ULEB (file
->directory_index
, tmp
, end
);
5130 data
= read_and_display_attr_value (0, form
, 0, start
,
5132 linfo
.li_offset_size
,
5139 warn (_("Corrupt file name list\n"));
5148 unsigned char *ptr_directory_table
= data
;
5150 while (data
< end
&& *data
!= 0)
5152 data
+= strnlen ((char *) data
, end
- data
) + 1;
5159 warn (_("directory table ends unexpectedly\n"));
5164 /* Go through the directory table again to save the directories. */
5165 directory_table
= (unsigned char **)
5166 xmalloc (n_directories
* sizeof (unsigned char *));
5169 while (*ptr_directory_table
!= 0)
5171 directory_table
[i
] = ptr_directory_table
;
5172 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
5173 ptr_directory_table
- end
) + 1;
5177 /* Skip the NUL at the end of the table. */
5180 /* Traverse the File Name table just to count the entries. */
5181 if (data
< end
&& *data
!= 0)
5183 unsigned char *ptr_file_name_table
= data
;
5185 while (data
< end
&& *data
!= 0)
5187 /* Skip Name, directory index, last modification
5188 time and length of file. */
5189 data
+= strnlen ((char *) data
, end
- data
) + 1;
5190 SKIP_ULEB (data
, end
);
5191 SKIP_ULEB (data
, end
);
5192 SKIP_ULEB (data
, end
);
5198 warn (_("file table ends unexpectedly\n"));
5203 /* Go through the file table again to save the strings. */
5204 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5207 while (*ptr_file_name_table
!= 0)
5209 file_table
[i
].name
= ptr_file_name_table
;
5210 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
5211 end
- ptr_file_name_table
) + 1;
5213 /* We are not interested in directory, time or size. */
5214 READ_ULEB (file_table
[i
].directory_index
,
5215 ptr_file_name_table
, end
);
5216 READ_ULEB (file_table
[i
].modification_date
,
5217 ptr_file_name_table
, end
);
5218 READ_ULEB (file_table
[i
].length
,
5219 ptr_file_name_table
, end
);
5225 /* Skip the NUL at the end of the table. */
5229 /* Print the Compilation Unit's name and a header. */
5230 if (file_table
== NULL
)
5231 printf (_("CU: No directory table\n"));
5232 else if (directory_table
== NULL
)
5233 printf (_("CU: %s:\n"), file_table
[0].name
);
5236 unsigned int ix
= file_table
[0].directory_index
;
5237 const char *directory
;
5242 else if (n_directories
== 0)
5243 directory
= _("<unknown>");
5244 else if (ix
> n_directories
)
5246 warn (_("directory index %u > number of directories %s\n"),
5247 ix
, dwarf_vmatoa ("u", n_directories
));
5248 directory
= _("<corrupt>");
5251 directory
= (char *) directory_table
[ix
- 1];
5253 if (do_wide
|| strlen (directory
) < 76)
5254 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5256 printf ("%s:\n", file_table
[0].name
);
5260 printf (_("File name Line number Starting address View Stmt\n"));
5262 printf (_("CU: Empty file name table\n"));
5263 saved_linfo
= linfo
;
5266 /* This loop iterates through the Dwarf Line Number Program. */
5267 while (data
< end_of_sequence
)
5269 unsigned char op_code
;
5272 unsigned long int uladv
;
5273 int is_special_opcode
= 0;
5278 if (op_code
>= linfo
.li_opcode_base
)
5280 op_code
-= linfo
.li_opcode_base
;
5281 uladv
= (op_code
/ linfo
.li_line_range
);
5282 if (linfo
.li_max_ops_per_insn
== 1)
5284 uladv
*= linfo
.li_min_insn_length
;
5285 state_machine_regs
.address
+= uladv
;
5287 state_machine_regs
.view
= 0;
5292 = ((state_machine_regs
.op_index
+ uladv
)
5293 / linfo
.li_max_ops_per_insn
)
5294 * linfo
.li_min_insn_length
;
5295 state_machine_regs
.address
5297 state_machine_regs
.op_index
5298 = (state_machine_regs
.op_index
+ uladv
)
5299 % linfo
.li_max_ops_per_insn
;
5301 state_machine_regs
.view
= 0;
5304 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5305 state_machine_regs
.line
+= adv
;
5306 is_special_opcode
= 1;
5307 /* Increment view after printing this row. */
5312 case DW_LNS_extended_op
:
5314 unsigned int ext_op_code_len
;
5315 unsigned char ext_op_code
;
5316 unsigned char *op_code_end
;
5317 unsigned char *op_code_data
= data
;
5319 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5320 op_code_end
= op_code_data
+ ext_op_code_len
;
5321 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5323 warn (_("Badly formed extended line op encountered!\n"));
5326 ext_op_code
= *op_code_data
++;
5330 switch (ext_op_code
)
5332 case DW_LNE_end_sequence
:
5333 /* Reset stuff after printing this row. */
5335 case DW_LNE_set_address
:
5336 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5338 op_code_end
- op_code_data
,
5340 state_machine_regs
.op_index
= 0;
5341 state_machine_regs
.view
= 0;
5343 case DW_LNE_define_file
:
5344 file_table
= (File_Entry
*) xrealloc
5345 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5347 ++state_machine_regs
.last_file_entry
;
5348 /* Source file name. */
5349 file_table
[n_files
].name
= op_code_data
;
5350 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5351 /* Directory index. */
5352 READ_ULEB (file_table
[n_files
].directory_index
,
5353 op_code_data
, op_code_end
);
5354 /* Last modification time. */
5355 READ_ULEB (file_table
[n_files
].modification_date
,
5356 op_code_data
, op_code_end
);
5358 READ_ULEB (file_table
[n_files
].length
,
5359 op_code_data
, op_code_end
);
5363 case DW_LNE_set_discriminator
:
5364 case DW_LNE_HP_set_sequence
:
5365 /* Simply ignored. */
5369 printf (_("UNKNOWN (%u): length %ld\n"),
5370 ext_op_code
, (long int) (op_code_data
- data
));
5377 /* Increment view after printing this row. */
5380 case DW_LNS_advance_pc
:
5381 READ_ULEB (uladv
, data
, end
);
5382 if (linfo
.li_max_ops_per_insn
== 1)
5384 uladv
*= linfo
.li_min_insn_length
;
5385 state_machine_regs
.address
+= uladv
;
5387 state_machine_regs
.view
= 0;
5392 = ((state_machine_regs
.op_index
+ uladv
)
5393 / linfo
.li_max_ops_per_insn
)
5394 * linfo
.li_min_insn_length
;
5395 state_machine_regs
.address
5397 state_machine_regs
.op_index
5398 = (state_machine_regs
.op_index
+ uladv
)
5399 % linfo
.li_max_ops_per_insn
;
5401 state_machine_regs
.view
= 0;
5405 case DW_LNS_advance_line
:
5406 READ_SLEB (adv
, data
, end
);
5407 state_machine_regs
.line
+= adv
;
5410 case DW_LNS_set_file
:
5411 READ_ULEB (uladv
, data
, end
);
5412 state_machine_regs
.file
= uladv
;
5415 unsigned file
= state_machine_regs
.file
- 1;
5418 if (file_table
== NULL
|| n_files
== 0)
5419 printf (_("\n [Use file table entry %d]\n"), file
);
5421 else if (file
>= n_files
)
5423 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
5424 printf (_("\n <over large file table index %u>"), file
);
5426 else if ((dir
= file_table
[file
].directory_index
) == 0)
5427 /* If directory index is 0, that means current directory. */
5428 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5429 else if (directory_table
== NULL
|| n_directories
== 0)
5430 printf (_("\n [Use file %s in directory table entry %d]\n"),
5431 file_table
[file
].name
, dir
);
5433 else if (dir
> n_directories
)
5435 warn (_("directory index %u > number of directories %s\n"),
5436 dir
, dwarf_vmatoa ("u", n_directories
));
5437 printf (_("\n <over large directory table entry %u>\n"), dir
);
5440 printf ("\n%s/%s:\n",
5441 /* The directory index starts counting at 1. */
5442 directory_table
[dir
- 1], file_table
[file
].name
);
5446 case DW_LNS_set_column
:
5447 READ_ULEB (uladv
, data
, end
);
5448 state_machine_regs
.column
= uladv
;
5451 case DW_LNS_negate_stmt
:
5452 adv
= state_machine_regs
.is_stmt
;
5454 state_machine_regs
.is_stmt
= adv
;
5457 case DW_LNS_set_basic_block
:
5458 state_machine_regs
.basic_block
= 1;
5461 case DW_LNS_const_add_pc
:
5462 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5463 if (linfo
.li_max_ops_per_insn
== 1)
5465 uladv
*= linfo
.li_min_insn_length
;
5466 state_machine_regs
.address
+= uladv
;
5468 state_machine_regs
.view
= 0;
5473 = ((state_machine_regs
.op_index
+ uladv
)
5474 / linfo
.li_max_ops_per_insn
)
5475 * linfo
.li_min_insn_length
;
5476 state_machine_regs
.address
5478 state_machine_regs
.op_index
5479 = (state_machine_regs
.op_index
+ uladv
)
5480 % linfo
.li_max_ops_per_insn
;
5482 state_machine_regs
.view
= 0;
5486 case DW_LNS_fixed_advance_pc
:
5487 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5488 state_machine_regs
.address
+= uladv
;
5489 state_machine_regs
.op_index
= 0;
5490 /* Do NOT reset view. */
5493 case DW_LNS_set_prologue_end
:
5496 case DW_LNS_set_epilogue_begin
:
5499 case DW_LNS_set_isa
:
5500 READ_ULEB (uladv
, data
, end
);
5501 printf (_(" Set ISA to %lu\n"), uladv
);
5505 printf (_(" Unknown opcode %d with operands: "), op_code
);
5507 if (standard_opcodes
!= NULL
)
5508 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5512 READ_ULEB (val
, data
, end
);
5513 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5514 i
== 1 ? "" : ", ");
5520 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5521 to the DWARF address/line matrix. */
5522 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5523 || (xop
== DW_LNS_copy
))
5525 const unsigned int MAX_FILENAME_LENGTH
= 35;
5527 char *newFileName
= NULL
;
5528 size_t fileNameLength
;
5532 unsigned indx
= state_machine_regs
.file
- 1;
5534 if (indx
>= n_files
)
5536 warn (_("corrupt file index %u encountered\n"), indx
);
5537 fileName
= _("<corrupt>");
5540 fileName
= (char *) file_table
[indx
].name
;
5543 fileName
= _("<unknown>");
5545 fileNameLength
= strlen (fileName
);
5547 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5549 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5550 /* Truncate file name */
5551 strncpy (newFileName
,
5552 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5553 MAX_FILENAME_LENGTH
+ 1);
5554 /* FIXME: This is to pacify gcc-10 which can warn that the
5555 strncpy above might leave a non-NUL terminated string
5556 in newFileName. It won't, but gcc's analysis doesn't
5557 quite go far enough to discover this. */
5558 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5562 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5563 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5566 /* A row with end_seq set to true has a meaningful address, but
5567 the other information in the same row is not significant.
5568 In such a row, print line as "-", and don't print
5570 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5572 if (linfo
.li_max_ops_per_insn
== 1)
5574 if (xop
== -DW_LNE_end_sequence
)
5575 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5577 state_machine_regs
.address
);
5579 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5580 newFileName
, state_machine_regs
.line
,
5581 state_machine_regs
.address
);
5585 if (xop
== -DW_LNE_end_sequence
)
5586 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5588 state_machine_regs
.address
,
5589 state_machine_regs
.op_index
);
5591 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5592 newFileName
, state_machine_regs
.line
,
5593 state_machine_regs
.address
,
5594 state_machine_regs
.op_index
);
5599 if (linfo
.li_max_ops_per_insn
== 1)
5601 if (xop
== -DW_LNE_end_sequence
)
5602 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5604 state_machine_regs
.address
);
5606 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5607 newFileName
, state_machine_regs
.line
,
5608 state_machine_regs
.address
);
5612 if (xop
== -DW_LNE_end_sequence
)
5613 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5615 state_machine_regs
.address
,
5616 state_machine_regs
.op_index
);
5618 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5619 newFileName
, state_machine_regs
.line
,
5620 state_machine_regs
.address
,
5621 state_machine_regs
.op_index
);
5625 if (xop
!= -DW_LNE_end_sequence
)
5627 if (state_machine_regs
.view
)
5628 printf (" %6u", state_machine_regs
.view
);
5632 if (state_machine_regs
.is_stmt
)
5637 state_machine_regs
.view
++;
5639 if (xop
== -DW_LNE_end_sequence
)
5641 reset_state_machine (linfo
.li_default_is_stmt
);
5656 if (directory_table
)
5658 free (directory_table
);
5659 directory_table
= NULL
;
5670 display_debug_lines (struct dwarf_section
*section
, void *file
)
5672 unsigned char *data
= section
->start
;
5673 unsigned char *end
= data
+ section
->size
;
5675 int retValDecoded
= 1;
5677 if (do_debug_lines
== 0)
5678 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5680 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5681 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5683 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5684 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5686 if (!retValRaw
|| !retValDecoded
)
5693 find_debug_info_for_offset (unsigned long offset
)
5697 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5700 for (i
= 0; i
< num_debug_info_entries
; i
++)
5701 if (debug_information
[i
].cu_offset
== offset
)
5702 return debug_information
+ i
;
5708 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5710 /* See gdb/gdb-index.h. */
5711 static const char * const kinds
[] =
5723 return _ (kinds
[kind
]);
5727 display_debug_pubnames_worker (struct dwarf_section
*section
,
5728 void *file ATTRIBUTE_UNUSED
,
5731 DWARF2_Internal_PubNames names
;
5732 unsigned char *start
= section
->start
;
5733 unsigned char *end
= start
+ section
->size
;
5735 /* It does not matter if this load fails,
5736 we test for that later on. */
5737 load_debug_info (file
);
5739 introduce (section
, false);
5743 unsigned char *data
;
5744 unsigned long sec_off
;
5745 unsigned int offset_size
, initial_length_size
;
5747 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5748 if (names
.pn_length
== 0xffffffff)
5750 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5752 initial_length_size
= 12;
5757 initial_length_size
= 4;
5760 sec_off
= start
- section
->start
;
5761 if (sec_off
+ names
.pn_length
< sec_off
5762 || sec_off
+ names
.pn_length
> section
->size
)
5764 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5766 sec_off
- initial_length_size
,
5767 dwarf_vmatoa ("x", names
.pn_length
));
5772 start
+= names
.pn_length
;
5774 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5775 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5777 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5778 && num_debug_info_entries
> 0
5779 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5780 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5781 (unsigned long) names
.pn_offset
, section
->name
);
5783 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5785 printf (_(" Length: %ld\n"),
5786 (long) names
.pn_length
);
5787 printf (_(" Version: %d\n"),
5789 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5790 (unsigned long) names
.pn_offset
);
5791 printf (_(" Size of area in .debug_info section: %ld\n"),
5792 (long) names
.pn_size
);
5794 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5796 static int warned
= 0;
5800 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5808 printf (_("\n Offset Kind Name\n"));
5810 printf (_("\n Offset\tName\n"));
5814 bfd_size_type maxprint
;
5817 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5822 data
+= offset_size
;
5825 maxprint
= (end
- data
) - 1;
5829 unsigned int kind_data
;
5830 gdb_index_symbol_kind kind
;
5831 const char *kind_name
;
5834 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5837 /* GCC computes the kind as the upper byte in the CU index
5838 word, and then right shifts it by the CU index size.
5839 Left shift KIND to where the gdb-index.h accessor macros
5841 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5842 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5843 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5844 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5845 printf (" %-6lx %s,%-10s %.*s\n",
5846 (unsigned long) offset
, is_static
? _("s") : _("g"),
5847 kind_name
, (int) maxprint
, data
);
5850 printf (" %-6lx\t%.*s\n",
5851 (unsigned long) offset
, (int) maxprint
, data
);
5853 data
+= strnlen ((char *) data
, maxprint
) + 1;
5864 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5866 return display_debug_pubnames_worker (section
, file
, 0);
5870 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5872 return display_debug_pubnames_worker (section
, file
, 1);
5876 display_debug_macinfo (struct dwarf_section
*section
,
5877 void *file ATTRIBUTE_UNUSED
)
5879 unsigned char *start
= section
->start
;
5880 unsigned char *end
= start
+ section
->size
;
5881 unsigned char *curr
= start
;
5882 enum dwarf_macinfo_record_type op
;
5884 introduce (section
, false);
5888 unsigned int lineno
;
5889 const unsigned char *string
;
5891 op
= (enum dwarf_macinfo_record_type
) *curr
;
5896 case DW_MACINFO_start_file
:
5898 unsigned int filenum
;
5900 READ_ULEB (lineno
, curr
, end
);
5901 READ_ULEB (filenum
, curr
, end
);
5902 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5907 case DW_MACINFO_end_file
:
5908 printf (_(" DW_MACINFO_end_file\n"));
5911 case DW_MACINFO_define
:
5912 READ_ULEB (lineno
, curr
, end
);
5914 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5915 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5919 case DW_MACINFO_undef
:
5920 READ_ULEB (lineno
, curr
, end
);
5922 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5923 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5927 case DW_MACINFO_vendor_ext
:
5929 unsigned int constant
;
5931 READ_ULEB (constant
, curr
, end
);
5933 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5934 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5944 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5945 filename and dirname corresponding to file name table entry with index
5946 FILEIDX. Return NULL on failure. */
5948 static unsigned char *
5949 get_line_filename_and_dirname (dwarf_vma line_offset
,
5951 unsigned char **dir_name
)
5953 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5954 unsigned char *hdrptr
, *dirtable
, *file_name
;
5955 unsigned int offset_size
, initial_length_size
;
5956 unsigned int version
, opcode_base
;
5957 dwarf_vma length
, diridx
;
5958 const unsigned char * end
;
5961 if (section
->start
== NULL
5962 || line_offset
>= section
->size
5966 hdrptr
= section
->start
+ line_offset
;
5967 end
= section
->start
+ section
->size
;
5969 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5970 if (length
== 0xffffffff)
5972 /* This section is 64-bit DWARF 3. */
5973 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5975 initial_length_size
= 12;
5980 initial_length_size
= 4;
5982 if (length
+ initial_length_size
< length
5983 || length
+ initial_length_size
> section
->size
)
5986 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5987 if (version
!= 2 && version
!= 3 && version
!= 4)
5989 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5991 hdrptr
++; /* Skip max_ops_per_insn. */
5992 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5994 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5995 if (opcode_base
== 0)
5998 hdrptr
+= opcode_base
- 1;
6003 /* Skip over dirname table. */
6004 while (*hdrptr
!= '\0')
6006 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
6010 hdrptr
++; /* Skip the NUL at the end of the table. */
6012 /* Now skip over preceding filename table entries. */
6013 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6015 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
6016 SKIP_ULEB (hdrptr
, end
);
6017 SKIP_ULEB (hdrptr
, end
);
6018 SKIP_ULEB (hdrptr
, end
);
6020 if (hdrptr
>= end
|| *hdrptr
== '\0')
6024 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
6027 READ_ULEB (diridx
, hdrptr
, end
);
6030 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6031 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
6032 if (dirtable
>= end
|| *dirtable
== '\0')
6034 *dir_name
= dirtable
;
6039 display_debug_macro (struct dwarf_section
*section
,
6042 unsigned char *start
= section
->start
;
6043 unsigned char *end
= start
+ section
->size
;
6044 unsigned char *curr
= start
;
6045 unsigned char *extended_op_buf
[256];
6046 bool is_dwo
= false;
6047 const char *suffix
= strrchr (section
->name
, '.');
6049 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6052 load_debug_section_with_follow (str
, file
);
6053 load_debug_section_with_follow (line
, file
);
6054 load_debug_section_with_follow (str_index
, file
);
6056 introduce (section
, false);
6060 unsigned int lineno
, version
, flags
;
6061 unsigned int offset_size
;
6062 const unsigned char *string
;
6063 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
6064 unsigned char **extended_ops
= NULL
;
6066 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6067 if (version
!= 4 && version
!= 5)
6069 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6070 section
->name
, version
);
6074 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6075 offset_size
= (flags
& 1) ? 8 : 4;
6076 printf (_(" Offset: 0x%lx\n"),
6077 (unsigned long) sec_offset
);
6078 printf (_(" Version: %d\n"), version
);
6079 printf (_(" Offset size: %d\n"), offset_size
);
6082 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6083 printf (_(" Offset into .debug_line: 0x%lx\n"),
6084 (unsigned long) line_offset
);
6088 unsigned int i
, count
, op
;
6091 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6093 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6094 extended_ops
= extended_op_buf
;
6097 printf (_(" Extension opcode arguments:\n"));
6098 for (i
= 0; i
< count
; i
++)
6100 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6101 extended_ops
[op
] = curr
;
6102 READ_ULEB (nargs
, curr
, end
);
6104 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6107 printf (_(" DW_MACRO_%02x arguments: "), op
);
6108 for (n
= 0; n
< nargs
; n
++)
6112 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6113 printf ("%s%s", get_FORM_name (form
),
6114 n
== nargs
- 1 ? "\n" : ", ");
6124 case DW_FORM_block1
:
6125 case DW_FORM_block2
:
6126 case DW_FORM_block4
:
6128 case DW_FORM_string
:
6130 case DW_FORM_sec_offset
:
6133 error (_("Invalid extension opcode form %s\n"),
6134 get_FORM_name (form
));
6150 error (_(".debug_macro section not zero terminated\n"));
6154 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6160 case DW_MACRO_define
:
6161 READ_ULEB (lineno
, curr
, end
);
6163 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6164 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
6168 case DW_MACRO_undef
:
6169 READ_ULEB (lineno
, curr
, end
);
6171 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6172 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
6176 case DW_MACRO_start_file
:
6178 unsigned int filenum
;
6179 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6181 READ_ULEB (lineno
, curr
, end
);
6182 READ_ULEB (filenum
, curr
, end
);
6184 if ((flags
& 2) == 0)
6185 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6188 = get_line_filename_and_dirname (line_offset
, filenum
,
6190 if (file_name
== NULL
)
6191 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6194 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6196 dir_name
!= NULL
? (const char *) dir_name
: "",
6197 dir_name
!= NULL
? "/" : "", file_name
);
6201 case DW_MACRO_end_file
:
6202 printf (_(" DW_MACRO_end_file\n"));
6205 case DW_MACRO_define_strp
:
6206 READ_ULEB (lineno
, curr
, end
);
6207 if (version
== 4 && is_dwo
)
6208 READ_ULEB (offset
, curr
, end
);
6210 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6211 string
= fetch_indirect_string (offset
);
6212 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6216 case DW_MACRO_undef_strp
:
6217 READ_ULEB (lineno
, curr
, end
);
6218 if (version
== 4 && is_dwo
)
6219 READ_ULEB (offset
, curr
, end
);
6221 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6222 string
= fetch_indirect_string (offset
);
6223 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6227 case DW_MACRO_import
:
6228 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6229 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6230 (unsigned long) offset
);
6233 case DW_MACRO_define_sup
:
6234 READ_ULEB (lineno
, curr
, end
);
6235 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6236 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6237 lineno
, (unsigned long) offset
);
6240 case DW_MACRO_undef_sup
:
6241 READ_ULEB (lineno
, curr
, end
);
6242 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6243 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6244 lineno
, (unsigned long) offset
);
6247 case DW_MACRO_import_sup
:
6248 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6249 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6250 (unsigned long) offset
);
6253 case DW_MACRO_define_strx
:
6254 case DW_MACRO_undef_strx
:
6255 READ_ULEB (lineno
, curr
, end
);
6256 READ_ULEB (offset
, curr
, end
);
6257 string
= (const unsigned char *)
6258 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6259 if (op
== DW_MACRO_define_strx
)
6260 printf (" DW_MACRO_define_strx ");
6262 printf (" DW_MACRO_undef_strx ");
6264 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6265 printf (_("lineno : %d macro : %s\n"),
6270 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6272 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6276 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6278 error (_(" Unknown macro opcode %02x seen\n"), op
);
6283 /* Skip over unhandled opcodes. */
6285 unsigned char *desc
= extended_ops
[op
];
6286 READ_ULEB (nargs
, desc
, end
);
6289 printf (_(" DW_MACRO_%02x\n"), op
);
6292 printf (_(" DW_MACRO_%02x -"), op
);
6293 for (n
= 0; n
< nargs
; n
++)
6297 /* DW_FORM_implicit_const is not expected here. */
6298 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6300 = read_and_display_attr_value (0, val
, 0,
6301 start
, curr
, end
, 0, 0, offset_size
,
6302 version
, NULL
, 0, NULL
,
6320 display_debug_abbrev (struct dwarf_section
*section
,
6321 void *file ATTRIBUTE_UNUSED
)
6323 abbrev_entry
*entry
;
6324 unsigned char *start
= section
->start
;
6325 const unsigned char *end
= start
+ section
->size
;
6327 introduce (section
, false);
6334 offset
= start
- section
->start
;
6335 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6338 list
= new_abbrev_list (0, offset
);
6339 start
= process_abbrev_set (start
, end
, list
);
6340 list
->start_of_next_abbrevs
= start
;
6343 start
= list
->start_of_next_abbrevs
;
6345 if (list
->first_abbrev
== NULL
)
6348 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6350 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6354 printf (" %ld %s [%s]\n",
6356 get_TAG_name (entry
->tag
),
6357 entry
->children
? _("has children") : _("no children"));
6359 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6361 printf (" %-18s %s",
6362 get_AT_name (attr
->attribute
),
6363 get_FORM_name (attr
->form
));
6364 if (attr
->form
== DW_FORM_implicit_const
)
6365 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
6377 /* Return true when ADDR is the maximum address, when addresses are
6378 POINTER_SIZE bytes long. */
6381 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6383 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6384 return ((addr
& mask
) == mask
);
6387 /* Display a view pair list starting at *VSTART_PTR and ending at
6388 VLISTEND within SECTION. */
6391 display_view_pair_list (struct dwarf_section
*section
,
6392 unsigned char **vstart_ptr
,
6393 unsigned int debug_info_entry
,
6394 unsigned char *vlistend
)
6396 unsigned char *vstart
= *vstart_ptr
;
6397 unsigned char *section_end
= section
->start
+ section
->size
;
6398 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6400 if (vlistend
< section_end
)
6401 section_end
= vlistend
;
6405 while (vstart
< section_end
)
6407 dwarf_vma off
= vstart
- section
->start
;
6408 dwarf_vma vbegin
, vend
;
6410 READ_ULEB (vbegin
, vstart
, section_end
);
6411 if (vstart
== section_end
)
6414 READ_ULEB (vend
, vstart
, section_end
);
6415 printf (" %8.8lx ", (unsigned long) off
);
6417 print_dwarf_view (vbegin
, pointer_size
, 1);
6418 print_dwarf_view (vend
, pointer_size
, 1);
6419 printf (_("location view pair\n"));
6423 *vstart_ptr
= vstart
;
6426 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6429 display_loc_list (struct dwarf_section
*section
,
6430 unsigned char **start_ptr
,
6431 unsigned int debug_info_entry
,
6433 dwarf_vma base_address
,
6434 unsigned char **vstart_ptr
,
6437 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6438 unsigned char *section_end
= section
->start
+ section
->size
;
6439 unsigned long cu_offset
;
6440 unsigned int pointer_size
;
6441 unsigned int offset_size
;
6446 unsigned short length
;
6447 int need_frame_base
;
6449 if (debug_info_entry
>= num_debug_info_entries
)
6451 warn (_("No debug information available for loc lists of entry: %u\n"),
6456 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6457 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6458 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6459 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6461 if (pointer_size
< 2 || pointer_size
> 8)
6463 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6464 pointer_size
, debug_info_entry
);
6470 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6471 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6473 if (start
+ 2 * pointer_size
> section_end
)
6475 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6476 (unsigned long) offset
);
6480 printf (" %8.8lx ", (unsigned long) off
);
6482 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6483 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6485 if (begin
== 0 && end
== 0)
6487 /* PR 18374: In a object file we can have a location list that
6488 starts with a begin and end of 0 because there are relocations
6489 that need to be applied to the addresses. Actually applying
6490 the relocations now does not help as they will probably resolve
6491 to 0, since the object file has not been fully linked. Real
6492 end of list markers will not have any relocations against them. */
6493 if (! reloc_at (section
, off
)
6494 && ! reloc_at (section
, off
+ pointer_size
))
6496 printf (_("<End of list>\n"));
6501 /* Check base address specifiers. */
6502 if (is_max_address (begin
, pointer_size
)
6503 && !is_max_address (end
, pointer_size
))
6506 print_dwarf_vma (begin
, pointer_size
);
6507 print_dwarf_vma (end
, pointer_size
);
6508 printf (_("(base address)\n"));
6514 off
= offset
+ (vstart
- *start_ptr
);
6516 READ_ULEB (vbegin
, vstart
, section_end
);
6517 print_dwarf_view (vbegin
, pointer_size
, 1);
6519 READ_ULEB (vend
, vstart
, section_end
);
6520 print_dwarf_view (vend
, pointer_size
, 1);
6522 printf (_("views at %8.8lx for:\n %*s "),
6523 (unsigned long) off
, 8, "");
6526 if (start
+ 2 > section_end
)
6528 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6529 (unsigned long) offset
);
6533 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6535 if (start
+ length
> section_end
)
6537 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6538 (unsigned long) offset
);
6542 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6543 print_dwarf_vma (end
+ base_address
, pointer_size
);
6546 need_frame_base
= decode_location_expression (start
,
6551 cu_offset
, section
);
6554 if (need_frame_base
&& !has_frame_base
)
6555 printf (_(" [without DW_AT_frame_base]"));
6557 if (begin
== end
&& vbegin
== vend
)
6558 fputs (_(" (start == end)"), stdout
);
6559 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6560 fputs (_(" (start > end)"), stdout
);
6568 *vstart_ptr
= vstart
;
6571 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6574 display_loclists_list (struct dwarf_section
*section
,
6575 unsigned char **start_ptr
,
6576 unsigned int debug_info_entry
,
6578 dwarf_vma base_address
,
6579 unsigned char **vstart_ptr
,
6582 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6583 unsigned char *section_end
= section
->start
+ section
->size
;
6584 unsigned long cu_offset
;
6585 unsigned int pointer_size
;
6586 unsigned int offset_size
;
6589 /* Initialize it due to a false compiler warning. */
6590 dwarf_vma begin
= -1, vbegin
= -1;
6591 dwarf_vma end
= -1, vend
= -1;
6593 int need_frame_base
;
6595 if (debug_info_entry
>= num_debug_info_entries
)
6597 warn (_("No debug information available for "
6598 "loclists lists of entry: %u\n"),
6603 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6604 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6605 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6606 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6608 if (pointer_size
< 2 || pointer_size
> 8)
6610 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6611 pointer_size
, debug_info_entry
);
6617 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6618 enum dwarf_location_list_entry_type llet
;
6620 if (start
+ 1 > section_end
)
6622 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6623 (unsigned long) offset
);
6627 printf (" %8.8lx ", (unsigned long) off
);
6629 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6631 if (vstart
&& (llet
== DW_LLE_offset_pair
6632 || llet
== DW_LLE_start_end
6633 || llet
== DW_LLE_start_length
))
6635 off
= offset
+ (vstart
- *start_ptr
);
6637 READ_ULEB (vbegin
, vstart
, section_end
);
6638 print_dwarf_view (vbegin
, pointer_size
, 1);
6640 READ_ULEB (vend
, vstart
, section_end
);
6641 print_dwarf_view (vend
, pointer_size
, 1);
6643 printf (_("views at %8.8lx for:\n %*s "),
6644 (unsigned long) off
, 8, "");
6649 case DW_LLE_end_of_list
:
6650 printf (_("<End of list>\n"));
6652 case DW_LLE_offset_pair
:
6653 READ_ULEB (begin
, start
, section_end
);
6654 begin
+= base_address
;
6655 READ_ULEB (end
, start
, section_end
);
6656 end
+= base_address
;
6658 case DW_LLE_start_end
:
6659 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6660 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6662 case DW_LLE_start_length
:
6663 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6664 READ_ULEB (end
, start
, section_end
);
6667 case DW_LLE_base_address
:
6668 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6670 print_dwarf_vma (base_address
, pointer_size
);
6671 printf (_("(base address)\n"));
6673 #ifdef DW_LLE_view_pair
6674 case DW_LLE_view_pair
:
6676 printf (_("View pair entry in loclist with locviews attribute\n"));
6677 READ_ULEB (vbegin
, start
, section_end
);
6678 print_dwarf_view (vbegin
, pointer_size
, 1);
6680 READ_ULEB (vend
, start
, section_end
);
6681 print_dwarf_view (vend
, pointer_size
, 1);
6683 printf (_("views for:\n"));
6687 error (_("Invalid location list entry type %d\n"), llet
);
6690 if (llet
== DW_LLE_end_of_list
)
6692 if (llet
!= DW_LLE_offset_pair
6693 && llet
!= DW_LLE_start_end
6694 && llet
!= DW_LLE_start_length
)
6697 if (start
+ 2 > section_end
)
6699 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6700 (unsigned long) offset
);
6704 READ_ULEB (length
, start
, section_end
);
6706 print_dwarf_vma (begin
, pointer_size
);
6707 print_dwarf_vma (end
, pointer_size
);
6710 need_frame_base
= decode_location_expression (start
,
6715 cu_offset
, section
);
6718 if (need_frame_base
&& !has_frame_base
)
6719 printf (_(" [without DW_AT_frame_base]"));
6721 if (begin
== end
&& vbegin
== vend
)
6722 fputs (_(" (start == end)"), stdout
);
6723 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6724 fputs (_(" (start > end)"), stdout
);
6732 if (vbegin
!= vm1
|| vend
!= vm1
)
6733 printf (_("Trailing view pair not used in a range"));
6736 *vstart_ptr
= vstart
;
6739 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6740 right-adjusted in a field of length LEN, and followed by a space. */
6743 print_addr_index (unsigned int idx
, unsigned int len
)
6745 static char buf
[15];
6746 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6747 printf ("%*s ", len
, buf
);
6750 /* Display a location list from a .dwo section. It uses address indexes rather
6751 than embedded addresses. This code closely follows display_loc_list, but the
6752 two are sufficiently different that combining things is very ugly. */
6755 display_loc_list_dwo (struct dwarf_section
*section
,
6756 unsigned char **start_ptr
,
6757 unsigned int debug_info_entry
,
6759 unsigned char **vstart_ptr
,
6762 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6763 unsigned char *section_end
= section
->start
+ section
->size
;
6764 unsigned long cu_offset
;
6765 unsigned int pointer_size
;
6766 unsigned int offset_size
;
6769 unsigned short length
;
6770 int need_frame_base
;
6773 if (debug_info_entry
>= num_debug_info_entries
)
6775 warn (_("No debug information for loc lists of entry: %u\n"),
6780 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6781 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6782 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6783 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6785 if (pointer_size
< 2 || pointer_size
> 8)
6787 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6788 pointer_size
, debug_info_entry
);
6794 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6796 if (start
>= section_end
)
6798 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6799 (unsigned long) offset
);
6803 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6816 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6818 READ_ULEB (view
, vstart
, section_end
);
6819 print_dwarf_view (view
, 8, 1);
6821 READ_ULEB (view
, vstart
, section_end
);
6822 print_dwarf_view (view
, 8, 1);
6824 printf (_("views at %8.8lx for:\n %*s "),
6825 (unsigned long) off
, 8, "");
6833 case 0: /* A terminating entry. */
6835 *vstart_ptr
= vstart
;
6836 printf (_("<End of list>\n"));
6838 case 1: /* A base-address entry. */
6839 READ_ULEB (idx
, start
, section_end
);
6840 print_addr_index (idx
, 8);
6841 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6842 printf (_("(base address selection entry)\n"));
6844 case 2: /* A start/end entry. */
6845 READ_ULEB (idx
, start
, section_end
);
6846 print_addr_index (idx
, 8);
6847 READ_ULEB (idx
, start
, section_end
);
6848 print_addr_index (idx
, 8);
6850 case 3: /* A start/length entry. */
6851 READ_ULEB (idx
, start
, section_end
);
6852 print_addr_index (idx
, 8);
6853 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6854 printf ("%08x ", idx
);
6856 case 4: /* An offset pair entry. */
6857 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6858 printf ("%08x ", idx
);
6859 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6860 printf ("%08x ", idx
);
6863 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6865 *vstart_ptr
= vstart
;
6869 if (start
+ 2 > section_end
)
6871 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6872 (unsigned long) offset
);
6876 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6877 if (start
+ length
> section_end
)
6879 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6880 (unsigned long) offset
);
6885 need_frame_base
= decode_location_expression (start
,
6890 cu_offset
, section
);
6893 if (need_frame_base
&& !has_frame_base
)
6894 printf (_(" [without DW_AT_frame_base]"));
6902 *vstart_ptr
= vstart
;
6905 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6908 static dwarf_vma
*loc_offsets
, *loc_views
;
6911 loc_offsets_compar (const void *ap
, const void *bp
)
6913 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6914 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6916 int ret
= (a
> b
) - (b
> a
);
6920 a
= loc_views
[*(const unsigned int *) ap
];
6921 b
= loc_views
[*(const unsigned int *) bp
];
6923 ret
= (a
> b
) - (b
> a
);
6929 display_debug_loc (struct dwarf_section
*section
, void *file
)
6931 unsigned char *start
= section
->start
, *vstart
= NULL
;
6932 unsigned long bytes
;
6933 unsigned char *section_begin
= start
;
6934 unsigned int num_loc_list
= 0;
6935 unsigned long last_offset
= 0;
6936 unsigned long last_view
= 0;
6937 unsigned int first
= 0;
6940 int seen_first_offset
= 0;
6941 int locs_sorted
= 1;
6942 unsigned char *next
= start
, *vnext
= vstart
;
6943 unsigned int *array
= NULL
;
6944 const char *suffix
= strrchr (section
->name
, '.');
6945 bool is_dwo
= false;
6946 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6947 dwarf_vma expected_start
= 0;
6949 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6952 bytes
= section
->size
;
6956 printf (_("\nThe %s section is empty.\n"), section
->name
);
6962 unsigned char *hdrptr
= section_begin
;
6963 dwarf_vma ll_length
;
6964 unsigned short ll_version
;
6965 unsigned char *end
= section_begin
+ section
->size
;
6966 unsigned char address_size
, segment_selector_size
;
6967 uint32_t offset_entry_count
;
6969 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6970 if (ll_length
== 0xffffffff)
6971 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6973 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6974 if (ll_version
!= 5)
6976 warn (_("The %s section contains corrupt or "
6977 "unsupported version number: %d.\n"),
6978 section
->name
, ll_version
);
6982 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6984 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6985 if (segment_selector_size
!= 0)
6987 warn (_("The %s section contains "
6988 "unsupported segment selector size: %d.\n"),
6989 section
->name
, segment_selector_size
);
6993 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6994 if (offset_entry_count
!= 0)
6996 warn (_("The %s section contains "
6997 "unsupported offset entry count: %d.\n"),
6998 section
->name
, offset_entry_count
);
7002 expected_start
= hdrptr
- section_begin
;
7005 if (load_debug_info (file
) == 0)
7007 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7012 /* Check the order of location list in .debug_info section. If
7013 offsets of location lists are in the ascending order, we can
7014 use `debug_information' directly. */
7015 for (i
= 0; i
< num_debug_info_entries
; i
++)
7019 num
= debug_information
[i
].num_loc_offsets
;
7020 if (num
> num_loc_list
)
7023 /* Check if we can use `debug_information' directly. */
7024 if (locs_sorted
&& num
!= 0)
7026 if (!seen_first_offset
)
7028 /* This is the first location list. */
7029 last_offset
= debug_information
[i
].loc_offsets
[0];
7030 last_view
= debug_information
[i
].loc_views
[0];
7032 seen_first_offset
= 1;
7038 for (; j
< num
; j
++)
7041 debug_information
[i
].loc_offsets
[j
]
7042 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7043 && last_view
> debug_information
[i
].loc_views
[j
]))
7048 last_offset
= debug_information
[i
].loc_offsets
[j
];
7049 last_view
= debug_information
[i
].loc_views
[j
];
7054 if (!seen_first_offset
)
7055 error (_("No location lists in .debug_info section!\n"));
7057 if (debug_information
[first
].num_loc_offsets
> 0
7058 && debug_information
[first
].loc_offsets
[0] != expected_start
7059 && debug_information
[first
].loc_views
[0] != expected_start
)
7060 warn (_("Location lists in %s section start at 0x%s\n"),
7062 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
7065 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7067 introduce (section
, false);
7069 if (reloc_at (section
, 0))
7070 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7072 printf (_(" Offset Begin End Expression\n"));
7074 seen_first_offset
= 0;
7075 for (i
= first
; i
< num_debug_info_entries
; i
++)
7077 dwarf_vma offset
, voffset
;
7078 dwarf_vma base_address
;
7084 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7086 loc_offsets
= debug_information
[i
].loc_offsets
;
7087 loc_views
= debug_information
[i
].loc_views
;
7088 qsort (array
, debug_information
[i
].num_loc_offsets
,
7089 sizeof (*array
), loc_offsets_compar
);
7092 int adjacent_view_loclists
= 1;
7093 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7095 j
= locs_sorted
? k
: array
[k
];
7097 && (debug_information
[i
].loc_offsets
[locs_sorted
7098 ? k
- 1 : array
[k
- 1]]
7099 == debug_information
[i
].loc_offsets
[j
])
7100 && (debug_information
[i
].loc_views
[locs_sorted
7101 ? k
- 1 : array
[k
- 1]]
7102 == debug_information
[i
].loc_views
[j
]))
7104 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7105 offset
= debug_information
[i
].loc_offsets
[j
];
7106 next
= section_begin
+ offset
;
7107 voffset
= debug_information
[i
].loc_views
[j
];
7109 vnext
= section_begin
+ voffset
;
7112 base_address
= debug_information
[i
].base_address
;
7114 if (vnext
&& vnext
< next
)
7117 display_view_pair_list (section
, &vstart
, i
, next
);
7122 if (!seen_first_offset
|| !adjacent_view_loclists
)
7123 seen_first_offset
= 1;
7127 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
7128 (unsigned long) (start
- section_begin
),
7129 (unsigned long) offset
);
7130 else if (start
> next
)
7131 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
7132 (unsigned long) (start
- section_begin
),
7133 (unsigned long) offset
);
7138 if (offset
>= bytes
)
7140 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
7141 (unsigned long) offset
);
7145 if (vnext
&& voffset
>= bytes
)
7147 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
7148 (unsigned long) voffset
);
7155 display_loc_list_dwo (section
, &start
, i
, offset
,
7156 &vstart
, has_frame_base
);
7158 display_loc_list (section
, &start
, i
, offset
, base_address
,
7159 &vstart
, has_frame_base
);
7164 warn (_("DWO is not yet supported.\n"));
7166 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7167 &vstart
, has_frame_base
);
7170 /* FIXME: this arrangement is quite simplistic. Nothing
7171 requires locview lists to be adjacent to corresponding
7172 loclists, and a single loclist could be augmented by
7173 different locview lists, and vice-versa, unlikely as it
7174 is that it would make sense to do so. Hopefully we'll
7175 have view pair support built into loclists before we ever
7176 need to address all these possibilities. */
7177 if (adjacent_view_loclists
&& vnext
7178 && vnext
!= start
&& vstart
!= next
)
7180 adjacent_view_loclists
= 0;
7181 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7184 if (vnext
&& vnext
== start
)
7185 display_view_pair_list (section
, &start
, i
, vstart
);
7189 if (start
< section
->start
+ section
->size
)
7190 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7191 "There are %ld unused bytes at the end of section %s\n",
7192 (long) (section
->start
+ section
->size
- start
)),
7193 (long) (section
->start
+ section
->size
- start
), section
->name
);
7200 display_debug_str (struct dwarf_section
*section
,
7201 void *file ATTRIBUTE_UNUSED
)
7203 unsigned char *start
= section
->start
;
7204 unsigned long bytes
= section
->size
;
7205 dwarf_vma addr
= section
->address
;
7209 printf (_("\nThe %s section is empty.\n"), section
->name
);
7213 introduce (section
, false);
7221 lbytes
= (bytes
> 16 ? 16 : bytes
);
7223 printf (" 0x%8.8lx ", (unsigned long) addr
);
7225 for (j
= 0; j
< 16; j
++)
7228 printf ("%2.2x", start
[j
]);
7236 for (j
= 0; j
< lbytes
; j
++)
7239 if (k
>= ' ' && k
< 0x80)
7258 display_debug_info (struct dwarf_section
*section
, void *file
)
7260 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7264 display_debug_types (struct dwarf_section
*section
, void *file
)
7266 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7270 display_trace_info (struct dwarf_section
*section
, void *file
)
7272 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7276 display_debug_aranges (struct dwarf_section
*section
,
7277 void *file ATTRIBUTE_UNUSED
)
7279 unsigned char *start
= section
->start
;
7280 unsigned char *end
= start
+ section
->size
;
7282 introduce (section
, false);
7284 /* It does not matter if this load fails,
7285 we test for that later on. */
7286 load_debug_info (file
);
7290 unsigned char *hdrptr
;
7291 DWARF2_Internal_ARange arange
;
7292 unsigned char *addr_ranges
;
7295 unsigned long sec_off
;
7296 unsigned char address_size
;
7298 unsigned int offset_size
;
7299 unsigned int initial_length_size
;
7303 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7304 if (arange
.ar_length
== 0xffffffff)
7306 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7308 initial_length_size
= 12;
7313 initial_length_size
= 4;
7316 sec_off
= hdrptr
- section
->start
;
7317 if (sec_off
+ arange
.ar_length
< sec_off
7318 || sec_off
+ arange
.ar_length
> section
->size
)
7320 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7322 sec_off
- initial_length_size
,
7323 dwarf_vmatoa ("x", arange
.ar_length
));
7327 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
7328 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
7330 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7331 && num_debug_info_entries
> 0
7332 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7333 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7334 (unsigned long) arange
.ar_info_offset
, section
->name
);
7336 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
7337 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
7339 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7341 /* PR 19872: A version number of 0 probably means that there is
7342 padding at the end of the .debug_aranges section. Gold puts
7343 it there when performing an incremental link, for example.
7344 So do not generate a warning in this case. */
7345 if (arange
.ar_version
)
7346 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7350 printf (_(" Length: %ld\n"),
7351 (long) arange
.ar_length
);
7352 printf (_(" Version: %d\n"), arange
.ar_version
);
7353 printf (_(" Offset into .debug_info: 0x%lx\n"),
7354 (unsigned long) arange
.ar_info_offset
);
7355 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7356 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7358 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7360 /* PR 17512: file: 001-108546-0.001:0.1. */
7361 if (address_size
== 0 || address_size
> 8)
7363 error (_("Invalid address size in %s section!\n"),
7368 /* The DWARF spec does not require that the address size be a power
7369 of two, but we do. This will have to change if we ever encounter
7370 an uneven architecture. */
7371 if ((address_size
& (address_size
- 1)) != 0)
7373 warn (_("Pointer size + Segment size is not a power of two.\n"));
7377 if (address_size
> 4)
7378 printf (_("\n Address Length\n"));
7380 printf (_("\n Address Length\n"));
7382 addr_ranges
= hdrptr
;
7384 /* Must pad to an alignment boundary that is twice the address size. */
7385 excess
= (hdrptr
- start
) % (2 * address_size
);
7387 addr_ranges
+= (2 * address_size
) - excess
;
7389 start
+= arange
.ar_length
+ initial_length_size
;
7391 while (addr_ranges
+ 2 * address_size
<= start
)
7393 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
7394 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
7397 print_dwarf_vma (address
, address_size
);
7398 print_dwarf_vma (length
, address_size
);
7408 /* Comparison function for qsort. */
7410 comp_addr_base (const void * v0
, const void * v1
)
7412 debug_info
*info0
= *(debug_info
**) v0
;
7413 debug_info
*info1
= *(debug_info
**) v1
;
7414 return info0
->addr_base
- info1
->addr_base
;
7417 /* Display the debug_addr section. */
7419 display_debug_addr (struct dwarf_section
*section
,
7422 debug_info
**debug_addr_info
;
7423 unsigned char *entry
;
7427 unsigned char * header
;
7429 if (section
->size
== 0)
7431 printf (_("\nThe %s section is empty.\n"), section
->name
);
7435 if (load_debug_info (file
) == 0)
7437 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7442 introduce (section
, false);
7444 /* PR 17531: file: cf38d01b.
7445 We use xcalloc because a corrupt file may not have initialised all of the
7446 fields in the debug_info structure, which means that the sort below might
7447 try to move uninitialised data. */
7448 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7449 sizeof (debug_info
*));
7452 for (i
= 0; i
< num_debug_info_entries
; i
++)
7453 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7455 /* PR 17531: file: cf38d01b. */
7456 if (debug_information
[i
].addr_base
>= section
->size
)
7457 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7458 (unsigned long) debug_information
[i
].addr_base
, i
);
7460 debug_addr_info
[count
++] = debug_information
+ i
;
7463 /* Add a sentinel to make iteration convenient. */
7464 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7465 debug_addr_info
[count
]->addr_base
= section
->size
;
7466 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7468 header
= section
->start
;
7469 for (i
= 0; i
< count
; i
++)
7472 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7474 printf (_(" For compilation unit at offset 0x%s:\n"),
7475 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7477 printf (_("\tIndex\tAddress\n"));
7478 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7479 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7481 size_t header_size
= entry
- header
;
7482 unsigned char * curr_header
= header
;
7485 int segment_selector_size
;
7487 if (header_size
!= 8 && header_size
!= 16)
7489 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7490 section
->name
, (long) header_size
);
7494 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7495 if (length
== 0xffffffff)
7496 SAFE_BYTE_GET (length
, curr_header
, 8, entry
);
7497 end
= curr_header
+ length
;
7499 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7501 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7502 section
->name
, version
);
7504 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7505 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7506 address_size
+= segment_selector_size
;
7509 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7514 dwarf_vma base
= byte_get (entry
, address_size
);
7515 printf (_("\t%d:\t"), idx
);
7516 print_dwarf_vma (base
, address_size
);
7518 entry
+= address_size
;
7524 free (debug_addr_info
);
7528 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7531 display_debug_str_offsets (struct dwarf_section
*section
,
7532 void *file ATTRIBUTE_UNUSED
)
7536 if (section
->size
== 0)
7538 printf (_("\nThe %s section is empty.\n"), section
->name
);
7542 unsigned char *start
= section
->start
;
7543 unsigned char *end
= start
+ section
->size
;
7544 unsigned char *curr
= start
;
7546 const char *suffix
= strrchr (section
->name
, '.');
7547 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7550 load_debug_section_with_follow (str_dwo
, file
);
7552 load_debug_section_with_follow (str
, file
);
7554 introduce (section
, false);
7559 dwarf_vma entry_length
;
7561 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7562 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7563 if (length
== 0xffffffff)
7565 SAFE_BYTE_GET (length
, curr
, 8, end
);
7571 unsigned char *entries_end
;
7574 /* This is probably an old style .debug_str_offset section which
7575 just contains offsets and no header (and the first offset is 0). */
7576 length
= section
->size
;
7577 curr
= section
->start
;
7580 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7581 printf (_(" Index Offset [String]\n"));
7585 entries_end
= curr
+ length
;
7588 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
7590 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7593 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
7595 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7597 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7598 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7599 printf (_(" Index Offset [String]\n"));
7602 for (idx
= 0; curr
< entries_end
; idx
++)
7605 const unsigned char * string
;
7607 if (curr
+ entry_length
> entries_end
)
7608 /* Not enough space to read one entry_length, give up. */
7611 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
7613 string
= (const unsigned char *)
7614 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7616 string
= fetch_indirect_string (offset
);
7618 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7626 /* Each debug_information[x].range_lists[y] gets this representation for
7627 sorting purposes. */
7631 /* The debug_information[x].range_lists[y] value. */
7632 dwarf_vma ranges_offset
;
7634 /* Original debug_information to find parameters of the data. */
7635 debug_info
*debug_info_p
;
7638 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7641 range_entry_compar (const void *ap
, const void *bp
)
7643 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7644 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7645 const dwarf_vma a
= a_re
->ranges_offset
;
7646 const dwarf_vma b
= b_re
->ranges_offset
;
7648 return (a
> b
) - (b
> a
);
7652 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7653 unsigned int pointer_size
, unsigned long offset
,
7654 unsigned long base_address
)
7656 while (start
< finish
)
7661 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7662 if (start
>= finish
)
7664 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7666 printf (" %8.8lx ", offset
);
7668 if (begin
== 0 && end
== 0)
7670 printf (_("<End of list>\n"));
7674 /* Check base address specifiers. */
7675 if (is_max_address (begin
, pointer_size
)
7676 && !is_max_address (end
, pointer_size
))
7679 print_dwarf_vma (begin
, pointer_size
);
7680 print_dwarf_vma (end
, pointer_size
);
7681 printf ("(base address)\n");
7685 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7686 print_dwarf_vma (end
+ base_address
, pointer_size
);
7689 fputs (_("(start == end)"), stdout
);
7690 else if (begin
> end
)
7691 fputs (_("(start > end)"), stdout
);
7698 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7699 unsigned int pointer_size
, unsigned long offset
,
7700 unsigned long base_address
)
7702 unsigned char *next
= start
;
7706 unsigned long off
= offset
+ (start
- next
);
7707 enum dwarf_range_list_entry rlet
;
7708 /* Initialize it due to a false compiler warning. */
7709 dwarf_vma begin
= -1, length
, end
= -1;
7711 if (start
+ 1 > finish
)
7713 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7718 printf (" %8.8lx ", off
);
7720 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7724 case DW_RLE_end_of_list
:
7725 printf (_("<End of list>\n"));
7727 case DW_RLE_base_address
:
7728 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7729 print_dwarf_vma (base_address
, pointer_size
);
7730 printf (_("(base address)\n"));
7732 case DW_RLE_start_length
:
7733 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7734 READ_ULEB (length
, start
, finish
);
7735 end
= begin
+ length
;
7737 case DW_RLE_offset_pair
:
7738 READ_ULEB (begin
, start
, finish
);
7739 READ_ULEB (end
, start
, finish
);
7741 case DW_RLE_start_end
:
7742 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7743 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7746 error (_("Invalid range list entry type %d\n"), rlet
);
7747 rlet
= DW_RLE_end_of_list
;
7750 if (rlet
== DW_RLE_end_of_list
)
7752 if (rlet
== DW_RLE_base_address
)
7755 /* Only a DW_RLE_offset_pair needs the base address added. */
7756 if (rlet
== DW_RLE_offset_pair
)
7758 begin
+= base_address
;
7759 end
+= base_address
;
7762 print_dwarf_vma (begin
, pointer_size
);
7763 print_dwarf_vma (end
, pointer_size
);
7766 fputs (_("(start == end)"), stdout
);
7767 else if (begin
> end
)
7768 fputs (_("(start > end)"), stdout
);
7775 display_debug_ranges (struct dwarf_section
*section
,
7776 void *file ATTRIBUTE_UNUSED
)
7778 unsigned char *start
= section
->start
;
7779 unsigned char *last_start
= start
;
7780 unsigned long bytes
= section
->size
;
7781 unsigned char *section_begin
= start
;
7782 unsigned char *finish
= start
+ bytes
;
7783 unsigned int num_range_list
, i
;
7784 struct range_entry
*range_entries
, *range_entry_fill
;
7785 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7786 /* Initialize it due to a false compiler warning. */
7787 unsigned char address_size
= 0;
7788 dwarf_vma last_offset
= 0;
7792 printf (_("\nThe %s section is empty.\n"), section
->name
);
7798 dwarf_vma initial_length
;
7799 unsigned int initial_length_size
;
7800 unsigned char segment_selector_size
;
7801 unsigned int offset_size
, offset_entry_count
;
7802 unsigned short version
;
7804 /* Get and check the length of the block. */
7805 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7807 if (initial_length
== 0xffffffff)
7809 /* This section is 64-bit DWARF 3. */
7810 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7812 initial_length_size
= 12;
7817 initial_length_size
= 4;
7820 if (initial_length
+ initial_length_size
> section
->size
)
7822 /* If the length field has a relocation against it, then we should
7823 not complain if it is inaccurate (and probably negative).
7824 It is copied from .debug_line handling code. */
7825 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7827 initial_length
= (finish
- start
) - initial_length_size
;
7831 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7832 (long) initial_length
);
7837 /* Get and check the version number. */
7838 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7842 warn (_("Only DWARF version 5 debug_rnglists info "
7843 "is currently supported.\n"));
7847 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7849 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7850 if (segment_selector_size
!= 0)
7852 warn (_("The %s section contains "
7853 "unsupported segment selector size: %d.\n"),
7854 section
->name
, segment_selector_size
);
7858 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7859 if (offset_entry_count
!= 0)
7861 warn (_("The %s section contains "
7862 "unsupported offset entry count: %u.\n"),
7863 section
->name
, offset_entry_count
);
7868 if (load_debug_info (file
) == 0)
7870 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7876 for (i
= 0; i
< num_debug_info_entries
; i
++)
7878 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7879 /* Skip .debug_rnglists reference. */
7881 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7882 /* Skip .debug_range reference. */
7884 num_range_list
+= debug_information
[i
].num_range_lists
;
7887 if (num_range_list
== 0)
7889 /* This can happen when the file was compiled with -gsplit-debug
7890 which removes references to range lists from the primary .o file. */
7891 printf (_("No range lists in .debug_info section.\n"));
7895 range_entries
= (struct range_entry
*)
7896 xmalloc (sizeof (*range_entries
) * num_range_list
);
7897 range_entry_fill
= range_entries
;
7899 for (i
= 0; i
< num_debug_info_entries
; i
++)
7901 debug_info
*debug_info_p
= &debug_information
[i
];
7904 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7905 /* Skip .debug_rnglists reference. */
7907 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7908 /* Skip .debug_range reference. */
7911 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7913 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7914 range_entry_fill
->debug_info_p
= debug_info_p
;
7919 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7920 range_entry_compar
);
7922 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7923 warn (_("Range lists in %s section start at 0x%lx\n"),
7924 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7926 introduce (section
, false);
7928 printf (_(" Offset Begin End\n"));
7930 for (i
= 0; i
< num_range_list
; i
++)
7932 struct range_entry
*range_entry
= &range_entries
[i
];
7933 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7934 unsigned int pointer_size
;
7936 unsigned char *next
;
7937 dwarf_vma base_address
;
7939 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7940 offset
= range_entry
->ranges_offset
;
7941 next
= section_begin
+ offset
;
7942 base_address
= debug_info_p
->base_address
;
7944 /* PR 17512: file: 001-101485-0.001:0.1. */
7945 if (pointer_size
< 2 || pointer_size
> 8)
7947 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7948 pointer_size
, (unsigned long) offset
);
7952 if (next
< section_begin
|| next
>= finish
)
7954 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7955 (unsigned long) offset
, i
);
7959 /* If multiple DWARF entities reference the same range then we will
7960 have multiple entries in the `range_entries' list for the same
7961 offset. Thanks to the sort above these will all be consecutive in
7962 the `range_entries' list, so we can easily ignore duplicates
7964 if (i
> 0 && last_offset
== offset
)
7966 last_offset
= offset
;
7968 if (dwarf_check
!= 0 && i
> 0)
7971 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7972 (unsigned long) (start
- section_begin
),
7973 (unsigned long) (next
- section_begin
), section
->name
);
7974 else if (start
> next
)
7976 if (next
== last_start
)
7978 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7979 (unsigned long) (start
- section_begin
),
7980 (unsigned long) (next
- section_begin
), section
->name
);
7987 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7988 (start
, finish
, pointer_size
, offset
, base_address
);
7992 free (range_entries
);
7997 typedef struct Frame_Chunk
7999 struct Frame_Chunk
*next
;
8000 unsigned char *chunk_start
;
8002 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8003 short int *col_type
;
8006 unsigned int code_factor
;
8010 unsigned int cfa_reg
;
8011 dwarf_vma cfa_offset
;
8013 unsigned char fde_encoding
;
8014 unsigned char cfa_exp
;
8015 unsigned char ptr_size
;
8016 unsigned char segment_size
;
8020 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8021 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8022 static const char *const *dwarf_regnames
;
8023 static unsigned int dwarf_regnames_count
;
8026 /* A marker for a col_type that means this column was never referenced
8027 in the frame info. */
8028 #define DW_CFA_unreferenced (-1)
8030 /* Return 0 if no more space is needed, 1 if more space is needed,
8031 -1 for invalid reg. */
8034 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8036 unsigned int prev
= fc
->ncols
;
8038 if (reg
< (unsigned int) fc
->ncols
)
8041 if (dwarf_regnames_count
> 0
8042 && reg
> dwarf_regnames_count
)
8045 fc
->ncols
= reg
+ 1;
8046 /* PR 17512: file: 10450-2643-0.004.
8047 If reg == -1 then this can happen... */
8051 /* PR 17512: file: 2844a11d. */
8052 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8054 error (_("Unfeasibly large register number: %u\n"), reg
);
8056 /* FIXME: 1024 is an arbitrary limit. Increase it if
8057 we ever encounter a valid binary that exceeds it. */
8061 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
8062 sizeof (short int));
8063 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
8064 /* PR 17512: file:002-10025-0.005. */
8065 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8067 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8073 while (prev
< fc
->ncols
)
8075 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8076 fc
->col_offset
[prev
] = 0;
8082 static const char *const dwarf_regnames_i386
[] =
8084 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8085 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8086 "eip", "eflags", NULL
, /* 8 - 10 */
8087 "st0", "st1", "st2", "st3", /* 11 - 14 */
8088 "st4", "st5", "st6", "st7", /* 15 - 18 */
8089 NULL
, NULL
, /* 19 - 20 */
8090 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8091 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8092 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8093 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8094 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8095 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8096 "tr", "ldtr", /* 48 - 49 */
8097 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8098 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8099 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8100 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8101 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8102 NULL
, NULL
, NULL
, /* 90 - 92 */
8103 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8106 static const char *const dwarf_regnames_iamcu
[] =
8108 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8109 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8110 "eip", "eflags", NULL
, /* 8 - 10 */
8111 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8112 NULL
, NULL
, /* 19 - 20 */
8113 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8114 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8115 NULL
, NULL
, NULL
, /* 37 - 39 */
8116 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8117 "tr", "ldtr", /* 48 - 49 */
8118 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8119 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8120 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8121 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8122 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8123 NULL
, NULL
, NULL
, /* 90 - 92 */
8124 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8128 init_dwarf_regnames_i386 (void)
8130 dwarf_regnames
= dwarf_regnames_i386
;
8131 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8132 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8136 init_dwarf_regnames_iamcu (void)
8138 dwarf_regnames
= dwarf_regnames_iamcu
;
8139 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8140 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8143 static const char *const dwarf_regnames_x86_64
[] =
8145 "rax", "rdx", "rcx", "rbx",
8146 "rsi", "rdi", "rbp", "rsp",
8147 "r8", "r9", "r10", "r11",
8148 "r12", "r13", "r14", "r15",
8150 "xmm0", "xmm1", "xmm2", "xmm3",
8151 "xmm4", "xmm5", "xmm6", "xmm7",
8152 "xmm8", "xmm9", "xmm10", "xmm11",
8153 "xmm12", "xmm13", "xmm14", "xmm15",
8154 "st0", "st1", "st2", "st3",
8155 "st4", "st5", "st6", "st7",
8156 "mm0", "mm1", "mm2", "mm3",
8157 "mm4", "mm5", "mm6", "mm7",
8159 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8160 "fs.base", "gs.base", NULL
, NULL
,
8162 "mxcsr", "fcw", "fsw",
8163 "xmm16", "xmm17", "xmm18", "xmm19",
8164 "xmm20", "xmm21", "xmm22", "xmm23",
8165 "xmm24", "xmm25", "xmm26", "xmm27",
8166 "xmm28", "xmm29", "xmm30", "xmm31",
8167 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8168 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8169 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8170 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8171 NULL
, NULL
, NULL
, /* 115 - 117 */
8172 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8176 init_dwarf_regnames_x86_64 (void)
8178 dwarf_regnames
= dwarf_regnames_x86_64
;
8179 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8180 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8183 static const char *const dwarf_regnames_aarch64
[] =
8185 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8186 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8187 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8188 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8189 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8190 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8191 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8192 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8193 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8194 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8195 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8196 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8197 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8198 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8199 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8200 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8204 init_dwarf_regnames_aarch64 (void)
8206 dwarf_regnames
= dwarf_regnames_aarch64
;
8207 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8208 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8211 static const char *const dwarf_regnames_s390
[] =
8213 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8214 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8215 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8216 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8217 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8218 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8219 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8220 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8221 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8224 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8225 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8229 init_dwarf_regnames_s390 (void)
8231 dwarf_regnames
= dwarf_regnames_s390
;
8232 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8233 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8236 static const char *const dwarf_regnames_riscv
[] =
8238 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8239 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8240 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8241 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8242 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8243 "fs0", "fs1", /* 40 - 41 */
8244 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8245 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8246 "fs10", "fs11", /* 58 - 59 */
8247 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8250 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8251 the large number of CSRs. */
8254 regname_internal_riscv (unsigned int regno
)
8256 const char *name
= NULL
;
8258 /* Lookup in the table first, this covers GPR and FPR. */
8259 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8260 name
= dwarf_regnames_riscv
[regno
];
8261 else if (regno
>= 4096 && regno
<= 8191)
8263 /* This might be a CSR, these live in a sparse number space from 4096
8264 to 8191 These numbers are defined in the RISC-V ELF ABI
8268 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8269 case VALUE + 4096: name = #NAME; break;
8270 #include "opcode/riscv-opc.h"
8275 static char csr_name
[10];
8276 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8287 init_dwarf_regnames_riscv (void)
8289 dwarf_regnames
= NULL
;
8290 dwarf_regnames_count
= 8192;
8291 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8295 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8297 dwarf_regnames_lookup_func
= NULL
;
8302 init_dwarf_regnames_i386 ();
8306 init_dwarf_regnames_iamcu ();
8312 init_dwarf_regnames_x86_64 ();
8316 init_dwarf_regnames_aarch64 ();
8320 init_dwarf_regnames_s390 ();
8324 init_dwarf_regnames_riscv ();
8332 /* Initialize the DWARF register name lookup state based on the
8333 architecture and specific machine type of a BFD. */
8336 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8339 dwarf_regnames_lookup_func
= NULL
;
8346 case bfd_mach_x86_64
:
8347 case bfd_mach_x86_64_intel_syntax
:
8348 case bfd_mach_x64_32
:
8349 case bfd_mach_x64_32_intel_syntax
:
8350 init_dwarf_regnames_x86_64 ();
8354 init_dwarf_regnames_i386 ();
8359 case bfd_arch_iamcu
:
8360 init_dwarf_regnames_iamcu ();
8363 case bfd_arch_aarch64
:
8364 init_dwarf_regnames_aarch64();
8368 init_dwarf_regnames_s390 ();
8371 case bfd_arch_riscv
:
8372 init_dwarf_regnames_riscv ();
8381 regname_internal_by_table_only (unsigned int regno
)
8383 if (dwarf_regnames
!= NULL
8384 && regno
< dwarf_regnames_count
8385 && dwarf_regnames
[regno
] != NULL
)
8386 return dwarf_regnames
[regno
];
8392 regname (unsigned int regno
, int name_only_p
)
8394 static char reg
[64];
8396 const char *name
= NULL
;
8398 if (dwarf_regnames_lookup_func
!= NULL
)
8399 name
= dwarf_regnames_lookup_func (regno
);
8405 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8408 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8413 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8418 if (*max_regs
!= fc
->ncols
)
8419 *max_regs
= fc
->ncols
;
8421 if (*need_col_headers
)
8423 *need_col_headers
= 0;
8425 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8427 for (r
= 0; r
< *max_regs
; r
++)
8428 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8433 printf ("%-5s ", regname (r
, 1));
8439 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8441 strcpy (tmp
, "exp");
8443 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8444 printf ("%-8s ", tmp
);
8446 for (r
= 0; r
< fc
->ncols
; r
++)
8448 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8450 switch (fc
->col_type
[r
])
8452 case DW_CFA_undefined
:
8455 case DW_CFA_same_value
:
8459 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8461 case DW_CFA_val_offset
:
8462 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8464 case DW_CFA_register
:
8465 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8467 case DW_CFA_expression
:
8468 strcpy (tmp
, "exp");
8470 case DW_CFA_val_expression
:
8471 strcpy (tmp
, "vexp");
8474 strcpy (tmp
, "n/a");
8477 printf ("%-5s ", tmp
);
8483 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8485 static unsigned char *
8486 read_cie (unsigned char *start
, unsigned char *end
,
8487 Frame_Chunk
**p_cie
, int *p_version
,
8488 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8492 unsigned char *augmentation_data
= NULL
;
8493 bfd_size_type augmentation_data_len
= 0;
8496 /* PR 17512: file: 001-228113-0.004. */
8500 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8501 memset (fc
, 0, sizeof (Frame_Chunk
));
8503 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8504 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8508 fc
->augmentation
= (char *) start
;
8509 /* PR 17512: file: 001-228113-0.004.
8510 Skip past augmentation name, but avoid running off the end of the data. */
8512 if (* start
++ == '\0')
8516 warn (_("No terminator for augmentation name\n"));
8520 if (strcmp (fc
->augmentation
, "eh") == 0)
8521 start
+= eh_addr_size
;
8525 GET (fc
->ptr_size
, 1);
8526 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8528 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8532 GET (fc
->segment_size
, 1);
8533 /* PR 17512: file: e99d2804. */
8534 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8536 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8540 eh_addr_size
= fc
->ptr_size
;
8544 fc
->ptr_size
= eh_addr_size
;
8545 fc
->segment_size
= 0;
8548 READ_ULEB (fc
->code_factor
, start
, end
);
8549 READ_SLEB (fc
->data_factor
, start
, end
);
8557 READ_ULEB (fc
->ra
, start
, end
);
8560 if (fc
->augmentation
[0] == 'z')
8562 READ_ULEB (augmentation_data_len
, start
, end
);
8563 augmentation_data
= start
;
8564 /* PR 17512: file: 11042-2589-0.004. */
8565 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8567 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8568 dwarf_vmatoa ("x", augmentation_data_len
),
8569 (unsigned long) (end
- start
));
8572 start
+= augmentation_data_len
;
8575 if (augmentation_data_len
)
8579 unsigned char *qend
;
8581 p
= (unsigned char *) fc
->augmentation
+ 1;
8582 q
= augmentation_data
;
8583 qend
= q
+ augmentation_data_len
;
8585 while (p
< end
&& q
< qend
)
8590 q
+= 1 + size_of_encoded_value (*q
);
8592 fc
->fde_encoding
= *q
++;
8601 /* Note - it is OK if this loop terminates with q < qend.
8602 Padding may have been inserted to align the end of the CIE. */
8607 *p_version
= version
;
8610 *p_aug_len
= augmentation_data_len
;
8611 *p_aug
= augmentation_data
;
8616 free (fc
->col_offset
);
8617 free (fc
->col_type
);
8622 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8623 If do_wide is not enabled, then formats the output to fit into 80 columns.
8624 PRINTED contains the number of characters already written to the current
8628 display_data (bfd_size_type printed
,
8629 const unsigned char * data
,
8630 const bfd_size_type len
)
8632 if (do_wide
|| len
< ((80 - printed
) / 3))
8633 for (printed
= 0; printed
< len
; ++printed
)
8634 printf (" %02x", data
[printed
]);
8637 for (printed
= 0; printed
< len
; ++printed
)
8639 if (printed
% (80 / 3) == 0)
8641 printf (" %02x", data
[printed
]);
8646 /* Prints out the contents on the augmentation data array.
8647 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8650 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8654 i
= printf (_(" Augmentation data: "));
8655 display_data (i
, data
, len
);
8659 display_debug_frames (struct dwarf_section
*section
,
8660 void *file ATTRIBUTE_UNUSED
)
8662 unsigned char *start
= section
->start
;
8663 unsigned char *end
= start
+ section
->size
;
8664 unsigned char *section_start
= start
;
8665 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8666 Frame_Chunk
*remembered_state
= NULL
;
8668 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8669 unsigned int max_regs
= 0;
8670 const char *bad_reg
= _("bad register: ");
8671 unsigned int saved_eh_addr_size
= eh_addr_size
;
8673 introduce (section
, false);
8677 unsigned char *saved_start
;
8678 unsigned char *block_end
;
8683 int need_col_headers
= 1;
8684 unsigned char *augmentation_data
= NULL
;
8685 bfd_size_type augmentation_data_len
= 0;
8686 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8687 unsigned int offset_size
;
8688 unsigned int initial_length_size
;
8690 static Frame_Chunk fde_fc
;
8692 saved_start
= start
;
8694 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8698 printf ("\n%08lx ZERO terminator\n\n",
8699 (unsigned long)(saved_start
- section_start
));
8700 /* Skip any zero terminators that directly follow.
8701 A corrupt section size could have loaded a whole
8702 slew of zero filled memory bytes. eg
8703 PR 17512: file: 070-19381-0.004. */
8704 while (start
< end
&& * start
== 0)
8709 if (length
== 0xffffffff)
8711 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8713 initial_length_size
= 12;
8718 initial_length_size
= 4;
8721 block_end
= saved_start
+ length
+ initial_length_size
;
8722 if (block_end
> end
|| block_end
< start
)
8724 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8725 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8726 (unsigned long) (saved_start
- section_start
));
8730 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8732 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8733 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8738 start
= read_cie (start
, end
, &cie
, &version
,
8739 &augmentation_data_len
, &augmentation_data
);
8740 /* PR 17512: file: 027-135133-0.005. */
8747 fc
->chunk_start
= saved_start
;
8748 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8751 if (frame_need_space (fc
, mreg
) < 0)
8753 if (fc
->fde_encoding
)
8754 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8756 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8757 print_dwarf_vma (length
, fc
->ptr_size
);
8758 print_dwarf_vma (cie_id
, offset_size
);
8760 if (do_debug_frames_interp
)
8762 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8763 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8768 printf (" Version: %d\n", version
);
8769 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8772 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8773 printf (" Segment Size: %u\n", fc
->segment_size
);
8775 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8776 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8777 printf (" Return address column: %d\n", fc
->ra
);
8779 if (augmentation_data_len
)
8780 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8787 unsigned char *look_for
;
8788 unsigned long segment_selector
;
8792 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8793 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8796 look_for
= section_start
+ cie_id
;
8798 if (look_for
<= saved_start
)
8800 for (cie
= chunks
; cie
; cie
= cie
->next
)
8801 if (cie
->chunk_start
== look_for
)
8806 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8807 if (cie
->chunk_start
== look_for
)
8811 unsigned int off_size
;
8812 unsigned char *cie_scan
;
8814 cie_scan
= look_for
;
8816 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8817 if (length
== 0xffffffff)
8819 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8826 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8829 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8830 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8835 read_cie (cie_scan
, end
, &cie
, &version
,
8836 &augmentation_data_len
, &augmentation_data
);
8837 /* PR 17512: file: 3450-2098-0.004. */
8840 warn (_("Failed to read CIE information\n"));
8843 cie
->next
= forward_refs
;
8845 cie
->chunk_start
= look_for
;
8846 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8849 if (frame_need_space (cie
, mreg
) < 0)
8851 warn (_("Invalid max register\n"));
8854 if (cie
->fde_encoding
)
8856 = size_of_encoded_value (cie
->fde_encoding
);
8863 memset (fc
, 0, sizeof (Frame_Chunk
));
8867 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8868 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8869 (unsigned long) (saved_start
- section_start
));
8871 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8872 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8873 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8875 warn (_("Invalid max register\n"));
8879 fc
->augmentation
= "";
8880 fc
->fde_encoding
= 0;
8881 fc
->ptr_size
= eh_addr_size
;
8882 fc
->segment_size
= 0;
8886 fc
->ncols
= cie
->ncols
;
8887 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8888 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8889 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8890 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8891 fc
->augmentation
= cie
->augmentation
;
8892 fc
->ptr_size
= cie
->ptr_size
;
8893 eh_addr_size
= cie
->ptr_size
;
8894 fc
->segment_size
= cie
->segment_size
;
8895 fc
->code_factor
= cie
->code_factor
;
8896 fc
->data_factor
= cie
->data_factor
;
8897 fc
->cfa_reg
= cie
->cfa_reg
;
8898 fc
->cfa_offset
= cie
->cfa_offset
;
8900 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8902 warn (_("Invalid max register\n"));
8905 fc
->fde_encoding
= cie
->fde_encoding
;
8908 if (fc
->fde_encoding
)
8909 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8911 segment_selector
= 0;
8912 if (fc
->segment_size
)
8914 if (fc
->segment_size
> sizeof (segment_selector
))
8916 /* PR 17512: file: 9e196b3e. */
8917 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8918 fc
->segment_size
= 4;
8920 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8923 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8925 /* FIXME: It appears that sometimes the final pc_range value is
8926 encoded in less than encoded_ptr_size bytes. See the x86_64
8927 run of the "objcopy on compressed debug sections" test for an
8929 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8931 if (cie
->augmentation
[0] == 'z')
8933 READ_ULEB (augmentation_data_len
, start
, end
);
8934 augmentation_data
= start
;
8935 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8936 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8938 warn (_("Augmentation data too long: 0x%s, "
8939 "expected at most %#lx\n"),
8940 dwarf_vmatoa ("x", augmentation_data_len
),
8941 (unsigned long) (end
- start
));
8943 augmentation_data
= NULL
;
8944 augmentation_data_len
= 0;
8946 start
+= augmentation_data_len
;
8949 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8950 (unsigned long)(saved_start
- section_start
),
8951 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8952 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8953 (unsigned long)(cie
->chunk_start
- section_start
));
8955 if (fc
->segment_size
)
8956 printf ("%04lx:", segment_selector
);
8959 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8960 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8962 if (! do_debug_frames_interp
&& augmentation_data_len
)
8964 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8969 /* At this point, fc is the current chunk, cie (if any) is set, and
8970 we're about to interpret instructions for the chunk. */
8971 /* ??? At present we need to do this always, since this sizes the
8972 fc->col_type and fc->col_offset arrays, which we write into always.
8973 We should probably split the interpreted and non-interpreted bits
8974 into two different routines, since there's so much that doesn't
8975 really overlap between them. */
8976 if (1 || do_debug_frames_interp
)
8978 /* Start by making a pass over the chunk, allocating storage
8979 and taking note of what registers are used. */
8980 unsigned char *tmp
= start
;
8982 while (start
< block_end
)
8984 unsigned int reg
, op
, opa
;
8986 unsigned char * new_start
;
8993 /* Warning: if you add any more cases to this switch, be
8994 sure to add them to the corresponding switch below. */
8997 case DW_CFA_advance_loc
:
9000 SKIP_ULEB (start
, end
);
9001 if (frame_need_space (fc
, opa
) >= 0)
9002 fc
->col_type
[opa
] = DW_CFA_undefined
;
9004 case DW_CFA_restore
:
9005 if (frame_need_space (fc
, opa
) >= 0)
9006 fc
->col_type
[opa
] = DW_CFA_undefined
;
9008 case DW_CFA_set_loc
:
9009 start
+= encoded_ptr_size
;
9011 case DW_CFA_advance_loc1
:
9014 case DW_CFA_advance_loc2
:
9017 case DW_CFA_advance_loc4
:
9020 case DW_CFA_offset_extended
:
9021 case DW_CFA_val_offset
:
9022 READ_ULEB (reg
, start
, end
);
9023 SKIP_ULEB (start
, end
);
9024 if (frame_need_space (fc
, reg
) >= 0)
9025 fc
->col_type
[reg
] = DW_CFA_undefined
;
9027 case DW_CFA_restore_extended
:
9028 READ_ULEB (reg
, start
, end
);
9029 if (frame_need_space (fc
, reg
) >= 0)
9030 fc
->col_type
[reg
] = DW_CFA_undefined
;
9032 case DW_CFA_undefined
:
9033 READ_ULEB (reg
, start
, end
);
9034 if (frame_need_space (fc
, reg
) >= 0)
9035 fc
->col_type
[reg
] = DW_CFA_undefined
;
9037 case DW_CFA_same_value
:
9038 READ_ULEB (reg
, start
, end
);
9039 if (frame_need_space (fc
, reg
) >= 0)
9040 fc
->col_type
[reg
] = DW_CFA_undefined
;
9042 case DW_CFA_register
:
9043 READ_ULEB (reg
, start
, end
);
9044 SKIP_ULEB (start
, end
);
9045 if (frame_need_space (fc
, reg
) >= 0)
9046 fc
->col_type
[reg
] = DW_CFA_undefined
;
9048 case DW_CFA_def_cfa
:
9049 SKIP_ULEB (start
, end
);
9050 SKIP_ULEB (start
, end
);
9052 case DW_CFA_def_cfa_register
:
9053 SKIP_ULEB (start
, end
);
9055 case DW_CFA_def_cfa_offset
:
9056 SKIP_ULEB (start
, end
);
9058 case DW_CFA_def_cfa_expression
:
9059 READ_ULEB (temp
, start
, end
);
9060 new_start
= start
+ temp
;
9061 if (new_start
< start
)
9063 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
9069 case DW_CFA_expression
:
9070 case DW_CFA_val_expression
:
9071 READ_ULEB (reg
, start
, end
);
9072 READ_ULEB (temp
, start
, end
);
9073 new_start
= start
+ temp
;
9074 if (new_start
< start
)
9076 /* PR 17512: file:306-192417-0.005. */
9077 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
9082 if (frame_need_space (fc
, reg
) >= 0)
9083 fc
->col_type
[reg
] = DW_CFA_undefined
;
9085 case DW_CFA_offset_extended_sf
:
9086 case DW_CFA_val_offset_sf
:
9087 READ_ULEB (reg
, start
, end
);
9088 SKIP_SLEB (start
, end
);
9089 if (frame_need_space (fc
, reg
) >= 0)
9090 fc
->col_type
[reg
] = DW_CFA_undefined
;
9092 case DW_CFA_def_cfa_sf
:
9093 SKIP_ULEB (start
, end
);
9094 SKIP_SLEB (start
, end
);
9096 case DW_CFA_def_cfa_offset_sf
:
9097 SKIP_SLEB (start
, end
);
9099 case DW_CFA_MIPS_advance_loc8
:
9102 case DW_CFA_GNU_args_size
:
9103 SKIP_ULEB (start
, end
);
9105 case DW_CFA_GNU_negative_offset_extended
:
9106 READ_ULEB (reg
, start
, end
);
9107 SKIP_ULEB (start
, end
);
9108 if (frame_need_space (fc
, reg
) >= 0)
9109 fc
->col_type
[reg
] = DW_CFA_undefined
;
9120 /* Now we know what registers are used, make a second pass over
9121 the chunk, this time actually printing out the info. */
9123 while (start
< block_end
)
9125 unsigned char * tmp
;
9127 unsigned long ul
, roffs
;
9128 /* Note: It is tempting to use an unsigned long for 'reg' but there
9129 are various functions, notably frame_space_needed() that assume that
9130 reg is an unsigned int. */
9135 const char *reg_prefix
= "";
9142 /* Make a note if something other than DW_CFA_nop happens. */
9143 if (op
!= DW_CFA_nop
)
9146 /* Warning: if you add any more cases to this switch, be
9147 sure to add them to the corresponding switch above. */
9150 case DW_CFA_advance_loc
:
9151 if (do_debug_frames_interp
)
9152 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9154 printf (" DW_CFA_advance_loc: %d to %s\n",
9155 opa
* fc
->code_factor
,
9156 dwarf_vmatoa_1 (NULL
,
9157 fc
->pc_begin
+ opa
* fc
->code_factor
,
9159 fc
->pc_begin
+= opa
* fc
->code_factor
;
9163 READ_ULEB (roffs
, start
, end
);
9164 if (opa
>= (unsigned int) fc
->ncols
)
9165 reg_prefix
= bad_reg
;
9166 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9167 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9168 reg_prefix
, regname (opa
, 0),
9169 roffs
* fc
->data_factor
);
9170 if (*reg_prefix
== '\0')
9172 fc
->col_type
[opa
] = DW_CFA_offset
;
9173 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9177 case DW_CFA_restore
:
9178 if (opa
>= (unsigned int) fc
->ncols
)
9179 reg_prefix
= bad_reg
;
9180 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9181 printf (" DW_CFA_restore: %s%s\n",
9182 reg_prefix
, regname (opa
, 0));
9183 if (*reg_prefix
!= '\0')
9186 if (opa
>= (unsigned int) cie
->ncols
9187 || (do_debug_frames_interp
9188 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9190 fc
->col_type
[opa
] = DW_CFA_undefined
;
9191 fc
->col_offset
[opa
] = 0;
9195 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9196 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9200 case DW_CFA_set_loc
:
9201 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
9202 if (do_debug_frames_interp
)
9203 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9205 printf (" DW_CFA_set_loc: %s\n",
9206 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9210 case DW_CFA_advance_loc1
:
9211 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
9212 if (do_debug_frames_interp
)
9213 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9215 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9216 (unsigned long) (ofs
* fc
->code_factor
),
9217 dwarf_vmatoa_1 (NULL
,
9218 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9220 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9223 case DW_CFA_advance_loc2
:
9224 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9225 if (do_debug_frames_interp
)
9226 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9228 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9229 (unsigned long) (ofs
* fc
->code_factor
),
9230 dwarf_vmatoa_1 (NULL
,
9231 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9233 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9236 case DW_CFA_advance_loc4
:
9237 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9238 if (do_debug_frames_interp
)
9239 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9241 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9242 (unsigned long) (ofs
* fc
->code_factor
),
9243 dwarf_vmatoa_1 (NULL
,
9244 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9246 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9249 case DW_CFA_offset_extended
:
9250 READ_ULEB (reg
, start
, end
);
9251 READ_ULEB (roffs
, start
, end
);
9252 if (reg
>= (unsigned int) fc
->ncols
)
9253 reg_prefix
= bad_reg
;
9254 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9255 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9256 reg_prefix
, regname (reg
, 0),
9257 roffs
* fc
->data_factor
);
9258 if (*reg_prefix
== '\0')
9260 fc
->col_type
[reg
] = DW_CFA_offset
;
9261 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9265 case DW_CFA_val_offset
:
9266 READ_ULEB (reg
, start
, end
);
9267 READ_ULEB (roffs
, start
, end
);
9268 if (reg
>= (unsigned int) fc
->ncols
)
9269 reg_prefix
= bad_reg
;
9270 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9271 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9272 reg_prefix
, regname (reg
, 0),
9273 roffs
* fc
->data_factor
);
9274 if (*reg_prefix
== '\0')
9276 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9277 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9281 case DW_CFA_restore_extended
:
9282 READ_ULEB (reg
, start
, end
);
9283 if (reg
>= (unsigned int) fc
->ncols
)
9284 reg_prefix
= bad_reg
;
9285 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9286 printf (" DW_CFA_restore_extended: %s%s\n",
9287 reg_prefix
, regname (reg
, 0));
9288 if (*reg_prefix
!= '\0')
9291 if (reg
>= (unsigned int) cie
->ncols
)
9293 fc
->col_type
[reg
] = DW_CFA_undefined
;
9294 fc
->col_offset
[reg
] = 0;
9298 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9299 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9303 case DW_CFA_undefined
:
9304 READ_ULEB (reg
, start
, end
);
9305 if (reg
>= (unsigned int) fc
->ncols
)
9306 reg_prefix
= bad_reg
;
9307 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9308 printf (" DW_CFA_undefined: %s%s\n",
9309 reg_prefix
, regname (reg
, 0));
9310 if (*reg_prefix
== '\0')
9312 fc
->col_type
[reg
] = DW_CFA_undefined
;
9313 fc
->col_offset
[reg
] = 0;
9317 case DW_CFA_same_value
:
9318 READ_ULEB (reg
, start
, end
);
9319 if (reg
>= (unsigned int) fc
->ncols
)
9320 reg_prefix
= bad_reg
;
9321 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9322 printf (" DW_CFA_same_value: %s%s\n",
9323 reg_prefix
, regname (reg
, 0));
9324 if (*reg_prefix
== '\0')
9326 fc
->col_type
[reg
] = DW_CFA_same_value
;
9327 fc
->col_offset
[reg
] = 0;
9331 case DW_CFA_register
:
9332 READ_ULEB (reg
, start
, end
);
9333 READ_ULEB (roffs
, start
, end
);
9334 if (reg
>= (unsigned int) fc
->ncols
)
9335 reg_prefix
= bad_reg
;
9336 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9338 printf (" DW_CFA_register: %s%s in ",
9339 reg_prefix
, regname (reg
, 0));
9340 puts (regname (roffs
, 0));
9342 if (*reg_prefix
== '\0')
9344 fc
->col_type
[reg
] = DW_CFA_register
;
9345 fc
->col_offset
[reg
] = roffs
;
9349 case DW_CFA_remember_state
:
9350 if (! do_debug_frames_interp
)
9351 printf (" DW_CFA_remember_state\n");
9352 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9353 rs
->cfa_offset
= fc
->cfa_offset
;
9354 rs
->cfa_reg
= fc
->cfa_reg
;
9356 rs
->cfa_exp
= fc
->cfa_exp
;
9357 rs
->ncols
= fc
->ncols
;
9358 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9359 sizeof (* rs
->col_type
));
9360 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9361 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9362 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9363 rs
->next
= remembered_state
;
9364 remembered_state
= rs
;
9367 case DW_CFA_restore_state
:
9368 if (! do_debug_frames_interp
)
9369 printf (" DW_CFA_restore_state\n");
9370 rs
= remembered_state
;
9373 remembered_state
= rs
->next
;
9374 fc
->cfa_offset
= rs
->cfa_offset
;
9375 fc
->cfa_reg
= rs
->cfa_reg
;
9377 fc
->cfa_exp
= rs
->cfa_exp
;
9378 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9380 warn (_("Invalid column number in saved frame state\n"));
9384 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9385 memcpy (fc
->col_offset
, rs
->col_offset
,
9386 rs
->ncols
* sizeof (* rs
->col_offset
));
9387 free (rs
->col_type
);
9388 free (rs
->col_offset
);
9391 else if (do_debug_frames_interp
)
9392 printf ("Mismatched DW_CFA_restore_state\n");
9395 case DW_CFA_def_cfa
:
9396 READ_ULEB (fc
->cfa_reg
, start
, end
);
9397 READ_ULEB (fc
->cfa_offset
, start
, end
);
9399 if (! do_debug_frames_interp
)
9400 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9401 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9404 case DW_CFA_def_cfa_register
:
9405 READ_ULEB (fc
->cfa_reg
, start
, end
);
9407 if (! do_debug_frames_interp
)
9408 printf (" DW_CFA_def_cfa_register: %s\n",
9409 regname (fc
->cfa_reg
, 0));
9412 case DW_CFA_def_cfa_offset
:
9413 READ_ULEB (fc
->cfa_offset
, start
, end
);
9414 if (! do_debug_frames_interp
)
9415 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9419 if (! do_debug_frames_interp
)
9420 printf (" DW_CFA_nop\n");
9423 case DW_CFA_def_cfa_expression
:
9424 READ_ULEB (ul
, start
, end
);
9425 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
9427 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9430 if (! do_debug_frames_interp
)
9432 printf (" DW_CFA_def_cfa_expression (");
9433 decode_location_expression (start
, eh_addr_size
, 0, -1,
9441 case DW_CFA_expression
:
9442 READ_ULEB (reg
, start
, end
);
9443 READ_ULEB (ul
, start
, end
);
9444 if (reg
>= (unsigned int) fc
->ncols
)
9445 reg_prefix
= bad_reg
;
9446 /* PR 17512: file: 069-133014-0.006. */
9447 /* PR 17512: file: 98c02eb4. */
9449 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9451 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9454 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9456 printf (" DW_CFA_expression: %s%s (",
9457 reg_prefix
, regname (reg
, 0));
9458 decode_location_expression (start
, eh_addr_size
, 0, -1,
9462 if (*reg_prefix
== '\0')
9463 fc
->col_type
[reg
] = DW_CFA_expression
;
9467 case DW_CFA_val_expression
:
9468 READ_ULEB (reg
, start
, end
);
9469 READ_ULEB (ul
, start
, end
);
9470 if (reg
>= (unsigned int) fc
->ncols
)
9471 reg_prefix
= bad_reg
;
9473 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9475 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9478 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9480 printf (" DW_CFA_val_expression: %s%s (",
9481 reg_prefix
, regname (reg
, 0));
9482 decode_location_expression (start
, eh_addr_size
, 0, -1,
9486 if (*reg_prefix
== '\0')
9487 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9491 case DW_CFA_offset_extended_sf
:
9492 READ_ULEB (reg
, start
, end
);
9493 READ_SLEB (l
, start
, end
);
9494 if (frame_need_space (fc
, reg
) < 0)
9495 reg_prefix
= bad_reg
;
9496 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9497 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9498 reg_prefix
, regname (reg
, 0),
9499 (long)(l
* fc
->data_factor
));
9500 if (*reg_prefix
== '\0')
9502 fc
->col_type
[reg
] = DW_CFA_offset
;
9503 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9507 case DW_CFA_val_offset_sf
:
9508 READ_ULEB (reg
, start
, end
);
9509 READ_SLEB (l
, start
, end
);
9510 if (frame_need_space (fc
, reg
) < 0)
9511 reg_prefix
= bad_reg
;
9512 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9513 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9514 reg_prefix
, regname (reg
, 0),
9515 (long)(l
* fc
->data_factor
));
9516 if (*reg_prefix
== '\0')
9518 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9519 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9523 case DW_CFA_def_cfa_sf
:
9524 READ_ULEB (fc
->cfa_reg
, start
, end
);
9525 READ_ULEB (fc
->cfa_offset
, start
, end
);
9526 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9528 if (! do_debug_frames_interp
)
9529 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9530 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9533 case DW_CFA_def_cfa_offset_sf
:
9534 READ_ULEB (fc
->cfa_offset
, start
, end
);
9535 fc
->cfa_offset
*= fc
->data_factor
;
9536 if (! do_debug_frames_interp
)
9537 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9540 case DW_CFA_MIPS_advance_loc8
:
9541 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9542 if (do_debug_frames_interp
)
9543 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9545 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9546 (unsigned long) (ofs
* fc
->code_factor
),
9547 dwarf_vmatoa_1 (NULL
,
9548 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9550 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9553 case DW_CFA_GNU_window_save
:
9554 if (! do_debug_frames_interp
)
9555 printf (" DW_CFA_GNU_window_save\n");
9558 case DW_CFA_GNU_args_size
:
9559 READ_ULEB (ul
, start
, end
);
9560 if (! do_debug_frames_interp
)
9561 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9564 case DW_CFA_GNU_negative_offset_extended
:
9565 READ_ULEB (reg
, start
, end
);
9566 READ_SLEB (l
, start
, end
);
9568 if (frame_need_space (fc
, reg
) < 0)
9569 reg_prefix
= bad_reg
;
9570 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9571 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9572 reg_prefix
, regname (reg
, 0),
9573 (long)(l
* fc
->data_factor
));
9574 if (*reg_prefix
== '\0')
9576 fc
->col_type
[reg
] = DW_CFA_offset
;
9577 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9582 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9583 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9585 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9590 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9591 if (do_debug_frames_interp
&& ! all_nops
)
9592 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9594 if (fde_fc
.col_type
!= NULL
)
9596 free (fde_fc
.col_type
);
9597 fde_fc
.col_type
= NULL
;
9599 if (fde_fc
.col_offset
!= NULL
)
9601 free (fde_fc
.col_offset
);
9602 fde_fc
.col_offset
= NULL
;
9606 eh_addr_size
= saved_eh_addr_size
;
9611 while (remembered_state
!= NULL
)
9613 rs
= remembered_state
;
9614 remembered_state
= rs
->next
;
9615 free (rs
->col_type
);
9616 free (rs
->col_offset
);
9617 rs
->next
= NULL
; /* Paranoia. */
9621 while (chunks
!= NULL
)
9625 free (rs
->col_type
);
9626 free (rs
->col_offset
);
9627 rs
->next
= NULL
; /* Paranoia. */
9631 while (forward_refs
!= NULL
)
9634 forward_refs
= rs
->next
;
9635 free (rs
->col_type
);
9636 free (rs
->col_offset
);
9637 rs
->next
= NULL
; /* Paranoia. */
9647 display_debug_names (struct dwarf_section
*section
, void *file
)
9649 unsigned char *hdrptr
= section
->start
;
9650 dwarf_vma unit_length
;
9651 unsigned char *unit_start
;
9652 const unsigned char *const section_end
= section
->start
+ section
->size
;
9653 unsigned char *unit_end
;
9655 introduce (section
, false);
9657 load_debug_section_with_follow (str
, file
);
9659 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9661 unsigned int offset_size
;
9662 uint16_t dwarf_version
, padding
;
9663 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9664 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9665 uint32_t augmentation_string_size
;
9667 unsigned long sec_off
;
9668 bool augmentation_printable
;
9669 const char *augmentation_string
;
9671 unit_start
= hdrptr
;
9673 /* Get and check the length of the block. */
9674 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9676 if (unit_length
== 0xffffffff)
9678 /* This section is 64-bit DWARF. */
9679 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9684 unit_end
= hdrptr
+ unit_length
;
9686 sec_off
= hdrptr
- section
->start
;
9687 if (sec_off
+ unit_length
< sec_off
9688 || sec_off
+ unit_length
> section
->size
)
9690 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9692 (unsigned long) (unit_start
- section
->start
),
9693 dwarf_vmatoa ("x", unit_length
));
9697 /* Get and check the version number. */
9698 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9699 printf (_("Version %ld\n"), (long) dwarf_version
);
9701 /* Prior versions did not exist, and future versions may not be
9702 backwards compatible. */
9703 if (dwarf_version
!= 5)
9705 warn (_("Only DWARF version 5 .debug_names "
9706 "is currently supported.\n"));
9710 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9712 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9715 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9716 if (comp_unit_count
== 0)
9717 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9719 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9720 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9721 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9722 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9723 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9725 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9726 if (augmentation_string_size
% 4 != 0)
9728 warn (_("Augmentation string length %u must be rounded up "
9729 "to a multiple of 4 in .debug_names.\n"),
9730 augmentation_string_size
);
9731 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9734 printf (_("Augmentation string:"));
9736 augmentation_printable
= true;
9737 augmentation_string
= (const char *) hdrptr
;
9739 for (i
= 0; i
< augmentation_string_size
; i
++)
9743 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9744 printf (" %02x", uc
);
9746 if (uc
!= 0 && !ISPRINT (uc
))
9747 augmentation_printable
= false;
9750 if (augmentation_printable
)
9754 i
< augmentation_string_size
&& augmentation_string
[i
];
9756 putchar (augmentation_string
[i
]);
9761 printf (_("CU table:\n"));
9762 for (i
= 0; i
< comp_unit_count
; i
++)
9766 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9767 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9771 printf (_("TU table:\n"));
9772 for (i
= 0; i
< local_type_unit_count
; i
++)
9776 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9777 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9781 printf (_("Foreign TU table:\n"));
9782 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9786 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9787 printf (_("[%3u] "), i
);
9788 print_dwarf_vma (signature
, 8);
9793 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9794 hdrptr
+= bucket_count
* sizeof (uint32_t);
9795 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9796 hdrptr
+= name_count
* sizeof (uint32_t);
9797 unsigned char *const name_table_string_offsets
= hdrptr
;
9798 hdrptr
+= name_count
* offset_size
;
9799 unsigned char *const name_table_entry_offsets
= hdrptr
;
9800 hdrptr
+= name_count
* offset_size
;
9801 unsigned char *const abbrev_table
= hdrptr
;
9802 hdrptr
+= abbrev_table_size
;
9803 const unsigned char *const abbrev_table_end
= hdrptr
;
9804 unsigned char *const entry_pool
= hdrptr
;
9805 if (hdrptr
> unit_end
)
9807 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9808 "for unit 0x%lx in the debug_names\n"),
9809 (long) (hdrptr
- section
->start
),
9810 (long) (unit_end
- section
->start
),
9811 (long) (unit_start
- section
->start
));
9815 size_t buckets_filled
= 0;
9817 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9819 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9824 printf (ngettext ("Used %zu of %lu bucket.\n",
9825 "Used %zu of %lu buckets.\n",
9827 buckets_filled
, (unsigned long) bucket_count
);
9829 uint32_t hash_prev
= 0;
9830 size_t hash_clash_count
= 0;
9831 size_t longest_clash
= 0;
9832 size_t this_length
= 0;
9834 for (hashi
= 0; hashi
< name_count
; hashi
++)
9836 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9840 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9844 longest_clash
= MAX (longest_clash
, this_length
);
9849 hash_prev
= hash_this
;
9851 printf (_("Out of %lu items there are %zu bucket clashes"
9852 " (longest of %zu entries).\n"),
9853 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9854 assert (name_count
== buckets_filled
+ hash_clash_count
);
9856 struct abbrev_lookup_entry
9858 dwarf_vma abbrev_tag
;
9859 unsigned char *abbrev_lookup_ptr
;
9861 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9862 size_t abbrev_lookup_used
= 0;
9863 size_t abbrev_lookup_allocated
= 0;
9865 unsigned char *abbrevptr
= abbrev_table
;
9868 dwarf_vma abbrev_tag
;
9870 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9871 if (abbrev_tag
== 0)
9873 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9875 abbrev_lookup_allocated
= MAX (0x100,
9876 abbrev_lookup_allocated
* 2);
9877 abbrev_lookup
= xrealloc (abbrev_lookup
,
9878 (abbrev_lookup_allocated
9879 * sizeof (*abbrev_lookup
)));
9881 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9882 struct abbrev_lookup_entry
*entry
;
9883 for (entry
= abbrev_lookup
;
9884 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9886 if (entry
->abbrev_tag
== abbrev_tag
)
9888 warn (_("Duplicate abbreviation tag %lu "
9889 "in unit 0x%lx in the debug_names\n"),
9890 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9893 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9894 entry
->abbrev_tag
= abbrev_tag
;
9895 entry
->abbrev_lookup_ptr
= abbrevptr
;
9897 /* Skip DWARF tag. */
9898 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9901 dwarf_vma xindex
, form
;
9903 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9904 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9905 if (xindex
== 0 && form
== 0)
9910 printf (_("\nSymbol table:\n"));
9912 for (namei
= 0; namei
< name_count
; ++namei
)
9914 uint64_t string_offset
, entry_offset
;
9916 SAFE_BYTE_GET (string_offset
,
9917 name_table_string_offsets
+ namei
* offset_size
,
9918 offset_size
, unit_end
);
9919 SAFE_BYTE_GET (entry_offset
,
9920 name_table_entry_offsets
+ namei
* offset_size
,
9921 offset_size
, unit_end
);
9923 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9924 fetch_indirect_string (string_offset
));
9926 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9928 /* We need to scan first whether there is a single or multiple
9929 entries. TAGNO is -2 for the first entry, it is -1 for the
9930 initial tag read of the second entry, then it becomes 0 for the
9931 first entry for real printing etc. */
9933 /* Initialize it due to a false compiler warning. */
9934 dwarf_vma second_abbrev_tag
= -1;
9937 dwarf_vma abbrev_tag
;
9938 dwarf_vma dwarf_tag
;
9939 const struct abbrev_lookup_entry
*entry
;
9941 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9944 second_abbrev_tag
= abbrev_tag
;
9946 entryptr
= entry_pool
+ entry_offset
;
9949 if (abbrev_tag
== 0)
9953 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9954 (unsigned long) abbrev_tag
);
9956 for (entry
= abbrev_lookup
;
9957 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9959 if (entry
->abbrev_tag
== abbrev_tag
)
9961 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9963 warn (_("Undefined abbreviation tag %lu "
9964 "in unit 0x%lx in the debug_names\n"),
9966 (long) (unit_start
- section
->start
));
9969 abbrevptr
= entry
->abbrev_lookup_ptr
;
9970 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9972 printf (" %s", get_TAG_name (dwarf_tag
));
9975 dwarf_vma xindex
, form
;
9977 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9978 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9979 if (xindex
== 0 && form
== 0)
9983 printf (" %s", get_IDX_name (xindex
));
9984 entryptr
= read_and_display_attr_value (0, form
, 0,
9985 unit_start
, entryptr
, unit_end
,
9987 dwarf_version
, NULL
,
9994 printf (_(" <no entries>"));
9998 free (abbrev_lookup
);
10005 display_debug_links (struct dwarf_section
* section
,
10006 void * file ATTRIBUTE_UNUSED
)
10008 const unsigned char * filename
;
10009 unsigned int filelen
;
10011 introduce (section
, false);
10013 /* The .gnu_debuglink section is formatted as:
10014 (c-string) Filename.
10015 (padding) If needed to reach a 4 byte boundary.
10016 (uint32_t) CRC32 value.
10018 The .gun_debugaltlink section is formatted as:
10019 (c-string) Filename.
10020 (binary) Build-ID. */
10022 filename
= section
->start
;
10023 filelen
= strnlen ((const char *) filename
, section
->size
);
10024 if (filelen
== section
->size
)
10026 warn (_("The debuglink filename is corrupt/missing\n"));
10030 printf (_(" Separate debug info file: %s\n"), filename
);
10032 if (startswith (section
->name
, ".gnu_debuglink"))
10034 unsigned int crc32
;
10035 unsigned int crc_offset
;
10037 crc_offset
= filelen
+ 1;
10038 crc_offset
= (crc_offset
+ 3) & ~3;
10039 if (crc_offset
+ 4 > section
->size
)
10041 warn (_("CRC offset missing/truncated\n"));
10045 crc32
= byte_get (filename
+ crc_offset
, 4);
10047 printf (_(" CRC value: %#x\n"), crc32
);
10049 if (crc_offset
+ 4 < section
->size
)
10051 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10052 (long)(section
->size
- (crc_offset
+ 4)));
10056 else /* startswith (section->name, ".gnu_debugaltlink") */
10058 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
10059 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
10060 bfd_size_type printed
;
10062 /* FIXME: Should we support smaller build-id notes ? */
10063 if (build_id_len
< 0x14)
10065 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
10069 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
10070 display_data (printed
, build_id
, build_id_len
);
10079 display_gdb_index (struct dwarf_section
*section
,
10080 void *file ATTRIBUTE_UNUSED
)
10082 unsigned char *start
= section
->start
;
10084 uint32_t cu_list_offset
, tu_list_offset
;
10085 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10086 unsigned int cu_list_elements
, tu_list_elements
;
10087 unsigned int address_table_size
, symbol_table_slots
;
10088 unsigned char *cu_list
, *tu_list
;
10089 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10092 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10094 introduce (section
, false);
10096 if (section
->size
< 6 * sizeof (uint32_t))
10098 warn (_("Truncated header in the %s section.\n"), section
->name
);
10102 version
= byte_get_little_endian (start
, 4);
10103 printf (_("Version %ld\n"), (long) version
);
10105 /* Prior versions are obsolete, and future versions may not be
10106 backwards compatible. */
10107 if (version
< 3 || version
> 8)
10109 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10113 warn (_("The address table data in version 3 may be wrong.\n"));
10115 warn (_("Version 4 does not support case insensitive lookups.\n"));
10117 warn (_("Version 5 does not include inlined functions.\n"));
10119 warn (_("Version 6 does not include symbol attributes.\n"));
10120 /* Version 7 indices generated by Gold have bad type unit references,
10121 PR binutils/15021. But we don't know if the index was generated by
10122 Gold or not, so to avoid worrying users with gdb-generated indices
10123 we say nothing for version 7 here. */
10125 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10126 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10127 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10128 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10129 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10131 if (cu_list_offset
> section
->size
10132 || tu_list_offset
> section
->size
10133 || address_table_offset
> section
->size
10134 || symbol_table_offset
> section
->size
10135 || constant_pool_offset
> section
->size
)
10137 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10141 /* PR 17531: file: 418d0a8a. */
10142 if (tu_list_offset
< cu_list_offset
)
10144 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10145 tu_list_offset
, cu_list_offset
);
10149 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
10151 if (address_table_offset
< tu_list_offset
)
10153 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10154 address_table_offset
, tu_list_offset
);
10158 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
10160 /* PR 17531: file: 18a47d3d. */
10161 if (symbol_table_offset
< address_table_offset
)
10163 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
10164 symbol_table_offset
, address_table_offset
);
10168 address_table_size
= symbol_table_offset
- address_table_offset
;
10170 if (constant_pool_offset
< symbol_table_offset
)
10172 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10173 constant_pool_offset
, symbol_table_offset
);
10177 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10179 cu_list
= start
+ cu_list_offset
;
10180 tu_list
= start
+ tu_list_offset
;
10181 address_table
= start
+ address_table_offset
;
10182 symbol_table
= start
+ symbol_table_offset
;
10183 constant_pool
= start
+ constant_pool_offset
;
10185 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
10187 warn (_("Address table extends beyond end of section.\n"));
10191 printf (_("\nCU table:\n"));
10192 for (i
= 0; i
< cu_list_elements
; i
+= 2)
10194 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
10195 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
10197 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
10198 (unsigned long) cu_offset
,
10199 (unsigned long) (cu_offset
+ cu_length
- 1));
10202 printf (_("\nTU table:\n"));
10203 for (i
= 0; i
< tu_list_elements
; i
+= 3)
10205 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
10206 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
10207 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
10209 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
10210 (unsigned long) tu_offset
,
10211 (unsigned long) type_offset
);
10212 print_dwarf_vma (signature
, 8);
10216 printf (_("\nAddress table:\n"));
10217 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10220 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10221 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10222 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10224 print_dwarf_vma (low
, 8);
10225 print_dwarf_vma (high
, 8);
10226 printf (_("%lu\n"), (unsigned long) cu_index
);
10229 printf (_("\nSymbol table:\n"));
10230 for (i
= 0; i
< symbol_table_slots
; ++i
)
10232 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10233 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10234 uint32_t num_cus
, cu
;
10236 if (name_offset
!= 0
10237 || cu_vector_offset
!= 0)
10240 unsigned char * adr
;
10242 adr
= constant_pool
+ name_offset
;
10243 /* PR 17531: file: 5b7b07ad. */
10244 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
10246 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10247 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10251 printf ("[%3u] %.*s:", i
,
10252 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10253 constant_pool
+ name_offset
);
10255 adr
= constant_pool
+ cu_vector_offset
;
10256 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
10258 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10259 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10260 cu_vector_offset
, i
);
10264 num_cus
= byte_get_little_endian (adr
, 4);
10266 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
10267 if (num_cus
* 4 < num_cus
10268 || adr
>= section
->start
+ section
->size
10269 || adr
< constant_pool
)
10271 printf ("<invalid number of CUs: %d>\n", num_cus
);
10272 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10280 for (j
= 0; j
< num_cus
; ++j
)
10283 gdb_index_symbol_kind kind
;
10285 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10286 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10287 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10288 cu
= GDB_INDEX_CU_VALUE (cu
);
10289 /* Convert to TU number if it's for a type unit. */
10290 if (cu
>= cu_list_elements
/ 2)
10291 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10292 (unsigned long) (cu
- cu_list_elements
/ 2));
10294 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10296 printf (" [%s, %s]",
10297 is_static
? _("static") : _("global"),
10298 get_gdb_index_symbol_kind_name (kind
));
10310 /* Pre-allocate enough space for the CU/TU sets needed. */
10313 prealloc_cu_tu_list (unsigned int nshndx
)
10315 if (shndx_pool
== NULL
)
10317 shndx_pool_size
= nshndx
;
10318 shndx_pool_used
= 0;
10319 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10320 sizeof (unsigned int));
10324 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10325 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10326 sizeof (unsigned int));
10331 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10333 if (shndx_pool_used
>= shndx_pool_size
)
10335 error (_("Internal error: out of space in the shndx pool.\n"));
10338 shndx_pool
[shndx_pool_used
++] = shndx
;
10342 end_cu_tu_entry (void)
10344 if (shndx_pool_used
>= shndx_pool_size
)
10346 error (_("Internal error: out of space in the shndx pool.\n"));
10349 shndx_pool
[shndx_pool_used
++] = 0;
10352 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10354 static const char *
10355 get_DW_SECT_short_name (unsigned int dw_sect
)
10357 static char buf
[16];
10363 case DW_SECT_TYPES
:
10365 case DW_SECT_ABBREV
:
10371 case DW_SECT_STR_OFFSETS
:
10373 case DW_SECT_MACINFO
:
10375 case DW_SECT_MACRO
:
10381 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10385 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10386 These sections are extensions for Fission.
10387 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10390 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10392 unsigned char *phdr
= section
->start
;
10393 unsigned char *limit
= phdr
+ section
->size
;
10394 unsigned char *phash
;
10395 unsigned char *pindex
;
10396 unsigned char *ppool
;
10397 unsigned int version
;
10398 unsigned int ncols
= 0;
10399 unsigned int nused
;
10400 unsigned int nslots
;
10403 dwarf_vma signature_high
;
10404 dwarf_vma signature_low
;
10407 /* PR 17512: file: 002-168123-0.004. */
10410 warn (_("Section %s is empty\n"), section
->name
);
10413 /* PR 17512: file: 002-376-0.004. */
10414 if (section
->size
< 24)
10416 warn (_("Section %s is too small to contain a CU/TU header\n"),
10421 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
10423 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
10424 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
10425 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
10428 pindex
= phash
+ (size_t) nslots
* 8;
10429 ppool
= pindex
+ (size_t) nslots
* 4;
10433 introduce (section
, false);
10435 printf (_(" Version: %u\n"), version
);
10437 printf (_(" Number of columns: %u\n"), ncols
);
10438 printf (_(" Number of used entries: %u\n"), nused
);
10439 printf (_(" Number of slots: %u\n\n"), nslots
);
10442 /* PR 17531: file: 45d69832. */
10443 if ((size_t) nslots
* 8 / 8 != nslots
10444 || phash
< phdr
|| phash
> limit
10445 || pindex
< phash
|| pindex
> limit
10446 || ppool
< pindex
|| ppool
> limit
)
10448 warn (ngettext ("Section %s is too small for %u slot\n",
10449 "Section %s is too small for %u slots\n",
10451 section
->name
, nslots
);
10458 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10459 for (i
= 0; i
< nslots
; i
++)
10461 unsigned char *shndx_list
;
10462 unsigned int shndx
;
10464 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
10465 if (signature_high
!= 0 || signature_low
!= 0)
10467 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10468 shndx_list
= ppool
+ j
* 4;
10469 /* PR 17531: file: 705e010d. */
10470 if (shndx_list
< ppool
)
10472 warn (_("Section index pool located before start of section\n"));
10477 printf (_(" [%3d] Signature: 0x%s Sections: "),
10478 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10479 buf
, sizeof (buf
)));
10482 if (shndx_list
>= limit
)
10484 warn (_("Section %s too small for shndx pool\n"),
10488 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10492 printf (" %d", shndx
);
10494 add_shndx_to_cu_tu_entry (shndx
);
10500 end_cu_tu_entry ();
10506 else if (version
== 2)
10509 unsigned int dw_sect
;
10510 unsigned char *ph
= phash
;
10511 unsigned char *pi
= pindex
;
10512 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10513 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10514 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10516 struct cu_tu_set
*this_set
= NULL
;
10518 unsigned char *prow
;
10520 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10522 /* PR 17531: file: 0dd159bf.
10523 Check for integer overflow (can occur when size_t is 32-bit)
10524 with overlarge ncols or nused values. */
10526 && ((size_t) ncols
* 4 / 4 != ncols
10527 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10528 || poffsets
< ppool
|| poffsets
> limit
10529 || psizes
< poffsets
|| psizes
> limit
10530 || pend
< psizes
|| pend
> limit
))
10532 warn (_("Section %s too small for offset and size tables\n"),
10539 printf (_(" Offset table\n"));
10540 printf (" slot %-16s ",
10541 is_tu_index
? _("signature") : _("dwo_id"));
10548 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10549 this_set
= tu_sets
;
10554 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10555 this_set
= cu_sets
;
10561 for (j
= 0; j
< ncols
; j
++)
10563 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10564 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10569 for (i
= 0; i
< nslots
; i
++)
10571 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10573 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10576 /* PR 17531: file: a05f6ab3. */
10579 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10586 size_t num_copy
= sizeof (uint64_t);
10588 /* PR 23064: Beware of buffer overflow. */
10589 if (ph
+ num_copy
< limit
)
10590 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10593 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10598 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10599 /* PR 17531: file: b8ce60a8. */
10600 if (prow
< poffsets
|| prow
> limit
)
10602 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10608 printf (_(" [%3d] 0x%s"),
10609 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10610 buf
, sizeof (buf
)));
10611 for (j
= 0; j
< ncols
; j
++)
10613 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10615 printf (" %8d", val
);
10618 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10620 /* PR 17531: file: 10796eb3. */
10621 if (dw_sect
>= DW_SECT_MAX
)
10622 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10624 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10640 printf (_(" Size table\n"));
10641 printf (" slot %-16s ",
10642 is_tu_index
? _("signature") : _("dwo_id"));
10645 for (j
= 0; j
< ncols
; j
++)
10647 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
10649 printf (" %8s", get_DW_SECT_short_name (val
));
10655 for (i
= 0; i
< nslots
; i
++)
10657 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10659 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10662 prow
= psizes
+ (row
- 1) * ncols
* 4;
10665 printf (_(" [%3d] 0x%s"),
10666 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10667 buf
, sizeof (buf
)));
10669 for (j
= 0; j
< ncols
; j
++)
10671 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10673 printf (" %8d", val
);
10676 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10677 if (dw_sect
>= DW_SECT_MAX
)
10678 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10680 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10692 else if (do_display
)
10693 printf (_(" Unsupported version (%d)\n"), version
);
10701 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10703 /* Load the CU and TU indexes if present. This will build a list of
10704 section sets that we can use to associate a .debug_info.dwo section
10705 with its associated .debug_abbrev.dwo section in a .dwp file. */
10708 load_cu_tu_indexes (void *file
)
10710 /* If we have already loaded (or tried to load) the CU and TU indexes
10711 then do not bother to repeat the task. */
10712 if (cu_tu_indexes_read
== -1)
10714 cu_tu_indexes_read
= true;
10716 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10717 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10718 cu_tu_indexes_read
= false;
10720 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10721 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10722 cu_tu_indexes_read
= false;
10725 return (bool) cu_tu_indexes_read
;
10728 /* Find the set of sections that includes section SHNDX. */
10731 find_cu_tu_set (void *file
, unsigned int shndx
)
10735 if (! load_cu_tu_indexes (file
))
10738 /* Find SHNDX in the shndx pool. */
10739 for (i
= 0; i
< shndx_pool_used
; i
++)
10740 if (shndx_pool
[i
] == shndx
)
10743 if (i
>= shndx_pool_used
)
10746 /* Now backup to find the first entry in the set. */
10747 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10750 return shndx_pool
+ i
;
10753 /* Display a .debug_cu_index or .debug_tu_index section. */
10756 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10758 return process_cu_tu_index (section
, 1);
10762 display_debug_not_supported (struct dwarf_section
*section
,
10763 void *file ATTRIBUTE_UNUSED
)
10765 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10771 /* Like malloc, but takes two parameters like calloc.
10772 Verifies that the first parameter is not too large.
10773 Note: does *not* initialise the allocated memory to zero. */
10776 cmalloc (size_t nmemb
, size_t size
)
10778 /* Check for overflow. */
10779 if (nmemb
>= ~(size_t) 0 / size
)
10782 return xmalloc (nmemb
* size
);
10785 /* Like xmalloc, but takes two parameters like calloc.
10786 Verifies that the first parameter is not too large.
10787 Note: does *not* initialise the allocated memory to zero. */
10790 xcmalloc (size_t nmemb
, size_t size
)
10792 /* Check for overflow. */
10793 if (nmemb
>= ~(size_t) 0 / size
)
10796 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10801 return xmalloc (nmemb
* size
);
10804 /* Like xrealloc, but takes three parameters.
10805 Verifies that the second parameter is not too large.
10806 Note: does *not* initialise any new memory to zero. */
10809 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10811 /* Check for overflow. */
10812 if (nmemb
>= ~(size_t) 0 / size
)
10814 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10819 return xrealloc (ptr
, nmemb
* size
);
10822 /* Like xcalloc, but verifies that the first parameter is not too large. */
10825 xcalloc2 (size_t nmemb
, size_t size
)
10827 /* Check for overflow. */
10828 if (nmemb
>= ~(size_t) 0 / size
)
10830 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10835 return xcalloc (nmemb
, size
);
10838 static unsigned long
10839 calc_gnu_debuglink_crc32 (unsigned long crc
,
10840 const unsigned char * buf
,
10843 static const unsigned long crc32_table
[256] =
10845 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10846 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10847 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10848 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10849 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10850 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10851 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10852 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10853 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10854 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10855 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10856 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10857 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10858 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10859 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10860 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10861 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10862 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10863 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10864 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10865 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10866 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10867 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10868 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10869 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10870 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10871 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10872 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10873 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10874 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10875 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10876 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10877 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10878 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10879 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10880 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10881 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10882 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10883 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10884 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10885 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10886 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10887 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10888 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10889 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10890 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10891 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10892 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10893 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10894 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10895 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10898 const unsigned char *end
;
10900 crc
= ~crc
& 0xffffffff;
10901 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10902 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10903 return ~crc
& 0xffffffff;
10906 typedef bool (*check_func_type
) (const char *, void *);
10907 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
10910 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10912 static unsigned char buffer
[8 * 1024];
10914 bfd_size_type count
;
10915 unsigned long crc
= 0;
10918 sep_data
= open_debug_file (pathname
);
10919 if (sep_data
== NULL
)
10922 /* Yes - we are opening the file twice... */
10923 f
= fopen (pathname
, "rb");
10926 /* Paranoia: This should never happen. */
10927 close_debug_file (sep_data
);
10928 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10932 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10933 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10937 if (crc
!= * (unsigned long *) crc_pointer
)
10939 close_debug_file (sep_data
);
10940 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10948 static const char *
10949 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10952 unsigned int crc_offset
;
10953 unsigned long * crc32
= (unsigned long *) data
;
10955 /* The name is first.
10956 The CRC value is stored after the filename, aligned up to 4 bytes. */
10957 name
= (const char *) section
->start
;
10959 crc_offset
= strnlen (name
, section
->size
) + 1;
10960 crc_offset
= (crc_offset
+ 3) & ~3;
10961 if (crc_offset
+ 4 > section
->size
)
10964 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10969 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10971 void * sep_data
= open_debug_file (filename
);
10973 if (sep_data
== NULL
)
10976 /* FIXME: We should now extract the build-id in the separate file
10982 typedef struct build_id_data
10985 const unsigned char * data
;
10988 static const char *
10989 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10992 bfd_size_type namelen
;
10993 bfd_size_type id_len
;
10994 Build_id_data
* build_id_data
;
10996 /* The name is first.
10997 The build-id follows immediately, with no padding, up to the section's end. */
10999 name
= (const char *) section
->start
;
11000 namelen
= strnlen (name
, section
->size
) + 1;
11001 if (namelen
>= section
->size
)
11004 id_len
= section
->size
- namelen
;
11008 build_id_data
= (Build_id_data
*) data
;
11009 build_id_data
->len
= id_len
;
11010 build_id_data
->data
= section
->start
+ namelen
;
11016 add_separate_debug_file (const char * filename
, void * handle
)
11018 separate_info
* i
= xmalloc (sizeof * i
);
11020 i
->filename
= filename
;
11021 i
->handle
= handle
;
11022 i
->next
= first_separate_info
;
11023 first_separate_info
= i
;
11026 #if HAVE_LIBDEBUGINFOD
11027 /* Query debuginfod servers for the target debuglink or debugaltlink
11028 file. If successful, store the path of the file in filename and
11029 return TRUE, otherwise return FALSE. */
11032 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11036 size_t build_id_len
;
11037 unsigned char * build_id
;
11039 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11041 /* Get the build-id of file. */
11042 build_id
= get_build_id (file
);
11045 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11047 /* Get the build-id of the debugaltlink file. */
11048 unsigned int filelen
;
11050 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11051 if (filelen
== section
->size
)
11052 /* Corrupt debugaltlink. */
11055 build_id
= section
->start
+ filelen
+ 1;
11056 build_id_len
= section
->size
- (filelen
+ 1);
11058 if (build_id_len
== 0)
11067 debuginfod_client
* client
;
11069 client
= debuginfod_begin ();
11070 if (client
== NULL
)
11073 /* Query debuginfod servers for the target file. If found its path
11074 will be stored in filename. */
11075 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11076 debuginfod_end (client
);
11078 /* Only free build_id if we allocated space for a hex string
11079 in get_build_id (). */
11080 if (build_id_len
== 0)
11085 /* File successfully retrieved. Close fd since we want to
11086 use open_debug_file () on filename instead. */
11097 load_separate_debug_info (const char * main_filename
,
11098 struct dwarf_section
* xlink
,
11099 parse_func_type parse_func
,
11100 check_func_type check_func
,
11102 void * file ATTRIBUTE_UNUSED
)
11104 const char * separate_filename
;
11105 char * debug_filename
;
11107 size_t canon_dirlen
;
11110 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11112 warn (_("Corrupt debuglink section: %s\n"),
11113 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11117 /* Attempt to locate the separate file.
11118 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11120 canon_dir
= lrealpath (main_filename
);
11122 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11123 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11125 canon_dir
[canon_dirlen
] = '\0';
11128 #define DEBUGDIR "/lib/debug"
11130 #ifndef EXTRA_DEBUG_ROOT1
11131 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11133 #ifndef EXTRA_DEBUG_ROOT2
11134 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11137 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11139 + strlen (".debug/")
11140 #ifdef EXTRA_DEBUG_ROOT1
11141 + strlen (EXTRA_DEBUG_ROOT1
)
11143 #ifdef EXTRA_DEBUG_ROOT2
11144 + strlen (EXTRA_DEBUG_ROOT2
)
11146 + strlen (separate_filename
)
11148 if (debug_filename
== NULL
)
11150 warn (_("Out of memory"));
11155 /* First try in the current directory. */
11156 sprintf (debug_filename
, "%s", separate_filename
);
11157 if (check_func (debug_filename
, func_data
))
11160 /* Then try in a subdirectory called .debug. */
11161 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11162 if (check_func (debug_filename
, func_data
))
11165 /* Then try in the same directory as the original file. */
11166 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11167 if (check_func (debug_filename
, func_data
))
11170 /* And the .debug subdirectory of that directory. */
11171 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11172 if (check_func (debug_filename
, func_data
))
11175 #ifdef EXTRA_DEBUG_ROOT1
11176 /* Try the first extra debug file root. */
11177 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11178 if (check_func (debug_filename
, func_data
))
11181 /* Try the first extra debug file root. */
11182 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11183 if (check_func (debug_filename
, func_data
))
11187 #ifdef EXTRA_DEBUG_ROOT2
11188 /* Try the second extra debug file root. */
11189 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11190 if (check_func (debug_filename
, func_data
))
11194 /* Then try in the global debug_filename directory. */
11195 strcpy (debug_filename
, DEBUGDIR
);
11196 dirlen
= strlen (DEBUGDIR
) - 1;
11197 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11198 strcat (debug_filename
, "/");
11199 strcat (debug_filename
, (const char *) separate_filename
);
11201 if (check_func (debug_filename
, func_data
))
11204 #if HAVE_LIBDEBUGINFOD
11206 char * tmp_filename
;
11208 if (debuginfod_fetch_separate_debug_info (xlink
,
11212 /* File successfully downloaded from server, replace
11213 debug_filename with the file's path. */
11214 free (debug_filename
);
11215 debug_filename
= tmp_filename
;
11221 if (do_debug_links
)
11223 /* Failed to find the file. */
11224 warn (_("could not find separate debug file '%s'\n"),
11225 separate_filename
);
11226 warn (_("tried: %s\n"), debug_filename
);
11228 #ifdef EXTRA_DEBUG_ROOT2
11229 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11230 separate_filename
);
11231 warn (_("tried: %s\n"), debug_filename
);
11234 #ifdef EXTRA_DEBUG_ROOT1
11235 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11236 canon_dir
, separate_filename
);
11237 warn (_("tried: %s\n"), debug_filename
);
11239 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11240 separate_filename
);
11241 warn (_("tried: %s\n"), debug_filename
);
11244 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11245 separate_filename
);
11246 warn (_("tried: %s\n"), debug_filename
);
11248 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11249 warn (_("tried: %s\n"), debug_filename
);
11251 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11252 warn (_("tried: %s\n"), debug_filename
);
11254 sprintf (debug_filename
, "%s", separate_filename
);
11255 warn (_("tried: %s\n"), debug_filename
);
11257 #if HAVE_LIBDEBUGINFOD
11259 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11263 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11269 free (debug_filename
);
11275 void * debug_handle
;
11277 /* Now open the file.... */
11278 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11280 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11281 free (debug_filename
);
11285 /* FIXME: We do not check to see if there are any other separate debug info
11286 files that would also match. */
11288 if (do_debug_links
)
11289 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11290 add_separate_debug_file (debug_filename
, debug_handle
);
11292 /* Do not free debug_filename - it might be referenced inside
11293 the structure returned by open_debug_file(). */
11294 return debug_handle
;
11297 /* Attempt to load a separate dwarf object file. */
11300 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11302 char * separate_filename
;
11303 void * separate_handle
;
11305 if (IS_ABSOLUTE_PATH (name
))
11306 separate_filename
= strdup (name
);
11308 /* FIXME: Skip adding / if dwo_dir ends in /. */
11309 separate_filename
= concat (dir
, "/", name
, NULL
);
11310 if (separate_filename
== NULL
)
11312 warn (_("Out of memory allocating dwo filename\n"));
11316 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11318 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11319 free (separate_filename
);
11323 /* FIXME: We should check the dwo_id. */
11325 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11326 add_separate_debug_file (separate_filename
, separate_handle
);
11327 /* Note - separate_filename will be freed in free_debug_memory(). */
11328 return separate_handle
;
11332 load_debug_sup_file (const char * main_filename
, void * file
)
11334 if (! load_debug_section (debug_sup
, file
))
11335 return; /* No .debug_sup section. */
11337 struct dwarf_section
* section
;
11338 section
= & debug_displays
[debug_sup
].section
;
11339 assert (section
!= NULL
);
11341 if (section
->start
== NULL
|| section
->size
< 5)
11343 warn (_(".debug_sup section is corrupt/empty\n"));
11347 if (section
->start
[2] != 0)
11348 return; /* This is a supplementary file. */
11350 const char * filename
= (const char *) section
->start
+ 3;
11351 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11353 warn (_("filename in .debug_sup section is corrupt\n"));
11357 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11360 if (asprintf (& new_name
, "%.*s/%s",
11361 (int) (strrchr (main_filename
, '/') - main_filename
),
11364 warn (_("unable to construct path for supplementary debug file"));
11366 filename
= new_name
;
11370 handle
= open_debug_file (filename
);
11371 if (handle
== NULL
)
11373 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11377 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11379 /* FIXME: Compare the checksums, if present. */
11380 add_separate_debug_file (filename
, handle
);
11383 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11384 Recursively check the loaded files for more of these sections.
11385 Also follow any links in .debug_sup sections.
11386 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11389 check_for_and_load_links (void * file
, const char * filename
)
11391 void * handle
= NULL
;
11393 if (load_debug_section (gnu_debugaltlink
, file
))
11395 Build_id_data build_id_data
;
11397 handle
= load_separate_debug_info (filename
,
11398 & debug_displays
[gnu_debugaltlink
].section
,
11399 parse_gnu_debugaltlink
,
11400 check_gnu_debugaltlink
,
11405 assert (handle
== first_separate_info
->handle
);
11406 check_for_and_load_links (first_separate_info
->handle
,
11407 first_separate_info
->filename
);
11411 if (load_debug_section (gnu_debuglink
, file
))
11413 unsigned long crc32
;
11415 handle
= load_separate_debug_info (filename
,
11416 & debug_displays
[gnu_debuglink
].section
,
11417 parse_gnu_debuglink
,
11418 check_gnu_debuglink
,
11423 assert (handle
== first_separate_info
->handle
);
11424 check_for_and_load_links (first_separate_info
->handle
,
11425 first_separate_info
->filename
);
11429 load_debug_sup_file (filename
, file
);
11432 /* Load the separate debug info file(s) attached to FILE, if any exist.
11433 Returns TRUE if any were found, FALSE otherwise.
11434 If TRUE is returned then the linked list starting at first_separate_info
11435 will be populated with open file handles. */
11438 load_separate_debug_files (void * file
, const char * filename
)
11440 /* Skip this operation if we are not interested in debug links. */
11441 if (! do_follow_links
&& ! do_debug_links
)
11444 /* See if there are any dwo links. */
11445 if (load_debug_section (str
, file
)
11446 && load_debug_section (abbrev
, file
)
11447 && load_debug_section (info
, file
))
11451 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11454 bool introduced
= false;
11456 const char *dir
= NULL
;
11457 const char *id
= NULL
;
11458 const char *name
= NULL
;
11460 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11462 /* Accumulate NAME, DIR and ID fields. */
11463 switch (dwinfo
->type
)
11467 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11468 name
= dwinfo
->value
;
11472 /* There can be multiple DW_AT_comp_dir entries in a CU,
11473 so do not complain. */
11474 dir
= dwinfo
->value
;
11479 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11480 id
= dwinfo
->value
;
11484 error (_("Unexpected DWO INFO type"));
11488 /* If we have reached the end of our list, or we are changing
11489 CUs, then display the information that we have accumulated
11492 && (dwinfo
->next
== NULL
11493 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11495 if (do_debug_links
)
11499 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11500 debug_displays
[info
].section
.uncompressed_name
);
11504 printf (_(" Name: %s\n"), name
);
11505 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11507 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11509 printf (_(" ID: <not specified>\n"));
11513 if (do_follow_links
)
11514 load_dwo_file (filename
, name
, dir
, id
);
11516 name
= dir
= id
= NULL
;
11522 if (! do_follow_links
)
11523 /* The other debug links will be displayed by display_debug_links()
11524 so we do not need to do any further processing here. */
11527 /* FIXME: We do not check for the presence of both link sections in the same file. */
11528 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11529 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11531 check_for_and_load_links (file
, filename
);
11532 if (first_separate_info
!= NULL
)
11535 do_follow_links
= 0;
11540 free_debug_memory (void)
11544 free_all_abbrevs ();
11546 free (cu_abbrev_map
);
11547 cu_abbrev_map
= NULL
;
11548 next_free_abbrev_map_entry
= 0;
11552 shndx_pool_size
= 0;
11553 shndx_pool_used
= 0;
11561 memset (level_type_signed
, 0, sizeof level_type_signed
);
11562 cu_tu_indexes_read
= -1;
11564 for (i
= 0; i
< max
; i
++)
11565 free_debug_section ((enum dwarf_section_display_enum
) i
);
11567 if (debug_information
!= NULL
)
11569 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11571 if (debug_information
[i
].max_loc_offsets
)
11573 free (debug_information
[i
].loc_offsets
);
11574 free (debug_information
[i
].have_frame_base
);
11576 if (debug_information
[i
].max_range_lists
)
11577 free (debug_information
[i
].range_lists
);
11579 free (debug_information
);
11580 debug_information
= NULL
;
11581 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11585 separate_info
* next
;
11587 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11589 close_debug_file (d
->handle
);
11590 free ((void *) d
->filename
);
11594 first_separate_info
= NULL
;
11600 dwarf_select_sections_by_names (const char *names
)
11604 const char * option
;
11608 debug_dump_long_opts
;
11610 static const debug_dump_long_opts opts_table
[] =
11612 /* Please keep this table alpha- sorted. */
11613 { "Ranges", & do_debug_ranges
, 1 },
11614 { "abbrev", & do_debug_abbrevs
, 1 },
11615 { "addr", & do_debug_addr
, 1 },
11616 { "aranges", & do_debug_aranges
, 1 },
11617 { "cu_index", & do_debug_cu_index
, 1 },
11618 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11619 { "follow-links", & do_follow_links
, 1 },
11620 { "frames", & do_debug_frames
, 1 },
11621 { "frames-interp", & do_debug_frames_interp
, 1 },
11622 /* The special .gdb_index section. */
11623 { "gdb_index", & do_gdb_index
, 1 },
11624 { "info", & do_debug_info
, 1 },
11625 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11626 { "links", & do_debug_links
, 1 },
11627 { "loc", & do_debug_loc
, 1 },
11628 { "macro", & do_debug_macinfo
, 1 },
11629 { "no-follow-links", & do_follow_links
, 0 },
11630 { "pubnames", & do_debug_pubnames
, 1 },
11631 { "pubtypes", & do_debug_pubtypes
, 1 },
11632 /* This entry is for compatibility
11633 with earlier versions of readelf. */
11634 { "ranges", & do_debug_aranges
, 1 },
11635 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11636 { "str", & do_debug_str
, 1 },
11637 { "str-offsets", & do_debug_str_offsets
, 1 },
11638 /* These trace_* sections are used by Itanium VMS. */
11639 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11640 { "trace_aranges", & do_trace_aranges
, 1 },
11641 { "trace_info", & do_trace_info
, 1 },
11650 const debug_dump_long_opts
* entry
;
11652 for (entry
= opts_table
; entry
->option
; entry
++)
11654 size_t len
= strlen (entry
->option
);
11656 if (strncmp (p
, entry
->option
, len
) == 0
11657 && (p
[len
] == ',' || p
[len
] == '\0'))
11659 * entry
->variable
= entry
->val
;
11661 /* The --debug-dump=frames-interp option also
11662 enables the --debug-dump=frames option. */
11663 if (do_debug_frames_interp
)
11664 do_debug_frames
= 1;
11671 if (entry
->option
== NULL
)
11673 warn (_("Unrecognized debug option '%s'\n"), p
);
11674 p
= strchr (p
, ',');
11685 dwarf_select_sections_by_letters (const char *letters
)
11687 unsigned int lindex
= 0;
11689 while (letters
[lindex
])
11690 switch (letters
[lindex
++])
11692 case 'A': do_debug_addr
= 1; break;
11693 case 'a': do_debug_abbrevs
= 1; break;
11694 case 'c': do_debug_cu_index
= 1; break;
11695 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11696 case 'f': do_debug_frames
= 1; break;
11697 case 'g': do_gdb_index
= 1; break;
11698 case 'i': do_debug_info
= 1; break;
11699 case 'K': do_follow_links
= 1; break;
11700 case 'N': do_follow_links
= 0; break;
11701 case 'k': do_debug_links
= 1; break;
11702 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11703 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11704 case 'm': do_debug_macinfo
= 1; break;
11705 case 'O': do_debug_str_offsets
= 1; break;
11706 case 'o': do_debug_loc
= 1; break;
11707 case 'p': do_debug_pubnames
= 1; break;
11708 case 'R': do_debug_ranges
= 1; break;
11709 case 'r': do_debug_aranges
= 1; break;
11710 case 's': do_debug_str
= 1; break;
11711 case 'T': do_trace_aranges
= 1; break;
11712 case 't': do_debug_pubtypes
= 1; break;
11713 case 'U': do_trace_info
= 1; break;
11714 case 'u': do_trace_abbrevs
= 1; break;
11717 warn (_("Unrecognized debug option '%s'\n"), letters
);
11723 dwarf_select_sections_all (void)
11726 do_debug_abbrevs
= 1;
11727 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11728 do_debug_pubnames
= 1;
11729 do_debug_pubtypes
= 1;
11730 do_debug_aranges
= 1;
11731 do_debug_ranges
= 1;
11732 do_debug_frames
= 1;
11733 do_debug_macinfo
= 1;
11738 do_trace_abbrevs
= 1;
11739 do_trace_aranges
= 1;
11741 do_debug_cu_index
= 1;
11742 do_follow_links
= 1;
11743 do_debug_links
= 1;
11744 do_debug_str_offsets
= 1;
11747 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
11748 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
11750 /* N.B. The order here must match the order in section_display_enum. */
11752 struct dwarf_section_display debug_displays
[] =
11754 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11755 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
11756 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11757 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
11758 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11759 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
11760 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
11761 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11762 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11763 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11764 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11765 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11766 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11767 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11768 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
11769 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
11770 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11771 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11772 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11773 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11774 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
11775 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11776 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
11777 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
11778 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
11779 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
11780 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
11781 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
11782 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11783 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
11784 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11785 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11786 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11787 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11788 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
11789 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11790 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11791 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
11792 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11793 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11794 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11795 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11796 { { ".debug_sup", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
11797 /* Separate debug info files can containt their own .debug_str section,
11798 and this might be in *addition* to a .debug_str section already present
11799 in the main file. Hence we need to have two entries for .debug_str. */
11800 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11803 /* A static assertion. */
11804 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];