1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2020 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"
24 #include "bfd_stdint.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>
41 #define MAX(a, b) ((a) > (b) ? (a) : (b))
42 #define MIN(a, b) ((a) < (b) ? (a) : (b))
44 static const char *regname (unsigned int regno
, int row
);
45 static const char *regname_internal_by_table_only (unsigned int regno
);
47 static int have_frame_base
;
48 static int need_base_address
;
50 static unsigned int num_debug_info_entries
= 0;
51 static unsigned int alloc_num_debug_info_entries
= 0;
52 static debug_info
*debug_information
= NULL
;
53 /* Special value for num_debug_info_entries to indicate
54 that the .debug_info section could not be loaded/parsed. */
55 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
57 /* A .debug_info section can contain multiple links to separate
58 DWO object files. We use these structures to record these links. */
66 typedef struct dwo_info
70 struct dwo_info
* next
;
73 static dwo_info
* first_dwo_info
= NULL
;
74 static bfd_boolean need_dwo_info
;
76 separate_info
* first_separate_info
= NULL
;
78 unsigned int eh_addr_size
;
83 int do_debug_pubnames
;
84 int do_debug_pubtypes
;
88 int do_debug_frames_interp
;
91 int do_debug_str_offsets
;
98 int do_debug_cu_index
;
102 bfd_boolean do_checks
;
104 int dwarf_cutoff_level
= -1;
105 unsigned long dwarf_start_die
;
109 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
110 testing whether e.g. a locview list is present. */
111 static const dwarf_vma vm1
= -1;
113 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
114 sections. For version 1 package files, each set is stored in SHNDX_POOL
115 as a zero-terminated list of section indexes comprising one set of debug
116 sections from a .dwo file. */
118 static unsigned int *shndx_pool
= NULL
;
119 static unsigned int shndx_pool_size
= 0;
120 static unsigned int shndx_pool_used
= 0;
122 /* For version 2 package files, each set contains an array of section offsets
123 and an array of section sizes, giving the offset and size of the
124 contribution from a CU or TU within one of the debug sections.
125 When displaying debug info from a package file, we need to use these
126 tables to locate the corresponding contributions to each section. */
131 dwarf_vma section_offsets
[DW_SECT_MAX
];
132 size_t section_sizes
[DW_SECT_MAX
];
135 static int cu_count
= 0;
136 static int tu_count
= 0;
137 static struct cu_tu_set
*cu_sets
= NULL
;
138 static struct cu_tu_set
*tu_sets
= NULL
;
140 static bfd_boolean
load_cu_tu_indexes (void *);
142 /* An array that indicates for a given level of CU nesting whether
143 the latest DW_AT_type seen for that level was a signed type or
145 #define MAX_CU_NESTING (1 << 8)
146 static bfd_boolean level_type_signed
[MAX_CU_NESTING
];
148 /* Values for do_debug_lines. */
149 #define FLAG_DEBUG_LINES_RAW 1
150 #define FLAG_DEBUG_LINES_DECODED 2
153 size_of_encoded_value (int encoding
)
155 switch (encoding
& 0x7)
158 case 0: return eh_addr_size
;
166 get_encoded_value (unsigned char **pdata
,
168 struct dwarf_section
*section
,
171 unsigned char * data
= * pdata
;
172 unsigned int size
= size_of_encoded_value (encoding
);
175 if (data
+ size
>= end
)
177 warn (_("Encoded value extends past end of section\n"));
182 /* PR 17512: file: 002-829853-0.004. */
185 warn (_("Encoded size of %d is too large to read\n"), size
);
190 /* PR 17512: file: 1085-5603-0.004. */
193 warn (_("Encoded size of 0 is too small to read\n"));
198 if (encoding
& DW_EH_PE_signed
)
199 val
= byte_get_signed (data
, size
);
201 val
= byte_get (data
, size
);
203 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
204 val
+= section
->address
+ (data
- section
->start
);
206 * pdata
= data
+ size
;
210 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
212 # define DWARF_VMA_FMT "ll"
213 # define DWARF_VMA_FMT_LONG "%16.16llx"
215 # define DWARF_VMA_FMT "I64"
216 # define DWARF_VMA_FMT_LONG "%016I64x"
219 # define DWARF_VMA_FMT "l"
220 # define DWARF_VMA_FMT_LONG "%16.16lx"
223 /* Convert a dwarf vma value into a string. Returns a pointer to a static
224 buffer containing the converted VALUE. The value is converted according
225 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
226 it specifies the maximum number of bytes to be displayed in the converted
227 value and FMTCH is ignored - hex is always used. */
230 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
232 /* As dwarf_vmatoa is used more then once in a printf call
233 for output, we are cycling through an fixed array of pointers
234 for return address. */
235 static int buf_pos
= 0;
236 static struct dwarf_vmatoa_buf
242 ret
= buf
[buf_pos
++].place
;
243 buf_pos
%= ARRAY_SIZE (buf
);
247 /* Printf does not have a way of specifying a maximum field width for an
248 integer value, so we print the full value into a buffer and then select
249 the precision we need. */
250 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
253 return ret
+ (16 - 2 * num_bytes
);
260 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
262 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
263 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
268 static inline const char *
269 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
271 return dwarf_vmatoa_1 (fmtch
, value
, 0);
274 /* Print a dwarf_vma value (typically an address, offset or length) in
275 hexadecimal format, followed by a space. The length of the VALUE (and
276 hence the precision displayed) is determined by the NUM_BYTES parameter. */
279 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
281 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
284 /* Print a view number in hexadecimal value, with the same width
285 print_dwarf_vma would have printed it with the same num_bytes.
286 Print blanks for zero view, unless force is nonzero. */
289 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
297 assert (value
== (unsigned long) value
);
299 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
301 printf ("%*s", len
+ 1, "");
304 /* Format a 64-bit value, given as two 32-bit values, in hex.
305 For reentrancy, this uses a buffer provided by the caller. */
308 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
309 unsigned int buf_len
)
314 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
317 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
318 snprintf (buf
+ len
, buf_len
- len
,
319 "%08" DWARF_VMA_FMT
"x", lvalue
);
325 /* Read in a LEB128 encoded value starting at address DATA.
326 If SIGN is true, return a signed LEB128 value.
327 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
328 If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the
329 terminating byte was not found and with bit 1 set if the value
330 overflows a dwarf_vma.
331 No bytes will be read at address END or beyond. */
334 read_leb128 (unsigned char *data
,
335 const unsigned char *const end
,
337 unsigned int *length_return
,
340 dwarf_vma result
= 0;
341 unsigned int num_read
= 0;
342 unsigned int shift
= 0;
347 unsigned char byte
= *data
++;
348 bfd_boolean cont
= (byte
& 0x80) ? TRUE
: FALSE
;
353 if (shift
< sizeof (result
) * 8)
355 result
|= ((dwarf_vma
) byte
) << shift
;
358 if ((((dwarf_signed_vma
) result
>> shift
) & 0x7f) != byte
)
362 else if ((result
>> shift
) != byte
)
378 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
379 result
|= -((dwarf_vma
) 1 << shift
);
384 if (length_return
!= NULL
)
385 *length_return
= num_read
;
386 if (status_return
!= NULL
)
387 *status_return
= status
;
392 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
393 Checks to make sure that the read will not reach or pass END
394 and that VAL is big enough to hold AMOUNT bytes. */
395 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
398 unsigned int amount = (AMOUNT); \
399 if (sizeof (VAL) < amount) \
401 error (ngettext ("internal error: attempt to read %d byte " \
402 "of data in to %d sized variable", \
403 "internal error: attempt to read %d bytes " \
404 "of data in to %d sized variable", \
406 amount, (int) sizeof (VAL)); \
407 amount = sizeof (VAL); \
409 if (((PTR) + amount) >= (END)) \
412 amount = (END) - (PTR); \
416 if (amount == 0 || amount > 8) \
419 VAL = byte_get ((PTR), amount); \
423 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
424 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
427 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
432 /* Like SAFE_BYTE_GET, but reads a signed value. */
433 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
436 unsigned int amount = (AMOUNT); \
437 if (((PTR) + amount) >= (END)) \
440 amount = (END) - (PTR); \
445 VAL = byte_get_signed ((PTR), amount); \
451 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
452 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
455 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
460 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
463 if (((PTR) + 8) <= (END)) \
465 byte_get_64 ((PTR), (HIGH), (LOW)); \
469 * (LOW) = * (HIGH) = 0; \
474 typedef struct State_Machine_Registers
483 unsigned char op_index
;
484 unsigned char end_sequence
;
485 /* This variable hold the number of the last entry seen
486 in the File Table. */
487 unsigned int last_file_entry
;
490 static SMR state_machine_regs
;
493 reset_state_machine (int is_stmt
)
495 state_machine_regs
.address
= 0;
496 state_machine_regs
.view
= 0;
497 state_machine_regs
.op_index
= 0;
498 state_machine_regs
.file
= 1;
499 state_machine_regs
.line
= 1;
500 state_machine_regs
.column
= 0;
501 state_machine_regs
.is_stmt
= is_stmt
;
502 state_machine_regs
.basic_block
= 0;
503 state_machine_regs
.end_sequence
= 0;
504 state_machine_regs
.last_file_entry
= 0;
507 /* Handled an extend line op.
508 Returns the number of bytes read. */
511 process_extended_line_op (unsigned char * data
,
515 unsigned char op_code
;
516 size_t len
, header_len
;
518 unsigned char *orig_data
= data
;
521 READ_ULEB (len
, data
, end
);
522 header_len
= data
- orig_data
;
524 if (len
== 0 || data
== end
|| len
> (size_t) (end
- data
))
526 warn (_("Badly formed extended line op encountered!\n"));
532 printf (_(" Extended opcode %d: "), op_code
);
536 case DW_LNE_end_sequence
:
537 printf (_("End of Sequence\n\n"));
538 reset_state_machine (is_stmt
);
541 case DW_LNE_set_address
:
542 /* PR 17512: file: 002-100480-0.004. */
545 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
546 (unsigned long) len
- 1);
550 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
551 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
552 state_machine_regs
.address
= adr
;
553 state_machine_regs
.view
= 0;
554 state_machine_regs
.op_index
= 0;
557 case DW_LNE_define_file
:
558 printf (_("define new File Table entry\n"));
559 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
560 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
566 l
= strnlen ((char *) data
, end
- data
);
568 READ_ULEB (val
, data
, end
);
569 printf ("%s\t", dwarf_vmatoa ("u", val
));
570 READ_ULEB (val
, data
, end
);
571 printf ("%s\t", dwarf_vmatoa ("u", val
));
572 READ_ULEB (val
, data
, end
);
573 printf ("%s\t", dwarf_vmatoa ("u", val
));
574 printf ("%.*s\n\n", (int) l
, name
);
577 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
== end
)
578 warn (_("DW_LNE_define_file: Bad opcode length\n"));
581 case DW_LNE_set_discriminator
:
582 READ_ULEB (val
, data
, end
);
583 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
587 case DW_LNE_HP_negate_is_UV_update
:
588 printf ("DW_LNE_HP_negate_is_UV_update\n");
590 case DW_LNE_HP_push_context
:
591 printf ("DW_LNE_HP_push_context\n");
593 case DW_LNE_HP_pop_context
:
594 printf ("DW_LNE_HP_pop_context\n");
596 case DW_LNE_HP_set_file_line_column
:
597 printf ("DW_LNE_HP_set_file_line_column\n");
599 case DW_LNE_HP_set_routine_name
:
600 printf ("DW_LNE_HP_set_routine_name\n");
602 case DW_LNE_HP_set_sequence
:
603 printf ("DW_LNE_HP_set_sequence\n");
605 case DW_LNE_HP_negate_post_semantics
:
606 printf ("DW_LNE_HP_negate_post_semantics\n");
608 case DW_LNE_HP_negate_function_exit
:
609 printf ("DW_LNE_HP_negate_function_exit\n");
611 case DW_LNE_HP_negate_front_end_logical
:
612 printf ("DW_LNE_HP_negate_front_end_logical\n");
614 case DW_LNE_HP_define_proc
:
615 printf ("DW_LNE_HP_define_proc\n");
617 case DW_LNE_HP_source_file_correlation
:
619 unsigned char *edata
= data
+ len
- 1;
621 printf ("DW_LNE_HP_source_file_correlation\n");
627 READ_ULEB (opc
, data
, edata
);
631 case DW_LNE_HP_SFC_formfeed
:
632 printf (" DW_LNE_HP_SFC_formfeed\n");
634 case DW_LNE_HP_SFC_set_listing_line
:
635 READ_ULEB (val
, data
, edata
);
636 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
637 dwarf_vmatoa ("u", val
));
639 case DW_LNE_HP_SFC_associate
:
640 printf (" DW_LNE_HP_SFC_associate ");
641 READ_ULEB (val
, data
, edata
);
642 printf ("(%s", dwarf_vmatoa ("u", val
));
643 READ_ULEB (val
, data
, edata
);
644 printf (",%s", dwarf_vmatoa ("u", val
));
645 READ_ULEB (val
, data
, edata
);
646 printf (",%s)\n", dwarf_vmatoa ("u", val
));
649 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
659 unsigned int rlen
= len
- 1;
661 if (op_code
>= DW_LNE_lo_user
662 /* The test against DW_LNW_hi_user is redundant due to
663 the limited range of the unsigned char data type used
665 /*&& op_code <= DW_LNE_hi_user*/)
666 printf (_("user defined: "));
668 printf (_("UNKNOWN: "));
669 printf (_("length %d ["), rlen
);
671 printf (" %02x", *data
++);
677 return len
+ header_len
;
680 static const unsigned char *
681 fetch_indirect_string (dwarf_vma offset
)
683 struct dwarf_section
*section
= &debug_displays
[str
].section
;
684 const unsigned char * ret
;
686 if (section
->start
== NULL
)
687 return (const unsigned char *) _("<no .debug_str section>");
689 if (offset
>= section
->size
)
691 warn (_("DW_FORM_strp offset too big: %s\n"),
692 dwarf_vmatoa ("x", offset
));
693 return (const unsigned char *) _("<offset is too big>");
696 ret
= section
->start
+ offset
;
697 /* Unfortunately we cannot rely upon the .debug_str section ending with a
698 NUL byte. Since our caller is expecting to receive a well formed C
699 string we test for the lack of a terminating byte here. */
700 if (strnlen ((const char *) ret
, section
->size
- offset
)
701 == section
->size
- offset
)
702 ret
= (const unsigned char *)
703 _("<no NUL byte at end of .debug_str section>");
708 static const unsigned char *
709 fetch_indirect_line_string (dwarf_vma offset
)
711 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
712 const unsigned char * ret
;
714 if (section
->start
== NULL
)
715 return (const unsigned char *) _("<no .debug_line_str section>");
717 if (offset
>= section
->size
)
719 warn (_("DW_FORM_line_strp offset too big: %s\n"),
720 dwarf_vmatoa ("x", offset
));
721 return (const unsigned char *) _("<offset is too big>");
724 ret
= section
->start
+ offset
;
725 /* Unfortunately we cannot rely upon the .debug_line_str section ending
726 with a NUL byte. Since our caller is expecting to receive a well formed
727 C string we test for the lack of a terminating byte here. */
728 if (strnlen ((const char *) ret
, section
->size
- offset
)
729 == section
->size
- offset
)
730 ret
= (const unsigned char *)
731 _("<no NUL byte at end of .debug_line_str section>");
737 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
738 dwarf_vma offset_size
, bfd_boolean dwo
)
740 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
741 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
742 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
743 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
744 dwarf_vma index_offset
;
745 dwarf_vma str_offset
;
747 unsigned char *curr
= index_section
->start
;
748 const unsigned char *end
= curr
+ index_section
->size
;
751 if (index_section
->start
== NULL
)
752 return (dwo
? _("<no .debug_str_offsets.dwo section>")
753 : _("<no .debug_str_offsets section>"));
755 if (str_section
->start
== NULL
)
756 return (dwo
? _("<no .debug_str.dwo section>")
757 : _("<no .debug_str section>"));
759 /* FIXME: We should cache the length... */
760 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
761 if (length
== 0xffffffff)
763 if (offset_size
!= 8)
764 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
765 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
767 else if (offset_size
!= 4)
769 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
774 /* This is probably an old style .debug_str_offset section which
775 just contains offsets and no header (and the first offset is 0). */
776 curr
= index_section
->start
;
777 length
= index_section
->size
;
781 /* Skip the version and padding bytes.
782 We assume that they are correct. */
785 /* FIXME: The code below assumes that there is only one table
786 in the .debug_str_offsets section, so check that now. */
787 if ((offset_size
== 4 && curr
+ length
< (end
- 8))
788 || (offset_size
== 8 && curr
+ length
< (end
- 16)))
790 warn (_("index table size is too small %s vs %s\n"),
791 dwarf_vmatoa ("x", length
),
792 dwarf_vmatoa ("x", index_section
->size
));
793 return _("<table too small>");
797 index_offset
= idx
* offset_size
;
799 if (this_set
!= NULL
)
800 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
802 if (index_offset
>= length
)
804 warn (_("DW_FORM_GNU_str_index offset too big: %s vs %s\n"),
805 dwarf_vmatoa ("x", index_offset
),
806 dwarf_vmatoa ("x", length
));
807 return _("<index offset is too big>");
810 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
811 str_offset
-= str_section
->address
;
812 if (str_offset
>= str_section
->size
)
814 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
815 dwarf_vmatoa ("x", str_offset
));
816 return _("<indirect index offset is too big>");
819 ret
= (const char *) str_section
->start
+ str_offset
;
820 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
821 Since our caller is expecting to receive a well formed C string we test
822 for the lack of a terminating byte here. */
823 if (strnlen (ret
, str_section
->size
- str_offset
)
824 == str_section
->size
- str_offset
)
825 ret
= (const char *) _("<no NUL byte at end of section>");
831 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
833 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
835 if (section
->start
== NULL
)
836 return (_("<no .debug_addr section>"));
838 if (offset
+ bytes
> section
->size
)
840 warn (_("Offset into section %s too big: %s\n"),
841 section
->name
, dwarf_vmatoa ("x", offset
));
842 return "<offset too big>";
845 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
849 /* FIXME: There are better and more efficient ways to handle
850 these structures. For now though, I just want something that
851 is simple to implement. */
852 typedef struct abbrev_attr
854 unsigned long attribute
;
856 bfd_signed_vma implicit_const
;
857 struct abbrev_attr
*next
;
861 typedef struct abbrev_entry
866 struct abbrev_attr
*first_attr
;
867 struct abbrev_attr
*last_attr
;
868 struct abbrev_entry
*next
;
872 static abbrev_entry
*first_abbrev
= NULL
;
873 static abbrev_entry
*last_abbrev
= NULL
;
880 for (abbrv
= first_abbrev
; abbrv
;)
882 abbrev_entry
*next_abbrev
= abbrv
->next
;
885 for (attr
= abbrv
->first_attr
; attr
;)
887 abbrev_attr
*next_attr
= attr
->next
;
897 last_abbrev
= first_abbrev
= NULL
;
901 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
905 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
910 entry
->entry
= number
;
912 entry
->children
= children
;
913 entry
->first_attr
= NULL
;
914 entry
->last_attr
= NULL
;
917 if (first_abbrev
== NULL
)
918 first_abbrev
= entry
;
920 last_abbrev
->next
= entry
;
926 add_abbrev_attr (unsigned long attribute
, unsigned long form
,
927 bfd_signed_vma implicit_const
)
931 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
936 attr
->attribute
= attribute
;
938 attr
->implicit_const
= implicit_const
;
941 if (last_abbrev
->first_attr
== NULL
)
942 last_abbrev
->first_attr
= attr
;
944 last_abbrev
->last_attr
->next
= attr
;
946 last_abbrev
->last_attr
= attr
;
949 /* Processes the (partial) contents of a .debug_abbrev section.
950 Returns NULL if the end of the section was encountered.
951 Returns the address after the last byte read if the end of
952 an abbreviation set was found. */
954 static unsigned char *
955 process_abbrev_section (unsigned char *start
, unsigned char *end
)
957 if (first_abbrev
!= NULL
)
964 unsigned long attribute
;
967 READ_ULEB (entry
, start
, end
);
969 /* A single zero is supposed to end the section according
970 to the standard. If there's more, then signal that to
977 READ_ULEB (tag
, start
, end
);
983 add_abbrev (entry
, tag
, children
);
988 /* Initialize it due to a false compiler warning. */
989 bfd_signed_vma implicit_const
= -1;
991 READ_ULEB (attribute
, start
, end
);
995 READ_ULEB (form
, start
, end
);
999 if (form
== DW_FORM_implicit_const
)
1001 READ_SLEB (implicit_const
, start
, end
);
1006 add_abbrev_attr (attribute
, form
, implicit_const
);
1008 while (attribute
!= 0);
1011 /* Report the missing single zero which ends the section. */
1012 error (_(".debug_abbrev section not zero terminated\n"));
1018 get_TAG_name (unsigned long tag
)
1020 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1024 static char buffer
[100];
1026 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1027 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1029 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1037 get_FORM_name (unsigned long form
)
1042 return "DW_FORM value: 0";
1044 name
= get_DW_FORM_name (form
);
1047 static char buffer
[100];
1049 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1057 get_IDX_name (unsigned long idx
)
1059 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1063 static char buffer
[100];
1065 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1072 static unsigned char *
1073 display_block (unsigned char *data
,
1075 const unsigned char * const end
, char delimiter
)
1079 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1081 return (unsigned char *) end
;
1083 maxlen
= (dwarf_vma
) (end
- data
);
1084 length
= length
> maxlen
? maxlen
: length
;
1087 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1093 decode_location_expression (unsigned char * data
,
1094 unsigned int pointer_size
,
1095 unsigned int offset_size
,
1098 dwarf_vma cu_offset
,
1099 struct dwarf_section
* section
)
1103 dwarf_signed_vma svalue
;
1104 unsigned char *end
= data
+ length
;
1105 int need_frame_base
= 0;
1114 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1115 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1118 printf ("DW_OP_deref");
1121 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1122 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1125 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1126 printf ("DW_OP_const1s: %ld", (long) svalue
);
1129 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1130 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1133 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1134 printf ("DW_OP_const2s: %ld", (long) svalue
);
1137 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1138 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1141 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1142 printf ("DW_OP_const4s: %ld", (long) svalue
);
1145 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1146 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1147 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1148 printf ("%lu", (unsigned long) uvalue
);
1151 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1152 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1153 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1154 printf ("%ld", (long) svalue
);
1157 READ_ULEB (uvalue
, data
, end
);
1158 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1161 READ_SLEB (svalue
, data
, end
);
1162 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1165 printf ("DW_OP_dup");
1168 printf ("DW_OP_drop");
1171 printf ("DW_OP_over");
1174 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1175 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1178 printf ("DW_OP_swap");
1181 printf ("DW_OP_rot");
1184 printf ("DW_OP_xderef");
1187 printf ("DW_OP_abs");
1190 printf ("DW_OP_and");
1193 printf ("DW_OP_div");
1196 printf ("DW_OP_minus");
1199 printf ("DW_OP_mod");
1202 printf ("DW_OP_mul");
1205 printf ("DW_OP_neg");
1208 printf ("DW_OP_not");
1211 printf ("DW_OP_or");
1214 printf ("DW_OP_plus");
1216 case DW_OP_plus_uconst
:
1217 READ_ULEB (uvalue
, data
, end
);
1218 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1221 printf ("DW_OP_shl");
1224 printf ("DW_OP_shr");
1227 printf ("DW_OP_shra");
1230 printf ("DW_OP_xor");
1233 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1234 printf ("DW_OP_bra: %ld", (long) svalue
);
1237 printf ("DW_OP_eq");
1240 printf ("DW_OP_ge");
1243 printf ("DW_OP_gt");
1246 printf ("DW_OP_le");
1249 printf ("DW_OP_lt");
1252 printf ("DW_OP_ne");
1255 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1256 printf ("DW_OP_skip: %ld", (long) svalue
);
1291 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1326 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1327 regname (op
- DW_OP_reg0
, 1));
1362 READ_SLEB (svalue
, data
, end
);
1363 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1364 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1368 READ_ULEB (uvalue
, data
, end
);
1369 printf ("DW_OP_regx: %s (%s)",
1370 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1373 need_frame_base
= 1;
1374 READ_SLEB (svalue
, data
, end
);
1375 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1378 READ_ULEB (uvalue
, data
, end
);
1379 READ_SLEB (svalue
, data
, end
);
1380 printf ("DW_OP_bregx: %s (%s) %s",
1381 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1382 dwarf_vmatoa ("d", svalue
));
1385 READ_ULEB (uvalue
, data
, end
);
1386 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1388 case DW_OP_deref_size
:
1389 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1390 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1392 case DW_OP_xderef_size
:
1393 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1394 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1397 printf ("DW_OP_nop");
1400 /* DWARF 3 extensions. */
1401 case DW_OP_push_object_address
:
1402 printf ("DW_OP_push_object_address");
1405 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1406 this ought to be an 8-byte wide computation. */
1407 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1408 printf ("DW_OP_call2: <0x%s>",
1409 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1412 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1413 this ought to be an 8-byte wide computation. */
1414 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1415 printf ("DW_OP_call4: <0x%s>",
1416 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1418 case DW_OP_call_ref
:
1419 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1420 this ought to be an 8-byte wide computation. */
1421 if (dwarf_version
== -1)
1423 printf (_("(DW_OP_call_ref in frame info)"));
1424 /* No way to tell where the next op is, so just bail. */
1425 return need_frame_base
;
1427 if (dwarf_version
== 2)
1429 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1433 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1435 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1437 case DW_OP_form_tls_address
:
1438 printf ("DW_OP_form_tls_address");
1440 case DW_OP_call_frame_cfa
:
1441 printf ("DW_OP_call_frame_cfa");
1443 case DW_OP_bit_piece
:
1444 printf ("DW_OP_bit_piece: ");
1445 READ_ULEB (uvalue
, data
, end
);
1446 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1447 READ_ULEB (uvalue
, data
, end
);
1448 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1451 /* DWARF 4 extensions. */
1452 case DW_OP_stack_value
:
1453 printf ("DW_OP_stack_value");
1456 case DW_OP_implicit_value
:
1457 printf ("DW_OP_implicit_value");
1458 READ_ULEB (uvalue
, data
, end
);
1459 data
= display_block (data
, uvalue
, end
, ' ');
1462 /* GNU extensions. */
1463 case DW_OP_GNU_push_tls_address
:
1464 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1466 case DW_OP_GNU_uninit
:
1467 printf ("DW_OP_GNU_uninit");
1468 /* FIXME: Is there data associated with this OP ? */
1470 case DW_OP_GNU_encoded_addr
:
1477 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1479 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1480 print_dwarf_vma (addr
, pointer_size
);
1483 case DW_OP_implicit_pointer
:
1484 case DW_OP_GNU_implicit_pointer
:
1485 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1486 this ought to be an 8-byte wide computation. */
1487 if (dwarf_version
== -1)
1489 printf (_("(%s in frame info)"),
1490 (op
== DW_OP_implicit_pointer
1491 ? "DW_OP_implicit_pointer"
1492 : "DW_OP_GNU_implicit_pointer"));
1493 /* No way to tell where the next op is, so just bail. */
1494 return need_frame_base
;
1496 if (dwarf_version
== 2)
1498 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1502 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1504 READ_SLEB (svalue
, data
, end
);
1505 printf ("%s: <0x%s> %s",
1506 (op
== DW_OP_implicit_pointer
1507 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1508 dwarf_vmatoa ("x", uvalue
),
1509 dwarf_vmatoa ("d", svalue
));
1511 case DW_OP_entry_value
:
1512 case DW_OP_GNU_entry_value
:
1513 READ_ULEB (uvalue
, data
, end
);
1514 /* PR 17531: file: 0cc9cd00. */
1515 if (uvalue
> (dwarf_vma
) (end
- data
))
1516 uvalue
= end
- data
;
1517 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1518 : "DW_OP_GNU_entry_value"));
1519 if (decode_location_expression (data
, pointer_size
, offset_size
,
1520 dwarf_version
, uvalue
,
1521 cu_offset
, section
))
1522 need_frame_base
= 1;
1528 case DW_OP_const_type
:
1529 case DW_OP_GNU_const_type
:
1530 READ_ULEB (uvalue
, data
, end
);
1531 printf ("%s: <0x%s> ",
1532 (op
== DW_OP_const_type
? "DW_OP_const_type"
1533 : "DW_OP_GNU_const_type"),
1534 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1535 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1536 data
= display_block (data
, uvalue
, end
, ' ');
1538 case DW_OP_regval_type
:
1539 case DW_OP_GNU_regval_type
:
1540 READ_ULEB (uvalue
, data
, end
);
1541 printf ("%s: %s (%s)",
1542 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1543 : "DW_OP_GNU_regval_type"),
1544 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1545 READ_ULEB (uvalue
, data
, end
);
1546 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1548 case DW_OP_deref_type
:
1549 case DW_OP_GNU_deref_type
:
1550 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1552 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1553 : "DW_OP_GNU_deref_type"),
1555 READ_ULEB (uvalue
, data
, end
);
1556 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1559 case DW_OP_GNU_convert
:
1560 READ_ULEB (uvalue
, data
, end
);
1561 printf ("%s <0x%s>",
1562 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1563 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1565 case DW_OP_reinterpret
:
1566 case DW_OP_GNU_reinterpret
:
1567 READ_ULEB (uvalue
, data
, end
);
1568 printf ("%s <0x%s>",
1569 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1570 : "DW_OP_GNU_reinterpret"),
1571 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1573 case DW_OP_GNU_parameter_ref
:
1574 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1575 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1576 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1578 case DW_OP_GNU_addr_index
:
1579 READ_ULEB (uvalue
, data
, end
);
1580 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1582 case DW_OP_GNU_const_index
:
1583 READ_ULEB (uvalue
, data
, end
);
1584 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1586 case DW_OP_GNU_variable_value
:
1587 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1588 this ought to be an 8-byte wide computation. */
1589 if (dwarf_version
== -1)
1591 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1592 /* No way to tell where the next op is, so just bail. */
1593 return need_frame_base
;
1595 if (dwarf_version
== 2)
1597 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1601 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1603 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1606 /* HP extensions. */
1607 case DW_OP_HP_is_value
:
1608 printf ("DW_OP_HP_is_value");
1609 /* FIXME: Is there data associated with this OP ? */
1611 case DW_OP_HP_fltconst4
:
1612 printf ("DW_OP_HP_fltconst4");
1613 /* FIXME: Is there data associated with this OP ? */
1615 case DW_OP_HP_fltconst8
:
1616 printf ("DW_OP_HP_fltconst8");
1617 /* FIXME: Is there data associated with this OP ? */
1619 case DW_OP_HP_mod_range
:
1620 printf ("DW_OP_HP_mod_range");
1621 /* FIXME: Is there data associated with this OP ? */
1623 case DW_OP_HP_unmod_range
:
1624 printf ("DW_OP_HP_unmod_range");
1625 /* FIXME: Is there data associated with this OP ? */
1628 printf ("DW_OP_HP_tls");
1629 /* FIXME: Is there data associated with this OP ? */
1632 /* PGI (STMicroelectronics) extensions. */
1633 case DW_OP_PGI_omp_thread_num
:
1634 /* Pushes the thread number for the current thread as it would be
1635 returned by the standard OpenMP library function:
1636 omp_get_thread_num(). The "current thread" is the thread for
1637 which the expression is being evaluated. */
1638 printf ("DW_OP_PGI_omp_thread_num");
1642 if (op
>= DW_OP_lo_user
1643 && op
<= DW_OP_hi_user
)
1644 printf (_("(User defined location op 0x%x)"), op
);
1646 printf (_("(Unknown location op 0x%x)"), op
);
1647 /* No way to tell where the next op is, so just bail. */
1648 return need_frame_base
;
1651 /* Separate the ops. */
1656 return need_frame_base
;
1659 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1660 This is used for DWARF package files. */
1662 static struct cu_tu_set
*
1663 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1665 struct cu_tu_set
*p
;
1667 unsigned int dw_sect
;
1673 dw_sect
= DW_SECT_TYPES
;
1679 dw_sect
= DW_SECT_INFO
;
1683 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1691 /* Add INC to HIGH_BITS:LOW_BITS. */
1693 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1695 dwarf_vma tmp
= * low_bits
;
1699 /* FIXME: There is probably a better way of handling this:
1701 We need to cope with dwarf_vma being a 32-bit or 64-bit
1702 type. Plus regardless of its size LOW_BITS is meant to
1703 only hold 32-bits, so if there is overflow or wrap around
1704 we must propagate into HIGH_BITS. */
1705 if (tmp
< * low_bits
)
1709 else if (sizeof (tmp
) > 8
1720 fetch_alt_indirect_string (dwarf_vma offset
)
1724 if (! do_follow_links
)
1727 if (first_separate_info
== NULL
)
1728 return _("<no links available>");
1730 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1732 struct dwarf_section
* section
;
1735 if (! load_debug_section (separate_debug_str
, i
->handle
))
1738 section
= &debug_displays
[separate_debug_str
].section
;
1740 if (section
->start
== NULL
)
1743 if (offset
>= section
->size
)
1746 ret
= (const char *) (section
->start
+ offset
);
1747 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1748 NUL byte. Since our caller is expecting to receive a well formed C
1749 string we test for the lack of a terminating byte here. */
1750 if (strnlen ((const char *) ret
, section
->size
- offset
)
1751 == section
->size
- offset
)
1752 return _("<no NUL byte at end of alt .debug_str section>");
1757 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1758 dwarf_vmatoa ("x", offset
));
1759 return _("<offset is too big>");
1763 get_AT_name (unsigned long attribute
)
1768 return "DW_AT value: 0";
1770 /* One value is shared by the MIPS and HP extensions: */
1771 if (attribute
== DW_AT_MIPS_fde
)
1772 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1774 name
= get_DW_AT_name (attribute
);
1778 static char buffer
[100];
1780 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1789 add_dwo_info (const char * field
, dwo_type type
)
1791 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1793 dwinfo
->type
= type
;
1794 dwinfo
->value
= field
;
1795 dwinfo
->next
= first_dwo_info
;
1796 first_dwo_info
= dwinfo
;
1800 add_dwo_name (const char * name
)
1802 add_dwo_info (name
, DWO_NAME
);
1806 add_dwo_dir (const char * dir
)
1808 add_dwo_info (dir
, DWO_DIR
);
1812 add_dwo_id (const char * id
)
1814 add_dwo_info (id
, DWO_ID
);
1818 free_dwo_info (void)
1823 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1825 next
= dwinfo
->next
;
1828 first_dwo_info
= NULL
;
1831 /* Ensure that START + UVALUE is less than END.
1832 Return an adjusted UVALUE if necessary to ensure this relationship. */
1834 static inline dwarf_vma
1835 check_uvalue (const unsigned char * start
,
1837 const unsigned char * end
)
1839 dwarf_vma max_uvalue
= end
- start
;
1841 /* See PR 17512: file: 008-103549-0.001:0.1.
1842 and PR 24829 for examples of where these tests are triggered. */
1843 if (uvalue
> max_uvalue
)
1845 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1846 uvalue
= max_uvalue
;
1852 static unsigned char *
1853 skip_attr_bytes (unsigned long form
,
1854 unsigned char * data
,
1855 unsigned const char * end
,
1856 dwarf_vma pointer_size
,
1857 dwarf_vma offset_size
,
1859 dwarf_vma
* value_return
)
1861 dwarf_signed_vma svalue
;
1862 dwarf_vma uvalue
= 0;
1868 case DW_FORM_ref_addr
:
1869 if (dwarf_version
== 2)
1870 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1871 else if (dwarf_version
== 3 || dwarf_version
== 4)
1872 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1878 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1882 case DW_FORM_line_strp
:
1883 case DW_FORM_sec_offset
:
1884 case DW_FORM_GNU_ref_alt
:
1885 case DW_FORM_GNU_strp_alt
:
1886 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1889 case DW_FORM_flag_present
:
1896 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1901 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1906 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1910 READ_SLEB (svalue
, data
, end
);
1914 case DW_FORM_ref_udata
:
1916 case DW_FORM_GNU_str_index
:
1917 case DW_FORM_GNU_addr_index
:
1918 READ_ULEB (uvalue
, data
, end
);
1926 case DW_FORM_data16
:
1930 case DW_FORM_string
:
1931 data
+= strnlen ((char *) data
, end
- data
) + 1;
1935 case DW_FORM_exprloc
:
1936 READ_ULEB (uvalue
, data
, end
);
1939 case DW_FORM_block1
:
1940 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1944 case DW_FORM_block2
:
1945 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1949 case DW_FORM_block4
:
1950 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1954 case DW_FORM_ref_sig8
:
1958 case DW_FORM_indirect
:
1959 /* FIXME: Handle this form. */
1964 * value_return
= uvalue
;
1966 data
= (unsigned char *) end
;
1970 /* Return IS_SIGNED set to TRUE if the type at
1971 DATA can be determined to be a signed type. */
1974 get_type_signedness (unsigned char * start
,
1975 unsigned char * data
,
1976 unsigned const char * end
,
1977 dwarf_vma pointer_size
,
1978 dwarf_vma offset_size
,
1980 bfd_boolean
* is_signed
,
1981 bfd_boolean is_nested
)
1983 unsigned long abbrev_number
;
1984 abbrev_entry
* entry
;
1987 * is_signed
= FALSE
;
1989 READ_ULEB (abbrev_number
, data
, end
);
1991 for (entry
= first_abbrev
;
1992 entry
!= NULL
&& entry
->entry
!= abbrev_number
;
1993 entry
= entry
->next
)
1997 /* FIXME: Issue a warning ? */
2000 for (attr
= entry
->first_attr
;
2001 attr
!= NULL
&& attr
->attribute
;
2004 dwarf_vma uvalue
= 0;
2006 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2007 offset_size
, dwarf_version
, & uvalue
);
2011 switch (attr
->attribute
)
2013 #if 0 /* FIXME: It would be nice to print the name of the type,
2014 but this would mean updating a lot of binutils tests. */
2016 if (attr
->form
== DW_FORM_strp
)
2017 printf ("%s", fetch_indirect_string (uvalue
));
2024 /* FIXME: Warn - or is this expected ?
2025 NB/ We need to avoid infinite recursion. */
2028 if (uvalue
>= (size_t) (end
- start
))
2030 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
2031 offset_size
, dwarf_version
, is_signed
, TRUE
);
2034 case DW_AT_encoding
:
2035 /* Determine signness. */
2038 case DW_ATE_address
:
2039 /* FIXME - some architectures have signed addresses. */
2040 case DW_ATE_boolean
:
2041 case DW_ATE_unsigned
:
2042 case DW_ATE_unsigned_char
:
2043 case DW_ATE_unsigned_fixed
:
2044 * is_signed
= FALSE
;
2048 case DW_ATE_complex_float
:
2051 case DW_ATE_signed_char
:
2052 case DW_ATE_imaginary_float
:
2053 case DW_ATE_decimal_float
:
2054 case DW_ATE_signed_fixed
:
2064 read_and_print_leb128 (unsigned char * data
,
2065 unsigned int * bytes_read
,
2066 unsigned const char * end
,
2067 bfd_boolean is_signed
)
2070 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2072 report_leb_status (status
, __FILE__
, __LINE__
);
2074 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2078 display_discr_list (unsigned long form
,
2080 unsigned char * data
,
2081 unsigned const char * end
,
2086 printf ("[default]");
2093 case DW_FORM_block1
:
2094 case DW_FORM_block2
:
2095 case DW_FORM_block4
:
2096 /* Move data pointer back to the start of the byte array. */
2100 printf ("<corrupt>\n");
2101 warn (_("corrupt discr_list - not using a block form\n"));
2107 printf ("<corrupt>\n");
2108 warn (_("corrupt discr_list - block not long enough\n"));
2112 bfd_boolean is_signed
=
2113 (level
> 0 && level
<= MAX_CU_NESTING
)
2114 ? level_type_signed
[level
- 1] : FALSE
;
2119 unsigned char discriminant
;
2120 unsigned int bytes_read
;
2122 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2126 assert (uvalue
> 0);
2127 switch (discriminant
)
2131 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2132 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2133 uvalue
-= bytes_read
;
2139 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2140 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2141 uvalue
-= bytes_read
;
2145 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2146 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2147 uvalue
-= bytes_read
;
2152 printf ("<corrupt>\n");
2153 warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"),
2163 printf (")(signed)");
2165 printf (")(unsigned)");
2168 static unsigned char *
2169 read_and_display_attr_value (unsigned long attribute
,
2171 dwarf_signed_vma implicit_const
,
2172 unsigned char * start
,
2173 unsigned char * data
,
2174 unsigned char * end
,
2175 dwarf_vma cu_offset
,
2176 dwarf_vma pointer_size
,
2177 dwarf_vma offset_size
,
2179 debug_info
* debug_info_p
,
2181 struct dwarf_section
* section
,
2182 struct cu_tu_set
* this_set
,
2186 dwarf_signed_vma svalue
;
2187 dwarf_vma uvalue
= 0;
2188 unsigned char * block_start
= NULL
;
2189 unsigned char * orig_data
= data
;
2191 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2193 warn (_("Corrupt attribute\n"));
2202 case DW_FORM_ref_addr
:
2203 if (dwarf_version
== 2)
2204 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2205 else if (dwarf_version
== 3 || dwarf_version
== 4)
2206 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2208 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
2213 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2217 case DW_FORM_line_strp
:
2218 case DW_FORM_sec_offset
:
2219 case DW_FORM_GNU_ref_alt
:
2220 case DW_FORM_GNU_strp_alt
:
2221 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2224 case DW_FORM_flag_present
:
2231 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2236 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2241 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2245 READ_SLEB (svalue
, data
, end
);
2249 case DW_FORM_GNU_str_index
:
2250 case DW_FORM_ref_udata
:
2252 case DW_FORM_GNU_addr_index
:
2253 READ_ULEB (uvalue
, data
, end
);
2256 case DW_FORM_indirect
:
2257 READ_ULEB (form
, data
, end
);
2259 printf ("%c%s", delimiter
, get_FORM_name (form
));
2260 if (form
== DW_FORM_implicit_const
)
2261 READ_SLEB (implicit_const
, data
, end
);
2262 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2264 cu_offset
, pointer_size
,
2265 offset_size
, dwarf_version
,
2266 debug_info_p
, do_loc
,
2267 section
, this_set
, delimiter
, level
);
2272 case DW_FORM_ref_addr
:
2274 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2277 case DW_FORM_GNU_ref_alt
:
2279 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2280 /* FIXME: Follow the reference... */
2286 case DW_FORM_ref_udata
:
2288 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2293 case DW_FORM_sec_offset
:
2295 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2298 case DW_FORM_flag_present
:
2305 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2308 case DW_FORM_implicit_const
:
2310 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2317 dwarf_vma high_bits
;
2321 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2323 if (form
== DW_FORM_ref8
)
2324 add64 (& high_bits
, & utmp
, cu_offset
);
2325 printf ("%c0x%s", delimiter
,
2326 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2329 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2330 && num_debug_info_entries
== 0)
2332 if (sizeof (uvalue
) == 8)
2333 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2335 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2341 case DW_FORM_data16
:
2344 dwarf_vma left_high_bits
, left_low_bits
;
2345 dwarf_vma right_high_bits
, right_low_bits
;
2347 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2348 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2349 if (byte_get
== byte_get_little_endian
)
2352 left_high_bits
^= right_high_bits
;
2353 right_high_bits
^= left_high_bits
;
2354 left_high_bits
^= right_high_bits
;
2355 left_low_bits
^= right_low_bits
;
2356 right_low_bits
^= left_low_bits
;
2357 left_low_bits
^= right_low_bits
;
2359 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2360 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2361 left_high_bits
, left_low_bits
, right_high_bits
,
2367 case DW_FORM_string
:
2369 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2370 data
+= strnlen ((char *) data
, end
- data
) + 1;
2374 case DW_FORM_exprloc
:
2375 READ_ULEB (uvalue
, data
, end
);
2378 if (block_start
>= end
)
2380 warn (_("Block ends prematurely\n"));
2385 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2388 data
= block_start
+ uvalue
;
2390 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2393 case DW_FORM_block1
:
2394 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2397 case DW_FORM_block2
:
2398 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2401 case DW_FORM_block4
:
2402 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2407 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2408 dwarf_vmatoa ("x", uvalue
),
2409 fetch_indirect_string (uvalue
));
2412 case DW_FORM_line_strp
:
2414 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2415 dwarf_vmatoa ("x", uvalue
),
2416 fetch_indirect_line_string (uvalue
));
2419 case DW_FORM_GNU_str_index
:
2422 const char * suffix
= strrchr (section
->name
, '.');
2423 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
2425 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2426 dwarf_vmatoa ("x", uvalue
),
2427 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2431 case DW_FORM_GNU_strp_alt
:
2434 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2435 dwarf_vmatoa ("x", uvalue
),
2436 fetch_alt_indirect_string (uvalue
));
2440 case DW_FORM_indirect
:
2441 /* Handled above. */
2444 case DW_FORM_ref_sig8
:
2447 dwarf_vma high_bits
;
2450 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2451 printf ("%csignature: 0x%s", delimiter
,
2452 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2457 case DW_FORM_GNU_addr_index
:
2459 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2460 dwarf_vmatoa ("x", uvalue
),
2461 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2465 warn (_("Unrecognized form: %lu\n"), form
);
2469 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2470 && num_debug_info_entries
== 0
2471 && debug_info_p
!= NULL
)
2475 case DW_AT_frame_base
:
2476 have_frame_base
= 1;
2478 case DW_AT_location
:
2479 case DW_AT_GNU_locviews
:
2480 case DW_AT_string_length
:
2481 case DW_AT_return_addr
:
2482 case DW_AT_data_member_location
:
2483 case DW_AT_vtable_elem_location
:
2485 case DW_AT_static_link
:
2486 case DW_AT_use_location
:
2487 case DW_AT_call_value
:
2488 case DW_AT_GNU_call_site_value
:
2489 case DW_AT_call_data_value
:
2490 case DW_AT_GNU_call_site_data_value
:
2491 case DW_AT_call_target
:
2492 case DW_AT_GNU_call_site_target
:
2493 case DW_AT_call_target_clobbered
:
2494 case DW_AT_GNU_call_site_target_clobbered
:
2495 if ((dwarf_version
< 4
2496 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2497 || form
== DW_FORM_sec_offset
)
2499 /* Process location list. */
2500 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2501 unsigned int num
= debug_info_p
->num_loc_offsets
;
2503 if (lmax
== 0 || num
>= lmax
)
2506 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2507 xcrealloc (debug_info_p
->loc_offsets
,
2508 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2509 debug_info_p
->loc_views
= (dwarf_vma
*)
2510 xcrealloc (debug_info_p
->loc_views
,
2511 lmax
, sizeof (*debug_info_p
->loc_views
));
2512 debug_info_p
->have_frame_base
= (int *)
2513 xcrealloc (debug_info_p
->have_frame_base
,
2514 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2515 debug_info_p
->max_loc_offsets
= lmax
;
2517 if (this_set
!= NULL
)
2518 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2519 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2520 if (attribute
!= DW_AT_GNU_locviews
)
2522 /* Corrupt DWARF info can produce more offsets than views.
2523 See PR 23062 for an example. */
2524 if (debug_info_p
->num_loc_offsets
2525 > debug_info_p
->num_loc_views
)
2526 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2529 debug_info_p
->loc_offsets
[num
] = uvalue
;
2530 debug_info_p
->num_loc_offsets
++;
2535 assert (debug_info_p
->num_loc_views
<= num
);
2536 num
= debug_info_p
->num_loc_views
;
2537 if (num
> debug_info_p
->num_loc_offsets
)
2538 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2541 debug_info_p
->loc_views
[num
] = uvalue
;
2542 debug_info_p
->num_loc_views
++;
2549 if (need_base_address
)
2550 debug_info_p
->base_address
= uvalue
;
2553 case DW_AT_GNU_addr_base
:
2554 debug_info_p
->addr_base
= uvalue
;
2557 case DW_AT_GNU_ranges_base
:
2558 debug_info_p
->ranges_base
= uvalue
;
2562 if ((dwarf_version
< 4
2563 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2564 || form
== DW_FORM_sec_offset
)
2566 /* Process range list. */
2567 unsigned int lmax
= debug_info_p
->max_range_lists
;
2568 unsigned int num
= debug_info_p
->num_range_lists
;
2570 if (lmax
== 0 || num
>= lmax
)
2573 debug_info_p
->range_lists
= (dwarf_vma
*)
2574 xcrealloc (debug_info_p
->range_lists
,
2575 lmax
, sizeof (*debug_info_p
->range_lists
));
2576 debug_info_p
->max_range_lists
= lmax
;
2578 debug_info_p
->range_lists
[num
] = uvalue
;
2579 debug_info_p
->num_range_lists
++;
2583 case DW_AT_GNU_dwo_name
:
2584 case DW_AT_dwo_name
:
2589 add_dwo_name ((const char *) fetch_indirect_string (uvalue
));
2591 case DW_FORM_GNU_strp_alt
:
2592 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
));
2594 case DW_FORM_GNU_str_index
:
2595 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2597 case DW_FORM_string
:
2598 add_dwo_name ((const char *) orig_data
);
2601 warn (_("Unsupported form (%s) for attribute %s\n"),
2602 get_FORM_name (form
), get_AT_name (attribute
));
2607 case DW_AT_comp_dir
:
2608 /* FIXME: Also extract a build-id in a CU/TU. */
2613 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
));
2615 case DW_FORM_GNU_strp_alt
:
2616 add_dwo_dir (fetch_alt_indirect_string (uvalue
));
2618 case DW_FORM_line_strp
:
2619 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
));
2621 case DW_FORM_GNU_str_index
:
2622 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2624 case DW_FORM_string
:
2625 add_dwo_dir ((const char *) orig_data
);
2628 warn (_("Unsupported form (%s) for attribute %s\n"),
2629 get_FORM_name (form
), get_AT_name (attribute
));
2634 case DW_AT_GNU_dwo_id
:
2639 /* FIXME: Record the length of the ID as well ? */
2640 add_dwo_id ((const char *) (data
- 8));
2643 warn (_("Unsupported form (%s) for attribute %s\n"),
2644 get_FORM_name (form
), get_AT_name (attribute
));
2654 if (do_loc
|| attribute
== 0)
2657 /* For some attributes we can display further information. */
2661 if (level
>= 0 && level
< MAX_CU_NESTING
2662 && uvalue
< (size_t) (end
- start
))
2664 bfd_boolean is_signed
= FALSE
;
2666 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
2667 offset_size
, dwarf_version
, & is_signed
, FALSE
);
2668 level_type_signed
[level
] = is_signed
;
2676 case DW_INL_not_inlined
:
2677 printf (_("(not inlined)"));
2679 case DW_INL_inlined
:
2680 printf (_("(inlined)"));
2682 case DW_INL_declared_not_inlined
:
2683 printf (_("(declared as inline but ignored)"));
2685 case DW_INL_declared_inlined
:
2686 printf (_("(declared as inline and inlined)"));
2689 printf (_(" (Unknown inline attribute value: %s)"),
2690 dwarf_vmatoa ("x", uvalue
));
2695 case DW_AT_language
:
2699 /* Ordered by the numeric value of these constants. */
2700 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2701 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2702 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2703 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2704 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2705 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2706 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2707 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2708 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2709 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2710 /* DWARF 2.1 values. */
2711 case DW_LANG_Java
: printf ("(Java)"); break;
2712 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2713 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2714 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2715 /* DWARF 3 values. */
2716 case DW_LANG_PLI
: printf ("(PLI)"); break;
2717 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2718 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2719 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2720 case DW_LANG_D
: printf ("(D)"); break;
2721 /* DWARF 4 values. */
2722 case DW_LANG_Python
: printf ("(Python)"); break;
2723 /* DWARF 5 values. */
2724 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
2725 case DW_LANG_Go
: printf ("(Go)"); break;
2726 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
2727 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
2728 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
2729 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2730 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
2731 case DW_LANG_Rust
: printf ("(Rust)"); break;
2732 case DW_LANG_C11
: printf ("(C11)"); break;
2733 case DW_LANG_Swift
: printf ("(Swift)"); break;
2734 case DW_LANG_Julia
: printf ("(Julia)"); break;
2735 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
2736 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2737 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2738 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2739 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
2740 /* MIPS extension. */
2741 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2742 /* UPC extension. */
2743 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2745 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2746 printf (_("(implementation defined: %s)"),
2747 dwarf_vmatoa ("x", uvalue
));
2749 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2754 case DW_AT_encoding
:
2758 case DW_ATE_void
: printf ("(void)"); break;
2759 case DW_ATE_address
: printf ("(machine address)"); break;
2760 case DW_ATE_boolean
: printf ("(boolean)"); break;
2761 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2762 case DW_ATE_float
: printf ("(float)"); break;
2763 case DW_ATE_signed
: printf ("(signed)"); break;
2764 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2765 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2766 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2767 /* DWARF 2.1 values: */
2768 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2769 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2770 /* DWARF 3 values: */
2771 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2772 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2773 case DW_ATE_edited
: printf ("(edited)"); break;
2774 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2775 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2776 /* DWARF 4 values: */
2777 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2778 /* DWARF 5 values: */
2779 case DW_ATE_UCS
: printf ("(UCS)"); break;
2780 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
2782 /* HP extensions: */
2783 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2784 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2785 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2786 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2787 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2788 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2789 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2792 if (uvalue
>= DW_ATE_lo_user
2793 && uvalue
<= DW_ATE_hi_user
)
2794 printf (_("(user defined type)"));
2796 printf (_("(unknown type)"));
2801 case DW_AT_accessibility
:
2805 case DW_ACCESS_public
: printf ("(public)"); break;
2806 case DW_ACCESS_protected
: printf ("(protected)"); break;
2807 case DW_ACCESS_private
: printf ("(private)"); break;
2809 printf (_("(unknown accessibility)"));
2814 case DW_AT_visibility
:
2818 case DW_VIS_local
: printf ("(local)"); break;
2819 case DW_VIS_exported
: printf ("(exported)"); break;
2820 case DW_VIS_qualified
: printf ("(qualified)"); break;
2821 default: printf (_("(unknown visibility)")); break;
2825 case DW_AT_endianity
:
2829 case DW_END_default
: printf ("(default)"); break;
2830 case DW_END_big
: printf ("(big)"); break;
2831 case DW_END_little
: printf ("(little)"); break;
2833 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
2834 printf (_("(user specified)"));
2836 printf (_("(unknown endianity)"));
2841 case DW_AT_virtuality
:
2845 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2846 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2847 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2848 default: printf (_("(unknown virtuality)")); break;
2852 case DW_AT_identifier_case
:
2856 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2857 case DW_ID_up_case
: printf ("(up_case)"); break;
2858 case DW_ID_down_case
: printf ("(down_case)"); break;
2859 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2860 default: printf (_("(unknown case)")); break;
2864 case DW_AT_calling_convention
:
2868 case DW_CC_normal
: printf ("(normal)"); break;
2869 case DW_CC_program
: printf ("(program)"); break;
2870 case DW_CC_nocall
: printf ("(nocall)"); break;
2871 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
2872 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
2873 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
2874 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
2876 if (uvalue
>= DW_CC_lo_user
2877 && uvalue
<= DW_CC_hi_user
)
2878 printf (_("(user defined)"));
2880 printf (_("(unknown convention)"));
2884 case DW_AT_ordering
:
2889 case -1: printf (_("(undefined)")); break;
2890 case 0: printf ("(row major)"); break;
2891 case 1: printf ("(column major)"); break;
2895 case DW_AT_decimal_sign
:
2899 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
2900 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
2901 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
2902 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
2903 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
2904 default: printf (_("(unrecognised)")); break;
2908 case DW_AT_defaulted
:
2912 case DW_DEFAULTED_no
: printf (_("(no)")); break;
2913 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
2914 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
2915 default: printf (_("(unrecognised)")); break;
2919 case DW_AT_discr_list
:
2921 display_discr_list (form
, uvalue
, data
, end
, level
);
2924 case DW_AT_frame_base
:
2925 have_frame_base
= 1;
2927 case DW_AT_location
:
2928 case DW_AT_string_length
:
2929 case DW_AT_return_addr
:
2930 case DW_AT_data_member_location
:
2931 case DW_AT_vtable_elem_location
:
2933 case DW_AT_static_link
:
2934 case DW_AT_use_location
:
2935 case DW_AT_call_value
:
2936 case DW_AT_GNU_call_site_value
:
2937 case DW_AT_call_data_value
:
2938 case DW_AT_GNU_call_site_data_value
:
2939 case DW_AT_call_target
:
2940 case DW_AT_GNU_call_site_target
:
2941 case DW_AT_call_target_clobbered
:
2942 case DW_AT_GNU_call_site_target_clobbered
:
2943 if ((dwarf_version
< 4
2944 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2945 || form
== DW_FORM_sec_offset
)
2946 printf (_(" (location list)"));
2948 case DW_AT_allocated
:
2949 case DW_AT_associated
:
2950 case DW_AT_data_location
:
2952 case DW_AT_upper_bound
:
2953 case DW_AT_lower_bound
:
2956 int need_frame_base
;
2959 need_frame_base
= decode_location_expression (block_start
,
2964 cu_offset
, section
);
2966 if (need_frame_base
&& !have_frame_base
)
2967 printf (_(" [without DW_AT_frame_base]"));
2971 case DW_AT_data_bit_offset
:
2972 case DW_AT_byte_size
:
2973 case DW_AT_bit_size
:
2974 case DW_AT_string_length_byte_size
:
2975 case DW_AT_string_length_bit_size
:
2976 case DW_AT_bit_stride
:
2977 if (form
== DW_FORM_exprloc
)
2980 (void) decode_location_expression (block_start
, pointer_size
,
2981 offset_size
, dwarf_version
,
2982 uvalue
, cu_offset
, section
);
2989 if (form
== DW_FORM_ref_sig8
2990 || form
== DW_FORM_GNU_ref_alt
)
2993 if (form
== DW_FORM_ref1
2994 || form
== DW_FORM_ref2
2995 || form
== DW_FORM_ref4
2996 || form
== DW_FORM_ref_udata
)
2997 uvalue
+= cu_offset
;
2999 if (uvalue
>= section
->size
)
3000 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3001 dwarf_vmatoa ("x", uvalue
),
3002 (unsigned long) (orig_data
- section
->start
));
3005 unsigned long abbrev_number
;
3006 abbrev_entry
*entry
;
3007 unsigned char *p
= section
->start
+ uvalue
;
3009 READ_ULEB (abbrev_number
, p
, end
);
3011 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3012 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
3013 use different abbrev table, and we don't track .debug_info chunks
3015 if (form
!= DW_FORM_ref_addr
)
3017 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3018 if (entry
->entry
== abbrev_number
)
3021 printf (" (%s)", get_TAG_name (entry
->tag
));
3035 static unsigned char *
3036 read_and_display_attr (unsigned long attribute
,
3038 dwarf_signed_vma implicit_const
,
3039 unsigned char * start
,
3040 unsigned char * data
,
3041 unsigned char * end
,
3042 dwarf_vma cu_offset
,
3043 dwarf_vma pointer_size
,
3044 dwarf_vma offset_size
,
3046 debug_info
* debug_info_p
,
3048 struct dwarf_section
* section
,
3049 struct cu_tu_set
* this_set
,
3053 printf (" %-18s:", get_AT_name (attribute
));
3054 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3056 cu_offset
, pointer_size
, offset_size
,
3057 dwarf_version
, debug_info_p
,
3058 do_loc
, section
, this_set
, ' ', level
);
3064 /* Like load_debug_section, but if the ordinary call fails, and we are
3065 following debug links, then attempt to load the requested section
3066 from one of the separate debug info files. */
3069 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3072 if (load_debug_section (sec_enum
, handle
))
3074 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3076 /* See if we can associate a filename with this section. */
3079 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3080 if (i
->handle
== handle
)
3082 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3090 if (do_follow_links
)
3094 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3096 if (load_debug_section (sec_enum
, i
->handle
))
3098 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3100 /* FIXME: We should check to see if any of the remaining debug info
3101 files also contain this section, and, umm, do something about it. */
3111 introduce (struct dwarf_section
* section
, bfd_boolean raw
)
3115 if (do_follow_links
&& section
->filename
)
3116 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3117 section
->name
, section
->filename
);
3119 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3123 if (do_follow_links
&& section
->filename
)
3124 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3125 section
->name
, section
->filename
);
3127 printf (_("Contents of the %s section:\n\n"), section
->name
);
3131 /* Process the contents of a .debug_info section.
3132 If do_loc is TRUE then we are scanning for location lists and dwo tags
3133 and we do not want to display anything to the user.
3134 If do_types is TRUE, we are processing a .debug_types section instead of
3135 a .debug_info section.
3136 The information displayed is restricted by the values in DWARF_START_DIE
3137 and DWARF_CUTOFF_LEVEL.
3138 Returns TRUE upon success. Otherwise an error or warning message is
3139 printed and FALSE is returned. */
3142 process_debug_info (struct dwarf_section
* section
,
3144 enum dwarf_section_display_enum abbrev_sec
,
3146 bfd_boolean do_types
)
3148 unsigned char *start
= section
->start
;
3149 unsigned char *end
= start
+ section
->size
;
3150 unsigned char *section_begin
;
3152 unsigned int num_units
= 0;
3154 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3155 && num_debug_info_entries
== 0
3160 /* First scan the section to get the number of comp units. */
3161 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3164 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3165 will be the length. For a 64-bit DWARF section, it'll be
3166 the escape code 0xffffffff followed by an 8 byte length. */
3167 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3169 if (length
== 0xffffffff)
3171 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3172 section_begin
+= length
+ 12;
3174 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3176 warn (_("Reserved length value (0x%s) found in section %s\n"),
3177 dwarf_vmatoa ("x", length
), section
->name
);
3181 section_begin
+= length
+ 4;
3183 /* Negative values are illegal, they may even cause infinite
3184 looping. This can happen if we can't accurately apply
3185 relocations to an object file, or if the file is corrupt. */
3186 if ((signed long) length
<= 0 || section_begin
< start
)
3188 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3189 dwarf_vmatoa ("x", length
), section
->name
);
3196 error (_("No comp units in %s section ?\n"), section
->name
);
3200 /* Then allocate an array to hold the information. */
3201 debug_information
= (debug_info
*) cmalloc (num_units
,
3202 sizeof (* debug_information
));
3203 if (debug_information
== NULL
)
3205 error (_("Not enough memory for a debug info array of %u entries\n"),
3207 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3211 /* PR 17531: file: 92ca3797.
3212 We cannot rely upon the debug_information array being initialised
3213 before it is used. A corrupt file could easily contain references
3214 to a unit for which information has not been made available. So
3215 we ensure that the array is zeroed here. */
3216 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3218 alloc_num_debug_info_entries
= num_units
;
3223 load_debug_section_with_follow (str
, file
);
3224 load_debug_section_with_follow (line_str
, file
);
3225 load_debug_section_with_follow (str_dwo
, file
);
3226 load_debug_section_with_follow (str_index
, file
);
3227 load_debug_section_with_follow (str_index_dwo
, file
);
3228 load_debug_section_with_follow (debug_addr
, file
);
3231 load_debug_section_with_follow (abbrev_sec
, file
);
3232 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3234 warn (_("Unable to locate %s section!\n"),
3235 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3239 if (!do_loc
&& dwarf_start_die
== 0)
3240 introduce (section
, FALSE
);
3242 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
3244 DWARF2_Internal_CompUnit compunit
;
3245 unsigned char *hdrptr
;
3246 unsigned char *tags
;
3247 int level
, last_level
, saved_level
;
3248 dwarf_vma cu_offset
;
3249 unsigned long sec_off
;
3250 unsigned int offset_size
;
3251 unsigned int initial_length_size
;
3252 dwarf_vma signature_high
= 0;
3253 dwarf_vma signature_low
= 0;
3254 dwarf_vma type_offset
= 0;
3255 struct cu_tu_set
*this_set
;
3256 dwarf_vma abbrev_base
;
3261 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3263 if (compunit
.cu_length
== 0xffffffff)
3265 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3267 initial_length_size
= 12;
3272 initial_length_size
= 4;
3275 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3277 cu_offset
= start
- section_begin
;
3279 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3281 if (compunit
.cu_version
< 5)
3283 compunit
.cu_unit_type
= DW_UT_compile
;
3284 /* Initialize it due to a false compiler warning. */
3285 compunit
.cu_pointer_size
= -1;
3289 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3290 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3292 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3295 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3297 if (this_set
== NULL
)
3300 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3304 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3305 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3308 if (compunit
.cu_version
< 5)
3309 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3311 /* PR 17512: file: 001-108546-0.001:0.1. */
3312 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3314 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3315 compunit
.cu_pointer_size
, offset_size
);
3316 compunit
.cu_pointer_size
= offset_size
;
3321 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3323 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3326 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3327 + initial_length_size
))
3329 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3330 + initial_length_size
;
3334 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3335 && num_debug_info_entries
== 0
3336 && alloc_num_debug_info_entries
> unit
3339 debug_information
[unit
].cu_offset
= cu_offset
;
3340 debug_information
[unit
].pointer_size
3341 = compunit
.cu_pointer_size
;
3342 debug_information
[unit
].offset_size
= offset_size
;
3343 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3344 debug_information
[unit
].base_address
= 0;
3345 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3346 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3347 debug_information
[unit
].loc_offsets
= NULL
;
3348 debug_information
[unit
].have_frame_base
= NULL
;
3349 debug_information
[unit
].max_loc_offsets
= 0;
3350 debug_information
[unit
].num_loc_offsets
= 0;
3351 debug_information
[unit
].range_lists
= NULL
;
3352 debug_information
[unit
].max_range_lists
= 0;
3353 debug_information
[unit
].num_range_lists
= 0;
3356 if (!do_loc
&& dwarf_start_die
== 0)
3358 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3359 dwarf_vmatoa ("x", cu_offset
));
3360 printf (_(" Length: 0x%s (%s)\n"),
3361 dwarf_vmatoa ("x", compunit
.cu_length
),
3362 offset_size
== 8 ? "64-bit" : "32-bit");
3363 printf (_(" Version: %d\n"), compunit
.cu_version
);
3364 printf (_(" Abbrev Offset: 0x%s\n"),
3365 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3366 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3371 printf (_(" Signature: 0x%s\n"),
3372 dwarf_vmatoa64 (signature_high
, signature_low
,
3373 buf
, sizeof (buf
)));
3374 printf (_(" Type Offset: 0x%s\n"),
3375 dwarf_vmatoa ("x", type_offset
));
3377 if (this_set
!= NULL
)
3379 dwarf_vma
*offsets
= this_set
->section_offsets
;
3380 size_t *sizes
= this_set
->section_sizes
;
3382 printf (_(" Section contributions:\n"));
3383 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3384 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3385 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3386 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3387 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3388 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3389 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3390 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3391 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3392 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3393 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3394 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3398 sec_off
= cu_offset
+ initial_length_size
;
3399 if (sec_off
+ compunit
.cu_length
< sec_off
3400 || sec_off
+ compunit
.cu_length
> section
->size
)
3402 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3404 (unsigned long) cu_offset
,
3405 dwarf_vmatoa ("x", compunit
.cu_length
));
3411 start
+= compunit
.cu_length
+ initial_length_size
;
3413 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3415 warn (_("CU at offset %s contains corrupt or "
3416 "unsupported version number: %d.\n"),
3417 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3421 if (compunit
.cu_unit_type
!= DW_UT_compile
3422 && compunit
.cu_unit_type
!= DW_UT_type
)
3424 warn (_("CU at offset %s contains corrupt or "
3425 "unsupported unit type: %d.\n"),
3426 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3432 /* Process the abbrevs used by this compilation unit. */
3433 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3434 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3435 (unsigned long) compunit
.cu_abbrev_offset
,
3436 (unsigned long) abbrev_size
);
3437 /* PR 17531: file:4bcd9ce9. */
3438 else if ((abbrev_base
+ abbrev_size
)
3439 > debug_displays
[abbrev_sec
].section
.size
)
3440 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3441 (unsigned long) abbrev_base
+ abbrev_size
,
3442 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3444 process_abbrev_section
3445 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3446 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3447 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3448 + abbrev_base
+ abbrev_size
));
3453 while (tags
< start
)
3455 unsigned long abbrev_number
;
3456 unsigned long die_offset
;
3457 abbrev_entry
*entry
;
3459 int do_printing
= 1;
3461 die_offset
= tags
- section_begin
;
3463 READ_ULEB (abbrev_number
, tags
, start
);
3465 /* A null DIE marks the end of a list of siblings or it may also be
3466 a section padding. */
3467 if (abbrev_number
== 0)
3469 /* Check if it can be a section padding for the last CU. */
3470 if (level
== 0 && start
== end
)
3474 for (chk
= tags
; chk
< start
; chk
++)
3481 if (!do_loc
&& die_offset
>= dwarf_start_die
3482 && (dwarf_cutoff_level
== -1
3483 || level
< dwarf_cutoff_level
))
3484 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3490 static unsigned num_bogus_warns
= 0;
3492 if (num_bogus_warns
< 3)
3494 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3495 die_offset
, section
->name
);
3497 if (num_bogus_warns
== 3)
3498 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3501 if (dwarf_start_die
!= 0 && level
< saved_level
)
3508 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3512 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3513 saved_level
= level
;
3514 do_printing
= (dwarf_cutoff_level
== -1
3515 || level
< dwarf_cutoff_level
);
3517 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3518 level
, die_offset
, abbrev_number
);
3519 else if (dwarf_cutoff_level
== -1
3520 || last_level
< dwarf_cutoff_level
)
3521 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3526 /* Scan through the abbreviation list until we reach the
3528 for (entry
= first_abbrev
;
3529 entry
&& entry
->entry
!= abbrev_number
;
3530 entry
= entry
->next
)
3535 if (!do_loc
&& do_printing
)
3540 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3541 die_offset
, abbrev_number
);
3545 if (!do_loc
&& do_printing
)
3546 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3551 need_base_address
= 0;
3553 case DW_TAG_compile_unit
:
3554 need_base_address
= 1;
3555 need_dwo_info
= do_loc
;
3557 case DW_TAG_entry_point
:
3558 case DW_TAG_subprogram
:
3559 need_base_address
= 0;
3560 /* Assuming that there is no DW_AT_frame_base. */
3561 have_frame_base
= 0;
3565 debug_info
*debug_info_p
=
3566 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3567 ? debug_information
+ unit
: NULL
;
3569 assert (!debug_info_p
3570 || (debug_info_p
->num_loc_offsets
3571 == debug_info_p
->num_loc_views
));
3573 for (attr
= entry
->first_attr
;
3574 attr
&& attr
->attribute
;
3577 if (! do_loc
&& do_printing
)
3578 /* Show the offset from where the tag was extracted. */
3579 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3580 tags
= read_and_display_attr (attr
->attribute
,
3582 attr
->implicit_const
,
3587 compunit
.cu_pointer_size
,
3589 compunit
.cu_version
,
3591 do_loc
|| ! do_printing
,
3597 /* If a locview attribute appears before a location one,
3598 make sure we don't associate it with an earlier
3601 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3604 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3605 debug_info_p
->num_loc_views
++;
3606 assert (debug_info_p
->num_loc_views
3607 == debug_info_p
->num_loc_offsets
);
3614 warn(_("DIE has locviews without loclist\n"));
3615 debug_info_p
->num_loc_views
--;
3622 if (entry
->children
)
3627 /* Set num_debug_info_entries here so that it can be used to check if
3628 we need to process .debug_loc and .debug_ranges sections. */
3629 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3630 && num_debug_info_entries
== 0
3633 if (num_units
> alloc_num_debug_info_entries
)
3634 num_debug_info_entries
= alloc_num_debug_info_entries
;
3636 num_debug_info_entries
= num_units
;
3645 /* Locate and scan the .debug_info section in the file and record the pointer
3646 sizes and offsets for the compilation units in it. Usually an executable
3647 will have just one pointer size, but this is not guaranteed, and so we try
3648 not to make any assumptions. Returns zero upon failure, or the number of
3649 compilation units upon success. */
3652 load_debug_info (void * file
)
3654 /* If we have already tried and failed to load the .debug_info
3655 section then do not bother to repeat the task. */
3656 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3659 /* If we already have the information there is nothing else to do. */
3660 if (num_debug_info_entries
> 0)
3661 return num_debug_info_entries
;
3663 /* If this is a DWARF package file, load the CU and TU indexes. */
3664 (void) load_cu_tu_indexes (file
);
3666 if (load_debug_section_with_follow (info
, file
)
3667 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
3668 return num_debug_info_entries
;
3670 if (load_debug_section_with_follow (info_dwo
, file
)
3671 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3672 abbrev_dwo
, TRUE
, FALSE
))
3673 return num_debug_info_entries
;
3675 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3679 /* Read a DWARF .debug_line section header starting at DATA.
3680 Upon success returns an updated DATA pointer and the LINFO
3681 structure and the END_OF_SEQUENCE pointer will be filled in.
3682 Otherwise returns NULL. */
3684 static unsigned char *
3685 read_debug_line_header (struct dwarf_section
* section
,
3686 unsigned char * data
,
3687 unsigned char * end
,
3688 DWARF2_Internal_LineInfo
* linfo
,
3689 unsigned char ** end_of_sequence
)
3691 unsigned char *hdrptr
;
3692 unsigned int initial_length_size
;
3694 /* Extract information from the Line Number Program Header.
3695 (section 6.2.4 in the Dwarf3 doc). */
3698 /* Get and check the length of the block. */
3699 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
3701 if (linfo
->li_length
== 0xffffffff)
3703 /* This section is 64-bit DWARF 3. */
3704 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
3705 linfo
->li_offset_size
= 8;
3706 initial_length_size
= 12;
3710 linfo
->li_offset_size
= 4;
3711 initial_length_size
= 4;
3714 if (linfo
->li_length
+ initial_length_size
> section
->size
)
3716 /* If the length field has a relocation against it, then we should
3717 not complain if it is inaccurate (and probably negative). This
3718 happens in object files when the .debug_line section is actually
3719 comprised of several different .debug_line.* sections, (some of
3720 which may be removed by linker garbage collection), and a relocation
3721 is used to compute the correct length once that is done. */
3722 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
3724 linfo
->li_length
= (end
- data
) - initial_length_size
;
3728 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3729 (long) linfo
->li_length
);
3734 /* Get and check the version number. */
3735 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
3737 if (linfo
->li_version
!= 2
3738 && linfo
->li_version
!= 3
3739 && linfo
->li_version
!= 4
3740 && linfo
->li_version
!= 5)
3742 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3743 "is currently supported.\n"));
3747 if (linfo
->li_version
>= 5)
3749 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
3751 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
3752 if (linfo
->li_segment_size
!= 0)
3754 warn (_("The %s section contains "
3755 "unsupported segment selector size: %d.\n"),
3756 section
->name
, linfo
->li_segment_size
);
3761 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
3762 linfo
->li_offset_size
, end
);
3763 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
3765 if (linfo
->li_version
>= 4)
3767 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
3769 if (linfo
->li_max_ops_per_insn
== 0)
3771 warn (_("Invalid maximum operations per insn.\n"));
3776 linfo
->li_max_ops_per_insn
= 1;
3778 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
3779 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
3780 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
3781 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
3783 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
3784 /* PR 17512: file:002-117414-0.004. */
3785 if (* end_of_sequence
> end
)
3787 warn (_("Line length %s extends beyond end of section\n"),
3788 dwarf_vmatoa ("u", linfo
->li_length
));
3789 * end_of_sequence
= end
;
3796 static unsigned char *
3797 display_formatted_table (unsigned char * data
,
3798 unsigned char * start
,
3799 unsigned char * end
,
3800 const DWARF2_Internal_LineInfo
* linfo
,
3801 struct dwarf_section
* section
,
3804 unsigned char *format_start
, format_count
, *format
, formati
;
3805 dwarf_vma data_count
, datai
;
3806 unsigned int namepass
, last_entry
= 0;
3807 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
3809 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3810 if (do_checks
&& format_count
> 5)
3811 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
3812 table_name
, format_count
);
3814 format_start
= data
;
3815 for (formati
= 0; formati
< format_count
; formati
++)
3817 SKIP_ULEB (data
, end
);
3818 SKIP_ULEB (data
, end
);
3821 warn (_("%s: Corrupt format description entry\n"), table_name
);
3826 READ_ULEB (data_count
, data
, end
);
3827 if (data_count
== 0)
3829 printf (_("\n The %s is empty.\n"), table_name
);
3832 else if (data
== end
)
3834 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
3835 table_name
, dwarf_vmatoa ("x", data_count
));
3839 else if (format_count
== 0)
3841 warn (_("%s: format count is zero, but the table is not empty\n"),
3846 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
3847 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
3850 printf (_(" Entry"));
3851 /* Delay displaying name as the last entry for better screen layout. */
3852 for (namepass
= 0; namepass
< 2; namepass
++)
3854 format
= format_start
;
3855 for (formati
= 0; formati
< format_count
; formati
++)
3857 dwarf_vma content_type
;
3859 READ_ULEB (content_type
, format
, end
);
3860 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
3861 switch (content_type
)
3864 printf (_("\tName"));
3866 case DW_LNCT_directory_index
:
3867 printf (_("\tDir"));
3869 case DW_LNCT_timestamp
:
3870 printf (_("\tTime"));
3873 printf (_("\tSize"));
3876 printf (_("\tMD5\t\t\t"));
3879 printf (_("\t(Unknown format content type %s)"),
3880 dwarf_vmatoa ("u", content_type
));
3882 SKIP_ULEB (format
, end
);
3887 for (datai
= 0; datai
< data_count
; datai
++)
3889 unsigned char *datapass
= data
;
3891 printf (" %d", last_entry
++);
3892 /* Delay displaying name as the last entry for better screen layout. */
3893 for (namepass
= 0; namepass
< 2; namepass
++)
3895 format
= format_start
;
3897 for (formati
= 0; formati
< format_count
; formati
++)
3899 dwarf_vma content_type
, form
;
3901 READ_ULEB (content_type
, format
, end
);
3902 READ_ULEB (form
, format
, end
);
3903 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
3904 0, 0, linfo
->li_offset_size
,
3905 linfo
->li_version
, NULL
,
3906 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3907 section
, NULL
, '\t', -1);
3911 if (data
== end
&& (datai
< data_count
- 1))
3913 warn (_("\n%s: Corrupt entries list\n"), table_name
);
3922 display_debug_lines_raw (struct dwarf_section
* section
,
3923 unsigned char * data
,
3924 unsigned char * end
,
3927 unsigned char *start
= section
->start
;
3928 int verbose_view
= 0;
3930 introduce (section
, TRUE
);
3934 static DWARF2_Internal_LineInfo saved_linfo
;
3935 DWARF2_Internal_LineInfo linfo
;
3936 unsigned char *standard_opcodes
;
3937 unsigned char *end_of_sequence
;
3940 if (const_strneq (section
->name
, ".debug_line.")
3941 /* Note: the following does not apply to .debug_line.dwo sections.
3942 These are full debug_line sections. */
3943 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3945 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3946 section containing just the Line Number Statements. They are
3947 created by the assembler and intended to be used alongside gcc's
3948 -ffunction-sections command line option. When the linker's
3949 garbage collection decides to discard a .text.<foo> section it
3950 can then also discard the line number information in .debug_line.<foo>.
3952 Since the section is a fragment it does not have the details
3953 needed to fill out a LineInfo structure, so instead we use the
3954 details from the last full debug_line section that we processed. */
3955 end_of_sequence
= end
;
3956 standard_opcodes
= NULL
;
3957 linfo
= saved_linfo
;
3958 /* PR 17531: file: 0522b371. */
3959 if (linfo
.li_line_range
== 0)
3961 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3964 reset_state_machine (linfo
.li_default_is_stmt
);
3968 unsigned char * hdrptr
;
3970 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3971 & end_of_sequence
)) == NULL
)
3974 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
3975 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
3976 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
3977 if (linfo
.li_version
>= 5)
3979 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
3980 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
3982 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
3983 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
3984 if (linfo
.li_version
>= 4)
3985 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
3986 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
3987 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
3988 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
3989 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
3991 /* PR 17512: file: 1665-6428-0.004. */
3992 if (linfo
.li_line_range
== 0)
3994 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3995 linfo
.li_line_range
= 1;
3998 reset_state_machine (linfo
.li_default_is_stmt
);
4000 /* Display the contents of the Opcodes table. */
4001 standard_opcodes
= hdrptr
;
4003 /* PR 17512: file: 002-417945-0.004. */
4004 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4006 warn (_("Line Base extends beyond end of section\n"));
4010 printf (_("\n Opcodes:\n"));
4012 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4013 printf (ngettext (" Opcode %d has %d arg\n",
4014 " Opcode %d has %d args\n",
4015 standard_opcodes
[i
- 1]),
4016 i
, standard_opcodes
[i
- 1]);
4018 /* Display the contents of the Directory table. */
4019 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4021 if (linfo
.li_version
>= 5)
4023 load_debug_section_with_follow (line_str
, file
);
4025 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4027 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4033 printf (_("\n The Directory Table is empty.\n"));
4036 unsigned int last_dir_entry
= 0;
4038 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4039 (long)(data
- start
));
4041 while (data
< end
&& *data
!= 0)
4043 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4045 data
+= strnlen ((char *) data
, end
- data
) + 1;
4048 /* PR 17512: file: 002-132094-0.004. */
4049 if (data
>= end
- 1)
4053 /* Skip the NUL at the end of the table. */
4056 /* Display the contents of the File Name table. */
4058 printf (_("\n The File Name Table is empty.\n"));
4061 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4062 (long)(data
- start
));
4063 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4065 while (data
< end
&& *data
!= 0)
4067 unsigned char *name
;
4070 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4072 data
+= strnlen ((char *) data
, end
- data
) + 1;
4074 READ_ULEB (val
, data
, end
);
4075 printf ("%s\t", dwarf_vmatoa ("u", val
));
4076 READ_ULEB (val
, data
, end
);
4077 printf ("%s\t", dwarf_vmatoa ("u", val
));
4078 READ_ULEB (val
, data
, end
);
4079 printf ("%s\t", dwarf_vmatoa ("u", val
));
4080 printf ("%.*s\n", (int)(end
- name
), name
);
4084 warn (_("Corrupt file name table entry\n"));
4090 /* Skip the NUL at the end of the table. */
4095 saved_linfo
= linfo
;
4098 /* Now display the statements. */
4099 if (data
>= end_of_sequence
)
4100 printf (_(" No Line Number Statements.\n"));
4103 printf (_(" Line Number Statements:\n"));
4105 while (data
< end_of_sequence
)
4107 unsigned char op_code
;
4108 dwarf_signed_vma adv
;
4111 printf (" [0x%08lx]", (long)(data
- start
));
4115 if (op_code
>= linfo
.li_opcode_base
)
4117 op_code
-= linfo
.li_opcode_base
;
4118 uladv
= (op_code
/ linfo
.li_line_range
);
4119 if (linfo
.li_max_ops_per_insn
== 1)
4121 uladv
*= linfo
.li_min_insn_length
;
4122 state_machine_regs
.address
+= uladv
;
4124 state_machine_regs
.view
= 0;
4125 printf (_(" Special opcode %d: "
4126 "advance Address by %s to 0x%s%s"),
4127 op_code
, dwarf_vmatoa ("u", uladv
),
4128 dwarf_vmatoa ("x", state_machine_regs
.address
),
4129 verbose_view
&& uladv
4130 ? _(" (reset view)") : "");
4135 = ((state_machine_regs
.op_index
+ uladv
)
4136 / linfo
.li_max_ops_per_insn
)
4137 * linfo
.li_min_insn_length
;
4139 state_machine_regs
.address
+= addrdelta
;
4140 state_machine_regs
.op_index
4141 = (state_machine_regs
.op_index
+ uladv
)
4142 % linfo
.li_max_ops_per_insn
;
4144 state_machine_regs
.view
= 0;
4145 printf (_(" Special opcode %d: "
4146 "advance Address by %s to 0x%s[%d]%s"),
4147 op_code
, dwarf_vmatoa ("u", uladv
),
4148 dwarf_vmatoa ("x", state_machine_regs
.address
),
4149 state_machine_regs
.op_index
,
4150 verbose_view
&& addrdelta
4151 ? _(" (reset view)") : "");
4153 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4154 state_machine_regs
.line
+= adv
;
4155 printf (_(" and Line by %s to %d"),
4156 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4157 if (verbose_view
|| state_machine_regs
.view
)
4158 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4161 state_machine_regs
.view
++;
4166 case DW_LNS_extended_op
:
4167 data
+= process_extended_line_op (data
,
4168 linfo
.li_default_is_stmt
,
4173 printf (_(" Copy"));
4174 if (verbose_view
|| state_machine_regs
.view
)
4175 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4178 state_machine_regs
.view
++;
4181 case DW_LNS_advance_pc
:
4182 READ_ULEB (uladv
, data
, end
);
4183 if (linfo
.li_max_ops_per_insn
== 1)
4185 uladv
*= linfo
.li_min_insn_length
;
4186 state_machine_regs
.address
+= uladv
;
4188 state_machine_regs
.view
= 0;
4189 printf (_(" Advance PC by %s to 0x%s%s\n"),
4190 dwarf_vmatoa ("u", uladv
),
4191 dwarf_vmatoa ("x", state_machine_regs
.address
),
4192 verbose_view
&& uladv
4193 ? _(" (reset view)") : "");
4198 = ((state_machine_regs
.op_index
+ uladv
)
4199 / linfo
.li_max_ops_per_insn
)
4200 * linfo
.li_min_insn_length
;
4201 state_machine_regs
.address
4203 state_machine_regs
.op_index
4204 = (state_machine_regs
.op_index
+ uladv
)
4205 % linfo
.li_max_ops_per_insn
;
4207 state_machine_regs
.view
= 0;
4208 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4209 dwarf_vmatoa ("u", uladv
),
4210 dwarf_vmatoa ("x", state_machine_regs
.address
),
4211 state_machine_regs
.op_index
,
4212 verbose_view
&& addrdelta
4213 ? _(" (reset view)") : "");
4217 case DW_LNS_advance_line
:
4218 READ_SLEB (adv
, data
, end
);
4219 state_machine_regs
.line
+= adv
;
4220 printf (_(" Advance Line by %s to %d\n"),
4221 dwarf_vmatoa ("d", adv
),
4222 state_machine_regs
.line
);
4225 case DW_LNS_set_file
:
4226 READ_ULEB (uladv
, data
, end
);
4227 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4228 dwarf_vmatoa ("u", uladv
));
4229 state_machine_regs
.file
= uladv
;
4232 case DW_LNS_set_column
:
4233 READ_ULEB (uladv
, data
, end
);
4234 printf (_(" Set column to %s\n"),
4235 dwarf_vmatoa ("u", uladv
));
4236 state_machine_regs
.column
= uladv
;
4239 case DW_LNS_negate_stmt
:
4240 adv
= state_machine_regs
.is_stmt
;
4242 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4243 state_machine_regs
.is_stmt
= adv
;
4246 case DW_LNS_set_basic_block
:
4247 printf (_(" Set basic block\n"));
4248 state_machine_regs
.basic_block
= 1;
4251 case DW_LNS_const_add_pc
:
4252 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4253 if (linfo
.li_max_ops_per_insn
)
4255 uladv
*= linfo
.li_min_insn_length
;
4256 state_machine_regs
.address
+= uladv
;
4258 state_machine_regs
.view
= 0;
4259 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4260 dwarf_vmatoa ("u", uladv
),
4261 dwarf_vmatoa ("x", state_machine_regs
.address
),
4262 verbose_view
&& uladv
4263 ? _(" (reset view)") : "");
4268 = ((state_machine_regs
.op_index
+ uladv
)
4269 / linfo
.li_max_ops_per_insn
)
4270 * linfo
.li_min_insn_length
;
4271 state_machine_regs
.address
4273 state_machine_regs
.op_index
4274 = (state_machine_regs
.op_index
+ uladv
)
4275 % linfo
.li_max_ops_per_insn
;
4277 state_machine_regs
.view
= 0;
4278 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4279 dwarf_vmatoa ("u", uladv
),
4280 dwarf_vmatoa ("x", state_machine_regs
.address
),
4281 state_machine_regs
.op_index
,
4282 verbose_view
&& addrdelta
4283 ? _(" (reset view)") : "");
4287 case DW_LNS_fixed_advance_pc
:
4288 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4289 state_machine_regs
.address
+= uladv
;
4290 state_machine_regs
.op_index
= 0;
4291 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4292 dwarf_vmatoa ("u", uladv
),
4293 dwarf_vmatoa ("x", state_machine_regs
.address
));
4294 /* Do NOT reset view. */
4297 case DW_LNS_set_prologue_end
:
4298 printf (_(" Set prologue_end to true\n"));
4301 case DW_LNS_set_epilogue_begin
:
4302 printf (_(" Set epilogue_begin to true\n"));
4305 case DW_LNS_set_isa
:
4306 READ_ULEB (uladv
, data
, end
);
4307 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4311 printf (_(" Unknown opcode %d with operands: "), op_code
);
4313 if (standard_opcodes
!= NULL
)
4314 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4316 READ_ULEB (uladv
, data
, end
);
4317 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4318 i
== 1 ? "" : ", ");
4333 unsigned char *name
;
4334 unsigned int directory_index
;
4335 unsigned int modification_date
;
4336 unsigned int length
;
4339 /* Output a decoded representation of the .debug_line section. */
4342 display_debug_lines_decoded (struct dwarf_section
* section
,
4343 unsigned char * start
,
4344 unsigned char * data
,
4345 unsigned char * end
,
4348 static DWARF2_Internal_LineInfo saved_linfo
;
4350 introduce (section
, FALSE
);
4354 /* This loop amounts to one iteration per compilation unit. */
4355 DWARF2_Internal_LineInfo linfo
;
4356 unsigned char *standard_opcodes
;
4357 unsigned char *end_of_sequence
;
4359 File_Entry
*file_table
= NULL
;
4360 unsigned int n_files
= 0;
4361 unsigned char **directory_table
= NULL
;
4362 dwarf_vma n_directories
= 0;
4364 if (const_strneq (section
->name
, ".debug_line.")
4365 /* Note: the following does not apply to .debug_line.dwo sections.
4366 These are full debug_line sections. */
4367 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4369 /* See comment in display_debug_lines_raw(). */
4370 end_of_sequence
= end
;
4371 standard_opcodes
= NULL
;
4372 linfo
= saved_linfo
;
4373 /* PR 17531: file: 0522b371. */
4374 if (linfo
.li_line_range
== 0)
4376 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4379 reset_state_machine (linfo
.li_default_is_stmt
);
4383 unsigned char *hdrptr
;
4385 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4386 & end_of_sequence
)) == NULL
)
4389 /* PR 17531: file: 0522b371. */
4390 if (linfo
.li_line_range
== 0)
4392 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4393 linfo
.li_line_range
= 1;
4395 reset_state_machine (linfo
.li_default_is_stmt
);
4397 /* Save a pointer to the contents of the Opcodes table. */
4398 standard_opcodes
= hdrptr
;
4400 /* Traverse the Directory table just to count entries. */
4401 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4405 warn (_("opcode base of %d extends beyond end of section\n"),
4406 linfo
.li_opcode_base
);
4410 if (linfo
.li_version
>= 5)
4412 unsigned char *format_start
, format_count
, *format
;
4413 dwarf_vma formati
, entryi
;
4415 load_debug_section_with_follow (line_str
, fileptr
);
4417 /* Skip directories format. */
4418 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4419 if (do_checks
&& format_count
> 1)
4420 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4422 format_start
= data
;
4423 for (formati
= 0; formati
< format_count
; formati
++)
4425 SKIP_ULEB (data
, end
);
4426 SKIP_ULEB (data
, end
);
4429 READ_ULEB (n_directories
, data
, end
);
4432 warn (_("Corrupt directories list\n"));
4436 if (n_directories
== 0)
4437 directory_table
= NULL
;
4439 directory_table
= (unsigned char **)
4440 xmalloc (n_directories
* sizeof (unsigned char *));
4442 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4444 unsigned char **pathp
= &directory_table
[entryi
];
4446 format
= format_start
;
4447 for (formati
= 0; formati
< format_count
; formati
++)
4449 dwarf_vma content_type
, form
;
4452 READ_ULEB (content_type
, format
, end
);
4453 READ_ULEB (form
, format
, end
);
4456 warn (_("Corrupt directories list\n"));
4459 switch (content_type
)
4464 case DW_FORM_string
:
4467 case DW_FORM_line_strp
:
4468 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4470 /* Remove const by the cast. */
4471 *pathp
= (unsigned char *)
4472 fetch_indirect_line_string (uvalue
);
4477 data
= read_and_display_attr_value (0, form
, 0, start
,
4479 linfo
.li_offset_size
,
4486 warn (_("Corrupt directories list\n"));
4491 /* Skip files format. */
4492 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4493 if (do_checks
&& format_count
> 5)
4494 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
4496 format_start
= data
;
4497 for (formati
= 0; formati
< format_count
; formati
++)
4499 SKIP_ULEB (data
, end
);
4500 SKIP_ULEB (data
, end
);
4503 READ_ULEB (n_files
, data
, end
);
4504 if (data
== end
&& n_files
> 0)
4506 warn (_("Corrupt file name list\n"));
4513 file_table
= (File_Entry
*) xcalloc (1, n_files
4514 * sizeof (File_Entry
));
4516 for (entryi
= 0; entryi
< n_files
; entryi
++)
4518 File_Entry
*file
= &file_table
[entryi
];
4520 format
= format_start
;
4521 for (formati
= 0; formati
< format_count
; formati
++)
4523 dwarf_vma content_type
, form
;
4527 READ_ULEB (content_type
, format
, end
);
4528 READ_ULEB (form
, format
, end
);
4531 warn (_("Corrupt file name list\n"));
4534 switch (content_type
)
4539 case DW_FORM_string
:
4542 case DW_FORM_line_strp
:
4543 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4545 /* Remove const by the cast. */
4546 file
->name
= (unsigned char *)
4547 fetch_indirect_line_string (uvalue
);
4551 case DW_LNCT_directory_index
:
4555 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4559 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4564 READ_ULEB (file
->directory_index
, tmp
, end
);
4569 data
= read_and_display_attr_value (0, form
, 0, start
,
4571 linfo
.li_offset_size
,
4578 warn (_("Corrupt file name list\n"));
4587 unsigned char *ptr_directory_table
= data
;
4589 while (data
< end
&& *data
!= 0)
4591 data
+= strnlen ((char *) data
, end
- data
) + 1;
4598 warn (_("directory table ends unexpectedly\n"));
4603 /* Go through the directory table again to save the directories. */
4604 directory_table
= (unsigned char **)
4605 xmalloc (n_directories
* sizeof (unsigned char *));
4608 while (*ptr_directory_table
!= 0)
4610 directory_table
[i
] = ptr_directory_table
;
4611 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
4612 ptr_directory_table
- end
) + 1;
4616 /* Skip the NUL at the end of the table. */
4619 /* Traverse the File Name table just to count the entries. */
4620 if (data
< end
&& *data
!= 0)
4622 unsigned char *ptr_file_name_table
= data
;
4624 while (data
< end
&& *data
!= 0)
4626 /* Skip Name, directory index, last modification
4627 time and length of file. */
4628 data
+= strnlen ((char *) data
, end
- data
) + 1;
4629 SKIP_ULEB (data
, end
);
4630 SKIP_ULEB (data
, end
);
4631 SKIP_ULEB (data
, end
);
4637 warn (_("file table ends unexpectedly\n"));
4642 /* Go through the file table again to save the strings. */
4643 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
4646 while (*ptr_file_name_table
!= 0)
4648 file_table
[i
].name
= ptr_file_name_table
;
4649 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
4650 end
- ptr_file_name_table
) + 1;
4652 /* We are not interested in directory, time or size. */
4653 READ_ULEB (file_table
[i
].directory_index
,
4654 ptr_file_name_table
, end
);
4655 READ_ULEB (file_table
[i
].modification_date
,
4656 ptr_file_name_table
, end
);
4657 READ_ULEB (file_table
[i
].length
,
4658 ptr_file_name_table
, end
);
4664 /* Skip the NUL at the end of the table. */
4668 /* Print the Compilation Unit's name and a header. */
4669 if (file_table
== NULL
)
4670 printf (_("CU: No directory table\n"));
4671 else if (directory_table
== NULL
)
4672 printf (_("CU: %s:\n"), file_table
[0].name
);
4675 unsigned int ix
= file_table
[0].directory_index
;
4676 const char *directory
;
4681 else if (n_directories
== 0)
4682 directory
= _("<unknown>");
4683 else if (ix
> n_directories
)
4685 warn (_("directory index %u > number of directories %s\n"),
4686 ix
, dwarf_vmatoa ("u", n_directories
));
4687 directory
= _("<corrupt>");
4690 directory
= (char *) directory_table
[ix
- 1];
4692 if (do_wide
|| strlen (directory
) < 76)
4693 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
4695 printf ("%s:\n", file_table
[0].name
);
4699 printf (_("File name Line number Starting address View Stmt\n"));
4701 printf (_("CU: Empty file name table\n"));
4702 saved_linfo
= linfo
;
4705 /* This loop iterates through the Dwarf Line Number Program. */
4706 while (data
< end_of_sequence
)
4708 unsigned char op_code
;
4711 unsigned long int uladv
;
4712 int is_special_opcode
= 0;
4717 if (op_code
>= linfo
.li_opcode_base
)
4719 op_code
-= linfo
.li_opcode_base
;
4720 uladv
= (op_code
/ linfo
.li_line_range
);
4721 if (linfo
.li_max_ops_per_insn
== 1)
4723 uladv
*= linfo
.li_min_insn_length
;
4724 state_machine_regs
.address
+= uladv
;
4726 state_machine_regs
.view
= 0;
4731 = ((state_machine_regs
.op_index
+ uladv
)
4732 / linfo
.li_max_ops_per_insn
)
4733 * linfo
.li_min_insn_length
;
4734 state_machine_regs
.address
4736 state_machine_regs
.op_index
4737 = (state_machine_regs
.op_index
+ uladv
)
4738 % linfo
.li_max_ops_per_insn
;
4740 state_machine_regs
.view
= 0;
4743 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4744 state_machine_regs
.line
+= adv
;
4745 is_special_opcode
= 1;
4746 /* Increment view after printing this row. */
4751 case DW_LNS_extended_op
:
4753 unsigned int ext_op_code_len
;
4754 unsigned char ext_op_code
;
4755 unsigned char *op_code_end
;
4756 unsigned char *op_code_data
= data
;
4758 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
4759 op_code_end
= op_code_data
+ ext_op_code_len
;
4760 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
4762 warn (_("Badly formed extended line op encountered!\n"));
4765 ext_op_code
= *op_code_data
++;
4769 switch (ext_op_code
)
4771 case DW_LNE_end_sequence
:
4772 /* Reset stuff after printing this row. */
4774 case DW_LNE_set_address
:
4775 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
4777 op_code_end
- op_code_data
,
4779 state_machine_regs
.op_index
= 0;
4780 state_machine_regs
.view
= 0;
4782 case DW_LNE_define_file
:
4783 file_table
= (File_Entry
*) xrealloc
4784 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
4786 ++state_machine_regs
.last_file_entry
;
4787 /* Source file name. */
4788 file_table
[n_files
].name
= op_code_data
;
4789 op_code_data
+= strlen ((char *) op_code_data
) + 1;
4790 /* Directory index. */
4791 READ_ULEB (file_table
[n_files
].directory_index
,
4792 op_code_data
, op_code_end
);
4793 /* Last modification time. */
4794 READ_ULEB (file_table
[n_files
].modification_date
,
4795 op_code_data
, op_code_end
);
4797 READ_ULEB (file_table
[n_files
].length
,
4798 op_code_data
, op_code_end
);
4802 case DW_LNE_set_discriminator
:
4803 case DW_LNE_HP_set_sequence
:
4804 /* Simply ignored. */
4808 printf (_("UNKNOWN (%u): length %ld\n"),
4809 ext_op_code
, (long int) (op_code_data
- data
));
4816 /* Increment view after printing this row. */
4819 case DW_LNS_advance_pc
:
4820 READ_ULEB (uladv
, data
, end
);
4821 if (linfo
.li_max_ops_per_insn
== 1)
4823 uladv
*= linfo
.li_min_insn_length
;
4824 state_machine_regs
.address
+= uladv
;
4826 state_machine_regs
.view
= 0;
4831 = ((state_machine_regs
.op_index
+ uladv
)
4832 / linfo
.li_max_ops_per_insn
)
4833 * linfo
.li_min_insn_length
;
4834 state_machine_regs
.address
4836 state_machine_regs
.op_index
4837 = (state_machine_regs
.op_index
+ uladv
)
4838 % linfo
.li_max_ops_per_insn
;
4840 state_machine_regs
.view
= 0;
4844 case DW_LNS_advance_line
:
4845 READ_SLEB (adv
, data
, end
);
4846 state_machine_regs
.line
+= adv
;
4849 case DW_LNS_set_file
:
4850 READ_ULEB (uladv
, data
, end
);
4851 state_machine_regs
.file
= uladv
;
4854 unsigned file
= state_machine_regs
.file
- 1;
4857 if (file_table
== NULL
|| n_files
== 0)
4858 printf (_("\n [Use file table entry %d]\n"), file
);
4860 else if (file
>= n_files
)
4862 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
4863 printf (_("\n <over large file table index %u>"), file
);
4865 else if ((dir
= file_table
[file
].directory_index
) == 0)
4866 /* If directory index is 0, that means current directory. */
4867 printf ("\n./%s:[++]\n", file_table
[file
].name
);
4868 else if (directory_table
== NULL
|| n_directories
== 0)
4869 printf (_("\n [Use file %s in directory table entry %d]\n"),
4870 file_table
[file
].name
, dir
);
4872 else if (dir
> n_directories
)
4874 warn (_("directory index %u > number of directories %s\n"),
4875 dir
, dwarf_vmatoa ("u", n_directories
));
4876 printf (_("\n <over large directory table entry %u>\n"), dir
);
4879 printf ("\n%s/%s:\n",
4880 /* The directory index starts counting at 1. */
4881 directory_table
[dir
- 1], file_table
[file
].name
);
4885 case DW_LNS_set_column
:
4886 READ_ULEB (uladv
, data
, end
);
4887 state_machine_regs
.column
= uladv
;
4890 case DW_LNS_negate_stmt
:
4891 adv
= state_machine_regs
.is_stmt
;
4893 state_machine_regs
.is_stmt
= adv
;
4896 case DW_LNS_set_basic_block
:
4897 state_machine_regs
.basic_block
= 1;
4900 case DW_LNS_const_add_pc
:
4901 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4902 if (linfo
.li_max_ops_per_insn
== 1)
4904 uladv
*= linfo
.li_min_insn_length
;
4905 state_machine_regs
.address
+= uladv
;
4907 state_machine_regs
.view
= 0;
4912 = ((state_machine_regs
.op_index
+ uladv
)
4913 / linfo
.li_max_ops_per_insn
)
4914 * linfo
.li_min_insn_length
;
4915 state_machine_regs
.address
4917 state_machine_regs
.op_index
4918 = (state_machine_regs
.op_index
+ uladv
)
4919 % linfo
.li_max_ops_per_insn
;
4921 state_machine_regs
.view
= 0;
4925 case DW_LNS_fixed_advance_pc
:
4926 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4927 state_machine_regs
.address
+= uladv
;
4928 state_machine_regs
.op_index
= 0;
4929 /* Do NOT reset view. */
4932 case DW_LNS_set_prologue_end
:
4935 case DW_LNS_set_epilogue_begin
:
4938 case DW_LNS_set_isa
:
4939 READ_ULEB (uladv
, data
, end
);
4940 printf (_(" Set ISA to %lu\n"), uladv
);
4944 printf (_(" Unknown opcode %d with operands: "), op_code
);
4946 if (standard_opcodes
!= NULL
)
4947 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4951 READ_ULEB (val
, data
, end
);
4952 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
4953 i
== 1 ? "" : ", ");
4959 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4960 to the DWARF address/line matrix. */
4961 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
4962 || (xop
== DW_LNS_copy
))
4964 const unsigned int MAX_FILENAME_LENGTH
= 35;
4966 char *newFileName
= NULL
;
4967 size_t fileNameLength
;
4971 unsigned indx
= state_machine_regs
.file
- 1;
4973 if (indx
>= n_files
)
4975 warn (_("corrupt file index %u encountered\n"), indx
);
4976 fileName
= _("<corrupt>");
4979 fileName
= (char *) file_table
[indx
].name
;
4982 fileName
= _("<unknown>");
4984 fileNameLength
= strlen (fileName
);
4986 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
4988 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
4989 /* Truncate file name */
4990 strncpy (newFileName
,
4991 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
4992 MAX_FILENAME_LENGTH
+ 1);
4993 /* FIXME: This is to pacify gcc-10 which can warn that the
4994 strncpy above might leave a non-NUL terminated string
4995 in newFileName. It won't, but gcc's analysis doesn't
4996 quite go far enough to discover this. */
4997 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5001 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5002 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5005 /* A row with end_seq set to true has a meaningful address, but
5006 the other information in the same row is not significant.
5007 In such a row, print line as "-", and don't print
5009 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5011 if (linfo
.li_max_ops_per_insn
== 1)
5013 if (xop
== -DW_LNE_end_sequence
)
5014 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5016 state_machine_regs
.address
);
5018 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5019 newFileName
, state_machine_regs
.line
,
5020 state_machine_regs
.address
);
5024 if (xop
== -DW_LNE_end_sequence
)
5025 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5027 state_machine_regs
.address
,
5028 state_machine_regs
.op_index
);
5030 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5031 newFileName
, state_machine_regs
.line
,
5032 state_machine_regs
.address
,
5033 state_machine_regs
.op_index
);
5038 if (linfo
.li_max_ops_per_insn
== 1)
5040 if (xop
== -DW_LNE_end_sequence
)
5041 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5043 state_machine_regs
.address
);
5045 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5046 newFileName
, state_machine_regs
.line
,
5047 state_machine_regs
.address
);
5051 if (xop
== -DW_LNE_end_sequence
)
5052 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5054 state_machine_regs
.address
,
5055 state_machine_regs
.op_index
);
5057 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5058 newFileName
, state_machine_regs
.line
,
5059 state_machine_regs
.address
,
5060 state_machine_regs
.op_index
);
5064 if (xop
!= -DW_LNE_end_sequence
)
5066 if (state_machine_regs
.view
)
5067 printf (" %6u", state_machine_regs
.view
);
5071 if (state_machine_regs
.is_stmt
)
5076 state_machine_regs
.view
++;
5078 if (xop
== -DW_LNE_end_sequence
)
5080 reset_state_machine (linfo
.li_default_is_stmt
);
5095 if (directory_table
)
5097 free (directory_table
);
5098 directory_table
= NULL
;
5109 display_debug_lines (struct dwarf_section
*section
, void *file
)
5111 unsigned char *data
= section
->start
;
5112 unsigned char *end
= data
+ section
->size
;
5114 int retValDecoded
= 1;
5116 if (do_debug_lines
== 0)
5117 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5119 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5120 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5122 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5123 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5125 if (!retValRaw
|| !retValDecoded
)
5132 find_debug_info_for_offset (unsigned long offset
)
5136 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5139 for (i
= 0; i
< num_debug_info_entries
; i
++)
5140 if (debug_information
[i
].cu_offset
== offset
)
5141 return debug_information
+ i
;
5147 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5149 /* See gdb/gdb-index.h. */
5150 static const char * const kinds
[] =
5162 return _ (kinds
[kind
]);
5166 display_debug_pubnames_worker (struct dwarf_section
*section
,
5167 void *file ATTRIBUTE_UNUSED
,
5170 DWARF2_Internal_PubNames names
;
5171 unsigned char *start
= section
->start
;
5172 unsigned char *end
= start
+ section
->size
;
5174 /* It does not matter if this load fails,
5175 we test for that later on. */
5176 load_debug_info (file
);
5178 introduce (section
, FALSE
);
5182 unsigned char *data
;
5183 unsigned long sec_off
;
5184 unsigned int offset_size
, initial_length_size
;
5186 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5187 if (names
.pn_length
== 0xffffffff)
5189 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5191 initial_length_size
= 12;
5196 initial_length_size
= 4;
5199 sec_off
= start
- section
->start
;
5200 if (sec_off
+ names
.pn_length
< sec_off
5201 || sec_off
+ names
.pn_length
> section
->size
)
5203 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5205 sec_off
- initial_length_size
,
5206 dwarf_vmatoa ("x", names
.pn_length
));
5211 start
+= names
.pn_length
;
5213 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5214 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5216 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5217 && num_debug_info_entries
> 0
5218 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5219 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5220 (unsigned long) names
.pn_offset
, section
->name
);
5222 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5224 printf (_(" Length: %ld\n"),
5225 (long) names
.pn_length
);
5226 printf (_(" Version: %d\n"),
5228 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5229 (unsigned long) names
.pn_offset
);
5230 printf (_(" Size of area in .debug_info section: %ld\n"),
5231 (long) names
.pn_size
);
5233 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5235 static int warned
= 0;
5239 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5247 printf (_("\n Offset Kind Name\n"));
5249 printf (_("\n Offset\tName\n"));
5253 bfd_size_type maxprint
;
5256 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5261 data
+= offset_size
;
5264 maxprint
= (end
- data
) - 1;
5268 unsigned int kind_data
;
5269 gdb_index_symbol_kind kind
;
5270 const char *kind_name
;
5273 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5276 /* GCC computes the kind as the upper byte in the CU index
5277 word, and then right shifts it by the CU index size.
5278 Left shift KIND to where the gdb-index.h accessor macros
5280 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5281 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5282 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5283 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5284 printf (" %-6lx %s,%-10s %.*s\n",
5285 (unsigned long) offset
, is_static
? _("s") : _("g"),
5286 kind_name
, (int) maxprint
, data
);
5289 printf (" %-6lx\t%.*s\n",
5290 (unsigned long) offset
, (int) maxprint
, data
);
5292 data
+= strnlen ((char *) data
, maxprint
) + 1;
5303 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5305 return display_debug_pubnames_worker (section
, file
, 0);
5309 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5311 return display_debug_pubnames_worker (section
, file
, 1);
5315 display_debug_macinfo (struct dwarf_section
*section
,
5316 void *file ATTRIBUTE_UNUSED
)
5318 unsigned char *start
= section
->start
;
5319 unsigned char *end
= start
+ section
->size
;
5320 unsigned char *curr
= start
;
5321 enum dwarf_macinfo_record_type op
;
5323 introduce (section
, FALSE
);
5327 unsigned int lineno
;
5328 const unsigned char *string
;
5330 op
= (enum dwarf_macinfo_record_type
) *curr
;
5335 case DW_MACINFO_start_file
:
5337 unsigned int filenum
;
5339 READ_ULEB (lineno
, curr
, end
);
5340 READ_ULEB (filenum
, curr
, end
);
5341 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5346 case DW_MACINFO_end_file
:
5347 printf (_(" DW_MACINFO_end_file\n"));
5350 case DW_MACINFO_define
:
5351 READ_ULEB (lineno
, curr
, end
);
5353 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5354 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5358 case DW_MACINFO_undef
:
5359 READ_ULEB (lineno
, curr
, end
);
5361 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5362 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5366 case DW_MACINFO_vendor_ext
:
5368 unsigned int constant
;
5370 READ_ULEB (constant
, curr
, end
);
5372 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5373 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5383 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5384 filename and dirname corresponding to file name table entry with index
5385 FILEIDX. Return NULL on failure. */
5387 static unsigned char *
5388 get_line_filename_and_dirname (dwarf_vma line_offset
,
5390 unsigned char **dir_name
)
5392 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5393 unsigned char *hdrptr
, *dirtable
, *file_name
;
5394 unsigned int offset_size
, initial_length_size
;
5395 unsigned int version
, opcode_base
;
5396 dwarf_vma length
, diridx
;
5397 const unsigned char * end
;
5400 if (section
->start
== NULL
5401 || line_offset
>= section
->size
5405 hdrptr
= section
->start
+ line_offset
;
5406 end
= section
->start
+ section
->size
;
5408 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5409 if (length
== 0xffffffff)
5411 /* This section is 64-bit DWARF 3. */
5412 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5414 initial_length_size
= 12;
5419 initial_length_size
= 4;
5421 if (length
+ initial_length_size
< length
5422 || length
+ initial_length_size
> section
->size
)
5425 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5426 if (version
!= 2 && version
!= 3 && version
!= 4)
5428 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5430 hdrptr
++; /* Skip max_ops_per_insn. */
5431 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5433 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5434 if (opcode_base
== 0)
5437 hdrptr
+= opcode_base
- 1;
5442 /* Skip over dirname table. */
5443 while (*hdrptr
!= '\0')
5445 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5449 hdrptr
++; /* Skip the NUL at the end of the table. */
5451 /* Now skip over preceding filename table entries. */
5452 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5454 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5455 SKIP_ULEB (hdrptr
, end
);
5456 SKIP_ULEB (hdrptr
, end
);
5457 SKIP_ULEB (hdrptr
, end
);
5459 if (hdrptr
>= end
|| *hdrptr
== '\0')
5463 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5466 READ_ULEB (diridx
, hdrptr
, end
);
5469 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5470 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5471 if (dirtable
>= end
|| *dirtable
== '\0')
5473 *dir_name
= dirtable
;
5478 display_debug_macro (struct dwarf_section
*section
,
5481 unsigned char *start
= section
->start
;
5482 unsigned char *end
= start
+ section
->size
;
5483 unsigned char *curr
= start
;
5484 unsigned char *extended_op_buf
[256];
5486 load_debug_section_with_follow (str
, file
);
5487 load_debug_section_with_follow (line
, file
);
5488 load_debug_section_with_follow (str_index
, file
);
5490 introduce (section
, FALSE
);
5494 unsigned int lineno
, version
, flags
;
5495 unsigned int offset_size
= 4;
5496 const unsigned char *string
;
5497 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5498 unsigned char **extended_ops
= NULL
;
5500 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5501 if (version
!= 4 && version
!= 5)
5503 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5508 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5511 printf (_(" Offset: 0x%lx\n"),
5512 (unsigned long) sec_offset
);
5513 printf (_(" Version: %d\n"), version
);
5514 printf (_(" Offset size: %d\n"), offset_size
);
5517 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5518 printf (_(" Offset into .debug_line: 0x%lx\n"),
5519 (unsigned long) line_offset
);
5523 unsigned int i
, count
, op
;
5526 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5528 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5529 extended_ops
= extended_op_buf
;
5532 printf (_(" Extension opcode arguments:\n"));
5533 for (i
= 0; i
< count
; i
++)
5535 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5536 extended_ops
[op
] = curr
;
5537 READ_ULEB (nargs
, curr
, end
);
5539 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5542 printf (_(" DW_MACRO_%02x arguments: "), op
);
5543 for (n
= 0; n
< nargs
; n
++)
5547 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5548 printf ("%s%s", get_FORM_name (form
),
5549 n
== nargs
- 1 ? "\n" : ", ");
5559 case DW_FORM_block1
:
5560 case DW_FORM_block2
:
5561 case DW_FORM_block4
:
5563 case DW_FORM_string
:
5565 case DW_FORM_sec_offset
:
5568 error (_("Invalid extension opcode form %s\n"),
5569 get_FORM_name (form
));
5585 error (_(".debug_macro section not zero terminated\n"));
5589 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5595 case DW_MACRO_define
:
5596 READ_ULEB (lineno
, curr
, end
);
5598 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5599 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5603 case DW_MACRO_undef
:
5604 READ_ULEB (lineno
, curr
, end
);
5606 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5607 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5611 case DW_MACRO_start_file
:
5613 unsigned int filenum
;
5614 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
5616 READ_ULEB (lineno
, curr
, end
);
5617 READ_ULEB (filenum
, curr
, end
);
5619 if ((flags
& 2) == 0)
5620 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5623 = get_line_filename_and_dirname (line_offset
, filenum
,
5625 if (file_name
== NULL
)
5626 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5629 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5631 dir_name
!= NULL
? (const char *) dir_name
: "",
5632 dir_name
!= NULL
? "/" : "", file_name
);
5636 case DW_MACRO_end_file
:
5637 printf (_(" DW_MACRO_end_file\n"));
5640 case DW_MACRO_define_strp
:
5641 READ_ULEB (lineno
, curr
, end
);
5642 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5643 string
= fetch_indirect_string (offset
);
5644 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5648 case DW_MACRO_undef_strp
:
5649 READ_ULEB (lineno
, curr
, end
);
5650 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5651 string
= fetch_indirect_string (offset
);
5652 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5656 case DW_MACRO_import
:
5657 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5658 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5659 (unsigned long) offset
);
5662 case DW_MACRO_define_sup
:
5663 READ_ULEB (lineno
, curr
, end
);
5664 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5665 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5666 lineno
, (unsigned long) offset
);
5669 case DW_MACRO_undef_sup
:
5670 READ_ULEB (lineno
, curr
, end
);
5671 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5672 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5673 lineno
, (unsigned long) offset
);
5676 case DW_MACRO_import_sup
:
5677 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5678 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5679 (unsigned long) offset
);
5682 case DW_MACRO_define_strx
:
5683 case DW_MACRO_undef_strx
:
5684 READ_ULEB (lineno
, curr
, end
);
5685 READ_ULEB (offset
, curr
, end
);
5686 string
= (const unsigned char *)
5687 fetch_indexed_string (offset
, NULL
, offset_size
, FALSE
);
5688 if (op
== DW_MACRO_define_strx
)
5689 printf (" DW_MACRO_define_strx ");
5691 printf (" DW_MACRO_undef_strx ");
5693 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
5694 printf (_("lineno : %d macro : %s\n"),
5699 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
5701 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
5705 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
5707 error (_(" Unknown macro opcode %02x seen\n"), op
);
5712 /* Skip over unhandled opcodes. */
5714 unsigned char *desc
= extended_ops
[op
];
5715 READ_ULEB (nargs
, desc
, end
);
5718 printf (_(" DW_MACRO_%02x\n"), op
);
5721 printf (_(" DW_MACRO_%02x -"), op
);
5722 for (n
= 0; n
< nargs
; n
++)
5726 /* DW_FORM_implicit_const is not expected here. */
5727 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
5729 = read_and_display_attr_value (0, val
, 0,
5730 start
, curr
, end
, 0, 0, offset_size
,
5731 version
, NULL
, 0, NULL
,
5749 display_debug_abbrev (struct dwarf_section
*section
,
5750 void *file ATTRIBUTE_UNUSED
)
5752 abbrev_entry
*entry
;
5753 unsigned char *start
= section
->start
;
5754 unsigned char *end
= start
+ section
->size
;
5756 introduce (section
, FALSE
);
5760 unsigned char *last
;
5765 start
= process_abbrev_section (start
, end
);
5767 if (first_abbrev
== NULL
)
5770 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
5772 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5776 printf (" %ld %s [%s]\n",
5778 get_TAG_name (entry
->tag
),
5779 entry
->children
? _("has children") : _("no children"));
5781 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5783 printf (" %-18s %s",
5784 get_AT_name (attr
->attribute
),
5785 get_FORM_name (attr
->form
));
5786 if (attr
->form
== DW_FORM_implicit_const
)
5787 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
5799 /* Return true when ADDR is the maximum address, when addresses are
5800 POINTER_SIZE bytes long. */
5803 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
5805 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
5806 return ((addr
& mask
) == mask
);
5809 /* Display a view pair list starting at *VSTART_PTR and ending at
5810 VLISTEND within SECTION. */
5813 display_view_pair_list (struct dwarf_section
*section
,
5814 unsigned char **vstart_ptr
,
5815 unsigned int debug_info_entry
,
5816 unsigned char *vlistend
)
5818 unsigned char *vstart
= *vstart_ptr
;
5819 unsigned char *section_end
= section
->start
+ section
->size
;
5820 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5822 if (vlistend
< section_end
)
5823 section_end
= vlistend
;
5827 while (vstart
< section_end
)
5829 dwarf_vma off
= vstart
- section
->start
;
5830 dwarf_vma vbegin
, vend
;
5832 READ_ULEB (vbegin
, vstart
, section_end
);
5833 if (vstart
== section_end
)
5836 READ_ULEB (vend
, vstart
, section_end
);
5837 printf (" %8.8lx ", (unsigned long) off
);
5839 print_dwarf_view (vbegin
, pointer_size
, 1);
5840 print_dwarf_view (vend
, pointer_size
, 1);
5841 printf (_("location view pair\n"));
5845 *vstart_ptr
= vstart
;
5848 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5851 display_loc_list (struct dwarf_section
*section
,
5852 unsigned char **start_ptr
,
5853 unsigned int debug_info_entry
,
5855 dwarf_vma base_address
,
5856 unsigned char **vstart_ptr
,
5859 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5860 unsigned char *section_end
= section
->start
+ section
->size
;
5861 unsigned long cu_offset
;
5862 unsigned int pointer_size
;
5863 unsigned int offset_size
;
5868 unsigned short length
;
5869 int need_frame_base
;
5871 if (debug_info_entry
>= num_debug_info_entries
)
5873 warn (_("No debug information available for loc lists of entry: %u\n"),
5878 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5879 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5880 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5881 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5883 if (pointer_size
< 2 || pointer_size
> 8)
5885 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5886 pointer_size
, debug_info_entry
);
5892 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5893 dwarf_vma vbegin
= vm1
, vend
= vm1
;
5895 if (start
+ 2 * pointer_size
> section_end
)
5897 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5898 (unsigned long) offset
);
5902 printf (" %8.8lx ", (unsigned long) off
);
5904 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
5905 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
5907 if (begin
== 0 && end
== 0)
5909 /* PR 18374: In a object file we can have a location list that
5910 starts with a begin and end of 0 because there are relocations
5911 that need to be applied to the addresses. Actually applying
5912 the relocations now does not help as they will probably resolve
5913 to 0, since the object file has not been fully linked. Real
5914 end of list markers will not have any relocations against them. */
5915 if (! reloc_at (section
, off
)
5916 && ! reloc_at (section
, off
+ pointer_size
))
5918 printf (_("<End of list>\n"));
5923 /* Check base address specifiers. */
5924 if (is_max_address (begin
, pointer_size
)
5925 && !is_max_address (end
, pointer_size
))
5928 print_dwarf_vma (begin
, pointer_size
);
5929 print_dwarf_vma (end
, pointer_size
);
5930 printf (_("(base address)\n"));
5936 off
= offset
+ (vstart
- *start_ptr
);
5938 READ_ULEB (vbegin
, vstart
, section_end
);
5939 print_dwarf_view (vbegin
, pointer_size
, 1);
5941 READ_ULEB (vend
, vstart
, section_end
);
5942 print_dwarf_view (vend
, pointer_size
, 1);
5944 printf (_("views at %8.8lx for:\n %*s "),
5945 (unsigned long) off
, 8, "");
5948 if (start
+ 2 > section_end
)
5950 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5951 (unsigned long) offset
);
5955 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5957 if (start
+ length
> section_end
)
5959 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5960 (unsigned long) offset
);
5964 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5965 print_dwarf_vma (end
+ base_address
, pointer_size
);
5968 need_frame_base
= decode_location_expression (start
,
5973 cu_offset
, section
);
5976 if (need_frame_base
&& !has_frame_base
)
5977 printf (_(" [without DW_AT_frame_base]"));
5979 if (begin
== end
&& vbegin
== vend
)
5980 fputs (_(" (start == end)"), stdout
);
5981 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5982 fputs (_(" (start > end)"), stdout
);
5990 *vstart_ptr
= vstart
;
5993 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5996 display_loclists_list (struct dwarf_section
*section
,
5997 unsigned char **start_ptr
,
5998 unsigned int debug_info_entry
,
6000 dwarf_vma base_address
,
6001 unsigned char **vstart_ptr
,
6004 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6005 unsigned char *section_end
= section
->start
+ section
->size
;
6006 unsigned long cu_offset
;
6007 unsigned int pointer_size
;
6008 unsigned int offset_size
;
6011 /* Initialize it due to a false compiler warning. */
6012 dwarf_vma begin
= -1, vbegin
= -1;
6013 dwarf_vma end
= -1, vend
= -1;
6015 int need_frame_base
;
6017 if (debug_info_entry
>= num_debug_info_entries
)
6019 warn (_("No debug information available for "
6020 "loclists lists of entry: %u\n"),
6025 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6026 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6027 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6028 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6030 if (pointer_size
< 2 || pointer_size
> 8)
6032 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6033 pointer_size
, debug_info_entry
);
6039 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6040 enum dwarf_location_list_entry_type llet
;
6042 if (start
+ 1 > section_end
)
6044 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6045 (unsigned long) offset
);
6049 printf (" %8.8lx ", (unsigned long) off
);
6051 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6053 if (vstart
&& llet
== DW_LLE_offset_pair
)
6055 off
= offset
+ (vstart
- *start_ptr
);
6057 READ_ULEB (vbegin
, vstart
, section_end
);
6058 print_dwarf_view (vbegin
, pointer_size
, 1);
6060 READ_ULEB (vend
, vstart
, section_end
);
6061 print_dwarf_view (vend
, pointer_size
, 1);
6063 printf (_("views at %8.8lx for:\n %*s "),
6064 (unsigned long) off
, 8, "");
6069 case DW_LLE_end_of_list
:
6070 printf (_("<End of list>\n"));
6072 case DW_LLE_offset_pair
:
6073 READ_ULEB (begin
, start
, section_end
);
6074 READ_ULEB (end
, start
, section_end
);
6076 case DW_LLE_base_address
:
6077 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6079 print_dwarf_vma (base_address
, pointer_size
);
6080 printf (_("(base address)\n"));
6082 #ifdef DW_LLE_view_pair
6083 case DW_LLE_view_pair
:
6085 printf (_("View pair entry in loclist with locviews attribute\n"));
6086 READ_ULEB (vbegin
, start
, section_end
);
6087 print_dwarf_view (vbegin
, pointer_size
, 1);
6089 READ_ULEB (vend
, start
, section_end
);
6090 print_dwarf_view (vend
, pointer_size
, 1);
6092 printf (_("views for:\n"));
6096 error (_("Invalid location list entry type %d\n"), llet
);
6099 if (llet
== DW_LLE_end_of_list
)
6101 if (llet
!= DW_LLE_offset_pair
)
6104 if (start
+ 2 > section_end
)
6106 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6107 (unsigned long) offset
);
6111 READ_ULEB (length
, start
, section_end
);
6113 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6114 print_dwarf_vma (end
+ base_address
, pointer_size
);
6117 need_frame_base
= decode_location_expression (start
,
6122 cu_offset
, section
);
6125 if (need_frame_base
&& !has_frame_base
)
6126 printf (_(" [without DW_AT_frame_base]"));
6128 if (begin
== end
&& vbegin
== vend
)
6129 fputs (_(" (start == end)"), stdout
);
6130 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6131 fputs (_(" (start > end)"), stdout
);
6139 if (vbegin
!= vm1
|| vend
!= vm1
)
6140 printf (_("Trailing view pair not used in a range"));
6143 *vstart_ptr
= vstart
;
6146 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6147 right-adjusted in a field of length LEN, and followed by a space. */
6150 print_addr_index (unsigned int idx
, unsigned int len
)
6152 static char buf
[15];
6153 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6154 printf ("%*s ", len
, buf
);
6157 /* Display a location list from a .dwo section. It uses address indexes rather
6158 than embedded addresses. This code closely follows display_loc_list, but the
6159 two are sufficiently different that combining things is very ugly. */
6162 display_loc_list_dwo (struct dwarf_section
*section
,
6163 unsigned char **start_ptr
,
6164 unsigned int debug_info_entry
,
6166 unsigned char **vstart_ptr
,
6169 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6170 unsigned char *section_end
= section
->start
+ section
->size
;
6171 unsigned long cu_offset
;
6172 unsigned int pointer_size
;
6173 unsigned int offset_size
;
6176 unsigned short length
;
6177 int need_frame_base
;
6180 if (debug_info_entry
>= num_debug_info_entries
)
6182 warn (_("No debug information for loc lists of entry: %u\n"),
6187 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6188 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6189 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6190 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6192 if (pointer_size
< 2 || pointer_size
> 8)
6194 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6195 pointer_size
, debug_info_entry
);
6201 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6203 if (start
>= section_end
)
6205 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6206 (unsigned long) offset
);
6210 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6223 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6225 READ_ULEB (view
, vstart
, section_end
);
6226 print_dwarf_view (view
, 8, 1);
6228 READ_ULEB (view
, vstart
, section_end
);
6229 print_dwarf_view (view
, 8, 1);
6231 printf (_("views at %8.8lx for:\n %*s "),
6232 (unsigned long) off
, 8, "");
6240 case 0: /* A terminating entry. */
6242 *vstart_ptr
= vstart
;
6243 printf (_("<End of list>\n"));
6245 case 1: /* A base-address entry. */
6246 READ_ULEB (idx
, start
, section_end
);
6247 print_addr_index (idx
, 8);
6248 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6249 printf (_("(base address selection entry)\n"));
6251 case 2: /* A start/end entry. */
6252 READ_ULEB (idx
, start
, section_end
);
6253 print_addr_index (idx
, 8);
6254 READ_ULEB (idx
, start
, section_end
);
6255 print_addr_index (idx
, 8);
6257 case 3: /* A start/length entry. */
6258 READ_ULEB (idx
, start
, section_end
);
6259 print_addr_index (idx
, 8);
6260 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6261 printf ("%08x ", idx
);
6263 case 4: /* An offset pair entry. */
6264 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6265 printf ("%08x ", idx
);
6266 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6267 printf ("%08x ", idx
);
6270 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6272 *vstart_ptr
= vstart
;
6276 if (start
+ 2 > section_end
)
6278 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6279 (unsigned long) offset
);
6283 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6284 if (start
+ length
> section_end
)
6286 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6287 (unsigned long) offset
);
6292 need_frame_base
= decode_location_expression (start
,
6297 cu_offset
, section
);
6300 if (need_frame_base
&& !has_frame_base
)
6301 printf (_(" [without DW_AT_frame_base]"));
6309 *vstart_ptr
= vstart
;
6312 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6315 static dwarf_vma
*loc_offsets
, *loc_views
;
6318 loc_offsets_compar (const void *ap
, const void *bp
)
6320 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6321 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6323 int ret
= (a
> b
) - (b
> a
);
6327 a
= loc_views
[*(const unsigned int *) ap
];
6328 b
= loc_views
[*(const unsigned int *) bp
];
6330 ret
= (a
> b
) - (b
> a
);
6336 display_debug_loc (struct dwarf_section
*section
, void *file
)
6338 unsigned char *start
= section
->start
, *vstart
= NULL
;
6339 unsigned long bytes
;
6340 unsigned char *section_begin
= start
;
6341 unsigned int num_loc_list
= 0;
6342 unsigned long last_offset
= 0;
6343 unsigned long last_view
= 0;
6344 unsigned int first
= 0;
6347 int seen_first_offset
= 0;
6348 int locs_sorted
= 1;
6349 unsigned char *next
= start
, *vnext
= vstart
;
6350 unsigned int *array
= NULL
;
6351 const char *suffix
= strrchr (section
->name
, '.');
6352 bfd_boolean is_dwo
= FALSE
;
6353 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6354 dwarf_vma expected_start
= 0;
6356 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6359 bytes
= section
->size
;
6363 printf (_("\nThe %s section is empty.\n"), section
->name
);
6369 unsigned char *hdrptr
= section_begin
;
6370 dwarf_vma ll_length
;
6371 unsigned short ll_version
;
6372 unsigned char *end
= section_begin
+ section
->size
;
6373 unsigned char address_size
, segment_selector_size
;
6374 uint32_t offset_entry_count
;
6376 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6377 if (ll_length
== 0xffffffff)
6378 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6380 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6381 if (ll_version
!= 5)
6383 warn (_("The %s section contains corrupt or "
6384 "unsupported version number: %d.\n"),
6385 section
->name
, ll_version
);
6389 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6391 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6392 if (segment_selector_size
!= 0)
6394 warn (_("The %s section contains "
6395 "unsupported segment selector size: %d.\n"),
6396 section
->name
, segment_selector_size
);
6400 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6401 if (offset_entry_count
!= 0)
6403 warn (_("The %s section contains "
6404 "unsupported offset entry count: %d.\n"),
6405 section
->name
, offset_entry_count
);
6409 expected_start
= hdrptr
- section_begin
;
6412 if (load_debug_info (file
) == 0)
6414 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6419 /* Check the order of location list in .debug_info section. If
6420 offsets of location lists are in the ascending order, we can
6421 use `debug_information' directly. */
6422 for (i
= 0; i
< num_debug_info_entries
; i
++)
6426 num
= debug_information
[i
].num_loc_offsets
;
6427 if (num
> num_loc_list
)
6430 /* Check if we can use `debug_information' directly. */
6431 if (locs_sorted
&& num
!= 0)
6433 if (!seen_first_offset
)
6435 /* This is the first location list. */
6436 last_offset
= debug_information
[i
].loc_offsets
[0];
6437 last_view
= debug_information
[i
].loc_views
[0];
6439 seen_first_offset
= 1;
6445 for (; j
< num
; j
++)
6448 debug_information
[i
].loc_offsets
[j
]
6449 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6450 && last_view
> debug_information
[i
].loc_views
[j
]))
6455 last_offset
= debug_information
[i
].loc_offsets
[j
];
6456 last_view
= debug_information
[i
].loc_views
[j
];
6461 if (!seen_first_offset
)
6462 error (_("No location lists in .debug_info section!\n"));
6464 if (debug_information
[first
].num_loc_offsets
> 0
6465 && debug_information
[first
].loc_offsets
[0] != expected_start
6466 && debug_information
[first
].loc_views
[0] != expected_start
)
6467 warn (_("Location lists in %s section start at 0x%s\n"),
6469 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6472 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6474 introduce (section
, FALSE
);
6476 if (reloc_at (section
, 0))
6477 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6479 printf (_(" Offset Begin End Expression\n"));
6481 seen_first_offset
= 0;
6482 for (i
= first
; i
< num_debug_info_entries
; i
++)
6484 dwarf_vma offset
, voffset
;
6485 dwarf_vma base_address
;
6491 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6493 loc_offsets
= debug_information
[i
].loc_offsets
;
6494 loc_views
= debug_information
[i
].loc_views
;
6495 qsort (array
, debug_information
[i
].num_loc_offsets
,
6496 sizeof (*array
), loc_offsets_compar
);
6499 int adjacent_view_loclists
= 1;
6500 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6502 j
= locs_sorted
? k
: array
[k
];
6504 && (debug_information
[i
].loc_offsets
[locs_sorted
6505 ? k
- 1 : array
[k
- 1]]
6506 == debug_information
[i
].loc_offsets
[j
])
6507 && (debug_information
[i
].loc_views
[locs_sorted
6508 ? k
- 1 : array
[k
- 1]]
6509 == debug_information
[i
].loc_views
[j
]))
6511 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6512 offset
= debug_information
[i
].loc_offsets
[j
];
6513 next
= section_begin
+ offset
;
6514 voffset
= debug_information
[i
].loc_views
[j
];
6516 vnext
= section_begin
+ voffset
;
6519 base_address
= debug_information
[i
].base_address
;
6521 if (vnext
&& vnext
< next
)
6524 display_view_pair_list (section
, &vstart
, i
, next
);
6529 if (!seen_first_offset
|| !adjacent_view_loclists
)
6530 seen_first_offset
= 1;
6534 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6535 (unsigned long) (start
- section_begin
),
6536 (unsigned long) offset
);
6537 else if (start
> next
)
6538 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6539 (unsigned long) (start
- section_begin
),
6540 (unsigned long) offset
);
6545 if (offset
>= bytes
)
6547 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6548 (unsigned long) offset
);
6552 if (vnext
&& voffset
>= bytes
)
6554 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6555 (unsigned long) voffset
);
6562 display_loc_list_dwo (section
, &start
, i
, offset
,
6563 &vstart
, has_frame_base
);
6565 display_loc_list (section
, &start
, i
, offset
, base_address
,
6566 &vstart
, has_frame_base
);
6571 warn (_("DWO is not yet supported.\n"));
6573 display_loclists_list (section
, &start
, i
, offset
, base_address
,
6574 &vstart
, has_frame_base
);
6577 /* FIXME: this arrangement is quite simplistic. Nothing
6578 requires locview lists to be adjacent to corresponding
6579 loclists, and a single loclist could be augmented by
6580 different locview lists, and vice-versa, unlikely as it
6581 is that it would make sense to do so. Hopefully we'll
6582 have view pair support built into loclists before we ever
6583 need to address all these possibilities. */
6584 if (adjacent_view_loclists
&& vnext
6585 && vnext
!= start
&& vstart
!= next
)
6587 adjacent_view_loclists
= 0;
6588 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6591 if (vnext
&& vnext
== start
)
6592 display_view_pair_list (section
, &start
, i
, vstart
);
6596 if (start
< section
->start
+ section
->size
)
6597 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6598 "There are %ld unused bytes at the end of section %s\n",
6599 (long) (section
->start
+ section
->size
- start
)),
6600 (long) (section
->start
+ section
->size
- start
), section
->name
);
6607 display_debug_str (struct dwarf_section
*section
,
6608 void *file ATTRIBUTE_UNUSED
)
6610 unsigned char *start
= section
->start
;
6611 unsigned long bytes
= section
->size
;
6612 dwarf_vma addr
= section
->address
;
6616 printf (_("\nThe %s section is empty.\n"), section
->name
);
6620 introduce (section
, FALSE
);
6628 lbytes
= (bytes
> 16 ? 16 : bytes
);
6630 printf (" 0x%8.8lx ", (unsigned long) addr
);
6632 for (j
= 0; j
< 16; j
++)
6635 printf ("%2.2x", start
[j
]);
6643 for (j
= 0; j
< lbytes
; j
++)
6646 if (k
>= ' ' && k
< 0x80)
6665 display_debug_info (struct dwarf_section
*section
, void *file
)
6667 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, FALSE
);
6671 display_debug_types (struct dwarf_section
*section
, void *file
)
6673 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6677 display_trace_info (struct dwarf_section
*section
, void *file
)
6679 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6683 display_debug_aranges (struct dwarf_section
*section
,
6684 void *file ATTRIBUTE_UNUSED
)
6686 unsigned char *start
= section
->start
;
6687 unsigned char *end
= start
+ section
->size
;
6689 introduce (section
, FALSE
);
6691 /* It does not matter if this load fails,
6692 we test for that later on. */
6693 load_debug_info (file
);
6697 unsigned char *hdrptr
;
6698 DWARF2_Internal_ARange arange
;
6699 unsigned char *addr_ranges
;
6702 unsigned long sec_off
;
6703 unsigned char address_size
;
6705 unsigned int offset_size
;
6706 unsigned int initial_length_size
;
6710 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
6711 if (arange
.ar_length
== 0xffffffff)
6713 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
6715 initial_length_size
= 12;
6720 initial_length_size
= 4;
6723 sec_off
= hdrptr
- section
->start
;
6724 if (sec_off
+ arange
.ar_length
< sec_off
6725 || sec_off
+ arange
.ar_length
> section
->size
)
6727 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6729 sec_off
- initial_length_size
,
6730 dwarf_vmatoa ("x", arange
.ar_length
));
6734 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
6735 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
6737 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6738 && num_debug_info_entries
> 0
6739 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
6740 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6741 (unsigned long) arange
.ar_info_offset
, section
->name
);
6743 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
6744 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
6746 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
6748 /* PR 19872: A version number of 0 probably means that there is
6749 padding at the end of the .debug_aranges section. Gold puts
6750 it there when performing an incremental link, for example.
6751 So do not generate a warning in this case. */
6752 if (arange
.ar_version
)
6753 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6757 printf (_(" Length: %ld\n"),
6758 (long) arange
.ar_length
);
6759 printf (_(" Version: %d\n"), arange
.ar_version
);
6760 printf (_(" Offset into .debug_info: 0x%lx\n"),
6761 (unsigned long) arange
.ar_info_offset
);
6762 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6763 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6765 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
6767 /* PR 17512: file: 001-108546-0.001:0.1. */
6768 if (address_size
== 0 || address_size
> 8)
6770 error (_("Invalid address size in %s section!\n"),
6775 /* The DWARF spec does not require that the address size be a power
6776 of two, but we do. This will have to change if we ever encounter
6777 an uneven architecture. */
6778 if ((address_size
& (address_size
- 1)) != 0)
6780 warn (_("Pointer size + Segment size is not a power of two.\n"));
6784 if (address_size
> 4)
6785 printf (_("\n Address Length\n"));
6787 printf (_("\n Address Length\n"));
6789 addr_ranges
= hdrptr
;
6791 /* Must pad to an alignment boundary that is twice the address size. */
6792 excess
= (hdrptr
- start
) % (2 * address_size
);
6794 addr_ranges
+= (2 * address_size
) - excess
;
6796 start
+= arange
.ar_length
+ initial_length_size
;
6798 while (addr_ranges
+ 2 * address_size
<= start
)
6800 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
6801 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
6804 print_dwarf_vma (address
, address_size
);
6805 print_dwarf_vma (length
, address_size
);
6815 /* Comparison function for qsort. */
6817 comp_addr_base (const void * v0
, const void * v1
)
6819 debug_info
*info0
= *(debug_info
**) v0
;
6820 debug_info
*info1
= *(debug_info
**) v1
;
6821 return info0
->addr_base
- info1
->addr_base
;
6824 /* Display the debug_addr section. */
6826 display_debug_addr (struct dwarf_section
*section
,
6829 debug_info
**debug_addr_info
;
6830 unsigned char *entry
;
6835 if (section
->size
== 0)
6837 printf (_("\nThe %s section is empty.\n"), section
->name
);
6841 if (load_debug_info (file
) == 0)
6843 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6848 introduce (section
, FALSE
);
6850 /* PR 17531: file: cf38d01b.
6851 We use xcalloc because a corrupt file may not have initialised all of the
6852 fields in the debug_info structure, which means that the sort below might
6853 try to move uninitialised data. */
6854 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
6855 sizeof (debug_info
*));
6858 for (i
= 0; i
< num_debug_info_entries
; i
++)
6859 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
6861 /* PR 17531: file: cf38d01b. */
6862 if (debug_information
[i
].addr_base
>= section
->size
)
6863 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6864 (unsigned long) debug_information
[i
].addr_base
, i
);
6866 debug_addr_info
[count
++] = debug_information
+ i
;
6869 /* Add a sentinel to make iteration convenient. */
6870 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
6871 debug_addr_info
[count
]->addr_base
= section
->size
;
6872 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
6874 for (i
= 0; i
< count
; i
++)
6877 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
6879 printf (_(" For compilation unit at offset 0x%s:\n"),
6880 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
6882 printf (_("\tIndex\tAddress\n"));
6883 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
6884 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
6888 dwarf_vma base
= byte_get (entry
, address_size
);
6889 printf (_("\t%d:\t"), idx
);
6890 print_dwarf_vma (base
, address_size
);
6892 entry
+= address_size
;
6898 free (debug_addr_info
);
6902 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6905 display_debug_str_offsets (struct dwarf_section
*section
,
6906 void *file ATTRIBUTE_UNUSED
)
6910 if (section
->size
== 0)
6912 printf (_("\nThe %s section is empty.\n"), section
->name
);
6916 unsigned char *start
= section
->start
;
6917 unsigned char *end
= start
+ section
->size
;
6918 unsigned char *curr
= start
;
6920 const char * suffix
= strrchr (section
->name
, '.');
6921 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
6924 load_debug_section_with_follow (str_dwo
, file
);
6926 load_debug_section_with_follow (str
, file
);
6928 introduce (section
, FALSE
);
6933 dwarf_vma entry_length
;
6935 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
6936 /* FIXME: We assume that this means 64-bit DWARF is being used. */
6937 if (length
== 0xffffffff)
6939 SAFE_BYTE_GET (length
, curr
, 8, end
);
6947 /* This is probably an old style .debug_str_offset section which
6948 just contains offsets and no header (and the first offset is 0). */
6949 length
= section
->size
;
6950 curr
= section
->start
;
6952 printf (_(" Length: %#lx\n"), (unsigned long) length
);
6953 printf (_(" Index Offset [String]\n"));
6958 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6960 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
6963 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
6965 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
6967 printf (_(" Length: %#lx\n"), (unsigned long) length
);
6968 printf (_(" Version: %#lx\n"), (unsigned long) version
);
6969 printf (_(" Index Offset [String]\n"));
6972 for (idx
= 0; length
>= entry_length
&& curr
< end
; idx
++)
6975 const unsigned char * string
;
6977 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
6979 string
= (const unsigned char *)
6980 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
6982 string
= fetch_indirect_string (offset
);
6984 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
6992 /* Each debug_information[x].range_lists[y] gets this representation for
6993 sorting purposes. */
6997 /* The debug_information[x].range_lists[y] value. */
6998 dwarf_vma ranges_offset
;
7000 /* Original debug_information to find parameters of the data. */
7001 debug_info
*debug_info_p
;
7004 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7007 range_entry_compar (const void *ap
, const void *bp
)
7009 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7010 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7011 const dwarf_vma a
= a_re
->ranges_offset
;
7012 const dwarf_vma b
= b_re
->ranges_offset
;
7014 return (a
> b
) - (b
> a
);
7018 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7019 unsigned int pointer_size
, unsigned long offset
,
7020 unsigned long base_address
)
7022 while (start
< finish
)
7027 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7028 if (start
>= finish
)
7030 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7033 printf (" %8.8lx ", offset
);
7035 if (begin
== 0 && end
== 0)
7037 printf (_("<End of list>\n"));
7041 /* Check base address specifiers. */
7042 if (is_max_address (begin
, pointer_size
)
7043 && !is_max_address (end
, pointer_size
))
7046 print_dwarf_vma (begin
, pointer_size
);
7047 print_dwarf_vma (end
, pointer_size
);
7048 printf ("(base address)\n");
7052 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7053 print_dwarf_vma (end
+ base_address
, pointer_size
);
7056 fputs (_("(start == end)"), stdout
);
7057 else if (begin
> end
)
7058 fputs (_("(start > end)"), stdout
);
7065 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7066 unsigned int pointer_size
, unsigned long offset
,
7067 unsigned long base_address
)
7069 unsigned char *next
= start
;
7073 unsigned long off
= offset
+ (start
- next
);
7074 enum dwarf_range_list_entry rlet
;
7075 /* Initialize it due to a false compiler warning. */
7076 dwarf_vma begin
= -1, length
, end
= -1;
7078 if (start
+ 1 > finish
)
7080 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7085 printf (" %8.8lx ", off
);
7087 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7091 case DW_RLE_end_of_list
:
7092 printf (_("<End of list>\n"));
7094 case DW_RLE_base_address
:
7095 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7096 print_dwarf_vma (base_address
, pointer_size
);
7097 printf (_("(base address)\n"));
7099 case DW_RLE_start_length
:
7100 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7101 READ_ULEB (length
, start
, finish
);
7102 end
= begin
+ length
;
7104 case DW_RLE_offset_pair
:
7105 READ_ULEB (begin
, start
, finish
);
7106 READ_ULEB (end
, start
, finish
);
7108 case DW_RLE_start_end
:
7109 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7110 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7113 error (_("Invalid range list entry type %d\n"), rlet
);
7114 rlet
= DW_RLE_end_of_list
;
7117 if (rlet
== DW_RLE_end_of_list
)
7119 if (rlet
== DW_RLE_base_address
)
7122 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7123 print_dwarf_vma (end
+ base_address
, pointer_size
);
7126 fputs (_("(start == end)"), stdout
);
7127 else if (begin
> end
)
7128 fputs (_("(start > end)"), stdout
);
7135 display_debug_ranges (struct dwarf_section
*section
,
7136 void *file ATTRIBUTE_UNUSED
)
7138 unsigned char *start
= section
->start
;
7139 unsigned char *last_start
= start
;
7140 unsigned long bytes
= section
->size
;
7141 unsigned char *section_begin
= start
;
7142 unsigned char *finish
= start
+ bytes
;
7143 unsigned int num_range_list
, i
;
7144 struct range_entry
*range_entries
, *range_entry_fill
;
7145 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7146 /* Initialize it due to a false compiler warning. */
7147 unsigned char address_size
= 0;
7148 dwarf_vma last_offset
= 0;
7152 printf (_("\nThe %s section is empty.\n"), section
->name
);
7158 dwarf_vma initial_length
;
7159 unsigned int initial_length_size
;
7160 unsigned char segment_selector_size
;
7161 unsigned int offset_size
, offset_entry_count
;
7162 unsigned short version
;
7164 /* Get and check the length of the block. */
7165 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7167 if (initial_length
== 0xffffffff)
7169 /* This section is 64-bit DWARF 3. */
7170 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7172 initial_length_size
= 12;
7177 initial_length_size
= 4;
7180 if (initial_length
+ initial_length_size
> section
->size
)
7182 /* If the length field has a relocation against it, then we should
7183 not complain if it is inaccurate (and probably negative).
7184 It is copied from .debug_line handling code. */
7185 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7187 initial_length
= (finish
- start
) - initial_length_size
;
7191 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7192 (long) initial_length
);
7197 /* Get and check the version number. */
7198 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7202 warn (_("Only DWARF version 5 debug_rnglists info "
7203 "is currently supported.\n"));
7207 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7209 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7210 if (segment_selector_size
!= 0)
7212 warn (_("The %s section contains "
7213 "unsupported segment selector size: %d.\n"),
7214 section
->name
, segment_selector_size
);
7218 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7219 if (offset_entry_count
!= 0)
7221 warn (_("The %s section contains "
7222 "unsupported offset entry count: %u.\n"),
7223 section
->name
, offset_entry_count
);
7228 if (load_debug_info (file
) == 0)
7230 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7236 for (i
= 0; i
< num_debug_info_entries
; i
++)
7237 num_range_list
+= debug_information
[i
].num_range_lists
;
7239 if (num_range_list
== 0)
7241 /* This can happen when the file was compiled with -gsplit-debug
7242 which removes references to range lists from the primary .o file. */
7243 printf (_("No range lists in .debug_info section.\n"));
7247 range_entries
= (struct range_entry
*)
7248 xmalloc (sizeof (*range_entries
) * num_range_list
);
7249 range_entry_fill
= range_entries
;
7251 for (i
= 0; i
< num_debug_info_entries
; i
++)
7253 debug_info
*debug_info_p
= &debug_information
[i
];
7256 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7258 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7259 range_entry_fill
->debug_info_p
= debug_info_p
;
7264 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7265 range_entry_compar
);
7267 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7268 warn (_("Range lists in %s section start at 0x%lx\n"),
7269 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7271 introduce (section
, FALSE
);
7273 printf (_(" Offset Begin End\n"));
7275 for (i
= 0; i
< num_range_list
; i
++)
7277 struct range_entry
*range_entry
= &range_entries
[i
];
7278 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7279 unsigned int pointer_size
;
7281 unsigned char *next
;
7282 dwarf_vma base_address
;
7284 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7285 offset
= range_entry
->ranges_offset
;
7286 next
= section_begin
+ offset
;
7287 base_address
= debug_info_p
->base_address
;
7289 /* PR 17512: file: 001-101485-0.001:0.1. */
7290 if (pointer_size
< 2 || pointer_size
> 8)
7292 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7293 pointer_size
, (unsigned long) offset
);
7297 if (next
< section_begin
|| next
>= finish
)
7299 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7300 (unsigned long) offset
, i
);
7304 /* If multiple DWARF entities reference the same range then we will
7305 have multiple entries in the `range_entries' list for the same
7306 offset. Thanks to the sort above these will all be consecutive in
7307 the `range_entries' list, so we can easily ignore duplicates
7309 if (i
> 0 && last_offset
== offset
)
7311 last_offset
= offset
;
7313 if (dwarf_check
!= 0 && i
> 0)
7316 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7317 (unsigned long) (start
- section_begin
),
7318 (unsigned long) (next
- section_begin
), section
->name
);
7319 else if (start
> next
)
7321 if (next
== last_start
)
7323 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7324 (unsigned long) (start
- section_begin
),
7325 (unsigned long) (next
- section_begin
), section
->name
);
7332 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7333 (start
, finish
, pointer_size
, offset
, base_address
);
7337 free (range_entries
);
7342 typedef struct Frame_Chunk
7344 struct Frame_Chunk
*next
;
7345 unsigned char *chunk_start
;
7347 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7348 short int *col_type
;
7351 unsigned int code_factor
;
7355 unsigned int cfa_reg
;
7356 dwarf_vma cfa_offset
;
7358 unsigned char fde_encoding
;
7359 unsigned char cfa_exp
;
7360 unsigned char ptr_size
;
7361 unsigned char segment_size
;
7365 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7366 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7367 static const char *const *dwarf_regnames
;
7368 static unsigned int dwarf_regnames_count
;
7371 /* A marker for a col_type that means this column was never referenced
7372 in the frame info. */
7373 #define DW_CFA_unreferenced (-1)
7375 /* Return 0 if no more space is needed, 1 if more space is needed,
7376 -1 for invalid reg. */
7379 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7381 unsigned int prev
= fc
->ncols
;
7383 if (reg
< (unsigned int) fc
->ncols
)
7386 if (dwarf_regnames_count
> 0
7387 && reg
> dwarf_regnames_count
)
7390 fc
->ncols
= reg
+ 1;
7391 /* PR 17512: file: 10450-2643-0.004.
7392 If reg == -1 then this can happen... */
7396 /* PR 17512: file: 2844a11d. */
7397 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7399 error (_("Unfeasibly large register number: %u\n"), reg
);
7401 /* FIXME: 1024 is an arbitrary limit. Increase it if
7402 we ever encounter a valid binary that exceeds it. */
7406 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7407 sizeof (short int));
7408 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7409 /* PR 17512: file:002-10025-0.005. */
7410 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7412 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7418 while (prev
< fc
->ncols
)
7420 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7421 fc
->col_offset
[prev
] = 0;
7427 static const char *const dwarf_regnames_i386
[] =
7429 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7430 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7431 "eip", "eflags", NULL
, /* 8 - 10 */
7432 "st0", "st1", "st2", "st3", /* 11 - 14 */
7433 "st4", "st5", "st6", "st7", /* 15 - 18 */
7434 NULL
, NULL
, /* 19 - 20 */
7435 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7436 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7437 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7438 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7439 "fcw", "fsw", "mxcsr", /* 37 - 39 */
7440 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7441 "tr", "ldtr", /* 48 - 49 */
7442 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7443 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7444 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7445 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7446 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7447 NULL
, NULL
, NULL
, /* 90 - 92 */
7448 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
7451 static const char *const dwarf_regnames_iamcu
[] =
7453 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7454 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7455 "eip", "eflags", NULL
, /* 8 - 10 */
7456 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
7457 NULL
, NULL
, /* 19 - 20 */
7458 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
7459 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
7460 NULL
, NULL
, NULL
, /* 37 - 39 */
7461 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7462 "tr", "ldtr", /* 48 - 49 */
7463 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7464 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7465 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7466 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7467 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7468 NULL
, NULL
, NULL
, /* 90 - 92 */
7469 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
7473 init_dwarf_regnames_i386 (void)
7475 dwarf_regnames
= dwarf_regnames_i386
;
7476 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
7477 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7481 init_dwarf_regnames_iamcu (void)
7483 dwarf_regnames
= dwarf_regnames_iamcu
;
7484 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
7485 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7488 static const char *const dwarf_regnames_x86_64
[] =
7490 "rax", "rdx", "rcx", "rbx",
7491 "rsi", "rdi", "rbp", "rsp",
7492 "r8", "r9", "r10", "r11",
7493 "r12", "r13", "r14", "r15",
7495 "xmm0", "xmm1", "xmm2", "xmm3",
7496 "xmm4", "xmm5", "xmm6", "xmm7",
7497 "xmm8", "xmm9", "xmm10", "xmm11",
7498 "xmm12", "xmm13", "xmm14", "xmm15",
7499 "st0", "st1", "st2", "st3",
7500 "st4", "st5", "st6", "st7",
7501 "mm0", "mm1", "mm2", "mm3",
7502 "mm4", "mm5", "mm6", "mm7",
7504 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
7505 "fs.base", "gs.base", NULL
, NULL
,
7507 "mxcsr", "fcw", "fsw",
7508 "xmm16", "xmm17", "xmm18", "xmm19",
7509 "xmm20", "xmm21", "xmm22", "xmm23",
7510 "xmm24", "xmm25", "xmm26", "xmm27",
7511 "xmm28", "xmm29", "xmm30", "xmm31",
7512 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
7513 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
7514 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
7515 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
7516 NULL
, NULL
, NULL
, /* 115 - 117 */
7517 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7521 init_dwarf_regnames_x86_64 (void)
7523 dwarf_regnames
= dwarf_regnames_x86_64
;
7524 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
7525 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7528 static const char *const dwarf_regnames_aarch64
[] =
7530 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7531 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7532 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7533 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7534 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7535 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
7536 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
7537 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
7538 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7539 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7540 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7541 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7542 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
7543 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
7544 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
7545 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
7549 init_dwarf_regnames_aarch64 (void)
7551 dwarf_regnames
= dwarf_regnames_aarch64
;
7552 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
7553 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7556 static const char *const dwarf_regnames_s390
[] =
7558 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7559 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7560 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7561 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7562 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7563 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7564 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7565 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7566 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7569 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7570 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7574 init_dwarf_regnames_s390 (void)
7576 dwarf_regnames
= dwarf_regnames_s390
;
7577 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
7578 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7581 static const char *const dwarf_regnames_riscv
[] =
7583 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
7584 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
7585 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
7586 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
7587 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
7588 "fs0", "fs1", /* 40 - 41 */
7589 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
7590 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
7591 "fs10", "fs11", /* 58 - 59 */
7592 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
7595 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
7596 the large number of CSRs. */
7599 regname_internal_riscv (unsigned int regno
)
7601 const char *name
= NULL
;
7603 /* Lookup in the table first, this covers GPR and FPR. */
7604 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
7605 name
= dwarf_regnames_riscv
[regno
];
7606 else if (regno
>= 4096 && regno
<= 8191)
7608 /* This might be a CSR, these live in a sparse number space from 4096
7609 to 8191 These numbers are defined in the RISC-V ELF ABI
7613 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
7614 case VALUE + 4096: name = #NAME; break;
7615 #include "opcode/riscv-opc.h"
7620 static char csr_name
[10];
7621 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
7632 init_dwarf_regnames_riscv (void)
7634 dwarf_regnames
= NULL
;
7635 dwarf_regnames_count
= 8192;
7636 dwarf_regnames_lookup_func
= regname_internal_riscv
;
7640 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
7642 dwarf_regnames_lookup_func
= NULL
;
7647 init_dwarf_regnames_i386 ();
7651 init_dwarf_regnames_iamcu ();
7657 init_dwarf_regnames_x86_64 ();
7661 init_dwarf_regnames_aarch64 ();
7665 init_dwarf_regnames_s390 ();
7669 init_dwarf_regnames_riscv ();
7677 /* Initialize the DWARF register name lookup state based on the
7678 architecture and specific machine type of a BFD. */
7681 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
7684 dwarf_regnames_lookup_func
= NULL
;
7691 case bfd_mach_x86_64
:
7692 case bfd_mach_x86_64_intel_syntax
:
7693 case bfd_mach_x64_32
:
7694 case bfd_mach_x64_32_intel_syntax
:
7695 init_dwarf_regnames_x86_64 ();
7699 init_dwarf_regnames_i386 ();
7704 case bfd_arch_iamcu
:
7705 init_dwarf_regnames_iamcu ();
7708 case bfd_arch_aarch64
:
7709 init_dwarf_regnames_aarch64();
7713 init_dwarf_regnames_s390 ();
7716 case bfd_arch_riscv
:
7717 init_dwarf_regnames_riscv ();
7726 regname_internal_by_table_only (unsigned int regno
)
7728 if (dwarf_regnames
!= NULL
7729 && regno
< dwarf_regnames_count
7730 && dwarf_regnames
[regno
] != NULL
)
7731 return dwarf_regnames
[regno
];
7737 regname (unsigned int regno
, int name_only_p
)
7739 static char reg
[64];
7741 const char *name
= NULL
;
7743 if (dwarf_regnames_lookup_func
!= NULL
)
7744 name
= dwarf_regnames_lookup_func (regno
);
7750 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
7753 snprintf (reg
, sizeof (reg
), "r%d", regno
);
7758 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
7763 if (*max_regs
!= fc
->ncols
)
7764 *max_regs
= fc
->ncols
;
7766 if (*need_col_headers
)
7768 static const char *sloc
= " LOC";
7770 *need_col_headers
= 0;
7772 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
7774 for (r
= 0; r
< *max_regs
; r
++)
7775 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7780 printf ("%-5s ", regname (r
, 1));
7786 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
7788 strcpy (tmp
, "exp");
7790 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
7791 printf ("%-8s ", tmp
);
7793 for (r
= 0; r
< fc
->ncols
; r
++)
7795 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7797 switch (fc
->col_type
[r
])
7799 case DW_CFA_undefined
:
7802 case DW_CFA_same_value
:
7806 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
7808 case DW_CFA_val_offset
:
7809 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
7811 case DW_CFA_register
:
7812 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
7814 case DW_CFA_expression
:
7815 strcpy (tmp
, "exp");
7817 case DW_CFA_val_expression
:
7818 strcpy (tmp
, "vexp");
7821 strcpy (tmp
, "n/a");
7824 printf ("%-5s ", tmp
);
7830 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
7832 static unsigned char *
7833 read_cie (unsigned char *start
, unsigned char *end
,
7834 Frame_Chunk
**p_cie
, int *p_version
,
7835 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
7839 unsigned char *augmentation_data
= NULL
;
7840 bfd_size_type augmentation_data_len
= 0;
7843 /* PR 17512: file: 001-228113-0.004. */
7847 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7848 memset (fc
, 0, sizeof (Frame_Chunk
));
7850 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7851 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7855 fc
->augmentation
= (char *) start
;
7856 /* PR 17512: file: 001-228113-0.004.
7857 Skip past augmentation name, but avoid running off the end of the data. */
7859 if (* start
++ == '\0')
7863 warn (_("No terminator for augmentation name\n"));
7867 if (strcmp (fc
->augmentation
, "eh") == 0)
7868 start
+= eh_addr_size
;
7872 GET (fc
->ptr_size
, 1);
7873 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
7875 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
7879 GET (fc
->segment_size
, 1);
7880 /* PR 17512: file: e99d2804. */
7881 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
7883 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
7887 eh_addr_size
= fc
->ptr_size
;
7891 fc
->ptr_size
= eh_addr_size
;
7892 fc
->segment_size
= 0;
7895 READ_ULEB (fc
->code_factor
, start
, end
);
7896 READ_SLEB (fc
->data_factor
, start
, end
);
7904 READ_ULEB (fc
->ra
, start
, end
);
7907 if (fc
->augmentation
[0] == 'z')
7909 READ_ULEB (augmentation_data_len
, start
, end
);
7910 augmentation_data
= start
;
7911 /* PR 17512: file: 11042-2589-0.004. */
7912 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
7914 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7915 dwarf_vmatoa ("x", augmentation_data_len
),
7916 (unsigned long) (end
- start
));
7919 start
+= augmentation_data_len
;
7922 if (augmentation_data_len
)
7926 unsigned char *qend
;
7928 p
= (unsigned char *) fc
->augmentation
+ 1;
7929 q
= augmentation_data
;
7930 qend
= q
+ augmentation_data_len
;
7932 while (p
< end
&& q
< qend
)
7937 q
+= 1 + size_of_encoded_value (*q
);
7939 fc
->fde_encoding
= *q
++;
7948 /* Note - it is OK if this loop terminates with q < qend.
7949 Padding may have been inserted to align the end of the CIE. */
7954 *p_version
= version
;
7957 *p_aug_len
= augmentation_data_len
;
7958 *p_aug
= augmentation_data
;
7963 free (fc
->col_offset
);
7964 free (fc
->col_type
);
7969 /* Prints out the contents on the DATA array formatted as unsigned bytes.
7970 If do_wide is not enabled, then formats the output to fit into 80 columns.
7971 PRINTED contains the number of characters already written to the current
7975 display_data (bfd_size_type printed
,
7976 const unsigned char * data
,
7977 const bfd_size_type len
)
7979 if (do_wide
|| len
< ((80 - printed
) / 3))
7980 for (printed
= 0; printed
< len
; ++printed
)
7981 printf (" %02x", data
[printed
]);
7984 for (printed
= 0; printed
< len
; ++printed
)
7986 if (printed
% (80 / 3) == 0)
7988 printf (" %02x", data
[printed
]);
7993 /* Prints out the contents on the augmentation data array.
7994 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7997 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8001 i
= printf (_(" Augmentation data: "));
8002 display_data (i
, data
, len
);
8006 display_debug_frames (struct dwarf_section
*section
,
8007 void *file ATTRIBUTE_UNUSED
)
8009 unsigned char *start
= section
->start
;
8010 unsigned char *end
= start
+ section
->size
;
8011 unsigned char *section_start
= start
;
8012 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8013 Frame_Chunk
*remembered_state
= NULL
;
8015 bfd_boolean is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8016 unsigned int max_regs
= 0;
8017 const char *bad_reg
= _("bad register: ");
8018 unsigned int saved_eh_addr_size
= eh_addr_size
;
8020 introduce (section
, FALSE
);
8024 unsigned char *saved_start
;
8025 unsigned char *block_end
;
8030 int need_col_headers
= 1;
8031 unsigned char *augmentation_data
= NULL
;
8032 bfd_size_type augmentation_data_len
= 0;
8033 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8034 unsigned int offset_size
;
8035 unsigned int initial_length_size
;
8036 bfd_boolean all_nops
;
8037 static Frame_Chunk fde_fc
;
8039 saved_start
= start
;
8041 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8045 printf ("\n%08lx ZERO terminator\n\n",
8046 (unsigned long)(saved_start
- section_start
));
8047 /* Skip any zero terminators that directly follow.
8048 A corrupt section size could have loaded a whole
8049 slew of zero filled memory bytes. eg
8050 PR 17512: file: 070-19381-0.004. */
8051 while (start
< end
&& * start
== 0)
8056 if (length
== 0xffffffff)
8058 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8060 initial_length_size
= 12;
8065 initial_length_size
= 4;
8068 block_end
= saved_start
+ length
+ initial_length_size
;
8069 if (block_end
> end
|| block_end
< start
)
8071 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8072 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8073 (unsigned long) (saved_start
- section_start
));
8077 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8079 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8080 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8085 start
= read_cie (start
, end
, &cie
, &version
,
8086 &augmentation_data_len
, &augmentation_data
);
8087 /* PR 17512: file: 027-135133-0.005. */
8094 fc
->chunk_start
= saved_start
;
8095 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8098 if (frame_need_space (fc
, mreg
) < 0)
8100 if (fc
->fde_encoding
)
8101 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8103 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8104 print_dwarf_vma (length
, fc
->ptr_size
);
8105 print_dwarf_vma (cie_id
, offset_size
);
8107 if (do_debug_frames_interp
)
8109 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8110 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8115 printf (" Version: %d\n", version
);
8116 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8119 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8120 printf (" Segment Size: %u\n", fc
->segment_size
);
8122 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8123 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8124 printf (" Return address column: %d\n", fc
->ra
);
8126 if (augmentation_data_len
)
8127 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8134 unsigned char *look_for
;
8135 unsigned long segment_selector
;
8139 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8140 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8143 look_for
= section_start
+ cie_id
;
8145 if (look_for
<= saved_start
)
8147 for (cie
= chunks
; cie
; cie
= cie
->next
)
8148 if (cie
->chunk_start
== look_for
)
8153 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8154 if (cie
->chunk_start
== look_for
)
8158 unsigned int off_size
;
8159 unsigned char *cie_scan
;
8161 cie_scan
= look_for
;
8163 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8164 if (length
== 0xffffffff)
8166 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8173 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8176 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8177 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8182 read_cie (cie_scan
, end
, &cie
, &version
,
8183 &augmentation_data_len
, &augmentation_data
);
8184 /* PR 17512: file: 3450-2098-0.004. */
8187 warn (_("Failed to read CIE information\n"));
8190 cie
->next
= forward_refs
;
8192 cie
->chunk_start
= look_for
;
8193 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8196 if (frame_need_space (cie
, mreg
) < 0)
8198 warn (_("Invalid max register\n"));
8201 if (cie
->fde_encoding
)
8203 = size_of_encoded_value (cie
->fde_encoding
);
8210 memset (fc
, 0, sizeof (Frame_Chunk
));
8214 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8215 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8216 (unsigned long) (saved_start
- section_start
));
8218 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8219 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8220 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8222 warn (_("Invalid max register\n"));
8226 fc
->augmentation
= "";
8227 fc
->fde_encoding
= 0;
8228 fc
->ptr_size
= eh_addr_size
;
8229 fc
->segment_size
= 0;
8233 fc
->ncols
= cie
->ncols
;
8234 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8235 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8236 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8237 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8238 fc
->augmentation
= cie
->augmentation
;
8239 fc
->ptr_size
= cie
->ptr_size
;
8240 eh_addr_size
= cie
->ptr_size
;
8241 fc
->segment_size
= cie
->segment_size
;
8242 fc
->code_factor
= cie
->code_factor
;
8243 fc
->data_factor
= cie
->data_factor
;
8244 fc
->cfa_reg
= cie
->cfa_reg
;
8245 fc
->cfa_offset
= cie
->cfa_offset
;
8247 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8249 warn (_("Invalid max register\n"));
8252 fc
->fde_encoding
= cie
->fde_encoding
;
8255 if (fc
->fde_encoding
)
8256 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8258 segment_selector
= 0;
8259 if (fc
->segment_size
)
8261 if (fc
->segment_size
> sizeof (segment_selector
))
8263 /* PR 17512: file: 9e196b3e. */
8264 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8265 fc
->segment_size
= 4;
8267 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8270 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8272 /* FIXME: It appears that sometimes the final pc_range value is
8273 encoded in less than encoded_ptr_size bytes. See the x86_64
8274 run of the "objcopy on compressed debug sections" test for an
8276 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8278 if (cie
->augmentation
[0] == 'z')
8280 READ_ULEB (augmentation_data_len
, start
, end
);
8281 augmentation_data
= start
;
8282 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8283 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8285 warn (_("Augmentation data too long: 0x%s, "
8286 "expected at most %#lx\n"),
8287 dwarf_vmatoa ("x", augmentation_data_len
),
8288 (unsigned long) (end
- start
));
8290 augmentation_data
= NULL
;
8291 augmentation_data_len
= 0;
8293 start
+= augmentation_data_len
;
8296 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8297 (unsigned long)(saved_start
- section_start
),
8298 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8299 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8300 (unsigned long)(cie
->chunk_start
- section_start
));
8302 if (fc
->segment_size
)
8303 printf ("%04lx:", segment_selector
);
8306 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8307 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8309 if (! do_debug_frames_interp
&& augmentation_data_len
)
8311 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8316 /* At this point, fc is the current chunk, cie (if any) is set, and
8317 we're about to interpret instructions for the chunk. */
8318 /* ??? At present we need to do this always, since this sizes the
8319 fc->col_type and fc->col_offset arrays, which we write into always.
8320 We should probably split the interpreted and non-interpreted bits
8321 into two different routines, since there's so much that doesn't
8322 really overlap between them. */
8323 if (1 || do_debug_frames_interp
)
8325 /* Start by making a pass over the chunk, allocating storage
8326 and taking note of what registers are used. */
8327 unsigned char *tmp
= start
;
8329 while (start
< block_end
)
8331 unsigned int reg
, op
, opa
;
8333 unsigned char * new_start
;
8340 /* Warning: if you add any more cases to this switch, be
8341 sure to add them to the corresponding switch below. */
8344 case DW_CFA_advance_loc
:
8347 SKIP_ULEB (start
, end
);
8348 if (frame_need_space (fc
, opa
) >= 0)
8349 fc
->col_type
[opa
] = DW_CFA_undefined
;
8351 case DW_CFA_restore
:
8352 if (frame_need_space (fc
, opa
) >= 0)
8353 fc
->col_type
[opa
] = DW_CFA_undefined
;
8355 case DW_CFA_set_loc
:
8356 start
+= encoded_ptr_size
;
8358 case DW_CFA_advance_loc1
:
8361 case DW_CFA_advance_loc2
:
8364 case DW_CFA_advance_loc4
:
8367 case DW_CFA_offset_extended
:
8368 case DW_CFA_val_offset
:
8369 READ_ULEB (reg
, start
, end
);
8370 SKIP_ULEB (start
, end
);
8371 if (frame_need_space (fc
, reg
) >= 0)
8372 fc
->col_type
[reg
] = DW_CFA_undefined
;
8374 case DW_CFA_restore_extended
:
8375 READ_ULEB (reg
, start
, end
);
8376 if (frame_need_space (fc
, reg
) >= 0)
8377 fc
->col_type
[reg
] = DW_CFA_undefined
;
8379 case DW_CFA_undefined
:
8380 READ_ULEB (reg
, start
, end
);
8381 if (frame_need_space (fc
, reg
) >= 0)
8382 fc
->col_type
[reg
] = DW_CFA_undefined
;
8384 case DW_CFA_same_value
:
8385 READ_ULEB (reg
, start
, end
);
8386 if (frame_need_space (fc
, reg
) >= 0)
8387 fc
->col_type
[reg
] = DW_CFA_undefined
;
8389 case DW_CFA_register
:
8390 READ_ULEB (reg
, start
, end
);
8391 SKIP_ULEB (start
, end
);
8392 if (frame_need_space (fc
, reg
) >= 0)
8393 fc
->col_type
[reg
] = DW_CFA_undefined
;
8395 case DW_CFA_def_cfa
:
8396 SKIP_ULEB (start
, end
);
8397 SKIP_ULEB (start
, end
);
8399 case DW_CFA_def_cfa_register
:
8400 SKIP_ULEB (start
, end
);
8402 case DW_CFA_def_cfa_offset
:
8403 SKIP_ULEB (start
, end
);
8405 case DW_CFA_def_cfa_expression
:
8406 READ_ULEB (temp
, start
, end
);
8407 new_start
= start
+ temp
;
8408 if (new_start
< start
)
8410 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8416 case DW_CFA_expression
:
8417 case DW_CFA_val_expression
:
8418 READ_ULEB (reg
, start
, end
);
8419 READ_ULEB (temp
, start
, end
);
8420 new_start
= start
+ temp
;
8421 if (new_start
< start
)
8423 /* PR 17512: file:306-192417-0.005. */
8424 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8429 if (frame_need_space (fc
, reg
) >= 0)
8430 fc
->col_type
[reg
] = DW_CFA_undefined
;
8432 case DW_CFA_offset_extended_sf
:
8433 case DW_CFA_val_offset_sf
:
8434 READ_ULEB (reg
, start
, end
);
8435 SKIP_SLEB (start
, end
);
8436 if (frame_need_space (fc
, reg
) >= 0)
8437 fc
->col_type
[reg
] = DW_CFA_undefined
;
8439 case DW_CFA_def_cfa_sf
:
8440 SKIP_ULEB (start
, end
);
8441 SKIP_SLEB (start
, end
);
8443 case DW_CFA_def_cfa_offset_sf
:
8444 SKIP_SLEB (start
, end
);
8446 case DW_CFA_MIPS_advance_loc8
:
8449 case DW_CFA_GNU_args_size
:
8450 SKIP_ULEB (start
, end
);
8452 case DW_CFA_GNU_negative_offset_extended
:
8453 READ_ULEB (reg
, start
, end
);
8454 SKIP_ULEB (start
, end
);
8455 if (frame_need_space (fc
, reg
) >= 0)
8456 fc
->col_type
[reg
] = DW_CFA_undefined
;
8467 /* Now we know what registers are used, make a second pass over
8468 the chunk, this time actually printing out the info. */
8470 while (start
< block_end
)
8472 unsigned char * tmp
;
8474 unsigned long ul
, roffs
;
8475 /* Note: It is tempting to use an unsigned long for 'reg' but there
8476 are various functions, notably frame_space_needed() that assume that
8477 reg is an unsigned int. */
8482 const char *reg_prefix
= "";
8489 /* Make a note if something other than DW_CFA_nop happens. */
8490 if (op
!= DW_CFA_nop
)
8493 /* Warning: if you add any more cases to this switch, be
8494 sure to add them to the corresponding switch above. */
8497 case DW_CFA_advance_loc
:
8498 if (do_debug_frames_interp
)
8499 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8501 printf (" DW_CFA_advance_loc: %d to %s\n",
8502 opa
* fc
->code_factor
,
8503 dwarf_vmatoa_1 (NULL
,
8504 fc
->pc_begin
+ opa
* fc
->code_factor
,
8506 fc
->pc_begin
+= opa
* fc
->code_factor
;
8510 READ_ULEB (roffs
, start
, end
);
8511 if (opa
>= (unsigned int) fc
->ncols
)
8512 reg_prefix
= bad_reg
;
8513 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8514 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
8515 reg_prefix
, regname (opa
, 0),
8516 roffs
* fc
->data_factor
);
8517 if (*reg_prefix
== '\0')
8519 fc
->col_type
[opa
] = DW_CFA_offset
;
8520 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8524 case DW_CFA_restore
:
8525 if (opa
>= (unsigned int) fc
->ncols
)
8526 reg_prefix
= bad_reg
;
8527 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8528 printf (" DW_CFA_restore: %s%s\n",
8529 reg_prefix
, regname (opa
, 0));
8530 if (*reg_prefix
!= '\0')
8533 if (opa
>= (unsigned int) cie
->ncols
8534 || (do_debug_frames_interp
8535 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
8537 fc
->col_type
[opa
] = DW_CFA_undefined
;
8538 fc
->col_offset
[opa
] = 0;
8542 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8543 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8547 case DW_CFA_set_loc
:
8548 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
8549 if (do_debug_frames_interp
)
8550 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8552 printf (" DW_CFA_set_loc: %s\n",
8553 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
8557 case DW_CFA_advance_loc1
:
8558 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
8559 if (do_debug_frames_interp
)
8560 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8562 printf (" DW_CFA_advance_loc1: %ld to %s\n",
8563 (unsigned long) (ofs
* fc
->code_factor
),
8564 dwarf_vmatoa_1 (NULL
,
8565 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8567 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8570 case DW_CFA_advance_loc2
:
8571 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
8572 if (do_debug_frames_interp
)
8573 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8575 printf (" DW_CFA_advance_loc2: %ld to %s\n",
8576 (unsigned long) (ofs
* fc
->code_factor
),
8577 dwarf_vmatoa_1 (NULL
,
8578 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8580 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8583 case DW_CFA_advance_loc4
:
8584 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
8585 if (do_debug_frames_interp
)
8586 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8588 printf (" DW_CFA_advance_loc4: %ld to %s\n",
8589 (unsigned long) (ofs
* fc
->code_factor
),
8590 dwarf_vmatoa_1 (NULL
,
8591 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8593 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8596 case DW_CFA_offset_extended
:
8597 READ_ULEB (reg
, start
, end
);
8598 READ_ULEB (roffs
, start
, end
);
8599 if (reg
>= (unsigned int) fc
->ncols
)
8600 reg_prefix
= bad_reg
;
8601 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8602 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
8603 reg_prefix
, regname (reg
, 0),
8604 roffs
* fc
->data_factor
);
8605 if (*reg_prefix
== '\0')
8607 fc
->col_type
[reg
] = DW_CFA_offset
;
8608 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8612 case DW_CFA_val_offset
:
8613 READ_ULEB (reg
, start
, end
);
8614 READ_ULEB (roffs
, start
, end
);
8615 if (reg
>= (unsigned int) fc
->ncols
)
8616 reg_prefix
= bad_reg
;
8617 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8618 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
8619 reg_prefix
, regname (reg
, 0),
8620 roffs
* fc
->data_factor
);
8621 if (*reg_prefix
== '\0')
8623 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8624 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8628 case DW_CFA_restore_extended
:
8629 READ_ULEB (reg
, start
, end
);
8630 if (reg
>= (unsigned int) fc
->ncols
)
8631 reg_prefix
= bad_reg
;
8632 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8633 printf (" DW_CFA_restore_extended: %s%s\n",
8634 reg_prefix
, regname (reg
, 0));
8635 if (*reg_prefix
!= '\0')
8638 if (reg
>= (unsigned int) cie
->ncols
)
8640 fc
->col_type
[reg
] = DW_CFA_undefined
;
8641 fc
->col_offset
[reg
] = 0;
8645 fc
->col_type
[reg
] = cie
->col_type
[reg
];
8646 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
8650 case DW_CFA_undefined
:
8651 READ_ULEB (reg
, start
, end
);
8652 if (reg
>= (unsigned int) fc
->ncols
)
8653 reg_prefix
= bad_reg
;
8654 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8655 printf (" DW_CFA_undefined: %s%s\n",
8656 reg_prefix
, regname (reg
, 0));
8657 if (*reg_prefix
== '\0')
8659 fc
->col_type
[reg
] = DW_CFA_undefined
;
8660 fc
->col_offset
[reg
] = 0;
8664 case DW_CFA_same_value
:
8665 READ_ULEB (reg
, start
, end
);
8666 if (reg
>= (unsigned int) fc
->ncols
)
8667 reg_prefix
= bad_reg
;
8668 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8669 printf (" DW_CFA_same_value: %s%s\n",
8670 reg_prefix
, regname (reg
, 0));
8671 if (*reg_prefix
== '\0')
8673 fc
->col_type
[reg
] = DW_CFA_same_value
;
8674 fc
->col_offset
[reg
] = 0;
8678 case DW_CFA_register
:
8679 READ_ULEB (reg
, start
, end
);
8680 READ_ULEB (roffs
, start
, end
);
8681 if (reg
>= (unsigned int) fc
->ncols
)
8682 reg_prefix
= bad_reg
;
8683 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8685 printf (" DW_CFA_register: %s%s in ",
8686 reg_prefix
, regname (reg
, 0));
8687 puts (regname (roffs
, 0));
8689 if (*reg_prefix
== '\0')
8691 fc
->col_type
[reg
] = DW_CFA_register
;
8692 fc
->col_offset
[reg
] = roffs
;
8696 case DW_CFA_remember_state
:
8697 if (! do_debug_frames_interp
)
8698 printf (" DW_CFA_remember_state\n");
8699 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8700 rs
->cfa_offset
= fc
->cfa_offset
;
8701 rs
->cfa_reg
= fc
->cfa_reg
;
8703 rs
->cfa_exp
= fc
->cfa_exp
;
8704 rs
->ncols
= fc
->ncols
;
8705 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
8706 sizeof (* rs
->col_type
));
8707 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
8708 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
8709 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
8710 rs
->next
= remembered_state
;
8711 remembered_state
= rs
;
8714 case DW_CFA_restore_state
:
8715 if (! do_debug_frames_interp
)
8716 printf (" DW_CFA_restore_state\n");
8717 rs
= remembered_state
;
8720 remembered_state
= rs
->next
;
8721 fc
->cfa_offset
= rs
->cfa_offset
;
8722 fc
->cfa_reg
= rs
->cfa_reg
;
8724 fc
->cfa_exp
= rs
->cfa_exp
;
8725 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
8727 warn (_("Invalid column number in saved frame state\n"));
8731 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
8732 memcpy (fc
->col_offset
, rs
->col_offset
,
8733 rs
->ncols
* sizeof (* rs
->col_offset
));
8734 free (rs
->col_type
);
8735 free (rs
->col_offset
);
8738 else if (do_debug_frames_interp
)
8739 printf ("Mismatched DW_CFA_restore_state\n");
8742 case DW_CFA_def_cfa
:
8743 READ_ULEB (fc
->cfa_reg
, start
, end
);
8744 READ_ULEB (fc
->cfa_offset
, start
, end
);
8746 if (! do_debug_frames_interp
)
8747 printf (" DW_CFA_def_cfa: %s ofs %d\n",
8748 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8751 case DW_CFA_def_cfa_register
:
8752 READ_ULEB (fc
->cfa_reg
, start
, end
);
8754 if (! do_debug_frames_interp
)
8755 printf (" DW_CFA_def_cfa_register: %s\n",
8756 regname (fc
->cfa_reg
, 0));
8759 case DW_CFA_def_cfa_offset
:
8760 READ_ULEB (fc
->cfa_offset
, start
, end
);
8761 if (! do_debug_frames_interp
)
8762 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
8766 if (! do_debug_frames_interp
)
8767 printf (" DW_CFA_nop\n");
8770 case DW_CFA_def_cfa_expression
:
8771 READ_ULEB (ul
, start
, end
);
8772 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
8774 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
8777 if (! do_debug_frames_interp
)
8779 printf (" DW_CFA_def_cfa_expression (");
8780 decode_location_expression (start
, eh_addr_size
, 0, -1,
8788 case DW_CFA_expression
:
8789 READ_ULEB (reg
, start
, end
);
8790 READ_ULEB (ul
, start
, end
);
8791 if (reg
>= (unsigned int) fc
->ncols
)
8792 reg_prefix
= bad_reg
;
8793 /* PR 17512: file: 069-133014-0.006. */
8794 /* PR 17512: file: 98c02eb4. */
8796 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8798 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
8801 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8803 printf (" DW_CFA_expression: %s%s (",
8804 reg_prefix
, regname (reg
, 0));
8805 decode_location_expression (start
, eh_addr_size
, 0, -1,
8809 if (*reg_prefix
== '\0')
8810 fc
->col_type
[reg
] = DW_CFA_expression
;
8814 case DW_CFA_val_expression
:
8815 READ_ULEB (reg
, start
, end
);
8816 READ_ULEB (ul
, start
, end
);
8817 if (reg
>= (unsigned int) fc
->ncols
)
8818 reg_prefix
= bad_reg
;
8820 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8822 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
8825 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8827 printf (" DW_CFA_val_expression: %s%s (",
8828 reg_prefix
, regname (reg
, 0));
8829 decode_location_expression (start
, eh_addr_size
, 0, -1,
8833 if (*reg_prefix
== '\0')
8834 fc
->col_type
[reg
] = DW_CFA_val_expression
;
8838 case DW_CFA_offset_extended_sf
:
8839 READ_ULEB (reg
, start
, end
);
8840 READ_SLEB (l
, start
, end
);
8841 if (frame_need_space (fc
, reg
) < 0)
8842 reg_prefix
= bad_reg
;
8843 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8844 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8845 reg_prefix
, regname (reg
, 0),
8846 (long)(l
* fc
->data_factor
));
8847 if (*reg_prefix
== '\0')
8849 fc
->col_type
[reg
] = DW_CFA_offset
;
8850 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8854 case DW_CFA_val_offset_sf
:
8855 READ_ULEB (reg
, start
, end
);
8856 READ_SLEB (l
, start
, end
);
8857 if (frame_need_space (fc
, reg
) < 0)
8858 reg_prefix
= bad_reg
;
8859 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8860 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8861 reg_prefix
, regname (reg
, 0),
8862 (long)(l
* fc
->data_factor
));
8863 if (*reg_prefix
== '\0')
8865 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8866 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8870 case DW_CFA_def_cfa_sf
:
8871 READ_ULEB (fc
->cfa_reg
, start
, end
);
8872 READ_ULEB (fc
->cfa_offset
, start
, end
);
8873 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
8875 if (! do_debug_frames_interp
)
8876 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8877 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8880 case DW_CFA_def_cfa_offset_sf
:
8881 READ_ULEB (fc
->cfa_offset
, start
, end
);
8882 fc
->cfa_offset
*= fc
->data_factor
;
8883 if (! do_debug_frames_interp
)
8884 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
8887 case DW_CFA_MIPS_advance_loc8
:
8888 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
8889 if (do_debug_frames_interp
)
8890 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8892 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8893 (unsigned long) (ofs
* fc
->code_factor
),
8894 dwarf_vmatoa_1 (NULL
,
8895 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8897 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8900 case DW_CFA_GNU_window_save
:
8901 if (! do_debug_frames_interp
)
8902 printf (" DW_CFA_GNU_window_save\n");
8905 case DW_CFA_GNU_args_size
:
8906 READ_ULEB (ul
, start
, end
);
8907 if (! do_debug_frames_interp
)
8908 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
8911 case DW_CFA_GNU_negative_offset_extended
:
8912 READ_ULEB (reg
, start
, end
);
8913 READ_SLEB (l
, start
, end
);
8915 if (frame_need_space (fc
, reg
) < 0)
8916 reg_prefix
= bad_reg
;
8917 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8918 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8919 reg_prefix
, regname (reg
, 0),
8920 (long)(l
* fc
->data_factor
));
8921 if (*reg_prefix
== '\0')
8923 fc
->col_type
[reg
] = DW_CFA_offset
;
8924 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8929 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
8930 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
8932 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
8937 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8938 if (do_debug_frames_interp
&& ! all_nops
)
8939 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8941 if (fde_fc
.col_type
!= NULL
)
8943 free (fde_fc
.col_type
);
8944 fde_fc
.col_type
= NULL
;
8946 if (fde_fc
.col_offset
!= NULL
)
8948 free (fde_fc
.col_offset
);
8949 fde_fc
.col_offset
= NULL
;
8953 eh_addr_size
= saved_eh_addr_size
;
8958 while (remembered_state
!= NULL
)
8960 rs
= remembered_state
;
8961 remembered_state
= rs
->next
;
8962 free (rs
->col_type
);
8963 free (rs
->col_offset
);
8964 rs
->next
= NULL
; /* Paranoia. */
8968 while (chunks
!= NULL
)
8972 free (rs
->col_type
);
8973 free (rs
->col_offset
);
8974 rs
->next
= NULL
; /* Paranoia. */
8978 while (forward_refs
!= NULL
)
8981 forward_refs
= rs
->next
;
8982 free (rs
->col_type
);
8983 free (rs
->col_offset
);
8984 rs
->next
= NULL
; /* Paranoia. */
8994 display_debug_names (struct dwarf_section
*section
, void *file
)
8996 unsigned char *hdrptr
= section
->start
;
8997 dwarf_vma unit_length
;
8998 unsigned char *unit_start
;
8999 const unsigned char *const section_end
= section
->start
+ section
->size
;
9000 unsigned char *unit_end
;
9002 introduce (section
, FALSE
);
9004 load_debug_section_with_follow (str
, file
);
9006 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9008 unsigned int offset_size
;
9009 uint16_t dwarf_version
, padding
;
9010 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9011 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9012 uint32_t augmentation_string_size
;
9014 unsigned long sec_off
;
9015 bfd_boolean augmentation_printable
;
9016 const char *augmentation_string
;
9018 unit_start
= hdrptr
;
9020 /* Get and check the length of the block. */
9021 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9023 if (unit_length
== 0xffffffff)
9025 /* This section is 64-bit DWARF. */
9026 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9031 unit_end
= hdrptr
+ unit_length
;
9033 sec_off
= hdrptr
- section
->start
;
9034 if (sec_off
+ unit_length
< sec_off
9035 || sec_off
+ unit_length
> section
->size
)
9037 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9039 (unsigned long) (unit_start
- section
->start
),
9040 dwarf_vmatoa ("x", unit_length
));
9044 /* Get and check the version number. */
9045 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9046 printf (_("Version %ld\n"), (long) dwarf_version
);
9048 /* Prior versions did not exist, and future versions may not be
9049 backwards compatible. */
9050 if (dwarf_version
!= 5)
9052 warn (_("Only DWARF version 5 .debug_names "
9053 "is currently supported.\n"));
9057 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9059 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9062 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9063 if (comp_unit_count
== 0)
9064 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9066 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9067 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9068 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9069 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9070 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9072 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9073 if (augmentation_string_size
% 4 != 0)
9075 warn (_("Augmentation string length %u must be rounded up "
9076 "to a multiple of 4 in .debug_names.\n"),
9077 augmentation_string_size
);
9078 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9081 printf (_("Augmentation string:"));
9083 augmentation_printable
= TRUE
;
9084 augmentation_string
= (const char *) hdrptr
;
9086 for (i
= 0; i
< augmentation_string_size
; i
++)
9090 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9091 printf (" %02x", uc
);
9093 if (uc
!= 0 && !ISPRINT (uc
))
9094 augmentation_printable
= FALSE
;
9097 if (augmentation_printable
)
9101 i
< augmentation_string_size
&& augmentation_string
[i
];
9103 putchar (augmentation_string
[i
]);
9108 printf (_("CU table:\n"));
9109 for (i
= 0; i
< comp_unit_count
; i
++)
9113 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9114 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9118 printf (_("TU table:\n"));
9119 for (i
= 0; i
< local_type_unit_count
; i
++)
9123 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9124 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9128 printf (_("Foreign TU table:\n"));
9129 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9133 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9134 printf (_("[%3u] "), i
);
9135 print_dwarf_vma (signature
, 8);
9140 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9141 hdrptr
+= bucket_count
* sizeof (uint32_t);
9142 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9143 hdrptr
+= name_count
* sizeof (uint32_t);
9144 unsigned char *const name_table_string_offsets
= hdrptr
;
9145 hdrptr
+= name_count
* offset_size
;
9146 unsigned char *const name_table_entry_offsets
= hdrptr
;
9147 hdrptr
+= name_count
* offset_size
;
9148 unsigned char *const abbrev_table
= hdrptr
;
9149 hdrptr
+= abbrev_table_size
;
9150 const unsigned char *const abbrev_table_end
= hdrptr
;
9151 unsigned char *const entry_pool
= hdrptr
;
9152 if (hdrptr
> unit_end
)
9154 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9155 "for unit 0x%lx in the debug_names\n"),
9156 (long) (hdrptr
- section
->start
),
9157 (long) (unit_end
- section
->start
),
9158 (long) (unit_start
- section
->start
));
9162 size_t buckets_filled
= 0;
9164 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9166 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9171 printf (ngettext ("Used %zu of %lu bucket.\n",
9172 "Used %zu of %lu buckets.\n",
9174 buckets_filled
, (unsigned long) bucket_count
);
9176 uint32_t hash_prev
= 0;
9177 size_t hash_clash_count
= 0;
9178 size_t longest_clash
= 0;
9179 size_t this_length
= 0;
9181 for (hashi
= 0; hashi
< name_count
; hashi
++)
9183 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9187 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9191 longest_clash
= MAX (longest_clash
, this_length
);
9196 hash_prev
= hash_this
;
9198 printf (_("Out of %lu items there are %zu bucket clashes"
9199 " (longest of %zu entries).\n"),
9200 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9201 assert (name_count
== buckets_filled
+ hash_clash_count
);
9203 struct abbrev_lookup_entry
9205 dwarf_vma abbrev_tag
;
9206 unsigned char *abbrev_lookup_ptr
;
9208 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9209 size_t abbrev_lookup_used
= 0;
9210 size_t abbrev_lookup_allocated
= 0;
9212 unsigned char *abbrevptr
= abbrev_table
;
9215 dwarf_vma abbrev_tag
;
9217 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9218 if (abbrev_tag
== 0)
9220 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9222 abbrev_lookup_allocated
= MAX (0x100,
9223 abbrev_lookup_allocated
* 2);
9224 abbrev_lookup
= xrealloc (abbrev_lookup
,
9225 (abbrev_lookup_allocated
9226 * sizeof (*abbrev_lookup
)));
9228 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9229 struct abbrev_lookup_entry
*entry
;
9230 for (entry
= abbrev_lookup
;
9231 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9233 if (entry
->abbrev_tag
== abbrev_tag
)
9235 warn (_("Duplicate abbreviation tag %lu "
9236 "in unit 0x%lx in the debug_names\n"),
9237 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9240 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9241 entry
->abbrev_tag
= abbrev_tag
;
9242 entry
->abbrev_lookup_ptr
= abbrevptr
;
9244 /* Skip DWARF tag. */
9245 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9248 dwarf_vma xindex
, form
;
9250 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9251 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9252 if (xindex
== 0 && form
== 0)
9257 printf (_("\nSymbol table:\n"));
9259 for (namei
= 0; namei
< name_count
; ++namei
)
9261 uint64_t string_offset
, entry_offset
;
9263 SAFE_BYTE_GET (string_offset
,
9264 name_table_string_offsets
+ namei
* offset_size
,
9265 offset_size
, unit_end
);
9266 SAFE_BYTE_GET (entry_offset
,
9267 name_table_entry_offsets
+ namei
* offset_size
,
9268 offset_size
, unit_end
);
9270 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9271 fetch_indirect_string (string_offset
));
9273 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9275 /* We need to scan first whether there is a single or multiple
9276 entries. TAGNO is -2 for the first entry, it is -1 for the
9277 initial tag read of the second entry, then it becomes 0 for the
9278 first entry for real printing etc. */
9280 /* Initialize it due to a false compiler warning. */
9281 dwarf_vma second_abbrev_tag
= -1;
9284 dwarf_vma abbrev_tag
;
9285 dwarf_vma dwarf_tag
;
9286 const struct abbrev_lookup_entry
*entry
;
9288 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9291 second_abbrev_tag
= abbrev_tag
;
9293 entryptr
= entry_pool
+ entry_offset
;
9296 if (abbrev_tag
== 0)
9300 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9301 (unsigned long) abbrev_tag
);
9303 for (entry
= abbrev_lookup
;
9304 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9306 if (entry
->abbrev_tag
== abbrev_tag
)
9308 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9310 warn (_("Undefined abbreviation tag %lu "
9311 "in unit 0x%lx in the debug_names\n"),
9313 (long) (unit_start
- section
->start
));
9316 abbrevptr
= entry
->abbrev_lookup_ptr
;
9317 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9319 printf (" %s", get_TAG_name (dwarf_tag
));
9322 dwarf_vma xindex
, form
;
9324 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9325 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9326 if (xindex
== 0 && form
== 0)
9330 printf (" %s", get_IDX_name (xindex
));
9331 entryptr
= read_and_display_attr_value (0, form
, 0,
9332 unit_start
, entryptr
, unit_end
,
9334 dwarf_version
, NULL
,
9341 printf (_(" <no entries>"));
9345 free (abbrev_lookup
);
9352 display_debug_links (struct dwarf_section
* section
,
9353 void * file ATTRIBUTE_UNUSED
)
9355 const unsigned char * filename
;
9356 unsigned int filelen
;
9358 introduce (section
, FALSE
);
9360 /* The .gnu_debuglink section is formatted as:
9361 (c-string) Filename.
9362 (padding) If needed to reach a 4 byte boundary.
9363 (uint32_t) CRC32 value.
9365 The .gun_debugaltlink section is formatted as:
9366 (c-string) Filename.
9367 (binary) Build-ID. */
9369 filename
= section
->start
;
9370 filelen
= strnlen ((const char *) filename
, section
->size
);
9371 if (filelen
== section
->size
)
9373 warn (_("The debuglink filename is corrupt/missing\n"));
9377 printf (_(" Separate debug info file: %s\n"), filename
);
9379 if (const_strneq (section
->name
, ".gnu_debuglink"))
9382 unsigned int crc_offset
;
9384 crc_offset
= filelen
+ 1;
9385 crc_offset
= (crc_offset
+ 3) & ~3;
9386 if (crc_offset
+ 4 > section
->size
)
9388 warn (_("CRC offset missing/truncated\n"));
9392 crc32
= byte_get (filename
+ crc_offset
, 4);
9394 printf (_(" CRC value: %#x\n"), crc32
);
9396 if (crc_offset
+ 4 < section
->size
)
9398 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9399 (long)(section
->size
- (crc_offset
+ 4)));
9403 else /* const_strneq (section->name, ".gnu_debugaltlink") */
9405 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9406 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9407 bfd_size_type printed
;
9409 /* FIXME: Should we support smaller build-id notes ? */
9410 if (build_id_len
< 0x14)
9412 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9416 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9417 display_data (printed
, build_id
, build_id_len
);
9426 display_gdb_index (struct dwarf_section
*section
,
9427 void *file ATTRIBUTE_UNUSED
)
9429 unsigned char *start
= section
->start
;
9431 uint32_t cu_list_offset
, tu_list_offset
;
9432 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
9433 unsigned int cu_list_elements
, tu_list_elements
;
9434 unsigned int address_table_size
, symbol_table_slots
;
9435 unsigned char *cu_list
, *tu_list
;
9436 unsigned char *address_table
, *symbol_table
, *constant_pool
;
9439 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
9441 introduce (section
, FALSE
);
9443 if (section
->size
< 6 * sizeof (uint32_t))
9445 warn (_("Truncated header in the %s section.\n"), section
->name
);
9449 version
= byte_get_little_endian (start
, 4);
9450 printf (_("Version %ld\n"), (long) version
);
9452 /* Prior versions are obsolete, and future versions may not be
9453 backwards compatible. */
9454 if (version
< 3 || version
> 8)
9456 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
9460 warn (_("The address table data in version 3 may be wrong.\n"));
9462 warn (_("Version 4 does not support case insensitive lookups.\n"));
9464 warn (_("Version 5 does not include inlined functions.\n"));
9466 warn (_("Version 6 does not include symbol attributes.\n"));
9467 /* Version 7 indices generated by Gold have bad type unit references,
9468 PR binutils/15021. But we don't know if the index was generated by
9469 Gold or not, so to avoid worrying users with gdb-generated indices
9470 we say nothing for version 7 here. */
9472 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
9473 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
9474 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
9475 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
9476 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
9478 if (cu_list_offset
> section
->size
9479 || tu_list_offset
> section
->size
9480 || address_table_offset
> section
->size
9481 || symbol_table_offset
> section
->size
9482 || constant_pool_offset
> section
->size
)
9484 warn (_("Corrupt header in the %s section.\n"), section
->name
);
9488 /* PR 17531: file: 418d0a8a. */
9489 if (tu_list_offset
< cu_list_offset
)
9491 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
9492 tu_list_offset
, cu_list_offset
);
9496 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
9498 if (address_table_offset
< tu_list_offset
)
9500 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
9501 address_table_offset
, tu_list_offset
);
9505 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
9507 /* PR 17531: file: 18a47d3d. */
9508 if (symbol_table_offset
< address_table_offset
)
9510 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
9511 symbol_table_offset
, address_table_offset
);
9515 address_table_size
= symbol_table_offset
- address_table_offset
;
9517 if (constant_pool_offset
< symbol_table_offset
)
9519 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
9520 constant_pool_offset
, symbol_table_offset
);
9524 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
9526 cu_list
= start
+ cu_list_offset
;
9527 tu_list
= start
+ tu_list_offset
;
9528 address_table
= start
+ address_table_offset
;
9529 symbol_table
= start
+ symbol_table_offset
;
9530 constant_pool
= start
+ constant_pool_offset
;
9532 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
9534 warn (_("Address table extends beyond end of section.\n"));
9538 printf (_("\nCU table:\n"));
9539 for (i
= 0; i
< cu_list_elements
; i
+= 2)
9541 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
9542 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
9544 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
9545 (unsigned long) cu_offset
,
9546 (unsigned long) (cu_offset
+ cu_length
- 1));
9549 printf (_("\nTU table:\n"));
9550 for (i
= 0; i
< tu_list_elements
; i
+= 3)
9552 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
9553 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
9554 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
9556 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
9557 (unsigned long) tu_offset
,
9558 (unsigned long) type_offset
);
9559 print_dwarf_vma (signature
, 8);
9563 printf (_("\nAddress table:\n"));
9564 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
9567 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
9568 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
9569 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
9571 print_dwarf_vma (low
, 8);
9572 print_dwarf_vma (high
, 8);
9573 printf (_("%lu\n"), (unsigned long) cu_index
);
9576 printf (_("\nSymbol table:\n"));
9577 for (i
= 0; i
< symbol_table_slots
; ++i
)
9579 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
9580 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
9581 uint32_t num_cus
, cu
;
9583 if (name_offset
!= 0
9584 || cu_vector_offset
!= 0)
9587 unsigned char * adr
;
9589 adr
= constant_pool
+ name_offset
;
9590 /* PR 17531: file: 5b7b07ad. */
9591 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
9593 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
9594 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
9598 printf ("[%3u] %.*s:", i
,
9599 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
9600 constant_pool
+ name_offset
);
9602 adr
= constant_pool
+ cu_vector_offset
;
9603 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
9605 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
9606 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
9607 cu_vector_offset
, i
);
9611 num_cus
= byte_get_little_endian (adr
, 4);
9613 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
9614 if (num_cus
* 4 < num_cus
9615 || adr
>= section
->start
+ section
->size
9616 || adr
< constant_pool
)
9618 printf ("<invalid number of CUs: %d>\n", num_cus
);
9619 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
9627 for (j
= 0; j
< num_cus
; ++j
)
9630 gdb_index_symbol_kind kind
;
9632 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
9633 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
9634 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
9635 cu
= GDB_INDEX_CU_VALUE (cu
);
9636 /* Convert to TU number if it's for a type unit. */
9637 if (cu
>= cu_list_elements
/ 2)
9638 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
9639 (unsigned long) (cu
- cu_list_elements
/ 2));
9641 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
9643 printf (" [%s, %s]",
9644 is_static
? _("static") : _("global"),
9645 get_gdb_index_symbol_kind_name (kind
));
9657 /* Pre-allocate enough space for the CU/TU sets needed. */
9660 prealloc_cu_tu_list (unsigned int nshndx
)
9662 if (shndx_pool
== NULL
)
9664 shndx_pool_size
= nshndx
;
9665 shndx_pool_used
= 0;
9666 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
9667 sizeof (unsigned int));
9671 shndx_pool_size
= shndx_pool_used
+ nshndx
;
9672 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
9673 sizeof (unsigned int));
9678 add_shndx_to_cu_tu_entry (unsigned int shndx
)
9680 if (shndx_pool_used
>= shndx_pool_size
)
9682 error (_("Internal error: out of space in the shndx pool.\n"));
9685 shndx_pool
[shndx_pool_used
++] = shndx
;
9689 end_cu_tu_entry (void)
9691 if (shndx_pool_used
>= shndx_pool_size
)
9693 error (_("Internal error: out of space in the shndx pool.\n"));
9696 shndx_pool
[shndx_pool_used
++] = 0;
9699 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
9702 get_DW_SECT_short_name (unsigned int dw_sect
)
9704 static char buf
[16];
9712 case DW_SECT_ABBREV
:
9718 case DW_SECT_STR_OFFSETS
:
9720 case DW_SECT_MACINFO
:
9728 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
9732 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
9733 These sections are extensions for Fission.
9734 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
9737 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
9739 unsigned char *phdr
= section
->start
;
9740 unsigned char *limit
= phdr
+ section
->size
;
9741 unsigned char *phash
;
9742 unsigned char *pindex
;
9743 unsigned char *ppool
;
9744 unsigned int version
;
9745 unsigned int ncols
= 0;
9747 unsigned int nslots
;
9750 dwarf_vma signature_high
;
9751 dwarf_vma signature_low
;
9754 /* PR 17512: file: 002-168123-0.004. */
9757 warn (_("Section %s is empty\n"), section
->name
);
9760 /* PR 17512: file: 002-376-0.004. */
9761 if (section
->size
< 24)
9763 warn (_("Section %s is too small to contain a CU/TU header\n"),
9768 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
9770 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
9771 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
9772 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
9775 pindex
= phash
+ (size_t) nslots
* 8;
9776 ppool
= pindex
+ (size_t) nslots
* 4;
9780 introduce (section
, FALSE
);
9782 printf (_(" Version: %u\n"), version
);
9784 printf (_(" Number of columns: %u\n"), ncols
);
9785 printf (_(" Number of used entries: %u\n"), nused
);
9786 printf (_(" Number of slots: %u\n\n"), nslots
);
9789 /* PR 17531: file: 45d69832. */
9790 if ((size_t) nslots
* 8 / 8 != nslots
9791 || phash
< phdr
|| phash
> limit
9792 || pindex
< phash
|| pindex
> limit
9793 || ppool
< pindex
|| ppool
> limit
)
9795 warn (ngettext ("Section %s is too small for %u slot\n",
9796 "Section %s is too small for %u slots\n",
9798 section
->name
, nslots
);
9805 prealloc_cu_tu_list ((limit
- ppool
) / 4);
9806 for (i
= 0; i
< nslots
; i
++)
9808 unsigned char *shndx_list
;
9811 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
9812 if (signature_high
!= 0 || signature_low
!= 0)
9814 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
9815 shndx_list
= ppool
+ j
* 4;
9816 /* PR 17531: file: 705e010d. */
9817 if (shndx_list
< ppool
)
9819 warn (_("Section index pool located before start of section\n"));
9824 printf (_(" [%3d] Signature: 0x%s Sections: "),
9825 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9826 buf
, sizeof (buf
)));
9829 if (shndx_list
>= limit
)
9831 warn (_("Section %s too small for shndx pool\n"),
9835 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
9839 printf (" %d", shndx
);
9841 add_shndx_to_cu_tu_entry (shndx
);
9853 else if (version
== 2)
9856 unsigned int dw_sect
;
9857 unsigned char *ph
= phash
;
9858 unsigned char *pi
= pindex
;
9859 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
9860 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
9861 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
9862 bfd_boolean is_tu_index
;
9863 struct cu_tu_set
*this_set
= NULL
;
9865 unsigned char *prow
;
9867 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
9869 /* PR 17531: file: 0dd159bf.
9870 Check for integer overflow (can occur when size_t is 32-bit)
9871 with overlarge ncols or nused values. */
9873 && ((size_t) ncols
* 4 / 4 != ncols
9874 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
9875 || poffsets
< ppool
|| poffsets
> limit
9876 || psizes
< poffsets
|| psizes
> limit
9877 || pend
< psizes
|| pend
> limit
))
9879 warn (_("Section %s too small for offset and size tables\n"),
9886 printf (_(" Offset table\n"));
9887 printf (" slot %-16s ",
9888 is_tu_index
? _("signature") : _("dwo_id"));
9895 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9901 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9908 for (j
= 0; j
< ncols
; j
++)
9910 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9911 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
9916 for (i
= 0; i
< nslots
; i
++)
9918 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9920 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9923 /* PR 17531: file: a05f6ab3. */
9926 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9933 size_t num_copy
= sizeof (uint64_t);
9935 /* PR 23064: Beware of buffer overflow. */
9936 if (ph
+ num_copy
< limit
)
9937 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
9940 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
9945 prow
= poffsets
+ (row
- 1) * ncols
* 4;
9946 /* PR 17531: file: b8ce60a8. */
9947 if (prow
< poffsets
|| prow
> limit
)
9949 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9955 printf (_(" [%3d] 0x%s"),
9956 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9957 buf
, sizeof (buf
)));
9958 for (j
= 0; j
< ncols
; j
++)
9960 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9962 printf (" %8d", val
);
9965 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9967 /* PR 17531: file: 10796eb3. */
9968 if (dw_sect
>= DW_SECT_MAX
)
9969 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9971 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
9987 printf (_(" Size table\n"));
9988 printf (" slot %-16s ",
9989 is_tu_index
? _("signature") : _("dwo_id"));
9992 for (j
= 0; j
< ncols
; j
++)
9994 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
9996 printf (" %8s", get_DW_SECT_short_name (val
));
10002 for (i
= 0; i
< nslots
; i
++)
10004 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10006 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10009 prow
= psizes
+ (row
- 1) * ncols
* 4;
10012 printf (_(" [%3d] 0x%s"),
10013 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10014 buf
, sizeof (buf
)));
10016 for (j
= 0; j
< ncols
; j
++)
10018 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10020 printf (" %8d", val
);
10023 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10024 if (dw_sect
>= DW_SECT_MAX
)
10025 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10027 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10039 else if (do_display
)
10040 printf (_(" Unsupported version (%d)\n"), version
);
10048 /* Load the CU and TU indexes if present. This will build a list of
10049 section sets that we can use to associate a .debug_info.dwo section
10050 with its associated .debug_abbrev.dwo section in a .dwp file. */
10053 load_cu_tu_indexes (void *file
)
10055 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10057 /* If we have already loaded (or tried to load) the CU and TU indexes
10058 then do not bother to repeat the task. */
10059 if (cu_tu_indexes_read
== -1)
10061 cu_tu_indexes_read
= TRUE
;
10063 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10064 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10065 cu_tu_indexes_read
= FALSE
;
10067 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10068 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10069 cu_tu_indexes_read
= FALSE
;
10072 return (bfd_boolean
) cu_tu_indexes_read
;
10075 /* Find the set of sections that includes section SHNDX. */
10078 find_cu_tu_set (void *file
, unsigned int shndx
)
10082 if (! load_cu_tu_indexes (file
))
10085 /* Find SHNDX in the shndx pool. */
10086 for (i
= 0; i
< shndx_pool_used
; i
++)
10087 if (shndx_pool
[i
] == shndx
)
10090 if (i
>= shndx_pool_used
)
10093 /* Now backup to find the first entry in the set. */
10094 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10097 return shndx_pool
+ i
;
10100 /* Display a .debug_cu_index or .debug_tu_index section. */
10103 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10105 return process_cu_tu_index (section
, 1);
10109 display_debug_not_supported (struct dwarf_section
*section
,
10110 void *file ATTRIBUTE_UNUSED
)
10112 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10118 /* Like malloc, but takes two parameters like calloc.
10119 Verifies that the first parameter is not too large.
10120 Note: does *not* initialise the allocated memory to zero. */
10123 cmalloc (size_t nmemb
, size_t size
)
10125 /* Check for overflow. */
10126 if (nmemb
>= ~(size_t) 0 / size
)
10129 return xmalloc (nmemb
* size
);
10132 /* Like xmalloc, but takes two parameters like calloc.
10133 Verifies that the first parameter is not too large.
10134 Note: does *not* initialise the allocated memory to zero. */
10137 xcmalloc (size_t nmemb
, size_t size
)
10139 /* Check for overflow. */
10140 if (nmemb
>= ~(size_t) 0 / size
)
10143 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10148 return xmalloc (nmemb
* size
);
10151 /* Like xrealloc, but takes three parameters.
10152 Verifies that the second parameter is not too large.
10153 Note: does *not* initialise any new memory to zero. */
10156 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10158 /* Check for overflow. */
10159 if (nmemb
>= ~(size_t) 0 / size
)
10161 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10166 return xrealloc (ptr
, nmemb
* size
);
10169 /* Like xcalloc, but verifies that the first parameter is not too large. */
10172 xcalloc2 (size_t nmemb
, size_t size
)
10174 /* Check for overflow. */
10175 if (nmemb
>= ~(size_t) 0 / size
)
10177 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10182 return xcalloc (nmemb
, size
);
10185 static unsigned long
10186 calc_gnu_debuglink_crc32 (unsigned long crc
,
10187 const unsigned char * buf
,
10190 static const unsigned long crc32_table
[256] =
10192 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10193 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10194 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10195 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10196 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10197 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10198 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10199 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10200 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10201 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10202 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10203 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10204 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10205 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10206 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10207 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10208 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10209 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10210 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10211 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10212 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10213 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10214 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10215 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10216 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10217 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10218 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10219 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10220 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10221 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10222 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10223 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10224 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10225 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10226 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10227 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10228 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10229 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10230 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10231 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10232 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10233 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10234 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10235 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10236 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10237 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10238 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10239 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10240 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10241 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10242 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10245 const unsigned char *end
;
10247 crc
= ~crc
& 0xffffffff;
10248 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10249 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10250 return ~crc
& 0xffffffff;
10253 typedef bfd_boolean (* check_func_type
) (const char *, void *);
10254 typedef const char * (* parse_func_type
) (struct dwarf_section
*, void *);
10257 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10259 static unsigned char buffer
[8 * 1024];
10261 bfd_size_type count
;
10262 unsigned long crc
= 0;
10265 sep_data
= open_debug_file (pathname
);
10266 if (sep_data
== NULL
)
10269 /* Yes - we are opening the file twice... */
10270 f
= fopen (pathname
, "rb");
10273 /* Paranoia: This should never happen. */
10274 close_debug_file (sep_data
);
10275 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10279 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10280 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10284 if (crc
!= * (unsigned long *) crc_pointer
)
10286 close_debug_file (sep_data
);
10287 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10295 static const char *
10296 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10299 unsigned int crc_offset
;
10300 unsigned long * crc32
= (unsigned long *) data
;
10302 /* The name is first.
10303 The CRC value is stored after the filename, aligned up to 4 bytes. */
10304 name
= (const char *) section
->start
;
10307 crc_offset
= strnlen (name
, section
->size
) + 1;
10308 crc_offset
= (crc_offset
+ 3) & ~3;
10309 if (crc_offset
+ 4 > section
->size
)
10312 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10317 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10319 void * sep_data
= open_debug_file (filename
);
10321 if (sep_data
== NULL
)
10324 /* FIXME: We should now extract the build-id in the separate file
10330 typedef struct build_id_data
10333 const unsigned char * data
;
10336 static const char *
10337 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10340 bfd_size_type namelen
;
10341 bfd_size_type id_len
;
10342 Build_id_data
* build_id_data
;
10344 /* The name is first.
10345 The build-id follows immediately, with no padding, up to the section's end. */
10347 name
= (const char *) section
->start
;
10348 namelen
= strnlen (name
, section
->size
) + 1;
10349 if (namelen
>= section
->size
)
10352 id_len
= section
->size
- namelen
;
10356 build_id_data
= (Build_id_data
*) data
;
10357 build_id_data
->len
= id_len
;
10358 build_id_data
->data
= section
->start
+ namelen
;
10364 add_separate_debug_file (const char * filename
, void * handle
)
10366 separate_info
* i
= xmalloc (sizeof * i
);
10368 i
->filename
= filename
;
10369 i
->handle
= handle
;
10370 i
->next
= first_separate_info
;
10371 first_separate_info
= i
;
10374 #if HAVE_LIBDEBUGINFOD
10375 /* Query debuginfod servers for the target debuglink or debugaltlink
10376 file. If successful, store the path of the file in filename and
10377 return TRUE, otherwise return FALSE. */
10380 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10384 size_t build_id_len
;
10385 unsigned char * build_id
;
10387 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10389 /* Get the build-id of file. */
10390 build_id
= get_build_id (file
);
10393 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10395 /* Get the build-id of the debugaltlink file. */
10396 unsigned int filelen
;
10398 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10399 if (filelen
== section
->size
)
10400 /* Corrupt debugaltlink. */
10403 build_id
= section
->start
+ filelen
+ 1;
10404 build_id_len
= section
->size
- (filelen
+ 1);
10406 if (build_id_len
== 0)
10415 debuginfod_client
* client
;
10417 client
= debuginfod_begin ();
10418 if (client
== NULL
)
10421 /* Query debuginfod servers for the target file. If found its path
10422 will be stored in filename. */
10423 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
10424 debuginfod_end (client
);
10426 /* Only free build_id if we allocated space for a hex string
10427 in get_build_id (). */
10428 if (build_id_len
== 0)
10433 /* File successfully retrieved. Close fd since we want to
10434 use open_debug_file () on filename instead. */
10445 load_separate_debug_info (const char * main_filename
,
10446 struct dwarf_section
* xlink
,
10447 parse_func_type parse_func
,
10448 check_func_type check_func
,
10450 void * file ATTRIBUTE_UNUSED
)
10452 const char * separate_filename
;
10453 char * debug_filename
;
10455 size_t canon_dirlen
;
10458 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
10460 warn (_("Corrupt debuglink section: %s\n"),
10461 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
10465 /* Attempt to locate the separate file.
10466 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
10468 canon_dir
= lrealpath (main_filename
);
10470 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
10471 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
10473 canon_dir
[canon_dirlen
] = '\0';
10476 #define DEBUGDIR "/lib/debug"
10478 #ifndef EXTRA_DEBUG_ROOT1
10479 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
10481 #ifndef EXTRA_DEBUG_ROOT2
10482 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
10485 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
10487 + strlen (".debug/")
10488 #ifdef EXTRA_DEBUG_ROOT1
10489 + strlen (EXTRA_DEBUG_ROOT1
)
10491 #ifdef EXTRA_DEBUG_ROOT2
10492 + strlen (EXTRA_DEBUG_ROOT2
)
10494 + strlen (separate_filename
)
10496 if (debug_filename
== NULL
)
10498 warn (_("Out of memory"));
10503 /* First try in the current directory. */
10504 sprintf (debug_filename
, "%s", separate_filename
);
10505 if (check_func (debug_filename
, func_data
))
10508 /* Then try in a subdirectory called .debug. */
10509 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10510 if (check_func (debug_filename
, func_data
))
10513 /* Then try in the same directory as the original file. */
10514 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10515 if (check_func (debug_filename
, func_data
))
10518 /* And the .debug subdirectory of that directory. */
10519 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10520 if (check_func (debug_filename
, func_data
))
10523 #ifdef EXTRA_DEBUG_ROOT1
10524 /* Try the first extra debug file root. */
10525 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10526 if (check_func (debug_filename
, func_data
))
10529 /* Try the first extra debug file root. */
10530 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10531 if (check_func (debug_filename
, func_data
))
10535 #ifdef EXTRA_DEBUG_ROOT2
10536 /* Try the second extra debug file root. */
10537 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10538 if (check_func (debug_filename
, func_data
))
10542 /* Then try in the global debug_filename directory. */
10543 strcpy (debug_filename
, DEBUGDIR
);
10544 dirlen
= strlen (DEBUGDIR
) - 1;
10545 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
10546 strcat (debug_filename
, "/");
10547 strcat (debug_filename
, (const char *) separate_filename
);
10549 if (check_func (debug_filename
, func_data
))
10552 #if HAVE_LIBDEBUGINFOD
10554 char * tmp_filename
;
10556 if (debuginfod_fetch_separate_debug_info (xlink
,
10560 /* File successfully downloaded from server, replace
10561 debug_filename with the file's path. */
10562 free (debug_filename
);
10563 debug_filename
= tmp_filename
;
10569 /* Failed to find the file. */
10570 warn (_("could not find separate debug file '%s'\n"), separate_filename
);
10571 warn (_("tried: %s\n"), debug_filename
);
10573 #ifdef EXTRA_DEBUG_ROOT2
10574 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10575 warn (_("tried: %s\n"), debug_filename
);
10578 #ifdef EXTRA_DEBUG_ROOT1
10579 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10580 warn (_("tried: %s\n"), debug_filename
);
10582 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10583 warn (_("tried: %s\n"), debug_filename
);
10586 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10587 warn (_("tried: %s\n"), debug_filename
);
10589 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10590 warn (_("tried: %s\n"), debug_filename
);
10592 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10593 warn (_("tried: %s\n"), debug_filename
);
10595 sprintf (debug_filename
, "%s", separate_filename
);
10596 warn (_("tried: %s\n"), debug_filename
);
10598 #if HAVE_LIBDEBUGINFOD
10600 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
10604 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
10609 free (debug_filename
);
10615 void * debug_handle
;
10617 /* Now open the file.... */
10618 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
10620 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
10621 free (debug_filename
);
10625 /* FIXME: We do not check to see if there are any other separate debug info
10626 files that would also match. */
10628 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename
, debug_filename
);
10629 add_separate_debug_file (debug_filename
, debug_handle
);
10631 /* Do not free debug_filename - it might be referenced inside
10632 the structure returned by open_debug_file(). */
10633 return debug_handle
;
10636 /* Attempt to load a separate dwarf object file. */
10639 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
10641 char * separate_filename
;
10642 void * separate_handle
;
10644 /* FIXME: Skip adding / if dwo_dir ends in /. */
10645 separate_filename
= concat (dir
, "/", name
, NULL
);
10646 if (separate_filename
== NULL
)
10648 warn (_("Out of memory allocating dwo filename\n"));
10652 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
10654 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
10655 free (separate_filename
);
10659 /* FIXME: We should check the dwo_id. */
10661 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
10662 add_separate_debug_file (separate_filename
, separate_handle
);
10663 /* Note - separate_filename will be freed in free_debug_memory(). */
10664 return separate_handle
;
10667 /* Load the separate debug info file(s) attached to FILE, if any exist.
10668 Returns TRUE if any were found, FALSE otherwise.
10669 If TRUE is returned then the linked list starting at first_separate_info
10670 will be populated with open file handles. */
10673 load_separate_debug_files (void * file
, const char * filename
)
10675 /* Skip this operation if we are not interested in debug links. */
10676 if (! do_follow_links
&& ! do_debug_links
)
10679 /* See if there are any dwo links. */
10680 if (load_debug_section (str
, file
)
10681 && load_debug_section (abbrev
, file
)
10682 && load_debug_section (info
, file
))
10686 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
10688 bfd_boolean introduced
= FALSE
;
10690 const char * dir
= NULL
;
10691 const char * id
= NULL
;
10693 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
10695 switch (dwinfo
->type
)
10698 if (do_debug_links
)
10702 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
10703 debug_displays
[info
].section
.uncompressed_name
);
10707 printf (_(" Name: %s\n"), dwinfo
->value
);
10708 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
10710 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
10712 printf (_(" ID: <unknown>\n"));
10716 if (do_follow_links
)
10717 load_dwo_file (filename
, dwinfo
->value
, dir
, id
);
10721 dir
= dwinfo
->value
;
10725 id
= dwinfo
->value
;
10729 error (_("Unexpected DWO INFO type"));
10736 if (! do_follow_links
)
10737 /* The other debug links will be displayed by display_debug_links()
10738 so we do not need to do any further processing here. */
10741 /* FIXME: We do not check for the presence of both link sections in the same file. */
10742 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
10743 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
10744 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
10746 if (load_debug_section (gnu_debugaltlink
, file
))
10748 Build_id_data build_id_data
;
10750 load_separate_debug_info (filename
,
10751 & debug_displays
[gnu_debugaltlink
].section
,
10752 parse_gnu_debugaltlink
,
10753 check_gnu_debugaltlink
,
10758 if (load_debug_section (gnu_debuglink
, file
))
10760 unsigned long crc32
;
10762 load_separate_debug_info (filename
,
10763 & debug_displays
[gnu_debuglink
].section
,
10764 parse_gnu_debuglink
,
10765 check_gnu_debuglink
,
10770 if (first_separate_info
!= NULL
)
10773 do_follow_links
= 0;
10778 free_debug_memory (void)
10784 for (i
= 0; i
< max
; i
++)
10785 free_debug_section ((enum dwarf_section_display_enum
) i
);
10787 if (debug_information
!= NULL
)
10789 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
10791 if (debug_information
[i
].max_loc_offsets
)
10793 free (debug_information
[i
].loc_offsets
);
10794 free (debug_information
[i
].have_frame_base
);
10796 if (debug_information
[i
].max_range_lists
)
10797 free (debug_information
[i
].range_lists
);
10799 free (debug_information
);
10800 debug_information
= NULL
;
10801 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
10805 separate_info
* next
;
10807 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
10809 close_debug_file (d
->handle
);
10810 free ((void *) d
->filename
);
10814 first_separate_info
= NULL
;
10820 dwarf_select_sections_by_names (const char *names
)
10824 const char * option
;
10828 debug_dump_long_opts
;
10830 static const debug_dump_long_opts opts_table
[] =
10832 /* Please keep this table alpha- sorted. */
10833 { "Ranges", & do_debug_ranges
, 1 },
10834 { "abbrev", & do_debug_abbrevs
, 1 },
10835 { "addr", & do_debug_addr
, 1 },
10836 { "aranges", & do_debug_aranges
, 1 },
10837 { "cu_index", & do_debug_cu_index
, 1 },
10838 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
10839 { "follow-links", & do_follow_links
, 1 },
10840 { "frames", & do_debug_frames
, 1 },
10841 { "frames-interp", & do_debug_frames_interp
, 1 },
10842 /* The special .gdb_index section. */
10843 { "gdb_index", & do_gdb_index
, 1 },
10844 { "info", & do_debug_info
, 1 },
10845 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
10846 { "links", & do_debug_links
, 1 },
10847 { "loc", & do_debug_loc
, 1 },
10848 { "macro", & do_debug_macinfo
, 1 },
10849 { "pubnames", & do_debug_pubnames
, 1 },
10850 { "pubtypes", & do_debug_pubtypes
, 1 },
10851 /* This entry is for compatibility
10852 with earlier versions of readelf. */
10853 { "ranges", & do_debug_aranges
, 1 },
10854 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
10855 { "str", & do_debug_str
, 1 },
10856 { "str-offsets", & do_debug_str_offsets
, 1 },
10857 /* These trace_* sections are used by Itanium VMS. */
10858 { "trace_abbrev", & do_trace_abbrevs
, 1 },
10859 { "trace_aranges", & do_trace_aranges
, 1 },
10860 { "trace_info", & do_trace_info
, 1 },
10869 const debug_dump_long_opts
* entry
;
10871 for (entry
= opts_table
; entry
->option
; entry
++)
10873 size_t len
= strlen (entry
->option
);
10875 if (strncmp (p
, entry
->option
, len
) == 0
10876 && (p
[len
] == ',' || p
[len
] == '\0'))
10878 * entry
->variable
|= entry
->val
;
10880 /* The --debug-dump=frames-interp option also
10881 enables the --debug-dump=frames option. */
10882 if (do_debug_frames_interp
)
10883 do_debug_frames
= 1;
10890 if (entry
->option
== NULL
)
10892 warn (_("Unrecognized debug option '%s'\n"), p
);
10893 p
= strchr (p
, ',');
10904 dwarf_select_sections_by_letters (const char *letters
)
10906 unsigned int lindex
= 0;
10908 while (letters
[lindex
])
10909 switch (letters
[lindex
++])
10911 case 'A': do_debug_addr
= 1; break;
10912 case 'a': do_debug_abbrevs
= 1; break;
10913 case 'c': do_debug_cu_index
= 1; break;
10914 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
10915 case 'f': do_debug_frames
= 1; break;
10916 case 'g': do_gdb_index
= 1; break;
10917 case 'i': do_debug_info
= 1; break;
10918 case 'K': do_follow_links
= 1; break;
10919 case 'k': do_debug_links
= 1; break;
10920 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
10921 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
10922 case 'm': do_debug_macinfo
= 1; break;
10923 case 'O': do_debug_str_offsets
= 1; break;
10924 case 'o': do_debug_loc
= 1; break;
10925 case 'p': do_debug_pubnames
= 1; break;
10926 case 'R': do_debug_ranges
= 1; break;
10927 case 'r': do_debug_aranges
= 1; break;
10928 case 's': do_debug_str
= 1; break;
10929 case 'T': do_trace_aranges
= 1; break;
10930 case 't': do_debug_pubtypes
= 1; break;
10931 case 'U': do_trace_info
= 1; break;
10932 case 'u': do_trace_abbrevs
= 1; break;
10935 warn (_("Unrecognized debug option '%s'\n"), letters
);
10941 dwarf_select_sections_all (void)
10944 do_debug_abbrevs
= 1;
10945 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
10946 do_debug_pubnames
= 1;
10947 do_debug_pubtypes
= 1;
10948 do_debug_aranges
= 1;
10949 do_debug_ranges
= 1;
10950 do_debug_frames
= 1;
10951 do_debug_macinfo
= 1;
10956 do_trace_abbrevs
= 1;
10957 do_trace_aranges
= 1;
10959 do_debug_cu_index
= 1;
10960 do_follow_links
= 1;
10961 do_debug_links
= 1;
10962 do_debug_str_offsets
= 1;
10965 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
10966 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
10968 /* N.B. The order here must match the order in section_display_enum. */
10970 struct dwarf_section_display debug_displays
[] =
10972 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10973 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, TRUE
},
10974 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10975 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, TRUE
},
10976 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10977 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
10978 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
10979 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10980 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10981 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10982 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10983 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10984 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10985 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10986 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
10987 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
10988 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10989 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10990 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10991 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10992 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, TRUE
},
10993 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10994 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, FALSE
},
10995 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, FALSE
},
10996 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, TRUE
},
10997 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
10998 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, FALSE
},
10999 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, TRUE
},
11000 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
11001 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, TRUE
},
11002 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
11003 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11004 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
11005 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
11006 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, TRUE
},
11007 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
11008 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
11009 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, TRUE
},
11010 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
11011 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
11012 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
11013 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
11014 /* Separate debug info files can containt their own .debug_str section,
11015 and this might be in *addition* to a .debug_str section already present
11016 in the main file. Hence we need to have two entries for .debug_str. */
11017 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11020 /* A static assertion. */
11021 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];