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 /* Records a single attribute in an abbrev. */
853 typedef struct abbrev_attr
855 unsigned long attribute
;
857 bfd_signed_vma implicit_const
;
858 struct abbrev_attr
* next
;
862 /* Records a single abbrev. */
863 typedef struct abbrev_entry
865 unsigned long number
;
868 struct abbrev_attr
* first_attr
;
869 struct abbrev_attr
* last_attr
;
870 struct abbrev_entry
* next
;
874 /* Records a set of abbreviations. */
875 typedef struct abbrev_list
877 abbrev_entry
* first_abbrev
;
878 abbrev_entry
* last_abbrev
;
879 dwarf_vma abbrev_base
;
880 dwarf_vma abbrev_offset
;
881 struct abbrev_list
* next
;
882 unsigned char * start_of_next_abbrevs
;
886 /* Records all the abbrevs found so far. */
887 static struct abbrev_list
* abbrev_lists
= NULL
;
889 typedef struct abbrev_map
896 /* Maps between CU offsets and abbrev sets. */
897 static abbrev_map
* cu_abbrev_map
= NULL
;
898 static unsigned long num_abbrev_map_entries
= 0;
899 static unsigned long next_free_abbrev_map_entry
= 0;
901 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
902 #define ABBREV_MAP_ENTRIES_INCREMENT 8
905 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
907 if (cu_abbrev_map
== NULL
)
909 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
910 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
912 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
914 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
915 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
918 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
919 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
920 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
921 next_free_abbrev_map_entry
++;
925 free_all_abbrevs (void)
929 for (list
= abbrev_lists
; list
!= NULL
;)
931 abbrev_list
* next
= list
->next
;
932 abbrev_entry
* abbrv
;
934 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
936 abbrev_entry
* next_abbrev
= abbrv
->next
;
939 for (attr
= abbrv
->first_attr
; attr
;)
941 abbrev_attr
*next_attr
= attr
->next
;
959 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
961 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
963 list
->abbrev_base
= abbrev_base
;
964 list
->abbrev_offset
= abbrev_offset
;
966 list
->next
= abbrev_lists
;
973 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
974 dwarf_vma abbrev_offset
)
978 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
979 if (list
->abbrev_base
== abbrev_base
980 && list
->abbrev_offset
== abbrev_offset
)
986 /* Find the abbreviation map for the CU that includes OFFSET.
987 OFFSET is an absolute offset from the start of the .debug_info section. */
988 /* FIXME: This function is going to slow down readelf & objdump.
989 Consider using a better algorithm to mitigate this effect. */
992 find_abbrev_map_by_offset (dwarf_vma offset
)
996 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
997 if (cu_abbrev_map
[i
].start
<= offset
998 && cu_abbrev_map
[i
].end
> offset
)
999 return cu_abbrev_map
+ i
;
1005 add_abbrev (unsigned long number
,
1010 abbrev_entry
* entry
;
1012 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
1014 entry
->number
= number
;
1016 entry
->children
= children
;
1017 entry
->first_attr
= NULL
;
1018 entry
->last_attr
= NULL
;
1021 assert (list
!= NULL
);
1023 if (list
->first_abbrev
== NULL
)
1024 list
->first_abbrev
= entry
;
1026 list
->last_abbrev
->next
= entry
;
1028 list
->last_abbrev
= entry
;
1032 add_abbrev_attr (unsigned long attribute
,
1034 bfd_signed_vma implicit_const
,
1039 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1041 attr
->attribute
= attribute
;
1043 attr
->implicit_const
= implicit_const
;
1046 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1048 if (list
->last_abbrev
->first_attr
== NULL
)
1049 list
->last_abbrev
->first_attr
= attr
;
1051 list
->last_abbrev
->last_attr
->next
= attr
;
1053 list
->last_abbrev
->last_attr
= attr
;
1056 /* Processes the (partial) contents of a .debug_abbrev section.
1057 Returns NULL if the end of the section was encountered.
1058 Returns the address after the last byte read if the end of
1059 an abbreviation set was found. */
1061 static unsigned char *
1062 process_abbrev_set (unsigned char * start
,
1063 const unsigned char * end
,
1068 unsigned long entry
;
1070 unsigned long attribute
;
1073 READ_ULEB (entry
, start
, end
);
1075 /* A single zero is supposed to end the set according
1076 to the standard. If there's more, then signal that to
1083 READ_ULEB (tag
, start
, end
);
1087 children
= *start
++;
1089 add_abbrev (entry
, tag
, children
, list
);
1094 /* Initialize it due to a false compiler warning. */
1095 bfd_signed_vma implicit_const
= -1;
1097 READ_ULEB (attribute
, start
, end
);
1101 READ_ULEB (form
, start
, end
);
1105 if (form
== DW_FORM_implicit_const
)
1107 READ_SLEB (implicit_const
, start
, end
);
1112 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1114 while (attribute
!= 0);
1117 /* Report the missing single zero which ends the section. */
1118 error (_(".debug_abbrev section not zero terminated\n"));
1124 get_TAG_name (unsigned long tag
)
1126 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1130 static char buffer
[100];
1132 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1133 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1135 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1143 get_FORM_name (unsigned long form
)
1148 return "DW_FORM value: 0";
1150 name
= get_DW_FORM_name (form
);
1153 static char buffer
[100];
1155 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1163 get_IDX_name (unsigned long idx
)
1165 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1169 static char buffer
[100];
1171 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1178 static unsigned char *
1179 display_block (unsigned char *data
,
1181 const unsigned char * const end
, char delimiter
)
1185 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1187 return (unsigned char *) end
;
1189 maxlen
= (dwarf_vma
) (end
- data
);
1190 length
= length
> maxlen
? maxlen
: length
;
1193 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1199 decode_location_expression (unsigned char * data
,
1200 unsigned int pointer_size
,
1201 unsigned int offset_size
,
1204 dwarf_vma cu_offset
,
1205 struct dwarf_section
* section
)
1209 dwarf_signed_vma svalue
;
1210 unsigned char *end
= data
+ length
;
1211 int need_frame_base
= 0;
1220 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1221 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1224 printf ("DW_OP_deref");
1227 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1228 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1231 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1232 printf ("DW_OP_const1s: %ld", (long) svalue
);
1235 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1236 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1239 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1240 printf ("DW_OP_const2s: %ld", (long) svalue
);
1243 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1244 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1247 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1248 printf ("DW_OP_const4s: %ld", (long) svalue
);
1251 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1252 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1253 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1254 printf ("%lu", (unsigned long) uvalue
);
1257 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1258 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1259 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1260 printf ("%ld", (long) svalue
);
1263 READ_ULEB (uvalue
, data
, end
);
1264 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1267 READ_SLEB (svalue
, data
, end
);
1268 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1271 printf ("DW_OP_dup");
1274 printf ("DW_OP_drop");
1277 printf ("DW_OP_over");
1280 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1281 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1284 printf ("DW_OP_swap");
1287 printf ("DW_OP_rot");
1290 printf ("DW_OP_xderef");
1293 printf ("DW_OP_abs");
1296 printf ("DW_OP_and");
1299 printf ("DW_OP_div");
1302 printf ("DW_OP_minus");
1305 printf ("DW_OP_mod");
1308 printf ("DW_OP_mul");
1311 printf ("DW_OP_neg");
1314 printf ("DW_OP_not");
1317 printf ("DW_OP_or");
1320 printf ("DW_OP_plus");
1322 case DW_OP_plus_uconst
:
1323 READ_ULEB (uvalue
, data
, end
);
1324 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1327 printf ("DW_OP_shl");
1330 printf ("DW_OP_shr");
1333 printf ("DW_OP_shra");
1336 printf ("DW_OP_xor");
1339 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1340 printf ("DW_OP_bra: %ld", (long) svalue
);
1343 printf ("DW_OP_eq");
1346 printf ("DW_OP_ge");
1349 printf ("DW_OP_gt");
1352 printf ("DW_OP_le");
1355 printf ("DW_OP_lt");
1358 printf ("DW_OP_ne");
1361 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1362 printf ("DW_OP_skip: %ld", (long) svalue
);
1397 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1432 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1433 regname (op
- DW_OP_reg0
, 1));
1468 READ_SLEB (svalue
, data
, end
);
1469 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1470 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1474 READ_ULEB (uvalue
, data
, end
);
1475 printf ("DW_OP_regx: %s (%s)",
1476 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1479 need_frame_base
= 1;
1480 READ_SLEB (svalue
, data
, end
);
1481 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1484 READ_ULEB (uvalue
, data
, end
);
1485 READ_SLEB (svalue
, data
, end
);
1486 printf ("DW_OP_bregx: %s (%s) %s",
1487 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1488 dwarf_vmatoa ("d", svalue
));
1491 READ_ULEB (uvalue
, data
, end
);
1492 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1494 case DW_OP_deref_size
:
1495 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1496 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1498 case DW_OP_xderef_size
:
1499 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1500 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1503 printf ("DW_OP_nop");
1506 /* DWARF 3 extensions. */
1507 case DW_OP_push_object_address
:
1508 printf ("DW_OP_push_object_address");
1511 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1512 this ought to be an 8-byte wide computation. */
1513 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1514 printf ("DW_OP_call2: <0x%s>",
1515 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1518 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1519 this ought to be an 8-byte wide computation. */
1520 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1521 printf ("DW_OP_call4: <0x%s>",
1522 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1524 case DW_OP_call_ref
:
1525 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1526 this ought to be an 8-byte wide computation. */
1527 if (dwarf_version
== -1)
1529 printf (_("(DW_OP_call_ref in frame info)"));
1530 /* No way to tell where the next op is, so just bail. */
1531 return need_frame_base
;
1533 if (dwarf_version
== 2)
1535 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1539 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1541 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1543 case DW_OP_form_tls_address
:
1544 printf ("DW_OP_form_tls_address");
1546 case DW_OP_call_frame_cfa
:
1547 printf ("DW_OP_call_frame_cfa");
1549 case DW_OP_bit_piece
:
1550 printf ("DW_OP_bit_piece: ");
1551 READ_ULEB (uvalue
, data
, end
);
1552 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1553 READ_ULEB (uvalue
, data
, end
);
1554 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1557 /* DWARF 4 extensions. */
1558 case DW_OP_stack_value
:
1559 printf ("DW_OP_stack_value");
1562 case DW_OP_implicit_value
:
1563 printf ("DW_OP_implicit_value");
1564 READ_ULEB (uvalue
, data
, end
);
1565 data
= display_block (data
, uvalue
, end
, ' ');
1568 /* GNU extensions. */
1569 case DW_OP_GNU_push_tls_address
:
1570 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1572 case DW_OP_GNU_uninit
:
1573 printf ("DW_OP_GNU_uninit");
1574 /* FIXME: Is there data associated with this OP ? */
1576 case DW_OP_GNU_encoded_addr
:
1583 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1585 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1586 print_dwarf_vma (addr
, pointer_size
);
1589 case DW_OP_implicit_pointer
:
1590 case DW_OP_GNU_implicit_pointer
:
1591 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1592 this ought to be an 8-byte wide computation. */
1593 if (dwarf_version
== -1)
1595 printf (_("(%s in frame info)"),
1596 (op
== DW_OP_implicit_pointer
1597 ? "DW_OP_implicit_pointer"
1598 : "DW_OP_GNU_implicit_pointer"));
1599 /* No way to tell where the next op is, so just bail. */
1600 return need_frame_base
;
1602 if (dwarf_version
== 2)
1604 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1608 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1610 READ_SLEB (svalue
, data
, end
);
1611 printf ("%s: <0x%s> %s",
1612 (op
== DW_OP_implicit_pointer
1613 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1614 dwarf_vmatoa ("x", uvalue
),
1615 dwarf_vmatoa ("d", svalue
));
1617 case DW_OP_entry_value
:
1618 case DW_OP_GNU_entry_value
:
1619 READ_ULEB (uvalue
, data
, end
);
1620 /* PR 17531: file: 0cc9cd00. */
1621 if (uvalue
> (dwarf_vma
) (end
- data
))
1622 uvalue
= end
- data
;
1623 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1624 : "DW_OP_GNU_entry_value"));
1625 if (decode_location_expression (data
, pointer_size
, offset_size
,
1626 dwarf_version
, uvalue
,
1627 cu_offset
, section
))
1628 need_frame_base
= 1;
1634 case DW_OP_const_type
:
1635 case DW_OP_GNU_const_type
:
1636 READ_ULEB (uvalue
, data
, end
);
1637 printf ("%s: <0x%s> ",
1638 (op
== DW_OP_const_type
? "DW_OP_const_type"
1639 : "DW_OP_GNU_const_type"),
1640 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1641 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1642 data
= display_block (data
, uvalue
, end
, ' ');
1644 case DW_OP_regval_type
:
1645 case DW_OP_GNU_regval_type
:
1646 READ_ULEB (uvalue
, data
, end
);
1647 printf ("%s: %s (%s)",
1648 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1649 : "DW_OP_GNU_regval_type"),
1650 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1651 READ_ULEB (uvalue
, data
, end
);
1652 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1654 case DW_OP_deref_type
:
1655 case DW_OP_GNU_deref_type
:
1656 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1658 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1659 : "DW_OP_GNU_deref_type"),
1661 READ_ULEB (uvalue
, data
, end
);
1662 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1665 case DW_OP_GNU_convert
:
1666 READ_ULEB (uvalue
, data
, end
);
1667 printf ("%s <0x%s>",
1668 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1669 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1671 case DW_OP_reinterpret
:
1672 case DW_OP_GNU_reinterpret
:
1673 READ_ULEB (uvalue
, data
, end
);
1674 printf ("%s <0x%s>",
1675 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1676 : "DW_OP_GNU_reinterpret"),
1677 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1679 case DW_OP_GNU_parameter_ref
:
1680 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1681 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1682 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1684 case DW_OP_GNU_addr_index
:
1685 READ_ULEB (uvalue
, data
, end
);
1686 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1688 case DW_OP_GNU_const_index
:
1689 READ_ULEB (uvalue
, data
, end
);
1690 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1692 case DW_OP_GNU_variable_value
:
1693 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1694 this ought to be an 8-byte wide computation. */
1695 if (dwarf_version
== -1)
1697 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1698 /* No way to tell where the next op is, so just bail. */
1699 return need_frame_base
;
1701 if (dwarf_version
== 2)
1703 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1707 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1709 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1712 /* HP extensions. */
1713 case DW_OP_HP_is_value
:
1714 printf ("DW_OP_HP_is_value");
1715 /* FIXME: Is there data associated with this OP ? */
1717 case DW_OP_HP_fltconst4
:
1718 printf ("DW_OP_HP_fltconst4");
1719 /* FIXME: Is there data associated with this OP ? */
1721 case DW_OP_HP_fltconst8
:
1722 printf ("DW_OP_HP_fltconst8");
1723 /* FIXME: Is there data associated with this OP ? */
1725 case DW_OP_HP_mod_range
:
1726 printf ("DW_OP_HP_mod_range");
1727 /* FIXME: Is there data associated with this OP ? */
1729 case DW_OP_HP_unmod_range
:
1730 printf ("DW_OP_HP_unmod_range");
1731 /* FIXME: Is there data associated with this OP ? */
1734 printf ("DW_OP_HP_tls");
1735 /* FIXME: Is there data associated with this OP ? */
1738 /* PGI (STMicroelectronics) extensions. */
1739 case DW_OP_PGI_omp_thread_num
:
1740 /* Pushes the thread number for the current thread as it would be
1741 returned by the standard OpenMP library function:
1742 omp_get_thread_num(). The "current thread" is the thread for
1743 which the expression is being evaluated. */
1744 printf ("DW_OP_PGI_omp_thread_num");
1748 if (op
>= DW_OP_lo_user
1749 && op
<= DW_OP_hi_user
)
1750 printf (_("(User defined location op 0x%x)"), op
);
1752 printf (_("(Unknown location op 0x%x)"), op
);
1753 /* No way to tell where the next op is, so just bail. */
1754 return need_frame_base
;
1757 /* Separate the ops. */
1762 return need_frame_base
;
1765 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1766 This is used for DWARF package files. */
1768 static struct cu_tu_set
*
1769 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1771 struct cu_tu_set
*p
;
1773 unsigned int dw_sect
;
1779 dw_sect
= DW_SECT_TYPES
;
1785 dw_sect
= DW_SECT_INFO
;
1789 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1797 /* Add INC to HIGH_BITS:LOW_BITS. */
1799 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1801 dwarf_vma tmp
= * low_bits
;
1805 /* FIXME: There is probably a better way of handling this:
1807 We need to cope with dwarf_vma being a 32-bit or 64-bit
1808 type. Plus regardless of its size LOW_BITS is meant to
1809 only hold 32-bits, so if there is overflow or wrap around
1810 we must propagate into HIGH_BITS. */
1811 if (tmp
< * low_bits
)
1815 else if (sizeof (tmp
) > 8
1826 fetch_alt_indirect_string (dwarf_vma offset
)
1830 if (! do_follow_links
)
1833 if (first_separate_info
== NULL
)
1834 return _("<no links available>");
1836 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1838 struct dwarf_section
* section
;
1841 if (! load_debug_section (separate_debug_str
, i
->handle
))
1844 section
= &debug_displays
[separate_debug_str
].section
;
1846 if (section
->start
== NULL
)
1849 if (offset
>= section
->size
)
1852 ret
= (const char *) (section
->start
+ offset
);
1853 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1854 NUL byte. Since our caller is expecting to receive a well formed C
1855 string we test for the lack of a terminating byte here. */
1856 if (strnlen ((const char *) ret
, section
->size
- offset
)
1857 == section
->size
- offset
)
1858 return _("<no NUL byte at end of alt .debug_str section>");
1863 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1864 dwarf_vmatoa ("x", offset
));
1865 return _("<offset is too big>");
1869 get_AT_name (unsigned long attribute
)
1874 return "DW_AT value: 0";
1876 /* One value is shared by the MIPS and HP extensions: */
1877 if (attribute
== DW_AT_MIPS_fde
)
1878 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1880 name
= get_DW_AT_name (attribute
);
1884 static char buffer
[100];
1886 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1895 add_dwo_info (const char * field
, dwo_type type
)
1897 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1899 dwinfo
->type
= type
;
1900 dwinfo
->value
= field
;
1901 dwinfo
->next
= first_dwo_info
;
1902 first_dwo_info
= dwinfo
;
1906 add_dwo_name (const char * name
)
1908 add_dwo_info (name
, DWO_NAME
);
1912 add_dwo_dir (const char * dir
)
1914 add_dwo_info (dir
, DWO_DIR
);
1918 add_dwo_id (const char * id
)
1920 add_dwo_info (id
, DWO_ID
);
1924 free_dwo_info (void)
1929 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1931 next
= dwinfo
->next
;
1934 first_dwo_info
= NULL
;
1937 /* Ensure that START + UVALUE is less than END.
1938 Return an adjusted UVALUE if necessary to ensure this relationship. */
1940 static inline dwarf_vma
1941 check_uvalue (const unsigned char * start
,
1943 const unsigned char * end
)
1945 dwarf_vma max_uvalue
= end
- start
;
1947 /* See PR 17512: file: 008-103549-0.001:0.1.
1948 and PR 24829 for examples of where these tests are triggered. */
1949 if (uvalue
> max_uvalue
)
1951 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1952 uvalue
= max_uvalue
;
1958 static unsigned char *
1959 skip_attr_bytes (unsigned long form
,
1960 unsigned char * data
,
1961 unsigned const char * end
,
1962 dwarf_vma pointer_size
,
1963 dwarf_vma offset_size
,
1965 dwarf_vma
* value_return
)
1967 dwarf_signed_vma svalue
;
1968 dwarf_vma uvalue
= 0;
1974 case DW_FORM_ref_addr
:
1975 if (dwarf_version
== 2)
1976 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1977 else if (dwarf_version
> 2)
1978 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1984 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1988 case DW_FORM_line_strp
:
1989 case DW_FORM_sec_offset
:
1990 case DW_FORM_GNU_ref_alt
:
1991 case DW_FORM_GNU_strp_alt
:
1992 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1995 case DW_FORM_flag_present
:
2002 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2007 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2012 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2016 READ_SLEB (svalue
, data
, end
);
2020 case DW_FORM_ref_udata
:
2022 case DW_FORM_GNU_str_index
:
2023 case DW_FORM_GNU_addr_index
:
2024 READ_ULEB (uvalue
, data
, end
);
2029 case DW_FORM_ref_sig8
:
2033 case DW_FORM_data16
:
2037 case DW_FORM_string
:
2038 data
+= strnlen ((char *) data
, end
- data
) + 1;
2042 case DW_FORM_exprloc
:
2043 READ_ULEB (uvalue
, data
, end
);
2047 case DW_FORM_block1
:
2048 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
2052 case DW_FORM_block2
:
2053 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2057 case DW_FORM_block4
:
2058 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2062 case DW_FORM_indirect
:
2063 READ_ULEB (form
, data
, end
);
2064 if (form
== DW_FORM_implicit_const
)
2065 SKIP_ULEB (data
, end
);
2066 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
, value_return
);
2072 * value_return
= uvalue
;
2074 data
= (unsigned char *) end
;
2078 /* Given form FORM with value UVALUE, locate and return the abbreviation
2079 associated with it. */
2081 static abbrev_entry
*
2082 get_type_abbrev_from_form (unsigned long form
,
2083 unsigned long uvalue
,
2084 dwarf_vma cu_offset
,
2085 const struct dwarf_section
* section
,
2086 unsigned long * abbrev_num_return
,
2087 unsigned char ** data_return
,
2088 unsigned long * cu_offset_return
)
2090 unsigned long abbrev_number
;
2092 abbrev_entry
* entry
;
2093 unsigned char * data
;
2095 if (abbrev_num_return
!= NULL
)
2096 * abbrev_num_return
= 0;
2097 if (data_return
!= NULL
)
2098 * data_return
= NULL
;
2102 case DW_FORM_GNU_ref_alt
:
2103 /* FIXME: We are unable to handle this form at the moment. */
2106 case DW_FORM_ref_addr
:
2107 if (uvalue
>= section
->size
)
2109 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2110 uvalue
, (long) section
->size
, section
->name
);
2118 case DW_FORM_ref_udata
:
2119 if (uvalue
+ cu_offset
> section
->size
)
2121 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2122 uvalue
, (long) cu_offset
, (long) section
->size
);
2125 uvalue
+= cu_offset
;
2128 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2131 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2135 data
= (unsigned char *) section
->start
+ uvalue
;
2136 map
= find_abbrev_map_by_offset (uvalue
);
2140 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2143 if (map
->list
== NULL
)
2145 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2149 if (cu_offset_return
!= NULL
)
2151 if (form
== DW_FORM_ref_addr
)
2152 * cu_offset_return
= map
->start
;
2154 * cu_offset_return
= cu_offset
;
2157 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2159 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2160 if (entry
->number
== abbrev_number
)
2163 if (abbrev_num_return
!= NULL
)
2164 * abbrev_num_return
= abbrev_number
;
2166 if (data_return
!= NULL
)
2167 * data_return
= data
;
2170 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2175 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2176 can be determined to be a signed type. The data for ENTRY can be
2177 found starting at DATA. */
2180 get_type_signedness (abbrev_entry
* entry
,
2181 const struct dwarf_section
* section
,
2182 unsigned char * data
,
2183 unsigned const char * end
,
2184 dwarf_vma cu_offset
,
2185 dwarf_vma pointer_size
,
2186 dwarf_vma offset_size
,
2188 bfd_boolean
* is_signed
,
2189 unsigned int nesting
)
2193 * is_signed
= FALSE
;
2195 #define MAX_NESTING 20
2196 if (nesting
> MAX_NESTING
)
2198 /* FIXME: Warn - or is this expected ?
2199 NB/ We need to avoid infinite recursion. */
2203 for (attr
= entry
->first_attr
;
2204 attr
!= NULL
&& attr
->attribute
;
2207 unsigned char * orig_data
= data
;
2208 dwarf_vma uvalue
= 0;
2210 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2211 offset_size
, dwarf_version
, & uvalue
);
2215 switch (attr
->attribute
)
2217 case DW_AT_linkage_name
:
2221 if (attr
->form
== DW_FORM_strp
)
2222 printf (", %s", fetch_indirect_string (uvalue
));
2223 else if (attr
->form
== DW_FORM_string
)
2224 printf (", %s", orig_data
);
2231 abbrev_entry
* type_abbrev
;
2232 unsigned char * type_data
;
2233 unsigned long type_cu_offset
;
2235 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2239 NULL
/* abbrev num return */,
2242 if (type_abbrev
== NULL
)
2245 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2246 pointer_size
, offset_size
, dwarf_version
,
2247 is_signed
, nesting
+ 1);
2251 case DW_AT_encoding
:
2252 /* Determine signness. */
2255 case DW_ATE_address
:
2256 /* FIXME - some architectures have signed addresses. */
2257 case DW_ATE_boolean
:
2258 case DW_ATE_unsigned
:
2259 case DW_ATE_unsigned_char
:
2260 case DW_ATE_unsigned_fixed
:
2261 * is_signed
= FALSE
;
2265 case DW_ATE_complex_float
:
2268 case DW_ATE_signed_char
:
2269 case DW_ATE_imaginary_float
:
2270 case DW_ATE_decimal_float
:
2271 case DW_ATE_signed_fixed
:
2281 read_and_print_leb128 (unsigned char * data
,
2282 unsigned int * bytes_read
,
2283 unsigned const char * end
,
2284 bfd_boolean is_signed
)
2287 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2289 report_leb_status (status
, __FILE__
, __LINE__
);
2291 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2295 display_discr_list (unsigned long form
,
2297 unsigned char * data
,
2298 unsigned const char * end
,
2303 printf ("[default]");
2310 case DW_FORM_block1
:
2311 case DW_FORM_block2
:
2312 case DW_FORM_block4
:
2313 /* Move data pointer back to the start of the byte array. */
2317 printf ("<corrupt>\n");
2318 warn (_("corrupt discr_list - not using a block form\n"));
2324 printf ("<corrupt>\n");
2325 warn (_("corrupt discr_list - block not long enough\n"));
2329 bfd_boolean is_signed
=
2330 (level
> 0 && level
<= MAX_CU_NESTING
)
2331 ? level_type_signed
[level
- 1] : FALSE
;
2336 unsigned char discriminant
;
2337 unsigned int bytes_read
;
2339 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2343 assert (uvalue
> 0);
2344 switch (discriminant
)
2348 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2349 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2350 uvalue
-= bytes_read
;
2356 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2357 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2358 uvalue
-= bytes_read
;
2362 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2363 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2364 uvalue
-= bytes_read
;
2369 printf ("<corrupt>\n");
2370 warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"),
2380 printf (")(signed)");
2382 printf (")(unsigned)");
2385 static unsigned char *
2386 read_and_display_attr_value (unsigned long attribute
,
2388 dwarf_signed_vma implicit_const
,
2389 unsigned char * start
,
2390 unsigned char * data
,
2391 unsigned char * end
,
2392 dwarf_vma cu_offset
,
2393 dwarf_vma pointer_size
,
2394 dwarf_vma offset_size
,
2396 debug_info
* debug_info_p
,
2398 struct dwarf_section
* section
,
2399 struct cu_tu_set
* this_set
,
2403 dwarf_signed_vma svalue
;
2404 dwarf_vma uvalue
= 0;
2405 unsigned char * block_start
= NULL
;
2406 unsigned char * orig_data
= data
;
2408 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2410 warn (_("Corrupt attribute\n"));
2419 case DW_FORM_ref_addr
:
2420 if (dwarf_version
== 2)
2421 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2422 else if (dwarf_version
> 2)
2423 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2425 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2429 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2433 case DW_FORM_line_strp
:
2434 case DW_FORM_sec_offset
:
2435 case DW_FORM_GNU_ref_alt
:
2436 case DW_FORM_GNU_strp_alt
:
2437 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2440 case DW_FORM_flag_present
:
2447 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2452 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2457 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2461 READ_SLEB (svalue
, data
, end
);
2465 case DW_FORM_GNU_str_index
:
2466 case DW_FORM_ref_udata
:
2468 case DW_FORM_GNU_addr_index
:
2469 READ_ULEB (uvalue
, data
, end
);
2472 case DW_FORM_indirect
:
2473 READ_ULEB (form
, data
, end
);
2475 printf ("%c%s", delimiter
, get_FORM_name (form
));
2476 if (form
== DW_FORM_implicit_const
)
2477 READ_SLEB (implicit_const
, data
, end
);
2478 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2480 cu_offset
, pointer_size
,
2481 offset_size
, dwarf_version
,
2482 debug_info_p
, do_loc
,
2483 section
, this_set
, delimiter
, level
);
2488 case DW_FORM_ref_addr
:
2490 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2493 case DW_FORM_GNU_ref_alt
:
2495 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2496 /* FIXME: Follow the reference... */
2502 case DW_FORM_ref_udata
:
2504 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2509 case DW_FORM_sec_offset
:
2511 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2514 case DW_FORM_flag_present
:
2521 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2524 case DW_FORM_implicit_const
:
2526 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2533 dwarf_vma high_bits
;
2537 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2539 if (form
== DW_FORM_ref8
)
2540 add64 (& high_bits
, & utmp
, cu_offset
);
2541 printf ("%c0x%s", delimiter
,
2542 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2545 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2546 && num_debug_info_entries
== 0)
2548 if (sizeof (uvalue
) == 8)
2549 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2551 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2557 case DW_FORM_data16
:
2560 dwarf_vma left_high_bits
, left_low_bits
;
2561 dwarf_vma right_high_bits
, right_low_bits
;
2563 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2564 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2565 if (byte_get
== byte_get_little_endian
)
2568 left_high_bits
^= right_high_bits
;
2569 right_high_bits
^= left_high_bits
;
2570 left_high_bits
^= right_high_bits
;
2571 left_low_bits
^= right_low_bits
;
2572 right_low_bits
^= left_low_bits
;
2573 left_low_bits
^= right_low_bits
;
2575 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2576 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2577 left_high_bits
, left_low_bits
, right_high_bits
,
2583 case DW_FORM_string
:
2585 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2586 data
+= strnlen ((char *) data
, end
- data
) + 1;
2590 case DW_FORM_exprloc
:
2591 READ_ULEB (uvalue
, data
, end
);
2594 if (block_start
>= end
)
2596 warn (_("Block ends prematurely\n"));
2601 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2604 data
= block_start
+ uvalue
;
2606 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2609 case DW_FORM_block1
:
2610 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2613 case DW_FORM_block2
:
2614 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2617 case DW_FORM_block4
:
2618 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2623 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2624 dwarf_vmatoa ("x", uvalue
),
2625 fetch_indirect_string (uvalue
));
2628 case DW_FORM_line_strp
:
2630 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2631 dwarf_vmatoa ("x", uvalue
),
2632 fetch_indirect_line_string (uvalue
));
2635 case DW_FORM_GNU_str_index
:
2638 const char * suffix
= strrchr (section
->name
, '.');
2639 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
2641 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2642 dwarf_vmatoa ("x", uvalue
),
2643 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2647 case DW_FORM_GNU_strp_alt
:
2650 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2651 dwarf_vmatoa ("x", uvalue
),
2652 fetch_alt_indirect_string (uvalue
));
2656 case DW_FORM_indirect
:
2657 /* Handled above. */
2660 case DW_FORM_ref_sig8
:
2663 dwarf_vma high_bits
;
2666 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2667 printf ("%csignature: 0x%s", delimiter
,
2668 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2673 case DW_FORM_GNU_addr_index
:
2675 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2676 dwarf_vmatoa ("x", uvalue
),
2677 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2681 warn (_("Unrecognized form: %lu\n"), form
);
2685 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2686 && num_debug_info_entries
== 0
2687 && debug_info_p
!= NULL
)
2691 case DW_AT_frame_base
:
2692 have_frame_base
= 1;
2694 case DW_AT_location
:
2695 case DW_AT_GNU_locviews
:
2696 case DW_AT_string_length
:
2697 case DW_AT_return_addr
:
2698 case DW_AT_data_member_location
:
2699 case DW_AT_vtable_elem_location
:
2701 case DW_AT_static_link
:
2702 case DW_AT_use_location
:
2703 case DW_AT_call_value
:
2704 case DW_AT_GNU_call_site_value
:
2705 case DW_AT_call_data_value
:
2706 case DW_AT_GNU_call_site_data_value
:
2707 case DW_AT_call_target
:
2708 case DW_AT_GNU_call_site_target
:
2709 case DW_AT_call_target_clobbered
:
2710 case DW_AT_GNU_call_site_target_clobbered
:
2711 if ((dwarf_version
< 4
2712 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2713 || form
== DW_FORM_sec_offset
)
2715 /* Process location list. */
2716 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2717 unsigned int num
= debug_info_p
->num_loc_offsets
;
2719 if (lmax
== 0 || num
>= lmax
)
2722 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2723 xcrealloc (debug_info_p
->loc_offsets
,
2724 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2725 debug_info_p
->loc_views
= (dwarf_vma
*)
2726 xcrealloc (debug_info_p
->loc_views
,
2727 lmax
, sizeof (*debug_info_p
->loc_views
));
2728 debug_info_p
->have_frame_base
= (int *)
2729 xcrealloc (debug_info_p
->have_frame_base
,
2730 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2731 debug_info_p
->max_loc_offsets
= lmax
;
2733 if (this_set
!= NULL
)
2734 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2735 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2736 if (attribute
!= DW_AT_GNU_locviews
)
2738 /* Corrupt DWARF info can produce more offsets than views.
2739 See PR 23062 for an example. */
2740 if (debug_info_p
->num_loc_offsets
2741 > debug_info_p
->num_loc_views
)
2742 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2745 debug_info_p
->loc_offsets
[num
] = uvalue
;
2746 debug_info_p
->num_loc_offsets
++;
2751 assert (debug_info_p
->num_loc_views
<= num
);
2752 num
= debug_info_p
->num_loc_views
;
2753 if (num
> debug_info_p
->num_loc_offsets
)
2754 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2757 debug_info_p
->loc_views
[num
] = uvalue
;
2758 debug_info_p
->num_loc_views
++;
2765 if (need_base_address
)
2766 debug_info_p
->base_address
= uvalue
;
2769 case DW_AT_GNU_addr_base
:
2770 debug_info_p
->addr_base
= uvalue
;
2773 case DW_AT_GNU_ranges_base
:
2774 debug_info_p
->ranges_base
= uvalue
;
2778 if ((dwarf_version
< 4
2779 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2780 || form
== DW_FORM_sec_offset
)
2782 /* Process range list. */
2783 unsigned int lmax
= debug_info_p
->max_range_lists
;
2784 unsigned int num
= debug_info_p
->num_range_lists
;
2786 if (lmax
== 0 || num
>= lmax
)
2789 debug_info_p
->range_lists
= (dwarf_vma
*)
2790 xcrealloc (debug_info_p
->range_lists
,
2791 lmax
, sizeof (*debug_info_p
->range_lists
));
2792 debug_info_p
->max_range_lists
= lmax
;
2794 debug_info_p
->range_lists
[num
] = uvalue
;
2795 debug_info_p
->num_range_lists
++;
2799 case DW_AT_GNU_dwo_name
:
2800 case DW_AT_dwo_name
:
2805 add_dwo_name ((const char *) fetch_indirect_string (uvalue
));
2807 case DW_FORM_GNU_strp_alt
:
2808 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
));
2810 case DW_FORM_GNU_str_index
:
2811 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2813 case DW_FORM_string
:
2814 add_dwo_name ((const char *) orig_data
);
2817 warn (_("Unsupported form (%s) for attribute %s\n"),
2818 get_FORM_name (form
), get_AT_name (attribute
));
2823 case DW_AT_comp_dir
:
2824 /* FIXME: Also extract a build-id in a CU/TU. */
2829 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
));
2831 case DW_FORM_GNU_strp_alt
:
2832 add_dwo_dir (fetch_alt_indirect_string (uvalue
));
2834 case DW_FORM_line_strp
:
2835 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
));
2837 case DW_FORM_GNU_str_index
:
2838 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2840 case DW_FORM_string
:
2841 add_dwo_dir ((const char *) orig_data
);
2844 warn (_("Unsupported form (%s) for attribute %s\n"),
2845 get_FORM_name (form
), get_AT_name (attribute
));
2850 case DW_AT_GNU_dwo_id
:
2855 /* FIXME: Record the length of the ID as well ? */
2856 add_dwo_id ((const char *) (data
- 8));
2859 warn (_("Unsupported form (%s) for attribute %s\n"),
2860 get_FORM_name (form
), get_AT_name (attribute
));
2870 if (do_loc
|| attribute
== 0)
2873 /* For some attributes we can display further information. */
2877 if (level
>= 0 && level
< MAX_CU_NESTING
2878 && uvalue
< (size_t) (end
- start
))
2880 bfd_boolean is_signed
= FALSE
;
2881 abbrev_entry
* type_abbrev
;
2882 unsigned char * type_data
;
2883 unsigned long type_cu_offset
;
2885 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
2886 section
, NULL
, & type_data
, & type_cu_offset
);
2887 if (type_abbrev
!= NULL
)
2889 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2890 pointer_size
, offset_size
, dwarf_version
,
2893 level_type_signed
[level
] = is_signed
;
2901 case DW_INL_not_inlined
:
2902 printf (_("(not inlined)"));
2904 case DW_INL_inlined
:
2905 printf (_("(inlined)"));
2907 case DW_INL_declared_not_inlined
:
2908 printf (_("(declared as inline but ignored)"));
2910 case DW_INL_declared_inlined
:
2911 printf (_("(declared as inline and inlined)"));
2914 printf (_(" (Unknown inline attribute value: %s)"),
2915 dwarf_vmatoa ("x", uvalue
));
2920 case DW_AT_language
:
2924 /* Ordered by the numeric value of these constants. */
2925 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2926 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2927 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2928 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2929 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2930 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2931 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2932 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2933 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2934 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2935 /* DWARF 2.1 values. */
2936 case DW_LANG_Java
: printf ("(Java)"); break;
2937 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2938 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2939 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2940 /* DWARF 3 values. */
2941 case DW_LANG_PLI
: printf ("(PLI)"); break;
2942 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2943 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2944 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2945 case DW_LANG_D
: printf ("(D)"); break;
2946 /* DWARF 4 values. */
2947 case DW_LANG_Python
: printf ("(Python)"); break;
2948 /* DWARF 5 values. */
2949 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
2950 case DW_LANG_Go
: printf ("(Go)"); break;
2951 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
2952 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
2953 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
2954 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2955 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
2956 case DW_LANG_Rust
: printf ("(Rust)"); break;
2957 case DW_LANG_C11
: printf ("(C11)"); break;
2958 case DW_LANG_Swift
: printf ("(Swift)"); break;
2959 case DW_LANG_Julia
: printf ("(Julia)"); break;
2960 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
2961 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2962 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2963 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2964 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
2965 /* MIPS extension. */
2966 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2967 /* UPC extension. */
2968 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2970 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2971 printf (_("(implementation defined: %s)"),
2972 dwarf_vmatoa ("x", uvalue
));
2974 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2979 case DW_AT_encoding
:
2983 case DW_ATE_void
: printf ("(void)"); break;
2984 case DW_ATE_address
: printf ("(machine address)"); break;
2985 case DW_ATE_boolean
: printf ("(boolean)"); break;
2986 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2987 case DW_ATE_float
: printf ("(float)"); break;
2988 case DW_ATE_signed
: printf ("(signed)"); break;
2989 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2990 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2991 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2992 /* DWARF 2.1 values: */
2993 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2994 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2995 /* DWARF 3 values: */
2996 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2997 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2998 case DW_ATE_edited
: printf ("(edited)"); break;
2999 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3000 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3001 /* DWARF 4 values: */
3002 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3003 /* DWARF 5 values: */
3004 case DW_ATE_UCS
: printf ("(UCS)"); break;
3005 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3007 /* HP extensions: */
3008 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3009 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3010 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3011 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3012 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3013 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3014 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3017 if (uvalue
>= DW_ATE_lo_user
3018 && uvalue
<= DW_ATE_hi_user
)
3019 printf (_("(user defined type)"));
3021 printf (_("(unknown type)"));
3026 case DW_AT_accessibility
:
3030 case DW_ACCESS_public
: printf ("(public)"); break;
3031 case DW_ACCESS_protected
: printf ("(protected)"); break;
3032 case DW_ACCESS_private
: printf ("(private)"); break;
3034 printf (_("(unknown accessibility)"));
3039 case DW_AT_visibility
:
3043 case DW_VIS_local
: printf ("(local)"); break;
3044 case DW_VIS_exported
: printf ("(exported)"); break;
3045 case DW_VIS_qualified
: printf ("(qualified)"); break;
3046 default: printf (_("(unknown visibility)")); break;
3050 case DW_AT_endianity
:
3054 case DW_END_default
: printf ("(default)"); break;
3055 case DW_END_big
: printf ("(big)"); break;
3056 case DW_END_little
: printf ("(little)"); break;
3058 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3059 printf (_("(user specified)"));
3061 printf (_("(unknown endianity)"));
3066 case DW_AT_virtuality
:
3070 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3071 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3072 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3073 default: printf (_("(unknown virtuality)")); break;
3077 case DW_AT_identifier_case
:
3081 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3082 case DW_ID_up_case
: printf ("(up_case)"); break;
3083 case DW_ID_down_case
: printf ("(down_case)"); break;
3084 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3085 default: printf (_("(unknown case)")); break;
3089 case DW_AT_calling_convention
:
3093 case DW_CC_normal
: printf ("(normal)"); break;
3094 case DW_CC_program
: printf ("(program)"); break;
3095 case DW_CC_nocall
: printf ("(nocall)"); break;
3096 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3097 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3098 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3099 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3101 if (uvalue
>= DW_CC_lo_user
3102 && uvalue
<= DW_CC_hi_user
)
3103 printf (_("(user defined)"));
3105 printf (_("(unknown convention)"));
3109 case DW_AT_ordering
:
3114 case -1: printf (_("(undefined)")); break;
3115 case 0: printf ("(row major)"); break;
3116 case 1: printf ("(column major)"); break;
3120 case DW_AT_decimal_sign
:
3124 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3125 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3126 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3127 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3128 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3129 default: printf (_("(unrecognised)")); break;
3133 case DW_AT_defaulted
:
3137 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3138 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3139 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3140 default: printf (_("(unrecognised)")); break;
3144 case DW_AT_discr_list
:
3146 display_discr_list (form
, uvalue
, data
, end
, level
);
3149 case DW_AT_frame_base
:
3150 have_frame_base
= 1;
3152 case DW_AT_location
:
3153 case DW_AT_string_length
:
3154 case DW_AT_return_addr
:
3155 case DW_AT_data_member_location
:
3156 case DW_AT_vtable_elem_location
:
3158 case DW_AT_static_link
:
3159 case DW_AT_use_location
:
3160 case DW_AT_call_value
:
3161 case DW_AT_GNU_call_site_value
:
3162 case DW_AT_call_data_value
:
3163 case DW_AT_GNU_call_site_data_value
:
3164 case DW_AT_call_target
:
3165 case DW_AT_GNU_call_site_target
:
3166 case DW_AT_call_target_clobbered
:
3167 case DW_AT_GNU_call_site_target_clobbered
:
3168 if ((dwarf_version
< 4
3169 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3170 || form
== DW_FORM_sec_offset
)
3171 printf (_(" (location list)"));
3173 case DW_AT_allocated
:
3174 case DW_AT_associated
:
3175 case DW_AT_data_location
:
3177 case DW_AT_upper_bound
:
3178 case DW_AT_lower_bound
:
3181 int need_frame_base
;
3184 need_frame_base
= decode_location_expression (block_start
,
3189 cu_offset
, section
);
3191 if (need_frame_base
&& !have_frame_base
)
3192 printf (_(" [without DW_AT_frame_base]"));
3196 case DW_AT_data_bit_offset
:
3197 case DW_AT_byte_size
:
3198 case DW_AT_bit_size
:
3199 case DW_AT_string_length_byte_size
:
3200 case DW_AT_string_length_bit_size
:
3201 case DW_AT_bit_stride
:
3202 if (form
== DW_FORM_exprloc
)
3205 (void) decode_location_expression (block_start
, pointer_size
,
3206 offset_size
, dwarf_version
,
3207 uvalue
, cu_offset
, section
);
3214 unsigned long abbrev_number
;
3215 abbrev_entry
*entry
;
3217 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3218 section
, & abbrev_number
, NULL
, NULL
);
3221 if (form
!= DW_FORM_GNU_ref_alt
)
3222 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3223 dwarf_vmatoa ("x", uvalue
),
3224 (unsigned long) (orig_data
- section
->start
));
3228 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3229 printf (" (%s)", get_TAG_name (entry
->tag
));
3242 static unsigned char *
3243 read_and_display_attr (unsigned long attribute
,
3245 dwarf_signed_vma implicit_const
,
3246 unsigned char * start
,
3247 unsigned char * data
,
3248 unsigned char * end
,
3249 dwarf_vma cu_offset
,
3250 dwarf_vma pointer_size
,
3251 dwarf_vma offset_size
,
3253 debug_info
* debug_info_p
,
3255 struct dwarf_section
* section
,
3256 struct cu_tu_set
* this_set
,
3260 printf (" %-18s:", get_AT_name (attribute
));
3261 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3263 cu_offset
, pointer_size
, offset_size
,
3264 dwarf_version
, debug_info_p
,
3265 do_loc
, section
, this_set
, ' ', level
);
3271 /* Like load_debug_section, but if the ordinary call fails, and we are
3272 following debug links, then attempt to load the requested section
3273 from one of the separate debug info files. */
3276 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3279 if (load_debug_section (sec_enum
, handle
))
3281 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3283 /* See if we can associate a filename with this section. */
3286 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3287 if (i
->handle
== handle
)
3289 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3297 if (do_follow_links
)
3301 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3303 if (load_debug_section (sec_enum
, i
->handle
))
3305 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3307 /* FIXME: We should check to see if any of the remaining debug info
3308 files also contain this section, and, umm, do something about it. */
3318 introduce (struct dwarf_section
* section
, bfd_boolean raw
)
3322 if (do_follow_links
&& section
->filename
)
3323 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3324 section
->name
, section
->filename
);
3326 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3330 if (do_follow_links
&& section
->filename
)
3331 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3332 section
->name
, section
->filename
);
3334 printf (_("Contents of the %s section:\n\n"), section
->name
);
3338 /* Process the contents of a .debug_info section.
3339 If do_loc is TRUE then we are scanning for location lists and dwo tags
3340 and we do not want to display anything to the user.
3341 If do_types is TRUE, we are processing a .debug_types section instead of
3342 a .debug_info section.
3343 The information displayed is restricted by the values in DWARF_START_DIE
3344 and DWARF_CUTOFF_LEVEL.
3345 Returns TRUE upon success. Otherwise an error or warning message is
3346 printed and FALSE is returned. */
3349 process_debug_info (struct dwarf_section
* section
,
3351 enum dwarf_section_display_enum abbrev_sec
,
3353 bfd_boolean do_types
)
3355 unsigned char *start
= section
->start
;
3356 unsigned char *end
= start
+ section
->size
;
3357 unsigned char *section_begin
;
3359 unsigned int num_units
= 0;
3361 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3362 && num_debug_info_entries
== 0
3367 /* First scan the section to get the number of comp units. */
3368 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3371 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3372 will be the length. For a 64-bit DWARF section, it'll be
3373 the escape code 0xffffffff followed by an 8 byte length. */
3374 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3376 if (length
== 0xffffffff)
3378 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3379 section_begin
+= length
+ 12;
3381 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3383 warn (_("Reserved length value (0x%s) found in section %s\n"),
3384 dwarf_vmatoa ("x", length
), section
->name
);
3388 section_begin
+= length
+ 4;
3390 /* Negative values are illegal, they may even cause infinite
3391 looping. This can happen if we can't accurately apply
3392 relocations to an object file, or if the file is corrupt. */
3393 if ((signed long) length
<= 0 || section_begin
< start
)
3395 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3396 dwarf_vmatoa ("x", length
), section
->name
);
3403 error (_("No comp units in %s section ?\n"), section
->name
);
3407 /* Then allocate an array to hold the information. */
3408 debug_information
= (debug_info
*) cmalloc (num_units
,
3409 sizeof (* debug_information
));
3410 if (debug_information
== NULL
)
3412 error (_("Not enough memory for a debug info array of %u entries\n"),
3414 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3418 /* PR 17531: file: 92ca3797.
3419 We cannot rely upon the debug_information array being initialised
3420 before it is used. A corrupt file could easily contain references
3421 to a unit for which information has not been made available. So
3422 we ensure that the array is zeroed here. */
3423 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3425 alloc_num_debug_info_entries
= num_units
;
3430 load_debug_section_with_follow (str
, file
);
3431 load_debug_section_with_follow (line_str
, file
);
3432 load_debug_section_with_follow (str_dwo
, file
);
3433 load_debug_section_with_follow (str_index
, file
);
3434 load_debug_section_with_follow (str_index_dwo
, file
);
3435 load_debug_section_with_follow (debug_addr
, file
);
3438 load_debug_section_with_follow (abbrev_sec
, file
);
3439 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3441 warn (_("Unable to locate %s section!\n"),
3442 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3446 if (!do_loc
&& dwarf_start_die
== 0)
3447 introduce (section
, FALSE
);
3449 free_all_abbrevs ();
3450 free (cu_abbrev_map
);
3451 cu_abbrev_map
= NULL
;
3452 next_free_abbrev_map_entry
= 0;
3454 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3455 to load *all* of the abbrevs for all CUs in this .debug_info
3456 section. This does effectively mean that we (partially) read
3457 every CU header twice. */
3458 for (section_begin
= start
; start
< end
;)
3460 DWARF2_Internal_CompUnit compunit
;
3461 unsigned char * hdrptr
;
3462 dwarf_vma abbrev_base
;
3464 dwarf_vma cu_offset
;
3465 unsigned int offset_size
;
3466 unsigned int initial_length_size
;
3467 struct cu_tu_set
* this_set
;
3472 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3474 if (compunit
.cu_length
== 0xffffffff)
3476 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3478 initial_length_size
= 12;
3483 initial_length_size
= 4;
3486 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3488 cu_offset
= start
- section_begin
;
3490 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3492 if (compunit
.cu_version
< 5)
3494 compunit
.cu_unit_type
= DW_UT_compile
;
3495 /* Initialize it due to a false compiler warning. */
3496 compunit
.cu_pointer_size
= -1;
3500 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3501 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3503 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3506 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3508 if (this_set
== NULL
)
3511 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3515 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3516 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3519 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3520 compunit
.cu_abbrev_offset
);
3523 unsigned char * next
;
3525 list
= new_abbrev_list (abbrev_base
,
3526 compunit
.cu_abbrev_offset
);
3527 next
= process_abbrev_set
3528 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3529 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3530 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3531 + abbrev_base
+ abbrev_size
),
3533 list
->start_of_next_abbrevs
= next
;
3536 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3537 + initial_length_size
;
3538 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3541 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3543 DWARF2_Internal_CompUnit compunit
;
3544 unsigned char *hdrptr
;
3545 unsigned char *tags
;
3546 int level
, last_level
, saved_level
;
3547 dwarf_vma cu_offset
;
3548 unsigned long sec_off
;
3549 unsigned int offset_size
;
3550 unsigned int initial_length_size
;
3551 dwarf_vma signature_high
= 0;
3552 dwarf_vma signature_low
= 0;
3553 dwarf_vma type_offset
= 0;
3554 struct cu_tu_set
*this_set
;
3555 dwarf_vma abbrev_base
;
3557 abbrev_list
* list
= NULL
;
3561 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3563 if (compunit
.cu_length
== 0xffffffff)
3565 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3567 initial_length_size
= 12;
3572 initial_length_size
= 4;
3575 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3577 cu_offset
= start
- section_begin
;
3579 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3581 if (compunit
.cu_version
< 5)
3583 compunit
.cu_unit_type
= DW_UT_compile
;
3584 /* Initialize it due to a false compiler warning. */
3585 compunit
.cu_pointer_size
= -1;
3589 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3590 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3592 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3595 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3597 if (this_set
== NULL
)
3600 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3604 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3605 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3608 if (compunit
.cu_version
< 5)
3609 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3611 /* PR 17512: file: 001-108546-0.001:0.1. */
3612 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3614 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3615 compunit
.cu_pointer_size
, offset_size
);
3616 compunit
.cu_pointer_size
= offset_size
;
3621 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3623 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3626 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3627 + initial_length_size
))
3629 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3630 + initial_length_size
;
3634 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3635 && num_debug_info_entries
== 0
3636 && alloc_num_debug_info_entries
> unit
3639 debug_information
[unit
].cu_offset
= cu_offset
;
3640 debug_information
[unit
].pointer_size
3641 = compunit
.cu_pointer_size
;
3642 debug_information
[unit
].offset_size
= offset_size
;
3643 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3644 debug_information
[unit
].base_address
= 0;
3645 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3646 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3647 debug_information
[unit
].loc_offsets
= NULL
;
3648 debug_information
[unit
].have_frame_base
= NULL
;
3649 debug_information
[unit
].max_loc_offsets
= 0;
3650 debug_information
[unit
].num_loc_offsets
= 0;
3651 debug_information
[unit
].range_lists
= NULL
;
3652 debug_information
[unit
].max_range_lists
= 0;
3653 debug_information
[unit
].num_range_lists
= 0;
3656 if (!do_loc
&& dwarf_start_die
== 0)
3658 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3659 dwarf_vmatoa ("x", cu_offset
));
3660 printf (_(" Length: 0x%s (%s)\n"),
3661 dwarf_vmatoa ("x", compunit
.cu_length
),
3662 offset_size
== 8 ? "64-bit" : "32-bit");
3663 printf (_(" Version: %d\n"), compunit
.cu_version
);
3664 if (compunit
.cu_version
>= 5)
3665 printf (_(" Unit Type: %s (%x)\n"),
3666 get_DW_UT_name (compunit
.cu_unit_type
) ?: "???",
3667 compunit
.cu_unit_type
);
3668 printf (_(" Abbrev Offset: 0x%s\n"),
3669 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3670 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3675 printf (_(" Signature: 0x%s\n"),
3676 dwarf_vmatoa64 (signature_high
, signature_low
,
3677 buf
, sizeof (buf
)));
3678 printf (_(" Type Offset: 0x%s\n"),
3679 dwarf_vmatoa ("x", type_offset
));
3681 if (this_set
!= NULL
)
3683 dwarf_vma
*offsets
= this_set
->section_offsets
;
3684 size_t *sizes
= this_set
->section_sizes
;
3686 printf (_(" Section contributions:\n"));
3687 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3688 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3689 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3690 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3691 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3692 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3693 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3694 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3695 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3696 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3697 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3698 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3702 sec_off
= cu_offset
+ initial_length_size
;
3703 if (sec_off
+ compunit
.cu_length
< sec_off
3704 || sec_off
+ compunit
.cu_length
> section
->size
)
3706 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3708 (unsigned long) cu_offset
,
3709 dwarf_vmatoa ("x", compunit
.cu_length
));
3715 start
+= compunit
.cu_length
+ initial_length_size
;
3717 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3719 warn (_("CU at offset %s contains corrupt or "
3720 "unsupported version number: %d.\n"),
3721 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3725 if (compunit
.cu_unit_type
!= DW_UT_compile
3726 && compunit
.cu_unit_type
!= DW_UT_partial
3727 && compunit
.cu_unit_type
!= DW_UT_type
)
3729 warn (_("CU at offset %s contains corrupt or "
3730 "unsupported unit type: %d.\n"),
3731 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3735 /* Process the abbrevs used by this compilation unit. */
3736 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3737 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3738 (unsigned long) compunit
.cu_abbrev_offset
,
3739 (unsigned long) abbrev_size
);
3740 /* PR 17531: file:4bcd9ce9. */
3741 else if ((abbrev_base
+ abbrev_size
)
3742 > debug_displays
[abbrev_sec
].section
.size
)
3743 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3744 (unsigned long) abbrev_base
+ abbrev_size
,
3745 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3748 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3749 compunit
.cu_abbrev_offset
);
3752 unsigned char * next
;
3754 list
= new_abbrev_list (abbrev_base
,
3755 compunit
.cu_abbrev_offset
);
3756 next
= process_abbrev_set
3757 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3758 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3759 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3760 + abbrev_base
+ abbrev_size
),
3762 list
->start_of_next_abbrevs
= next
;
3769 while (tags
< start
)
3771 unsigned long abbrev_number
;
3772 unsigned long die_offset
;
3773 abbrev_entry
*entry
;
3775 int do_printing
= 1;
3777 die_offset
= tags
- section_begin
;
3779 READ_ULEB (abbrev_number
, tags
, start
);
3781 /* A null DIE marks the end of a list of siblings or it may also be
3782 a section padding. */
3783 if (abbrev_number
== 0)
3785 /* Check if it can be a section padding for the last CU. */
3786 if (level
== 0 && start
== end
)
3790 for (chk
= tags
; chk
< start
; chk
++)
3797 if (!do_loc
&& die_offset
>= dwarf_start_die
3798 && (dwarf_cutoff_level
== -1
3799 || level
< dwarf_cutoff_level
))
3800 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3806 static unsigned num_bogus_warns
= 0;
3808 if (num_bogus_warns
< 3)
3810 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3811 die_offset
, section
->name
);
3813 if (num_bogus_warns
== 3)
3814 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3817 if (dwarf_start_die
!= 0 && level
< saved_level
)
3824 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3828 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3829 saved_level
= level
;
3830 do_printing
= (dwarf_cutoff_level
== -1
3831 || level
< dwarf_cutoff_level
);
3833 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3834 level
, die_offset
, abbrev_number
);
3835 else if (dwarf_cutoff_level
== -1
3836 || last_level
< dwarf_cutoff_level
)
3837 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3842 /* Scan through the abbreviation list until we reach the
3847 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3848 if (entry
->number
== abbrev_number
)
3853 if (!do_loc
&& do_printing
)
3858 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3859 die_offset
, abbrev_number
);
3863 if (!do_loc
&& do_printing
)
3864 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3869 need_base_address
= 0;
3871 case DW_TAG_compile_unit
:
3872 need_base_address
= 1;
3873 need_dwo_info
= do_loc
;
3875 case DW_TAG_entry_point
:
3876 case DW_TAG_subprogram
:
3877 need_base_address
= 0;
3878 /* Assuming that there is no DW_AT_frame_base. */
3879 have_frame_base
= 0;
3883 debug_info
*debug_info_p
=
3884 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3885 ? debug_information
+ unit
: NULL
;
3887 assert (!debug_info_p
3888 || (debug_info_p
->num_loc_offsets
3889 == debug_info_p
->num_loc_views
));
3891 for (attr
= entry
->first_attr
;
3892 attr
&& attr
->attribute
;
3895 if (! do_loc
&& do_printing
)
3896 /* Show the offset from where the tag was extracted. */
3897 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3898 tags
= read_and_display_attr (attr
->attribute
,
3900 attr
->implicit_const
,
3905 compunit
.cu_pointer_size
,
3907 compunit
.cu_version
,
3909 do_loc
|| ! do_printing
,
3915 /* If a locview attribute appears before a location one,
3916 make sure we don't associate it with an earlier
3919 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3922 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3923 debug_info_p
->num_loc_views
++;
3924 assert (debug_info_p
->num_loc_views
3925 == debug_info_p
->num_loc_offsets
);
3932 warn(_("DIE has locviews without loclist\n"));
3933 debug_info_p
->num_loc_views
--;
3940 if (entry
->children
)
3945 /* Set num_debug_info_entries here so that it can be used to check if
3946 we need to process .debug_loc and .debug_ranges sections. */
3947 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3948 && num_debug_info_entries
== 0
3951 if (num_units
> alloc_num_debug_info_entries
)
3952 num_debug_info_entries
= alloc_num_debug_info_entries
;
3954 num_debug_info_entries
= num_units
;
3963 /* Locate and scan the .debug_info section in the file and record the pointer
3964 sizes and offsets for the compilation units in it. Usually an executable
3965 will have just one pointer size, but this is not guaranteed, and so we try
3966 not to make any assumptions. Returns zero upon failure, or the number of
3967 compilation units upon success. */
3970 load_debug_info (void * file
)
3972 /* If we have already tried and failed to load the .debug_info
3973 section then do not bother to repeat the task. */
3974 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3977 /* If we already have the information there is nothing else to do. */
3978 if (num_debug_info_entries
> 0)
3979 return num_debug_info_entries
;
3981 /* If this is a DWARF package file, load the CU and TU indexes. */
3982 (void) load_cu_tu_indexes (file
);
3984 if (load_debug_section_with_follow (info
, file
)
3985 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
3986 return num_debug_info_entries
;
3988 if (load_debug_section_with_follow (info_dwo
, file
)
3989 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3990 abbrev_dwo
, TRUE
, FALSE
))
3991 return num_debug_info_entries
;
3993 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3997 /* Read a DWARF .debug_line section header starting at DATA.
3998 Upon success returns an updated DATA pointer and the LINFO
3999 structure and the END_OF_SEQUENCE pointer will be filled in.
4000 Otherwise returns NULL. */
4002 static unsigned char *
4003 read_debug_line_header (struct dwarf_section
* section
,
4004 unsigned char * data
,
4005 unsigned char * end
,
4006 DWARF2_Internal_LineInfo
* linfo
,
4007 unsigned char ** end_of_sequence
)
4009 unsigned char *hdrptr
;
4010 unsigned int initial_length_size
;
4012 /* Extract information from the Line Number Program Header.
4013 (section 6.2.4 in the Dwarf3 doc). */
4016 /* Get and check the length of the block. */
4017 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4019 if (linfo
->li_length
== 0xffffffff)
4021 /* This section is 64-bit DWARF 3. */
4022 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4023 linfo
->li_offset_size
= 8;
4024 initial_length_size
= 12;
4028 linfo
->li_offset_size
= 4;
4029 initial_length_size
= 4;
4032 if (linfo
->li_length
+ initial_length_size
> section
->size
)
4034 /* If the length field has a relocation against it, then we should
4035 not complain if it is inaccurate (and probably negative). This
4036 happens in object files when the .debug_line section is actually
4037 comprised of several different .debug_line.* sections, (some of
4038 which may be removed by linker garbage collection), and a relocation
4039 is used to compute the correct length once that is done. */
4040 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4042 linfo
->li_length
= (end
- data
) - initial_length_size
;
4046 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4047 (long) linfo
->li_length
);
4052 /* Get and check the version number. */
4053 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4055 if (linfo
->li_version
!= 2
4056 && linfo
->li_version
!= 3
4057 && linfo
->li_version
!= 4
4058 && linfo
->li_version
!= 5)
4060 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4061 "is currently supported.\n"));
4065 if (linfo
->li_version
>= 5)
4067 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4069 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4070 if (linfo
->li_segment_size
!= 0)
4072 warn (_("The %s section contains "
4073 "unsupported segment selector size: %d.\n"),
4074 section
->name
, linfo
->li_segment_size
);
4079 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4080 linfo
->li_offset_size
, end
);
4081 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4083 if (linfo
->li_version
>= 4)
4085 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4087 if (linfo
->li_max_ops_per_insn
== 0)
4089 warn (_("Invalid maximum operations per insn.\n"));
4094 linfo
->li_max_ops_per_insn
= 1;
4096 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4097 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4098 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4099 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4101 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
4102 /* PR 17512: file:002-117414-0.004. */
4103 if (* end_of_sequence
> end
)
4105 warn (_("Line length %s extends beyond end of section\n"),
4106 dwarf_vmatoa ("u", linfo
->li_length
));
4107 * end_of_sequence
= end
;
4114 static unsigned char *
4115 display_formatted_table (unsigned char * data
,
4116 unsigned char * start
,
4117 unsigned char * end
,
4118 const DWARF2_Internal_LineInfo
* linfo
,
4119 struct dwarf_section
* section
,
4122 unsigned char *format_start
, format_count
, *format
, formati
;
4123 dwarf_vma data_count
, datai
;
4124 unsigned int namepass
, last_entry
= 0;
4125 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4127 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4128 if (do_checks
&& format_count
> 5)
4129 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4130 table_name
, format_count
);
4132 format_start
= data
;
4133 for (formati
= 0; formati
< format_count
; formati
++)
4135 SKIP_ULEB (data
, end
);
4136 SKIP_ULEB (data
, end
);
4139 warn (_("%s: Corrupt format description entry\n"), table_name
);
4144 READ_ULEB (data_count
, data
, end
);
4145 if (data_count
== 0)
4147 printf (_("\n The %s is empty.\n"), table_name
);
4150 else if (data
== end
)
4152 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4153 table_name
, dwarf_vmatoa ("x", data_count
));
4157 else if (format_count
== 0)
4159 warn (_("%s: format count is zero, but the table is not empty\n"),
4164 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4165 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4168 printf (_(" Entry"));
4169 /* Delay displaying name as the last entry for better screen layout. */
4170 for (namepass
= 0; namepass
< 2; namepass
++)
4172 format
= format_start
;
4173 for (formati
= 0; formati
< format_count
; formati
++)
4175 dwarf_vma content_type
;
4177 READ_ULEB (content_type
, format
, end
);
4178 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4179 switch (content_type
)
4182 printf (_("\tName"));
4184 case DW_LNCT_directory_index
:
4185 printf (_("\tDir"));
4187 case DW_LNCT_timestamp
:
4188 printf (_("\tTime"));
4191 printf (_("\tSize"));
4194 printf (_("\tMD5\t\t\t"));
4197 printf (_("\t(Unknown format content type %s)"),
4198 dwarf_vmatoa ("u", content_type
));
4200 SKIP_ULEB (format
, end
);
4205 for (datai
= 0; datai
< data_count
; datai
++)
4207 unsigned char *datapass
= data
;
4209 printf (" %d", last_entry
++);
4210 /* Delay displaying name as the last entry for better screen layout. */
4211 for (namepass
= 0; namepass
< 2; namepass
++)
4213 format
= format_start
;
4215 for (formati
= 0; formati
< format_count
; formati
++)
4217 dwarf_vma content_type
, form
;
4219 READ_ULEB (content_type
, format
, end
);
4220 READ_ULEB (form
, format
, end
);
4221 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4222 0, 0, linfo
->li_offset_size
,
4223 linfo
->li_version
, NULL
,
4224 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4225 section
, NULL
, '\t', -1);
4229 if (data
== end
&& (datai
< data_count
- 1))
4231 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4240 display_debug_lines_raw (struct dwarf_section
* section
,
4241 unsigned char * data
,
4242 unsigned char * end
,
4245 unsigned char *start
= section
->start
;
4246 int verbose_view
= 0;
4248 introduce (section
, TRUE
);
4252 static DWARF2_Internal_LineInfo saved_linfo
;
4253 DWARF2_Internal_LineInfo linfo
;
4254 unsigned char *standard_opcodes
;
4255 unsigned char *end_of_sequence
;
4258 if (const_strneq (section
->name
, ".debug_line.")
4259 /* Note: the following does not apply to .debug_line.dwo sections.
4260 These are full debug_line sections. */
4261 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4263 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4264 section containing just the Line Number Statements. They are
4265 created by the assembler and intended to be used alongside gcc's
4266 -ffunction-sections command line option. When the linker's
4267 garbage collection decides to discard a .text.<foo> section it
4268 can then also discard the line number information in .debug_line.<foo>.
4270 Since the section is a fragment it does not have the details
4271 needed to fill out a LineInfo structure, so instead we use the
4272 details from the last full debug_line section that we processed. */
4273 end_of_sequence
= end
;
4274 standard_opcodes
= NULL
;
4275 linfo
= saved_linfo
;
4276 /* PR 17531: file: 0522b371. */
4277 if (linfo
.li_line_range
== 0)
4279 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4282 reset_state_machine (linfo
.li_default_is_stmt
);
4286 unsigned char * hdrptr
;
4288 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4289 & end_of_sequence
)) == NULL
)
4292 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4293 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4294 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4295 if (linfo
.li_version
>= 5)
4297 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4298 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4300 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4301 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4302 if (linfo
.li_version
>= 4)
4303 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4304 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4305 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4306 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4307 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4309 /* PR 17512: file: 1665-6428-0.004. */
4310 if (linfo
.li_line_range
== 0)
4312 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4313 linfo
.li_line_range
= 1;
4316 reset_state_machine (linfo
.li_default_is_stmt
);
4318 /* Display the contents of the Opcodes table. */
4319 standard_opcodes
= hdrptr
;
4321 /* PR 17512: file: 002-417945-0.004. */
4322 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4324 warn (_("Line Base extends beyond end of section\n"));
4328 printf (_("\n Opcodes:\n"));
4330 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4331 printf (ngettext (" Opcode %d has %d arg\n",
4332 " Opcode %d has %d args\n",
4333 standard_opcodes
[i
- 1]),
4334 i
, standard_opcodes
[i
- 1]);
4336 /* Display the contents of the Directory table. */
4337 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4339 if (linfo
.li_version
>= 5)
4341 load_debug_section_with_follow (line_str
, file
);
4343 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4345 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4351 printf (_("\n The Directory Table is empty.\n"));
4354 unsigned int last_dir_entry
= 0;
4356 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4357 (long)(data
- start
));
4359 while (data
< end
&& *data
!= 0)
4361 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4363 data
+= strnlen ((char *) data
, end
- data
) + 1;
4366 /* PR 17512: file: 002-132094-0.004. */
4367 if (data
>= end
- 1)
4371 /* Skip the NUL at the end of the table. */
4374 /* Display the contents of the File Name table. */
4376 printf (_("\n The File Name Table is empty.\n"));
4379 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4380 (long)(data
- start
));
4381 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4383 while (data
< end
&& *data
!= 0)
4385 unsigned char *name
;
4388 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4390 data
+= strnlen ((char *) data
, end
- data
) + 1;
4392 READ_ULEB (val
, data
, end
);
4393 printf ("%s\t", dwarf_vmatoa ("u", val
));
4394 READ_ULEB (val
, data
, end
);
4395 printf ("%s\t", dwarf_vmatoa ("u", val
));
4396 READ_ULEB (val
, data
, end
);
4397 printf ("%s\t", dwarf_vmatoa ("u", val
));
4398 printf ("%.*s\n", (int)(end
- name
), name
);
4402 warn (_("Corrupt file name table entry\n"));
4408 /* Skip the NUL at the end of the table. */
4413 saved_linfo
= linfo
;
4416 /* Now display the statements. */
4417 if (data
>= end_of_sequence
)
4418 printf (_(" No Line Number Statements.\n"));
4421 printf (_(" Line Number Statements:\n"));
4423 while (data
< end_of_sequence
)
4425 unsigned char op_code
;
4426 dwarf_signed_vma adv
;
4429 printf (" [0x%08lx]", (long)(data
- start
));
4433 if (op_code
>= linfo
.li_opcode_base
)
4435 op_code
-= linfo
.li_opcode_base
;
4436 uladv
= (op_code
/ linfo
.li_line_range
);
4437 if (linfo
.li_max_ops_per_insn
== 1)
4439 uladv
*= linfo
.li_min_insn_length
;
4440 state_machine_regs
.address
+= uladv
;
4442 state_machine_regs
.view
= 0;
4443 printf (_(" Special opcode %d: "
4444 "advance Address by %s to 0x%s%s"),
4445 op_code
, dwarf_vmatoa ("u", uladv
),
4446 dwarf_vmatoa ("x", state_machine_regs
.address
),
4447 verbose_view
&& uladv
4448 ? _(" (reset view)") : "");
4453 = ((state_machine_regs
.op_index
+ uladv
)
4454 / linfo
.li_max_ops_per_insn
)
4455 * linfo
.li_min_insn_length
;
4457 state_machine_regs
.address
+= addrdelta
;
4458 state_machine_regs
.op_index
4459 = (state_machine_regs
.op_index
+ uladv
)
4460 % linfo
.li_max_ops_per_insn
;
4462 state_machine_regs
.view
= 0;
4463 printf (_(" Special opcode %d: "
4464 "advance Address by %s to 0x%s[%d]%s"),
4465 op_code
, dwarf_vmatoa ("u", uladv
),
4466 dwarf_vmatoa ("x", state_machine_regs
.address
),
4467 state_machine_regs
.op_index
,
4468 verbose_view
&& addrdelta
4469 ? _(" (reset view)") : "");
4471 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4472 state_machine_regs
.line
+= adv
;
4473 printf (_(" and Line by %s to %d"),
4474 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4475 if (verbose_view
|| state_machine_regs
.view
)
4476 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4479 state_machine_regs
.view
++;
4484 case DW_LNS_extended_op
:
4485 data
+= process_extended_line_op (data
,
4486 linfo
.li_default_is_stmt
,
4491 printf (_(" Copy"));
4492 if (verbose_view
|| state_machine_regs
.view
)
4493 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4496 state_machine_regs
.view
++;
4499 case DW_LNS_advance_pc
:
4500 READ_ULEB (uladv
, data
, end
);
4501 if (linfo
.li_max_ops_per_insn
== 1)
4503 uladv
*= linfo
.li_min_insn_length
;
4504 state_machine_regs
.address
+= uladv
;
4506 state_machine_regs
.view
= 0;
4507 printf (_(" Advance PC by %s to 0x%s%s\n"),
4508 dwarf_vmatoa ("u", uladv
),
4509 dwarf_vmatoa ("x", state_machine_regs
.address
),
4510 verbose_view
&& uladv
4511 ? _(" (reset view)") : "");
4516 = ((state_machine_regs
.op_index
+ uladv
)
4517 / linfo
.li_max_ops_per_insn
)
4518 * linfo
.li_min_insn_length
;
4519 state_machine_regs
.address
4521 state_machine_regs
.op_index
4522 = (state_machine_regs
.op_index
+ uladv
)
4523 % linfo
.li_max_ops_per_insn
;
4525 state_machine_regs
.view
= 0;
4526 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4527 dwarf_vmatoa ("u", uladv
),
4528 dwarf_vmatoa ("x", state_machine_regs
.address
),
4529 state_machine_regs
.op_index
,
4530 verbose_view
&& addrdelta
4531 ? _(" (reset view)") : "");
4535 case DW_LNS_advance_line
:
4536 READ_SLEB (adv
, data
, end
);
4537 state_machine_regs
.line
+= adv
;
4538 printf (_(" Advance Line by %s to %d\n"),
4539 dwarf_vmatoa ("d", adv
),
4540 state_machine_regs
.line
);
4543 case DW_LNS_set_file
:
4544 READ_ULEB (uladv
, data
, end
);
4545 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4546 dwarf_vmatoa ("u", uladv
));
4547 state_machine_regs
.file
= uladv
;
4550 case DW_LNS_set_column
:
4551 READ_ULEB (uladv
, data
, end
);
4552 printf (_(" Set column to %s\n"),
4553 dwarf_vmatoa ("u", uladv
));
4554 state_machine_regs
.column
= uladv
;
4557 case DW_LNS_negate_stmt
:
4558 adv
= state_machine_regs
.is_stmt
;
4560 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4561 state_machine_regs
.is_stmt
= adv
;
4564 case DW_LNS_set_basic_block
:
4565 printf (_(" Set basic block\n"));
4566 state_machine_regs
.basic_block
= 1;
4569 case DW_LNS_const_add_pc
:
4570 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4571 if (linfo
.li_max_ops_per_insn
)
4573 uladv
*= linfo
.li_min_insn_length
;
4574 state_machine_regs
.address
+= uladv
;
4576 state_machine_regs
.view
= 0;
4577 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4578 dwarf_vmatoa ("u", uladv
),
4579 dwarf_vmatoa ("x", state_machine_regs
.address
),
4580 verbose_view
&& uladv
4581 ? _(" (reset view)") : "");
4586 = ((state_machine_regs
.op_index
+ uladv
)
4587 / linfo
.li_max_ops_per_insn
)
4588 * linfo
.li_min_insn_length
;
4589 state_machine_regs
.address
4591 state_machine_regs
.op_index
4592 = (state_machine_regs
.op_index
+ uladv
)
4593 % linfo
.li_max_ops_per_insn
;
4595 state_machine_regs
.view
= 0;
4596 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4597 dwarf_vmatoa ("u", uladv
),
4598 dwarf_vmatoa ("x", state_machine_regs
.address
),
4599 state_machine_regs
.op_index
,
4600 verbose_view
&& addrdelta
4601 ? _(" (reset view)") : "");
4605 case DW_LNS_fixed_advance_pc
:
4606 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4607 state_machine_regs
.address
+= uladv
;
4608 state_machine_regs
.op_index
= 0;
4609 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4610 dwarf_vmatoa ("u", uladv
),
4611 dwarf_vmatoa ("x", state_machine_regs
.address
));
4612 /* Do NOT reset view. */
4615 case DW_LNS_set_prologue_end
:
4616 printf (_(" Set prologue_end to true\n"));
4619 case DW_LNS_set_epilogue_begin
:
4620 printf (_(" Set epilogue_begin to true\n"));
4623 case DW_LNS_set_isa
:
4624 READ_ULEB (uladv
, data
, end
);
4625 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4629 printf (_(" Unknown opcode %d with operands: "), op_code
);
4631 if (standard_opcodes
!= NULL
)
4632 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4634 READ_ULEB (uladv
, data
, end
);
4635 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4636 i
== 1 ? "" : ", ");
4651 unsigned char *name
;
4652 unsigned int directory_index
;
4653 unsigned int modification_date
;
4654 unsigned int length
;
4657 /* Output a decoded representation of the .debug_line section. */
4660 display_debug_lines_decoded (struct dwarf_section
* section
,
4661 unsigned char * start
,
4662 unsigned char * data
,
4663 unsigned char * end
,
4666 static DWARF2_Internal_LineInfo saved_linfo
;
4668 introduce (section
, FALSE
);
4672 /* This loop amounts to one iteration per compilation unit. */
4673 DWARF2_Internal_LineInfo linfo
;
4674 unsigned char *standard_opcodes
;
4675 unsigned char *end_of_sequence
;
4677 File_Entry
*file_table
= NULL
;
4678 unsigned int n_files
= 0;
4679 unsigned char **directory_table
= NULL
;
4680 dwarf_vma n_directories
= 0;
4682 if (const_strneq (section
->name
, ".debug_line.")
4683 /* Note: the following does not apply to .debug_line.dwo sections.
4684 These are full debug_line sections. */
4685 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4687 /* See comment in display_debug_lines_raw(). */
4688 end_of_sequence
= end
;
4689 standard_opcodes
= NULL
;
4690 linfo
= saved_linfo
;
4691 /* PR 17531: file: 0522b371. */
4692 if (linfo
.li_line_range
== 0)
4694 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4697 reset_state_machine (linfo
.li_default_is_stmt
);
4701 unsigned char *hdrptr
;
4703 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4704 & end_of_sequence
)) == NULL
)
4707 /* PR 17531: file: 0522b371. */
4708 if (linfo
.li_line_range
== 0)
4710 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4711 linfo
.li_line_range
= 1;
4713 reset_state_machine (linfo
.li_default_is_stmt
);
4715 /* Save a pointer to the contents of the Opcodes table. */
4716 standard_opcodes
= hdrptr
;
4718 /* Traverse the Directory table just to count entries. */
4719 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4723 warn (_("opcode base of %d extends beyond end of section\n"),
4724 linfo
.li_opcode_base
);
4728 if (linfo
.li_version
>= 5)
4730 unsigned char *format_start
, format_count
, *format
;
4731 dwarf_vma formati
, entryi
;
4733 load_debug_section_with_follow (line_str
, fileptr
);
4735 /* Skip directories format. */
4736 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4737 if (do_checks
&& format_count
> 1)
4738 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4740 format_start
= data
;
4741 for (formati
= 0; formati
< format_count
; formati
++)
4743 SKIP_ULEB (data
, end
);
4744 SKIP_ULEB (data
, end
);
4747 READ_ULEB (n_directories
, data
, end
);
4750 warn (_("Corrupt directories list\n"));
4754 if (n_directories
== 0)
4755 directory_table
= NULL
;
4757 directory_table
= (unsigned char **)
4758 xmalloc (n_directories
* sizeof (unsigned char *));
4760 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4762 unsigned char **pathp
= &directory_table
[entryi
];
4764 format
= format_start
;
4765 for (formati
= 0; formati
< format_count
; formati
++)
4767 dwarf_vma content_type
, form
;
4770 READ_ULEB (content_type
, format
, end
);
4771 READ_ULEB (form
, format
, end
);
4774 warn (_("Corrupt directories list\n"));
4777 switch (content_type
)
4782 case DW_FORM_string
:
4785 case DW_FORM_line_strp
:
4786 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4788 /* Remove const by the cast. */
4789 *pathp
= (unsigned char *)
4790 fetch_indirect_line_string (uvalue
);
4795 data
= read_and_display_attr_value (0, form
, 0, start
,
4797 linfo
.li_offset_size
,
4804 warn (_("Corrupt directories list\n"));
4809 /* Skip files format. */
4810 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4811 if (do_checks
&& format_count
> 5)
4812 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
4814 format_start
= data
;
4815 for (formati
= 0; formati
< format_count
; formati
++)
4817 SKIP_ULEB (data
, end
);
4818 SKIP_ULEB (data
, end
);
4821 READ_ULEB (n_files
, data
, end
);
4822 if (data
== end
&& n_files
> 0)
4824 warn (_("Corrupt file name list\n"));
4831 file_table
= (File_Entry
*) xcalloc (1, n_files
4832 * sizeof (File_Entry
));
4834 for (entryi
= 0; entryi
< n_files
; entryi
++)
4836 File_Entry
*file
= &file_table
[entryi
];
4838 format
= format_start
;
4839 for (formati
= 0; formati
< format_count
; formati
++)
4841 dwarf_vma content_type
, form
;
4845 READ_ULEB (content_type
, format
, end
);
4846 READ_ULEB (form
, format
, end
);
4849 warn (_("Corrupt file name list\n"));
4852 switch (content_type
)
4857 case DW_FORM_string
:
4860 case DW_FORM_line_strp
:
4861 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4863 /* Remove const by the cast. */
4864 file
->name
= (unsigned char *)
4865 fetch_indirect_line_string (uvalue
);
4869 case DW_LNCT_directory_index
:
4873 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4877 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4882 READ_ULEB (file
->directory_index
, tmp
, end
);
4887 data
= read_and_display_attr_value (0, form
, 0, start
,
4889 linfo
.li_offset_size
,
4896 warn (_("Corrupt file name list\n"));
4905 unsigned char *ptr_directory_table
= data
;
4907 while (data
< end
&& *data
!= 0)
4909 data
+= strnlen ((char *) data
, end
- data
) + 1;
4916 warn (_("directory table ends unexpectedly\n"));
4921 /* Go through the directory table again to save the directories. */
4922 directory_table
= (unsigned char **)
4923 xmalloc (n_directories
* sizeof (unsigned char *));
4926 while (*ptr_directory_table
!= 0)
4928 directory_table
[i
] = ptr_directory_table
;
4929 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
4930 ptr_directory_table
- end
) + 1;
4934 /* Skip the NUL at the end of the table. */
4937 /* Traverse the File Name table just to count the entries. */
4938 if (data
< end
&& *data
!= 0)
4940 unsigned char *ptr_file_name_table
= data
;
4942 while (data
< end
&& *data
!= 0)
4944 /* Skip Name, directory index, last modification
4945 time and length of file. */
4946 data
+= strnlen ((char *) data
, end
- data
) + 1;
4947 SKIP_ULEB (data
, end
);
4948 SKIP_ULEB (data
, end
);
4949 SKIP_ULEB (data
, end
);
4955 warn (_("file table ends unexpectedly\n"));
4960 /* Go through the file table again to save the strings. */
4961 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
4964 while (*ptr_file_name_table
!= 0)
4966 file_table
[i
].name
= ptr_file_name_table
;
4967 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
4968 end
- ptr_file_name_table
) + 1;
4970 /* We are not interested in directory, time or size. */
4971 READ_ULEB (file_table
[i
].directory_index
,
4972 ptr_file_name_table
, end
);
4973 READ_ULEB (file_table
[i
].modification_date
,
4974 ptr_file_name_table
, end
);
4975 READ_ULEB (file_table
[i
].length
,
4976 ptr_file_name_table
, end
);
4982 /* Skip the NUL at the end of the table. */
4986 /* Print the Compilation Unit's name and a header. */
4987 if (file_table
== NULL
)
4988 printf (_("CU: No directory table\n"));
4989 else if (directory_table
== NULL
)
4990 printf (_("CU: %s:\n"), file_table
[0].name
);
4993 unsigned int ix
= file_table
[0].directory_index
;
4994 const char *directory
;
4999 else if (n_directories
== 0)
5000 directory
= _("<unknown>");
5001 else if (ix
> n_directories
)
5003 warn (_("directory index %u > number of directories %s\n"),
5004 ix
, dwarf_vmatoa ("u", n_directories
));
5005 directory
= _("<corrupt>");
5008 directory
= (char *) directory_table
[ix
- 1];
5010 if (do_wide
|| strlen (directory
) < 76)
5011 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5013 printf ("%s:\n", file_table
[0].name
);
5017 printf (_("File name Line number Starting address View Stmt\n"));
5019 printf (_("CU: Empty file name table\n"));
5020 saved_linfo
= linfo
;
5023 /* This loop iterates through the Dwarf Line Number Program. */
5024 while (data
< end_of_sequence
)
5026 unsigned char op_code
;
5029 unsigned long int uladv
;
5030 int is_special_opcode
= 0;
5035 if (op_code
>= linfo
.li_opcode_base
)
5037 op_code
-= linfo
.li_opcode_base
;
5038 uladv
= (op_code
/ linfo
.li_line_range
);
5039 if (linfo
.li_max_ops_per_insn
== 1)
5041 uladv
*= linfo
.li_min_insn_length
;
5042 state_machine_regs
.address
+= uladv
;
5044 state_machine_regs
.view
= 0;
5049 = ((state_machine_regs
.op_index
+ uladv
)
5050 / linfo
.li_max_ops_per_insn
)
5051 * linfo
.li_min_insn_length
;
5052 state_machine_regs
.address
5054 state_machine_regs
.op_index
5055 = (state_machine_regs
.op_index
+ uladv
)
5056 % linfo
.li_max_ops_per_insn
;
5058 state_machine_regs
.view
= 0;
5061 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5062 state_machine_regs
.line
+= adv
;
5063 is_special_opcode
= 1;
5064 /* Increment view after printing this row. */
5069 case DW_LNS_extended_op
:
5071 unsigned int ext_op_code_len
;
5072 unsigned char ext_op_code
;
5073 unsigned char *op_code_end
;
5074 unsigned char *op_code_data
= data
;
5076 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5077 op_code_end
= op_code_data
+ ext_op_code_len
;
5078 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5080 warn (_("Badly formed extended line op encountered!\n"));
5083 ext_op_code
= *op_code_data
++;
5087 switch (ext_op_code
)
5089 case DW_LNE_end_sequence
:
5090 /* Reset stuff after printing this row. */
5092 case DW_LNE_set_address
:
5093 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5095 op_code_end
- op_code_data
,
5097 state_machine_regs
.op_index
= 0;
5098 state_machine_regs
.view
= 0;
5100 case DW_LNE_define_file
:
5101 file_table
= (File_Entry
*) xrealloc
5102 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5104 ++state_machine_regs
.last_file_entry
;
5105 /* Source file name. */
5106 file_table
[n_files
].name
= op_code_data
;
5107 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5108 /* Directory index. */
5109 READ_ULEB (file_table
[n_files
].directory_index
,
5110 op_code_data
, op_code_end
);
5111 /* Last modification time. */
5112 READ_ULEB (file_table
[n_files
].modification_date
,
5113 op_code_data
, op_code_end
);
5115 READ_ULEB (file_table
[n_files
].length
,
5116 op_code_data
, op_code_end
);
5120 case DW_LNE_set_discriminator
:
5121 case DW_LNE_HP_set_sequence
:
5122 /* Simply ignored. */
5126 printf (_("UNKNOWN (%u): length %ld\n"),
5127 ext_op_code
, (long int) (op_code_data
- data
));
5134 /* Increment view after printing this row. */
5137 case DW_LNS_advance_pc
:
5138 READ_ULEB (uladv
, data
, end
);
5139 if (linfo
.li_max_ops_per_insn
== 1)
5141 uladv
*= linfo
.li_min_insn_length
;
5142 state_machine_regs
.address
+= uladv
;
5144 state_machine_regs
.view
= 0;
5149 = ((state_machine_regs
.op_index
+ uladv
)
5150 / linfo
.li_max_ops_per_insn
)
5151 * linfo
.li_min_insn_length
;
5152 state_machine_regs
.address
5154 state_machine_regs
.op_index
5155 = (state_machine_regs
.op_index
+ uladv
)
5156 % linfo
.li_max_ops_per_insn
;
5158 state_machine_regs
.view
= 0;
5162 case DW_LNS_advance_line
:
5163 READ_SLEB (adv
, data
, end
);
5164 state_machine_regs
.line
+= adv
;
5167 case DW_LNS_set_file
:
5168 READ_ULEB (uladv
, data
, end
);
5169 state_machine_regs
.file
= uladv
;
5172 unsigned file
= state_machine_regs
.file
- 1;
5175 if (file_table
== NULL
|| n_files
== 0)
5176 printf (_("\n [Use file table entry %d]\n"), file
);
5178 else if (file
>= n_files
)
5180 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
5181 printf (_("\n <over large file table index %u>"), file
);
5183 else if ((dir
= file_table
[file
].directory_index
) == 0)
5184 /* If directory index is 0, that means current directory. */
5185 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5186 else if (directory_table
== NULL
|| n_directories
== 0)
5187 printf (_("\n [Use file %s in directory table entry %d]\n"),
5188 file_table
[file
].name
, dir
);
5190 else if (dir
> n_directories
)
5192 warn (_("directory index %u > number of directories %s\n"),
5193 dir
, dwarf_vmatoa ("u", n_directories
));
5194 printf (_("\n <over large directory table entry %u>\n"), dir
);
5197 printf ("\n%s/%s:\n",
5198 /* The directory index starts counting at 1. */
5199 directory_table
[dir
- 1], file_table
[file
].name
);
5203 case DW_LNS_set_column
:
5204 READ_ULEB (uladv
, data
, end
);
5205 state_machine_regs
.column
= uladv
;
5208 case DW_LNS_negate_stmt
:
5209 adv
= state_machine_regs
.is_stmt
;
5211 state_machine_regs
.is_stmt
= adv
;
5214 case DW_LNS_set_basic_block
:
5215 state_machine_regs
.basic_block
= 1;
5218 case DW_LNS_const_add_pc
:
5219 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5220 if (linfo
.li_max_ops_per_insn
== 1)
5222 uladv
*= linfo
.li_min_insn_length
;
5223 state_machine_regs
.address
+= uladv
;
5225 state_machine_regs
.view
= 0;
5230 = ((state_machine_regs
.op_index
+ uladv
)
5231 / linfo
.li_max_ops_per_insn
)
5232 * linfo
.li_min_insn_length
;
5233 state_machine_regs
.address
5235 state_machine_regs
.op_index
5236 = (state_machine_regs
.op_index
+ uladv
)
5237 % linfo
.li_max_ops_per_insn
;
5239 state_machine_regs
.view
= 0;
5243 case DW_LNS_fixed_advance_pc
:
5244 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5245 state_machine_regs
.address
+= uladv
;
5246 state_machine_regs
.op_index
= 0;
5247 /* Do NOT reset view. */
5250 case DW_LNS_set_prologue_end
:
5253 case DW_LNS_set_epilogue_begin
:
5256 case DW_LNS_set_isa
:
5257 READ_ULEB (uladv
, data
, end
);
5258 printf (_(" Set ISA to %lu\n"), uladv
);
5262 printf (_(" Unknown opcode %d with operands: "), op_code
);
5264 if (standard_opcodes
!= NULL
)
5265 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5269 READ_ULEB (val
, data
, end
);
5270 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5271 i
== 1 ? "" : ", ");
5277 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5278 to the DWARF address/line matrix. */
5279 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5280 || (xop
== DW_LNS_copy
))
5282 const unsigned int MAX_FILENAME_LENGTH
= 35;
5284 char *newFileName
= NULL
;
5285 size_t fileNameLength
;
5289 unsigned indx
= state_machine_regs
.file
- 1;
5291 if (indx
>= n_files
)
5293 warn (_("corrupt file index %u encountered\n"), indx
);
5294 fileName
= _("<corrupt>");
5297 fileName
= (char *) file_table
[indx
].name
;
5300 fileName
= _("<unknown>");
5302 fileNameLength
= strlen (fileName
);
5304 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5306 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5307 /* Truncate file name */
5308 strncpy (newFileName
,
5309 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5310 MAX_FILENAME_LENGTH
+ 1);
5311 /* FIXME: This is to pacify gcc-10 which can warn that the
5312 strncpy above might leave a non-NUL terminated string
5313 in newFileName. It won't, but gcc's analysis doesn't
5314 quite go far enough to discover this. */
5315 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5319 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5320 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5323 /* A row with end_seq set to true has a meaningful address, but
5324 the other information in the same row is not significant.
5325 In such a row, print line as "-", and don't print
5327 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5329 if (linfo
.li_max_ops_per_insn
== 1)
5331 if (xop
== -DW_LNE_end_sequence
)
5332 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5334 state_machine_regs
.address
);
5336 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5337 newFileName
, state_machine_regs
.line
,
5338 state_machine_regs
.address
);
5342 if (xop
== -DW_LNE_end_sequence
)
5343 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5345 state_machine_regs
.address
,
5346 state_machine_regs
.op_index
);
5348 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5349 newFileName
, state_machine_regs
.line
,
5350 state_machine_regs
.address
,
5351 state_machine_regs
.op_index
);
5356 if (linfo
.li_max_ops_per_insn
== 1)
5358 if (xop
== -DW_LNE_end_sequence
)
5359 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5361 state_machine_regs
.address
);
5363 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5364 newFileName
, state_machine_regs
.line
,
5365 state_machine_regs
.address
);
5369 if (xop
== -DW_LNE_end_sequence
)
5370 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5372 state_machine_regs
.address
,
5373 state_machine_regs
.op_index
);
5375 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5376 newFileName
, state_machine_regs
.line
,
5377 state_machine_regs
.address
,
5378 state_machine_regs
.op_index
);
5382 if (xop
!= -DW_LNE_end_sequence
)
5384 if (state_machine_regs
.view
)
5385 printf (" %6u", state_machine_regs
.view
);
5389 if (state_machine_regs
.is_stmt
)
5394 state_machine_regs
.view
++;
5396 if (xop
== -DW_LNE_end_sequence
)
5398 reset_state_machine (linfo
.li_default_is_stmt
);
5413 if (directory_table
)
5415 free (directory_table
);
5416 directory_table
= NULL
;
5427 display_debug_lines (struct dwarf_section
*section
, void *file
)
5429 unsigned char *data
= section
->start
;
5430 unsigned char *end
= data
+ section
->size
;
5432 int retValDecoded
= 1;
5434 if (do_debug_lines
== 0)
5435 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5437 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5438 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5440 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5441 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5443 if (!retValRaw
|| !retValDecoded
)
5450 find_debug_info_for_offset (unsigned long offset
)
5454 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5457 for (i
= 0; i
< num_debug_info_entries
; i
++)
5458 if (debug_information
[i
].cu_offset
== offset
)
5459 return debug_information
+ i
;
5465 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5467 /* See gdb/gdb-index.h. */
5468 static const char * const kinds
[] =
5480 return _ (kinds
[kind
]);
5484 display_debug_pubnames_worker (struct dwarf_section
*section
,
5485 void *file ATTRIBUTE_UNUSED
,
5488 DWARF2_Internal_PubNames names
;
5489 unsigned char *start
= section
->start
;
5490 unsigned char *end
= start
+ section
->size
;
5492 /* It does not matter if this load fails,
5493 we test for that later on. */
5494 load_debug_info (file
);
5496 introduce (section
, FALSE
);
5500 unsigned char *data
;
5501 unsigned long sec_off
;
5502 unsigned int offset_size
, initial_length_size
;
5504 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5505 if (names
.pn_length
== 0xffffffff)
5507 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5509 initial_length_size
= 12;
5514 initial_length_size
= 4;
5517 sec_off
= start
- section
->start
;
5518 if (sec_off
+ names
.pn_length
< sec_off
5519 || sec_off
+ names
.pn_length
> section
->size
)
5521 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5523 sec_off
- initial_length_size
,
5524 dwarf_vmatoa ("x", names
.pn_length
));
5529 start
+= names
.pn_length
;
5531 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5532 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5534 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5535 && num_debug_info_entries
> 0
5536 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5537 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5538 (unsigned long) names
.pn_offset
, section
->name
);
5540 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5542 printf (_(" Length: %ld\n"),
5543 (long) names
.pn_length
);
5544 printf (_(" Version: %d\n"),
5546 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5547 (unsigned long) names
.pn_offset
);
5548 printf (_(" Size of area in .debug_info section: %ld\n"),
5549 (long) names
.pn_size
);
5551 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5553 static int warned
= 0;
5557 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5565 printf (_("\n Offset Kind Name\n"));
5567 printf (_("\n Offset\tName\n"));
5571 bfd_size_type maxprint
;
5574 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5579 data
+= offset_size
;
5582 maxprint
= (end
- data
) - 1;
5586 unsigned int kind_data
;
5587 gdb_index_symbol_kind kind
;
5588 const char *kind_name
;
5591 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5594 /* GCC computes the kind as the upper byte in the CU index
5595 word, and then right shifts it by the CU index size.
5596 Left shift KIND to where the gdb-index.h accessor macros
5598 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5599 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5600 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5601 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5602 printf (" %-6lx %s,%-10s %.*s\n",
5603 (unsigned long) offset
, is_static
? _("s") : _("g"),
5604 kind_name
, (int) maxprint
, data
);
5607 printf (" %-6lx\t%.*s\n",
5608 (unsigned long) offset
, (int) maxprint
, data
);
5610 data
+= strnlen ((char *) data
, maxprint
) + 1;
5621 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5623 return display_debug_pubnames_worker (section
, file
, 0);
5627 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5629 return display_debug_pubnames_worker (section
, file
, 1);
5633 display_debug_macinfo (struct dwarf_section
*section
,
5634 void *file ATTRIBUTE_UNUSED
)
5636 unsigned char *start
= section
->start
;
5637 unsigned char *end
= start
+ section
->size
;
5638 unsigned char *curr
= start
;
5639 enum dwarf_macinfo_record_type op
;
5641 introduce (section
, FALSE
);
5645 unsigned int lineno
;
5646 const unsigned char *string
;
5648 op
= (enum dwarf_macinfo_record_type
) *curr
;
5653 case DW_MACINFO_start_file
:
5655 unsigned int filenum
;
5657 READ_ULEB (lineno
, curr
, end
);
5658 READ_ULEB (filenum
, curr
, end
);
5659 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5664 case DW_MACINFO_end_file
:
5665 printf (_(" DW_MACINFO_end_file\n"));
5668 case DW_MACINFO_define
:
5669 READ_ULEB (lineno
, curr
, end
);
5671 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5672 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5676 case DW_MACINFO_undef
:
5677 READ_ULEB (lineno
, curr
, end
);
5679 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5680 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5684 case DW_MACINFO_vendor_ext
:
5686 unsigned int constant
;
5688 READ_ULEB (constant
, curr
, end
);
5690 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5691 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5701 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5702 filename and dirname corresponding to file name table entry with index
5703 FILEIDX. Return NULL on failure. */
5705 static unsigned char *
5706 get_line_filename_and_dirname (dwarf_vma line_offset
,
5708 unsigned char **dir_name
)
5710 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5711 unsigned char *hdrptr
, *dirtable
, *file_name
;
5712 unsigned int offset_size
, initial_length_size
;
5713 unsigned int version
, opcode_base
;
5714 dwarf_vma length
, diridx
;
5715 const unsigned char * end
;
5718 if (section
->start
== NULL
5719 || line_offset
>= section
->size
5723 hdrptr
= section
->start
+ line_offset
;
5724 end
= section
->start
+ section
->size
;
5726 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5727 if (length
== 0xffffffff)
5729 /* This section is 64-bit DWARF 3. */
5730 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5732 initial_length_size
= 12;
5737 initial_length_size
= 4;
5739 if (length
+ initial_length_size
< length
5740 || length
+ initial_length_size
> section
->size
)
5743 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5744 if (version
!= 2 && version
!= 3 && version
!= 4)
5746 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5748 hdrptr
++; /* Skip max_ops_per_insn. */
5749 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5751 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5752 if (opcode_base
== 0)
5755 hdrptr
+= opcode_base
- 1;
5760 /* Skip over dirname table. */
5761 while (*hdrptr
!= '\0')
5763 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5767 hdrptr
++; /* Skip the NUL at the end of the table. */
5769 /* Now skip over preceding filename table entries. */
5770 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5772 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5773 SKIP_ULEB (hdrptr
, end
);
5774 SKIP_ULEB (hdrptr
, end
);
5775 SKIP_ULEB (hdrptr
, end
);
5777 if (hdrptr
>= end
|| *hdrptr
== '\0')
5781 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5784 READ_ULEB (diridx
, hdrptr
, end
);
5787 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5788 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5789 if (dirtable
>= end
|| *dirtable
== '\0')
5791 *dir_name
= dirtable
;
5796 display_debug_macro (struct dwarf_section
*section
,
5799 unsigned char *start
= section
->start
;
5800 unsigned char *end
= start
+ section
->size
;
5801 unsigned char *curr
= start
;
5802 unsigned char *extended_op_buf
[256];
5804 load_debug_section_with_follow (str
, file
);
5805 load_debug_section_with_follow (line
, file
);
5806 load_debug_section_with_follow (str_index
, file
);
5808 introduce (section
, FALSE
);
5812 unsigned int lineno
, version
, flags
;
5813 unsigned int offset_size
= 4;
5814 const unsigned char *string
;
5815 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5816 unsigned char **extended_ops
= NULL
;
5818 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5819 if (version
!= 4 && version
!= 5)
5821 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5826 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5829 printf (_(" Offset: 0x%lx\n"),
5830 (unsigned long) sec_offset
);
5831 printf (_(" Version: %d\n"), version
);
5832 printf (_(" Offset size: %d\n"), offset_size
);
5835 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5836 printf (_(" Offset into .debug_line: 0x%lx\n"),
5837 (unsigned long) line_offset
);
5841 unsigned int i
, count
, op
;
5844 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5846 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5847 extended_ops
= extended_op_buf
;
5850 printf (_(" Extension opcode arguments:\n"));
5851 for (i
= 0; i
< count
; i
++)
5853 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5854 extended_ops
[op
] = curr
;
5855 READ_ULEB (nargs
, curr
, end
);
5857 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5860 printf (_(" DW_MACRO_%02x arguments: "), op
);
5861 for (n
= 0; n
< nargs
; n
++)
5865 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5866 printf ("%s%s", get_FORM_name (form
),
5867 n
== nargs
- 1 ? "\n" : ", ");
5877 case DW_FORM_block1
:
5878 case DW_FORM_block2
:
5879 case DW_FORM_block4
:
5881 case DW_FORM_string
:
5883 case DW_FORM_sec_offset
:
5886 error (_("Invalid extension opcode form %s\n"),
5887 get_FORM_name (form
));
5903 error (_(".debug_macro section not zero terminated\n"));
5907 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5913 case DW_MACRO_define
:
5914 READ_ULEB (lineno
, curr
, end
);
5916 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5917 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5921 case DW_MACRO_undef
:
5922 READ_ULEB (lineno
, curr
, end
);
5924 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5925 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5929 case DW_MACRO_start_file
:
5931 unsigned int filenum
;
5932 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
5934 READ_ULEB (lineno
, curr
, end
);
5935 READ_ULEB (filenum
, curr
, end
);
5937 if ((flags
& 2) == 0)
5938 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5941 = get_line_filename_and_dirname (line_offset
, filenum
,
5943 if (file_name
== NULL
)
5944 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5947 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5949 dir_name
!= NULL
? (const char *) dir_name
: "",
5950 dir_name
!= NULL
? "/" : "", file_name
);
5954 case DW_MACRO_end_file
:
5955 printf (_(" DW_MACRO_end_file\n"));
5958 case DW_MACRO_define_strp
:
5959 READ_ULEB (lineno
, curr
, end
);
5960 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5961 string
= fetch_indirect_string (offset
);
5962 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5966 case DW_MACRO_undef_strp
:
5967 READ_ULEB (lineno
, curr
, end
);
5968 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5969 string
= fetch_indirect_string (offset
);
5970 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5974 case DW_MACRO_import
:
5975 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5976 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5977 (unsigned long) offset
);
5980 case DW_MACRO_define_sup
:
5981 READ_ULEB (lineno
, curr
, end
);
5982 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5983 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5984 lineno
, (unsigned long) offset
);
5987 case DW_MACRO_undef_sup
:
5988 READ_ULEB (lineno
, curr
, end
);
5989 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5990 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5991 lineno
, (unsigned long) offset
);
5994 case DW_MACRO_import_sup
:
5995 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5996 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5997 (unsigned long) offset
);
6000 case DW_MACRO_define_strx
:
6001 case DW_MACRO_undef_strx
:
6002 READ_ULEB (lineno
, curr
, end
);
6003 READ_ULEB (offset
, curr
, end
);
6004 string
= (const unsigned char *)
6005 fetch_indexed_string (offset
, NULL
, offset_size
, FALSE
);
6006 if (op
== DW_MACRO_define_strx
)
6007 printf (" DW_MACRO_define_strx ");
6009 printf (" DW_MACRO_undef_strx ");
6011 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6012 printf (_("lineno : %d macro : %s\n"),
6017 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6019 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6023 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6025 error (_(" Unknown macro opcode %02x seen\n"), op
);
6030 /* Skip over unhandled opcodes. */
6032 unsigned char *desc
= extended_ops
[op
];
6033 READ_ULEB (nargs
, desc
, end
);
6036 printf (_(" DW_MACRO_%02x\n"), op
);
6039 printf (_(" DW_MACRO_%02x -"), op
);
6040 for (n
= 0; n
< nargs
; n
++)
6044 /* DW_FORM_implicit_const is not expected here. */
6045 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6047 = read_and_display_attr_value (0, val
, 0,
6048 start
, curr
, end
, 0, 0, offset_size
,
6049 version
, NULL
, 0, NULL
,
6067 display_debug_abbrev (struct dwarf_section
*section
,
6068 void *file ATTRIBUTE_UNUSED
)
6070 abbrev_entry
*entry
;
6071 unsigned char *start
= section
->start
;
6072 const unsigned char *end
= start
+ section
->size
;
6074 introduce (section
, FALSE
);
6081 offset
= start
- section
->start
;
6082 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6085 list
= new_abbrev_list (0, offset
);
6086 start
= process_abbrev_set (start
, end
, list
);
6087 list
->start_of_next_abbrevs
= start
;
6090 start
= list
->start_of_next_abbrevs
;
6092 if (list
->first_abbrev
== NULL
)
6095 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6097 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6101 printf (" %ld %s [%s]\n",
6103 get_TAG_name (entry
->tag
),
6104 entry
->children
? _("has children") : _("no children"));
6106 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6108 printf (" %-18s %s",
6109 get_AT_name (attr
->attribute
),
6110 get_FORM_name (attr
->form
));
6111 if (attr
->form
== DW_FORM_implicit_const
)
6112 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
6124 /* Return true when ADDR is the maximum address, when addresses are
6125 POINTER_SIZE bytes long. */
6128 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6130 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6131 return ((addr
& mask
) == mask
);
6134 /* Display a view pair list starting at *VSTART_PTR and ending at
6135 VLISTEND within SECTION. */
6138 display_view_pair_list (struct dwarf_section
*section
,
6139 unsigned char **vstart_ptr
,
6140 unsigned int debug_info_entry
,
6141 unsigned char *vlistend
)
6143 unsigned char *vstart
= *vstart_ptr
;
6144 unsigned char *section_end
= section
->start
+ section
->size
;
6145 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6147 if (vlistend
< section_end
)
6148 section_end
= vlistend
;
6152 while (vstart
< section_end
)
6154 dwarf_vma off
= vstart
- section
->start
;
6155 dwarf_vma vbegin
, vend
;
6157 READ_ULEB (vbegin
, vstart
, section_end
);
6158 if (vstart
== section_end
)
6161 READ_ULEB (vend
, vstart
, section_end
);
6162 printf (" %8.8lx ", (unsigned long) off
);
6164 print_dwarf_view (vbegin
, pointer_size
, 1);
6165 print_dwarf_view (vend
, pointer_size
, 1);
6166 printf (_("location view pair\n"));
6170 *vstart_ptr
= vstart
;
6173 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6176 display_loc_list (struct dwarf_section
*section
,
6177 unsigned char **start_ptr
,
6178 unsigned int debug_info_entry
,
6180 dwarf_vma base_address
,
6181 unsigned char **vstart_ptr
,
6184 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6185 unsigned char *section_end
= section
->start
+ section
->size
;
6186 unsigned long cu_offset
;
6187 unsigned int pointer_size
;
6188 unsigned int offset_size
;
6193 unsigned short length
;
6194 int need_frame_base
;
6196 if (debug_info_entry
>= num_debug_info_entries
)
6198 warn (_("No debug information available for loc lists of entry: %u\n"),
6203 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6204 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6205 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6206 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6208 if (pointer_size
< 2 || pointer_size
> 8)
6210 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6211 pointer_size
, debug_info_entry
);
6217 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6218 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6220 if (start
+ 2 * pointer_size
> section_end
)
6222 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6223 (unsigned long) offset
);
6227 printf (" %8.8lx ", (unsigned long) off
);
6229 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6230 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6232 if (begin
== 0 && end
== 0)
6234 /* PR 18374: In a object file we can have a location list that
6235 starts with a begin and end of 0 because there are relocations
6236 that need to be applied to the addresses. Actually applying
6237 the relocations now does not help as they will probably resolve
6238 to 0, since the object file has not been fully linked. Real
6239 end of list markers will not have any relocations against them. */
6240 if (! reloc_at (section
, off
)
6241 && ! reloc_at (section
, off
+ pointer_size
))
6243 printf (_("<End of list>\n"));
6248 /* Check base address specifiers. */
6249 if (is_max_address (begin
, pointer_size
)
6250 && !is_max_address (end
, pointer_size
))
6253 print_dwarf_vma (begin
, pointer_size
);
6254 print_dwarf_vma (end
, pointer_size
);
6255 printf (_("(base address)\n"));
6261 off
= offset
+ (vstart
- *start_ptr
);
6263 READ_ULEB (vbegin
, vstart
, section_end
);
6264 print_dwarf_view (vbegin
, pointer_size
, 1);
6266 READ_ULEB (vend
, vstart
, section_end
);
6267 print_dwarf_view (vend
, pointer_size
, 1);
6269 printf (_("views at %8.8lx for:\n %*s "),
6270 (unsigned long) off
, 8, "");
6273 if (start
+ 2 > section_end
)
6275 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6276 (unsigned long) offset
);
6280 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6282 if (start
+ length
> section_end
)
6284 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6285 (unsigned long) offset
);
6289 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6290 print_dwarf_vma (end
+ base_address
, pointer_size
);
6293 need_frame_base
= decode_location_expression (start
,
6298 cu_offset
, section
);
6301 if (need_frame_base
&& !has_frame_base
)
6302 printf (_(" [without DW_AT_frame_base]"));
6304 if (begin
== end
&& vbegin
== vend
)
6305 fputs (_(" (start == end)"), stdout
);
6306 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6307 fputs (_(" (start > end)"), stdout
);
6315 *vstart_ptr
= vstart
;
6318 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6321 display_loclists_list (struct dwarf_section
*section
,
6322 unsigned char **start_ptr
,
6323 unsigned int debug_info_entry
,
6325 dwarf_vma base_address
,
6326 unsigned char **vstart_ptr
,
6329 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6330 unsigned char *section_end
= section
->start
+ section
->size
;
6331 unsigned long cu_offset
;
6332 unsigned int pointer_size
;
6333 unsigned int offset_size
;
6336 /* Initialize it due to a false compiler warning. */
6337 dwarf_vma begin
= -1, vbegin
= -1;
6338 dwarf_vma end
= -1, vend
= -1;
6340 int need_frame_base
;
6342 if (debug_info_entry
>= num_debug_info_entries
)
6344 warn (_("No debug information available for "
6345 "loclists lists of entry: %u\n"),
6350 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6351 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6352 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6353 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6355 if (pointer_size
< 2 || pointer_size
> 8)
6357 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6358 pointer_size
, debug_info_entry
);
6364 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6365 enum dwarf_location_list_entry_type llet
;
6367 if (start
+ 1 > section_end
)
6369 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6370 (unsigned long) offset
);
6374 printf (" %8.8lx ", (unsigned long) off
);
6376 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6378 if (vstart
&& (llet
== DW_LLE_offset_pair
6379 || llet
== DW_LLE_start_end
6380 || llet
== DW_LLE_start_length
))
6382 off
= offset
+ (vstart
- *start_ptr
);
6384 READ_ULEB (vbegin
, vstart
, section_end
);
6385 print_dwarf_view (vbegin
, pointer_size
, 1);
6387 READ_ULEB (vend
, vstart
, section_end
);
6388 print_dwarf_view (vend
, pointer_size
, 1);
6390 printf (_("views at %8.8lx for:\n %*s "),
6391 (unsigned long) off
, 8, "");
6396 case DW_LLE_end_of_list
:
6397 printf (_("<End of list>\n"));
6399 case DW_LLE_offset_pair
:
6400 READ_ULEB (begin
, start
, section_end
);
6401 begin
+= base_address
;
6402 READ_ULEB (end
, start
, section_end
);
6403 end
+= base_address
;
6405 case DW_LLE_start_end
:
6406 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6407 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6409 case DW_LLE_start_length
:
6410 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6411 READ_ULEB (end
, start
, section_end
);
6414 case DW_LLE_base_address
:
6415 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6417 print_dwarf_vma (base_address
, pointer_size
);
6418 printf (_("(base address)\n"));
6420 #ifdef DW_LLE_view_pair
6421 case DW_LLE_view_pair
:
6423 printf (_("View pair entry in loclist with locviews attribute\n"));
6424 READ_ULEB (vbegin
, start
, section_end
);
6425 print_dwarf_view (vbegin
, pointer_size
, 1);
6427 READ_ULEB (vend
, start
, section_end
);
6428 print_dwarf_view (vend
, pointer_size
, 1);
6430 printf (_("views for:\n"));
6434 error (_("Invalid location list entry type %d\n"), llet
);
6437 if (llet
== DW_LLE_end_of_list
)
6439 if (llet
!= DW_LLE_offset_pair
6440 && llet
!= DW_LLE_start_end
6441 && llet
!= DW_LLE_start_length
)
6444 if (start
+ 2 > section_end
)
6446 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6447 (unsigned long) offset
);
6451 READ_ULEB (length
, start
, section_end
);
6453 print_dwarf_vma (begin
, pointer_size
);
6454 print_dwarf_vma (end
, pointer_size
);
6457 need_frame_base
= decode_location_expression (start
,
6462 cu_offset
, section
);
6465 if (need_frame_base
&& !has_frame_base
)
6466 printf (_(" [without DW_AT_frame_base]"));
6468 if (begin
== end
&& vbegin
== vend
)
6469 fputs (_(" (start == end)"), stdout
);
6470 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6471 fputs (_(" (start > end)"), stdout
);
6479 if (vbegin
!= vm1
|| vend
!= vm1
)
6480 printf (_("Trailing view pair not used in a range"));
6483 *vstart_ptr
= vstart
;
6486 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6487 right-adjusted in a field of length LEN, and followed by a space. */
6490 print_addr_index (unsigned int idx
, unsigned int len
)
6492 static char buf
[15];
6493 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6494 printf ("%*s ", len
, buf
);
6497 /* Display a location list from a .dwo section. It uses address indexes rather
6498 than embedded addresses. This code closely follows display_loc_list, but the
6499 two are sufficiently different that combining things is very ugly. */
6502 display_loc_list_dwo (struct dwarf_section
*section
,
6503 unsigned char **start_ptr
,
6504 unsigned int debug_info_entry
,
6506 unsigned char **vstart_ptr
,
6509 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6510 unsigned char *section_end
= section
->start
+ section
->size
;
6511 unsigned long cu_offset
;
6512 unsigned int pointer_size
;
6513 unsigned int offset_size
;
6516 unsigned short length
;
6517 int need_frame_base
;
6520 if (debug_info_entry
>= num_debug_info_entries
)
6522 warn (_("No debug information for loc lists of entry: %u\n"),
6527 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6528 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6529 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6530 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6532 if (pointer_size
< 2 || pointer_size
> 8)
6534 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6535 pointer_size
, debug_info_entry
);
6541 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6543 if (start
>= section_end
)
6545 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6546 (unsigned long) offset
);
6550 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6563 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6565 READ_ULEB (view
, vstart
, section_end
);
6566 print_dwarf_view (view
, 8, 1);
6568 READ_ULEB (view
, vstart
, section_end
);
6569 print_dwarf_view (view
, 8, 1);
6571 printf (_("views at %8.8lx for:\n %*s "),
6572 (unsigned long) off
, 8, "");
6580 case 0: /* A terminating entry. */
6582 *vstart_ptr
= vstart
;
6583 printf (_("<End of list>\n"));
6585 case 1: /* A base-address entry. */
6586 READ_ULEB (idx
, start
, section_end
);
6587 print_addr_index (idx
, 8);
6588 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6589 printf (_("(base address selection entry)\n"));
6591 case 2: /* A start/end entry. */
6592 READ_ULEB (idx
, start
, section_end
);
6593 print_addr_index (idx
, 8);
6594 READ_ULEB (idx
, start
, section_end
);
6595 print_addr_index (idx
, 8);
6597 case 3: /* A start/length entry. */
6598 READ_ULEB (idx
, start
, section_end
);
6599 print_addr_index (idx
, 8);
6600 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6601 printf ("%08x ", idx
);
6603 case 4: /* An offset pair entry. */
6604 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6605 printf ("%08x ", idx
);
6606 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6607 printf ("%08x ", idx
);
6610 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6612 *vstart_ptr
= vstart
;
6616 if (start
+ 2 > section_end
)
6618 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6619 (unsigned long) offset
);
6623 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6624 if (start
+ length
> section_end
)
6626 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6627 (unsigned long) offset
);
6632 need_frame_base
= decode_location_expression (start
,
6637 cu_offset
, section
);
6640 if (need_frame_base
&& !has_frame_base
)
6641 printf (_(" [without DW_AT_frame_base]"));
6649 *vstart_ptr
= vstart
;
6652 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6655 static dwarf_vma
*loc_offsets
, *loc_views
;
6658 loc_offsets_compar (const void *ap
, const void *bp
)
6660 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6661 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6663 int ret
= (a
> b
) - (b
> a
);
6667 a
= loc_views
[*(const unsigned int *) ap
];
6668 b
= loc_views
[*(const unsigned int *) bp
];
6670 ret
= (a
> b
) - (b
> a
);
6676 display_debug_loc (struct dwarf_section
*section
, void *file
)
6678 unsigned char *start
= section
->start
, *vstart
= NULL
;
6679 unsigned long bytes
;
6680 unsigned char *section_begin
= start
;
6681 unsigned int num_loc_list
= 0;
6682 unsigned long last_offset
= 0;
6683 unsigned long last_view
= 0;
6684 unsigned int first
= 0;
6687 int seen_first_offset
= 0;
6688 int locs_sorted
= 1;
6689 unsigned char *next
= start
, *vnext
= vstart
;
6690 unsigned int *array
= NULL
;
6691 const char *suffix
= strrchr (section
->name
, '.');
6692 bfd_boolean is_dwo
= FALSE
;
6693 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6694 dwarf_vma expected_start
= 0;
6696 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6699 bytes
= section
->size
;
6703 printf (_("\nThe %s section is empty.\n"), section
->name
);
6709 unsigned char *hdrptr
= section_begin
;
6710 dwarf_vma ll_length
;
6711 unsigned short ll_version
;
6712 unsigned char *end
= section_begin
+ section
->size
;
6713 unsigned char address_size
, segment_selector_size
;
6714 uint32_t offset_entry_count
;
6716 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6717 if (ll_length
== 0xffffffff)
6718 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6720 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6721 if (ll_version
!= 5)
6723 warn (_("The %s section contains corrupt or "
6724 "unsupported version number: %d.\n"),
6725 section
->name
, ll_version
);
6729 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6731 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6732 if (segment_selector_size
!= 0)
6734 warn (_("The %s section contains "
6735 "unsupported segment selector size: %d.\n"),
6736 section
->name
, segment_selector_size
);
6740 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6741 if (offset_entry_count
!= 0)
6743 warn (_("The %s section contains "
6744 "unsupported offset entry count: %d.\n"),
6745 section
->name
, offset_entry_count
);
6749 expected_start
= hdrptr
- section_begin
;
6752 if (load_debug_info (file
) == 0)
6754 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6759 /* Check the order of location list in .debug_info section. If
6760 offsets of location lists are in the ascending order, we can
6761 use `debug_information' directly. */
6762 for (i
= 0; i
< num_debug_info_entries
; i
++)
6766 num
= debug_information
[i
].num_loc_offsets
;
6767 if (num
> num_loc_list
)
6770 /* Check if we can use `debug_information' directly. */
6771 if (locs_sorted
&& num
!= 0)
6773 if (!seen_first_offset
)
6775 /* This is the first location list. */
6776 last_offset
= debug_information
[i
].loc_offsets
[0];
6777 last_view
= debug_information
[i
].loc_views
[0];
6779 seen_first_offset
= 1;
6785 for (; j
< num
; j
++)
6788 debug_information
[i
].loc_offsets
[j
]
6789 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6790 && last_view
> debug_information
[i
].loc_views
[j
]))
6795 last_offset
= debug_information
[i
].loc_offsets
[j
];
6796 last_view
= debug_information
[i
].loc_views
[j
];
6801 if (!seen_first_offset
)
6802 error (_("No location lists in .debug_info section!\n"));
6804 if (debug_information
[first
].num_loc_offsets
> 0
6805 && debug_information
[first
].loc_offsets
[0] != expected_start
6806 && debug_information
[first
].loc_views
[0] != expected_start
)
6807 warn (_("Location lists in %s section start at 0x%s\n"),
6809 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6812 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6814 introduce (section
, FALSE
);
6816 if (reloc_at (section
, 0))
6817 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6819 printf (_(" Offset Begin End Expression\n"));
6821 seen_first_offset
= 0;
6822 for (i
= first
; i
< num_debug_info_entries
; i
++)
6824 dwarf_vma offset
, voffset
;
6825 dwarf_vma base_address
;
6831 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6833 loc_offsets
= debug_information
[i
].loc_offsets
;
6834 loc_views
= debug_information
[i
].loc_views
;
6835 qsort (array
, debug_information
[i
].num_loc_offsets
,
6836 sizeof (*array
), loc_offsets_compar
);
6839 int adjacent_view_loclists
= 1;
6840 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6842 j
= locs_sorted
? k
: array
[k
];
6844 && (debug_information
[i
].loc_offsets
[locs_sorted
6845 ? k
- 1 : array
[k
- 1]]
6846 == debug_information
[i
].loc_offsets
[j
])
6847 && (debug_information
[i
].loc_views
[locs_sorted
6848 ? k
- 1 : array
[k
- 1]]
6849 == debug_information
[i
].loc_views
[j
]))
6851 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6852 offset
= debug_information
[i
].loc_offsets
[j
];
6853 next
= section_begin
+ offset
;
6854 voffset
= debug_information
[i
].loc_views
[j
];
6856 vnext
= section_begin
+ voffset
;
6859 base_address
= debug_information
[i
].base_address
;
6861 if (vnext
&& vnext
< next
)
6864 display_view_pair_list (section
, &vstart
, i
, next
);
6869 if (!seen_first_offset
|| !adjacent_view_loclists
)
6870 seen_first_offset
= 1;
6874 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6875 (unsigned long) (start
- section_begin
),
6876 (unsigned long) offset
);
6877 else if (start
> next
)
6878 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6879 (unsigned long) (start
- section_begin
),
6880 (unsigned long) offset
);
6885 if (offset
>= bytes
)
6887 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6888 (unsigned long) offset
);
6892 if (vnext
&& voffset
>= bytes
)
6894 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6895 (unsigned long) voffset
);
6902 display_loc_list_dwo (section
, &start
, i
, offset
,
6903 &vstart
, has_frame_base
);
6905 display_loc_list (section
, &start
, i
, offset
, base_address
,
6906 &vstart
, has_frame_base
);
6911 warn (_("DWO is not yet supported.\n"));
6913 display_loclists_list (section
, &start
, i
, offset
, base_address
,
6914 &vstart
, has_frame_base
);
6917 /* FIXME: this arrangement is quite simplistic. Nothing
6918 requires locview lists to be adjacent to corresponding
6919 loclists, and a single loclist could be augmented by
6920 different locview lists, and vice-versa, unlikely as it
6921 is that it would make sense to do so. Hopefully we'll
6922 have view pair support built into loclists before we ever
6923 need to address all these possibilities. */
6924 if (adjacent_view_loclists
&& vnext
6925 && vnext
!= start
&& vstart
!= next
)
6927 adjacent_view_loclists
= 0;
6928 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6931 if (vnext
&& vnext
== start
)
6932 display_view_pair_list (section
, &start
, i
, vstart
);
6936 if (start
< section
->start
+ section
->size
)
6937 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6938 "There are %ld unused bytes at the end of section %s\n",
6939 (long) (section
->start
+ section
->size
- start
)),
6940 (long) (section
->start
+ section
->size
- start
), section
->name
);
6947 display_debug_str (struct dwarf_section
*section
,
6948 void *file ATTRIBUTE_UNUSED
)
6950 unsigned char *start
= section
->start
;
6951 unsigned long bytes
= section
->size
;
6952 dwarf_vma addr
= section
->address
;
6956 printf (_("\nThe %s section is empty.\n"), section
->name
);
6960 introduce (section
, FALSE
);
6968 lbytes
= (bytes
> 16 ? 16 : bytes
);
6970 printf (" 0x%8.8lx ", (unsigned long) addr
);
6972 for (j
= 0; j
< 16; j
++)
6975 printf ("%2.2x", start
[j
]);
6983 for (j
= 0; j
< lbytes
; j
++)
6986 if (k
>= ' ' && k
< 0x80)
7005 display_debug_info (struct dwarf_section
*section
, void *file
)
7007 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, FALSE
);
7011 display_debug_types (struct dwarf_section
*section
, void *file
)
7013 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
7017 display_trace_info (struct dwarf_section
*section
, void *file
)
7019 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
7023 display_debug_aranges (struct dwarf_section
*section
,
7024 void *file ATTRIBUTE_UNUSED
)
7026 unsigned char *start
= section
->start
;
7027 unsigned char *end
= start
+ section
->size
;
7029 introduce (section
, FALSE
);
7031 /* It does not matter if this load fails,
7032 we test for that later on. */
7033 load_debug_info (file
);
7037 unsigned char *hdrptr
;
7038 DWARF2_Internal_ARange arange
;
7039 unsigned char *addr_ranges
;
7042 unsigned long sec_off
;
7043 unsigned char address_size
;
7045 unsigned int offset_size
;
7046 unsigned int initial_length_size
;
7050 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7051 if (arange
.ar_length
== 0xffffffff)
7053 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7055 initial_length_size
= 12;
7060 initial_length_size
= 4;
7063 sec_off
= hdrptr
- section
->start
;
7064 if (sec_off
+ arange
.ar_length
< sec_off
7065 || sec_off
+ arange
.ar_length
> section
->size
)
7067 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7069 sec_off
- initial_length_size
,
7070 dwarf_vmatoa ("x", arange
.ar_length
));
7074 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
7075 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
7077 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7078 && num_debug_info_entries
> 0
7079 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7080 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7081 (unsigned long) arange
.ar_info_offset
, section
->name
);
7083 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
7084 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
7086 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7088 /* PR 19872: A version number of 0 probably means that there is
7089 padding at the end of the .debug_aranges section. Gold puts
7090 it there when performing an incremental link, for example.
7091 So do not generate a warning in this case. */
7092 if (arange
.ar_version
)
7093 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7097 printf (_(" Length: %ld\n"),
7098 (long) arange
.ar_length
);
7099 printf (_(" Version: %d\n"), arange
.ar_version
);
7100 printf (_(" Offset into .debug_info: 0x%lx\n"),
7101 (unsigned long) arange
.ar_info_offset
);
7102 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7103 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7105 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7107 /* PR 17512: file: 001-108546-0.001:0.1. */
7108 if (address_size
== 0 || address_size
> 8)
7110 error (_("Invalid address size in %s section!\n"),
7115 /* The DWARF spec does not require that the address size be a power
7116 of two, but we do. This will have to change if we ever encounter
7117 an uneven architecture. */
7118 if ((address_size
& (address_size
- 1)) != 0)
7120 warn (_("Pointer size + Segment size is not a power of two.\n"));
7124 if (address_size
> 4)
7125 printf (_("\n Address Length\n"));
7127 printf (_("\n Address Length\n"));
7129 addr_ranges
= hdrptr
;
7131 /* Must pad to an alignment boundary that is twice the address size. */
7132 excess
= (hdrptr
- start
) % (2 * address_size
);
7134 addr_ranges
+= (2 * address_size
) - excess
;
7136 start
+= arange
.ar_length
+ initial_length_size
;
7138 while (addr_ranges
+ 2 * address_size
<= start
)
7140 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
7141 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
7144 print_dwarf_vma (address
, address_size
);
7145 print_dwarf_vma (length
, address_size
);
7155 /* Comparison function for qsort. */
7157 comp_addr_base (const void * v0
, const void * v1
)
7159 debug_info
*info0
= *(debug_info
**) v0
;
7160 debug_info
*info1
= *(debug_info
**) v1
;
7161 return info0
->addr_base
- info1
->addr_base
;
7164 /* Display the debug_addr section. */
7166 display_debug_addr (struct dwarf_section
*section
,
7169 debug_info
**debug_addr_info
;
7170 unsigned char *entry
;
7175 if (section
->size
== 0)
7177 printf (_("\nThe %s section is empty.\n"), section
->name
);
7181 if (load_debug_info (file
) == 0)
7183 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7188 introduce (section
, FALSE
);
7190 /* PR 17531: file: cf38d01b.
7191 We use xcalloc because a corrupt file may not have initialised all of the
7192 fields in the debug_info structure, which means that the sort below might
7193 try to move uninitialised data. */
7194 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7195 sizeof (debug_info
*));
7198 for (i
= 0; i
< num_debug_info_entries
; i
++)
7199 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7201 /* PR 17531: file: cf38d01b. */
7202 if (debug_information
[i
].addr_base
>= section
->size
)
7203 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7204 (unsigned long) debug_information
[i
].addr_base
, i
);
7206 debug_addr_info
[count
++] = debug_information
+ i
;
7209 /* Add a sentinel to make iteration convenient. */
7210 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7211 debug_addr_info
[count
]->addr_base
= section
->size
;
7212 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7214 for (i
= 0; i
< count
; i
++)
7217 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7219 printf (_(" For compilation unit at offset 0x%s:\n"),
7220 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7222 printf (_("\tIndex\tAddress\n"));
7223 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7224 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7228 dwarf_vma base
= byte_get (entry
, address_size
);
7229 printf (_("\t%d:\t"), idx
);
7230 print_dwarf_vma (base
, address_size
);
7232 entry
+= address_size
;
7238 free (debug_addr_info
);
7242 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7245 display_debug_str_offsets (struct dwarf_section
*section
,
7246 void *file ATTRIBUTE_UNUSED
)
7250 if (section
->size
== 0)
7252 printf (_("\nThe %s section is empty.\n"), section
->name
);
7256 unsigned char *start
= section
->start
;
7257 unsigned char *end
= start
+ section
->size
;
7258 unsigned char *curr
= start
;
7260 const char * suffix
= strrchr (section
->name
, '.');
7261 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
7264 load_debug_section_with_follow (str_dwo
, file
);
7266 load_debug_section_with_follow (str
, file
);
7268 introduce (section
, FALSE
);
7273 dwarf_vma entry_length
;
7275 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7276 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7277 if (length
== 0xffffffff)
7279 SAFE_BYTE_GET (length
, curr
, 8, end
);
7287 /* This is probably an old style .debug_str_offset section which
7288 just contains offsets and no header (and the first offset is 0). */
7289 length
= section
->size
;
7290 curr
= section
->start
;
7292 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7293 printf (_(" Index Offset [String]\n"));
7298 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
7300 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7303 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
7305 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7307 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7308 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7309 printf (_(" Index Offset [String]\n"));
7312 for (idx
= 0; length
>= entry_length
&& curr
< end
; idx
++)
7315 const unsigned char * string
;
7317 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
7319 string
= (const unsigned char *)
7320 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7322 string
= fetch_indirect_string (offset
);
7324 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7332 /* Each debug_information[x].range_lists[y] gets this representation for
7333 sorting purposes. */
7337 /* The debug_information[x].range_lists[y] value. */
7338 dwarf_vma ranges_offset
;
7340 /* Original debug_information to find parameters of the data. */
7341 debug_info
*debug_info_p
;
7344 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7347 range_entry_compar (const void *ap
, const void *bp
)
7349 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7350 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7351 const dwarf_vma a
= a_re
->ranges_offset
;
7352 const dwarf_vma b
= b_re
->ranges_offset
;
7354 return (a
> b
) - (b
> a
);
7358 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7359 unsigned int pointer_size
, unsigned long offset
,
7360 unsigned long base_address
)
7362 while (start
< finish
)
7367 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7368 if (start
>= finish
)
7370 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7373 printf (" %8.8lx ", offset
);
7375 if (begin
== 0 && end
== 0)
7377 printf (_("<End of list>\n"));
7381 /* Check base address specifiers. */
7382 if (is_max_address (begin
, pointer_size
)
7383 && !is_max_address (end
, pointer_size
))
7386 print_dwarf_vma (begin
, pointer_size
);
7387 print_dwarf_vma (end
, pointer_size
);
7388 printf ("(base address)\n");
7392 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7393 print_dwarf_vma (end
+ base_address
, pointer_size
);
7396 fputs (_("(start == end)"), stdout
);
7397 else if (begin
> end
)
7398 fputs (_("(start > end)"), stdout
);
7405 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7406 unsigned int pointer_size
, unsigned long offset
,
7407 unsigned long base_address
)
7409 unsigned char *next
= start
;
7413 unsigned long off
= offset
+ (start
- next
);
7414 enum dwarf_range_list_entry rlet
;
7415 /* Initialize it due to a false compiler warning. */
7416 dwarf_vma begin
= -1, length
, end
= -1;
7418 if (start
+ 1 > finish
)
7420 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7425 printf (" %8.8lx ", off
);
7427 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7431 case DW_RLE_end_of_list
:
7432 printf (_("<End of list>\n"));
7434 case DW_RLE_base_address
:
7435 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7436 print_dwarf_vma (base_address
, pointer_size
);
7437 printf (_("(base address)\n"));
7439 case DW_RLE_start_length
:
7440 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7441 READ_ULEB (length
, start
, finish
);
7442 end
= begin
+ length
;
7444 case DW_RLE_offset_pair
:
7445 READ_ULEB (begin
, start
, finish
);
7446 READ_ULEB (end
, start
, finish
);
7448 case DW_RLE_start_end
:
7449 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7450 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7453 error (_("Invalid range list entry type %d\n"), rlet
);
7454 rlet
= DW_RLE_end_of_list
;
7457 if (rlet
== DW_RLE_end_of_list
)
7459 if (rlet
== DW_RLE_base_address
)
7462 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7463 print_dwarf_vma (end
+ base_address
, pointer_size
);
7466 fputs (_("(start == end)"), stdout
);
7467 else if (begin
> end
)
7468 fputs (_("(start > end)"), stdout
);
7475 display_debug_ranges (struct dwarf_section
*section
,
7476 void *file ATTRIBUTE_UNUSED
)
7478 unsigned char *start
= section
->start
;
7479 unsigned char *last_start
= start
;
7480 unsigned long bytes
= section
->size
;
7481 unsigned char *section_begin
= start
;
7482 unsigned char *finish
= start
+ bytes
;
7483 unsigned int num_range_list
, i
;
7484 struct range_entry
*range_entries
, *range_entry_fill
;
7485 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7486 /* Initialize it due to a false compiler warning. */
7487 unsigned char address_size
= 0;
7488 dwarf_vma last_offset
= 0;
7492 printf (_("\nThe %s section is empty.\n"), section
->name
);
7498 dwarf_vma initial_length
;
7499 unsigned int initial_length_size
;
7500 unsigned char segment_selector_size
;
7501 unsigned int offset_size
, offset_entry_count
;
7502 unsigned short version
;
7504 /* Get and check the length of the block. */
7505 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7507 if (initial_length
== 0xffffffff)
7509 /* This section is 64-bit DWARF 3. */
7510 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7512 initial_length_size
= 12;
7517 initial_length_size
= 4;
7520 if (initial_length
+ initial_length_size
> section
->size
)
7522 /* If the length field has a relocation against it, then we should
7523 not complain if it is inaccurate (and probably negative).
7524 It is copied from .debug_line handling code. */
7525 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7527 initial_length
= (finish
- start
) - initial_length_size
;
7531 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7532 (long) initial_length
);
7537 /* Get and check the version number. */
7538 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7542 warn (_("Only DWARF version 5 debug_rnglists info "
7543 "is currently supported.\n"));
7547 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7549 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7550 if (segment_selector_size
!= 0)
7552 warn (_("The %s section contains "
7553 "unsupported segment selector size: %d.\n"),
7554 section
->name
, segment_selector_size
);
7558 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7559 if (offset_entry_count
!= 0)
7561 warn (_("The %s section contains "
7562 "unsupported offset entry count: %u.\n"),
7563 section
->name
, offset_entry_count
);
7568 if (load_debug_info (file
) == 0)
7570 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7576 for (i
= 0; i
< num_debug_info_entries
; i
++)
7577 num_range_list
+= debug_information
[i
].num_range_lists
;
7579 if (num_range_list
== 0)
7581 /* This can happen when the file was compiled with -gsplit-debug
7582 which removes references to range lists from the primary .o file. */
7583 printf (_("No range lists in .debug_info section.\n"));
7587 range_entries
= (struct range_entry
*)
7588 xmalloc (sizeof (*range_entries
) * num_range_list
);
7589 range_entry_fill
= range_entries
;
7591 for (i
= 0; i
< num_debug_info_entries
; i
++)
7593 debug_info
*debug_info_p
= &debug_information
[i
];
7596 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7598 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7599 range_entry_fill
->debug_info_p
= debug_info_p
;
7604 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7605 range_entry_compar
);
7607 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7608 warn (_("Range lists in %s section start at 0x%lx\n"),
7609 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7611 introduce (section
, FALSE
);
7613 printf (_(" Offset Begin End\n"));
7615 for (i
= 0; i
< num_range_list
; i
++)
7617 struct range_entry
*range_entry
= &range_entries
[i
];
7618 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7619 unsigned int pointer_size
;
7621 unsigned char *next
;
7622 dwarf_vma base_address
;
7624 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7625 offset
= range_entry
->ranges_offset
;
7626 next
= section_begin
+ offset
;
7627 base_address
= debug_info_p
->base_address
;
7629 /* PR 17512: file: 001-101485-0.001:0.1. */
7630 if (pointer_size
< 2 || pointer_size
> 8)
7632 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7633 pointer_size
, (unsigned long) offset
);
7637 if (next
< section_begin
|| next
>= finish
)
7639 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7640 (unsigned long) offset
, i
);
7644 /* If multiple DWARF entities reference the same range then we will
7645 have multiple entries in the `range_entries' list for the same
7646 offset. Thanks to the sort above these will all be consecutive in
7647 the `range_entries' list, so we can easily ignore duplicates
7649 if (i
> 0 && last_offset
== offset
)
7651 last_offset
= offset
;
7653 if (dwarf_check
!= 0 && i
> 0)
7656 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7657 (unsigned long) (start
- section_begin
),
7658 (unsigned long) (next
- section_begin
), section
->name
);
7659 else if (start
> next
)
7661 if (next
== last_start
)
7663 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7664 (unsigned long) (start
- section_begin
),
7665 (unsigned long) (next
- section_begin
), section
->name
);
7672 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7673 (start
, finish
, pointer_size
, offset
, base_address
);
7677 free (range_entries
);
7682 typedef struct Frame_Chunk
7684 struct Frame_Chunk
*next
;
7685 unsigned char *chunk_start
;
7687 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7688 short int *col_type
;
7691 unsigned int code_factor
;
7695 unsigned int cfa_reg
;
7696 dwarf_vma cfa_offset
;
7698 unsigned char fde_encoding
;
7699 unsigned char cfa_exp
;
7700 unsigned char ptr_size
;
7701 unsigned char segment_size
;
7705 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7706 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7707 static const char *const *dwarf_regnames
;
7708 static unsigned int dwarf_regnames_count
;
7711 /* A marker for a col_type that means this column was never referenced
7712 in the frame info. */
7713 #define DW_CFA_unreferenced (-1)
7715 /* Return 0 if no more space is needed, 1 if more space is needed,
7716 -1 for invalid reg. */
7719 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7721 unsigned int prev
= fc
->ncols
;
7723 if (reg
< (unsigned int) fc
->ncols
)
7726 if (dwarf_regnames_count
> 0
7727 && reg
> dwarf_regnames_count
)
7730 fc
->ncols
= reg
+ 1;
7731 /* PR 17512: file: 10450-2643-0.004.
7732 If reg == -1 then this can happen... */
7736 /* PR 17512: file: 2844a11d. */
7737 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7739 error (_("Unfeasibly large register number: %u\n"), reg
);
7741 /* FIXME: 1024 is an arbitrary limit. Increase it if
7742 we ever encounter a valid binary that exceeds it. */
7746 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7747 sizeof (short int));
7748 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7749 /* PR 17512: file:002-10025-0.005. */
7750 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7752 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7758 while (prev
< fc
->ncols
)
7760 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7761 fc
->col_offset
[prev
] = 0;
7767 static const char *const dwarf_regnames_i386
[] =
7769 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7770 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7771 "eip", "eflags", NULL
, /* 8 - 10 */
7772 "st0", "st1", "st2", "st3", /* 11 - 14 */
7773 "st4", "st5", "st6", "st7", /* 15 - 18 */
7774 NULL
, NULL
, /* 19 - 20 */
7775 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7776 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7777 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7778 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7779 "fcw", "fsw", "mxcsr", /* 37 - 39 */
7780 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7781 "tr", "ldtr", /* 48 - 49 */
7782 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7783 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7784 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7785 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7786 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7787 NULL
, NULL
, NULL
, /* 90 - 92 */
7788 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
7791 static const char *const dwarf_regnames_iamcu
[] =
7793 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7794 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7795 "eip", "eflags", NULL
, /* 8 - 10 */
7796 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
7797 NULL
, NULL
, /* 19 - 20 */
7798 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
7799 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
7800 NULL
, NULL
, NULL
, /* 37 - 39 */
7801 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7802 "tr", "ldtr", /* 48 - 49 */
7803 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7804 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7805 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7806 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7807 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7808 NULL
, NULL
, NULL
, /* 90 - 92 */
7809 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
7813 init_dwarf_regnames_i386 (void)
7815 dwarf_regnames
= dwarf_regnames_i386
;
7816 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
7817 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7821 init_dwarf_regnames_iamcu (void)
7823 dwarf_regnames
= dwarf_regnames_iamcu
;
7824 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
7825 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7828 static const char *const dwarf_regnames_x86_64
[] =
7830 "rax", "rdx", "rcx", "rbx",
7831 "rsi", "rdi", "rbp", "rsp",
7832 "r8", "r9", "r10", "r11",
7833 "r12", "r13", "r14", "r15",
7835 "xmm0", "xmm1", "xmm2", "xmm3",
7836 "xmm4", "xmm5", "xmm6", "xmm7",
7837 "xmm8", "xmm9", "xmm10", "xmm11",
7838 "xmm12", "xmm13", "xmm14", "xmm15",
7839 "st0", "st1", "st2", "st3",
7840 "st4", "st5", "st6", "st7",
7841 "mm0", "mm1", "mm2", "mm3",
7842 "mm4", "mm5", "mm6", "mm7",
7844 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
7845 "fs.base", "gs.base", NULL
, NULL
,
7847 "mxcsr", "fcw", "fsw",
7848 "xmm16", "xmm17", "xmm18", "xmm19",
7849 "xmm20", "xmm21", "xmm22", "xmm23",
7850 "xmm24", "xmm25", "xmm26", "xmm27",
7851 "xmm28", "xmm29", "xmm30", "xmm31",
7852 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
7853 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
7854 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
7855 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
7856 NULL
, NULL
, NULL
, /* 115 - 117 */
7857 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7861 init_dwarf_regnames_x86_64 (void)
7863 dwarf_regnames
= dwarf_regnames_x86_64
;
7864 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
7865 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7868 static const char *const dwarf_regnames_aarch64
[] =
7870 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7871 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7872 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7873 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7874 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7875 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
7876 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
7877 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
7878 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7879 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7880 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7881 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7882 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
7883 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
7884 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
7885 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
7889 init_dwarf_regnames_aarch64 (void)
7891 dwarf_regnames
= dwarf_regnames_aarch64
;
7892 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
7893 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7896 static const char *const dwarf_regnames_s390
[] =
7898 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7899 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7900 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7901 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7902 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7903 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7904 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7905 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7906 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7909 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7910 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7914 init_dwarf_regnames_s390 (void)
7916 dwarf_regnames
= dwarf_regnames_s390
;
7917 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
7918 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7921 static const char *const dwarf_regnames_riscv
[] =
7923 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
7924 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
7925 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
7926 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
7927 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
7928 "fs0", "fs1", /* 40 - 41 */
7929 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
7930 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
7931 "fs10", "fs11", /* 58 - 59 */
7932 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
7935 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
7936 the large number of CSRs. */
7939 regname_internal_riscv (unsigned int regno
)
7941 const char *name
= NULL
;
7943 /* Lookup in the table first, this covers GPR and FPR. */
7944 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
7945 name
= dwarf_regnames_riscv
[regno
];
7946 else if (regno
>= 4096 && regno
<= 8191)
7948 /* This might be a CSR, these live in a sparse number space from 4096
7949 to 8191 These numbers are defined in the RISC-V ELF ABI
7953 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
7954 case VALUE + 4096: name = #NAME; break;
7955 #include "opcode/riscv-opc.h"
7960 static char csr_name
[10];
7961 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
7972 init_dwarf_regnames_riscv (void)
7974 dwarf_regnames
= NULL
;
7975 dwarf_regnames_count
= 8192;
7976 dwarf_regnames_lookup_func
= regname_internal_riscv
;
7980 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
7982 dwarf_regnames_lookup_func
= NULL
;
7987 init_dwarf_regnames_i386 ();
7991 init_dwarf_regnames_iamcu ();
7997 init_dwarf_regnames_x86_64 ();
8001 init_dwarf_regnames_aarch64 ();
8005 init_dwarf_regnames_s390 ();
8009 init_dwarf_regnames_riscv ();
8017 /* Initialize the DWARF register name lookup state based on the
8018 architecture and specific machine type of a BFD. */
8021 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8024 dwarf_regnames_lookup_func
= NULL
;
8031 case bfd_mach_x86_64
:
8032 case bfd_mach_x86_64_intel_syntax
:
8033 case bfd_mach_x64_32
:
8034 case bfd_mach_x64_32_intel_syntax
:
8035 init_dwarf_regnames_x86_64 ();
8039 init_dwarf_regnames_i386 ();
8044 case bfd_arch_iamcu
:
8045 init_dwarf_regnames_iamcu ();
8048 case bfd_arch_aarch64
:
8049 init_dwarf_regnames_aarch64();
8053 init_dwarf_regnames_s390 ();
8056 case bfd_arch_riscv
:
8057 init_dwarf_regnames_riscv ();
8066 regname_internal_by_table_only (unsigned int regno
)
8068 if (dwarf_regnames
!= NULL
8069 && regno
< dwarf_regnames_count
8070 && dwarf_regnames
[regno
] != NULL
)
8071 return dwarf_regnames
[regno
];
8077 regname (unsigned int regno
, int name_only_p
)
8079 static char reg
[64];
8081 const char *name
= NULL
;
8083 if (dwarf_regnames_lookup_func
!= NULL
)
8084 name
= dwarf_regnames_lookup_func (regno
);
8090 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8093 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8098 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8103 if (*max_regs
!= fc
->ncols
)
8104 *max_regs
= fc
->ncols
;
8106 if (*need_col_headers
)
8108 static const char *sloc
= " LOC";
8110 *need_col_headers
= 0;
8112 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
8114 for (r
= 0; r
< *max_regs
; r
++)
8115 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8120 printf ("%-5s ", regname (r
, 1));
8126 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8128 strcpy (tmp
, "exp");
8130 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8131 printf ("%-8s ", tmp
);
8133 for (r
= 0; r
< fc
->ncols
; r
++)
8135 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8137 switch (fc
->col_type
[r
])
8139 case DW_CFA_undefined
:
8142 case DW_CFA_same_value
:
8146 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8148 case DW_CFA_val_offset
:
8149 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8151 case DW_CFA_register
:
8152 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8154 case DW_CFA_expression
:
8155 strcpy (tmp
, "exp");
8157 case DW_CFA_val_expression
:
8158 strcpy (tmp
, "vexp");
8161 strcpy (tmp
, "n/a");
8164 printf ("%-5s ", tmp
);
8170 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8172 static unsigned char *
8173 read_cie (unsigned char *start
, unsigned char *end
,
8174 Frame_Chunk
**p_cie
, int *p_version
,
8175 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8179 unsigned char *augmentation_data
= NULL
;
8180 bfd_size_type augmentation_data_len
= 0;
8183 /* PR 17512: file: 001-228113-0.004. */
8187 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8188 memset (fc
, 0, sizeof (Frame_Chunk
));
8190 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8191 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8195 fc
->augmentation
= (char *) start
;
8196 /* PR 17512: file: 001-228113-0.004.
8197 Skip past augmentation name, but avoid running off the end of the data. */
8199 if (* start
++ == '\0')
8203 warn (_("No terminator for augmentation name\n"));
8207 if (strcmp (fc
->augmentation
, "eh") == 0)
8208 start
+= eh_addr_size
;
8212 GET (fc
->ptr_size
, 1);
8213 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8215 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8219 GET (fc
->segment_size
, 1);
8220 /* PR 17512: file: e99d2804. */
8221 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8223 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8227 eh_addr_size
= fc
->ptr_size
;
8231 fc
->ptr_size
= eh_addr_size
;
8232 fc
->segment_size
= 0;
8235 READ_ULEB (fc
->code_factor
, start
, end
);
8236 READ_SLEB (fc
->data_factor
, start
, end
);
8244 READ_ULEB (fc
->ra
, start
, end
);
8247 if (fc
->augmentation
[0] == 'z')
8249 READ_ULEB (augmentation_data_len
, start
, end
);
8250 augmentation_data
= start
;
8251 /* PR 17512: file: 11042-2589-0.004. */
8252 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8254 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8255 dwarf_vmatoa ("x", augmentation_data_len
),
8256 (unsigned long) (end
- start
));
8259 start
+= augmentation_data_len
;
8262 if (augmentation_data_len
)
8266 unsigned char *qend
;
8268 p
= (unsigned char *) fc
->augmentation
+ 1;
8269 q
= augmentation_data
;
8270 qend
= q
+ augmentation_data_len
;
8272 while (p
< end
&& q
< qend
)
8277 q
+= 1 + size_of_encoded_value (*q
);
8279 fc
->fde_encoding
= *q
++;
8288 /* Note - it is OK if this loop terminates with q < qend.
8289 Padding may have been inserted to align the end of the CIE. */
8294 *p_version
= version
;
8297 *p_aug_len
= augmentation_data_len
;
8298 *p_aug
= augmentation_data
;
8303 free (fc
->col_offset
);
8304 free (fc
->col_type
);
8309 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8310 If do_wide is not enabled, then formats the output to fit into 80 columns.
8311 PRINTED contains the number of characters already written to the current
8315 display_data (bfd_size_type printed
,
8316 const unsigned char * data
,
8317 const bfd_size_type len
)
8319 if (do_wide
|| len
< ((80 - printed
) / 3))
8320 for (printed
= 0; printed
< len
; ++printed
)
8321 printf (" %02x", data
[printed
]);
8324 for (printed
= 0; printed
< len
; ++printed
)
8326 if (printed
% (80 / 3) == 0)
8328 printf (" %02x", data
[printed
]);
8333 /* Prints out the contents on the augmentation data array.
8334 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8337 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8341 i
= printf (_(" Augmentation data: "));
8342 display_data (i
, data
, len
);
8346 display_debug_frames (struct dwarf_section
*section
,
8347 void *file ATTRIBUTE_UNUSED
)
8349 unsigned char *start
= section
->start
;
8350 unsigned char *end
= start
+ section
->size
;
8351 unsigned char *section_start
= start
;
8352 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8353 Frame_Chunk
*remembered_state
= NULL
;
8355 bfd_boolean is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8356 unsigned int max_regs
= 0;
8357 const char *bad_reg
= _("bad register: ");
8358 unsigned int saved_eh_addr_size
= eh_addr_size
;
8360 introduce (section
, FALSE
);
8364 unsigned char *saved_start
;
8365 unsigned char *block_end
;
8370 int need_col_headers
= 1;
8371 unsigned char *augmentation_data
= NULL
;
8372 bfd_size_type augmentation_data_len
= 0;
8373 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8374 unsigned int offset_size
;
8375 unsigned int initial_length_size
;
8376 bfd_boolean all_nops
;
8377 static Frame_Chunk fde_fc
;
8379 saved_start
= start
;
8381 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8385 printf ("\n%08lx ZERO terminator\n\n",
8386 (unsigned long)(saved_start
- section_start
));
8387 /* Skip any zero terminators that directly follow.
8388 A corrupt section size could have loaded a whole
8389 slew of zero filled memory bytes. eg
8390 PR 17512: file: 070-19381-0.004. */
8391 while (start
< end
&& * start
== 0)
8396 if (length
== 0xffffffff)
8398 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8400 initial_length_size
= 12;
8405 initial_length_size
= 4;
8408 block_end
= saved_start
+ length
+ initial_length_size
;
8409 if (block_end
> end
|| block_end
< start
)
8411 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8412 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8413 (unsigned long) (saved_start
- section_start
));
8417 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8419 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8420 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8425 start
= read_cie (start
, end
, &cie
, &version
,
8426 &augmentation_data_len
, &augmentation_data
);
8427 /* PR 17512: file: 027-135133-0.005. */
8434 fc
->chunk_start
= saved_start
;
8435 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8438 if (frame_need_space (fc
, mreg
) < 0)
8440 if (fc
->fde_encoding
)
8441 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8443 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8444 print_dwarf_vma (length
, fc
->ptr_size
);
8445 print_dwarf_vma (cie_id
, offset_size
);
8447 if (do_debug_frames_interp
)
8449 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8450 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8455 printf (" Version: %d\n", version
);
8456 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8459 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8460 printf (" Segment Size: %u\n", fc
->segment_size
);
8462 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8463 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8464 printf (" Return address column: %d\n", fc
->ra
);
8466 if (augmentation_data_len
)
8467 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8474 unsigned char *look_for
;
8475 unsigned long segment_selector
;
8479 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8480 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8483 look_for
= section_start
+ cie_id
;
8485 if (look_for
<= saved_start
)
8487 for (cie
= chunks
; cie
; cie
= cie
->next
)
8488 if (cie
->chunk_start
== look_for
)
8493 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8494 if (cie
->chunk_start
== look_for
)
8498 unsigned int off_size
;
8499 unsigned char *cie_scan
;
8501 cie_scan
= look_for
;
8503 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8504 if (length
== 0xffffffff)
8506 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8513 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8516 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8517 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8522 read_cie (cie_scan
, end
, &cie
, &version
,
8523 &augmentation_data_len
, &augmentation_data
);
8524 /* PR 17512: file: 3450-2098-0.004. */
8527 warn (_("Failed to read CIE information\n"));
8530 cie
->next
= forward_refs
;
8532 cie
->chunk_start
= look_for
;
8533 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8536 if (frame_need_space (cie
, mreg
) < 0)
8538 warn (_("Invalid max register\n"));
8541 if (cie
->fde_encoding
)
8543 = size_of_encoded_value (cie
->fde_encoding
);
8550 memset (fc
, 0, sizeof (Frame_Chunk
));
8554 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8555 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8556 (unsigned long) (saved_start
- section_start
));
8558 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8559 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8560 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8562 warn (_("Invalid max register\n"));
8566 fc
->augmentation
= "";
8567 fc
->fde_encoding
= 0;
8568 fc
->ptr_size
= eh_addr_size
;
8569 fc
->segment_size
= 0;
8573 fc
->ncols
= cie
->ncols
;
8574 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8575 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8576 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8577 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8578 fc
->augmentation
= cie
->augmentation
;
8579 fc
->ptr_size
= cie
->ptr_size
;
8580 eh_addr_size
= cie
->ptr_size
;
8581 fc
->segment_size
= cie
->segment_size
;
8582 fc
->code_factor
= cie
->code_factor
;
8583 fc
->data_factor
= cie
->data_factor
;
8584 fc
->cfa_reg
= cie
->cfa_reg
;
8585 fc
->cfa_offset
= cie
->cfa_offset
;
8587 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8589 warn (_("Invalid max register\n"));
8592 fc
->fde_encoding
= cie
->fde_encoding
;
8595 if (fc
->fde_encoding
)
8596 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8598 segment_selector
= 0;
8599 if (fc
->segment_size
)
8601 if (fc
->segment_size
> sizeof (segment_selector
))
8603 /* PR 17512: file: 9e196b3e. */
8604 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8605 fc
->segment_size
= 4;
8607 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8610 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8612 /* FIXME: It appears that sometimes the final pc_range value is
8613 encoded in less than encoded_ptr_size bytes. See the x86_64
8614 run of the "objcopy on compressed debug sections" test for an
8616 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8618 if (cie
->augmentation
[0] == 'z')
8620 READ_ULEB (augmentation_data_len
, start
, end
);
8621 augmentation_data
= start
;
8622 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8623 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8625 warn (_("Augmentation data too long: 0x%s, "
8626 "expected at most %#lx\n"),
8627 dwarf_vmatoa ("x", augmentation_data_len
),
8628 (unsigned long) (end
- start
));
8630 augmentation_data
= NULL
;
8631 augmentation_data_len
= 0;
8633 start
+= augmentation_data_len
;
8636 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8637 (unsigned long)(saved_start
- section_start
),
8638 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8639 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8640 (unsigned long)(cie
->chunk_start
- section_start
));
8642 if (fc
->segment_size
)
8643 printf ("%04lx:", segment_selector
);
8646 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8647 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8649 if (! do_debug_frames_interp
&& augmentation_data_len
)
8651 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8656 /* At this point, fc is the current chunk, cie (if any) is set, and
8657 we're about to interpret instructions for the chunk. */
8658 /* ??? At present we need to do this always, since this sizes the
8659 fc->col_type and fc->col_offset arrays, which we write into always.
8660 We should probably split the interpreted and non-interpreted bits
8661 into two different routines, since there's so much that doesn't
8662 really overlap between them. */
8663 if (1 || do_debug_frames_interp
)
8665 /* Start by making a pass over the chunk, allocating storage
8666 and taking note of what registers are used. */
8667 unsigned char *tmp
= start
;
8669 while (start
< block_end
)
8671 unsigned int reg
, op
, opa
;
8673 unsigned char * new_start
;
8680 /* Warning: if you add any more cases to this switch, be
8681 sure to add them to the corresponding switch below. */
8684 case DW_CFA_advance_loc
:
8687 SKIP_ULEB (start
, end
);
8688 if (frame_need_space (fc
, opa
) >= 0)
8689 fc
->col_type
[opa
] = DW_CFA_undefined
;
8691 case DW_CFA_restore
:
8692 if (frame_need_space (fc
, opa
) >= 0)
8693 fc
->col_type
[opa
] = DW_CFA_undefined
;
8695 case DW_CFA_set_loc
:
8696 start
+= encoded_ptr_size
;
8698 case DW_CFA_advance_loc1
:
8701 case DW_CFA_advance_loc2
:
8704 case DW_CFA_advance_loc4
:
8707 case DW_CFA_offset_extended
:
8708 case DW_CFA_val_offset
:
8709 READ_ULEB (reg
, start
, end
);
8710 SKIP_ULEB (start
, end
);
8711 if (frame_need_space (fc
, reg
) >= 0)
8712 fc
->col_type
[reg
] = DW_CFA_undefined
;
8714 case DW_CFA_restore_extended
:
8715 READ_ULEB (reg
, start
, end
);
8716 if (frame_need_space (fc
, reg
) >= 0)
8717 fc
->col_type
[reg
] = DW_CFA_undefined
;
8719 case DW_CFA_undefined
:
8720 READ_ULEB (reg
, start
, end
);
8721 if (frame_need_space (fc
, reg
) >= 0)
8722 fc
->col_type
[reg
] = DW_CFA_undefined
;
8724 case DW_CFA_same_value
:
8725 READ_ULEB (reg
, start
, end
);
8726 if (frame_need_space (fc
, reg
) >= 0)
8727 fc
->col_type
[reg
] = DW_CFA_undefined
;
8729 case DW_CFA_register
:
8730 READ_ULEB (reg
, start
, end
);
8731 SKIP_ULEB (start
, end
);
8732 if (frame_need_space (fc
, reg
) >= 0)
8733 fc
->col_type
[reg
] = DW_CFA_undefined
;
8735 case DW_CFA_def_cfa
:
8736 SKIP_ULEB (start
, end
);
8737 SKIP_ULEB (start
, end
);
8739 case DW_CFA_def_cfa_register
:
8740 SKIP_ULEB (start
, end
);
8742 case DW_CFA_def_cfa_offset
:
8743 SKIP_ULEB (start
, end
);
8745 case DW_CFA_def_cfa_expression
:
8746 READ_ULEB (temp
, start
, end
);
8747 new_start
= start
+ temp
;
8748 if (new_start
< start
)
8750 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8756 case DW_CFA_expression
:
8757 case DW_CFA_val_expression
:
8758 READ_ULEB (reg
, start
, end
);
8759 READ_ULEB (temp
, start
, end
);
8760 new_start
= start
+ temp
;
8761 if (new_start
< start
)
8763 /* PR 17512: file:306-192417-0.005. */
8764 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8769 if (frame_need_space (fc
, reg
) >= 0)
8770 fc
->col_type
[reg
] = DW_CFA_undefined
;
8772 case DW_CFA_offset_extended_sf
:
8773 case DW_CFA_val_offset_sf
:
8774 READ_ULEB (reg
, start
, end
);
8775 SKIP_SLEB (start
, end
);
8776 if (frame_need_space (fc
, reg
) >= 0)
8777 fc
->col_type
[reg
] = DW_CFA_undefined
;
8779 case DW_CFA_def_cfa_sf
:
8780 SKIP_ULEB (start
, end
);
8781 SKIP_SLEB (start
, end
);
8783 case DW_CFA_def_cfa_offset_sf
:
8784 SKIP_SLEB (start
, end
);
8786 case DW_CFA_MIPS_advance_loc8
:
8789 case DW_CFA_GNU_args_size
:
8790 SKIP_ULEB (start
, end
);
8792 case DW_CFA_GNU_negative_offset_extended
:
8793 READ_ULEB (reg
, start
, end
);
8794 SKIP_ULEB (start
, end
);
8795 if (frame_need_space (fc
, reg
) >= 0)
8796 fc
->col_type
[reg
] = DW_CFA_undefined
;
8807 /* Now we know what registers are used, make a second pass over
8808 the chunk, this time actually printing out the info. */
8810 while (start
< block_end
)
8812 unsigned char * tmp
;
8814 unsigned long ul
, roffs
;
8815 /* Note: It is tempting to use an unsigned long for 'reg' but there
8816 are various functions, notably frame_space_needed() that assume that
8817 reg is an unsigned int. */
8822 const char *reg_prefix
= "";
8829 /* Make a note if something other than DW_CFA_nop happens. */
8830 if (op
!= DW_CFA_nop
)
8833 /* Warning: if you add any more cases to this switch, be
8834 sure to add them to the corresponding switch above. */
8837 case DW_CFA_advance_loc
:
8838 if (do_debug_frames_interp
)
8839 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8841 printf (" DW_CFA_advance_loc: %d to %s\n",
8842 opa
* fc
->code_factor
,
8843 dwarf_vmatoa_1 (NULL
,
8844 fc
->pc_begin
+ opa
* fc
->code_factor
,
8846 fc
->pc_begin
+= opa
* fc
->code_factor
;
8850 READ_ULEB (roffs
, start
, end
);
8851 if (opa
>= (unsigned int) fc
->ncols
)
8852 reg_prefix
= bad_reg
;
8853 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8854 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
8855 reg_prefix
, regname (opa
, 0),
8856 roffs
* fc
->data_factor
);
8857 if (*reg_prefix
== '\0')
8859 fc
->col_type
[opa
] = DW_CFA_offset
;
8860 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8864 case DW_CFA_restore
:
8865 if (opa
>= (unsigned int) fc
->ncols
)
8866 reg_prefix
= bad_reg
;
8867 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8868 printf (" DW_CFA_restore: %s%s\n",
8869 reg_prefix
, regname (opa
, 0));
8870 if (*reg_prefix
!= '\0')
8873 if (opa
>= (unsigned int) cie
->ncols
8874 || (do_debug_frames_interp
8875 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
8877 fc
->col_type
[opa
] = DW_CFA_undefined
;
8878 fc
->col_offset
[opa
] = 0;
8882 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8883 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8887 case DW_CFA_set_loc
:
8888 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
8889 if (do_debug_frames_interp
)
8890 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8892 printf (" DW_CFA_set_loc: %s\n",
8893 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
8897 case DW_CFA_advance_loc1
:
8898 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
8899 if (do_debug_frames_interp
)
8900 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8902 printf (" DW_CFA_advance_loc1: %ld to %s\n",
8903 (unsigned long) (ofs
* fc
->code_factor
),
8904 dwarf_vmatoa_1 (NULL
,
8905 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8907 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8910 case DW_CFA_advance_loc2
:
8911 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
8912 if (do_debug_frames_interp
)
8913 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8915 printf (" DW_CFA_advance_loc2: %ld to %s\n",
8916 (unsigned long) (ofs
* fc
->code_factor
),
8917 dwarf_vmatoa_1 (NULL
,
8918 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8920 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8923 case DW_CFA_advance_loc4
:
8924 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
8925 if (do_debug_frames_interp
)
8926 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8928 printf (" DW_CFA_advance_loc4: %ld to %s\n",
8929 (unsigned long) (ofs
* fc
->code_factor
),
8930 dwarf_vmatoa_1 (NULL
,
8931 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8933 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8936 case DW_CFA_offset_extended
:
8937 READ_ULEB (reg
, start
, end
);
8938 READ_ULEB (roffs
, start
, end
);
8939 if (reg
>= (unsigned int) fc
->ncols
)
8940 reg_prefix
= bad_reg
;
8941 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8942 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
8943 reg_prefix
, regname (reg
, 0),
8944 roffs
* fc
->data_factor
);
8945 if (*reg_prefix
== '\0')
8947 fc
->col_type
[reg
] = DW_CFA_offset
;
8948 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8952 case DW_CFA_val_offset
:
8953 READ_ULEB (reg
, start
, end
);
8954 READ_ULEB (roffs
, start
, end
);
8955 if (reg
>= (unsigned int) fc
->ncols
)
8956 reg_prefix
= bad_reg
;
8957 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8958 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
8959 reg_prefix
, regname (reg
, 0),
8960 roffs
* fc
->data_factor
);
8961 if (*reg_prefix
== '\0')
8963 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8964 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8968 case DW_CFA_restore_extended
:
8969 READ_ULEB (reg
, start
, end
);
8970 if (reg
>= (unsigned int) fc
->ncols
)
8971 reg_prefix
= bad_reg
;
8972 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8973 printf (" DW_CFA_restore_extended: %s%s\n",
8974 reg_prefix
, regname (reg
, 0));
8975 if (*reg_prefix
!= '\0')
8978 if (reg
>= (unsigned int) cie
->ncols
)
8980 fc
->col_type
[reg
] = DW_CFA_undefined
;
8981 fc
->col_offset
[reg
] = 0;
8985 fc
->col_type
[reg
] = cie
->col_type
[reg
];
8986 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
8990 case DW_CFA_undefined
:
8991 READ_ULEB (reg
, start
, end
);
8992 if (reg
>= (unsigned int) fc
->ncols
)
8993 reg_prefix
= bad_reg
;
8994 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8995 printf (" DW_CFA_undefined: %s%s\n",
8996 reg_prefix
, regname (reg
, 0));
8997 if (*reg_prefix
== '\0')
8999 fc
->col_type
[reg
] = DW_CFA_undefined
;
9000 fc
->col_offset
[reg
] = 0;
9004 case DW_CFA_same_value
:
9005 READ_ULEB (reg
, start
, end
);
9006 if (reg
>= (unsigned int) fc
->ncols
)
9007 reg_prefix
= bad_reg
;
9008 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9009 printf (" DW_CFA_same_value: %s%s\n",
9010 reg_prefix
, regname (reg
, 0));
9011 if (*reg_prefix
== '\0')
9013 fc
->col_type
[reg
] = DW_CFA_same_value
;
9014 fc
->col_offset
[reg
] = 0;
9018 case DW_CFA_register
:
9019 READ_ULEB (reg
, start
, end
);
9020 READ_ULEB (roffs
, start
, end
);
9021 if (reg
>= (unsigned int) fc
->ncols
)
9022 reg_prefix
= bad_reg
;
9023 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9025 printf (" DW_CFA_register: %s%s in ",
9026 reg_prefix
, regname (reg
, 0));
9027 puts (regname (roffs
, 0));
9029 if (*reg_prefix
== '\0')
9031 fc
->col_type
[reg
] = DW_CFA_register
;
9032 fc
->col_offset
[reg
] = roffs
;
9036 case DW_CFA_remember_state
:
9037 if (! do_debug_frames_interp
)
9038 printf (" DW_CFA_remember_state\n");
9039 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9040 rs
->cfa_offset
= fc
->cfa_offset
;
9041 rs
->cfa_reg
= fc
->cfa_reg
;
9043 rs
->cfa_exp
= fc
->cfa_exp
;
9044 rs
->ncols
= fc
->ncols
;
9045 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9046 sizeof (* rs
->col_type
));
9047 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9048 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9049 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9050 rs
->next
= remembered_state
;
9051 remembered_state
= rs
;
9054 case DW_CFA_restore_state
:
9055 if (! do_debug_frames_interp
)
9056 printf (" DW_CFA_restore_state\n");
9057 rs
= remembered_state
;
9060 remembered_state
= rs
->next
;
9061 fc
->cfa_offset
= rs
->cfa_offset
;
9062 fc
->cfa_reg
= rs
->cfa_reg
;
9064 fc
->cfa_exp
= rs
->cfa_exp
;
9065 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9067 warn (_("Invalid column number in saved frame state\n"));
9071 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9072 memcpy (fc
->col_offset
, rs
->col_offset
,
9073 rs
->ncols
* sizeof (* rs
->col_offset
));
9074 free (rs
->col_type
);
9075 free (rs
->col_offset
);
9078 else if (do_debug_frames_interp
)
9079 printf ("Mismatched DW_CFA_restore_state\n");
9082 case DW_CFA_def_cfa
:
9083 READ_ULEB (fc
->cfa_reg
, start
, end
);
9084 READ_ULEB (fc
->cfa_offset
, start
, end
);
9086 if (! do_debug_frames_interp
)
9087 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9088 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9091 case DW_CFA_def_cfa_register
:
9092 READ_ULEB (fc
->cfa_reg
, start
, end
);
9094 if (! do_debug_frames_interp
)
9095 printf (" DW_CFA_def_cfa_register: %s\n",
9096 regname (fc
->cfa_reg
, 0));
9099 case DW_CFA_def_cfa_offset
:
9100 READ_ULEB (fc
->cfa_offset
, start
, end
);
9101 if (! do_debug_frames_interp
)
9102 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9106 if (! do_debug_frames_interp
)
9107 printf (" DW_CFA_nop\n");
9110 case DW_CFA_def_cfa_expression
:
9111 READ_ULEB (ul
, start
, end
);
9112 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
9114 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9117 if (! do_debug_frames_interp
)
9119 printf (" DW_CFA_def_cfa_expression (");
9120 decode_location_expression (start
, eh_addr_size
, 0, -1,
9128 case DW_CFA_expression
:
9129 READ_ULEB (reg
, start
, end
);
9130 READ_ULEB (ul
, start
, end
);
9131 if (reg
>= (unsigned int) fc
->ncols
)
9132 reg_prefix
= bad_reg
;
9133 /* PR 17512: file: 069-133014-0.006. */
9134 /* PR 17512: file: 98c02eb4. */
9136 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9138 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9141 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9143 printf (" DW_CFA_expression: %s%s (",
9144 reg_prefix
, regname (reg
, 0));
9145 decode_location_expression (start
, eh_addr_size
, 0, -1,
9149 if (*reg_prefix
== '\0')
9150 fc
->col_type
[reg
] = DW_CFA_expression
;
9154 case DW_CFA_val_expression
:
9155 READ_ULEB (reg
, start
, end
);
9156 READ_ULEB (ul
, start
, end
);
9157 if (reg
>= (unsigned int) fc
->ncols
)
9158 reg_prefix
= bad_reg
;
9160 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9162 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9165 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9167 printf (" DW_CFA_val_expression: %s%s (",
9168 reg_prefix
, regname (reg
, 0));
9169 decode_location_expression (start
, eh_addr_size
, 0, -1,
9173 if (*reg_prefix
== '\0')
9174 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9178 case DW_CFA_offset_extended_sf
:
9179 READ_ULEB (reg
, start
, end
);
9180 READ_SLEB (l
, start
, end
);
9181 if (frame_need_space (fc
, reg
) < 0)
9182 reg_prefix
= bad_reg
;
9183 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9184 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9185 reg_prefix
, regname (reg
, 0),
9186 (long)(l
* fc
->data_factor
));
9187 if (*reg_prefix
== '\0')
9189 fc
->col_type
[reg
] = DW_CFA_offset
;
9190 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9194 case DW_CFA_val_offset_sf
:
9195 READ_ULEB (reg
, start
, end
);
9196 READ_SLEB (l
, start
, end
);
9197 if (frame_need_space (fc
, reg
) < 0)
9198 reg_prefix
= bad_reg
;
9199 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9200 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9201 reg_prefix
, regname (reg
, 0),
9202 (long)(l
* fc
->data_factor
));
9203 if (*reg_prefix
== '\0')
9205 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9206 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9210 case DW_CFA_def_cfa_sf
:
9211 READ_ULEB (fc
->cfa_reg
, start
, end
);
9212 READ_ULEB (fc
->cfa_offset
, start
, end
);
9213 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9215 if (! do_debug_frames_interp
)
9216 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9217 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9220 case DW_CFA_def_cfa_offset_sf
:
9221 READ_ULEB (fc
->cfa_offset
, start
, end
);
9222 fc
->cfa_offset
*= fc
->data_factor
;
9223 if (! do_debug_frames_interp
)
9224 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9227 case DW_CFA_MIPS_advance_loc8
:
9228 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9229 if (do_debug_frames_interp
)
9230 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9232 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9233 (unsigned long) (ofs
* fc
->code_factor
),
9234 dwarf_vmatoa_1 (NULL
,
9235 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9237 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9240 case DW_CFA_GNU_window_save
:
9241 if (! do_debug_frames_interp
)
9242 printf (" DW_CFA_GNU_window_save\n");
9245 case DW_CFA_GNU_args_size
:
9246 READ_ULEB (ul
, start
, end
);
9247 if (! do_debug_frames_interp
)
9248 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9251 case DW_CFA_GNU_negative_offset_extended
:
9252 READ_ULEB (reg
, start
, end
);
9253 READ_SLEB (l
, start
, end
);
9255 if (frame_need_space (fc
, reg
) < 0)
9256 reg_prefix
= bad_reg
;
9257 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9258 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9259 reg_prefix
, regname (reg
, 0),
9260 (long)(l
* fc
->data_factor
));
9261 if (*reg_prefix
== '\0')
9263 fc
->col_type
[reg
] = DW_CFA_offset
;
9264 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9269 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9270 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9272 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9277 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9278 if (do_debug_frames_interp
&& ! all_nops
)
9279 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9281 if (fde_fc
.col_type
!= NULL
)
9283 free (fde_fc
.col_type
);
9284 fde_fc
.col_type
= NULL
;
9286 if (fde_fc
.col_offset
!= NULL
)
9288 free (fde_fc
.col_offset
);
9289 fde_fc
.col_offset
= NULL
;
9293 eh_addr_size
= saved_eh_addr_size
;
9298 while (remembered_state
!= NULL
)
9300 rs
= remembered_state
;
9301 remembered_state
= rs
->next
;
9302 free (rs
->col_type
);
9303 free (rs
->col_offset
);
9304 rs
->next
= NULL
; /* Paranoia. */
9308 while (chunks
!= NULL
)
9312 free (rs
->col_type
);
9313 free (rs
->col_offset
);
9314 rs
->next
= NULL
; /* Paranoia. */
9318 while (forward_refs
!= NULL
)
9321 forward_refs
= rs
->next
;
9322 free (rs
->col_type
);
9323 free (rs
->col_offset
);
9324 rs
->next
= NULL
; /* Paranoia. */
9334 display_debug_names (struct dwarf_section
*section
, void *file
)
9336 unsigned char *hdrptr
= section
->start
;
9337 dwarf_vma unit_length
;
9338 unsigned char *unit_start
;
9339 const unsigned char *const section_end
= section
->start
+ section
->size
;
9340 unsigned char *unit_end
;
9342 introduce (section
, FALSE
);
9344 load_debug_section_with_follow (str
, file
);
9346 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9348 unsigned int offset_size
;
9349 uint16_t dwarf_version
, padding
;
9350 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9351 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9352 uint32_t augmentation_string_size
;
9354 unsigned long sec_off
;
9355 bfd_boolean augmentation_printable
;
9356 const char *augmentation_string
;
9358 unit_start
= hdrptr
;
9360 /* Get and check the length of the block. */
9361 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9363 if (unit_length
== 0xffffffff)
9365 /* This section is 64-bit DWARF. */
9366 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9371 unit_end
= hdrptr
+ unit_length
;
9373 sec_off
= hdrptr
- section
->start
;
9374 if (sec_off
+ unit_length
< sec_off
9375 || sec_off
+ unit_length
> section
->size
)
9377 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9379 (unsigned long) (unit_start
- section
->start
),
9380 dwarf_vmatoa ("x", unit_length
));
9384 /* Get and check the version number. */
9385 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9386 printf (_("Version %ld\n"), (long) dwarf_version
);
9388 /* Prior versions did not exist, and future versions may not be
9389 backwards compatible. */
9390 if (dwarf_version
!= 5)
9392 warn (_("Only DWARF version 5 .debug_names "
9393 "is currently supported.\n"));
9397 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9399 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9402 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9403 if (comp_unit_count
== 0)
9404 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9406 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9407 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9408 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9409 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9410 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9412 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9413 if (augmentation_string_size
% 4 != 0)
9415 warn (_("Augmentation string length %u must be rounded up "
9416 "to a multiple of 4 in .debug_names.\n"),
9417 augmentation_string_size
);
9418 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9421 printf (_("Augmentation string:"));
9423 augmentation_printable
= TRUE
;
9424 augmentation_string
= (const char *) hdrptr
;
9426 for (i
= 0; i
< augmentation_string_size
; i
++)
9430 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9431 printf (" %02x", uc
);
9433 if (uc
!= 0 && !ISPRINT (uc
))
9434 augmentation_printable
= FALSE
;
9437 if (augmentation_printable
)
9441 i
< augmentation_string_size
&& augmentation_string
[i
];
9443 putchar (augmentation_string
[i
]);
9448 printf (_("CU table:\n"));
9449 for (i
= 0; i
< comp_unit_count
; i
++)
9453 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9454 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9458 printf (_("TU table:\n"));
9459 for (i
= 0; i
< local_type_unit_count
; i
++)
9463 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9464 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9468 printf (_("Foreign TU table:\n"));
9469 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9473 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9474 printf (_("[%3u] "), i
);
9475 print_dwarf_vma (signature
, 8);
9480 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9481 hdrptr
+= bucket_count
* sizeof (uint32_t);
9482 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9483 hdrptr
+= name_count
* sizeof (uint32_t);
9484 unsigned char *const name_table_string_offsets
= hdrptr
;
9485 hdrptr
+= name_count
* offset_size
;
9486 unsigned char *const name_table_entry_offsets
= hdrptr
;
9487 hdrptr
+= name_count
* offset_size
;
9488 unsigned char *const abbrev_table
= hdrptr
;
9489 hdrptr
+= abbrev_table_size
;
9490 const unsigned char *const abbrev_table_end
= hdrptr
;
9491 unsigned char *const entry_pool
= hdrptr
;
9492 if (hdrptr
> unit_end
)
9494 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9495 "for unit 0x%lx in the debug_names\n"),
9496 (long) (hdrptr
- section
->start
),
9497 (long) (unit_end
- section
->start
),
9498 (long) (unit_start
- section
->start
));
9502 size_t buckets_filled
= 0;
9504 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9506 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9511 printf (ngettext ("Used %zu of %lu bucket.\n",
9512 "Used %zu of %lu buckets.\n",
9514 buckets_filled
, (unsigned long) bucket_count
);
9516 uint32_t hash_prev
= 0;
9517 size_t hash_clash_count
= 0;
9518 size_t longest_clash
= 0;
9519 size_t this_length
= 0;
9521 for (hashi
= 0; hashi
< name_count
; hashi
++)
9523 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9527 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9531 longest_clash
= MAX (longest_clash
, this_length
);
9536 hash_prev
= hash_this
;
9538 printf (_("Out of %lu items there are %zu bucket clashes"
9539 " (longest of %zu entries).\n"),
9540 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9541 assert (name_count
== buckets_filled
+ hash_clash_count
);
9543 struct abbrev_lookup_entry
9545 dwarf_vma abbrev_tag
;
9546 unsigned char *abbrev_lookup_ptr
;
9548 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9549 size_t abbrev_lookup_used
= 0;
9550 size_t abbrev_lookup_allocated
= 0;
9552 unsigned char *abbrevptr
= abbrev_table
;
9555 dwarf_vma abbrev_tag
;
9557 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9558 if (abbrev_tag
== 0)
9560 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9562 abbrev_lookup_allocated
= MAX (0x100,
9563 abbrev_lookup_allocated
* 2);
9564 abbrev_lookup
= xrealloc (abbrev_lookup
,
9565 (abbrev_lookup_allocated
9566 * sizeof (*abbrev_lookup
)));
9568 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9569 struct abbrev_lookup_entry
*entry
;
9570 for (entry
= abbrev_lookup
;
9571 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9573 if (entry
->abbrev_tag
== abbrev_tag
)
9575 warn (_("Duplicate abbreviation tag %lu "
9576 "in unit 0x%lx in the debug_names\n"),
9577 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9580 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9581 entry
->abbrev_tag
= abbrev_tag
;
9582 entry
->abbrev_lookup_ptr
= abbrevptr
;
9584 /* Skip DWARF tag. */
9585 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9588 dwarf_vma xindex
, form
;
9590 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9591 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9592 if (xindex
== 0 && form
== 0)
9597 printf (_("\nSymbol table:\n"));
9599 for (namei
= 0; namei
< name_count
; ++namei
)
9601 uint64_t string_offset
, entry_offset
;
9603 SAFE_BYTE_GET (string_offset
,
9604 name_table_string_offsets
+ namei
* offset_size
,
9605 offset_size
, unit_end
);
9606 SAFE_BYTE_GET (entry_offset
,
9607 name_table_entry_offsets
+ namei
* offset_size
,
9608 offset_size
, unit_end
);
9610 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9611 fetch_indirect_string (string_offset
));
9613 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9615 /* We need to scan first whether there is a single or multiple
9616 entries. TAGNO is -2 for the first entry, it is -1 for the
9617 initial tag read of the second entry, then it becomes 0 for the
9618 first entry for real printing etc. */
9620 /* Initialize it due to a false compiler warning. */
9621 dwarf_vma second_abbrev_tag
= -1;
9624 dwarf_vma abbrev_tag
;
9625 dwarf_vma dwarf_tag
;
9626 const struct abbrev_lookup_entry
*entry
;
9628 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9631 second_abbrev_tag
= abbrev_tag
;
9633 entryptr
= entry_pool
+ entry_offset
;
9636 if (abbrev_tag
== 0)
9640 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9641 (unsigned long) abbrev_tag
);
9643 for (entry
= abbrev_lookup
;
9644 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9646 if (entry
->abbrev_tag
== abbrev_tag
)
9648 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9650 warn (_("Undefined abbreviation tag %lu "
9651 "in unit 0x%lx in the debug_names\n"),
9653 (long) (unit_start
- section
->start
));
9656 abbrevptr
= entry
->abbrev_lookup_ptr
;
9657 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9659 printf (" %s", get_TAG_name (dwarf_tag
));
9662 dwarf_vma xindex
, form
;
9664 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9665 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9666 if (xindex
== 0 && form
== 0)
9670 printf (" %s", get_IDX_name (xindex
));
9671 entryptr
= read_and_display_attr_value (0, form
, 0,
9672 unit_start
, entryptr
, unit_end
,
9674 dwarf_version
, NULL
,
9681 printf (_(" <no entries>"));
9685 free (abbrev_lookup
);
9692 display_debug_links (struct dwarf_section
* section
,
9693 void * file ATTRIBUTE_UNUSED
)
9695 const unsigned char * filename
;
9696 unsigned int filelen
;
9698 introduce (section
, FALSE
);
9700 /* The .gnu_debuglink section is formatted as:
9701 (c-string) Filename.
9702 (padding) If needed to reach a 4 byte boundary.
9703 (uint32_t) CRC32 value.
9705 The .gun_debugaltlink section is formatted as:
9706 (c-string) Filename.
9707 (binary) Build-ID. */
9709 filename
= section
->start
;
9710 filelen
= strnlen ((const char *) filename
, section
->size
);
9711 if (filelen
== section
->size
)
9713 warn (_("The debuglink filename is corrupt/missing\n"));
9717 printf (_(" Separate debug info file: %s\n"), filename
);
9719 if (const_strneq (section
->name
, ".gnu_debuglink"))
9722 unsigned int crc_offset
;
9724 crc_offset
= filelen
+ 1;
9725 crc_offset
= (crc_offset
+ 3) & ~3;
9726 if (crc_offset
+ 4 > section
->size
)
9728 warn (_("CRC offset missing/truncated\n"));
9732 crc32
= byte_get (filename
+ crc_offset
, 4);
9734 printf (_(" CRC value: %#x\n"), crc32
);
9736 if (crc_offset
+ 4 < section
->size
)
9738 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9739 (long)(section
->size
- (crc_offset
+ 4)));
9743 else /* const_strneq (section->name, ".gnu_debugaltlink") */
9745 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9746 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9747 bfd_size_type printed
;
9749 /* FIXME: Should we support smaller build-id notes ? */
9750 if (build_id_len
< 0x14)
9752 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9756 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9757 display_data (printed
, build_id
, build_id_len
);
9766 display_gdb_index (struct dwarf_section
*section
,
9767 void *file ATTRIBUTE_UNUSED
)
9769 unsigned char *start
= section
->start
;
9771 uint32_t cu_list_offset
, tu_list_offset
;
9772 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
9773 unsigned int cu_list_elements
, tu_list_elements
;
9774 unsigned int address_table_size
, symbol_table_slots
;
9775 unsigned char *cu_list
, *tu_list
;
9776 unsigned char *address_table
, *symbol_table
, *constant_pool
;
9779 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
9781 introduce (section
, FALSE
);
9783 if (section
->size
< 6 * sizeof (uint32_t))
9785 warn (_("Truncated header in the %s section.\n"), section
->name
);
9789 version
= byte_get_little_endian (start
, 4);
9790 printf (_("Version %ld\n"), (long) version
);
9792 /* Prior versions are obsolete, and future versions may not be
9793 backwards compatible. */
9794 if (version
< 3 || version
> 8)
9796 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
9800 warn (_("The address table data in version 3 may be wrong.\n"));
9802 warn (_("Version 4 does not support case insensitive lookups.\n"));
9804 warn (_("Version 5 does not include inlined functions.\n"));
9806 warn (_("Version 6 does not include symbol attributes.\n"));
9807 /* Version 7 indices generated by Gold have bad type unit references,
9808 PR binutils/15021. But we don't know if the index was generated by
9809 Gold or not, so to avoid worrying users with gdb-generated indices
9810 we say nothing for version 7 here. */
9812 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
9813 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
9814 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
9815 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
9816 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
9818 if (cu_list_offset
> section
->size
9819 || tu_list_offset
> section
->size
9820 || address_table_offset
> section
->size
9821 || symbol_table_offset
> section
->size
9822 || constant_pool_offset
> section
->size
)
9824 warn (_("Corrupt header in the %s section.\n"), section
->name
);
9828 /* PR 17531: file: 418d0a8a. */
9829 if (tu_list_offset
< cu_list_offset
)
9831 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
9832 tu_list_offset
, cu_list_offset
);
9836 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
9838 if (address_table_offset
< tu_list_offset
)
9840 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
9841 address_table_offset
, tu_list_offset
);
9845 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
9847 /* PR 17531: file: 18a47d3d. */
9848 if (symbol_table_offset
< address_table_offset
)
9850 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
9851 symbol_table_offset
, address_table_offset
);
9855 address_table_size
= symbol_table_offset
- address_table_offset
;
9857 if (constant_pool_offset
< symbol_table_offset
)
9859 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
9860 constant_pool_offset
, symbol_table_offset
);
9864 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
9866 cu_list
= start
+ cu_list_offset
;
9867 tu_list
= start
+ tu_list_offset
;
9868 address_table
= start
+ address_table_offset
;
9869 symbol_table
= start
+ symbol_table_offset
;
9870 constant_pool
= start
+ constant_pool_offset
;
9872 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
9874 warn (_("Address table extends beyond end of section.\n"));
9878 printf (_("\nCU table:\n"));
9879 for (i
= 0; i
< cu_list_elements
; i
+= 2)
9881 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
9882 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
9884 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
9885 (unsigned long) cu_offset
,
9886 (unsigned long) (cu_offset
+ cu_length
- 1));
9889 printf (_("\nTU table:\n"));
9890 for (i
= 0; i
< tu_list_elements
; i
+= 3)
9892 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
9893 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
9894 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
9896 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
9897 (unsigned long) tu_offset
,
9898 (unsigned long) type_offset
);
9899 print_dwarf_vma (signature
, 8);
9903 printf (_("\nAddress table:\n"));
9904 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
9907 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
9908 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
9909 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
9911 print_dwarf_vma (low
, 8);
9912 print_dwarf_vma (high
, 8);
9913 printf (_("%lu\n"), (unsigned long) cu_index
);
9916 printf (_("\nSymbol table:\n"));
9917 for (i
= 0; i
< symbol_table_slots
; ++i
)
9919 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
9920 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
9921 uint32_t num_cus
, cu
;
9923 if (name_offset
!= 0
9924 || cu_vector_offset
!= 0)
9927 unsigned char * adr
;
9929 adr
= constant_pool
+ name_offset
;
9930 /* PR 17531: file: 5b7b07ad. */
9931 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
9933 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
9934 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
9938 printf ("[%3u] %.*s:", i
,
9939 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
9940 constant_pool
+ name_offset
);
9942 adr
= constant_pool
+ cu_vector_offset
;
9943 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
9945 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
9946 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
9947 cu_vector_offset
, i
);
9951 num_cus
= byte_get_little_endian (adr
, 4);
9953 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
9954 if (num_cus
* 4 < num_cus
9955 || adr
>= section
->start
+ section
->size
9956 || adr
< constant_pool
)
9958 printf ("<invalid number of CUs: %d>\n", num_cus
);
9959 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
9967 for (j
= 0; j
< num_cus
; ++j
)
9970 gdb_index_symbol_kind kind
;
9972 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
9973 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
9974 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
9975 cu
= GDB_INDEX_CU_VALUE (cu
);
9976 /* Convert to TU number if it's for a type unit. */
9977 if (cu
>= cu_list_elements
/ 2)
9978 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
9979 (unsigned long) (cu
- cu_list_elements
/ 2));
9981 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
9983 printf (" [%s, %s]",
9984 is_static
? _("static") : _("global"),
9985 get_gdb_index_symbol_kind_name (kind
));
9997 /* Pre-allocate enough space for the CU/TU sets needed. */
10000 prealloc_cu_tu_list (unsigned int nshndx
)
10002 if (shndx_pool
== NULL
)
10004 shndx_pool_size
= nshndx
;
10005 shndx_pool_used
= 0;
10006 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10007 sizeof (unsigned int));
10011 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10012 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10013 sizeof (unsigned int));
10018 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10020 if (shndx_pool_used
>= shndx_pool_size
)
10022 error (_("Internal error: out of space in the shndx pool.\n"));
10025 shndx_pool
[shndx_pool_used
++] = shndx
;
10029 end_cu_tu_entry (void)
10031 if (shndx_pool_used
>= shndx_pool_size
)
10033 error (_("Internal error: out of space in the shndx pool.\n"));
10036 shndx_pool
[shndx_pool_used
++] = 0;
10039 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10041 static const char *
10042 get_DW_SECT_short_name (unsigned int dw_sect
)
10044 static char buf
[16];
10050 case DW_SECT_TYPES
:
10052 case DW_SECT_ABBREV
:
10058 case DW_SECT_STR_OFFSETS
:
10060 case DW_SECT_MACINFO
:
10062 case DW_SECT_MACRO
:
10068 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10072 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10073 These sections are extensions for Fission.
10074 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10077 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10079 unsigned char *phdr
= section
->start
;
10080 unsigned char *limit
= phdr
+ section
->size
;
10081 unsigned char *phash
;
10082 unsigned char *pindex
;
10083 unsigned char *ppool
;
10084 unsigned int version
;
10085 unsigned int ncols
= 0;
10086 unsigned int nused
;
10087 unsigned int nslots
;
10090 dwarf_vma signature_high
;
10091 dwarf_vma signature_low
;
10094 /* PR 17512: file: 002-168123-0.004. */
10097 warn (_("Section %s is empty\n"), section
->name
);
10100 /* PR 17512: file: 002-376-0.004. */
10101 if (section
->size
< 24)
10103 warn (_("Section %s is too small to contain a CU/TU header\n"),
10108 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
10110 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
10111 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
10112 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
10115 pindex
= phash
+ (size_t) nslots
* 8;
10116 ppool
= pindex
+ (size_t) nslots
* 4;
10120 introduce (section
, FALSE
);
10122 printf (_(" Version: %u\n"), version
);
10124 printf (_(" Number of columns: %u\n"), ncols
);
10125 printf (_(" Number of used entries: %u\n"), nused
);
10126 printf (_(" Number of slots: %u\n\n"), nslots
);
10129 /* PR 17531: file: 45d69832. */
10130 if ((size_t) nslots
* 8 / 8 != nslots
10131 || phash
< phdr
|| phash
> limit
10132 || pindex
< phash
|| pindex
> limit
10133 || ppool
< pindex
|| ppool
> limit
)
10135 warn (ngettext ("Section %s is too small for %u slot\n",
10136 "Section %s is too small for %u slots\n",
10138 section
->name
, nslots
);
10145 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10146 for (i
= 0; i
< nslots
; i
++)
10148 unsigned char *shndx_list
;
10149 unsigned int shndx
;
10151 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
10152 if (signature_high
!= 0 || signature_low
!= 0)
10154 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10155 shndx_list
= ppool
+ j
* 4;
10156 /* PR 17531: file: 705e010d. */
10157 if (shndx_list
< ppool
)
10159 warn (_("Section index pool located before start of section\n"));
10164 printf (_(" [%3d] Signature: 0x%s Sections: "),
10165 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10166 buf
, sizeof (buf
)));
10169 if (shndx_list
>= limit
)
10171 warn (_("Section %s too small for shndx pool\n"),
10175 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10179 printf (" %d", shndx
);
10181 add_shndx_to_cu_tu_entry (shndx
);
10187 end_cu_tu_entry ();
10193 else if (version
== 2)
10196 unsigned int dw_sect
;
10197 unsigned char *ph
= phash
;
10198 unsigned char *pi
= pindex
;
10199 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10200 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10201 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10202 bfd_boolean is_tu_index
;
10203 struct cu_tu_set
*this_set
= NULL
;
10205 unsigned char *prow
;
10207 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10209 /* PR 17531: file: 0dd159bf.
10210 Check for integer overflow (can occur when size_t is 32-bit)
10211 with overlarge ncols or nused values. */
10213 && ((size_t) ncols
* 4 / 4 != ncols
10214 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10215 || poffsets
< ppool
|| poffsets
> limit
10216 || psizes
< poffsets
|| psizes
> limit
10217 || pend
< psizes
|| pend
> limit
))
10219 warn (_("Section %s too small for offset and size tables\n"),
10226 printf (_(" Offset table\n"));
10227 printf (" slot %-16s ",
10228 is_tu_index
? _("signature") : _("dwo_id"));
10235 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10236 this_set
= tu_sets
;
10241 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10242 this_set
= cu_sets
;
10248 for (j
= 0; j
< ncols
; j
++)
10250 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10251 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10256 for (i
= 0; i
< nslots
; i
++)
10258 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10260 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10263 /* PR 17531: file: a05f6ab3. */
10266 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10273 size_t num_copy
= sizeof (uint64_t);
10275 /* PR 23064: Beware of buffer overflow. */
10276 if (ph
+ num_copy
< limit
)
10277 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10280 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10285 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10286 /* PR 17531: file: b8ce60a8. */
10287 if (prow
< poffsets
|| prow
> limit
)
10289 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10295 printf (_(" [%3d] 0x%s"),
10296 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10297 buf
, sizeof (buf
)));
10298 for (j
= 0; j
< ncols
; j
++)
10300 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10302 printf (" %8d", val
);
10305 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10307 /* PR 17531: file: 10796eb3. */
10308 if (dw_sect
>= DW_SECT_MAX
)
10309 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10311 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10327 printf (_(" Size table\n"));
10328 printf (" slot %-16s ",
10329 is_tu_index
? _("signature") : _("dwo_id"));
10332 for (j
= 0; j
< ncols
; j
++)
10334 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
10336 printf (" %8s", get_DW_SECT_short_name (val
));
10342 for (i
= 0; i
< nslots
; i
++)
10344 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10346 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10349 prow
= psizes
+ (row
- 1) * ncols
* 4;
10352 printf (_(" [%3d] 0x%s"),
10353 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10354 buf
, sizeof (buf
)));
10356 for (j
= 0; j
< ncols
; j
++)
10358 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10360 printf (" %8d", val
);
10363 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10364 if (dw_sect
>= DW_SECT_MAX
)
10365 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10367 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10379 else if (do_display
)
10380 printf (_(" Unsupported version (%d)\n"), version
);
10388 /* Load the CU and TU indexes if present. This will build a list of
10389 section sets that we can use to associate a .debug_info.dwo section
10390 with its associated .debug_abbrev.dwo section in a .dwp file. */
10393 load_cu_tu_indexes (void *file
)
10395 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10397 /* If we have already loaded (or tried to load) the CU and TU indexes
10398 then do not bother to repeat the task. */
10399 if (cu_tu_indexes_read
== -1)
10401 cu_tu_indexes_read
= TRUE
;
10403 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10404 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10405 cu_tu_indexes_read
= FALSE
;
10407 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10408 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10409 cu_tu_indexes_read
= FALSE
;
10412 return (bfd_boolean
) cu_tu_indexes_read
;
10415 /* Find the set of sections that includes section SHNDX. */
10418 find_cu_tu_set (void *file
, unsigned int shndx
)
10422 if (! load_cu_tu_indexes (file
))
10425 /* Find SHNDX in the shndx pool. */
10426 for (i
= 0; i
< shndx_pool_used
; i
++)
10427 if (shndx_pool
[i
] == shndx
)
10430 if (i
>= shndx_pool_used
)
10433 /* Now backup to find the first entry in the set. */
10434 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10437 return shndx_pool
+ i
;
10440 /* Display a .debug_cu_index or .debug_tu_index section. */
10443 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10445 return process_cu_tu_index (section
, 1);
10449 display_debug_not_supported (struct dwarf_section
*section
,
10450 void *file ATTRIBUTE_UNUSED
)
10452 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10458 /* Like malloc, but takes two parameters like calloc.
10459 Verifies that the first parameter is not too large.
10460 Note: does *not* initialise the allocated memory to zero. */
10463 cmalloc (size_t nmemb
, size_t size
)
10465 /* Check for overflow. */
10466 if (nmemb
>= ~(size_t) 0 / size
)
10469 return xmalloc (nmemb
* size
);
10472 /* Like xmalloc, but takes two parameters like calloc.
10473 Verifies that the first parameter is not too large.
10474 Note: does *not* initialise the allocated memory to zero. */
10477 xcmalloc (size_t nmemb
, size_t size
)
10479 /* Check for overflow. */
10480 if (nmemb
>= ~(size_t) 0 / size
)
10483 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10488 return xmalloc (nmemb
* size
);
10491 /* Like xrealloc, but takes three parameters.
10492 Verifies that the second parameter is not too large.
10493 Note: does *not* initialise any new memory to zero. */
10496 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10498 /* Check for overflow. */
10499 if (nmemb
>= ~(size_t) 0 / size
)
10501 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10506 return xrealloc (ptr
, nmemb
* size
);
10509 /* Like xcalloc, but verifies that the first parameter is not too large. */
10512 xcalloc2 (size_t nmemb
, size_t size
)
10514 /* Check for overflow. */
10515 if (nmemb
>= ~(size_t) 0 / size
)
10517 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10522 return xcalloc (nmemb
, size
);
10525 static unsigned long
10526 calc_gnu_debuglink_crc32 (unsigned long crc
,
10527 const unsigned char * buf
,
10530 static const unsigned long crc32_table
[256] =
10532 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10533 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10534 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10535 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10536 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10537 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10538 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10539 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10540 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10541 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10542 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10543 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10544 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10545 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10546 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10547 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10548 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10549 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10550 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10551 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10552 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10553 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10554 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10555 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10556 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10557 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10558 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10559 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10560 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10561 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10562 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10563 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10564 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10565 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10566 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10567 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10568 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10569 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10570 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10571 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10572 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10573 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10574 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10575 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10576 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10577 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10578 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10579 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10580 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10581 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10582 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10585 const unsigned char *end
;
10587 crc
= ~crc
& 0xffffffff;
10588 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10589 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10590 return ~crc
& 0xffffffff;
10593 typedef bfd_boolean (* check_func_type
) (const char *, void *);
10594 typedef const char * (* parse_func_type
) (struct dwarf_section
*, void *);
10597 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10599 static unsigned char buffer
[8 * 1024];
10601 bfd_size_type count
;
10602 unsigned long crc
= 0;
10605 sep_data
= open_debug_file (pathname
);
10606 if (sep_data
== NULL
)
10609 /* Yes - we are opening the file twice... */
10610 f
= fopen (pathname
, "rb");
10613 /* Paranoia: This should never happen. */
10614 close_debug_file (sep_data
);
10615 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10619 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10620 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10624 if (crc
!= * (unsigned long *) crc_pointer
)
10626 close_debug_file (sep_data
);
10627 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10635 static const char *
10636 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10639 unsigned int crc_offset
;
10640 unsigned long * crc32
= (unsigned long *) data
;
10642 /* The name is first.
10643 The CRC value is stored after the filename, aligned up to 4 bytes. */
10644 name
= (const char *) section
->start
;
10647 crc_offset
= strnlen (name
, section
->size
) + 1;
10648 crc_offset
= (crc_offset
+ 3) & ~3;
10649 if (crc_offset
+ 4 > section
->size
)
10652 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10657 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10659 void * sep_data
= open_debug_file (filename
);
10661 if (sep_data
== NULL
)
10664 /* FIXME: We should now extract the build-id in the separate file
10670 typedef struct build_id_data
10673 const unsigned char * data
;
10676 static const char *
10677 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10680 bfd_size_type namelen
;
10681 bfd_size_type id_len
;
10682 Build_id_data
* build_id_data
;
10684 /* The name is first.
10685 The build-id follows immediately, with no padding, up to the section's end. */
10687 name
= (const char *) section
->start
;
10688 namelen
= strnlen (name
, section
->size
) + 1;
10689 if (namelen
>= section
->size
)
10692 id_len
= section
->size
- namelen
;
10696 build_id_data
= (Build_id_data
*) data
;
10697 build_id_data
->len
= id_len
;
10698 build_id_data
->data
= section
->start
+ namelen
;
10704 add_separate_debug_file (const char * filename
, void * handle
)
10706 separate_info
* i
= xmalloc (sizeof * i
);
10708 i
->filename
= filename
;
10709 i
->handle
= handle
;
10710 i
->next
= first_separate_info
;
10711 first_separate_info
= i
;
10714 #if HAVE_LIBDEBUGINFOD
10715 /* Query debuginfod servers for the target debuglink or debugaltlink
10716 file. If successful, store the path of the file in filename and
10717 return TRUE, otherwise return FALSE. */
10720 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10724 size_t build_id_len
;
10725 unsigned char * build_id
;
10727 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10729 /* Get the build-id of file. */
10730 build_id
= get_build_id (file
);
10733 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10735 /* Get the build-id of the debugaltlink file. */
10736 unsigned int filelen
;
10738 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10739 if (filelen
== section
->size
)
10740 /* Corrupt debugaltlink. */
10743 build_id
= section
->start
+ filelen
+ 1;
10744 build_id_len
= section
->size
- (filelen
+ 1);
10746 if (build_id_len
== 0)
10755 debuginfod_client
* client
;
10757 client
= debuginfod_begin ();
10758 if (client
== NULL
)
10761 /* Query debuginfod servers for the target file. If found its path
10762 will be stored in filename. */
10763 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
10764 debuginfod_end (client
);
10766 /* Only free build_id if we allocated space for a hex string
10767 in get_build_id (). */
10768 if (build_id_len
== 0)
10773 /* File successfully retrieved. Close fd since we want to
10774 use open_debug_file () on filename instead. */
10785 load_separate_debug_info (const char * main_filename
,
10786 struct dwarf_section
* xlink
,
10787 parse_func_type parse_func
,
10788 check_func_type check_func
,
10790 void * file ATTRIBUTE_UNUSED
)
10792 const char * separate_filename
;
10793 char * debug_filename
;
10795 size_t canon_dirlen
;
10798 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
10800 warn (_("Corrupt debuglink section: %s\n"),
10801 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
10805 /* Attempt to locate the separate file.
10806 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
10808 canon_dir
= lrealpath (main_filename
);
10810 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
10811 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
10813 canon_dir
[canon_dirlen
] = '\0';
10816 #define DEBUGDIR "/lib/debug"
10818 #ifndef EXTRA_DEBUG_ROOT1
10819 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
10821 #ifndef EXTRA_DEBUG_ROOT2
10822 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
10825 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
10827 + strlen (".debug/")
10828 #ifdef EXTRA_DEBUG_ROOT1
10829 + strlen (EXTRA_DEBUG_ROOT1
)
10831 #ifdef EXTRA_DEBUG_ROOT2
10832 + strlen (EXTRA_DEBUG_ROOT2
)
10834 + strlen (separate_filename
)
10836 if (debug_filename
== NULL
)
10838 warn (_("Out of memory"));
10843 /* First try in the current directory. */
10844 sprintf (debug_filename
, "%s", separate_filename
);
10845 if (check_func (debug_filename
, func_data
))
10848 /* Then try in a subdirectory called .debug. */
10849 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10850 if (check_func (debug_filename
, func_data
))
10853 /* Then try in the same directory as the original file. */
10854 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10855 if (check_func (debug_filename
, func_data
))
10858 /* And the .debug subdirectory of that directory. */
10859 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10860 if (check_func (debug_filename
, func_data
))
10863 #ifdef EXTRA_DEBUG_ROOT1
10864 /* Try the first extra debug file root. */
10865 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10866 if (check_func (debug_filename
, func_data
))
10869 /* Try the first extra debug file root. */
10870 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10871 if (check_func (debug_filename
, func_data
))
10875 #ifdef EXTRA_DEBUG_ROOT2
10876 /* Try the second extra debug file root. */
10877 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10878 if (check_func (debug_filename
, func_data
))
10882 /* Then try in the global debug_filename directory. */
10883 strcpy (debug_filename
, DEBUGDIR
);
10884 dirlen
= strlen (DEBUGDIR
) - 1;
10885 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
10886 strcat (debug_filename
, "/");
10887 strcat (debug_filename
, (const char *) separate_filename
);
10889 if (check_func (debug_filename
, func_data
))
10892 #if HAVE_LIBDEBUGINFOD
10894 char * tmp_filename
;
10896 if (debuginfod_fetch_separate_debug_info (xlink
,
10900 /* File successfully downloaded from server, replace
10901 debug_filename with the file's path. */
10902 free (debug_filename
);
10903 debug_filename
= tmp_filename
;
10909 /* Failed to find the file. */
10910 warn (_("could not find separate debug file '%s'\n"), separate_filename
);
10911 warn (_("tried: %s\n"), debug_filename
);
10913 #ifdef EXTRA_DEBUG_ROOT2
10914 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10915 warn (_("tried: %s\n"), debug_filename
);
10918 #ifdef EXTRA_DEBUG_ROOT1
10919 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10920 warn (_("tried: %s\n"), debug_filename
);
10922 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10923 warn (_("tried: %s\n"), debug_filename
);
10926 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10927 warn (_("tried: %s\n"), debug_filename
);
10929 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10930 warn (_("tried: %s\n"), debug_filename
);
10932 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10933 warn (_("tried: %s\n"), debug_filename
);
10935 sprintf (debug_filename
, "%s", separate_filename
);
10936 warn (_("tried: %s\n"), debug_filename
);
10938 #if HAVE_LIBDEBUGINFOD
10940 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
10944 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
10949 free (debug_filename
);
10955 void * debug_handle
;
10957 /* Now open the file.... */
10958 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
10960 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
10961 free (debug_filename
);
10965 /* FIXME: We do not check to see if there are any other separate debug info
10966 files that would also match. */
10968 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename
, debug_filename
);
10969 add_separate_debug_file (debug_filename
, debug_handle
);
10971 /* Do not free debug_filename - it might be referenced inside
10972 the structure returned by open_debug_file(). */
10973 return debug_handle
;
10976 /* Attempt to load a separate dwarf object file. */
10979 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
10981 char * separate_filename
;
10982 void * separate_handle
;
10984 /* FIXME: Skip adding / if dwo_dir ends in /. */
10985 separate_filename
= concat (dir
, "/", name
, NULL
);
10986 if (separate_filename
== NULL
)
10988 warn (_("Out of memory allocating dwo filename\n"));
10992 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
10994 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
10995 free (separate_filename
);
10999 /* FIXME: We should check the dwo_id. */
11001 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11002 add_separate_debug_file (separate_filename
, separate_handle
);
11003 /* Note - separate_filename will be freed in free_debug_memory(). */
11004 return separate_handle
;
11007 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11008 Recursively check the loaded files for more of these sections.
11009 FIXME: Should also check for DWO_* entries in the newlu loaded files. */
11012 check_for_and_load_links (void * file
, const char * filename
)
11014 void * handle
= NULL
;
11016 if (load_debug_section (gnu_debugaltlink
, file
))
11018 Build_id_data build_id_data
;
11020 handle
= load_separate_debug_info (filename
,
11021 & debug_displays
[gnu_debugaltlink
].section
,
11022 parse_gnu_debugaltlink
,
11023 check_gnu_debugaltlink
,
11028 assert (handle
== first_separate_info
->handle
);
11029 check_for_and_load_links (first_separate_info
->handle
,
11030 first_separate_info
->filename
);
11034 if (load_debug_section (gnu_debuglink
, file
))
11036 unsigned long crc32
;
11038 handle
= load_separate_debug_info (filename
,
11039 & debug_displays
[gnu_debuglink
].section
,
11040 parse_gnu_debuglink
,
11041 check_gnu_debuglink
,
11046 assert (handle
== first_separate_info
->handle
);
11047 check_for_and_load_links (first_separate_info
->handle
,
11048 first_separate_info
->filename
);
11053 /* Load the separate debug info file(s) attached to FILE, if any exist.
11054 Returns TRUE if any were found, FALSE otherwise.
11055 If TRUE is returned then the linked list starting at first_separate_info
11056 will be populated with open file handles. */
11059 load_separate_debug_files (void * file
, const char * filename
)
11061 /* Skip this operation if we are not interested in debug links. */
11062 if (! do_follow_links
&& ! do_debug_links
)
11065 /* See if there are any dwo links. */
11066 if (load_debug_section (str
, file
)
11067 && load_debug_section (abbrev
, file
)
11068 && load_debug_section (info
, file
))
11072 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
11074 bfd_boolean introduced
= FALSE
;
11076 const char * dir
= NULL
;
11077 const char * id
= NULL
;
11079 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11081 switch (dwinfo
->type
)
11084 if (do_debug_links
)
11088 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11089 debug_displays
[info
].section
.uncompressed_name
);
11093 printf (_(" Name: %s\n"), dwinfo
->value
);
11094 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11096 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11098 printf (_(" ID: <unknown>\n"));
11102 if (do_follow_links
)
11103 load_dwo_file (filename
, dwinfo
->value
, dir
, id
);
11107 dir
= dwinfo
->value
;
11111 id
= dwinfo
->value
;
11115 error (_("Unexpected DWO INFO type"));
11122 if (! do_follow_links
)
11123 /* The other debug links will be displayed by display_debug_links()
11124 so we do not need to do any further processing here. */
11127 /* FIXME: We do not check for the presence of both link sections in the same file. */
11128 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11129 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11131 check_for_and_load_links (file
, filename
);
11132 if (first_separate_info
!= NULL
)
11135 do_follow_links
= 0;
11140 free_debug_memory (void)
11144 free_all_abbrevs ();
11146 free (cu_abbrev_map
);
11147 cu_abbrev_map
= NULL
;
11148 next_free_abbrev_map_entry
= 0;
11150 for (i
= 0; i
< max
; i
++)
11151 free_debug_section ((enum dwarf_section_display_enum
) i
);
11153 if (debug_information
!= NULL
)
11155 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11157 if (debug_information
[i
].max_loc_offsets
)
11159 free (debug_information
[i
].loc_offsets
);
11160 free (debug_information
[i
].have_frame_base
);
11162 if (debug_information
[i
].max_range_lists
)
11163 free (debug_information
[i
].range_lists
);
11165 free (debug_information
);
11166 debug_information
= NULL
;
11167 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11171 separate_info
* next
;
11173 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11175 close_debug_file (d
->handle
);
11176 free ((void *) d
->filename
);
11180 first_separate_info
= NULL
;
11186 dwarf_select_sections_by_names (const char *names
)
11190 const char * option
;
11194 debug_dump_long_opts
;
11196 static const debug_dump_long_opts opts_table
[] =
11198 /* Please keep this table alpha- sorted. */
11199 { "Ranges", & do_debug_ranges
, 1 },
11200 { "abbrev", & do_debug_abbrevs
, 1 },
11201 { "addr", & do_debug_addr
, 1 },
11202 { "aranges", & do_debug_aranges
, 1 },
11203 { "cu_index", & do_debug_cu_index
, 1 },
11204 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11205 { "follow-links", & do_follow_links
, 1 },
11206 { "frames", & do_debug_frames
, 1 },
11207 { "frames-interp", & do_debug_frames_interp
, 1 },
11208 /* The special .gdb_index section. */
11209 { "gdb_index", & do_gdb_index
, 1 },
11210 { "info", & do_debug_info
, 1 },
11211 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11212 { "links", & do_debug_links
, 1 },
11213 { "loc", & do_debug_loc
, 1 },
11214 { "macro", & do_debug_macinfo
, 1 },
11215 { "pubnames", & do_debug_pubnames
, 1 },
11216 { "pubtypes", & do_debug_pubtypes
, 1 },
11217 /* This entry is for compatibility
11218 with earlier versions of readelf. */
11219 { "ranges", & do_debug_aranges
, 1 },
11220 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11221 { "str", & do_debug_str
, 1 },
11222 { "str-offsets", & do_debug_str_offsets
, 1 },
11223 /* These trace_* sections are used by Itanium VMS. */
11224 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11225 { "trace_aranges", & do_trace_aranges
, 1 },
11226 { "trace_info", & do_trace_info
, 1 },
11235 const debug_dump_long_opts
* entry
;
11237 for (entry
= opts_table
; entry
->option
; entry
++)
11239 size_t len
= strlen (entry
->option
);
11241 if (strncmp (p
, entry
->option
, len
) == 0
11242 && (p
[len
] == ',' || p
[len
] == '\0'))
11244 * entry
->variable
|= entry
->val
;
11246 /* The --debug-dump=frames-interp option also
11247 enables the --debug-dump=frames option. */
11248 if (do_debug_frames_interp
)
11249 do_debug_frames
= 1;
11256 if (entry
->option
== NULL
)
11258 warn (_("Unrecognized debug option '%s'\n"), p
);
11259 p
= strchr (p
, ',');
11270 dwarf_select_sections_by_letters (const char *letters
)
11272 unsigned int lindex
= 0;
11274 while (letters
[lindex
])
11275 switch (letters
[lindex
++])
11277 case 'A': do_debug_addr
= 1; break;
11278 case 'a': do_debug_abbrevs
= 1; break;
11279 case 'c': do_debug_cu_index
= 1; break;
11280 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11281 case 'f': do_debug_frames
= 1; break;
11282 case 'g': do_gdb_index
= 1; break;
11283 case 'i': do_debug_info
= 1; break;
11284 case 'K': do_follow_links
= 1; break;
11285 case 'k': do_debug_links
= 1; break;
11286 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11287 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11288 case 'm': do_debug_macinfo
= 1; break;
11289 case 'O': do_debug_str_offsets
= 1; break;
11290 case 'o': do_debug_loc
= 1; break;
11291 case 'p': do_debug_pubnames
= 1; break;
11292 case 'R': do_debug_ranges
= 1; break;
11293 case 'r': do_debug_aranges
= 1; break;
11294 case 's': do_debug_str
= 1; break;
11295 case 'T': do_trace_aranges
= 1; break;
11296 case 't': do_debug_pubtypes
= 1; break;
11297 case 'U': do_trace_info
= 1; break;
11298 case 'u': do_trace_abbrevs
= 1; break;
11301 warn (_("Unrecognized debug option '%s'\n"), letters
);
11307 dwarf_select_sections_all (void)
11310 do_debug_abbrevs
= 1;
11311 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11312 do_debug_pubnames
= 1;
11313 do_debug_pubtypes
= 1;
11314 do_debug_aranges
= 1;
11315 do_debug_ranges
= 1;
11316 do_debug_frames
= 1;
11317 do_debug_macinfo
= 1;
11322 do_trace_abbrevs
= 1;
11323 do_trace_aranges
= 1;
11325 do_debug_cu_index
= 1;
11326 do_follow_links
= 1;
11327 do_debug_links
= 1;
11328 do_debug_str_offsets
= 1;
11331 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
11332 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
11334 /* N.B. The order here must match the order in section_display_enum. */
11336 struct dwarf_section_display debug_displays
[] =
11338 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
11339 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, TRUE
},
11340 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
11341 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, TRUE
},
11342 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
11343 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
11344 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
11345 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
11346 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
11347 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
11348 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11349 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11350 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11351 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11352 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
11353 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
11354 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
11355 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
11356 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
11357 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
11358 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, TRUE
},
11359 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
11360 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, FALSE
},
11361 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, FALSE
},
11362 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, TRUE
},
11363 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
11364 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, FALSE
},
11365 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, TRUE
},
11366 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
11367 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, TRUE
},
11368 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
11369 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11370 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
11371 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
11372 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, TRUE
},
11373 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
11374 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
11375 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, TRUE
},
11376 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
11377 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
11378 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
11379 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
11380 /* Separate debug info files can containt their own .debug_str section,
11381 and this might be in *addition* to a .debug_str section already present
11382 in the main file. Hence we need to have two entries for .debug_str. */
11383 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11386 /* A static assertion. */
11387 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];