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
>= end
|| size
> (size_t) (end
- data
))
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 /* Read in a LEB128 encoded value starting at address DATA.
311 If SIGN is true, return a signed LEB128 value.
312 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
313 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
314 terminating byte was not found and with bit 1 set if the value
315 overflows a dwarf_vma.
316 No bytes will be read at address END or beyond. */
319 read_leb128 (unsigned char *data
,
320 const unsigned char *const end
,
322 unsigned int *length_return
,
325 dwarf_vma result
= 0;
326 unsigned int num_read
= 0;
327 unsigned int shift
= 0;
332 unsigned char byte
= *data
++;
333 unsigned char lost
, mask
;
337 if (shift
< CHAR_BIT
* sizeof (result
))
339 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
340 /* These bits overflowed. */
341 lost
= byte
^ (result
>> shift
);
342 /* And this is the mask of possible overflow bits. */
343 mask
= 0x7f ^ ((dwarf_vma
) 0x7f << shift
>> shift
);
351 if ((lost
& mask
) != (sign
&& (dwarf_signed_vma
) result
< 0 ? mask
: 0))
354 if ((byte
& 0x80) == 0)
357 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
358 result
|= -((dwarf_vma
) 1 << shift
);
363 if (length_return
!= NULL
)
364 *length_return
= num_read
;
365 if (status_return
!= NULL
)
366 *status_return
= status
;
371 /* Read AMOUNT bytes from PTR and store them in VAL.
372 Checks to make sure that the read will not reach or pass END.
373 FUNC chooses whether the value read is unsigned or signed, and may
374 be either byte_get or byte_get_signed. If INC is true, PTR is
375 incremented after reading the value.
376 This macro cannot protect against PTR values derived from user input.
377 The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
378 pointers is undefined behaviour. */
379 #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
382 size_t amount = (AMOUNT); \
383 if (sizeof (VAL) < amount) \
385 error (ngettext ("internal error: attempt to read %d byte " \
386 "of data in to %d sized variable", \
387 "internal error: attempt to read %d bytes " \
388 "of data in to %d sized variable", \
390 (int) amount, (int) sizeof (VAL)); \
391 amount = sizeof (VAL); \
393 if (ENABLE_CHECKING) \
394 assert ((PTR) <= (END)); \
395 size_t avail = (END) - (PTR); \
398 if (amount > avail) \
403 (VAL) = (FUNC) ((PTR), amount); \
409 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
410 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
412 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
413 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
415 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
416 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
418 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
419 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
421 typedef struct State_Machine_Registers
430 unsigned char op_index
;
431 unsigned char end_sequence
;
432 /* This variable hold the number of the last entry seen
433 in the File Table. */
434 unsigned int last_file_entry
;
437 static SMR state_machine_regs
;
440 reset_state_machine (int is_stmt
)
442 state_machine_regs
.address
= 0;
443 state_machine_regs
.view
= 0;
444 state_machine_regs
.op_index
= 0;
445 state_machine_regs
.file
= 1;
446 state_machine_regs
.line
= 1;
447 state_machine_regs
.column
= 0;
448 state_machine_regs
.is_stmt
= is_stmt
;
449 state_machine_regs
.basic_block
= 0;
450 state_machine_regs
.end_sequence
= 0;
451 state_machine_regs
.last_file_entry
= 0;
454 /* Handled an extend line op.
455 Returns the number of bytes read. */
458 process_extended_line_op (unsigned char * data
,
462 unsigned char op_code
;
463 size_t len
, header_len
;
465 unsigned char *orig_data
= data
;
468 READ_ULEB (len
, data
, end
);
469 header_len
= data
- orig_data
;
471 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
473 warn (_("Badly formed extended line op encountered!\n"));
479 printf (_(" Extended opcode %d: "), op_code
);
483 case DW_LNE_end_sequence
:
484 printf (_("End of Sequence\n\n"));
485 reset_state_machine (is_stmt
);
488 case DW_LNE_set_address
:
489 /* PR 17512: file: 002-100480-0.004. */
492 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
493 (unsigned long) len
- 1);
497 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
498 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
499 state_machine_regs
.address
= adr
;
500 state_machine_regs
.view
= 0;
501 state_machine_regs
.op_index
= 0;
504 case DW_LNE_define_file
:
505 printf (_("define new File Table entry\n"));
506 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
507 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
513 l
= strnlen ((char *) data
, end
- data
);
517 READ_ULEB (val
, data
, end
);
518 printf ("%s\t", dwarf_vmatoa ("u", val
));
519 READ_ULEB (val
, data
, end
);
520 printf ("%s\t", dwarf_vmatoa ("u", val
));
521 READ_ULEB (val
, data
, end
);
522 printf ("%s\t", dwarf_vmatoa ("u", val
));
523 printf ("%.*s\n\n", (int) l
, name
);
526 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
527 warn (_("DW_LNE_define_file: Bad opcode length\n"));
530 case DW_LNE_set_discriminator
:
531 READ_ULEB (val
, data
, end
);
532 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
536 case DW_LNE_HP_negate_is_UV_update
:
537 printf ("DW_LNE_HP_negate_is_UV_update\n");
539 case DW_LNE_HP_push_context
:
540 printf ("DW_LNE_HP_push_context\n");
542 case DW_LNE_HP_pop_context
:
543 printf ("DW_LNE_HP_pop_context\n");
545 case DW_LNE_HP_set_file_line_column
:
546 printf ("DW_LNE_HP_set_file_line_column\n");
548 case DW_LNE_HP_set_routine_name
:
549 printf ("DW_LNE_HP_set_routine_name\n");
551 case DW_LNE_HP_set_sequence
:
552 printf ("DW_LNE_HP_set_sequence\n");
554 case DW_LNE_HP_negate_post_semantics
:
555 printf ("DW_LNE_HP_negate_post_semantics\n");
557 case DW_LNE_HP_negate_function_exit
:
558 printf ("DW_LNE_HP_negate_function_exit\n");
560 case DW_LNE_HP_negate_front_end_logical
:
561 printf ("DW_LNE_HP_negate_front_end_logical\n");
563 case DW_LNE_HP_define_proc
:
564 printf ("DW_LNE_HP_define_proc\n");
566 case DW_LNE_HP_source_file_correlation
:
568 unsigned char *edata
= data
+ len
- 1;
570 printf ("DW_LNE_HP_source_file_correlation\n");
576 READ_ULEB (opc
, data
, edata
);
580 case DW_LNE_HP_SFC_formfeed
:
581 printf (" DW_LNE_HP_SFC_formfeed\n");
583 case DW_LNE_HP_SFC_set_listing_line
:
584 READ_ULEB (val
, data
, edata
);
585 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
586 dwarf_vmatoa ("u", val
));
588 case DW_LNE_HP_SFC_associate
:
589 printf (" DW_LNE_HP_SFC_associate ");
590 READ_ULEB (val
, data
, edata
);
591 printf ("(%s", dwarf_vmatoa ("u", val
));
592 READ_ULEB (val
, data
, edata
);
593 printf (",%s", dwarf_vmatoa ("u", val
));
594 READ_ULEB (val
, data
, edata
);
595 printf (",%s)\n", dwarf_vmatoa ("u", val
));
598 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
608 unsigned int rlen
= len
- 1;
610 if (op_code
>= DW_LNE_lo_user
611 /* The test against DW_LNW_hi_user is redundant due to
612 the limited range of the unsigned char data type used
614 /*&& op_code <= DW_LNE_hi_user*/)
615 printf (_("user defined: "));
617 printf (_("UNKNOWN: "));
618 printf (_("length %d ["), rlen
);
620 printf (" %02x", *data
++);
626 return len
+ header_len
;
629 static const unsigned char *
630 fetch_indirect_string (dwarf_vma offset
)
632 struct dwarf_section
*section
= &debug_displays
[str
].section
;
633 const unsigned char * ret
;
635 if (section
->start
== NULL
)
636 return (const unsigned char *) _("<no .debug_str section>");
638 if (offset
>= section
->size
)
640 warn (_("DW_FORM_strp offset too big: 0x%s\n"),
641 dwarf_vmatoa ("x", offset
));
642 return (const unsigned char *) _("<offset is too big>");
645 ret
= section
->start
+ offset
;
646 /* Unfortunately we cannot rely upon the .debug_str section ending with a
647 NUL byte. Since our caller is expecting to receive a well formed C
648 string we test for the lack of a terminating byte here. */
649 if (strnlen ((const char *) ret
, section
->size
- offset
)
650 == section
->size
- offset
)
651 ret
= (const unsigned char *)
652 _("<no NUL byte at end of .debug_str section>");
657 static const unsigned char *
658 fetch_indirect_line_string (dwarf_vma offset
)
660 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
661 const unsigned char * ret
;
663 if (section
->start
== NULL
)
664 return (const unsigned char *) _("<no .debug_line_str section>");
666 if (offset
>= section
->size
)
668 warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
669 dwarf_vmatoa ("x", offset
));
670 return (const unsigned char *) _("<offset is too big>");
673 ret
= section
->start
+ offset
;
674 /* Unfortunately we cannot rely upon the .debug_line_str section ending
675 with a NUL byte. Since our caller is expecting to receive a well formed
676 C string we test for the lack of a terminating byte here. */
677 if (strnlen ((const char *) ret
, section
->size
- offset
)
678 == section
->size
- offset
)
679 ret
= (const unsigned char *)
680 _("<no NUL byte at end of .debug_line_str section>");
686 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
687 dwarf_vma offset_size
, bool dwo
)
689 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
690 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
691 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
692 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
693 dwarf_vma index_offset
;
694 dwarf_vma str_offset
;
696 unsigned char *curr
= index_section
->start
;
697 unsigned char *end
= curr
+ index_section
->size
;
700 if (index_section
->start
== NULL
)
701 return (dwo
? _("<no .debug_str_offsets.dwo section>")
702 : _("<no .debug_str_offsets section>"));
704 if (str_section
->start
== NULL
)
705 return (dwo
? _("<no .debug_str.dwo section>")
706 : _("<no .debug_str section>"));
708 /* FIXME: We should cache the length... */
709 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
710 if (length
== 0xffffffff)
712 if (offset_size
!= 8)
713 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
714 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
716 else if (offset_size
!= 4)
718 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
723 /* This is probably an old style .debug_str_offset section which
724 just contains offsets and no header (and the first offset is 0). */
725 curr
= index_section
->start
;
726 length
= index_section
->size
;
730 /* Skip the version and padding bytes.
731 We assume that they are correct. */
742 && this_set
->section_sizes
[DW_SECT_STR_OFFSETS
] < length
)
743 length
= this_set
->section_sizes
[DW_SECT_STR_OFFSETS
];
745 if (length
> (dwarf_vma
) (end
- curr
))
747 warn (_("index table size too large for section %s vs %s\n"),
748 dwarf_vmatoa ("x", length
),
749 dwarf_vmatoa ("x", index_section
->size
));
753 if (length
< offset_size
)
755 warn (_("index table size %s is too small\n"),
756 dwarf_vmatoa ("x", length
));
757 return _("<table too small>");
761 index_offset
= idx
* offset_size
;
763 if (this_set
!= NULL
)
764 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
766 if (index_offset
>= length
767 || length
- index_offset
< offset_size
)
769 warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
770 dwarf_vmatoa ("x", index_offset
),
771 dwarf_vmatoa ("x", length
));
772 return _("<index offset is too big>");
775 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
776 str_offset
-= str_section
->address
;
777 if (str_offset
>= str_section
->size
)
779 warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
780 dwarf_vmatoa ("x", str_offset
));
781 return _("<indirect index offset is too big>");
784 ret
= (const char *) str_section
->start
+ str_offset
;
785 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
786 Since our caller is expecting to receive a well formed C string we test
787 for the lack of a terminating byte here. */
788 if (strnlen (ret
, str_section
->size
- str_offset
)
789 == str_section
->size
- str_offset
)
790 ret
= (const char *) _("<no NUL byte at end of section>");
796 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
798 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
800 if (section
->start
== NULL
)
801 return (_("<no .debug_addr section>"));
803 if (offset
+ bytes
> section
->size
)
805 warn (_("Offset into section %s too big: 0x%s\n"),
806 section
->name
, dwarf_vmatoa ("x", offset
));
807 return "<offset too big>";
810 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
814 /* FIXME: There are better and more efficient ways to handle
815 these structures. For now though, I just want something that
816 is simple to implement. */
817 /* Records a single attribute in an abbrev. */
818 typedef struct abbrev_attr
820 unsigned long attribute
;
822 bfd_signed_vma implicit_const
;
823 struct abbrev_attr
* next
;
827 /* Records a single abbrev. */
828 typedef struct abbrev_entry
830 unsigned long number
;
833 struct abbrev_attr
* first_attr
;
834 struct abbrev_attr
* last_attr
;
835 struct abbrev_entry
* next
;
839 /* Records a set of abbreviations. */
840 typedef struct abbrev_list
842 abbrev_entry
* first_abbrev
;
843 abbrev_entry
* last_abbrev
;
844 dwarf_vma abbrev_base
;
845 dwarf_vma abbrev_offset
;
846 struct abbrev_list
* next
;
847 unsigned char * start_of_next_abbrevs
;
851 /* Records all the abbrevs found so far. */
852 static struct abbrev_list
* abbrev_lists
= NULL
;
854 typedef struct abbrev_map
861 /* Maps between CU offsets and abbrev sets. */
862 static abbrev_map
* cu_abbrev_map
= NULL
;
863 static unsigned long num_abbrev_map_entries
= 0;
864 static unsigned long next_free_abbrev_map_entry
= 0;
866 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
867 #define ABBREV_MAP_ENTRIES_INCREMENT 8
870 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
872 if (cu_abbrev_map
== NULL
)
874 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
875 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
877 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
879 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
880 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
883 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
884 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
885 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
886 next_free_abbrev_map_entry
++;
890 free_all_abbrevs (void)
894 for (list
= abbrev_lists
; list
!= NULL
;)
896 abbrev_list
* next
= list
->next
;
897 abbrev_entry
* abbrv
;
899 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
901 abbrev_entry
* next_abbrev
= abbrv
->next
;
904 for (attr
= abbrv
->first_attr
; attr
;)
906 abbrev_attr
*next_attr
= attr
->next
;
924 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
926 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
928 list
->abbrev_base
= abbrev_base
;
929 list
->abbrev_offset
= abbrev_offset
;
931 list
->next
= abbrev_lists
;
938 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
939 dwarf_vma abbrev_offset
)
943 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
944 if (list
->abbrev_base
== abbrev_base
945 && list
->abbrev_offset
== abbrev_offset
)
951 /* Find the abbreviation map for the CU that includes OFFSET.
952 OFFSET is an absolute offset from the start of the .debug_info section. */
953 /* FIXME: This function is going to slow down readelf & objdump.
954 Consider using a better algorithm to mitigate this effect. */
957 find_abbrev_map_by_offset (dwarf_vma offset
)
961 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
962 if (cu_abbrev_map
[i
].start
<= offset
963 && cu_abbrev_map
[i
].end
> offset
)
964 return cu_abbrev_map
+ i
;
970 add_abbrev (unsigned long number
,
975 abbrev_entry
* entry
;
977 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
979 entry
->number
= number
;
981 entry
->children
= children
;
982 entry
->first_attr
= NULL
;
983 entry
->last_attr
= NULL
;
986 assert (list
!= NULL
);
988 if (list
->first_abbrev
== NULL
)
989 list
->first_abbrev
= entry
;
991 list
->last_abbrev
->next
= entry
;
993 list
->last_abbrev
= entry
;
997 add_abbrev_attr (unsigned long attribute
,
999 bfd_signed_vma implicit_const
,
1004 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1006 attr
->attribute
= attribute
;
1008 attr
->implicit_const
= implicit_const
;
1011 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1013 if (list
->last_abbrev
->first_attr
== NULL
)
1014 list
->last_abbrev
->first_attr
= attr
;
1016 list
->last_abbrev
->last_attr
->next
= attr
;
1018 list
->last_abbrev
->last_attr
= attr
;
1021 /* Processes the (partial) contents of a .debug_abbrev section.
1022 Returns NULL if the end of the section was encountered.
1023 Returns the address after the last byte read if the end of
1024 an abbreviation set was found. */
1026 static unsigned char *
1027 process_abbrev_set (struct dwarf_section
*section
,
1028 dwarf_vma abbrev_base
,
1029 dwarf_vma abbrev_size
,
1030 dwarf_vma abbrev_offset
,
1033 if (abbrev_base
>= section
->size
1034 || abbrev_size
> section
->size
- abbrev_base
)
1036 /* PR 17531: file:4bcd9ce9. */
1037 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
1038 "abbrev section size (%lx)\n"),
1039 (unsigned long) (abbrev_base
+ abbrev_size
),
1040 (unsigned long) section
->size
);
1043 if (abbrev_offset
>= abbrev_size
)
1045 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
1046 "abbrev section size (%lx)\n"),
1047 (unsigned long) abbrev_offset
,
1048 (unsigned long) abbrev_size
);
1052 unsigned char *start
= section
->start
+ abbrev_base
;
1053 unsigned char *end
= start
+ abbrev_size
;
1054 start
+= abbrev_offset
;
1057 unsigned long entry
;
1059 unsigned long attribute
;
1062 READ_ULEB (entry
, start
, end
);
1064 /* A single zero is supposed to end the set according
1065 to the standard. If there's more, then signal that to
1072 READ_ULEB (tag
, start
, end
);
1076 children
= *start
++;
1078 add_abbrev (entry
, tag
, children
, list
);
1083 /* Initialize it due to a false compiler warning. */
1084 bfd_signed_vma implicit_const
= -1;
1086 READ_ULEB (attribute
, start
, end
);
1090 READ_ULEB (form
, start
, end
);
1094 if (form
== DW_FORM_implicit_const
)
1096 READ_SLEB (implicit_const
, start
, end
);
1101 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1103 while (attribute
!= 0);
1106 /* Report the missing single zero which ends the section. */
1107 error (_(".debug_abbrev section not zero terminated\n"));
1113 get_TAG_name (unsigned long tag
)
1115 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1119 static char buffer
[100];
1121 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1122 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1124 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1132 get_FORM_name (unsigned long form
)
1137 return "DW_FORM value: 0";
1139 name
= get_DW_FORM_name (form
);
1142 static char buffer
[100];
1144 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1152 get_IDX_name (unsigned long idx
)
1154 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1158 static char buffer
[100];
1160 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1167 static unsigned char *
1168 display_block (unsigned char *data
,
1170 const unsigned char * const end
, char delimiter
)
1174 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1176 return (unsigned char *) end
;
1178 maxlen
= (dwarf_vma
) (end
- data
);
1179 length
= length
> maxlen
? maxlen
: length
;
1182 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1188 decode_location_expression (unsigned char * data
,
1189 unsigned int pointer_size
,
1190 unsigned int offset_size
,
1193 dwarf_vma cu_offset
,
1194 struct dwarf_section
* section
)
1198 dwarf_signed_vma svalue
;
1199 unsigned char *end
= data
+ length
;
1200 int need_frame_base
= 0;
1209 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1210 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1213 printf ("DW_OP_deref");
1216 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1217 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1220 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1221 printf ("DW_OP_const1s: %ld", (long) svalue
);
1224 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1225 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1228 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1229 printf ("DW_OP_const2s: %ld", (long) svalue
);
1232 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1233 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1236 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1237 printf ("DW_OP_const4s: %ld", (long) svalue
);
1240 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1241 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1242 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1243 printf ("%lu", (unsigned long) uvalue
);
1246 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1247 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1248 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1249 printf ("%ld", (long) svalue
);
1252 READ_ULEB (uvalue
, data
, end
);
1253 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1256 READ_SLEB (svalue
, data
, end
);
1257 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1260 printf ("DW_OP_dup");
1263 printf ("DW_OP_drop");
1266 printf ("DW_OP_over");
1269 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1270 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1273 printf ("DW_OP_swap");
1276 printf ("DW_OP_rot");
1279 printf ("DW_OP_xderef");
1282 printf ("DW_OP_abs");
1285 printf ("DW_OP_and");
1288 printf ("DW_OP_div");
1291 printf ("DW_OP_minus");
1294 printf ("DW_OP_mod");
1297 printf ("DW_OP_mul");
1300 printf ("DW_OP_neg");
1303 printf ("DW_OP_not");
1306 printf ("DW_OP_or");
1309 printf ("DW_OP_plus");
1311 case DW_OP_plus_uconst
:
1312 READ_ULEB (uvalue
, data
, end
);
1313 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1316 printf ("DW_OP_shl");
1319 printf ("DW_OP_shr");
1322 printf ("DW_OP_shra");
1325 printf ("DW_OP_xor");
1328 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1329 printf ("DW_OP_bra: %ld", (long) svalue
);
1332 printf ("DW_OP_eq");
1335 printf ("DW_OP_ge");
1338 printf ("DW_OP_gt");
1341 printf ("DW_OP_le");
1344 printf ("DW_OP_lt");
1347 printf ("DW_OP_ne");
1350 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1351 printf ("DW_OP_skip: %ld", (long) svalue
);
1386 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1421 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1422 regname (op
- DW_OP_reg0
, 1));
1457 READ_SLEB (svalue
, data
, end
);
1458 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1459 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1463 READ_ULEB (uvalue
, data
, end
);
1464 printf ("DW_OP_regx: %s (%s)",
1465 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1468 need_frame_base
= 1;
1469 READ_SLEB (svalue
, data
, end
);
1470 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1473 READ_ULEB (uvalue
, data
, end
);
1474 READ_SLEB (svalue
, data
, end
);
1475 printf ("DW_OP_bregx: %s (%s) %s",
1476 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1477 dwarf_vmatoa ("d", svalue
));
1480 READ_ULEB (uvalue
, data
, end
);
1481 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1483 case DW_OP_deref_size
:
1484 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1485 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1487 case DW_OP_xderef_size
:
1488 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1489 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1492 printf ("DW_OP_nop");
1495 /* DWARF 3 extensions. */
1496 case DW_OP_push_object_address
:
1497 printf ("DW_OP_push_object_address");
1500 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1501 this ought to be an 8-byte wide computation. */
1502 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1503 printf ("DW_OP_call2: <0x%s>",
1504 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1507 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1508 this ought to be an 8-byte wide computation. */
1509 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1510 printf ("DW_OP_call4: <0x%s>",
1511 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1513 case DW_OP_call_ref
:
1514 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1515 this ought to be an 8-byte wide computation. */
1516 if (dwarf_version
== -1)
1518 printf (_("(DW_OP_call_ref in frame info)"));
1519 /* No way to tell where the next op is, so just bail. */
1520 return need_frame_base
;
1522 if (dwarf_version
== 2)
1524 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1528 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1530 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1532 case DW_OP_form_tls_address
:
1533 printf ("DW_OP_form_tls_address");
1535 case DW_OP_call_frame_cfa
:
1536 printf ("DW_OP_call_frame_cfa");
1538 case DW_OP_bit_piece
:
1539 printf ("DW_OP_bit_piece: ");
1540 READ_ULEB (uvalue
, data
, end
);
1541 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1542 READ_ULEB (uvalue
, data
, end
);
1543 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1546 /* DWARF 4 extensions. */
1547 case DW_OP_stack_value
:
1548 printf ("DW_OP_stack_value");
1551 case DW_OP_implicit_value
:
1552 printf ("DW_OP_implicit_value");
1553 READ_ULEB (uvalue
, data
, end
);
1554 data
= display_block (data
, uvalue
, end
, ' ');
1557 /* GNU extensions. */
1558 case DW_OP_GNU_push_tls_address
:
1559 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1561 case DW_OP_GNU_uninit
:
1562 printf ("DW_OP_GNU_uninit");
1563 /* FIXME: Is there data associated with this OP ? */
1565 case DW_OP_GNU_encoded_addr
:
1572 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1574 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1575 print_dwarf_vma (addr
, pointer_size
);
1578 case DW_OP_implicit_pointer
:
1579 case DW_OP_GNU_implicit_pointer
:
1580 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1581 this ought to be an 8-byte wide computation. */
1582 if (dwarf_version
== -1)
1584 printf (_("(%s in frame info)"),
1585 (op
== DW_OP_implicit_pointer
1586 ? "DW_OP_implicit_pointer"
1587 : "DW_OP_GNU_implicit_pointer"));
1588 /* No way to tell where the next op is, so just bail. */
1589 return need_frame_base
;
1591 if (dwarf_version
== 2)
1593 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1597 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1599 READ_SLEB (svalue
, data
, end
);
1600 printf ("%s: <0x%s> %s",
1601 (op
== DW_OP_implicit_pointer
1602 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1603 dwarf_vmatoa ("x", uvalue
),
1604 dwarf_vmatoa ("d", svalue
));
1606 case DW_OP_entry_value
:
1607 case DW_OP_GNU_entry_value
:
1608 READ_ULEB (uvalue
, data
, end
);
1609 /* PR 17531: file: 0cc9cd00. */
1610 if (uvalue
> (dwarf_vma
) (end
- data
))
1611 uvalue
= end
- data
;
1612 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1613 : "DW_OP_GNU_entry_value"));
1614 if (decode_location_expression (data
, pointer_size
, offset_size
,
1615 dwarf_version
, uvalue
,
1616 cu_offset
, section
))
1617 need_frame_base
= 1;
1621 case DW_OP_const_type
:
1622 case DW_OP_GNU_const_type
:
1623 READ_ULEB (uvalue
, data
, end
);
1624 printf ("%s: <0x%s> ",
1625 (op
== DW_OP_const_type
? "DW_OP_const_type"
1626 : "DW_OP_GNU_const_type"),
1627 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1628 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1629 data
= display_block (data
, uvalue
, end
, ' ');
1631 case DW_OP_regval_type
:
1632 case DW_OP_GNU_regval_type
:
1633 READ_ULEB (uvalue
, data
, end
);
1634 printf ("%s: %s (%s)",
1635 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1636 : "DW_OP_GNU_regval_type"),
1637 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1638 READ_ULEB (uvalue
, data
, end
);
1639 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1641 case DW_OP_deref_type
:
1642 case DW_OP_GNU_deref_type
:
1643 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1645 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1646 : "DW_OP_GNU_deref_type"),
1648 READ_ULEB (uvalue
, data
, end
);
1649 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1652 case DW_OP_GNU_convert
:
1653 READ_ULEB (uvalue
, data
, end
);
1654 printf ("%s <0x%s>",
1655 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1656 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1658 case DW_OP_reinterpret
:
1659 case DW_OP_GNU_reinterpret
:
1660 READ_ULEB (uvalue
, data
, end
);
1661 printf ("%s <0x%s>",
1662 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1663 : "DW_OP_GNU_reinterpret"),
1664 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1666 case DW_OP_GNU_parameter_ref
:
1667 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1668 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1669 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1671 case DW_OP_GNU_addr_index
:
1672 READ_ULEB (uvalue
, data
, end
);
1673 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1675 case DW_OP_GNU_const_index
:
1676 READ_ULEB (uvalue
, data
, end
);
1677 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1679 case DW_OP_GNU_variable_value
:
1680 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1681 this ought to be an 8-byte wide computation. */
1682 if (dwarf_version
== -1)
1684 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1685 /* No way to tell where the next op is, so just bail. */
1686 return need_frame_base
;
1688 if (dwarf_version
== 2)
1690 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1694 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1696 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1699 /* HP extensions. */
1700 case DW_OP_HP_is_value
:
1701 printf ("DW_OP_HP_is_value");
1702 /* FIXME: Is there data associated with this OP ? */
1704 case DW_OP_HP_fltconst4
:
1705 printf ("DW_OP_HP_fltconst4");
1706 /* FIXME: Is there data associated with this OP ? */
1708 case DW_OP_HP_fltconst8
:
1709 printf ("DW_OP_HP_fltconst8");
1710 /* FIXME: Is there data associated with this OP ? */
1712 case DW_OP_HP_mod_range
:
1713 printf ("DW_OP_HP_mod_range");
1714 /* FIXME: Is there data associated with this OP ? */
1716 case DW_OP_HP_unmod_range
:
1717 printf ("DW_OP_HP_unmod_range");
1718 /* FIXME: Is there data associated with this OP ? */
1721 printf ("DW_OP_HP_tls");
1722 /* FIXME: Is there data associated with this OP ? */
1725 /* PGI (STMicroelectronics) extensions. */
1726 case DW_OP_PGI_omp_thread_num
:
1727 /* Pushes the thread number for the current thread as it would be
1728 returned by the standard OpenMP library function:
1729 omp_get_thread_num(). The "current thread" is the thread for
1730 which the expression is being evaluated. */
1731 printf ("DW_OP_PGI_omp_thread_num");
1735 if (op
>= DW_OP_lo_user
1736 && op
<= DW_OP_hi_user
)
1737 printf (_("(User defined location op 0x%x)"), op
);
1739 printf (_("(Unknown location op 0x%x)"), op
);
1740 /* No way to tell where the next op is, so just bail. */
1741 return need_frame_base
;
1744 /* Separate the ops. */
1749 return need_frame_base
;
1752 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1753 This is used for DWARF package files. */
1755 static struct cu_tu_set
*
1756 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1758 struct cu_tu_set
*p
;
1760 unsigned int dw_sect
;
1766 dw_sect
= DW_SECT_TYPES
;
1772 dw_sect
= DW_SECT_INFO
;
1776 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1785 fetch_alt_indirect_string (dwarf_vma offset
)
1789 if (! do_follow_links
)
1792 if (first_separate_info
== NULL
)
1793 return _("<no links available>");
1795 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1797 struct dwarf_section
* section
;
1800 if (! load_debug_section (separate_debug_str
, i
->handle
))
1803 section
= &debug_displays
[separate_debug_str
].section
;
1805 if (section
->start
== NULL
)
1808 if (offset
>= section
->size
)
1811 ret
= (const char *) (section
->start
+ offset
);
1812 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1813 NUL byte. Since our caller is expecting to receive a well formed C
1814 string we test for the lack of a terminating byte here. */
1815 if (strnlen ((const char *) ret
, section
->size
- offset
)
1816 == section
->size
- offset
)
1817 return _("<no NUL byte at end of alt .debug_str section>");
1822 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1823 dwarf_vmatoa ("x", offset
));
1824 return _("<offset is too big>");
1828 get_AT_name (unsigned long attribute
)
1833 return "DW_AT value: 0";
1835 /* One value is shared by the MIPS and HP extensions: */
1836 if (attribute
== DW_AT_MIPS_fde
)
1837 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1839 name
= get_DW_AT_name (attribute
);
1843 static char buffer
[100];
1845 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1854 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1856 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1858 dwinfo
->type
= type
;
1859 dwinfo
->value
= value
;
1860 dwinfo
->cu_offset
= cu_offset
;
1861 dwinfo
->next
= first_dwo_info
;
1862 first_dwo_info
= dwinfo
;
1866 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1868 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1872 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1874 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1878 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1880 add_dwo_info (id
, cu_offset
, DWO_ID
);
1884 free_dwo_info (void)
1889 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1891 next
= dwinfo
->next
;
1894 first_dwo_info
= NULL
;
1897 /* Ensure that START + UVALUE is less than END.
1898 Return an adjusted UVALUE if necessary to ensure this relationship. */
1900 static inline dwarf_vma
1901 check_uvalue (const unsigned char * start
,
1903 const unsigned char * end
)
1905 dwarf_vma max_uvalue
= end
- start
;
1907 /* See PR 17512: file: 008-103549-0.001:0.1.
1908 and PR 24829 for examples of where these tests are triggered. */
1909 if (uvalue
> max_uvalue
)
1911 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1912 uvalue
= max_uvalue
;
1918 static unsigned char *
1919 skip_attr_bytes (unsigned long form
,
1920 unsigned char *data
,
1922 dwarf_vma pointer_size
,
1923 dwarf_vma offset_size
,
1925 dwarf_vma
*value_return
)
1927 dwarf_signed_vma svalue
;
1928 dwarf_vma uvalue
= 0;
1935 case DW_FORM_ref_addr
:
1936 if (dwarf_version
== 2)
1937 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1938 else if (dwarf_version
> 2)
1939 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1945 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1949 case DW_FORM_line_strp
:
1950 case DW_FORM_sec_offset
:
1951 case DW_FORM_GNU_ref_alt
:
1952 case DW_FORM_GNU_strp_alt
:
1953 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1956 case DW_FORM_flag_present
:
1964 case DW_FORM_addrx1
:
1965 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1969 case DW_FORM_addrx3
:
1970 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1976 case DW_FORM_addrx2
:
1977 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1983 case DW_FORM_addrx4
:
1984 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1988 READ_SLEB (svalue
, data
, end
);
1992 case DW_FORM_ref_udata
:
1994 case DW_FORM_GNU_str_index
:
1996 case DW_FORM_GNU_addr_index
:
1998 READ_ULEB (uvalue
, data
, end
);
2002 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2006 case DW_FORM_ref_sig8
:
2010 case DW_FORM_data16
:
2014 case DW_FORM_string
:
2015 inc
= strnlen ((char *) data
, end
- data
) + 1;
2019 case DW_FORM_exprloc
:
2020 READ_ULEB (uvalue
, data
, end
);
2024 case DW_FORM_block1
:
2025 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2029 case DW_FORM_block2
:
2030 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2034 case DW_FORM_block4
:
2035 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2039 case DW_FORM_indirect
:
2040 READ_ULEB (form
, data
, end
);
2041 if (form
== DW_FORM_implicit_const
)
2042 SKIP_ULEB (data
, end
);
2043 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2044 dwarf_version
, value_return
);
2050 * value_return
= uvalue
;
2051 if (inc
<= (dwarf_vma
) (end
- data
))
2058 /* Given form FORM with value UVALUE, locate and return the abbreviation
2059 associated with it. */
2061 static abbrev_entry
*
2062 get_type_abbrev_from_form (unsigned long form
,
2063 unsigned long uvalue
,
2064 dwarf_vma cu_offset
,
2065 const struct dwarf_section
* section
,
2066 unsigned long * abbrev_num_return
,
2067 unsigned char ** data_return
,
2068 unsigned long * cu_offset_return
)
2070 unsigned long abbrev_number
;
2072 abbrev_entry
* entry
;
2073 unsigned char * data
;
2075 if (abbrev_num_return
!= NULL
)
2076 * abbrev_num_return
= 0;
2077 if (data_return
!= NULL
)
2078 * data_return
= NULL
;
2082 case DW_FORM_GNU_ref_alt
:
2083 case DW_FORM_ref_sig8
:
2084 /* FIXME: We are unable to handle this form at the moment. */
2087 case DW_FORM_ref_addr
:
2088 if (uvalue
>= section
->size
)
2090 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2091 uvalue
, (long) section
->size
, section
->name
);
2096 case DW_FORM_ref_sup4
:
2097 case DW_FORM_ref_sup8
:
2104 case DW_FORM_ref_udata
:
2105 if (uvalue
+ cu_offset
> section
->size
)
2107 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2108 uvalue
, (long) cu_offset
, (long) section
->size
);
2111 uvalue
+= cu_offset
;
2114 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2117 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2121 data
= (unsigned char *) section
->start
+ uvalue
;
2122 map
= find_abbrev_map_by_offset (uvalue
);
2126 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2129 if (map
->list
== NULL
)
2131 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2135 if (cu_offset_return
!= NULL
)
2137 if (form
== DW_FORM_ref_addr
)
2138 * cu_offset_return
= map
->start
;
2140 * cu_offset_return
= cu_offset
;
2143 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2145 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2146 if (entry
->number
== abbrev_number
)
2149 if (abbrev_num_return
!= NULL
)
2150 * abbrev_num_return
= abbrev_number
;
2152 if (data_return
!= NULL
)
2153 * data_return
= data
;
2156 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2161 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2162 can be determined to be a signed type. The data for ENTRY can be
2163 found starting at DATA. */
2166 get_type_signedness (abbrev_entry
*entry
,
2167 const struct dwarf_section
*section
,
2168 unsigned char *data
,
2170 dwarf_vma cu_offset
,
2171 dwarf_vma pointer_size
,
2172 dwarf_vma offset_size
,
2175 unsigned int nesting
)
2179 * is_signed
= false;
2181 #define MAX_NESTING 20
2182 if (nesting
> MAX_NESTING
)
2184 /* FIXME: Warn - or is this expected ?
2185 NB/ We need to avoid infinite recursion. */
2189 for (attr
= entry
->first_attr
;
2190 attr
!= NULL
&& attr
->attribute
;
2193 unsigned char * orig_data
= data
;
2194 dwarf_vma uvalue
= 0;
2196 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2197 offset_size
, dwarf_version
, & uvalue
);
2201 switch (attr
->attribute
)
2203 case DW_AT_linkage_name
:
2207 if (attr
->form
== DW_FORM_strp
)
2208 printf (", %s", fetch_indirect_string (uvalue
));
2209 else if (attr
->form
== DW_FORM_string
)
2210 printf (", %s", orig_data
);
2217 abbrev_entry
* type_abbrev
;
2218 unsigned char * type_data
;
2219 unsigned long type_cu_offset
;
2221 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2225 NULL
/* abbrev num return */,
2228 if (type_abbrev
== NULL
)
2231 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2232 pointer_size
, offset_size
, dwarf_version
,
2233 is_signed
, nesting
+ 1);
2237 case DW_AT_encoding
:
2238 /* Determine signness. */
2241 case DW_ATE_address
:
2242 /* FIXME - some architectures have signed addresses. */
2243 case DW_ATE_boolean
:
2244 case DW_ATE_unsigned
:
2245 case DW_ATE_unsigned_char
:
2246 case DW_ATE_unsigned_fixed
:
2247 * is_signed
= false;
2251 case DW_ATE_complex_float
:
2254 case DW_ATE_signed_char
:
2255 case DW_ATE_imaginary_float
:
2256 case DW_ATE_decimal_float
:
2257 case DW_ATE_signed_fixed
:
2267 read_and_print_leb128 (unsigned char *data
,
2268 unsigned int *bytes_read
,
2269 unsigned const char *end
,
2273 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2275 report_leb_status (status
, __FILE__
, __LINE__
);
2277 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2281 display_discr_list (unsigned long form
,
2283 unsigned char * data
,
2284 unsigned const char * end
,
2289 printf ("[default]");
2296 case DW_FORM_block1
:
2297 case DW_FORM_block2
:
2298 case DW_FORM_block4
:
2299 /* Move data pointer back to the start of the byte array. */
2303 printf ("<corrupt>\n");
2304 warn (_("corrupt discr_list - not using a block form\n"));
2310 printf ("<corrupt>\n");
2311 warn (_("corrupt discr_list - block not long enough\n"));
2316 (level
> 0 && level
<= MAX_CU_NESTING
)
2317 ? level_type_signed
[level
- 1] : false;
2322 unsigned char discriminant
;
2323 unsigned int bytes_read
;
2325 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2328 assert (uvalue
> 0);
2329 switch (discriminant
)
2333 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2334 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2335 uvalue
-= bytes_read
;
2341 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2342 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2343 uvalue
-= bytes_read
;
2347 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2348 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2349 uvalue
-= bytes_read
;
2354 printf ("<corrupt>\n");
2355 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2365 printf (")(signed)");
2367 printf (")(unsigned)");
2370 static unsigned char *
2371 read_and_display_attr_value (unsigned long attribute
,
2373 dwarf_signed_vma implicit_const
,
2374 unsigned char * start
,
2375 unsigned char * data
,
2376 unsigned char * end
,
2377 dwarf_vma cu_offset
,
2378 dwarf_vma pointer_size
,
2379 dwarf_vma offset_size
,
2381 debug_info
* debug_info_p
,
2383 struct dwarf_section
* section
,
2384 struct cu_tu_set
* this_set
,
2388 dwarf_signed_vma svalue
;
2389 dwarf_vma uvalue
= 0;
2390 dwarf_vma uvalue_hi
= 0;
2391 unsigned char *block_start
= NULL
;
2392 unsigned char *orig_data
= data
;
2394 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2396 warn (_("Corrupt attribute\n"));
2400 if (do_wide
&& ! do_loc
)
2402 /* PR 26847: Display the name of the form. */
2403 const char * name
= get_FORM_name (form
);
2405 /* For convenience we skip the DW_FORM_ prefix to the name. */
2407 name
+= 8; /* strlen ("DW_FORM_") */
2408 printf ("%c(%s)", delimiter
, name
);
2416 case DW_FORM_ref_addr
:
2417 if (dwarf_version
== 2)
2418 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2419 else if (dwarf_version
> 2)
2420 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2422 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2426 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2429 case DW_FORM_strp_sup
:
2431 case DW_FORM_line_strp
:
2432 case DW_FORM_sec_offset
:
2433 case DW_FORM_GNU_ref_alt
:
2434 case DW_FORM_GNU_strp_alt
:
2435 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2438 case DW_FORM_flag_present
:
2446 case DW_FORM_addrx1
:
2447 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2453 case DW_FORM_addrx2
:
2454 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2458 case DW_FORM_addrx3
:
2459 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2462 case DW_FORM_ref_sup4
:
2466 case DW_FORM_addrx4
:
2467 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2470 case DW_FORM_ref_sup8
:
2473 case DW_FORM_ref_sig8
:
2474 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2477 case DW_FORM_data16
:
2478 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2479 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2480 if (byte_get
!= byte_get_little_endian
)
2482 dwarf_vma utmp
= uvalue
;
2489 READ_SLEB (svalue
, data
, end
);
2493 case DW_FORM_GNU_str_index
:
2495 case DW_FORM_ref_udata
:
2497 case DW_FORM_GNU_addr_index
:
2499 READ_ULEB (uvalue
, data
, end
);
2502 case DW_FORM_indirect
:
2503 READ_ULEB (form
, data
, end
);
2505 printf ("%c%s", delimiter
, get_FORM_name (form
));
2506 if (form
== DW_FORM_implicit_const
)
2507 READ_SLEB (implicit_const
, data
, end
);
2508 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2510 cu_offset
, pointer_size
,
2511 offset_size
, dwarf_version
,
2512 debug_info_p
, do_loc
,
2513 section
, this_set
, delimiter
, level
);
2518 case DW_FORM_ref_addr
:
2520 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2523 case DW_FORM_GNU_ref_alt
:
2527 /* We have already printed the form name. */
2528 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2530 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2532 /* FIXME: Follow the reference... */
2538 case DW_FORM_ref_sup4
:
2539 case DW_FORM_ref_udata
:
2541 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2546 case DW_FORM_sec_offset
:
2548 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2551 case DW_FORM_flag_present
:
2558 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2561 case DW_FORM_implicit_const
:
2563 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2566 case DW_FORM_ref_sup8
:
2571 dwarf_vma utmp
= uvalue
;
2572 if (form
== DW_FORM_ref8
)
2574 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", utmp
));
2578 case DW_FORM_data16
:
2581 uvalue_hi
== 0 ? "" : dwarf_vmatoa ("x", uvalue_hi
),
2582 dwarf_vmatoa_1 ("x", uvalue
, uvalue_hi
== 0 ? 0 : 8));
2585 case DW_FORM_string
:
2587 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2588 data
+= strnlen ((char *) data
, end
- data
);
2594 case DW_FORM_exprloc
:
2595 READ_ULEB (uvalue
, data
, end
);
2598 if (block_start
>= end
)
2600 warn (_("Block ends prematurely\n"));
2605 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2608 data
= block_start
+ uvalue
;
2610 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2613 case DW_FORM_block1
:
2614 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2617 case DW_FORM_block2
:
2618 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2621 case DW_FORM_block4
:
2622 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2629 /* We have already displayed the form name. */
2630 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2631 dwarf_vmatoa ("x", uvalue
),
2632 fetch_indirect_string (uvalue
));
2634 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2635 dwarf_vmatoa ("x", uvalue
),
2636 fetch_indirect_string (uvalue
));
2640 case DW_FORM_line_strp
:
2644 /* We have already displayed the form name. */
2645 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2646 dwarf_vmatoa ("x", uvalue
),
2647 fetch_indirect_line_string (uvalue
));
2649 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2650 dwarf_vmatoa ("x", uvalue
),
2651 fetch_indirect_line_string (uvalue
));
2655 case DW_FORM_GNU_str_index
:
2663 const char *suffix
= strrchr (section
->name
, '.');
2664 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2667 /* We have already displayed the form name. */
2668 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2669 dwarf_vmatoa ("x", uvalue
),
2670 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2672 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2673 dwarf_vmatoa ("x", uvalue
),
2674 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2678 case DW_FORM_GNU_strp_alt
:
2682 /* We have already displayed the form name. */
2683 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2684 dwarf_vmatoa ("x", uvalue
),
2685 fetch_alt_indirect_string (uvalue
));
2687 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2688 dwarf_vmatoa ("x", uvalue
),
2689 fetch_alt_indirect_string (uvalue
));
2693 case DW_FORM_indirect
:
2694 /* Handled above. */
2697 case DW_FORM_ref_sig8
:
2699 printf ("%c%s: 0x%s", delimiter
, do_wide
? "" : "signature",
2700 dwarf_vmatoa ("x", uvalue
));
2703 case DW_FORM_GNU_addr_index
:
2705 case DW_FORM_addrx1
:
2706 case DW_FORM_addrx2
:
2707 case DW_FORM_addrx3
:
2708 case DW_FORM_addrx4
:
2714 if (debug_info_p
== NULL
)
2716 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2719 base
= debug_info_p
->addr_base
;
2721 offset
= base
+ uvalue
* pointer_size
;
2724 /* We have already displayed the form name. */
2725 printf (_("%c(index: 0x%s): %s"), delimiter
,
2726 dwarf_vmatoa ("x", uvalue
),
2727 fetch_indexed_value (offset
, pointer_size
));
2729 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2730 dwarf_vmatoa ("x", uvalue
),
2731 fetch_indexed_value (offset
, pointer_size
));
2735 case DW_FORM_strp_sup
:
2737 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2741 warn (_("Unrecognized form: 0x%lx\n"), form
);
2745 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2746 && num_debug_info_entries
== 0
2747 && debug_info_p
!= NULL
)
2751 case DW_AT_frame_base
:
2752 have_frame_base
= 1;
2754 case DW_AT_location
:
2755 case DW_AT_GNU_locviews
:
2756 case DW_AT_string_length
:
2757 case DW_AT_return_addr
:
2758 case DW_AT_data_member_location
:
2759 case DW_AT_vtable_elem_location
:
2761 case DW_AT_static_link
:
2762 case DW_AT_use_location
:
2763 case DW_AT_call_value
:
2764 case DW_AT_GNU_call_site_value
:
2765 case DW_AT_call_data_value
:
2766 case DW_AT_GNU_call_site_data_value
:
2767 case DW_AT_call_target
:
2768 case DW_AT_GNU_call_site_target
:
2769 case DW_AT_call_target_clobbered
:
2770 case DW_AT_GNU_call_site_target_clobbered
:
2771 if ((dwarf_version
< 4
2772 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2773 || form
== DW_FORM_sec_offset
)
2775 /* Process location list. */
2776 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2777 unsigned int num
= debug_info_p
->num_loc_offsets
;
2779 if (lmax
== 0 || num
>= lmax
)
2782 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2783 xcrealloc (debug_info_p
->loc_offsets
,
2784 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2785 debug_info_p
->loc_views
= (dwarf_vma
*)
2786 xcrealloc (debug_info_p
->loc_views
,
2787 lmax
, sizeof (*debug_info_p
->loc_views
));
2788 debug_info_p
->have_frame_base
= (int *)
2789 xcrealloc (debug_info_p
->have_frame_base
,
2790 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2791 debug_info_p
->max_loc_offsets
= lmax
;
2793 if (this_set
!= NULL
)
2794 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2795 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2796 if (attribute
!= DW_AT_GNU_locviews
)
2798 /* Corrupt DWARF info can produce more offsets than views.
2799 See PR 23062 for an example. */
2800 if (debug_info_p
->num_loc_offsets
2801 > debug_info_p
->num_loc_views
)
2802 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2805 debug_info_p
->loc_offsets
[num
] = uvalue
;
2806 debug_info_p
->num_loc_offsets
++;
2811 assert (debug_info_p
->num_loc_views
<= num
);
2812 num
= debug_info_p
->num_loc_views
;
2813 if (num
> debug_info_p
->num_loc_offsets
)
2814 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2817 debug_info_p
->loc_views
[num
] = uvalue
;
2818 debug_info_p
->num_loc_views
++;
2825 if (need_base_address
)
2826 debug_info_p
->base_address
= uvalue
;
2829 case DW_AT_GNU_addr_base
:
2830 case DW_AT_addr_base
:
2831 debug_info_p
->addr_base
= uvalue
;
2834 case DW_AT_GNU_ranges_base
:
2835 debug_info_p
->ranges_base
= uvalue
;
2839 if ((dwarf_version
< 4
2840 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2841 || form
== DW_FORM_sec_offset
)
2843 /* Process range list. */
2844 unsigned int lmax
= debug_info_p
->max_range_lists
;
2845 unsigned int num
= debug_info_p
->num_range_lists
;
2847 if (lmax
== 0 || num
>= lmax
)
2850 debug_info_p
->range_lists
= (dwarf_vma
*)
2851 xcrealloc (debug_info_p
->range_lists
,
2852 lmax
, sizeof (*debug_info_p
->range_lists
));
2853 debug_info_p
->max_range_lists
= lmax
;
2855 debug_info_p
->range_lists
[num
] = uvalue
;
2856 debug_info_p
->num_range_lists
++;
2860 case DW_AT_GNU_dwo_name
:
2861 case DW_AT_dwo_name
:
2866 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2868 case DW_FORM_GNU_strp_alt
:
2869 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2871 case DW_FORM_GNU_str_index
:
2877 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2879 case DW_FORM_string
:
2880 add_dwo_name ((const char *) orig_data
, cu_offset
);
2883 warn (_("Unsupported form (%s) for attribute %s\n"),
2884 get_FORM_name (form
), get_AT_name (attribute
));
2889 case DW_AT_comp_dir
:
2890 /* FIXME: Also extract a build-id in a CU/TU. */
2895 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2897 case DW_FORM_GNU_strp_alt
:
2898 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2900 case DW_FORM_line_strp
:
2901 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2903 case DW_FORM_GNU_str_index
:
2909 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2911 case DW_FORM_string
:
2912 add_dwo_dir ((const char *) orig_data
, cu_offset
);
2915 warn (_("Unsupported form (%s) for attribute %s\n"),
2916 get_FORM_name (form
), get_AT_name (attribute
));
2921 case DW_AT_GNU_dwo_id
:
2926 /* FIXME: Record the length of the ID as well ? */
2927 add_dwo_id ((const char *) (data
- 8), cu_offset
);
2930 warn (_("Unsupported form (%s) for attribute %s\n"),
2931 get_FORM_name (form
), get_AT_name (attribute
));
2941 if (do_loc
|| attribute
== 0)
2944 /* For some attributes we can display further information. */
2948 if (level
>= 0 && level
< MAX_CU_NESTING
2949 && uvalue
< (size_t) (end
- start
))
2951 bool is_signed
= false;
2952 abbrev_entry
*type_abbrev
;
2953 unsigned char *type_data
;
2954 unsigned long type_cu_offset
;
2956 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
2957 section
, NULL
, & type_data
, & type_cu_offset
);
2958 if (type_abbrev
!= NULL
)
2960 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2961 pointer_size
, offset_size
, dwarf_version
,
2964 level_type_signed
[level
] = is_signed
;
2972 case DW_INL_not_inlined
:
2973 printf (_("(not inlined)"));
2975 case DW_INL_inlined
:
2976 printf (_("(inlined)"));
2978 case DW_INL_declared_not_inlined
:
2979 printf (_("(declared as inline but ignored)"));
2981 case DW_INL_declared_inlined
:
2982 printf (_("(declared as inline and inlined)"));
2985 printf (_(" (Unknown inline attribute value: %s)"),
2986 dwarf_vmatoa ("x", uvalue
));
2991 case DW_AT_language
:
2995 /* Ordered by the numeric value of these constants. */
2996 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2997 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2998 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2999 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3000 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3001 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3002 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3003 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3004 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3005 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3006 /* DWARF 2.1 values. */
3007 case DW_LANG_Java
: printf ("(Java)"); break;
3008 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3009 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3010 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3011 /* DWARF 3 values. */
3012 case DW_LANG_PLI
: printf ("(PLI)"); break;
3013 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3014 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3015 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3016 case DW_LANG_D
: printf ("(D)"); break;
3017 /* DWARF 4 values. */
3018 case DW_LANG_Python
: printf ("(Python)"); break;
3019 /* DWARF 5 values. */
3020 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3021 case DW_LANG_Go
: printf ("(Go)"); break;
3022 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3023 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3024 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3025 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3026 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3027 case DW_LANG_Rust
: printf ("(Rust)"); break;
3028 case DW_LANG_C11
: printf ("(C11)"); break;
3029 case DW_LANG_Swift
: printf ("(Swift)"); break;
3030 case DW_LANG_Julia
: printf ("(Julia)"); break;
3031 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3032 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3033 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3034 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3035 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3036 /* MIPS extension. */
3037 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3038 /* UPC extension. */
3039 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3041 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3042 printf (_("(implementation defined: %s)"),
3043 dwarf_vmatoa ("x", uvalue
));
3045 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3050 case DW_AT_encoding
:
3054 case DW_ATE_void
: printf ("(void)"); break;
3055 case DW_ATE_address
: printf ("(machine address)"); break;
3056 case DW_ATE_boolean
: printf ("(boolean)"); break;
3057 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3058 case DW_ATE_float
: printf ("(float)"); break;
3059 case DW_ATE_signed
: printf ("(signed)"); break;
3060 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3061 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3062 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3063 /* DWARF 2.1 values: */
3064 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3065 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3066 /* DWARF 3 values: */
3067 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3068 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3069 case DW_ATE_edited
: printf ("(edited)"); break;
3070 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3071 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3072 /* DWARF 4 values: */
3073 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3074 /* DWARF 5 values: */
3075 case DW_ATE_UCS
: printf ("(UCS)"); break;
3076 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3078 /* HP extensions: */
3079 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3080 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3081 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3082 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3083 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3084 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3085 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3088 if (uvalue
>= DW_ATE_lo_user
3089 && uvalue
<= DW_ATE_hi_user
)
3090 printf (_("(user defined type)"));
3092 printf (_("(unknown type)"));
3097 case DW_AT_accessibility
:
3101 case DW_ACCESS_public
: printf ("(public)"); break;
3102 case DW_ACCESS_protected
: printf ("(protected)"); break;
3103 case DW_ACCESS_private
: printf ("(private)"); break;
3105 printf (_("(unknown accessibility)"));
3110 case DW_AT_visibility
:
3114 case DW_VIS_local
: printf ("(local)"); break;
3115 case DW_VIS_exported
: printf ("(exported)"); break;
3116 case DW_VIS_qualified
: printf ("(qualified)"); break;
3117 default: printf (_("(unknown visibility)")); break;
3121 case DW_AT_endianity
:
3125 case DW_END_default
: printf ("(default)"); break;
3126 case DW_END_big
: printf ("(big)"); break;
3127 case DW_END_little
: printf ("(little)"); break;
3129 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3130 printf (_("(user specified)"));
3132 printf (_("(unknown endianity)"));
3137 case DW_AT_virtuality
:
3141 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3142 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3143 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3144 default: printf (_("(unknown virtuality)")); break;
3148 case DW_AT_identifier_case
:
3152 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3153 case DW_ID_up_case
: printf ("(up_case)"); break;
3154 case DW_ID_down_case
: printf ("(down_case)"); break;
3155 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3156 default: printf (_("(unknown case)")); break;
3160 case DW_AT_calling_convention
:
3164 case DW_CC_normal
: printf ("(normal)"); break;
3165 case DW_CC_program
: printf ("(program)"); break;
3166 case DW_CC_nocall
: printf ("(nocall)"); break;
3167 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3168 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3169 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3170 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3172 if (uvalue
>= DW_CC_lo_user
3173 && uvalue
<= DW_CC_hi_user
)
3174 printf (_("(user defined)"));
3176 printf (_("(unknown convention)"));
3180 case DW_AT_ordering
:
3185 case -1: printf (_("(undefined)")); break;
3186 case 0: printf ("(row major)"); break;
3187 case 1: printf ("(column major)"); break;
3191 case DW_AT_decimal_sign
:
3195 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3196 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3197 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3198 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3199 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3200 default: printf (_("(unrecognised)")); break;
3204 case DW_AT_defaulted
:
3208 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3209 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3210 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3211 default: printf (_("(unrecognised)")); break;
3215 case DW_AT_discr_list
:
3217 display_discr_list (form
, uvalue
, data
, end
, level
);
3220 case DW_AT_frame_base
:
3221 have_frame_base
= 1;
3223 case DW_AT_location
:
3224 case DW_AT_string_length
:
3225 case DW_AT_return_addr
:
3226 case DW_AT_data_member_location
:
3227 case DW_AT_vtable_elem_location
:
3229 case DW_AT_static_link
:
3230 case DW_AT_use_location
:
3231 case DW_AT_call_value
:
3232 case DW_AT_GNU_call_site_value
:
3233 case DW_AT_call_data_value
:
3234 case DW_AT_GNU_call_site_data_value
:
3235 case DW_AT_call_target
:
3236 case DW_AT_GNU_call_site_target
:
3237 case DW_AT_call_target_clobbered
:
3238 case DW_AT_GNU_call_site_target_clobbered
:
3239 if ((dwarf_version
< 4
3240 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3241 || form
== DW_FORM_sec_offset
)
3242 printf (_(" (location list)"));
3244 case DW_AT_allocated
:
3245 case DW_AT_associated
:
3246 case DW_AT_data_location
:
3248 case DW_AT_upper_bound
:
3249 case DW_AT_lower_bound
:
3252 int need_frame_base
;
3255 need_frame_base
= decode_location_expression (block_start
,
3260 cu_offset
, section
);
3262 if (need_frame_base
&& !have_frame_base
)
3263 printf (_(" [without DW_AT_frame_base]"));
3267 case DW_AT_data_bit_offset
:
3268 case DW_AT_byte_size
:
3269 case DW_AT_bit_size
:
3270 case DW_AT_string_length_byte_size
:
3271 case DW_AT_string_length_bit_size
:
3272 case DW_AT_bit_stride
:
3273 if (form
== DW_FORM_exprloc
)
3276 (void) decode_location_expression (block_start
, pointer_size
,
3277 offset_size
, dwarf_version
,
3278 uvalue
, cu_offset
, section
);
3285 unsigned long abbrev_number
;
3286 abbrev_entry
*entry
;
3288 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3289 section
, & abbrev_number
, NULL
, NULL
);
3292 if (form
!= DW_FORM_GNU_ref_alt
)
3293 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3294 dwarf_vmatoa ("x", uvalue
),
3295 (unsigned long) (orig_data
- section
->start
));
3299 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3300 printf (" (%s)", get_TAG_name (entry
->tag
));
3313 static unsigned char *
3314 read_and_display_attr (unsigned long attribute
,
3316 dwarf_signed_vma implicit_const
,
3317 unsigned char * start
,
3318 unsigned char * data
,
3319 unsigned char * end
,
3320 dwarf_vma cu_offset
,
3321 dwarf_vma pointer_size
,
3322 dwarf_vma offset_size
,
3324 debug_info
* debug_info_p
,
3326 struct dwarf_section
* section
,
3327 struct cu_tu_set
* this_set
,
3331 printf (" %-18s:", get_AT_name (attribute
));
3332 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3334 cu_offset
, pointer_size
, offset_size
,
3335 dwarf_version
, debug_info_p
,
3336 do_loc
, section
, this_set
, ' ', level
);
3342 /* Like load_debug_section, but if the ordinary call fails, and we are
3343 following debug links, then attempt to load the requested section
3344 from one of the separate debug info files. */
3347 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3350 if (load_debug_section (sec_enum
, handle
))
3352 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3354 /* See if we can associate a filename with this section. */
3357 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3358 if (i
->handle
== handle
)
3360 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3368 if (do_follow_links
)
3372 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3374 if (load_debug_section (sec_enum
, i
->handle
))
3376 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3378 /* FIXME: We should check to see if any of the remaining debug info
3379 files also contain this section, and, umm, do something about it. */
3389 introduce (struct dwarf_section
* section
, bool raw
)
3393 if (do_follow_links
&& section
->filename
)
3394 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3395 section
->name
, section
->filename
);
3397 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3401 if (do_follow_links
&& section
->filename
)
3402 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3403 section
->name
, section
->filename
);
3405 printf (_("Contents of the %s section:\n\n"), section
->name
);
3409 /* Process the contents of a .debug_info section.
3410 If do_loc is TRUE then we are scanning for location lists and dwo tags
3411 and we do not want to display anything to the user.
3412 If do_types is TRUE, we are processing a .debug_types section instead of
3413 a .debug_info section.
3414 The information displayed is restricted by the values in DWARF_START_DIE
3415 and DWARF_CUTOFF_LEVEL.
3416 Returns TRUE upon success. Otherwise an error or warning message is
3417 printed and FALSE is returned. */
3420 process_debug_info (struct dwarf_section
* section
,
3422 enum dwarf_section_display_enum abbrev_sec
,
3426 unsigned char *start
= section
->start
;
3427 unsigned char *end
= start
+ section
->size
;
3428 unsigned char *section_begin
;
3430 unsigned int num_units
= 0;
3432 /* First scan the section to get the number of comp units.
3433 Length sanity checks are done here. */
3434 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3439 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3440 will be the length. For a 64-bit DWARF section, it'll be
3441 the escape code 0xffffffff followed by an 8 byte length. */
3442 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3444 if (length
== 0xffffffff)
3445 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3446 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3448 warn (_("Reserved length value (0x%s) found in section %s\n"),
3449 dwarf_vmatoa ("x", length
), section
->name
);
3453 /* Negative values are illegal, they may even cause infinite
3454 looping. This can happen if we can't accurately apply
3455 relocations to an object file, or if the file is corrupt. */
3456 if (length
> (size_t) (end
- section_begin
))
3458 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3459 dwarf_vmatoa ("x", length
), section
->name
);
3462 section_begin
+= length
;
3467 error (_("No comp units in %s section ?\n"), section
->name
);
3471 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3472 && num_debug_info_entries
== 0
3476 /* Then allocate an array to hold the information. */
3477 debug_information
= (debug_info
*) cmalloc (num_units
,
3478 sizeof (* debug_information
));
3479 if (debug_information
== NULL
)
3481 error (_("Not enough memory for a debug info array of %u entries\n"),
3483 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3487 /* PR 17531: file: 92ca3797.
3488 We cannot rely upon the debug_information array being initialised
3489 before it is used. A corrupt file could easily contain references
3490 to a unit for which information has not been made available. So
3491 we ensure that the array is zeroed here. */
3492 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3494 alloc_num_debug_info_entries
= num_units
;
3499 load_debug_section_with_follow (str
, file
);
3500 load_debug_section_with_follow (line_str
, file
);
3501 load_debug_section_with_follow (str_dwo
, file
);
3502 load_debug_section_with_follow (str_index
, file
);
3503 load_debug_section_with_follow (str_index_dwo
, file
);
3504 load_debug_section_with_follow (debug_addr
, file
);
3507 load_debug_section_with_follow (abbrev_sec
, file
);
3508 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3510 warn (_("Unable to locate %s section!\n"),
3511 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3515 if (!do_loc
&& dwarf_start_die
== 0)
3516 introduce (section
, false);
3518 free_all_abbrevs ();
3519 free (cu_abbrev_map
);
3520 cu_abbrev_map
= NULL
;
3521 next_free_abbrev_map_entry
= 0;
3523 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3524 to load *all* of the abbrevs for all CUs in this .debug_info
3525 section. This does effectively mean that we (partially) read
3526 every CU header twice. */
3527 for (section_begin
= start
; start
< end
;)
3529 DWARF2_Internal_CompUnit compunit
;
3530 unsigned char * hdrptr
;
3531 dwarf_vma abbrev_base
;
3533 dwarf_vma cu_offset
;
3534 unsigned int offset_size
;
3535 struct cu_tu_set
* this_set
;
3537 unsigned char *end_cu
;
3540 cu_offset
= start
- section_begin
;
3542 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3544 if (compunit
.cu_length
== 0xffffffff)
3546 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3551 end_cu
= hdrptr
+ compunit
.cu_length
;
3553 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3555 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3557 if (compunit
.cu_version
< 5)
3559 compunit
.cu_unit_type
= DW_UT_compile
;
3560 /* Initialize it due to a false compiler warning. */
3561 compunit
.cu_pointer_size
= -1;
3565 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3566 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3568 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3571 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3574 if (compunit
.cu_unit_type
== DW_UT_split_compile
3575 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3578 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3581 if (this_set
== NULL
)
3584 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3588 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3589 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3592 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3593 compunit
.cu_abbrev_offset
);
3596 unsigned char * next
;
3598 list
= new_abbrev_list (abbrev_base
,
3599 compunit
.cu_abbrev_offset
);
3600 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3601 abbrev_base
, abbrev_size
,
3602 compunit
.cu_abbrev_offset
, list
);
3603 list
->start_of_next_abbrevs
= next
;
3607 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3610 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3612 DWARF2_Internal_CompUnit compunit
;
3613 unsigned char *hdrptr
;
3614 unsigned char *tags
;
3615 int level
, last_level
, saved_level
;
3616 dwarf_vma cu_offset
;
3617 unsigned int offset_size
;
3618 dwarf_vma signature
= 0;
3619 dwarf_vma type_offset
= 0;
3620 struct cu_tu_set
*this_set
;
3621 dwarf_vma abbrev_base
;
3623 abbrev_list
* list
= NULL
;
3624 unsigned char *end_cu
;
3627 cu_offset
= start
- section_begin
;
3629 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3631 if (compunit
.cu_length
== 0xffffffff)
3633 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3638 end_cu
= hdrptr
+ compunit
.cu_length
;
3640 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3642 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3644 if (compunit
.cu_version
< 5)
3646 compunit
.cu_unit_type
= DW_UT_compile
;
3647 /* Initialize it due to a false compiler warning. */
3648 compunit
.cu_pointer_size
= -1;
3652 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3653 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3655 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3658 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3660 if (this_set
== NULL
)
3663 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3667 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3668 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3671 if (compunit
.cu_version
< 5)
3672 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3674 bool do_dwo_id
= false;
3675 uint64_t dwo_id
= 0;
3676 if (compunit
.cu_unit_type
== DW_UT_split_compile
3677 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3679 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3683 /* PR 17512: file: 001-108546-0.001:0.1. */
3684 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3686 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3687 compunit
.cu_pointer_size
, offset_size
);
3688 compunit
.cu_pointer_size
= offset_size
;
3693 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3694 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3697 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3703 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3704 && num_debug_info_entries
== 0
3705 && alloc_num_debug_info_entries
> unit
3708 debug_information
[unit
].cu_offset
= cu_offset
;
3709 debug_information
[unit
].pointer_size
3710 = compunit
.cu_pointer_size
;
3711 debug_information
[unit
].offset_size
= offset_size
;
3712 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3713 debug_information
[unit
].base_address
= 0;
3714 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3715 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3716 debug_information
[unit
].loc_offsets
= NULL
;
3717 debug_information
[unit
].have_frame_base
= NULL
;
3718 debug_information
[unit
].max_loc_offsets
= 0;
3719 debug_information
[unit
].num_loc_offsets
= 0;
3720 debug_information
[unit
].range_lists
= NULL
;
3721 debug_information
[unit
].max_range_lists
= 0;
3722 debug_information
[unit
].num_range_lists
= 0;
3725 if (!do_loc
&& dwarf_start_die
== 0)
3727 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3728 dwarf_vmatoa ("x", cu_offset
));
3729 printf (_(" Length: 0x%s (%s)\n"),
3730 dwarf_vmatoa ("x", compunit
.cu_length
),
3731 offset_size
== 8 ? "64-bit" : "32-bit");
3732 printf (_(" Version: %d\n"), compunit
.cu_version
);
3733 if (compunit
.cu_version
>= 5)
3735 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3737 printf (_(" Unit Type: %s (%x)\n"),
3738 name
? name
: "???",
3739 compunit
.cu_unit_type
);
3741 printf (_(" Abbrev Offset: 0x%s\n"),
3742 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3743 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3746 printf (_(" Signature: 0x%s\n"),
3747 dwarf_vmatoa ("x", signature
));
3748 printf (_(" Type Offset: 0x%s\n"),
3749 dwarf_vmatoa ("x", type_offset
));
3752 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3753 if (this_set
!= NULL
)
3755 dwarf_vma
*offsets
= this_set
->section_offsets
;
3756 size_t *sizes
= this_set
->section_sizes
;
3758 printf (_(" Section contributions:\n"));
3759 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3760 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3761 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3762 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3763 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3764 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3765 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3766 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3767 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3768 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3769 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3770 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3777 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3779 warn (_("CU at offset %s contains corrupt or "
3780 "unsupported version number: %d.\n"),
3781 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3785 if (compunit
.cu_unit_type
!= DW_UT_compile
3786 && compunit
.cu_unit_type
!= DW_UT_partial
3787 && compunit
.cu_unit_type
!= DW_UT_type
3788 && compunit
.cu_unit_type
!= DW_UT_split_compile
3789 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3791 warn (_("CU at offset %s contains corrupt or "
3792 "unsupported unit type: %d.\n"),
3793 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3797 /* Process the abbrevs used by this compilation unit. */
3798 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3799 compunit
.cu_abbrev_offset
);
3802 unsigned char *next
;
3804 list
= new_abbrev_list (abbrev_base
,
3805 compunit
.cu_abbrev_offset
);
3806 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3807 abbrev_base
, abbrev_size
,
3808 compunit
.cu_abbrev_offset
, list
);
3809 list
->start_of_next_abbrevs
= next
;
3815 while (tags
< start
)
3817 unsigned long abbrev_number
;
3818 unsigned long die_offset
;
3819 abbrev_entry
*entry
;
3821 int do_printing
= 1;
3823 die_offset
= tags
- section_begin
;
3825 READ_ULEB (abbrev_number
, tags
, start
);
3827 /* A null DIE marks the end of a list of siblings or it may also be
3828 a section padding. */
3829 if (abbrev_number
== 0)
3831 /* Check if it can be a section padding for the last CU. */
3832 if (level
== 0 && start
== end
)
3836 for (chk
= tags
; chk
< start
; chk
++)
3843 if (!do_loc
&& die_offset
>= dwarf_start_die
3844 && (dwarf_cutoff_level
== -1
3845 || level
< dwarf_cutoff_level
))
3846 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3852 static unsigned num_bogus_warns
= 0;
3854 if (num_bogus_warns
< 3)
3856 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3857 die_offset
, section
->name
);
3859 if (num_bogus_warns
== 3)
3860 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3863 if (dwarf_start_die
!= 0 && level
< saved_level
)
3870 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3874 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3875 saved_level
= level
;
3876 do_printing
= (dwarf_cutoff_level
== -1
3877 || level
< dwarf_cutoff_level
);
3879 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3880 level
, die_offset
, abbrev_number
);
3881 else if (dwarf_cutoff_level
== -1
3882 || last_level
< dwarf_cutoff_level
)
3883 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3888 /* Scan through the abbreviation list until we reach the
3893 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3894 if (entry
->number
== abbrev_number
)
3899 if (!do_loc
&& do_printing
)
3904 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3905 die_offset
, abbrev_number
);
3909 if (!do_loc
&& do_printing
)
3910 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3915 need_base_address
= 0;
3917 case DW_TAG_compile_unit
:
3918 need_base_address
= 1;
3919 need_dwo_info
= do_loc
;
3921 case DW_TAG_entry_point
:
3922 case DW_TAG_subprogram
:
3923 need_base_address
= 0;
3924 /* Assuming that there is no DW_AT_frame_base. */
3925 have_frame_base
= 0;
3929 debug_info
*debug_info_p
=
3930 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3931 ? debug_information
+ unit
: NULL
;
3933 assert (!debug_info_p
3934 || (debug_info_p
->num_loc_offsets
3935 == debug_info_p
->num_loc_views
));
3937 for (attr
= entry
->first_attr
;
3938 attr
&& attr
->attribute
;
3941 if (! do_loc
&& do_printing
)
3942 /* Show the offset from where the tag was extracted. */
3943 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3944 tags
= read_and_display_attr (attr
->attribute
,
3946 attr
->implicit_const
,
3951 compunit
.cu_pointer_size
,
3953 compunit
.cu_version
,
3955 do_loc
|| ! do_printing
,
3961 /* If a locview attribute appears before a location one,
3962 make sure we don't associate it with an earlier
3965 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3968 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3969 debug_info_p
->num_loc_views
++;
3970 assert (debug_info_p
->num_loc_views
3971 == debug_info_p
->num_loc_offsets
);
3978 warn(_("DIE has locviews without loclist\n"));
3979 debug_info_p
->num_loc_views
--;
3986 if (entry
->children
)
3991 /* Set num_debug_info_entries here so that it can be used to check if
3992 we need to process .debug_loc and .debug_ranges sections. */
3993 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3994 && num_debug_info_entries
== 0
3997 if (num_units
> alloc_num_debug_info_entries
)
3998 num_debug_info_entries
= alloc_num_debug_info_entries
;
4000 num_debug_info_entries
= num_units
;
4009 /* Locate and scan the .debug_info section in the file and record the pointer
4010 sizes and offsets for the compilation units in it. Usually an executable
4011 will have just one pointer size, but this is not guaranteed, and so we try
4012 not to make any assumptions. Returns zero upon failure, or the number of
4013 compilation units upon success. */
4016 load_debug_info (void * file
)
4018 /* If we have already tried and failed to load the .debug_info
4019 section then do not bother to repeat the task. */
4020 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4023 /* If we already have the information there is nothing else to do. */
4024 if (num_debug_info_entries
> 0)
4025 return num_debug_info_entries
;
4027 /* If this is a DWARF package file, load the CU and TU indexes. */
4028 (void) load_cu_tu_indexes (file
);
4030 if (load_debug_section_with_follow (info
, file
)
4031 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4032 return num_debug_info_entries
;
4034 if (load_debug_section_with_follow (info_dwo
, file
)
4035 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4036 abbrev_dwo
, true, false))
4037 return num_debug_info_entries
;
4039 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4043 /* Read a DWARF .debug_line section header starting at DATA.
4044 Upon success returns an updated DATA pointer and the LINFO
4045 structure and the END_OF_SEQUENCE pointer will be filled in.
4046 Otherwise returns NULL. */
4048 static unsigned char *
4049 read_debug_line_header (struct dwarf_section
* section
,
4050 unsigned char * data
,
4051 unsigned char * end
,
4052 DWARF2_Internal_LineInfo
* linfo
,
4053 unsigned char ** end_of_sequence
)
4055 unsigned char *hdrptr
;
4057 /* Extract information from the Line Number Program Header.
4058 (section 6.2.4 in the Dwarf3 doc). */
4061 /* Get and check the length of the block. */
4062 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4064 if (linfo
->li_length
== 0xffffffff)
4066 /* This section is 64-bit DWARF 3. */
4067 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4068 linfo
->li_offset_size
= 8;
4071 linfo
->li_offset_size
= 4;
4073 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4075 /* If the length field has a relocation against it, then we should
4076 not complain if it is inaccurate (and probably negative). This
4077 happens in object files when the .debug_line section is actually
4078 comprised of several different .debug_line.* sections, (some of
4079 which may be removed by linker garbage collection), and a relocation
4080 is used to compute the correct length once that is done. */
4081 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4083 linfo
->li_length
= end
- hdrptr
;
4087 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4088 (long) linfo
->li_length
);
4092 end
= hdrptr
+ linfo
->li_length
;
4094 /* Get and check the version number. */
4095 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4097 if (linfo
->li_version
!= 2
4098 && linfo
->li_version
!= 3
4099 && linfo
->li_version
!= 4
4100 && linfo
->li_version
!= 5)
4102 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4103 "is currently supported.\n"));
4107 if (linfo
->li_version
>= 5)
4109 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4111 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4112 if (linfo
->li_segment_size
!= 0)
4114 warn (_("The %s section contains "
4115 "unsupported segment selector size: %d.\n"),
4116 section
->name
, linfo
->li_segment_size
);
4121 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4122 linfo
->li_offset_size
, end
);
4123 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4125 if (linfo
->li_version
>= 4)
4127 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4129 if (linfo
->li_max_ops_per_insn
== 0)
4131 warn (_("Invalid maximum operations per insn.\n"));
4136 linfo
->li_max_ops_per_insn
= 1;
4138 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4139 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4140 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4141 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4143 *end_of_sequence
= end
;
4147 static unsigned char *
4148 display_formatted_table (unsigned char *data
,
4149 unsigned char *start
,
4151 const DWARF2_Internal_LineInfo
*linfo
,
4152 struct dwarf_section
*section
,
4155 unsigned char *format_start
, format_count
, *format
, formati
;
4156 dwarf_vma data_count
, datai
;
4157 unsigned int namepass
, last_entry
= 0;
4158 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4160 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4161 if (do_checks
&& format_count
> 5)
4162 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4163 table_name
, format_count
);
4165 format_start
= data
;
4166 for (formati
= 0; formati
< format_count
; formati
++)
4168 SKIP_ULEB (data
, end
);
4169 SKIP_ULEB (data
, end
);
4172 warn (_("%s: Corrupt format description entry\n"), table_name
);
4177 READ_ULEB (data_count
, data
, end
);
4178 if (data_count
== 0)
4180 printf (_("\n The %s is empty.\n"), table_name
);
4183 else if (data
>= end
)
4185 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4186 table_name
, dwarf_vmatoa ("x", data_count
));
4190 else if (format_count
== 0)
4192 warn (_("%s: format count is zero, but the table is not empty\n"),
4197 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4198 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4201 printf (_(" Entry"));
4202 /* Delay displaying name as the last entry for better screen layout. */
4203 for (namepass
= 0; namepass
< 2; namepass
++)
4205 format
= format_start
;
4206 for (formati
= 0; formati
< format_count
; formati
++)
4208 dwarf_vma content_type
;
4210 READ_ULEB (content_type
, format
, end
);
4211 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4212 switch (content_type
)
4215 printf (_("\tName"));
4217 case DW_LNCT_directory_index
:
4218 printf (_("\tDir"));
4220 case DW_LNCT_timestamp
:
4221 printf (_("\tTime"));
4224 printf (_("\tSize"));
4227 printf (_("\tMD5\t\t\t"));
4230 printf (_("\t(Unknown format content type %s)"),
4231 dwarf_vmatoa ("u", content_type
));
4233 SKIP_ULEB (format
, end
);
4238 for (datai
= 0; datai
< data_count
; datai
++)
4240 unsigned char *datapass
= data
;
4242 printf (" %d", last_entry
++);
4243 /* Delay displaying name as the last entry for better screen layout. */
4244 for (namepass
= 0; namepass
< 2; namepass
++)
4246 format
= format_start
;
4248 for (formati
= 0; formati
< format_count
; formati
++)
4250 dwarf_vma content_type
, form
;
4252 READ_ULEB (content_type
, format
, end
);
4253 READ_ULEB (form
, format
, end
);
4254 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4255 0, 0, linfo
->li_offset_size
,
4256 linfo
->li_version
, NULL
,
4257 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4258 section
, NULL
, '\t', -1);
4262 if (data
>= end
&& (datai
< data_count
- 1))
4264 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4273 display_debug_sup (struct dwarf_section
* section
,
4274 void * file ATTRIBUTE_UNUSED
)
4276 unsigned char * start
= section
->start
;
4277 unsigned char * end
= section
->start
+ section
->size
;
4278 unsigned int version
;
4279 char is_supplementary
;
4280 const unsigned char * sup_filename
;
4281 size_t sup_filename_len
;
4282 unsigned int num_read
;
4284 dwarf_vma checksum_len
;
4287 introduce (section
, true);
4288 if (section
->size
< 4)
4290 error (_("corrupt .debug_sup section: size is too small\n"));
4294 /* Read the data. */
4295 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4297 warn (_("corrupt .debug_sup section: version < 5"));
4299 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4300 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4301 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4303 sup_filename
= start
;
4304 if (is_supplementary
&& sup_filename
[0] != 0)
4305 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4307 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4308 if (sup_filename_len
== (size_t) (end
- start
))
4310 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4313 start
+= sup_filename_len
+ 1;
4315 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4318 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4322 if (checksum_len
> (dwarf_vma
) (end
- start
))
4324 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4325 checksum_len
= end
- start
;
4327 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4329 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4330 (long) ((end
- start
) - checksum_len
));
4333 printf (_(" Version: %u\n"), version
);
4334 printf (_(" Is Supp: %u\n"), is_supplementary
);
4335 printf (_(" Filename: %s\n"), sup_filename
);
4336 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4337 if (checksum_len
> 0)
4339 printf (_(" Checksum: "));
4340 while (checksum_len
--)
4341 printf ("0x%x ", * start
++ );
4348 display_debug_lines_raw (struct dwarf_section
* section
,
4349 unsigned char * data
,
4350 unsigned char * end
,
4353 unsigned char *start
= section
->start
;
4354 int verbose_view
= 0;
4356 introduce (section
, true);
4360 static DWARF2_Internal_LineInfo saved_linfo
;
4361 DWARF2_Internal_LineInfo linfo
;
4362 unsigned char *standard_opcodes
;
4363 unsigned char *end_of_sequence
;
4366 if (startswith (section
->name
, ".debug_line.")
4367 /* Note: the following does not apply to .debug_line.dwo sections.
4368 These are full debug_line sections. */
4369 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4371 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4372 section containing just the Line Number Statements. They are
4373 created by the assembler and intended to be used alongside gcc's
4374 -ffunction-sections command line option. When the linker's
4375 garbage collection decides to discard a .text.<foo> section it
4376 can then also discard the line number information in .debug_line.<foo>.
4378 Since the section is a fragment it does not have the details
4379 needed to fill out a LineInfo structure, so instead we use the
4380 details from the last full debug_line section that we processed. */
4381 end_of_sequence
= end
;
4382 standard_opcodes
= NULL
;
4383 linfo
= saved_linfo
;
4384 /* PR 17531: file: 0522b371. */
4385 if (linfo
.li_line_range
== 0)
4387 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4390 reset_state_machine (linfo
.li_default_is_stmt
);
4394 unsigned char * hdrptr
;
4396 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4397 & end_of_sequence
)) == NULL
)
4400 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4401 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4402 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4403 if (linfo
.li_version
>= 5)
4405 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4406 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4408 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4409 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4410 if (linfo
.li_version
>= 4)
4411 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4412 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4413 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4414 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4415 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4417 /* PR 17512: file: 1665-6428-0.004. */
4418 if (linfo
.li_line_range
== 0)
4420 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4421 linfo
.li_line_range
= 1;
4424 reset_state_machine (linfo
.li_default_is_stmt
);
4426 /* Display the contents of the Opcodes table. */
4427 standard_opcodes
= hdrptr
;
4429 /* PR 17512: file: 002-417945-0.004. */
4430 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4432 warn (_("Line Base extends beyond end of section\n"));
4436 printf (_("\n Opcodes:\n"));
4438 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4439 printf (ngettext (" Opcode %d has %d arg\n",
4440 " Opcode %d has %d args\n",
4441 standard_opcodes
[i
- 1]),
4442 i
, standard_opcodes
[i
- 1]);
4444 /* Display the contents of the Directory table. */
4445 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4447 if (linfo
.li_version
>= 5)
4449 load_debug_section_with_follow (line_str
, file
);
4451 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4453 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4459 printf (_("\n The Directory Table is empty.\n"));
4462 unsigned int last_dir_entry
= 0;
4464 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4465 (long)(data
- start
));
4467 while (data
< end
&& *data
!= 0)
4469 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4471 data
+= strnlen ((char *) data
, end
- data
);
4476 /* PR 17512: file: 002-132094-0.004. */
4477 if (data
>= end
- 1)
4481 /* Skip the NUL at the end of the table. */
4485 /* Display the contents of the File Name table. */
4486 if (data
>= end
|| *data
== 0)
4487 printf (_("\n The File Name Table is empty.\n"));
4490 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4491 (long)(data
- start
));
4492 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4494 while (data
< end
&& *data
!= 0)
4496 unsigned char *name
;
4499 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4501 data
+= strnlen ((char *) data
, end
- data
);
4505 READ_ULEB (val
, data
, end
);
4506 printf ("%s\t", dwarf_vmatoa ("u", val
));
4507 READ_ULEB (val
, data
, end
);
4508 printf ("%s\t", dwarf_vmatoa ("u", val
));
4509 READ_ULEB (val
, data
, end
);
4510 printf ("%s\t", dwarf_vmatoa ("u", val
));
4511 printf ("%.*s\n", (int)(end
- name
), name
);
4515 warn (_("Corrupt file name table entry\n"));
4521 /* Skip the NUL at the end of the table. */
4527 saved_linfo
= linfo
;
4530 /* Now display the statements. */
4531 if (data
>= end_of_sequence
)
4532 printf (_(" No Line Number Statements.\n"));
4535 printf (_(" Line Number Statements:\n"));
4537 while (data
< end_of_sequence
)
4539 unsigned char op_code
;
4540 dwarf_signed_vma adv
;
4543 printf (" [0x%08lx]", (long)(data
- start
));
4547 if (op_code
>= linfo
.li_opcode_base
)
4549 op_code
-= linfo
.li_opcode_base
;
4550 uladv
= (op_code
/ linfo
.li_line_range
);
4551 if (linfo
.li_max_ops_per_insn
== 1)
4553 uladv
*= linfo
.li_min_insn_length
;
4554 state_machine_regs
.address
+= uladv
;
4556 state_machine_regs
.view
= 0;
4557 printf (_(" Special opcode %d: "
4558 "advance Address by %s to 0x%s%s"),
4559 op_code
, dwarf_vmatoa ("u", uladv
),
4560 dwarf_vmatoa ("x", state_machine_regs
.address
),
4561 verbose_view
&& uladv
4562 ? _(" (reset view)") : "");
4567 = ((state_machine_regs
.op_index
+ uladv
)
4568 / linfo
.li_max_ops_per_insn
)
4569 * linfo
.li_min_insn_length
;
4571 state_machine_regs
.address
+= addrdelta
;
4572 state_machine_regs
.op_index
4573 = (state_machine_regs
.op_index
+ uladv
)
4574 % linfo
.li_max_ops_per_insn
;
4576 state_machine_regs
.view
= 0;
4577 printf (_(" Special opcode %d: "
4578 "advance Address by %s to 0x%s[%d]%s"),
4579 op_code
, dwarf_vmatoa ("u", uladv
),
4580 dwarf_vmatoa ("x", state_machine_regs
.address
),
4581 state_machine_regs
.op_index
,
4582 verbose_view
&& addrdelta
4583 ? _(" (reset view)") : "");
4585 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4586 state_machine_regs
.line
+= adv
;
4587 printf (_(" and Line by %s to %d"),
4588 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4589 if (verbose_view
|| state_machine_regs
.view
)
4590 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4593 state_machine_regs
.view
++;
4598 case DW_LNS_extended_op
:
4599 data
+= process_extended_line_op (data
,
4600 linfo
.li_default_is_stmt
,
4605 printf (_(" Copy"));
4606 if (verbose_view
|| state_machine_regs
.view
)
4607 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4610 state_machine_regs
.view
++;
4613 case DW_LNS_advance_pc
:
4614 READ_ULEB (uladv
, data
, end
);
4615 if (linfo
.li_max_ops_per_insn
== 1)
4617 uladv
*= linfo
.li_min_insn_length
;
4618 state_machine_regs
.address
+= uladv
;
4620 state_machine_regs
.view
= 0;
4621 printf (_(" Advance PC by %s to 0x%s%s\n"),
4622 dwarf_vmatoa ("u", uladv
),
4623 dwarf_vmatoa ("x", state_machine_regs
.address
),
4624 verbose_view
&& uladv
4625 ? _(" (reset view)") : "");
4630 = ((state_machine_regs
.op_index
+ uladv
)
4631 / linfo
.li_max_ops_per_insn
)
4632 * linfo
.li_min_insn_length
;
4633 state_machine_regs
.address
4635 state_machine_regs
.op_index
4636 = (state_machine_regs
.op_index
+ uladv
)
4637 % linfo
.li_max_ops_per_insn
;
4639 state_machine_regs
.view
= 0;
4640 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4641 dwarf_vmatoa ("u", uladv
),
4642 dwarf_vmatoa ("x", state_machine_regs
.address
),
4643 state_machine_regs
.op_index
,
4644 verbose_view
&& addrdelta
4645 ? _(" (reset view)") : "");
4649 case DW_LNS_advance_line
:
4650 READ_SLEB (adv
, data
, end
);
4651 state_machine_regs
.line
+= adv
;
4652 printf (_(" Advance Line by %s to %d\n"),
4653 dwarf_vmatoa ("d", adv
),
4654 state_machine_regs
.line
);
4657 case DW_LNS_set_file
:
4658 READ_ULEB (uladv
, data
, end
);
4659 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4660 dwarf_vmatoa ("u", uladv
));
4661 state_machine_regs
.file
= uladv
;
4664 case DW_LNS_set_column
:
4665 READ_ULEB (uladv
, data
, end
);
4666 printf (_(" Set column to %s\n"),
4667 dwarf_vmatoa ("u", uladv
));
4668 state_machine_regs
.column
= uladv
;
4671 case DW_LNS_negate_stmt
:
4672 adv
= state_machine_regs
.is_stmt
;
4674 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4675 state_machine_regs
.is_stmt
= adv
;
4678 case DW_LNS_set_basic_block
:
4679 printf (_(" Set basic block\n"));
4680 state_machine_regs
.basic_block
= 1;
4683 case DW_LNS_const_add_pc
:
4684 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4685 if (linfo
.li_max_ops_per_insn
)
4687 uladv
*= linfo
.li_min_insn_length
;
4688 state_machine_regs
.address
+= uladv
;
4690 state_machine_regs
.view
= 0;
4691 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4692 dwarf_vmatoa ("u", uladv
),
4693 dwarf_vmatoa ("x", state_machine_regs
.address
),
4694 verbose_view
&& uladv
4695 ? _(" (reset view)") : "");
4700 = ((state_machine_regs
.op_index
+ uladv
)
4701 / linfo
.li_max_ops_per_insn
)
4702 * linfo
.li_min_insn_length
;
4703 state_machine_regs
.address
4705 state_machine_regs
.op_index
4706 = (state_machine_regs
.op_index
+ uladv
)
4707 % linfo
.li_max_ops_per_insn
;
4709 state_machine_regs
.view
= 0;
4710 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4711 dwarf_vmatoa ("u", uladv
),
4712 dwarf_vmatoa ("x", state_machine_regs
.address
),
4713 state_machine_regs
.op_index
,
4714 verbose_view
&& addrdelta
4715 ? _(" (reset view)") : "");
4719 case DW_LNS_fixed_advance_pc
:
4720 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4721 state_machine_regs
.address
+= uladv
;
4722 state_machine_regs
.op_index
= 0;
4723 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4724 dwarf_vmatoa ("u", uladv
),
4725 dwarf_vmatoa ("x", state_machine_regs
.address
));
4726 /* Do NOT reset view. */
4729 case DW_LNS_set_prologue_end
:
4730 printf (_(" Set prologue_end to true\n"));
4733 case DW_LNS_set_epilogue_begin
:
4734 printf (_(" Set epilogue_begin to true\n"));
4737 case DW_LNS_set_isa
:
4738 READ_ULEB (uladv
, data
, end
);
4739 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4743 printf (_(" Unknown opcode %d with operands: "), op_code
);
4745 if (standard_opcodes
!= NULL
)
4746 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4748 READ_ULEB (uladv
, data
, end
);
4749 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4750 i
== 1 ? "" : ", ");
4765 unsigned char *name
;
4766 unsigned int directory_index
;
4767 unsigned int modification_date
;
4768 unsigned int length
;
4771 /* Output a decoded representation of the .debug_line section. */
4774 display_debug_lines_decoded (struct dwarf_section
* section
,
4775 unsigned char * start
,
4776 unsigned char * data
,
4777 unsigned char * end
,
4780 static DWARF2_Internal_LineInfo saved_linfo
;
4782 introduce (section
, false);
4786 /* This loop amounts to one iteration per compilation unit. */
4787 DWARF2_Internal_LineInfo linfo
;
4788 unsigned char *standard_opcodes
;
4789 unsigned char *end_of_sequence
;
4791 File_Entry
*file_table
= NULL
;
4792 unsigned int n_files
= 0;
4793 unsigned char **directory_table
= NULL
;
4794 dwarf_vma n_directories
= 0;
4796 if (startswith (section
->name
, ".debug_line.")
4797 /* Note: the following does not apply to .debug_line.dwo sections.
4798 These are full debug_line sections. */
4799 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4801 /* See comment in display_debug_lines_raw(). */
4802 end_of_sequence
= end
;
4803 standard_opcodes
= NULL
;
4804 linfo
= saved_linfo
;
4805 /* PR 17531: file: 0522b371. */
4806 if (linfo
.li_line_range
== 0)
4808 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4811 reset_state_machine (linfo
.li_default_is_stmt
);
4815 unsigned char *hdrptr
;
4817 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4818 & end_of_sequence
)) == NULL
)
4821 /* PR 17531: file: 0522b371. */
4822 if (linfo
.li_line_range
== 0)
4824 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4825 linfo
.li_line_range
= 1;
4827 reset_state_machine (linfo
.li_default_is_stmt
);
4829 /* Save a pointer to the contents of the Opcodes table. */
4830 standard_opcodes
= hdrptr
;
4832 /* Traverse the Directory table just to count entries. */
4833 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4837 warn (_("opcode base of %d extends beyond end of section\n"),
4838 linfo
.li_opcode_base
);
4842 if (linfo
.li_version
>= 5)
4844 unsigned char *format_start
, format_count
, *format
;
4845 dwarf_vma formati
, entryi
;
4847 load_debug_section_with_follow (line_str
, fileptr
);
4849 /* Skip directories format. */
4850 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4851 if (do_checks
&& format_count
> 1)
4852 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4854 format_start
= data
;
4855 for (formati
= 0; formati
< format_count
; formati
++)
4857 SKIP_ULEB (data
, end
);
4858 SKIP_ULEB (data
, end
);
4861 READ_ULEB (n_directories
, data
, end
);
4864 warn (_("Corrupt directories list\n"));
4868 if (n_directories
== 0)
4869 directory_table
= NULL
;
4871 directory_table
= (unsigned char **)
4872 xmalloc (n_directories
* sizeof (unsigned char *));
4874 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4876 unsigned char **pathp
= &directory_table
[entryi
];
4878 format
= format_start
;
4879 for (formati
= 0; formati
< format_count
; formati
++)
4881 dwarf_vma content_type
, form
;
4884 READ_ULEB (content_type
, format
, end
);
4885 READ_ULEB (form
, format
, end
);
4888 warn (_("Corrupt directories list\n"));
4891 switch (content_type
)
4896 case DW_FORM_string
:
4899 case DW_FORM_line_strp
:
4900 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4902 /* Remove const by the cast. */
4903 *pathp
= (unsigned char *)
4904 fetch_indirect_line_string (uvalue
);
4909 data
= read_and_display_attr_value (0, form
, 0, start
,
4911 linfo
.li_offset_size
,
4918 warn (_("Corrupt directories list\n"));
4923 /* Skip files format. */
4924 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4925 if (do_checks
&& format_count
> 5)
4926 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
4928 format_start
= data
;
4929 for (formati
= 0; formati
< format_count
; formati
++)
4931 SKIP_ULEB (data
, end
);
4932 SKIP_ULEB (data
, end
);
4935 READ_ULEB (n_files
, data
, end
);
4936 if (data
>= end
&& n_files
> 0)
4938 warn (_("Corrupt file name list\n"));
4945 file_table
= (File_Entry
*) xcalloc (1, n_files
4946 * sizeof (File_Entry
));
4948 for (entryi
= 0; entryi
< n_files
; entryi
++)
4950 File_Entry
*file
= &file_table
[entryi
];
4952 format
= format_start
;
4953 for (formati
= 0; formati
< format_count
; formati
++)
4955 dwarf_vma content_type
, form
;
4959 READ_ULEB (content_type
, format
, end
);
4960 READ_ULEB (form
, format
, end
);
4963 warn (_("Corrupt file name list\n"));
4966 switch (content_type
)
4971 case DW_FORM_string
:
4974 case DW_FORM_line_strp
:
4975 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4977 /* Remove const by the cast. */
4978 file
->name
= (unsigned char *)
4979 fetch_indirect_line_string (uvalue
);
4983 case DW_LNCT_directory_index
:
4987 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4991 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4996 READ_ULEB (file
->directory_index
, tmp
, end
);
5001 data
= read_and_display_attr_value (0, form
, 0, start
,
5003 linfo
.li_offset_size
,
5010 warn (_("Corrupt file name list\n"));
5019 unsigned char *ptr_directory_table
= data
;
5021 while (data
< end
&& *data
!= 0)
5023 data
+= strnlen ((char *) data
, end
- data
);
5032 warn (_("directory table ends unexpectedly\n"));
5037 /* Go through the directory table again to save the directories. */
5038 directory_table
= (unsigned char **)
5039 xmalloc (n_directories
* sizeof (unsigned char *));
5042 while (*ptr_directory_table
!= 0)
5044 directory_table
[i
] = ptr_directory_table
;
5046 += strlen ((char *) ptr_directory_table
) + 1;
5050 /* Skip the NUL at the end of the table. */
5053 /* Traverse the File Name table just to count the entries. */
5054 if (data
< end
&& *data
!= 0)
5056 unsigned char *ptr_file_name_table
= data
;
5058 while (data
< end
&& *data
!= 0)
5060 /* Skip Name, directory index, last modification
5061 time and length of file. */
5062 data
+= strnlen ((char *) data
, end
- data
);
5065 SKIP_ULEB (data
, end
);
5066 SKIP_ULEB (data
, end
);
5067 SKIP_ULEB (data
, end
);
5073 warn (_("file table ends unexpectedly\n"));
5078 /* Go through the file table again to save the strings. */
5079 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5082 while (*ptr_file_name_table
!= 0)
5084 file_table
[i
].name
= ptr_file_name_table
;
5086 += strlen ((char *) ptr_file_name_table
) + 1;
5088 /* We are not interested in directory, time or size. */
5089 READ_ULEB (file_table
[i
].directory_index
,
5090 ptr_file_name_table
, end
);
5091 READ_ULEB (file_table
[i
].modification_date
,
5092 ptr_file_name_table
, end
);
5093 READ_ULEB (file_table
[i
].length
,
5094 ptr_file_name_table
, end
);
5100 /* Skip the NUL at the end of the table. */
5104 /* Print the Compilation Unit's name and a header. */
5105 if (file_table
== NULL
)
5106 printf (_("CU: No directory table\n"));
5107 else if (directory_table
== NULL
)
5108 printf (_("CU: %s:\n"), file_table
[0].name
);
5111 unsigned int ix
= file_table
[0].directory_index
;
5112 const char *directory
;
5117 else if (n_directories
== 0)
5118 directory
= _("<unknown>");
5119 else if (ix
> n_directories
)
5121 warn (_("directory index %u > number of directories %s\n"),
5122 ix
, dwarf_vmatoa ("u", n_directories
));
5123 directory
= _("<corrupt>");
5126 directory
= (char *) directory_table
[ix
- 1];
5128 if (do_wide
|| strlen (directory
) < 76)
5129 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5131 printf ("%s:\n", file_table
[0].name
);
5135 printf (_("File name Line number Starting address View Stmt\n"));
5137 printf (_("CU: Empty file name table\n"));
5138 saved_linfo
= linfo
;
5141 /* This loop iterates through the Dwarf Line Number Program. */
5142 while (data
< end_of_sequence
)
5144 unsigned char op_code
;
5147 unsigned long int uladv
;
5148 int is_special_opcode
= 0;
5153 if (op_code
>= linfo
.li_opcode_base
)
5155 op_code
-= linfo
.li_opcode_base
;
5156 uladv
= (op_code
/ linfo
.li_line_range
);
5157 if (linfo
.li_max_ops_per_insn
== 1)
5159 uladv
*= linfo
.li_min_insn_length
;
5160 state_machine_regs
.address
+= uladv
;
5162 state_machine_regs
.view
= 0;
5167 = ((state_machine_regs
.op_index
+ uladv
)
5168 / linfo
.li_max_ops_per_insn
)
5169 * linfo
.li_min_insn_length
;
5170 state_machine_regs
.address
5172 state_machine_regs
.op_index
5173 = (state_machine_regs
.op_index
+ uladv
)
5174 % linfo
.li_max_ops_per_insn
;
5176 state_machine_regs
.view
= 0;
5179 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5180 state_machine_regs
.line
+= adv
;
5181 is_special_opcode
= 1;
5182 /* Increment view after printing this row. */
5187 case DW_LNS_extended_op
:
5189 unsigned int ext_op_code_len
;
5190 unsigned char ext_op_code
;
5191 unsigned char *op_code_end
;
5192 unsigned char *op_code_data
= data
;
5194 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5195 op_code_end
= op_code_data
+ ext_op_code_len
;
5196 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5198 warn (_("Badly formed extended line op encountered!\n"));
5201 ext_op_code
= *op_code_data
++;
5205 switch (ext_op_code
)
5207 case DW_LNE_end_sequence
:
5208 /* Reset stuff after printing this row. */
5210 case DW_LNE_set_address
:
5211 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5213 op_code_end
- op_code_data
,
5215 state_machine_regs
.op_index
= 0;
5216 state_machine_regs
.view
= 0;
5218 case DW_LNE_define_file
:
5219 file_table
= (File_Entry
*) xrealloc
5220 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5222 ++state_machine_regs
.last_file_entry
;
5223 /* Source file name. */
5224 file_table
[n_files
].name
= op_code_data
;
5225 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5226 /* Directory index. */
5227 READ_ULEB (file_table
[n_files
].directory_index
,
5228 op_code_data
, op_code_end
);
5229 /* Last modification time. */
5230 READ_ULEB (file_table
[n_files
].modification_date
,
5231 op_code_data
, op_code_end
);
5233 READ_ULEB (file_table
[n_files
].length
,
5234 op_code_data
, op_code_end
);
5238 case DW_LNE_set_discriminator
:
5239 case DW_LNE_HP_set_sequence
:
5240 /* Simply ignored. */
5244 printf (_("UNKNOWN (%u): length %ld\n"),
5245 ext_op_code
, (long int) (op_code_data
- data
));
5252 /* Increment view after printing this row. */
5255 case DW_LNS_advance_pc
:
5256 READ_ULEB (uladv
, data
, end
);
5257 if (linfo
.li_max_ops_per_insn
== 1)
5259 uladv
*= linfo
.li_min_insn_length
;
5260 state_machine_regs
.address
+= uladv
;
5262 state_machine_regs
.view
= 0;
5267 = ((state_machine_regs
.op_index
+ uladv
)
5268 / linfo
.li_max_ops_per_insn
)
5269 * linfo
.li_min_insn_length
;
5270 state_machine_regs
.address
5272 state_machine_regs
.op_index
5273 = (state_machine_regs
.op_index
+ uladv
)
5274 % linfo
.li_max_ops_per_insn
;
5276 state_machine_regs
.view
= 0;
5280 case DW_LNS_advance_line
:
5281 READ_SLEB (adv
, data
, end
);
5282 state_machine_regs
.line
+= adv
;
5285 case DW_LNS_set_file
:
5286 READ_ULEB (uladv
, data
, end
);
5287 state_machine_regs
.file
= uladv
;
5290 unsigned file
= state_machine_regs
.file
- 1;
5293 if (file_table
== NULL
|| n_files
== 0)
5294 printf (_("\n [Use file table entry %d]\n"), file
);
5296 else if (file
>= n_files
)
5298 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
5299 printf (_("\n <over large file table index %u>"), file
);
5301 else if ((dir
= file_table
[file
].directory_index
) == 0)
5302 /* If directory index is 0, that means current directory. */
5303 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5304 else if (directory_table
== NULL
|| n_directories
== 0)
5305 printf (_("\n [Use file %s in directory table entry %d]\n"),
5306 file_table
[file
].name
, dir
);
5308 else if (dir
> n_directories
)
5310 warn (_("directory index %u > number of directories %s\n"),
5311 dir
, dwarf_vmatoa ("u", n_directories
));
5312 printf (_("\n <over large directory table entry %u>\n"), dir
);
5315 printf ("\n%s/%s:\n",
5316 /* The directory index starts counting at 1. */
5317 directory_table
[dir
- 1], file_table
[file
].name
);
5321 case DW_LNS_set_column
:
5322 READ_ULEB (uladv
, data
, end
);
5323 state_machine_regs
.column
= uladv
;
5326 case DW_LNS_negate_stmt
:
5327 adv
= state_machine_regs
.is_stmt
;
5329 state_machine_regs
.is_stmt
= adv
;
5332 case DW_LNS_set_basic_block
:
5333 state_machine_regs
.basic_block
= 1;
5336 case DW_LNS_const_add_pc
:
5337 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5338 if (linfo
.li_max_ops_per_insn
== 1)
5340 uladv
*= linfo
.li_min_insn_length
;
5341 state_machine_regs
.address
+= uladv
;
5343 state_machine_regs
.view
= 0;
5348 = ((state_machine_regs
.op_index
+ uladv
)
5349 / linfo
.li_max_ops_per_insn
)
5350 * linfo
.li_min_insn_length
;
5351 state_machine_regs
.address
5353 state_machine_regs
.op_index
5354 = (state_machine_regs
.op_index
+ uladv
)
5355 % linfo
.li_max_ops_per_insn
;
5357 state_machine_regs
.view
= 0;
5361 case DW_LNS_fixed_advance_pc
:
5362 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5363 state_machine_regs
.address
+= uladv
;
5364 state_machine_regs
.op_index
= 0;
5365 /* Do NOT reset view. */
5368 case DW_LNS_set_prologue_end
:
5371 case DW_LNS_set_epilogue_begin
:
5374 case DW_LNS_set_isa
:
5375 READ_ULEB (uladv
, data
, end
);
5376 printf (_(" Set ISA to %lu\n"), uladv
);
5380 printf (_(" Unknown opcode %d with operands: "), op_code
);
5382 if (standard_opcodes
!= NULL
)
5383 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5387 READ_ULEB (val
, data
, end
);
5388 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5389 i
== 1 ? "" : ", ");
5395 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5396 to the DWARF address/line matrix. */
5397 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5398 || (xop
== DW_LNS_copy
))
5400 const unsigned int MAX_FILENAME_LENGTH
= 35;
5402 char *newFileName
= NULL
;
5403 size_t fileNameLength
;
5407 unsigned indx
= state_machine_regs
.file
- 1;
5409 if (indx
>= n_files
)
5411 warn (_("corrupt file index %u encountered\n"), indx
);
5412 fileName
= _("<corrupt>");
5415 fileName
= (char *) file_table
[indx
].name
;
5418 fileName
= _("<unknown>");
5420 fileNameLength
= strlen (fileName
);
5422 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5424 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5425 /* Truncate file name */
5426 strncpy (newFileName
,
5427 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5428 MAX_FILENAME_LENGTH
+ 1);
5429 /* FIXME: This is to pacify gcc-10 which can warn that the
5430 strncpy above might leave a non-NUL terminated string
5431 in newFileName. It won't, but gcc's analysis doesn't
5432 quite go far enough to discover this. */
5433 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5437 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5438 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5441 /* A row with end_seq set to true has a meaningful address, but
5442 the other information in the same row is not significant.
5443 In such a row, print line as "-", and don't print
5445 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5447 if (linfo
.li_max_ops_per_insn
== 1)
5449 if (xop
== -DW_LNE_end_sequence
)
5450 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5452 state_machine_regs
.address
);
5454 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5455 newFileName
, state_machine_regs
.line
,
5456 state_machine_regs
.address
);
5460 if (xop
== -DW_LNE_end_sequence
)
5461 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5463 state_machine_regs
.address
,
5464 state_machine_regs
.op_index
);
5466 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5467 newFileName
, state_machine_regs
.line
,
5468 state_machine_regs
.address
,
5469 state_machine_regs
.op_index
);
5474 if (linfo
.li_max_ops_per_insn
== 1)
5476 if (xop
== -DW_LNE_end_sequence
)
5477 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5479 state_machine_regs
.address
);
5481 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5482 newFileName
, state_machine_regs
.line
,
5483 state_machine_regs
.address
);
5487 if (xop
== -DW_LNE_end_sequence
)
5488 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5490 state_machine_regs
.address
,
5491 state_machine_regs
.op_index
);
5493 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5494 newFileName
, state_machine_regs
.line
,
5495 state_machine_regs
.address
,
5496 state_machine_regs
.op_index
);
5500 if (xop
!= -DW_LNE_end_sequence
)
5502 if (state_machine_regs
.view
)
5503 printf (" %6u", state_machine_regs
.view
);
5507 if (state_machine_regs
.is_stmt
)
5512 state_machine_regs
.view
++;
5514 if (xop
== -DW_LNE_end_sequence
)
5516 reset_state_machine (linfo
.li_default_is_stmt
);
5531 if (directory_table
)
5533 free (directory_table
);
5534 directory_table
= NULL
;
5545 display_debug_lines (struct dwarf_section
*section
, void *file
)
5547 unsigned char *data
= section
->start
;
5548 unsigned char *end
= data
+ section
->size
;
5550 int retValDecoded
= 1;
5552 if (do_debug_lines
== 0)
5553 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5555 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5556 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5558 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5559 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5561 if (!retValRaw
|| !retValDecoded
)
5568 find_debug_info_for_offset (unsigned long offset
)
5572 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5575 for (i
= 0; i
< num_debug_info_entries
; i
++)
5576 if (debug_information
[i
].cu_offset
== offset
)
5577 return debug_information
+ i
;
5583 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5585 /* See gdb/gdb-index.h. */
5586 static const char * const kinds
[] =
5598 return _ (kinds
[kind
]);
5602 display_debug_pubnames_worker (struct dwarf_section
*section
,
5603 void *file ATTRIBUTE_UNUSED
,
5606 DWARF2_Internal_PubNames names
;
5607 unsigned char *start
= section
->start
;
5608 unsigned char *end
= start
+ section
->size
;
5610 /* It does not matter if this load fails,
5611 we test for that later on. */
5612 load_debug_info (file
);
5614 introduce (section
, false);
5618 unsigned char *data
;
5619 unsigned long sec_off
= start
- section
->start
;
5620 unsigned int offset_size
;
5622 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5623 if (names
.pn_length
== 0xffffffff)
5625 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5631 if (names
.pn_length
> (size_t) (end
- start
))
5633 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5636 dwarf_vmatoa ("x", names
.pn_length
));
5641 start
+= names
.pn_length
;
5643 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5644 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5646 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5647 && num_debug_info_entries
> 0
5648 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5649 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5650 (unsigned long) names
.pn_offset
, section
->name
);
5652 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5654 printf (_(" Length: %ld\n"),
5655 (long) names
.pn_length
);
5656 printf (_(" Version: %d\n"),
5658 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5659 (unsigned long) names
.pn_offset
);
5660 printf (_(" Size of area in .debug_info section: %ld\n"),
5661 (long) names
.pn_size
);
5663 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5665 static int warned
= 0;
5669 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5677 printf (_("\n Offset Kind Name\n"));
5679 printf (_("\n Offset\tName\n"));
5683 bfd_size_type maxprint
;
5686 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5693 maxprint
= (start
- data
) - 1;
5697 unsigned int kind_data
;
5698 gdb_index_symbol_kind kind
;
5699 const char *kind_name
;
5702 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5704 /* GCC computes the kind as the upper byte in the CU index
5705 word, and then right shifts it by the CU index size.
5706 Left shift KIND to where the gdb-index.h accessor macros
5708 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5709 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5710 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5711 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5712 printf (" %-6lx %s,%-10s %.*s\n",
5713 (unsigned long) offset
, is_static
? _("s") : _("g"),
5714 kind_name
, (int) maxprint
, data
);
5717 printf (" %-6lx\t%.*s\n",
5718 (unsigned long) offset
, (int) maxprint
, data
);
5720 data
+= strnlen ((char *) data
, maxprint
);
5733 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5735 return display_debug_pubnames_worker (section
, file
, 0);
5739 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5741 return display_debug_pubnames_worker (section
, file
, 1);
5745 display_debug_macinfo (struct dwarf_section
*section
,
5746 void *file ATTRIBUTE_UNUSED
)
5748 unsigned char *start
= section
->start
;
5749 unsigned char *end
= start
+ section
->size
;
5750 unsigned char *curr
= start
;
5751 enum dwarf_macinfo_record_type op
;
5753 introduce (section
, false);
5757 unsigned int lineno
;
5758 const unsigned char *string
;
5760 op
= (enum dwarf_macinfo_record_type
) *curr
;
5765 case DW_MACINFO_start_file
:
5767 unsigned int filenum
;
5769 READ_ULEB (lineno
, curr
, end
);
5770 READ_ULEB (filenum
, curr
, end
);
5771 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5776 case DW_MACINFO_end_file
:
5777 printf (_(" DW_MACINFO_end_file\n"));
5780 case DW_MACINFO_define
:
5781 READ_ULEB (lineno
, curr
, end
);
5783 curr
+= strnlen ((char *) string
, end
- string
);
5784 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5785 lineno
, (int) (curr
- string
), string
);
5790 case DW_MACINFO_undef
:
5791 READ_ULEB (lineno
, curr
, end
);
5793 curr
+= strnlen ((char *) string
, end
- string
);
5794 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5795 lineno
, (int) (curr
- string
), string
);
5800 case DW_MACINFO_vendor_ext
:
5802 unsigned int constant
;
5804 READ_ULEB (constant
, curr
, end
);
5806 curr
+= strnlen ((char *) string
, end
- string
);
5807 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5808 constant
, (int) (curr
- string
), string
);
5819 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5820 filename and dirname corresponding to file name table entry with index
5821 FILEIDX. Return NULL on failure. */
5823 static unsigned char *
5824 get_line_filename_and_dirname (dwarf_vma line_offset
,
5826 unsigned char **dir_name
)
5828 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5829 unsigned char *hdrptr
, *dirtable
, *file_name
;
5830 unsigned int offset_size
;
5831 unsigned int version
, opcode_base
;
5832 dwarf_vma length
, diridx
;
5833 const unsigned char * end
;
5836 if (section
->start
== NULL
5837 || line_offset
>= section
->size
5841 hdrptr
= section
->start
+ line_offset
;
5842 end
= section
->start
+ section
->size
;
5844 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5845 if (length
== 0xffffffff)
5847 /* This section is 64-bit DWARF 3. */
5848 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5854 if (length
> (size_t) (end
- hdrptr
)
5855 || length
< 2 + offset_size
+ 1 + 3 + 1)
5857 end
= hdrptr
+ length
;
5859 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5860 if (version
!= 2 && version
!= 3 && version
!= 4)
5862 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5864 hdrptr
++; /* Skip max_ops_per_insn. */
5865 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5867 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5868 if (opcode_base
== 0
5869 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
5872 hdrptr
+= opcode_base
- 1;
5875 /* Skip over dirname table. */
5876 while (*hdrptr
!= '\0')
5878 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5884 hdrptr
++; /* Skip the NUL at the end of the table. */
5886 /* Now skip over preceding filename table entries. */
5887 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5889 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5892 SKIP_ULEB (hdrptr
, end
);
5893 SKIP_ULEB (hdrptr
, end
);
5894 SKIP_ULEB (hdrptr
, end
);
5896 if (hdrptr
>= end
|| *hdrptr
== '\0')
5900 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5905 READ_ULEB (diridx
, hdrptr
, end
);
5908 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5910 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
5914 if (dirtable
>= end
|| *dirtable
== '\0')
5916 *dir_name
= dirtable
;
5921 display_debug_macro (struct dwarf_section
*section
,
5924 unsigned char *start
= section
->start
;
5925 unsigned char *end
= start
+ section
->size
;
5926 unsigned char *curr
= start
;
5927 unsigned char *extended_op_buf
[256];
5928 bool is_dwo
= false;
5929 const char *suffix
= strrchr (section
->name
, '.');
5931 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
5934 load_debug_section_with_follow (str
, file
);
5935 load_debug_section_with_follow (line
, file
);
5936 load_debug_section_with_follow (str_index
, file
);
5938 introduce (section
, false);
5942 unsigned int lineno
, version
, flags
;
5943 unsigned int offset_size
;
5944 const unsigned char *string
;
5945 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5946 unsigned char **extended_ops
= NULL
;
5948 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5949 if (version
!= 4 && version
!= 5)
5951 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
5952 section
->name
, version
);
5956 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5957 offset_size
= (flags
& 1) ? 8 : 4;
5958 printf (_(" Offset: 0x%lx\n"),
5959 (unsigned long) sec_offset
);
5960 printf (_(" Version: %d\n"), version
);
5961 printf (_(" Offset size: %d\n"), offset_size
);
5964 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5965 printf (_(" Offset into .debug_line: 0x%lx\n"),
5966 (unsigned long) line_offset
);
5970 unsigned int i
, count
, op
;
5973 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5975 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5976 extended_ops
= extended_op_buf
;
5979 printf (_(" Extension opcode arguments:\n"));
5980 for (i
= 0; i
< count
; i
++)
5982 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5983 extended_ops
[op
] = curr
;
5984 READ_ULEB (nargs
, curr
, end
);
5986 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5989 printf (_(" DW_MACRO_%02x arguments: "), op
);
5990 for (n
= 0; n
< nargs
; n
++)
5994 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5995 printf ("%s%s", get_FORM_name (form
),
5996 n
== nargs
- 1 ? "\n" : ", ");
6006 case DW_FORM_block1
:
6007 case DW_FORM_block2
:
6008 case DW_FORM_block4
:
6010 case DW_FORM_string
:
6012 case DW_FORM_sec_offset
:
6015 error (_("Invalid extension opcode form %s\n"),
6016 get_FORM_name (form
));
6032 error (_(".debug_macro section not zero terminated\n"));
6036 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6042 case DW_MACRO_define
:
6043 READ_ULEB (lineno
, curr
, end
);
6045 curr
+= strnlen ((char *) string
, end
- string
);
6046 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6047 lineno
, (int) (curr
- string
), string
);
6052 case DW_MACRO_undef
:
6053 READ_ULEB (lineno
, curr
, end
);
6055 curr
+= strnlen ((char *) string
, end
- string
);
6056 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6057 lineno
, (int) (curr
- string
), string
);
6062 case DW_MACRO_start_file
:
6064 unsigned int filenum
;
6065 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6067 READ_ULEB (lineno
, curr
, end
);
6068 READ_ULEB (filenum
, curr
, end
);
6070 if ((flags
& 2) == 0)
6071 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6074 = get_line_filename_and_dirname (line_offset
, filenum
,
6076 if (file_name
== NULL
)
6077 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6080 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6082 dir_name
!= NULL
? (const char *) dir_name
: "",
6083 dir_name
!= NULL
? "/" : "", file_name
);
6087 case DW_MACRO_end_file
:
6088 printf (_(" DW_MACRO_end_file\n"));
6091 case DW_MACRO_define_strp
:
6092 READ_ULEB (lineno
, curr
, end
);
6093 if (version
== 4 && is_dwo
)
6094 READ_ULEB (offset
, curr
, end
);
6096 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6097 string
= fetch_indirect_string (offset
);
6098 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6102 case DW_MACRO_undef_strp
:
6103 READ_ULEB (lineno
, curr
, end
);
6104 if (version
== 4 && is_dwo
)
6105 READ_ULEB (offset
, curr
, end
);
6107 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6108 string
= fetch_indirect_string (offset
);
6109 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6113 case DW_MACRO_import
:
6114 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6115 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6116 (unsigned long) offset
);
6119 case DW_MACRO_define_sup
:
6120 READ_ULEB (lineno
, curr
, end
);
6121 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6122 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6123 lineno
, (unsigned long) offset
);
6126 case DW_MACRO_undef_sup
:
6127 READ_ULEB (lineno
, curr
, end
);
6128 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6129 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6130 lineno
, (unsigned long) offset
);
6133 case DW_MACRO_import_sup
:
6134 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6135 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6136 (unsigned long) offset
);
6139 case DW_MACRO_define_strx
:
6140 case DW_MACRO_undef_strx
:
6141 READ_ULEB (lineno
, curr
, end
);
6142 READ_ULEB (offset
, curr
, end
);
6143 string
= (const unsigned char *)
6144 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6145 if (op
== DW_MACRO_define_strx
)
6146 printf (" DW_MACRO_define_strx ");
6148 printf (" DW_MACRO_undef_strx ");
6150 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6151 printf (_("lineno : %d macro : %s\n"),
6156 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6158 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6162 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6164 error (_(" Unknown macro opcode %02x seen\n"), op
);
6169 /* Skip over unhandled opcodes. */
6171 unsigned char *desc
= extended_ops
[op
];
6172 READ_ULEB (nargs
, desc
, end
);
6175 printf (_(" DW_MACRO_%02x\n"), op
);
6178 printf (_(" DW_MACRO_%02x -"), op
);
6179 for (n
= 0; n
< nargs
; n
++)
6183 /* DW_FORM_implicit_const is not expected here. */
6184 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6186 = read_and_display_attr_value (0, val
, 0,
6187 start
, curr
, end
, 0, 0, offset_size
,
6188 version
, NULL
, 0, NULL
,
6206 display_debug_abbrev (struct dwarf_section
*section
,
6207 void *file ATTRIBUTE_UNUSED
)
6209 abbrev_entry
*entry
;
6210 unsigned char *start
= section
->start
;
6212 introduce (section
, false);
6219 offset
= start
- section
->start
;
6220 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6223 list
= new_abbrev_list (0, offset
);
6224 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6225 list
->start_of_next_abbrevs
= start
;
6228 start
= list
->start_of_next_abbrevs
;
6230 if (list
->first_abbrev
== NULL
)
6233 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6235 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6239 printf (" %ld %s [%s]\n",
6241 get_TAG_name (entry
->tag
),
6242 entry
->children
? _("has children") : _("no children"));
6244 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6246 printf (" %-18s %s",
6247 get_AT_name (attr
->attribute
),
6248 get_FORM_name (attr
->form
));
6249 if (attr
->form
== DW_FORM_implicit_const
)
6250 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
6262 /* Return true when ADDR is the maximum address, when addresses are
6263 POINTER_SIZE bytes long. */
6266 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6268 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6269 return ((addr
& mask
) == mask
);
6272 /* Display a view pair list starting at *VSTART_PTR and ending at
6273 VLISTEND within SECTION. */
6276 display_view_pair_list (struct dwarf_section
*section
,
6277 unsigned char **vstart_ptr
,
6278 unsigned int debug_info_entry
,
6279 unsigned char *vlistend
)
6281 unsigned char *vstart
= *vstart_ptr
;
6282 unsigned char *section_end
= section
->start
+ section
->size
;
6283 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6285 if (vlistend
< section_end
)
6286 section_end
= vlistend
;
6290 while (vstart
< section_end
)
6292 dwarf_vma off
= vstart
- section
->start
;
6293 dwarf_vma vbegin
, vend
;
6295 READ_ULEB (vbegin
, vstart
, section_end
);
6296 if (vstart
== section_end
)
6299 READ_ULEB (vend
, vstart
, section_end
);
6300 printf (" %8.8lx ", (unsigned long) off
);
6302 print_dwarf_view (vbegin
, pointer_size
, 1);
6303 print_dwarf_view (vend
, pointer_size
, 1);
6304 printf (_("location view pair\n"));
6308 *vstart_ptr
= vstart
;
6311 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6314 display_loc_list (struct dwarf_section
*section
,
6315 unsigned char **start_ptr
,
6316 unsigned int debug_info_entry
,
6318 dwarf_vma base_address
,
6319 unsigned char **vstart_ptr
,
6322 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6323 unsigned char *section_end
= section
->start
+ section
->size
;
6324 unsigned long cu_offset
;
6325 unsigned int pointer_size
;
6326 unsigned int offset_size
;
6331 unsigned short length
;
6332 int need_frame_base
;
6334 if (debug_info_entry
>= num_debug_info_entries
)
6336 warn (_("No debug information available for loc lists of entry: %u\n"),
6341 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6342 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6343 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6344 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6346 if (pointer_size
< 2 || pointer_size
> 8)
6348 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6349 pointer_size
, debug_info_entry
);
6355 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6356 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6358 if (2 * pointer_size
> (size_t) (section_end
- start
))
6360 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6361 (unsigned long) offset
);
6365 printf (" %8.8lx ", (unsigned long) off
);
6367 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6368 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6370 if (begin
== 0 && end
== 0)
6372 /* PR 18374: In a object file we can have a location list that
6373 starts with a begin and end of 0 because there are relocations
6374 that need to be applied to the addresses. Actually applying
6375 the relocations now does not help as they will probably resolve
6376 to 0, since the object file has not been fully linked. Real
6377 end of list markers will not have any relocations against them. */
6378 if (! reloc_at (section
, off
)
6379 && ! reloc_at (section
, off
+ pointer_size
))
6381 printf (_("<End of list>\n"));
6386 /* Check base address specifiers. */
6387 if (is_max_address (begin
, pointer_size
)
6388 && !is_max_address (end
, pointer_size
))
6391 print_dwarf_vma (begin
, pointer_size
);
6392 print_dwarf_vma (end
, pointer_size
);
6393 printf (_("(base address)\n"));
6399 off
= offset
+ (vstart
- *start_ptr
);
6401 READ_ULEB (vbegin
, vstart
, section_end
);
6402 print_dwarf_view (vbegin
, pointer_size
, 1);
6404 READ_ULEB (vend
, vstart
, section_end
);
6405 print_dwarf_view (vend
, pointer_size
, 1);
6407 printf (_("views at %8.8lx for:\n %*s "),
6408 (unsigned long) off
, 8, "");
6411 if (2 > (size_t) (section_end
- start
))
6413 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6414 (unsigned long) offset
);
6418 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6420 if (length
> (size_t) (section_end
- start
))
6422 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6423 (unsigned long) offset
);
6427 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6428 print_dwarf_vma (end
+ base_address
, pointer_size
);
6431 need_frame_base
= decode_location_expression (start
,
6436 cu_offset
, section
);
6439 if (need_frame_base
&& !has_frame_base
)
6440 printf (_(" [without DW_AT_frame_base]"));
6442 if (begin
== end
&& vbegin
== vend
)
6443 fputs (_(" (start == end)"), stdout
);
6444 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6445 fputs (_(" (start > end)"), stdout
);
6453 *vstart_ptr
= vstart
;
6456 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6459 display_loclists_list (struct dwarf_section
*section
,
6460 unsigned char **start_ptr
,
6461 unsigned int debug_info_entry
,
6463 dwarf_vma base_address
,
6464 unsigned char **vstart_ptr
,
6467 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6468 unsigned char *section_end
= section
->start
+ section
->size
;
6469 unsigned long cu_offset
;
6470 unsigned int pointer_size
;
6471 unsigned int offset_size
;
6474 /* Initialize it due to a false compiler warning. */
6475 dwarf_vma begin
= -1, vbegin
= -1;
6476 dwarf_vma end
= -1, vend
= -1;
6478 int need_frame_base
;
6480 if (debug_info_entry
>= num_debug_info_entries
)
6482 warn (_("No debug information available for "
6483 "loclists lists of entry: %u\n"),
6488 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6489 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6490 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6491 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6493 if (pointer_size
< 2 || pointer_size
> 8)
6495 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6496 pointer_size
, debug_info_entry
);
6502 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6503 enum dwarf_location_list_entry_type llet
;
6505 if (start
+ 1 > section_end
)
6507 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6508 (unsigned long) offset
);
6512 printf (" %8.8lx ", (unsigned long) off
);
6514 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6516 if (vstart
&& (llet
== DW_LLE_offset_pair
6517 || llet
== DW_LLE_start_end
6518 || llet
== DW_LLE_start_length
))
6520 off
= offset
+ (vstart
- *start_ptr
);
6522 READ_ULEB (vbegin
, vstart
, section_end
);
6523 print_dwarf_view (vbegin
, pointer_size
, 1);
6525 READ_ULEB (vend
, vstart
, section_end
);
6526 print_dwarf_view (vend
, pointer_size
, 1);
6528 printf (_("views at %8.8lx for:\n %*s "),
6529 (unsigned long) off
, 8, "");
6534 case DW_LLE_end_of_list
:
6535 printf (_("<End of list>\n"));
6537 case DW_LLE_offset_pair
:
6538 READ_ULEB (begin
, start
, section_end
);
6539 begin
+= base_address
;
6540 READ_ULEB (end
, start
, section_end
);
6541 end
+= base_address
;
6543 case DW_LLE_start_end
:
6544 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6545 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6547 case DW_LLE_start_length
:
6548 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6549 READ_ULEB (end
, start
, section_end
);
6552 case DW_LLE_base_address
:
6553 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6555 print_dwarf_vma (base_address
, pointer_size
);
6556 printf (_("(base address)\n"));
6558 #ifdef DW_LLE_view_pair
6559 case DW_LLE_view_pair
:
6561 printf (_("View pair entry in loclist with locviews attribute\n"));
6562 READ_ULEB (vbegin
, start
, section_end
);
6563 print_dwarf_view (vbegin
, pointer_size
, 1);
6565 READ_ULEB (vend
, start
, section_end
);
6566 print_dwarf_view (vend
, pointer_size
, 1);
6568 printf (_("views for:\n"));
6572 error (_("Invalid location list entry type %d\n"), llet
);
6575 if (llet
== DW_LLE_end_of_list
)
6577 if (llet
!= DW_LLE_offset_pair
6578 && llet
!= DW_LLE_start_end
6579 && llet
!= DW_LLE_start_length
)
6582 if (start
== section_end
)
6584 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6585 (unsigned long) offset
);
6588 READ_ULEB (length
, start
, section_end
);
6590 if (length
> (size_t) (section_end
- start
))
6592 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6593 (unsigned long) offset
);
6597 print_dwarf_vma (begin
, pointer_size
);
6598 print_dwarf_vma (end
, pointer_size
);
6601 need_frame_base
= decode_location_expression (start
,
6606 cu_offset
, section
);
6609 if (need_frame_base
&& !has_frame_base
)
6610 printf (_(" [without DW_AT_frame_base]"));
6612 if (begin
== end
&& vbegin
== vend
)
6613 fputs (_(" (start == end)"), stdout
);
6614 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6615 fputs (_(" (start > end)"), stdout
);
6623 if (vbegin
!= vm1
|| vend
!= vm1
)
6624 printf (_("Trailing view pair not used in a range"));
6627 *vstart_ptr
= vstart
;
6630 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6631 right-adjusted in a field of length LEN, and followed by a space. */
6634 print_addr_index (unsigned int idx
, unsigned int len
)
6636 static char buf
[15];
6637 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6638 printf ("%*s ", len
, buf
);
6641 /* Display a location list from a .dwo section. It uses address indexes rather
6642 than embedded addresses. This code closely follows display_loc_list, but the
6643 two are sufficiently different that combining things is very ugly. */
6646 display_loc_list_dwo (struct dwarf_section
*section
,
6647 unsigned char **start_ptr
,
6648 unsigned int debug_info_entry
,
6650 unsigned char **vstart_ptr
,
6653 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6654 unsigned char *section_end
= section
->start
+ section
->size
;
6655 unsigned long cu_offset
;
6656 unsigned int pointer_size
;
6657 unsigned int offset_size
;
6660 unsigned short length
;
6661 int need_frame_base
;
6664 if (debug_info_entry
>= num_debug_info_entries
)
6666 warn (_("No debug information for loc lists of entry: %u\n"),
6671 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6672 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6673 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6674 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6676 if (pointer_size
< 2 || pointer_size
> 8)
6678 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6679 pointer_size
, debug_info_entry
);
6685 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6687 if (start
>= section_end
)
6689 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6690 (unsigned long) offset
);
6694 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6707 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6709 READ_ULEB (view
, vstart
, section_end
);
6710 print_dwarf_view (view
, 8, 1);
6712 READ_ULEB (view
, vstart
, section_end
);
6713 print_dwarf_view (view
, 8, 1);
6715 printf (_("views at %8.8lx for:\n %*s "),
6716 (unsigned long) off
, 8, "");
6724 case 0: /* A terminating entry. */
6726 *vstart_ptr
= vstart
;
6727 printf (_("<End of list>\n"));
6729 case 1: /* A base-address entry. */
6730 READ_ULEB (idx
, start
, section_end
);
6731 print_addr_index (idx
, 8);
6732 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6733 printf (_("(base address selection entry)\n"));
6735 case 2: /* A start/end entry. */
6736 READ_ULEB (idx
, start
, section_end
);
6737 print_addr_index (idx
, 8);
6738 READ_ULEB (idx
, start
, section_end
);
6739 print_addr_index (idx
, 8);
6741 case 3: /* A start/length entry. */
6742 READ_ULEB (idx
, start
, section_end
);
6743 print_addr_index (idx
, 8);
6744 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6745 printf ("%08x ", idx
);
6747 case 4: /* An offset pair entry. */
6748 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6749 printf ("%08x ", idx
);
6750 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6751 printf ("%08x ", idx
);
6754 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6756 *vstart_ptr
= vstart
;
6760 if (2 > (size_t) (section_end
- start
))
6762 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6763 (unsigned long) offset
);
6767 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6768 if (length
> (size_t) (section_end
- start
))
6770 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6771 (unsigned long) offset
);
6776 need_frame_base
= decode_location_expression (start
,
6781 cu_offset
, section
);
6784 if (need_frame_base
&& !has_frame_base
)
6785 printf (_(" [without DW_AT_frame_base]"));
6793 *vstart_ptr
= vstart
;
6796 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6799 static dwarf_vma
*loc_offsets
, *loc_views
;
6802 loc_offsets_compar (const void *ap
, const void *bp
)
6804 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6805 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6807 int ret
= (a
> b
) - (b
> a
);
6811 a
= loc_views
[*(const unsigned int *) ap
];
6812 b
= loc_views
[*(const unsigned int *) bp
];
6814 ret
= (a
> b
) - (b
> a
);
6820 display_debug_loc (struct dwarf_section
*section
, void *file
)
6822 unsigned char *start
= section
->start
, *vstart
= NULL
;
6823 unsigned long bytes
;
6824 unsigned char *section_begin
= start
;
6825 unsigned int num_loc_list
= 0;
6826 unsigned long last_offset
= 0;
6827 unsigned long last_view
= 0;
6828 unsigned int first
= 0;
6831 int seen_first_offset
= 0;
6832 int locs_sorted
= 1;
6833 unsigned char *next
= start
, *vnext
= vstart
;
6834 unsigned int *array
= NULL
;
6835 const char *suffix
= strrchr (section
->name
, '.');
6836 bool is_dwo
= false;
6837 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6838 dwarf_vma expected_start
= 0;
6840 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6843 bytes
= section
->size
;
6847 printf (_("\nThe %s section is empty.\n"), section
->name
);
6853 unsigned char *hdrptr
= section_begin
;
6854 dwarf_vma ll_length
;
6855 unsigned short ll_version
;
6856 unsigned char *end
= section_begin
+ section
->size
;
6857 unsigned char address_size
, segment_selector_size
;
6858 uint32_t offset_entry_count
;
6860 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6861 if (ll_length
== 0xffffffff)
6862 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6864 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6865 if (ll_version
!= 5)
6867 warn (_("The %s section contains corrupt or "
6868 "unsupported version number: %d.\n"),
6869 section
->name
, ll_version
);
6873 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6875 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6876 if (segment_selector_size
!= 0)
6878 warn (_("The %s section contains "
6879 "unsupported segment selector size: %d.\n"),
6880 section
->name
, segment_selector_size
);
6884 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6885 if (offset_entry_count
!= 0)
6887 warn (_("The %s section contains "
6888 "unsupported offset entry count: %d.\n"),
6889 section
->name
, offset_entry_count
);
6893 expected_start
= hdrptr
- section_begin
;
6896 if (load_debug_info (file
) == 0)
6898 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6903 /* Check the order of location list in .debug_info section. If
6904 offsets of location lists are in the ascending order, we can
6905 use `debug_information' directly. */
6906 for (i
= 0; i
< num_debug_info_entries
; i
++)
6910 num
= debug_information
[i
].num_loc_offsets
;
6911 if (num
> num_loc_list
)
6914 /* Check if we can use `debug_information' directly. */
6915 if (locs_sorted
&& num
!= 0)
6917 if (!seen_first_offset
)
6919 /* This is the first location list. */
6920 last_offset
= debug_information
[i
].loc_offsets
[0];
6921 last_view
= debug_information
[i
].loc_views
[0];
6923 seen_first_offset
= 1;
6929 for (; j
< num
; j
++)
6932 debug_information
[i
].loc_offsets
[j
]
6933 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6934 && last_view
> debug_information
[i
].loc_views
[j
]))
6939 last_offset
= debug_information
[i
].loc_offsets
[j
];
6940 last_view
= debug_information
[i
].loc_views
[j
];
6945 if (!seen_first_offset
)
6946 error (_("No location lists in .debug_info section!\n"));
6948 if (debug_information
[first
].num_loc_offsets
> 0
6949 && debug_information
[first
].loc_offsets
[0] != expected_start
6950 && debug_information
[first
].loc_views
[0] != expected_start
)
6951 warn (_("Location lists in %s section start at 0x%s\n"),
6953 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6956 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6958 introduce (section
, false);
6960 if (reloc_at (section
, 0))
6961 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6963 printf (_(" Offset Begin End Expression\n"));
6965 seen_first_offset
= 0;
6966 for (i
= first
; i
< num_debug_info_entries
; i
++)
6968 dwarf_vma offset
, voffset
;
6969 dwarf_vma base_address
;
6975 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6977 loc_offsets
= debug_information
[i
].loc_offsets
;
6978 loc_views
= debug_information
[i
].loc_views
;
6979 qsort (array
, debug_information
[i
].num_loc_offsets
,
6980 sizeof (*array
), loc_offsets_compar
);
6983 int adjacent_view_loclists
= 1;
6984 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6986 j
= locs_sorted
? k
: array
[k
];
6988 && (debug_information
[i
].loc_offsets
[locs_sorted
6989 ? k
- 1 : array
[k
- 1]]
6990 == debug_information
[i
].loc_offsets
[j
])
6991 && (debug_information
[i
].loc_views
[locs_sorted
6992 ? k
- 1 : array
[k
- 1]]
6993 == debug_information
[i
].loc_views
[j
]))
6995 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6996 offset
= debug_information
[i
].loc_offsets
[j
];
6997 next
= section_begin
+ offset
;
6998 voffset
= debug_information
[i
].loc_views
[j
];
7000 vnext
= section_begin
+ voffset
;
7003 base_address
= debug_information
[i
].base_address
;
7005 if (vnext
&& vnext
< next
)
7008 display_view_pair_list (section
, &vstart
, i
, next
);
7013 if (!seen_first_offset
|| !adjacent_view_loclists
)
7014 seen_first_offset
= 1;
7018 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
7019 (unsigned long) (start
- section_begin
),
7020 (unsigned long) offset
);
7021 else if (start
> next
)
7022 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
7023 (unsigned long) (start
- section_begin
),
7024 (unsigned long) offset
);
7029 if (offset
>= bytes
)
7031 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
7032 (unsigned long) offset
);
7036 if (vnext
&& voffset
>= bytes
)
7038 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
7039 (unsigned long) voffset
);
7046 display_loc_list_dwo (section
, &start
, i
, offset
,
7047 &vstart
, has_frame_base
);
7049 display_loc_list (section
, &start
, i
, offset
, base_address
,
7050 &vstart
, has_frame_base
);
7055 warn (_("DWO is not yet supported.\n"));
7057 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7058 &vstart
, has_frame_base
);
7061 /* FIXME: this arrangement is quite simplistic. Nothing
7062 requires locview lists to be adjacent to corresponding
7063 loclists, and a single loclist could be augmented by
7064 different locview lists, and vice-versa, unlikely as it
7065 is that it would make sense to do so. Hopefully we'll
7066 have view pair support built into loclists before we ever
7067 need to address all these possibilities. */
7068 if (adjacent_view_loclists
&& vnext
7069 && vnext
!= start
&& vstart
!= next
)
7071 adjacent_view_loclists
= 0;
7072 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7075 if (vnext
&& vnext
== start
)
7076 display_view_pair_list (section
, &start
, i
, vstart
);
7080 if (start
< section
->start
+ section
->size
)
7081 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7082 "There are %ld unused bytes at the end of section %s\n",
7083 (long) (section
->start
+ section
->size
- start
)),
7084 (long) (section
->start
+ section
->size
- start
), section
->name
);
7091 display_debug_str (struct dwarf_section
*section
,
7092 void *file ATTRIBUTE_UNUSED
)
7094 unsigned char *start
= section
->start
;
7095 unsigned long bytes
= section
->size
;
7096 dwarf_vma addr
= section
->address
;
7100 printf (_("\nThe %s section is empty.\n"), section
->name
);
7104 introduce (section
, false);
7112 lbytes
= (bytes
> 16 ? 16 : bytes
);
7114 printf (" 0x%8.8lx ", (unsigned long) addr
);
7116 for (j
= 0; j
< 16; j
++)
7119 printf ("%2.2x", start
[j
]);
7127 for (j
= 0; j
< lbytes
; j
++)
7130 if (k
>= ' ' && k
< 0x80)
7149 display_debug_info (struct dwarf_section
*section
, void *file
)
7151 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7155 display_debug_types (struct dwarf_section
*section
, void *file
)
7157 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7161 display_trace_info (struct dwarf_section
*section
, void *file
)
7163 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7167 display_debug_aranges (struct dwarf_section
*section
,
7168 void *file ATTRIBUTE_UNUSED
)
7170 unsigned char *start
= section
->start
;
7171 unsigned char *end
= start
+ section
->size
;
7173 introduce (section
, false);
7175 /* It does not matter if this load fails,
7176 we test for that later on. */
7177 load_debug_info (file
);
7181 unsigned char *hdrptr
;
7182 DWARF2_Internal_ARange arange
;
7183 unsigned char *addr_ranges
;
7186 unsigned long sec_off
;
7187 unsigned char address_size
;
7189 unsigned int offset_size
;
7190 unsigned char *end_ranges
;
7193 sec_off
= hdrptr
- section
->start
;
7195 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7196 if (arange
.ar_length
== 0xffffffff)
7198 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7204 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7206 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7209 dwarf_vmatoa ("x", arange
.ar_length
));
7212 end_ranges
= hdrptr
+ arange
.ar_length
;
7214 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7215 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7218 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7219 && num_debug_info_entries
> 0
7220 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7221 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7222 (unsigned long) arange
.ar_info_offset
, section
->name
);
7224 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7225 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7227 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7229 /* PR 19872: A version number of 0 probably means that there is
7230 padding at the end of the .debug_aranges section. Gold puts
7231 it there when performing an incremental link, for example.
7232 So do not generate a warning in this case. */
7233 if (arange
.ar_version
)
7234 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7238 printf (_(" Length: %ld\n"),
7239 (long) arange
.ar_length
);
7240 printf (_(" Version: %d\n"), arange
.ar_version
);
7241 printf (_(" Offset into .debug_info: 0x%lx\n"),
7242 (unsigned long) arange
.ar_info_offset
);
7243 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7244 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7246 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7248 /* PR 17512: file: 001-108546-0.001:0.1. */
7249 if (address_size
== 0 || address_size
> 8)
7251 error (_("Invalid address size in %s section!\n"),
7256 /* The DWARF spec does not require that the address size be a power
7257 of two, but we do. This will have to change if we ever encounter
7258 an uneven architecture. */
7259 if ((address_size
& (address_size
- 1)) != 0)
7261 warn (_("Pointer size + Segment size is not a power of two.\n"));
7265 if (address_size
> 4)
7266 printf (_("\n Address Length\n"));
7268 printf (_("\n Address Length\n"));
7270 addr_ranges
= hdrptr
;
7272 /* Must pad to an alignment boundary that is twice the address size. */
7273 excess
= (hdrptr
- start
) % (2 * address_size
);
7275 addr_ranges
+= (2 * address_size
) - excess
;
7279 while (2 * address_size
<= (size_t) (start
- addr_ranges
))
7281 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, start
);
7282 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, start
);
7285 print_dwarf_vma (address
, address_size
);
7286 print_dwarf_vma (length
, address_size
);
7296 /* Comparison function for qsort. */
7298 comp_addr_base (const void * v0
, const void * v1
)
7300 debug_info
*info0
= *(debug_info
**) v0
;
7301 debug_info
*info1
= *(debug_info
**) v1
;
7302 return info0
->addr_base
- info1
->addr_base
;
7305 /* Display the debug_addr section. */
7307 display_debug_addr (struct dwarf_section
*section
,
7310 debug_info
**debug_addr_info
;
7311 unsigned char *entry
;
7315 unsigned char * header
;
7317 if (section
->size
== 0)
7319 printf (_("\nThe %s section is empty.\n"), section
->name
);
7323 if (load_debug_info (file
) == 0)
7325 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7330 introduce (section
, false);
7332 /* PR 17531: file: cf38d01b.
7333 We use xcalloc because a corrupt file may not have initialised all of the
7334 fields in the debug_info structure, which means that the sort below might
7335 try to move uninitialised data. */
7336 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7337 sizeof (debug_info
*));
7340 for (i
= 0; i
< num_debug_info_entries
; i
++)
7341 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7343 /* PR 17531: file: cf38d01b. */
7344 if (debug_information
[i
].addr_base
>= section
->size
)
7345 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7346 (unsigned long) debug_information
[i
].addr_base
, i
);
7348 debug_addr_info
[count
++] = debug_information
+ i
;
7351 /* Add a sentinel to make iteration convenient. */
7352 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7353 debug_addr_info
[count
]->addr_base
= section
->size
;
7354 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7356 header
= section
->start
;
7357 for (i
= 0; i
< count
; i
++)
7360 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7362 printf (_(" For compilation unit at offset 0x%s:\n"),
7363 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7365 printf (_("\tIndex\tAddress\n"));
7366 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7367 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7369 size_t header_size
= entry
- header
;
7370 unsigned char * curr_header
= header
;
7373 int segment_selector_size
;
7375 if (header_size
!= 8 && header_size
!= 16)
7377 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7378 section
->name
, (long) header_size
);
7382 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7383 if (length
== 0xffffffff)
7384 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7385 end
= curr_header
+ length
;
7387 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7389 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7390 section
->name
, version
);
7392 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7393 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7394 address_size
+= segment_selector_size
;
7397 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7402 dwarf_vma base
= byte_get (entry
, address_size
);
7403 printf (_("\t%d:\t"), idx
);
7404 print_dwarf_vma (base
, address_size
);
7406 entry
+= address_size
;
7412 free (debug_addr_info
);
7416 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7419 display_debug_str_offsets (struct dwarf_section
*section
,
7420 void *file ATTRIBUTE_UNUSED
)
7424 if (section
->size
== 0)
7426 printf (_("\nThe %s section is empty.\n"), section
->name
);
7430 unsigned char *start
= section
->start
;
7431 unsigned char *end
= start
+ section
->size
;
7432 unsigned char *curr
= start
;
7434 const char *suffix
= strrchr (section
->name
, '.');
7435 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7438 load_debug_section_with_follow (str_dwo
, file
);
7440 load_debug_section_with_follow (str
, file
);
7442 introduce (section
, false);
7447 dwarf_vma entry_length
;
7449 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7450 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7451 if (length
== 0xffffffff)
7453 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7459 unsigned char *entries_end
;
7462 /* This is probably an old style .debug_str_offset section which
7463 just contains offsets and no header (and the first offset is 0). */
7464 length
= section
->size
;
7465 curr
= section
->start
;
7468 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7469 printf (_(" Index Offset [String]\n"));
7473 if (length
<= (dwarf_vma
) (end
- curr
))
7474 entries_end
= curr
+ length
;
7477 warn (_("Section %s is too small %#lx\n"),
7478 section
->name
, (unsigned long) section
->size
);
7483 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7485 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7488 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7490 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7492 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7493 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7494 printf (_(" Index Offset [String]\n"));
7497 for (idx
= 0; curr
< entries_end
; idx
++)
7500 const unsigned char * string
;
7502 if ((dwarf_vma
) (entries_end
- curr
) < entry_length
)
7503 /* Not enough space to read one entry_length, give up. */
7506 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7508 string
= (const unsigned char *)
7509 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7511 string
= fetch_indirect_string (offset
);
7513 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7521 /* Each debug_information[x].range_lists[y] gets this representation for
7522 sorting purposes. */
7526 /* The debug_information[x].range_lists[y] value. */
7527 dwarf_vma ranges_offset
;
7529 /* Original debug_information to find parameters of the data. */
7530 debug_info
*debug_info_p
;
7533 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7536 range_entry_compar (const void *ap
, const void *bp
)
7538 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7539 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7540 const dwarf_vma a
= a_re
->ranges_offset
;
7541 const dwarf_vma b
= b_re
->ranges_offset
;
7543 return (a
> b
) - (b
> a
);
7547 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7548 unsigned int pointer_size
, unsigned long offset
,
7549 unsigned long base_address
)
7551 while (start
< finish
)
7556 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7557 if (start
>= finish
)
7559 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7561 printf (" %8.8lx ", offset
);
7563 if (begin
== 0 && end
== 0)
7565 printf (_("<End of list>\n"));
7569 /* Check base address specifiers. */
7570 if (is_max_address (begin
, pointer_size
)
7571 && !is_max_address (end
, pointer_size
))
7574 print_dwarf_vma (begin
, pointer_size
);
7575 print_dwarf_vma (end
, pointer_size
);
7576 printf ("(base address)\n");
7580 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7581 print_dwarf_vma (end
+ base_address
, pointer_size
);
7584 fputs (_("(start == end)"), stdout
);
7585 else if (begin
> end
)
7586 fputs (_("(start > end)"), stdout
);
7593 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7594 unsigned int pointer_size
, unsigned long offset
,
7595 unsigned long base_address
)
7597 unsigned char *next
= start
;
7601 unsigned long off
= offset
+ (start
- next
);
7602 enum dwarf_range_list_entry rlet
;
7603 /* Initialize it due to a false compiler warning. */
7604 dwarf_vma begin
= -1, length
, end
= -1;
7606 if (start
>= finish
)
7608 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7613 printf (" %8.8lx ", off
);
7615 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7619 case DW_RLE_end_of_list
:
7620 printf (_("<End of list>\n"));
7622 case DW_RLE_base_address
:
7623 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7624 print_dwarf_vma (base_address
, pointer_size
);
7625 printf (_("(base address)\n"));
7627 case DW_RLE_start_length
:
7628 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7629 READ_ULEB (length
, start
, finish
);
7630 end
= begin
+ length
;
7632 case DW_RLE_offset_pair
:
7633 READ_ULEB (begin
, start
, finish
);
7634 READ_ULEB (end
, start
, finish
);
7636 case DW_RLE_start_end
:
7637 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7638 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7641 error (_("Invalid range list entry type %d\n"), rlet
);
7642 rlet
= DW_RLE_end_of_list
;
7645 if (rlet
== DW_RLE_end_of_list
)
7647 if (rlet
== DW_RLE_base_address
)
7650 /* Only a DW_RLE_offset_pair needs the base address added. */
7651 if (rlet
== DW_RLE_offset_pair
)
7653 begin
+= base_address
;
7654 end
+= base_address
;
7657 print_dwarf_vma (begin
, pointer_size
);
7658 print_dwarf_vma (end
, pointer_size
);
7661 fputs (_("(start == end)"), stdout
);
7662 else if (begin
> end
)
7663 fputs (_("(start > end)"), stdout
);
7670 display_debug_ranges (struct dwarf_section
*section
,
7671 void *file ATTRIBUTE_UNUSED
)
7673 unsigned char *start
= section
->start
;
7674 unsigned char *last_start
= start
;
7675 unsigned long bytes
= section
->size
;
7676 unsigned char *section_begin
= start
;
7677 unsigned char *finish
= start
+ bytes
;
7678 unsigned int num_range_list
, i
;
7679 struct range_entry
*range_entries
, *range_entry_fill
;
7680 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7681 /* Initialize it due to a false compiler warning. */
7682 unsigned char address_size
= 0;
7683 dwarf_vma last_offset
= 0;
7687 printf (_("\nThe %s section is empty.\n"), section
->name
);
7693 dwarf_vma initial_length
;
7694 unsigned char segment_selector_size
;
7695 unsigned int offset_size
, offset_entry_count
;
7696 unsigned short version
;
7698 /* Get and check the length of the block. */
7699 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7701 if (initial_length
== 0xffffffff)
7703 /* This section is 64-bit DWARF 3. */
7704 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7710 if (initial_length
> (size_t) (finish
- start
))
7712 /* If the length field has a relocation against it, then we should
7713 not complain if it is inaccurate (and probably negative).
7714 It is copied from .debug_line handling code. */
7715 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7717 initial_length
= finish
- start
;
7721 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7722 (long) initial_length
);
7726 finish
= start
+ initial_length
;
7728 /* Get and check the version number. */
7729 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7733 warn (_("Only DWARF version 5 debug_rnglists info "
7734 "is currently supported.\n"));
7738 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7740 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7741 if (segment_selector_size
!= 0)
7743 warn (_("The %s section contains "
7744 "unsupported segment selector size: %d.\n"),
7745 section
->name
, segment_selector_size
);
7749 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7750 if (offset_entry_count
!= 0)
7752 warn (_("The %s section contains "
7753 "unsupported offset entry count: %u.\n"),
7754 section
->name
, offset_entry_count
);
7759 if (load_debug_info (file
) == 0)
7761 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7767 for (i
= 0; i
< num_debug_info_entries
; i
++)
7769 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7770 /* Skip .debug_rnglists reference. */
7772 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7773 /* Skip .debug_range reference. */
7775 num_range_list
+= debug_information
[i
].num_range_lists
;
7778 if (num_range_list
== 0)
7780 /* This can happen when the file was compiled with -gsplit-debug
7781 which removes references to range lists from the primary .o file. */
7782 printf (_("No range lists in .debug_info section.\n"));
7786 range_entries
= (struct range_entry
*)
7787 xmalloc (sizeof (*range_entries
) * num_range_list
);
7788 range_entry_fill
= range_entries
;
7790 for (i
= 0; i
< num_debug_info_entries
; i
++)
7792 debug_info
*debug_info_p
= &debug_information
[i
];
7795 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
7796 /* Skip .debug_rnglists reference. */
7798 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
7799 /* Skip .debug_range reference. */
7802 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7804 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7805 range_entry_fill
->debug_info_p
= debug_info_p
;
7810 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7811 range_entry_compar
);
7813 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7814 warn (_("Range lists in %s section start at 0x%lx\n"),
7815 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7817 introduce (section
, false);
7819 printf (_(" Offset Begin End\n"));
7821 for (i
= 0; i
< num_range_list
; i
++)
7823 struct range_entry
*range_entry
= &range_entries
[i
];
7824 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7825 unsigned int pointer_size
;
7827 unsigned char *next
;
7828 dwarf_vma base_address
;
7830 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7831 offset
= range_entry
->ranges_offset
;
7832 base_address
= debug_info_p
->base_address
;
7834 /* PR 17512: file: 001-101485-0.001:0.1. */
7835 if (pointer_size
< 2 || pointer_size
> 8)
7837 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7838 pointer_size
, (unsigned long) offset
);
7842 if (offset
> (size_t) (finish
- section_begin
))
7844 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7845 (unsigned long) offset
, i
);
7848 next
= section_begin
+ offset
;
7850 /* If multiple DWARF entities reference the same range then we will
7851 have multiple entries in the `range_entries' list for the same
7852 offset. Thanks to the sort above these will all be consecutive in
7853 the `range_entries' list, so we can easily ignore duplicates
7855 if (i
> 0 && last_offset
== offset
)
7857 last_offset
= offset
;
7859 if (dwarf_check
!= 0 && i
> 0)
7862 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7863 (unsigned long) (start
- section_begin
),
7864 (unsigned long) (next
- section_begin
), section
->name
);
7865 else if (start
> next
)
7867 if (next
== last_start
)
7869 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7870 (unsigned long) (start
- section_begin
),
7871 (unsigned long) (next
- section_begin
), section
->name
);
7878 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7879 (start
, finish
, pointer_size
, offset
, base_address
);
7883 free (range_entries
);
7888 typedef struct Frame_Chunk
7890 struct Frame_Chunk
*next
;
7891 unsigned char *chunk_start
;
7893 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7894 short int *col_type
;
7897 unsigned int code_factor
;
7901 unsigned int cfa_reg
;
7902 dwarf_vma cfa_offset
;
7904 unsigned char fde_encoding
;
7905 unsigned char cfa_exp
;
7906 unsigned char ptr_size
;
7907 unsigned char segment_size
;
7911 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7912 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7913 static const char *const *dwarf_regnames
;
7914 static unsigned int dwarf_regnames_count
;
7917 /* A marker for a col_type that means this column was never referenced
7918 in the frame info. */
7919 #define DW_CFA_unreferenced (-1)
7921 /* Return 0 if no more space is needed, 1 if more space is needed,
7922 -1 for invalid reg. */
7925 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7927 unsigned int prev
= fc
->ncols
;
7929 if (reg
< (unsigned int) fc
->ncols
)
7932 if (dwarf_regnames_count
> 0
7933 && reg
> dwarf_regnames_count
)
7936 fc
->ncols
= reg
+ 1;
7937 /* PR 17512: file: 10450-2643-0.004.
7938 If reg == -1 then this can happen... */
7942 /* PR 17512: file: 2844a11d. */
7943 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7945 error (_("Unfeasibly large register number: %u\n"), reg
);
7947 /* FIXME: 1024 is an arbitrary limit. Increase it if
7948 we ever encounter a valid binary that exceeds it. */
7952 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7953 sizeof (short int));
7954 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7955 /* PR 17512: file:002-10025-0.005. */
7956 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7958 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7964 while (prev
< fc
->ncols
)
7966 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7967 fc
->col_offset
[prev
] = 0;
7973 static const char *const dwarf_regnames_i386
[] =
7975 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7976 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7977 "eip", "eflags", NULL
, /* 8 - 10 */
7978 "st0", "st1", "st2", "st3", /* 11 - 14 */
7979 "st4", "st5", "st6", "st7", /* 15 - 18 */
7980 NULL
, NULL
, /* 19 - 20 */
7981 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7982 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7983 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7984 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7985 "fcw", "fsw", "mxcsr", /* 37 - 39 */
7986 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7987 "tr", "ldtr", /* 48 - 49 */
7988 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7989 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7990 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7991 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7992 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7993 NULL
, NULL
, NULL
, /* 90 - 92 */
7994 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
7997 static const char *const dwarf_regnames_iamcu
[] =
7999 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8000 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8001 "eip", "eflags", NULL
, /* 8 - 10 */
8002 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8003 NULL
, NULL
, /* 19 - 20 */
8004 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8005 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8006 NULL
, NULL
, NULL
, /* 37 - 39 */
8007 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8008 "tr", "ldtr", /* 48 - 49 */
8009 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8010 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8011 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8012 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8013 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8014 NULL
, NULL
, NULL
, /* 90 - 92 */
8015 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8019 init_dwarf_regnames_i386 (void)
8021 dwarf_regnames
= dwarf_regnames_i386
;
8022 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8023 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8027 init_dwarf_regnames_iamcu (void)
8029 dwarf_regnames
= dwarf_regnames_iamcu
;
8030 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8031 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8034 static const char *const dwarf_regnames_x86_64
[] =
8036 "rax", "rdx", "rcx", "rbx",
8037 "rsi", "rdi", "rbp", "rsp",
8038 "r8", "r9", "r10", "r11",
8039 "r12", "r13", "r14", "r15",
8041 "xmm0", "xmm1", "xmm2", "xmm3",
8042 "xmm4", "xmm5", "xmm6", "xmm7",
8043 "xmm8", "xmm9", "xmm10", "xmm11",
8044 "xmm12", "xmm13", "xmm14", "xmm15",
8045 "st0", "st1", "st2", "st3",
8046 "st4", "st5", "st6", "st7",
8047 "mm0", "mm1", "mm2", "mm3",
8048 "mm4", "mm5", "mm6", "mm7",
8050 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8051 "fs.base", "gs.base", NULL
, NULL
,
8053 "mxcsr", "fcw", "fsw",
8054 "xmm16", "xmm17", "xmm18", "xmm19",
8055 "xmm20", "xmm21", "xmm22", "xmm23",
8056 "xmm24", "xmm25", "xmm26", "xmm27",
8057 "xmm28", "xmm29", "xmm30", "xmm31",
8058 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8059 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8060 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8061 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8062 NULL
, NULL
, NULL
, /* 115 - 117 */
8063 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8067 init_dwarf_regnames_x86_64 (void)
8069 dwarf_regnames
= dwarf_regnames_x86_64
;
8070 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8071 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8074 static const char *const dwarf_regnames_aarch64
[] =
8076 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8077 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8078 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8079 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8080 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8081 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8082 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8083 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8084 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8085 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8086 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8087 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8088 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8089 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8090 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8091 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8095 init_dwarf_regnames_aarch64 (void)
8097 dwarf_regnames
= dwarf_regnames_aarch64
;
8098 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8099 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8102 static const char *const dwarf_regnames_s390
[] =
8104 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8105 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8106 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8107 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8108 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8109 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8110 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8111 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8112 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8115 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8116 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8120 init_dwarf_regnames_s390 (void)
8122 dwarf_regnames
= dwarf_regnames_s390
;
8123 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8124 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8127 static const char *const dwarf_regnames_riscv
[] =
8129 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8130 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8131 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8132 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8133 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8134 "fs0", "fs1", /* 40 - 41 */
8135 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8136 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8137 "fs10", "fs11", /* 58 - 59 */
8138 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8141 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8142 the large number of CSRs. */
8145 regname_internal_riscv (unsigned int regno
)
8147 const char *name
= NULL
;
8149 /* Lookup in the table first, this covers GPR and FPR. */
8150 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8151 name
= dwarf_regnames_riscv
[regno
];
8152 else if (regno
>= 4096 && regno
<= 8191)
8154 /* This might be a CSR, these live in a sparse number space from 4096
8155 to 8191 These numbers are defined in the RISC-V ELF ABI
8159 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8160 case VALUE + 4096: name = #NAME; break;
8161 #include "opcode/riscv-opc.h"
8166 static char csr_name
[10];
8167 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8178 init_dwarf_regnames_riscv (void)
8180 dwarf_regnames
= NULL
;
8181 dwarf_regnames_count
= 8192;
8182 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8186 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8188 dwarf_regnames_lookup_func
= NULL
;
8193 init_dwarf_regnames_i386 ();
8197 init_dwarf_regnames_iamcu ();
8203 init_dwarf_regnames_x86_64 ();
8207 init_dwarf_regnames_aarch64 ();
8211 init_dwarf_regnames_s390 ();
8215 init_dwarf_regnames_riscv ();
8223 /* Initialize the DWARF register name lookup state based on the
8224 architecture and specific machine type of a BFD. */
8227 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8230 dwarf_regnames_lookup_func
= NULL
;
8237 case bfd_mach_x86_64
:
8238 case bfd_mach_x86_64_intel_syntax
:
8239 case bfd_mach_x64_32
:
8240 case bfd_mach_x64_32_intel_syntax
:
8241 init_dwarf_regnames_x86_64 ();
8245 init_dwarf_regnames_i386 ();
8250 case bfd_arch_iamcu
:
8251 init_dwarf_regnames_iamcu ();
8254 case bfd_arch_aarch64
:
8255 init_dwarf_regnames_aarch64();
8259 init_dwarf_regnames_s390 ();
8262 case bfd_arch_riscv
:
8263 init_dwarf_regnames_riscv ();
8272 regname_internal_by_table_only (unsigned int regno
)
8274 if (dwarf_regnames
!= NULL
8275 && regno
< dwarf_regnames_count
8276 && dwarf_regnames
[regno
] != NULL
)
8277 return dwarf_regnames
[regno
];
8283 regname (unsigned int regno
, int name_only_p
)
8285 static char reg
[64];
8287 const char *name
= NULL
;
8289 if (dwarf_regnames_lookup_func
!= NULL
)
8290 name
= dwarf_regnames_lookup_func (regno
);
8296 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8299 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8304 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8309 if (*max_regs
!= fc
->ncols
)
8310 *max_regs
= fc
->ncols
;
8312 if (*need_col_headers
)
8314 *need_col_headers
= 0;
8316 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8318 for (r
= 0; r
< *max_regs
; r
++)
8319 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8324 printf ("%-5s ", regname (r
, 1));
8330 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8332 strcpy (tmp
, "exp");
8334 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8335 printf ("%-8s ", tmp
);
8337 for (r
= 0; r
< fc
->ncols
; r
++)
8339 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8341 switch (fc
->col_type
[r
])
8343 case DW_CFA_undefined
:
8346 case DW_CFA_same_value
:
8350 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8352 case DW_CFA_val_offset
:
8353 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8355 case DW_CFA_register
:
8356 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8358 case DW_CFA_expression
:
8359 strcpy (tmp
, "exp");
8361 case DW_CFA_val_expression
:
8362 strcpy (tmp
, "vexp");
8365 strcpy (tmp
, "n/a");
8368 printf ("%-5s ", tmp
);
8374 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8376 static unsigned char *
8377 read_cie (unsigned char *start
, unsigned char *end
,
8378 Frame_Chunk
**p_cie
, int *p_version
,
8379 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8383 unsigned char *augmentation_data
= NULL
;
8384 bfd_size_type augmentation_data_len
= 0;
8387 /* PR 17512: file: 001-228113-0.004. */
8391 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8392 memset (fc
, 0, sizeof (Frame_Chunk
));
8394 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8395 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8399 fc
->augmentation
= (char *) start
;
8400 /* PR 17512: file: 001-228113-0.004.
8401 Skip past augmentation name, but avoid running off the end of the data. */
8403 if (* start
++ == '\0')
8407 warn (_("No terminator for augmentation name\n"));
8411 if (strcmp (fc
->augmentation
, "eh") == 0)
8413 if (eh_addr_size
> (size_t) (end
- start
))
8415 start
+= eh_addr_size
;
8420 if (2 > (size_t) (end
- start
))
8422 GET (fc
->ptr_size
, 1);
8423 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8425 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8429 GET (fc
->segment_size
, 1);
8430 /* PR 17512: file: e99d2804. */
8431 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8433 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8437 eh_addr_size
= fc
->ptr_size
;
8441 fc
->ptr_size
= eh_addr_size
;
8442 fc
->segment_size
= 0;
8445 READ_ULEB (fc
->code_factor
, start
, end
);
8446 READ_SLEB (fc
->data_factor
, start
, end
);
8457 READ_ULEB (fc
->ra
, start
, end
);
8460 if (fc
->augmentation
[0] == 'z')
8464 READ_ULEB (augmentation_data_len
, start
, end
);
8465 augmentation_data
= start
;
8466 /* PR 17512: file: 11042-2589-0.004. */
8467 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8469 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8470 dwarf_vmatoa ("x", augmentation_data_len
),
8471 (unsigned long) (end
- start
));
8474 start
+= augmentation_data_len
;
8477 if (augmentation_data_len
)
8481 unsigned char *qend
;
8483 p
= (unsigned char *) fc
->augmentation
+ 1;
8484 q
= augmentation_data
;
8485 qend
= q
+ augmentation_data_len
;
8487 while (p
< end
&& q
< qend
)
8492 q
+= 1 + size_of_encoded_value (*q
);
8494 fc
->fde_encoding
= *q
++;
8503 /* Note - it is OK if this loop terminates with q < qend.
8504 Padding may have been inserted to align the end of the CIE. */
8509 *p_version
= version
;
8512 *p_aug_len
= augmentation_data_len
;
8513 *p_aug
= augmentation_data
;
8518 free (fc
->col_offset
);
8519 free (fc
->col_type
);
8524 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8525 If do_wide is not enabled, then formats the output to fit into 80 columns.
8526 PRINTED contains the number of characters already written to the current
8530 display_data (bfd_size_type printed
,
8531 const unsigned char * data
,
8532 const bfd_size_type len
)
8534 if (do_wide
|| len
< ((80 - printed
) / 3))
8535 for (printed
= 0; printed
< len
; ++printed
)
8536 printf (" %02x", data
[printed
]);
8539 for (printed
= 0; printed
< len
; ++printed
)
8541 if (printed
% (80 / 3) == 0)
8543 printf (" %02x", data
[printed
]);
8548 /* Prints out the contents on the augmentation data array.
8549 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8552 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8556 i
= printf (_(" Augmentation data: "));
8557 display_data (i
, data
, len
);
8561 display_debug_frames (struct dwarf_section
*section
,
8562 void *file ATTRIBUTE_UNUSED
)
8564 unsigned char *start
= section
->start
;
8565 unsigned char *end
= start
+ section
->size
;
8566 unsigned char *section_start
= start
;
8567 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8568 Frame_Chunk
*remembered_state
= NULL
;
8570 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8571 unsigned int max_regs
= 0;
8572 const char *bad_reg
= _("bad register: ");
8573 unsigned int saved_eh_addr_size
= eh_addr_size
;
8575 introduce (section
, false);
8579 unsigned char *saved_start
;
8580 unsigned char *block_end
;
8585 int need_col_headers
= 1;
8586 unsigned char *augmentation_data
= NULL
;
8587 bfd_size_type augmentation_data_len
= 0;
8588 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8589 unsigned int offset_size
;
8591 static Frame_Chunk fde_fc
;
8593 saved_start
= start
;
8595 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8599 printf ("\n%08lx ZERO terminator\n\n",
8600 (unsigned long)(saved_start
- section_start
));
8601 /* Skip any zero terminators that directly follow.
8602 A corrupt section size could have loaded a whole
8603 slew of zero filled memory bytes. eg
8604 PR 17512: file: 070-19381-0.004. */
8605 while (start
< end
&& * start
== 0)
8610 if (length
== 0xffffffff)
8612 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8618 if (length
> (size_t) (end
- start
))
8620 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8621 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8622 (unsigned long) (saved_start
- section_start
));
8626 block_end
= start
+ length
;
8628 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
8630 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8631 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8636 start
= read_cie (start
, block_end
, &cie
, &version
,
8637 &augmentation_data_len
, &augmentation_data
);
8638 /* PR 17512: file: 027-135133-0.005. */
8645 fc
->chunk_start
= saved_start
;
8646 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8649 if (frame_need_space (fc
, mreg
) < 0)
8651 if (fc
->fde_encoding
)
8652 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8654 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8655 print_dwarf_vma (length
, fc
->ptr_size
);
8656 print_dwarf_vma (cie_id
, offset_size
);
8658 if (do_debug_frames_interp
)
8660 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8661 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8666 printf (" Version: %d\n", version
);
8667 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8670 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8671 printf (" Segment Size: %u\n", fc
->segment_size
);
8673 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8674 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8675 printf (" Return address column: %d\n", fc
->ra
);
8677 if (augmentation_data_len
)
8678 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8685 unsigned char *look_for
;
8686 unsigned long segment_selector
;
8692 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8693 cie_off
= (cie_off
^ sign
) - sign
;
8694 cie_off
= start
- 4 - section_start
- cie_off
;
8697 look_for
= section_start
+ cie_off
;
8698 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
8700 for (cie
= chunks
; cie
; cie
= cie
->next
)
8701 if (cie
->chunk_start
== look_for
)
8704 else if (cie_off
>= section
->size
)
8708 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8709 if (cie
->chunk_start
== look_for
)
8713 unsigned int off_size
;
8714 unsigned char *cie_scan
;
8716 cie_scan
= look_for
;
8718 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8719 if (length
== 0xffffffff)
8721 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8724 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
8727 unsigned char *cie_end
= cie_scan
+ length
;
8729 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
8733 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8734 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8739 read_cie (cie_scan
, cie_end
, &cie
, &version
,
8740 &augmentation_data_len
, &augmentation_data
);
8741 /* PR 17512: file: 3450-2098-0.004. */
8744 warn (_("Failed to read CIE information\n"));
8747 cie
->next
= forward_refs
;
8749 cie
->chunk_start
= look_for
;
8750 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8753 if (frame_need_space (cie
, mreg
) < 0)
8755 warn (_("Invalid max register\n"));
8758 if (cie
->fde_encoding
)
8760 = size_of_encoded_value (cie
->fde_encoding
);
8767 memset (fc
, 0, sizeof (Frame_Chunk
));
8771 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8772 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8773 (unsigned long) (saved_start
- section_start
));
8775 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8776 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8777 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8779 warn (_("Invalid max register\n"));
8783 fc
->augmentation
= "";
8784 fc
->fde_encoding
= 0;
8785 fc
->ptr_size
= eh_addr_size
;
8786 fc
->segment_size
= 0;
8790 fc
->ncols
= cie
->ncols
;
8791 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8792 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8793 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8794 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8795 fc
->augmentation
= cie
->augmentation
;
8796 fc
->ptr_size
= cie
->ptr_size
;
8797 eh_addr_size
= cie
->ptr_size
;
8798 fc
->segment_size
= cie
->segment_size
;
8799 fc
->code_factor
= cie
->code_factor
;
8800 fc
->data_factor
= cie
->data_factor
;
8801 fc
->cfa_reg
= cie
->cfa_reg
;
8802 fc
->cfa_offset
= cie
->cfa_offset
;
8804 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8806 warn (_("Invalid max register\n"));
8809 fc
->fde_encoding
= cie
->fde_encoding
;
8812 if (fc
->fde_encoding
)
8813 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8815 segment_selector
= 0;
8816 if (fc
->segment_size
)
8818 if (fc
->segment_size
> sizeof (segment_selector
))
8820 /* PR 17512: file: 9e196b3e. */
8821 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8822 fc
->segment_size
= 4;
8824 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
8825 fc
->segment_size
, block_end
);
8828 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
8831 /* FIXME: It appears that sometimes the final pc_range value is
8832 encoded in less than encoded_ptr_size bytes. See the x86_64
8833 run of the "objcopy on compressed debug sections" test for an
8835 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
8838 if (cie
->augmentation
[0] == 'z')
8840 READ_ULEB (augmentation_data_len
, start
, block_end
);
8841 augmentation_data
= start
;
8842 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8843 if (augmentation_data_len
> (bfd_size_type
) (block_end
- start
))
8845 warn (_("Augmentation data too long: 0x%s, "
8846 "expected at most %#lx\n"),
8847 dwarf_vmatoa ("x", augmentation_data_len
),
8848 (unsigned long) (block_end
- start
));
8850 augmentation_data
= NULL
;
8851 augmentation_data_len
= 0;
8853 start
+= augmentation_data_len
;
8856 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8857 (unsigned long)(saved_start
- section_start
),
8858 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8859 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8860 (unsigned long)(cie
->chunk_start
- section_start
));
8862 if (fc
->segment_size
)
8863 printf ("%04lx:", segment_selector
);
8866 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8867 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8869 if (! do_debug_frames_interp
&& augmentation_data_len
)
8871 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8876 /* At this point, fc is the current chunk, cie (if any) is set, and
8877 we're about to interpret instructions for the chunk. */
8878 /* ??? At present we need to do this always, since this sizes the
8879 fc->col_type and fc->col_offset arrays, which we write into always.
8880 We should probably split the interpreted and non-interpreted bits
8881 into two different routines, since there's so much that doesn't
8882 really overlap between them. */
8883 if (1 || do_debug_frames_interp
)
8885 /* Start by making a pass over the chunk, allocating storage
8886 and taking note of what registers are used. */
8887 unsigned char *tmp
= start
;
8889 while (start
< block_end
)
8891 unsigned int reg
, op
, opa
;
8899 /* Warning: if you add any more cases to this switch, be
8900 sure to add them to the corresponding switch below. */
8903 case DW_CFA_advance_loc
:
8906 SKIP_ULEB (start
, block_end
);
8907 if (frame_need_space (fc
, opa
) >= 0)
8908 fc
->col_type
[opa
] = DW_CFA_undefined
;
8910 case DW_CFA_restore
:
8911 if (frame_need_space (fc
, opa
) >= 0)
8912 fc
->col_type
[opa
] = DW_CFA_undefined
;
8914 case DW_CFA_set_loc
:
8915 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
8918 start
+= encoded_ptr_size
;
8920 case DW_CFA_advance_loc1
:
8921 if ((size_t) (block_end
- start
) < 1)
8926 case DW_CFA_advance_loc2
:
8927 if ((size_t) (block_end
- start
) < 2)
8932 case DW_CFA_advance_loc4
:
8933 if ((size_t) (block_end
- start
) < 4)
8938 case DW_CFA_offset_extended
:
8939 case DW_CFA_val_offset
:
8940 READ_ULEB (reg
, start
, block_end
);
8941 SKIP_ULEB (start
, block_end
);
8942 if (frame_need_space (fc
, reg
) >= 0)
8943 fc
->col_type
[reg
] = DW_CFA_undefined
;
8945 case DW_CFA_restore_extended
:
8946 READ_ULEB (reg
, start
, block_end
);
8947 if (frame_need_space (fc
, reg
) >= 0)
8948 fc
->col_type
[reg
] = DW_CFA_undefined
;
8950 case DW_CFA_undefined
:
8951 READ_ULEB (reg
, start
, block_end
);
8952 if (frame_need_space (fc
, reg
) >= 0)
8953 fc
->col_type
[reg
] = DW_CFA_undefined
;
8955 case DW_CFA_same_value
:
8956 READ_ULEB (reg
, start
, block_end
);
8957 if (frame_need_space (fc
, reg
) >= 0)
8958 fc
->col_type
[reg
] = DW_CFA_undefined
;
8960 case DW_CFA_register
:
8961 READ_ULEB (reg
, start
, block_end
);
8962 SKIP_ULEB (start
, block_end
);
8963 if (frame_need_space (fc
, reg
) >= 0)
8964 fc
->col_type
[reg
] = DW_CFA_undefined
;
8966 case DW_CFA_def_cfa
:
8967 SKIP_ULEB (start
, block_end
);
8968 SKIP_ULEB (start
, block_end
);
8970 case DW_CFA_def_cfa_register
:
8971 SKIP_ULEB (start
, block_end
);
8973 case DW_CFA_def_cfa_offset
:
8974 SKIP_ULEB (start
, block_end
);
8976 case DW_CFA_def_cfa_expression
:
8977 READ_ULEB (temp
, start
, block_end
);
8978 if ((size_t) (block_end
- start
) < temp
)
8983 case DW_CFA_expression
:
8984 case DW_CFA_val_expression
:
8985 READ_ULEB (reg
, start
, block_end
);
8986 READ_ULEB (temp
, start
, block_end
);
8987 if ((size_t) (block_end
- start
) < temp
)
8991 if (frame_need_space (fc
, reg
) >= 0)
8992 fc
->col_type
[reg
] = DW_CFA_undefined
;
8994 case DW_CFA_offset_extended_sf
:
8995 case DW_CFA_val_offset_sf
:
8996 READ_ULEB (reg
, start
, block_end
);
8997 SKIP_SLEB (start
, block_end
);
8998 if (frame_need_space (fc
, reg
) >= 0)
8999 fc
->col_type
[reg
] = DW_CFA_undefined
;
9001 case DW_CFA_def_cfa_sf
:
9002 SKIP_ULEB (start
, block_end
);
9003 SKIP_SLEB (start
, block_end
);
9005 case DW_CFA_def_cfa_offset_sf
:
9006 SKIP_SLEB (start
, block_end
);
9008 case DW_CFA_MIPS_advance_loc8
:
9009 if ((size_t) (block_end
- start
) < 8)
9014 case DW_CFA_GNU_args_size
:
9015 SKIP_ULEB (start
, block_end
);
9017 case DW_CFA_GNU_negative_offset_extended
:
9018 READ_ULEB (reg
, start
, block_end
);
9019 SKIP_ULEB (start
, block_end
);
9020 if (frame_need_space (fc
, reg
) >= 0)
9021 fc
->col_type
[reg
] = DW_CFA_undefined
;
9032 /* Now we know what registers are used, make a second pass over
9033 the chunk, this time actually printing out the info. */
9035 while (start
< block_end
)
9038 unsigned long ul
, roffs
;
9039 /* Note: It is tempting to use an unsigned long for 'reg' but there
9040 are various functions, notably frame_space_needed() that assume that
9041 reg is an unsigned int. */
9046 const char *reg_prefix
= "";
9053 /* Make a note if something other than DW_CFA_nop happens. */
9054 if (op
!= DW_CFA_nop
)
9057 /* Warning: if you add any more cases to this switch, be
9058 sure to add them to the corresponding switch above. */
9061 case DW_CFA_advance_loc
:
9062 if (do_debug_frames_interp
)
9063 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9065 printf (" DW_CFA_advance_loc: %d to %s\n",
9066 opa
* fc
->code_factor
,
9067 dwarf_vmatoa_1 (NULL
,
9068 fc
->pc_begin
+ opa
* fc
->code_factor
,
9070 fc
->pc_begin
+= opa
* fc
->code_factor
;
9074 READ_ULEB (roffs
, start
, block_end
);
9075 if (opa
>= (unsigned int) fc
->ncols
)
9076 reg_prefix
= bad_reg
;
9077 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9078 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9079 reg_prefix
, regname (opa
, 0),
9080 roffs
* fc
->data_factor
);
9081 if (*reg_prefix
== '\0')
9083 fc
->col_type
[opa
] = DW_CFA_offset
;
9084 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9088 case DW_CFA_restore
:
9089 if (opa
>= (unsigned int) fc
->ncols
)
9090 reg_prefix
= bad_reg
;
9091 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9092 printf (" DW_CFA_restore: %s%s\n",
9093 reg_prefix
, regname (opa
, 0));
9094 if (*reg_prefix
!= '\0')
9097 if (opa
>= (unsigned int) cie
->ncols
9098 || (do_debug_frames_interp
9099 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9101 fc
->col_type
[opa
] = DW_CFA_undefined
;
9102 fc
->col_offset
[opa
] = 0;
9106 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9107 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9111 case DW_CFA_set_loc
:
9112 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9114 if (do_debug_frames_interp
)
9115 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9117 printf (" DW_CFA_set_loc: %s\n",
9118 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9122 case DW_CFA_advance_loc1
:
9123 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9124 if (do_debug_frames_interp
)
9125 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9127 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9128 (unsigned long) (ofs
* fc
->code_factor
),
9129 dwarf_vmatoa_1 (NULL
,
9130 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9132 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9135 case DW_CFA_advance_loc2
:
9136 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9137 if (do_debug_frames_interp
)
9138 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9140 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9141 (unsigned long) (ofs
* fc
->code_factor
),
9142 dwarf_vmatoa_1 (NULL
,
9143 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9145 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9148 case DW_CFA_advance_loc4
:
9149 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9150 if (do_debug_frames_interp
)
9151 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9153 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9154 (unsigned long) (ofs
* fc
->code_factor
),
9155 dwarf_vmatoa_1 (NULL
,
9156 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9158 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9161 case DW_CFA_offset_extended
:
9162 READ_ULEB (reg
, start
, block_end
);
9163 READ_ULEB (roffs
, start
, block_end
);
9164 if (reg
>= (unsigned int) fc
->ncols
)
9165 reg_prefix
= bad_reg
;
9166 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9167 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9168 reg_prefix
, regname (reg
, 0),
9169 roffs
* fc
->data_factor
);
9170 if (*reg_prefix
== '\0')
9172 fc
->col_type
[reg
] = DW_CFA_offset
;
9173 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9177 case DW_CFA_val_offset
:
9178 READ_ULEB (reg
, start
, block_end
);
9179 READ_ULEB (roffs
, start
, block_end
);
9180 if (reg
>= (unsigned int) fc
->ncols
)
9181 reg_prefix
= bad_reg
;
9182 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9183 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9184 reg_prefix
, regname (reg
, 0),
9185 roffs
* fc
->data_factor
);
9186 if (*reg_prefix
== '\0')
9188 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9189 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9193 case DW_CFA_restore_extended
:
9194 READ_ULEB (reg
, start
, block_end
);
9195 if (reg
>= (unsigned int) fc
->ncols
)
9196 reg_prefix
= bad_reg
;
9197 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9198 printf (" DW_CFA_restore_extended: %s%s\n",
9199 reg_prefix
, regname (reg
, 0));
9200 if (*reg_prefix
!= '\0')
9203 if (reg
>= (unsigned int) cie
->ncols
)
9205 fc
->col_type
[reg
] = DW_CFA_undefined
;
9206 fc
->col_offset
[reg
] = 0;
9210 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9211 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9215 case DW_CFA_undefined
:
9216 READ_ULEB (reg
, start
, block_end
);
9217 if (reg
>= (unsigned int) fc
->ncols
)
9218 reg_prefix
= bad_reg
;
9219 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9220 printf (" DW_CFA_undefined: %s%s\n",
9221 reg_prefix
, regname (reg
, 0));
9222 if (*reg_prefix
== '\0')
9224 fc
->col_type
[reg
] = DW_CFA_undefined
;
9225 fc
->col_offset
[reg
] = 0;
9229 case DW_CFA_same_value
:
9230 READ_ULEB (reg
, start
, block_end
);
9231 if (reg
>= (unsigned int) fc
->ncols
)
9232 reg_prefix
= bad_reg
;
9233 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9234 printf (" DW_CFA_same_value: %s%s\n",
9235 reg_prefix
, regname (reg
, 0));
9236 if (*reg_prefix
== '\0')
9238 fc
->col_type
[reg
] = DW_CFA_same_value
;
9239 fc
->col_offset
[reg
] = 0;
9243 case DW_CFA_register
:
9244 READ_ULEB (reg
, start
, block_end
);
9245 READ_ULEB (roffs
, start
, block_end
);
9246 if (reg
>= (unsigned int) fc
->ncols
)
9247 reg_prefix
= bad_reg
;
9248 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9250 printf (" DW_CFA_register: %s%s in ",
9251 reg_prefix
, regname (reg
, 0));
9252 puts (regname (roffs
, 0));
9254 if (*reg_prefix
== '\0')
9256 fc
->col_type
[reg
] = DW_CFA_register
;
9257 fc
->col_offset
[reg
] = roffs
;
9261 case DW_CFA_remember_state
:
9262 if (! do_debug_frames_interp
)
9263 printf (" DW_CFA_remember_state\n");
9264 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9265 rs
->cfa_offset
= fc
->cfa_offset
;
9266 rs
->cfa_reg
= fc
->cfa_reg
;
9268 rs
->cfa_exp
= fc
->cfa_exp
;
9269 rs
->ncols
= fc
->ncols
;
9270 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9271 sizeof (* rs
->col_type
));
9272 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9273 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9274 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9275 rs
->next
= remembered_state
;
9276 remembered_state
= rs
;
9279 case DW_CFA_restore_state
:
9280 if (! do_debug_frames_interp
)
9281 printf (" DW_CFA_restore_state\n");
9282 rs
= remembered_state
;
9285 remembered_state
= rs
->next
;
9286 fc
->cfa_offset
= rs
->cfa_offset
;
9287 fc
->cfa_reg
= rs
->cfa_reg
;
9289 fc
->cfa_exp
= rs
->cfa_exp
;
9290 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9292 warn (_("Invalid column number in saved frame state\n"));
9296 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9297 memcpy (fc
->col_offset
, rs
->col_offset
,
9298 rs
->ncols
* sizeof (* rs
->col_offset
));
9299 free (rs
->col_type
);
9300 free (rs
->col_offset
);
9303 else if (do_debug_frames_interp
)
9304 printf ("Mismatched DW_CFA_restore_state\n");
9307 case DW_CFA_def_cfa
:
9308 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9309 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9311 if (! do_debug_frames_interp
)
9312 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9313 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9316 case DW_CFA_def_cfa_register
:
9317 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9319 if (! do_debug_frames_interp
)
9320 printf (" DW_CFA_def_cfa_register: %s\n",
9321 regname (fc
->cfa_reg
, 0));
9324 case DW_CFA_def_cfa_offset
:
9325 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9326 if (! do_debug_frames_interp
)
9327 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9331 if (! do_debug_frames_interp
)
9332 printf (" DW_CFA_nop\n");
9335 case DW_CFA_def_cfa_expression
:
9336 READ_ULEB (ul
, start
, block_end
);
9337 if (ul
> (size_t) (block_end
- start
))
9339 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9342 if (! do_debug_frames_interp
)
9344 printf (" DW_CFA_def_cfa_expression (");
9345 decode_location_expression (start
, eh_addr_size
, 0, -1,
9353 case DW_CFA_expression
:
9354 READ_ULEB (reg
, start
, block_end
);
9355 READ_ULEB (ul
, start
, block_end
);
9356 if (reg
>= (unsigned int) fc
->ncols
)
9357 reg_prefix
= bad_reg
;
9358 /* PR 17512: file: 069-133014-0.006. */
9359 /* PR 17512: file: 98c02eb4. */
9360 if (ul
> (size_t) (block_end
- start
))
9362 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9365 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9367 printf (" DW_CFA_expression: %s%s (",
9368 reg_prefix
, regname (reg
, 0));
9369 decode_location_expression (start
, eh_addr_size
, 0, -1,
9373 if (*reg_prefix
== '\0')
9374 fc
->col_type
[reg
] = DW_CFA_expression
;
9378 case DW_CFA_val_expression
:
9379 READ_ULEB (reg
, start
, block_end
);
9380 READ_ULEB (ul
, start
, block_end
);
9381 if (reg
>= (unsigned int) fc
->ncols
)
9382 reg_prefix
= bad_reg
;
9383 if (ul
> (size_t) (block_end
- start
))
9385 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9388 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9390 printf (" DW_CFA_val_expression: %s%s (",
9391 reg_prefix
, regname (reg
, 0));
9392 decode_location_expression (start
, eh_addr_size
, 0, -1,
9396 if (*reg_prefix
== '\0')
9397 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9401 case DW_CFA_offset_extended_sf
:
9402 READ_ULEB (reg
, start
, block_end
);
9403 READ_SLEB (l
, start
, block_end
);
9404 if (frame_need_space (fc
, reg
) < 0)
9405 reg_prefix
= bad_reg
;
9406 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9407 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9408 reg_prefix
, regname (reg
, 0),
9409 (long)(l
* fc
->data_factor
));
9410 if (*reg_prefix
== '\0')
9412 fc
->col_type
[reg
] = DW_CFA_offset
;
9413 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9417 case DW_CFA_val_offset_sf
:
9418 READ_ULEB (reg
, start
, block_end
);
9419 READ_SLEB (l
, start
, block_end
);
9420 if (frame_need_space (fc
, reg
) < 0)
9421 reg_prefix
= bad_reg
;
9422 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9423 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9424 reg_prefix
, regname (reg
, 0),
9425 (long)(l
* fc
->data_factor
));
9426 if (*reg_prefix
== '\0')
9428 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9429 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9433 case DW_CFA_def_cfa_sf
:
9434 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9435 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9436 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9438 if (! do_debug_frames_interp
)
9439 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9440 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9443 case DW_CFA_def_cfa_offset_sf
:
9444 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9445 fc
->cfa_offset
*= fc
->data_factor
;
9446 if (! do_debug_frames_interp
)
9447 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9450 case DW_CFA_MIPS_advance_loc8
:
9451 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9452 if (do_debug_frames_interp
)
9453 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9455 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9456 (unsigned long) (ofs
* fc
->code_factor
),
9457 dwarf_vmatoa_1 (NULL
,
9458 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9460 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9463 case DW_CFA_GNU_window_save
:
9464 if (! do_debug_frames_interp
)
9465 printf (" DW_CFA_GNU_window_save\n");
9468 case DW_CFA_GNU_args_size
:
9469 READ_ULEB (ul
, start
, block_end
);
9470 if (! do_debug_frames_interp
)
9471 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9474 case DW_CFA_GNU_negative_offset_extended
:
9475 READ_ULEB (reg
, start
, block_end
);
9476 READ_SLEB (l
, start
, block_end
);
9478 if (frame_need_space (fc
, reg
) < 0)
9479 reg_prefix
= bad_reg
;
9480 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9481 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9482 reg_prefix
, regname (reg
, 0),
9483 (long)(l
* fc
->data_factor
));
9484 if (*reg_prefix
== '\0')
9486 fc
->col_type
[reg
] = DW_CFA_offset
;
9487 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9492 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9493 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9495 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9500 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9501 if (do_debug_frames_interp
&& ! all_nops
)
9502 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9504 if (fde_fc
.col_type
!= NULL
)
9506 free (fde_fc
.col_type
);
9507 fde_fc
.col_type
= NULL
;
9509 if (fde_fc
.col_offset
!= NULL
)
9511 free (fde_fc
.col_offset
);
9512 fde_fc
.col_offset
= NULL
;
9516 eh_addr_size
= saved_eh_addr_size
;
9521 while (remembered_state
!= NULL
)
9523 rs
= remembered_state
;
9524 remembered_state
= rs
->next
;
9525 free (rs
->col_type
);
9526 free (rs
->col_offset
);
9527 rs
->next
= NULL
; /* Paranoia. */
9531 while (chunks
!= NULL
)
9535 free (rs
->col_type
);
9536 free (rs
->col_offset
);
9537 rs
->next
= NULL
; /* Paranoia. */
9541 while (forward_refs
!= NULL
)
9544 forward_refs
= rs
->next
;
9545 free (rs
->col_type
);
9546 free (rs
->col_offset
);
9547 rs
->next
= NULL
; /* Paranoia. */
9557 display_debug_names (struct dwarf_section
*section
, void *file
)
9559 unsigned char *hdrptr
= section
->start
;
9560 dwarf_vma unit_length
;
9561 unsigned char *unit_start
;
9562 const unsigned char *const section_end
= section
->start
+ section
->size
;
9563 unsigned char *unit_end
;
9565 introduce (section
, false);
9567 load_debug_section_with_follow (str
, file
);
9569 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9571 unsigned int offset_size
;
9572 uint16_t dwarf_version
, padding
;
9573 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9574 uint64_t bucket_count
, name_count
, abbrev_table_size
;
9575 uint32_t augmentation_string_size
;
9577 bool augmentation_printable
;
9578 const char *augmentation_string
;
9581 unit_start
= hdrptr
;
9583 /* Get and check the length of the block. */
9584 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9586 if (unit_length
== 0xffffffff)
9588 /* This section is 64-bit DWARF. */
9589 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9595 if (unit_length
> (size_t) (section_end
- hdrptr
)
9596 || unit_length
< 2 + 2 + 4 * 7)
9599 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9601 (unsigned long) (unit_start
- section
->start
),
9602 dwarf_vmatoa ("x", unit_length
));
9605 unit_end
= hdrptr
+ unit_length
;
9607 /* Get and check the version number. */
9608 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9609 printf (_("Version %ld\n"), (long) dwarf_version
);
9611 /* Prior versions did not exist, and future versions may not be
9612 backwards compatible. */
9613 if (dwarf_version
!= 5)
9615 warn (_("Only DWARF version 5 .debug_names "
9616 "is currently supported.\n"));
9620 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9622 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9625 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9626 if (comp_unit_count
== 0)
9627 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9629 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9630 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9631 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9632 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9633 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9635 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9636 if (augmentation_string_size
% 4 != 0)
9638 warn (_("Augmentation string length %u must be rounded up "
9639 "to a multiple of 4 in .debug_names.\n"),
9640 augmentation_string_size
);
9641 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9643 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
9646 printf (_("Augmentation string:"));
9648 augmentation_printable
= true;
9649 augmentation_string
= (const char *) hdrptr
;
9651 for (i
= 0; i
< augmentation_string_size
; i
++)
9655 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9656 printf (" %02x", uc
);
9658 if (uc
!= 0 && !ISPRINT (uc
))
9659 augmentation_printable
= false;
9662 if (augmentation_printable
)
9666 i
< augmentation_string_size
&& augmentation_string
[i
];
9668 putchar (augmentation_string
[i
]);
9673 printf (_("CU table:\n"));
9674 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
9675 || total
> (size_t) (unit_end
- hdrptr
))
9677 for (i
= 0; i
< comp_unit_count
; i
++)
9681 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9682 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9686 printf (_("TU table:\n"));
9687 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
9688 || total
> (size_t) (unit_end
- hdrptr
))
9690 for (i
= 0; i
< local_type_unit_count
; i
++)
9694 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9695 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9699 printf (_("Foreign TU table:\n"));
9700 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
9701 || total
> (size_t) (unit_end
- hdrptr
))
9703 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9707 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9708 printf (_("[%3u] "), i
);
9709 print_dwarf_vma (signature
, 8);
9714 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
9715 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
9716 + abbrev_table_size
);
9717 if (xtra
> (size_t) (unit_end
- hdrptr
))
9719 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9720 "for unit 0x%lx in the debug_names\n"),
9722 (long) (unit_end
- unit_start
),
9723 (long) (unit_start
- section
->start
));
9726 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9727 hdrptr
+= bucket_count
* sizeof (uint32_t);
9728 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9729 hdrptr
+= name_count
* sizeof (uint32_t);
9730 unsigned char *const name_table_string_offsets
= hdrptr
;
9731 hdrptr
+= name_count
* offset_size
;
9732 unsigned char *const name_table_entry_offsets
= hdrptr
;
9733 hdrptr
+= name_count
* offset_size
;
9734 unsigned char *const abbrev_table
= hdrptr
;
9735 hdrptr
+= abbrev_table_size
;
9736 const unsigned char *const abbrev_table_end
= hdrptr
;
9737 unsigned char *const entry_pool
= hdrptr
;
9739 size_t buckets_filled
= 0;
9741 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9743 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9748 printf (ngettext ("Used %zu of %lu bucket.\n",
9749 "Used %zu of %lu buckets.\n",
9751 buckets_filled
, (unsigned long) bucket_count
);
9753 uint32_t hash_prev
= 0;
9754 size_t hash_clash_count
= 0;
9755 size_t longest_clash
= 0;
9756 size_t this_length
= 0;
9758 for (hashi
= 0; hashi
< name_count
; hashi
++)
9760 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9764 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9768 longest_clash
= MAX (longest_clash
, this_length
);
9773 hash_prev
= hash_this
;
9775 printf (_("Out of %lu items there are %zu bucket clashes"
9776 " (longest of %zu entries).\n"),
9777 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9778 assert (name_count
== buckets_filled
+ hash_clash_count
);
9780 struct abbrev_lookup_entry
9782 dwarf_vma abbrev_tag
;
9783 unsigned char *abbrev_lookup_ptr
;
9785 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9786 size_t abbrev_lookup_used
= 0;
9787 size_t abbrev_lookup_allocated
= 0;
9789 unsigned char *abbrevptr
= abbrev_table
;
9792 dwarf_vma abbrev_tag
;
9794 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9795 if (abbrev_tag
== 0)
9797 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9799 abbrev_lookup_allocated
= MAX (0x100,
9800 abbrev_lookup_allocated
* 2);
9801 abbrev_lookup
= xrealloc (abbrev_lookup
,
9802 (abbrev_lookup_allocated
9803 * sizeof (*abbrev_lookup
)));
9805 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9806 struct abbrev_lookup_entry
*entry
;
9807 for (entry
= abbrev_lookup
;
9808 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9810 if (entry
->abbrev_tag
== abbrev_tag
)
9812 warn (_("Duplicate abbreviation tag %lu "
9813 "in unit 0x%lx in the debug_names\n"),
9814 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9817 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9818 entry
->abbrev_tag
= abbrev_tag
;
9819 entry
->abbrev_lookup_ptr
= abbrevptr
;
9821 /* Skip DWARF tag. */
9822 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9825 dwarf_vma xindex
, form
;
9827 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9828 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9829 if (xindex
== 0 && form
== 0)
9834 printf (_("\nSymbol table:\n"));
9836 for (namei
= 0; namei
< name_count
; ++namei
)
9838 uint64_t string_offset
, entry_offset
;
9841 p
= name_table_string_offsets
+ namei
* offset_size
;
9842 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
9843 p
= name_table_entry_offsets
+ namei
* offset_size
;
9844 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
9846 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9847 fetch_indirect_string (string_offset
));
9849 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9851 /* We need to scan first whether there is a single or multiple
9852 entries. TAGNO is -2 for the first entry, it is -1 for the
9853 initial tag read of the second entry, then it becomes 0 for the
9854 first entry for real printing etc. */
9856 /* Initialize it due to a false compiler warning. */
9857 dwarf_vma second_abbrev_tag
= -1;
9860 dwarf_vma abbrev_tag
;
9861 dwarf_vma dwarf_tag
;
9862 const struct abbrev_lookup_entry
*entry
;
9864 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9867 second_abbrev_tag
= abbrev_tag
;
9869 entryptr
= entry_pool
+ entry_offset
;
9872 if (abbrev_tag
== 0)
9876 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9877 (unsigned long) abbrev_tag
);
9879 for (entry
= abbrev_lookup
;
9880 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9882 if (entry
->abbrev_tag
== abbrev_tag
)
9884 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9886 warn (_("Undefined abbreviation tag %lu "
9887 "in unit 0x%lx in the debug_names\n"),
9889 (long) (unit_start
- section
->start
));
9892 abbrevptr
= entry
->abbrev_lookup_ptr
;
9893 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9895 printf (" %s", get_TAG_name (dwarf_tag
));
9898 dwarf_vma xindex
, form
;
9900 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9901 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9902 if (xindex
== 0 && form
== 0)
9906 printf (" %s", get_IDX_name (xindex
));
9907 entryptr
= read_and_display_attr_value (0, form
, 0,
9908 unit_start
, entryptr
, unit_end
,
9910 dwarf_version
, NULL
,
9917 printf (_(" <no entries>"));
9921 free (abbrev_lookup
);
9928 display_debug_links (struct dwarf_section
* section
,
9929 void * file ATTRIBUTE_UNUSED
)
9931 const unsigned char * filename
;
9932 unsigned int filelen
;
9934 introduce (section
, false);
9936 /* The .gnu_debuglink section is formatted as:
9937 (c-string) Filename.
9938 (padding) If needed to reach a 4 byte boundary.
9939 (uint32_t) CRC32 value.
9941 The .gun_debugaltlink section is formatted as:
9942 (c-string) Filename.
9943 (binary) Build-ID. */
9945 filename
= section
->start
;
9946 filelen
= strnlen ((const char *) filename
, section
->size
);
9947 if (filelen
== section
->size
)
9949 warn (_("The debuglink filename is corrupt/missing\n"));
9953 printf (_(" Separate debug info file: %s\n"), filename
);
9955 if (startswith (section
->name
, ".gnu_debuglink"))
9958 unsigned int crc_offset
;
9960 crc_offset
= filelen
+ 1;
9961 crc_offset
= (crc_offset
+ 3) & ~3;
9962 if (crc_offset
+ 4 > section
->size
)
9964 warn (_("CRC offset missing/truncated\n"));
9968 crc32
= byte_get (filename
+ crc_offset
, 4);
9970 printf (_(" CRC value: %#x\n"), crc32
);
9972 if (crc_offset
+ 4 < section
->size
)
9974 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9975 (long)(section
->size
- (crc_offset
+ 4)));
9979 else /* startswith (section->name, ".gnu_debugaltlink") */
9981 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9982 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9983 bfd_size_type printed
;
9985 /* FIXME: Should we support smaller build-id notes ? */
9986 if (build_id_len
< 0x14)
9988 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9992 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9993 display_data (printed
, build_id
, build_id_len
);
10002 display_gdb_index (struct dwarf_section
*section
,
10003 void *file ATTRIBUTE_UNUSED
)
10005 unsigned char *start
= section
->start
;
10007 uint32_t cu_list_offset
, tu_list_offset
;
10008 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10009 unsigned int cu_list_elements
, tu_list_elements
;
10010 unsigned int address_table_size
, symbol_table_slots
;
10011 unsigned char *cu_list
, *tu_list
;
10012 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10015 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10017 introduce (section
, false);
10019 if (section
->size
< 6 * sizeof (uint32_t))
10021 warn (_("Truncated header in the %s section.\n"), section
->name
);
10025 version
= byte_get_little_endian (start
, 4);
10026 printf (_("Version %ld\n"), (long) version
);
10028 /* Prior versions are obsolete, and future versions may not be
10029 backwards compatible. */
10030 if (version
< 3 || version
> 8)
10032 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10036 warn (_("The address table data in version 3 may be wrong.\n"));
10038 warn (_("Version 4 does not support case insensitive lookups.\n"));
10040 warn (_("Version 5 does not include inlined functions.\n"));
10042 warn (_("Version 6 does not include symbol attributes.\n"));
10043 /* Version 7 indices generated by Gold have bad type unit references,
10044 PR binutils/15021. But we don't know if the index was generated by
10045 Gold or not, so to avoid worrying users with gdb-generated indices
10046 we say nothing for version 7 here. */
10048 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10049 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10050 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10051 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10052 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10054 if (cu_list_offset
> section
->size
10055 || tu_list_offset
> section
->size
10056 || address_table_offset
> section
->size
10057 || symbol_table_offset
> section
->size
10058 || constant_pool_offset
> section
->size
)
10060 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10064 /* PR 17531: file: 418d0a8a. */
10065 if (tu_list_offset
< cu_list_offset
)
10067 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
10068 tu_list_offset
, cu_list_offset
);
10072 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
10074 if (address_table_offset
< tu_list_offset
)
10076 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
10077 address_table_offset
, tu_list_offset
);
10081 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
10083 /* PR 17531: file: 18a47d3d. */
10084 if (symbol_table_offset
< address_table_offset
)
10086 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
10087 symbol_table_offset
, address_table_offset
);
10091 address_table_size
= symbol_table_offset
- address_table_offset
;
10093 if (constant_pool_offset
< symbol_table_offset
)
10095 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
10096 constant_pool_offset
, symbol_table_offset
);
10100 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10102 cu_list
= start
+ cu_list_offset
;
10103 tu_list
= start
+ tu_list_offset
;
10104 address_table
= start
+ address_table_offset
;
10105 symbol_table
= start
+ symbol_table_offset
;
10106 constant_pool
= start
+ constant_pool_offset
;
10108 if (address_table_offset
+ address_table_size
> section
->size
)
10110 warn (_("Address table extends beyond end of section.\n"));
10114 printf (_("\nCU table:\n"));
10115 for (i
= 0; i
< cu_list_elements
; i
+= 2)
10117 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
10118 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
10120 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
10121 (unsigned long) cu_offset
,
10122 (unsigned long) (cu_offset
+ cu_length
- 1));
10125 printf (_("\nTU table:\n"));
10126 for (i
= 0; i
< tu_list_elements
; i
+= 3)
10128 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
10129 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
10130 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
10132 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
10133 (unsigned long) tu_offset
,
10134 (unsigned long) type_offset
);
10135 print_dwarf_vma (signature
, 8);
10139 printf (_("\nAddress table:\n"));
10140 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
10143 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
10144 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
10145 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
10147 print_dwarf_vma (low
, 8);
10148 print_dwarf_vma (high
, 8);
10149 printf (_("%lu\n"), (unsigned long) cu_index
);
10152 printf (_("\nSymbol table:\n"));
10153 for (i
= 0; i
< symbol_table_slots
; ++i
)
10155 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10156 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10157 uint32_t num_cus
, cu
;
10159 if (name_offset
!= 0
10160 || cu_vector_offset
!= 0)
10164 /* PR 17531: file: 5b7b07ad. */
10165 if (name_offset
>= section
->size
- constant_pool_offset
)
10167 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10168 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10172 printf ("[%3u] %.*s:", i
,
10173 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10174 constant_pool
+ name_offset
);
10176 if (section
->size
- constant_pool_offset
< 4
10177 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10179 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10180 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10181 cu_vector_offset
, i
);
10185 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10187 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10188 + cu_vector_offset
+ 4))
10190 printf ("<invalid number of CUs: %d>\n", num_cus
);
10191 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10199 for (j
= 0; j
< num_cus
; ++j
)
10202 gdb_index_symbol_kind kind
;
10204 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10205 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10206 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10207 cu
= GDB_INDEX_CU_VALUE (cu
);
10208 /* Convert to TU number if it's for a type unit. */
10209 if (cu
>= cu_list_elements
/ 2)
10210 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10211 (unsigned long) (cu
- cu_list_elements
/ 2));
10213 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10215 printf (" [%s, %s]",
10216 is_static
? _("static") : _("global"),
10217 get_gdb_index_symbol_kind_name (kind
));
10229 /* Pre-allocate enough space for the CU/TU sets needed. */
10232 prealloc_cu_tu_list (unsigned int nshndx
)
10234 if (shndx_pool
== NULL
)
10236 shndx_pool_size
= nshndx
;
10237 shndx_pool_used
= 0;
10238 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10239 sizeof (unsigned int));
10243 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10244 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10245 sizeof (unsigned int));
10250 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10252 if (shndx_pool_used
>= shndx_pool_size
)
10254 error (_("Internal error: out of space in the shndx pool.\n"));
10257 shndx_pool
[shndx_pool_used
++] = shndx
;
10261 end_cu_tu_entry (void)
10263 if (shndx_pool_used
>= shndx_pool_size
)
10265 error (_("Internal error: out of space in the shndx pool.\n"));
10268 shndx_pool
[shndx_pool_used
++] = 0;
10271 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10273 static const char *
10274 get_DW_SECT_short_name (unsigned int dw_sect
)
10276 static char buf
[16];
10282 case DW_SECT_TYPES
:
10284 case DW_SECT_ABBREV
:
10290 case DW_SECT_STR_OFFSETS
:
10292 case DW_SECT_MACINFO
:
10294 case DW_SECT_MACRO
:
10300 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10304 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10305 These sections are extensions for Fission.
10306 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10309 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10311 unsigned char *phdr
= section
->start
;
10312 unsigned char *limit
= phdr
+ section
->size
;
10313 unsigned char *phash
;
10314 unsigned char *pindex
;
10315 unsigned char *ppool
;
10316 unsigned int version
;
10317 unsigned int ncols
= 0;
10318 unsigned int nused
;
10319 unsigned int nslots
;
10322 dwarf_vma signature
;
10324 /* PR 17512: file: 002-168123-0.004. */
10327 warn (_("Section %s is empty\n"), section
->name
);
10330 /* PR 17512: file: 002-376-0.004. */
10331 if (section
->size
< 24)
10333 warn (_("Section %s is too small to contain a CU/TU header\n"),
10339 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10341 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10342 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10343 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10345 pindex
= phash
+ (size_t) nslots
* 8;
10346 ppool
= pindex
+ (size_t) nslots
* 4;
10350 introduce (section
, false);
10352 printf (_(" Version: %u\n"), version
);
10354 printf (_(" Number of columns: %u\n"), ncols
);
10355 printf (_(" Number of used entries: %u\n"), nused
);
10356 printf (_(" Number of slots: %u\n\n"), nslots
);
10359 /* PR 17531: file: 45d69832. */
10360 if ((size_t) nslots
* 8 / 8 != nslots
10361 || phash
< phdr
|| phash
> limit
10362 || pindex
< phash
|| pindex
> limit
10363 || ppool
< pindex
|| ppool
> limit
)
10365 warn (ngettext ("Section %s is too small for %u slot\n",
10366 "Section %s is too small for %u slots\n",
10368 section
->name
, nslots
);
10375 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10376 for (i
= 0; i
< nslots
; i
++)
10378 unsigned char *shndx_list
;
10379 unsigned int shndx
;
10381 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10382 if (signature
!= 0)
10384 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10385 shndx_list
= ppool
+ j
* 4;
10386 /* PR 17531: file: 705e010d. */
10387 if (shndx_list
< ppool
)
10389 warn (_("Section index pool located before start of section\n"));
10394 printf (_(" [%3d] Signature: 0x%s Sections: "),
10395 i
, dwarf_vmatoa ("x", signature
));
10398 if (shndx_list
>= limit
)
10400 warn (_("Section %s too small for shndx pool\n"),
10404 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10408 printf (" %d", shndx
);
10410 add_shndx_to_cu_tu_entry (shndx
);
10416 end_cu_tu_entry ();
10422 else if (version
== 2)
10425 unsigned int dw_sect
;
10426 unsigned char *ph
= phash
;
10427 unsigned char *pi
= pindex
;
10428 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10429 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10430 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10432 struct cu_tu_set
*this_set
= NULL
;
10434 unsigned char *prow
;
10436 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10438 /* PR 17531: file: 0dd159bf.
10439 Check for integer overflow (can occur when size_t is 32-bit)
10440 with overlarge ncols or nused values. */
10442 && ((size_t) ncols
* 4 / 4 != ncols
10443 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10444 || poffsets
< ppool
|| poffsets
> limit
10445 || psizes
< poffsets
|| psizes
> limit
10446 || pend
< psizes
|| pend
> limit
))
10448 warn (_("Section %s too small for offset and size tables\n"),
10455 printf (_(" Offset table\n"));
10456 printf (" slot %-16s ",
10457 is_tu_index
? _("signature") : _("dwo_id"));
10464 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10465 this_set
= tu_sets
;
10470 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10471 this_set
= cu_sets
;
10477 for (j
= 0; j
< ncols
; j
++)
10479 unsigned char *p
= ppool
+ j
* 4;
10480 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10481 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10486 for (i
= 0; i
< nslots
; i
++)
10488 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10490 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10493 /* PR 17531: file: a05f6ab3. */
10496 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10503 size_t num_copy
= sizeof (uint64_t);
10505 /* PR 23064: Beware of buffer overflow. */
10506 if (ph
+ num_copy
< limit
)
10507 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10510 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10515 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10516 /* PR 17531: file: b8ce60a8. */
10517 if (prow
< poffsets
|| prow
> limit
)
10519 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10525 printf (_(" [%3d] 0x%s"),
10526 i
, dwarf_vmatoa ("x", signature
));
10527 for (j
= 0; j
< ncols
; j
++)
10529 unsigned char *p
= prow
+ j
* 4;
10530 SAFE_BYTE_GET (val
, p
, 4, limit
);
10532 printf (" %8d", val
);
10536 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10538 /* PR 17531: file: 10796eb3. */
10539 if (dw_sect
>= DW_SECT_MAX
)
10540 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10542 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10558 printf (_(" Size table\n"));
10559 printf (" slot %-16s ",
10560 is_tu_index
? _("signature") : _("dwo_id"));
10563 for (j
= 0; j
< ncols
; j
++)
10565 unsigned char *p
= ppool
+ j
* 4;
10566 SAFE_BYTE_GET (val
, p
, 4, limit
);
10568 printf (" %8s", get_DW_SECT_short_name (val
));
10574 for (i
= 0; i
< nslots
; i
++)
10576 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10578 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10581 prow
= psizes
+ (row
- 1) * ncols
* 4;
10584 printf (_(" [%3d] 0x%s"),
10585 i
, dwarf_vmatoa ("x", signature
));
10587 for (j
= 0; j
< ncols
; j
++)
10589 unsigned char *p
= prow
+ j
* 4;
10590 SAFE_BYTE_GET (val
, p
, 4, limit
);
10592 printf (" %8d", val
);
10596 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10597 if (dw_sect
>= DW_SECT_MAX
)
10598 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10600 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10612 else if (do_display
)
10613 printf (_(" Unsupported version (%d)\n"), version
);
10621 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10623 /* Load the CU and TU indexes if present. This will build a list of
10624 section sets that we can use to associate a .debug_info.dwo section
10625 with its associated .debug_abbrev.dwo section in a .dwp file. */
10628 load_cu_tu_indexes (void *file
)
10630 /* If we have already loaded (or tried to load) the CU and TU indexes
10631 then do not bother to repeat the task. */
10632 if (cu_tu_indexes_read
== -1)
10634 cu_tu_indexes_read
= true;
10636 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10637 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10638 cu_tu_indexes_read
= false;
10640 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10641 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10642 cu_tu_indexes_read
= false;
10645 return (bool) cu_tu_indexes_read
;
10648 /* Find the set of sections that includes section SHNDX. */
10651 find_cu_tu_set (void *file
, unsigned int shndx
)
10655 if (! load_cu_tu_indexes (file
))
10658 /* Find SHNDX in the shndx pool. */
10659 for (i
= 0; i
< shndx_pool_used
; i
++)
10660 if (shndx_pool
[i
] == shndx
)
10663 if (i
>= shndx_pool_used
)
10666 /* Now backup to find the first entry in the set. */
10667 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10670 return shndx_pool
+ i
;
10673 /* Display a .debug_cu_index or .debug_tu_index section. */
10676 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10678 return process_cu_tu_index (section
, 1);
10682 display_debug_not_supported (struct dwarf_section
*section
,
10683 void *file ATTRIBUTE_UNUSED
)
10685 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10691 /* Like malloc, but takes two parameters like calloc.
10692 Verifies that the first parameter is not too large.
10693 Note: does *not* initialise the allocated memory to zero. */
10696 cmalloc (size_t nmemb
, size_t size
)
10698 /* Check for overflow. */
10699 if (nmemb
>= ~(size_t) 0 / size
)
10702 return xmalloc (nmemb
* size
);
10705 /* Like xmalloc, but takes two parameters like calloc.
10706 Verifies that the first parameter is not too large.
10707 Note: does *not* initialise the allocated memory to zero. */
10710 xcmalloc (size_t nmemb
, size_t size
)
10712 /* Check for overflow. */
10713 if (nmemb
>= ~(size_t) 0 / size
)
10716 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10721 return xmalloc (nmemb
* size
);
10724 /* Like xrealloc, but takes three parameters.
10725 Verifies that the second parameter is not too large.
10726 Note: does *not* initialise any new memory to zero. */
10729 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10731 /* Check for overflow. */
10732 if (nmemb
>= ~(size_t) 0 / size
)
10734 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10739 return xrealloc (ptr
, nmemb
* size
);
10742 /* Like xcalloc, but verifies that the first parameter is not too large. */
10745 xcalloc2 (size_t nmemb
, size_t size
)
10747 /* Check for overflow. */
10748 if (nmemb
>= ~(size_t) 0 / size
)
10750 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10755 return xcalloc (nmemb
, size
);
10758 static unsigned long
10759 calc_gnu_debuglink_crc32 (unsigned long crc
,
10760 const unsigned char * buf
,
10763 static const unsigned long crc32_table
[256] =
10765 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10766 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10767 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10768 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10769 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10770 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10771 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10772 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10773 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10774 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10775 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10776 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10777 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10778 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10779 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10780 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10781 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10782 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10783 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10784 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10785 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10786 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10787 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10788 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10789 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10790 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10791 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10792 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10793 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10794 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10795 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10796 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10797 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10798 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10799 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10800 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10801 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10802 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10803 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10804 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10805 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10806 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10807 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10808 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10809 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10810 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10811 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10812 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10813 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10814 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10815 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10818 const unsigned char *end
;
10820 crc
= ~crc
& 0xffffffff;
10821 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10822 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10823 return ~crc
& 0xffffffff;
10826 typedef bool (*check_func_type
) (const char *, void *);
10827 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
10830 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10832 static unsigned char buffer
[8 * 1024];
10834 bfd_size_type count
;
10835 unsigned long crc
= 0;
10838 sep_data
= open_debug_file (pathname
);
10839 if (sep_data
== NULL
)
10842 /* Yes - we are opening the file twice... */
10843 f
= fopen (pathname
, "rb");
10846 /* Paranoia: This should never happen. */
10847 close_debug_file (sep_data
);
10848 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10852 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10853 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10857 if (crc
!= * (unsigned long *) crc_pointer
)
10859 close_debug_file (sep_data
);
10860 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10868 static const char *
10869 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10872 unsigned int crc_offset
;
10873 unsigned long * crc32
= (unsigned long *) data
;
10875 /* The name is first.
10876 The CRC value is stored after the filename, aligned up to 4 bytes. */
10877 name
= (const char *) section
->start
;
10879 crc_offset
= strnlen (name
, section
->size
) + 1;
10880 if (crc_offset
== 1)
10882 crc_offset
= (crc_offset
+ 3) & ~3;
10883 if (crc_offset
+ 4 > section
->size
)
10886 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10891 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10893 void * sep_data
= open_debug_file (filename
);
10895 if (sep_data
== NULL
)
10898 /* FIXME: We should now extract the build-id in the separate file
10904 typedef struct build_id_data
10907 const unsigned char * data
;
10910 static const char *
10911 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10914 bfd_size_type namelen
;
10915 bfd_size_type id_len
;
10916 Build_id_data
* build_id_data
;
10918 /* The name is first.
10919 The build-id follows immediately, with no padding, up to the section's end. */
10921 name
= (const char *) section
->start
;
10922 namelen
= strnlen (name
, section
->size
) + 1;
10925 if (namelen
>= section
->size
)
10928 id_len
= section
->size
- namelen
;
10932 build_id_data
= (Build_id_data
*) data
;
10933 build_id_data
->len
= id_len
;
10934 build_id_data
->data
= section
->start
+ namelen
;
10940 add_separate_debug_file (const char * filename
, void * handle
)
10942 separate_info
* i
= xmalloc (sizeof * i
);
10944 i
->filename
= filename
;
10945 i
->handle
= handle
;
10946 i
->next
= first_separate_info
;
10947 first_separate_info
= i
;
10950 #if HAVE_LIBDEBUGINFOD
10951 /* Query debuginfod servers for the target debuglink or debugaltlink
10952 file. If successful, store the path of the file in filename and
10953 return TRUE, otherwise return FALSE. */
10956 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10960 size_t build_id_len
;
10961 unsigned char * build_id
;
10963 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10965 /* Get the build-id of file. */
10966 build_id
= get_build_id (file
);
10969 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10971 /* Get the build-id of the debugaltlink file. */
10972 unsigned int filelen
;
10974 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10975 if (filelen
== section
->size
)
10976 /* Corrupt debugaltlink. */
10979 build_id
= section
->start
+ filelen
+ 1;
10980 build_id_len
= section
->size
- (filelen
+ 1);
10982 if (build_id_len
== 0)
10991 debuginfod_client
* client
;
10993 client
= debuginfod_begin ();
10994 if (client
== NULL
)
10997 /* Query debuginfod servers for the target file. If found its path
10998 will be stored in filename. */
10999 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11000 debuginfod_end (client
);
11002 /* Only free build_id if we allocated space for a hex string
11003 in get_build_id (). */
11004 if (build_id_len
== 0)
11009 /* File successfully retrieved. Close fd since we want to
11010 use open_debug_file () on filename instead. */
11021 load_separate_debug_info (const char * main_filename
,
11022 struct dwarf_section
* xlink
,
11023 parse_func_type parse_func
,
11024 check_func_type check_func
,
11026 void * file ATTRIBUTE_UNUSED
)
11028 const char * separate_filename
;
11029 char * debug_filename
;
11031 size_t canon_dirlen
;
11034 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11036 warn (_("Corrupt debuglink section: %s\n"),
11037 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11041 /* Attempt to locate the separate file.
11042 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11044 canon_dir
= lrealpath (main_filename
);
11046 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11047 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11049 canon_dir
[canon_dirlen
] = '\0';
11052 #define DEBUGDIR "/lib/debug"
11054 #ifndef EXTRA_DEBUG_ROOT1
11055 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11057 #ifndef EXTRA_DEBUG_ROOT2
11058 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11061 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11063 + strlen (".debug/")
11064 #ifdef EXTRA_DEBUG_ROOT1
11065 + strlen (EXTRA_DEBUG_ROOT1
)
11067 #ifdef EXTRA_DEBUG_ROOT2
11068 + strlen (EXTRA_DEBUG_ROOT2
)
11070 + strlen (separate_filename
)
11072 if (debug_filename
== NULL
)
11074 warn (_("Out of memory"));
11079 /* First try in the current directory. */
11080 sprintf (debug_filename
, "%s", separate_filename
);
11081 if (check_func (debug_filename
, func_data
))
11084 /* Then try in a subdirectory called .debug. */
11085 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11086 if (check_func (debug_filename
, func_data
))
11089 /* Then try in the same directory as the original file. */
11090 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11091 if (check_func (debug_filename
, func_data
))
11094 /* And the .debug subdirectory of that directory. */
11095 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11096 if (check_func (debug_filename
, func_data
))
11099 #ifdef EXTRA_DEBUG_ROOT1
11100 /* Try the first extra debug file root. */
11101 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11102 if (check_func (debug_filename
, func_data
))
11105 /* Try the first extra debug file root. */
11106 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11107 if (check_func (debug_filename
, func_data
))
11111 #ifdef EXTRA_DEBUG_ROOT2
11112 /* Try the second extra debug file root. */
11113 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11114 if (check_func (debug_filename
, func_data
))
11118 /* Then try in the global debug_filename directory. */
11119 strcpy (debug_filename
, DEBUGDIR
);
11120 dirlen
= strlen (DEBUGDIR
) - 1;
11121 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11122 strcat (debug_filename
, "/");
11123 strcat (debug_filename
, (const char *) separate_filename
);
11125 if (check_func (debug_filename
, func_data
))
11128 #if HAVE_LIBDEBUGINFOD
11130 char * tmp_filename
;
11132 if (debuginfod_fetch_separate_debug_info (xlink
,
11136 /* File successfully downloaded from server, replace
11137 debug_filename with the file's path. */
11138 free (debug_filename
);
11139 debug_filename
= tmp_filename
;
11145 if (do_debug_links
)
11147 /* Failed to find the file. */
11148 warn (_("could not find separate debug file '%s'\n"),
11149 separate_filename
);
11150 warn (_("tried: %s\n"), debug_filename
);
11152 #ifdef EXTRA_DEBUG_ROOT2
11153 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11154 separate_filename
);
11155 warn (_("tried: %s\n"), debug_filename
);
11158 #ifdef EXTRA_DEBUG_ROOT1
11159 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11160 canon_dir
, separate_filename
);
11161 warn (_("tried: %s\n"), debug_filename
);
11163 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11164 separate_filename
);
11165 warn (_("tried: %s\n"), debug_filename
);
11168 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11169 separate_filename
);
11170 warn (_("tried: %s\n"), debug_filename
);
11172 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11173 warn (_("tried: %s\n"), debug_filename
);
11175 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11176 warn (_("tried: %s\n"), debug_filename
);
11178 sprintf (debug_filename
, "%s", separate_filename
);
11179 warn (_("tried: %s\n"), debug_filename
);
11181 #if HAVE_LIBDEBUGINFOD
11183 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11187 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11193 free (debug_filename
);
11199 void * debug_handle
;
11201 /* Now open the file.... */
11202 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11204 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11205 free (debug_filename
);
11209 /* FIXME: We do not check to see if there are any other separate debug info
11210 files that would also match. */
11212 if (do_debug_links
)
11213 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11214 add_separate_debug_file (debug_filename
, debug_handle
);
11216 /* Do not free debug_filename - it might be referenced inside
11217 the structure returned by open_debug_file(). */
11218 return debug_handle
;
11221 /* Attempt to load a separate dwarf object file. */
11224 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11226 char * separate_filename
;
11227 void * separate_handle
;
11229 if (IS_ABSOLUTE_PATH (name
))
11230 separate_filename
= strdup (name
);
11232 /* FIXME: Skip adding / if dwo_dir ends in /. */
11233 separate_filename
= concat (dir
, "/", name
, NULL
);
11234 if (separate_filename
== NULL
)
11236 warn (_("Out of memory allocating dwo filename\n"));
11240 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11242 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11243 free (separate_filename
);
11247 /* FIXME: We should check the dwo_id. */
11249 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11251 add_separate_debug_file (separate_filename
, separate_handle
);
11252 /* Note - separate_filename will be freed in free_debug_memory(). */
11253 return separate_handle
;
11257 load_debug_sup_file (const char * main_filename
, void * file
)
11259 if (! load_debug_section (debug_sup
, file
))
11260 return; /* No .debug_sup section. */
11262 struct dwarf_section
* section
;
11263 section
= & debug_displays
[debug_sup
].section
;
11264 assert (section
!= NULL
);
11266 if (section
->start
== NULL
|| section
->size
< 5)
11268 warn (_(".debug_sup section is corrupt/empty\n"));
11272 if (section
->start
[2] != 0)
11273 return; /* This is a supplementary file. */
11275 const char * filename
= (const char *) section
->start
+ 3;
11276 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11278 warn (_("filename in .debug_sup section is corrupt\n"));
11282 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11287 new_len
= asprintf (& new_name
, "%.*s/%s",
11288 (int) (strrchr (main_filename
, '/') - main_filename
),
11293 warn (_("unable to construct path for supplementary debug file"));
11298 filename
= new_name
;
11302 /* PR 27796: Make sure that we pass a filename that can be free'd to
11303 add_separate_debug_file(). */
11304 filename
= strdup (filename
);
11305 if (filename
== NULL
)
11307 warn (_("out of memory constructing filename for .debug_sup link\n"));
11312 void * handle
= open_debug_file (filename
);
11313 if (handle
== NULL
)
11315 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11316 free ((void *) filename
);
11320 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11322 /* FIXME: Compare the checksums, if present. */
11323 add_separate_debug_file (filename
, handle
);
11326 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11327 Recursively check the loaded files for more of these sections.
11328 Also follow any links in .debug_sup sections.
11329 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11332 check_for_and_load_links (void * file
, const char * filename
)
11334 void * handle
= NULL
;
11336 if (load_debug_section (gnu_debugaltlink
, file
))
11338 Build_id_data build_id_data
;
11340 handle
= load_separate_debug_info (filename
,
11341 & debug_displays
[gnu_debugaltlink
].section
,
11342 parse_gnu_debugaltlink
,
11343 check_gnu_debugaltlink
,
11348 assert (handle
== first_separate_info
->handle
);
11349 check_for_and_load_links (first_separate_info
->handle
,
11350 first_separate_info
->filename
);
11354 if (load_debug_section (gnu_debuglink
, file
))
11356 unsigned long crc32
;
11358 handle
= load_separate_debug_info (filename
,
11359 & debug_displays
[gnu_debuglink
].section
,
11360 parse_gnu_debuglink
,
11361 check_gnu_debuglink
,
11366 assert (handle
== first_separate_info
->handle
);
11367 check_for_and_load_links (first_separate_info
->handle
,
11368 first_separate_info
->filename
);
11372 load_debug_sup_file (filename
, file
);
11375 /* Load the separate debug info file(s) attached to FILE, if any exist.
11376 Returns TRUE if any were found, FALSE otherwise.
11377 If TRUE is returned then the linked list starting at first_separate_info
11378 will be populated with open file handles. */
11381 load_separate_debug_files (void * file
, const char * filename
)
11383 /* Skip this operation if we are not interested in debug links. */
11384 if (! do_follow_links
&& ! do_debug_links
)
11387 /* See if there are any dwo links. */
11388 if (load_debug_section (str
, file
)
11389 && load_debug_section (abbrev
, file
)
11390 && load_debug_section (info
, file
))
11394 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11397 bool introduced
= false;
11399 const char *dir
= NULL
;
11400 const char *id
= NULL
;
11401 const char *name
= NULL
;
11403 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11405 /* Accumulate NAME, DIR and ID fields. */
11406 switch (dwinfo
->type
)
11410 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11411 name
= dwinfo
->value
;
11415 /* There can be multiple DW_AT_comp_dir entries in a CU,
11416 so do not complain. */
11417 dir
= dwinfo
->value
;
11422 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11423 id
= dwinfo
->value
;
11427 error (_("Unexpected DWO INFO type"));
11431 /* If we have reached the end of our list, or we are changing
11432 CUs, then display the information that we have accumulated
11435 && (dwinfo
->next
== NULL
11436 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11438 if (do_debug_links
)
11442 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11443 debug_displays
[info
].section
.uncompressed_name
);
11447 printf (_(" Name: %s\n"), name
);
11448 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11450 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11452 printf (_(" ID: <not specified>\n"));
11456 if (do_follow_links
)
11457 load_dwo_file (filename
, name
, dir
, id
);
11459 name
= dir
= id
= NULL
;
11465 if (! do_follow_links
)
11466 /* The other debug links will be displayed by display_debug_links()
11467 so we do not need to do any further processing here. */
11470 /* FIXME: We do not check for the presence of both link sections in the same file. */
11471 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11472 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11474 check_for_and_load_links (file
, filename
);
11475 if (first_separate_info
!= NULL
)
11478 do_follow_links
= 0;
11483 free_debug_memory (void)
11487 free_all_abbrevs ();
11489 free (cu_abbrev_map
);
11490 cu_abbrev_map
= NULL
;
11491 next_free_abbrev_map_entry
= 0;
11495 shndx_pool_size
= 0;
11496 shndx_pool_used
= 0;
11504 memset (level_type_signed
, 0, sizeof level_type_signed
);
11505 cu_tu_indexes_read
= -1;
11507 for (i
= 0; i
< max
; i
++)
11508 free_debug_section ((enum dwarf_section_display_enum
) i
);
11510 if (debug_information
!= NULL
)
11512 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11514 if (debug_information
[i
].max_loc_offsets
)
11516 free (debug_information
[i
].loc_offsets
);
11517 free (debug_information
[i
].have_frame_base
);
11519 if (debug_information
[i
].max_range_lists
)
11520 free (debug_information
[i
].range_lists
);
11522 free (debug_information
);
11523 debug_information
= NULL
;
11524 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11528 separate_info
* next
;
11530 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11532 close_debug_file (d
->handle
);
11533 free ((void *) d
->filename
);
11537 first_separate_info
= NULL
;
11543 dwarf_select_sections_by_names (const char *names
)
11547 const char * option
;
11551 debug_dump_long_opts
;
11553 static const debug_dump_long_opts opts_table
[] =
11555 /* Please keep this table alpha- sorted. */
11556 { "Ranges", & do_debug_ranges
, 1 },
11557 { "abbrev", & do_debug_abbrevs
, 1 },
11558 { "addr", & do_debug_addr
, 1 },
11559 { "aranges", & do_debug_aranges
, 1 },
11560 { "cu_index", & do_debug_cu_index
, 1 },
11561 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11562 { "follow-links", & do_follow_links
, 1 },
11563 { "frames", & do_debug_frames
, 1 },
11564 { "frames-interp", & do_debug_frames_interp
, 1 },
11565 /* The special .gdb_index section. */
11566 { "gdb_index", & do_gdb_index
, 1 },
11567 { "info", & do_debug_info
, 1 },
11568 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11569 { "links", & do_debug_links
, 1 },
11570 { "loc", & do_debug_loc
, 1 },
11571 { "macro", & do_debug_macinfo
, 1 },
11572 { "no-follow-links", & do_follow_links
, 0 },
11573 { "pubnames", & do_debug_pubnames
, 1 },
11574 { "pubtypes", & do_debug_pubtypes
, 1 },
11575 /* This entry is for compatibility
11576 with earlier versions of readelf. */
11577 { "ranges", & do_debug_aranges
, 1 },
11578 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11579 { "str", & do_debug_str
, 1 },
11580 { "str-offsets", & do_debug_str_offsets
, 1 },
11581 /* These trace_* sections are used by Itanium VMS. */
11582 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11583 { "trace_aranges", & do_trace_aranges
, 1 },
11584 { "trace_info", & do_trace_info
, 1 },
11593 const debug_dump_long_opts
* entry
;
11595 for (entry
= opts_table
; entry
->option
; entry
++)
11597 size_t len
= strlen (entry
->option
);
11599 if (strncmp (p
, entry
->option
, len
) == 0
11600 && (p
[len
] == ',' || p
[len
] == '\0'))
11602 * entry
->variable
= entry
->val
;
11604 /* The --debug-dump=frames-interp option also
11605 enables the --debug-dump=frames option. */
11606 if (do_debug_frames_interp
)
11607 do_debug_frames
= 1;
11614 if (entry
->option
== NULL
)
11616 warn (_("Unrecognized debug option '%s'\n"), p
);
11617 p
= strchr (p
, ',');
11628 dwarf_select_sections_by_letters (const char *letters
)
11630 unsigned int lindex
= 0;
11632 while (letters
[lindex
])
11633 switch (letters
[lindex
++])
11635 case 'A': do_debug_addr
= 1; break;
11636 case 'a': do_debug_abbrevs
= 1; break;
11637 case 'c': do_debug_cu_index
= 1; break;
11638 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11639 case 'f': do_debug_frames
= 1; break;
11640 case 'g': do_gdb_index
= 1; break;
11641 case 'i': do_debug_info
= 1; break;
11642 case 'K': do_follow_links
= 1; break;
11643 case 'N': do_follow_links
= 0; break;
11644 case 'k': do_debug_links
= 1; break;
11645 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11646 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11647 case 'm': do_debug_macinfo
= 1; break;
11648 case 'O': do_debug_str_offsets
= 1; break;
11649 case 'o': do_debug_loc
= 1; break;
11650 case 'p': do_debug_pubnames
= 1; break;
11651 case 'R': do_debug_ranges
= 1; break;
11652 case 'r': do_debug_aranges
= 1; break;
11653 case 's': do_debug_str
= 1; break;
11654 case 'T': do_trace_aranges
= 1; break;
11655 case 't': do_debug_pubtypes
= 1; break;
11656 case 'U': do_trace_info
= 1; break;
11657 case 'u': do_trace_abbrevs
= 1; break;
11660 warn (_("Unrecognized debug option '%s'\n"), letters
);
11666 dwarf_select_sections_all (void)
11669 do_debug_abbrevs
= 1;
11670 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11671 do_debug_pubnames
= 1;
11672 do_debug_pubtypes
= 1;
11673 do_debug_aranges
= 1;
11674 do_debug_ranges
= 1;
11675 do_debug_frames
= 1;
11676 do_debug_macinfo
= 1;
11681 do_trace_abbrevs
= 1;
11682 do_trace_aranges
= 1;
11684 do_debug_cu_index
= 1;
11685 do_follow_links
= 1;
11686 do_debug_links
= 1;
11687 do_debug_str_offsets
= 1;
11690 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
11691 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
11693 /* N.B. The order here must match the order in section_display_enum. */
11695 struct dwarf_section_display debug_displays
[] =
11697 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11698 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
11699 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11700 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
11701 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11702 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
11703 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
11704 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
11705 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11706 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11707 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11708 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11709 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11710 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11711 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
11712 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
11713 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11714 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
11715 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11716 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11717 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
11718 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
11719 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
11720 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
11721 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
11722 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
11723 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
11724 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
11725 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
11726 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
11727 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
11728 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
11729 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
11730 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
11731 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
11732 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11733 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
11734 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
11735 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11736 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
11737 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11738 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
11739 { { ".debug_sup", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
11740 /* Separate debug info files can containt their own .debug_str section,
11741 and this might be in *addition* to a .debug_str section already present
11742 in the main file. Hence we need to have two entries for .debug_str. */
11743 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
11746 /* A static assertion. */
11747 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];