1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2022 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
44 #ifndef ENABLE_CHECKING
45 #define ENABLE_CHECKING 0
50 #define MAX(a, b) ((a) > (b) ? (a) : (b))
51 #define MIN(a, b) ((a) < (b) ? (a) : (b))
53 static const char *regname (unsigned int regno
, int row
);
54 static const char *regname_internal_by_table_only (unsigned int regno
);
56 static int have_frame_base
;
57 static int need_base_address
;
59 static unsigned int num_debug_info_entries
= 0;
60 static unsigned int alloc_num_debug_info_entries
= 0;
61 static debug_info
*debug_information
= NULL
;
62 /* Special value for num_debug_info_entries to indicate
63 that the .debug_info section could not be loaded/parsed. */
64 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
66 /* A .debug_info section can contain multiple links to separate
67 DWO object files. We use these structures to record these links. */
75 typedef struct dwo_info
80 struct dwo_info
* next
;
83 static dwo_info
*first_dwo_info
= NULL
;
84 static bool need_dwo_info
;
86 separate_info
* first_separate_info
= NULL
;
88 unsigned int eh_addr_size
;
93 int do_debug_pubnames
;
94 int do_debug_pubtypes
;
98 int do_debug_frames_interp
;
101 int do_debug_str_offsets
;
105 int do_trace_abbrevs
;
106 int do_trace_aranges
;
108 int do_debug_cu_index
;
111 int do_follow_links
= DEFAULT_FOR_FOLLOW_LINKS
;
112 #ifdef HAVE_LIBDEBUGINFOD
113 int use_debuginfod
= 1;
117 int dwarf_cutoff_level
= -1;
118 unsigned long dwarf_start_die
;
122 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
123 testing whether e.g. a locview list is present. */
124 static const dwarf_vma vm1
= -1;
126 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
127 sections. For version 1 package files, each set is stored in SHNDX_POOL
128 as a zero-terminated list of section indexes comprising one set of debug
129 sections from a .dwo file. */
131 static unsigned int *shndx_pool
= NULL
;
132 static unsigned int shndx_pool_size
= 0;
133 static unsigned int shndx_pool_used
= 0;
135 /* For version 2 package files, each set contains an array of section offsets
136 and an array of section sizes, giving the offset and size of the
137 contribution from a CU or TU within one of the debug sections.
138 When displaying debug info from a package file, we need to use these
139 tables to locate the corresponding contributions to each section. */
144 dwarf_vma section_offsets
[DW_SECT_MAX
];
145 size_t section_sizes
[DW_SECT_MAX
];
148 static int cu_count
= 0;
149 static int tu_count
= 0;
150 static struct cu_tu_set
*cu_sets
= NULL
;
151 static struct cu_tu_set
*tu_sets
= NULL
;
153 static bool load_cu_tu_indexes (void *);
155 /* An array that indicates for a given level of CU nesting whether
156 the latest DW_AT_type seen for that level was a signed type or
158 #define MAX_CU_NESTING (1 << 8)
159 static bool level_type_signed
[MAX_CU_NESTING
];
161 /* Values for do_debug_lines. */
162 #define FLAG_DEBUG_LINES_RAW 1
163 #define FLAG_DEBUG_LINES_DECODED 2
166 size_of_encoded_value (int encoding
)
168 switch (encoding
& 0x7)
171 case 0: return eh_addr_size
;
179 get_encoded_value (unsigned char **pdata
,
181 struct dwarf_section
*section
,
184 unsigned char * data
= * pdata
;
185 unsigned int size
= size_of_encoded_value (encoding
);
188 if (data
>= end
|| size
> (size_t) (end
- data
))
190 warn (_("Encoded value extends past end of section\n"));
195 /* PR 17512: file: 002-829853-0.004. */
198 warn (_("Encoded size of %d is too large to read\n"), size
);
203 /* PR 17512: file: 1085-5603-0.004. */
206 warn (_("Encoded size of 0 is too small to read\n"));
211 if (encoding
& DW_EH_PE_signed
)
212 val
= byte_get_signed (data
, size
);
214 val
= byte_get (data
, size
);
216 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
217 val
+= section
->address
+ (data
- section
->start
);
219 * pdata
= data
+ size
;
223 #if SIZEOF_LONG_LONG > SIZEOF_LONG
225 # define DWARF_VMA_FMT "ll"
226 # define DWARF_VMA_FMT_LONG "%16.16llx"
228 # define DWARF_VMA_FMT "I64"
229 # define DWARF_VMA_FMT_LONG "%016I64x"
232 # define DWARF_VMA_FMT "l"
233 # define DWARF_VMA_FMT_LONG "%16.16lx"
236 /* Convert a dwarf vma value into a string. Returns a pointer to a static
237 buffer containing the converted VALUE. The value is converted according
238 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
239 it specifies the maximum number of bytes to be displayed in the converted
240 value and FMTCH is ignored - hex is always used. */
243 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
245 /* As dwarf_vmatoa is used more then once in a printf call
246 for output, we are cycling through a fixed array of pointers
247 for return address. */
248 static int buf_pos
= 0;
249 static struct dwarf_vmatoa_buf
255 ret
= buf
[buf_pos
++].place
;
256 buf_pos
%= ARRAY_SIZE (buf
);
260 /* Printf does not have a way of specifying a maximum field width for an
261 integer value, so we print the full value into a buffer and then select
262 the precision we need. */
263 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
266 return ret
+ (16 - 2 * num_bytes
);
273 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
275 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
276 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
281 static inline const char *
282 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
284 return dwarf_vmatoa_1 (fmtch
, value
, 0);
287 /* Print a dwarf_vma value (typically an address, offset or length) in
288 hexadecimal format, followed by a space. The length of the VALUE (and
289 hence the precision displayed) is determined by the NUM_BYTES parameter. */
292 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
294 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
297 /* Print a view number in hexadecimal value, with the same width
298 print_dwarf_vma would have printed it with the same num_bytes.
299 Print blanks for zero view, unless force is nonzero. */
302 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
310 assert (value
== (unsigned long) value
);
312 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
314 printf ("%*s", len
+ 1, "");
317 /* Read in a LEB128 encoded value starting at address DATA.
318 If SIGN is true, return a signed LEB128 value.
319 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
320 If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the
321 terminating byte was not found and with bit 1 set if the value
322 overflows a dwarf_vma.
323 No bytes will be read at address END or beyond. */
326 read_leb128 (unsigned char *data
,
327 const unsigned char *const end
,
329 unsigned int *length_return
,
332 dwarf_vma result
= 0;
333 unsigned int num_read
= 0;
334 unsigned int shift
= 0;
339 unsigned char byte
= *data
++;
340 unsigned char lost
, mask
;
344 if (shift
< CHAR_BIT
* sizeof (result
))
346 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
347 /* These bits overflowed. */
348 lost
= byte
^ (result
>> shift
);
349 /* And this is the mask of possible overflow bits. */
350 mask
= 0x7f ^ ((dwarf_vma
) 0x7f << shift
>> shift
);
358 if ((lost
& mask
) != (sign
&& (dwarf_signed_vma
) result
< 0 ? mask
: 0))
361 if ((byte
& 0x80) == 0)
364 if (sign
&& shift
< CHAR_BIT
* sizeof (result
) && (byte
& 0x40))
365 result
|= -((dwarf_vma
) 1 << shift
);
370 if (length_return
!= NULL
)
371 *length_return
= num_read
;
372 if (status_return
!= NULL
)
373 *status_return
= status
;
378 /* Read AMOUNT bytes from PTR and store them in VAL.
379 Checks to make sure that the read will not reach or pass END.
380 FUNC chooses whether the value read is unsigned or signed, and may
381 be either byte_get or byte_get_signed. If INC is true, PTR is
382 incremented after reading the value.
383 This macro cannot protect against PTR values derived from user input.
384 The C standard sections 6.5.6 and 6.5.8 say attempts to do so using
385 pointers is undefined behaviour. */
386 #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \
389 size_t amount = (AMOUNT); \
390 if (sizeof (VAL) < amount) \
392 error (ngettext ("internal error: attempt to read %d byte " \
393 "of data in to %d sized variable", \
394 "internal error: attempt to read %d bytes " \
395 "of data in to %d sized variable", \
397 (int) amount, (int) sizeof (VAL)); \
398 amount = sizeof (VAL); \
400 if (ENABLE_CHECKING) \
401 assert ((PTR) <= (END)); \
402 size_t avail = (END) - (PTR); \
405 if (amount > avail) \
410 (VAL) = (FUNC) ((PTR), amount); \
416 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
417 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false)
419 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
420 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true)
422 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
423 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false)
425 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
426 SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true)
428 typedef struct State_Machine_Registers
437 unsigned char op_index
;
438 unsigned char end_sequence
;
439 /* This variable hold the number of the last entry seen
440 in the File Table. */
441 unsigned int last_file_entry
;
444 static SMR state_machine_regs
;
447 reset_state_machine (int is_stmt
)
449 state_machine_regs
.address
= 0;
450 state_machine_regs
.view
= 0;
451 state_machine_regs
.op_index
= 0;
452 state_machine_regs
.file
= 1;
453 state_machine_regs
.line
= 1;
454 state_machine_regs
.column
= 0;
455 state_machine_regs
.is_stmt
= is_stmt
;
456 state_machine_regs
.basic_block
= 0;
457 state_machine_regs
.end_sequence
= 0;
458 state_machine_regs
.last_file_entry
= 0;
461 /* Handled an extend line op.
462 Returns the number of bytes read. */
465 process_extended_line_op (unsigned char * data
,
469 unsigned char op_code
;
470 size_t len
, header_len
;
472 unsigned char *orig_data
= data
;
475 READ_ULEB (len
, data
, end
);
476 header_len
= data
- orig_data
;
478 if (len
== 0 || data
>= end
|| len
> (size_t) (end
- data
))
480 warn (_("Badly formed extended line op encountered!\n"));
486 printf (_(" Extended opcode %d: "), op_code
);
490 case DW_LNE_end_sequence
:
491 printf (_("End of Sequence\n\n"));
492 reset_state_machine (is_stmt
);
495 case DW_LNE_set_address
:
496 /* PR 17512: file: 002-100480-0.004. */
499 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
500 (unsigned long) len
- 1);
504 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
505 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
506 state_machine_regs
.address
= adr
;
507 state_machine_regs
.view
= 0;
508 state_machine_regs
.op_index
= 0;
511 case DW_LNE_define_file
:
512 printf (_("define new File Table entry\n"));
513 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
514 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
520 l
= strnlen ((char *) data
, end
- data
);
524 READ_ULEB (val
, data
, end
);
525 printf ("%s\t", dwarf_vmatoa ("u", val
));
526 READ_ULEB (val
, data
, end
);
527 printf ("%s\t", dwarf_vmatoa ("u", val
));
528 READ_ULEB (val
, data
, end
);
529 printf ("%s\t", dwarf_vmatoa ("u", val
));
530 printf ("%.*s\n\n", (int) l
, name
);
533 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
>= end
)
534 warn (_("DW_LNE_define_file: Bad opcode length\n"));
537 case DW_LNE_set_discriminator
:
538 READ_ULEB (val
, data
, end
);
539 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
543 case DW_LNE_HP_negate_is_UV_update
:
544 printf ("DW_LNE_HP_negate_is_UV_update\n");
546 case DW_LNE_HP_push_context
:
547 printf ("DW_LNE_HP_push_context\n");
549 case DW_LNE_HP_pop_context
:
550 printf ("DW_LNE_HP_pop_context\n");
552 case DW_LNE_HP_set_file_line_column
:
553 printf ("DW_LNE_HP_set_file_line_column\n");
555 case DW_LNE_HP_set_routine_name
:
556 printf ("DW_LNE_HP_set_routine_name\n");
558 case DW_LNE_HP_set_sequence
:
559 printf ("DW_LNE_HP_set_sequence\n");
561 case DW_LNE_HP_negate_post_semantics
:
562 printf ("DW_LNE_HP_negate_post_semantics\n");
564 case DW_LNE_HP_negate_function_exit
:
565 printf ("DW_LNE_HP_negate_function_exit\n");
567 case DW_LNE_HP_negate_front_end_logical
:
568 printf ("DW_LNE_HP_negate_front_end_logical\n");
570 case DW_LNE_HP_define_proc
:
571 printf ("DW_LNE_HP_define_proc\n");
573 case DW_LNE_HP_source_file_correlation
:
575 unsigned char *edata
= data
+ len
- 1;
577 printf ("DW_LNE_HP_source_file_correlation\n");
583 READ_ULEB (opc
, data
, edata
);
587 case DW_LNE_HP_SFC_formfeed
:
588 printf (" DW_LNE_HP_SFC_formfeed\n");
590 case DW_LNE_HP_SFC_set_listing_line
:
591 READ_ULEB (val
, data
, edata
);
592 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
593 dwarf_vmatoa ("u", val
));
595 case DW_LNE_HP_SFC_associate
:
596 printf (" DW_LNE_HP_SFC_associate ");
597 READ_ULEB (val
, data
, edata
);
598 printf ("(%s", dwarf_vmatoa ("u", val
));
599 READ_ULEB (val
, data
, edata
);
600 printf (",%s", dwarf_vmatoa ("u", val
));
601 READ_ULEB (val
, data
, edata
);
602 printf (",%s)\n", dwarf_vmatoa ("u", val
));
605 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
615 unsigned int rlen
= len
- 1;
617 if (op_code
>= DW_LNE_lo_user
618 /* The test against DW_LNW_hi_user is redundant due to
619 the limited range of the unsigned char data type used
621 /*&& op_code <= DW_LNE_hi_user*/)
622 printf (_("user defined: "));
624 printf (_("UNKNOWN: "));
625 printf (_("length %d ["), rlen
);
627 printf (" %02x", *data
++);
633 return len
+ header_len
;
636 static const unsigned char *
637 fetch_indirect_string (dwarf_vma offset
)
639 struct dwarf_section
*section
= &debug_displays
[str
].section
;
640 const unsigned char * ret
;
642 if (section
->start
== NULL
)
643 return (const unsigned char *) _("<no .debug_str section>");
645 if (offset
>= section
->size
)
647 warn (_("DW_FORM_strp offset too big: 0x%s\n"),
648 dwarf_vmatoa ("x", offset
));
649 return (const unsigned char *) _("<offset is too big>");
652 ret
= section
->start
+ offset
;
653 /* Unfortunately we cannot rely upon the .debug_str section ending with a
654 NUL byte. Since our caller is expecting to receive a well formed C
655 string we test for the lack of a terminating byte here. */
656 if (strnlen ((const char *) ret
, section
->size
- offset
)
657 == section
->size
- offset
)
658 ret
= (const unsigned char *)
659 _("<no NUL byte at end of .debug_str section>");
664 static const unsigned char *
665 fetch_indirect_line_string (dwarf_vma offset
)
667 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
668 const unsigned char * ret
;
670 if (section
->start
== NULL
)
671 return (const unsigned char *) _("<no .debug_line_str section>");
673 if (offset
>= section
->size
)
675 warn (_("DW_FORM_line_strp offset too big: 0x%s\n"),
676 dwarf_vmatoa ("x", offset
));
677 return (const unsigned char *) _("<offset is too big>");
680 ret
= section
->start
+ offset
;
681 /* Unfortunately we cannot rely upon the .debug_line_str section ending
682 with a NUL byte. Since our caller is expecting to receive a well formed
683 C string we test for the lack of a terminating byte here. */
684 if (strnlen ((const char *) ret
, section
->size
- offset
)
685 == section
->size
- offset
)
686 ret
= (const unsigned char *)
687 _("<no NUL byte at end of .debug_line_str section>");
693 fetch_indexed_string (dwarf_vma idx
,
694 struct cu_tu_set
* this_set
,
695 dwarf_vma offset_size
,
697 dwarf_vma str_offsets_base
)
699 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
700 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
701 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
702 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
703 dwarf_vma index_offset
;
704 dwarf_vma str_offset
;
707 if (index_section
->start
== NULL
)
708 return (dwo
? _("<no .debug_str_offsets.dwo section>")
709 : _("<no .debug_str_offsets section>"));
711 if (str_section
->start
== NULL
)
712 return (dwo
? _("<no .debug_str.dwo section>")
713 : _("<no .debug_str section>"));
715 index_offset
= idx
* offset_size
;
717 if (this_set
!= NULL
)
718 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
720 index_offset
+= str_offsets_base
;
722 if (index_offset
+ offset_size
> index_section
->size
)
724 warn (_("string index of %s converts to an offset of 0x%s which is too big for section %s"),
725 dwarf_vmatoa ("d", idx
),
726 dwarf_vmatoa ("x", index_offset
),
729 return _("<string index too big>");
732 /* FIXME: If we are being paranoid then we should also check to see if
733 IDX references an entry beyond the end of the string table pointed to
734 by STR_OFFSETS_BASE. (Since there can be more than one string table
735 in a DWARF string section). */
737 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
739 str_offset
-= str_section
->address
;
740 if (str_offset
>= str_section
->size
)
742 warn (_("indirect offset too big: 0x%s\n"),
743 dwarf_vmatoa ("x", str_offset
));
744 return _("<indirect index offset is too big>");
747 ret
= (const char *) str_section
->start
+ str_offset
;
749 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
750 Since our caller is expecting to receive a well formed C string we test
751 for the lack of a terminating byte here. */
752 if (strnlen (ret
, str_section
->size
- str_offset
)
753 == str_section
->size
- str_offset
)
754 return _("<no NUL byte at end of section>");
760 fetch_indexed_addr (dwarf_vma offset
, uint32_t num_bytes
)
762 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
764 if (section
->start
== NULL
)
766 warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n"));
770 if (offset
+ num_bytes
> section
->size
)
772 warn (_("Offset into section %s too big: 0x%s\n"),
773 section
->name
, dwarf_vmatoa ("x", offset
));
777 return byte_get (section
->start
+ offset
, num_bytes
);
780 /* Fetch a value from a debug section that has been indexed by
781 something in another section (eg DW_FORM_loclistx or DW_FORM_rnglistx).
782 Returns 0 if the value could not be found. */
785 fetch_indexed_value (dwarf_vma idx
,
786 enum dwarf_section_display_enum sec_enum
,
787 dwarf_vma base_address
)
789 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
791 if (section
->start
== NULL
)
793 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
797 uint32_t pointer_size
, bias
;
799 if (byte_get (section
->start
, 4) == 0xffffffff)
810 dwarf_vma offset
= idx
* pointer_size
;
812 /* Offsets are biased by the size of the section header
815 offset
+= base_address
;
819 if (offset
+ pointer_size
> section
->size
)
821 warn (_("Offset into section %s too big: 0x%s\n"),
822 section
->name
, dwarf_vmatoa ("x", offset
));
826 return byte_get (section
->start
+ offset
, pointer_size
);
829 /* FIXME: There are better and more efficient ways to handle
830 these structures. For now though, I just want something that
831 is simple to implement. */
832 /* Records a single attribute in an abbrev. */
833 typedef struct abbrev_attr
835 unsigned long attribute
;
837 dwarf_signed_vma implicit_const
;
838 struct abbrev_attr
* next
;
842 /* Records a single abbrev. */
843 typedef struct abbrev_entry
845 unsigned long number
;
848 struct abbrev_attr
* first_attr
;
849 struct abbrev_attr
* last_attr
;
850 struct abbrev_entry
* next
;
854 /* Records a set of abbreviations. */
855 typedef struct abbrev_list
857 abbrev_entry
* first_abbrev
;
858 abbrev_entry
* last_abbrev
;
859 dwarf_vma abbrev_base
;
860 dwarf_vma abbrev_offset
;
861 struct abbrev_list
* next
;
862 unsigned char * start_of_next_abbrevs
;
866 /* Records all the abbrevs found so far. */
867 static struct abbrev_list
* abbrev_lists
= NULL
;
869 typedef struct abbrev_map
876 /* Maps between CU offsets and abbrev sets. */
877 static abbrev_map
* cu_abbrev_map
= NULL
;
878 static unsigned long num_abbrev_map_entries
= 0;
879 static unsigned long next_free_abbrev_map_entry
= 0;
881 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
882 #define ABBREV_MAP_ENTRIES_INCREMENT 8
885 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
887 if (cu_abbrev_map
== NULL
)
889 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
890 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
892 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
894 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
895 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
898 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
899 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
900 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
901 next_free_abbrev_map_entry
++;
905 free_abbrev_list (abbrev_list
*list
)
907 abbrev_entry
*abbrv
= list
->first_abbrev
;
911 abbrev_attr
*attr
= abbrv
->first_attr
;
915 abbrev_attr
*next_attr
= attr
->next
;
920 abbrev_entry
*next_abbrev
= abbrv
->next
;
925 abbrev_list
*next
= list
->next
;
931 free_all_abbrevs (void)
934 abbrev_lists
= free_abbrev_list (abbrev_lists
);
936 free (cu_abbrev_map
);
937 cu_abbrev_map
= NULL
;
938 next_free_abbrev_map_entry
= 0;
942 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
944 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
946 list
->abbrev_base
= abbrev_base
;
947 list
->abbrev_offset
= abbrev_offset
;
949 list
->next
= abbrev_lists
;
956 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
957 dwarf_vma abbrev_offset
)
961 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
962 if (list
->abbrev_base
== abbrev_base
963 && list
->abbrev_offset
== abbrev_offset
)
969 /* Find the abbreviation map for the CU that includes OFFSET.
970 OFFSET is an absolute offset from the start of the .debug_info section. */
971 /* FIXME: This function is going to slow down readelf & objdump.
972 Consider using a better algorithm to mitigate this effect. */
975 find_abbrev_map_by_offset (dwarf_vma offset
)
979 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
980 if (cu_abbrev_map
[i
].start
<= offset
981 && cu_abbrev_map
[i
].end
> offset
)
982 return cu_abbrev_map
+ i
;
988 add_abbrev (unsigned long number
,
993 abbrev_entry
* entry
;
995 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
997 entry
->number
= number
;
999 entry
->children
= children
;
1000 entry
->first_attr
= NULL
;
1001 entry
->last_attr
= NULL
;
1004 assert (list
!= NULL
);
1006 if (list
->first_abbrev
== NULL
)
1007 list
->first_abbrev
= entry
;
1009 list
->last_abbrev
->next
= entry
;
1011 list
->last_abbrev
= entry
;
1015 add_abbrev_attr (unsigned long attribute
,
1017 dwarf_signed_vma implicit_const
,
1022 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1024 attr
->attribute
= attribute
;
1026 attr
->implicit_const
= implicit_const
;
1029 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1031 if (list
->last_abbrev
->first_attr
== NULL
)
1032 list
->last_abbrev
->first_attr
= attr
;
1034 list
->last_abbrev
->last_attr
->next
= attr
;
1036 list
->last_abbrev
->last_attr
= attr
;
1039 /* Processes the (partial) contents of a .debug_abbrev section.
1040 Returns NULL if the end of the section was encountered.
1041 Returns the address after the last byte read if the end of
1042 an abbreviation set was found. */
1044 static unsigned char *
1045 process_abbrev_set (struct dwarf_section
*section
,
1046 dwarf_vma abbrev_base
,
1047 dwarf_vma abbrev_size
,
1048 dwarf_vma abbrev_offset
,
1051 if (abbrev_base
>= section
->size
1052 || abbrev_size
> section
->size
- abbrev_base
)
1054 /* PR 17531: file:4bcd9ce9. */
1055 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
1056 "abbrev section size (%lx)\n"),
1057 (unsigned long) (abbrev_base
+ abbrev_size
),
1058 (unsigned long) section
->size
);
1061 if (abbrev_offset
>= abbrev_size
)
1063 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
1064 "abbrev section size (%lx)\n"),
1065 (unsigned long) abbrev_offset
,
1066 (unsigned long) abbrev_size
);
1070 unsigned char *start
= section
->start
+ abbrev_base
;
1071 unsigned char *end
= start
+ abbrev_size
;
1072 start
+= abbrev_offset
;
1075 unsigned long entry
;
1077 unsigned long attribute
;
1080 READ_ULEB (entry
, start
, end
);
1082 /* A single zero is supposed to end the set according
1083 to the standard. If there's more, then signal that to
1090 READ_ULEB (tag
, start
, end
);
1094 children
= *start
++;
1096 add_abbrev (entry
, tag
, children
, list
);
1101 /* Initialize it due to a false compiler warning. */
1102 dwarf_signed_vma implicit_const
= -1;
1104 READ_ULEB (attribute
, start
, end
);
1108 READ_ULEB (form
, start
, end
);
1112 if (form
== DW_FORM_implicit_const
)
1114 READ_SLEB (implicit_const
, start
, end
);
1119 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1121 while (attribute
!= 0);
1124 /* Report the missing single zero which ends the section. */
1125 error (_("%s section not zero terminated\n"), section
->name
);
1131 get_TAG_name (unsigned long tag
)
1133 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1137 static char buffer
[100];
1139 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1140 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1142 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1150 get_FORM_name (unsigned long form
)
1155 return "DW_FORM value: 0";
1157 name
= get_DW_FORM_name (form
);
1160 static char buffer
[100];
1162 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1170 get_IDX_name (unsigned long idx
)
1172 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1176 static char buffer
[100];
1178 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1185 static unsigned char *
1186 display_block (unsigned char *data
,
1188 const unsigned char * const end
, char delimiter
)
1192 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1194 return (unsigned char *) end
;
1196 maxlen
= (dwarf_vma
) (end
- data
);
1197 length
= length
> maxlen
? maxlen
: length
;
1200 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1206 decode_location_expression (unsigned char * data
,
1207 unsigned int pointer_size
,
1208 unsigned int offset_size
,
1211 dwarf_vma cu_offset
,
1212 struct dwarf_section
* section
)
1216 dwarf_signed_vma svalue
;
1217 unsigned char *end
= data
+ length
;
1218 int need_frame_base
= 0;
1227 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1228 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1231 printf ("DW_OP_deref");
1234 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1235 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1238 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1239 printf ("DW_OP_const1s: %ld", (long) svalue
);
1242 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1243 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1246 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1247 printf ("DW_OP_const2s: %ld", (long) svalue
);
1250 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1251 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1254 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1255 printf ("DW_OP_const4s: %ld", (long) svalue
);
1258 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1259 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1260 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1261 printf ("%lu", (unsigned long) uvalue
);
1264 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1265 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1266 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1267 printf ("%ld", (long) svalue
);
1270 READ_ULEB (uvalue
, data
, end
);
1271 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1274 READ_SLEB (svalue
, data
, end
);
1275 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1278 printf ("DW_OP_dup");
1281 printf ("DW_OP_drop");
1284 printf ("DW_OP_over");
1287 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1288 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1291 printf ("DW_OP_swap");
1294 printf ("DW_OP_rot");
1297 printf ("DW_OP_xderef");
1300 printf ("DW_OP_abs");
1303 printf ("DW_OP_and");
1306 printf ("DW_OP_div");
1309 printf ("DW_OP_minus");
1312 printf ("DW_OP_mod");
1315 printf ("DW_OP_mul");
1318 printf ("DW_OP_neg");
1321 printf ("DW_OP_not");
1324 printf ("DW_OP_or");
1327 printf ("DW_OP_plus");
1329 case DW_OP_plus_uconst
:
1330 READ_ULEB (uvalue
, data
, end
);
1331 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1334 printf ("DW_OP_shl");
1337 printf ("DW_OP_shr");
1340 printf ("DW_OP_shra");
1343 printf ("DW_OP_xor");
1346 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1347 printf ("DW_OP_bra: %ld", (long) svalue
);
1350 printf ("DW_OP_eq");
1353 printf ("DW_OP_ge");
1356 printf ("DW_OP_gt");
1359 printf ("DW_OP_le");
1362 printf ("DW_OP_lt");
1365 printf ("DW_OP_ne");
1368 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1369 printf ("DW_OP_skip: %ld", (long) svalue
);
1404 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1439 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1440 regname (op
- DW_OP_reg0
, 1));
1475 READ_SLEB (svalue
, data
, end
);
1476 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1477 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1481 READ_ULEB (uvalue
, data
, end
);
1482 printf ("DW_OP_regx: %s (%s)",
1483 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1486 need_frame_base
= 1;
1487 READ_SLEB (svalue
, data
, end
);
1488 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1491 READ_ULEB (uvalue
, data
, end
);
1492 READ_SLEB (svalue
, data
, end
);
1493 printf ("DW_OP_bregx: %s (%s) %s",
1494 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1495 dwarf_vmatoa ("d", svalue
));
1498 READ_ULEB (uvalue
, data
, end
);
1499 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1501 case DW_OP_deref_size
:
1502 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1503 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1505 case DW_OP_xderef_size
:
1506 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1507 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1510 printf ("DW_OP_nop");
1513 /* DWARF 3 extensions. */
1514 case DW_OP_push_object_address
:
1515 printf ("DW_OP_push_object_address");
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
, 2, end
);
1521 printf ("DW_OP_call2: <0x%s>",
1522 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1525 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1526 this ought to be an 8-byte wide computation. */
1527 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1528 printf ("DW_OP_call4: <0x%s>",
1529 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1531 case DW_OP_call_ref
:
1532 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1533 this ought to be an 8-byte wide computation. */
1534 if (dwarf_version
== -1)
1536 printf (_("(DW_OP_call_ref in frame info)"));
1537 /* No way to tell where the next op is, so just bail. */
1538 return need_frame_base
;
1540 if (dwarf_version
== 2)
1542 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1546 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1548 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1550 case DW_OP_form_tls_address
:
1551 printf ("DW_OP_form_tls_address");
1553 case DW_OP_call_frame_cfa
:
1554 printf ("DW_OP_call_frame_cfa");
1556 case DW_OP_bit_piece
:
1557 printf ("DW_OP_bit_piece: ");
1558 READ_ULEB (uvalue
, data
, end
);
1559 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1560 READ_ULEB (uvalue
, data
, end
);
1561 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1564 /* DWARF 4 extensions. */
1565 case DW_OP_stack_value
:
1566 printf ("DW_OP_stack_value");
1569 case DW_OP_implicit_value
:
1570 printf ("DW_OP_implicit_value");
1571 READ_ULEB (uvalue
, data
, end
);
1572 data
= display_block (data
, uvalue
, end
, ' ');
1575 /* GNU extensions. */
1576 case DW_OP_GNU_push_tls_address
:
1577 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1579 case DW_OP_GNU_uninit
:
1580 printf ("DW_OP_GNU_uninit");
1581 /* FIXME: Is there data associated with this OP ? */
1583 case DW_OP_GNU_encoded_addr
:
1590 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1592 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1593 print_dwarf_vma (addr
, pointer_size
);
1596 case DW_OP_implicit_pointer
:
1597 case DW_OP_GNU_implicit_pointer
:
1598 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1599 this ought to be an 8-byte wide computation. */
1600 if (dwarf_version
== -1)
1602 printf (_("(%s in frame info)"),
1603 (op
== DW_OP_implicit_pointer
1604 ? "DW_OP_implicit_pointer"
1605 : "DW_OP_GNU_implicit_pointer"));
1606 /* No way to tell where the next op is, so just bail. */
1607 return need_frame_base
;
1609 if (dwarf_version
== 2)
1611 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1615 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1617 READ_SLEB (svalue
, data
, end
);
1618 printf ("%s: <0x%s> %s",
1619 (op
== DW_OP_implicit_pointer
1620 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1621 dwarf_vmatoa ("x", uvalue
),
1622 dwarf_vmatoa ("d", svalue
));
1624 case DW_OP_entry_value
:
1625 case DW_OP_GNU_entry_value
:
1626 READ_ULEB (uvalue
, data
, end
);
1627 /* PR 17531: file: 0cc9cd00. */
1628 if (uvalue
> (dwarf_vma
) (end
- data
))
1629 uvalue
= end
- data
;
1630 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1631 : "DW_OP_GNU_entry_value"));
1632 if (decode_location_expression (data
, pointer_size
, offset_size
,
1633 dwarf_version
, uvalue
,
1634 cu_offset
, section
))
1635 need_frame_base
= 1;
1639 case DW_OP_const_type
:
1640 case DW_OP_GNU_const_type
:
1641 READ_ULEB (uvalue
, data
, end
);
1642 printf ("%s: <0x%s> ",
1643 (op
== DW_OP_const_type
? "DW_OP_const_type"
1644 : "DW_OP_GNU_const_type"),
1645 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1646 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1647 data
= display_block (data
, uvalue
, end
, ' ');
1649 case DW_OP_regval_type
:
1650 case DW_OP_GNU_regval_type
:
1651 READ_ULEB (uvalue
, data
, end
);
1652 printf ("%s: %s (%s)",
1653 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1654 : "DW_OP_GNU_regval_type"),
1655 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1656 READ_ULEB (uvalue
, data
, end
);
1657 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1659 case DW_OP_deref_type
:
1660 case DW_OP_GNU_deref_type
:
1661 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1663 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1664 : "DW_OP_GNU_deref_type"),
1666 READ_ULEB (uvalue
, data
, end
);
1667 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1670 case DW_OP_GNU_convert
:
1671 READ_ULEB (uvalue
, data
, end
);
1672 printf ("%s <0x%s>",
1673 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1674 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1676 case DW_OP_reinterpret
:
1677 case DW_OP_GNU_reinterpret
:
1678 READ_ULEB (uvalue
, data
, end
);
1679 printf ("%s <0x%s>",
1680 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1681 : "DW_OP_GNU_reinterpret"),
1682 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1684 case DW_OP_GNU_parameter_ref
:
1685 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1686 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1687 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1690 READ_ULEB (uvalue
, data
, end
);
1691 printf ("DW_OP_addrx <0x%s>", dwarf_vmatoa ("x", uvalue
));
1693 case DW_OP_GNU_addr_index
:
1694 READ_ULEB (uvalue
, data
, end
);
1695 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1697 case DW_OP_GNU_const_index
:
1698 READ_ULEB (uvalue
, data
, end
);
1699 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1701 case DW_OP_GNU_variable_value
:
1702 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1703 this ought to be an 8-byte wide computation. */
1704 if (dwarf_version
== -1)
1706 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1707 /* No way to tell where the next op is, so just bail. */
1708 return need_frame_base
;
1710 if (dwarf_version
== 2)
1712 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1716 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1718 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1721 /* HP extensions. */
1722 case DW_OP_HP_is_value
:
1723 printf ("DW_OP_HP_is_value");
1724 /* FIXME: Is there data associated with this OP ? */
1726 case DW_OP_HP_fltconst4
:
1727 printf ("DW_OP_HP_fltconst4");
1728 /* FIXME: Is there data associated with this OP ? */
1730 case DW_OP_HP_fltconst8
:
1731 printf ("DW_OP_HP_fltconst8");
1732 /* FIXME: Is there data associated with this OP ? */
1734 case DW_OP_HP_mod_range
:
1735 printf ("DW_OP_HP_mod_range");
1736 /* FIXME: Is there data associated with this OP ? */
1738 case DW_OP_HP_unmod_range
:
1739 printf ("DW_OP_HP_unmod_range");
1740 /* FIXME: Is there data associated with this OP ? */
1743 printf ("DW_OP_HP_tls");
1744 /* FIXME: Is there data associated with this OP ? */
1747 /* PGI (STMicroelectronics) extensions. */
1748 case DW_OP_PGI_omp_thread_num
:
1749 /* Pushes the thread number for the current thread as it would be
1750 returned by the standard OpenMP library function:
1751 omp_get_thread_num(). The "current thread" is the thread for
1752 which the expression is being evaluated. */
1753 printf ("DW_OP_PGI_omp_thread_num");
1757 if (op
>= DW_OP_lo_user
1758 && op
<= DW_OP_hi_user
)
1759 printf (_("(User defined location op 0x%x)"), op
);
1761 printf (_("(Unknown location op 0x%x)"), op
);
1762 /* No way to tell where the next op is, so just bail. */
1763 return need_frame_base
;
1766 /* Separate the ops. */
1771 return need_frame_base
;
1774 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1775 This is used for DWARF package files. */
1777 static struct cu_tu_set
*
1778 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1780 struct cu_tu_set
*p
;
1782 unsigned int dw_sect
;
1788 dw_sect
= DW_SECT_TYPES
;
1794 dw_sect
= DW_SECT_INFO
;
1798 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1807 fetch_alt_indirect_string (dwarf_vma offset
)
1811 if (! do_follow_links
)
1814 if (first_separate_info
== NULL
)
1815 return _("<no links available>");
1817 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1819 struct dwarf_section
* section
;
1822 if (! load_debug_section (separate_debug_str
, i
->handle
))
1825 section
= &debug_displays
[separate_debug_str
].section
;
1827 if (section
->start
== NULL
)
1830 if (offset
>= section
->size
)
1833 ret
= (const char *) (section
->start
+ offset
);
1834 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1835 NUL byte. Since our caller is expecting to receive a well formed C
1836 string we test for the lack of a terminating byte here. */
1837 if (strnlen ((const char *) ret
, section
->size
- offset
)
1838 == section
->size
- offset
)
1839 return _("<no NUL byte at end of alt .debug_str section>");
1844 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1845 dwarf_vmatoa ("x", offset
));
1846 return _("<offset is too big>");
1850 get_AT_name (unsigned long attribute
)
1855 return "DW_AT value: 0";
1857 /* One value is shared by the MIPS and HP extensions: */
1858 if (attribute
== DW_AT_MIPS_fde
)
1859 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1861 name
= get_DW_AT_name (attribute
);
1865 static char buffer
[100];
1867 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1876 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1878 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1880 dwinfo
->type
= type
;
1881 dwinfo
->value
= value
;
1882 dwinfo
->cu_offset
= cu_offset
;
1883 dwinfo
->next
= first_dwo_info
;
1884 first_dwo_info
= dwinfo
;
1888 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1890 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1894 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1896 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1900 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1902 add_dwo_info (id
, cu_offset
, DWO_ID
);
1906 free_dwo_info (void)
1911 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1913 next
= dwinfo
->next
;
1916 first_dwo_info
= NULL
;
1919 /* Ensure that START + UVALUE is less than END.
1920 Return an adjusted UVALUE if necessary to ensure this relationship. */
1922 static inline dwarf_vma
1923 check_uvalue (const unsigned char * start
,
1925 const unsigned char * end
)
1927 dwarf_vma max_uvalue
= end
- start
;
1929 /* See PR 17512: file: 008-103549-0.001:0.1.
1930 and PR 24829 for examples of where these tests are triggered. */
1931 if (uvalue
> max_uvalue
)
1933 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1934 uvalue
= max_uvalue
;
1940 static unsigned char *
1941 skip_attr_bytes (unsigned long form
,
1942 unsigned char *data
,
1944 dwarf_vma pointer_size
,
1945 dwarf_vma offset_size
,
1947 dwarf_vma
*value_return
)
1949 dwarf_signed_vma svalue
;
1950 dwarf_vma uvalue
= 0;
1957 case DW_FORM_ref_addr
:
1958 if (dwarf_version
== 2)
1959 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1960 else if (dwarf_version
> 2)
1961 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1967 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1971 case DW_FORM_line_strp
:
1972 case DW_FORM_sec_offset
:
1973 case DW_FORM_GNU_ref_alt
:
1974 case DW_FORM_GNU_strp_alt
:
1975 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1978 case DW_FORM_flag_present
:
1986 case DW_FORM_addrx1
:
1987 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1991 case DW_FORM_addrx3
:
1992 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
1998 case DW_FORM_addrx2
:
1999 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2005 case DW_FORM_addrx4
:
2006 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2010 READ_SLEB (svalue
, data
, end
);
2014 case DW_FORM_ref_udata
:
2016 case DW_FORM_GNU_str_index
:
2018 case DW_FORM_GNU_addr_index
:
2020 case DW_FORM_loclistx
:
2021 case DW_FORM_rnglistx
:
2022 READ_ULEB (uvalue
, data
, end
);
2026 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2030 case DW_FORM_ref_sig8
:
2034 case DW_FORM_data16
:
2038 case DW_FORM_string
:
2039 inc
= strnlen ((char *) data
, end
- data
) + 1;
2043 case DW_FORM_exprloc
:
2044 READ_ULEB (uvalue
, data
, end
);
2048 case DW_FORM_block1
:
2049 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2053 case DW_FORM_block2
:
2054 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2058 case DW_FORM_block4
:
2059 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2063 case DW_FORM_indirect
:
2064 READ_ULEB (form
, data
, end
);
2065 if (form
== DW_FORM_implicit_const
)
2066 SKIP_ULEB (data
, end
);
2067 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2068 dwarf_version
, value_return
);
2074 * value_return
= uvalue
;
2075 if (inc
<= (dwarf_vma
) (end
- data
))
2082 /* Given form FORM with value UVALUE, locate and return the abbreviation
2083 associated with it. */
2085 static abbrev_entry
*
2086 get_type_abbrev_from_form (unsigned long form
,
2087 unsigned long uvalue
,
2088 dwarf_vma cu_offset
,
2089 unsigned char *cu_end
,
2090 const struct dwarf_section
*section
,
2091 unsigned long *abbrev_num_return
,
2092 unsigned char **data_return
,
2093 abbrev_map
**map_return
)
2095 unsigned long abbrev_number
;
2097 abbrev_entry
* entry
;
2098 unsigned char * data
;
2100 if (abbrev_num_return
!= NULL
)
2101 * abbrev_num_return
= 0;
2102 if (data_return
!= NULL
)
2103 * data_return
= NULL
;
2107 case DW_FORM_GNU_ref_alt
:
2108 case DW_FORM_ref_sig8
:
2109 /* FIXME: We are unable to handle this form at the moment. */
2112 case DW_FORM_ref_addr
:
2113 if (uvalue
>= section
->size
)
2115 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2116 uvalue
, (long) section
->size
, section
->name
);
2121 case DW_FORM_ref_sup4
:
2122 case DW_FORM_ref_sup8
:
2129 case DW_FORM_ref_udata
:
2130 if (uvalue
+ cu_offset
< uvalue
2131 || uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2133 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > CU size %lx\n"),
2134 uvalue
, (long) cu_offset
, (long) (cu_end
- section
->start
));
2137 uvalue
+= cu_offset
;
2140 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2143 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2147 data
= (unsigned char *) section
->start
+ uvalue
;
2148 map
= find_abbrev_map_by_offset (uvalue
);
2152 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2155 if (map
->list
== NULL
)
2157 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2161 if (map_return
!= NULL
)
2163 if (form
== DW_FORM_ref_addr
)
2169 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2171 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2172 if (entry
->number
== abbrev_number
)
2175 if (abbrev_num_return
!= NULL
)
2176 * abbrev_num_return
= abbrev_number
;
2178 if (data_return
!= NULL
)
2179 * data_return
= data
;
2182 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2187 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2188 can be determined to be a signed type. The data for ENTRY can be
2189 found starting at DATA. */
2192 get_type_signedness (abbrev_entry
*entry
,
2193 const struct dwarf_section
*section
,
2194 unsigned char *data
,
2196 dwarf_vma cu_offset
,
2197 dwarf_vma pointer_size
,
2198 dwarf_vma offset_size
,
2201 unsigned int nesting
)
2205 * is_signed
= false;
2207 #define MAX_NESTING 20
2208 if (nesting
> MAX_NESTING
)
2210 /* FIXME: Warn - or is this expected ?
2211 NB/ We need to avoid infinite recursion. */
2215 for (attr
= entry
->first_attr
;
2216 attr
!= NULL
&& attr
->attribute
;
2219 unsigned char * orig_data
= data
;
2220 dwarf_vma uvalue
= 0;
2222 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2223 offset_size
, dwarf_version
, & uvalue
);
2227 switch (attr
->attribute
)
2229 case DW_AT_linkage_name
:
2233 if (attr
->form
== DW_FORM_strp
)
2234 printf (", %s", fetch_indirect_string (uvalue
));
2235 else if (attr
->form
== DW_FORM_string
)
2236 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2243 abbrev_entry
*type_abbrev
;
2244 unsigned char *type_data
;
2247 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2252 NULL
/* abbrev num return */,
2255 if (type_abbrev
== NULL
)
2258 get_type_signedness (type_abbrev
, section
, type_data
,
2259 map
? section
->start
+ map
->end
: end
,
2260 map
? map
->start
: cu_offset
,
2261 pointer_size
, offset_size
, dwarf_version
,
2262 is_signed
, nesting
+ 1);
2266 case DW_AT_encoding
:
2267 /* Determine signness. */
2270 case DW_ATE_address
:
2271 /* FIXME - some architectures have signed addresses. */
2272 case DW_ATE_boolean
:
2273 case DW_ATE_unsigned
:
2274 case DW_ATE_unsigned_char
:
2275 case DW_ATE_unsigned_fixed
:
2276 * is_signed
= false;
2280 case DW_ATE_complex_float
:
2283 case DW_ATE_signed_char
:
2284 case DW_ATE_imaginary_float
:
2285 case DW_ATE_decimal_float
:
2286 case DW_ATE_signed_fixed
:
2296 read_and_print_leb128 (unsigned char *data
,
2297 unsigned int *bytes_read
,
2298 unsigned const char *end
,
2302 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2304 report_leb_status (status
);
2306 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2310 display_discr_list (unsigned long form
,
2312 unsigned char * data
,
2315 unsigned char *end
= data
;
2319 printf ("[default]");
2326 case DW_FORM_block1
:
2327 case DW_FORM_block2
:
2328 case DW_FORM_block4
:
2329 /* Move data pointer back to the start of the byte array. */
2333 printf ("<corrupt>\n");
2334 warn (_("corrupt discr_list - not using a block form\n"));
2340 printf ("<corrupt>\n");
2341 warn (_("corrupt discr_list - block not long enough\n"));
2345 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2346 ? level_type_signed
[level
- 1] : false);
2351 unsigned char discriminant
;
2352 unsigned int bytes_read
;
2354 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2356 switch (discriminant
)
2360 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2366 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2370 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2375 printf ("<corrupt>\n");
2376 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2386 printf (")(signed)");
2388 printf (")(unsigned)");
2391 static unsigned char *
2392 read_and_display_attr_value (unsigned long attribute
,
2394 dwarf_signed_vma implicit_const
,
2395 unsigned char * start
,
2396 unsigned char * data
,
2397 unsigned char * end
,
2398 dwarf_vma cu_offset
,
2399 dwarf_vma pointer_size
,
2400 dwarf_vma offset_size
,
2402 debug_info
* debug_info_p
,
2404 struct dwarf_section
* section
,
2405 struct cu_tu_set
* this_set
,
2409 dwarf_signed_vma svalue
;
2410 dwarf_vma uvalue
= 0;
2411 dwarf_vma uvalue_hi
= 0;
2412 unsigned char *block_start
= NULL
;
2413 unsigned char *orig_data
= data
;
2415 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2417 warn (_("Corrupt attribute\n"));
2421 if (do_wide
&& ! do_loc
)
2423 /* PR 26847: Display the name of the form. */
2424 const char * name
= get_FORM_name (form
);
2426 /* For convenience we skip the DW_FORM_ prefix to the name. */
2428 name
+= 8; /* strlen ("DW_FORM_") */
2429 printf ("%c(%s)", delimiter
, name
);
2434 case DW_FORM_ref_addr
:
2435 if (dwarf_version
== 2)
2436 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2437 else if (dwarf_version
> 2)
2438 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2440 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2444 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2447 case DW_FORM_strp_sup
:
2449 case DW_FORM_line_strp
:
2450 case DW_FORM_sec_offset
:
2451 case DW_FORM_GNU_ref_alt
:
2452 case DW_FORM_GNU_strp_alt
:
2453 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2456 case DW_FORM_flag_present
:
2464 case DW_FORM_addrx1
:
2465 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2471 case DW_FORM_addrx2
:
2472 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2476 case DW_FORM_addrx3
:
2477 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2480 case DW_FORM_ref_sup4
:
2484 case DW_FORM_addrx4
:
2485 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2488 case DW_FORM_ref_sup8
:
2491 case DW_FORM_ref_sig8
:
2492 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2495 case DW_FORM_data16
:
2496 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2497 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2498 if (byte_get
!= byte_get_little_endian
)
2500 dwarf_vma utmp
= uvalue
;
2507 READ_SLEB (svalue
, data
, end
);
2511 case DW_FORM_GNU_str_index
:
2513 case DW_FORM_ref_udata
:
2515 case DW_FORM_GNU_addr_index
:
2517 case DW_FORM_loclistx
:
2518 case DW_FORM_rnglistx
:
2519 READ_ULEB (uvalue
, data
, end
);
2522 case DW_FORM_indirect
:
2523 READ_ULEB (form
, data
, end
);
2525 printf ("%c%s", delimiter
, get_FORM_name (form
));
2526 if (form
== DW_FORM_implicit_const
)
2527 READ_SLEB (implicit_const
, data
, end
);
2528 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2530 cu_offset
, pointer_size
,
2531 offset_size
, dwarf_version
,
2532 debug_info_p
, do_loc
,
2533 section
, this_set
, delimiter
, level
);
2535 case DW_FORM_implicit_const
:
2536 uvalue
= implicit_const
;
2545 case DW_FORM_ref_addr
:
2547 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2550 case DW_FORM_GNU_ref_alt
:
2554 /* We have already printed the form name. */
2555 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2557 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2559 /* FIXME: Follow the reference... */
2565 case DW_FORM_ref_sup4
:
2566 case DW_FORM_ref_udata
:
2568 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2573 case DW_FORM_sec_offset
:
2575 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2578 case DW_FORM_flag_present
:
2584 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2589 printf ("%c%s", delimiter
, dwarf_vmatoa ("u", uvalue
));
2592 case DW_FORM_implicit_const
:
2594 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2597 case DW_FORM_ref_sup8
:
2602 dwarf_vma utmp
= uvalue
;
2603 if (form
== DW_FORM_ref8
)
2605 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", utmp
));
2609 case DW_FORM_data16
:
2612 uvalue_hi
== 0 ? "" : dwarf_vmatoa ("x", uvalue_hi
),
2613 dwarf_vmatoa_1 ("x", uvalue
, uvalue_hi
== 0 ? 0 : 8));
2616 case DW_FORM_string
:
2618 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2619 data
+= strnlen ((char *) data
, end
- data
);
2625 case DW_FORM_exprloc
:
2626 READ_ULEB (uvalue
, data
, end
);
2629 if (block_start
>= end
)
2631 warn (_("Block ends prematurely\n"));
2636 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2638 data
= block_start
+ uvalue
;
2643 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2644 if (op
!= DW_OP_addrx
)
2645 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2649 case DW_FORM_block1
:
2650 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2653 case DW_FORM_block2
:
2654 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2657 case DW_FORM_block4
:
2658 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2665 /* We have already displayed the form name. */
2666 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2667 dwarf_vmatoa ("x", uvalue
),
2668 fetch_indirect_string (uvalue
));
2670 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2671 dwarf_vmatoa ("x", uvalue
),
2672 fetch_indirect_string (uvalue
));
2676 case DW_FORM_line_strp
:
2680 /* We have already displayed the form name. */
2681 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2682 dwarf_vmatoa ("x", uvalue
),
2683 fetch_indirect_line_string (uvalue
));
2685 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2686 dwarf_vmatoa ("x", uvalue
),
2687 fetch_indirect_line_string (uvalue
));
2691 case DW_FORM_GNU_str_index
:
2699 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2700 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2703 strng
= fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
,
2704 debug_info_p
? debug_info_p
->str_offsets_base
: 0);
2706 /* We have already displayed the form name. */
2707 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2708 dwarf_vmatoa ("x", uvalue
), strng
);
2710 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2711 dwarf_vmatoa ("x", uvalue
), strng
);
2715 case DW_FORM_GNU_strp_alt
:
2719 /* We have already displayed the form name. */
2720 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2721 dwarf_vmatoa ("x", uvalue
),
2722 fetch_alt_indirect_string (uvalue
));
2724 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2725 dwarf_vmatoa ("x", uvalue
),
2726 fetch_alt_indirect_string (uvalue
));
2730 case DW_FORM_indirect
:
2731 /* Handled above. */
2734 case DW_FORM_ref_sig8
:
2736 printf ("%c%s: 0x%s", delimiter
, do_wide
? "" : "signature",
2737 dwarf_vmatoa ("x", uvalue
));
2740 case DW_FORM_GNU_addr_index
:
2742 case DW_FORM_addrx1
:
2743 case DW_FORM_addrx2
:
2744 case DW_FORM_addrx3
:
2745 case DW_FORM_addrx4
:
2746 case DW_FORM_loclistx
:
2747 case DW_FORM_rnglistx
:
2750 dwarf_vma base
, index
;
2751 const char *suffix
= strrchr (section
->name
, '.');
2752 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2754 if (form
== DW_FORM_loclistx
)
2758 index
= fetch_indexed_value (uvalue
, loclists_dwo
, 0);
2759 index
+= (offset_size
== 8) ? 20 : 12;
2761 else if (debug_info_p
== NULL
)
2763 index
= fetch_indexed_value (uvalue
, loclists
, 0);
2767 /* We want to compute:
2768 index = fetch_indexed_value (uvalue, loclists, debug_info_p->loclists_base);
2769 index += debug_info_p->loclists_base;
2770 Fortunately we already have that sum cached in the
2771 loc_offsets array. */
2772 index
= debug_info_p
->loc_offsets
[uvalue
];
2775 else if (form
== DW_FORM_rnglistx
)
2779 index
= fetch_indexed_value (uvalue
, rnglists_dwo
, 0);
2780 index
+= (offset_size
== 8) ? 20 : 12;
2784 if (debug_info_p
== NULL
)
2787 base
= debug_info_p
->rnglists_base
;
2788 /* We do not have a cached value this time, so we perform the
2789 computation manually. */
2790 index
= fetch_indexed_value (uvalue
, rnglists
, base
);
2796 if (debug_info_p
== NULL
)
2798 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2801 base
= debug_info_p
->addr_base
;
2803 base
+= uvalue
* pointer_size
;
2804 index
= fetch_indexed_addr (base
, pointer_size
);
2807 /* We have already displayed the form name. */
2808 printf (_("%c(index: 0x%s): %s"), delimiter
,
2809 dwarf_vmatoa ("x", uvalue
),
2810 dwarf_vmatoa ("x", index
));
2814 case DW_FORM_strp_sup
:
2816 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2820 warn (_("Unrecognized form: 0x%lx\n"), form
);
2821 /* What to do? Consume a byte maybe? */
2826 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
2827 && num_debug_info_entries
== 0
2828 && debug_info_p
!= NULL
)
2832 case DW_AT_loclists_base
:
2833 if (debug_info_p
->loclists_base
)
2834 warn (_("CU @ 0x%s has multiple loclists_base values (0x%s and 0x%s)"),
2835 dwarf_vmatoa ("x", debug_info_p
->cu_offset
),
2836 dwarf_vmatoa ("x", debug_info_p
->loclists_base
),
2837 dwarf_vmatoa ("x", uvalue
));
2838 debug_info_p
->loclists_base
= uvalue
;
2840 case DW_AT_rnglists_base
:
2841 if (debug_info_p
->rnglists_base
)
2842 warn (_("CU @ 0x%s has multiple rnglists_base values (0x%s and 0x%s)"),
2843 dwarf_vmatoa ("x", debug_info_p
->cu_offset
),
2844 dwarf_vmatoa ("x", debug_info_p
->rnglists_base
),
2845 dwarf_vmatoa ("x", uvalue
));
2846 debug_info_p
->rnglists_base
= uvalue
;
2848 case DW_AT_str_offsets_base
:
2849 if (debug_info_p
->str_offsets_base
)
2850 warn (_("CU @ 0x%s has multiple str_offsets_base values (0x%s and 0x%s)"),
2851 dwarf_vmatoa ("x", debug_info_p
->cu_offset
),
2852 dwarf_vmatoa ("x", debug_info_p
->str_offsets_base
),
2853 dwarf_vmatoa ("x", uvalue
));
2854 debug_info_p
->str_offsets_base
= uvalue
;
2857 case DW_AT_frame_base
:
2858 have_frame_base
= 1;
2860 case DW_AT_location
:
2861 case DW_AT_GNU_locviews
:
2862 case DW_AT_string_length
:
2863 case DW_AT_return_addr
:
2864 case DW_AT_data_member_location
:
2865 case DW_AT_vtable_elem_location
:
2867 case DW_AT_static_link
:
2868 case DW_AT_use_location
:
2869 case DW_AT_call_value
:
2870 case DW_AT_GNU_call_site_value
:
2871 case DW_AT_call_data_value
:
2872 case DW_AT_GNU_call_site_data_value
:
2873 case DW_AT_call_target
:
2874 case DW_AT_GNU_call_site_target
:
2875 case DW_AT_call_target_clobbered
:
2876 case DW_AT_GNU_call_site_target_clobbered
:
2877 if ((dwarf_version
< 4
2878 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2879 || form
== DW_FORM_sec_offset
2880 || form
== DW_FORM_loclistx
)
2882 /* Process location list. */
2883 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2884 unsigned int num
= debug_info_p
->num_loc_offsets
;
2886 if (lmax
== 0 || num
>= lmax
)
2889 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2890 xcrealloc (debug_info_p
->loc_offsets
,
2891 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2892 debug_info_p
->loc_views
= (dwarf_vma
*)
2893 xcrealloc (debug_info_p
->loc_views
,
2894 lmax
, sizeof (*debug_info_p
->loc_views
));
2895 debug_info_p
->have_frame_base
= (int *)
2896 xcrealloc (debug_info_p
->have_frame_base
,
2897 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2898 debug_info_p
->max_loc_offsets
= lmax
;
2900 if (form
== DW_FORM_loclistx
)
2901 uvalue
= fetch_indexed_value (num
, loclists
, debug_info_p
->loclists_base
);
2902 else if (this_set
!= NULL
)
2903 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2905 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2906 if (attribute
!= DW_AT_GNU_locviews
)
2908 uvalue
+= debug_info_p
->loclists_base
;
2910 /* Corrupt DWARF info can produce more offsets than views.
2911 See PR 23062 for an example. */
2912 if (debug_info_p
->num_loc_offsets
2913 > debug_info_p
->num_loc_views
)
2914 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2917 debug_info_p
->loc_offsets
[num
] = uvalue
;
2918 debug_info_p
->num_loc_offsets
++;
2923 assert (debug_info_p
->num_loc_views
<= num
);
2924 num
= debug_info_p
->num_loc_views
;
2925 if (num
> debug_info_p
->num_loc_offsets
)
2926 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2929 debug_info_p
->loc_views
[num
] = uvalue
;
2930 debug_info_p
->num_loc_views
++;
2937 if (need_base_address
)
2938 debug_info_p
->base_address
= uvalue
;
2941 case DW_AT_GNU_addr_base
:
2942 case DW_AT_addr_base
:
2943 debug_info_p
->addr_base
= uvalue
;
2946 case DW_AT_GNU_ranges_base
:
2947 debug_info_p
->ranges_base
= uvalue
;
2951 if ((dwarf_version
< 4
2952 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2953 || form
== DW_FORM_sec_offset
2954 || form
== DW_FORM_rnglistx
)
2956 /* Process range list. */
2957 unsigned int lmax
= debug_info_p
->max_range_lists
;
2958 unsigned int num
= debug_info_p
->num_range_lists
;
2960 if (lmax
== 0 || num
>= lmax
)
2963 debug_info_p
->range_lists
= (dwarf_vma
*)
2964 xcrealloc (debug_info_p
->range_lists
,
2965 lmax
, sizeof (*debug_info_p
->range_lists
));
2966 debug_info_p
->max_range_lists
= lmax
;
2969 if (form
== DW_FORM_rnglistx
)
2970 uvalue
= fetch_indexed_value (uvalue
, rnglists
, 0);
2972 debug_info_p
->range_lists
[num
] = uvalue
;
2973 debug_info_p
->num_range_lists
++;
2977 case DW_AT_GNU_dwo_name
:
2978 case DW_AT_dwo_name
:
2983 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2985 case DW_FORM_GNU_strp_alt
:
2986 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2988 case DW_FORM_GNU_str_index
:
2994 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
2995 debug_info_p
->str_offsets_base
),
2998 case DW_FORM_string
:
2999 add_dwo_name ((const char *) orig_data
, cu_offset
);
3002 warn (_("Unsupported form (%s) for attribute %s\n"),
3003 get_FORM_name (form
), get_AT_name (attribute
));
3008 case DW_AT_comp_dir
:
3009 /* FIXME: Also extract a build-id in a CU/TU. */
3014 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
3016 case DW_FORM_GNU_strp_alt
:
3017 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
3019 case DW_FORM_line_strp
:
3020 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
3022 case DW_FORM_GNU_str_index
:
3028 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false,
3029 debug_info_p
->str_offsets_base
),
3032 case DW_FORM_string
:
3033 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3036 warn (_("Unsupported form (%s) for attribute %s\n"),
3037 get_FORM_name (form
), get_AT_name (attribute
));
3042 case DW_AT_GNU_dwo_id
:
3047 /* FIXME: Record the length of the ID as well ? */
3048 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3051 warn (_("Unsupported form (%s) for attribute %s\n"),
3052 get_FORM_name (form
), get_AT_name (attribute
));
3062 if (do_loc
|| attribute
== 0)
3065 /* For some attributes we can display further information. */
3069 if (level
>= 0 && level
< MAX_CU_NESTING
3070 && uvalue
< (size_t) (end
- start
))
3072 bool is_signed
= false;
3073 abbrev_entry
*type_abbrev
;
3074 unsigned char *type_data
;
3077 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3081 if (type_abbrev
!= NULL
)
3083 get_type_signedness (type_abbrev
, section
, type_data
,
3084 map
? section
->start
+ map
->end
: end
,
3085 map
? map
->start
: cu_offset
,
3086 pointer_size
, offset_size
, dwarf_version
,
3089 level_type_signed
[level
] = is_signed
;
3097 case DW_INL_not_inlined
:
3098 printf (_("(not inlined)"));
3100 case DW_INL_inlined
:
3101 printf (_("(inlined)"));
3103 case DW_INL_declared_not_inlined
:
3104 printf (_("(declared as inline but ignored)"));
3106 case DW_INL_declared_inlined
:
3107 printf (_("(declared as inline and inlined)"));
3110 printf (_(" (Unknown inline attribute value: %s)"),
3111 dwarf_vmatoa ("x", uvalue
));
3116 case DW_AT_language
:
3120 /* Ordered by the numeric value of these constants. */
3121 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3122 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3123 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3124 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3125 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3126 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3127 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3128 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3129 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3130 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3131 /* DWARF 2.1 values. */
3132 case DW_LANG_Java
: printf ("(Java)"); break;
3133 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3134 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3135 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3136 /* DWARF 3 values. */
3137 case DW_LANG_PLI
: printf ("(PLI)"); break;
3138 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3139 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3140 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3141 case DW_LANG_D
: printf ("(D)"); break;
3142 /* DWARF 4 values. */
3143 case DW_LANG_Python
: printf ("(Python)"); break;
3144 /* DWARF 5 values. */
3145 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3146 case DW_LANG_Go
: printf ("(Go)"); break;
3147 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3148 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3149 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3150 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3151 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3152 case DW_LANG_Rust
: printf ("(Rust)"); break;
3153 case DW_LANG_C11
: printf ("(C11)"); break;
3154 case DW_LANG_Swift
: printf ("(Swift)"); break;
3155 case DW_LANG_Julia
: printf ("(Julia)"); break;
3156 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3157 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3158 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3159 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3160 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3161 /* MIPS extension. */
3162 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3163 /* UPC extension. */
3164 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3166 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3167 printf (_("(implementation defined: %s)"),
3168 dwarf_vmatoa ("x", uvalue
));
3170 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3175 case DW_AT_encoding
:
3179 case DW_ATE_void
: printf ("(void)"); break;
3180 case DW_ATE_address
: printf ("(machine address)"); break;
3181 case DW_ATE_boolean
: printf ("(boolean)"); break;
3182 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3183 case DW_ATE_float
: printf ("(float)"); break;
3184 case DW_ATE_signed
: printf ("(signed)"); break;
3185 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3186 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3187 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3188 /* DWARF 2.1 values: */
3189 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3190 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3191 /* DWARF 3 values: */
3192 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3193 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3194 case DW_ATE_edited
: printf ("(edited)"); break;
3195 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3196 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3197 /* DWARF 4 values: */
3198 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3199 /* DWARF 5 values: */
3200 case DW_ATE_UCS
: printf ("(UCS)"); break;
3201 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3203 /* HP extensions: */
3204 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3205 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3206 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3207 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3208 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3209 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3210 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3213 if (uvalue
>= DW_ATE_lo_user
3214 && uvalue
<= DW_ATE_hi_user
)
3215 printf (_("(user defined type)"));
3217 printf (_("(unknown type)"));
3222 case DW_AT_accessibility
:
3226 case DW_ACCESS_public
: printf ("(public)"); break;
3227 case DW_ACCESS_protected
: printf ("(protected)"); break;
3228 case DW_ACCESS_private
: printf ("(private)"); break;
3230 printf (_("(unknown accessibility)"));
3235 case DW_AT_visibility
:
3239 case DW_VIS_local
: printf ("(local)"); break;
3240 case DW_VIS_exported
: printf ("(exported)"); break;
3241 case DW_VIS_qualified
: printf ("(qualified)"); break;
3242 default: printf (_("(unknown visibility)")); break;
3246 case DW_AT_endianity
:
3250 case DW_END_default
: printf ("(default)"); break;
3251 case DW_END_big
: printf ("(big)"); break;
3252 case DW_END_little
: printf ("(little)"); break;
3254 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3255 printf (_("(user specified)"));
3257 printf (_("(unknown endianity)"));
3262 case DW_AT_virtuality
:
3266 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3267 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3268 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3269 default: printf (_("(unknown virtuality)")); break;
3273 case DW_AT_identifier_case
:
3277 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3278 case DW_ID_up_case
: printf ("(up_case)"); break;
3279 case DW_ID_down_case
: printf ("(down_case)"); break;
3280 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3281 default: printf (_("(unknown case)")); break;
3285 case DW_AT_calling_convention
:
3289 case DW_CC_normal
: printf ("(normal)"); break;
3290 case DW_CC_program
: printf ("(program)"); break;
3291 case DW_CC_nocall
: printf ("(nocall)"); break;
3292 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3293 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3294 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3295 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3297 if (uvalue
>= DW_CC_lo_user
3298 && uvalue
<= DW_CC_hi_user
)
3299 printf (_("(user defined)"));
3301 printf (_("(unknown convention)"));
3305 case DW_AT_ordering
:
3310 case -1: printf (_("(undefined)")); break;
3311 case 0: printf ("(row major)"); break;
3312 case 1: printf ("(column major)"); break;
3316 case DW_AT_decimal_sign
:
3320 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3321 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3322 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3323 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3324 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3325 default: printf (_("(unrecognised)")); break;
3329 case DW_AT_defaulted
:
3333 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3334 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3335 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3336 default: printf (_("(unrecognised)")); break;
3340 case DW_AT_discr_list
:
3342 display_discr_list (form
, uvalue
, data
, level
);
3345 case DW_AT_frame_base
:
3346 have_frame_base
= 1;
3348 case DW_AT_location
:
3349 case DW_AT_loclists_base
:
3350 case DW_AT_rnglists_base
:
3351 case DW_AT_str_offsets_base
:
3352 case DW_AT_string_length
:
3353 case DW_AT_return_addr
:
3354 case DW_AT_data_member_location
:
3355 case DW_AT_vtable_elem_location
:
3357 case DW_AT_static_link
:
3358 case DW_AT_use_location
:
3359 case DW_AT_call_value
:
3360 case DW_AT_GNU_call_site_value
:
3361 case DW_AT_call_data_value
:
3362 case DW_AT_GNU_call_site_data_value
:
3363 case DW_AT_call_target
:
3364 case DW_AT_GNU_call_site_target
:
3365 case DW_AT_call_target_clobbered
:
3366 case DW_AT_GNU_call_site_target_clobbered
:
3367 if ((dwarf_version
< 4
3368 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3369 || form
== DW_FORM_sec_offset
3370 || form
== DW_FORM_loclistx
)
3372 if (attribute
!= DW_AT_rnglists_base
3373 && attribute
!= DW_AT_str_offsets_base
)
3374 printf (_(" (location list)"));
3377 case DW_AT_allocated
:
3378 case DW_AT_associated
:
3379 case DW_AT_data_location
:
3381 case DW_AT_upper_bound
:
3382 case DW_AT_lower_bound
:
3386 int need_frame_base
;
3389 need_frame_base
= decode_location_expression (block_start
,
3394 cu_offset
, section
);
3396 if (need_frame_base
&& !have_frame_base
)
3397 printf (_(" [without DW_AT_frame_base]"));
3401 case DW_AT_data_bit_offset
:
3402 case DW_AT_byte_size
:
3403 case DW_AT_bit_size
:
3404 case DW_AT_string_length_byte_size
:
3405 case DW_AT_string_length_bit_size
:
3406 case DW_AT_bit_stride
:
3407 if (form
== DW_FORM_exprloc
)
3410 (void) decode_location_expression (block_start
, pointer_size
,
3411 offset_size
, dwarf_version
,
3412 uvalue
, cu_offset
, section
);
3419 unsigned long abbrev_number
;
3420 abbrev_entry
*entry
;
3422 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3423 section
, & abbrev_number
, NULL
, NULL
);
3426 if (form
!= DW_FORM_GNU_ref_alt
)
3427 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3428 dwarf_vmatoa ("x", uvalue
),
3429 (unsigned long) (orig_data
- section
->start
));
3433 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3434 printf (" (%s)", get_TAG_name (entry
->tag
));
3447 static unsigned char *
3448 read_and_display_attr (unsigned long attribute
,
3450 dwarf_signed_vma implicit_const
,
3451 unsigned char * start
,
3452 unsigned char * data
,
3453 unsigned char * end
,
3454 dwarf_vma cu_offset
,
3455 dwarf_vma pointer_size
,
3456 dwarf_vma offset_size
,
3458 debug_info
* debug_info_p
,
3460 struct dwarf_section
* section
,
3461 struct cu_tu_set
* this_set
,
3465 printf (" %-18s:", get_AT_name (attribute
));
3466 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3468 cu_offset
, pointer_size
, offset_size
,
3469 dwarf_version
, debug_info_p
,
3470 do_loc
, section
, this_set
, ' ', level
);
3476 /* Like load_debug_section, but if the ordinary call fails, and we are
3477 following debug links, then attempt to load the requested section
3478 from one of the separate debug info files. */
3481 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3484 if (load_debug_section (sec_enum
, handle
))
3486 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3488 /* See if we can associate a filename with this section. */
3491 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3492 if (i
->handle
== handle
)
3494 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3502 if (do_follow_links
)
3506 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3508 if (load_debug_section (sec_enum
, i
->handle
))
3510 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3512 /* FIXME: We should check to see if any of the remaining debug info
3513 files also contain this section, and, umm, do something about it. */
3523 introduce (struct dwarf_section
* section
, bool raw
)
3527 if (do_follow_links
&& section
->filename
)
3528 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3529 section
->name
, section
->filename
);
3531 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3535 if (do_follow_links
&& section
->filename
)
3536 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3537 section
->name
, section
->filename
);
3539 printf (_("Contents of the %s section:\n\n"), section
->name
);
3543 /* Process the contents of a .debug_info section.
3544 If do_loc is TRUE then we are scanning for location lists and dwo tags
3545 and we do not want to display anything to the user.
3546 If do_types is TRUE, we are processing a .debug_types section instead of
3547 a .debug_info section.
3548 The information displayed is restricted by the values in DWARF_START_DIE
3549 and DWARF_CUTOFF_LEVEL.
3550 Returns TRUE upon success. Otherwise an error or warning message is
3551 printed and FALSE is returned. */
3554 process_debug_info (struct dwarf_section
* section
,
3556 enum dwarf_section_display_enum abbrev_sec
,
3560 unsigned char *start
= section
->start
;
3561 unsigned char *end
= start
+ section
->size
;
3562 unsigned char *section_begin
;
3564 unsigned int num_units
= 0;
3566 /* First scan the section to get the number of comp units.
3567 Length sanity checks are done here. */
3568 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3573 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3574 will be the length. For a 64-bit DWARF section, it'll be
3575 the escape code 0xffffffff followed by an 8 byte length. */
3576 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3578 if (length
== 0xffffffff)
3579 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3580 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3582 warn (_("Reserved length value (0x%s) found in section %s\n"),
3583 dwarf_vmatoa ("x", length
), section
->name
);
3587 /* Negative values are illegal, they may even cause infinite
3588 looping. This can happen if we can't accurately apply
3589 relocations to an object file, or if the file is corrupt. */
3590 if (length
> (size_t) (end
- section_begin
))
3592 warn (_("Corrupt unit length (got 0x%s expected at most 0x%s) in section %s\n"),
3593 dwarf_vmatoa ("x", length
),
3594 dwarf_vmatoa ("x", end
- section_begin
),
3598 section_begin
+= length
;
3603 error (_("No comp units in %s section ?\n"), section
->name
);
3607 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3608 && num_debug_info_entries
== 0
3612 /* Then allocate an array to hold the information. */
3613 debug_information
= (debug_info
*) cmalloc (num_units
,
3614 sizeof (* debug_information
));
3615 if (debug_information
== NULL
)
3617 error (_("Not enough memory for a debug info array of %u entries\n"),
3619 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3623 /* PR 17531: file: 92ca3797.
3624 We cannot rely upon the debug_information array being initialised
3625 before it is used. A corrupt file could easily contain references
3626 to a unit for which information has not been made available. So
3627 we ensure that the array is zeroed here. */
3628 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3630 alloc_num_debug_info_entries
= num_units
;
3635 load_debug_section_with_follow (str
, file
);
3636 load_debug_section_with_follow (line_str
, file
);
3637 load_debug_section_with_follow (str_dwo
, file
);
3638 load_debug_section_with_follow (str_index
, file
);
3639 load_debug_section_with_follow (str_index_dwo
, file
);
3640 load_debug_section_with_follow (debug_addr
, file
);
3643 load_debug_section_with_follow (abbrev_sec
, file
);
3644 load_debug_section_with_follow (loclists
, file
);
3645 load_debug_section_with_follow (rnglists
, file
);
3646 load_debug_section_with_follow (loclists_dwo
, file
);
3647 load_debug_section_with_follow (rnglists_dwo
, file
);
3649 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3651 warn (_("Unable to locate %s section!\n"),
3652 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3656 if (!do_loc
&& dwarf_start_die
== 0)
3657 introduce (section
, false);
3659 free_all_abbrevs ();
3661 /* In order to be able to resolve DW_FORM_ref_addr forms we need
3662 to load *all* of the abbrevs for all CUs in this .debug_info
3663 section. This does effectively mean that we (partially) read
3664 every CU header twice. */
3665 for (section_begin
= start
; start
< end
;)
3667 DWARF2_Internal_CompUnit compunit
;
3668 unsigned char * hdrptr
;
3669 dwarf_vma abbrev_base
;
3671 dwarf_vma cu_offset
;
3672 unsigned int offset_size
;
3673 struct cu_tu_set
* this_set
;
3675 unsigned char *end_cu
;
3678 cu_offset
= start
- section_begin
;
3680 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3682 if (compunit
.cu_length
== 0xffffffff)
3684 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3689 end_cu
= hdrptr
+ compunit
.cu_length
;
3691 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3693 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3695 if (compunit
.cu_version
< 5)
3697 compunit
.cu_unit_type
= DW_UT_compile
;
3698 /* Initialize it due to a false compiler warning. */
3699 compunit
.cu_pointer_size
= -1;
3703 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3704 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3706 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3709 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3712 if (compunit
.cu_unit_type
== DW_UT_split_compile
3713 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3716 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3719 if (this_set
== NULL
)
3722 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3726 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3727 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3730 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3731 compunit
.cu_abbrev_offset
);
3734 unsigned char * next
;
3736 list
= new_abbrev_list (abbrev_base
,
3737 compunit
.cu_abbrev_offset
);
3738 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3739 abbrev_base
, abbrev_size
,
3740 compunit
.cu_abbrev_offset
, list
);
3741 list
->start_of_next_abbrevs
= next
;
3745 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3748 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3750 DWARF2_Internal_CompUnit compunit
;
3751 unsigned char *hdrptr
;
3752 unsigned char *tags
;
3753 int level
, last_level
, saved_level
;
3754 dwarf_vma cu_offset
;
3755 unsigned int offset_size
;
3756 dwarf_vma signature
= 0;
3757 dwarf_vma type_offset
= 0;
3758 struct cu_tu_set
*this_set
;
3759 dwarf_vma abbrev_base
;
3761 abbrev_list
* list
= NULL
;
3762 unsigned char *end_cu
;
3765 cu_offset
= start
- section_begin
;
3767 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3769 if (compunit
.cu_length
== 0xffffffff)
3771 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3776 end_cu
= hdrptr
+ compunit
.cu_length
;
3778 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3780 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3782 if (compunit
.cu_version
< 5)
3784 compunit
.cu_unit_type
= DW_UT_compile
;
3785 /* Initialize it due to a false compiler warning. */
3786 compunit
.cu_pointer_size
= -1;
3790 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3791 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3793 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3796 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3798 if (this_set
== NULL
)
3801 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3805 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3806 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3809 if (compunit
.cu_version
< 5)
3810 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3812 bool do_dwo_id
= false;
3813 uint64_t dwo_id
= 0;
3814 if (compunit
.cu_unit_type
== DW_UT_split_compile
3815 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3817 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3821 /* PR 17512: file: 001-108546-0.001:0.1. */
3822 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3824 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3825 compunit
.cu_pointer_size
, offset_size
);
3826 compunit
.cu_pointer_size
= offset_size
;
3831 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3832 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3835 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3841 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
3842 && num_debug_info_entries
== 0
3843 && alloc_num_debug_info_entries
> unit
3846 debug_information
[unit
].cu_offset
= cu_offset
;
3847 debug_information
[unit
].pointer_size
3848 = compunit
.cu_pointer_size
;
3849 debug_information
[unit
].offset_size
= offset_size
;
3850 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3851 debug_information
[unit
].base_address
= 0;
3852 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3853 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3854 debug_information
[unit
].rnglists_base
= 0;
3855 debug_information
[unit
].loc_offsets
= NULL
;
3856 debug_information
[unit
].have_frame_base
= NULL
;
3857 debug_information
[unit
].max_loc_offsets
= 0;
3858 debug_information
[unit
].num_loc_offsets
= 0;
3859 debug_information
[unit
].loclists_base
= 0;
3860 debug_information
[unit
].range_lists
= NULL
;
3861 debug_information
[unit
].max_range_lists
= 0;
3862 debug_information
[unit
].num_range_lists
= 0;
3863 debug_information
[unit
].rnglists_base
= 0;
3864 debug_information
[unit
].str_offsets_base
= 0;
3867 if (!do_loc
&& dwarf_start_die
== 0)
3869 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3870 dwarf_vmatoa ("x", cu_offset
));
3871 printf (_(" Length: 0x%s (%s)\n"),
3872 dwarf_vmatoa ("x", compunit
.cu_length
),
3873 offset_size
== 8 ? "64-bit" : "32-bit");
3874 printf (_(" Version: %d\n"), compunit
.cu_version
);
3875 if (compunit
.cu_version
>= 5)
3877 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3879 printf (_(" Unit Type: %s (%x)\n"),
3880 name
? name
: "???",
3881 compunit
.cu_unit_type
);
3883 printf (_(" Abbrev Offset: 0x%s\n"),
3884 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3885 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3888 printf (_(" Signature: 0x%s\n"),
3889 dwarf_vmatoa ("x", signature
));
3890 printf (_(" Type Offset: 0x%s\n"),
3891 dwarf_vmatoa ("x", type_offset
));
3894 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3895 if (this_set
!= NULL
)
3897 dwarf_vma
*offsets
= this_set
->section_offsets
;
3898 size_t *sizes
= this_set
->section_sizes
;
3900 printf (_(" Section contributions:\n"));
3901 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3902 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3903 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3904 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3905 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3906 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3907 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3908 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3909 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3910 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3911 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3912 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3919 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3921 warn (_("CU at offset %s contains corrupt or "
3922 "unsupported version number: %d.\n"),
3923 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3927 if (compunit
.cu_unit_type
!= DW_UT_compile
3928 && compunit
.cu_unit_type
!= DW_UT_partial
3929 && compunit
.cu_unit_type
!= DW_UT_type
3930 && compunit
.cu_unit_type
!= DW_UT_split_compile
3931 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3933 warn (_("CU at offset %s contains corrupt or "
3934 "unsupported unit type: %d.\n"),
3935 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3939 /* Process the abbrevs used by this compilation unit. */
3940 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3941 compunit
.cu_abbrev_offset
);
3944 unsigned char *next
;
3946 list
= new_abbrev_list (abbrev_base
,
3947 compunit
.cu_abbrev_offset
);
3948 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3949 abbrev_base
, abbrev_size
,
3950 compunit
.cu_abbrev_offset
, list
);
3951 list
->start_of_next_abbrevs
= next
;
3957 while (tags
< start
)
3959 unsigned long abbrev_number
;
3960 unsigned long die_offset
;
3961 abbrev_entry
*entry
;
3963 int do_printing
= 1;
3965 die_offset
= tags
- section_begin
;
3967 READ_ULEB (abbrev_number
, tags
, start
);
3969 /* A null DIE marks the end of a list of siblings or it may also be
3970 a section padding. */
3971 if (abbrev_number
== 0)
3973 /* Check if it can be a section padding for the last CU. */
3974 if (level
== 0 && start
== end
)
3978 for (chk
= tags
; chk
< start
; chk
++)
3985 if (!do_loc
&& die_offset
>= dwarf_start_die
3986 && (dwarf_cutoff_level
== -1
3987 || level
< dwarf_cutoff_level
))
3988 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3994 static unsigned num_bogus_warns
= 0;
3996 if (num_bogus_warns
< 3)
3998 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3999 die_offset
, section
->name
);
4001 if (num_bogus_warns
== 3)
4002 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
4005 if (dwarf_start_die
!= 0 && level
< saved_level
)
4012 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
4016 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
4017 saved_level
= level
;
4018 do_printing
= (dwarf_cutoff_level
== -1
4019 || level
< dwarf_cutoff_level
);
4021 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
4022 level
, die_offset
, abbrev_number
);
4023 else if (dwarf_cutoff_level
== -1
4024 || last_level
< dwarf_cutoff_level
)
4025 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4030 /* Scan through the abbreviation list until we reach the
4034 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4035 if (entry
->number
== abbrev_number
)
4040 if (!do_loc
&& do_printing
)
4045 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
4046 die_offset
, abbrev_number
);
4050 if (!do_loc
&& do_printing
)
4051 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4056 need_base_address
= 0;
4058 case DW_TAG_compile_unit
:
4059 case DW_TAG_skeleton_unit
:
4060 need_base_address
= 1;
4061 need_dwo_info
= do_loc
;
4063 case DW_TAG_entry_point
:
4064 case DW_TAG_subprogram
:
4065 need_base_address
= 0;
4066 /* Assuming that there is no DW_AT_frame_base. */
4067 have_frame_base
= 0;
4071 debug_info
*debug_info_p
=
4072 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4073 ? debug_information
+ unit
: NULL
;
4075 assert (!debug_info_p
4076 || (debug_info_p
->num_loc_offsets
4077 == debug_info_p
->num_loc_views
));
4079 for (attr
= entry
->first_attr
;
4080 attr
&& attr
->attribute
;
4083 if (! do_loc
&& do_printing
)
4084 /* Show the offset from where the tag was extracted. */
4085 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
4086 tags
= read_and_display_attr (attr
->attribute
,
4088 attr
->implicit_const
,
4093 compunit
.cu_pointer_size
,
4095 compunit
.cu_version
,
4097 do_loc
|| ! do_printing
,
4103 /* If a locview attribute appears before a location one,
4104 make sure we don't associate it with an earlier
4107 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4110 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4111 debug_info_p
->num_loc_views
++;
4112 assert (debug_info_p
->num_loc_views
4113 == debug_info_p
->num_loc_offsets
);
4120 warn(_("DIE has locviews without loclist\n"));
4121 debug_info_p
->num_loc_views
--;
4128 if (entry
->children
)
4133 /* Set num_debug_info_entries here so that it can be used to check if
4134 we need to process .debug_loc and .debug_ranges sections. */
4135 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
|| do_debug_info
)
4136 && num_debug_info_entries
== 0
4139 if (num_units
> alloc_num_debug_info_entries
)
4140 num_debug_info_entries
= alloc_num_debug_info_entries
;
4142 num_debug_info_entries
= num_units
;
4151 /* Locate and scan the .debug_info section in the file and record the pointer
4152 sizes and offsets for the compilation units in it. Usually an executable
4153 will have just one pointer size, but this is not guaranteed, and so we try
4154 not to make any assumptions. Returns zero upon failure, or the number of
4155 compilation units upon success. */
4158 load_debug_info (void * file
)
4160 /* If we have already tried and failed to load the .debug_info
4161 section then do not bother to repeat the task. */
4162 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4165 /* If we already have the information there is nothing else to do. */
4166 if (num_debug_info_entries
> 0)
4167 return num_debug_info_entries
;
4169 /* If this is a DWARF package file, load the CU and TU indexes. */
4170 (void) load_cu_tu_indexes (file
);
4172 if (load_debug_section_with_follow (info
, file
)
4173 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4174 return num_debug_info_entries
;
4176 if (load_debug_section_with_follow (info_dwo
, file
)
4177 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4178 abbrev_dwo
, true, false))
4179 return num_debug_info_entries
;
4181 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4185 /* Read a DWARF .debug_line section header starting at DATA.
4186 Upon success returns an updated DATA pointer and the LINFO
4187 structure and the END_OF_SEQUENCE pointer will be filled in.
4188 Otherwise returns NULL. */
4190 static unsigned char *
4191 read_debug_line_header (struct dwarf_section
* section
,
4192 unsigned char * data
,
4193 unsigned char * end
,
4194 DWARF2_Internal_LineInfo
* linfo
,
4195 unsigned char ** end_of_sequence
)
4197 unsigned char *hdrptr
;
4199 /* Extract information from the Line Number Program Header.
4200 (section 6.2.4 in the Dwarf3 doc). */
4203 /* Get and check the length of the block. */
4204 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4206 if (linfo
->li_length
== 0xffffffff)
4208 /* This section is 64-bit DWARF 3. */
4209 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4210 linfo
->li_offset_size
= 8;
4213 linfo
->li_offset_size
= 4;
4215 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4217 /* If the length field has a relocation against it, then we should
4218 not complain if it is inaccurate (and probably negative). This
4219 happens in object files when the .debug_line section is actually
4220 comprised of several different .debug_line.* sections, (some of
4221 which may be removed by linker garbage collection), and a relocation
4222 is used to compute the correct length once that is done. */
4223 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4225 linfo
->li_length
= end
- hdrptr
;
4229 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4230 (long) linfo
->li_length
);
4234 end
= hdrptr
+ linfo
->li_length
;
4236 /* Get and check the version number. */
4237 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4239 if (linfo
->li_version
!= 2
4240 && linfo
->li_version
!= 3
4241 && linfo
->li_version
!= 4
4242 && linfo
->li_version
!= 5)
4244 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4245 "is currently supported.\n"));
4249 if (linfo
->li_version
>= 5)
4251 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4253 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4254 if (linfo
->li_segment_size
!= 0)
4256 warn (_("The %s section contains "
4257 "unsupported segment selector size: %d.\n"),
4258 section
->name
, linfo
->li_segment_size
);
4263 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4264 linfo
->li_offset_size
, end
);
4265 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4267 if (linfo
->li_version
>= 4)
4269 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4271 if (linfo
->li_max_ops_per_insn
== 0)
4273 warn (_("Invalid maximum operations per insn.\n"));
4278 linfo
->li_max_ops_per_insn
= 1;
4280 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4281 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4282 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4283 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4285 *end_of_sequence
= end
;
4289 static unsigned char *
4290 display_formatted_table (unsigned char *data
,
4291 unsigned char *start
,
4293 const DWARF2_Internal_LineInfo
*linfo
,
4294 struct dwarf_section
*section
,
4297 unsigned char *format_start
, format_count
, *format
, formati
;
4298 dwarf_vma data_count
, datai
;
4299 unsigned int namepass
, last_entry
= 0;
4300 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4302 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4303 if (do_checks
&& format_count
> 5)
4304 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4305 table_name
, format_count
);
4307 format_start
= data
;
4308 for (formati
= 0; formati
< format_count
; formati
++)
4310 SKIP_ULEB (data
, end
);
4311 SKIP_ULEB (data
, end
);
4314 warn (_("%s: Corrupt format description entry\n"), table_name
);
4319 READ_ULEB (data_count
, data
, end
);
4320 if (data_count
== 0)
4322 printf (_("\n The %s is empty.\n"), table_name
);
4325 else if (data
>= end
)
4327 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4328 table_name
, dwarf_vmatoa ("x", data_count
));
4332 else if (format_count
== 0)
4334 warn (_("%s: format count is zero, but the table is not empty\n"),
4339 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4340 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4343 printf (_(" Entry"));
4344 /* Delay displaying name as the last entry for better screen layout. */
4345 for (namepass
= 0; namepass
< 2; namepass
++)
4347 format
= format_start
;
4348 for (formati
= 0; formati
< format_count
; formati
++)
4350 dwarf_vma content_type
;
4352 READ_ULEB (content_type
, format
, end
);
4353 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4354 switch (content_type
)
4357 printf (_("\tName"));
4359 case DW_LNCT_directory_index
:
4360 printf (_("\tDir"));
4362 case DW_LNCT_timestamp
:
4363 printf (_("\tTime"));
4366 printf (_("\tSize"));
4369 printf (_("\tMD5\t\t\t"));
4372 printf (_("\t(Unknown format content type %s)"),
4373 dwarf_vmatoa ("u", content_type
));
4375 SKIP_ULEB (format
, end
);
4380 for (datai
= 0; datai
< data_count
; datai
++)
4382 unsigned char *datapass
= data
;
4384 printf (" %d", last_entry
++);
4385 /* Delay displaying name as the last entry for better screen layout. */
4386 for (namepass
= 0; namepass
< 2; namepass
++)
4388 format
= format_start
;
4390 for (formati
= 0; formati
< format_count
; formati
++)
4392 dwarf_vma content_type
, form
;
4394 READ_ULEB (content_type
, format
, end
);
4395 READ_ULEB (form
, format
, end
);
4396 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4397 0, 0, linfo
->li_offset_size
,
4398 linfo
->li_version
, NULL
,
4399 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4400 section
, NULL
, '\t', -1);
4404 if (data
>= end
&& (datai
< data_count
- 1))
4406 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4415 display_debug_sup (struct dwarf_section
* section
,
4416 void * file ATTRIBUTE_UNUSED
)
4418 unsigned char * start
= section
->start
;
4419 unsigned char * end
= section
->start
+ section
->size
;
4420 unsigned int version
;
4421 char is_supplementary
;
4422 const unsigned char * sup_filename
;
4423 size_t sup_filename_len
;
4424 unsigned int num_read
;
4426 dwarf_vma checksum_len
;
4429 introduce (section
, true);
4430 if (section
->size
< 4)
4432 error (_("corrupt .debug_sup section: size is too small\n"));
4436 /* Read the data. */
4437 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4439 warn (_("corrupt .debug_sup section: version < 5"));
4441 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4442 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4443 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4445 sup_filename
= start
;
4446 if (is_supplementary
&& sup_filename
[0] != 0)
4447 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4449 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4450 if (sup_filename_len
== (size_t) (end
- start
))
4452 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4455 start
+= sup_filename_len
+ 1;
4457 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4460 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4464 if (checksum_len
> (dwarf_vma
) (end
- start
))
4466 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4467 checksum_len
= end
- start
;
4469 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4471 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4472 (long) ((end
- start
) - checksum_len
));
4475 printf (_(" Version: %u\n"), version
);
4476 printf (_(" Is Supp: %u\n"), is_supplementary
);
4477 printf (_(" Filename: %s\n"), sup_filename
);
4478 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4479 if (checksum_len
> 0)
4481 printf (_(" Checksum: "));
4482 while (checksum_len
--)
4483 printf ("0x%x ", * start
++ );
4490 display_debug_lines_raw (struct dwarf_section
* section
,
4491 unsigned char * data
,
4492 unsigned char * end
,
4495 unsigned char *start
= section
->start
;
4496 int verbose_view
= 0;
4498 introduce (section
, true);
4502 static DWARF2_Internal_LineInfo saved_linfo
;
4503 DWARF2_Internal_LineInfo linfo
;
4504 unsigned char *standard_opcodes
;
4505 unsigned char *end_of_sequence
;
4508 if (startswith (section
->name
, ".debug_line.")
4509 /* Note: the following does not apply to .debug_line.dwo sections.
4510 These are full debug_line sections. */
4511 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4513 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4514 section containing just the Line Number Statements. They are
4515 created by the assembler and intended to be used alongside gcc's
4516 -ffunction-sections command line option. When the linker's
4517 garbage collection decides to discard a .text.<foo> section it
4518 can then also discard the line number information in .debug_line.<foo>.
4520 Since the section is a fragment it does not have the details
4521 needed to fill out a LineInfo structure, so instead we use the
4522 details from the last full debug_line section that we processed. */
4523 end_of_sequence
= end
;
4524 standard_opcodes
= NULL
;
4525 linfo
= saved_linfo
;
4526 /* PR 17531: file: 0522b371. */
4527 if (linfo
.li_line_range
== 0)
4529 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4532 reset_state_machine (linfo
.li_default_is_stmt
);
4536 unsigned char * hdrptr
;
4538 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4539 & end_of_sequence
)) == NULL
)
4542 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4543 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4544 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4545 if (linfo
.li_version
>= 5)
4547 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4548 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4550 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4551 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4552 if (linfo
.li_version
>= 4)
4553 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4554 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4555 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4556 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4557 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4559 /* PR 17512: file: 1665-6428-0.004. */
4560 if (linfo
.li_line_range
== 0)
4562 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4563 linfo
.li_line_range
= 1;
4566 reset_state_machine (linfo
.li_default_is_stmt
);
4568 /* Display the contents of the Opcodes table. */
4569 standard_opcodes
= hdrptr
;
4571 /* PR 17512: file: 002-417945-0.004. */
4572 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4574 warn (_("Line Base extends beyond end of section\n"));
4578 printf (_("\n Opcodes:\n"));
4580 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4581 printf (ngettext (" Opcode %d has %d arg\n",
4582 " Opcode %d has %d args\n",
4583 standard_opcodes
[i
- 1]),
4584 i
, standard_opcodes
[i
- 1]);
4586 /* Display the contents of the Directory table. */
4587 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4589 if (linfo
.li_version
>= 5)
4591 load_debug_section_with_follow (line_str
, file
);
4593 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4595 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4601 printf (_("\n The Directory Table is empty.\n"));
4604 unsigned int last_dir_entry
= 0;
4606 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4607 (long)(data
- start
));
4609 while (data
< end
&& *data
!= 0)
4611 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4613 data
+= strnlen ((char *) data
, end
- data
);
4618 /* PR 17512: file: 002-132094-0.004. */
4619 if (data
>= end
- 1)
4623 /* Skip the NUL at the end of the table. */
4627 /* Display the contents of the File Name table. */
4628 if (data
>= end
|| *data
== 0)
4629 printf (_("\n The File Name Table is empty.\n"));
4632 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4633 (long)(data
- start
));
4634 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4636 while (data
< end
&& *data
!= 0)
4638 unsigned char *name
;
4641 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4643 data
+= strnlen ((char *) data
, end
- data
);
4647 READ_ULEB (val
, data
, end
);
4648 printf ("%s\t", dwarf_vmatoa ("u", val
));
4649 READ_ULEB (val
, data
, end
);
4650 printf ("%s\t", dwarf_vmatoa ("u", val
));
4651 READ_ULEB (val
, data
, end
);
4652 printf ("%s\t", dwarf_vmatoa ("u", val
));
4653 printf ("%.*s\n", (int)(end
- name
), name
);
4657 warn (_("Corrupt file name table entry\n"));
4663 /* Skip the NUL at the end of the table. */
4669 saved_linfo
= linfo
;
4672 /* Now display the statements. */
4673 if (data
>= end_of_sequence
)
4674 printf (_(" No Line Number Statements.\n"));
4677 printf (_(" Line Number Statements:\n"));
4679 while (data
< end_of_sequence
)
4681 unsigned char op_code
;
4682 dwarf_signed_vma adv
;
4685 printf (" [0x%08lx]", (long)(data
- start
));
4689 if (op_code
>= linfo
.li_opcode_base
)
4691 op_code
-= linfo
.li_opcode_base
;
4692 uladv
= (op_code
/ linfo
.li_line_range
);
4693 if (linfo
.li_max_ops_per_insn
== 1)
4695 uladv
*= linfo
.li_min_insn_length
;
4696 state_machine_regs
.address
+= uladv
;
4698 state_machine_regs
.view
= 0;
4699 printf (_(" Special opcode %d: "
4700 "advance Address by %s to 0x%s%s"),
4701 op_code
, dwarf_vmatoa ("u", uladv
),
4702 dwarf_vmatoa ("x", state_machine_regs
.address
),
4703 verbose_view
&& uladv
4704 ? _(" (reset view)") : "");
4709 = ((state_machine_regs
.op_index
+ uladv
)
4710 / linfo
.li_max_ops_per_insn
)
4711 * linfo
.li_min_insn_length
;
4713 state_machine_regs
.address
+= addrdelta
;
4714 state_machine_regs
.op_index
4715 = (state_machine_regs
.op_index
+ uladv
)
4716 % linfo
.li_max_ops_per_insn
;
4718 state_machine_regs
.view
= 0;
4719 printf (_(" Special opcode %d: "
4720 "advance Address by %s to 0x%s[%d]%s"),
4721 op_code
, dwarf_vmatoa ("u", uladv
),
4722 dwarf_vmatoa ("x", state_machine_regs
.address
),
4723 state_machine_regs
.op_index
,
4724 verbose_view
&& addrdelta
4725 ? _(" (reset view)") : "");
4727 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4728 state_machine_regs
.line
+= adv
;
4729 printf (_(" and Line by %s to %d"),
4730 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4731 if (verbose_view
|| state_machine_regs
.view
)
4732 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4735 state_machine_regs
.view
++;
4740 case DW_LNS_extended_op
:
4741 data
+= process_extended_line_op (data
,
4742 linfo
.li_default_is_stmt
,
4747 printf (_(" Copy"));
4748 if (verbose_view
|| state_machine_regs
.view
)
4749 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4752 state_machine_regs
.view
++;
4755 case DW_LNS_advance_pc
:
4756 READ_ULEB (uladv
, data
, end
);
4757 if (linfo
.li_max_ops_per_insn
== 1)
4759 uladv
*= linfo
.li_min_insn_length
;
4760 state_machine_regs
.address
+= uladv
;
4762 state_machine_regs
.view
= 0;
4763 printf (_(" Advance PC by %s to 0x%s%s\n"),
4764 dwarf_vmatoa ("u", uladv
),
4765 dwarf_vmatoa ("x", state_machine_regs
.address
),
4766 verbose_view
&& uladv
4767 ? _(" (reset view)") : "");
4772 = ((state_machine_regs
.op_index
+ uladv
)
4773 / linfo
.li_max_ops_per_insn
)
4774 * linfo
.li_min_insn_length
;
4775 state_machine_regs
.address
4777 state_machine_regs
.op_index
4778 = (state_machine_regs
.op_index
+ uladv
)
4779 % linfo
.li_max_ops_per_insn
;
4781 state_machine_regs
.view
= 0;
4782 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4783 dwarf_vmatoa ("u", uladv
),
4784 dwarf_vmatoa ("x", state_machine_regs
.address
),
4785 state_machine_regs
.op_index
,
4786 verbose_view
&& addrdelta
4787 ? _(" (reset view)") : "");
4791 case DW_LNS_advance_line
:
4792 READ_SLEB (adv
, data
, end
);
4793 state_machine_regs
.line
+= adv
;
4794 printf (_(" Advance Line by %s to %d\n"),
4795 dwarf_vmatoa ("d", adv
),
4796 state_machine_regs
.line
);
4799 case DW_LNS_set_file
:
4800 READ_ULEB (uladv
, data
, end
);
4801 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4802 dwarf_vmatoa ("u", uladv
));
4803 state_machine_regs
.file
= uladv
;
4806 case DW_LNS_set_column
:
4807 READ_ULEB (uladv
, data
, end
);
4808 printf (_(" Set column to %s\n"),
4809 dwarf_vmatoa ("u", uladv
));
4810 state_machine_regs
.column
= uladv
;
4813 case DW_LNS_negate_stmt
:
4814 adv
= state_machine_regs
.is_stmt
;
4816 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4817 state_machine_regs
.is_stmt
= adv
;
4820 case DW_LNS_set_basic_block
:
4821 printf (_(" Set basic block\n"));
4822 state_machine_regs
.basic_block
= 1;
4825 case DW_LNS_const_add_pc
:
4826 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4827 if (linfo
.li_max_ops_per_insn
)
4829 uladv
*= linfo
.li_min_insn_length
;
4830 state_machine_regs
.address
+= uladv
;
4832 state_machine_regs
.view
= 0;
4833 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4834 dwarf_vmatoa ("u", uladv
),
4835 dwarf_vmatoa ("x", state_machine_regs
.address
),
4836 verbose_view
&& uladv
4837 ? _(" (reset view)") : "");
4842 = ((state_machine_regs
.op_index
+ uladv
)
4843 / linfo
.li_max_ops_per_insn
)
4844 * linfo
.li_min_insn_length
;
4845 state_machine_regs
.address
4847 state_machine_regs
.op_index
4848 = (state_machine_regs
.op_index
+ uladv
)
4849 % linfo
.li_max_ops_per_insn
;
4851 state_machine_regs
.view
= 0;
4852 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4853 dwarf_vmatoa ("u", uladv
),
4854 dwarf_vmatoa ("x", state_machine_regs
.address
),
4855 state_machine_regs
.op_index
,
4856 verbose_view
&& addrdelta
4857 ? _(" (reset view)") : "");
4861 case DW_LNS_fixed_advance_pc
:
4862 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4863 state_machine_regs
.address
+= uladv
;
4864 state_machine_regs
.op_index
= 0;
4865 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4866 dwarf_vmatoa ("u", uladv
),
4867 dwarf_vmatoa ("x", state_machine_regs
.address
));
4868 /* Do NOT reset view. */
4871 case DW_LNS_set_prologue_end
:
4872 printf (_(" Set prologue_end to true\n"));
4875 case DW_LNS_set_epilogue_begin
:
4876 printf (_(" Set epilogue_begin to true\n"));
4879 case DW_LNS_set_isa
:
4880 READ_ULEB (uladv
, data
, end
);
4881 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4885 printf (_(" Unknown opcode %d with operands: "), op_code
);
4887 if (standard_opcodes
!= NULL
)
4888 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4890 READ_ULEB (uladv
, data
, end
);
4891 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4892 i
== 1 ? "" : ", ");
4907 unsigned char *name
;
4908 unsigned int directory_index
;
4909 unsigned int modification_date
;
4910 unsigned int length
;
4913 /* Output a decoded representation of the .debug_line section. */
4916 display_debug_lines_decoded (struct dwarf_section
* section
,
4917 unsigned char * start
,
4918 unsigned char * data
,
4919 unsigned char * end
,
4922 static DWARF2_Internal_LineInfo saved_linfo
;
4924 introduce (section
, false);
4928 /* This loop amounts to one iteration per compilation unit. */
4929 DWARF2_Internal_LineInfo linfo
;
4930 unsigned char *standard_opcodes
;
4931 unsigned char *end_of_sequence
;
4933 File_Entry
*file_table
= NULL
;
4934 unsigned int n_files
= 0;
4935 unsigned char **directory_table
= NULL
;
4936 dwarf_vma n_directories
= 0;
4938 if (startswith (section
->name
, ".debug_line.")
4939 /* Note: the following does not apply to .debug_line.dwo sections.
4940 These are full debug_line sections. */
4941 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4943 /* See comment in display_debug_lines_raw(). */
4944 end_of_sequence
= end
;
4945 standard_opcodes
= NULL
;
4946 linfo
= saved_linfo
;
4947 /* PR 17531: file: 0522b371. */
4948 if (linfo
.li_line_range
== 0)
4950 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4953 reset_state_machine (linfo
.li_default_is_stmt
);
4957 unsigned char *hdrptr
;
4959 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4960 & end_of_sequence
)) == NULL
)
4963 /* PR 17531: file: 0522b371. */
4964 if (linfo
.li_line_range
== 0)
4966 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4967 linfo
.li_line_range
= 1;
4969 reset_state_machine (linfo
.li_default_is_stmt
);
4971 /* Save a pointer to the contents of the Opcodes table. */
4972 standard_opcodes
= hdrptr
;
4974 /* Traverse the Directory table just to count entries. */
4975 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4979 warn (_("opcode base of %d extends beyond end of section\n"),
4980 linfo
.li_opcode_base
);
4984 if (linfo
.li_version
>= 5)
4986 unsigned char *format_start
, format_count
, *format
;
4987 dwarf_vma formati
, entryi
;
4989 load_debug_section_with_follow (line_str
, fileptr
);
4991 /* Skip directories format. */
4992 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4993 if (do_checks
&& format_count
> 1)
4994 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4996 format_start
= data
;
4997 for (formati
= 0; formati
< format_count
; formati
++)
4999 SKIP_ULEB (data
, end
);
5000 SKIP_ULEB (data
, end
);
5003 READ_ULEB (n_directories
, data
, end
);
5006 warn (_("Corrupt directories list\n"));
5010 if (n_directories
== 0)
5011 directory_table
= NULL
;
5013 directory_table
= (unsigned char **)
5014 xmalloc (n_directories
* sizeof (unsigned char *));
5016 for (entryi
= 0; entryi
< n_directories
; entryi
++)
5018 unsigned char **pathp
= &directory_table
[entryi
];
5020 format
= format_start
;
5021 for (formati
= 0; formati
< format_count
; formati
++)
5023 dwarf_vma content_type
, form
;
5026 READ_ULEB (content_type
, format
, end
);
5027 READ_ULEB (form
, format
, end
);
5030 warn (_("Corrupt directories list\n"));
5033 switch (content_type
)
5038 case DW_FORM_string
:
5041 case DW_FORM_line_strp
:
5042 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5044 /* Remove const by the cast. */
5045 *pathp
= (unsigned char *)
5046 fetch_indirect_line_string (uvalue
);
5051 data
= read_and_display_attr_value (0, form
, 0, start
,
5053 linfo
.li_offset_size
,
5060 warn (_("Corrupt directories list\n"));
5065 /* Skip files format. */
5066 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5067 if (do_checks
&& format_count
> 5)
5068 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5070 format_start
= data
;
5071 for (formati
= 0; formati
< format_count
; formati
++)
5073 SKIP_ULEB (data
, end
);
5074 SKIP_ULEB (data
, end
);
5077 READ_ULEB (n_files
, data
, end
);
5078 if (data
>= end
&& n_files
> 0)
5080 warn (_("Corrupt file name list\n"));
5087 file_table
= (File_Entry
*) xcalloc (1, n_files
5088 * sizeof (File_Entry
));
5090 for (entryi
= 0; entryi
< n_files
; entryi
++)
5092 File_Entry
*file
= &file_table
[entryi
];
5094 format
= format_start
;
5095 for (formati
= 0; formati
< format_count
; formati
++)
5097 dwarf_vma content_type
, form
;
5101 READ_ULEB (content_type
, format
, end
);
5102 READ_ULEB (form
, format
, end
);
5105 warn (_("Corrupt file name list\n"));
5108 switch (content_type
)
5113 case DW_FORM_string
:
5116 case DW_FORM_line_strp
:
5117 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5119 /* Remove const by the cast. */
5120 file
->name
= (unsigned char *)
5121 fetch_indirect_line_string (uvalue
);
5125 case DW_LNCT_directory_index
:
5129 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5133 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5138 READ_ULEB (file
->directory_index
, tmp
, end
);
5143 data
= read_and_display_attr_value (0, form
, 0, start
,
5145 linfo
.li_offset_size
,
5152 warn (_("Corrupt file name list\n"));
5161 unsigned char *ptr_directory_table
= data
;
5163 while (data
< end
&& *data
!= 0)
5165 data
+= strnlen ((char *) data
, end
- data
);
5174 warn (_("directory table ends unexpectedly\n"));
5179 /* Go through the directory table again to save the directories. */
5180 directory_table
= (unsigned char **)
5181 xmalloc (n_directories
* sizeof (unsigned char *));
5184 while (*ptr_directory_table
!= 0)
5186 directory_table
[i
] = ptr_directory_table
;
5188 += strlen ((char *) ptr_directory_table
) + 1;
5192 /* Skip the NUL at the end of the table. */
5195 /* Traverse the File Name table just to count the entries. */
5196 if (data
< end
&& *data
!= 0)
5198 unsigned char *ptr_file_name_table
= data
;
5200 while (data
< end
&& *data
!= 0)
5202 /* Skip Name, directory index, last modification
5203 time and length of file. */
5204 data
+= strnlen ((char *) data
, end
- data
);
5207 SKIP_ULEB (data
, end
);
5208 SKIP_ULEB (data
, end
);
5209 SKIP_ULEB (data
, end
);
5215 warn (_("file table ends unexpectedly\n"));
5220 /* Go through the file table again to save the strings. */
5221 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5224 while (*ptr_file_name_table
!= 0)
5226 file_table
[i
].name
= ptr_file_name_table
;
5228 += strlen ((char *) ptr_file_name_table
) + 1;
5230 /* We are not interested in directory, time or size. */
5231 READ_ULEB (file_table
[i
].directory_index
,
5232 ptr_file_name_table
, end
);
5233 READ_ULEB (file_table
[i
].modification_date
,
5234 ptr_file_name_table
, end
);
5235 READ_ULEB (file_table
[i
].length
,
5236 ptr_file_name_table
, end
);
5242 /* Skip the NUL at the end of the table. */
5246 /* Print the Compilation Unit's name and a header. */
5247 if (file_table
== NULL
)
5248 printf (_("CU: No directory table\n"));
5249 else if (directory_table
== NULL
)
5250 printf (_("CU: %s:\n"), file_table
[0].name
);
5253 unsigned int ix
= file_table
[0].directory_index
;
5254 const char *directory
;
5259 else if (n_directories
== 0)
5260 directory
= _("<unknown>");
5261 else if (ix
> n_directories
)
5263 warn (_("directory index %u > number of directories %s\n"),
5264 ix
, dwarf_vmatoa ("u", n_directories
));
5265 directory
= _("<corrupt>");
5268 directory
= (char *) directory_table
[ix
- 1];
5271 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5273 printf ("%s:\n", file_table
[0].name
);
5277 printf (_("File name Line number Starting address View Stmt\n"));
5279 printf (_("CU: Empty file name table\n"));
5280 saved_linfo
= linfo
;
5283 /* This loop iterates through the Dwarf Line Number Program. */
5284 while (data
< end_of_sequence
)
5286 unsigned char op_code
;
5289 unsigned long int uladv
;
5290 int is_special_opcode
= 0;
5295 if (op_code
>= linfo
.li_opcode_base
)
5297 op_code
-= linfo
.li_opcode_base
;
5298 uladv
= (op_code
/ linfo
.li_line_range
);
5299 if (linfo
.li_max_ops_per_insn
== 1)
5301 uladv
*= linfo
.li_min_insn_length
;
5302 state_machine_regs
.address
+= uladv
;
5304 state_machine_regs
.view
= 0;
5309 = ((state_machine_regs
.op_index
+ uladv
)
5310 / linfo
.li_max_ops_per_insn
)
5311 * linfo
.li_min_insn_length
;
5312 state_machine_regs
.address
5314 state_machine_regs
.op_index
5315 = (state_machine_regs
.op_index
+ uladv
)
5316 % linfo
.li_max_ops_per_insn
;
5318 state_machine_regs
.view
= 0;
5321 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5322 state_machine_regs
.line
+= adv
;
5323 is_special_opcode
= 1;
5324 /* Increment view after printing this row. */
5329 case DW_LNS_extended_op
:
5331 unsigned int ext_op_code_len
;
5332 unsigned char ext_op_code
;
5333 unsigned char *op_code_end
;
5334 unsigned char *op_code_data
= data
;
5336 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5337 op_code_end
= op_code_data
+ ext_op_code_len
;
5338 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5340 warn (_("Badly formed extended line op encountered!\n"));
5343 ext_op_code
= *op_code_data
++;
5347 switch (ext_op_code
)
5349 case DW_LNE_end_sequence
:
5350 /* Reset stuff after printing this row. */
5352 case DW_LNE_set_address
:
5353 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5355 op_code_end
- op_code_data
,
5357 state_machine_regs
.op_index
= 0;
5358 state_machine_regs
.view
= 0;
5360 case DW_LNE_define_file
:
5361 file_table
= (File_Entry
*) xrealloc
5362 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5364 ++state_machine_regs
.last_file_entry
;
5365 /* Source file name. */
5366 file_table
[n_files
].name
= op_code_data
;
5367 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5368 /* Directory index. */
5369 READ_ULEB (file_table
[n_files
].directory_index
,
5370 op_code_data
, op_code_end
);
5371 /* Last modification time. */
5372 READ_ULEB (file_table
[n_files
].modification_date
,
5373 op_code_data
, op_code_end
);
5375 READ_ULEB (file_table
[n_files
].length
,
5376 op_code_data
, op_code_end
);
5380 case DW_LNE_set_discriminator
:
5381 case DW_LNE_HP_set_sequence
:
5382 /* Simply ignored. */
5386 printf (_("UNKNOWN (%u): length %ld\n"),
5387 ext_op_code
, (long int) (op_code_data
- data
));
5394 /* Increment view after printing this row. */
5397 case DW_LNS_advance_pc
:
5398 READ_ULEB (uladv
, data
, end
);
5399 if (linfo
.li_max_ops_per_insn
== 1)
5401 uladv
*= linfo
.li_min_insn_length
;
5402 state_machine_regs
.address
+= uladv
;
5404 state_machine_regs
.view
= 0;
5409 = ((state_machine_regs
.op_index
+ uladv
)
5410 / linfo
.li_max_ops_per_insn
)
5411 * linfo
.li_min_insn_length
;
5412 state_machine_regs
.address
5414 state_machine_regs
.op_index
5415 = (state_machine_regs
.op_index
+ uladv
)
5416 % linfo
.li_max_ops_per_insn
;
5418 state_machine_regs
.view
= 0;
5422 case DW_LNS_advance_line
:
5423 READ_SLEB (adv
, data
, end
);
5424 state_machine_regs
.line
+= adv
;
5427 case DW_LNS_set_file
:
5428 READ_ULEB (uladv
, data
, end
);
5429 state_machine_regs
.file
= uladv
;
5432 unsigned file
= state_machine_regs
.file
;
5435 if (linfo
.li_version
< 5)
5437 if (file_table
== NULL
|| n_files
== 0)
5438 printf (_("\n [Use file table entry %d]\n"), file
);
5440 else if (file
>= n_files
)
5442 warn (_("file index %u > number of files %u\n"), file
, n_files
);
5443 printf (_("\n <over large file table index %u>"), file
);
5445 else if ((dir
= file_table
[file
].directory_index
) == 0)
5446 /* If directory index is 0, that means current directory. */
5447 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5448 else if (directory_table
== NULL
|| n_directories
== 0)
5449 printf (_("\n [Use file %s in directory table entry %d]\n"),
5450 file_table
[file
].name
, dir
);
5452 else if (dir
> n_directories
)
5454 warn (_("directory index %u > number of directories %s\n"),
5455 dir
, dwarf_vmatoa ("u", n_directories
));
5456 printf (_("\n <over large directory table entry %u>\n"), dir
);
5459 printf ("\n%s/%s:\n",
5460 /* The directory index starts counting at 1. */
5461 directory_table
[dir
- 1], file_table
[file
].name
);
5465 case DW_LNS_set_column
:
5466 READ_ULEB (uladv
, data
, end
);
5467 state_machine_regs
.column
= uladv
;
5470 case DW_LNS_negate_stmt
:
5471 adv
= state_machine_regs
.is_stmt
;
5473 state_machine_regs
.is_stmt
= adv
;
5476 case DW_LNS_set_basic_block
:
5477 state_machine_regs
.basic_block
= 1;
5480 case DW_LNS_const_add_pc
:
5481 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5482 if (linfo
.li_max_ops_per_insn
== 1)
5484 uladv
*= linfo
.li_min_insn_length
;
5485 state_machine_regs
.address
+= uladv
;
5487 state_machine_regs
.view
= 0;
5492 = ((state_machine_regs
.op_index
+ uladv
)
5493 / linfo
.li_max_ops_per_insn
)
5494 * linfo
.li_min_insn_length
;
5495 state_machine_regs
.address
5497 state_machine_regs
.op_index
5498 = (state_machine_regs
.op_index
+ uladv
)
5499 % linfo
.li_max_ops_per_insn
;
5501 state_machine_regs
.view
= 0;
5505 case DW_LNS_fixed_advance_pc
:
5506 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5507 state_machine_regs
.address
+= uladv
;
5508 state_machine_regs
.op_index
= 0;
5509 /* Do NOT reset view. */
5512 case DW_LNS_set_prologue_end
:
5515 case DW_LNS_set_epilogue_begin
:
5518 case DW_LNS_set_isa
:
5519 READ_ULEB (uladv
, data
, end
);
5520 printf (_(" Set ISA to %lu\n"), uladv
);
5524 printf (_(" Unknown opcode %d with operands: "), op_code
);
5526 if (standard_opcodes
!= NULL
)
5527 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5531 READ_ULEB (val
, data
, end
);
5532 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5533 i
== 1 ? "" : ", ");
5539 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5540 to the DWARF address/line matrix. */
5541 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5542 || (xop
== DW_LNS_copy
))
5544 const unsigned int MAX_FILENAME_LENGTH
= 35;
5546 char *newFileName
= NULL
;
5547 size_t fileNameLength
;
5551 unsigned indx
= state_machine_regs
.file
;
5553 if (linfo
.li_version
< 5)
5556 if (indx
>= n_files
)
5558 warn (_("corrupt file index %u encountered\n"), indx
);
5559 fileName
= _("<corrupt>");
5562 fileName
= (char *) file_table
[indx
].name
;
5565 fileName
= _("<unknown>");
5567 fileNameLength
= strlen (fileName
);
5568 newFileName
= fileName
;
5569 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5571 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5572 /* Truncate file name */
5573 memcpy (newFileName
,
5574 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5575 MAX_FILENAME_LENGTH
);
5576 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5579 /* A row with end_seq set to true has a meaningful address, but
5580 the other information in the same row is not significant.
5581 In such a row, print line as "-", and don't print
5583 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5585 if (linfo
.li_max_ops_per_insn
== 1)
5587 if (xop
== -DW_LNE_end_sequence
)
5588 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5590 state_machine_regs
.address
);
5592 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5593 newFileName
, state_machine_regs
.line
,
5594 state_machine_regs
.address
);
5598 if (xop
== -DW_LNE_end_sequence
)
5599 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5601 state_machine_regs
.address
,
5602 state_machine_regs
.op_index
);
5604 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5605 newFileName
, state_machine_regs
.line
,
5606 state_machine_regs
.address
,
5607 state_machine_regs
.op_index
);
5612 if (linfo
.li_max_ops_per_insn
== 1)
5614 if (xop
== -DW_LNE_end_sequence
)
5615 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5617 state_machine_regs
.address
);
5619 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5620 newFileName
, state_machine_regs
.line
,
5621 state_machine_regs
.address
);
5625 if (xop
== -DW_LNE_end_sequence
)
5626 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5628 state_machine_regs
.address
,
5629 state_machine_regs
.op_index
);
5631 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5632 newFileName
, state_machine_regs
.line
,
5633 state_machine_regs
.address
,
5634 state_machine_regs
.op_index
);
5638 if (xop
!= -DW_LNE_end_sequence
)
5640 if (state_machine_regs
.view
)
5641 printf (" %6u", state_machine_regs
.view
);
5645 if (state_machine_regs
.is_stmt
)
5650 state_machine_regs
.view
++;
5652 if (xop
== -DW_LNE_end_sequence
)
5654 reset_state_machine (linfo
.li_default_is_stmt
);
5658 if (newFileName
!= fileName
)
5670 if (directory_table
)
5672 free (directory_table
);
5673 directory_table
= NULL
;
5684 display_debug_lines (struct dwarf_section
*section
, void *file
)
5686 unsigned char *data
= section
->start
;
5687 unsigned char *end
= data
+ section
->size
;
5689 int retValDecoded
= 1;
5691 if (do_debug_lines
== 0)
5692 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5694 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5695 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5697 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5698 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5700 if (!retValRaw
|| !retValDecoded
)
5707 find_debug_info_for_offset (dwarf_vma offset
)
5711 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5714 for (i
= 0; i
< num_debug_info_entries
; i
++)
5715 if (debug_information
[i
].cu_offset
== offset
)
5716 return debug_information
+ i
;
5722 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5724 /* See gdb/gdb-index.h. */
5725 static const char * const kinds
[] =
5737 return _ (kinds
[kind
]);
5741 display_debug_pubnames_worker (struct dwarf_section
*section
,
5742 void *file ATTRIBUTE_UNUSED
,
5745 DWARF2_Internal_PubNames names
;
5746 unsigned char *start
= section
->start
;
5747 unsigned char *end
= start
+ section
->size
;
5749 /* It does not matter if this load fails,
5750 we test for that later on. */
5751 load_debug_info (file
);
5753 introduce (section
, false);
5757 unsigned char *data
;
5758 unsigned long sec_off
= start
- section
->start
;
5759 unsigned int offset_size
;
5761 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5762 if (names
.pn_length
== 0xffffffff)
5764 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5770 if (names
.pn_length
> (size_t) (end
- start
))
5772 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5775 dwarf_vmatoa ("x", names
.pn_length
));
5780 start
+= names
.pn_length
;
5782 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5783 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5785 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5786 && num_debug_info_entries
> 0
5787 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5788 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5789 (unsigned long) names
.pn_offset
, section
->name
);
5791 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5793 printf (_(" Length: %ld\n"),
5794 (long) names
.pn_length
);
5795 printf (_(" Version: %d\n"),
5797 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5798 (unsigned long) names
.pn_offset
);
5799 printf (_(" Size of area in .debug_info section: %ld\n"),
5800 (long) names
.pn_size
);
5802 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5804 static int warned
= 0;
5808 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5816 printf (_("\n Offset Kind Name\n"));
5818 printf (_("\n Offset\tName\n"));
5822 bfd_size_type maxprint
;
5825 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5832 maxprint
= (start
- data
) - 1;
5836 unsigned int kind_data
;
5837 gdb_index_symbol_kind kind
;
5838 const char *kind_name
;
5841 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5843 /* GCC computes the kind as the upper byte in the CU index
5844 word, and then right shifts it by the CU index size.
5845 Left shift KIND to where the gdb-index.h accessor macros
5847 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5848 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5849 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5850 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5851 printf (" %-6lx %s,%-10s %.*s\n",
5852 (unsigned long) offset
, is_static
? _("s") : _("g"),
5853 kind_name
, (int) maxprint
, data
);
5856 printf (" %-6lx\t%.*s\n",
5857 (unsigned long) offset
, (int) maxprint
, data
);
5859 data
+= strnlen ((char *) data
, maxprint
);
5872 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5874 return display_debug_pubnames_worker (section
, file
, 0);
5878 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5880 return display_debug_pubnames_worker (section
, file
, 1);
5884 display_debug_macinfo (struct dwarf_section
*section
,
5885 void *file ATTRIBUTE_UNUSED
)
5887 unsigned char *start
= section
->start
;
5888 unsigned char *end
= start
+ section
->size
;
5889 unsigned char *curr
= start
;
5890 enum dwarf_macinfo_record_type op
;
5892 introduce (section
, false);
5896 unsigned int lineno
;
5897 const unsigned char *string
;
5899 op
= (enum dwarf_macinfo_record_type
) *curr
;
5904 case DW_MACINFO_start_file
:
5906 unsigned int filenum
;
5908 READ_ULEB (lineno
, curr
, end
);
5909 READ_ULEB (filenum
, curr
, end
);
5910 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5915 case DW_MACINFO_end_file
:
5916 printf (_(" DW_MACINFO_end_file\n"));
5919 case DW_MACINFO_define
:
5920 READ_ULEB (lineno
, curr
, end
);
5922 curr
+= strnlen ((char *) string
, end
- string
);
5923 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5924 lineno
, (int) (curr
- string
), string
);
5929 case DW_MACINFO_undef
:
5930 READ_ULEB (lineno
, curr
, end
);
5932 curr
+= strnlen ((char *) string
, end
- string
);
5933 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5934 lineno
, (int) (curr
- string
), string
);
5939 case DW_MACINFO_vendor_ext
:
5941 unsigned int constant
;
5943 READ_ULEB (constant
, curr
, end
);
5945 curr
+= strnlen ((char *) string
, end
- string
);
5946 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5947 constant
, (int) (curr
- string
), string
);
5958 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5959 filename and dirname corresponding to file name table entry with index
5960 FILEIDX. Return NULL on failure. */
5962 static unsigned char *
5963 get_line_filename_and_dirname (dwarf_vma line_offset
,
5965 unsigned char **dir_name
)
5967 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5968 unsigned char *hdrptr
, *dirtable
, *file_name
;
5969 unsigned int offset_size
;
5970 unsigned int version
, opcode_base
;
5971 dwarf_vma length
, diridx
;
5972 const unsigned char * end
;
5975 if (section
->start
== NULL
5976 || line_offset
>= section
->size
5980 hdrptr
= section
->start
+ line_offset
;
5981 end
= section
->start
+ section
->size
;
5983 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5984 if (length
== 0xffffffff)
5986 /* This section is 64-bit DWARF 3. */
5987 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5993 if (length
> (size_t) (end
- hdrptr
)
5994 || length
< 2 + offset_size
+ 1 + 3 + 1)
5996 end
= hdrptr
+ length
;
5998 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5999 if (version
!= 2 && version
!= 3 && version
!= 4)
6001 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
6003 hdrptr
++; /* Skip max_ops_per_insn. */
6004 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
6006 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
6007 if (opcode_base
== 0
6008 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
6011 hdrptr
+= opcode_base
- 1;
6014 /* Skip over dirname table. */
6015 while (*hdrptr
!= '\0')
6017 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6023 hdrptr
++; /* Skip the NUL at the end of the table. */
6025 /* Now skip over preceding filename table entries. */
6026 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
6028 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6031 SKIP_ULEB (hdrptr
, end
);
6032 SKIP_ULEB (hdrptr
, end
);
6033 SKIP_ULEB (hdrptr
, end
);
6035 if (hdrptr
>= end
|| *hdrptr
== '\0')
6039 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6044 READ_ULEB (diridx
, hdrptr
, end
);
6047 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6049 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6053 if (dirtable
>= end
|| *dirtable
== '\0')
6055 *dir_name
= dirtable
;
6060 display_debug_macro (struct dwarf_section
*section
,
6063 unsigned char *start
= section
->start
;
6064 unsigned char *end
= start
+ section
->size
;
6065 unsigned char *curr
= start
;
6066 unsigned char *extended_op_buf
[256];
6067 bool is_dwo
= false;
6068 const char *suffix
= strrchr (section
->name
, '.');
6070 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6073 load_debug_section_with_follow (str
, file
);
6074 load_debug_section_with_follow (line
, file
);
6075 load_debug_section_with_follow (str_index
, file
);
6077 introduce (section
, false);
6081 unsigned int lineno
, version
, flags
;
6082 unsigned int offset_size
;
6083 const unsigned char *string
;
6084 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
6085 unsigned char **extended_ops
= NULL
;
6087 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6088 if (version
!= 4 && version
!= 5)
6090 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6091 section
->name
, version
);
6095 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6096 offset_size
= (flags
& 1) ? 8 : 4;
6097 printf (_(" Offset: 0x%lx\n"),
6098 (unsigned long) sec_offset
);
6099 printf (_(" Version: %d\n"), version
);
6100 printf (_(" Offset size: %d\n"), offset_size
);
6103 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6104 printf (_(" Offset into .debug_line: 0x%lx\n"),
6105 (unsigned long) line_offset
);
6109 unsigned int i
, count
, op
;
6112 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6114 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6115 extended_ops
= extended_op_buf
;
6118 printf (_(" Extension opcode arguments:\n"));
6119 for (i
= 0; i
< count
; i
++)
6121 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6122 extended_ops
[op
] = curr
;
6123 READ_ULEB (nargs
, curr
, end
);
6125 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6128 printf (_(" DW_MACRO_%02x arguments: "), op
);
6129 for (n
= 0; n
< nargs
; n
++)
6133 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6134 printf ("%s%s", get_FORM_name (form
),
6135 n
== nargs
- 1 ? "\n" : ", ");
6145 case DW_FORM_block1
:
6146 case DW_FORM_block2
:
6147 case DW_FORM_block4
:
6149 case DW_FORM_string
:
6151 case DW_FORM_sec_offset
:
6154 error (_("Invalid extension opcode form %s\n"),
6155 get_FORM_name (form
));
6171 error (_(".debug_macro section not zero terminated\n"));
6175 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6181 case DW_MACRO_define
:
6182 READ_ULEB (lineno
, curr
, end
);
6184 curr
+= strnlen ((char *) string
, end
- string
);
6185 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6186 lineno
, (int) (curr
- string
), string
);
6191 case DW_MACRO_undef
:
6192 READ_ULEB (lineno
, curr
, end
);
6194 curr
+= strnlen ((char *) string
, end
- string
);
6195 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6196 lineno
, (int) (curr
- string
), string
);
6201 case DW_MACRO_start_file
:
6203 unsigned int filenum
;
6204 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6206 READ_ULEB (lineno
, curr
, end
);
6207 READ_ULEB (filenum
, curr
, end
);
6209 if ((flags
& 2) == 0)
6210 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6213 = get_line_filename_and_dirname (line_offset
, filenum
,
6215 if (file_name
== NULL
)
6216 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6219 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6221 dir_name
!= NULL
? (const char *) dir_name
: "",
6222 dir_name
!= NULL
? "/" : "", file_name
);
6226 case DW_MACRO_end_file
:
6227 printf (_(" DW_MACRO_end_file\n"));
6230 case DW_MACRO_define_strp
:
6231 READ_ULEB (lineno
, curr
, end
);
6232 if (version
== 4 && is_dwo
)
6233 READ_ULEB (offset
, curr
, end
);
6235 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6236 string
= fetch_indirect_string (offset
);
6237 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6241 case DW_MACRO_undef_strp
:
6242 READ_ULEB (lineno
, curr
, end
);
6243 if (version
== 4 && is_dwo
)
6244 READ_ULEB (offset
, curr
, end
);
6246 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6247 string
= fetch_indirect_string (offset
);
6248 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6252 case DW_MACRO_import
:
6253 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6254 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6255 (unsigned long) offset
);
6258 case DW_MACRO_define_sup
:
6259 READ_ULEB (lineno
, curr
, end
);
6260 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6261 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6262 lineno
, (unsigned long) offset
);
6265 case DW_MACRO_undef_sup
:
6266 READ_ULEB (lineno
, curr
, end
);
6267 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6268 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6269 lineno
, (unsigned long) offset
);
6272 case DW_MACRO_import_sup
:
6273 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6274 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6275 (unsigned long) offset
);
6278 case DW_MACRO_define_strx
:
6279 case DW_MACRO_undef_strx
:
6280 READ_ULEB (lineno
, curr
, end
);
6281 READ_ULEB (offset
, curr
, end
);
6282 string
= (const unsigned char *)
6283 fetch_indexed_string (offset
, NULL
, offset_size
, false, 0);
6284 if (op
== DW_MACRO_define_strx
)
6285 printf (" DW_MACRO_define_strx ");
6287 printf (" DW_MACRO_undef_strx ");
6289 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6290 printf (_("lineno : %d macro : %s\n"),
6295 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6297 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6301 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6303 error (_(" Unknown macro opcode %02x seen\n"), op
);
6308 /* Skip over unhandled opcodes. */
6310 unsigned char *desc
= extended_ops
[op
];
6311 READ_ULEB (nargs
, desc
, end
);
6314 printf (_(" DW_MACRO_%02x\n"), op
);
6317 printf (_(" DW_MACRO_%02x -"), op
);
6318 for (n
= 0; n
< nargs
; n
++)
6322 /* DW_FORM_implicit_const is not expected here. */
6323 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6325 = read_and_display_attr_value (0, val
, 0,
6326 start
, curr
, end
, 0, 0,
6327 offset_size
, version
,
6346 display_debug_abbrev (struct dwarf_section
*section
,
6347 void *file ATTRIBUTE_UNUSED
)
6349 abbrev_entry
*entry
;
6350 unsigned char *start
= section
->start
;
6352 introduce (section
, false);
6359 offset
= start
- section
->start
;
6360 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6363 list
= new_abbrev_list (0, offset
);
6364 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6365 list
->start_of_next_abbrevs
= start
;
6368 start
= list
->start_of_next_abbrevs
;
6370 if (list
->first_abbrev
== NULL
)
6373 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6375 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6379 printf (" %ld %s [%s]\n",
6381 get_TAG_name (entry
->tag
),
6382 entry
->children
? _("has children") : _("no children"));
6384 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6386 printf (" %-18s %s",
6387 get_AT_name (attr
->attribute
),
6388 get_FORM_name (attr
->form
));
6389 if (attr
->form
== DW_FORM_implicit_const
)
6390 printf (": %s", dwarf_vmatoa ("d", attr
->implicit_const
));
6402 /* Return true when ADDR is the maximum address, when addresses are
6403 POINTER_SIZE bytes long. */
6406 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6408 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6409 return ((addr
& mask
) == mask
);
6412 /* Display a view pair list starting at *VSTART_PTR and ending at
6413 VLISTEND within SECTION. */
6416 display_view_pair_list (struct dwarf_section
*section
,
6417 unsigned char **vstart_ptr
,
6418 unsigned int debug_info_entry
,
6419 unsigned char *vlistend
)
6421 unsigned char *vstart
= *vstart_ptr
;
6422 unsigned char *section_end
= section
->start
+ section
->size
;
6423 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6425 if (vlistend
< section_end
)
6426 section_end
= vlistend
;
6430 while (vstart
< section_end
)
6432 dwarf_vma off
= vstart
- section
->start
;
6433 dwarf_vma vbegin
, vend
;
6435 READ_ULEB (vbegin
, vstart
, section_end
);
6436 if (vstart
== section_end
)
6439 READ_ULEB (vend
, vstart
, section_end
);
6440 printf (" %8.8lx ", (unsigned long) off
);
6442 print_dwarf_view (vbegin
, pointer_size
, 1);
6443 print_dwarf_view (vend
, pointer_size
, 1);
6444 printf (_("location view pair\n"));
6448 *vstart_ptr
= vstart
;
6451 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6454 display_loc_list (struct dwarf_section
*section
,
6455 unsigned char **start_ptr
,
6456 unsigned int debug_info_entry
,
6458 dwarf_vma base_address
,
6459 unsigned char **vstart_ptr
,
6462 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6463 unsigned char *section_end
= section
->start
+ section
->size
;
6464 dwarf_vma cu_offset
;
6465 unsigned int pointer_size
;
6466 unsigned int offset_size
;
6470 unsigned short length
;
6471 int need_frame_base
;
6473 if (debug_info_entry
>= num_debug_info_entries
)
6475 warn (_("No debug information available for loc lists of entry: %u\n"),
6480 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6481 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6482 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6483 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6485 if (pointer_size
< 2 || pointer_size
> 8)
6487 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6488 pointer_size
, debug_info_entry
);
6494 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6495 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6497 if (2 * pointer_size
> (size_t) (section_end
- start
))
6499 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6500 (unsigned long) offset
);
6505 print_dwarf_vma (off
, 4);
6507 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6508 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6510 if (begin
== 0 && end
== 0)
6512 /* PR 18374: In a object file we can have a location list that
6513 starts with a begin and end of 0 because there are relocations
6514 that need to be applied to the addresses. Actually applying
6515 the relocations now does not help as they will probably resolve
6516 to 0, since the object file has not been fully linked. Real
6517 end of list markers will not have any relocations against them. */
6518 if (! reloc_at (section
, off
)
6519 && ! reloc_at (section
, off
+ pointer_size
))
6521 printf (_("<End of list>\n"));
6526 /* Check base address specifiers. */
6527 if (is_max_address (begin
, pointer_size
)
6528 && !is_max_address (end
, pointer_size
))
6531 print_dwarf_vma (begin
, pointer_size
);
6532 print_dwarf_vma (end
, pointer_size
);
6533 printf (_("(base address)\n"));
6539 off
= offset
+ (vstart
- *start_ptr
);
6541 READ_ULEB (vbegin
, vstart
, section_end
);
6542 print_dwarf_view (vbegin
, pointer_size
, 1);
6544 READ_ULEB (vend
, vstart
, section_end
);
6545 print_dwarf_view (vend
, pointer_size
, 1);
6547 printf (_("views at %8.8lx for:\n %*s "),
6548 (unsigned long) off
, 8, "");
6551 if (2 > (size_t) (section_end
- start
))
6553 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6554 (unsigned long) offset
);
6558 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6560 if (length
> (size_t) (section_end
- start
))
6562 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6563 (unsigned long) offset
);
6567 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6568 print_dwarf_vma (end
+ base_address
, pointer_size
);
6571 need_frame_base
= decode_location_expression (start
,
6576 cu_offset
, section
);
6579 if (need_frame_base
&& !has_frame_base
)
6580 printf (_(" [without DW_AT_frame_base]"));
6582 if (begin
== end
&& vbegin
== vend
)
6583 fputs (_(" (start == end)"), stdout
);
6584 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6585 fputs (_(" (start > end)"), stdout
);
6593 *vstart_ptr
= vstart
;
6596 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6599 display_loclists_list (struct dwarf_section
* section
,
6600 unsigned char ** start_ptr
,
6601 unsigned int debug_info_entry
,
6603 dwarf_vma base_address
,
6604 unsigned char ** vstart_ptr
,
6607 unsigned char * start
= *start_ptr
;
6608 unsigned char * vstart
= *vstart_ptr
;
6609 unsigned char * section_end
= section
->start
+ section
->size
;
6610 dwarf_vma cu_offset
;
6611 unsigned int pointer_size
;
6612 unsigned int offset_size
;
6613 unsigned int dwarf_version
;
6615 /* Initialize it due to a false compiler warning. */
6616 dwarf_vma begin
= -1, vbegin
= -1;
6617 dwarf_vma end
= -1, vend
= -1;
6619 int need_frame_base
;
6621 if (debug_info_entry
>= num_debug_info_entries
)
6623 warn (_("No debug information available for "
6624 "loclists lists of entry: %u\n"),
6629 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6630 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6631 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6632 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6634 if (pointer_size
< 2 || pointer_size
> 8)
6636 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6637 pointer_size
, debug_info_entry
);
6643 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6644 enum dwarf_location_list_entry_type llet
;
6646 if (start
+ 1 > section_end
)
6648 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6649 (unsigned long) offset
);
6654 print_dwarf_vma (off
, 4);
6656 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6658 if (vstart
&& (llet
== DW_LLE_offset_pair
6659 || llet
== DW_LLE_start_end
6660 || llet
== DW_LLE_start_length
))
6662 off
= offset
+ (vstart
- *start_ptr
);
6664 READ_ULEB (vbegin
, vstart
, section_end
);
6665 print_dwarf_view (vbegin
, pointer_size
, 1);
6667 READ_ULEB (vend
, vstart
, section_end
);
6668 print_dwarf_view (vend
, pointer_size
, 1);
6670 printf (_("views at %8.8lx for:\n %*s "),
6671 (unsigned long) off
, 8, "");
6676 case DW_LLE_end_of_list
:
6677 printf (_("<End of list>\n"));
6680 case DW_LLE_base_addressx
:
6681 READ_ULEB (base_address
, start
, section_end
);
6682 print_dwarf_vma (base_address
, pointer_size
);
6683 printf (_("(index into .debug_addr) "));
6684 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6685 print_dwarf_vma (base_address
, pointer_size
);
6686 printf (_("(base address)\n"));
6689 case DW_LLE_startx_endx
:
6690 READ_ULEB (begin
, start
, section_end
);
6691 begin
= fetch_indexed_addr (begin
, pointer_size
);
6692 READ_ULEB (end
, start
, section_end
);
6693 end
= fetch_indexed_addr (end
, pointer_size
);
6696 case DW_LLE_startx_length
:
6697 READ_ULEB (begin
, start
, section_end
);
6698 begin
= fetch_indexed_addr (begin
, pointer_size
);
6699 READ_ULEB (end
, start
, section_end
);
6703 case DW_LLE_default_location
:
6707 case DW_LLE_offset_pair
:
6708 READ_ULEB (begin
, start
, section_end
);
6709 begin
+= base_address
;
6710 READ_ULEB (end
, start
, section_end
);
6711 end
+= base_address
;
6714 case DW_LLE_base_address
:
6715 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6717 print_dwarf_vma (base_address
, pointer_size
);
6718 printf (_("(base address)\n"));
6721 case DW_LLE_start_end
:
6722 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6723 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6726 case DW_LLE_start_length
:
6727 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6728 READ_ULEB (end
, start
, section_end
);
6732 #ifdef DW_LLE_view_pair
6733 case DW_LLE_view_pair
:
6735 printf (_("View pair entry in loclist with locviews attribute\n"));
6736 READ_ULEB (vbegin
, start
, section_end
);
6737 print_dwarf_view (vbegin
, pointer_size
, 1);
6739 READ_ULEB (vend
, start
, section_end
);
6740 print_dwarf_view (vend
, pointer_size
, 1);
6742 printf (_("views for:\n"));
6747 error (_("Invalid location list entry type %d\n"), llet
);
6751 if (llet
== DW_LLE_end_of_list
)
6754 if (llet
== DW_LLE_base_address
6755 || llet
== DW_LLE_base_addressx
)
6758 if (start
== section_end
)
6760 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6761 (unsigned long) offset
);
6764 READ_ULEB (length
, start
, section_end
);
6766 if (length
> (size_t) (section_end
- start
))
6768 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6769 (unsigned long) offset
);
6773 print_dwarf_vma (begin
, pointer_size
);
6774 print_dwarf_vma (end
, pointer_size
);
6777 need_frame_base
= decode_location_expression (start
,
6782 cu_offset
, section
);
6785 if (need_frame_base
&& !has_frame_base
)
6786 printf (_(" [without DW_AT_frame_base]"));
6788 if (begin
== end
&& vbegin
== vend
)
6789 fputs (_(" (start == end)"), stdout
);
6790 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6791 fputs (_(" (start > end)"), stdout
);
6799 if (vbegin
!= vm1
|| vend
!= vm1
)
6800 printf (_("Trailing view pair not used in a range"));
6803 *vstart_ptr
= vstart
;
6806 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6807 right-adjusted in a field of length LEN, and followed by a space. */
6810 print_addr_index (unsigned int idx
, unsigned int len
)
6812 static char buf
[15];
6813 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6814 printf ("%*s ", len
, buf
);
6817 /* Display a location list from a .dwo section. It uses address indexes rather
6818 than embedded addresses. This code closely follows display_loc_list, but the
6819 two are sufficiently different that combining things is very ugly. */
6822 display_loc_list_dwo (struct dwarf_section
*section
,
6823 unsigned char **start_ptr
,
6824 unsigned int debug_info_entry
,
6826 unsigned char **vstart_ptr
,
6829 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6830 unsigned char *section_end
= section
->start
+ section
->size
;
6831 dwarf_vma cu_offset
;
6832 unsigned int pointer_size
;
6833 unsigned int offset_size
;
6836 unsigned short length
;
6837 int need_frame_base
;
6840 if (debug_info_entry
>= num_debug_info_entries
)
6842 warn (_("No debug information for loc lists of entry: %u\n"),
6847 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6848 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6849 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6850 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6852 if (pointer_size
< 2 || pointer_size
> 8)
6854 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6855 pointer_size
, debug_info_entry
);
6862 print_dwarf_vma (offset
+ (start
- *start_ptr
), 4);
6864 if (start
>= section_end
)
6866 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6867 (unsigned long) offset
);
6871 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6884 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6886 READ_ULEB (view
, vstart
, section_end
);
6887 print_dwarf_view (view
, 8, 1);
6889 READ_ULEB (view
, vstart
, section_end
);
6890 print_dwarf_view (view
, 8, 1);
6892 printf (_("views at %8.8lx for:\n %*s "),
6893 (unsigned long) off
, 8, "");
6901 case 0: /* A terminating entry. */
6903 *vstart_ptr
= vstart
;
6904 printf (_("<End of list>\n"));
6906 case 1: /* A base-address entry. */
6907 READ_ULEB (idx
, start
, section_end
);
6908 print_addr_index (idx
, 8);
6909 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6910 printf (_("(base address selection entry)\n"));
6912 case 2: /* A start/end entry. */
6913 READ_ULEB (idx
, start
, section_end
);
6914 print_addr_index (idx
, 8);
6915 READ_ULEB (idx
, start
, section_end
);
6916 print_addr_index (idx
, 8);
6918 case 3: /* A start/length entry. */
6919 READ_ULEB (idx
, start
, section_end
);
6920 print_addr_index (idx
, 8);
6921 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6922 printf ("%08x ", idx
);
6924 case 4: /* An offset pair entry. */
6925 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6926 printf ("%08x ", idx
);
6927 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6928 printf ("%08x ", idx
);
6931 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6933 *vstart_ptr
= vstart
;
6937 if (2 > (size_t) (section_end
- start
))
6939 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6940 (unsigned long) offset
);
6944 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6945 if (length
> (size_t) (section_end
- start
))
6947 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6948 (unsigned long) offset
);
6953 need_frame_base
= decode_location_expression (start
,
6958 cu_offset
, section
);
6961 if (need_frame_base
&& !has_frame_base
)
6962 printf (_(" [without DW_AT_frame_base]"));
6970 *vstart_ptr
= vstart
;
6973 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6976 static dwarf_vma
*loc_offsets
, *loc_views
;
6979 loc_offsets_compar (const void *ap
, const void *bp
)
6981 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6982 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6984 int ret
= (a
> b
) - (b
> a
);
6988 a
= loc_views
[*(const unsigned int *) ap
];
6989 b
= loc_views
[*(const unsigned int *) bp
];
6991 ret
= (a
> b
) - (b
> a
);
6997 display_offset_entry_loclists (struct dwarf_section
*section
)
6999 unsigned char * start
= section
->start
;
7000 unsigned char * const end
= start
+ section
->size
;
7002 introduce (section
, false);
7007 unsigned short version
;
7008 unsigned char address_size
;
7009 unsigned char segment_selector_size
;
7010 uint32_t offset_entry_count
;
7014 printf (_("Table at Offset 0x%lx\n"), (long)(start
- section
->start
));
7016 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7017 if (length
== 0xffffffff)
7020 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7025 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
7026 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
7027 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
7028 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
7030 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", length
));
7031 printf (_(" DWARF version: %u\n"), version
);
7032 printf (_(" Address size: %u\n"), address_size
);
7033 printf (_(" Segment size: %u\n"), segment_selector_size
);
7034 printf (_(" Offset entries: %u\n"), offset_entry_count
);
7038 warn (_("The %s section contains a corrupt or "
7039 "unsupported version number: %d.\n"),
7040 section
->name
, version
);
7044 if (segment_selector_size
!= 0)
7046 warn (_("The %s section contains an "
7047 "unsupported segment selector size: %d.\n"),
7048 section
->name
, segment_selector_size
);
7052 if (offset_entry_count
== 0)
7054 warn (_("The %s section contains a table without offset\n"),
7059 printf (_("\n Offset Entries starting at 0x%lx:\n"),
7060 (long)(start
- section
->start
));
7064 for (i
= 0; i
< offset_entry_count
; i
++)
7068 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, end
);
7069 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
7074 for (i
= 0; i
< offset_entry_count
; i
++)
7078 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, end
);
7079 printf (_(" [%6u] 0x%x\n"), i
, entry
);
7087 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7090 dwarf_vma base_address
= 0;
7093 dwarf_vma off
= start
- section
->start
;
7097 printf (_(" Offset Entry %u\n"), i
);
7102 print_dwarf_vma (off
, 4);
7104 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7108 case DW_LLE_end_of_list
:
7109 printf (_("<End of list>\n\n"));
7113 case DW_LLE_base_addressx
:
7114 READ_ULEB (base_address
, start
, end
);
7115 print_dwarf_vma (base_address
, address_size
);
7116 printf (_("(index into .debug_addr) "));
7117 base_address
= fetch_indexed_addr (base_address
, address_size
);
7118 print_dwarf_vma (base_address
, address_size
);
7119 printf (_("(base address)\n"));
7122 case DW_LLE_startx_endx
:
7123 READ_ULEB (begin
, start
, end
);
7124 begin
= fetch_indexed_addr (begin
, address_size
);
7125 READ_ULEB (finish
, start
, end
);
7126 finish
= fetch_indexed_addr (finish
, address_size
);
7129 case DW_LLE_startx_length
:
7130 READ_ULEB (begin
, start
, end
);
7131 begin
= fetch_indexed_addr (begin
, address_size
);
7132 READ_ULEB (finish
, start
, end
);
7136 case DW_LLE_offset_pair
:
7137 READ_ULEB (begin
, start
, end
);
7138 begin
+= base_address
;
7139 READ_ULEB (finish
, start
, end
);
7140 finish
+= base_address
;
7143 case DW_LLE_default_location
:
7147 case DW_LLE_base_address
:
7148 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7149 print_dwarf_vma (base_address
, address_size
);
7150 printf (_("(base address)\n"));
7153 case DW_LLE_start_end
:
7154 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7155 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7158 case DW_LLE_start_length
:
7159 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7160 READ_ULEB (finish
, start
, end
);
7165 error (_("Invalid location list entry type %d\n"), lle
);
7171 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7172 (unsigned long) off
);
7176 print_dwarf_vma (begin
, address_size
);
7177 print_dwarf_vma (finish
, address_size
);
7179 if (begin
== finish
)
7180 fputs (_(" (start == end)"), stdout
);
7181 else if (begin
> finish
)
7182 fputs (_(" (start > end)"), stdout
);
7184 /* Read the counted location descriptions. */
7185 READ_ULEB (length
, start
, end
);
7187 if (length
> (size_t) (end
- start
))
7189 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7190 (unsigned long) off
);
7195 (void) decode_location_expression (start
, address_size
, address_size
,
7196 version
, length
, 0, section
);
7203 while (start
< end
);
7209 display_debug_loc (struct dwarf_section
*section
, void *file
)
7211 unsigned char *start
= section
->start
, *vstart
= NULL
;
7213 unsigned char *section_begin
= start
;
7214 unsigned int num_loc_list
= 0;
7215 dwarf_vma last_offset
= 0;
7216 dwarf_vma last_view
= 0;
7217 unsigned int first
= 0;
7220 int seen_first_offset
= 0;
7221 int locs_sorted
= 1;
7222 unsigned char *next
= start
, *vnext
= vstart
;
7223 unsigned int *array
= NULL
;
7224 const char *suffix
= strrchr (section
->name
, '.');
7225 bool is_dwo
= false;
7226 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7227 dwarf_vma expected_start
= 0;
7229 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7232 bytes
= section
->size
;
7236 printf (_("\nThe %s section is empty.\n"), section
->name
);
7242 unsigned char *hdrptr
= section_begin
;
7243 dwarf_vma ll_length
;
7244 unsigned short ll_version
;
7245 unsigned char *end
= section_begin
+ section
->size
;
7246 unsigned char address_size
, segment_selector_size
;
7247 uint32_t offset_entry_count
;
7249 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7250 if (ll_length
== 0xffffffff)
7251 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7253 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7254 if (ll_version
!= 5)
7256 warn (_("The %s section contains corrupt or "
7257 "unsupported version number: %d.\n"),
7258 section
->name
, ll_version
);
7262 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7264 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7265 if (segment_selector_size
!= 0)
7267 warn (_("The %s section contains "
7268 "unsupported segment selector size: %d.\n"),
7269 section
->name
, segment_selector_size
);
7273 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7275 if (offset_entry_count
!= 0)
7276 return display_offset_entry_loclists (section
);
7278 expected_start
= hdrptr
- section_begin
;
7281 if (load_debug_info (file
) == 0)
7283 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7288 /* Check the order of location list in .debug_info section. If
7289 offsets of location lists are in the ascending order, we can
7290 use `debug_information' directly. */
7291 for (i
= 0; i
< num_debug_info_entries
; i
++)
7295 num
= debug_information
[i
].num_loc_offsets
;
7296 if (num
> num_loc_list
)
7299 /* Check if we can use `debug_information' directly. */
7300 if (locs_sorted
&& num
!= 0)
7302 if (!seen_first_offset
)
7304 /* This is the first location list. */
7305 last_offset
= debug_information
[i
].loc_offsets
[0];
7306 last_view
= debug_information
[i
].loc_views
[0];
7308 seen_first_offset
= 1;
7314 for (; j
< num
; j
++)
7317 debug_information
[i
].loc_offsets
[j
]
7318 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7319 && last_view
> debug_information
[i
].loc_views
[j
]))
7324 last_offset
= debug_information
[i
].loc_offsets
[j
];
7325 last_view
= debug_information
[i
].loc_views
[j
];
7330 if (!seen_first_offset
)
7331 error (_("No location lists in .debug_info section!\n"));
7333 if (debug_information
[first
].num_loc_offsets
> 0
7334 && debug_information
[first
].loc_offsets
[0] != expected_start
7335 && debug_information
[first
].loc_views
[0] != expected_start
)
7336 warn (_("Location lists in %s section start at 0x%s rather than 0x%s\n"),
7338 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]),
7339 dwarf_vmatoa ("x", expected_start
));
7342 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7344 introduce (section
, false);
7346 if (reloc_at (section
, 0))
7347 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7349 printf (_(" Offset Begin End Expression\n"));
7351 seen_first_offset
= 0;
7352 for (i
= first
; i
< num_debug_info_entries
; i
++)
7354 dwarf_vma offset
, voffset
;
7355 dwarf_vma base_address
;
7361 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7363 loc_offsets
= debug_information
[i
].loc_offsets
;
7364 loc_views
= debug_information
[i
].loc_views
;
7365 qsort (array
, debug_information
[i
].num_loc_offsets
,
7366 sizeof (*array
), loc_offsets_compar
);
7369 int adjacent_view_loclists
= 1;
7370 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7372 j
= locs_sorted
? k
: array
[k
];
7374 && (debug_information
[i
].loc_offsets
[locs_sorted
7375 ? k
- 1 : array
[k
- 1]]
7376 == debug_information
[i
].loc_offsets
[j
])
7377 && (debug_information
[i
].loc_views
[locs_sorted
7378 ? k
- 1 : array
[k
- 1]]
7379 == debug_information
[i
].loc_views
[j
]))
7381 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7382 offset
= debug_information
[i
].loc_offsets
[j
];
7383 next
= section_begin
+ offset
;
7384 voffset
= debug_information
[i
].loc_views
[j
];
7386 vnext
= section_begin
+ voffset
;
7389 base_address
= debug_information
[i
].base_address
;
7391 if (vnext
&& vnext
< next
)
7394 display_view_pair_list (section
, &vstart
, i
, next
);
7399 if (!seen_first_offset
|| !adjacent_view_loclists
)
7400 seen_first_offset
= 1;
7404 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7405 (unsigned long) (start
- section_begin
),
7406 (unsigned long) offset
,
7408 else if (start
> next
)
7409 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7410 (unsigned long) (start
- section_begin
),
7411 (unsigned long) offset
,
7417 if (offset
>= bytes
)
7419 warn (_("Offset 0x%lx is bigger than %s section size.\n"),
7420 (unsigned long) offset
,
7425 if (vnext
&& voffset
>= bytes
)
7427 warn (_("View Offset 0x%lx is bigger than %s section size.\n"),
7428 (unsigned long) voffset
,
7436 display_loc_list_dwo (section
, &start
, i
, offset
,
7437 &vstart
, has_frame_base
);
7439 display_loc_list (section
, &start
, i
, offset
, base_address
,
7440 &vstart
, has_frame_base
);
7445 warn (_("DWO is not yet supported.\n"));
7447 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7448 &vstart
, has_frame_base
);
7451 /* FIXME: this arrangement is quite simplistic. Nothing
7452 requires locview lists to be adjacent to corresponding
7453 loclists, and a single loclist could be augmented by
7454 different locview lists, and vice-versa, unlikely as it
7455 is that it would make sense to do so. Hopefully we'll
7456 have view pair support built into loclists before we ever
7457 need to address all these possibilities. */
7458 if (adjacent_view_loclists
&& vnext
7459 && vnext
!= start
&& vstart
!= next
)
7461 adjacent_view_loclists
= 0;
7462 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7465 if (vnext
&& vnext
== start
)
7466 display_view_pair_list (section
, &start
, i
, vstart
);
7470 if (start
< section
->start
+ section
->size
)
7471 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7472 "There are %ld unused bytes at the end of section %s\n",
7473 (long) (section
->start
+ section
->size
- start
)),
7474 (long) (section
->start
+ section
->size
- start
), section
->name
);
7481 display_debug_str (struct dwarf_section
*section
,
7482 void *file ATTRIBUTE_UNUSED
)
7484 unsigned char *start
= section
->start
;
7485 dwarf_vma bytes
= section
->size
;
7486 dwarf_vma addr
= section
->address
;
7490 printf (_("\nThe %s section is empty.\n"), section
->name
);
7494 introduce (section
, false);
7502 lbytes
= (bytes
> 16 ? 16 : bytes
);
7504 printf (" 0x%8.8lx ", (unsigned long) addr
);
7506 for (j
= 0; j
< 16; j
++)
7509 printf ("%2.2x", start
[j
]);
7517 for (j
= 0; j
< lbytes
; j
++)
7520 if (k
>= ' ' && k
< 0x80)
7539 display_debug_info (struct dwarf_section
*section
, void *file
)
7541 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7545 display_debug_types (struct dwarf_section
*section
, void *file
)
7547 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7551 display_trace_info (struct dwarf_section
*section
, void *file
)
7553 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7557 display_debug_aranges (struct dwarf_section
*section
,
7558 void *file ATTRIBUTE_UNUSED
)
7560 unsigned char *start
= section
->start
;
7561 unsigned char *end
= start
+ section
->size
;
7563 introduce (section
, false);
7565 /* It does not matter if this load fails,
7566 we test for that later on. */
7567 load_debug_info (file
);
7571 unsigned char *hdrptr
;
7572 DWARF2_Internal_ARange arange
;
7573 unsigned char *addr_ranges
;
7577 unsigned char address_size
;
7578 unsigned int offset_size
;
7579 unsigned char *end_ranges
;
7582 sec_off
= hdrptr
- section
->start
;
7584 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7585 if (arange
.ar_length
== 0xffffffff)
7587 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7593 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7595 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7597 (unsigned long) sec_off
,
7598 dwarf_vmatoa ("x", arange
.ar_length
));
7601 end_ranges
= hdrptr
+ arange
.ar_length
;
7603 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7604 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7607 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7608 && num_debug_info_entries
> 0
7609 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7610 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7611 (unsigned long) arange
.ar_info_offset
, section
->name
);
7613 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7614 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7616 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7618 /* PR 19872: A version number of 0 probably means that there is
7619 padding at the end of the .debug_aranges section. Gold puts
7620 it there when performing an incremental link, for example.
7621 So do not generate a warning in this case. */
7622 if (arange
.ar_version
)
7623 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7627 printf (_(" Length: %ld\n"),
7628 (long) arange
.ar_length
);
7629 printf (_(" Version: %d\n"), arange
.ar_version
);
7630 printf (_(" Offset into .debug_info: 0x%lx\n"),
7631 (unsigned long) arange
.ar_info_offset
);
7632 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7633 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7635 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7637 /* PR 17512: file: 001-108546-0.001:0.1. */
7638 if (address_size
== 0 || address_size
> 8)
7640 error (_("Invalid address size in %s section!\n"),
7645 /* The DWARF spec does not require that the address size be a power
7646 of two, but we do. This will have to change if we ever encounter
7647 an uneven architecture. */
7648 if ((address_size
& (address_size
- 1)) != 0)
7650 warn (_("Pointer size + Segment size is not a power of two.\n"));
7654 if (address_size
> 4)
7655 printf (_("\n Address Length\n"));
7657 printf (_("\n Address Length\n"));
7659 addr_ranges
= hdrptr
;
7661 /* Must pad to an alignment boundary that is twice the address size. */
7662 addr_ranges
+= (2 * address_size
- 1
7663 - (hdrptr
- start
- 1) % (2 * address_size
));
7665 while (2 * address_size
<= end_ranges
- addr_ranges
)
7667 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7669 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7672 print_dwarf_vma (address
, address_size
);
7673 print_dwarf_vma (length
, address_size
);
7685 /* Comparison function for qsort. */
7687 comp_addr_base (const void * v0
, const void * v1
)
7689 debug_info
*info0
= *(debug_info
**) v0
;
7690 debug_info
*info1
= *(debug_info
**) v1
;
7691 return info0
->addr_base
- info1
->addr_base
;
7694 /* Display the debug_addr section. */
7696 display_debug_addr (struct dwarf_section
*section
,
7699 debug_info
**debug_addr_info
;
7700 unsigned char *entry
;
7704 unsigned char * header
;
7706 if (section
->size
== 0)
7708 printf (_("\nThe %s section is empty.\n"), section
->name
);
7712 if (load_debug_info (file
) == 0)
7714 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7719 introduce (section
, false);
7721 /* PR 17531: file: cf38d01b.
7722 We use xcalloc because a corrupt file may not have initialised all of the
7723 fields in the debug_info structure, which means that the sort below might
7724 try to move uninitialised data. */
7725 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7726 sizeof (debug_info
*));
7729 for (i
= 0; i
< num_debug_info_entries
; i
++)
7730 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7732 /* PR 17531: file: cf38d01b. */
7733 if (debug_information
[i
].addr_base
>= section
->size
)
7734 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7735 (unsigned long) debug_information
[i
].addr_base
, i
);
7737 debug_addr_info
[count
++] = debug_information
+ i
;
7740 /* Add a sentinel to make iteration convenient. */
7741 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7742 debug_addr_info
[count
]->addr_base
= section
->size
;
7743 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7745 header
= section
->start
;
7746 for (i
= 0; i
< count
; i
++)
7749 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7751 printf (_(" For compilation unit at offset 0x%s:\n"),
7752 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7754 printf (_("\tIndex\tAddress\n"));
7755 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7756 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7758 size_t header_size
= entry
- header
;
7759 unsigned char * curr_header
= header
;
7762 int segment_selector_size
;
7764 if (header_size
!= 8 && header_size
!= 16)
7766 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7767 section
->name
, (long) header_size
);
7771 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7772 if (length
== 0xffffffff)
7773 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7774 end
= curr_header
+ length
;
7776 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7778 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7779 section
->name
, version
);
7781 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7782 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7783 address_size
+= segment_selector_size
;
7786 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7791 dwarf_vma base
= byte_get (entry
, address_size
);
7792 printf (_("\t%d:\t"), idx
);
7793 print_dwarf_vma (base
, address_size
);
7795 entry
+= address_size
;
7801 free (debug_addr_info
);
7805 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7808 display_debug_str_offsets (struct dwarf_section
*section
,
7809 void *file ATTRIBUTE_UNUSED
)
7813 if (section
->size
== 0)
7815 printf (_("\nThe %s section is empty.\n"), section
->name
);
7819 unsigned char *start
= section
->start
;
7820 unsigned char *end
= start
+ section
->size
;
7821 unsigned char *curr
= start
;
7822 dwarf_vma debug_str_offsets_hdr_len
;
7824 const char *suffix
= strrchr (section
->name
, '.');
7825 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7828 load_debug_section_with_follow (str_dwo
, file
);
7830 load_debug_section_with_follow (str
, file
);
7832 introduce (section
, false);
7837 dwarf_vma entry_length
;
7839 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7840 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7841 if (length
== 0xffffffff)
7843 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7845 debug_str_offsets_hdr_len
= 16;
7850 debug_str_offsets_hdr_len
= 8;
7853 unsigned char *entries_end
;
7856 /* This is probably an old style .debug_str_offset section which
7857 just contains offsets and no header (and the first offset is 0). */
7858 length
= section
->size
;
7859 curr
= section
->start
;
7862 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7863 printf (_(" Index Offset [String]\n"));
7867 if (length
<= (dwarf_vma
) (end
- curr
))
7868 entries_end
= curr
+ length
;
7871 warn (_("Section %s is too small %#lx\n"),
7872 section
->name
, (unsigned long) section
->size
);
7877 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7879 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7882 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7884 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7886 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7887 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7888 printf (_(" Index Offset [String]\n"));
7891 for (idx
= 0; curr
< entries_end
; idx
++)
7894 const unsigned char * string
;
7896 if ((dwarf_vma
) (entries_end
- curr
) < entry_length
)
7897 /* Not enough space to read one entry_length, give up. */
7900 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7902 string
= (const unsigned char *)
7903 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
, debug_str_offsets_hdr_len
);
7905 string
= fetch_indirect_string (offset
);
7907 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7915 /* Each debug_information[x].range_lists[y] gets this representation for
7916 sorting purposes. */
7920 /* The debug_information[x].range_lists[y] value. */
7921 dwarf_vma ranges_offset
;
7923 /* Original debug_information to find parameters of the data. */
7924 debug_info
*debug_info_p
;
7927 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7930 range_entry_compar (const void *ap
, const void *bp
)
7932 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7933 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7934 const dwarf_vma a
= a_re
->ranges_offset
;
7935 const dwarf_vma b
= b_re
->ranges_offset
;
7937 return (a
> b
) - (b
> a
);
7941 display_debug_ranges_list (unsigned char * start
,
7942 unsigned char * finish
,
7943 unsigned int pointer_size
,
7945 dwarf_vma base_address
)
7947 while (start
< finish
)
7952 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7953 if (start
>= finish
)
7955 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7958 print_dwarf_vma (offset
, 4);
7960 if (begin
== 0 && end
== 0)
7962 printf (_("<End of list>\n"));
7966 /* Check base address specifiers. */
7967 if (is_max_address (begin
, pointer_size
)
7968 && !is_max_address (end
, pointer_size
))
7971 print_dwarf_vma (begin
, pointer_size
);
7972 print_dwarf_vma (end
, pointer_size
);
7973 printf ("(base address)\n");
7977 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7978 print_dwarf_vma (end
+ base_address
, pointer_size
);
7981 fputs (_("(start == end)"), stdout
);
7982 else if (begin
> end
)
7983 fputs (_("(start > end)"), stdout
);
7989 static unsigned char *
7990 display_debug_rnglists_list (unsigned char * start
,
7991 unsigned char * finish
,
7992 unsigned int pointer_size
,
7994 dwarf_vma base_address
,
7995 unsigned int offset_size
)
7997 unsigned char *next
= start
;
7998 unsigned int debug_addr_section_hdr_len
;
8000 if (offset_size
== 4)
8001 debug_addr_section_hdr_len
= 8;
8003 debug_addr_section_hdr_len
= 16;
8007 dwarf_vma off
= offset
+ (start
- next
);
8008 enum dwarf_range_list_entry rlet
;
8009 /* Initialize it due to a false compiler warning. */
8010 dwarf_vma begin
= -1, length
, end
= -1;
8012 if (start
>= finish
)
8014 warn (_("Range list starting at offset 0x%s is not terminated.\n"),
8015 dwarf_vmatoa ("x", offset
));
8020 print_dwarf_vma (off
, 4);
8022 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
8026 case DW_RLE_end_of_list
:
8027 printf (_("<End of list>\n"));
8029 case DW_RLE_base_addressx
:
8030 READ_ULEB (base_address
, start
, finish
);
8031 print_dwarf_vma (base_address
, pointer_size
);
8032 printf (_("(base address index) "));
8033 base_address
= fetch_indexed_addr ((base_address
* pointer_size
)
8034 + debug_addr_section_hdr_len
, pointer_size
);
8035 print_dwarf_vma (base_address
, pointer_size
);
8036 printf (_("(base address)\n"));
8038 case DW_RLE_startx_endx
:
8039 READ_ULEB (begin
, start
, finish
);
8040 READ_ULEB (end
, start
, finish
);
8041 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8042 + debug_addr_section_hdr_len
, pointer_size
);
8043 end
= fetch_indexed_addr ((begin
* pointer_size
)
8044 + debug_addr_section_hdr_len
, pointer_size
);
8046 case DW_RLE_startx_length
:
8047 READ_ULEB (begin
, start
, finish
);
8048 READ_ULEB (length
, start
, finish
);
8049 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8050 + debug_addr_section_hdr_len
, pointer_size
);
8051 end
= begin
+ length
;
8053 case DW_RLE_offset_pair
:
8054 READ_ULEB (begin
, start
, finish
);
8055 READ_ULEB (end
, start
, finish
);
8057 case DW_RLE_base_address
:
8058 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8059 print_dwarf_vma (base_address
, pointer_size
);
8060 printf (_("(base address)\n"));
8062 case DW_RLE_start_end
:
8063 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8064 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8066 case DW_RLE_start_length
:
8067 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8068 READ_ULEB (length
, start
, finish
);
8069 end
= begin
+ length
;
8072 error (_("Invalid range list entry type %d\n"), rlet
);
8073 rlet
= DW_RLE_end_of_list
;
8077 if (rlet
== DW_RLE_end_of_list
)
8079 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8082 /* Only a DW_RLE_offset_pair needs the base address added. */
8083 if (rlet
== DW_RLE_offset_pair
)
8085 begin
+= base_address
;
8086 end
+= base_address
;
8089 print_dwarf_vma (begin
, pointer_size
);
8090 print_dwarf_vma (end
, pointer_size
);
8093 fputs (_("(start == end)"), stdout
);
8094 else if (begin
> end
)
8095 fputs (_("(start > end)"), stdout
);
8104 display_debug_rnglists (struct dwarf_section
*section
)
8106 unsigned char * start
= section
->start
;
8107 unsigned char * finish
= start
+ section
->size
;
8109 while (start
< finish
)
8111 unsigned char * table_start
;
8112 dwarf_vma offset
= start
- section
->start
;
8113 unsigned char * end
;
8114 dwarf_vma initial_length
;
8115 unsigned char segment_selector_size
;
8116 unsigned int offset_entry_count
;
8118 unsigned short version
;
8119 unsigned char address_size
= 0;
8120 unsigned char offset_size
;
8122 /* Get and check the length of the block. */
8123 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8125 if (initial_length
== 0xffffffff)
8127 /* This section is 64-bit DWARF 3. */
8128 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8134 if (initial_length
> (size_t) (finish
- start
))
8136 /* If the length field has a relocation against it, then we should
8137 not complain if it is inaccurate (and probably negative).
8138 It is copied from .debug_line handling code. */
8139 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8140 initial_length
= finish
- start
;
8143 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
8144 (long) initial_length
);
8149 end
= start
+ initial_length
;
8151 /* Get the other fields in the header. */
8152 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8153 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8154 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8155 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8157 printf (_(" Table at Offset: 0x%s:\n"), dwarf_vmatoa ("x", offset
));
8158 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", initial_length
));
8159 printf (_(" DWARF version: %u\n"), version
);
8160 printf (_(" Address size: %u\n"), address_size
);
8161 printf (_(" Segment size: %u\n"), segment_selector_size
);
8162 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8164 /* Check the fields. */
8165 if (segment_selector_size
!= 0)
8167 warn (_("The %s section contains "
8168 "unsupported segment selector size: %d.\n"),
8169 section
->name
, segment_selector_size
);
8175 warn (_("Only DWARF version 5+ debug_rnglists info "
8176 "is currently supported.\n"));
8180 table_start
= start
;
8182 if (offset_entry_count
!= 0)
8184 printf (_("\n Offsets starting at 0x%lx:\n"), (long)(start
- section
->start
));
8185 if (offset_size
== 8)
8187 for (i
= 0; i
< offset_entry_count
; i
++)
8191 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, finish
);
8192 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
8197 for (i
= 0; i
< offset_entry_count
; i
++)
8201 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, finish
);
8202 printf (_(" [%6u] 0x%x\n"), i
, entry
);
8207 offset_entry_count
= 1;
8209 for (i
= 0; i
< offset_entry_count
; i
++)
8211 dwarf_vma indx
= start
- table_start
;
8213 offset
= start
- section
->start
;
8214 printf (_("\n Offset: %lx, Index: 0x%s\n"),
8215 (long) offset
, dwarf_vmatoa ("x", indx
));
8216 printf (_(" Offset Begin End\n"));
8217 start
= display_debug_rnglists_list
8218 (start
, end
, address_size
, offset
, 0, offset_size
);
8234 display_debug_ranges (struct dwarf_section
*section
,
8235 void *file ATTRIBUTE_UNUSED
)
8237 unsigned char * start
= section
->start
;
8238 unsigned char * last_start
= start
;
8239 dwarf_vma bytes
= section
->size
;
8240 unsigned char * section_begin
= start
;
8241 unsigned char * finish
= start
+ bytes
;
8242 unsigned int num_range_list
, i
;
8243 struct range_entry
* range_entries
;
8244 struct range_entry
* range_entry_fill
;
8245 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8246 /* Initialize it due to a false compiler warning. */
8247 unsigned char address_size
= 0;
8248 dwarf_vma last_offset
= 0;
8252 printf (_("\nThe %s section is empty.\n"), section
->name
);
8256 introduce (section
, false);
8259 return display_debug_rnglists (section
);
8261 if (load_debug_info (file
) == 0)
8263 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8269 for (i
= 0; i
< num_debug_info_entries
; i
++)
8270 num_range_list
+= debug_information
[i
].num_range_lists
;
8272 if (num_range_list
== 0)
8274 /* This can happen when the file was compiled with -gsplit-debug
8275 which removes references to range lists from the primary .o file. */
8276 printf (_("No range lists in .debug_info section.\n"));
8280 range_entries
= (struct range_entry
*)
8281 xmalloc (sizeof (*range_entries
) * num_range_list
);
8282 range_entry_fill
= range_entries
;
8284 for (i
= 0; i
< num_debug_info_entries
; i
++)
8286 debug_info
*debug_info_p
= &debug_information
[i
];
8289 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8291 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8292 range_entry_fill
->debug_info_p
= debug_info_p
;
8297 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8298 range_entry_compar
);
8300 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8301 warn (_("Range lists in %s section start at 0x%lx\n"),
8302 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
8305 printf (_(" Offset Begin End\n"));
8307 for (i
= 0; i
< num_range_list
; i
++)
8309 struct range_entry
*range_entry
= &range_entries
[i
];
8310 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8311 unsigned int pointer_size
;
8313 unsigned char *next
;
8314 dwarf_vma base_address
;
8316 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8317 offset
= range_entry
->ranges_offset
;
8318 base_address
= debug_info_p
->base_address
;
8320 /* PR 17512: file: 001-101485-0.001:0.1. */
8321 if (pointer_size
< 2 || pointer_size
> 8)
8323 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
8324 pointer_size
, (unsigned long) offset
);
8328 if (offset
> (size_t) (finish
- section_begin
))
8330 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
8331 (unsigned long) offset
, i
);
8335 next
= section_begin
+ offset
+ debug_info_p
->rnglists_base
;
8337 /* If multiple DWARF entities reference the same range then we will
8338 have multiple entries in the `range_entries' list for the same
8339 offset. Thanks to the sort above these will all be consecutive in
8340 the `range_entries' list, so we can easily ignore duplicates
8342 if (i
> 0 && last_offset
== offset
)
8344 last_offset
= offset
;
8346 if (dwarf_check
!= 0 && i
> 0)
8349 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
8350 (unsigned long) (start
- section_begin
),
8351 (unsigned long) (next
- section_begin
), section
->name
);
8352 else if (start
> next
)
8354 if (next
== last_start
)
8356 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
8357 (unsigned long) (start
- section_begin
),
8358 (unsigned long) (next
- section_begin
), section
->name
);
8365 display_debug_ranges_list
8366 (start
, finish
, pointer_size
, offset
, base_address
);
8370 free (range_entries
);
8375 typedef struct Frame_Chunk
8377 struct Frame_Chunk
*next
;
8378 unsigned char *chunk_start
;
8380 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8381 short int *col_type
;
8384 unsigned int code_factor
;
8388 unsigned int cfa_reg
;
8389 dwarf_vma cfa_offset
;
8391 unsigned char fde_encoding
;
8392 unsigned char cfa_exp
;
8393 unsigned char ptr_size
;
8394 unsigned char segment_size
;
8398 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8399 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8400 static const char *const *dwarf_regnames
;
8401 static unsigned int dwarf_regnames_count
;
8404 /* A marker for a col_type that means this column was never referenced
8405 in the frame info. */
8406 #define DW_CFA_unreferenced (-1)
8408 /* Return 0 if no more space is needed, 1 if more space is needed,
8409 -1 for invalid reg. */
8412 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8414 unsigned int prev
= fc
->ncols
;
8416 if (reg
< (unsigned int) fc
->ncols
)
8419 if (dwarf_regnames_count
> 0
8420 && reg
> dwarf_regnames_count
)
8423 fc
->ncols
= reg
+ 1;
8424 /* PR 17512: file: 10450-2643-0.004.
8425 If reg == -1 then this can happen... */
8429 /* PR 17512: file: 2844a11d. */
8430 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8432 error (_("Unfeasibly large register number: %u\n"), reg
);
8434 /* FIXME: 1024 is an arbitrary limit. Increase it if
8435 we ever encounter a valid binary that exceeds it. */
8439 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
8440 sizeof (short int));
8441 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
8442 /* PR 17512: file:002-10025-0.005. */
8443 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8445 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8451 while (prev
< fc
->ncols
)
8453 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8454 fc
->col_offset
[prev
] = 0;
8460 static const char *const dwarf_regnames_i386
[] =
8462 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8463 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8464 "eip", "eflags", NULL
, /* 8 - 10 */
8465 "st0", "st1", "st2", "st3", /* 11 - 14 */
8466 "st4", "st5", "st6", "st7", /* 15 - 18 */
8467 NULL
, NULL
, /* 19 - 20 */
8468 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8469 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8470 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8471 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8472 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8473 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8474 "tr", "ldtr", /* 48 - 49 */
8475 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8476 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8477 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8478 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8479 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8480 NULL
, NULL
, NULL
, /* 90 - 92 */
8481 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8484 static const char *const dwarf_regnames_iamcu
[] =
8486 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8487 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8488 "eip", "eflags", NULL
, /* 8 - 10 */
8489 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8490 NULL
, NULL
, /* 19 - 20 */
8491 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8492 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8493 NULL
, NULL
, NULL
, /* 37 - 39 */
8494 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8495 "tr", "ldtr", /* 48 - 49 */
8496 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8497 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8498 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8499 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8500 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8501 NULL
, NULL
, NULL
, /* 90 - 92 */
8502 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8506 init_dwarf_regnames_i386 (void)
8508 dwarf_regnames
= dwarf_regnames_i386
;
8509 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8510 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8514 init_dwarf_regnames_iamcu (void)
8516 dwarf_regnames
= dwarf_regnames_iamcu
;
8517 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8518 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8521 static const char *const dwarf_regnames_x86_64
[] =
8523 "rax", "rdx", "rcx", "rbx",
8524 "rsi", "rdi", "rbp", "rsp",
8525 "r8", "r9", "r10", "r11",
8526 "r12", "r13", "r14", "r15",
8528 "xmm0", "xmm1", "xmm2", "xmm3",
8529 "xmm4", "xmm5", "xmm6", "xmm7",
8530 "xmm8", "xmm9", "xmm10", "xmm11",
8531 "xmm12", "xmm13", "xmm14", "xmm15",
8532 "st0", "st1", "st2", "st3",
8533 "st4", "st5", "st6", "st7",
8534 "mm0", "mm1", "mm2", "mm3",
8535 "mm4", "mm5", "mm6", "mm7",
8537 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8538 "fs.base", "gs.base", NULL
, NULL
,
8540 "mxcsr", "fcw", "fsw",
8541 "xmm16", "xmm17", "xmm18", "xmm19",
8542 "xmm20", "xmm21", "xmm22", "xmm23",
8543 "xmm24", "xmm25", "xmm26", "xmm27",
8544 "xmm28", "xmm29", "xmm30", "xmm31",
8545 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8546 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8547 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8548 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8549 NULL
, NULL
, NULL
, /* 115 - 117 */
8550 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8554 init_dwarf_regnames_x86_64 (void)
8556 dwarf_regnames
= dwarf_regnames_x86_64
;
8557 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8558 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8561 static const char *const dwarf_regnames_aarch64
[] =
8563 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8564 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8565 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8566 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8567 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8568 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8569 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8570 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8571 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8572 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8573 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8574 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8575 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8576 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8577 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8578 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8582 init_dwarf_regnames_aarch64 (void)
8584 dwarf_regnames
= dwarf_regnames_aarch64
;
8585 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8586 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8589 static const char *const dwarf_regnames_s390
[] =
8591 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8592 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8593 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8594 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8595 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8596 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8597 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8598 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8599 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8602 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8603 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8607 init_dwarf_regnames_s390 (void)
8609 dwarf_regnames
= dwarf_regnames_s390
;
8610 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8611 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8614 static const char *const dwarf_regnames_riscv
[] =
8616 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8617 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8618 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8619 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8620 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8621 "fs0", "fs1", /* 40 - 41 */
8622 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8623 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8624 "fs10", "fs11", /* 58 - 59 */
8625 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8628 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8629 the large number of CSRs. */
8632 regname_internal_riscv (unsigned int regno
)
8634 const char *name
= NULL
;
8636 /* Lookup in the table first, this covers GPR and FPR. */
8637 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8638 name
= dwarf_regnames_riscv
[regno
];
8639 else if (regno
>= 4096 && regno
<= 8191)
8641 /* This might be a CSR, these live in a sparse number space from 4096
8642 to 8191 These numbers are defined in the RISC-V ELF ABI
8646 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8647 case VALUE + 4096: name = #NAME; break;
8648 #include "opcode/riscv-opc.h"
8653 static char csr_name
[10];
8654 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8665 init_dwarf_regnames_riscv (void)
8667 dwarf_regnames
= NULL
;
8668 dwarf_regnames_count
= 8192;
8669 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8673 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8675 dwarf_regnames_lookup_func
= NULL
;
8680 init_dwarf_regnames_i386 ();
8684 init_dwarf_regnames_iamcu ();
8690 init_dwarf_regnames_x86_64 ();
8694 init_dwarf_regnames_aarch64 ();
8698 init_dwarf_regnames_s390 ();
8702 init_dwarf_regnames_riscv ();
8710 /* Initialize the DWARF register name lookup state based on the
8711 architecture and specific machine type of a BFD. */
8714 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8717 dwarf_regnames_lookup_func
= NULL
;
8724 case bfd_mach_x86_64
:
8725 case bfd_mach_x86_64_intel_syntax
:
8726 case bfd_mach_x64_32
:
8727 case bfd_mach_x64_32_intel_syntax
:
8728 init_dwarf_regnames_x86_64 ();
8732 init_dwarf_regnames_i386 ();
8737 case bfd_arch_iamcu
:
8738 init_dwarf_regnames_iamcu ();
8741 case bfd_arch_aarch64
:
8742 init_dwarf_regnames_aarch64();
8746 init_dwarf_regnames_s390 ();
8749 case bfd_arch_riscv
:
8750 init_dwarf_regnames_riscv ();
8759 regname_internal_by_table_only (unsigned int regno
)
8761 if (dwarf_regnames
!= NULL
8762 && regno
< dwarf_regnames_count
8763 && dwarf_regnames
[regno
] != NULL
)
8764 return dwarf_regnames
[regno
];
8770 regname (unsigned int regno
, int name_only_p
)
8772 static char reg
[64];
8774 const char *name
= NULL
;
8776 if (dwarf_regnames_lookup_func
!= NULL
)
8777 name
= dwarf_regnames_lookup_func (regno
);
8783 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8786 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8791 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8796 if (*max_regs
!= fc
->ncols
)
8797 *max_regs
= fc
->ncols
;
8799 if (*need_col_headers
)
8801 *need_col_headers
= 0;
8803 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8805 for (r
= 0; r
< *max_regs
; r
++)
8806 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8811 printf ("%-5s ", regname (r
, 1));
8817 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8819 strcpy (tmp
, "exp");
8821 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8822 printf ("%-8s ", tmp
);
8824 for (r
= 0; r
< fc
->ncols
; r
++)
8826 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8828 switch (fc
->col_type
[r
])
8830 case DW_CFA_undefined
:
8833 case DW_CFA_same_value
:
8837 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8839 case DW_CFA_val_offset
:
8840 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8842 case DW_CFA_register
:
8843 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8845 case DW_CFA_expression
:
8846 strcpy (tmp
, "exp");
8848 case DW_CFA_val_expression
:
8849 strcpy (tmp
, "vexp");
8852 strcpy (tmp
, "n/a");
8855 printf ("%-5s ", tmp
);
8861 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8863 static unsigned char *
8864 read_cie (unsigned char *start
, unsigned char *end
,
8865 Frame_Chunk
**p_cie
, int *p_version
,
8866 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8870 unsigned char *augmentation_data
= NULL
;
8871 bfd_size_type augmentation_data_len
= 0;
8874 /* PR 17512: file: 001-228113-0.004. */
8878 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8879 memset (fc
, 0, sizeof (Frame_Chunk
));
8881 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8882 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8886 fc
->augmentation
= (char *) start
;
8887 /* PR 17512: file: 001-228113-0.004.
8888 Skip past augmentation name, but avoid running off the end of the data. */
8890 if (* start
++ == '\0')
8894 warn (_("No terminator for augmentation name\n"));
8898 if (strcmp (fc
->augmentation
, "eh") == 0)
8900 if (eh_addr_size
> (size_t) (end
- start
))
8902 start
+= eh_addr_size
;
8907 if (2 > (size_t) (end
- start
))
8909 GET (fc
->ptr_size
, 1);
8910 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8912 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8916 GET (fc
->segment_size
, 1);
8917 /* PR 17512: file: e99d2804. */
8918 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8920 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8924 eh_addr_size
= fc
->ptr_size
;
8928 fc
->ptr_size
= eh_addr_size
;
8929 fc
->segment_size
= 0;
8932 READ_ULEB (fc
->code_factor
, start
, end
);
8933 READ_SLEB (fc
->data_factor
, start
, end
);
8944 READ_ULEB (fc
->ra
, start
, end
);
8947 if (fc
->augmentation
[0] == 'z')
8951 READ_ULEB (augmentation_data_len
, start
, end
);
8952 augmentation_data
= start
;
8953 /* PR 17512: file: 11042-2589-0.004. */
8954 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8956 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8957 dwarf_vmatoa ("x", augmentation_data_len
),
8958 (unsigned long) (end
- start
));
8961 start
+= augmentation_data_len
;
8964 if (augmentation_data_len
)
8968 unsigned char *qend
;
8970 p
= (unsigned char *) fc
->augmentation
+ 1;
8971 q
= augmentation_data
;
8972 qend
= q
+ augmentation_data_len
;
8974 while (p
< end
&& q
< qend
)
8979 q
+= 1 + size_of_encoded_value (*q
);
8981 fc
->fde_encoding
= *q
++;
8990 /* Note - it is OK if this loop terminates with q < qend.
8991 Padding may have been inserted to align the end of the CIE. */
8996 *p_version
= version
;
8999 *p_aug_len
= augmentation_data_len
;
9000 *p_aug
= augmentation_data
;
9005 free (fc
->col_offset
);
9006 free (fc
->col_type
);
9011 /* Prints out the contents on the DATA array formatted as unsigned bytes.
9012 If do_wide is not enabled, then formats the output to fit into 80 columns.
9013 PRINTED contains the number of characters already written to the current
9017 display_data (bfd_size_type printed
,
9018 const unsigned char * data
,
9019 const bfd_size_type len
)
9021 if (do_wide
|| len
< ((80 - printed
) / 3))
9022 for (printed
= 0; printed
< len
; ++printed
)
9023 printf (" %02x", data
[printed
]);
9026 for (printed
= 0; printed
< len
; ++printed
)
9028 if (printed
% (80 / 3) == 0)
9030 printf (" %02x", data
[printed
]);
9035 /* Prints out the contents on the augmentation data array.
9036 If do_wide is not enabled, then formats the output to fit into 80 columns. */
9039 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
9043 i
= printf (_(" Augmentation data: "));
9044 display_data (i
, data
, len
);
9048 display_debug_frames (struct dwarf_section
*section
,
9049 void *file ATTRIBUTE_UNUSED
)
9051 unsigned char *start
= section
->start
;
9052 unsigned char *end
= start
+ section
->size
;
9053 unsigned char *section_start
= start
;
9054 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
9055 Frame_Chunk
*remembered_state
= NULL
;
9057 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
9058 unsigned int max_regs
= 0;
9059 const char *bad_reg
= _("bad register: ");
9060 unsigned int saved_eh_addr_size
= eh_addr_size
;
9062 introduce (section
, false);
9066 unsigned char *saved_start
;
9067 unsigned char *block_end
;
9072 int need_col_headers
= 1;
9073 unsigned char *augmentation_data
= NULL
;
9074 bfd_size_type augmentation_data_len
= 0;
9075 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9076 unsigned int offset_size
;
9078 static Frame_Chunk fde_fc
;
9080 saved_start
= start
;
9082 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9086 printf ("\n%08lx ZERO terminator\n\n",
9087 (unsigned long)(saved_start
- section_start
));
9088 /* Skip any zero terminators that directly follow.
9089 A corrupt section size could have loaded a whole
9090 slew of zero filled memory bytes. eg
9091 PR 17512: file: 070-19381-0.004. */
9092 while (start
< end
&& * start
== 0)
9097 if (length
== 0xffffffff)
9099 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9105 if (length
> (size_t) (end
- start
))
9107 warn ("Invalid length 0x%s in FDE at %#08lx\n",
9108 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
9109 (unsigned long) (saved_start
- section_start
));
9113 block_end
= start
+ length
;
9115 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9117 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9118 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9123 start
= read_cie (start
, block_end
, &cie
, &version
,
9124 &augmentation_data_len
, &augmentation_data
);
9125 /* PR 17512: file: 027-135133-0.005. */
9132 fc
->chunk_start
= saved_start
;
9133 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9136 if (frame_need_space (fc
, mreg
) < 0)
9138 if (fc
->fde_encoding
)
9139 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9141 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
9142 print_dwarf_vma (length
, fc
->ptr_size
);
9143 print_dwarf_vma (cie_id
, offset_size
);
9145 if (do_debug_frames_interp
)
9147 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9148 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9153 printf (" Version: %d\n", version
);
9154 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9157 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9158 printf (" Segment Size: %u\n", fc
->segment_size
);
9160 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9161 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9162 printf (" Return address column: %d\n", fc
->ra
);
9164 if (augmentation_data_len
)
9165 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9172 unsigned char *look_for
;
9173 unsigned long segment_selector
;
9179 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
9180 cie_off
= (cie_off
^ sign
) - sign
;
9181 cie_off
= start
- 4 - section_start
- cie_off
;
9184 look_for
= section_start
+ cie_off
;
9185 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
9187 for (cie
= chunks
; cie
; cie
= cie
->next
)
9188 if (cie
->chunk_start
== look_for
)
9191 else if (cie_off
>= section
->size
)
9195 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9196 if (cie
->chunk_start
== look_for
)
9200 unsigned int off_size
;
9201 unsigned char *cie_scan
;
9203 cie_scan
= look_for
;
9205 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9206 if (length
== 0xffffffff)
9208 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9211 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9214 unsigned char *cie_end
= cie_scan
+ length
;
9216 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9220 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9221 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9226 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9227 &augmentation_data_len
, &augmentation_data
);
9228 /* PR 17512: file: 3450-2098-0.004. */
9231 warn (_("Failed to read CIE information\n"));
9234 cie
->next
= forward_refs
;
9236 cie
->chunk_start
= look_for
;
9237 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9240 if (frame_need_space (cie
, mreg
) < 0)
9242 warn (_("Invalid max register\n"));
9245 if (cie
->fde_encoding
)
9247 = size_of_encoded_value (cie
->fde_encoding
);
9254 memset (fc
, 0, sizeof (Frame_Chunk
));
9259 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
9260 fc
->col_offset
= (int *) xmalloc (sizeof (int));
9261 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9263 warn (_("Invalid max register\n"));
9267 fc
->augmentation
= "";
9268 fc
->fde_encoding
= 0;
9269 fc
->ptr_size
= eh_addr_size
;
9270 fc
->segment_size
= 0;
9274 fc
->ncols
= cie
->ncols
;
9275 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
9276 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
9277 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
9278 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
9279 fc
->augmentation
= cie
->augmentation
;
9280 fc
->ptr_size
= cie
->ptr_size
;
9281 eh_addr_size
= cie
->ptr_size
;
9282 fc
->segment_size
= cie
->segment_size
;
9283 fc
->code_factor
= cie
->code_factor
;
9284 fc
->data_factor
= cie
->data_factor
;
9285 fc
->cfa_reg
= cie
->cfa_reg
;
9286 fc
->cfa_offset
= cie
->cfa_offset
;
9288 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9290 warn (_("Invalid max register\n"));
9293 fc
->fde_encoding
= cie
->fde_encoding
;
9296 if (fc
->fde_encoding
)
9297 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9299 segment_selector
= 0;
9300 if (fc
->segment_size
)
9302 if (fc
->segment_size
> sizeof (segment_selector
))
9304 /* PR 17512: file: 9e196b3e. */
9305 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9306 fc
->segment_size
= 4;
9308 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9309 fc
->segment_size
, block_end
);
9312 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9315 /* FIXME: It appears that sometimes the final pc_range value is
9316 encoded in less than encoded_ptr_size bytes. See the x86_64
9317 run of the "objcopy on compressed debug sections" test for an
9319 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9322 if (cie
->augmentation
[0] == 'z')
9324 READ_ULEB (augmentation_data_len
, start
, block_end
);
9325 augmentation_data
= start
;
9326 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9327 if (augmentation_data_len
> (bfd_size_type
) (block_end
- start
))
9329 warn (_("Augmentation data too long: 0x%s, "
9330 "expected at most %#lx\n"),
9331 dwarf_vmatoa ("x", augmentation_data_len
),
9332 (unsigned long) (block_end
- start
));
9334 augmentation_data
= NULL
;
9335 augmentation_data_len
= 0;
9337 start
+= augmentation_data_len
;
9340 printf ("\n%08lx %s %s FDE ",
9341 (unsigned long)(saved_start
- section_start
),
9342 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
9343 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
));
9345 if (cie
->chunk_start
)
9346 printf ("cie=%08lx",
9347 (unsigned long) (cie
->chunk_start
- section_start
));
9349 /* Ideally translate "invalid " to 8 chars, trailing space
9351 printf (_("cie=invalid "));
9354 if (fc
->segment_size
)
9355 printf ("%04lx:", segment_selector
);
9358 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
9359 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
9361 if (! do_debug_frames_interp
&& augmentation_data_len
)
9363 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9368 /* At this point, fc is the current chunk, cie (if any) is set, and
9369 we're about to interpret instructions for the chunk. */
9370 /* ??? At present we need to do this always, since this sizes the
9371 fc->col_type and fc->col_offset arrays, which we write into always.
9372 We should probably split the interpreted and non-interpreted bits
9373 into two different routines, since there's so much that doesn't
9374 really overlap between them. */
9375 if (1 || do_debug_frames_interp
)
9377 /* Start by making a pass over the chunk, allocating storage
9378 and taking note of what registers are used. */
9379 unsigned char *tmp
= start
;
9381 while (start
< block_end
)
9383 unsigned int reg
, op
, opa
;
9391 /* Warning: if you add any more cases to this switch, be
9392 sure to add them to the corresponding switch below. */
9396 case DW_CFA_advance_loc
:
9399 SKIP_ULEB (start
, block_end
);
9402 case DW_CFA_restore
:
9405 case DW_CFA_set_loc
:
9406 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9409 start
+= encoded_ptr_size
;
9411 case DW_CFA_advance_loc1
:
9412 if ((size_t) (block_end
- start
) < 1)
9417 case DW_CFA_advance_loc2
:
9418 if ((size_t) (block_end
- start
) < 2)
9423 case DW_CFA_advance_loc4
:
9424 if ((size_t) (block_end
- start
) < 4)
9429 case DW_CFA_offset_extended
:
9430 case DW_CFA_val_offset
:
9431 READ_ULEB (reg
, start
, block_end
);
9432 SKIP_ULEB (start
, block_end
);
9434 case DW_CFA_restore_extended
:
9435 READ_ULEB (reg
, start
, block_end
);
9437 case DW_CFA_undefined
:
9438 READ_ULEB (reg
, start
, block_end
);
9440 case DW_CFA_same_value
:
9441 READ_ULEB (reg
, start
, block_end
);
9443 case DW_CFA_register
:
9444 READ_ULEB (reg
, start
, block_end
);
9445 SKIP_ULEB (start
, block_end
);
9447 case DW_CFA_def_cfa
:
9448 SKIP_ULEB (start
, block_end
);
9449 SKIP_ULEB (start
, block_end
);
9451 case DW_CFA_def_cfa_register
:
9452 SKIP_ULEB (start
, block_end
);
9454 case DW_CFA_def_cfa_offset
:
9455 SKIP_ULEB (start
, block_end
);
9457 case DW_CFA_def_cfa_expression
:
9458 READ_ULEB (temp
, start
, block_end
);
9459 if ((size_t) (block_end
- start
) < temp
)
9464 case DW_CFA_expression
:
9465 case DW_CFA_val_expression
:
9466 READ_ULEB (reg
, start
, block_end
);
9467 READ_ULEB (temp
, start
, block_end
);
9468 if ((size_t) (block_end
- start
) < temp
)
9473 case DW_CFA_offset_extended_sf
:
9474 case DW_CFA_val_offset_sf
:
9475 READ_ULEB (reg
, start
, block_end
);
9476 SKIP_SLEB (start
, block_end
);
9478 case DW_CFA_def_cfa_sf
:
9479 SKIP_ULEB (start
, block_end
);
9480 SKIP_SLEB (start
, block_end
);
9482 case DW_CFA_def_cfa_offset_sf
:
9483 SKIP_SLEB (start
, block_end
);
9485 case DW_CFA_MIPS_advance_loc8
:
9486 if ((size_t) (block_end
- start
) < 8)
9491 case DW_CFA_GNU_args_size
:
9492 SKIP_ULEB (start
, block_end
);
9494 case DW_CFA_GNU_negative_offset_extended
:
9495 READ_ULEB (reg
, start
, block_end
);
9496 SKIP_ULEB (start
, block_end
);
9501 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9503 /* Don't leave any reg as DW_CFA_unreferenced so
9504 that frame_display_row prints name of regs in
9505 header, and all referenced regs in each line. */
9506 if (reg
>= cie
->ncols
9507 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9508 fc
->col_type
[reg
] = DW_CFA_undefined
;
9510 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9518 /* Now we know what registers are used, make a second pass over
9519 the chunk, this time actually printing out the info. */
9521 while (start
< block_end
)
9524 unsigned long ul
, roffs
;
9525 /* Note: It is tempting to use an unsigned long for 'reg' but there
9526 are various functions, notably frame_space_needed() that assume that
9527 reg is an unsigned int. */
9532 const char *reg_prefix
= "";
9539 /* Make a note if something other than DW_CFA_nop happens. */
9540 if (op
!= DW_CFA_nop
)
9543 /* Warning: if you add any more cases to this switch, be
9544 sure to add them to the corresponding switch above. */
9547 case DW_CFA_advance_loc
:
9548 if (do_debug_frames_interp
)
9549 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9551 printf (" DW_CFA_advance_loc: %d to %s\n",
9552 opa
* fc
->code_factor
,
9553 dwarf_vmatoa_1 (NULL
,
9554 fc
->pc_begin
+ opa
* fc
->code_factor
,
9556 fc
->pc_begin
+= opa
* fc
->code_factor
;
9560 READ_ULEB (roffs
, start
, block_end
);
9561 if (opa
>= fc
->ncols
)
9562 reg_prefix
= bad_reg
;
9563 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9564 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9565 reg_prefix
, regname (opa
, 0),
9566 roffs
* fc
->data_factor
);
9567 if (*reg_prefix
== '\0')
9569 fc
->col_type
[opa
] = DW_CFA_offset
;
9570 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9574 case DW_CFA_restore
:
9575 if (opa
>= fc
->ncols
)
9576 reg_prefix
= bad_reg
;
9577 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9578 printf (" DW_CFA_restore: %s%s\n",
9579 reg_prefix
, regname (opa
, 0));
9580 if (*reg_prefix
!= '\0')
9583 if (opa
>= cie
->ncols
9584 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9586 fc
->col_type
[opa
] = DW_CFA_undefined
;
9587 fc
->col_offset
[opa
] = 0;
9591 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9592 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9596 case DW_CFA_set_loc
:
9597 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9599 if (do_debug_frames_interp
)
9600 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9602 printf (" DW_CFA_set_loc: %s\n",
9603 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9607 case DW_CFA_advance_loc1
:
9608 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9609 if (do_debug_frames_interp
)
9610 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9612 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9613 (unsigned long) (ofs
* fc
->code_factor
),
9614 dwarf_vmatoa_1 (NULL
,
9615 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9617 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9620 case DW_CFA_advance_loc2
:
9621 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9622 if (do_debug_frames_interp
)
9623 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9625 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9626 (unsigned long) (ofs
* fc
->code_factor
),
9627 dwarf_vmatoa_1 (NULL
,
9628 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9630 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9633 case DW_CFA_advance_loc4
:
9634 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9635 if (do_debug_frames_interp
)
9636 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9638 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9639 (unsigned long) (ofs
* fc
->code_factor
),
9640 dwarf_vmatoa_1 (NULL
,
9641 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9643 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9646 case DW_CFA_offset_extended
:
9647 READ_ULEB (reg
, start
, block_end
);
9648 READ_ULEB (roffs
, start
, block_end
);
9649 if (reg
>= fc
->ncols
)
9650 reg_prefix
= bad_reg
;
9651 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9652 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9653 reg_prefix
, regname (reg
, 0),
9654 roffs
* fc
->data_factor
);
9655 if (*reg_prefix
== '\0')
9657 fc
->col_type
[reg
] = DW_CFA_offset
;
9658 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9662 case DW_CFA_val_offset
:
9663 READ_ULEB (reg
, start
, block_end
);
9664 READ_ULEB (roffs
, start
, block_end
);
9665 if (reg
>= fc
->ncols
)
9666 reg_prefix
= bad_reg
;
9667 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9668 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9669 reg_prefix
, regname (reg
, 0),
9670 roffs
* fc
->data_factor
);
9671 if (*reg_prefix
== '\0')
9673 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9674 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9678 case DW_CFA_restore_extended
:
9679 READ_ULEB (reg
, start
, block_end
);
9680 if (reg
>= fc
->ncols
)
9681 reg_prefix
= bad_reg
;
9682 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9683 printf (" DW_CFA_restore_extended: %s%s\n",
9684 reg_prefix
, regname (reg
, 0));
9685 if (*reg_prefix
!= '\0')
9688 if (reg
>= cie
->ncols
9689 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9691 fc
->col_type
[reg
] = DW_CFA_undefined
;
9692 fc
->col_offset
[reg
] = 0;
9696 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9697 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9701 case DW_CFA_undefined
:
9702 READ_ULEB (reg
, start
, block_end
);
9703 if (reg
>= fc
->ncols
)
9704 reg_prefix
= bad_reg
;
9705 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9706 printf (" DW_CFA_undefined: %s%s\n",
9707 reg_prefix
, regname (reg
, 0));
9708 if (*reg_prefix
== '\0')
9710 fc
->col_type
[reg
] = DW_CFA_undefined
;
9711 fc
->col_offset
[reg
] = 0;
9715 case DW_CFA_same_value
:
9716 READ_ULEB (reg
, start
, block_end
);
9717 if (reg
>= fc
->ncols
)
9718 reg_prefix
= bad_reg
;
9719 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9720 printf (" DW_CFA_same_value: %s%s\n",
9721 reg_prefix
, regname (reg
, 0));
9722 if (*reg_prefix
== '\0')
9724 fc
->col_type
[reg
] = DW_CFA_same_value
;
9725 fc
->col_offset
[reg
] = 0;
9729 case DW_CFA_register
:
9730 READ_ULEB (reg
, start
, block_end
);
9731 READ_ULEB (roffs
, start
, block_end
);
9732 if (reg
>= fc
->ncols
)
9733 reg_prefix
= bad_reg
;
9734 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9736 printf (" DW_CFA_register: %s%s in ",
9737 reg_prefix
, regname (reg
, 0));
9738 puts (regname (roffs
, 0));
9740 if (*reg_prefix
== '\0')
9742 fc
->col_type
[reg
] = DW_CFA_register
;
9743 fc
->col_offset
[reg
] = roffs
;
9747 case DW_CFA_remember_state
:
9748 if (! do_debug_frames_interp
)
9749 printf (" DW_CFA_remember_state\n");
9750 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9751 rs
->cfa_offset
= fc
->cfa_offset
;
9752 rs
->cfa_reg
= fc
->cfa_reg
;
9754 rs
->cfa_exp
= fc
->cfa_exp
;
9755 rs
->ncols
= fc
->ncols
;
9756 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9757 sizeof (* rs
->col_type
));
9758 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9759 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9760 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9761 rs
->next
= remembered_state
;
9762 remembered_state
= rs
;
9765 case DW_CFA_restore_state
:
9766 if (! do_debug_frames_interp
)
9767 printf (" DW_CFA_restore_state\n");
9768 rs
= remembered_state
;
9771 remembered_state
= rs
->next
;
9772 fc
->cfa_offset
= rs
->cfa_offset
;
9773 fc
->cfa_reg
= rs
->cfa_reg
;
9775 fc
->cfa_exp
= rs
->cfa_exp
;
9776 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9778 warn (_("Invalid column number in saved frame state\n"));
9782 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9783 memcpy (fc
->col_offset
, rs
->col_offset
,
9784 rs
->ncols
* sizeof (* rs
->col_offset
));
9785 free (rs
->col_type
);
9786 free (rs
->col_offset
);
9789 else if (do_debug_frames_interp
)
9790 printf ("Mismatched DW_CFA_restore_state\n");
9793 case DW_CFA_def_cfa
:
9794 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9795 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9797 if (! do_debug_frames_interp
)
9798 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9799 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9802 case DW_CFA_def_cfa_register
:
9803 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9805 if (! do_debug_frames_interp
)
9806 printf (" DW_CFA_def_cfa_register: %s\n",
9807 regname (fc
->cfa_reg
, 0));
9810 case DW_CFA_def_cfa_offset
:
9811 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9812 if (! do_debug_frames_interp
)
9813 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9817 if (! do_debug_frames_interp
)
9818 printf (" DW_CFA_nop\n");
9821 case DW_CFA_def_cfa_expression
:
9822 READ_ULEB (ul
, start
, block_end
);
9823 if (ul
> (size_t) (block_end
- start
))
9825 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9828 if (! do_debug_frames_interp
)
9830 printf (" DW_CFA_def_cfa_expression (");
9831 decode_location_expression (start
, eh_addr_size
, 0, -1,
9839 case DW_CFA_expression
:
9840 READ_ULEB (reg
, start
, block_end
);
9841 READ_ULEB (ul
, start
, block_end
);
9842 if (reg
>= fc
->ncols
)
9843 reg_prefix
= bad_reg
;
9844 /* PR 17512: file: 069-133014-0.006. */
9845 /* PR 17512: file: 98c02eb4. */
9846 if (ul
> (size_t) (block_end
- start
))
9848 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9851 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9853 printf (" DW_CFA_expression: %s%s (",
9854 reg_prefix
, regname (reg
, 0));
9855 decode_location_expression (start
, eh_addr_size
, 0, -1,
9859 if (*reg_prefix
== '\0')
9860 fc
->col_type
[reg
] = DW_CFA_expression
;
9864 case DW_CFA_val_expression
:
9865 READ_ULEB (reg
, start
, block_end
);
9866 READ_ULEB (ul
, start
, block_end
);
9867 if (reg
>= fc
->ncols
)
9868 reg_prefix
= bad_reg
;
9869 if (ul
> (size_t) (block_end
- start
))
9871 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9874 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9876 printf (" DW_CFA_val_expression: %s%s (",
9877 reg_prefix
, regname (reg
, 0));
9878 decode_location_expression (start
, eh_addr_size
, 0, -1,
9882 if (*reg_prefix
== '\0')
9883 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9887 case DW_CFA_offset_extended_sf
:
9888 READ_ULEB (reg
, start
, block_end
);
9889 READ_SLEB (l
, start
, block_end
);
9890 if (reg
>= fc
->ncols
)
9891 reg_prefix
= bad_reg
;
9892 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9893 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9894 reg_prefix
, regname (reg
, 0),
9895 (long)(l
* fc
->data_factor
));
9896 if (*reg_prefix
== '\0')
9898 fc
->col_type
[reg
] = DW_CFA_offset
;
9899 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9903 case DW_CFA_val_offset_sf
:
9904 READ_ULEB (reg
, start
, block_end
);
9905 READ_SLEB (l
, start
, block_end
);
9906 if (reg
>= fc
->ncols
)
9907 reg_prefix
= bad_reg
;
9908 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9909 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9910 reg_prefix
, regname (reg
, 0),
9911 (long)(l
* fc
->data_factor
));
9912 if (*reg_prefix
== '\0')
9914 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9915 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9919 case DW_CFA_def_cfa_sf
:
9920 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9921 READ_SLEB (l
, start
, block_end
);
9922 l
*= fc
->data_factor
;
9925 if (! do_debug_frames_interp
)
9926 printf (" DW_CFA_def_cfa_sf: %s ofs %ld\n",
9927 regname (fc
->cfa_reg
, 0), (long) l
);
9930 case DW_CFA_def_cfa_offset_sf
:
9931 READ_SLEB (l
, start
, block_end
);
9932 l
*= fc
->data_factor
;
9934 if (! do_debug_frames_interp
)
9935 printf (" DW_CFA_def_cfa_offset_sf: %ld\n", (long) l
);
9938 case DW_CFA_MIPS_advance_loc8
:
9939 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9940 if (do_debug_frames_interp
)
9941 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9943 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9944 (unsigned long) (ofs
* fc
->code_factor
),
9945 dwarf_vmatoa_1 (NULL
,
9946 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9948 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9951 case DW_CFA_GNU_window_save
:
9952 if (! do_debug_frames_interp
)
9953 printf (" DW_CFA_GNU_window_save\n");
9956 case DW_CFA_GNU_args_size
:
9957 READ_ULEB (ul
, start
, block_end
);
9958 if (! do_debug_frames_interp
)
9959 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9962 case DW_CFA_GNU_negative_offset_extended
:
9963 READ_ULEB (reg
, start
, block_end
);
9964 READ_SLEB (l
, start
, block_end
);
9966 if (reg
>= fc
->ncols
)
9967 reg_prefix
= bad_reg
;
9968 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9969 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9970 reg_prefix
, regname (reg
, 0),
9971 (long)(l
* fc
->data_factor
));
9972 if (*reg_prefix
== '\0')
9974 fc
->col_type
[reg
] = DW_CFA_offset
;
9975 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9980 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9981 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9983 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9988 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9989 if (do_debug_frames_interp
&& ! all_nops
)
9990 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9992 if (fde_fc
.col_type
!= NULL
)
9994 free (fde_fc
.col_type
);
9995 fde_fc
.col_type
= NULL
;
9997 if (fde_fc
.col_offset
!= NULL
)
9999 free (fde_fc
.col_offset
);
10000 fde_fc
.col_offset
= NULL
;
10004 eh_addr_size
= saved_eh_addr_size
;
10009 while (remembered_state
!= NULL
)
10011 rs
= remembered_state
;
10012 remembered_state
= rs
->next
;
10013 free (rs
->col_type
);
10014 free (rs
->col_offset
);
10015 rs
->next
= NULL
; /* Paranoia. */
10019 while (chunks
!= NULL
)
10023 free (rs
->col_type
);
10024 free (rs
->col_offset
);
10025 rs
->next
= NULL
; /* Paranoia. */
10029 while (forward_refs
!= NULL
)
10032 forward_refs
= rs
->next
;
10033 free (rs
->col_type
);
10034 free (rs
->col_offset
);
10035 rs
->next
= NULL
; /* Paranoia. */
10045 display_debug_names (struct dwarf_section
*section
, void *file
)
10047 unsigned char *hdrptr
= section
->start
;
10048 dwarf_vma unit_length
;
10049 unsigned char *unit_start
;
10050 const unsigned char *const section_end
= section
->start
+ section
->size
;
10051 unsigned char *unit_end
;
10053 introduce (section
, false);
10055 load_debug_section_with_follow (str
, file
);
10057 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
10059 unsigned int offset_size
;
10060 uint16_t dwarf_version
, padding
;
10061 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10062 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10063 uint32_t augmentation_string_size
;
10065 bool augmentation_printable
;
10066 const char *augmentation_string
;
10069 unit_start
= hdrptr
;
10071 /* Get and check the length of the block. */
10072 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10074 if (unit_length
== 0xffffffff)
10076 /* This section is 64-bit DWARF. */
10077 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10083 if (unit_length
> (size_t) (section_end
- hdrptr
)
10084 || unit_length
< 2 + 2 + 4 * 7)
10087 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
10089 (unsigned long) (unit_start
- section
->start
),
10090 dwarf_vmatoa ("x", unit_length
));
10093 unit_end
= hdrptr
+ unit_length
;
10095 /* Get and check the version number. */
10096 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10097 printf (_("Version %ld\n"), (long) dwarf_version
);
10099 /* Prior versions did not exist, and future versions may not be
10100 backwards compatible. */
10101 if (dwarf_version
!= 5)
10103 warn (_("Only DWARF version 5 .debug_names "
10104 "is currently supported.\n"));
10108 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10110 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10113 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10114 if (comp_unit_count
== 0)
10115 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10117 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10118 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10119 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10120 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10121 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10123 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10124 if (augmentation_string_size
% 4 != 0)
10126 warn (_("Augmentation string length %u must be rounded up "
10127 "to a multiple of 4 in .debug_names.\n"),
10128 augmentation_string_size
);
10129 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10131 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10134 printf (_("Augmentation string:"));
10136 augmentation_printable
= true;
10137 augmentation_string
= (const char *) hdrptr
;
10139 for (i
= 0; i
< augmentation_string_size
; i
++)
10143 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10144 printf (" %02x", uc
);
10146 if (uc
!= 0 && !ISPRINT (uc
))
10147 augmentation_printable
= false;
10150 if (augmentation_printable
)
10154 i
< augmentation_string_size
&& augmentation_string
[i
];
10156 putchar (augmentation_string
[i
]);
10161 printf (_("CU table:\n"));
10162 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10163 || total
> (size_t) (unit_end
- hdrptr
))
10165 for (i
= 0; i
< comp_unit_count
; i
++)
10167 uint64_t cu_offset
;
10169 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10170 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
10174 printf (_("TU table:\n"));
10175 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10176 || total
> (size_t) (unit_end
- hdrptr
))
10178 for (i
= 0; i
< local_type_unit_count
; i
++)
10180 uint64_t tu_offset
;
10182 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10183 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
10187 printf (_("Foreign TU table:\n"));
10188 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10189 || total
> (size_t) (unit_end
- hdrptr
))
10191 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10193 uint64_t signature
;
10195 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10196 printf (_("[%3u] "), i
);
10197 print_dwarf_vma (signature
, 8);
10202 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10203 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10204 + abbrev_table_size
);
10205 if (xtra
> (size_t) (unit_end
- hdrptr
))
10207 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
10208 "for unit 0x%lx in the debug_names\n"),
10210 (long) (unit_end
- unit_start
),
10211 (long) (unit_start
- section
->start
));
10214 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10215 hdrptr
+= bucket_count
* sizeof (uint32_t);
10216 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10217 hdrptr
+= name_count
* sizeof (uint32_t);
10218 unsigned char *const name_table_string_offsets
= hdrptr
;
10219 hdrptr
+= name_count
* offset_size
;
10220 unsigned char *const name_table_entry_offsets
= hdrptr
;
10221 hdrptr
+= name_count
* offset_size
;
10222 unsigned char *const abbrev_table
= hdrptr
;
10223 hdrptr
+= abbrev_table_size
;
10224 const unsigned char *const abbrev_table_end
= hdrptr
;
10225 unsigned char *const entry_pool
= hdrptr
;
10227 size_t buckets_filled
= 0;
10229 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10231 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10236 printf (ngettext ("Used %zu of %lu bucket.\n",
10237 "Used %zu of %lu buckets.\n",
10239 buckets_filled
, (unsigned long) bucket_count
);
10241 if (bucket_count
!= 0)
10243 uint32_t hash_prev
= 0;
10244 size_t hash_clash_count
= 0;
10245 size_t longest_clash
= 0;
10246 size_t this_length
= 0;
10248 for (hashi
= 0; hashi
< name_count
; hashi
++)
10250 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10254 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10256 ++hash_clash_count
;
10258 longest_clash
= MAX (longest_clash
, this_length
);
10263 hash_prev
= hash_this
;
10265 printf (_("Out of %lu items there are %zu bucket clashes"
10266 " (longest of %zu entries).\n"),
10267 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
10269 if (name_count
!= buckets_filled
+ hash_clash_count
)
10270 warn (_("The name_count (%lu) is not the same as the used bucket_count (%lu) + the hash clash count (%lu)"),
10271 (unsigned long) name_count
,
10272 (unsigned long) buckets_filled
,
10273 (unsigned long) hash_clash_count
);
10276 struct abbrev_lookup_entry
10278 dwarf_vma abbrev_tag
;
10279 unsigned char *abbrev_lookup_ptr
;
10281 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10282 size_t abbrev_lookup_used
= 0;
10283 size_t abbrev_lookup_allocated
= 0;
10285 unsigned char *abbrevptr
= abbrev_table
;
10288 dwarf_vma abbrev_tag
;
10290 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10291 if (abbrev_tag
== 0)
10293 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10295 abbrev_lookup_allocated
= MAX (0x100,
10296 abbrev_lookup_allocated
* 2);
10297 abbrev_lookup
= xrealloc (abbrev_lookup
,
10298 (abbrev_lookup_allocated
10299 * sizeof (*abbrev_lookup
)));
10301 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10302 struct abbrev_lookup_entry
*entry
;
10303 for (entry
= abbrev_lookup
;
10304 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10306 if (entry
->abbrev_tag
== abbrev_tag
)
10308 warn (_("Duplicate abbreviation tag %lu "
10309 "in unit 0x%lx in the debug_names\n"),
10310 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
10313 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10314 entry
->abbrev_tag
= abbrev_tag
;
10315 entry
->abbrev_lookup_ptr
= abbrevptr
;
10317 /* Skip DWARF tag. */
10318 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10321 dwarf_vma xindex
, form
;
10323 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10324 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10325 if (xindex
== 0 && form
== 0)
10330 printf (_("\nSymbol table:\n"));
10332 for (namei
= 0; namei
< name_count
; ++namei
)
10334 uint64_t string_offset
, entry_offset
;
10337 p
= name_table_string_offsets
+ namei
* offset_size
;
10338 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10339 p
= name_table_entry_offsets
+ namei
* offset_size
;
10340 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10342 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10343 fetch_indirect_string (string_offset
));
10345 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10347 /* We need to scan first whether there is a single or multiple
10348 entries. TAGNO is -2 for the first entry, it is -1 for the
10349 initial tag read of the second entry, then it becomes 0 for the
10350 first entry for real printing etc. */
10352 /* Initialize it due to a false compiler warning. */
10353 dwarf_vma second_abbrev_tag
= -1;
10356 dwarf_vma abbrev_tag
;
10357 dwarf_vma dwarf_tag
;
10358 const struct abbrev_lookup_entry
*entry
;
10360 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10363 second_abbrev_tag
= abbrev_tag
;
10365 entryptr
= entry_pool
+ entry_offset
;
10368 if (abbrev_tag
== 0)
10372 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10373 (unsigned long) abbrev_tag
);
10375 for (entry
= abbrev_lookup
;
10376 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10378 if (entry
->abbrev_tag
== abbrev_tag
)
10380 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10382 warn (_("Undefined abbreviation tag %lu "
10383 "in unit 0x%lx in the debug_names\n"),
10385 (long) (unit_start
- section
->start
));
10388 abbrevptr
= entry
->abbrev_lookup_ptr
;
10389 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10391 printf (" %s", get_TAG_name (dwarf_tag
));
10394 dwarf_vma xindex
, form
;
10396 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10397 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10398 if (xindex
== 0 && form
== 0)
10402 printf (" %s", get_IDX_name (xindex
));
10403 entryptr
= read_and_display_attr_value (0, form
, 0,
10404 unit_start
, entryptr
, unit_end
,
10406 dwarf_version
, NULL
,
10407 (tagno
< 0), section
,
10413 printf (_(" <no entries>"));
10417 free (abbrev_lookup
);
10424 display_debug_links (struct dwarf_section
* section
,
10425 void * file ATTRIBUTE_UNUSED
)
10427 const unsigned char * filename
;
10428 unsigned int filelen
;
10430 introduce (section
, false);
10432 /* The .gnu_debuglink section is formatted as:
10433 (c-string) Filename.
10434 (padding) If needed to reach a 4 byte boundary.
10435 (uint32_t) CRC32 value.
10437 The .gun_debugaltlink section is formatted as:
10438 (c-string) Filename.
10439 (binary) Build-ID. */
10441 filename
= section
->start
;
10442 filelen
= strnlen ((const char *) filename
, section
->size
);
10443 if (filelen
== section
->size
)
10445 warn (_("The debuglink filename is corrupt/missing\n"));
10449 printf (_(" Separate debug info file: %s\n"), filename
);
10451 if (startswith (section
->name
, ".gnu_debuglink"))
10453 unsigned int crc32
;
10454 unsigned int crc_offset
;
10456 crc_offset
= filelen
+ 1;
10457 crc_offset
= (crc_offset
+ 3) & ~3;
10458 if (crc_offset
+ 4 > section
->size
)
10460 warn (_("CRC offset missing/truncated\n"));
10464 crc32
= byte_get (filename
+ crc_offset
, 4);
10466 printf (_(" CRC value: %#x\n"), crc32
);
10468 if (crc_offset
+ 4 < section
->size
)
10470 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10471 (long)(section
->size
- (crc_offset
+ 4)));
10475 else /* startswith (section->name, ".gnu_debugaltlink") */
10477 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
10478 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
10479 bfd_size_type printed
;
10481 /* FIXME: Should we support smaller build-id notes ? */
10482 if (build_id_len
< 0x14)
10484 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
10488 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
10489 display_data (printed
, build_id
, build_id_len
);
10498 display_gdb_index (struct dwarf_section
*section
,
10499 void *file ATTRIBUTE_UNUSED
)
10501 unsigned char *start
= section
->start
;
10503 uint32_t cu_list_offset
, tu_list_offset
;
10504 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10505 unsigned int cu_list_elements
, tu_list_elements
;
10506 unsigned int address_table_elements
, symbol_table_slots
;
10507 unsigned char *cu_list
, *tu_list
;
10508 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10511 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10513 introduce (section
, false);
10515 if (section
->size
< 6 * sizeof (uint32_t))
10517 warn (_("Truncated header in the %s section.\n"), section
->name
);
10521 version
= byte_get_little_endian (start
, 4);
10522 printf (_("Version %ld\n"), (long) version
);
10524 /* Prior versions are obsolete, and future versions may not be
10525 backwards compatible. */
10526 if (version
< 3 || version
> 8)
10528 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10532 warn (_("The address table data in version 3 may be wrong.\n"));
10534 warn (_("Version 4 does not support case insensitive lookups.\n"));
10536 warn (_("Version 5 does not include inlined functions.\n"));
10538 warn (_("Version 6 does not include symbol attributes.\n"));
10539 /* Version 7 indices generated by Gold have bad type unit references,
10540 PR binutils/15021. But we don't know if the index was generated by
10541 Gold or not, so to avoid worrying users with gdb-generated indices
10542 we say nothing for version 7 here. */
10544 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10545 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10546 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10547 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10548 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10550 if (cu_list_offset
> section
->size
10551 || tu_list_offset
> section
->size
10552 || address_table_offset
> section
->size
10553 || symbol_table_offset
> section
->size
10554 || constant_pool_offset
> section
->size
10555 || tu_list_offset
< cu_list_offset
10556 || address_table_offset
< tu_list_offset
10557 || symbol_table_offset
< address_table_offset
10558 || constant_pool_offset
< symbol_table_offset
)
10560 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10564 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10565 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10566 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10567 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10569 cu_list
= start
+ cu_list_offset
;
10570 tu_list
= start
+ tu_list_offset
;
10571 address_table
= start
+ address_table_offset
;
10572 symbol_table
= start
+ symbol_table_offset
;
10573 constant_pool
= start
+ constant_pool_offset
;
10575 printf (_("\nCU table:\n"));
10576 for (i
= 0; i
< cu_list_elements
; i
++)
10578 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10579 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10581 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
,
10582 (unsigned long) cu_offset
,
10583 (unsigned long) (cu_offset
+ cu_length
- 1));
10586 printf (_("\nTU table:\n"));
10587 for (i
= 0; i
< tu_list_elements
; i
++)
10589 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10590 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10591 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10593 printf (_("[%3u] 0x%lx 0x%lx "), i
,
10594 (unsigned long) tu_offset
,
10595 (unsigned long) type_offset
);
10596 print_dwarf_vma (signature
, 8);
10600 printf (_("\nAddress table:\n"));
10601 for (i
= 0; i
< address_table_elements
; i
++)
10603 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10604 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10605 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 20 + 16, 4);
10607 print_dwarf_vma (low
, 8);
10608 print_dwarf_vma (high
, 8);
10609 printf (_("%lu\n"), (unsigned long) cu_index
);
10612 printf (_("\nSymbol table:\n"));
10613 for (i
= 0; i
< symbol_table_slots
; ++i
)
10615 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10616 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10617 uint32_t num_cus
, cu
;
10619 if (name_offset
!= 0
10620 || cu_vector_offset
!= 0)
10624 /* PR 17531: file: 5b7b07ad. */
10625 if (name_offset
>= section
->size
- constant_pool_offset
)
10627 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10628 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10632 printf ("[%3u] %.*s:", i
,
10633 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10634 constant_pool
+ name_offset
);
10636 if (section
->size
- constant_pool_offset
< 4
10637 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10639 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10640 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10641 cu_vector_offset
, i
);
10645 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10647 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10648 + cu_vector_offset
+ 4))
10650 printf ("<invalid number of CUs: %d>\n", num_cus
);
10651 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10659 for (j
= 0; j
< num_cus
; ++j
)
10662 gdb_index_symbol_kind kind
;
10664 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10665 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10666 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10667 cu
= GDB_INDEX_CU_VALUE (cu
);
10668 /* Convert to TU number if it's for a type unit. */
10669 if (cu
>= cu_list_elements
/ 2)
10670 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10671 (unsigned long) (cu
- cu_list_elements
/ 2));
10673 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10675 printf (" [%s, %s]",
10676 is_static
? _("static") : _("global"),
10677 get_gdb_index_symbol_kind_name (kind
));
10689 /* Pre-allocate enough space for the CU/TU sets needed. */
10692 prealloc_cu_tu_list (unsigned int nshndx
)
10694 if (shndx_pool
== NULL
)
10696 shndx_pool_size
= nshndx
;
10697 shndx_pool_used
= 0;
10698 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10699 sizeof (unsigned int));
10703 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10704 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10705 sizeof (unsigned int));
10710 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10712 if (shndx_pool_used
>= shndx_pool_size
)
10714 error (_("Internal error: out of space in the shndx pool.\n"));
10717 shndx_pool
[shndx_pool_used
++] = shndx
;
10721 end_cu_tu_entry (void)
10723 if (shndx_pool_used
>= shndx_pool_size
)
10725 error (_("Internal error: out of space in the shndx pool.\n"));
10728 shndx_pool
[shndx_pool_used
++] = 0;
10731 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10733 static const char *
10734 get_DW_SECT_short_name (unsigned int dw_sect
)
10736 static char buf
[16];
10742 case DW_SECT_TYPES
:
10744 case DW_SECT_ABBREV
:
10750 case DW_SECT_STR_OFFSETS
:
10752 case DW_SECT_MACINFO
:
10754 case DW_SECT_MACRO
:
10760 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10764 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10765 These sections are extensions for Fission.
10766 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10769 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10771 unsigned char *phdr
= section
->start
;
10772 unsigned char *limit
= phdr
+ section
->size
;
10773 unsigned char *phash
;
10774 unsigned char *pindex
;
10775 unsigned char *ppool
;
10776 unsigned int version
;
10777 unsigned int ncols
= 0;
10778 unsigned int nused
;
10779 unsigned int nslots
;
10782 dwarf_vma signature
;
10785 /* PR 17512: file: 002-168123-0.004. */
10788 warn (_("Section %s is empty\n"), section
->name
);
10791 /* PR 17512: file: 002-376-0.004. */
10792 if (section
->size
< 24)
10794 warn (_("Section %s is too small to contain a CU/TU header\n"),
10800 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10802 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10803 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10804 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10806 pindex
= phash
+ (size_t) nslots
* 8;
10807 ppool
= pindex
+ (size_t) nslots
* 4;
10811 introduce (section
, false);
10813 printf (_(" Version: %u\n"), version
);
10815 printf (_(" Number of columns: %u\n"), ncols
);
10816 printf (_(" Number of used entries: %u\n"), nused
);
10817 printf (_(" Number of slots: %u\n\n"), nslots
);
10820 /* PR 17531: file: 45d69832. */
10821 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10822 || total
> (size_t) (limit
- phash
))
10824 warn (ngettext ("Section %s is too small for %u slot\n",
10825 "Section %s is too small for %u slots\n",
10827 section
->name
, nslots
);
10834 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10835 for (i
= 0; i
< nslots
; i
++)
10837 unsigned char *shndx_list
;
10838 unsigned int shndx
;
10840 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10841 if (signature
!= 0)
10843 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10844 shndx_list
= ppool
+ j
* 4;
10845 /* PR 17531: file: 705e010d. */
10846 if (shndx_list
< ppool
)
10848 warn (_("Section index pool located before start of section\n"));
10853 printf (_(" [%3d] Signature: 0x%s Sections: "),
10854 i
, dwarf_vmatoa ("x", signature
));
10857 if (shndx_list
>= limit
)
10859 warn (_("Section %s too small for shndx pool\n"),
10863 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10867 printf (" %d", shndx
);
10869 add_shndx_to_cu_tu_entry (shndx
);
10875 end_cu_tu_entry ();
10881 else if (version
== 2)
10884 unsigned int dw_sect
;
10885 unsigned char *ph
= phash
;
10886 unsigned char *pi
= pindex
;
10887 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10888 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10890 struct cu_tu_set
*this_set
= NULL
;
10892 unsigned char *prow
;
10895 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10897 /* PR 17531: file: 0dd159bf.
10898 Check for integer overflow (can occur when size_t is 32-bit)
10899 with overlarge ncols or nused values. */
10901 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10902 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10903 || total
> (size_t) (limit
- ppool
))
10905 warn (_("Section %s too small for offset and size tables\n"),
10912 printf (_(" Offset table\n"));
10913 printf (" slot %-16s ",
10914 is_tu_index
? _("signature") : _("dwo_id"));
10921 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10922 this_set
= tu_sets
;
10927 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10928 this_set
= cu_sets
;
10934 for (j
= 0; j
< ncols
; j
++)
10936 unsigned char *p
= ppool
+ j
* 4;
10937 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10938 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10943 for (i
= 0; i
< nslots
; i
++)
10945 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10947 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10950 /* PR 17531: file: a05f6ab3. */
10953 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10960 size_t num_copy
= sizeof (uint64_t);
10962 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10965 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10967 printf (_(" [%3d] 0x%s"),
10968 i
, dwarf_vmatoa ("x", signature
));
10969 for (j
= 0; j
< ncols
; j
++)
10971 unsigned char *p
= prow
+ j
* 4;
10972 SAFE_BYTE_GET (val
, p
, 4, limit
);
10974 printf (" %8d", val
);
10978 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10980 /* PR 17531: file: 10796eb3. */
10981 if (dw_sect
>= DW_SECT_MAX
)
10982 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10984 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
11000 printf (_(" Size table\n"));
11001 printf (" slot %-16s ",
11002 is_tu_index
? _("signature") : _("dwo_id"));
11005 for (j
= 0; j
< ncols
; j
++)
11007 unsigned char *p
= ppool
+ j
* 4;
11008 SAFE_BYTE_GET (val
, p
, 4, limit
);
11010 printf (" %8s", get_DW_SECT_short_name (val
));
11016 for (i
= 0; i
< nslots
; i
++)
11018 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
11020 SAFE_BYTE_GET (row
, pi
, 4, limit
);
11023 prow
= psizes
+ (row
- 1) * ncols
* 4;
11026 printf (_(" [%3d] 0x%s"),
11027 i
, dwarf_vmatoa ("x", signature
));
11029 for (j
= 0; j
< ncols
; j
++)
11031 unsigned char *p
= prow
+ j
* 4;
11033 /* PR 28645: Check for overflow. Since we do not know how
11034 many populated rows there will be, we cannot just
11035 perform a single check at the start of this function. */
11036 if (p
> (limit
- 4))
11040 warn (_("Too many rows/columns in DWARF index section %s\n"),
11045 SAFE_BYTE_GET (val
, p
, 4, limit
);
11048 printf (" %8d", val
);
11052 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
11053 if (dw_sect
>= DW_SECT_MAX
)
11054 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
11056 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11068 else if (do_display
)
11069 printf (_(" Unsupported version (%d)\n"), version
);
11077 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11079 /* Load the CU and TU indexes if present. This will build a list of
11080 section sets that we can use to associate a .debug_info.dwo section
11081 with its associated .debug_abbrev.dwo section in a .dwp file. */
11084 load_cu_tu_indexes (void *file
)
11086 /* If we have already loaded (or tried to load) the CU and TU indexes
11087 then do not bother to repeat the task. */
11088 if (cu_tu_indexes_read
== -1)
11090 cu_tu_indexes_read
= true;
11092 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11093 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11094 cu_tu_indexes_read
= false;
11096 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11097 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11098 cu_tu_indexes_read
= false;
11101 return (bool) cu_tu_indexes_read
;
11104 /* Find the set of sections that includes section SHNDX. */
11107 find_cu_tu_set (void *file
, unsigned int shndx
)
11111 if (! load_cu_tu_indexes (file
))
11114 /* Find SHNDX in the shndx pool. */
11115 for (i
= 0; i
< shndx_pool_used
; i
++)
11116 if (shndx_pool
[i
] == shndx
)
11119 if (i
>= shndx_pool_used
)
11122 /* Now backup to find the first entry in the set. */
11123 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11126 return shndx_pool
+ i
;
11129 /* Display a .debug_cu_index or .debug_tu_index section. */
11132 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11134 return process_cu_tu_index (section
, 1);
11138 display_debug_not_supported (struct dwarf_section
*section
,
11139 void *file ATTRIBUTE_UNUSED
)
11141 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11147 /* Like malloc, but takes two parameters like calloc.
11148 Verifies that the first parameter is not too large.
11149 Note: does *not* initialise the allocated memory to zero. */
11152 cmalloc (size_t nmemb
, size_t size
)
11154 /* Check for overflow. */
11155 if (nmemb
>= ~(size_t) 0 / size
)
11158 return xmalloc (nmemb
* size
);
11161 /* Like xmalloc, but takes two parameters like calloc.
11162 Verifies that the first parameter is not too large.
11163 Note: does *not* initialise the allocated memory to zero. */
11166 xcmalloc (size_t nmemb
, size_t size
)
11168 /* Check for overflow. */
11169 if (nmemb
>= ~(size_t) 0 / size
)
11172 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
11177 return xmalloc (nmemb
* size
);
11180 /* Like xrealloc, but takes three parameters.
11181 Verifies that the second parameter is not too large.
11182 Note: does *not* initialise any new memory to zero. */
11185 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
11187 /* Check for overflow. */
11188 if (nmemb
>= ~(size_t) 0 / size
)
11190 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
11195 return xrealloc (ptr
, nmemb
* size
);
11198 /* Like xcalloc, but verifies that the first parameter is not too large. */
11201 xcalloc2 (size_t nmemb
, size_t size
)
11203 /* Check for overflow. */
11204 if (nmemb
>= ~(size_t) 0 / size
)
11206 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
11211 return xcalloc (nmemb
, size
);
11214 static unsigned long
11215 calc_gnu_debuglink_crc32 (unsigned long crc
,
11216 const unsigned char * buf
,
11219 static const unsigned long crc32_table
[256] =
11221 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11222 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11223 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11224 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11225 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11226 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11227 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11228 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11229 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11230 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11231 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11232 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11233 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11234 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11235 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11236 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11237 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11238 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11239 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11240 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11241 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11242 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11243 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11244 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11245 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11246 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11247 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11248 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11249 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11250 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11251 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11252 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11253 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11254 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11255 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11256 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11257 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11258 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11259 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11260 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11261 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11262 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11263 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11264 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11265 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11266 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11267 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11268 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11269 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11270 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11271 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11274 const unsigned char *end
;
11276 crc
= ~crc
& 0xffffffff;
11277 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11278 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11279 return ~crc
& 0xffffffff;
11282 typedef bool (*check_func_type
) (const char *, void *);
11283 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11286 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11288 static unsigned char buffer
[8 * 1024];
11290 bfd_size_type count
;
11291 unsigned long crc
= 0;
11294 sep_data
= open_debug_file (pathname
);
11295 if (sep_data
== NULL
)
11298 /* Yes - we are opening the file twice... */
11299 f
= fopen (pathname
, "rb");
11302 /* Paranoia: This should never happen. */
11303 close_debug_file (sep_data
);
11304 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11308 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11309 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11313 if (crc
!= * (unsigned long *) crc_pointer
)
11315 close_debug_file (sep_data
);
11316 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11324 static const char *
11325 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11328 unsigned int crc_offset
;
11329 unsigned long * crc32
= (unsigned long *) data
;
11331 /* The name is first.
11332 The CRC value is stored after the filename, aligned up to 4 bytes. */
11333 name
= (const char *) section
->start
;
11335 crc_offset
= strnlen (name
, section
->size
) + 1;
11336 if (crc_offset
== 1)
11338 crc_offset
= (crc_offset
+ 3) & ~3;
11339 if (crc_offset
+ 4 > section
->size
)
11342 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11347 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11349 void * sep_data
= open_debug_file (filename
);
11351 if (sep_data
== NULL
)
11354 /* FIXME: We should now extract the build-id in the separate file
11360 typedef struct build_id_data
11363 const unsigned char * data
;
11366 static const char *
11367 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11370 bfd_size_type namelen
;
11371 bfd_size_type id_len
;
11372 Build_id_data
* build_id_data
;
11374 /* The name is first.
11375 The build-id follows immediately, with no padding, up to the section's end. */
11377 name
= (const char *) section
->start
;
11378 namelen
= strnlen (name
, section
->size
) + 1;
11381 if (namelen
>= section
->size
)
11384 id_len
= section
->size
- namelen
;
11388 build_id_data
= (Build_id_data
*) data
;
11389 build_id_data
->len
= id_len
;
11390 build_id_data
->data
= section
->start
+ namelen
;
11396 add_separate_debug_file (const char * filename
, void * handle
)
11398 separate_info
* i
= xmalloc (sizeof * i
);
11400 i
->filename
= filename
;
11401 i
->handle
= handle
;
11402 i
->next
= first_separate_info
;
11403 first_separate_info
= i
;
11406 #if HAVE_LIBDEBUGINFOD
11407 /* Query debuginfod servers for the target debuglink or debugaltlink
11408 file. If successful, store the path of the file in filename and
11409 return TRUE, otherwise return FALSE. */
11412 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11416 size_t build_id_len
;
11417 unsigned char * build_id
;
11419 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11421 /* Get the build-id of file. */
11422 build_id
= get_build_id (file
);
11425 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11427 /* Get the build-id of the debugaltlink file. */
11428 unsigned int filelen
;
11430 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11431 if (filelen
== section
->size
)
11432 /* Corrupt debugaltlink. */
11435 build_id
= section
->start
+ filelen
+ 1;
11436 build_id_len
= section
->size
- (filelen
+ 1);
11438 if (build_id_len
== 0)
11447 debuginfod_client
* client
;
11449 client
= debuginfod_begin ();
11450 if (client
== NULL
)
11453 /* Query debuginfod servers for the target file. If found its path
11454 will be stored in filename. */
11455 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11456 debuginfod_end (client
);
11458 /* Only free build_id if we allocated space for a hex string
11459 in get_build_id (). */
11460 if (build_id_len
== 0)
11465 /* File successfully retrieved. Close fd since we want to
11466 use open_debug_file () on filename instead. */
11474 #endif /* HAVE_LIBDEBUGINFOD */
11477 load_separate_debug_info (const char * main_filename
,
11478 struct dwarf_section
* xlink
,
11479 parse_func_type parse_func
,
11480 check_func_type check_func
,
11482 void * file ATTRIBUTE_UNUSED
)
11484 const char * separate_filename
;
11485 char * debug_filename
;
11487 size_t canon_dirlen
;
11489 char * canon_filename
;
11490 char * canon_debug_filename
;
11493 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11495 warn (_("Corrupt debuglink section: %s\n"),
11496 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11500 /* Attempt to locate the separate file.
11501 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11503 canon_filename
= lrealpath (main_filename
);
11504 canon_dir
= xstrdup (canon_filename
);
11506 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11507 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11509 canon_dir
[canon_dirlen
] = '\0';
11512 #define DEBUGDIR "/lib/debug"
11514 #ifndef EXTRA_DEBUG_ROOT1
11515 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11517 #ifndef EXTRA_DEBUG_ROOT2
11518 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11521 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11523 + strlen (".debug/")
11524 #ifdef EXTRA_DEBUG_ROOT1
11525 + strlen (EXTRA_DEBUG_ROOT1
)
11527 #ifdef EXTRA_DEBUG_ROOT2
11528 + strlen (EXTRA_DEBUG_ROOT2
)
11530 + strlen (separate_filename
)
11532 if (debug_filename
== NULL
)
11534 warn (_("Out of memory"));
11536 free (canon_filename
);
11540 /* First try in the current directory. */
11541 sprintf (debug_filename
, "%s", separate_filename
);
11542 if (check_func (debug_filename
, func_data
))
11545 /* Then try in a subdirectory called .debug. */
11546 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11547 if (check_func (debug_filename
, func_data
))
11550 /* Then try in the same directory as the original file. */
11551 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11552 if (check_func (debug_filename
, func_data
))
11555 /* And the .debug subdirectory of that directory. */
11556 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11557 if (check_func (debug_filename
, func_data
))
11560 #ifdef EXTRA_DEBUG_ROOT1
11561 /* Try the first extra debug file root. */
11562 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11563 if (check_func (debug_filename
, func_data
))
11566 /* Try the first extra debug file root. */
11567 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11568 if (check_func (debug_filename
, func_data
))
11572 #ifdef EXTRA_DEBUG_ROOT2
11573 /* Try the second extra debug file root. */
11574 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11575 if (check_func (debug_filename
, func_data
))
11579 /* Then try in the global debug_filename directory. */
11580 strcpy (debug_filename
, DEBUGDIR
);
11581 dirlen
= strlen (DEBUGDIR
) - 1;
11582 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11583 strcat (debug_filename
, "/");
11584 strcat (debug_filename
, (const char *) separate_filename
);
11586 if (check_func (debug_filename
, func_data
))
11589 #if HAVE_LIBDEBUGINFOD
11591 char * tmp_filename
;
11594 && debuginfod_fetch_separate_debug_info (xlink
,
11598 /* File successfully downloaded from server, replace
11599 debug_filename with the file's path. */
11600 free (debug_filename
);
11601 debug_filename
= tmp_filename
;
11607 if (do_debug_links
)
11609 /* Failed to find the file. */
11610 warn (_("could not find separate debug file '%s'\n"),
11611 separate_filename
);
11612 warn (_("tried: %s\n"), debug_filename
);
11614 #ifdef EXTRA_DEBUG_ROOT2
11615 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11616 separate_filename
);
11617 warn (_("tried: %s\n"), debug_filename
);
11620 #ifdef EXTRA_DEBUG_ROOT1
11621 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11622 canon_dir
, separate_filename
);
11623 warn (_("tried: %s\n"), debug_filename
);
11625 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11626 separate_filename
);
11627 warn (_("tried: %s\n"), debug_filename
);
11630 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11631 separate_filename
);
11632 warn (_("tried: %s\n"), debug_filename
);
11634 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11635 warn (_("tried: %s\n"), debug_filename
);
11637 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11638 warn (_("tried: %s\n"), debug_filename
);
11640 sprintf (debug_filename
, "%s", separate_filename
);
11641 warn (_("tried: %s\n"), debug_filename
);
11643 #if HAVE_LIBDEBUGINFOD
11644 if (use_debuginfod
)
11646 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11651 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11657 free (debug_filename
);
11658 free (canon_filename
);
11664 canon_debug_filename
= lrealpath (debug_filename
);
11665 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11666 free (canon_filename
);
11667 free (canon_debug_filename
);
11670 free (debug_filename
);
11674 void * debug_handle
;
11676 /* Now open the file.... */
11677 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11679 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11680 free (debug_filename
);
11684 /* FIXME: We do not check to see if there are any other separate debug info
11685 files that would also match. */
11687 if (do_debug_links
)
11688 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11689 add_separate_debug_file (debug_filename
, debug_handle
);
11691 /* Do not free debug_filename - it might be referenced inside
11692 the structure returned by open_debug_file(). */
11693 return debug_handle
;
11696 /* Attempt to load a separate dwarf object file. */
11699 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11701 char * separate_filename
;
11702 void * separate_handle
;
11704 if (IS_ABSOLUTE_PATH (name
))
11705 separate_filename
= strdup (name
);
11707 /* FIXME: Skip adding / if dwo_dir ends in /. */
11708 separate_filename
= concat (dir
, "/", name
, NULL
);
11709 if (separate_filename
== NULL
)
11711 warn (_("Out of memory allocating dwo filename\n"));
11715 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11717 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11718 free (separate_filename
);
11722 /* FIXME: We should check the dwo_id. */
11724 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11726 add_separate_debug_file (separate_filename
, separate_handle
);
11727 /* Note - separate_filename will be freed in free_debug_memory(). */
11728 return separate_handle
;
11732 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11734 char * f
= filename
;
11736 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11739 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11740 strcpy (f
, ".debug");
11742 return open_debug_file (filename
);
11745 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11748 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11750 if (! load_debug_section (note_gnu_build_id
, main_file
))
11751 return; /* No .note.gnu.build-id section. */
11753 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11754 if (section
== NULL
)
11756 warn (_("Unable to load the .note.gnu.build-id section\n"));
11760 if (section
->start
== NULL
|| section
->size
< 0x18)
11762 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11766 /* In theory we should extract the contents of the section into
11767 a note structure and then check the fields. For now though
11768 just use hard coded offsets instead:
11770 Field Bytes Contents
11773 Type 8..11 3 (NT_GNU_BUILD_ID)
11777 /* FIXME: Check the name size, name and type fields. */
11779 unsigned long build_id_size
;
11780 build_id_size
= byte_get (section
->start
+ 4, 4);
11781 if (build_id_size
< 8)
11783 warn (_(".note.gnu.build-id data size is too small\n"));
11787 if (build_id_size
> (section
->size
- 16))
11789 warn (_(".note.gnu.build-id data size is too bug\n"));
11794 filename
= xmalloc (strlen (".build-id/")
11795 + build_id_size
* 2 + 2
11796 + strlen (".debug")
11797 /* The next string should be the same as the longest
11798 name found in the prefixes[] array below. */
11799 + strlen ("/usrlib64/debug/usr")
11803 static const char * prefixes
[] =
11808 "/usr/lib/debug/usr/",
11809 "/usr/lib64/debug/",
11810 "/usr/lib64/debug/usr"
11812 long unsigned int i
;
11814 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11816 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11817 section
->start
+ 16, build_id_size
);
11818 if (handle
!= NULL
)
11821 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11822 if (handle
== NULL
)
11824 /* Failed to find a debug file associated with the build-id.
11825 This is not an error however, rather it just means that
11826 the debug info has probably not been loaded on the system,
11827 or that another method is being used to link to the debug
11833 add_separate_debug_file (filename
, handle
);
11836 /* Try to load a debug file pointed to by the .debug_sup section. */
11839 load_debug_sup_file (const char * main_filename
, void * file
)
11841 if (! load_debug_section (debug_sup
, file
))
11842 return; /* No .debug_sup section. */
11844 struct dwarf_section
* section
;
11845 section
= & debug_displays
[debug_sup
].section
;
11846 assert (section
!= NULL
);
11848 if (section
->start
== NULL
|| section
->size
< 5)
11850 warn (_(".debug_sup section is corrupt/empty\n"));
11854 if (section
->start
[2] != 0)
11855 return; /* This is a supplementary file. */
11857 const char * filename
= (const char *) section
->start
+ 3;
11858 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11860 warn (_("filename in .debug_sup section is corrupt\n"));
11864 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11869 new_len
= asprintf (& new_name
, "%.*s/%s",
11870 (int) (strrchr (main_filename
, '/') - main_filename
),
11875 warn (_("unable to construct path for supplementary debug file"));
11880 filename
= new_name
;
11884 /* PR 27796: Make sure that we pass a filename that can be free'd to
11885 add_separate_debug_file(). */
11886 filename
= strdup (filename
);
11887 if (filename
== NULL
)
11889 warn (_("out of memory constructing filename for .debug_sup link\n"));
11894 void * handle
= open_debug_file (filename
);
11895 if (handle
== NULL
)
11897 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11898 free ((void *) filename
);
11902 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11904 /* FIXME: Compare the checksums, if present. */
11905 add_separate_debug_file (filename
, handle
);
11908 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11909 Recursively check the loaded files for more of these sections.
11910 Also follow any links in .debug_sup sections.
11911 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11914 check_for_and_load_links (void * file
, const char * filename
)
11916 void * handle
= NULL
;
11918 if (load_debug_section (gnu_debugaltlink
, file
))
11920 Build_id_data build_id_data
;
11922 handle
= load_separate_debug_info (filename
,
11923 & debug_displays
[gnu_debugaltlink
].section
,
11924 parse_gnu_debugaltlink
,
11925 check_gnu_debugaltlink
,
11930 assert (handle
== first_separate_info
->handle
);
11931 check_for_and_load_links (first_separate_info
->handle
,
11932 first_separate_info
->filename
);
11936 if (load_debug_section (gnu_debuglink
, file
))
11938 unsigned long crc32
;
11940 handle
= load_separate_debug_info (filename
,
11941 & debug_displays
[gnu_debuglink
].section
,
11942 parse_gnu_debuglink
,
11943 check_gnu_debuglink
,
11948 assert (handle
== first_separate_info
->handle
);
11949 check_for_and_load_links (first_separate_info
->handle
,
11950 first_separate_info
->filename
);
11954 load_debug_sup_file (filename
, file
);
11956 load_build_id_debug_file (filename
, file
);
11959 /* Load the separate debug info file(s) attached to FILE, if any exist.
11960 Returns TRUE if any were found, FALSE otherwise.
11961 If TRUE is returned then the linked list starting at first_separate_info
11962 will be populated with open file handles. */
11965 load_separate_debug_files (void * file
, const char * filename
)
11967 /* Skip this operation if we are not interested in debug links. */
11968 if (! do_follow_links
&& ! do_debug_links
)
11971 /* See if there are any dwo links. */
11972 if (load_debug_section (str
, file
)
11973 && load_debug_section (abbrev
, file
)
11974 && load_debug_section (info
, file
))
11976 /* Load the .debug_addr section, if it exists. */
11977 load_debug_section (debug_addr
, file
);
11978 /* Load the .debug_str_offsets section, if it exists. */
11979 load_debug_section (str_index
, file
);
11980 /* Load the .debug_loclists section, if it exists. */
11981 load_debug_section (loclists
, file
);
11982 /* Load the .debug_rnglists section, if it exists. */
11983 load_debug_section (rnglists
, file
);
11987 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11990 bool introduced
= false;
11992 const char *dir
= NULL
;
11993 const char *id
= NULL
;
11994 const char *name
= NULL
;
11996 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11998 /* Accumulate NAME, DIR and ID fields. */
11999 switch (dwinfo
->type
)
12003 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
12004 name
= dwinfo
->value
;
12008 /* There can be multiple DW_AT_comp_dir entries in a CU,
12009 so do not complain. */
12010 dir
= dwinfo
->value
;
12015 warn (_("multiple DWO_IDs encountered for the same CU\n"));
12016 id
= dwinfo
->value
;
12020 error (_("Unexpected DWO INFO type"));
12024 /* If we have reached the end of our list, or we are changing
12025 CUs, then display the information that we have accumulated
12028 && (dwinfo
->next
== NULL
12029 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
12031 if (do_debug_links
)
12035 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
12036 debug_displays
[info
].section
.uncompressed_name
);
12040 printf (_(" Name: %s\n"), name
);
12041 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
12043 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
12044 else if (debug_information
[0].dwarf_version
!= 5)
12045 printf (_(" ID: <not specified>\n"));
12049 if (do_follow_links
)
12050 load_dwo_file (filename
, name
, dir
, id
);
12052 name
= dir
= id
= NULL
;
12058 if (! do_follow_links
)
12059 /* The other debug links will be displayed by display_debug_links()
12060 so we do not need to do any further processing here. */
12063 /* FIXME: We do not check for the presence of both link sections in the same file. */
12064 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
12065 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
12067 check_for_and_load_links (file
, filename
);
12068 if (first_separate_info
!= NULL
)
12071 do_follow_links
= 0;
12076 free_debug_memory (void)
12080 free_all_abbrevs ();
12084 shndx_pool_size
= 0;
12085 shndx_pool_used
= 0;
12093 memset (level_type_signed
, 0, sizeof level_type_signed
);
12094 cu_tu_indexes_read
= -1;
12096 for (i
= 0; i
< max
; i
++)
12097 free_debug_section ((enum dwarf_section_display_enum
) i
);
12099 if (debug_information
!= NULL
)
12101 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12103 if (debug_information
[i
].max_loc_offsets
)
12105 free (debug_information
[i
].loc_offsets
);
12106 free (debug_information
[i
].have_frame_base
);
12108 if (debug_information
[i
].max_range_lists
)
12109 free (debug_information
[i
].range_lists
);
12111 free (debug_information
);
12112 debug_information
= NULL
;
12113 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12117 separate_info
* next
;
12119 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12121 close_debug_file (d
->handle
);
12122 free ((void *) d
->filename
);
12126 first_separate_info
= NULL
;
12134 const char *option
;
12137 } debug_dump_long_opts
;
12139 static const debug_dump_long_opts debug_option_table
[] =
12141 { 'A', "addr", &do_debug_addr
, 1 },
12142 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12143 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12144 #ifdef HAVE_LIBDEBUGINFOD
12145 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12146 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12148 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12149 { 'f', "frames", &do_debug_frames
, 1 },
12150 { 'g', "gdb_index", &do_gdb_index
, 1 },
12151 { 'i', "info", &do_debug_info
, 1 },
12152 { 'K', "follow-links", &do_follow_links
, 1 },
12153 { 'k', "links", &do_debug_links
, 1 },
12154 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12155 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12156 /* For compatibility with earlier versions of readelf. */
12157 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12158 { 'm', "macro", &do_debug_macinfo
, 1 },
12159 { 'N', "no-follow-links", &do_follow_links
, 0 },
12160 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12161 { 'o', "loc", &do_debug_loc
, 1 },
12162 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12163 { 'R', "Ranges", &do_debug_ranges
, 1 },
12164 { 'r', "aranges", &do_debug_aranges
, 1 },
12165 /* For compatibility with earlier versions of readelf. */
12166 { 'r', "ranges", &do_debug_aranges
, 1 },
12167 { 's', "str", &do_debug_str
, 1 },
12168 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12169 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12170 { 'U', "trace_info", &do_trace_info
, 1 },
12171 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12172 { 0, NULL
, NULL
, 0 }
12175 /* Enable display of specific DWARF sections as determined by the comma
12176 separated strings in NAMES. Returns non-zero if any displaying was
12180 dwarf_select_sections_by_names (const char *names
)
12188 const debug_dump_long_opts
*entry
;
12190 for (entry
= debug_option_table
; entry
->option
; entry
++)
12192 size_t len
= strlen (entry
->option
);
12194 if (strncmp (p
, entry
->option
, len
) == 0
12195 && (p
[len
] == ',' || p
[len
] == '\0'))
12197 if (entry
->val
== 0)
12198 * entry
->variable
= 0;
12200 * entry
->variable
= entry
->val
;
12201 result
|= entry
->val
;
12208 if (entry
->option
== NULL
)
12210 warn (_("Unrecognized debug option '%s'\n"), p
);
12211 p
= strchr (p
, ',');
12220 /* The --debug-dump=frames-interp option also enables the
12221 --debug-dump=frames option. */
12222 if (do_debug_frames_interp
)
12223 do_debug_frames
= 1;
12228 /* Enable display of specific DWARF sections as determined by the characters
12229 in LETTERS. Returns non-zero if any displaying was enabled. */
12232 dwarf_select_sections_by_letters (const char *letters
)
12238 const debug_dump_long_opts
*entry
;
12240 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12242 if (entry
->letter
== * letters
)
12244 if (entry
->val
== 0)
12245 * entry
->variable
= 0;
12247 * entry
->variable
|= entry
->val
;
12248 result
|= entry
->val
;
12253 if (entry
->letter
== 0)
12254 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12259 /* The --debug-dump=frames-interp option also enables the
12260 --debug-dump=frames option. */
12261 if (do_debug_frames_interp
)
12262 do_debug_frames
= 1;
12268 dwarf_select_sections_all (void)
12271 do_debug_abbrevs
= 1;
12272 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12273 do_debug_pubnames
= 1;
12274 do_debug_pubtypes
= 1;
12275 do_debug_aranges
= 1;
12276 do_debug_ranges
= 1;
12277 do_debug_frames
= 1;
12278 do_debug_macinfo
= 1;
12283 do_trace_abbrevs
= 1;
12284 do_trace_aranges
= 1;
12286 do_debug_cu_index
= 1;
12287 do_follow_links
= 1;
12288 do_debug_links
= 1;
12289 do_debug_str_offsets
= 1;
12292 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12293 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12295 /* N.B. The order here must match the order in section_display_enum. */
12297 struct dwarf_section_display debug_displays
[] =
12299 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12300 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12301 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12302 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12303 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12304 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12305 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12306 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12307 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12308 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12309 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12310 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12311 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12312 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12313 { { ".debug_loclists.dwo", ".zdebug_loclists.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12314 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12315 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12316 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12317 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12318 { { ".debug_rnglists.dwo", ".zdebug_rnglists.dwo", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12319 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12320 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12321 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12322 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12323 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12324 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12325 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12326 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12327 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12328 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12329 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12330 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12331 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12332 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12333 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12334 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12335 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12336 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12337 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12338 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12339 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12340 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12341 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12342 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12343 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12344 /* Separate debug info files can containt their own .debug_str section,
12345 and this might be in *addition* to a .debug_str section already present
12346 in the main file. Hence we need to have two entries for .debug_str. */
12347 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12348 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12351 /* A static assertion. */
12352 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];