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
, struct cu_tu_set
*this_set
,
694 dwarf_vma offset_size
, bool dwo
)
696 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
697 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
698 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
699 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
700 dwarf_vma index_offset
;
701 dwarf_vma str_offset
;
703 unsigned char *curr
, *end
;
706 if (index_section
->start
== NULL
)
707 return (dwo
? _("<no .debug_str_offsets.dwo section>")
708 : _("<no .debug_str_offsets section>"));
710 if (str_section
->start
== NULL
)
711 return (dwo
? _("<no .debug_str.dwo section>")
712 : _("<no .debug_str section>"));
714 curr
= index_section
->start
;
715 end
= curr
+ index_section
->size
;
716 /* FIXME: We should cache the length... */
717 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
718 if (length
== 0xffffffff)
720 if (offset_size
!= 8)
721 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
722 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
724 else if (offset_size
!= 4)
726 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
731 /* This is probably an old style .debug_str_offset section which
732 just contains offsets and no header (and the first offset is 0). */
733 curr
= index_section
->start
;
734 length
= index_section
->size
;
738 /* Skip the version and padding bytes.
739 We assume that they are correct. */
750 && this_set
->section_sizes
[DW_SECT_STR_OFFSETS
] < length
)
751 length
= this_set
->section_sizes
[DW_SECT_STR_OFFSETS
];
753 if (length
> (dwarf_vma
) (end
- curr
))
755 warn (_("index table size too large for section %s vs %s\n"),
756 dwarf_vmatoa ("x", length
),
757 dwarf_vmatoa ("x", index_section
->size
));
761 if (length
< offset_size
)
763 warn (_("index table size %s is too small\n"),
764 dwarf_vmatoa ("x", length
));
765 return _("<table too small>");
769 index_offset
= idx
* offset_size
;
771 if (this_set
!= NULL
)
772 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
774 if (index_offset
>= length
775 || length
- index_offset
< offset_size
)
777 warn (_("DW_FORM_GNU_str_index offset too big: 0x%s vs 0x%s\n"),
778 dwarf_vmatoa ("x", index_offset
),
779 dwarf_vmatoa ("x", length
));
780 return _("<index offset is too big>");
783 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
784 str_offset
-= str_section
->address
;
785 if (str_offset
>= str_section
->size
)
787 warn (_("DW_FORM_GNU_str_index indirect offset too big: 0x%s\n"),
788 dwarf_vmatoa ("x", str_offset
));
789 return _("<indirect index offset is too big>");
792 ret
= (const char *) str_section
->start
+ str_offset
;
793 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
794 Since our caller is expecting to receive a well formed C string we test
795 for the lack of a terminating byte here. */
796 if (strnlen (ret
, str_section
->size
- str_offset
)
797 == str_section
->size
- str_offset
)
798 ret
= (const char *) _("<no NUL byte at end of section>");
804 fetch_indexed_addr (dwarf_vma offset
, uint32_t num_bytes
)
806 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
808 if (section
->start
== NULL
)
810 warn (_("<no .debug_addr section>"));
814 if (offset
+ num_bytes
> section
->size
)
816 warn (_("Offset into section %s too big: 0x%s\n"),
817 section
->name
, dwarf_vmatoa ("x", offset
));
821 return byte_get (section
->start
+ offset
, num_bytes
);
824 /* Fetch a value from a debug section that has been indexed by
825 something in another section (eg DW_FORM_loclistx).
826 Returns 0 if the value could not be found. */
829 fetch_indexed_value (dwarf_vma idx
,
830 enum dwarf_section_display_enum sec_enum
)
832 struct dwarf_section
*section
= &debug_displays
[sec_enum
].section
;
834 if (section
->start
== NULL
)
836 warn (_("Unable to locate %s section\n"), section
->uncompressed_name
);
840 uint32_t pointer_size
, bias
;
842 if (byte_get (section
->start
, 4) == 0xffffffff)
853 dwarf_vma offset
= idx
* pointer_size
;
855 /* Offsets are biased by the size of the section header. */
858 if (offset
+ pointer_size
> section
->size
)
860 warn (_("Offset into section %s too big: 0x%s\n"),
861 section
->name
, dwarf_vmatoa ("x", offset
));
865 return byte_get (section
->start
+ offset
, pointer_size
);
868 /* FIXME: There are better and more efficient ways to handle
869 these structures. For now though, I just want something that
870 is simple to implement. */
871 /* Records a single attribute in an abbrev. */
872 typedef struct abbrev_attr
874 unsigned long attribute
;
876 dwarf_signed_vma implicit_const
;
877 struct abbrev_attr
* next
;
881 /* Records a single abbrev. */
882 typedef struct abbrev_entry
884 unsigned long number
;
887 struct abbrev_attr
* first_attr
;
888 struct abbrev_attr
* last_attr
;
889 struct abbrev_entry
* next
;
893 /* Records a set of abbreviations. */
894 typedef struct abbrev_list
896 abbrev_entry
* first_abbrev
;
897 abbrev_entry
* last_abbrev
;
898 dwarf_vma abbrev_base
;
899 dwarf_vma abbrev_offset
;
900 struct abbrev_list
* next
;
901 unsigned char * start_of_next_abbrevs
;
905 /* Records all the abbrevs found so far. */
906 static struct abbrev_list
* abbrev_lists
= NULL
;
908 typedef struct abbrev_map
915 /* Maps between CU offsets and abbrev sets. */
916 static abbrev_map
* cu_abbrev_map
= NULL
;
917 static unsigned long num_abbrev_map_entries
= 0;
918 static unsigned long next_free_abbrev_map_entry
= 0;
920 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
921 #define ABBREV_MAP_ENTRIES_INCREMENT 8
924 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
926 if (cu_abbrev_map
== NULL
)
928 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
929 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
931 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
933 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
934 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
937 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
938 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
939 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
940 next_free_abbrev_map_entry
++;
944 free_all_abbrevs (void)
948 for (list
= abbrev_lists
; list
!= NULL
;)
950 abbrev_list
* next
= list
->next
;
951 abbrev_entry
* abbrv
;
953 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
955 abbrev_entry
* next_abbrev
= abbrv
->next
;
958 for (attr
= abbrv
->first_attr
; attr
;)
960 abbrev_attr
*next_attr
= attr
->next
;
978 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
980 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
982 list
->abbrev_base
= abbrev_base
;
983 list
->abbrev_offset
= abbrev_offset
;
985 list
->next
= abbrev_lists
;
992 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
993 dwarf_vma abbrev_offset
)
997 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
998 if (list
->abbrev_base
== abbrev_base
999 && list
->abbrev_offset
== abbrev_offset
)
1005 /* Find the abbreviation map for the CU that includes OFFSET.
1006 OFFSET is an absolute offset from the start of the .debug_info section. */
1007 /* FIXME: This function is going to slow down readelf & objdump.
1008 Consider using a better algorithm to mitigate this effect. */
1011 find_abbrev_map_by_offset (dwarf_vma offset
)
1015 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
1016 if (cu_abbrev_map
[i
].start
<= offset
1017 && cu_abbrev_map
[i
].end
> offset
)
1018 return cu_abbrev_map
+ i
;
1024 add_abbrev (unsigned long number
,
1029 abbrev_entry
* entry
;
1031 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
1033 entry
->number
= number
;
1035 entry
->children
= children
;
1036 entry
->first_attr
= NULL
;
1037 entry
->last_attr
= NULL
;
1040 assert (list
!= NULL
);
1042 if (list
->first_abbrev
== NULL
)
1043 list
->first_abbrev
= entry
;
1045 list
->last_abbrev
->next
= entry
;
1047 list
->last_abbrev
= entry
;
1051 add_abbrev_attr (unsigned long attribute
,
1053 dwarf_signed_vma implicit_const
,
1058 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1060 attr
->attribute
= attribute
;
1062 attr
->implicit_const
= implicit_const
;
1065 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1067 if (list
->last_abbrev
->first_attr
== NULL
)
1068 list
->last_abbrev
->first_attr
= attr
;
1070 list
->last_abbrev
->last_attr
->next
= attr
;
1072 list
->last_abbrev
->last_attr
= attr
;
1075 /* Processes the (partial) contents of a .debug_abbrev section.
1076 Returns NULL if the end of the section was encountered.
1077 Returns the address after the last byte read if the end of
1078 an abbreviation set was found. */
1080 static unsigned char *
1081 process_abbrev_set (struct dwarf_section
*section
,
1082 dwarf_vma abbrev_base
,
1083 dwarf_vma abbrev_size
,
1084 dwarf_vma abbrev_offset
,
1087 if (abbrev_base
>= section
->size
1088 || abbrev_size
> section
->size
- abbrev_base
)
1090 /* PR 17531: file:4bcd9ce9. */
1091 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than "
1092 "abbrev section size (%lx)\n"),
1093 (unsigned long) (abbrev_base
+ abbrev_size
),
1094 (unsigned long) section
->size
);
1097 if (abbrev_offset
>= abbrev_size
)
1099 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than "
1100 "abbrev section size (%lx)\n"),
1101 (unsigned long) abbrev_offset
,
1102 (unsigned long) abbrev_size
);
1106 unsigned char *start
= section
->start
+ abbrev_base
;
1107 unsigned char *end
= start
+ abbrev_size
;
1108 start
+= abbrev_offset
;
1111 unsigned long entry
;
1113 unsigned long attribute
;
1116 READ_ULEB (entry
, start
, end
);
1118 /* A single zero is supposed to end the set according
1119 to the standard. If there's more, then signal that to
1126 READ_ULEB (tag
, start
, end
);
1130 children
= *start
++;
1132 add_abbrev (entry
, tag
, children
, list
);
1137 /* Initialize it due to a false compiler warning. */
1138 dwarf_signed_vma implicit_const
= -1;
1140 READ_ULEB (attribute
, start
, end
);
1144 READ_ULEB (form
, start
, end
);
1148 if (form
== DW_FORM_implicit_const
)
1150 READ_SLEB (implicit_const
, start
, end
);
1155 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1157 while (attribute
!= 0);
1160 /* Report the missing single zero which ends the section. */
1161 error (_(".debug_abbrev section not zero terminated\n"));
1167 get_TAG_name (unsigned long tag
)
1169 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1173 static char buffer
[100];
1175 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1176 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1178 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1186 get_FORM_name (unsigned long form
)
1191 return "DW_FORM value: 0";
1193 name
= get_DW_FORM_name (form
);
1196 static char buffer
[100];
1198 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1206 get_IDX_name (unsigned long idx
)
1208 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1212 static char buffer
[100];
1214 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1221 static unsigned char *
1222 display_block (unsigned char *data
,
1224 const unsigned char * const end
, char delimiter
)
1228 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1230 return (unsigned char *) end
;
1232 maxlen
= (dwarf_vma
) (end
- data
);
1233 length
= length
> maxlen
? maxlen
: length
;
1236 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1242 decode_location_expression (unsigned char * data
,
1243 unsigned int pointer_size
,
1244 unsigned int offset_size
,
1247 dwarf_vma cu_offset
,
1248 struct dwarf_section
* section
)
1252 dwarf_signed_vma svalue
;
1253 unsigned char *end
= data
+ length
;
1254 int need_frame_base
= 0;
1263 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1264 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1267 printf ("DW_OP_deref");
1270 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1271 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1274 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1275 printf ("DW_OP_const1s: %ld", (long) svalue
);
1278 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1279 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1282 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1283 printf ("DW_OP_const2s: %ld", (long) svalue
);
1286 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1287 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1290 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1291 printf ("DW_OP_const4s: %ld", (long) svalue
);
1294 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1295 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1296 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1297 printf ("%lu", (unsigned long) uvalue
);
1300 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1301 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1302 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1303 printf ("%ld", (long) svalue
);
1306 READ_ULEB (uvalue
, data
, end
);
1307 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1310 READ_SLEB (svalue
, data
, end
);
1311 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1314 printf ("DW_OP_dup");
1317 printf ("DW_OP_drop");
1320 printf ("DW_OP_over");
1323 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1324 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1327 printf ("DW_OP_swap");
1330 printf ("DW_OP_rot");
1333 printf ("DW_OP_xderef");
1336 printf ("DW_OP_abs");
1339 printf ("DW_OP_and");
1342 printf ("DW_OP_div");
1345 printf ("DW_OP_minus");
1348 printf ("DW_OP_mod");
1351 printf ("DW_OP_mul");
1354 printf ("DW_OP_neg");
1357 printf ("DW_OP_not");
1360 printf ("DW_OP_or");
1363 printf ("DW_OP_plus");
1365 case DW_OP_plus_uconst
:
1366 READ_ULEB (uvalue
, data
, end
);
1367 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1370 printf ("DW_OP_shl");
1373 printf ("DW_OP_shr");
1376 printf ("DW_OP_shra");
1379 printf ("DW_OP_xor");
1382 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1383 printf ("DW_OP_bra: %ld", (long) svalue
);
1386 printf ("DW_OP_eq");
1389 printf ("DW_OP_ge");
1392 printf ("DW_OP_gt");
1395 printf ("DW_OP_le");
1398 printf ("DW_OP_lt");
1401 printf ("DW_OP_ne");
1404 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1405 printf ("DW_OP_skip: %ld", (long) svalue
);
1440 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1475 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1476 regname (op
- DW_OP_reg0
, 1));
1511 READ_SLEB (svalue
, data
, end
);
1512 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1513 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1517 READ_ULEB (uvalue
, data
, end
);
1518 printf ("DW_OP_regx: %s (%s)",
1519 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1522 need_frame_base
= 1;
1523 READ_SLEB (svalue
, data
, end
);
1524 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1527 READ_ULEB (uvalue
, data
, end
);
1528 READ_SLEB (svalue
, data
, end
);
1529 printf ("DW_OP_bregx: %s (%s) %s",
1530 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1531 dwarf_vmatoa ("d", svalue
));
1534 READ_ULEB (uvalue
, data
, end
);
1535 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1537 case DW_OP_deref_size
:
1538 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1539 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1541 case DW_OP_xderef_size
:
1542 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1543 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1546 printf ("DW_OP_nop");
1549 /* DWARF 3 extensions. */
1550 case DW_OP_push_object_address
:
1551 printf ("DW_OP_push_object_address");
1554 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1555 this ought to be an 8-byte wide computation. */
1556 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1557 printf ("DW_OP_call2: <0x%s>",
1558 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1561 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1562 this ought to be an 8-byte wide computation. */
1563 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1564 printf ("DW_OP_call4: <0x%s>",
1565 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1567 case DW_OP_call_ref
:
1568 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1569 this ought to be an 8-byte wide computation. */
1570 if (dwarf_version
== -1)
1572 printf (_("(DW_OP_call_ref in frame info)"));
1573 /* No way to tell where the next op is, so just bail. */
1574 return need_frame_base
;
1576 if (dwarf_version
== 2)
1578 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1582 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1584 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1586 case DW_OP_form_tls_address
:
1587 printf ("DW_OP_form_tls_address");
1589 case DW_OP_call_frame_cfa
:
1590 printf ("DW_OP_call_frame_cfa");
1592 case DW_OP_bit_piece
:
1593 printf ("DW_OP_bit_piece: ");
1594 READ_ULEB (uvalue
, data
, end
);
1595 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1596 READ_ULEB (uvalue
, data
, end
);
1597 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1600 /* DWARF 4 extensions. */
1601 case DW_OP_stack_value
:
1602 printf ("DW_OP_stack_value");
1605 case DW_OP_implicit_value
:
1606 printf ("DW_OP_implicit_value");
1607 READ_ULEB (uvalue
, data
, end
);
1608 data
= display_block (data
, uvalue
, end
, ' ');
1611 /* GNU extensions. */
1612 case DW_OP_GNU_push_tls_address
:
1613 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1615 case DW_OP_GNU_uninit
:
1616 printf ("DW_OP_GNU_uninit");
1617 /* FIXME: Is there data associated with this OP ? */
1619 case DW_OP_GNU_encoded_addr
:
1626 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1628 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1629 print_dwarf_vma (addr
, pointer_size
);
1632 case DW_OP_implicit_pointer
:
1633 case DW_OP_GNU_implicit_pointer
:
1634 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1635 this ought to be an 8-byte wide computation. */
1636 if (dwarf_version
== -1)
1638 printf (_("(%s in frame info)"),
1639 (op
== DW_OP_implicit_pointer
1640 ? "DW_OP_implicit_pointer"
1641 : "DW_OP_GNU_implicit_pointer"));
1642 /* No way to tell where the next op is, so just bail. */
1643 return need_frame_base
;
1645 if (dwarf_version
== 2)
1647 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1651 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1653 READ_SLEB (svalue
, data
, end
);
1654 printf ("%s: <0x%s> %s",
1655 (op
== DW_OP_implicit_pointer
1656 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1657 dwarf_vmatoa ("x", uvalue
),
1658 dwarf_vmatoa ("d", svalue
));
1660 case DW_OP_entry_value
:
1661 case DW_OP_GNU_entry_value
:
1662 READ_ULEB (uvalue
, data
, end
);
1663 /* PR 17531: file: 0cc9cd00. */
1664 if (uvalue
> (dwarf_vma
) (end
- data
))
1665 uvalue
= end
- data
;
1666 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1667 : "DW_OP_GNU_entry_value"));
1668 if (decode_location_expression (data
, pointer_size
, offset_size
,
1669 dwarf_version
, uvalue
,
1670 cu_offset
, section
))
1671 need_frame_base
= 1;
1675 case DW_OP_const_type
:
1676 case DW_OP_GNU_const_type
:
1677 READ_ULEB (uvalue
, data
, end
);
1678 printf ("%s: <0x%s> ",
1679 (op
== DW_OP_const_type
? "DW_OP_const_type"
1680 : "DW_OP_GNU_const_type"),
1681 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1682 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1683 data
= display_block (data
, uvalue
, end
, ' ');
1685 case DW_OP_regval_type
:
1686 case DW_OP_GNU_regval_type
:
1687 READ_ULEB (uvalue
, data
, end
);
1688 printf ("%s: %s (%s)",
1689 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1690 : "DW_OP_GNU_regval_type"),
1691 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1692 READ_ULEB (uvalue
, data
, end
);
1693 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1695 case DW_OP_deref_type
:
1696 case DW_OP_GNU_deref_type
:
1697 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1699 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1700 : "DW_OP_GNU_deref_type"),
1702 READ_ULEB (uvalue
, data
, end
);
1703 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1706 case DW_OP_GNU_convert
:
1707 READ_ULEB (uvalue
, data
, end
);
1708 printf ("%s <0x%s>",
1709 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1710 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1712 case DW_OP_reinterpret
:
1713 case DW_OP_GNU_reinterpret
:
1714 READ_ULEB (uvalue
, data
, end
);
1715 printf ("%s <0x%s>",
1716 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1717 : "DW_OP_GNU_reinterpret"),
1718 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1720 case DW_OP_GNU_parameter_ref
:
1721 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1722 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1723 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1726 READ_ULEB (uvalue
, data
, end
);
1727 printf ("DW_OP_addrx <0x%s>", dwarf_vmatoa ("x", uvalue
));
1729 case DW_OP_GNU_addr_index
:
1730 READ_ULEB (uvalue
, data
, end
);
1731 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1733 case DW_OP_GNU_const_index
:
1734 READ_ULEB (uvalue
, data
, end
);
1735 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1737 case DW_OP_GNU_variable_value
:
1738 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1739 this ought to be an 8-byte wide computation. */
1740 if (dwarf_version
== -1)
1742 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1743 /* No way to tell where the next op is, so just bail. */
1744 return need_frame_base
;
1746 if (dwarf_version
== 2)
1748 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1752 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1754 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1757 /* HP extensions. */
1758 case DW_OP_HP_is_value
:
1759 printf ("DW_OP_HP_is_value");
1760 /* FIXME: Is there data associated with this OP ? */
1762 case DW_OP_HP_fltconst4
:
1763 printf ("DW_OP_HP_fltconst4");
1764 /* FIXME: Is there data associated with this OP ? */
1766 case DW_OP_HP_fltconst8
:
1767 printf ("DW_OP_HP_fltconst8");
1768 /* FIXME: Is there data associated with this OP ? */
1770 case DW_OP_HP_mod_range
:
1771 printf ("DW_OP_HP_mod_range");
1772 /* FIXME: Is there data associated with this OP ? */
1774 case DW_OP_HP_unmod_range
:
1775 printf ("DW_OP_HP_unmod_range");
1776 /* FIXME: Is there data associated with this OP ? */
1779 printf ("DW_OP_HP_tls");
1780 /* FIXME: Is there data associated with this OP ? */
1783 /* PGI (STMicroelectronics) extensions. */
1784 case DW_OP_PGI_omp_thread_num
:
1785 /* Pushes the thread number for the current thread as it would be
1786 returned by the standard OpenMP library function:
1787 omp_get_thread_num(). The "current thread" is the thread for
1788 which the expression is being evaluated. */
1789 printf ("DW_OP_PGI_omp_thread_num");
1793 if (op
>= DW_OP_lo_user
1794 && op
<= DW_OP_hi_user
)
1795 printf (_("(User defined location op 0x%x)"), op
);
1797 printf (_("(Unknown location op 0x%x)"), op
);
1798 /* No way to tell where the next op is, so just bail. */
1799 return need_frame_base
;
1802 /* Separate the ops. */
1807 return need_frame_base
;
1810 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1811 This is used for DWARF package files. */
1813 static struct cu_tu_set
*
1814 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1816 struct cu_tu_set
*p
;
1818 unsigned int dw_sect
;
1824 dw_sect
= DW_SECT_TYPES
;
1830 dw_sect
= DW_SECT_INFO
;
1834 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1843 fetch_alt_indirect_string (dwarf_vma offset
)
1847 if (! do_follow_links
)
1850 if (first_separate_info
== NULL
)
1851 return _("<no links available>");
1853 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1855 struct dwarf_section
* section
;
1858 if (! load_debug_section (separate_debug_str
, i
->handle
))
1861 section
= &debug_displays
[separate_debug_str
].section
;
1863 if (section
->start
== NULL
)
1866 if (offset
>= section
->size
)
1869 ret
= (const char *) (section
->start
+ offset
);
1870 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1871 NUL byte. Since our caller is expecting to receive a well formed C
1872 string we test for the lack of a terminating byte here. */
1873 if (strnlen ((const char *) ret
, section
->size
- offset
)
1874 == section
->size
- offset
)
1875 return _("<no NUL byte at end of alt .debug_str section>");
1880 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1881 dwarf_vmatoa ("x", offset
));
1882 return _("<offset is too big>");
1886 get_AT_name (unsigned long attribute
)
1891 return "DW_AT value: 0";
1893 /* One value is shared by the MIPS and HP extensions: */
1894 if (attribute
== DW_AT_MIPS_fde
)
1895 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1897 name
= get_DW_AT_name (attribute
);
1901 static char buffer
[100];
1903 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1912 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1914 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1916 dwinfo
->type
= type
;
1917 dwinfo
->value
= value
;
1918 dwinfo
->cu_offset
= cu_offset
;
1919 dwinfo
->next
= first_dwo_info
;
1920 first_dwo_info
= dwinfo
;
1924 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1926 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1930 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1932 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1936 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1938 add_dwo_info (id
, cu_offset
, DWO_ID
);
1942 free_dwo_info (void)
1947 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1949 next
= dwinfo
->next
;
1952 first_dwo_info
= NULL
;
1955 /* Ensure that START + UVALUE is less than END.
1956 Return an adjusted UVALUE if necessary to ensure this relationship. */
1958 static inline dwarf_vma
1959 check_uvalue (const unsigned char * start
,
1961 const unsigned char * end
)
1963 dwarf_vma max_uvalue
= end
- start
;
1965 /* See PR 17512: file: 008-103549-0.001:0.1.
1966 and PR 24829 for examples of where these tests are triggered. */
1967 if (uvalue
> max_uvalue
)
1969 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1970 uvalue
= max_uvalue
;
1976 static unsigned char *
1977 skip_attr_bytes (unsigned long form
,
1978 unsigned char *data
,
1980 dwarf_vma pointer_size
,
1981 dwarf_vma offset_size
,
1983 dwarf_vma
*value_return
)
1985 dwarf_signed_vma svalue
;
1986 dwarf_vma uvalue
= 0;
1993 case DW_FORM_ref_addr
:
1994 if (dwarf_version
== 2)
1995 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1996 else if (dwarf_version
> 2)
1997 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2003 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2007 case DW_FORM_line_strp
:
2008 case DW_FORM_sec_offset
:
2009 case DW_FORM_GNU_ref_alt
:
2010 case DW_FORM_GNU_strp_alt
:
2011 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2014 case DW_FORM_flag_present
:
2022 case DW_FORM_addrx1
:
2023 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2027 case DW_FORM_addrx3
:
2028 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2034 case DW_FORM_addrx2
:
2035 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2041 case DW_FORM_addrx4
:
2042 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2046 READ_SLEB (svalue
, data
, end
);
2050 case DW_FORM_ref_udata
:
2052 case DW_FORM_GNU_str_index
:
2054 case DW_FORM_GNU_addr_index
:
2056 case DW_FORM_loclistx
:
2057 case DW_FORM_rnglistx
:
2058 READ_ULEB (uvalue
, data
, end
);
2062 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2066 case DW_FORM_ref_sig8
:
2070 case DW_FORM_data16
:
2074 case DW_FORM_string
:
2075 inc
= strnlen ((char *) data
, end
- data
) + 1;
2079 case DW_FORM_exprloc
:
2080 READ_ULEB (uvalue
, data
, end
);
2084 case DW_FORM_block1
:
2085 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2089 case DW_FORM_block2
:
2090 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2094 case DW_FORM_block4
:
2095 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2099 case DW_FORM_indirect
:
2100 READ_ULEB (form
, data
, end
);
2101 if (form
== DW_FORM_implicit_const
)
2102 SKIP_ULEB (data
, end
);
2103 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
,
2104 dwarf_version
, value_return
);
2110 * value_return
= uvalue
;
2111 if (inc
<= (dwarf_vma
) (end
- data
))
2118 /* Given form FORM with value UVALUE, locate and return the abbreviation
2119 associated with it. */
2121 static abbrev_entry
*
2122 get_type_abbrev_from_form (unsigned long form
,
2123 unsigned long uvalue
,
2124 dwarf_vma cu_offset
,
2125 unsigned char *cu_end
,
2126 const struct dwarf_section
*section
,
2127 unsigned long *abbrev_num_return
,
2128 unsigned char **data_return
,
2129 abbrev_map
**map_return
)
2131 unsigned long abbrev_number
;
2133 abbrev_entry
* entry
;
2134 unsigned char * data
;
2136 if (abbrev_num_return
!= NULL
)
2137 * abbrev_num_return
= 0;
2138 if (data_return
!= NULL
)
2139 * data_return
= NULL
;
2143 case DW_FORM_GNU_ref_alt
:
2144 case DW_FORM_ref_sig8
:
2145 /* FIXME: We are unable to handle this form at the moment. */
2148 case DW_FORM_ref_addr
:
2149 if (uvalue
>= section
->size
)
2151 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2152 uvalue
, (long) section
->size
, section
->name
);
2157 case DW_FORM_ref_sup4
:
2158 case DW_FORM_ref_sup8
:
2165 case DW_FORM_ref_udata
:
2166 if (uvalue
+ cu_offset
> (size_t) (cu_end
- section
->start
))
2168 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > CU size %lx\n"),
2169 uvalue
, (long) cu_offset
, (long) (cu_end
- section
->start
));
2172 uvalue
+= cu_offset
;
2175 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2178 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2182 data
= (unsigned char *) section
->start
+ uvalue
;
2183 map
= find_abbrev_map_by_offset (uvalue
);
2187 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2190 if (map
->list
== NULL
)
2192 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2196 if (map_return
!= NULL
)
2198 if (form
== DW_FORM_ref_addr
)
2204 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2206 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2207 if (entry
->number
== abbrev_number
)
2210 if (abbrev_num_return
!= NULL
)
2211 * abbrev_num_return
= abbrev_number
;
2213 if (data_return
!= NULL
)
2214 * data_return
= data
;
2217 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2222 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2223 can be determined to be a signed type. The data for ENTRY can be
2224 found starting at DATA. */
2227 get_type_signedness (abbrev_entry
*entry
,
2228 const struct dwarf_section
*section
,
2229 unsigned char *data
,
2231 dwarf_vma cu_offset
,
2232 dwarf_vma pointer_size
,
2233 dwarf_vma offset_size
,
2236 unsigned int nesting
)
2240 * is_signed
= false;
2242 #define MAX_NESTING 20
2243 if (nesting
> MAX_NESTING
)
2245 /* FIXME: Warn - or is this expected ?
2246 NB/ We need to avoid infinite recursion. */
2250 for (attr
= entry
->first_attr
;
2251 attr
!= NULL
&& attr
->attribute
;
2254 unsigned char * orig_data
= data
;
2255 dwarf_vma uvalue
= 0;
2257 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2258 offset_size
, dwarf_version
, & uvalue
);
2262 switch (attr
->attribute
)
2264 case DW_AT_linkage_name
:
2268 if (attr
->form
== DW_FORM_strp
)
2269 printf (", %s", fetch_indirect_string (uvalue
));
2270 else if (attr
->form
== DW_FORM_string
)
2271 printf (", %.*s", (int) (end
- orig_data
), orig_data
);
2278 abbrev_entry
*type_abbrev
;
2279 unsigned char *type_data
;
2282 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2287 NULL
/* abbrev num return */,
2290 if (type_abbrev
== NULL
)
2293 get_type_signedness (type_abbrev
, section
, type_data
,
2294 map
? section
->start
+ map
->end
: end
,
2295 map
? map
->start
: cu_offset
,
2296 pointer_size
, offset_size
, dwarf_version
,
2297 is_signed
, nesting
+ 1);
2301 case DW_AT_encoding
:
2302 /* Determine signness. */
2305 case DW_ATE_address
:
2306 /* FIXME - some architectures have signed addresses. */
2307 case DW_ATE_boolean
:
2308 case DW_ATE_unsigned
:
2309 case DW_ATE_unsigned_char
:
2310 case DW_ATE_unsigned_fixed
:
2311 * is_signed
= false;
2315 case DW_ATE_complex_float
:
2318 case DW_ATE_signed_char
:
2319 case DW_ATE_imaginary_float
:
2320 case DW_ATE_decimal_float
:
2321 case DW_ATE_signed_fixed
:
2331 read_and_print_leb128 (unsigned char *data
,
2332 unsigned int *bytes_read
,
2333 unsigned const char *end
,
2337 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2339 report_leb_status (status
);
2341 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2345 display_discr_list (unsigned long form
,
2347 unsigned char * data
,
2350 unsigned char *end
= data
;
2354 printf ("[default]");
2361 case DW_FORM_block1
:
2362 case DW_FORM_block2
:
2363 case DW_FORM_block4
:
2364 /* Move data pointer back to the start of the byte array. */
2368 printf ("<corrupt>\n");
2369 warn (_("corrupt discr_list - not using a block form\n"));
2375 printf ("<corrupt>\n");
2376 warn (_("corrupt discr_list - block not long enough\n"));
2380 bool is_signed
= (level
> 0 && level
<= MAX_CU_NESTING
2381 ? level_type_signed
[level
- 1] : false);
2386 unsigned char discriminant
;
2387 unsigned int bytes_read
;
2389 SAFE_BYTE_GET_AND_INC (discriminant
, data
, 1, end
);
2391 switch (discriminant
)
2395 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2401 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2405 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2410 printf ("<corrupt>\n");
2411 warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"),
2421 printf (")(signed)");
2423 printf (")(unsigned)");
2426 static unsigned char *
2427 read_and_display_attr_value (unsigned long attribute
,
2429 dwarf_signed_vma implicit_const
,
2430 unsigned char * start
,
2431 unsigned char * data
,
2432 unsigned char * end
,
2433 dwarf_vma cu_offset
,
2434 dwarf_vma pointer_size
,
2435 dwarf_vma offset_size
,
2437 debug_info
* debug_info_p
,
2439 struct dwarf_section
* section
,
2440 struct cu_tu_set
* this_set
,
2444 dwarf_signed_vma svalue
;
2445 dwarf_vma uvalue
= 0;
2446 dwarf_vma uvalue_hi
= 0;
2447 unsigned char *block_start
= NULL
;
2448 unsigned char *orig_data
= data
;
2450 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2452 warn (_("Corrupt attribute\n"));
2456 if (do_wide
&& ! do_loc
)
2458 /* PR 26847: Display the name of the form. */
2459 const char * name
= get_FORM_name (form
);
2461 /* For convenience we skip the DW_FORM_ prefix to the name. */
2463 name
+= 8; /* strlen ("DW_FORM_") */
2464 printf ("%c(%s)", delimiter
, name
);
2469 case DW_FORM_ref_addr
:
2470 if (dwarf_version
== 2)
2471 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2472 else if (dwarf_version
> 2)
2473 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2475 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2479 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2482 case DW_FORM_strp_sup
:
2484 case DW_FORM_line_strp
:
2485 case DW_FORM_sec_offset
:
2486 case DW_FORM_GNU_ref_alt
:
2487 case DW_FORM_GNU_strp_alt
:
2488 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2491 case DW_FORM_flag_present
:
2499 case DW_FORM_addrx1
:
2500 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2506 case DW_FORM_addrx2
:
2507 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2511 case DW_FORM_addrx3
:
2512 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 3, end
);
2515 case DW_FORM_ref_sup4
:
2519 case DW_FORM_addrx4
:
2520 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2523 case DW_FORM_ref_sup8
:
2526 case DW_FORM_ref_sig8
:
2527 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2530 case DW_FORM_data16
:
2531 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 8, end
);
2532 SAFE_BYTE_GET_AND_INC (uvalue_hi
, data
, 8, end
);
2533 if (byte_get
!= byte_get_little_endian
)
2535 dwarf_vma utmp
= uvalue
;
2542 READ_SLEB (svalue
, data
, end
);
2546 case DW_FORM_GNU_str_index
:
2548 case DW_FORM_ref_udata
:
2550 case DW_FORM_GNU_addr_index
:
2552 case DW_FORM_loclistx
:
2553 case DW_FORM_rnglistx
:
2554 READ_ULEB (uvalue
, data
, end
);
2557 case DW_FORM_indirect
:
2558 READ_ULEB (form
, data
, end
);
2560 printf ("%c%s", delimiter
, get_FORM_name (form
));
2561 if (form
== DW_FORM_implicit_const
)
2562 READ_SLEB (implicit_const
, data
, end
);
2563 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2565 cu_offset
, pointer_size
,
2566 offset_size
, dwarf_version
,
2567 debug_info_p
, do_loc
,
2568 section
, this_set
, delimiter
, level
);
2570 case DW_FORM_implicit_const
:
2571 uvalue
= implicit_const
;
2580 case DW_FORM_ref_addr
:
2582 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2585 case DW_FORM_GNU_ref_alt
:
2589 /* We have already printed the form name. */
2590 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2592 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2594 /* FIXME: Follow the reference... */
2600 case DW_FORM_ref_sup4
:
2601 case DW_FORM_ref_udata
:
2603 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2608 case DW_FORM_sec_offset
:
2610 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2613 case DW_FORM_flag_present
:
2620 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2623 case DW_FORM_implicit_const
:
2625 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2628 case DW_FORM_ref_sup8
:
2633 dwarf_vma utmp
= uvalue
;
2634 if (form
== DW_FORM_ref8
)
2636 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", utmp
));
2640 case DW_FORM_data16
:
2643 uvalue_hi
== 0 ? "" : dwarf_vmatoa ("x", uvalue_hi
),
2644 dwarf_vmatoa_1 ("x", uvalue
, uvalue_hi
== 0 ? 0 : 8));
2647 case DW_FORM_string
:
2649 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2650 data
+= strnlen ((char *) data
, end
- data
);
2656 case DW_FORM_exprloc
:
2657 READ_ULEB (uvalue
, data
, end
);
2660 if (block_start
>= end
)
2662 warn (_("Block ends prematurely\n"));
2667 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2669 data
= block_start
+ uvalue
;
2674 SAFE_BYTE_GET (op
, block_start
, sizeof (op
), end
);
2675 if (op
!= DW_OP_addrx
)
2676 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2680 case DW_FORM_block1
:
2681 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2684 case DW_FORM_block2
:
2685 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2688 case DW_FORM_block4
:
2689 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2696 /* We have already displayed the form name. */
2697 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2698 dwarf_vmatoa ("x", uvalue
),
2699 fetch_indirect_string (uvalue
));
2701 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2702 dwarf_vmatoa ("x", uvalue
),
2703 fetch_indirect_string (uvalue
));
2707 case DW_FORM_line_strp
:
2711 /* We have already displayed the form name. */
2712 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2713 dwarf_vmatoa ("x", uvalue
),
2714 fetch_indirect_line_string (uvalue
));
2716 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2717 dwarf_vmatoa ("x", uvalue
),
2718 fetch_indirect_line_string (uvalue
));
2722 case DW_FORM_GNU_str_index
:
2730 const char *suffix
= section
? strrchr (section
->name
, '.') : NULL
;
2731 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
2734 /* We have already displayed the form name. */
2735 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2736 dwarf_vmatoa ("x", uvalue
),
2737 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2739 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2740 dwarf_vmatoa ("x", uvalue
),
2741 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2745 case DW_FORM_GNU_strp_alt
:
2749 /* We have already displayed the form name. */
2750 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2751 dwarf_vmatoa ("x", uvalue
),
2752 fetch_alt_indirect_string (uvalue
));
2754 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2755 dwarf_vmatoa ("x", uvalue
),
2756 fetch_alt_indirect_string (uvalue
));
2760 case DW_FORM_indirect
:
2761 /* Handled above. */
2764 case DW_FORM_ref_sig8
:
2766 printf ("%c%s: 0x%s", delimiter
, do_wide
? "" : "signature",
2767 dwarf_vmatoa ("x", uvalue
));
2770 case DW_FORM_GNU_addr_index
:
2772 case DW_FORM_addrx1
:
2773 case DW_FORM_addrx2
:
2774 case DW_FORM_addrx3
:
2775 case DW_FORM_addrx4
:
2776 case DW_FORM_loclistx
:
2777 case DW_FORM_rnglistx
:
2783 if (debug_info_p
== NULL
)
2785 else if (debug_info_p
->addr_base
== DEBUG_INFO_UNAVAILABLE
)
2788 base
= debug_info_p
->addr_base
;
2790 offset
= base
+ uvalue
* pointer_size
;
2793 /* We have already displayed the form name. */
2794 printf (_("%c(index: 0x%s): %s"), delimiter
,
2795 dwarf_vmatoa ("x", uvalue
),
2796 dwarf_vmatoa ("x", fetch_indexed_addr (offset
, pointer_size
)));
2798 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2799 dwarf_vmatoa ("x", uvalue
),
2800 dwarf_vmatoa ("x", fetch_indexed_addr (offset
, pointer_size
)));
2804 case DW_FORM_strp_sup
:
2806 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2810 warn (_("Unrecognized form: 0x%lx\n"), form
);
2811 /* What to do? Consume a byte maybe? */
2816 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2817 && num_debug_info_entries
== 0
2818 && debug_info_p
!= NULL
)
2822 case DW_AT_loclists_base
:
2823 if (debug_info_p
->loclists_base
)
2824 warn (_("CU @ 0x%s has multiple loclists_base values"),
2825 dwarf_vmatoa ("x", debug_info_p
->cu_offset
));
2826 debug_info_p
->loclists_base
= uvalue
;
2828 case DW_AT_rnglists_base
:
2829 if (debug_info_p
->rnglists_base
)
2830 warn (_("CU @ 0x%s has multiple rnglists_base values"),
2831 dwarf_vmatoa ("x", debug_info_p
->cu_offset
));
2832 debug_info_p
->rnglists_base
= uvalue
;
2834 case DW_AT_frame_base
:
2835 have_frame_base
= 1;
2837 case DW_AT_location
:
2838 case DW_AT_GNU_locviews
:
2839 case DW_AT_string_length
:
2840 case DW_AT_return_addr
:
2841 case DW_AT_data_member_location
:
2842 case DW_AT_vtable_elem_location
:
2844 case DW_AT_static_link
:
2845 case DW_AT_use_location
:
2846 case DW_AT_call_value
:
2847 case DW_AT_GNU_call_site_value
:
2848 case DW_AT_call_data_value
:
2849 case DW_AT_GNU_call_site_data_value
:
2850 case DW_AT_call_target
:
2851 case DW_AT_GNU_call_site_target
:
2852 case DW_AT_call_target_clobbered
:
2853 case DW_AT_GNU_call_site_target_clobbered
:
2854 if ((dwarf_version
< 4
2855 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2856 || form
== DW_FORM_sec_offset
2857 || form
== DW_FORM_loclistx
)
2859 /* Process location list. */
2860 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2861 unsigned int num
= debug_info_p
->num_loc_offsets
;
2863 if (lmax
== 0 || num
>= lmax
)
2866 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2867 xcrealloc (debug_info_p
->loc_offsets
,
2868 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2869 debug_info_p
->loc_views
= (dwarf_vma
*)
2870 xcrealloc (debug_info_p
->loc_views
,
2871 lmax
, sizeof (*debug_info_p
->loc_views
));
2872 debug_info_p
->have_frame_base
= (int *)
2873 xcrealloc (debug_info_p
->have_frame_base
,
2874 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2875 debug_info_p
->max_loc_offsets
= lmax
;
2878 if (form
== DW_FORM_loclistx
)
2879 uvalue
= fetch_indexed_value (uvalue
, loclists
);
2880 else if (this_set
!= NULL
)
2881 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2883 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2884 if (attribute
!= DW_AT_GNU_locviews
)
2886 uvalue
+= debug_info_p
->loclists_base
;
2888 /* Corrupt DWARF info can produce more offsets than views.
2889 See PR 23062 for an example. */
2890 if (debug_info_p
->num_loc_offsets
2891 > debug_info_p
->num_loc_views
)
2892 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2895 debug_info_p
->loc_offsets
[num
] = uvalue
;
2896 debug_info_p
->num_loc_offsets
++;
2901 assert (debug_info_p
->num_loc_views
<= num
);
2902 num
= debug_info_p
->num_loc_views
;
2903 if (num
> debug_info_p
->num_loc_offsets
)
2904 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2907 debug_info_p
->loc_views
[num
] = uvalue
;
2908 debug_info_p
->num_loc_views
++;
2915 if (need_base_address
)
2916 debug_info_p
->base_address
= uvalue
;
2919 case DW_AT_GNU_addr_base
:
2920 case DW_AT_addr_base
:
2921 debug_info_p
->addr_base
= uvalue
;
2924 case DW_AT_GNU_ranges_base
:
2925 debug_info_p
->ranges_base
= uvalue
;
2929 if ((dwarf_version
< 4
2930 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2931 || form
== DW_FORM_sec_offset
2932 || form
== DW_FORM_rnglistx
)
2934 /* Process range list. */
2935 unsigned int lmax
= debug_info_p
->max_range_lists
;
2936 unsigned int num
= debug_info_p
->num_range_lists
;
2938 if (lmax
== 0 || num
>= lmax
)
2941 debug_info_p
->range_lists
= (dwarf_vma
*)
2942 xcrealloc (debug_info_p
->range_lists
,
2943 lmax
, sizeof (*debug_info_p
->range_lists
));
2944 debug_info_p
->max_range_lists
= lmax
;
2947 if (form
== DW_FORM_rnglistx
)
2948 uvalue
= fetch_indexed_value (uvalue
, rnglists
);
2950 debug_info_p
->range_lists
[num
] = uvalue
;
2951 debug_info_p
->num_range_lists
++;
2955 case DW_AT_GNU_dwo_name
:
2956 case DW_AT_dwo_name
:
2961 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2963 case DW_FORM_GNU_strp_alt
:
2964 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2966 case DW_FORM_GNU_str_index
:
2972 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2974 case DW_FORM_string
:
2975 add_dwo_name ((const char *) orig_data
, cu_offset
);
2978 warn (_("Unsupported form (%s) for attribute %s\n"),
2979 get_FORM_name (form
), get_AT_name (attribute
));
2984 case DW_AT_comp_dir
:
2985 /* FIXME: Also extract a build-id in a CU/TU. */
2990 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2992 case DW_FORM_GNU_strp_alt
:
2993 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2995 case DW_FORM_line_strp
:
2996 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2998 case DW_FORM_GNU_str_index
:
3004 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
3006 case DW_FORM_string
:
3007 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3010 warn (_("Unsupported form (%s) for attribute %s\n"),
3011 get_FORM_name (form
), get_AT_name (attribute
));
3016 case DW_AT_GNU_dwo_id
:
3021 /* FIXME: Record the length of the ID as well ? */
3022 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3025 warn (_("Unsupported form (%s) for attribute %s\n"),
3026 get_FORM_name (form
), get_AT_name (attribute
));
3036 if (do_loc
|| attribute
== 0)
3039 /* For some attributes we can display further information. */
3043 if (level
>= 0 && level
< MAX_CU_NESTING
3044 && uvalue
< (size_t) (end
- start
))
3046 bool is_signed
= false;
3047 abbrev_entry
*type_abbrev
;
3048 unsigned char *type_data
;
3051 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3055 if (type_abbrev
!= NULL
)
3057 get_type_signedness (type_abbrev
, section
, type_data
,
3058 map
? section
->start
+ map
->end
: end
,
3059 map
? map
->start
: cu_offset
,
3060 pointer_size
, offset_size
, dwarf_version
,
3063 level_type_signed
[level
] = is_signed
;
3071 case DW_INL_not_inlined
:
3072 printf (_("(not inlined)"));
3074 case DW_INL_inlined
:
3075 printf (_("(inlined)"));
3077 case DW_INL_declared_not_inlined
:
3078 printf (_("(declared as inline but ignored)"));
3080 case DW_INL_declared_inlined
:
3081 printf (_("(declared as inline and inlined)"));
3084 printf (_(" (Unknown inline attribute value: %s)"),
3085 dwarf_vmatoa ("x", uvalue
));
3090 case DW_AT_language
:
3094 /* Ordered by the numeric value of these constants. */
3095 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3096 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3097 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3098 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3099 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3100 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3101 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3102 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3103 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3104 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3105 /* DWARF 2.1 values. */
3106 case DW_LANG_Java
: printf ("(Java)"); break;
3107 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3108 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3109 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3110 /* DWARF 3 values. */
3111 case DW_LANG_PLI
: printf ("(PLI)"); break;
3112 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3113 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3114 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3115 case DW_LANG_D
: printf ("(D)"); break;
3116 /* DWARF 4 values. */
3117 case DW_LANG_Python
: printf ("(Python)"); break;
3118 /* DWARF 5 values. */
3119 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3120 case DW_LANG_Go
: printf ("(Go)"); break;
3121 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3122 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3123 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3124 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3125 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3126 case DW_LANG_Rust
: printf ("(Rust)"); break;
3127 case DW_LANG_C11
: printf ("(C11)"); break;
3128 case DW_LANG_Swift
: printf ("(Swift)"); break;
3129 case DW_LANG_Julia
: printf ("(Julia)"); break;
3130 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3131 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3132 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3133 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3134 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3135 /* MIPS extension. */
3136 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3137 /* UPC extension. */
3138 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3140 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3141 printf (_("(implementation defined: %s)"),
3142 dwarf_vmatoa ("x", uvalue
));
3144 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3149 case DW_AT_encoding
:
3153 case DW_ATE_void
: printf ("(void)"); break;
3154 case DW_ATE_address
: printf ("(machine address)"); break;
3155 case DW_ATE_boolean
: printf ("(boolean)"); break;
3156 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3157 case DW_ATE_float
: printf ("(float)"); break;
3158 case DW_ATE_signed
: printf ("(signed)"); break;
3159 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3160 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3161 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3162 /* DWARF 2.1 values: */
3163 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3164 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3165 /* DWARF 3 values: */
3166 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3167 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3168 case DW_ATE_edited
: printf ("(edited)"); break;
3169 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3170 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3171 /* DWARF 4 values: */
3172 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3173 /* DWARF 5 values: */
3174 case DW_ATE_UCS
: printf ("(UCS)"); break;
3175 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3177 /* HP extensions: */
3178 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3179 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3180 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3181 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3182 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3183 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3184 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3187 if (uvalue
>= DW_ATE_lo_user
3188 && uvalue
<= DW_ATE_hi_user
)
3189 printf (_("(user defined type)"));
3191 printf (_("(unknown type)"));
3196 case DW_AT_accessibility
:
3200 case DW_ACCESS_public
: printf ("(public)"); break;
3201 case DW_ACCESS_protected
: printf ("(protected)"); break;
3202 case DW_ACCESS_private
: printf ("(private)"); break;
3204 printf (_("(unknown accessibility)"));
3209 case DW_AT_visibility
:
3213 case DW_VIS_local
: printf ("(local)"); break;
3214 case DW_VIS_exported
: printf ("(exported)"); break;
3215 case DW_VIS_qualified
: printf ("(qualified)"); break;
3216 default: printf (_("(unknown visibility)")); break;
3220 case DW_AT_endianity
:
3224 case DW_END_default
: printf ("(default)"); break;
3225 case DW_END_big
: printf ("(big)"); break;
3226 case DW_END_little
: printf ("(little)"); break;
3228 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3229 printf (_("(user specified)"));
3231 printf (_("(unknown endianity)"));
3236 case DW_AT_virtuality
:
3240 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3241 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3242 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3243 default: printf (_("(unknown virtuality)")); break;
3247 case DW_AT_identifier_case
:
3251 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3252 case DW_ID_up_case
: printf ("(up_case)"); break;
3253 case DW_ID_down_case
: printf ("(down_case)"); break;
3254 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3255 default: printf (_("(unknown case)")); break;
3259 case DW_AT_calling_convention
:
3263 case DW_CC_normal
: printf ("(normal)"); break;
3264 case DW_CC_program
: printf ("(program)"); break;
3265 case DW_CC_nocall
: printf ("(nocall)"); break;
3266 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3267 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3268 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3269 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3271 if (uvalue
>= DW_CC_lo_user
3272 && uvalue
<= DW_CC_hi_user
)
3273 printf (_("(user defined)"));
3275 printf (_("(unknown convention)"));
3279 case DW_AT_ordering
:
3284 case -1: printf (_("(undefined)")); break;
3285 case 0: printf ("(row major)"); break;
3286 case 1: printf ("(column major)"); break;
3290 case DW_AT_decimal_sign
:
3294 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3295 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3296 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3297 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3298 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3299 default: printf (_("(unrecognised)")); break;
3303 case DW_AT_defaulted
:
3307 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3308 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3309 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3310 default: printf (_("(unrecognised)")); break;
3314 case DW_AT_discr_list
:
3316 display_discr_list (form
, uvalue
, data
, level
);
3319 case DW_AT_frame_base
:
3320 have_frame_base
= 1;
3322 case DW_AT_location
:
3323 case DW_AT_loclists_base
:
3324 case DW_AT_rnglists_base
:
3325 case DW_AT_string_length
:
3326 case DW_AT_return_addr
:
3327 case DW_AT_data_member_location
:
3328 case DW_AT_vtable_elem_location
:
3330 case DW_AT_static_link
:
3331 case DW_AT_use_location
:
3332 case DW_AT_call_value
:
3333 case DW_AT_GNU_call_site_value
:
3334 case DW_AT_call_data_value
:
3335 case DW_AT_GNU_call_site_data_value
:
3336 case DW_AT_call_target
:
3337 case DW_AT_GNU_call_site_target
:
3338 case DW_AT_call_target_clobbered
:
3339 case DW_AT_GNU_call_site_target_clobbered
:
3340 if ((dwarf_version
< 4
3341 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3342 || form
== DW_FORM_sec_offset
3343 || form
== DW_FORM_loclistx
)
3345 if (attribute
!= DW_AT_rnglists_base
)
3346 printf (_(" (location list)"));
3349 case DW_AT_allocated
:
3350 case DW_AT_associated
:
3351 case DW_AT_data_location
:
3353 case DW_AT_upper_bound
:
3354 case DW_AT_lower_bound
:
3357 int need_frame_base
;
3360 need_frame_base
= decode_location_expression (block_start
,
3365 cu_offset
, section
);
3367 if (need_frame_base
&& !have_frame_base
)
3368 printf (_(" [without DW_AT_frame_base]"));
3372 case DW_AT_data_bit_offset
:
3373 case DW_AT_byte_size
:
3374 case DW_AT_bit_size
:
3375 case DW_AT_string_length_byte_size
:
3376 case DW_AT_string_length_bit_size
:
3377 case DW_AT_bit_stride
:
3378 if (form
== DW_FORM_exprloc
)
3381 (void) decode_location_expression (block_start
, pointer_size
,
3382 offset_size
, dwarf_version
,
3383 uvalue
, cu_offset
, section
);
3390 unsigned long abbrev_number
;
3391 abbrev_entry
*entry
;
3393 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3394 section
, & abbrev_number
, NULL
, NULL
);
3397 if (form
!= DW_FORM_GNU_ref_alt
)
3398 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3399 dwarf_vmatoa ("x", uvalue
),
3400 (unsigned long) (orig_data
- section
->start
));
3404 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3405 printf (" (%s)", get_TAG_name (entry
->tag
));
3418 static unsigned char *
3419 read_and_display_attr (unsigned long attribute
,
3421 dwarf_signed_vma implicit_const
,
3422 unsigned char * start
,
3423 unsigned char * data
,
3424 unsigned char * end
,
3425 dwarf_vma cu_offset
,
3426 dwarf_vma pointer_size
,
3427 dwarf_vma offset_size
,
3429 debug_info
* debug_info_p
,
3431 struct dwarf_section
* section
,
3432 struct cu_tu_set
* this_set
,
3436 printf (" %-18s:", get_AT_name (attribute
));
3437 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3439 cu_offset
, pointer_size
, offset_size
,
3440 dwarf_version
, debug_info_p
,
3441 do_loc
, section
, this_set
, ' ', level
);
3447 /* Like load_debug_section, but if the ordinary call fails, and we are
3448 following debug links, then attempt to load the requested section
3449 from one of the separate debug info files. */
3452 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3455 if (load_debug_section (sec_enum
, handle
))
3457 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3459 /* See if we can associate a filename with this section. */
3462 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3463 if (i
->handle
== handle
)
3465 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3473 if (do_follow_links
)
3477 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3479 if (load_debug_section (sec_enum
, i
->handle
))
3481 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3483 /* FIXME: We should check to see if any of the remaining debug info
3484 files also contain this section, and, umm, do something about it. */
3494 introduce (struct dwarf_section
* section
, bool raw
)
3498 if (do_follow_links
&& section
->filename
)
3499 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3500 section
->name
, section
->filename
);
3502 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3506 if (do_follow_links
&& section
->filename
)
3507 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3508 section
->name
, section
->filename
);
3510 printf (_("Contents of the %s section:\n\n"), section
->name
);
3514 /* Process the contents of a .debug_info section.
3515 If do_loc is TRUE then we are scanning for location lists and dwo tags
3516 and we do not want to display anything to the user.
3517 If do_types is TRUE, we are processing a .debug_types section instead of
3518 a .debug_info section.
3519 The information displayed is restricted by the values in DWARF_START_DIE
3520 and DWARF_CUTOFF_LEVEL.
3521 Returns TRUE upon success. Otherwise an error or warning message is
3522 printed and FALSE is returned. */
3525 process_debug_info (struct dwarf_section
* section
,
3527 enum dwarf_section_display_enum abbrev_sec
,
3531 unsigned char *start
= section
->start
;
3532 unsigned char *end
= start
+ section
->size
;
3533 unsigned char *section_begin
;
3535 unsigned int num_units
= 0;
3537 /* First scan the section to get the number of comp units.
3538 Length sanity checks are done here. */
3539 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3544 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3545 will be the length. For a 64-bit DWARF section, it'll be
3546 the escape code 0xffffffff followed by an 8 byte length. */
3547 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3549 if (length
== 0xffffffff)
3550 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3551 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3553 warn (_("Reserved length value (0x%s) found in section %s\n"),
3554 dwarf_vmatoa ("x", length
), section
->name
);
3558 /* Negative values are illegal, they may even cause infinite
3559 looping. This can happen if we can't accurately apply
3560 relocations to an object file, or if the file is corrupt. */
3561 if (length
> (size_t) (end
- section_begin
))
3563 warn (_("Corrupt unit length (got 0x%s expected at most 0x%s) in section %s\n"),
3564 dwarf_vmatoa ("x", length
),
3565 dwarf_vmatoa ("x", end
- section_begin
),
3569 section_begin
+= length
;
3574 error (_("No comp units in %s section ?\n"), section
->name
);
3578 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3579 && num_debug_info_entries
== 0
3583 /* Then allocate an array to hold the information. */
3584 debug_information
= (debug_info
*) cmalloc (num_units
,
3585 sizeof (* debug_information
));
3586 if (debug_information
== NULL
)
3588 error (_("Not enough memory for a debug info array of %u entries\n"),
3590 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3594 /* PR 17531: file: 92ca3797.
3595 We cannot rely upon the debug_information array being initialised
3596 before it is used. A corrupt file could easily contain references
3597 to a unit for which information has not been made available. So
3598 we ensure that the array is zeroed here. */
3599 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3601 alloc_num_debug_info_entries
= num_units
;
3606 load_debug_section_with_follow (str
, file
);
3607 load_debug_section_with_follow (line_str
, file
);
3608 load_debug_section_with_follow (str_dwo
, file
);
3609 load_debug_section_with_follow (str_index
, file
);
3610 load_debug_section_with_follow (str_index_dwo
, file
);
3611 load_debug_section_with_follow (debug_addr
, file
);
3614 load_debug_section_with_follow (abbrev_sec
, file
);
3615 load_debug_section_with_follow (loclists
, file
);
3616 load_debug_section_with_follow (rnglists
, file
);
3618 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3620 warn (_("Unable to locate %s section!\n"),
3621 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3625 if (!do_loc
&& dwarf_start_die
== 0)
3626 introduce (section
, false);
3628 free_all_abbrevs ();
3629 free (cu_abbrev_map
);
3630 cu_abbrev_map
= NULL
;
3631 next_free_abbrev_map_entry
= 0;
3633 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3634 to load *all* of the abbrevs for all CUs in this .debug_info
3635 section. This does effectively mean that we (partially) read
3636 every CU header twice. */
3637 for (section_begin
= start
; start
< end
;)
3639 DWARF2_Internal_CompUnit compunit
;
3640 unsigned char * hdrptr
;
3641 dwarf_vma abbrev_base
;
3643 dwarf_vma cu_offset
;
3644 unsigned int offset_size
;
3645 struct cu_tu_set
* this_set
;
3647 unsigned char *end_cu
;
3650 cu_offset
= start
- section_begin
;
3652 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3654 if (compunit
.cu_length
== 0xffffffff)
3656 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3661 end_cu
= hdrptr
+ compunit
.cu_length
;
3663 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3665 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3667 if (compunit
.cu_version
< 5)
3669 compunit
.cu_unit_type
= DW_UT_compile
;
3670 /* Initialize it due to a false compiler warning. */
3671 compunit
.cu_pointer_size
= -1;
3675 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3676 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3678 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3681 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3684 if (compunit
.cu_unit_type
== DW_UT_split_compile
3685 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3688 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3691 if (this_set
== NULL
)
3694 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3698 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3699 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3702 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3703 compunit
.cu_abbrev_offset
);
3706 unsigned char * next
;
3708 list
= new_abbrev_list (abbrev_base
,
3709 compunit
.cu_abbrev_offset
);
3710 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3711 abbrev_base
, abbrev_size
,
3712 compunit
.cu_abbrev_offset
, list
);
3713 list
->start_of_next_abbrevs
= next
;
3717 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3720 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3722 DWARF2_Internal_CompUnit compunit
;
3723 unsigned char *hdrptr
;
3724 unsigned char *tags
;
3725 int level
, last_level
, saved_level
;
3726 dwarf_vma cu_offset
;
3727 unsigned int offset_size
;
3728 dwarf_vma signature
= 0;
3729 dwarf_vma type_offset
= 0;
3730 struct cu_tu_set
*this_set
;
3731 dwarf_vma abbrev_base
;
3733 abbrev_list
* list
= NULL
;
3734 unsigned char *end_cu
;
3737 cu_offset
= start
- section_begin
;
3739 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3741 if (compunit
.cu_length
== 0xffffffff)
3743 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3748 end_cu
= hdrptr
+ compunit
.cu_length
;
3750 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3752 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3754 if (compunit
.cu_version
< 5)
3756 compunit
.cu_unit_type
= DW_UT_compile
;
3757 /* Initialize it due to a false compiler warning. */
3758 compunit
.cu_pointer_size
= -1;
3762 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3763 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3765 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3768 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3770 if (this_set
== NULL
)
3773 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3777 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3778 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3781 if (compunit
.cu_version
< 5)
3782 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3784 bool do_dwo_id
= false;
3785 uint64_t dwo_id
= 0;
3786 if (compunit
.cu_unit_type
== DW_UT_split_compile
3787 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3789 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3793 /* PR 17512: file: 001-108546-0.001:0.1. */
3794 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3796 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3797 compunit
.cu_pointer_size
, offset_size
);
3798 compunit
.cu_pointer_size
= offset_size
;
3803 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3804 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3807 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3813 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3814 && num_debug_info_entries
== 0
3815 && alloc_num_debug_info_entries
> unit
3818 debug_information
[unit
].cu_offset
= cu_offset
;
3819 debug_information
[unit
].pointer_size
3820 = compunit
.cu_pointer_size
;
3821 debug_information
[unit
].offset_size
= offset_size
;
3822 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3823 debug_information
[unit
].base_address
= 0;
3824 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3825 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3826 debug_information
[unit
].loc_offsets
= NULL
;
3827 debug_information
[unit
].have_frame_base
= NULL
;
3828 debug_information
[unit
].max_loc_offsets
= 0;
3829 debug_information
[unit
].num_loc_offsets
= 0;
3830 debug_information
[unit
].loclists_base
= 0;
3831 debug_information
[unit
].range_lists
= NULL
;
3832 debug_information
[unit
].max_range_lists
= 0;
3833 debug_information
[unit
].num_range_lists
= 0;
3834 debug_information
[unit
].rnglists_base
= 0;
3837 if (!do_loc
&& dwarf_start_die
== 0)
3839 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3840 dwarf_vmatoa ("x", cu_offset
));
3841 printf (_(" Length: 0x%s (%s)\n"),
3842 dwarf_vmatoa ("x", compunit
.cu_length
),
3843 offset_size
== 8 ? "64-bit" : "32-bit");
3844 printf (_(" Version: %d\n"), compunit
.cu_version
);
3845 if (compunit
.cu_version
>= 5)
3847 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3849 printf (_(" Unit Type: %s (%x)\n"),
3850 name
? name
: "???",
3851 compunit
.cu_unit_type
);
3853 printf (_(" Abbrev Offset: 0x%s\n"),
3854 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3855 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3858 printf (_(" Signature: 0x%s\n"),
3859 dwarf_vmatoa ("x", signature
));
3860 printf (_(" Type Offset: 0x%s\n"),
3861 dwarf_vmatoa ("x", type_offset
));
3864 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3865 if (this_set
!= NULL
)
3867 dwarf_vma
*offsets
= this_set
->section_offsets
;
3868 size_t *sizes
= this_set
->section_sizes
;
3870 printf (_(" Section contributions:\n"));
3871 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3872 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3873 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3874 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3875 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3876 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3877 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3878 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3879 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3880 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3881 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3882 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3889 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3891 warn (_("CU at offset %s contains corrupt or "
3892 "unsupported version number: %d.\n"),
3893 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3897 if (compunit
.cu_unit_type
!= DW_UT_compile
3898 && compunit
.cu_unit_type
!= DW_UT_partial
3899 && compunit
.cu_unit_type
!= DW_UT_type
3900 && compunit
.cu_unit_type
!= DW_UT_split_compile
3901 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3903 warn (_("CU at offset %s contains corrupt or "
3904 "unsupported unit type: %d.\n"),
3905 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3909 /* Process the abbrevs used by this compilation unit. */
3910 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3911 compunit
.cu_abbrev_offset
);
3914 unsigned char *next
;
3916 list
= new_abbrev_list (abbrev_base
,
3917 compunit
.cu_abbrev_offset
);
3918 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3919 abbrev_base
, abbrev_size
,
3920 compunit
.cu_abbrev_offset
, list
);
3921 list
->start_of_next_abbrevs
= next
;
3927 while (tags
< start
)
3929 unsigned long abbrev_number
;
3930 unsigned long die_offset
;
3931 abbrev_entry
*entry
;
3933 int do_printing
= 1;
3935 die_offset
= tags
- section_begin
;
3937 READ_ULEB (abbrev_number
, tags
, start
);
3939 /* A null DIE marks the end of a list of siblings or it may also be
3940 a section padding. */
3941 if (abbrev_number
== 0)
3943 /* Check if it can be a section padding for the last CU. */
3944 if (level
== 0 && start
== end
)
3948 for (chk
= tags
; chk
< start
; chk
++)
3955 if (!do_loc
&& die_offset
>= dwarf_start_die
3956 && (dwarf_cutoff_level
== -1
3957 || level
< dwarf_cutoff_level
))
3958 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3964 static unsigned num_bogus_warns
= 0;
3966 if (num_bogus_warns
< 3)
3968 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3969 die_offset
, section
->name
);
3971 if (num_bogus_warns
== 3)
3972 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3975 if (dwarf_start_die
!= 0 && level
< saved_level
)
3982 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3986 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3987 saved_level
= level
;
3988 do_printing
= (dwarf_cutoff_level
== -1
3989 || level
< dwarf_cutoff_level
);
3991 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3992 level
, die_offset
, abbrev_number
);
3993 else if (dwarf_cutoff_level
== -1
3994 || last_level
< dwarf_cutoff_level
)
3995 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
4000 /* Scan through the abbreviation list until we reach the
4005 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
4006 if (entry
->number
== abbrev_number
)
4011 if (!do_loc
&& do_printing
)
4016 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
4017 die_offset
, abbrev_number
);
4021 if (!do_loc
&& do_printing
)
4022 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4027 need_base_address
= 0;
4029 case DW_TAG_compile_unit
:
4030 need_base_address
= 1;
4031 need_dwo_info
= do_loc
;
4033 case DW_TAG_entry_point
:
4034 case DW_TAG_subprogram
:
4035 need_base_address
= 0;
4036 /* Assuming that there is no DW_AT_frame_base. */
4037 have_frame_base
= 0;
4041 debug_info
*debug_info_p
=
4042 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4043 ? debug_information
+ unit
: NULL
;
4045 assert (!debug_info_p
4046 || (debug_info_p
->num_loc_offsets
4047 == debug_info_p
->num_loc_views
));
4049 for (attr
= entry
->first_attr
;
4050 attr
&& attr
->attribute
;
4053 if (! do_loc
&& do_printing
)
4054 /* Show the offset from where the tag was extracted. */
4055 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
4056 tags
= read_and_display_attr (attr
->attribute
,
4058 attr
->implicit_const
,
4063 compunit
.cu_pointer_size
,
4065 compunit
.cu_version
,
4067 do_loc
|| ! do_printing
,
4073 /* If a locview attribute appears before a location one,
4074 make sure we don't associate it with an earlier
4077 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4080 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4081 debug_info_p
->num_loc_views
++;
4082 assert (debug_info_p
->num_loc_views
4083 == debug_info_p
->num_loc_offsets
);
4090 warn(_("DIE has locviews without loclist\n"));
4091 debug_info_p
->num_loc_views
--;
4098 if (entry
->children
)
4103 /* Set num_debug_info_entries here so that it can be used to check if
4104 we need to process .debug_loc and .debug_ranges sections. */
4105 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4106 && num_debug_info_entries
== 0
4109 if (num_units
> alloc_num_debug_info_entries
)
4110 num_debug_info_entries
= alloc_num_debug_info_entries
;
4112 num_debug_info_entries
= num_units
;
4121 /* Locate and scan the .debug_info section in the file and record the pointer
4122 sizes and offsets for the compilation units in it. Usually an executable
4123 will have just one pointer size, but this is not guaranteed, and so we try
4124 not to make any assumptions. Returns zero upon failure, or the number of
4125 compilation units upon success. */
4128 load_debug_info (void * file
)
4130 /* If we have already tried and failed to load the .debug_info
4131 section then do not bother to repeat the task. */
4132 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4135 /* If we already have the information there is nothing else to do. */
4136 if (num_debug_info_entries
> 0)
4137 return num_debug_info_entries
;
4139 /* If this is a DWARF package file, load the CU and TU indexes. */
4140 (void) load_cu_tu_indexes (file
);
4142 if (load_debug_section_with_follow (info
, file
)
4143 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4144 return num_debug_info_entries
;
4146 if (load_debug_section_with_follow (info_dwo
, file
)
4147 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4148 abbrev_dwo
, true, false))
4149 return num_debug_info_entries
;
4151 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4155 /* Read a DWARF .debug_line section header starting at DATA.
4156 Upon success returns an updated DATA pointer and the LINFO
4157 structure and the END_OF_SEQUENCE pointer will be filled in.
4158 Otherwise returns NULL. */
4160 static unsigned char *
4161 read_debug_line_header (struct dwarf_section
* section
,
4162 unsigned char * data
,
4163 unsigned char * end
,
4164 DWARF2_Internal_LineInfo
* linfo
,
4165 unsigned char ** end_of_sequence
)
4167 unsigned char *hdrptr
;
4169 /* Extract information from the Line Number Program Header.
4170 (section 6.2.4 in the Dwarf3 doc). */
4173 /* Get and check the length of the block. */
4174 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4176 if (linfo
->li_length
== 0xffffffff)
4178 /* This section is 64-bit DWARF 3. */
4179 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4180 linfo
->li_offset_size
= 8;
4183 linfo
->li_offset_size
= 4;
4185 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4187 /* If the length field has a relocation against it, then we should
4188 not complain if it is inaccurate (and probably negative). This
4189 happens in object files when the .debug_line section is actually
4190 comprised of several different .debug_line.* sections, (some of
4191 which may be removed by linker garbage collection), and a relocation
4192 is used to compute the correct length once that is done. */
4193 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4195 linfo
->li_length
= end
- hdrptr
;
4199 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4200 (long) linfo
->li_length
);
4204 end
= hdrptr
+ linfo
->li_length
;
4206 /* Get and check the version number. */
4207 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4209 if (linfo
->li_version
!= 2
4210 && linfo
->li_version
!= 3
4211 && linfo
->li_version
!= 4
4212 && linfo
->li_version
!= 5)
4214 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4215 "is currently supported.\n"));
4219 if (linfo
->li_version
>= 5)
4221 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4223 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4224 if (linfo
->li_segment_size
!= 0)
4226 warn (_("The %s section contains "
4227 "unsupported segment selector size: %d.\n"),
4228 section
->name
, linfo
->li_segment_size
);
4233 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4234 linfo
->li_offset_size
, end
);
4235 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4237 if (linfo
->li_version
>= 4)
4239 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4241 if (linfo
->li_max_ops_per_insn
== 0)
4243 warn (_("Invalid maximum operations per insn.\n"));
4248 linfo
->li_max_ops_per_insn
= 1;
4250 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4251 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4252 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4253 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4255 *end_of_sequence
= end
;
4259 static unsigned char *
4260 display_formatted_table (unsigned char *data
,
4261 unsigned char *start
,
4263 const DWARF2_Internal_LineInfo
*linfo
,
4264 struct dwarf_section
*section
,
4267 unsigned char *format_start
, format_count
, *format
, formati
;
4268 dwarf_vma data_count
, datai
;
4269 unsigned int namepass
, last_entry
= 0;
4270 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4272 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4273 if (do_checks
&& format_count
> 5)
4274 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4275 table_name
, format_count
);
4277 format_start
= data
;
4278 for (formati
= 0; formati
< format_count
; formati
++)
4280 SKIP_ULEB (data
, end
);
4281 SKIP_ULEB (data
, end
);
4284 warn (_("%s: Corrupt format description entry\n"), table_name
);
4289 READ_ULEB (data_count
, data
, end
);
4290 if (data_count
== 0)
4292 printf (_("\n The %s is empty.\n"), table_name
);
4295 else if (data
>= end
)
4297 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4298 table_name
, dwarf_vmatoa ("x", data_count
));
4302 else if (format_count
== 0)
4304 warn (_("%s: format count is zero, but the table is not empty\n"),
4309 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4310 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4313 printf (_(" Entry"));
4314 /* Delay displaying name as the last entry for better screen layout. */
4315 for (namepass
= 0; namepass
< 2; namepass
++)
4317 format
= format_start
;
4318 for (formati
= 0; formati
< format_count
; formati
++)
4320 dwarf_vma content_type
;
4322 READ_ULEB (content_type
, format
, end
);
4323 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4324 switch (content_type
)
4327 printf (_("\tName"));
4329 case DW_LNCT_directory_index
:
4330 printf (_("\tDir"));
4332 case DW_LNCT_timestamp
:
4333 printf (_("\tTime"));
4336 printf (_("\tSize"));
4339 printf (_("\tMD5\t\t\t"));
4342 printf (_("\t(Unknown format content type %s)"),
4343 dwarf_vmatoa ("u", content_type
));
4345 SKIP_ULEB (format
, end
);
4350 for (datai
= 0; datai
< data_count
; datai
++)
4352 unsigned char *datapass
= data
;
4354 printf (" %d", last_entry
++);
4355 /* Delay displaying name as the last entry for better screen layout. */
4356 for (namepass
= 0; namepass
< 2; namepass
++)
4358 format
= format_start
;
4360 for (formati
= 0; formati
< format_count
; formati
++)
4362 dwarf_vma content_type
, form
;
4364 READ_ULEB (content_type
, format
, end
);
4365 READ_ULEB (form
, format
, end
);
4366 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4367 0, 0, linfo
->li_offset_size
,
4368 linfo
->li_version
, NULL
,
4369 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4370 section
, NULL
, '\t', -1);
4374 if (data
>= end
&& (datai
< data_count
- 1))
4376 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4385 display_debug_sup (struct dwarf_section
* section
,
4386 void * file ATTRIBUTE_UNUSED
)
4388 unsigned char * start
= section
->start
;
4389 unsigned char * end
= section
->start
+ section
->size
;
4390 unsigned int version
;
4391 char is_supplementary
;
4392 const unsigned char * sup_filename
;
4393 size_t sup_filename_len
;
4394 unsigned int num_read
;
4396 dwarf_vma checksum_len
;
4399 introduce (section
, true);
4400 if (section
->size
< 4)
4402 error (_("corrupt .debug_sup section: size is too small\n"));
4406 /* Read the data. */
4407 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4409 warn (_("corrupt .debug_sup section: version < 5"));
4411 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4412 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4413 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4415 sup_filename
= start
;
4416 if (is_supplementary
&& sup_filename
[0] != 0)
4417 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4419 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4420 if (sup_filename_len
== (size_t) (end
- start
))
4422 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4425 start
+= sup_filename_len
+ 1;
4427 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4430 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4434 if (checksum_len
> (dwarf_vma
) (end
- start
))
4436 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4437 checksum_len
= end
- start
;
4439 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4441 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4442 (long) ((end
- start
) - checksum_len
));
4445 printf (_(" Version: %u\n"), version
);
4446 printf (_(" Is Supp: %u\n"), is_supplementary
);
4447 printf (_(" Filename: %s\n"), sup_filename
);
4448 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4449 if (checksum_len
> 0)
4451 printf (_(" Checksum: "));
4452 while (checksum_len
--)
4453 printf ("0x%x ", * start
++ );
4460 display_debug_lines_raw (struct dwarf_section
* section
,
4461 unsigned char * data
,
4462 unsigned char * end
,
4465 unsigned char *start
= section
->start
;
4466 int verbose_view
= 0;
4468 introduce (section
, true);
4472 static DWARF2_Internal_LineInfo saved_linfo
;
4473 DWARF2_Internal_LineInfo linfo
;
4474 unsigned char *standard_opcodes
;
4475 unsigned char *end_of_sequence
;
4478 if (startswith (section
->name
, ".debug_line.")
4479 /* Note: the following does not apply to .debug_line.dwo sections.
4480 These are full debug_line sections. */
4481 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4483 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4484 section containing just the Line Number Statements. They are
4485 created by the assembler and intended to be used alongside gcc's
4486 -ffunction-sections command line option. When the linker's
4487 garbage collection decides to discard a .text.<foo> section it
4488 can then also discard the line number information in .debug_line.<foo>.
4490 Since the section is a fragment it does not have the details
4491 needed to fill out a LineInfo structure, so instead we use the
4492 details from the last full debug_line section that we processed. */
4493 end_of_sequence
= end
;
4494 standard_opcodes
= NULL
;
4495 linfo
= saved_linfo
;
4496 /* PR 17531: file: 0522b371. */
4497 if (linfo
.li_line_range
== 0)
4499 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4502 reset_state_machine (linfo
.li_default_is_stmt
);
4506 unsigned char * hdrptr
;
4508 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4509 & end_of_sequence
)) == NULL
)
4512 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4513 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4514 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4515 if (linfo
.li_version
>= 5)
4517 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4518 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4520 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4521 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4522 if (linfo
.li_version
>= 4)
4523 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4524 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4525 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4526 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4527 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4529 /* PR 17512: file: 1665-6428-0.004. */
4530 if (linfo
.li_line_range
== 0)
4532 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4533 linfo
.li_line_range
= 1;
4536 reset_state_machine (linfo
.li_default_is_stmt
);
4538 /* Display the contents of the Opcodes table. */
4539 standard_opcodes
= hdrptr
;
4541 /* PR 17512: file: 002-417945-0.004. */
4542 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4544 warn (_("Line Base extends beyond end of section\n"));
4548 printf (_("\n Opcodes:\n"));
4550 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4551 printf (ngettext (" Opcode %d has %d arg\n",
4552 " Opcode %d has %d args\n",
4553 standard_opcodes
[i
- 1]),
4554 i
, standard_opcodes
[i
- 1]);
4556 /* Display the contents of the Directory table. */
4557 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4559 if (linfo
.li_version
>= 5)
4561 load_debug_section_with_follow (line_str
, file
);
4563 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4565 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4571 printf (_("\n The Directory Table is empty.\n"));
4574 unsigned int last_dir_entry
= 0;
4576 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4577 (long)(data
- start
));
4579 while (data
< end
&& *data
!= 0)
4581 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4583 data
+= strnlen ((char *) data
, end
- data
);
4588 /* PR 17512: file: 002-132094-0.004. */
4589 if (data
>= end
- 1)
4593 /* Skip the NUL at the end of the table. */
4597 /* Display the contents of the File Name table. */
4598 if (data
>= end
|| *data
== 0)
4599 printf (_("\n The File Name Table is empty.\n"));
4602 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4603 (long)(data
- start
));
4604 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4606 while (data
< end
&& *data
!= 0)
4608 unsigned char *name
;
4611 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4613 data
+= strnlen ((char *) data
, end
- data
);
4617 READ_ULEB (val
, data
, end
);
4618 printf ("%s\t", dwarf_vmatoa ("u", val
));
4619 READ_ULEB (val
, data
, end
);
4620 printf ("%s\t", dwarf_vmatoa ("u", val
));
4621 READ_ULEB (val
, data
, end
);
4622 printf ("%s\t", dwarf_vmatoa ("u", val
));
4623 printf ("%.*s\n", (int)(end
- name
), name
);
4627 warn (_("Corrupt file name table entry\n"));
4633 /* Skip the NUL at the end of the table. */
4639 saved_linfo
= linfo
;
4642 /* Now display the statements. */
4643 if (data
>= end_of_sequence
)
4644 printf (_(" No Line Number Statements.\n"));
4647 printf (_(" Line Number Statements:\n"));
4649 while (data
< end_of_sequence
)
4651 unsigned char op_code
;
4652 dwarf_signed_vma adv
;
4655 printf (" [0x%08lx]", (long)(data
- start
));
4659 if (op_code
>= linfo
.li_opcode_base
)
4661 op_code
-= linfo
.li_opcode_base
;
4662 uladv
= (op_code
/ linfo
.li_line_range
);
4663 if (linfo
.li_max_ops_per_insn
== 1)
4665 uladv
*= linfo
.li_min_insn_length
;
4666 state_machine_regs
.address
+= uladv
;
4668 state_machine_regs
.view
= 0;
4669 printf (_(" Special opcode %d: "
4670 "advance Address by %s to 0x%s%s"),
4671 op_code
, dwarf_vmatoa ("u", uladv
),
4672 dwarf_vmatoa ("x", state_machine_regs
.address
),
4673 verbose_view
&& uladv
4674 ? _(" (reset view)") : "");
4679 = ((state_machine_regs
.op_index
+ uladv
)
4680 / linfo
.li_max_ops_per_insn
)
4681 * linfo
.li_min_insn_length
;
4683 state_machine_regs
.address
+= addrdelta
;
4684 state_machine_regs
.op_index
4685 = (state_machine_regs
.op_index
+ uladv
)
4686 % linfo
.li_max_ops_per_insn
;
4688 state_machine_regs
.view
= 0;
4689 printf (_(" Special opcode %d: "
4690 "advance Address by %s to 0x%s[%d]%s"),
4691 op_code
, dwarf_vmatoa ("u", uladv
),
4692 dwarf_vmatoa ("x", state_machine_regs
.address
),
4693 state_machine_regs
.op_index
,
4694 verbose_view
&& addrdelta
4695 ? _(" (reset view)") : "");
4697 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4698 state_machine_regs
.line
+= adv
;
4699 printf (_(" and Line by %s to %d"),
4700 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4701 if (verbose_view
|| state_machine_regs
.view
)
4702 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4705 state_machine_regs
.view
++;
4710 case DW_LNS_extended_op
:
4711 data
+= process_extended_line_op (data
,
4712 linfo
.li_default_is_stmt
,
4717 printf (_(" Copy"));
4718 if (verbose_view
|| state_machine_regs
.view
)
4719 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4722 state_machine_regs
.view
++;
4725 case DW_LNS_advance_pc
:
4726 READ_ULEB (uladv
, data
, end
);
4727 if (linfo
.li_max_ops_per_insn
== 1)
4729 uladv
*= linfo
.li_min_insn_length
;
4730 state_machine_regs
.address
+= uladv
;
4732 state_machine_regs
.view
= 0;
4733 printf (_(" Advance PC by %s to 0x%s%s\n"),
4734 dwarf_vmatoa ("u", uladv
),
4735 dwarf_vmatoa ("x", state_machine_regs
.address
),
4736 verbose_view
&& uladv
4737 ? _(" (reset view)") : "");
4742 = ((state_machine_regs
.op_index
+ uladv
)
4743 / linfo
.li_max_ops_per_insn
)
4744 * linfo
.li_min_insn_length
;
4745 state_machine_regs
.address
4747 state_machine_regs
.op_index
4748 = (state_machine_regs
.op_index
+ uladv
)
4749 % linfo
.li_max_ops_per_insn
;
4751 state_machine_regs
.view
= 0;
4752 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4753 dwarf_vmatoa ("u", uladv
),
4754 dwarf_vmatoa ("x", state_machine_regs
.address
),
4755 state_machine_regs
.op_index
,
4756 verbose_view
&& addrdelta
4757 ? _(" (reset view)") : "");
4761 case DW_LNS_advance_line
:
4762 READ_SLEB (adv
, data
, end
);
4763 state_machine_regs
.line
+= adv
;
4764 printf (_(" Advance Line by %s to %d\n"),
4765 dwarf_vmatoa ("d", adv
),
4766 state_machine_regs
.line
);
4769 case DW_LNS_set_file
:
4770 READ_ULEB (uladv
, data
, end
);
4771 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4772 dwarf_vmatoa ("u", uladv
));
4773 state_machine_regs
.file
= uladv
;
4776 case DW_LNS_set_column
:
4777 READ_ULEB (uladv
, data
, end
);
4778 printf (_(" Set column to %s\n"),
4779 dwarf_vmatoa ("u", uladv
));
4780 state_machine_regs
.column
= uladv
;
4783 case DW_LNS_negate_stmt
:
4784 adv
= state_machine_regs
.is_stmt
;
4786 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4787 state_machine_regs
.is_stmt
= adv
;
4790 case DW_LNS_set_basic_block
:
4791 printf (_(" Set basic block\n"));
4792 state_machine_regs
.basic_block
= 1;
4795 case DW_LNS_const_add_pc
:
4796 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4797 if (linfo
.li_max_ops_per_insn
)
4799 uladv
*= linfo
.li_min_insn_length
;
4800 state_machine_regs
.address
+= uladv
;
4802 state_machine_regs
.view
= 0;
4803 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4804 dwarf_vmatoa ("u", uladv
),
4805 dwarf_vmatoa ("x", state_machine_regs
.address
),
4806 verbose_view
&& uladv
4807 ? _(" (reset view)") : "");
4812 = ((state_machine_regs
.op_index
+ uladv
)
4813 / linfo
.li_max_ops_per_insn
)
4814 * linfo
.li_min_insn_length
;
4815 state_machine_regs
.address
4817 state_machine_regs
.op_index
4818 = (state_machine_regs
.op_index
+ uladv
)
4819 % linfo
.li_max_ops_per_insn
;
4821 state_machine_regs
.view
= 0;
4822 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4823 dwarf_vmatoa ("u", uladv
),
4824 dwarf_vmatoa ("x", state_machine_regs
.address
),
4825 state_machine_regs
.op_index
,
4826 verbose_view
&& addrdelta
4827 ? _(" (reset view)") : "");
4831 case DW_LNS_fixed_advance_pc
:
4832 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4833 state_machine_regs
.address
+= uladv
;
4834 state_machine_regs
.op_index
= 0;
4835 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4836 dwarf_vmatoa ("u", uladv
),
4837 dwarf_vmatoa ("x", state_machine_regs
.address
));
4838 /* Do NOT reset view. */
4841 case DW_LNS_set_prologue_end
:
4842 printf (_(" Set prologue_end to true\n"));
4845 case DW_LNS_set_epilogue_begin
:
4846 printf (_(" Set epilogue_begin to true\n"));
4849 case DW_LNS_set_isa
:
4850 READ_ULEB (uladv
, data
, end
);
4851 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4855 printf (_(" Unknown opcode %d with operands: "), op_code
);
4857 if (standard_opcodes
!= NULL
)
4858 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4860 READ_ULEB (uladv
, data
, end
);
4861 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4862 i
== 1 ? "" : ", ");
4877 unsigned char *name
;
4878 unsigned int directory_index
;
4879 unsigned int modification_date
;
4880 unsigned int length
;
4883 /* Output a decoded representation of the .debug_line section. */
4886 display_debug_lines_decoded (struct dwarf_section
* section
,
4887 unsigned char * start
,
4888 unsigned char * data
,
4889 unsigned char * end
,
4892 static DWARF2_Internal_LineInfo saved_linfo
;
4894 introduce (section
, false);
4898 /* This loop amounts to one iteration per compilation unit. */
4899 DWARF2_Internal_LineInfo linfo
;
4900 unsigned char *standard_opcodes
;
4901 unsigned char *end_of_sequence
;
4903 File_Entry
*file_table
= NULL
;
4904 unsigned int n_files
= 0;
4905 unsigned char **directory_table
= NULL
;
4906 dwarf_vma n_directories
= 0;
4908 if (startswith (section
->name
, ".debug_line.")
4909 /* Note: the following does not apply to .debug_line.dwo sections.
4910 These are full debug_line sections. */
4911 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4913 /* See comment in display_debug_lines_raw(). */
4914 end_of_sequence
= end
;
4915 standard_opcodes
= NULL
;
4916 linfo
= saved_linfo
;
4917 /* PR 17531: file: 0522b371. */
4918 if (linfo
.li_line_range
== 0)
4920 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4923 reset_state_machine (linfo
.li_default_is_stmt
);
4927 unsigned char *hdrptr
;
4929 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4930 & end_of_sequence
)) == NULL
)
4933 /* PR 17531: file: 0522b371. */
4934 if (linfo
.li_line_range
== 0)
4936 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4937 linfo
.li_line_range
= 1;
4939 reset_state_machine (linfo
.li_default_is_stmt
);
4941 /* Save a pointer to the contents of the Opcodes table. */
4942 standard_opcodes
= hdrptr
;
4944 /* Traverse the Directory table just to count entries. */
4945 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4949 warn (_("opcode base of %d extends beyond end of section\n"),
4950 linfo
.li_opcode_base
);
4954 if (linfo
.li_version
>= 5)
4956 unsigned char *format_start
, format_count
, *format
;
4957 dwarf_vma formati
, entryi
;
4959 load_debug_section_with_follow (line_str
, fileptr
);
4961 /* Skip directories format. */
4962 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4963 if (do_checks
&& format_count
> 1)
4964 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4966 format_start
= data
;
4967 for (formati
= 0; formati
< format_count
; formati
++)
4969 SKIP_ULEB (data
, end
);
4970 SKIP_ULEB (data
, end
);
4973 READ_ULEB (n_directories
, data
, end
);
4976 warn (_("Corrupt directories list\n"));
4980 if (n_directories
== 0)
4981 directory_table
= NULL
;
4983 directory_table
= (unsigned char **)
4984 xmalloc (n_directories
* sizeof (unsigned char *));
4986 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4988 unsigned char **pathp
= &directory_table
[entryi
];
4990 format
= format_start
;
4991 for (formati
= 0; formati
< format_count
; formati
++)
4993 dwarf_vma content_type
, form
;
4996 READ_ULEB (content_type
, format
, end
);
4997 READ_ULEB (form
, format
, end
);
5000 warn (_("Corrupt directories list\n"));
5003 switch (content_type
)
5008 case DW_FORM_string
:
5011 case DW_FORM_line_strp
:
5012 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5014 /* Remove const by the cast. */
5015 *pathp
= (unsigned char *)
5016 fetch_indirect_line_string (uvalue
);
5021 data
= read_and_display_attr_value (0, form
, 0, start
,
5023 linfo
.li_offset_size
,
5030 warn (_("Corrupt directories list\n"));
5035 /* Skip files format. */
5036 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5037 if (do_checks
&& format_count
> 5)
5038 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5040 format_start
= data
;
5041 for (formati
= 0; formati
< format_count
; formati
++)
5043 SKIP_ULEB (data
, end
);
5044 SKIP_ULEB (data
, end
);
5047 READ_ULEB (n_files
, data
, end
);
5048 if (data
>= end
&& n_files
> 0)
5050 warn (_("Corrupt file name list\n"));
5057 file_table
= (File_Entry
*) xcalloc (1, n_files
5058 * sizeof (File_Entry
));
5060 for (entryi
= 0; entryi
< n_files
; entryi
++)
5062 File_Entry
*file
= &file_table
[entryi
];
5064 format
= format_start
;
5065 for (formati
= 0; formati
< format_count
; formati
++)
5067 dwarf_vma content_type
, form
;
5071 READ_ULEB (content_type
, format
, end
);
5072 READ_ULEB (form
, format
, end
);
5075 warn (_("Corrupt file name list\n"));
5078 switch (content_type
)
5083 case DW_FORM_string
:
5086 case DW_FORM_line_strp
:
5087 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5089 /* Remove const by the cast. */
5090 file
->name
= (unsigned char *)
5091 fetch_indirect_line_string (uvalue
);
5095 case DW_LNCT_directory_index
:
5099 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5103 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5108 READ_ULEB (file
->directory_index
, tmp
, end
);
5113 data
= read_and_display_attr_value (0, form
, 0, start
,
5115 linfo
.li_offset_size
,
5122 warn (_("Corrupt file name list\n"));
5131 unsigned char *ptr_directory_table
= data
;
5133 while (data
< end
&& *data
!= 0)
5135 data
+= strnlen ((char *) data
, end
- data
);
5144 warn (_("directory table ends unexpectedly\n"));
5149 /* Go through the directory table again to save the directories. */
5150 directory_table
= (unsigned char **)
5151 xmalloc (n_directories
* sizeof (unsigned char *));
5154 while (*ptr_directory_table
!= 0)
5156 directory_table
[i
] = ptr_directory_table
;
5158 += strlen ((char *) ptr_directory_table
) + 1;
5162 /* Skip the NUL at the end of the table. */
5165 /* Traverse the File Name table just to count the entries. */
5166 if (data
< end
&& *data
!= 0)
5168 unsigned char *ptr_file_name_table
= data
;
5170 while (data
< end
&& *data
!= 0)
5172 /* Skip Name, directory index, last modification
5173 time and length of file. */
5174 data
+= strnlen ((char *) data
, end
- data
);
5177 SKIP_ULEB (data
, end
);
5178 SKIP_ULEB (data
, end
);
5179 SKIP_ULEB (data
, end
);
5185 warn (_("file table ends unexpectedly\n"));
5190 /* Go through the file table again to save the strings. */
5191 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5194 while (*ptr_file_name_table
!= 0)
5196 file_table
[i
].name
= ptr_file_name_table
;
5198 += strlen ((char *) ptr_file_name_table
) + 1;
5200 /* We are not interested in directory, time or size. */
5201 READ_ULEB (file_table
[i
].directory_index
,
5202 ptr_file_name_table
, end
);
5203 READ_ULEB (file_table
[i
].modification_date
,
5204 ptr_file_name_table
, end
);
5205 READ_ULEB (file_table
[i
].length
,
5206 ptr_file_name_table
, end
);
5212 /* Skip the NUL at the end of the table. */
5216 /* Print the Compilation Unit's name and a header. */
5217 if (file_table
== NULL
)
5218 printf (_("CU: No directory table\n"));
5219 else if (directory_table
== NULL
)
5220 printf (_("CU: %s:\n"), file_table
[0].name
);
5223 unsigned int ix
= file_table
[0].directory_index
;
5224 const char *directory
;
5229 else if (n_directories
== 0)
5230 directory
= _("<unknown>");
5231 else if (ix
> n_directories
)
5233 warn (_("directory index %u > number of directories %s\n"),
5234 ix
, dwarf_vmatoa ("u", n_directories
));
5235 directory
= _("<corrupt>");
5238 directory
= (char *) directory_table
[ix
- 1];
5241 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5243 printf ("%s:\n", file_table
[0].name
);
5247 printf (_("File name Line number Starting address View Stmt\n"));
5249 printf (_("CU: Empty file name table\n"));
5250 saved_linfo
= linfo
;
5253 /* This loop iterates through the Dwarf Line Number Program. */
5254 while (data
< end_of_sequence
)
5256 unsigned char op_code
;
5259 unsigned long int uladv
;
5260 int is_special_opcode
= 0;
5265 if (op_code
>= linfo
.li_opcode_base
)
5267 op_code
-= linfo
.li_opcode_base
;
5268 uladv
= (op_code
/ linfo
.li_line_range
);
5269 if (linfo
.li_max_ops_per_insn
== 1)
5271 uladv
*= linfo
.li_min_insn_length
;
5272 state_machine_regs
.address
+= uladv
;
5274 state_machine_regs
.view
= 0;
5279 = ((state_machine_regs
.op_index
+ uladv
)
5280 / linfo
.li_max_ops_per_insn
)
5281 * linfo
.li_min_insn_length
;
5282 state_machine_regs
.address
5284 state_machine_regs
.op_index
5285 = (state_machine_regs
.op_index
+ uladv
)
5286 % linfo
.li_max_ops_per_insn
;
5288 state_machine_regs
.view
= 0;
5291 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5292 state_machine_regs
.line
+= adv
;
5293 is_special_opcode
= 1;
5294 /* Increment view after printing this row. */
5299 case DW_LNS_extended_op
:
5301 unsigned int ext_op_code_len
;
5302 unsigned char ext_op_code
;
5303 unsigned char *op_code_end
;
5304 unsigned char *op_code_data
= data
;
5306 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5307 op_code_end
= op_code_data
+ ext_op_code_len
;
5308 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5310 warn (_("Badly formed extended line op encountered!\n"));
5313 ext_op_code
= *op_code_data
++;
5317 switch (ext_op_code
)
5319 case DW_LNE_end_sequence
:
5320 /* Reset stuff after printing this row. */
5322 case DW_LNE_set_address
:
5323 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5325 op_code_end
- op_code_data
,
5327 state_machine_regs
.op_index
= 0;
5328 state_machine_regs
.view
= 0;
5330 case DW_LNE_define_file
:
5331 file_table
= (File_Entry
*) xrealloc
5332 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5334 ++state_machine_regs
.last_file_entry
;
5335 /* Source file name. */
5336 file_table
[n_files
].name
= op_code_data
;
5337 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5338 /* Directory index. */
5339 READ_ULEB (file_table
[n_files
].directory_index
,
5340 op_code_data
, op_code_end
);
5341 /* Last modification time. */
5342 READ_ULEB (file_table
[n_files
].modification_date
,
5343 op_code_data
, op_code_end
);
5345 READ_ULEB (file_table
[n_files
].length
,
5346 op_code_data
, op_code_end
);
5350 case DW_LNE_set_discriminator
:
5351 case DW_LNE_HP_set_sequence
:
5352 /* Simply ignored. */
5356 printf (_("UNKNOWN (%u): length %ld\n"),
5357 ext_op_code
, (long int) (op_code_data
- data
));
5364 /* Increment view after printing this row. */
5367 case DW_LNS_advance_pc
:
5368 READ_ULEB (uladv
, data
, end
);
5369 if (linfo
.li_max_ops_per_insn
== 1)
5371 uladv
*= linfo
.li_min_insn_length
;
5372 state_machine_regs
.address
+= uladv
;
5374 state_machine_regs
.view
= 0;
5379 = ((state_machine_regs
.op_index
+ uladv
)
5380 / linfo
.li_max_ops_per_insn
)
5381 * linfo
.li_min_insn_length
;
5382 state_machine_regs
.address
5384 state_machine_regs
.op_index
5385 = (state_machine_regs
.op_index
+ uladv
)
5386 % linfo
.li_max_ops_per_insn
;
5388 state_machine_regs
.view
= 0;
5392 case DW_LNS_advance_line
:
5393 READ_SLEB (adv
, data
, end
);
5394 state_machine_regs
.line
+= adv
;
5397 case DW_LNS_set_file
:
5398 READ_ULEB (uladv
, data
, end
);
5399 state_machine_regs
.file
= uladv
;
5402 unsigned file
= state_machine_regs
.file
;
5405 if (linfo
.li_version
< 5)
5407 if (file_table
== NULL
|| n_files
== 0)
5408 printf (_("\n [Use file table entry %d]\n"), file
);
5410 else if (file
>= n_files
)
5412 warn (_("file index %u > number of files %u\n"), file
, n_files
);
5413 printf (_("\n <over large file table index %u>"), file
);
5415 else if ((dir
= file_table
[file
].directory_index
) == 0)
5416 /* If directory index is 0, that means current directory. */
5417 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5418 else if (directory_table
== NULL
|| n_directories
== 0)
5419 printf (_("\n [Use file %s in directory table entry %d]\n"),
5420 file_table
[file
].name
, dir
);
5422 else if (dir
> n_directories
)
5424 warn (_("directory index %u > number of directories %s\n"),
5425 dir
, dwarf_vmatoa ("u", n_directories
));
5426 printf (_("\n <over large directory table entry %u>\n"), dir
);
5429 printf ("\n%s/%s:\n",
5430 /* The directory index starts counting at 1. */
5431 directory_table
[dir
- 1], file_table
[file
].name
);
5435 case DW_LNS_set_column
:
5436 READ_ULEB (uladv
, data
, end
);
5437 state_machine_regs
.column
= uladv
;
5440 case DW_LNS_negate_stmt
:
5441 adv
= state_machine_regs
.is_stmt
;
5443 state_machine_regs
.is_stmt
= adv
;
5446 case DW_LNS_set_basic_block
:
5447 state_machine_regs
.basic_block
= 1;
5450 case DW_LNS_const_add_pc
:
5451 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5452 if (linfo
.li_max_ops_per_insn
== 1)
5454 uladv
*= linfo
.li_min_insn_length
;
5455 state_machine_regs
.address
+= uladv
;
5457 state_machine_regs
.view
= 0;
5462 = ((state_machine_regs
.op_index
+ uladv
)
5463 / linfo
.li_max_ops_per_insn
)
5464 * linfo
.li_min_insn_length
;
5465 state_machine_regs
.address
5467 state_machine_regs
.op_index
5468 = (state_machine_regs
.op_index
+ uladv
)
5469 % linfo
.li_max_ops_per_insn
;
5471 state_machine_regs
.view
= 0;
5475 case DW_LNS_fixed_advance_pc
:
5476 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5477 state_machine_regs
.address
+= uladv
;
5478 state_machine_regs
.op_index
= 0;
5479 /* Do NOT reset view. */
5482 case DW_LNS_set_prologue_end
:
5485 case DW_LNS_set_epilogue_begin
:
5488 case DW_LNS_set_isa
:
5489 READ_ULEB (uladv
, data
, end
);
5490 printf (_(" Set ISA to %lu\n"), uladv
);
5494 printf (_(" Unknown opcode %d with operands: "), op_code
);
5496 if (standard_opcodes
!= NULL
)
5497 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5501 READ_ULEB (val
, data
, end
);
5502 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5503 i
== 1 ? "" : ", ");
5509 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5510 to the DWARF address/line matrix. */
5511 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5512 || (xop
== DW_LNS_copy
))
5514 const unsigned int MAX_FILENAME_LENGTH
= 35;
5516 char *newFileName
= NULL
;
5517 size_t fileNameLength
;
5521 unsigned indx
= state_machine_regs
.file
;
5523 if (linfo
.li_version
< 5)
5526 if (indx
>= n_files
)
5528 warn (_("corrupt file index %u encountered\n"), indx
);
5529 fileName
= _("<corrupt>");
5532 fileName
= (char *) file_table
[indx
].name
;
5535 fileName
= _("<unknown>");
5537 fileNameLength
= strlen (fileName
);
5538 newFileName
= fileName
;
5539 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5541 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5542 /* Truncate file name */
5543 memcpy (newFileName
,
5544 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5545 MAX_FILENAME_LENGTH
);
5546 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5549 /* A row with end_seq set to true has a meaningful address, but
5550 the other information in the same row is not significant.
5551 In such a row, print line as "-", and don't print
5553 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5555 if (linfo
.li_max_ops_per_insn
== 1)
5557 if (xop
== -DW_LNE_end_sequence
)
5558 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5560 state_machine_regs
.address
);
5562 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5563 newFileName
, state_machine_regs
.line
,
5564 state_machine_regs
.address
);
5568 if (xop
== -DW_LNE_end_sequence
)
5569 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5571 state_machine_regs
.address
,
5572 state_machine_regs
.op_index
);
5574 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5575 newFileName
, state_machine_regs
.line
,
5576 state_machine_regs
.address
,
5577 state_machine_regs
.op_index
);
5582 if (linfo
.li_max_ops_per_insn
== 1)
5584 if (xop
== -DW_LNE_end_sequence
)
5585 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5587 state_machine_regs
.address
);
5589 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5590 newFileName
, state_machine_regs
.line
,
5591 state_machine_regs
.address
);
5595 if (xop
== -DW_LNE_end_sequence
)
5596 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5598 state_machine_regs
.address
,
5599 state_machine_regs
.op_index
);
5601 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5602 newFileName
, state_machine_regs
.line
,
5603 state_machine_regs
.address
,
5604 state_machine_regs
.op_index
);
5608 if (xop
!= -DW_LNE_end_sequence
)
5610 if (state_machine_regs
.view
)
5611 printf (" %6u", state_machine_regs
.view
);
5615 if (state_machine_regs
.is_stmt
)
5620 state_machine_regs
.view
++;
5622 if (xop
== -DW_LNE_end_sequence
)
5624 reset_state_machine (linfo
.li_default_is_stmt
);
5628 if (newFileName
!= fileName
)
5640 if (directory_table
)
5642 free (directory_table
);
5643 directory_table
= NULL
;
5654 display_debug_lines (struct dwarf_section
*section
, void *file
)
5656 unsigned char *data
= section
->start
;
5657 unsigned char *end
= data
+ section
->size
;
5659 int retValDecoded
= 1;
5661 if (do_debug_lines
== 0)
5662 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5664 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5665 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5667 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5668 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5670 if (!retValRaw
|| !retValDecoded
)
5677 find_debug_info_for_offset (dwarf_vma offset
)
5681 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5684 for (i
= 0; i
< num_debug_info_entries
; i
++)
5685 if (debug_information
[i
].cu_offset
== offset
)
5686 return debug_information
+ i
;
5692 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5694 /* See gdb/gdb-index.h. */
5695 static const char * const kinds
[] =
5707 return _ (kinds
[kind
]);
5711 display_debug_pubnames_worker (struct dwarf_section
*section
,
5712 void *file ATTRIBUTE_UNUSED
,
5715 DWARF2_Internal_PubNames names
;
5716 unsigned char *start
= section
->start
;
5717 unsigned char *end
= start
+ section
->size
;
5719 /* It does not matter if this load fails,
5720 we test for that later on. */
5721 load_debug_info (file
);
5723 introduce (section
, false);
5727 unsigned char *data
;
5728 unsigned long sec_off
= start
- section
->start
;
5729 unsigned int offset_size
;
5731 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5732 if (names
.pn_length
== 0xffffffff)
5734 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5740 if (names
.pn_length
> (size_t) (end
- start
))
5742 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5745 dwarf_vmatoa ("x", names
.pn_length
));
5750 start
+= names
.pn_length
;
5752 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5753 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5755 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5756 && num_debug_info_entries
> 0
5757 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5758 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5759 (unsigned long) names
.pn_offset
, section
->name
);
5761 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5763 printf (_(" Length: %ld\n"),
5764 (long) names
.pn_length
);
5765 printf (_(" Version: %d\n"),
5767 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5768 (unsigned long) names
.pn_offset
);
5769 printf (_(" Size of area in .debug_info section: %ld\n"),
5770 (long) names
.pn_size
);
5772 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5774 static int warned
= 0;
5778 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5786 printf (_("\n Offset Kind Name\n"));
5788 printf (_("\n Offset\tName\n"));
5792 bfd_size_type maxprint
;
5795 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5802 maxprint
= (start
- data
) - 1;
5806 unsigned int kind_data
;
5807 gdb_index_symbol_kind kind
;
5808 const char *kind_name
;
5811 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5813 /* GCC computes the kind as the upper byte in the CU index
5814 word, and then right shifts it by the CU index size.
5815 Left shift KIND to where the gdb-index.h accessor macros
5817 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5818 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5819 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5820 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5821 printf (" %-6lx %s,%-10s %.*s\n",
5822 (unsigned long) offset
, is_static
? _("s") : _("g"),
5823 kind_name
, (int) maxprint
, data
);
5826 printf (" %-6lx\t%.*s\n",
5827 (unsigned long) offset
, (int) maxprint
, data
);
5829 data
+= strnlen ((char *) data
, maxprint
);
5842 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5844 return display_debug_pubnames_worker (section
, file
, 0);
5848 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5850 return display_debug_pubnames_worker (section
, file
, 1);
5854 display_debug_macinfo (struct dwarf_section
*section
,
5855 void *file ATTRIBUTE_UNUSED
)
5857 unsigned char *start
= section
->start
;
5858 unsigned char *end
= start
+ section
->size
;
5859 unsigned char *curr
= start
;
5860 enum dwarf_macinfo_record_type op
;
5862 introduce (section
, false);
5866 unsigned int lineno
;
5867 const unsigned char *string
;
5869 op
= (enum dwarf_macinfo_record_type
) *curr
;
5874 case DW_MACINFO_start_file
:
5876 unsigned int filenum
;
5878 READ_ULEB (lineno
, curr
, end
);
5879 READ_ULEB (filenum
, curr
, end
);
5880 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5885 case DW_MACINFO_end_file
:
5886 printf (_(" DW_MACINFO_end_file\n"));
5889 case DW_MACINFO_define
:
5890 READ_ULEB (lineno
, curr
, end
);
5892 curr
+= strnlen ((char *) string
, end
- string
);
5893 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5894 lineno
, (int) (curr
- string
), string
);
5899 case DW_MACINFO_undef
:
5900 READ_ULEB (lineno
, curr
, end
);
5902 curr
+= strnlen ((char *) string
, end
- string
);
5903 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5904 lineno
, (int) (curr
- string
), string
);
5909 case DW_MACINFO_vendor_ext
:
5911 unsigned int constant
;
5913 READ_ULEB (constant
, curr
, end
);
5915 curr
+= strnlen ((char *) string
, end
- string
);
5916 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5917 constant
, (int) (curr
- string
), string
);
5928 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5929 filename and dirname corresponding to file name table entry with index
5930 FILEIDX. Return NULL on failure. */
5932 static unsigned char *
5933 get_line_filename_and_dirname (dwarf_vma line_offset
,
5935 unsigned char **dir_name
)
5937 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5938 unsigned char *hdrptr
, *dirtable
, *file_name
;
5939 unsigned int offset_size
;
5940 unsigned int version
, opcode_base
;
5941 dwarf_vma length
, diridx
;
5942 const unsigned char * end
;
5945 if (section
->start
== NULL
5946 || line_offset
>= section
->size
5950 hdrptr
= section
->start
+ line_offset
;
5951 end
= section
->start
+ section
->size
;
5953 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5954 if (length
== 0xffffffff)
5956 /* This section is 64-bit DWARF 3. */
5957 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5963 if (length
> (size_t) (end
- hdrptr
)
5964 || length
< 2 + offset_size
+ 1 + 3 + 1)
5966 end
= hdrptr
+ length
;
5968 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5969 if (version
!= 2 && version
!= 3 && version
!= 4)
5971 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5973 hdrptr
++; /* Skip max_ops_per_insn. */
5974 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5976 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5977 if (opcode_base
== 0
5978 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
5981 hdrptr
+= opcode_base
- 1;
5984 /* Skip over dirname table. */
5985 while (*hdrptr
!= '\0')
5987 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5993 hdrptr
++; /* Skip the NUL at the end of the table. */
5995 /* Now skip over preceding filename table entries. */
5996 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5998 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6001 SKIP_ULEB (hdrptr
, end
);
6002 SKIP_ULEB (hdrptr
, end
);
6003 SKIP_ULEB (hdrptr
, end
);
6005 if (hdrptr
>= end
|| *hdrptr
== '\0')
6009 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6014 READ_ULEB (diridx
, hdrptr
, end
);
6017 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6019 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6023 if (dirtable
>= end
|| *dirtable
== '\0')
6025 *dir_name
= dirtable
;
6030 display_debug_macro (struct dwarf_section
*section
,
6033 unsigned char *start
= section
->start
;
6034 unsigned char *end
= start
+ section
->size
;
6035 unsigned char *curr
= start
;
6036 unsigned char *extended_op_buf
[256];
6037 bool is_dwo
= false;
6038 const char *suffix
= strrchr (section
->name
, '.');
6040 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6043 load_debug_section_with_follow (str
, file
);
6044 load_debug_section_with_follow (line
, file
);
6045 load_debug_section_with_follow (str_index
, file
);
6047 introduce (section
, false);
6051 unsigned int lineno
, version
, flags
;
6052 unsigned int offset_size
;
6053 const unsigned char *string
;
6054 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
6055 unsigned char **extended_ops
= NULL
;
6057 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6058 if (version
!= 4 && version
!= 5)
6060 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6061 section
->name
, version
);
6065 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6066 offset_size
= (flags
& 1) ? 8 : 4;
6067 printf (_(" Offset: 0x%lx\n"),
6068 (unsigned long) sec_offset
);
6069 printf (_(" Version: %d\n"), version
);
6070 printf (_(" Offset size: %d\n"), offset_size
);
6073 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6074 printf (_(" Offset into .debug_line: 0x%lx\n"),
6075 (unsigned long) line_offset
);
6079 unsigned int i
, count
, op
;
6082 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6084 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6085 extended_ops
= extended_op_buf
;
6088 printf (_(" Extension opcode arguments:\n"));
6089 for (i
= 0; i
< count
; i
++)
6091 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6092 extended_ops
[op
] = curr
;
6093 READ_ULEB (nargs
, curr
, end
);
6095 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6098 printf (_(" DW_MACRO_%02x arguments: "), op
);
6099 for (n
= 0; n
< nargs
; n
++)
6103 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6104 printf ("%s%s", get_FORM_name (form
),
6105 n
== nargs
- 1 ? "\n" : ", ");
6115 case DW_FORM_block1
:
6116 case DW_FORM_block2
:
6117 case DW_FORM_block4
:
6119 case DW_FORM_string
:
6121 case DW_FORM_sec_offset
:
6124 error (_("Invalid extension opcode form %s\n"),
6125 get_FORM_name (form
));
6141 error (_(".debug_macro section not zero terminated\n"));
6145 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6151 case DW_MACRO_define
:
6152 READ_ULEB (lineno
, curr
, end
);
6154 curr
+= strnlen ((char *) string
, end
- string
);
6155 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6156 lineno
, (int) (curr
- string
), string
);
6161 case DW_MACRO_undef
:
6162 READ_ULEB (lineno
, curr
, end
);
6164 curr
+= strnlen ((char *) string
, end
- string
);
6165 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6166 lineno
, (int) (curr
- string
), string
);
6171 case DW_MACRO_start_file
:
6173 unsigned int filenum
;
6174 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6176 READ_ULEB (lineno
, curr
, end
);
6177 READ_ULEB (filenum
, curr
, end
);
6179 if ((flags
& 2) == 0)
6180 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6183 = get_line_filename_and_dirname (line_offset
, filenum
,
6185 if (file_name
== NULL
)
6186 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6189 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6191 dir_name
!= NULL
? (const char *) dir_name
: "",
6192 dir_name
!= NULL
? "/" : "", file_name
);
6196 case DW_MACRO_end_file
:
6197 printf (_(" DW_MACRO_end_file\n"));
6200 case DW_MACRO_define_strp
:
6201 READ_ULEB (lineno
, curr
, end
);
6202 if (version
== 4 && is_dwo
)
6203 READ_ULEB (offset
, curr
, end
);
6205 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6206 string
= fetch_indirect_string (offset
);
6207 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6211 case DW_MACRO_undef_strp
:
6212 READ_ULEB (lineno
, curr
, end
);
6213 if (version
== 4 && is_dwo
)
6214 READ_ULEB (offset
, curr
, end
);
6216 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6217 string
= fetch_indirect_string (offset
);
6218 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6222 case DW_MACRO_import
:
6223 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6224 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6225 (unsigned long) offset
);
6228 case DW_MACRO_define_sup
:
6229 READ_ULEB (lineno
, curr
, end
);
6230 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6231 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6232 lineno
, (unsigned long) offset
);
6235 case DW_MACRO_undef_sup
:
6236 READ_ULEB (lineno
, curr
, end
);
6237 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6238 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6239 lineno
, (unsigned long) offset
);
6242 case DW_MACRO_import_sup
:
6243 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6244 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6245 (unsigned long) offset
);
6248 case DW_MACRO_define_strx
:
6249 case DW_MACRO_undef_strx
:
6250 READ_ULEB (lineno
, curr
, end
);
6251 READ_ULEB (offset
, curr
, end
);
6252 string
= (const unsigned char *)
6253 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6254 if (op
== DW_MACRO_define_strx
)
6255 printf (" DW_MACRO_define_strx ");
6257 printf (" DW_MACRO_undef_strx ");
6259 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6260 printf (_("lineno : %d macro : %s\n"),
6265 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6267 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6271 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6273 error (_(" Unknown macro opcode %02x seen\n"), op
);
6278 /* Skip over unhandled opcodes. */
6280 unsigned char *desc
= extended_ops
[op
];
6281 READ_ULEB (nargs
, desc
, end
);
6284 printf (_(" DW_MACRO_%02x\n"), op
);
6287 printf (_(" DW_MACRO_%02x -"), op
);
6288 for (n
= 0; n
< nargs
; n
++)
6292 /* DW_FORM_implicit_const is not expected here. */
6293 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6295 = read_and_display_attr_value (0, val
, 0,
6296 start
, curr
, end
, 0, 0,
6297 offset_size
, version
,
6316 display_debug_abbrev (struct dwarf_section
*section
,
6317 void *file ATTRIBUTE_UNUSED
)
6319 abbrev_entry
*entry
;
6320 unsigned char *start
= section
->start
;
6322 introduce (section
, false);
6329 offset
= start
- section
->start
;
6330 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6333 list
= new_abbrev_list (0, offset
);
6334 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6335 list
->start_of_next_abbrevs
= start
;
6338 start
= list
->start_of_next_abbrevs
;
6340 if (list
->first_abbrev
== NULL
)
6343 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6345 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6349 printf (" %ld %s [%s]\n",
6351 get_TAG_name (entry
->tag
),
6352 entry
->children
? _("has children") : _("no children"));
6354 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6356 printf (" %-18s %s",
6357 get_AT_name (attr
->attribute
),
6358 get_FORM_name (attr
->form
));
6359 if (attr
->form
== DW_FORM_implicit_const
)
6360 printf (": %s", dwarf_vmatoa ("d", attr
->implicit_const
));
6372 /* Return true when ADDR is the maximum address, when addresses are
6373 POINTER_SIZE bytes long. */
6376 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6378 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6379 return ((addr
& mask
) == mask
);
6382 /* Display a view pair list starting at *VSTART_PTR and ending at
6383 VLISTEND within SECTION. */
6386 display_view_pair_list (struct dwarf_section
*section
,
6387 unsigned char **vstart_ptr
,
6388 unsigned int debug_info_entry
,
6389 unsigned char *vlistend
)
6391 unsigned char *vstart
= *vstart_ptr
;
6392 unsigned char *section_end
= section
->start
+ section
->size
;
6393 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6395 if (vlistend
< section_end
)
6396 section_end
= vlistend
;
6400 while (vstart
< section_end
)
6402 dwarf_vma off
= vstart
- section
->start
;
6403 dwarf_vma vbegin
, vend
;
6405 READ_ULEB (vbegin
, vstart
, section_end
);
6406 if (vstart
== section_end
)
6409 READ_ULEB (vend
, vstart
, section_end
);
6410 printf (" %8.8lx ", (unsigned long) off
);
6412 print_dwarf_view (vbegin
, pointer_size
, 1);
6413 print_dwarf_view (vend
, pointer_size
, 1);
6414 printf (_("location view pair\n"));
6418 *vstart_ptr
= vstart
;
6421 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6424 display_loc_list (struct dwarf_section
*section
,
6425 unsigned char **start_ptr
,
6426 unsigned int debug_info_entry
,
6428 dwarf_vma base_address
,
6429 unsigned char **vstart_ptr
,
6432 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6433 unsigned char *section_end
= section
->start
+ section
->size
;
6434 dwarf_vma cu_offset
;
6435 unsigned int pointer_size
;
6436 unsigned int offset_size
;
6440 unsigned short length
;
6441 int need_frame_base
;
6443 if (debug_info_entry
>= num_debug_info_entries
)
6445 warn (_("No debug information available for loc lists of entry: %u\n"),
6450 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6451 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6452 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6453 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6455 if (pointer_size
< 2 || pointer_size
> 8)
6457 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6458 pointer_size
, debug_info_entry
);
6464 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6465 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6467 if (2 * pointer_size
> (size_t) (section_end
- start
))
6469 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6470 (unsigned long) offset
);
6475 print_dwarf_vma (off
, 4);
6477 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6478 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6480 if (begin
== 0 && end
== 0)
6482 /* PR 18374: In a object file we can have a location list that
6483 starts with a begin and end of 0 because there are relocations
6484 that need to be applied to the addresses. Actually applying
6485 the relocations now does not help as they will probably resolve
6486 to 0, since the object file has not been fully linked. Real
6487 end of list markers will not have any relocations against them. */
6488 if (! reloc_at (section
, off
)
6489 && ! reloc_at (section
, off
+ pointer_size
))
6491 printf (_("<End of list>\n"));
6496 /* Check base address specifiers. */
6497 if (is_max_address (begin
, pointer_size
)
6498 && !is_max_address (end
, pointer_size
))
6501 print_dwarf_vma (begin
, pointer_size
);
6502 print_dwarf_vma (end
, pointer_size
);
6503 printf (_("(base address)\n"));
6509 off
= offset
+ (vstart
- *start_ptr
);
6511 READ_ULEB (vbegin
, vstart
, section_end
);
6512 print_dwarf_view (vbegin
, pointer_size
, 1);
6514 READ_ULEB (vend
, vstart
, section_end
);
6515 print_dwarf_view (vend
, pointer_size
, 1);
6517 printf (_("views at %8.8lx for:\n %*s "),
6518 (unsigned long) off
, 8, "");
6521 if (2 > (size_t) (section_end
- start
))
6523 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6524 (unsigned long) offset
);
6528 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6530 if (length
> (size_t) (section_end
- start
))
6532 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6533 (unsigned long) offset
);
6537 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6538 print_dwarf_vma (end
+ base_address
, pointer_size
);
6541 need_frame_base
= decode_location_expression (start
,
6546 cu_offset
, section
);
6549 if (need_frame_base
&& !has_frame_base
)
6550 printf (_(" [without DW_AT_frame_base]"));
6552 if (begin
== end
&& vbegin
== vend
)
6553 fputs (_(" (start == end)"), stdout
);
6554 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6555 fputs (_(" (start > end)"), stdout
);
6563 *vstart_ptr
= vstart
;
6566 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6569 display_loclists_list (struct dwarf_section
* section
,
6570 unsigned char ** start_ptr
,
6571 unsigned int debug_info_entry
,
6573 dwarf_vma base_address
,
6574 unsigned char ** vstart_ptr
,
6577 unsigned char * start
= *start_ptr
;
6578 unsigned char * vstart
= *vstart_ptr
;
6579 unsigned char * section_end
= section
->start
+ section
->size
;
6580 dwarf_vma cu_offset
;
6581 unsigned int pointer_size
;
6582 unsigned int offset_size
;
6583 unsigned int dwarf_version
;
6585 /* Initialize it due to a false compiler warning. */
6586 dwarf_vma begin
= -1, vbegin
= -1;
6587 dwarf_vma end
= -1, vend
= -1;
6589 int need_frame_base
;
6591 if (debug_info_entry
>= num_debug_info_entries
)
6593 warn (_("No debug information available for "
6594 "loclists lists of entry: %u\n"),
6599 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6600 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6601 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6602 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6604 if (pointer_size
< 2 || pointer_size
> 8)
6606 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6607 pointer_size
, debug_info_entry
);
6613 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6614 enum dwarf_location_list_entry_type llet
;
6616 if (start
+ 1 > section_end
)
6618 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6619 (unsigned long) offset
);
6624 print_dwarf_vma (off
, 4);
6626 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6628 if (vstart
&& (llet
== DW_LLE_offset_pair
6629 || llet
== DW_LLE_start_end
6630 || llet
== DW_LLE_start_length
))
6632 off
= offset
+ (vstart
- *start_ptr
);
6634 READ_ULEB (vbegin
, vstart
, section_end
);
6635 print_dwarf_view (vbegin
, pointer_size
, 1);
6637 READ_ULEB (vend
, vstart
, section_end
);
6638 print_dwarf_view (vend
, pointer_size
, 1);
6640 printf (_("views at %8.8lx for:\n %*s "),
6641 (unsigned long) off
, 8, "");
6646 case DW_LLE_end_of_list
:
6647 printf (_("<End of list>\n"));
6650 case DW_LLE_base_addressx
:
6651 READ_ULEB (base_address
, start
, section_end
);
6652 print_dwarf_vma (base_address
, pointer_size
);
6653 printf (_("(index into .debug_addr) "));
6654 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6655 print_dwarf_vma (base_address
, pointer_size
);
6656 printf (_("(base address)\n"));
6659 case DW_LLE_startx_endx
:
6660 READ_ULEB (begin
, start
, section_end
);
6661 begin
= fetch_indexed_addr (begin
, pointer_size
);
6662 READ_ULEB (end
, start
, section_end
);
6663 end
= fetch_indexed_addr (end
, pointer_size
);
6666 case DW_LLE_startx_length
:
6667 READ_ULEB (begin
, start
, section_end
);
6668 begin
= fetch_indexed_addr (begin
, pointer_size
);
6669 READ_ULEB (end
, start
, section_end
);
6673 case DW_LLE_default_location
:
6677 case DW_LLE_offset_pair
:
6678 READ_ULEB (begin
, start
, section_end
);
6679 begin
+= base_address
;
6680 READ_ULEB (end
, start
, section_end
);
6681 end
+= base_address
;
6684 case DW_LLE_base_address
:
6685 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6687 print_dwarf_vma (base_address
, pointer_size
);
6688 printf (_("(base address)\n"));
6691 case DW_LLE_start_end
:
6692 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6693 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6696 case DW_LLE_start_length
:
6697 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6698 READ_ULEB (end
, start
, section_end
);
6702 #ifdef DW_LLE_view_pair
6703 case DW_LLE_view_pair
:
6705 printf (_("View pair entry in loclist with locviews attribute\n"));
6706 READ_ULEB (vbegin
, start
, section_end
);
6707 print_dwarf_view (vbegin
, pointer_size
, 1);
6709 READ_ULEB (vend
, start
, section_end
);
6710 print_dwarf_view (vend
, pointer_size
, 1);
6712 printf (_("views for:\n"));
6717 error (_("Invalid location list entry type %d\n"), llet
);
6721 if (llet
== DW_LLE_end_of_list
)
6724 if (llet
== DW_LLE_base_address
6725 || llet
== DW_LLE_base_addressx
)
6728 if (start
== section_end
)
6730 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6731 (unsigned long) offset
);
6734 READ_ULEB (length
, start
, section_end
);
6736 if (length
> (size_t) (section_end
- start
))
6738 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6739 (unsigned long) offset
);
6743 print_dwarf_vma (begin
, pointer_size
);
6744 print_dwarf_vma (end
, pointer_size
);
6747 need_frame_base
= decode_location_expression (start
,
6752 cu_offset
, section
);
6755 if (need_frame_base
&& !has_frame_base
)
6756 printf (_(" [without DW_AT_frame_base]"));
6758 if (begin
== end
&& vbegin
== vend
)
6759 fputs (_(" (start == end)"), stdout
);
6760 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6761 fputs (_(" (start > end)"), stdout
);
6769 if (vbegin
!= vm1
|| vend
!= vm1
)
6770 printf (_("Trailing view pair not used in a range"));
6773 *vstart_ptr
= vstart
;
6776 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6777 right-adjusted in a field of length LEN, and followed by a space. */
6780 print_addr_index (unsigned int idx
, unsigned int len
)
6782 static char buf
[15];
6783 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6784 printf ("%*s ", len
, buf
);
6787 /* Display a location list from a .dwo section. It uses address indexes rather
6788 than embedded addresses. This code closely follows display_loc_list, but the
6789 two are sufficiently different that combining things is very ugly. */
6792 display_loc_list_dwo (struct dwarf_section
*section
,
6793 unsigned char **start_ptr
,
6794 unsigned int debug_info_entry
,
6796 unsigned char **vstart_ptr
,
6799 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6800 unsigned char *section_end
= section
->start
+ section
->size
;
6801 dwarf_vma cu_offset
;
6802 unsigned int pointer_size
;
6803 unsigned int offset_size
;
6806 unsigned short length
;
6807 int need_frame_base
;
6810 if (debug_info_entry
>= num_debug_info_entries
)
6812 warn (_("No debug information for loc lists of entry: %u\n"),
6817 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6818 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6819 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6820 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6822 if (pointer_size
< 2 || pointer_size
> 8)
6824 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6825 pointer_size
, debug_info_entry
);
6832 print_dwarf_vma (offset
+ (start
- *start_ptr
), 4);
6834 if (start
>= section_end
)
6836 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6837 (unsigned long) offset
);
6841 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6854 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6856 READ_ULEB (view
, vstart
, section_end
);
6857 print_dwarf_view (view
, 8, 1);
6859 READ_ULEB (view
, vstart
, section_end
);
6860 print_dwarf_view (view
, 8, 1);
6862 printf (_("views at %8.8lx for:\n %*s "),
6863 (unsigned long) off
, 8, "");
6871 case 0: /* A terminating entry. */
6873 *vstart_ptr
= vstart
;
6874 printf (_("<End of list>\n"));
6876 case 1: /* A base-address entry. */
6877 READ_ULEB (idx
, start
, section_end
);
6878 print_addr_index (idx
, 8);
6879 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6880 printf (_("(base address selection entry)\n"));
6882 case 2: /* A start/end entry. */
6883 READ_ULEB (idx
, start
, section_end
);
6884 print_addr_index (idx
, 8);
6885 READ_ULEB (idx
, start
, section_end
);
6886 print_addr_index (idx
, 8);
6888 case 3: /* A start/length entry. */
6889 READ_ULEB (idx
, start
, section_end
);
6890 print_addr_index (idx
, 8);
6891 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6892 printf ("%08x ", idx
);
6894 case 4: /* An offset pair entry. */
6895 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6896 printf ("%08x ", idx
);
6897 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6898 printf ("%08x ", idx
);
6901 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6903 *vstart_ptr
= vstart
;
6907 if (2 > (size_t) (section_end
- start
))
6909 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6910 (unsigned long) offset
);
6914 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6915 if (length
> (size_t) (section_end
- start
))
6917 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6918 (unsigned long) offset
);
6923 need_frame_base
= decode_location_expression (start
,
6928 cu_offset
, section
);
6931 if (need_frame_base
&& !has_frame_base
)
6932 printf (_(" [without DW_AT_frame_base]"));
6940 *vstart_ptr
= vstart
;
6943 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6946 static dwarf_vma
*loc_offsets
, *loc_views
;
6949 loc_offsets_compar (const void *ap
, const void *bp
)
6951 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6952 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6954 int ret
= (a
> b
) - (b
> a
);
6958 a
= loc_views
[*(const unsigned int *) ap
];
6959 b
= loc_views
[*(const unsigned int *) bp
];
6961 ret
= (a
> b
) - (b
> a
);
6967 display_offset_entry_loclists (struct dwarf_section
*section
)
6969 unsigned char * start
= section
->start
;
6970 unsigned char * const end
= start
+ section
->size
;
6972 introduce (section
, false);
6977 unsigned short version
;
6978 unsigned char address_size
;
6979 unsigned char segment_selector_size
;
6980 uint32_t offset_entry_count
;
6984 printf (_("Table at Offset 0x%lx\n"), (long)(start
- section
->start
));
6986 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
6987 if (length
== 0xffffffff)
6990 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
6995 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
6996 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
6997 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
6998 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
7000 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", length
));
7001 printf (_(" DWARF version: %u\n"), version
);
7002 printf (_(" Address size: %u\n"), address_size
);
7003 printf (_(" Segment size: %u\n"), segment_selector_size
);
7004 printf (_(" Offset entries: %u\n"), offset_entry_count
);
7008 warn (_("The %s section contains a corrupt or "
7009 "unsupported version number: %d.\n"),
7010 section
->name
, version
);
7014 if (segment_selector_size
!= 0)
7016 warn (_("The %s section contains an "
7017 "unsupported segment selector size: %d.\n"),
7018 section
->name
, segment_selector_size
);
7022 if (offset_entry_count
== 0)
7024 warn (_("The %s section contains a table without offset\n"),
7029 printf (_("\n Offset Entries starting at 0x%lx:\n"),
7030 (long)(start
- section
->start
));
7034 for (i
= 0; i
< offset_entry_count
; i
++)
7038 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, end
);
7039 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
7044 for (i
= 0; i
< offset_entry_count
; i
++)
7048 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, end
);
7049 printf (_(" [%6u] 0x%x\n"), i
, entry
);
7057 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7060 dwarf_vma base_address
= 0;
7063 dwarf_vma off
= start
- section
->start
;
7067 printf (_(" Offset Entry %u\n"), i
);
7072 print_dwarf_vma (off
, 4);
7074 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7078 case DW_LLE_end_of_list
:
7079 printf (_("<End of list>\n\n"));
7083 case DW_LLE_base_addressx
:
7084 READ_ULEB (base_address
, start
, end
);
7085 print_dwarf_vma (base_address
, address_size
);
7086 printf (_("(index into .debug_addr) "));
7087 base_address
= fetch_indexed_addr (base_address
, address_size
);
7088 print_dwarf_vma (base_address
, address_size
);
7089 printf (_("(base address)\n"));
7092 case DW_LLE_startx_endx
:
7093 READ_ULEB (begin
, start
, end
);
7094 begin
= fetch_indexed_addr (begin
, address_size
);
7095 READ_ULEB (finish
, start
, end
);
7096 finish
= fetch_indexed_addr (finish
, address_size
);
7099 case DW_LLE_startx_length
:
7100 READ_ULEB (begin
, start
, end
);
7101 begin
= fetch_indexed_addr (begin
, address_size
);
7102 READ_ULEB (finish
, start
, end
);
7106 case DW_LLE_offset_pair
:
7107 READ_ULEB (begin
, start
, end
);
7108 begin
+= base_address
;
7109 READ_ULEB (finish
, start
, end
);
7110 finish
+= base_address
;
7113 case DW_LLE_default_location
:
7117 case DW_LLE_base_address
:
7118 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7119 print_dwarf_vma (base_address
, address_size
);
7120 printf (_("(base address)\n"));
7123 case DW_LLE_start_end
:
7124 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7125 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7128 case DW_LLE_start_length
:
7129 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7130 READ_ULEB (finish
, start
, end
);
7135 error (_("Invalid location list entry type %d\n"), lle
);
7141 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7142 (unsigned long) off
);
7146 print_dwarf_vma (begin
, address_size
);
7147 print_dwarf_vma (finish
, address_size
);
7149 if (begin
== finish
)
7150 fputs (_(" (start == end)"), stdout
);
7151 else if (begin
> finish
)
7152 fputs (_(" (start > end)"), stdout
);
7154 /* Read the counted location descriptions. */
7155 READ_ULEB (length
, start
, end
);
7157 if (length
> (size_t) (end
- start
))
7159 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7160 (unsigned long) off
);
7165 (void) decode_location_expression (start
, address_size
, address_size
,
7166 version
, length
, 0, section
);
7173 while (start
< end
);
7179 display_debug_loc (struct dwarf_section
*section
, void *file
)
7181 unsigned char *start
= section
->start
, *vstart
= NULL
;
7183 unsigned char *section_begin
= start
;
7184 unsigned int num_loc_list
= 0;
7185 dwarf_vma last_offset
= 0;
7186 dwarf_vma last_view
= 0;
7187 unsigned int first
= 0;
7190 int seen_first_offset
= 0;
7191 int locs_sorted
= 1;
7192 unsigned char *next
= start
, *vnext
= vstart
;
7193 unsigned int *array
= NULL
;
7194 const char *suffix
= strrchr (section
->name
, '.');
7195 bool is_dwo
= false;
7196 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7197 dwarf_vma expected_start
= 0;
7199 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7202 bytes
= section
->size
;
7206 printf (_("\nThe %s section is empty.\n"), section
->name
);
7212 unsigned char *hdrptr
= section_begin
;
7213 dwarf_vma ll_length
;
7214 unsigned short ll_version
;
7215 unsigned char *end
= section_begin
+ section
->size
;
7216 unsigned char address_size
, segment_selector_size
;
7217 uint32_t offset_entry_count
;
7219 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7220 if (ll_length
== 0xffffffff)
7221 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7223 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7224 if (ll_version
!= 5)
7226 warn (_("The %s section contains corrupt or "
7227 "unsupported version number: %d.\n"),
7228 section
->name
, ll_version
);
7232 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7234 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7235 if (segment_selector_size
!= 0)
7237 warn (_("The %s section contains "
7238 "unsupported segment selector size: %d.\n"),
7239 section
->name
, segment_selector_size
);
7243 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7245 if (offset_entry_count
!= 0)
7246 return display_offset_entry_loclists (section
);
7248 expected_start
= hdrptr
- section_begin
;
7251 if (load_debug_info (file
) == 0)
7253 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7258 /* Check the order of location list in .debug_info section. If
7259 offsets of location lists are in the ascending order, we can
7260 use `debug_information' directly. */
7261 for (i
= 0; i
< num_debug_info_entries
; i
++)
7265 num
= debug_information
[i
].num_loc_offsets
;
7266 if (num
> num_loc_list
)
7269 /* Check if we can use `debug_information' directly. */
7270 if (locs_sorted
&& num
!= 0)
7272 if (!seen_first_offset
)
7274 /* This is the first location list. */
7275 last_offset
= debug_information
[i
].loc_offsets
[0];
7276 last_view
= debug_information
[i
].loc_views
[0];
7278 seen_first_offset
= 1;
7284 for (; j
< num
; j
++)
7287 debug_information
[i
].loc_offsets
[j
]
7288 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7289 && last_view
> debug_information
[i
].loc_views
[j
]))
7294 last_offset
= debug_information
[i
].loc_offsets
[j
];
7295 last_view
= debug_information
[i
].loc_views
[j
];
7300 if (!seen_first_offset
)
7301 error (_("No location lists in .debug_info section!\n"));
7303 if (debug_information
[first
].num_loc_offsets
> 0
7304 && debug_information
[first
].loc_offsets
[0] != expected_start
7305 && debug_information
[first
].loc_views
[0] != expected_start
)
7306 warn (_("Location lists in %s section start at 0x%s rather than 0x%s\n"),
7308 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]),
7309 dwarf_vmatoa ("x", expected_start
));
7312 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7314 introduce (section
, false);
7316 if (reloc_at (section
, 0))
7317 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7319 printf (_(" Offset Begin End Expression\n"));
7321 seen_first_offset
= 0;
7322 for (i
= first
; i
< num_debug_info_entries
; i
++)
7324 dwarf_vma offset
, voffset
;
7325 dwarf_vma base_address
;
7331 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7333 loc_offsets
= debug_information
[i
].loc_offsets
;
7334 loc_views
= debug_information
[i
].loc_views
;
7335 qsort (array
, debug_information
[i
].num_loc_offsets
,
7336 sizeof (*array
), loc_offsets_compar
);
7339 int adjacent_view_loclists
= 1;
7340 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7342 j
= locs_sorted
? k
: array
[k
];
7344 && (debug_information
[i
].loc_offsets
[locs_sorted
7345 ? k
- 1 : array
[k
- 1]]
7346 == debug_information
[i
].loc_offsets
[j
])
7347 && (debug_information
[i
].loc_views
[locs_sorted
7348 ? k
- 1 : array
[k
- 1]]
7349 == debug_information
[i
].loc_views
[j
]))
7351 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7352 offset
= debug_information
[i
].loc_offsets
[j
];
7353 next
= section_begin
+ offset
;
7354 voffset
= debug_information
[i
].loc_views
[j
];
7356 vnext
= section_begin
+ voffset
;
7359 base_address
= debug_information
[i
].base_address
;
7361 if (vnext
&& vnext
< next
)
7364 display_view_pair_list (section
, &vstart
, i
, next
);
7369 if (!seen_first_offset
|| !adjacent_view_loclists
)
7370 seen_first_offset
= 1;
7374 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7375 (unsigned long) (start
- section_begin
),
7376 (unsigned long) offset
,
7378 else if (start
> next
)
7379 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7380 (unsigned long) (start
- section_begin
),
7381 (unsigned long) offset
,
7387 if (offset
>= bytes
)
7389 warn (_("Offset 0x%lx is bigger than %s section size.\n"),
7390 (unsigned long) offset
,
7395 if (vnext
&& voffset
>= bytes
)
7397 warn (_("View Offset 0x%lx is bigger than %s section size.\n"),
7398 (unsigned long) voffset
,
7406 display_loc_list_dwo (section
, &start
, i
, offset
,
7407 &vstart
, has_frame_base
);
7409 display_loc_list (section
, &start
, i
, offset
, base_address
,
7410 &vstart
, has_frame_base
);
7415 warn (_("DWO is not yet supported.\n"));
7417 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7418 &vstart
, has_frame_base
);
7421 /* FIXME: this arrangement is quite simplistic. Nothing
7422 requires locview lists to be adjacent to corresponding
7423 loclists, and a single loclist could be augmented by
7424 different locview lists, and vice-versa, unlikely as it
7425 is that it would make sense to do so. Hopefully we'll
7426 have view pair support built into loclists before we ever
7427 need to address all these possibilities. */
7428 if (adjacent_view_loclists
&& vnext
7429 && vnext
!= start
&& vstart
!= next
)
7431 adjacent_view_loclists
= 0;
7432 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7435 if (vnext
&& vnext
== start
)
7436 display_view_pair_list (section
, &start
, i
, vstart
);
7440 if (start
< section
->start
+ section
->size
)
7441 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7442 "There are %ld unused bytes at the end of section %s\n",
7443 (long) (section
->start
+ section
->size
- start
)),
7444 (long) (section
->start
+ section
->size
- start
), section
->name
);
7451 display_debug_str (struct dwarf_section
*section
,
7452 void *file ATTRIBUTE_UNUSED
)
7454 unsigned char *start
= section
->start
;
7455 dwarf_vma bytes
= section
->size
;
7456 dwarf_vma addr
= section
->address
;
7460 printf (_("\nThe %s section is empty.\n"), section
->name
);
7464 introduce (section
, false);
7472 lbytes
= (bytes
> 16 ? 16 : bytes
);
7474 printf (" 0x%8.8lx ", (unsigned long) addr
);
7476 for (j
= 0; j
< 16; j
++)
7479 printf ("%2.2x", start
[j
]);
7487 for (j
= 0; j
< lbytes
; j
++)
7490 if (k
>= ' ' && k
< 0x80)
7509 display_debug_info (struct dwarf_section
*section
, void *file
)
7511 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7515 display_debug_types (struct dwarf_section
*section
, void *file
)
7517 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7521 display_trace_info (struct dwarf_section
*section
, void *file
)
7523 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7527 display_debug_aranges (struct dwarf_section
*section
,
7528 void *file ATTRIBUTE_UNUSED
)
7530 unsigned char *start
= section
->start
;
7531 unsigned char *end
= start
+ section
->size
;
7533 introduce (section
, false);
7535 /* It does not matter if this load fails,
7536 we test for that later on. */
7537 load_debug_info (file
);
7541 unsigned char *hdrptr
;
7542 DWARF2_Internal_ARange arange
;
7543 unsigned char *addr_ranges
;
7547 unsigned char address_size
;
7548 unsigned int offset_size
;
7549 unsigned char *end_ranges
;
7552 sec_off
= hdrptr
- section
->start
;
7554 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7555 if (arange
.ar_length
== 0xffffffff)
7557 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7563 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7565 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7567 (unsigned long) sec_off
,
7568 dwarf_vmatoa ("x", arange
.ar_length
));
7571 end_ranges
= hdrptr
+ arange
.ar_length
;
7573 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7574 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7577 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7578 && num_debug_info_entries
> 0
7579 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7580 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7581 (unsigned long) arange
.ar_info_offset
, section
->name
);
7583 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7584 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7586 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7588 /* PR 19872: A version number of 0 probably means that there is
7589 padding at the end of the .debug_aranges section. Gold puts
7590 it there when performing an incremental link, for example.
7591 So do not generate a warning in this case. */
7592 if (arange
.ar_version
)
7593 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7597 printf (_(" Length: %ld\n"),
7598 (long) arange
.ar_length
);
7599 printf (_(" Version: %d\n"), arange
.ar_version
);
7600 printf (_(" Offset into .debug_info: 0x%lx\n"),
7601 (unsigned long) arange
.ar_info_offset
);
7602 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7603 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7605 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7607 /* PR 17512: file: 001-108546-0.001:0.1. */
7608 if (address_size
== 0 || address_size
> 8)
7610 error (_("Invalid address size in %s section!\n"),
7615 /* The DWARF spec does not require that the address size be a power
7616 of two, but we do. This will have to change if we ever encounter
7617 an uneven architecture. */
7618 if ((address_size
& (address_size
- 1)) != 0)
7620 warn (_("Pointer size + Segment size is not a power of two.\n"));
7624 if (address_size
> 4)
7625 printf (_("\n Address Length\n"));
7627 printf (_("\n Address Length\n"));
7629 addr_ranges
= hdrptr
;
7631 /* Must pad to an alignment boundary that is twice the address size. */
7632 addr_ranges
+= (2 * address_size
- 1
7633 - (hdrptr
- start
- 1) % (2 * address_size
));
7635 while (2 * address_size
<= end_ranges
- addr_ranges
)
7637 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7639 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7642 print_dwarf_vma (address
, address_size
);
7643 print_dwarf_vma (length
, address_size
);
7655 /* Comparison function for qsort. */
7657 comp_addr_base (const void * v0
, const void * v1
)
7659 debug_info
*info0
= *(debug_info
**) v0
;
7660 debug_info
*info1
= *(debug_info
**) v1
;
7661 return info0
->addr_base
- info1
->addr_base
;
7664 /* Display the debug_addr section. */
7666 display_debug_addr (struct dwarf_section
*section
,
7669 debug_info
**debug_addr_info
;
7670 unsigned char *entry
;
7674 unsigned char * header
;
7676 if (section
->size
== 0)
7678 printf (_("\nThe %s section is empty.\n"), section
->name
);
7682 if (load_debug_info (file
) == 0)
7684 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7689 introduce (section
, false);
7691 /* PR 17531: file: cf38d01b.
7692 We use xcalloc because a corrupt file may not have initialised all of the
7693 fields in the debug_info structure, which means that the sort below might
7694 try to move uninitialised data. */
7695 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7696 sizeof (debug_info
*));
7699 for (i
= 0; i
< num_debug_info_entries
; i
++)
7700 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7702 /* PR 17531: file: cf38d01b. */
7703 if (debug_information
[i
].addr_base
>= section
->size
)
7704 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7705 (unsigned long) debug_information
[i
].addr_base
, i
);
7707 debug_addr_info
[count
++] = debug_information
+ i
;
7710 /* Add a sentinel to make iteration convenient. */
7711 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7712 debug_addr_info
[count
]->addr_base
= section
->size
;
7713 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7715 header
= section
->start
;
7716 for (i
= 0; i
< count
; i
++)
7719 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7721 printf (_(" For compilation unit at offset 0x%s:\n"),
7722 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7724 printf (_("\tIndex\tAddress\n"));
7725 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7726 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7728 size_t header_size
= entry
- header
;
7729 unsigned char * curr_header
= header
;
7732 int segment_selector_size
;
7734 if (header_size
!= 8 && header_size
!= 16)
7736 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7737 section
->name
, (long) header_size
);
7741 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7742 if (length
== 0xffffffff)
7743 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7744 end
= curr_header
+ length
;
7746 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7748 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7749 section
->name
, version
);
7751 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7752 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7753 address_size
+= segment_selector_size
;
7756 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7761 dwarf_vma base
= byte_get (entry
, address_size
);
7762 printf (_("\t%d:\t"), idx
);
7763 print_dwarf_vma (base
, address_size
);
7765 entry
+= address_size
;
7771 free (debug_addr_info
);
7775 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7778 display_debug_str_offsets (struct dwarf_section
*section
,
7779 void *file ATTRIBUTE_UNUSED
)
7783 if (section
->size
== 0)
7785 printf (_("\nThe %s section is empty.\n"), section
->name
);
7789 unsigned char *start
= section
->start
;
7790 unsigned char *end
= start
+ section
->size
;
7791 unsigned char *curr
= start
;
7793 const char *suffix
= strrchr (section
->name
, '.');
7794 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7797 load_debug_section_with_follow (str_dwo
, file
);
7799 load_debug_section_with_follow (str
, file
);
7801 introduce (section
, false);
7806 dwarf_vma entry_length
;
7808 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7809 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7810 if (length
== 0xffffffff)
7812 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7818 unsigned char *entries_end
;
7821 /* This is probably an old style .debug_str_offset section which
7822 just contains offsets and no header (and the first offset is 0). */
7823 length
= section
->size
;
7824 curr
= section
->start
;
7827 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7828 printf (_(" Index Offset [String]\n"));
7832 if (length
<= (dwarf_vma
) (end
- curr
))
7833 entries_end
= curr
+ length
;
7836 warn (_("Section %s is too small %#lx\n"),
7837 section
->name
, (unsigned long) section
->size
);
7842 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7844 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7847 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7849 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7851 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7852 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7853 printf (_(" Index Offset [String]\n"));
7856 for (idx
= 0; curr
< entries_end
; idx
++)
7859 const unsigned char * string
;
7861 if ((dwarf_vma
) (entries_end
- curr
) < entry_length
)
7862 /* Not enough space to read one entry_length, give up. */
7865 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7867 string
= (const unsigned char *)
7868 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7870 string
= fetch_indirect_string (offset
);
7872 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7880 /* Each debug_information[x].range_lists[y] gets this representation for
7881 sorting purposes. */
7885 /* The debug_information[x].range_lists[y] value. */
7886 dwarf_vma ranges_offset
;
7888 /* Original debug_information to find parameters of the data. */
7889 debug_info
*debug_info_p
;
7892 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7895 range_entry_compar (const void *ap
, const void *bp
)
7897 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7898 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7899 const dwarf_vma a
= a_re
->ranges_offset
;
7900 const dwarf_vma b
= b_re
->ranges_offset
;
7902 return (a
> b
) - (b
> a
);
7906 display_debug_ranges_list (unsigned char * start
,
7907 unsigned char * finish
,
7908 unsigned int pointer_size
,
7910 dwarf_vma base_address
)
7912 while (start
< finish
)
7917 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7918 if (start
>= finish
)
7920 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7923 print_dwarf_vma (offset
, 4);
7925 if (begin
== 0 && end
== 0)
7927 printf (_("<End of list>\n"));
7931 /* Check base address specifiers. */
7932 if (is_max_address (begin
, pointer_size
)
7933 && !is_max_address (end
, pointer_size
))
7936 print_dwarf_vma (begin
, pointer_size
);
7937 print_dwarf_vma (end
, pointer_size
);
7938 printf ("(base address)\n");
7942 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7943 print_dwarf_vma (end
+ base_address
, pointer_size
);
7946 fputs (_("(start == end)"), stdout
);
7947 else if (begin
> end
)
7948 fputs (_("(start > end)"), stdout
);
7955 display_debug_rnglists_list (unsigned char * start
,
7956 unsigned char * finish
,
7957 unsigned int pointer_size
,
7959 dwarf_vma base_address
,
7960 unsigned int offset_size
)
7962 unsigned char *next
= start
;
7963 unsigned int debug_addr_section_hdr_len
;
7965 if (offset_size
== 4)
7966 debug_addr_section_hdr_len
= 8;
7968 debug_addr_section_hdr_len
= 16;
7972 dwarf_vma off
= offset
+ (start
- next
);
7973 enum dwarf_range_list_entry rlet
;
7974 /* Initialize it due to a false compiler warning. */
7975 dwarf_vma begin
= -1, length
, end
= -1;
7977 if (start
>= finish
)
7979 warn (_("Range list starting at offset 0x%s is not terminated.\n"),
7980 dwarf_vmatoa ("x", offset
));
7985 print_dwarf_vma (off
, 4);
7987 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7991 case DW_RLE_end_of_list
:
7992 printf (_("<End of list>\n"));
7994 case DW_RLE_base_addressx
:
7995 READ_ULEB (base_address
, start
, finish
);
7996 print_dwarf_vma (base_address
, pointer_size
);
7997 printf (_("(base address index) "));
7998 base_address
= fetch_indexed_addr ((base_address
* pointer_size
)
7999 + debug_addr_section_hdr_len
, pointer_size
);
8000 print_dwarf_vma (base_address
, pointer_size
);
8001 printf (_("(base address)\n"));
8003 case DW_RLE_startx_endx
:
8004 READ_ULEB (begin
, start
, finish
);
8005 READ_ULEB (end
, start
, finish
);
8006 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8007 + debug_addr_section_hdr_len
, pointer_size
);
8008 end
= fetch_indexed_addr ((begin
* pointer_size
)
8009 + debug_addr_section_hdr_len
, pointer_size
);
8011 case DW_RLE_startx_length
:
8012 READ_ULEB (begin
, start
, finish
);
8013 READ_ULEB (length
, start
, finish
);
8014 begin
= fetch_indexed_addr ((begin
* pointer_size
)
8015 + debug_addr_section_hdr_len
, pointer_size
);
8016 end
= begin
+ length
;
8018 case DW_RLE_offset_pair
:
8019 READ_ULEB (begin
, start
, finish
);
8020 READ_ULEB (end
, start
, finish
);
8022 case DW_RLE_base_address
:
8023 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8024 print_dwarf_vma (base_address
, pointer_size
);
8025 printf (_("(base address)\n"));
8027 case DW_RLE_start_end
:
8028 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8029 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8031 case DW_RLE_start_length
:
8032 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8033 READ_ULEB (length
, start
, finish
);
8034 end
= begin
+ length
;
8037 error (_("Invalid range list entry type %d\n"), rlet
);
8038 rlet
= DW_RLE_end_of_list
;
8042 if (rlet
== DW_RLE_end_of_list
)
8044 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8047 /* Only a DW_RLE_offset_pair needs the base address added. */
8048 if (rlet
== DW_RLE_offset_pair
)
8050 begin
+= base_address
;
8051 end
+= base_address
;
8054 print_dwarf_vma (begin
, pointer_size
);
8055 print_dwarf_vma (end
, pointer_size
);
8058 fputs (_("(start == end)"), stdout
);
8059 else if (begin
> end
)
8060 fputs (_("(start > end)"), stdout
);
8067 display_debug_ranges (struct dwarf_section
*section
,
8068 void *file ATTRIBUTE_UNUSED
)
8070 unsigned char * start
= section
->start
;
8071 unsigned char * last_start
= start
;
8072 dwarf_vma bytes
= section
->size
;
8073 unsigned char * section_begin
= start
;
8074 unsigned char * finish
= start
+ bytes
;
8075 unsigned int num_range_list
, i
;
8076 struct range_entry
* range_entries
;
8077 struct range_entry
* range_entry_fill
;
8078 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8079 /* Initialize it due to a false compiler warning. */
8080 unsigned char address_size
= 0;
8081 dwarf_vma last_offset
= 0;
8082 unsigned int offset_size
= 0;
8086 printf (_("\nThe %s section is empty.\n"), section
->name
);
8090 introduce (section
, false);
8094 dwarf_vma initial_length
;
8095 unsigned char segment_selector_size
;
8096 unsigned int offset_entry_count
;
8097 unsigned short version
;
8099 /* Get and check the length of the block. */
8100 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8102 if (initial_length
== 0xffffffff)
8104 /* This section is 64-bit DWARF 3. */
8105 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8111 if (initial_length
> (size_t) (finish
- start
))
8113 /* If the length field has a relocation against it, then we should
8114 not complain if it is inaccurate (and probably negative).
8115 It is copied from .debug_line handling code. */
8116 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8118 initial_length
= finish
- start
;
8122 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
8123 (long) initial_length
);
8128 /* Get the other fields in the header. */
8129 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8130 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8131 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8132 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8134 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", initial_length
));
8135 printf (_(" DWARF version: %u\n"), version
);
8136 printf (_(" Address size: %u\n"), address_size
);
8137 printf (_(" Segment size: %u\n"), segment_selector_size
);
8138 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8140 /* Check the fields. */
8141 if (segment_selector_size
!= 0)
8143 warn (_("The %s section contains "
8144 "unsupported segment selector size: %d.\n"),
8145 section
->name
, segment_selector_size
);
8151 warn (_("Only DWARF version 5+ debug_rnglists info "
8152 "is currently supported.\n"));
8156 if (offset_entry_count
!= 0)
8158 printf (_("\n Offsets starting at 0x%lx:\n"), (long)(start
- section
->start
));
8159 if (offset_size
== 8)
8161 for (i
= 0; i
< offset_entry_count
; i
++)
8165 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, finish
);
8166 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
8171 for (i
= 0; i
< offset_entry_count
; i
++)
8175 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, finish
);
8176 printf (_(" [%6u] 0x%x\n"), i
, entry
);
8182 if (load_debug_info (file
) == 0)
8184 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8190 for (i
= 0; i
< num_debug_info_entries
; i
++)
8192 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
8193 /* Skip .debug_rnglists reference. */
8195 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
8196 /* Skip .debug_range reference. */
8198 num_range_list
+= debug_information
[i
].num_range_lists
;
8201 if (num_range_list
== 0)
8203 /* This can happen when the file was compiled with -gsplit-debug
8204 which removes references to range lists from the primary .o file. */
8205 printf (_("No range lists in .debug_info section.\n"));
8209 range_entries
= (struct range_entry
*)
8210 xmalloc (sizeof (*range_entries
) * num_range_list
);
8211 range_entry_fill
= range_entries
;
8213 for (i
= 0; i
< num_debug_info_entries
; i
++)
8215 debug_info
*debug_info_p
= &debug_information
[i
];
8218 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
8219 /* Skip .debug_rnglists reference. */
8221 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
8222 /* Skip .debug_range reference. */
8225 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8227 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8228 range_entry_fill
->debug_info_p
= debug_info_p
;
8233 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8234 range_entry_compar
);
8236 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8237 warn (_("Range lists in %s section start at 0x%lx\n"),
8238 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
8241 printf (_(" Offset Begin End\n"));
8243 for (i
= 0; i
< num_range_list
; i
++)
8245 struct range_entry
*range_entry
= &range_entries
[i
];
8246 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8247 unsigned int pointer_size
;
8249 unsigned char *next
;
8250 dwarf_vma base_address
;
8252 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8253 offset
= range_entry
->ranges_offset
;
8254 base_address
= debug_info_p
->base_address
;
8256 /* PR 17512: file: 001-101485-0.001:0.1. */
8257 if (pointer_size
< 2 || pointer_size
> 8)
8259 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
8260 pointer_size
, (unsigned long) offset
);
8264 if (offset
> (size_t) (finish
- section_begin
))
8266 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
8267 (unsigned long) offset
, i
);
8271 next
= section_begin
+ offset
+ debug_info_p
->rnglists_base
;
8273 /* If multiple DWARF entities reference the same range then we will
8274 have multiple entries in the `range_entries' list for the same
8275 offset. Thanks to the sort above these will all be consecutive in
8276 the `range_entries' list, so we can easily ignore duplicates
8278 if (i
> 0 && last_offset
== offset
)
8280 last_offset
= offset
;
8282 if (dwarf_check
!= 0 && i
> 0)
8285 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
8286 (unsigned long) (start
- section_begin
),
8287 (unsigned long) (next
- section_begin
), section
->name
);
8288 else if (start
> next
)
8290 if (next
== last_start
)
8292 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
8293 (unsigned long) (start
- section_begin
),
8294 (unsigned long) (next
- section_begin
), section
->name
);
8302 display_debug_rnglists_list
8303 (start
, finish
, pointer_size
, offset
, base_address
, offset_size
);
8305 display_debug_ranges_list
8306 (start
, finish
, pointer_size
, offset
, base_address
);
8310 free (range_entries
);
8315 typedef struct Frame_Chunk
8317 struct Frame_Chunk
*next
;
8318 unsigned char *chunk_start
;
8320 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8321 short int *col_type
;
8324 unsigned int code_factor
;
8328 unsigned int cfa_reg
;
8329 dwarf_vma cfa_offset
;
8331 unsigned char fde_encoding
;
8332 unsigned char cfa_exp
;
8333 unsigned char ptr_size
;
8334 unsigned char segment_size
;
8338 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8339 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8340 static const char *const *dwarf_regnames
;
8341 static unsigned int dwarf_regnames_count
;
8344 /* A marker for a col_type that means this column was never referenced
8345 in the frame info. */
8346 #define DW_CFA_unreferenced (-1)
8348 /* Return 0 if no more space is needed, 1 if more space is needed,
8349 -1 for invalid reg. */
8352 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8354 unsigned int prev
= fc
->ncols
;
8356 if (reg
< (unsigned int) fc
->ncols
)
8359 if (dwarf_regnames_count
> 0
8360 && reg
> dwarf_regnames_count
)
8363 fc
->ncols
= reg
+ 1;
8364 /* PR 17512: file: 10450-2643-0.004.
8365 If reg == -1 then this can happen... */
8369 /* PR 17512: file: 2844a11d. */
8370 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8372 error (_("Unfeasibly large register number: %u\n"), reg
);
8374 /* FIXME: 1024 is an arbitrary limit. Increase it if
8375 we ever encounter a valid binary that exceeds it. */
8379 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
8380 sizeof (short int));
8381 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
8382 /* PR 17512: file:002-10025-0.005. */
8383 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8385 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8391 while (prev
< fc
->ncols
)
8393 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8394 fc
->col_offset
[prev
] = 0;
8400 static const char *const dwarf_regnames_i386
[] =
8402 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8403 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8404 "eip", "eflags", NULL
, /* 8 - 10 */
8405 "st0", "st1", "st2", "st3", /* 11 - 14 */
8406 "st4", "st5", "st6", "st7", /* 15 - 18 */
8407 NULL
, NULL
, /* 19 - 20 */
8408 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8409 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8410 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8411 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8412 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8413 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8414 "tr", "ldtr", /* 48 - 49 */
8415 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8416 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8417 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8418 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8419 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8420 NULL
, NULL
, NULL
, /* 90 - 92 */
8421 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8424 static const char *const dwarf_regnames_iamcu
[] =
8426 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8427 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8428 "eip", "eflags", NULL
, /* 8 - 10 */
8429 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8430 NULL
, NULL
, /* 19 - 20 */
8431 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8432 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8433 NULL
, NULL
, NULL
, /* 37 - 39 */
8434 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8435 "tr", "ldtr", /* 48 - 49 */
8436 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8437 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8438 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8439 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8440 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8441 NULL
, NULL
, NULL
, /* 90 - 92 */
8442 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8446 init_dwarf_regnames_i386 (void)
8448 dwarf_regnames
= dwarf_regnames_i386
;
8449 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8450 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8454 init_dwarf_regnames_iamcu (void)
8456 dwarf_regnames
= dwarf_regnames_iamcu
;
8457 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8458 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8461 static const char *const dwarf_regnames_x86_64
[] =
8463 "rax", "rdx", "rcx", "rbx",
8464 "rsi", "rdi", "rbp", "rsp",
8465 "r8", "r9", "r10", "r11",
8466 "r12", "r13", "r14", "r15",
8468 "xmm0", "xmm1", "xmm2", "xmm3",
8469 "xmm4", "xmm5", "xmm6", "xmm7",
8470 "xmm8", "xmm9", "xmm10", "xmm11",
8471 "xmm12", "xmm13", "xmm14", "xmm15",
8472 "st0", "st1", "st2", "st3",
8473 "st4", "st5", "st6", "st7",
8474 "mm0", "mm1", "mm2", "mm3",
8475 "mm4", "mm5", "mm6", "mm7",
8477 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8478 "fs.base", "gs.base", NULL
, NULL
,
8480 "mxcsr", "fcw", "fsw",
8481 "xmm16", "xmm17", "xmm18", "xmm19",
8482 "xmm20", "xmm21", "xmm22", "xmm23",
8483 "xmm24", "xmm25", "xmm26", "xmm27",
8484 "xmm28", "xmm29", "xmm30", "xmm31",
8485 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8486 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8487 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8488 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8489 NULL
, NULL
, NULL
, /* 115 - 117 */
8490 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8494 init_dwarf_regnames_x86_64 (void)
8496 dwarf_regnames
= dwarf_regnames_x86_64
;
8497 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8498 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8501 static const char *const dwarf_regnames_aarch64
[] =
8503 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8504 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8505 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8506 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8507 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8508 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8509 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8510 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8511 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8512 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8513 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8514 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8515 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8516 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8517 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8518 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8522 init_dwarf_regnames_aarch64 (void)
8524 dwarf_regnames
= dwarf_regnames_aarch64
;
8525 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8526 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8529 static const char *const dwarf_regnames_s390
[] =
8531 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8532 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8533 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8534 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8535 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8536 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8537 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8538 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8539 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8542 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8543 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8547 init_dwarf_regnames_s390 (void)
8549 dwarf_regnames
= dwarf_regnames_s390
;
8550 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8551 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8554 static const char *const dwarf_regnames_riscv
[] =
8556 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8557 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8558 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8559 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8560 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8561 "fs0", "fs1", /* 40 - 41 */
8562 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8563 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8564 "fs10", "fs11", /* 58 - 59 */
8565 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8568 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8569 the large number of CSRs. */
8572 regname_internal_riscv (unsigned int regno
)
8574 const char *name
= NULL
;
8576 /* Lookup in the table first, this covers GPR and FPR. */
8577 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8578 name
= dwarf_regnames_riscv
[regno
];
8579 else if (regno
>= 4096 && regno
<= 8191)
8581 /* This might be a CSR, these live in a sparse number space from 4096
8582 to 8191 These numbers are defined in the RISC-V ELF ABI
8586 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8587 case VALUE + 4096: name = #NAME; break;
8588 #include "opcode/riscv-opc.h"
8593 static char csr_name
[10];
8594 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8605 init_dwarf_regnames_riscv (void)
8607 dwarf_regnames
= NULL
;
8608 dwarf_regnames_count
= 8192;
8609 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8613 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8615 dwarf_regnames_lookup_func
= NULL
;
8620 init_dwarf_regnames_i386 ();
8624 init_dwarf_regnames_iamcu ();
8630 init_dwarf_regnames_x86_64 ();
8634 init_dwarf_regnames_aarch64 ();
8638 init_dwarf_regnames_s390 ();
8642 init_dwarf_regnames_riscv ();
8650 /* Initialize the DWARF register name lookup state based on the
8651 architecture and specific machine type of a BFD. */
8654 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8657 dwarf_regnames_lookup_func
= NULL
;
8664 case bfd_mach_x86_64
:
8665 case bfd_mach_x86_64_intel_syntax
:
8666 case bfd_mach_x64_32
:
8667 case bfd_mach_x64_32_intel_syntax
:
8668 init_dwarf_regnames_x86_64 ();
8672 init_dwarf_regnames_i386 ();
8677 case bfd_arch_iamcu
:
8678 init_dwarf_regnames_iamcu ();
8681 case bfd_arch_aarch64
:
8682 init_dwarf_regnames_aarch64();
8686 init_dwarf_regnames_s390 ();
8689 case bfd_arch_riscv
:
8690 init_dwarf_regnames_riscv ();
8699 regname_internal_by_table_only (unsigned int regno
)
8701 if (dwarf_regnames
!= NULL
8702 && regno
< dwarf_regnames_count
8703 && dwarf_regnames
[regno
] != NULL
)
8704 return dwarf_regnames
[regno
];
8710 regname (unsigned int regno
, int name_only_p
)
8712 static char reg
[64];
8714 const char *name
= NULL
;
8716 if (dwarf_regnames_lookup_func
!= NULL
)
8717 name
= dwarf_regnames_lookup_func (regno
);
8723 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8726 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8731 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8736 if (*max_regs
!= fc
->ncols
)
8737 *max_regs
= fc
->ncols
;
8739 if (*need_col_headers
)
8741 *need_col_headers
= 0;
8743 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8745 for (r
= 0; r
< *max_regs
; r
++)
8746 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8751 printf ("%-5s ", regname (r
, 1));
8757 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8759 strcpy (tmp
, "exp");
8761 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8762 printf ("%-8s ", tmp
);
8764 for (r
= 0; r
< fc
->ncols
; r
++)
8766 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8768 switch (fc
->col_type
[r
])
8770 case DW_CFA_undefined
:
8773 case DW_CFA_same_value
:
8777 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8779 case DW_CFA_val_offset
:
8780 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8782 case DW_CFA_register
:
8783 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8785 case DW_CFA_expression
:
8786 strcpy (tmp
, "exp");
8788 case DW_CFA_val_expression
:
8789 strcpy (tmp
, "vexp");
8792 strcpy (tmp
, "n/a");
8795 printf ("%-5s ", tmp
);
8801 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8803 static unsigned char *
8804 read_cie (unsigned char *start
, unsigned char *end
,
8805 Frame_Chunk
**p_cie
, int *p_version
,
8806 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8810 unsigned char *augmentation_data
= NULL
;
8811 bfd_size_type augmentation_data_len
= 0;
8814 /* PR 17512: file: 001-228113-0.004. */
8818 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8819 memset (fc
, 0, sizeof (Frame_Chunk
));
8821 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8822 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8826 fc
->augmentation
= (char *) start
;
8827 /* PR 17512: file: 001-228113-0.004.
8828 Skip past augmentation name, but avoid running off the end of the data. */
8830 if (* start
++ == '\0')
8834 warn (_("No terminator for augmentation name\n"));
8838 if (strcmp (fc
->augmentation
, "eh") == 0)
8840 if (eh_addr_size
> (size_t) (end
- start
))
8842 start
+= eh_addr_size
;
8847 if (2 > (size_t) (end
- start
))
8849 GET (fc
->ptr_size
, 1);
8850 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8852 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8856 GET (fc
->segment_size
, 1);
8857 /* PR 17512: file: e99d2804. */
8858 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8860 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8864 eh_addr_size
= fc
->ptr_size
;
8868 fc
->ptr_size
= eh_addr_size
;
8869 fc
->segment_size
= 0;
8872 READ_ULEB (fc
->code_factor
, start
, end
);
8873 READ_SLEB (fc
->data_factor
, start
, end
);
8884 READ_ULEB (fc
->ra
, start
, end
);
8887 if (fc
->augmentation
[0] == 'z')
8891 READ_ULEB (augmentation_data_len
, start
, end
);
8892 augmentation_data
= start
;
8893 /* PR 17512: file: 11042-2589-0.004. */
8894 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8896 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8897 dwarf_vmatoa ("x", augmentation_data_len
),
8898 (unsigned long) (end
- start
));
8901 start
+= augmentation_data_len
;
8904 if (augmentation_data_len
)
8908 unsigned char *qend
;
8910 p
= (unsigned char *) fc
->augmentation
+ 1;
8911 q
= augmentation_data
;
8912 qend
= q
+ augmentation_data_len
;
8914 while (p
< end
&& q
< qend
)
8919 q
+= 1 + size_of_encoded_value (*q
);
8921 fc
->fde_encoding
= *q
++;
8930 /* Note - it is OK if this loop terminates with q < qend.
8931 Padding may have been inserted to align the end of the CIE. */
8936 *p_version
= version
;
8939 *p_aug_len
= augmentation_data_len
;
8940 *p_aug
= augmentation_data
;
8945 free (fc
->col_offset
);
8946 free (fc
->col_type
);
8951 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8952 If do_wide is not enabled, then formats the output to fit into 80 columns.
8953 PRINTED contains the number of characters already written to the current
8957 display_data (bfd_size_type printed
,
8958 const unsigned char * data
,
8959 const bfd_size_type len
)
8961 if (do_wide
|| len
< ((80 - printed
) / 3))
8962 for (printed
= 0; printed
< len
; ++printed
)
8963 printf (" %02x", data
[printed
]);
8966 for (printed
= 0; printed
< len
; ++printed
)
8968 if (printed
% (80 / 3) == 0)
8970 printf (" %02x", data
[printed
]);
8975 /* Prints out the contents on the augmentation data array.
8976 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8979 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8983 i
= printf (_(" Augmentation data: "));
8984 display_data (i
, data
, len
);
8988 display_debug_frames (struct dwarf_section
*section
,
8989 void *file ATTRIBUTE_UNUSED
)
8991 unsigned char *start
= section
->start
;
8992 unsigned char *end
= start
+ section
->size
;
8993 unsigned char *section_start
= start
;
8994 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8995 Frame_Chunk
*remembered_state
= NULL
;
8997 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8998 unsigned int max_regs
= 0;
8999 const char *bad_reg
= _("bad register: ");
9000 unsigned int saved_eh_addr_size
= eh_addr_size
;
9002 introduce (section
, false);
9006 unsigned char *saved_start
;
9007 unsigned char *block_end
;
9012 int need_col_headers
= 1;
9013 unsigned char *augmentation_data
= NULL
;
9014 bfd_size_type augmentation_data_len
= 0;
9015 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
9016 unsigned int offset_size
;
9018 static Frame_Chunk fde_fc
;
9020 saved_start
= start
;
9022 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9026 printf ("\n%08lx ZERO terminator\n\n",
9027 (unsigned long)(saved_start
- section_start
));
9028 /* Skip any zero terminators that directly follow.
9029 A corrupt section size could have loaded a whole
9030 slew of zero filled memory bytes. eg
9031 PR 17512: file: 070-19381-0.004. */
9032 while (start
< end
&& * start
== 0)
9037 if (length
== 0xffffffff)
9039 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9045 if (length
> (size_t) (end
- start
))
9047 warn ("Invalid length 0x%s in FDE at %#08lx\n",
9048 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
9049 (unsigned long) (saved_start
- section_start
));
9053 block_end
= start
+ length
;
9055 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9057 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9058 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9063 start
= read_cie (start
, block_end
, &cie
, &version
,
9064 &augmentation_data_len
, &augmentation_data
);
9065 /* PR 17512: file: 027-135133-0.005. */
9072 fc
->chunk_start
= saved_start
;
9073 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9076 if (frame_need_space (fc
, mreg
) < 0)
9078 if (fc
->fde_encoding
)
9079 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9081 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
9082 print_dwarf_vma (length
, fc
->ptr_size
);
9083 print_dwarf_vma (cie_id
, offset_size
);
9085 if (do_debug_frames_interp
)
9087 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9088 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9093 printf (" Version: %d\n", version
);
9094 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9097 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9098 printf (" Segment Size: %u\n", fc
->segment_size
);
9100 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9101 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9102 printf (" Return address column: %d\n", fc
->ra
);
9104 if (augmentation_data_len
)
9105 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9112 unsigned char *look_for
;
9113 unsigned long segment_selector
;
9119 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
9120 cie_off
= (cie_off
^ sign
) - sign
;
9121 cie_off
= start
- 4 - section_start
- cie_off
;
9124 look_for
= section_start
+ cie_off
;
9125 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
9127 for (cie
= chunks
; cie
; cie
= cie
->next
)
9128 if (cie
->chunk_start
== look_for
)
9131 else if (cie_off
>= section
->size
)
9135 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9136 if (cie
->chunk_start
== look_for
)
9140 unsigned int off_size
;
9141 unsigned char *cie_scan
;
9143 cie_scan
= look_for
;
9145 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9146 if (length
== 0xffffffff)
9148 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9151 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9154 unsigned char *cie_end
= cie_scan
+ length
;
9156 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9160 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9161 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9166 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9167 &augmentation_data_len
, &augmentation_data
);
9168 /* PR 17512: file: 3450-2098-0.004. */
9171 warn (_("Failed to read CIE information\n"));
9174 cie
->next
= forward_refs
;
9176 cie
->chunk_start
= look_for
;
9177 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9180 if (frame_need_space (cie
, mreg
) < 0)
9182 warn (_("Invalid max register\n"));
9185 if (cie
->fde_encoding
)
9187 = size_of_encoded_value (cie
->fde_encoding
);
9194 memset (fc
, 0, sizeof (Frame_Chunk
));
9199 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
9200 fc
->col_offset
= (int *) xmalloc (sizeof (int));
9201 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9203 warn (_("Invalid max register\n"));
9207 fc
->augmentation
= "";
9208 fc
->fde_encoding
= 0;
9209 fc
->ptr_size
= eh_addr_size
;
9210 fc
->segment_size
= 0;
9214 fc
->ncols
= cie
->ncols
;
9215 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
9216 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
9217 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
9218 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
9219 fc
->augmentation
= cie
->augmentation
;
9220 fc
->ptr_size
= cie
->ptr_size
;
9221 eh_addr_size
= cie
->ptr_size
;
9222 fc
->segment_size
= cie
->segment_size
;
9223 fc
->code_factor
= cie
->code_factor
;
9224 fc
->data_factor
= cie
->data_factor
;
9225 fc
->cfa_reg
= cie
->cfa_reg
;
9226 fc
->cfa_offset
= cie
->cfa_offset
;
9228 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9230 warn (_("Invalid max register\n"));
9233 fc
->fde_encoding
= cie
->fde_encoding
;
9236 if (fc
->fde_encoding
)
9237 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9239 segment_selector
= 0;
9240 if (fc
->segment_size
)
9242 if (fc
->segment_size
> sizeof (segment_selector
))
9244 /* PR 17512: file: 9e196b3e. */
9245 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9246 fc
->segment_size
= 4;
9248 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9249 fc
->segment_size
, block_end
);
9252 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9255 /* FIXME: It appears that sometimes the final pc_range value is
9256 encoded in less than encoded_ptr_size bytes. See the x86_64
9257 run of the "objcopy on compressed debug sections" test for an
9259 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9262 if (cie
->augmentation
[0] == 'z')
9264 READ_ULEB (augmentation_data_len
, start
, block_end
);
9265 augmentation_data
= start
;
9266 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9267 if (augmentation_data_len
> (bfd_size_type
) (block_end
- start
))
9269 warn (_("Augmentation data too long: 0x%s, "
9270 "expected at most %#lx\n"),
9271 dwarf_vmatoa ("x", augmentation_data_len
),
9272 (unsigned long) (block_end
- start
));
9274 augmentation_data
= NULL
;
9275 augmentation_data_len
= 0;
9277 start
+= augmentation_data_len
;
9280 printf ("\n%08lx %s %s FDE ",
9281 (unsigned long)(saved_start
- section_start
),
9282 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
9283 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
));
9285 if (cie
->chunk_start
)
9286 printf ("cie=%08lx",
9287 (unsigned long) (cie
->chunk_start
- section_start
));
9289 /* Ideally translate "invalid " to 8 chars, trailing space
9291 printf (_("cie=invalid "));
9294 if (fc
->segment_size
)
9295 printf ("%04lx:", segment_selector
);
9298 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
9299 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
9301 if (! do_debug_frames_interp
&& augmentation_data_len
)
9303 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9308 /* At this point, fc is the current chunk, cie (if any) is set, and
9309 we're about to interpret instructions for the chunk. */
9310 /* ??? At present we need to do this always, since this sizes the
9311 fc->col_type and fc->col_offset arrays, which we write into always.
9312 We should probably split the interpreted and non-interpreted bits
9313 into two different routines, since there's so much that doesn't
9314 really overlap between them. */
9315 if (1 || do_debug_frames_interp
)
9317 /* Start by making a pass over the chunk, allocating storage
9318 and taking note of what registers are used. */
9319 unsigned char *tmp
= start
;
9321 while (start
< block_end
)
9323 unsigned int reg
, op
, opa
;
9331 /* Warning: if you add any more cases to this switch, be
9332 sure to add them to the corresponding switch below. */
9336 case DW_CFA_advance_loc
:
9339 SKIP_ULEB (start
, block_end
);
9342 case DW_CFA_restore
:
9345 case DW_CFA_set_loc
:
9346 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9349 start
+= encoded_ptr_size
;
9351 case DW_CFA_advance_loc1
:
9352 if ((size_t) (block_end
- start
) < 1)
9357 case DW_CFA_advance_loc2
:
9358 if ((size_t) (block_end
- start
) < 2)
9363 case DW_CFA_advance_loc4
:
9364 if ((size_t) (block_end
- start
) < 4)
9369 case DW_CFA_offset_extended
:
9370 case DW_CFA_val_offset
:
9371 READ_ULEB (reg
, start
, block_end
);
9372 SKIP_ULEB (start
, block_end
);
9374 case DW_CFA_restore_extended
:
9375 READ_ULEB (reg
, start
, block_end
);
9377 case DW_CFA_undefined
:
9378 READ_ULEB (reg
, start
, block_end
);
9380 case DW_CFA_same_value
:
9381 READ_ULEB (reg
, start
, block_end
);
9383 case DW_CFA_register
:
9384 READ_ULEB (reg
, start
, block_end
);
9385 SKIP_ULEB (start
, block_end
);
9387 case DW_CFA_def_cfa
:
9388 SKIP_ULEB (start
, block_end
);
9389 SKIP_ULEB (start
, block_end
);
9391 case DW_CFA_def_cfa_register
:
9392 SKIP_ULEB (start
, block_end
);
9394 case DW_CFA_def_cfa_offset
:
9395 SKIP_ULEB (start
, block_end
);
9397 case DW_CFA_def_cfa_expression
:
9398 READ_ULEB (temp
, start
, block_end
);
9399 if ((size_t) (block_end
- start
) < temp
)
9404 case DW_CFA_expression
:
9405 case DW_CFA_val_expression
:
9406 READ_ULEB (reg
, start
, block_end
);
9407 READ_ULEB (temp
, start
, block_end
);
9408 if ((size_t) (block_end
- start
) < temp
)
9413 case DW_CFA_offset_extended_sf
:
9414 case DW_CFA_val_offset_sf
:
9415 READ_ULEB (reg
, start
, block_end
);
9416 SKIP_SLEB (start
, block_end
);
9418 case DW_CFA_def_cfa_sf
:
9419 SKIP_ULEB (start
, block_end
);
9420 SKIP_SLEB (start
, block_end
);
9422 case DW_CFA_def_cfa_offset_sf
:
9423 SKIP_SLEB (start
, block_end
);
9425 case DW_CFA_MIPS_advance_loc8
:
9426 if ((size_t) (block_end
- start
) < 8)
9431 case DW_CFA_GNU_args_size
:
9432 SKIP_ULEB (start
, block_end
);
9434 case DW_CFA_GNU_negative_offset_extended
:
9435 READ_ULEB (reg
, start
, block_end
);
9436 SKIP_ULEB (start
, block_end
);
9441 if (reg
!= -1u && frame_need_space (fc
, reg
) >= 0)
9443 /* Don't leave any reg as DW_CFA_unreferenced so
9444 that frame_display_row prints name of regs in
9445 header, and all referenced regs in each line. */
9446 if (reg
>= cie
->ncols
9447 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9448 fc
->col_type
[reg
] = DW_CFA_undefined
;
9450 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9458 /* Now we know what registers are used, make a second pass over
9459 the chunk, this time actually printing out the info. */
9461 while (start
< block_end
)
9464 unsigned long ul
, roffs
;
9465 /* Note: It is tempting to use an unsigned long for 'reg' but there
9466 are various functions, notably frame_space_needed() that assume that
9467 reg is an unsigned int. */
9472 const char *reg_prefix
= "";
9479 /* Make a note if something other than DW_CFA_nop happens. */
9480 if (op
!= DW_CFA_nop
)
9483 /* Warning: if you add any more cases to this switch, be
9484 sure to add them to the corresponding switch above. */
9487 case DW_CFA_advance_loc
:
9488 if (do_debug_frames_interp
)
9489 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9491 printf (" DW_CFA_advance_loc: %d to %s\n",
9492 opa
* fc
->code_factor
,
9493 dwarf_vmatoa_1 (NULL
,
9494 fc
->pc_begin
+ opa
* fc
->code_factor
,
9496 fc
->pc_begin
+= opa
* fc
->code_factor
;
9500 READ_ULEB (roffs
, start
, block_end
);
9501 if (opa
>= fc
->ncols
)
9502 reg_prefix
= bad_reg
;
9503 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9504 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9505 reg_prefix
, regname (opa
, 0),
9506 roffs
* fc
->data_factor
);
9507 if (*reg_prefix
== '\0')
9509 fc
->col_type
[opa
] = DW_CFA_offset
;
9510 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9514 case DW_CFA_restore
:
9515 if (opa
>= fc
->ncols
)
9516 reg_prefix
= bad_reg
;
9517 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9518 printf (" DW_CFA_restore: %s%s\n",
9519 reg_prefix
, regname (opa
, 0));
9520 if (*reg_prefix
!= '\0')
9523 if (opa
>= cie
->ncols
9524 || cie
->col_type
[opa
] == DW_CFA_unreferenced
)
9526 fc
->col_type
[opa
] = DW_CFA_undefined
;
9527 fc
->col_offset
[opa
] = 0;
9531 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9532 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9536 case DW_CFA_set_loc
:
9537 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9539 if (do_debug_frames_interp
)
9540 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9542 printf (" DW_CFA_set_loc: %s\n",
9543 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9547 case DW_CFA_advance_loc1
:
9548 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9549 if (do_debug_frames_interp
)
9550 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9552 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9553 (unsigned long) (ofs
* fc
->code_factor
),
9554 dwarf_vmatoa_1 (NULL
,
9555 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9557 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9560 case DW_CFA_advance_loc2
:
9561 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9562 if (do_debug_frames_interp
)
9563 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9565 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9566 (unsigned long) (ofs
* fc
->code_factor
),
9567 dwarf_vmatoa_1 (NULL
,
9568 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9570 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9573 case DW_CFA_advance_loc4
:
9574 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9575 if (do_debug_frames_interp
)
9576 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9578 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9579 (unsigned long) (ofs
* fc
->code_factor
),
9580 dwarf_vmatoa_1 (NULL
,
9581 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9583 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9586 case DW_CFA_offset_extended
:
9587 READ_ULEB (reg
, start
, block_end
);
9588 READ_ULEB (roffs
, start
, block_end
);
9589 if (reg
>= fc
->ncols
)
9590 reg_prefix
= bad_reg
;
9591 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9592 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9593 reg_prefix
, regname (reg
, 0),
9594 roffs
* fc
->data_factor
);
9595 if (*reg_prefix
== '\0')
9597 fc
->col_type
[reg
] = DW_CFA_offset
;
9598 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9602 case DW_CFA_val_offset
:
9603 READ_ULEB (reg
, start
, block_end
);
9604 READ_ULEB (roffs
, start
, block_end
);
9605 if (reg
>= fc
->ncols
)
9606 reg_prefix
= bad_reg
;
9607 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9608 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9609 reg_prefix
, regname (reg
, 0),
9610 roffs
* fc
->data_factor
);
9611 if (*reg_prefix
== '\0')
9613 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9614 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9618 case DW_CFA_restore_extended
:
9619 READ_ULEB (reg
, start
, block_end
);
9620 if (reg
>= fc
->ncols
)
9621 reg_prefix
= bad_reg
;
9622 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9623 printf (" DW_CFA_restore_extended: %s%s\n",
9624 reg_prefix
, regname (reg
, 0));
9625 if (*reg_prefix
!= '\0')
9628 if (reg
>= cie
->ncols
9629 || cie
->col_type
[reg
] == DW_CFA_unreferenced
)
9631 fc
->col_type
[reg
] = DW_CFA_undefined
;
9632 fc
->col_offset
[reg
] = 0;
9636 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9637 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9641 case DW_CFA_undefined
:
9642 READ_ULEB (reg
, start
, block_end
);
9643 if (reg
>= fc
->ncols
)
9644 reg_prefix
= bad_reg
;
9645 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9646 printf (" DW_CFA_undefined: %s%s\n",
9647 reg_prefix
, regname (reg
, 0));
9648 if (*reg_prefix
== '\0')
9650 fc
->col_type
[reg
] = DW_CFA_undefined
;
9651 fc
->col_offset
[reg
] = 0;
9655 case DW_CFA_same_value
:
9656 READ_ULEB (reg
, start
, block_end
);
9657 if (reg
>= fc
->ncols
)
9658 reg_prefix
= bad_reg
;
9659 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9660 printf (" DW_CFA_same_value: %s%s\n",
9661 reg_prefix
, regname (reg
, 0));
9662 if (*reg_prefix
== '\0')
9664 fc
->col_type
[reg
] = DW_CFA_same_value
;
9665 fc
->col_offset
[reg
] = 0;
9669 case DW_CFA_register
:
9670 READ_ULEB (reg
, start
, block_end
);
9671 READ_ULEB (roffs
, start
, block_end
);
9672 if (reg
>= fc
->ncols
)
9673 reg_prefix
= bad_reg
;
9674 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9676 printf (" DW_CFA_register: %s%s in ",
9677 reg_prefix
, regname (reg
, 0));
9678 puts (regname (roffs
, 0));
9680 if (*reg_prefix
== '\0')
9682 fc
->col_type
[reg
] = DW_CFA_register
;
9683 fc
->col_offset
[reg
] = roffs
;
9687 case DW_CFA_remember_state
:
9688 if (! do_debug_frames_interp
)
9689 printf (" DW_CFA_remember_state\n");
9690 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9691 rs
->cfa_offset
= fc
->cfa_offset
;
9692 rs
->cfa_reg
= fc
->cfa_reg
;
9694 rs
->cfa_exp
= fc
->cfa_exp
;
9695 rs
->ncols
= fc
->ncols
;
9696 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9697 sizeof (* rs
->col_type
));
9698 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9699 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9700 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9701 rs
->next
= remembered_state
;
9702 remembered_state
= rs
;
9705 case DW_CFA_restore_state
:
9706 if (! do_debug_frames_interp
)
9707 printf (" DW_CFA_restore_state\n");
9708 rs
= remembered_state
;
9711 remembered_state
= rs
->next
;
9712 fc
->cfa_offset
= rs
->cfa_offset
;
9713 fc
->cfa_reg
= rs
->cfa_reg
;
9715 fc
->cfa_exp
= rs
->cfa_exp
;
9716 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9718 warn (_("Invalid column number in saved frame state\n"));
9722 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9723 memcpy (fc
->col_offset
, rs
->col_offset
,
9724 rs
->ncols
* sizeof (* rs
->col_offset
));
9725 free (rs
->col_type
);
9726 free (rs
->col_offset
);
9729 else if (do_debug_frames_interp
)
9730 printf ("Mismatched DW_CFA_restore_state\n");
9733 case DW_CFA_def_cfa
:
9734 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9735 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9737 if (! do_debug_frames_interp
)
9738 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9739 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9742 case DW_CFA_def_cfa_register
:
9743 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9745 if (! do_debug_frames_interp
)
9746 printf (" DW_CFA_def_cfa_register: %s\n",
9747 regname (fc
->cfa_reg
, 0));
9750 case DW_CFA_def_cfa_offset
:
9751 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9752 if (! do_debug_frames_interp
)
9753 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9757 if (! do_debug_frames_interp
)
9758 printf (" DW_CFA_nop\n");
9761 case DW_CFA_def_cfa_expression
:
9762 READ_ULEB (ul
, start
, block_end
);
9763 if (ul
> (size_t) (block_end
- start
))
9765 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9768 if (! do_debug_frames_interp
)
9770 printf (" DW_CFA_def_cfa_expression (");
9771 decode_location_expression (start
, eh_addr_size
, 0, -1,
9779 case DW_CFA_expression
:
9780 READ_ULEB (reg
, start
, block_end
);
9781 READ_ULEB (ul
, start
, block_end
);
9782 if (reg
>= fc
->ncols
)
9783 reg_prefix
= bad_reg
;
9784 /* PR 17512: file: 069-133014-0.006. */
9785 /* PR 17512: file: 98c02eb4. */
9786 if (ul
> (size_t) (block_end
- start
))
9788 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9791 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9793 printf (" DW_CFA_expression: %s%s (",
9794 reg_prefix
, regname (reg
, 0));
9795 decode_location_expression (start
, eh_addr_size
, 0, -1,
9799 if (*reg_prefix
== '\0')
9800 fc
->col_type
[reg
] = DW_CFA_expression
;
9804 case DW_CFA_val_expression
:
9805 READ_ULEB (reg
, start
, block_end
);
9806 READ_ULEB (ul
, start
, block_end
);
9807 if (reg
>= fc
->ncols
)
9808 reg_prefix
= bad_reg
;
9809 if (ul
> (size_t) (block_end
- start
))
9811 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9814 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9816 printf (" DW_CFA_val_expression: %s%s (",
9817 reg_prefix
, regname (reg
, 0));
9818 decode_location_expression (start
, eh_addr_size
, 0, -1,
9822 if (*reg_prefix
== '\0')
9823 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9827 case DW_CFA_offset_extended_sf
:
9828 READ_ULEB (reg
, start
, block_end
);
9829 READ_SLEB (l
, start
, block_end
);
9830 if (reg
>= fc
->ncols
)
9831 reg_prefix
= bad_reg
;
9832 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9833 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9834 reg_prefix
, regname (reg
, 0),
9835 (long)(l
* fc
->data_factor
));
9836 if (*reg_prefix
== '\0')
9838 fc
->col_type
[reg
] = DW_CFA_offset
;
9839 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9843 case DW_CFA_val_offset_sf
:
9844 READ_ULEB (reg
, start
, block_end
);
9845 READ_SLEB (l
, start
, block_end
);
9846 if (reg
>= fc
->ncols
)
9847 reg_prefix
= bad_reg
;
9848 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9849 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9850 reg_prefix
, regname (reg
, 0),
9851 (long)(l
* fc
->data_factor
));
9852 if (*reg_prefix
== '\0')
9854 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9855 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9859 case DW_CFA_def_cfa_sf
:
9860 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9861 READ_SLEB (l
, start
, block_end
);
9862 l
*= fc
->data_factor
;
9865 if (! do_debug_frames_interp
)
9866 printf (" DW_CFA_def_cfa_sf: %s ofs %ld\n",
9867 regname (fc
->cfa_reg
, 0), (long) l
);
9870 case DW_CFA_def_cfa_offset_sf
:
9871 READ_SLEB (l
, start
, block_end
);
9872 l
*= fc
->data_factor
;
9874 if (! do_debug_frames_interp
)
9875 printf (" DW_CFA_def_cfa_offset_sf: %ld\n", (long) l
);
9878 case DW_CFA_MIPS_advance_loc8
:
9879 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9880 if (do_debug_frames_interp
)
9881 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9883 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9884 (unsigned long) (ofs
* fc
->code_factor
),
9885 dwarf_vmatoa_1 (NULL
,
9886 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9888 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9891 case DW_CFA_GNU_window_save
:
9892 if (! do_debug_frames_interp
)
9893 printf (" DW_CFA_GNU_window_save\n");
9896 case DW_CFA_GNU_args_size
:
9897 READ_ULEB (ul
, start
, block_end
);
9898 if (! do_debug_frames_interp
)
9899 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9902 case DW_CFA_GNU_negative_offset_extended
:
9903 READ_ULEB (reg
, start
, block_end
);
9904 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_GNU_negative_offset_extended: %s%s at 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_offset
;
9915 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9920 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9921 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9923 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9928 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9929 if (do_debug_frames_interp
&& ! all_nops
)
9930 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9932 if (fde_fc
.col_type
!= NULL
)
9934 free (fde_fc
.col_type
);
9935 fde_fc
.col_type
= NULL
;
9937 if (fde_fc
.col_offset
!= NULL
)
9939 free (fde_fc
.col_offset
);
9940 fde_fc
.col_offset
= NULL
;
9944 eh_addr_size
= saved_eh_addr_size
;
9949 while (remembered_state
!= NULL
)
9951 rs
= remembered_state
;
9952 remembered_state
= rs
->next
;
9953 free (rs
->col_type
);
9954 free (rs
->col_offset
);
9955 rs
->next
= NULL
; /* Paranoia. */
9959 while (chunks
!= NULL
)
9963 free (rs
->col_type
);
9964 free (rs
->col_offset
);
9965 rs
->next
= NULL
; /* Paranoia. */
9969 while (forward_refs
!= NULL
)
9972 forward_refs
= rs
->next
;
9973 free (rs
->col_type
);
9974 free (rs
->col_offset
);
9975 rs
->next
= NULL
; /* Paranoia. */
9985 display_debug_names (struct dwarf_section
*section
, void *file
)
9987 unsigned char *hdrptr
= section
->start
;
9988 dwarf_vma unit_length
;
9989 unsigned char *unit_start
;
9990 const unsigned char *const section_end
= section
->start
+ section
->size
;
9991 unsigned char *unit_end
;
9993 introduce (section
, false);
9995 load_debug_section_with_follow (str
, file
);
9997 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9999 unsigned int offset_size
;
10000 uint16_t dwarf_version
, padding
;
10001 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
10002 uint64_t bucket_count
, name_count
, abbrev_table_size
;
10003 uint32_t augmentation_string_size
;
10005 bool augmentation_printable
;
10006 const char *augmentation_string
;
10009 unit_start
= hdrptr
;
10011 /* Get and check the length of the block. */
10012 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
10014 if (unit_length
== 0xffffffff)
10016 /* This section is 64-bit DWARF. */
10017 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10023 if (unit_length
> (size_t) (section_end
- hdrptr
)
10024 || unit_length
< 2 + 2 + 4 * 7)
10027 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
10029 (unsigned long) (unit_start
- section
->start
),
10030 dwarf_vmatoa ("x", unit_length
));
10033 unit_end
= hdrptr
+ unit_length
;
10035 /* Get and check the version number. */
10036 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10037 printf (_("Version %ld\n"), (long) dwarf_version
);
10039 /* Prior versions did not exist, and future versions may not be
10040 backwards compatible. */
10041 if (dwarf_version
!= 5)
10043 warn (_("Only DWARF version 5 .debug_names "
10044 "is currently supported.\n"));
10048 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10050 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10053 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10054 if (comp_unit_count
== 0)
10055 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10057 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10058 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10059 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10060 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10061 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10063 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10064 if (augmentation_string_size
% 4 != 0)
10066 warn (_("Augmentation string length %u must be rounded up "
10067 "to a multiple of 4 in .debug_names.\n"),
10068 augmentation_string_size
);
10069 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10071 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10074 printf (_("Augmentation string:"));
10076 augmentation_printable
= true;
10077 augmentation_string
= (const char *) hdrptr
;
10079 for (i
= 0; i
< augmentation_string_size
; i
++)
10083 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10084 printf (" %02x", uc
);
10086 if (uc
!= 0 && !ISPRINT (uc
))
10087 augmentation_printable
= false;
10090 if (augmentation_printable
)
10094 i
< augmentation_string_size
&& augmentation_string
[i
];
10096 putchar (augmentation_string
[i
]);
10101 printf (_("CU table:\n"));
10102 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10103 || total
> (size_t) (unit_end
- hdrptr
))
10105 for (i
= 0; i
< comp_unit_count
; i
++)
10107 uint64_t cu_offset
;
10109 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10110 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
10114 printf (_("TU table:\n"));
10115 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10116 || total
> (size_t) (unit_end
- hdrptr
))
10118 for (i
= 0; i
< local_type_unit_count
; i
++)
10120 uint64_t tu_offset
;
10122 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10123 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
10127 printf (_("Foreign TU table:\n"));
10128 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10129 || total
> (size_t) (unit_end
- hdrptr
))
10131 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10133 uint64_t signature
;
10135 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10136 printf (_("[%3u] "), i
);
10137 print_dwarf_vma (signature
, 8);
10142 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10143 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10144 + abbrev_table_size
);
10145 if (xtra
> (size_t) (unit_end
- hdrptr
))
10147 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
10148 "for unit 0x%lx in the debug_names\n"),
10150 (long) (unit_end
- unit_start
),
10151 (long) (unit_start
- section
->start
));
10154 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10155 hdrptr
+= bucket_count
* sizeof (uint32_t);
10156 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10157 hdrptr
+= name_count
* sizeof (uint32_t);
10158 unsigned char *const name_table_string_offsets
= hdrptr
;
10159 hdrptr
+= name_count
* offset_size
;
10160 unsigned char *const name_table_entry_offsets
= hdrptr
;
10161 hdrptr
+= name_count
* offset_size
;
10162 unsigned char *const abbrev_table
= hdrptr
;
10163 hdrptr
+= abbrev_table_size
;
10164 const unsigned char *const abbrev_table_end
= hdrptr
;
10165 unsigned char *const entry_pool
= hdrptr
;
10167 size_t buckets_filled
= 0;
10169 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10171 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10176 printf (ngettext ("Used %zu of %lu bucket.\n",
10177 "Used %zu of %lu buckets.\n",
10179 buckets_filled
, (unsigned long) bucket_count
);
10181 if (bucket_count
!= 0)
10183 uint32_t hash_prev
= 0;
10184 size_t hash_clash_count
= 0;
10185 size_t longest_clash
= 0;
10186 size_t this_length
= 0;
10188 for (hashi
= 0; hashi
< name_count
; hashi
++)
10190 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10194 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10196 ++hash_clash_count
;
10198 longest_clash
= MAX (longest_clash
, this_length
);
10203 hash_prev
= hash_this
;
10205 printf (_("Out of %lu items there are %zu bucket clashes"
10206 " (longest of %zu entries).\n"),
10207 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
10208 assert (name_count
== buckets_filled
+ hash_clash_count
);
10211 struct abbrev_lookup_entry
10213 dwarf_vma abbrev_tag
;
10214 unsigned char *abbrev_lookup_ptr
;
10216 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10217 size_t abbrev_lookup_used
= 0;
10218 size_t abbrev_lookup_allocated
= 0;
10220 unsigned char *abbrevptr
= abbrev_table
;
10223 dwarf_vma abbrev_tag
;
10225 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10226 if (abbrev_tag
== 0)
10228 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10230 abbrev_lookup_allocated
= MAX (0x100,
10231 abbrev_lookup_allocated
* 2);
10232 abbrev_lookup
= xrealloc (abbrev_lookup
,
10233 (abbrev_lookup_allocated
10234 * sizeof (*abbrev_lookup
)));
10236 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10237 struct abbrev_lookup_entry
*entry
;
10238 for (entry
= abbrev_lookup
;
10239 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10241 if (entry
->abbrev_tag
== abbrev_tag
)
10243 warn (_("Duplicate abbreviation tag %lu "
10244 "in unit 0x%lx in the debug_names\n"),
10245 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
10248 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10249 entry
->abbrev_tag
= abbrev_tag
;
10250 entry
->abbrev_lookup_ptr
= abbrevptr
;
10252 /* Skip DWARF tag. */
10253 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10256 dwarf_vma xindex
, form
;
10258 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10259 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10260 if (xindex
== 0 && form
== 0)
10265 printf (_("\nSymbol table:\n"));
10267 for (namei
= 0; namei
< name_count
; ++namei
)
10269 uint64_t string_offset
, entry_offset
;
10272 p
= name_table_string_offsets
+ namei
* offset_size
;
10273 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10274 p
= name_table_entry_offsets
+ namei
* offset_size
;
10275 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10277 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10278 fetch_indirect_string (string_offset
));
10280 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10282 /* We need to scan first whether there is a single or multiple
10283 entries. TAGNO is -2 for the first entry, it is -1 for the
10284 initial tag read of the second entry, then it becomes 0 for the
10285 first entry for real printing etc. */
10287 /* Initialize it due to a false compiler warning. */
10288 dwarf_vma second_abbrev_tag
= -1;
10291 dwarf_vma abbrev_tag
;
10292 dwarf_vma dwarf_tag
;
10293 const struct abbrev_lookup_entry
*entry
;
10295 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10298 second_abbrev_tag
= abbrev_tag
;
10300 entryptr
= entry_pool
+ entry_offset
;
10303 if (abbrev_tag
== 0)
10307 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10308 (unsigned long) abbrev_tag
);
10310 for (entry
= abbrev_lookup
;
10311 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10313 if (entry
->abbrev_tag
== abbrev_tag
)
10315 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10317 warn (_("Undefined abbreviation tag %lu "
10318 "in unit 0x%lx in the debug_names\n"),
10320 (long) (unit_start
- section
->start
));
10323 abbrevptr
= entry
->abbrev_lookup_ptr
;
10324 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10326 printf (" %s", get_TAG_name (dwarf_tag
));
10329 dwarf_vma xindex
, form
;
10331 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10332 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10333 if (xindex
== 0 && form
== 0)
10337 printf (" %s", get_IDX_name (xindex
));
10338 entryptr
= read_and_display_attr_value (0, form
, 0,
10339 unit_start
, entryptr
, unit_end
,
10341 dwarf_version
, NULL
,
10342 (tagno
< 0), section
,
10348 printf (_(" <no entries>"));
10352 free (abbrev_lookup
);
10359 display_debug_links (struct dwarf_section
* section
,
10360 void * file ATTRIBUTE_UNUSED
)
10362 const unsigned char * filename
;
10363 unsigned int filelen
;
10365 introduce (section
, false);
10367 /* The .gnu_debuglink section is formatted as:
10368 (c-string) Filename.
10369 (padding) If needed to reach a 4 byte boundary.
10370 (uint32_t) CRC32 value.
10372 The .gun_debugaltlink section is formatted as:
10373 (c-string) Filename.
10374 (binary) Build-ID. */
10376 filename
= section
->start
;
10377 filelen
= strnlen ((const char *) filename
, section
->size
);
10378 if (filelen
== section
->size
)
10380 warn (_("The debuglink filename is corrupt/missing\n"));
10384 printf (_(" Separate debug info file: %s\n"), filename
);
10386 if (startswith (section
->name
, ".gnu_debuglink"))
10388 unsigned int crc32
;
10389 unsigned int crc_offset
;
10391 crc_offset
= filelen
+ 1;
10392 crc_offset
= (crc_offset
+ 3) & ~3;
10393 if (crc_offset
+ 4 > section
->size
)
10395 warn (_("CRC offset missing/truncated\n"));
10399 crc32
= byte_get (filename
+ crc_offset
, 4);
10401 printf (_(" CRC value: %#x\n"), crc32
);
10403 if (crc_offset
+ 4 < section
->size
)
10405 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10406 (long)(section
->size
- (crc_offset
+ 4)));
10410 else /* startswith (section->name, ".gnu_debugaltlink") */
10412 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
10413 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
10414 bfd_size_type printed
;
10416 /* FIXME: Should we support smaller build-id notes ? */
10417 if (build_id_len
< 0x14)
10419 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
10423 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
10424 display_data (printed
, build_id
, build_id_len
);
10433 display_gdb_index (struct dwarf_section
*section
,
10434 void *file ATTRIBUTE_UNUSED
)
10436 unsigned char *start
= section
->start
;
10438 uint32_t cu_list_offset
, tu_list_offset
;
10439 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10440 unsigned int cu_list_elements
, tu_list_elements
;
10441 unsigned int address_table_elements
, symbol_table_slots
;
10442 unsigned char *cu_list
, *tu_list
;
10443 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10446 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10448 introduce (section
, false);
10450 if (section
->size
< 6 * sizeof (uint32_t))
10452 warn (_("Truncated header in the %s section.\n"), section
->name
);
10456 version
= byte_get_little_endian (start
, 4);
10457 printf (_("Version %ld\n"), (long) version
);
10459 /* Prior versions are obsolete, and future versions may not be
10460 backwards compatible. */
10461 if (version
< 3 || version
> 8)
10463 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10467 warn (_("The address table data in version 3 may be wrong.\n"));
10469 warn (_("Version 4 does not support case insensitive lookups.\n"));
10471 warn (_("Version 5 does not include inlined functions.\n"));
10473 warn (_("Version 6 does not include symbol attributes.\n"));
10474 /* Version 7 indices generated by Gold have bad type unit references,
10475 PR binutils/15021. But we don't know if the index was generated by
10476 Gold or not, so to avoid worrying users with gdb-generated indices
10477 we say nothing for version 7 here. */
10479 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10480 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10481 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10482 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10483 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10485 if (cu_list_offset
> section
->size
10486 || tu_list_offset
> section
->size
10487 || address_table_offset
> section
->size
10488 || symbol_table_offset
> section
->size
10489 || constant_pool_offset
> section
->size
10490 || tu_list_offset
< cu_list_offset
10491 || address_table_offset
< tu_list_offset
10492 || symbol_table_offset
< address_table_offset
10493 || constant_pool_offset
< symbol_table_offset
)
10495 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10499 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10500 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10501 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10502 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10504 cu_list
= start
+ cu_list_offset
;
10505 tu_list
= start
+ tu_list_offset
;
10506 address_table
= start
+ address_table_offset
;
10507 symbol_table
= start
+ symbol_table_offset
;
10508 constant_pool
= start
+ constant_pool_offset
;
10510 printf (_("\nCU table:\n"));
10511 for (i
= 0; i
< cu_list_elements
; i
++)
10513 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10514 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10516 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
,
10517 (unsigned long) cu_offset
,
10518 (unsigned long) (cu_offset
+ cu_length
- 1));
10521 printf (_("\nTU table:\n"));
10522 for (i
= 0; i
< tu_list_elements
; i
++)
10524 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10525 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10526 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10528 printf (_("[%3u] 0x%lx 0x%lx "), i
,
10529 (unsigned long) tu_offset
,
10530 (unsigned long) type_offset
);
10531 print_dwarf_vma (signature
, 8);
10535 printf (_("\nAddress table:\n"));
10536 for (i
= 0; i
< address_table_elements
; i
++)
10538 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10539 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10540 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 20 + 16, 4);
10542 print_dwarf_vma (low
, 8);
10543 print_dwarf_vma (high
, 8);
10544 printf (_("%lu\n"), (unsigned long) cu_index
);
10547 printf (_("\nSymbol table:\n"));
10548 for (i
= 0; i
< symbol_table_slots
; ++i
)
10550 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10551 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10552 uint32_t num_cus
, cu
;
10554 if (name_offset
!= 0
10555 || cu_vector_offset
!= 0)
10559 /* PR 17531: file: 5b7b07ad. */
10560 if (name_offset
>= section
->size
- constant_pool_offset
)
10562 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10563 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10567 printf ("[%3u] %.*s:", i
,
10568 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10569 constant_pool
+ name_offset
);
10571 if (section
->size
- constant_pool_offset
< 4
10572 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10574 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10575 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10576 cu_vector_offset
, i
);
10580 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10582 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10583 + cu_vector_offset
+ 4))
10585 printf ("<invalid number of CUs: %d>\n", num_cus
);
10586 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10594 for (j
= 0; j
< num_cus
; ++j
)
10597 gdb_index_symbol_kind kind
;
10599 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10600 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10601 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10602 cu
= GDB_INDEX_CU_VALUE (cu
);
10603 /* Convert to TU number if it's for a type unit. */
10604 if (cu
>= cu_list_elements
/ 2)
10605 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10606 (unsigned long) (cu
- cu_list_elements
/ 2));
10608 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10610 printf (" [%s, %s]",
10611 is_static
? _("static") : _("global"),
10612 get_gdb_index_symbol_kind_name (kind
));
10624 /* Pre-allocate enough space for the CU/TU sets needed. */
10627 prealloc_cu_tu_list (unsigned int nshndx
)
10629 if (shndx_pool
== NULL
)
10631 shndx_pool_size
= nshndx
;
10632 shndx_pool_used
= 0;
10633 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10634 sizeof (unsigned int));
10638 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10639 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10640 sizeof (unsigned int));
10645 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10647 if (shndx_pool_used
>= shndx_pool_size
)
10649 error (_("Internal error: out of space in the shndx pool.\n"));
10652 shndx_pool
[shndx_pool_used
++] = shndx
;
10656 end_cu_tu_entry (void)
10658 if (shndx_pool_used
>= shndx_pool_size
)
10660 error (_("Internal error: out of space in the shndx pool.\n"));
10663 shndx_pool
[shndx_pool_used
++] = 0;
10666 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10668 static const char *
10669 get_DW_SECT_short_name (unsigned int dw_sect
)
10671 static char buf
[16];
10677 case DW_SECT_TYPES
:
10679 case DW_SECT_ABBREV
:
10685 case DW_SECT_STR_OFFSETS
:
10687 case DW_SECT_MACINFO
:
10689 case DW_SECT_MACRO
:
10695 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10699 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10700 These sections are extensions for Fission.
10701 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10704 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10706 unsigned char *phdr
= section
->start
;
10707 unsigned char *limit
= phdr
+ section
->size
;
10708 unsigned char *phash
;
10709 unsigned char *pindex
;
10710 unsigned char *ppool
;
10711 unsigned int version
;
10712 unsigned int ncols
= 0;
10713 unsigned int nused
;
10714 unsigned int nslots
;
10717 dwarf_vma signature
;
10720 /* PR 17512: file: 002-168123-0.004. */
10723 warn (_("Section %s is empty\n"), section
->name
);
10726 /* PR 17512: file: 002-376-0.004. */
10727 if (section
->size
< 24)
10729 warn (_("Section %s is too small to contain a CU/TU header\n"),
10735 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10737 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10738 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10739 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10741 pindex
= phash
+ (size_t) nslots
* 8;
10742 ppool
= pindex
+ (size_t) nslots
* 4;
10746 introduce (section
, false);
10748 printf (_(" Version: %u\n"), version
);
10750 printf (_(" Number of columns: %u\n"), ncols
);
10751 printf (_(" Number of used entries: %u\n"), nused
);
10752 printf (_(" Number of slots: %u\n\n"), nslots
);
10755 /* PR 17531: file: 45d69832. */
10756 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10757 || total
> (size_t) (limit
- phash
))
10759 warn (ngettext ("Section %s is too small for %u slot\n",
10760 "Section %s is too small for %u slots\n",
10762 section
->name
, nslots
);
10769 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10770 for (i
= 0; i
< nslots
; i
++)
10772 unsigned char *shndx_list
;
10773 unsigned int shndx
;
10775 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10776 if (signature
!= 0)
10778 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10779 shndx_list
= ppool
+ j
* 4;
10780 /* PR 17531: file: 705e010d. */
10781 if (shndx_list
< ppool
)
10783 warn (_("Section index pool located before start of section\n"));
10788 printf (_(" [%3d] Signature: 0x%s Sections: "),
10789 i
, dwarf_vmatoa ("x", signature
));
10792 if (shndx_list
>= limit
)
10794 warn (_("Section %s too small for shndx pool\n"),
10798 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10802 printf (" %d", shndx
);
10804 add_shndx_to_cu_tu_entry (shndx
);
10810 end_cu_tu_entry ();
10816 else if (version
== 2)
10819 unsigned int dw_sect
;
10820 unsigned char *ph
= phash
;
10821 unsigned char *pi
= pindex
;
10822 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10823 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10825 struct cu_tu_set
*this_set
= NULL
;
10827 unsigned char *prow
;
10830 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10832 /* PR 17531: file: 0dd159bf.
10833 Check for integer overflow (can occur when size_t is 32-bit)
10834 with overlarge ncols or nused values. */
10836 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10837 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10838 || total
> (size_t) (limit
- ppool
))
10840 warn (_("Section %s too small for offset and size tables\n"),
10847 printf (_(" Offset table\n"));
10848 printf (" slot %-16s ",
10849 is_tu_index
? _("signature") : _("dwo_id"));
10856 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10857 this_set
= tu_sets
;
10862 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10863 this_set
= cu_sets
;
10869 for (j
= 0; j
< ncols
; j
++)
10871 unsigned char *p
= ppool
+ j
* 4;
10872 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10873 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10878 for (i
= 0; i
< nslots
; i
++)
10880 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10882 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10885 /* PR 17531: file: a05f6ab3. */
10888 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10895 size_t num_copy
= sizeof (uint64_t);
10897 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10900 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10902 printf (_(" [%3d] 0x%s"),
10903 i
, dwarf_vmatoa ("x", signature
));
10904 for (j
= 0; j
< ncols
; j
++)
10906 unsigned char *p
= prow
+ j
* 4;
10907 SAFE_BYTE_GET (val
, p
, 4, limit
);
10909 printf (" %8d", val
);
10913 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10915 /* PR 17531: file: 10796eb3. */
10916 if (dw_sect
>= DW_SECT_MAX
)
10917 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10919 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10935 printf (_(" Size table\n"));
10936 printf (" slot %-16s ",
10937 is_tu_index
? _("signature") : _("dwo_id"));
10940 for (j
= 0; j
< ncols
; j
++)
10942 unsigned char *p
= ppool
+ j
* 4;
10943 SAFE_BYTE_GET (val
, p
, 4, limit
);
10945 printf (" %8s", get_DW_SECT_short_name (val
));
10951 for (i
= 0; i
< nslots
; i
++)
10953 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10955 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10958 prow
= psizes
+ (row
- 1) * ncols
* 4;
10961 printf (_(" [%3d] 0x%s"),
10962 i
, dwarf_vmatoa ("x", signature
));
10964 for (j
= 0; j
< ncols
; j
++)
10966 unsigned char *p
= prow
+ j
* 4;
10968 /* PR 28645: Check for overflow. Since we do not know how
10969 many populated rows there will be, we cannot just
10970 perform a single check at the start of this function. */
10971 if (p
> (limit
- 4))
10975 warn (_("Too many rows/columns in DWARF index section %s\n"),
10980 SAFE_BYTE_GET (val
, p
, 4, limit
);
10983 printf (" %8d", val
);
10987 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10988 if (dw_sect
>= DW_SECT_MAX
)
10989 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10991 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
11003 else if (do_display
)
11004 printf (_(" Unsupported version (%d)\n"), version
);
11012 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
11014 /* Load the CU and TU indexes if present. This will build a list of
11015 section sets that we can use to associate a .debug_info.dwo section
11016 with its associated .debug_abbrev.dwo section in a .dwp file. */
11019 load_cu_tu_indexes (void *file
)
11021 /* If we have already loaded (or tried to load) the CU and TU indexes
11022 then do not bother to repeat the task. */
11023 if (cu_tu_indexes_read
== -1)
11025 cu_tu_indexes_read
= true;
11027 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11028 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11029 cu_tu_indexes_read
= false;
11031 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11032 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11033 cu_tu_indexes_read
= false;
11036 return (bool) cu_tu_indexes_read
;
11039 /* Find the set of sections that includes section SHNDX. */
11042 find_cu_tu_set (void *file
, unsigned int shndx
)
11046 if (! load_cu_tu_indexes (file
))
11049 /* Find SHNDX in the shndx pool. */
11050 for (i
= 0; i
< shndx_pool_used
; i
++)
11051 if (shndx_pool
[i
] == shndx
)
11054 if (i
>= shndx_pool_used
)
11057 /* Now backup to find the first entry in the set. */
11058 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11061 return shndx_pool
+ i
;
11064 /* Display a .debug_cu_index or .debug_tu_index section. */
11067 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11069 return process_cu_tu_index (section
, 1);
11073 display_debug_not_supported (struct dwarf_section
*section
,
11074 void *file ATTRIBUTE_UNUSED
)
11076 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11082 /* Like malloc, but takes two parameters like calloc.
11083 Verifies that the first parameter is not too large.
11084 Note: does *not* initialise the allocated memory to zero. */
11087 cmalloc (size_t nmemb
, size_t size
)
11089 /* Check for overflow. */
11090 if (nmemb
>= ~(size_t) 0 / size
)
11093 return xmalloc (nmemb
* size
);
11096 /* Like xmalloc, but takes two parameters like calloc.
11097 Verifies that the first parameter is not too large.
11098 Note: does *not* initialise the allocated memory to zero. */
11101 xcmalloc (size_t nmemb
, size_t size
)
11103 /* Check for overflow. */
11104 if (nmemb
>= ~(size_t) 0 / size
)
11107 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
11112 return xmalloc (nmemb
* size
);
11115 /* Like xrealloc, but takes three parameters.
11116 Verifies that the second parameter is not too large.
11117 Note: does *not* initialise any new memory to zero. */
11120 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
11122 /* Check for overflow. */
11123 if (nmemb
>= ~(size_t) 0 / size
)
11125 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
11130 return xrealloc (ptr
, nmemb
* size
);
11133 /* Like xcalloc, but verifies that the first parameter is not too large. */
11136 xcalloc2 (size_t nmemb
, size_t size
)
11138 /* Check for overflow. */
11139 if (nmemb
>= ~(size_t) 0 / size
)
11141 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
11146 return xcalloc (nmemb
, size
);
11149 static unsigned long
11150 calc_gnu_debuglink_crc32 (unsigned long crc
,
11151 const unsigned char * buf
,
11154 static const unsigned long crc32_table
[256] =
11156 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11157 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11158 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11159 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11160 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11161 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11162 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11163 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11164 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11165 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11166 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11167 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11168 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11169 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11170 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11171 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11172 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11173 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11174 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11175 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11176 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11177 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11178 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11179 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11180 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11181 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11182 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11183 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11184 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11185 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11186 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11187 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11188 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11189 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11190 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11191 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11192 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11193 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11194 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11195 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11196 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11197 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11198 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11199 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11200 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11201 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11202 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11203 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11204 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11205 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11206 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11209 const unsigned char *end
;
11211 crc
= ~crc
& 0xffffffff;
11212 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11213 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11214 return ~crc
& 0xffffffff;
11217 typedef bool (*check_func_type
) (const char *, void *);
11218 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11221 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11223 static unsigned char buffer
[8 * 1024];
11225 bfd_size_type count
;
11226 unsigned long crc
= 0;
11229 sep_data
= open_debug_file (pathname
);
11230 if (sep_data
== NULL
)
11233 /* Yes - we are opening the file twice... */
11234 f
= fopen (pathname
, "rb");
11237 /* Paranoia: This should never happen. */
11238 close_debug_file (sep_data
);
11239 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11243 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11244 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11248 if (crc
!= * (unsigned long *) crc_pointer
)
11250 close_debug_file (sep_data
);
11251 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11259 static const char *
11260 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11263 unsigned int crc_offset
;
11264 unsigned long * crc32
= (unsigned long *) data
;
11266 /* The name is first.
11267 The CRC value is stored after the filename, aligned up to 4 bytes. */
11268 name
= (const char *) section
->start
;
11270 crc_offset
= strnlen (name
, section
->size
) + 1;
11271 if (crc_offset
== 1)
11273 crc_offset
= (crc_offset
+ 3) & ~3;
11274 if (crc_offset
+ 4 > section
->size
)
11277 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11282 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11284 void * sep_data
= open_debug_file (filename
);
11286 if (sep_data
== NULL
)
11289 /* FIXME: We should now extract the build-id in the separate file
11295 typedef struct build_id_data
11298 const unsigned char * data
;
11301 static const char *
11302 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11305 bfd_size_type namelen
;
11306 bfd_size_type id_len
;
11307 Build_id_data
* build_id_data
;
11309 /* The name is first.
11310 The build-id follows immediately, with no padding, up to the section's end. */
11312 name
= (const char *) section
->start
;
11313 namelen
= strnlen (name
, section
->size
) + 1;
11316 if (namelen
>= section
->size
)
11319 id_len
= section
->size
- namelen
;
11323 build_id_data
= (Build_id_data
*) data
;
11324 build_id_data
->len
= id_len
;
11325 build_id_data
->data
= section
->start
+ namelen
;
11331 add_separate_debug_file (const char * filename
, void * handle
)
11333 separate_info
* i
= xmalloc (sizeof * i
);
11335 i
->filename
= filename
;
11336 i
->handle
= handle
;
11337 i
->next
= first_separate_info
;
11338 first_separate_info
= i
;
11341 #if HAVE_LIBDEBUGINFOD
11342 /* Query debuginfod servers for the target debuglink or debugaltlink
11343 file. If successful, store the path of the file in filename and
11344 return TRUE, otherwise return FALSE. */
11347 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11351 size_t build_id_len
;
11352 unsigned char * build_id
;
11354 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11356 /* Get the build-id of file. */
11357 build_id
= get_build_id (file
);
11360 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11362 /* Get the build-id of the debugaltlink file. */
11363 unsigned int filelen
;
11365 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11366 if (filelen
== section
->size
)
11367 /* Corrupt debugaltlink. */
11370 build_id
= section
->start
+ filelen
+ 1;
11371 build_id_len
= section
->size
- (filelen
+ 1);
11373 if (build_id_len
== 0)
11382 debuginfod_client
* client
;
11384 client
= debuginfod_begin ();
11385 if (client
== NULL
)
11388 /* Query debuginfod servers for the target file. If found its path
11389 will be stored in filename. */
11390 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11391 debuginfod_end (client
);
11393 /* Only free build_id if we allocated space for a hex string
11394 in get_build_id (). */
11395 if (build_id_len
== 0)
11400 /* File successfully retrieved. Close fd since we want to
11401 use open_debug_file () on filename instead. */
11409 #endif /* HAVE_LIBDEBUGINFOD */
11412 load_separate_debug_info (const char * main_filename
,
11413 struct dwarf_section
* xlink
,
11414 parse_func_type parse_func
,
11415 check_func_type check_func
,
11417 void * file ATTRIBUTE_UNUSED
)
11419 const char * separate_filename
;
11420 char * debug_filename
;
11422 size_t canon_dirlen
;
11424 char * canon_filename
;
11425 char * canon_debug_filename
;
11428 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11430 warn (_("Corrupt debuglink section: %s\n"),
11431 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11435 /* Attempt to locate the separate file.
11436 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11438 canon_filename
= lrealpath (main_filename
);
11439 canon_dir
= xstrdup (canon_filename
);
11441 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11442 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11444 canon_dir
[canon_dirlen
] = '\0';
11447 #define DEBUGDIR "/lib/debug"
11449 #ifndef EXTRA_DEBUG_ROOT1
11450 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11452 #ifndef EXTRA_DEBUG_ROOT2
11453 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11456 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11458 + strlen (".debug/")
11459 #ifdef EXTRA_DEBUG_ROOT1
11460 + strlen (EXTRA_DEBUG_ROOT1
)
11462 #ifdef EXTRA_DEBUG_ROOT2
11463 + strlen (EXTRA_DEBUG_ROOT2
)
11465 + strlen (separate_filename
)
11467 if (debug_filename
== NULL
)
11469 warn (_("Out of memory"));
11471 free (canon_filename
);
11475 /* First try in the current directory. */
11476 sprintf (debug_filename
, "%s", separate_filename
);
11477 if (check_func (debug_filename
, func_data
))
11480 /* Then try in a subdirectory called .debug. */
11481 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11482 if (check_func (debug_filename
, func_data
))
11485 /* Then try in the same directory as the original file. */
11486 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11487 if (check_func (debug_filename
, func_data
))
11490 /* And the .debug subdirectory of that directory. */
11491 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11492 if (check_func (debug_filename
, func_data
))
11495 #ifdef EXTRA_DEBUG_ROOT1
11496 /* Try the first extra debug file root. */
11497 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11498 if (check_func (debug_filename
, func_data
))
11501 /* Try the first extra debug file root. */
11502 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11503 if (check_func (debug_filename
, func_data
))
11507 #ifdef EXTRA_DEBUG_ROOT2
11508 /* Try the second extra debug file root. */
11509 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11510 if (check_func (debug_filename
, func_data
))
11514 /* Then try in the global debug_filename directory. */
11515 strcpy (debug_filename
, DEBUGDIR
);
11516 dirlen
= strlen (DEBUGDIR
) - 1;
11517 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11518 strcat (debug_filename
, "/");
11519 strcat (debug_filename
, (const char *) separate_filename
);
11521 if (check_func (debug_filename
, func_data
))
11524 #if HAVE_LIBDEBUGINFOD
11526 char * tmp_filename
;
11529 && debuginfod_fetch_separate_debug_info (xlink
,
11533 /* File successfully downloaded from server, replace
11534 debug_filename with the file's path. */
11535 free (debug_filename
);
11536 debug_filename
= tmp_filename
;
11542 if (do_debug_links
)
11544 /* Failed to find the file. */
11545 warn (_("could not find separate debug file '%s'\n"),
11546 separate_filename
);
11547 warn (_("tried: %s\n"), debug_filename
);
11549 #ifdef EXTRA_DEBUG_ROOT2
11550 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11551 separate_filename
);
11552 warn (_("tried: %s\n"), debug_filename
);
11555 #ifdef EXTRA_DEBUG_ROOT1
11556 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11557 canon_dir
, separate_filename
);
11558 warn (_("tried: %s\n"), debug_filename
);
11560 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11561 separate_filename
);
11562 warn (_("tried: %s\n"), debug_filename
);
11565 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11566 separate_filename
);
11567 warn (_("tried: %s\n"), debug_filename
);
11569 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11570 warn (_("tried: %s\n"), debug_filename
);
11572 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11573 warn (_("tried: %s\n"), debug_filename
);
11575 sprintf (debug_filename
, "%s", separate_filename
);
11576 warn (_("tried: %s\n"), debug_filename
);
11578 #if HAVE_LIBDEBUGINFOD
11579 if (use_debuginfod
)
11581 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11586 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11592 free (debug_filename
);
11593 free (canon_filename
);
11599 canon_debug_filename
= lrealpath (debug_filename
);
11600 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11601 free (canon_filename
);
11602 free (canon_debug_filename
);
11605 free (debug_filename
);
11609 void * debug_handle
;
11611 /* Now open the file.... */
11612 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11614 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11615 free (debug_filename
);
11619 /* FIXME: We do not check to see if there are any other separate debug info
11620 files that would also match. */
11622 if (do_debug_links
)
11623 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11624 add_separate_debug_file (debug_filename
, debug_handle
);
11626 /* Do not free debug_filename - it might be referenced inside
11627 the structure returned by open_debug_file(). */
11628 return debug_handle
;
11631 /* Attempt to load a separate dwarf object file. */
11634 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11636 char * separate_filename
;
11637 void * separate_handle
;
11639 if (IS_ABSOLUTE_PATH (name
))
11640 separate_filename
= strdup (name
);
11642 /* FIXME: Skip adding / if dwo_dir ends in /. */
11643 separate_filename
= concat (dir
, "/", name
, NULL
);
11644 if (separate_filename
== NULL
)
11646 warn (_("Out of memory allocating dwo filename\n"));
11650 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11652 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11653 free (separate_filename
);
11657 /* FIXME: We should check the dwo_id. */
11659 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11661 add_separate_debug_file (separate_filename
, separate_handle
);
11662 /* Note - separate_filename will be freed in free_debug_memory(). */
11663 return separate_handle
;
11667 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11669 char * f
= filename
;
11671 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11674 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11675 strcpy (f
, ".debug");
11677 return open_debug_file (filename
);
11680 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11683 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11685 if (! load_debug_section (note_gnu_build_id
, main_file
))
11686 return; /* No .note.gnu.build-id section. */
11688 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11689 if (section
== NULL
)
11691 warn (_("Unable to load the .note.gnu.build-id section\n"));
11695 if (section
->start
== NULL
|| section
->size
< 0x18)
11697 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11701 /* In theory we should extract the contents of the section into
11702 a note structure and then check the fields. For now though
11703 just use hard coded offsets instead:
11705 Field Bytes Contents
11708 Type 8..11 3 (NT_GNU_BUILD_ID)
11712 /* FIXME: Check the name size, name and type fields. */
11714 unsigned long build_id_size
;
11715 build_id_size
= byte_get (section
->start
+ 4, 4);
11716 if (build_id_size
< 8)
11718 warn (_(".note.gnu.build-id data size is too small\n"));
11722 if (build_id_size
> (section
->size
- 16))
11724 warn (_(".note.gnu.build-id data size is too bug\n"));
11729 filename
= xmalloc (strlen (".build-id/")
11730 + build_id_size
* 2 + 2
11731 + strlen (".debug")
11732 /* The next string should be the same as the longest
11733 name found in the prefixes[] array below. */
11734 + strlen ("/usrlib64/debug/usr")
11738 static const char * prefixes
[] =
11743 "/usr/lib/debug/usr/",
11744 "/usr/lib64/debug/",
11745 "/usr/lib64/debug/usr"
11747 long unsigned int i
;
11749 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11751 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11752 section
->start
+ 16, build_id_size
);
11753 if (handle
!= NULL
)
11756 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11757 if (handle
== NULL
)
11759 /* Failed to find a debug file associated with the build-id.
11760 This is not an error however, rather it just means that
11761 the debug info has probably not been loaded on the system,
11762 or that another method is being used to link to the debug
11768 add_separate_debug_file (filename
, handle
);
11771 /* Try to load a debug file pointed to by the .debug_sup section. */
11774 load_debug_sup_file (const char * main_filename
, void * file
)
11776 if (! load_debug_section (debug_sup
, file
))
11777 return; /* No .debug_sup section. */
11779 struct dwarf_section
* section
;
11780 section
= & debug_displays
[debug_sup
].section
;
11781 assert (section
!= NULL
);
11783 if (section
->start
== NULL
|| section
->size
< 5)
11785 warn (_(".debug_sup section is corrupt/empty\n"));
11789 if (section
->start
[2] != 0)
11790 return; /* This is a supplementary file. */
11792 const char * filename
= (const char *) section
->start
+ 3;
11793 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11795 warn (_("filename in .debug_sup section is corrupt\n"));
11799 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11804 new_len
= asprintf (& new_name
, "%.*s/%s",
11805 (int) (strrchr (main_filename
, '/') - main_filename
),
11810 warn (_("unable to construct path for supplementary debug file"));
11815 filename
= new_name
;
11819 /* PR 27796: Make sure that we pass a filename that can be free'd to
11820 add_separate_debug_file(). */
11821 filename
= strdup (filename
);
11822 if (filename
== NULL
)
11824 warn (_("out of memory constructing filename for .debug_sup link\n"));
11829 void * handle
= open_debug_file (filename
);
11830 if (handle
== NULL
)
11832 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11833 free ((void *) filename
);
11837 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11839 /* FIXME: Compare the checksums, if present. */
11840 add_separate_debug_file (filename
, handle
);
11843 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11844 Recursively check the loaded files for more of these sections.
11845 Also follow any links in .debug_sup sections.
11846 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11849 check_for_and_load_links (void * file
, const char * filename
)
11851 void * handle
= NULL
;
11853 if (load_debug_section (gnu_debugaltlink
, file
))
11855 Build_id_data build_id_data
;
11857 handle
= load_separate_debug_info (filename
,
11858 & debug_displays
[gnu_debugaltlink
].section
,
11859 parse_gnu_debugaltlink
,
11860 check_gnu_debugaltlink
,
11865 assert (handle
== first_separate_info
->handle
);
11866 check_for_and_load_links (first_separate_info
->handle
,
11867 first_separate_info
->filename
);
11871 if (load_debug_section (gnu_debuglink
, file
))
11873 unsigned long crc32
;
11875 handle
= load_separate_debug_info (filename
,
11876 & debug_displays
[gnu_debuglink
].section
,
11877 parse_gnu_debuglink
,
11878 check_gnu_debuglink
,
11883 assert (handle
== first_separate_info
->handle
);
11884 check_for_and_load_links (first_separate_info
->handle
,
11885 first_separate_info
->filename
);
11889 load_debug_sup_file (filename
, file
);
11891 load_build_id_debug_file (filename
, file
);
11894 /* Load the separate debug info file(s) attached to FILE, if any exist.
11895 Returns TRUE if any were found, FALSE otherwise.
11896 If TRUE is returned then the linked list starting at first_separate_info
11897 will be populated with open file handles. */
11900 load_separate_debug_files (void * file
, const char * filename
)
11902 /* Skip this operation if we are not interested in debug links. */
11903 if (! do_follow_links
&& ! do_debug_links
)
11906 /* See if there are any dwo links. */
11907 if (load_debug_section (str
, file
)
11908 && load_debug_section (abbrev
, file
)
11909 && load_debug_section (info
, file
))
11911 /* Load the .debug_addr section, if it exists. */
11912 load_debug_section (debug_addr
, file
);
11916 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11919 bool introduced
= false;
11921 const char *dir
= NULL
;
11922 const char *id
= NULL
;
11923 const char *name
= NULL
;
11925 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11927 /* Accumulate NAME, DIR and ID fields. */
11928 switch (dwinfo
->type
)
11932 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11933 name
= dwinfo
->value
;
11937 /* There can be multiple DW_AT_comp_dir entries in a CU,
11938 so do not complain. */
11939 dir
= dwinfo
->value
;
11944 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11945 id
= dwinfo
->value
;
11949 error (_("Unexpected DWO INFO type"));
11953 /* If we have reached the end of our list, or we are changing
11954 CUs, then display the information that we have accumulated
11957 && (dwinfo
->next
== NULL
11958 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11960 if (do_debug_links
)
11964 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11965 debug_displays
[info
].section
.uncompressed_name
);
11969 printf (_(" Name: %s\n"), name
);
11970 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11972 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11974 printf (_(" ID: <not specified>\n"));
11978 if (do_follow_links
)
11979 load_dwo_file (filename
, name
, dir
, id
);
11981 name
= dir
= id
= NULL
;
11987 if (! do_follow_links
)
11988 /* The other debug links will be displayed by display_debug_links()
11989 so we do not need to do any further processing here. */
11992 /* FIXME: We do not check for the presence of both link sections in the same file. */
11993 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11994 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11996 check_for_and_load_links (file
, filename
);
11997 if (first_separate_info
!= NULL
)
12000 do_follow_links
= 0;
12005 free_debug_memory (void)
12009 free_all_abbrevs ();
12011 free (cu_abbrev_map
);
12012 cu_abbrev_map
= NULL
;
12013 next_free_abbrev_map_entry
= 0;
12017 shndx_pool_size
= 0;
12018 shndx_pool_used
= 0;
12026 memset (level_type_signed
, 0, sizeof level_type_signed
);
12027 cu_tu_indexes_read
= -1;
12029 for (i
= 0; i
< max
; i
++)
12030 free_debug_section ((enum dwarf_section_display_enum
) i
);
12032 if (debug_information
!= NULL
)
12034 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12036 if (debug_information
[i
].max_loc_offsets
)
12038 free (debug_information
[i
].loc_offsets
);
12039 free (debug_information
[i
].have_frame_base
);
12041 if (debug_information
[i
].max_range_lists
)
12042 free (debug_information
[i
].range_lists
);
12044 free (debug_information
);
12045 debug_information
= NULL
;
12046 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12050 separate_info
* next
;
12052 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12054 close_debug_file (d
->handle
);
12055 free ((void *) d
->filename
);
12059 first_separate_info
= NULL
;
12067 const char *option
;
12070 } debug_dump_long_opts
;
12072 static const debug_dump_long_opts debug_option_table
[] =
12074 { 'A', "addr", &do_debug_addr
, 1 },
12075 { 'a', "abbrev", &do_debug_abbrevs
, 1 },
12076 { 'c', "cu_index", &do_debug_cu_index
, 1 },
12077 #ifdef HAVE_LIBDEBUGINFOD
12078 { 'D', "use-debuginfod", &use_debuginfod
, 1 },
12079 { 'E', "do-not-use-debuginfod", &use_debuginfod
, 0 },
12081 { 'F', "frames-interp", &do_debug_frames_interp
, 1 },
12082 { 'f', "frames", &do_debug_frames
, 1 },
12083 { 'g', "gdb_index", &do_gdb_index
, 1 },
12084 { 'i', "info", &do_debug_info
, 1 },
12085 { 'K', "follow-links", &do_follow_links
, 1 },
12086 { 'k', "links", &do_debug_links
, 1 },
12087 { 'L', "decodedline", &do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12088 { 'l', "rawline", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12089 /* For compatibility with earlier versions of readelf. */
12090 { 'l', "line", &do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12091 { 'm', "macro", &do_debug_macinfo
, 1 },
12092 { 'N', "no-follow-links", &do_follow_links
, 0 },
12093 { 'O', "str-offsets", &do_debug_str_offsets
, 1 },
12094 { 'o', "loc", &do_debug_loc
, 1 },
12095 { 'p', "pubnames", &do_debug_pubnames
, 1 },
12096 { 'R', "Ranges", &do_debug_ranges
, 1 },
12097 { 'r', "aranges", &do_debug_aranges
, 1 },
12098 /* For compatibility with earlier versions of readelf. */
12099 { 'r', "ranges", &do_debug_aranges
, 1 },
12100 { 's', "str", &do_debug_str
, 1 },
12101 { 'T', "trace_aranges", &do_trace_aranges
, 1 },
12102 { 't', "pubtypes", &do_debug_pubtypes
, 1 },
12103 { 'U', "trace_info", &do_trace_info
, 1 },
12104 { 'u', "trace_abbrev", &do_trace_abbrevs
, 1 },
12105 { 0, NULL
, NULL
, 0 }
12108 /* Enable display of specific DWARF sections as determined by the comma
12109 separated strings in NAMES. Returns non-zero if any displaying was
12113 dwarf_select_sections_by_names (const char *names
)
12121 const debug_dump_long_opts
*entry
;
12123 for (entry
= debug_option_table
; entry
->option
; entry
++)
12125 size_t len
= strlen (entry
->option
);
12127 if (strncmp (p
, entry
->option
, len
) == 0
12128 && (p
[len
] == ',' || p
[len
] == '\0'))
12130 * entry
->variable
= entry
->val
;
12131 result
|= entry
->val
;
12138 if (entry
->option
== NULL
)
12140 warn (_("Unrecognized debug option '%s'\n"), p
);
12141 p
= strchr (p
, ',');
12150 /* The --debug-dump=frames-interp option also enables the
12151 --debug-dump=frames option. */
12152 if (do_debug_frames_interp
)
12153 do_debug_frames
= 1;
12158 /* Enable display of specific DWARF sections as determined by the characters
12159 in LETTERS. Returns non-zero if any displaying was enabled. */
12162 dwarf_select_sections_by_letters (const char *letters
)
12168 const debug_dump_long_opts
*entry
;
12170 for (entry
= debug_option_table
; entry
->letter
; entry
++)
12172 if (entry
->letter
== * letters
)
12174 * entry
->variable
|= entry
->val
;
12175 result
|= entry
->val
;
12180 if (entry
->letter
== 0)
12181 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12186 /* The --debug-dump=frames-interp option also enables the
12187 --debug-dump=frames option. */
12188 if (do_debug_frames_interp
)
12189 do_debug_frames
= 1;
12195 dwarf_select_sections_all (void)
12198 do_debug_abbrevs
= 1;
12199 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12200 do_debug_pubnames
= 1;
12201 do_debug_pubtypes
= 1;
12202 do_debug_aranges
= 1;
12203 do_debug_ranges
= 1;
12204 do_debug_frames
= 1;
12205 do_debug_macinfo
= 1;
12210 do_trace_abbrevs
= 1;
12211 do_trace_aranges
= 1;
12213 do_debug_cu_index
= 1;
12214 do_follow_links
= 1;
12215 do_debug_links
= 1;
12216 do_debug_str_offsets
= 1;
12219 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12220 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12222 /* N.B. The order here must match the order in section_display_enum. */
12224 struct dwarf_section_display debug_displays
[] =
12226 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12227 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12228 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12229 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12230 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12231 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12232 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12233 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12234 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12235 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12236 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12237 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12238 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12239 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12240 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12241 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12242 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12243 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12244 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12245 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12246 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12247 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12248 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12249 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12250 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12251 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12252 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12253 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12254 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12255 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12256 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12257 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12258 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12259 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12260 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12261 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12262 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12263 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12264 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12265 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12266 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12267 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12268 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12269 /* Separate debug info files can containt their own .debug_str section,
12270 and this might be in *addition* to a .debug_str section already present
12271 in the main file. Hence we need to have two entries for .debug_str. */
12272 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12273 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12276 /* A static assertion. */
12277 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];