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
;
2829 case DW_AT_frame_base
:
2830 have_frame_base
= 1;
2832 case DW_AT_location
:
2833 case DW_AT_GNU_locviews
:
2834 case DW_AT_string_length
:
2835 case DW_AT_return_addr
:
2836 case DW_AT_data_member_location
:
2837 case DW_AT_vtable_elem_location
:
2839 case DW_AT_static_link
:
2840 case DW_AT_use_location
:
2841 case DW_AT_call_value
:
2842 case DW_AT_GNU_call_site_value
:
2843 case DW_AT_call_data_value
:
2844 case DW_AT_GNU_call_site_data_value
:
2845 case DW_AT_call_target
:
2846 case DW_AT_GNU_call_site_target
:
2847 case DW_AT_call_target_clobbered
:
2848 case DW_AT_GNU_call_site_target_clobbered
:
2849 if ((dwarf_version
< 4
2850 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2851 || form
== DW_FORM_sec_offset
2852 || form
== DW_FORM_loclistx
)
2854 /* Process location list. */
2855 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2856 unsigned int num
= debug_info_p
->num_loc_offsets
;
2858 if (lmax
== 0 || num
>= lmax
)
2861 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2862 xcrealloc (debug_info_p
->loc_offsets
,
2863 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2864 debug_info_p
->loc_views
= (dwarf_vma
*)
2865 xcrealloc (debug_info_p
->loc_views
,
2866 lmax
, sizeof (*debug_info_p
->loc_views
));
2867 debug_info_p
->have_frame_base
= (int *)
2868 xcrealloc (debug_info_p
->have_frame_base
,
2869 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2870 debug_info_p
->max_loc_offsets
= lmax
;
2873 if (form
== DW_FORM_loclistx
)
2874 uvalue
= fetch_indexed_value (uvalue
, loclists
);
2875 else if (this_set
!= NULL
)
2876 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2878 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2879 if (attribute
!= DW_AT_GNU_locviews
)
2881 uvalue
+= debug_info_p
->loclists_base
;
2883 /* Corrupt DWARF info can produce more offsets than views.
2884 See PR 23062 for an example. */
2885 if (debug_info_p
->num_loc_offsets
2886 > debug_info_p
->num_loc_views
)
2887 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2890 debug_info_p
->loc_offsets
[num
] = uvalue
;
2891 debug_info_p
->num_loc_offsets
++;
2896 assert (debug_info_p
->num_loc_views
<= num
);
2897 num
= debug_info_p
->num_loc_views
;
2898 if (num
> debug_info_p
->num_loc_offsets
)
2899 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2902 debug_info_p
->loc_views
[num
] = uvalue
;
2903 debug_info_p
->num_loc_views
++;
2910 if (need_base_address
)
2911 debug_info_p
->base_address
= uvalue
;
2914 case DW_AT_GNU_addr_base
:
2915 case DW_AT_addr_base
:
2916 debug_info_p
->addr_base
= uvalue
;
2919 case DW_AT_GNU_ranges_base
:
2920 debug_info_p
->ranges_base
= uvalue
;
2924 if ((dwarf_version
< 4
2925 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2926 || form
== DW_FORM_sec_offset
2927 || form
== DW_FORM_rnglistx
)
2929 /* Process range list. */
2930 unsigned int lmax
= debug_info_p
->max_range_lists
;
2931 unsigned int num
= debug_info_p
->num_range_lists
;
2933 if (lmax
== 0 || num
>= lmax
)
2936 debug_info_p
->range_lists
= (dwarf_vma
*)
2937 xcrealloc (debug_info_p
->range_lists
,
2938 lmax
, sizeof (*debug_info_p
->range_lists
));
2939 debug_info_p
->max_range_lists
= lmax
;
2942 if (form
== DW_FORM_rnglistx
)
2943 uvalue
= fetch_indexed_value (uvalue
, rnglists
);
2945 debug_info_p
->range_lists
[num
] = uvalue
;
2946 debug_info_p
->num_range_lists
++;
2950 case DW_AT_GNU_dwo_name
:
2951 case DW_AT_dwo_name
:
2956 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2958 case DW_FORM_GNU_strp_alt
:
2959 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2961 case DW_FORM_GNU_str_index
:
2967 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
2969 case DW_FORM_string
:
2970 add_dwo_name ((const char *) orig_data
, cu_offset
);
2973 warn (_("Unsupported form (%s) for attribute %s\n"),
2974 get_FORM_name (form
), get_AT_name (attribute
));
2979 case DW_AT_comp_dir
:
2980 /* FIXME: Also extract a build-id in a CU/TU. */
2985 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2987 case DW_FORM_GNU_strp_alt
:
2988 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2990 case DW_FORM_line_strp
:
2991 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2993 case DW_FORM_GNU_str_index
:
2999 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, false), cu_offset
);
3001 case DW_FORM_string
:
3002 add_dwo_dir ((const char *) orig_data
, cu_offset
);
3005 warn (_("Unsupported form (%s) for attribute %s\n"),
3006 get_FORM_name (form
), get_AT_name (attribute
));
3011 case DW_AT_GNU_dwo_id
:
3016 /* FIXME: Record the length of the ID as well ? */
3017 add_dwo_id ((const char *) (data
- 8), cu_offset
);
3020 warn (_("Unsupported form (%s) for attribute %s\n"),
3021 get_FORM_name (form
), get_AT_name (attribute
));
3031 if (do_loc
|| attribute
== 0)
3034 /* For some attributes we can display further information. */
3038 if (level
>= 0 && level
< MAX_CU_NESTING
3039 && uvalue
< (size_t) (end
- start
))
3041 bool is_signed
= false;
3042 abbrev_entry
*type_abbrev
;
3043 unsigned char *type_data
;
3046 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
,
3050 if (type_abbrev
!= NULL
)
3052 get_type_signedness (type_abbrev
, section
, type_data
,
3053 map
? section
->start
+ map
->end
: end
,
3054 map
? map
->start
: cu_offset
,
3055 pointer_size
, offset_size
, dwarf_version
,
3058 level_type_signed
[level
] = is_signed
;
3066 case DW_INL_not_inlined
:
3067 printf (_("(not inlined)"));
3069 case DW_INL_inlined
:
3070 printf (_("(inlined)"));
3072 case DW_INL_declared_not_inlined
:
3073 printf (_("(declared as inline but ignored)"));
3075 case DW_INL_declared_inlined
:
3076 printf (_("(declared as inline and inlined)"));
3079 printf (_(" (Unknown inline attribute value: %s)"),
3080 dwarf_vmatoa ("x", uvalue
));
3085 case DW_AT_language
:
3089 /* Ordered by the numeric value of these constants. */
3090 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3091 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3092 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3093 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3094 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3095 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3096 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3097 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3098 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3099 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3100 /* DWARF 2.1 values. */
3101 case DW_LANG_Java
: printf ("(Java)"); break;
3102 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3103 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3104 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3105 /* DWARF 3 values. */
3106 case DW_LANG_PLI
: printf ("(PLI)"); break;
3107 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3108 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3109 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3110 case DW_LANG_D
: printf ("(D)"); break;
3111 /* DWARF 4 values. */
3112 case DW_LANG_Python
: printf ("(Python)"); break;
3113 /* DWARF 5 values. */
3114 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3115 case DW_LANG_Go
: printf ("(Go)"); break;
3116 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3117 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3118 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3119 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3120 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3121 case DW_LANG_Rust
: printf ("(Rust)"); break;
3122 case DW_LANG_C11
: printf ("(C11)"); break;
3123 case DW_LANG_Swift
: printf ("(Swift)"); break;
3124 case DW_LANG_Julia
: printf ("(Julia)"); break;
3125 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3126 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3127 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3128 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3129 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3130 /* MIPS extension. */
3131 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3132 /* UPC extension. */
3133 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3135 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3136 printf (_("(implementation defined: %s)"),
3137 dwarf_vmatoa ("x", uvalue
));
3139 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3144 case DW_AT_encoding
:
3148 case DW_ATE_void
: printf ("(void)"); break;
3149 case DW_ATE_address
: printf ("(machine address)"); break;
3150 case DW_ATE_boolean
: printf ("(boolean)"); break;
3151 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3152 case DW_ATE_float
: printf ("(float)"); break;
3153 case DW_ATE_signed
: printf ("(signed)"); break;
3154 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3155 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3156 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3157 /* DWARF 2.1 values: */
3158 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3159 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3160 /* DWARF 3 values: */
3161 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3162 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3163 case DW_ATE_edited
: printf ("(edited)"); break;
3164 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3165 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3166 /* DWARF 4 values: */
3167 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3168 /* DWARF 5 values: */
3169 case DW_ATE_UCS
: printf ("(UCS)"); break;
3170 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3172 /* HP extensions: */
3173 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3174 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3175 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3176 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3177 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3178 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3179 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3182 if (uvalue
>= DW_ATE_lo_user
3183 && uvalue
<= DW_ATE_hi_user
)
3184 printf (_("(user defined type)"));
3186 printf (_("(unknown type)"));
3191 case DW_AT_accessibility
:
3195 case DW_ACCESS_public
: printf ("(public)"); break;
3196 case DW_ACCESS_protected
: printf ("(protected)"); break;
3197 case DW_ACCESS_private
: printf ("(private)"); break;
3199 printf (_("(unknown accessibility)"));
3204 case DW_AT_visibility
:
3208 case DW_VIS_local
: printf ("(local)"); break;
3209 case DW_VIS_exported
: printf ("(exported)"); break;
3210 case DW_VIS_qualified
: printf ("(qualified)"); break;
3211 default: printf (_("(unknown visibility)")); break;
3215 case DW_AT_endianity
:
3219 case DW_END_default
: printf ("(default)"); break;
3220 case DW_END_big
: printf ("(big)"); break;
3221 case DW_END_little
: printf ("(little)"); break;
3223 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3224 printf (_("(user specified)"));
3226 printf (_("(unknown endianity)"));
3231 case DW_AT_virtuality
:
3235 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3236 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3237 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3238 default: printf (_("(unknown virtuality)")); break;
3242 case DW_AT_identifier_case
:
3246 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3247 case DW_ID_up_case
: printf ("(up_case)"); break;
3248 case DW_ID_down_case
: printf ("(down_case)"); break;
3249 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3250 default: printf (_("(unknown case)")); break;
3254 case DW_AT_calling_convention
:
3258 case DW_CC_normal
: printf ("(normal)"); break;
3259 case DW_CC_program
: printf ("(program)"); break;
3260 case DW_CC_nocall
: printf ("(nocall)"); break;
3261 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3262 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3263 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3264 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3266 if (uvalue
>= DW_CC_lo_user
3267 && uvalue
<= DW_CC_hi_user
)
3268 printf (_("(user defined)"));
3270 printf (_("(unknown convention)"));
3274 case DW_AT_ordering
:
3279 case -1: printf (_("(undefined)")); break;
3280 case 0: printf ("(row major)"); break;
3281 case 1: printf ("(column major)"); break;
3285 case DW_AT_decimal_sign
:
3289 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3290 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3291 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3292 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3293 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3294 default: printf (_("(unrecognised)")); break;
3298 case DW_AT_defaulted
:
3302 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3303 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3304 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3305 default: printf (_("(unrecognised)")); break;
3309 case DW_AT_discr_list
:
3311 display_discr_list (form
, uvalue
, data
, level
);
3314 case DW_AT_frame_base
:
3315 have_frame_base
= 1;
3317 case DW_AT_location
:
3318 case DW_AT_loclists_base
:
3319 case DW_AT_string_length
:
3320 case DW_AT_return_addr
:
3321 case DW_AT_data_member_location
:
3322 case DW_AT_vtable_elem_location
:
3324 case DW_AT_static_link
:
3325 case DW_AT_use_location
:
3326 case DW_AT_call_value
:
3327 case DW_AT_GNU_call_site_value
:
3328 case DW_AT_call_data_value
:
3329 case DW_AT_GNU_call_site_data_value
:
3330 case DW_AT_call_target
:
3331 case DW_AT_GNU_call_site_target
:
3332 case DW_AT_call_target_clobbered
:
3333 case DW_AT_GNU_call_site_target_clobbered
:
3334 if ((dwarf_version
< 4
3335 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3336 || form
== DW_FORM_sec_offset
3337 || form
== DW_FORM_loclistx
)
3338 printf (_(" (location list)"));
3340 case DW_AT_allocated
:
3341 case DW_AT_associated
:
3342 case DW_AT_data_location
:
3344 case DW_AT_upper_bound
:
3345 case DW_AT_lower_bound
:
3348 int need_frame_base
;
3351 need_frame_base
= decode_location_expression (block_start
,
3356 cu_offset
, section
);
3358 if (need_frame_base
&& !have_frame_base
)
3359 printf (_(" [without DW_AT_frame_base]"));
3363 case DW_AT_data_bit_offset
:
3364 case DW_AT_byte_size
:
3365 case DW_AT_bit_size
:
3366 case DW_AT_string_length_byte_size
:
3367 case DW_AT_string_length_bit_size
:
3368 case DW_AT_bit_stride
:
3369 if (form
== DW_FORM_exprloc
)
3372 (void) decode_location_expression (block_start
, pointer_size
,
3373 offset_size
, dwarf_version
,
3374 uvalue
, cu_offset
, section
);
3381 unsigned long abbrev_number
;
3382 abbrev_entry
*entry
;
3384 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
, end
,
3385 section
, & abbrev_number
, NULL
, NULL
);
3388 if (form
!= DW_FORM_GNU_ref_alt
)
3389 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3390 dwarf_vmatoa ("x", uvalue
),
3391 (unsigned long) (orig_data
- section
->start
));
3395 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3396 printf (" (%s)", get_TAG_name (entry
->tag
));
3409 static unsigned char *
3410 read_and_display_attr (unsigned long attribute
,
3412 dwarf_signed_vma implicit_const
,
3413 unsigned char * start
,
3414 unsigned char * data
,
3415 unsigned char * end
,
3416 dwarf_vma cu_offset
,
3417 dwarf_vma pointer_size
,
3418 dwarf_vma offset_size
,
3420 debug_info
* debug_info_p
,
3422 struct dwarf_section
* section
,
3423 struct cu_tu_set
* this_set
,
3427 printf (" %-18s:", get_AT_name (attribute
));
3428 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3430 cu_offset
, pointer_size
, offset_size
,
3431 dwarf_version
, debug_info_p
,
3432 do_loc
, section
, this_set
, ' ', level
);
3438 /* Like load_debug_section, but if the ordinary call fails, and we are
3439 following debug links, then attempt to load the requested section
3440 from one of the separate debug info files. */
3443 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3446 if (load_debug_section (sec_enum
, handle
))
3448 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3450 /* See if we can associate a filename with this section. */
3453 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3454 if (i
->handle
== handle
)
3456 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3464 if (do_follow_links
)
3468 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3470 if (load_debug_section (sec_enum
, i
->handle
))
3472 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3474 /* FIXME: We should check to see if any of the remaining debug info
3475 files also contain this section, and, umm, do something about it. */
3485 introduce (struct dwarf_section
* section
, bool raw
)
3489 if (do_follow_links
&& section
->filename
)
3490 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3491 section
->name
, section
->filename
);
3493 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3497 if (do_follow_links
&& section
->filename
)
3498 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3499 section
->name
, section
->filename
);
3501 printf (_("Contents of the %s section:\n\n"), section
->name
);
3505 /* Process the contents of a .debug_info section.
3506 If do_loc is TRUE then we are scanning for location lists and dwo tags
3507 and we do not want to display anything to the user.
3508 If do_types is TRUE, we are processing a .debug_types section instead of
3509 a .debug_info section.
3510 The information displayed is restricted by the values in DWARF_START_DIE
3511 and DWARF_CUTOFF_LEVEL.
3512 Returns TRUE upon success. Otherwise an error or warning message is
3513 printed and FALSE is returned. */
3516 process_debug_info (struct dwarf_section
* section
,
3518 enum dwarf_section_display_enum abbrev_sec
,
3522 unsigned char *start
= section
->start
;
3523 unsigned char *end
= start
+ section
->size
;
3524 unsigned char *section_begin
;
3526 unsigned int num_units
= 0;
3528 /* First scan the section to get the number of comp units.
3529 Length sanity checks are done here. */
3530 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3535 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3536 will be the length. For a 64-bit DWARF section, it'll be
3537 the escape code 0xffffffff followed by an 8 byte length. */
3538 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 4, end
);
3540 if (length
== 0xffffffff)
3541 SAFE_BYTE_GET_AND_INC (length
, section_begin
, 8, end
);
3542 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3544 warn (_("Reserved length value (0x%s) found in section %s\n"),
3545 dwarf_vmatoa ("x", length
), section
->name
);
3549 /* Negative values are illegal, they may even cause infinite
3550 looping. This can happen if we can't accurately apply
3551 relocations to an object file, or if the file is corrupt. */
3552 if (length
> (size_t) (end
- section_begin
))
3554 warn (_("Corrupt unit length (got 0x%s expected at most 0x%s) in section %s\n"),
3555 dwarf_vmatoa ("x", length
),
3556 dwarf_vmatoa ("x", end
- section_begin
),
3560 section_begin
+= length
;
3565 error (_("No comp units in %s section ?\n"), section
->name
);
3569 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3570 && num_debug_info_entries
== 0
3574 /* Then allocate an array to hold the information. */
3575 debug_information
= (debug_info
*) cmalloc (num_units
,
3576 sizeof (* debug_information
));
3577 if (debug_information
== NULL
)
3579 error (_("Not enough memory for a debug info array of %u entries\n"),
3581 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3585 /* PR 17531: file: 92ca3797.
3586 We cannot rely upon the debug_information array being initialised
3587 before it is used. A corrupt file could easily contain references
3588 to a unit for which information has not been made available. So
3589 we ensure that the array is zeroed here. */
3590 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3592 alloc_num_debug_info_entries
= num_units
;
3597 load_debug_section_with_follow (str
, file
);
3598 load_debug_section_with_follow (line_str
, file
);
3599 load_debug_section_with_follow (str_dwo
, file
);
3600 load_debug_section_with_follow (str_index
, file
);
3601 load_debug_section_with_follow (str_index_dwo
, file
);
3602 load_debug_section_with_follow (debug_addr
, file
);
3605 load_debug_section_with_follow (abbrev_sec
, file
);
3606 load_debug_section_with_follow (loclists
, file
);
3607 load_debug_section_with_follow (rnglists
, file
);
3609 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3611 warn (_("Unable to locate %s section!\n"),
3612 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3616 if (!do_loc
&& dwarf_start_die
== 0)
3617 introduce (section
, false);
3619 free_all_abbrevs ();
3620 free (cu_abbrev_map
);
3621 cu_abbrev_map
= NULL
;
3622 next_free_abbrev_map_entry
= 0;
3624 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3625 to load *all* of the abbrevs for all CUs in this .debug_info
3626 section. This does effectively mean that we (partially) read
3627 every CU header twice. */
3628 for (section_begin
= start
; start
< end
;)
3630 DWARF2_Internal_CompUnit compunit
;
3631 unsigned char * hdrptr
;
3632 dwarf_vma abbrev_base
;
3634 dwarf_vma cu_offset
;
3635 unsigned int offset_size
;
3636 struct cu_tu_set
* this_set
;
3638 unsigned char *end_cu
;
3641 cu_offset
= start
- section_begin
;
3643 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3645 if (compunit
.cu_length
== 0xffffffff)
3647 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3652 end_cu
= hdrptr
+ compunit
.cu_length
;
3654 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3656 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3658 if (compunit
.cu_version
< 5)
3660 compunit
.cu_unit_type
= DW_UT_compile
;
3661 /* Initialize it due to a false compiler warning. */
3662 compunit
.cu_pointer_size
= -1;
3666 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3667 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3669 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3672 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
,
3675 if (compunit
.cu_unit_type
== DW_UT_split_compile
3676 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3679 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3682 if (this_set
== NULL
)
3685 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3689 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3690 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3693 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3694 compunit
.cu_abbrev_offset
);
3697 unsigned char * next
;
3699 list
= new_abbrev_list (abbrev_base
,
3700 compunit
.cu_abbrev_offset
);
3701 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3702 abbrev_base
, abbrev_size
,
3703 compunit
.cu_abbrev_offset
, list
);
3704 list
->start_of_next_abbrevs
= next
;
3708 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3711 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3713 DWARF2_Internal_CompUnit compunit
;
3714 unsigned char *hdrptr
;
3715 unsigned char *tags
;
3716 int level
, last_level
, saved_level
;
3717 dwarf_vma cu_offset
;
3718 unsigned int offset_size
;
3719 dwarf_vma signature
= 0;
3720 dwarf_vma type_offset
= 0;
3721 struct cu_tu_set
*this_set
;
3722 dwarf_vma abbrev_base
;
3724 abbrev_list
* list
= NULL
;
3725 unsigned char *end_cu
;
3728 cu_offset
= start
- section_begin
;
3730 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3732 if (compunit
.cu_length
== 0xffffffff)
3734 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3739 end_cu
= hdrptr
+ compunit
.cu_length
;
3741 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end_cu
);
3743 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3745 if (compunit
.cu_version
< 5)
3747 compunit
.cu_unit_type
= DW_UT_compile
;
3748 /* Initialize it due to a false compiler warning. */
3749 compunit
.cu_pointer_size
= -1;
3753 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end_cu
);
3754 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3756 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3759 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end_cu
);
3761 if (this_set
== NULL
)
3764 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3768 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3769 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3772 if (compunit
.cu_version
< 5)
3773 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end_cu
);
3775 bool do_dwo_id
= false;
3776 uint64_t dwo_id
= 0;
3777 if (compunit
.cu_unit_type
== DW_UT_split_compile
3778 || compunit
.cu_unit_type
== DW_UT_skeleton
)
3780 SAFE_BYTE_GET_AND_INC (dwo_id
, hdrptr
, 8, end_cu
);
3784 /* PR 17512: file: 001-108546-0.001:0.1. */
3785 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3787 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3788 compunit
.cu_pointer_size
, offset_size
);
3789 compunit
.cu_pointer_size
= offset_size
;
3794 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, end_cu
);
3795 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end_cu
);
3798 if (dwarf_start_die
>= (size_t) (end_cu
- section_begin
))
3804 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3805 && num_debug_info_entries
== 0
3806 && alloc_num_debug_info_entries
> unit
3809 debug_information
[unit
].cu_offset
= cu_offset
;
3810 debug_information
[unit
].pointer_size
3811 = compunit
.cu_pointer_size
;
3812 debug_information
[unit
].offset_size
= offset_size
;
3813 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3814 debug_information
[unit
].base_address
= 0;
3815 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3816 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3817 debug_information
[unit
].loc_offsets
= NULL
;
3818 debug_information
[unit
].have_frame_base
= NULL
;
3819 debug_information
[unit
].max_loc_offsets
= 0;
3820 debug_information
[unit
].num_loc_offsets
= 0;
3821 debug_information
[unit
].loclists_base
= 0;
3822 debug_information
[unit
].range_lists
= NULL
;
3823 debug_information
[unit
].max_range_lists
= 0;
3824 debug_information
[unit
].num_range_lists
= 0;
3827 if (!do_loc
&& dwarf_start_die
== 0)
3829 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3830 dwarf_vmatoa ("x", cu_offset
));
3831 printf (_(" Length: 0x%s (%s)\n"),
3832 dwarf_vmatoa ("x", compunit
.cu_length
),
3833 offset_size
== 8 ? "64-bit" : "32-bit");
3834 printf (_(" Version: %d\n"), compunit
.cu_version
);
3835 if (compunit
.cu_version
>= 5)
3837 const char *name
= get_DW_UT_name (compunit
.cu_unit_type
);
3839 printf (_(" Unit Type: %s (%x)\n"),
3840 name
? name
: "???",
3841 compunit
.cu_unit_type
);
3843 printf (_(" Abbrev Offset: 0x%s\n"),
3844 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3845 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3848 printf (_(" Signature: 0x%s\n"),
3849 dwarf_vmatoa ("x", signature
));
3850 printf (_(" Type Offset: 0x%s\n"),
3851 dwarf_vmatoa ("x", type_offset
));
3854 printf (_(" DWO ID: 0x%s\n"), dwarf_vmatoa ("x", dwo_id
));
3855 if (this_set
!= NULL
)
3857 dwarf_vma
*offsets
= this_set
->section_offsets
;
3858 size_t *sizes
= this_set
->section_sizes
;
3860 printf (_(" Section contributions:\n"));
3861 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3862 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3863 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3864 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3865 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3866 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3867 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3868 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3869 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3870 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3871 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3872 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3879 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3881 warn (_("CU at offset %s contains corrupt or "
3882 "unsupported version number: %d.\n"),
3883 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3887 if (compunit
.cu_unit_type
!= DW_UT_compile
3888 && compunit
.cu_unit_type
!= DW_UT_partial
3889 && compunit
.cu_unit_type
!= DW_UT_type
3890 && compunit
.cu_unit_type
!= DW_UT_split_compile
3891 && compunit
.cu_unit_type
!= DW_UT_skeleton
)
3893 warn (_("CU at offset %s contains corrupt or "
3894 "unsupported unit type: %d.\n"),
3895 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3899 /* Process the abbrevs used by this compilation unit. */
3900 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3901 compunit
.cu_abbrev_offset
);
3904 unsigned char *next
;
3906 list
= new_abbrev_list (abbrev_base
,
3907 compunit
.cu_abbrev_offset
);
3908 next
= process_abbrev_set (&debug_displays
[abbrev_sec
].section
,
3909 abbrev_base
, abbrev_size
,
3910 compunit
.cu_abbrev_offset
, list
);
3911 list
->start_of_next_abbrevs
= next
;
3917 while (tags
< start
)
3919 unsigned long abbrev_number
;
3920 unsigned long die_offset
;
3921 abbrev_entry
*entry
;
3923 int do_printing
= 1;
3925 die_offset
= tags
- section_begin
;
3927 READ_ULEB (abbrev_number
, tags
, start
);
3929 /* A null DIE marks the end of a list of siblings or it may also be
3930 a section padding. */
3931 if (abbrev_number
== 0)
3933 /* Check if it can be a section padding for the last CU. */
3934 if (level
== 0 && start
== end
)
3938 for (chk
= tags
; chk
< start
; chk
++)
3945 if (!do_loc
&& die_offset
>= dwarf_start_die
3946 && (dwarf_cutoff_level
== -1
3947 || level
< dwarf_cutoff_level
))
3948 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3954 static unsigned num_bogus_warns
= 0;
3956 if (num_bogus_warns
< 3)
3958 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3959 die_offset
, section
->name
);
3961 if (num_bogus_warns
== 3)
3962 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3965 if (dwarf_start_die
!= 0 && level
< saved_level
)
3972 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3976 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3977 saved_level
= level
;
3978 do_printing
= (dwarf_cutoff_level
== -1
3979 || level
< dwarf_cutoff_level
);
3981 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3982 level
, die_offset
, abbrev_number
);
3983 else if (dwarf_cutoff_level
== -1
3984 || last_level
< dwarf_cutoff_level
)
3985 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3990 /* Scan through the abbreviation list until we reach the
3995 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3996 if (entry
->number
== abbrev_number
)
4001 if (!do_loc
&& do_printing
)
4006 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
4007 die_offset
, abbrev_number
);
4011 if (!do_loc
&& do_printing
)
4012 printf (" (%s)\n", get_TAG_name (entry
->tag
));
4017 need_base_address
= 0;
4019 case DW_TAG_compile_unit
:
4020 need_base_address
= 1;
4021 need_dwo_info
= do_loc
;
4023 case DW_TAG_entry_point
:
4024 case DW_TAG_subprogram
:
4025 need_base_address
= 0;
4026 /* Assuming that there is no DW_AT_frame_base. */
4027 have_frame_base
= 0;
4031 debug_info
*debug_info_p
=
4032 (debug_information
&& unit
< alloc_num_debug_info_entries
)
4033 ? debug_information
+ unit
: NULL
;
4035 assert (!debug_info_p
4036 || (debug_info_p
->num_loc_offsets
4037 == debug_info_p
->num_loc_views
));
4039 for (attr
= entry
->first_attr
;
4040 attr
&& attr
->attribute
;
4043 if (! do_loc
&& do_printing
)
4044 /* Show the offset from where the tag was extracted. */
4045 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
4046 tags
= read_and_display_attr (attr
->attribute
,
4048 attr
->implicit_const
,
4053 compunit
.cu_pointer_size
,
4055 compunit
.cu_version
,
4057 do_loc
|| ! do_printing
,
4063 /* If a locview attribute appears before a location one,
4064 make sure we don't associate it with an earlier
4067 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
4070 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
4071 debug_info_p
->num_loc_views
++;
4072 assert (debug_info_p
->num_loc_views
4073 == debug_info_p
->num_loc_offsets
);
4080 warn(_("DIE has locviews without loclist\n"));
4081 debug_info_p
->num_loc_views
--;
4088 if (entry
->children
)
4093 /* Set num_debug_info_entries here so that it can be used to check if
4094 we need to process .debug_loc and .debug_ranges sections. */
4095 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4096 && num_debug_info_entries
== 0
4099 if (num_units
> alloc_num_debug_info_entries
)
4100 num_debug_info_entries
= alloc_num_debug_info_entries
;
4102 num_debug_info_entries
= num_units
;
4111 /* Locate and scan the .debug_info section in the file and record the pointer
4112 sizes and offsets for the compilation units in it. Usually an executable
4113 will have just one pointer size, but this is not guaranteed, and so we try
4114 not to make any assumptions. Returns zero upon failure, or the number of
4115 compilation units upon success. */
4118 load_debug_info (void * file
)
4120 /* If we have already tried and failed to load the .debug_info
4121 section then do not bother to repeat the task. */
4122 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4125 /* If we already have the information there is nothing else to do. */
4126 if (num_debug_info_entries
> 0)
4127 return num_debug_info_entries
;
4129 /* If this is a DWARF package file, load the CU and TU indexes. */
4130 (void) load_cu_tu_indexes (file
);
4132 if (load_debug_section_with_follow (info
, file
)
4133 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, true, false))
4134 return num_debug_info_entries
;
4136 if (load_debug_section_with_follow (info_dwo
, file
)
4137 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4138 abbrev_dwo
, true, false))
4139 return num_debug_info_entries
;
4141 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4145 /* Read a DWARF .debug_line section header starting at DATA.
4146 Upon success returns an updated DATA pointer and the LINFO
4147 structure and the END_OF_SEQUENCE pointer will be filled in.
4148 Otherwise returns NULL. */
4150 static unsigned char *
4151 read_debug_line_header (struct dwarf_section
* section
,
4152 unsigned char * data
,
4153 unsigned char * end
,
4154 DWARF2_Internal_LineInfo
* linfo
,
4155 unsigned char ** end_of_sequence
)
4157 unsigned char *hdrptr
;
4159 /* Extract information from the Line Number Program Header.
4160 (section 6.2.4 in the Dwarf3 doc). */
4163 /* Get and check the length of the block. */
4164 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4166 if (linfo
->li_length
== 0xffffffff)
4168 /* This section is 64-bit DWARF 3. */
4169 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4170 linfo
->li_offset_size
= 8;
4173 linfo
->li_offset_size
= 4;
4175 if (linfo
->li_length
> (size_t) (end
- hdrptr
))
4177 /* If the length field has a relocation against it, then we should
4178 not complain if it is inaccurate (and probably negative). This
4179 happens in object files when the .debug_line section is actually
4180 comprised of several different .debug_line.* sections, (some of
4181 which may be removed by linker garbage collection), and a relocation
4182 is used to compute the correct length once that is done. */
4183 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4185 linfo
->li_length
= end
- hdrptr
;
4189 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4190 (long) linfo
->li_length
);
4194 end
= hdrptr
+ linfo
->li_length
;
4196 /* Get and check the version number. */
4197 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4199 if (linfo
->li_version
!= 2
4200 && linfo
->li_version
!= 3
4201 && linfo
->li_version
!= 4
4202 && linfo
->li_version
!= 5)
4204 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4205 "is currently supported.\n"));
4209 if (linfo
->li_version
>= 5)
4211 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4213 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4214 if (linfo
->li_segment_size
!= 0)
4216 warn (_("The %s section contains "
4217 "unsupported segment selector size: %d.\n"),
4218 section
->name
, linfo
->li_segment_size
);
4223 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4224 linfo
->li_offset_size
, end
);
4225 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4227 if (linfo
->li_version
>= 4)
4229 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4231 if (linfo
->li_max_ops_per_insn
== 0)
4233 warn (_("Invalid maximum operations per insn.\n"));
4238 linfo
->li_max_ops_per_insn
= 1;
4240 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4241 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4242 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4243 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4245 *end_of_sequence
= end
;
4249 static unsigned char *
4250 display_formatted_table (unsigned char *data
,
4251 unsigned char *start
,
4253 const DWARF2_Internal_LineInfo
*linfo
,
4254 struct dwarf_section
*section
,
4257 unsigned char *format_start
, format_count
, *format
, formati
;
4258 dwarf_vma data_count
, datai
;
4259 unsigned int namepass
, last_entry
= 0;
4260 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4262 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4263 if (do_checks
&& format_count
> 5)
4264 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4265 table_name
, format_count
);
4267 format_start
= data
;
4268 for (formati
= 0; formati
< format_count
; formati
++)
4270 SKIP_ULEB (data
, end
);
4271 SKIP_ULEB (data
, end
);
4274 warn (_("%s: Corrupt format description entry\n"), table_name
);
4279 READ_ULEB (data_count
, data
, end
);
4280 if (data_count
== 0)
4282 printf (_("\n The %s is empty.\n"), table_name
);
4285 else if (data
>= end
)
4287 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4288 table_name
, dwarf_vmatoa ("x", data_count
));
4292 else if (format_count
== 0)
4294 warn (_("%s: format count is zero, but the table is not empty\n"),
4299 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4300 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4303 printf (_(" Entry"));
4304 /* Delay displaying name as the last entry for better screen layout. */
4305 for (namepass
= 0; namepass
< 2; namepass
++)
4307 format
= format_start
;
4308 for (formati
= 0; formati
< format_count
; formati
++)
4310 dwarf_vma content_type
;
4312 READ_ULEB (content_type
, format
, end
);
4313 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4314 switch (content_type
)
4317 printf (_("\tName"));
4319 case DW_LNCT_directory_index
:
4320 printf (_("\tDir"));
4322 case DW_LNCT_timestamp
:
4323 printf (_("\tTime"));
4326 printf (_("\tSize"));
4329 printf (_("\tMD5\t\t\t"));
4332 printf (_("\t(Unknown format content type %s)"),
4333 dwarf_vmatoa ("u", content_type
));
4335 SKIP_ULEB (format
, end
);
4340 for (datai
= 0; datai
< data_count
; datai
++)
4342 unsigned char *datapass
= data
;
4344 printf (" %d", last_entry
++);
4345 /* Delay displaying name as the last entry for better screen layout. */
4346 for (namepass
= 0; namepass
< 2; namepass
++)
4348 format
= format_start
;
4350 for (formati
= 0; formati
< format_count
; formati
++)
4352 dwarf_vma content_type
, form
;
4354 READ_ULEB (content_type
, format
, end
);
4355 READ_ULEB (form
, format
, end
);
4356 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4357 0, 0, linfo
->li_offset_size
,
4358 linfo
->li_version
, NULL
,
4359 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4360 section
, NULL
, '\t', -1);
4364 if (data
>= end
&& (datai
< data_count
- 1))
4366 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4375 display_debug_sup (struct dwarf_section
* section
,
4376 void * file ATTRIBUTE_UNUSED
)
4378 unsigned char * start
= section
->start
;
4379 unsigned char * end
= section
->start
+ section
->size
;
4380 unsigned int version
;
4381 char is_supplementary
;
4382 const unsigned char * sup_filename
;
4383 size_t sup_filename_len
;
4384 unsigned int num_read
;
4386 dwarf_vma checksum_len
;
4389 introduce (section
, true);
4390 if (section
->size
< 4)
4392 error (_("corrupt .debug_sup section: size is too small\n"));
4396 /* Read the data. */
4397 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
4399 warn (_("corrupt .debug_sup section: version < 5"));
4401 SAFE_BYTE_GET_AND_INC (is_supplementary
, start
, 1, end
);
4402 if (is_supplementary
!= 0 && is_supplementary
!= 1)
4403 warn (_("corrupt .debug_sup section: is_supplementary not 0 or 1\n"));
4405 sup_filename
= start
;
4406 if (is_supplementary
&& sup_filename
[0] != 0)
4407 warn (_("corrupt .debug_sup section: filename not empty in supplementary section\n"));
4409 sup_filename_len
= strnlen ((const char *) start
, end
- start
);
4410 if (sup_filename_len
== (size_t) (end
- start
))
4412 error (_("corrupt .debug_sup section: filename is not NUL terminated\n"));
4415 start
+= sup_filename_len
+ 1;
4417 checksum_len
= read_leb128 (start
, end
, false /* unsigned */, & num_read
, & status
);
4420 error (_("corrupt .debug_sup section: bad LEB128 field for checksum length\n"));
4424 if (checksum_len
> (dwarf_vma
) (end
- start
))
4426 error (_("corrupt .debug_sup section: checksum length is longer than the remaining section length\n"));
4427 checksum_len
= end
- start
;
4429 else if (checksum_len
< (dwarf_vma
) (end
- start
))
4431 warn (_("corrupt .debug_sup section: there are 0x%lx extra, unused bytes at the end of the section\n"),
4432 (long) ((end
- start
) - checksum_len
));
4435 printf (_(" Version: %u\n"), version
);
4436 printf (_(" Is Supp: %u\n"), is_supplementary
);
4437 printf (_(" Filename: %s\n"), sup_filename
);
4438 printf (_(" Checksum Len: %lu\n"), (long) checksum_len
);
4439 if (checksum_len
> 0)
4441 printf (_(" Checksum: "));
4442 while (checksum_len
--)
4443 printf ("0x%x ", * start
++ );
4450 display_debug_lines_raw (struct dwarf_section
* section
,
4451 unsigned char * data
,
4452 unsigned char * end
,
4455 unsigned char *start
= section
->start
;
4456 int verbose_view
= 0;
4458 introduce (section
, true);
4462 static DWARF2_Internal_LineInfo saved_linfo
;
4463 DWARF2_Internal_LineInfo linfo
;
4464 unsigned char *standard_opcodes
;
4465 unsigned char *end_of_sequence
;
4468 if (startswith (section
->name
, ".debug_line.")
4469 /* Note: the following does not apply to .debug_line.dwo sections.
4470 These are full debug_line sections. */
4471 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4473 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4474 section containing just the Line Number Statements. They are
4475 created by the assembler and intended to be used alongside gcc's
4476 -ffunction-sections command line option. When the linker's
4477 garbage collection decides to discard a .text.<foo> section it
4478 can then also discard the line number information in .debug_line.<foo>.
4480 Since the section is a fragment it does not have the details
4481 needed to fill out a LineInfo structure, so instead we use the
4482 details from the last full debug_line section that we processed. */
4483 end_of_sequence
= end
;
4484 standard_opcodes
= NULL
;
4485 linfo
= saved_linfo
;
4486 /* PR 17531: file: 0522b371. */
4487 if (linfo
.li_line_range
== 0)
4489 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4492 reset_state_machine (linfo
.li_default_is_stmt
);
4496 unsigned char * hdrptr
;
4498 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4499 & end_of_sequence
)) == NULL
)
4502 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4503 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4504 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4505 if (linfo
.li_version
>= 5)
4507 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4508 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4510 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4511 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4512 if (linfo
.li_version
>= 4)
4513 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4514 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4515 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4516 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4517 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4519 /* PR 17512: file: 1665-6428-0.004. */
4520 if (linfo
.li_line_range
== 0)
4522 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4523 linfo
.li_line_range
= 1;
4526 reset_state_machine (linfo
.li_default_is_stmt
);
4528 /* Display the contents of the Opcodes table. */
4529 standard_opcodes
= hdrptr
;
4531 /* PR 17512: file: 002-417945-0.004. */
4532 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4534 warn (_("Line Base extends beyond end of section\n"));
4538 printf (_("\n Opcodes:\n"));
4540 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4541 printf (ngettext (" Opcode %d has %d arg\n",
4542 " Opcode %d has %d args\n",
4543 standard_opcodes
[i
- 1]),
4544 i
, standard_opcodes
[i
- 1]);
4546 /* Display the contents of the Directory table. */
4547 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4549 if (linfo
.li_version
>= 5)
4551 load_debug_section_with_follow (line_str
, file
);
4553 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4555 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4561 printf (_("\n The Directory Table is empty.\n"));
4564 unsigned int last_dir_entry
= 0;
4566 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4567 (long)(data
- start
));
4569 while (data
< end
&& *data
!= 0)
4571 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4573 data
+= strnlen ((char *) data
, end
- data
);
4578 /* PR 17512: file: 002-132094-0.004. */
4579 if (data
>= end
- 1)
4583 /* Skip the NUL at the end of the table. */
4587 /* Display the contents of the File Name table. */
4588 if (data
>= end
|| *data
== 0)
4589 printf (_("\n The File Name Table is empty.\n"));
4592 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4593 (long)(data
- start
));
4594 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4596 while (data
< end
&& *data
!= 0)
4598 unsigned char *name
;
4601 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4603 data
+= strnlen ((char *) data
, end
- data
);
4607 READ_ULEB (val
, data
, end
);
4608 printf ("%s\t", dwarf_vmatoa ("u", val
));
4609 READ_ULEB (val
, data
, end
);
4610 printf ("%s\t", dwarf_vmatoa ("u", val
));
4611 READ_ULEB (val
, data
, end
);
4612 printf ("%s\t", dwarf_vmatoa ("u", val
));
4613 printf ("%.*s\n", (int)(end
- name
), name
);
4617 warn (_("Corrupt file name table entry\n"));
4623 /* Skip the NUL at the end of the table. */
4629 saved_linfo
= linfo
;
4632 /* Now display the statements. */
4633 if (data
>= end_of_sequence
)
4634 printf (_(" No Line Number Statements.\n"));
4637 printf (_(" Line Number Statements:\n"));
4639 while (data
< end_of_sequence
)
4641 unsigned char op_code
;
4642 dwarf_signed_vma adv
;
4645 printf (" [0x%08lx]", (long)(data
- start
));
4649 if (op_code
>= linfo
.li_opcode_base
)
4651 op_code
-= linfo
.li_opcode_base
;
4652 uladv
= (op_code
/ linfo
.li_line_range
);
4653 if (linfo
.li_max_ops_per_insn
== 1)
4655 uladv
*= linfo
.li_min_insn_length
;
4656 state_machine_regs
.address
+= uladv
;
4658 state_machine_regs
.view
= 0;
4659 printf (_(" Special opcode %d: "
4660 "advance Address by %s to 0x%s%s"),
4661 op_code
, dwarf_vmatoa ("u", uladv
),
4662 dwarf_vmatoa ("x", state_machine_regs
.address
),
4663 verbose_view
&& uladv
4664 ? _(" (reset view)") : "");
4669 = ((state_machine_regs
.op_index
+ uladv
)
4670 / linfo
.li_max_ops_per_insn
)
4671 * linfo
.li_min_insn_length
;
4673 state_machine_regs
.address
+= addrdelta
;
4674 state_machine_regs
.op_index
4675 = (state_machine_regs
.op_index
+ uladv
)
4676 % linfo
.li_max_ops_per_insn
;
4678 state_machine_regs
.view
= 0;
4679 printf (_(" Special opcode %d: "
4680 "advance Address by %s to 0x%s[%d]%s"),
4681 op_code
, dwarf_vmatoa ("u", uladv
),
4682 dwarf_vmatoa ("x", state_machine_regs
.address
),
4683 state_machine_regs
.op_index
,
4684 verbose_view
&& addrdelta
4685 ? _(" (reset view)") : "");
4687 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4688 state_machine_regs
.line
+= adv
;
4689 printf (_(" and Line by %s to %d"),
4690 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4691 if (verbose_view
|| state_machine_regs
.view
)
4692 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4695 state_machine_regs
.view
++;
4700 case DW_LNS_extended_op
:
4701 data
+= process_extended_line_op (data
,
4702 linfo
.li_default_is_stmt
,
4707 printf (_(" Copy"));
4708 if (verbose_view
|| state_machine_regs
.view
)
4709 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4712 state_machine_regs
.view
++;
4715 case DW_LNS_advance_pc
:
4716 READ_ULEB (uladv
, data
, end
);
4717 if (linfo
.li_max_ops_per_insn
== 1)
4719 uladv
*= linfo
.li_min_insn_length
;
4720 state_machine_regs
.address
+= uladv
;
4722 state_machine_regs
.view
= 0;
4723 printf (_(" Advance PC by %s to 0x%s%s\n"),
4724 dwarf_vmatoa ("u", uladv
),
4725 dwarf_vmatoa ("x", state_machine_regs
.address
),
4726 verbose_view
&& uladv
4727 ? _(" (reset view)") : "");
4732 = ((state_machine_regs
.op_index
+ uladv
)
4733 / linfo
.li_max_ops_per_insn
)
4734 * linfo
.li_min_insn_length
;
4735 state_machine_regs
.address
4737 state_machine_regs
.op_index
4738 = (state_machine_regs
.op_index
+ uladv
)
4739 % linfo
.li_max_ops_per_insn
;
4741 state_machine_regs
.view
= 0;
4742 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4743 dwarf_vmatoa ("u", uladv
),
4744 dwarf_vmatoa ("x", state_machine_regs
.address
),
4745 state_machine_regs
.op_index
,
4746 verbose_view
&& addrdelta
4747 ? _(" (reset view)") : "");
4751 case DW_LNS_advance_line
:
4752 READ_SLEB (adv
, data
, end
);
4753 state_machine_regs
.line
+= adv
;
4754 printf (_(" Advance Line by %s to %d\n"),
4755 dwarf_vmatoa ("d", adv
),
4756 state_machine_regs
.line
);
4759 case DW_LNS_set_file
:
4760 READ_ULEB (uladv
, data
, end
);
4761 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4762 dwarf_vmatoa ("u", uladv
));
4763 state_machine_regs
.file
= uladv
;
4766 case DW_LNS_set_column
:
4767 READ_ULEB (uladv
, data
, end
);
4768 printf (_(" Set column to %s\n"),
4769 dwarf_vmatoa ("u", uladv
));
4770 state_machine_regs
.column
= uladv
;
4773 case DW_LNS_negate_stmt
:
4774 adv
= state_machine_regs
.is_stmt
;
4776 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4777 state_machine_regs
.is_stmt
= adv
;
4780 case DW_LNS_set_basic_block
:
4781 printf (_(" Set basic block\n"));
4782 state_machine_regs
.basic_block
= 1;
4785 case DW_LNS_const_add_pc
:
4786 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4787 if (linfo
.li_max_ops_per_insn
)
4789 uladv
*= linfo
.li_min_insn_length
;
4790 state_machine_regs
.address
+= uladv
;
4792 state_machine_regs
.view
= 0;
4793 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4794 dwarf_vmatoa ("u", uladv
),
4795 dwarf_vmatoa ("x", state_machine_regs
.address
),
4796 verbose_view
&& uladv
4797 ? _(" (reset view)") : "");
4802 = ((state_machine_regs
.op_index
+ uladv
)
4803 / linfo
.li_max_ops_per_insn
)
4804 * linfo
.li_min_insn_length
;
4805 state_machine_regs
.address
4807 state_machine_regs
.op_index
4808 = (state_machine_regs
.op_index
+ uladv
)
4809 % linfo
.li_max_ops_per_insn
;
4811 state_machine_regs
.view
= 0;
4812 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4813 dwarf_vmatoa ("u", uladv
),
4814 dwarf_vmatoa ("x", state_machine_regs
.address
),
4815 state_machine_regs
.op_index
,
4816 verbose_view
&& addrdelta
4817 ? _(" (reset view)") : "");
4821 case DW_LNS_fixed_advance_pc
:
4822 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4823 state_machine_regs
.address
+= uladv
;
4824 state_machine_regs
.op_index
= 0;
4825 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4826 dwarf_vmatoa ("u", uladv
),
4827 dwarf_vmatoa ("x", state_machine_regs
.address
));
4828 /* Do NOT reset view. */
4831 case DW_LNS_set_prologue_end
:
4832 printf (_(" Set prologue_end to true\n"));
4835 case DW_LNS_set_epilogue_begin
:
4836 printf (_(" Set epilogue_begin to true\n"));
4839 case DW_LNS_set_isa
:
4840 READ_ULEB (uladv
, data
, end
);
4841 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4845 printf (_(" Unknown opcode %d with operands: "), op_code
);
4847 if (standard_opcodes
!= NULL
)
4848 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4850 READ_ULEB (uladv
, data
, end
);
4851 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4852 i
== 1 ? "" : ", ");
4867 unsigned char *name
;
4868 unsigned int directory_index
;
4869 unsigned int modification_date
;
4870 unsigned int length
;
4873 /* Output a decoded representation of the .debug_line section. */
4876 display_debug_lines_decoded (struct dwarf_section
* section
,
4877 unsigned char * start
,
4878 unsigned char * data
,
4879 unsigned char * end
,
4882 static DWARF2_Internal_LineInfo saved_linfo
;
4884 introduce (section
, false);
4888 /* This loop amounts to one iteration per compilation unit. */
4889 DWARF2_Internal_LineInfo linfo
;
4890 unsigned char *standard_opcodes
;
4891 unsigned char *end_of_sequence
;
4893 File_Entry
*file_table
= NULL
;
4894 unsigned int n_files
= 0;
4895 unsigned char **directory_table
= NULL
;
4896 dwarf_vma n_directories
= 0;
4898 if (startswith (section
->name
, ".debug_line.")
4899 /* Note: the following does not apply to .debug_line.dwo sections.
4900 These are full debug_line sections. */
4901 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4903 /* See comment in display_debug_lines_raw(). */
4904 end_of_sequence
= end
;
4905 standard_opcodes
= NULL
;
4906 linfo
= saved_linfo
;
4907 /* PR 17531: file: 0522b371. */
4908 if (linfo
.li_line_range
== 0)
4910 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4913 reset_state_machine (linfo
.li_default_is_stmt
);
4917 unsigned char *hdrptr
;
4919 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4920 & end_of_sequence
)) == NULL
)
4923 /* PR 17531: file: 0522b371. */
4924 if (linfo
.li_line_range
== 0)
4926 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4927 linfo
.li_line_range
= 1;
4929 reset_state_machine (linfo
.li_default_is_stmt
);
4931 /* Save a pointer to the contents of the Opcodes table. */
4932 standard_opcodes
= hdrptr
;
4934 /* Traverse the Directory table just to count entries. */
4935 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4939 warn (_("opcode base of %d extends beyond end of section\n"),
4940 linfo
.li_opcode_base
);
4944 if (linfo
.li_version
>= 5)
4946 unsigned char *format_start
, format_count
, *format
;
4947 dwarf_vma formati
, entryi
;
4949 load_debug_section_with_follow (line_str
, fileptr
);
4951 /* Skip directories format. */
4952 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4953 if (do_checks
&& format_count
> 1)
4954 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4956 format_start
= data
;
4957 for (formati
= 0; formati
< format_count
; formati
++)
4959 SKIP_ULEB (data
, end
);
4960 SKIP_ULEB (data
, end
);
4963 READ_ULEB (n_directories
, data
, end
);
4966 warn (_("Corrupt directories list\n"));
4970 if (n_directories
== 0)
4971 directory_table
= NULL
;
4973 directory_table
= (unsigned char **)
4974 xmalloc (n_directories
* sizeof (unsigned char *));
4976 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4978 unsigned char **pathp
= &directory_table
[entryi
];
4980 format
= format_start
;
4981 for (formati
= 0; formati
< format_count
; formati
++)
4983 dwarf_vma content_type
, form
;
4986 READ_ULEB (content_type
, format
, end
);
4987 READ_ULEB (form
, format
, end
);
4990 warn (_("Corrupt directories list\n"));
4993 switch (content_type
)
4998 case DW_FORM_string
:
5001 case DW_FORM_line_strp
:
5002 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5004 /* Remove const by the cast. */
5005 *pathp
= (unsigned char *)
5006 fetch_indirect_line_string (uvalue
);
5011 data
= read_and_display_attr_value (0, form
, 0, start
,
5013 linfo
.li_offset_size
,
5020 warn (_("Corrupt directories list\n"));
5025 /* Skip files format. */
5026 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
5027 if (do_checks
&& format_count
> 5)
5028 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
5030 format_start
= data
;
5031 for (formati
= 0; formati
< format_count
; formati
++)
5033 SKIP_ULEB (data
, end
);
5034 SKIP_ULEB (data
, end
);
5037 READ_ULEB (n_files
, data
, end
);
5038 if (data
>= end
&& n_files
> 0)
5040 warn (_("Corrupt file name list\n"));
5047 file_table
= (File_Entry
*) xcalloc (1, n_files
5048 * sizeof (File_Entry
));
5050 for (entryi
= 0; entryi
< n_files
; entryi
++)
5052 File_Entry
*file
= &file_table
[entryi
];
5054 format
= format_start
;
5055 for (formati
= 0; formati
< format_count
; formati
++)
5057 dwarf_vma content_type
, form
;
5061 READ_ULEB (content_type
, format
, end
);
5062 READ_ULEB (form
, format
, end
);
5065 warn (_("Corrupt file name list\n"));
5068 switch (content_type
)
5073 case DW_FORM_string
:
5076 case DW_FORM_line_strp
:
5077 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
5079 /* Remove const by the cast. */
5080 file
->name
= (unsigned char *)
5081 fetch_indirect_line_string (uvalue
);
5085 case DW_LNCT_directory_index
:
5089 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
5093 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
5098 READ_ULEB (file
->directory_index
, tmp
, end
);
5103 data
= read_and_display_attr_value (0, form
, 0, start
,
5105 linfo
.li_offset_size
,
5112 warn (_("Corrupt file name list\n"));
5121 unsigned char *ptr_directory_table
= data
;
5123 while (data
< end
&& *data
!= 0)
5125 data
+= strnlen ((char *) data
, end
- data
);
5134 warn (_("directory table ends unexpectedly\n"));
5139 /* Go through the directory table again to save the directories. */
5140 directory_table
= (unsigned char **)
5141 xmalloc (n_directories
* sizeof (unsigned char *));
5144 while (*ptr_directory_table
!= 0)
5146 directory_table
[i
] = ptr_directory_table
;
5148 += strlen ((char *) ptr_directory_table
) + 1;
5152 /* Skip the NUL at the end of the table. */
5155 /* Traverse the File Name table just to count the entries. */
5156 if (data
< end
&& *data
!= 0)
5158 unsigned char *ptr_file_name_table
= data
;
5160 while (data
< end
&& *data
!= 0)
5162 /* Skip Name, directory index, last modification
5163 time and length of file. */
5164 data
+= strnlen ((char *) data
, end
- data
);
5167 SKIP_ULEB (data
, end
);
5168 SKIP_ULEB (data
, end
);
5169 SKIP_ULEB (data
, end
);
5175 warn (_("file table ends unexpectedly\n"));
5180 /* Go through the file table again to save the strings. */
5181 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5184 while (*ptr_file_name_table
!= 0)
5186 file_table
[i
].name
= ptr_file_name_table
;
5188 += strlen ((char *) ptr_file_name_table
) + 1;
5190 /* We are not interested in directory, time or size. */
5191 READ_ULEB (file_table
[i
].directory_index
,
5192 ptr_file_name_table
, end
);
5193 READ_ULEB (file_table
[i
].modification_date
,
5194 ptr_file_name_table
, end
);
5195 READ_ULEB (file_table
[i
].length
,
5196 ptr_file_name_table
, end
);
5202 /* Skip the NUL at the end of the table. */
5206 /* Print the Compilation Unit's name and a header. */
5207 if (file_table
== NULL
)
5208 printf (_("CU: No directory table\n"));
5209 else if (directory_table
== NULL
)
5210 printf (_("CU: %s:\n"), file_table
[0].name
);
5213 unsigned int ix
= file_table
[0].directory_index
;
5214 const char *directory
;
5219 else if (n_directories
== 0)
5220 directory
= _("<unknown>");
5221 else if (ix
> n_directories
)
5223 warn (_("directory index %u > number of directories %s\n"),
5224 ix
, dwarf_vmatoa ("u", n_directories
));
5225 directory
= _("<corrupt>");
5228 directory
= (char *) directory_table
[ix
- 1];
5231 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5233 printf ("%s:\n", file_table
[0].name
);
5237 printf (_("File name Line number Starting address View Stmt\n"));
5239 printf (_("CU: Empty file name table\n"));
5240 saved_linfo
= linfo
;
5243 /* This loop iterates through the Dwarf Line Number Program. */
5244 while (data
< end_of_sequence
)
5246 unsigned char op_code
;
5249 unsigned long int uladv
;
5250 int is_special_opcode
= 0;
5255 if (op_code
>= linfo
.li_opcode_base
)
5257 op_code
-= linfo
.li_opcode_base
;
5258 uladv
= (op_code
/ linfo
.li_line_range
);
5259 if (linfo
.li_max_ops_per_insn
== 1)
5261 uladv
*= linfo
.li_min_insn_length
;
5262 state_machine_regs
.address
+= uladv
;
5264 state_machine_regs
.view
= 0;
5269 = ((state_machine_regs
.op_index
+ uladv
)
5270 / linfo
.li_max_ops_per_insn
)
5271 * linfo
.li_min_insn_length
;
5272 state_machine_regs
.address
5274 state_machine_regs
.op_index
5275 = (state_machine_regs
.op_index
+ uladv
)
5276 % linfo
.li_max_ops_per_insn
;
5278 state_machine_regs
.view
= 0;
5281 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5282 state_machine_regs
.line
+= adv
;
5283 is_special_opcode
= 1;
5284 /* Increment view after printing this row. */
5289 case DW_LNS_extended_op
:
5291 unsigned int ext_op_code_len
;
5292 unsigned char ext_op_code
;
5293 unsigned char *op_code_end
;
5294 unsigned char *op_code_data
= data
;
5296 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5297 op_code_end
= op_code_data
+ ext_op_code_len
;
5298 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5300 warn (_("Badly formed extended line op encountered!\n"));
5303 ext_op_code
= *op_code_data
++;
5307 switch (ext_op_code
)
5309 case DW_LNE_end_sequence
:
5310 /* Reset stuff after printing this row. */
5312 case DW_LNE_set_address
:
5313 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5315 op_code_end
- op_code_data
,
5317 state_machine_regs
.op_index
= 0;
5318 state_machine_regs
.view
= 0;
5320 case DW_LNE_define_file
:
5321 file_table
= (File_Entry
*) xrealloc
5322 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5324 ++state_machine_regs
.last_file_entry
;
5325 /* Source file name. */
5326 file_table
[n_files
].name
= op_code_data
;
5327 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5328 /* Directory index. */
5329 READ_ULEB (file_table
[n_files
].directory_index
,
5330 op_code_data
, op_code_end
);
5331 /* Last modification time. */
5332 READ_ULEB (file_table
[n_files
].modification_date
,
5333 op_code_data
, op_code_end
);
5335 READ_ULEB (file_table
[n_files
].length
,
5336 op_code_data
, op_code_end
);
5340 case DW_LNE_set_discriminator
:
5341 case DW_LNE_HP_set_sequence
:
5342 /* Simply ignored. */
5346 printf (_("UNKNOWN (%u): length %ld\n"),
5347 ext_op_code
, (long int) (op_code_data
- data
));
5354 /* Increment view after printing this row. */
5357 case DW_LNS_advance_pc
:
5358 READ_ULEB (uladv
, data
, end
);
5359 if (linfo
.li_max_ops_per_insn
== 1)
5361 uladv
*= linfo
.li_min_insn_length
;
5362 state_machine_regs
.address
+= uladv
;
5364 state_machine_regs
.view
= 0;
5369 = ((state_machine_regs
.op_index
+ uladv
)
5370 / linfo
.li_max_ops_per_insn
)
5371 * linfo
.li_min_insn_length
;
5372 state_machine_regs
.address
5374 state_machine_regs
.op_index
5375 = (state_machine_regs
.op_index
+ uladv
)
5376 % linfo
.li_max_ops_per_insn
;
5378 state_machine_regs
.view
= 0;
5382 case DW_LNS_advance_line
:
5383 READ_SLEB (adv
, data
, end
);
5384 state_machine_regs
.line
+= adv
;
5387 case DW_LNS_set_file
:
5388 READ_ULEB (uladv
, data
, end
);
5389 state_machine_regs
.file
= uladv
;
5392 unsigned file
= state_machine_regs
.file
;
5395 if (linfo
.li_version
< 5)
5397 if (file_table
== NULL
|| n_files
== 0)
5398 printf (_("\n [Use file table entry %d]\n"), file
);
5400 else if (file
>= n_files
)
5402 warn (_("file index %u > number of files %u\n"), file
, n_files
);
5403 printf (_("\n <over large file table index %u>"), file
);
5405 else if ((dir
= file_table
[file
].directory_index
) == 0)
5406 /* If directory index is 0, that means current directory. */
5407 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5408 else if (directory_table
== NULL
|| n_directories
== 0)
5409 printf (_("\n [Use file %s in directory table entry %d]\n"),
5410 file_table
[file
].name
, dir
);
5412 else if (dir
> n_directories
)
5414 warn (_("directory index %u > number of directories %s\n"),
5415 dir
, dwarf_vmatoa ("u", n_directories
));
5416 printf (_("\n <over large directory table entry %u>\n"), dir
);
5419 printf ("\n%s/%s:\n",
5420 /* The directory index starts counting at 1. */
5421 directory_table
[dir
- 1], file_table
[file
].name
);
5425 case DW_LNS_set_column
:
5426 READ_ULEB (uladv
, data
, end
);
5427 state_machine_regs
.column
= uladv
;
5430 case DW_LNS_negate_stmt
:
5431 adv
= state_machine_regs
.is_stmt
;
5433 state_machine_regs
.is_stmt
= adv
;
5436 case DW_LNS_set_basic_block
:
5437 state_machine_regs
.basic_block
= 1;
5440 case DW_LNS_const_add_pc
:
5441 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5442 if (linfo
.li_max_ops_per_insn
== 1)
5444 uladv
*= linfo
.li_min_insn_length
;
5445 state_machine_regs
.address
+= uladv
;
5447 state_machine_regs
.view
= 0;
5452 = ((state_machine_regs
.op_index
+ uladv
)
5453 / linfo
.li_max_ops_per_insn
)
5454 * linfo
.li_min_insn_length
;
5455 state_machine_regs
.address
5457 state_machine_regs
.op_index
5458 = (state_machine_regs
.op_index
+ uladv
)
5459 % linfo
.li_max_ops_per_insn
;
5461 state_machine_regs
.view
= 0;
5465 case DW_LNS_fixed_advance_pc
:
5466 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5467 state_machine_regs
.address
+= uladv
;
5468 state_machine_regs
.op_index
= 0;
5469 /* Do NOT reset view. */
5472 case DW_LNS_set_prologue_end
:
5475 case DW_LNS_set_epilogue_begin
:
5478 case DW_LNS_set_isa
:
5479 READ_ULEB (uladv
, data
, end
);
5480 printf (_(" Set ISA to %lu\n"), uladv
);
5484 printf (_(" Unknown opcode %d with operands: "), op_code
);
5486 if (standard_opcodes
!= NULL
)
5487 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5491 READ_ULEB (val
, data
, end
);
5492 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5493 i
== 1 ? "" : ", ");
5499 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5500 to the DWARF address/line matrix. */
5501 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5502 || (xop
== DW_LNS_copy
))
5504 const unsigned int MAX_FILENAME_LENGTH
= 35;
5506 char *newFileName
= NULL
;
5507 size_t fileNameLength
;
5511 unsigned indx
= state_machine_regs
.file
;
5513 if (linfo
.li_version
< 5)
5516 if (indx
>= n_files
)
5518 warn (_("corrupt file index %u encountered\n"), indx
);
5519 fileName
= _("<corrupt>");
5522 fileName
= (char *) file_table
[indx
].name
;
5525 fileName
= _("<unknown>");
5527 fileNameLength
= strlen (fileName
);
5528 newFileName
= fileName
;
5529 if (fileNameLength
> MAX_FILENAME_LENGTH
&& !do_wide
)
5531 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5532 /* Truncate file name */
5533 memcpy (newFileName
,
5534 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5535 MAX_FILENAME_LENGTH
);
5536 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5539 /* A row with end_seq set to true has a meaningful address, but
5540 the other information in the same row is not significant.
5541 In such a row, print line as "-", and don't print
5543 if (!do_wide
|| fileNameLength
<= MAX_FILENAME_LENGTH
)
5545 if (linfo
.li_max_ops_per_insn
== 1)
5547 if (xop
== -DW_LNE_end_sequence
)
5548 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5550 state_machine_regs
.address
);
5552 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5553 newFileName
, state_machine_regs
.line
,
5554 state_machine_regs
.address
);
5558 if (xop
== -DW_LNE_end_sequence
)
5559 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5561 state_machine_regs
.address
,
5562 state_machine_regs
.op_index
);
5564 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5565 newFileName
, state_machine_regs
.line
,
5566 state_machine_regs
.address
,
5567 state_machine_regs
.op_index
);
5572 if (linfo
.li_max_ops_per_insn
== 1)
5574 if (xop
== -DW_LNE_end_sequence
)
5575 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5577 state_machine_regs
.address
);
5579 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5580 newFileName
, state_machine_regs
.line
,
5581 state_machine_regs
.address
);
5585 if (xop
== -DW_LNE_end_sequence
)
5586 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5588 state_machine_regs
.address
,
5589 state_machine_regs
.op_index
);
5591 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5592 newFileName
, state_machine_regs
.line
,
5593 state_machine_regs
.address
,
5594 state_machine_regs
.op_index
);
5598 if (xop
!= -DW_LNE_end_sequence
)
5600 if (state_machine_regs
.view
)
5601 printf (" %6u", state_machine_regs
.view
);
5605 if (state_machine_regs
.is_stmt
)
5610 state_machine_regs
.view
++;
5612 if (xop
== -DW_LNE_end_sequence
)
5614 reset_state_machine (linfo
.li_default_is_stmt
);
5618 if (newFileName
!= fileName
)
5630 if (directory_table
)
5632 free (directory_table
);
5633 directory_table
= NULL
;
5644 display_debug_lines (struct dwarf_section
*section
, void *file
)
5646 unsigned char *data
= section
->start
;
5647 unsigned char *end
= data
+ section
->size
;
5649 int retValDecoded
= 1;
5651 if (do_debug_lines
== 0)
5652 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5654 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5655 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5657 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5658 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5660 if (!retValRaw
|| !retValDecoded
)
5667 find_debug_info_for_offset (dwarf_vma offset
)
5671 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5674 for (i
= 0; i
< num_debug_info_entries
; i
++)
5675 if (debug_information
[i
].cu_offset
== offset
)
5676 return debug_information
+ i
;
5682 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5684 /* See gdb/gdb-index.h. */
5685 static const char * const kinds
[] =
5697 return _ (kinds
[kind
]);
5701 display_debug_pubnames_worker (struct dwarf_section
*section
,
5702 void *file ATTRIBUTE_UNUSED
,
5705 DWARF2_Internal_PubNames names
;
5706 unsigned char *start
= section
->start
;
5707 unsigned char *end
= start
+ section
->size
;
5709 /* It does not matter if this load fails,
5710 we test for that later on. */
5711 load_debug_info (file
);
5713 introduce (section
, false);
5717 unsigned char *data
;
5718 unsigned long sec_off
= start
- section
->start
;
5719 unsigned int offset_size
;
5721 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5722 if (names
.pn_length
== 0xffffffff)
5724 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5730 if (names
.pn_length
> (size_t) (end
- start
))
5732 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5735 dwarf_vmatoa ("x", names
.pn_length
));
5740 start
+= names
.pn_length
;
5742 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, start
);
5743 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, start
);
5745 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5746 && num_debug_info_entries
> 0
5747 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5748 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5749 (unsigned long) names
.pn_offset
, section
->name
);
5751 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, start
);
5753 printf (_(" Length: %ld\n"),
5754 (long) names
.pn_length
);
5755 printf (_(" Version: %d\n"),
5757 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5758 (unsigned long) names
.pn_offset
);
5759 printf (_(" Size of area in .debug_info section: %ld\n"),
5760 (long) names
.pn_size
);
5762 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5764 static int warned
= 0;
5768 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5776 printf (_("\n Offset Kind Name\n"));
5778 printf (_("\n Offset\tName\n"));
5782 bfd_size_type maxprint
;
5785 SAFE_BYTE_GET_AND_INC (offset
, data
, offset_size
, start
);
5792 maxprint
= (start
- data
) - 1;
5796 unsigned int kind_data
;
5797 gdb_index_symbol_kind kind
;
5798 const char *kind_name
;
5801 SAFE_BYTE_GET_AND_INC (kind_data
, data
, 1, start
);
5803 /* GCC computes the kind as the upper byte in the CU index
5804 word, and then right shifts it by the CU index size.
5805 Left shift KIND to where the gdb-index.h accessor macros
5807 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5808 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5809 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5810 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5811 printf (" %-6lx %s,%-10s %.*s\n",
5812 (unsigned long) offset
, is_static
? _("s") : _("g"),
5813 kind_name
, (int) maxprint
, data
);
5816 printf (" %-6lx\t%.*s\n",
5817 (unsigned long) offset
, (int) maxprint
, data
);
5819 data
+= strnlen ((char *) data
, maxprint
);
5832 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5834 return display_debug_pubnames_worker (section
, file
, 0);
5838 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5840 return display_debug_pubnames_worker (section
, file
, 1);
5844 display_debug_macinfo (struct dwarf_section
*section
,
5845 void *file ATTRIBUTE_UNUSED
)
5847 unsigned char *start
= section
->start
;
5848 unsigned char *end
= start
+ section
->size
;
5849 unsigned char *curr
= start
;
5850 enum dwarf_macinfo_record_type op
;
5852 introduce (section
, false);
5856 unsigned int lineno
;
5857 const unsigned char *string
;
5859 op
= (enum dwarf_macinfo_record_type
) *curr
;
5864 case DW_MACINFO_start_file
:
5866 unsigned int filenum
;
5868 READ_ULEB (lineno
, curr
, end
);
5869 READ_ULEB (filenum
, curr
, end
);
5870 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5875 case DW_MACINFO_end_file
:
5876 printf (_(" DW_MACINFO_end_file\n"));
5879 case DW_MACINFO_define
:
5880 READ_ULEB (lineno
, curr
, end
);
5882 curr
+= strnlen ((char *) string
, end
- string
);
5883 printf (_(" DW_MACINFO_define - lineno : %d macro : %*s\n"),
5884 lineno
, (int) (curr
- string
), string
);
5889 case DW_MACINFO_undef
:
5890 READ_ULEB (lineno
, curr
, end
);
5892 curr
+= strnlen ((char *) string
, end
- string
);
5893 printf (_(" DW_MACINFO_undef - lineno : %d macro : %*s\n"),
5894 lineno
, (int) (curr
- string
), string
);
5899 case DW_MACINFO_vendor_ext
:
5901 unsigned int constant
;
5903 READ_ULEB (constant
, curr
, end
);
5905 curr
+= strnlen ((char *) string
, end
- string
);
5906 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %*s\n"),
5907 constant
, (int) (curr
- string
), string
);
5918 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5919 filename and dirname corresponding to file name table entry with index
5920 FILEIDX. Return NULL on failure. */
5922 static unsigned char *
5923 get_line_filename_and_dirname (dwarf_vma line_offset
,
5925 unsigned char **dir_name
)
5927 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5928 unsigned char *hdrptr
, *dirtable
, *file_name
;
5929 unsigned int offset_size
;
5930 unsigned int version
, opcode_base
;
5931 dwarf_vma length
, diridx
;
5932 const unsigned char * end
;
5935 if (section
->start
== NULL
5936 || line_offset
>= section
->size
5940 hdrptr
= section
->start
+ line_offset
;
5941 end
= section
->start
+ section
->size
;
5943 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5944 if (length
== 0xffffffff)
5946 /* This section is 64-bit DWARF 3. */
5947 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5953 if (length
> (size_t) (end
- hdrptr
)
5954 || length
< 2 + offset_size
+ 1 + 3 + 1)
5956 end
= hdrptr
+ length
;
5958 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5959 if (version
!= 2 && version
!= 3 && version
!= 4)
5961 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5963 hdrptr
++; /* Skip max_ops_per_insn. */
5964 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5966 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5967 if (opcode_base
== 0
5968 || opcode_base
- 1 >= (size_t) (end
- hdrptr
))
5971 hdrptr
+= opcode_base
- 1;
5974 /* Skip over dirname table. */
5975 while (*hdrptr
!= '\0')
5977 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5983 hdrptr
++; /* Skip the NUL at the end of the table. */
5985 /* Now skip over preceding filename table entries. */
5986 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5988 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
5991 SKIP_ULEB (hdrptr
, end
);
5992 SKIP_ULEB (hdrptr
, end
);
5993 SKIP_ULEB (hdrptr
, end
);
5995 if (hdrptr
>= end
|| *hdrptr
== '\0')
5999 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
);
6004 READ_ULEB (diridx
, hdrptr
, end
);
6007 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
6009 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
);
6013 if (dirtable
>= end
|| *dirtable
== '\0')
6015 *dir_name
= dirtable
;
6020 display_debug_macro (struct dwarf_section
*section
,
6023 unsigned char *start
= section
->start
;
6024 unsigned char *end
= start
+ section
->size
;
6025 unsigned char *curr
= start
;
6026 unsigned char *extended_op_buf
[256];
6027 bool is_dwo
= false;
6028 const char *suffix
= strrchr (section
->name
, '.');
6030 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6033 load_debug_section_with_follow (str
, file
);
6034 load_debug_section_with_follow (line
, file
);
6035 load_debug_section_with_follow (str_index
, file
);
6037 introduce (section
, false);
6041 unsigned int lineno
, version
, flags
;
6042 unsigned int offset_size
;
6043 const unsigned char *string
;
6044 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
6045 unsigned char **extended_ops
= NULL
;
6047 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
6048 if (version
!= 4 && version
!= 5)
6050 error (_("Expected to find a version number of 4 or 5 in section %s but found %d instead\n"),
6051 section
->name
, version
);
6055 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
6056 offset_size
= (flags
& 1) ? 8 : 4;
6057 printf (_(" Offset: 0x%lx\n"),
6058 (unsigned long) sec_offset
);
6059 printf (_(" Version: %d\n"), version
);
6060 printf (_(" Offset size: %d\n"), offset_size
);
6063 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
6064 printf (_(" Offset into .debug_line: 0x%lx\n"),
6065 (unsigned long) line_offset
);
6069 unsigned int i
, count
, op
;
6072 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
6074 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
6075 extended_ops
= extended_op_buf
;
6078 printf (_(" Extension opcode arguments:\n"));
6079 for (i
= 0; i
< count
; i
++)
6081 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6082 extended_ops
[op
] = curr
;
6083 READ_ULEB (nargs
, curr
, end
);
6085 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
6088 printf (_(" DW_MACRO_%02x arguments: "), op
);
6089 for (n
= 0; n
< nargs
; n
++)
6093 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
6094 printf ("%s%s", get_FORM_name (form
),
6095 n
== nargs
- 1 ? "\n" : ", ");
6105 case DW_FORM_block1
:
6106 case DW_FORM_block2
:
6107 case DW_FORM_block4
:
6109 case DW_FORM_string
:
6111 case DW_FORM_sec_offset
:
6114 error (_("Invalid extension opcode form %s\n"),
6115 get_FORM_name (form
));
6131 error (_(".debug_macro section not zero terminated\n"));
6135 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
6141 case DW_MACRO_define
:
6142 READ_ULEB (lineno
, curr
, end
);
6144 curr
+= strnlen ((char *) string
, end
- string
);
6145 printf (_(" DW_MACRO_define - lineno : %d macro : %*s\n"),
6146 lineno
, (int) (curr
- string
), string
);
6151 case DW_MACRO_undef
:
6152 READ_ULEB (lineno
, curr
, end
);
6154 curr
+= strnlen ((char *) string
, end
- string
);
6155 printf (_(" DW_MACRO_undef - lineno : %d macro : %*s\n"),
6156 lineno
, (int) (curr
- string
), string
);
6161 case DW_MACRO_start_file
:
6163 unsigned int filenum
;
6164 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6166 READ_ULEB (lineno
, curr
, end
);
6167 READ_ULEB (filenum
, curr
, end
);
6169 if ((flags
& 2) == 0)
6170 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6173 = get_line_filename_and_dirname (line_offset
, filenum
,
6175 if (file_name
== NULL
)
6176 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6179 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6181 dir_name
!= NULL
? (const char *) dir_name
: "",
6182 dir_name
!= NULL
? "/" : "", file_name
);
6186 case DW_MACRO_end_file
:
6187 printf (_(" DW_MACRO_end_file\n"));
6190 case DW_MACRO_define_strp
:
6191 READ_ULEB (lineno
, curr
, end
);
6192 if (version
== 4 && is_dwo
)
6193 READ_ULEB (offset
, curr
, end
);
6195 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6196 string
= fetch_indirect_string (offset
);
6197 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6201 case DW_MACRO_undef_strp
:
6202 READ_ULEB (lineno
, curr
, end
);
6203 if (version
== 4 && is_dwo
)
6204 READ_ULEB (offset
, curr
, end
);
6206 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6207 string
= fetch_indirect_string (offset
);
6208 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6212 case DW_MACRO_import
:
6213 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6214 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6215 (unsigned long) offset
);
6218 case DW_MACRO_define_sup
:
6219 READ_ULEB (lineno
, curr
, end
);
6220 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6221 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6222 lineno
, (unsigned long) offset
);
6225 case DW_MACRO_undef_sup
:
6226 READ_ULEB (lineno
, curr
, end
);
6227 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6228 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6229 lineno
, (unsigned long) offset
);
6232 case DW_MACRO_import_sup
:
6233 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6234 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6235 (unsigned long) offset
);
6238 case DW_MACRO_define_strx
:
6239 case DW_MACRO_undef_strx
:
6240 READ_ULEB (lineno
, curr
, end
);
6241 READ_ULEB (offset
, curr
, end
);
6242 string
= (const unsigned char *)
6243 fetch_indexed_string (offset
, NULL
, offset_size
, false);
6244 if (op
== DW_MACRO_define_strx
)
6245 printf (" DW_MACRO_define_strx ");
6247 printf (" DW_MACRO_undef_strx ");
6249 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6250 printf (_("lineno : %d macro : %s\n"),
6255 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6257 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6261 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6263 error (_(" Unknown macro opcode %02x seen\n"), op
);
6268 /* Skip over unhandled opcodes. */
6270 unsigned char *desc
= extended_ops
[op
];
6271 READ_ULEB (nargs
, desc
, end
);
6274 printf (_(" DW_MACRO_%02x\n"), op
);
6277 printf (_(" DW_MACRO_%02x -"), op
);
6278 for (n
= 0; n
< nargs
; n
++)
6282 /* DW_FORM_implicit_const is not expected here. */
6283 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6285 = read_and_display_attr_value (0, val
, 0,
6286 start
, curr
, end
, 0, 0,
6287 offset_size
, version
,
6306 display_debug_abbrev (struct dwarf_section
*section
,
6307 void *file ATTRIBUTE_UNUSED
)
6309 abbrev_entry
*entry
;
6310 unsigned char *start
= section
->start
;
6312 introduce (section
, false);
6319 offset
= start
- section
->start
;
6320 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6323 list
= new_abbrev_list (0, offset
);
6324 start
= process_abbrev_set (section
, 0, section
->size
, offset
, list
);
6325 list
->start_of_next_abbrevs
= start
;
6328 start
= list
->start_of_next_abbrevs
;
6330 if (list
->first_abbrev
== NULL
)
6333 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6335 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6339 printf (" %ld %s [%s]\n",
6341 get_TAG_name (entry
->tag
),
6342 entry
->children
? _("has children") : _("no children"));
6344 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6346 printf (" %-18s %s",
6347 get_AT_name (attr
->attribute
),
6348 get_FORM_name (attr
->form
));
6349 if (attr
->form
== DW_FORM_implicit_const
)
6350 printf (": %s", dwarf_vmatoa ("d", attr
->implicit_const
));
6362 /* Return true when ADDR is the maximum address, when addresses are
6363 POINTER_SIZE bytes long. */
6366 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6368 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6369 return ((addr
& mask
) == mask
);
6372 /* Display a view pair list starting at *VSTART_PTR and ending at
6373 VLISTEND within SECTION. */
6376 display_view_pair_list (struct dwarf_section
*section
,
6377 unsigned char **vstart_ptr
,
6378 unsigned int debug_info_entry
,
6379 unsigned char *vlistend
)
6381 unsigned char *vstart
= *vstart_ptr
;
6382 unsigned char *section_end
= section
->start
+ section
->size
;
6383 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6385 if (vlistend
< section_end
)
6386 section_end
= vlistend
;
6390 while (vstart
< section_end
)
6392 dwarf_vma off
= vstart
- section
->start
;
6393 dwarf_vma vbegin
, vend
;
6395 READ_ULEB (vbegin
, vstart
, section_end
);
6396 if (vstart
== section_end
)
6399 READ_ULEB (vend
, vstart
, section_end
);
6400 printf (" %8.8lx ", (unsigned long) off
);
6402 print_dwarf_view (vbegin
, pointer_size
, 1);
6403 print_dwarf_view (vend
, pointer_size
, 1);
6404 printf (_("location view pair\n"));
6408 *vstart_ptr
= vstart
;
6411 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6414 display_loc_list (struct dwarf_section
*section
,
6415 unsigned char **start_ptr
,
6416 unsigned int debug_info_entry
,
6418 dwarf_vma base_address
,
6419 unsigned char **vstart_ptr
,
6422 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6423 unsigned char *section_end
= section
->start
+ section
->size
;
6424 dwarf_vma cu_offset
;
6425 unsigned int pointer_size
;
6426 unsigned int offset_size
;
6430 unsigned short length
;
6431 int need_frame_base
;
6433 if (debug_info_entry
>= num_debug_info_entries
)
6435 warn (_("No debug information available for loc lists of entry: %u\n"),
6440 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6441 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6442 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6443 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6445 if (pointer_size
< 2 || pointer_size
> 8)
6447 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6448 pointer_size
, debug_info_entry
);
6454 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6455 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6457 if (2 * pointer_size
> (size_t) (section_end
- start
))
6459 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6460 (unsigned long) offset
);
6465 print_dwarf_vma (off
, 4);
6467 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6468 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6470 if (begin
== 0 && end
== 0)
6472 /* PR 18374: In a object file we can have a location list that
6473 starts with a begin and end of 0 because there are relocations
6474 that need to be applied to the addresses. Actually applying
6475 the relocations now does not help as they will probably resolve
6476 to 0, since the object file has not been fully linked. Real
6477 end of list markers will not have any relocations against them. */
6478 if (! reloc_at (section
, off
)
6479 && ! reloc_at (section
, off
+ pointer_size
))
6481 printf (_("<End of list>\n"));
6486 /* Check base address specifiers. */
6487 if (is_max_address (begin
, pointer_size
)
6488 && !is_max_address (end
, pointer_size
))
6491 print_dwarf_vma (begin
, pointer_size
);
6492 print_dwarf_vma (end
, pointer_size
);
6493 printf (_("(base address)\n"));
6499 off
= offset
+ (vstart
- *start_ptr
);
6501 READ_ULEB (vbegin
, vstart
, section_end
);
6502 print_dwarf_view (vbegin
, pointer_size
, 1);
6504 READ_ULEB (vend
, vstart
, section_end
);
6505 print_dwarf_view (vend
, pointer_size
, 1);
6507 printf (_("views at %8.8lx for:\n %*s "),
6508 (unsigned long) off
, 8, "");
6511 if (2 > (size_t) (section_end
- start
))
6513 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6514 (unsigned long) offset
);
6518 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6520 if (length
> (size_t) (section_end
- start
))
6522 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6523 (unsigned long) offset
);
6527 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6528 print_dwarf_vma (end
+ base_address
, pointer_size
);
6531 need_frame_base
= decode_location_expression (start
,
6536 cu_offset
, section
);
6539 if (need_frame_base
&& !has_frame_base
)
6540 printf (_(" [without DW_AT_frame_base]"));
6542 if (begin
== end
&& vbegin
== vend
)
6543 fputs (_(" (start == end)"), stdout
);
6544 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6545 fputs (_(" (start > end)"), stdout
);
6553 *vstart_ptr
= vstart
;
6556 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6559 display_loclists_list (struct dwarf_section
* section
,
6560 unsigned char ** start_ptr
,
6561 unsigned int debug_info_entry
,
6563 dwarf_vma base_address
,
6564 unsigned char ** vstart_ptr
,
6567 unsigned char * start
= *start_ptr
;
6568 unsigned char * vstart
= *vstart_ptr
;
6569 unsigned char * section_end
= section
->start
+ section
->size
;
6570 dwarf_vma cu_offset
;
6571 unsigned int pointer_size
;
6572 unsigned int offset_size
;
6573 unsigned int dwarf_version
;
6575 /* Initialize it due to a false compiler warning. */
6576 dwarf_vma begin
= -1, vbegin
= -1;
6577 dwarf_vma end
= -1, vend
= -1;
6579 int need_frame_base
;
6581 if (debug_info_entry
>= num_debug_info_entries
)
6583 warn (_("No debug information available for "
6584 "loclists lists of entry: %u\n"),
6589 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6590 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6591 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6592 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6594 if (pointer_size
< 2 || pointer_size
> 8)
6596 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6597 pointer_size
, debug_info_entry
);
6603 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6604 enum dwarf_location_list_entry_type llet
;
6606 if (start
+ 1 > section_end
)
6608 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6609 (unsigned long) offset
);
6614 print_dwarf_vma (off
, 4);
6616 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6618 if (vstart
&& (llet
== DW_LLE_offset_pair
6619 || llet
== DW_LLE_start_end
6620 || llet
== DW_LLE_start_length
))
6622 off
= offset
+ (vstart
- *start_ptr
);
6624 READ_ULEB (vbegin
, vstart
, section_end
);
6625 print_dwarf_view (vbegin
, pointer_size
, 1);
6627 READ_ULEB (vend
, vstart
, section_end
);
6628 print_dwarf_view (vend
, pointer_size
, 1);
6630 printf (_("views at %8.8lx for:\n %*s "),
6631 (unsigned long) off
, 8, "");
6636 case DW_LLE_end_of_list
:
6637 printf (_("<End of list>\n"));
6640 case DW_LLE_base_addressx
:
6641 READ_ULEB (base_address
, start
, section_end
);
6642 print_dwarf_vma (base_address
, pointer_size
);
6643 printf (_("(index into .debug_addr) "));
6644 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
6645 print_dwarf_vma (base_address
, pointer_size
);
6646 printf (_("(base address)\n"));
6649 case DW_LLE_startx_endx
:
6650 READ_ULEB (begin
, start
, section_end
);
6651 begin
= fetch_indexed_addr (begin
, pointer_size
);
6652 READ_ULEB (end
, start
, section_end
);
6653 end
= fetch_indexed_addr (end
, pointer_size
);
6656 case DW_LLE_startx_length
:
6657 READ_ULEB (begin
, start
, section_end
);
6658 begin
= fetch_indexed_addr (begin
, pointer_size
);
6659 READ_ULEB (end
, start
, section_end
);
6663 case DW_LLE_default_location
:
6667 case DW_LLE_offset_pair
:
6668 READ_ULEB (begin
, start
, section_end
);
6669 begin
+= base_address
;
6670 READ_ULEB (end
, start
, section_end
);
6671 end
+= base_address
;
6674 case DW_LLE_base_address
:
6675 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6677 print_dwarf_vma (base_address
, pointer_size
);
6678 printf (_("(base address)\n"));
6681 case DW_LLE_start_end
:
6682 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6683 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6686 case DW_LLE_start_length
:
6687 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6688 READ_ULEB (end
, start
, section_end
);
6692 #ifdef DW_LLE_view_pair
6693 case DW_LLE_view_pair
:
6695 printf (_("View pair entry in loclist with locviews attribute\n"));
6696 READ_ULEB (vbegin
, start
, section_end
);
6697 print_dwarf_view (vbegin
, pointer_size
, 1);
6699 READ_ULEB (vend
, start
, section_end
);
6700 print_dwarf_view (vend
, pointer_size
, 1);
6702 printf (_("views for:\n"));
6707 error (_("Invalid location list entry type %d\n"), llet
);
6711 if (llet
== DW_LLE_end_of_list
)
6714 if (llet
== DW_LLE_base_address
6715 || llet
== DW_LLE_base_addressx
)
6718 if (start
== section_end
)
6720 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6721 (unsigned long) offset
);
6724 READ_ULEB (length
, start
, section_end
);
6726 if (length
> (size_t) (section_end
- start
))
6728 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6729 (unsigned long) offset
);
6733 print_dwarf_vma (begin
, pointer_size
);
6734 print_dwarf_vma (end
, pointer_size
);
6737 need_frame_base
= decode_location_expression (start
,
6742 cu_offset
, section
);
6745 if (need_frame_base
&& !has_frame_base
)
6746 printf (_(" [without DW_AT_frame_base]"));
6748 if (begin
== end
&& vbegin
== vend
)
6749 fputs (_(" (start == end)"), stdout
);
6750 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6751 fputs (_(" (start > end)"), stdout
);
6759 if (vbegin
!= vm1
|| vend
!= vm1
)
6760 printf (_("Trailing view pair not used in a range"));
6763 *vstart_ptr
= vstart
;
6766 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6767 right-adjusted in a field of length LEN, and followed by a space. */
6770 print_addr_index (unsigned int idx
, unsigned int len
)
6772 static char buf
[15];
6773 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6774 printf ("%*s ", len
, buf
);
6777 /* Display a location list from a .dwo section. It uses address indexes rather
6778 than embedded addresses. This code closely follows display_loc_list, but the
6779 two are sufficiently different that combining things is very ugly. */
6782 display_loc_list_dwo (struct dwarf_section
*section
,
6783 unsigned char **start_ptr
,
6784 unsigned int debug_info_entry
,
6786 unsigned char **vstart_ptr
,
6789 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6790 unsigned char *section_end
= section
->start
+ section
->size
;
6791 dwarf_vma cu_offset
;
6792 unsigned int pointer_size
;
6793 unsigned int offset_size
;
6796 unsigned short length
;
6797 int need_frame_base
;
6800 if (debug_info_entry
>= num_debug_info_entries
)
6802 warn (_("No debug information for loc lists of entry: %u\n"),
6807 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6808 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6809 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6810 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6812 if (pointer_size
< 2 || pointer_size
> 8)
6814 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6815 pointer_size
, debug_info_entry
);
6822 print_dwarf_vma (offset
+ (start
- *start_ptr
), 4);
6824 if (start
>= section_end
)
6826 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6827 (unsigned long) offset
);
6831 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6844 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6846 READ_ULEB (view
, vstart
, section_end
);
6847 print_dwarf_view (view
, 8, 1);
6849 READ_ULEB (view
, vstart
, section_end
);
6850 print_dwarf_view (view
, 8, 1);
6852 printf (_("views at %8.8lx for:\n %*s "),
6853 (unsigned long) off
, 8, "");
6861 case 0: /* A terminating entry. */
6863 *vstart_ptr
= vstart
;
6864 printf (_("<End of list>\n"));
6866 case 1: /* A base-address entry. */
6867 READ_ULEB (idx
, start
, section_end
);
6868 print_addr_index (idx
, 8);
6869 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6870 printf (_("(base address selection entry)\n"));
6872 case 2: /* A start/end entry. */
6873 READ_ULEB (idx
, start
, section_end
);
6874 print_addr_index (idx
, 8);
6875 READ_ULEB (idx
, start
, section_end
);
6876 print_addr_index (idx
, 8);
6878 case 3: /* A start/length entry. */
6879 READ_ULEB (idx
, start
, section_end
);
6880 print_addr_index (idx
, 8);
6881 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6882 printf ("%08x ", idx
);
6884 case 4: /* An offset pair entry. */
6885 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6886 printf ("%08x ", idx
);
6887 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6888 printf ("%08x ", idx
);
6891 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6893 *vstart_ptr
= vstart
;
6897 if (2 > (size_t) (section_end
- start
))
6899 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6900 (unsigned long) offset
);
6904 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6905 if (length
> (size_t) (section_end
- start
))
6907 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6908 (unsigned long) offset
);
6913 need_frame_base
= decode_location_expression (start
,
6918 cu_offset
, section
);
6921 if (need_frame_base
&& !has_frame_base
)
6922 printf (_(" [without DW_AT_frame_base]"));
6930 *vstart_ptr
= vstart
;
6933 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6936 static dwarf_vma
*loc_offsets
, *loc_views
;
6939 loc_offsets_compar (const void *ap
, const void *bp
)
6941 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6942 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6944 int ret
= (a
> b
) - (b
> a
);
6948 a
= loc_views
[*(const unsigned int *) ap
];
6949 b
= loc_views
[*(const unsigned int *) bp
];
6951 ret
= (a
> b
) - (b
> a
);
6957 display_offset_entry_loclists (struct dwarf_section
*section
)
6959 unsigned char * start
= section
->start
;
6960 unsigned char * const end
= start
+ section
->size
;
6962 introduce (section
, false);
6967 unsigned short version
;
6968 unsigned char address_size
;
6969 unsigned char segment_selector_size
;
6970 uint32_t offset_entry_count
;
6974 printf (_("Table at Offset 0x%lx\n"), (long)(start
- section
->start
));
6976 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
6977 if (length
== 0xffffffff)
6980 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
6985 SAFE_BYTE_GET_AND_INC (version
, start
, 2, end
);
6986 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, end
);
6987 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, end
);
6988 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, end
);
6990 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", length
));
6991 printf (_(" DWARF version: %u\n"), version
);
6992 printf (_(" Address size: %u\n"), address_size
);
6993 printf (_(" Segment size: %u\n"), segment_selector_size
);
6994 printf (_(" Offset entries: %u\n"), offset_entry_count
);
6998 warn (_("The %s section contains a corrupt or "
6999 "unsupported version number: %d.\n"),
7000 section
->name
, version
);
7004 if (segment_selector_size
!= 0)
7006 warn (_("The %s section contains an "
7007 "unsupported segment selector size: %d.\n"),
7008 section
->name
, segment_selector_size
);
7012 if (offset_entry_count
== 0)
7014 warn (_("The %s section contains a table without offset\n"),
7019 printf (_("\n Offset Entries starting at 0x%lx:\n"),
7020 (long)(start
- section
->start
));
7024 for (i
= 0; i
< offset_entry_count
; i
++)
7028 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, end
);
7029 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
7034 for (i
= 0; i
< offset_entry_count
; i
++)
7038 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, end
);
7039 printf (_(" [%6u] 0x%x\n"), i
, entry
);
7047 for (j
= 1, i
= 0; i
< offset_entry_count
;)
7050 dwarf_vma base_address
= 0;
7053 dwarf_vma off
= start
- section
->start
;
7057 printf (_(" Offset Entry %u\n"), i
);
7062 print_dwarf_vma (off
, 4);
7064 SAFE_BYTE_GET_AND_INC (lle
, start
, 1, end
);
7068 case DW_LLE_end_of_list
:
7069 printf (_("<End of list>\n\n"));
7073 case DW_LLE_base_addressx
:
7074 READ_ULEB (base_address
, start
, end
);
7075 print_dwarf_vma (base_address
, address_size
);
7076 printf (_("(index into .debug_addr) "));
7077 base_address
= fetch_indexed_addr (base_address
, address_size
);
7078 print_dwarf_vma (base_address
, address_size
);
7079 printf (_("(base address)\n"));
7082 case DW_LLE_startx_endx
:
7083 READ_ULEB (begin
, start
, end
);
7084 begin
= fetch_indexed_addr (begin
, address_size
);
7085 READ_ULEB (finish
, start
, end
);
7086 finish
= fetch_indexed_addr (finish
, address_size
);
7089 case DW_LLE_startx_length
:
7090 READ_ULEB (begin
, start
, end
);
7091 begin
= fetch_indexed_addr (begin
, address_size
);
7092 READ_ULEB (finish
, start
, end
);
7096 case DW_LLE_offset_pair
:
7097 READ_ULEB (begin
, start
, end
);
7098 begin
+= base_address
;
7099 READ_ULEB (finish
, start
, end
);
7100 finish
+= base_address
;
7103 case DW_LLE_default_location
:
7107 case DW_LLE_base_address
:
7108 SAFE_BYTE_GET_AND_INC (base_address
, start
, address_size
, end
);
7109 print_dwarf_vma (base_address
, address_size
);
7110 printf (_("(base address)\n"));
7113 case DW_LLE_start_end
:
7114 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7115 SAFE_BYTE_GET_AND_INC (finish
, start
, address_size
, end
);
7118 case DW_LLE_start_length
:
7119 SAFE_BYTE_GET_AND_INC (begin
, start
, address_size
, end
);
7120 READ_ULEB (finish
, start
, end
);
7125 error (_("Invalid location list entry type %d\n"), lle
);
7131 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7132 (unsigned long) off
);
7136 print_dwarf_vma (begin
, address_size
);
7137 print_dwarf_vma (finish
, address_size
);
7139 if (begin
== finish
)
7140 fputs (_(" (start == end)"), stdout
);
7141 else if (begin
> finish
)
7142 fputs (_(" (start > end)"), stdout
);
7144 /* Read the counted location descriptions. */
7145 READ_ULEB (length
, start
, end
);
7147 if (length
> (size_t) (end
- start
))
7149 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
7150 (unsigned long) off
);
7155 (void) decode_location_expression (start
, address_size
, address_size
,
7156 version
, length
, 0, section
);
7163 while (start
< end
);
7169 display_debug_loc (struct dwarf_section
*section
, void *file
)
7171 unsigned char *start
= section
->start
, *vstart
= NULL
;
7173 unsigned char *section_begin
= start
;
7174 unsigned int num_loc_list
= 0;
7175 dwarf_vma last_offset
= 0;
7176 dwarf_vma last_view
= 0;
7177 unsigned int first
= 0;
7180 int seen_first_offset
= 0;
7181 int locs_sorted
= 1;
7182 unsigned char *next
= start
, *vnext
= vstart
;
7183 unsigned int *array
= NULL
;
7184 const char *suffix
= strrchr (section
->name
, '.');
7185 bool is_dwo
= false;
7186 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
7187 dwarf_vma expected_start
= 0;
7189 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
7192 bytes
= section
->size
;
7196 printf (_("\nThe %s section is empty.\n"), section
->name
);
7202 unsigned char *hdrptr
= section_begin
;
7203 dwarf_vma ll_length
;
7204 unsigned short ll_version
;
7205 unsigned char *end
= section_begin
+ section
->size
;
7206 unsigned char address_size
, segment_selector_size
;
7207 uint32_t offset_entry_count
;
7209 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
7210 if (ll_length
== 0xffffffff)
7211 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
7213 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
7214 if (ll_version
!= 5)
7216 warn (_("The %s section contains corrupt or "
7217 "unsupported version number: %d.\n"),
7218 section
->name
, ll_version
);
7222 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
7224 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
7225 if (segment_selector_size
!= 0)
7227 warn (_("The %s section contains "
7228 "unsupported segment selector size: %d.\n"),
7229 section
->name
, segment_selector_size
);
7233 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
7235 if (offset_entry_count
!= 0)
7236 return display_offset_entry_loclists (section
);
7238 expected_start
= hdrptr
- section_begin
;
7241 if (load_debug_info (file
) == 0)
7243 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7248 /* Check the order of location list in .debug_info section. If
7249 offsets of location lists are in the ascending order, we can
7250 use `debug_information' directly. */
7251 for (i
= 0; i
< num_debug_info_entries
; i
++)
7255 num
= debug_information
[i
].num_loc_offsets
;
7256 if (num
> num_loc_list
)
7259 /* Check if we can use `debug_information' directly. */
7260 if (locs_sorted
&& num
!= 0)
7262 if (!seen_first_offset
)
7264 /* This is the first location list. */
7265 last_offset
= debug_information
[i
].loc_offsets
[0];
7266 last_view
= debug_information
[i
].loc_views
[0];
7268 seen_first_offset
= 1;
7274 for (; j
< num
; j
++)
7277 debug_information
[i
].loc_offsets
[j
]
7278 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
7279 && last_view
> debug_information
[i
].loc_views
[j
]))
7284 last_offset
= debug_information
[i
].loc_offsets
[j
];
7285 last_view
= debug_information
[i
].loc_views
[j
];
7290 if (!seen_first_offset
)
7291 error (_("No location lists in .debug_info section!\n"));
7293 if (debug_information
[first
].num_loc_offsets
> 0
7294 && debug_information
[first
].loc_offsets
[0] != expected_start
7295 && debug_information
[first
].loc_views
[0] != expected_start
)
7296 warn (_("Location lists in %s section start at 0x%s rather than 0x%s\n"),
7298 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]),
7299 dwarf_vmatoa ("x", expected_start
));
7302 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
7304 introduce (section
, false);
7306 if (reloc_at (section
, 0))
7307 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
7309 printf (_(" Offset Begin End Expression\n"));
7311 seen_first_offset
= 0;
7312 for (i
= first
; i
< num_debug_info_entries
; i
++)
7314 dwarf_vma offset
, voffset
;
7315 dwarf_vma base_address
;
7321 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7323 loc_offsets
= debug_information
[i
].loc_offsets
;
7324 loc_views
= debug_information
[i
].loc_views
;
7325 qsort (array
, debug_information
[i
].num_loc_offsets
,
7326 sizeof (*array
), loc_offsets_compar
);
7329 int adjacent_view_loclists
= 1;
7330 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
7332 j
= locs_sorted
? k
: array
[k
];
7334 && (debug_information
[i
].loc_offsets
[locs_sorted
7335 ? k
- 1 : array
[k
- 1]]
7336 == debug_information
[i
].loc_offsets
[j
])
7337 && (debug_information
[i
].loc_views
[locs_sorted
7338 ? k
- 1 : array
[k
- 1]]
7339 == debug_information
[i
].loc_views
[j
]))
7341 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
7342 offset
= debug_information
[i
].loc_offsets
[j
];
7343 next
= section_begin
+ offset
;
7344 voffset
= debug_information
[i
].loc_views
[j
];
7346 vnext
= section_begin
+ voffset
;
7349 base_address
= debug_information
[i
].base_address
;
7351 if (vnext
&& vnext
< next
)
7354 display_view_pair_list (section
, &vstart
, i
, next
);
7359 if (!seen_first_offset
|| !adjacent_view_loclists
)
7360 seen_first_offset
= 1;
7364 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7365 (unsigned long) (start
- section_begin
),
7366 (unsigned long) offset
,
7368 else if (start
> next
)
7369 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7370 (unsigned long) (start
- section_begin
),
7371 (unsigned long) offset
,
7377 if (offset
>= bytes
)
7379 warn (_("Offset 0x%lx is bigger than %s section size.\n"),
7380 (unsigned long) offset
,
7385 if (vnext
&& voffset
>= bytes
)
7387 warn (_("View Offset 0x%lx is bigger than %s section size.\n"),
7388 (unsigned long) voffset
,
7396 display_loc_list_dwo (section
, &start
, i
, offset
,
7397 &vstart
, has_frame_base
);
7399 display_loc_list (section
, &start
, i
, offset
, base_address
,
7400 &vstart
, has_frame_base
);
7405 warn (_("DWO is not yet supported.\n"));
7407 display_loclists_list (section
, &start
, i
, offset
, base_address
,
7408 &vstart
, has_frame_base
);
7411 /* FIXME: this arrangement is quite simplistic. Nothing
7412 requires locview lists to be adjacent to corresponding
7413 loclists, and a single loclist could be augmented by
7414 different locview lists, and vice-versa, unlikely as it
7415 is that it would make sense to do so. Hopefully we'll
7416 have view pair support built into loclists before we ever
7417 need to address all these possibilities. */
7418 if (adjacent_view_loclists
&& vnext
7419 && vnext
!= start
&& vstart
!= next
)
7421 adjacent_view_loclists
= 0;
7422 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7425 if (vnext
&& vnext
== start
)
7426 display_view_pair_list (section
, &start
, i
, vstart
);
7430 if (start
< section
->start
+ section
->size
)
7431 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7432 "There are %ld unused bytes at the end of section %s\n",
7433 (long) (section
->start
+ section
->size
- start
)),
7434 (long) (section
->start
+ section
->size
- start
), section
->name
);
7441 display_debug_str (struct dwarf_section
*section
,
7442 void *file ATTRIBUTE_UNUSED
)
7444 unsigned char *start
= section
->start
;
7445 dwarf_vma bytes
= section
->size
;
7446 dwarf_vma addr
= section
->address
;
7450 printf (_("\nThe %s section is empty.\n"), section
->name
);
7454 introduce (section
, false);
7462 lbytes
= (bytes
> 16 ? 16 : bytes
);
7464 printf (" 0x%8.8lx ", (unsigned long) addr
);
7466 for (j
= 0; j
< 16; j
++)
7469 printf ("%2.2x", start
[j
]);
7477 for (j
= 0; j
< lbytes
; j
++)
7480 if (k
>= ' ' && k
< 0x80)
7499 display_debug_info (struct dwarf_section
*section
, void *file
)
7501 return process_debug_info (section
, file
, section
->abbrev_sec
, false, false);
7505 display_debug_types (struct dwarf_section
*section
, void *file
)
7507 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7511 display_trace_info (struct dwarf_section
*section
, void *file
)
7513 return process_debug_info (section
, file
, section
->abbrev_sec
, false, true);
7517 display_debug_aranges (struct dwarf_section
*section
,
7518 void *file ATTRIBUTE_UNUSED
)
7520 unsigned char *start
= section
->start
;
7521 unsigned char *end
= start
+ section
->size
;
7523 introduce (section
, false);
7525 /* It does not matter if this load fails,
7526 we test for that later on. */
7527 load_debug_info (file
);
7531 unsigned char *hdrptr
;
7532 DWARF2_Internal_ARange arange
;
7533 unsigned char *addr_ranges
;
7537 unsigned char address_size
;
7538 unsigned int offset_size
;
7539 unsigned char *end_ranges
;
7542 sec_off
= hdrptr
- section
->start
;
7544 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7545 if (arange
.ar_length
== 0xffffffff)
7547 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7553 if (arange
.ar_length
> (size_t) (end
- hdrptr
))
7555 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7557 (unsigned long) sec_off
,
7558 dwarf_vmatoa ("x", arange
.ar_length
));
7561 end_ranges
= hdrptr
+ arange
.ar_length
;
7563 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end_ranges
);
7564 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
,
7567 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7568 && num_debug_info_entries
> 0
7569 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7570 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7571 (unsigned long) arange
.ar_info_offset
, section
->name
);
7573 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end_ranges
);
7574 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end_ranges
);
7576 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7578 /* PR 19872: A version number of 0 probably means that there is
7579 padding at the end of the .debug_aranges section. Gold puts
7580 it there when performing an incremental link, for example.
7581 So do not generate a warning in this case. */
7582 if (arange
.ar_version
)
7583 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7587 printf (_(" Length: %ld\n"),
7588 (long) arange
.ar_length
);
7589 printf (_(" Version: %d\n"), arange
.ar_version
);
7590 printf (_(" Offset into .debug_info: 0x%lx\n"),
7591 (unsigned long) arange
.ar_info_offset
);
7592 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7593 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7595 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7597 /* PR 17512: file: 001-108546-0.001:0.1. */
7598 if (address_size
== 0 || address_size
> 8)
7600 error (_("Invalid address size in %s section!\n"),
7605 /* The DWARF spec does not require that the address size be a power
7606 of two, but we do. This will have to change if we ever encounter
7607 an uneven architecture. */
7608 if ((address_size
& (address_size
- 1)) != 0)
7610 warn (_("Pointer size + Segment size is not a power of two.\n"));
7614 if (address_size
> 4)
7615 printf (_("\n Address Length\n"));
7617 printf (_("\n Address Length\n"));
7619 addr_ranges
= hdrptr
;
7621 /* Must pad to an alignment boundary that is twice the address size. */
7622 addr_ranges
+= (2 * address_size
- 1
7623 - (hdrptr
- start
- 1) % (2 * address_size
));
7625 while (2 * address_size
<= end_ranges
- addr_ranges
)
7627 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
,
7629 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
,
7632 print_dwarf_vma (address
, address_size
);
7633 print_dwarf_vma (length
, address_size
);
7645 /* Comparison function for qsort. */
7647 comp_addr_base (const void * v0
, const void * v1
)
7649 debug_info
*info0
= *(debug_info
**) v0
;
7650 debug_info
*info1
= *(debug_info
**) v1
;
7651 return info0
->addr_base
- info1
->addr_base
;
7654 /* Display the debug_addr section. */
7656 display_debug_addr (struct dwarf_section
*section
,
7659 debug_info
**debug_addr_info
;
7660 unsigned char *entry
;
7664 unsigned char * header
;
7666 if (section
->size
== 0)
7668 printf (_("\nThe %s section is empty.\n"), section
->name
);
7672 if (load_debug_info (file
) == 0)
7674 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7679 introduce (section
, false);
7681 /* PR 17531: file: cf38d01b.
7682 We use xcalloc because a corrupt file may not have initialised all of the
7683 fields in the debug_info structure, which means that the sort below might
7684 try to move uninitialised data. */
7685 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7686 sizeof (debug_info
*));
7689 for (i
= 0; i
< num_debug_info_entries
; i
++)
7690 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7692 /* PR 17531: file: cf38d01b. */
7693 if (debug_information
[i
].addr_base
>= section
->size
)
7694 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7695 (unsigned long) debug_information
[i
].addr_base
, i
);
7697 debug_addr_info
[count
++] = debug_information
+ i
;
7700 /* Add a sentinel to make iteration convenient. */
7701 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7702 debug_addr_info
[count
]->addr_base
= section
->size
;
7703 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7705 header
= section
->start
;
7706 for (i
= 0; i
< count
; i
++)
7709 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7711 printf (_(" For compilation unit at offset 0x%s:\n"),
7712 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7714 printf (_("\tIndex\tAddress\n"));
7715 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7716 if (debug_addr_info
[i
]->dwarf_version
>= 5)
7718 size_t header_size
= entry
- header
;
7719 unsigned char * curr_header
= header
;
7722 int segment_selector_size
;
7724 if (header_size
!= 8 && header_size
!= 16)
7726 warn (_("Corrupt %s section: expecting header size of 8 or 16, but found %ld instead\n"),
7727 section
->name
, (long) header_size
);
7731 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 4, entry
);
7732 if (length
== 0xffffffff)
7733 SAFE_BYTE_GET_AND_INC (length
, curr_header
, 8, entry
);
7734 end
= curr_header
+ length
;
7736 SAFE_BYTE_GET_AND_INC (version
, curr_header
, 2, entry
);
7738 warn (_("Corrupt %s section: expecting version number 5 in header but found %d instead\n"),
7739 section
->name
, version
);
7741 SAFE_BYTE_GET_AND_INC (address_size
, curr_header
, 1, entry
);
7742 SAFE_BYTE_GET_AND_INC (segment_selector_size
, curr_header
, 1, entry
);
7743 address_size
+= segment_selector_size
;
7746 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7751 dwarf_vma base
= byte_get (entry
, address_size
);
7752 printf (_("\t%d:\t"), idx
);
7753 print_dwarf_vma (base
, address_size
);
7755 entry
+= address_size
;
7761 free (debug_addr_info
);
7765 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7768 display_debug_str_offsets (struct dwarf_section
*section
,
7769 void *file ATTRIBUTE_UNUSED
)
7773 if (section
->size
== 0)
7775 printf (_("\nThe %s section is empty.\n"), section
->name
);
7779 unsigned char *start
= section
->start
;
7780 unsigned char *end
= start
+ section
->size
;
7781 unsigned char *curr
= start
;
7783 const char *suffix
= strrchr (section
->name
, '.');
7784 bool dwo
= suffix
&& strcmp (suffix
, ".dwo") == 0;
7787 load_debug_section_with_follow (str_dwo
, file
);
7789 load_debug_section_with_follow (str
, file
);
7791 introduce (section
, false);
7796 dwarf_vma entry_length
;
7798 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7799 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7800 if (length
== 0xffffffff)
7802 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
7808 unsigned char *entries_end
;
7811 /* This is probably an old style .debug_str_offset section which
7812 just contains offsets and no header (and the first offset is 0). */
7813 length
= section
->size
;
7814 curr
= section
->start
;
7817 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7818 printf (_(" Index Offset [String]\n"));
7822 if (length
<= (dwarf_vma
) (end
- curr
))
7823 entries_end
= curr
+ length
;
7826 warn (_("Section %s is too small %#lx\n"),
7827 section
->name
, (unsigned long) section
->size
);
7832 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, entries_end
);
7834 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7837 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, entries_end
);
7839 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7841 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7842 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7843 printf (_(" Index Offset [String]\n"));
7846 for (idx
= 0; curr
< entries_end
; idx
++)
7849 const unsigned char * string
;
7851 if ((dwarf_vma
) (entries_end
- curr
) < entry_length
)
7852 /* Not enough space to read one entry_length, give up. */
7855 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, entries_end
);
7857 string
= (const unsigned char *)
7858 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7860 string
= fetch_indirect_string (offset
);
7862 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7870 /* Each debug_information[x].range_lists[y] gets this representation for
7871 sorting purposes. */
7875 /* The debug_information[x].range_lists[y] value. */
7876 dwarf_vma ranges_offset
;
7878 /* Original debug_information to find parameters of the data. */
7879 debug_info
*debug_info_p
;
7882 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7885 range_entry_compar (const void *ap
, const void *bp
)
7887 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7888 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7889 const dwarf_vma a
= a_re
->ranges_offset
;
7890 const dwarf_vma b
= b_re
->ranges_offset
;
7892 return (a
> b
) - (b
> a
);
7896 display_debug_ranges_list (unsigned char * start
,
7897 unsigned char * finish
,
7898 unsigned int pointer_size
,
7900 dwarf_vma base_address
)
7902 while (start
< finish
)
7907 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7908 if (start
>= finish
)
7910 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7913 print_dwarf_vma (offset
, 4);
7915 if (begin
== 0 && end
== 0)
7917 printf (_("<End of list>\n"));
7921 /* Check base address specifiers. */
7922 if (is_max_address (begin
, pointer_size
)
7923 && !is_max_address (end
, pointer_size
))
7926 print_dwarf_vma (begin
, pointer_size
);
7927 print_dwarf_vma (end
, pointer_size
);
7928 printf ("(base address)\n");
7932 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7933 print_dwarf_vma (end
+ base_address
, pointer_size
);
7936 fputs (_("(start == end)"), stdout
);
7937 else if (begin
> end
)
7938 fputs (_("(start > end)"), stdout
);
7945 display_debug_rnglists_list (unsigned char * start
,
7946 unsigned char * finish
,
7947 unsigned int pointer_size
,
7949 dwarf_vma base_address
)
7951 unsigned char *next
= start
;
7955 dwarf_vma off
= offset
+ (start
- next
);
7956 enum dwarf_range_list_entry rlet
;
7957 /* Initialize it due to a false compiler warning. */
7958 dwarf_vma begin
= -1, length
, end
= -1;
7960 if (start
>= finish
)
7962 warn (_("Range list starting at offset 0x%s is not terminated.\n"),
7963 dwarf_vmatoa ("x", offset
));
7968 print_dwarf_vma (off
, 4);
7970 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7974 case DW_RLE_end_of_list
:
7975 printf (_("<End of list>\n"));
7977 case DW_RLE_base_addressx
:
7978 READ_ULEB (base_address
, start
, finish
);
7979 print_dwarf_vma (base_address
, pointer_size
);
7980 printf (_("(base address index) "));
7981 base_address
= fetch_indexed_addr (base_address
, pointer_size
);
7982 print_dwarf_vma (base_address
, pointer_size
);
7983 printf (_("(base address)\n"));
7985 case DW_RLE_startx_endx
:
7986 READ_ULEB (begin
, start
, finish
);
7987 READ_ULEB (end
, start
, finish
);
7988 begin
= fetch_indexed_addr (begin
, pointer_size
);
7989 end
= fetch_indexed_addr (begin
, pointer_size
);
7991 case DW_RLE_startx_length
:
7992 READ_ULEB (begin
, start
, finish
);
7993 READ_ULEB (length
, start
, finish
);
7994 begin
= fetch_indexed_addr (begin
, pointer_size
);
7995 end
= begin
+ length
;
7997 case DW_RLE_offset_pair
:
7998 READ_ULEB (begin
, start
, finish
);
7999 READ_ULEB (end
, start
, finish
);
8001 case DW_RLE_base_address
:
8002 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
8003 print_dwarf_vma (base_address
, pointer_size
);
8004 printf (_("(base address)\n"));
8006 case DW_RLE_start_end
:
8007 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8008 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
8010 case DW_RLE_start_length
:
8011 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
8012 READ_ULEB (length
, start
, finish
);
8013 end
= begin
+ length
;
8016 error (_("Invalid range list entry type %d\n"), rlet
);
8017 rlet
= DW_RLE_end_of_list
;
8020 if (rlet
== DW_RLE_end_of_list
)
8022 if (rlet
== DW_RLE_base_address
|| rlet
== DW_RLE_base_addressx
)
8025 /* Only a DW_RLE_offset_pair needs the base address added. */
8026 if (rlet
== DW_RLE_offset_pair
)
8028 begin
+= base_address
;
8029 end
+= base_address
;
8032 print_dwarf_vma (begin
, pointer_size
);
8033 print_dwarf_vma (end
, pointer_size
);
8036 fputs (_("(start == end)"), stdout
);
8037 else if (begin
> end
)
8038 fputs (_("(start > end)"), stdout
);
8045 display_debug_ranges (struct dwarf_section
*section
,
8046 void *file ATTRIBUTE_UNUSED
)
8048 unsigned char * start
= section
->start
;
8049 unsigned char * last_start
= start
;
8050 dwarf_vma bytes
= section
->size
;
8051 unsigned char * section_begin
= start
;
8052 unsigned char * finish
= start
+ bytes
;
8053 unsigned int num_range_list
, i
;
8054 struct range_entry
* range_entries
;
8055 struct range_entry
* range_entry_fill
;
8056 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
8057 /* Initialize it due to a false compiler warning. */
8058 unsigned char address_size
= 0;
8059 dwarf_vma last_offset
= 0;
8063 printf (_("\nThe %s section is empty.\n"), section
->name
);
8067 introduce (section
, false);
8071 dwarf_vma initial_length
;
8072 unsigned char segment_selector_size
;
8073 unsigned int offset_size
, offset_entry_count
;
8074 unsigned short version
;
8076 /* Get and check the length of the block. */
8077 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
8079 if (initial_length
== 0xffffffff)
8081 /* This section is 64-bit DWARF 3. */
8082 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
8088 if (initial_length
> (size_t) (finish
- start
))
8090 /* If the length field has a relocation against it, then we should
8091 not complain if it is inaccurate (and probably negative).
8092 It is copied from .debug_line handling code. */
8093 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
8095 initial_length
= finish
- start
;
8099 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
8100 (long) initial_length
);
8105 /* Get the other fields in the header. */
8106 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
8107 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
8108 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
8109 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
8111 printf (_(" Length: 0x%s\n"), dwarf_vmatoa ("x", initial_length
));
8112 printf (_(" DWARF version: %u\n"), version
);
8113 printf (_(" Address size: %u\n"), address_size
);
8114 printf (_(" Segment size: %u\n"), segment_selector_size
);
8115 printf (_(" Offset entries: %u\n"), offset_entry_count
);
8117 /* Check the fields. */
8118 if (segment_selector_size
!= 0)
8120 warn (_("The %s section contains "
8121 "unsupported segment selector size: %d.\n"),
8122 section
->name
, segment_selector_size
);
8128 warn (_("Only DWARF version 5+ debug_rnglists info "
8129 "is currently supported.\n"));
8133 if (offset_entry_count
!= 0)
8135 printf (_("\n Offsets starting at 0x%lx:\n"), (long)(start
- section
->start
));
8136 if (offset_size
== 8)
8138 for (i
= 0; i
< offset_entry_count
; i
++)
8142 SAFE_BYTE_GET_AND_INC (entry
, start
, 8, finish
);
8143 printf (_(" [%6u] 0x%s\n"), i
, dwarf_vmatoa ("x", entry
));
8148 for (i
= 0; i
< offset_entry_count
; i
++)
8152 SAFE_BYTE_GET_AND_INC (entry
, start
, 4, finish
);
8153 printf (_(" [%6u] 0x%x\n"), i
, entry
);
8159 if (load_debug_info (file
) == 0)
8161 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
8167 for (i
= 0; i
< num_debug_info_entries
; i
++)
8169 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
8170 /* Skip .debug_rnglists reference. */
8172 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
8173 /* Skip .debug_range reference. */
8175 num_range_list
+= debug_information
[i
].num_range_lists
;
8178 if (num_range_list
== 0)
8180 /* This can happen when the file was compiled with -gsplit-debug
8181 which removes references to range lists from the primary .o file. */
8182 printf (_("No range lists in .debug_info section.\n"));
8186 range_entries
= (struct range_entry
*)
8187 xmalloc (sizeof (*range_entries
) * num_range_list
);
8188 range_entry_fill
= range_entries
;
8190 for (i
= 0; i
< num_debug_info_entries
; i
++)
8192 debug_info
*debug_info_p
= &debug_information
[i
];
8195 if (debug_information
[i
].dwarf_version
< 5 && is_rnglists
)
8196 /* Skip .debug_rnglists reference. */
8198 if (debug_information
[i
].dwarf_version
>= 5 && !is_rnglists
)
8199 /* Skip .debug_range reference. */
8202 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
8204 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
8205 range_entry_fill
->debug_info_p
= debug_info_p
;
8210 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
8211 range_entry_compar
);
8213 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
8214 warn (_("Range lists in %s section start at 0x%lx\n"),
8215 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
8218 printf (_(" Offset Begin End\n"));
8220 for (i
= 0; i
< num_range_list
; i
++)
8222 struct range_entry
*range_entry
= &range_entries
[i
];
8223 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
8224 unsigned int pointer_size
;
8226 unsigned char *next
;
8227 dwarf_vma base_address
;
8229 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
8230 offset
= range_entry
->ranges_offset
;
8231 base_address
= debug_info_p
->base_address
;
8233 /* PR 17512: file: 001-101485-0.001:0.1. */
8234 if (pointer_size
< 2 || pointer_size
> 8)
8236 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
8237 pointer_size
, (unsigned long) offset
);
8241 if (offset
> (size_t) (finish
- section_begin
))
8243 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
8244 (unsigned long) offset
, i
);
8247 next
= section_begin
+ offset
;
8249 /* If multiple DWARF entities reference the same range then we will
8250 have multiple entries in the `range_entries' list for the same
8251 offset. Thanks to the sort above these will all be consecutive in
8252 the `range_entries' list, so we can easily ignore duplicates
8254 if (i
> 0 && last_offset
== offset
)
8256 last_offset
= offset
;
8258 if (dwarf_check
!= 0 && i
> 0)
8261 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
8262 (unsigned long) (start
- section_begin
),
8263 (unsigned long) (next
- section_begin
), section
->name
);
8264 else if (start
> next
)
8266 if (next
== last_start
)
8268 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
8269 (unsigned long) (start
- section_begin
),
8270 (unsigned long) (next
- section_begin
), section
->name
);
8278 display_debug_rnglists_list
8279 (start
, finish
, pointer_size
, offset
, base_address
);
8281 display_debug_ranges_list
8282 (start
, finish
, pointer_size
, offset
, base_address
);
8286 free (range_entries
);
8291 typedef struct Frame_Chunk
8293 struct Frame_Chunk
*next
;
8294 unsigned char *chunk_start
;
8296 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
8297 short int *col_type
;
8300 unsigned int code_factor
;
8304 unsigned int cfa_reg
;
8305 dwarf_vma cfa_offset
;
8307 unsigned char fde_encoding
;
8308 unsigned char cfa_exp
;
8309 unsigned char ptr_size
;
8310 unsigned char segment_size
;
8314 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
8315 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
8316 static const char *const *dwarf_regnames
;
8317 static unsigned int dwarf_regnames_count
;
8320 /* A marker for a col_type that means this column was never referenced
8321 in the frame info. */
8322 #define DW_CFA_unreferenced (-1)
8324 /* Return 0 if no more space is needed, 1 if more space is needed,
8325 -1 for invalid reg. */
8328 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
8330 unsigned int prev
= fc
->ncols
;
8332 if (reg
< (unsigned int) fc
->ncols
)
8335 if (dwarf_regnames_count
> 0
8336 && reg
> dwarf_regnames_count
)
8339 fc
->ncols
= reg
+ 1;
8340 /* PR 17512: file: 10450-2643-0.004.
8341 If reg == -1 then this can happen... */
8345 /* PR 17512: file: 2844a11d. */
8346 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
8348 error (_("Unfeasibly large register number: %u\n"), reg
);
8350 /* FIXME: 1024 is an arbitrary limit. Increase it if
8351 we ever encounter a valid binary that exceeds it. */
8355 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
8356 sizeof (short int));
8357 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
8358 /* PR 17512: file:002-10025-0.005. */
8359 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
8361 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
8367 while (prev
< fc
->ncols
)
8369 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
8370 fc
->col_offset
[prev
] = 0;
8376 static const char *const dwarf_regnames_i386
[] =
8378 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8379 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8380 "eip", "eflags", NULL
, /* 8 - 10 */
8381 "st0", "st1", "st2", "st3", /* 11 - 14 */
8382 "st4", "st5", "st6", "st7", /* 15 - 18 */
8383 NULL
, NULL
, /* 19 - 20 */
8384 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
8385 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
8386 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
8387 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
8388 "fcw", "fsw", "mxcsr", /* 37 - 39 */
8389 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8390 "tr", "ldtr", /* 48 - 49 */
8391 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8392 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8393 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8394 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8395 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8396 NULL
, NULL
, NULL
, /* 90 - 92 */
8397 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
8400 static const char *const dwarf_regnames_iamcu
[] =
8402 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
8403 "esp", "ebp", "esi", "edi", /* 4 - 7 */
8404 "eip", "eflags", NULL
, /* 8 - 10 */
8405 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
8406 NULL
, NULL
, /* 19 - 20 */
8407 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
8408 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
8409 NULL
, NULL
, NULL
, /* 37 - 39 */
8410 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
8411 "tr", "ldtr", /* 48 - 49 */
8412 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
8413 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
8414 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
8415 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
8416 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
8417 NULL
, NULL
, NULL
, /* 90 - 92 */
8418 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
8422 init_dwarf_regnames_i386 (void)
8424 dwarf_regnames
= dwarf_regnames_i386
;
8425 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
8426 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8430 init_dwarf_regnames_iamcu (void)
8432 dwarf_regnames
= dwarf_regnames_iamcu
;
8433 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
8434 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8437 static const char *const dwarf_regnames_x86_64
[] =
8439 "rax", "rdx", "rcx", "rbx",
8440 "rsi", "rdi", "rbp", "rsp",
8441 "r8", "r9", "r10", "r11",
8442 "r12", "r13", "r14", "r15",
8444 "xmm0", "xmm1", "xmm2", "xmm3",
8445 "xmm4", "xmm5", "xmm6", "xmm7",
8446 "xmm8", "xmm9", "xmm10", "xmm11",
8447 "xmm12", "xmm13", "xmm14", "xmm15",
8448 "st0", "st1", "st2", "st3",
8449 "st4", "st5", "st6", "st7",
8450 "mm0", "mm1", "mm2", "mm3",
8451 "mm4", "mm5", "mm6", "mm7",
8453 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
8454 "fs.base", "gs.base", NULL
, NULL
,
8456 "mxcsr", "fcw", "fsw",
8457 "xmm16", "xmm17", "xmm18", "xmm19",
8458 "xmm20", "xmm21", "xmm22", "xmm23",
8459 "xmm24", "xmm25", "xmm26", "xmm27",
8460 "xmm28", "xmm29", "xmm30", "xmm31",
8461 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
8462 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
8463 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
8464 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
8465 NULL
, NULL
, NULL
, /* 115 - 117 */
8466 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
8470 init_dwarf_regnames_x86_64 (void)
8472 dwarf_regnames
= dwarf_regnames_x86_64
;
8473 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
8474 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8477 static const char *const dwarf_regnames_aarch64
[] =
8479 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
8480 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
8481 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
8482 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
8483 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8484 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
8485 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
8486 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
8487 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
8488 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
8489 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
8490 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
8491 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
8492 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
8493 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
8494 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
8498 init_dwarf_regnames_aarch64 (void)
8500 dwarf_regnames
= dwarf_regnames_aarch64
;
8501 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
8502 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8505 static const char *const dwarf_regnames_s390
[] =
8507 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
8508 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8509 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
8510 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
8511 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
8512 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
8513 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
8514 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
8515 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
8518 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
8519 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
8523 init_dwarf_regnames_s390 (void)
8525 dwarf_regnames
= dwarf_regnames_s390
;
8526 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8527 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8530 static const char *const dwarf_regnames_riscv
[] =
8532 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8533 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8534 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8535 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8536 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8537 "fs0", "fs1", /* 40 - 41 */
8538 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8539 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8540 "fs10", "fs11", /* 58 - 59 */
8541 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8544 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8545 the large number of CSRs. */
8548 regname_internal_riscv (unsigned int regno
)
8550 const char *name
= NULL
;
8552 /* Lookup in the table first, this covers GPR and FPR. */
8553 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8554 name
= dwarf_regnames_riscv
[regno
];
8555 else if (regno
>= 4096 && regno
<= 8191)
8557 /* This might be a CSR, these live in a sparse number space from 4096
8558 to 8191 These numbers are defined in the RISC-V ELF ABI
8562 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8563 case VALUE + 4096: name = #NAME; break;
8564 #include "opcode/riscv-opc.h"
8569 static char csr_name
[10];
8570 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8581 init_dwarf_regnames_riscv (void)
8583 dwarf_regnames
= NULL
;
8584 dwarf_regnames_count
= 8192;
8585 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8589 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8591 dwarf_regnames_lookup_func
= NULL
;
8596 init_dwarf_regnames_i386 ();
8600 init_dwarf_regnames_iamcu ();
8606 init_dwarf_regnames_x86_64 ();
8610 init_dwarf_regnames_aarch64 ();
8614 init_dwarf_regnames_s390 ();
8618 init_dwarf_regnames_riscv ();
8626 /* Initialize the DWARF register name lookup state based on the
8627 architecture and specific machine type of a BFD. */
8630 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8633 dwarf_regnames_lookup_func
= NULL
;
8640 case bfd_mach_x86_64
:
8641 case bfd_mach_x86_64_intel_syntax
:
8642 case bfd_mach_x64_32
:
8643 case bfd_mach_x64_32_intel_syntax
:
8644 init_dwarf_regnames_x86_64 ();
8648 init_dwarf_regnames_i386 ();
8653 case bfd_arch_iamcu
:
8654 init_dwarf_regnames_iamcu ();
8657 case bfd_arch_aarch64
:
8658 init_dwarf_regnames_aarch64();
8662 init_dwarf_regnames_s390 ();
8665 case bfd_arch_riscv
:
8666 init_dwarf_regnames_riscv ();
8675 regname_internal_by_table_only (unsigned int regno
)
8677 if (dwarf_regnames
!= NULL
8678 && regno
< dwarf_regnames_count
8679 && dwarf_regnames
[regno
] != NULL
)
8680 return dwarf_regnames
[regno
];
8686 regname (unsigned int regno
, int name_only_p
)
8688 static char reg
[64];
8690 const char *name
= NULL
;
8692 if (dwarf_regnames_lookup_func
!= NULL
)
8693 name
= dwarf_regnames_lookup_func (regno
);
8699 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8702 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8707 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8712 if (*max_regs
!= fc
->ncols
)
8713 *max_regs
= fc
->ncols
;
8715 if (*need_col_headers
)
8717 *need_col_headers
= 0;
8719 printf ("%-*s CFA ", eh_addr_size
* 2, " LOC");
8721 for (r
= 0; r
< *max_regs
; r
++)
8722 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8727 printf ("%-5s ", regname (r
, 1));
8733 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8735 strcpy (tmp
, "exp");
8737 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8738 printf ("%-8s ", tmp
);
8740 for (r
= 0; r
< fc
->ncols
; r
++)
8742 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8744 switch (fc
->col_type
[r
])
8746 case DW_CFA_undefined
:
8749 case DW_CFA_same_value
:
8753 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8755 case DW_CFA_val_offset
:
8756 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8758 case DW_CFA_register
:
8759 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8761 case DW_CFA_expression
:
8762 strcpy (tmp
, "exp");
8764 case DW_CFA_val_expression
:
8765 strcpy (tmp
, "vexp");
8768 strcpy (tmp
, "n/a");
8771 printf ("%-5s ", tmp
);
8777 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8779 static unsigned char *
8780 read_cie (unsigned char *start
, unsigned char *end
,
8781 Frame_Chunk
**p_cie
, int *p_version
,
8782 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8786 unsigned char *augmentation_data
= NULL
;
8787 bfd_size_type augmentation_data_len
= 0;
8790 /* PR 17512: file: 001-228113-0.004. */
8794 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8795 memset (fc
, 0, sizeof (Frame_Chunk
));
8797 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8798 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8802 fc
->augmentation
= (char *) start
;
8803 /* PR 17512: file: 001-228113-0.004.
8804 Skip past augmentation name, but avoid running off the end of the data. */
8806 if (* start
++ == '\0')
8810 warn (_("No terminator for augmentation name\n"));
8814 if (strcmp (fc
->augmentation
, "eh") == 0)
8816 if (eh_addr_size
> (size_t) (end
- start
))
8818 start
+= eh_addr_size
;
8823 if (2 > (size_t) (end
- start
))
8825 GET (fc
->ptr_size
, 1);
8826 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8828 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8832 GET (fc
->segment_size
, 1);
8833 /* PR 17512: file: e99d2804. */
8834 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8836 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8840 eh_addr_size
= fc
->ptr_size
;
8844 fc
->ptr_size
= eh_addr_size
;
8845 fc
->segment_size
= 0;
8848 READ_ULEB (fc
->code_factor
, start
, end
);
8849 READ_SLEB (fc
->data_factor
, start
, end
);
8860 READ_ULEB (fc
->ra
, start
, end
);
8863 if (fc
->augmentation
[0] == 'z')
8867 READ_ULEB (augmentation_data_len
, start
, end
);
8868 augmentation_data
= start
;
8869 /* PR 17512: file: 11042-2589-0.004. */
8870 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8872 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8873 dwarf_vmatoa ("x", augmentation_data_len
),
8874 (unsigned long) (end
- start
));
8877 start
+= augmentation_data_len
;
8880 if (augmentation_data_len
)
8884 unsigned char *qend
;
8886 p
= (unsigned char *) fc
->augmentation
+ 1;
8887 q
= augmentation_data
;
8888 qend
= q
+ augmentation_data_len
;
8890 while (p
< end
&& q
< qend
)
8895 q
+= 1 + size_of_encoded_value (*q
);
8897 fc
->fde_encoding
= *q
++;
8906 /* Note - it is OK if this loop terminates with q < qend.
8907 Padding may have been inserted to align the end of the CIE. */
8912 *p_version
= version
;
8915 *p_aug_len
= augmentation_data_len
;
8916 *p_aug
= augmentation_data
;
8921 free (fc
->col_offset
);
8922 free (fc
->col_type
);
8927 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8928 If do_wide is not enabled, then formats the output to fit into 80 columns.
8929 PRINTED contains the number of characters already written to the current
8933 display_data (bfd_size_type printed
,
8934 const unsigned char * data
,
8935 const bfd_size_type len
)
8937 if (do_wide
|| len
< ((80 - printed
) / 3))
8938 for (printed
= 0; printed
< len
; ++printed
)
8939 printf (" %02x", data
[printed
]);
8942 for (printed
= 0; printed
< len
; ++printed
)
8944 if (printed
% (80 / 3) == 0)
8946 printf (" %02x", data
[printed
]);
8951 /* Prints out the contents on the augmentation data array.
8952 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8955 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8959 i
= printf (_(" Augmentation data: "));
8960 display_data (i
, data
, len
);
8964 display_debug_frames (struct dwarf_section
*section
,
8965 void *file ATTRIBUTE_UNUSED
)
8967 unsigned char *start
= section
->start
;
8968 unsigned char *end
= start
+ section
->size
;
8969 unsigned char *section_start
= start
;
8970 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8971 Frame_Chunk
*remembered_state
= NULL
;
8973 bool is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8974 unsigned int max_regs
= 0;
8975 const char *bad_reg
= _("bad register: ");
8976 unsigned int saved_eh_addr_size
= eh_addr_size
;
8978 introduce (section
, false);
8982 unsigned char *saved_start
;
8983 unsigned char *block_end
;
8988 int need_col_headers
= 1;
8989 unsigned char *augmentation_data
= NULL
;
8990 bfd_size_type augmentation_data_len
= 0;
8991 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8992 unsigned int offset_size
;
8994 static Frame_Chunk fde_fc
;
8996 saved_start
= start
;
8998 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
9002 printf ("\n%08lx ZERO terminator\n\n",
9003 (unsigned long)(saved_start
- section_start
));
9004 /* Skip any zero terminators that directly follow.
9005 A corrupt section size could have loaded a whole
9006 slew of zero filled memory bytes. eg
9007 PR 17512: file: 070-19381-0.004. */
9008 while (start
< end
&& * start
== 0)
9013 if (length
== 0xffffffff)
9015 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
9021 if (length
> (size_t) (end
- start
))
9023 warn ("Invalid length 0x%s in FDE at %#08lx\n",
9024 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
9025 (unsigned long) (saved_start
- section_start
));
9029 block_end
= start
+ length
;
9031 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, block_end
);
9033 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
9034 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
9039 start
= read_cie (start
, block_end
, &cie
, &version
,
9040 &augmentation_data_len
, &augmentation_data
);
9041 /* PR 17512: file: 027-135133-0.005. */
9048 fc
->chunk_start
= saved_start
;
9049 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9052 if (frame_need_space (fc
, mreg
) < 0)
9054 if (fc
->fde_encoding
)
9055 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9057 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
9058 print_dwarf_vma (length
, fc
->ptr_size
);
9059 print_dwarf_vma (cie_id
, offset_size
);
9061 if (do_debug_frames_interp
)
9063 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
9064 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
9069 printf (" Version: %d\n", version
);
9070 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
9073 printf (" Pointer Size: %u\n", fc
->ptr_size
);
9074 printf (" Segment Size: %u\n", fc
->segment_size
);
9076 printf (" Code alignment factor: %u\n", fc
->code_factor
);
9077 printf (" Data alignment factor: %d\n", fc
->data_factor
);
9078 printf (" Return address column: %d\n", fc
->ra
);
9080 if (augmentation_data_len
)
9081 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9088 unsigned char *look_for
;
9089 unsigned long segment_selector
;
9095 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
9096 cie_off
= (cie_off
^ sign
) - sign
;
9097 cie_off
= start
- 4 - section_start
- cie_off
;
9100 look_for
= section_start
+ cie_off
;
9101 if (cie_off
<= (dwarf_vma
) (saved_start
- section_start
))
9103 for (cie
= chunks
; cie
; cie
= cie
->next
)
9104 if (cie
->chunk_start
== look_for
)
9107 else if (cie_off
>= section
->size
)
9111 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
9112 if (cie
->chunk_start
== look_for
)
9116 unsigned int off_size
;
9117 unsigned char *cie_scan
;
9119 cie_scan
= look_for
;
9121 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
9122 if (length
== 0xffffffff)
9124 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
9127 if (length
!= 0 && length
<= (size_t) (end
- cie_scan
))
9130 unsigned char *cie_end
= cie_scan
+ length
;
9132 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
,
9136 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
9137 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
9142 read_cie (cie_scan
, cie_end
, &cie
, &version
,
9143 &augmentation_data_len
, &augmentation_data
);
9144 /* PR 17512: file: 3450-2098-0.004. */
9147 warn (_("Failed to read CIE information\n"));
9150 cie
->next
= forward_refs
;
9152 cie
->chunk_start
= look_for
;
9153 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
9156 if (frame_need_space (cie
, mreg
) < 0)
9158 warn (_("Invalid max register\n"));
9161 if (cie
->fde_encoding
)
9163 = size_of_encoded_value (cie
->fde_encoding
);
9170 memset (fc
, 0, sizeof (Frame_Chunk
));
9175 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
9176 fc
->col_offset
= (int *) xmalloc (sizeof (int));
9177 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
9179 warn (_("Invalid max register\n"));
9183 fc
->augmentation
= "";
9184 fc
->fde_encoding
= 0;
9185 fc
->ptr_size
= eh_addr_size
;
9186 fc
->segment_size
= 0;
9190 fc
->ncols
= cie
->ncols
;
9191 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
9192 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
9193 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
9194 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
9195 fc
->augmentation
= cie
->augmentation
;
9196 fc
->ptr_size
= cie
->ptr_size
;
9197 eh_addr_size
= cie
->ptr_size
;
9198 fc
->segment_size
= cie
->segment_size
;
9199 fc
->code_factor
= cie
->code_factor
;
9200 fc
->data_factor
= cie
->data_factor
;
9201 fc
->cfa_reg
= cie
->cfa_reg
;
9202 fc
->cfa_offset
= cie
->cfa_offset
;
9204 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
9206 warn (_("Invalid max register\n"));
9209 fc
->fde_encoding
= cie
->fde_encoding
;
9212 if (fc
->fde_encoding
)
9213 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
9215 segment_selector
= 0;
9216 if (fc
->segment_size
)
9218 if (fc
->segment_size
> sizeof (segment_selector
))
9220 /* PR 17512: file: 9e196b3e. */
9221 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
9222 fc
->segment_size
= 4;
9224 SAFE_BYTE_GET_AND_INC (segment_selector
, start
,
9225 fc
->segment_size
, block_end
);
9228 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9231 /* FIXME: It appears that sometimes the final pc_range value is
9232 encoded in less than encoded_ptr_size bytes. See the x86_64
9233 run of the "objcopy on compressed debug sections" test for an
9235 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
,
9238 if (cie
->augmentation
[0] == 'z')
9240 READ_ULEB (augmentation_data_len
, start
, block_end
);
9241 augmentation_data
= start
;
9242 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
9243 if (augmentation_data_len
> (bfd_size_type
) (block_end
- start
))
9245 warn (_("Augmentation data too long: 0x%s, "
9246 "expected at most %#lx\n"),
9247 dwarf_vmatoa ("x", augmentation_data_len
),
9248 (unsigned long) (block_end
- start
));
9250 augmentation_data
= NULL
;
9251 augmentation_data_len
= 0;
9253 start
+= augmentation_data_len
;
9256 printf ("\n%08lx %s %s FDE ",
9257 (unsigned long)(saved_start
- section_start
),
9258 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
9259 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
));
9261 if (cie
->chunk_start
)
9262 printf ("cie=%08lx",
9263 (unsigned long) (cie
->chunk_start
- section_start
));
9265 /* Ideally translate "invalid " to 8 chars, trailing space
9267 printf (_("cie=invalid "));
9270 if (fc
->segment_size
)
9271 printf ("%04lx:", segment_selector
);
9274 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
9275 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
9277 if (! do_debug_frames_interp
&& augmentation_data_len
)
9279 display_augmentation_data (augmentation_data
, augmentation_data_len
);
9284 /* At this point, fc is the current chunk, cie (if any) is set, and
9285 we're about to interpret instructions for the chunk. */
9286 /* ??? At present we need to do this always, since this sizes the
9287 fc->col_type and fc->col_offset arrays, which we write into always.
9288 We should probably split the interpreted and non-interpreted bits
9289 into two different routines, since there's so much that doesn't
9290 really overlap between them. */
9291 if (1 || do_debug_frames_interp
)
9293 /* Start by making a pass over the chunk, allocating storage
9294 and taking note of what registers are used. */
9295 unsigned char *tmp
= start
;
9297 while (start
< block_end
)
9299 unsigned int reg
, op
, opa
;
9307 /* Warning: if you add any more cases to this switch, be
9308 sure to add them to the corresponding switch below. */
9311 case DW_CFA_advance_loc
:
9314 SKIP_ULEB (start
, block_end
);
9315 if (frame_need_space (fc
, opa
) >= 0)
9316 fc
->col_type
[opa
] = DW_CFA_undefined
;
9318 case DW_CFA_restore
:
9319 if (frame_need_space (fc
, opa
) >= 0)
9320 fc
->col_type
[opa
] = DW_CFA_undefined
;
9322 case DW_CFA_set_loc
:
9323 if ((size_t) (block_end
- start
) < encoded_ptr_size
)
9326 start
+= encoded_ptr_size
;
9328 case DW_CFA_advance_loc1
:
9329 if ((size_t) (block_end
- start
) < 1)
9334 case DW_CFA_advance_loc2
:
9335 if ((size_t) (block_end
- start
) < 2)
9340 case DW_CFA_advance_loc4
:
9341 if ((size_t) (block_end
- start
) < 4)
9346 case DW_CFA_offset_extended
:
9347 case DW_CFA_val_offset
:
9348 READ_ULEB (reg
, start
, block_end
);
9349 SKIP_ULEB (start
, block_end
);
9350 if (frame_need_space (fc
, reg
) >= 0)
9351 fc
->col_type
[reg
] = DW_CFA_undefined
;
9353 case DW_CFA_restore_extended
:
9354 READ_ULEB (reg
, start
, block_end
);
9355 if (frame_need_space (fc
, reg
) >= 0)
9356 fc
->col_type
[reg
] = DW_CFA_undefined
;
9358 case DW_CFA_undefined
:
9359 READ_ULEB (reg
, start
, block_end
);
9360 if (frame_need_space (fc
, reg
) >= 0)
9361 fc
->col_type
[reg
] = DW_CFA_undefined
;
9363 case DW_CFA_same_value
:
9364 READ_ULEB (reg
, start
, block_end
);
9365 if (frame_need_space (fc
, reg
) >= 0)
9366 fc
->col_type
[reg
] = DW_CFA_undefined
;
9368 case DW_CFA_register
:
9369 READ_ULEB (reg
, start
, block_end
);
9370 SKIP_ULEB (start
, block_end
);
9371 if (frame_need_space (fc
, reg
) >= 0)
9372 fc
->col_type
[reg
] = DW_CFA_undefined
;
9374 case DW_CFA_def_cfa
:
9375 SKIP_ULEB (start
, block_end
);
9376 SKIP_ULEB (start
, block_end
);
9378 case DW_CFA_def_cfa_register
:
9379 SKIP_ULEB (start
, block_end
);
9381 case DW_CFA_def_cfa_offset
:
9382 SKIP_ULEB (start
, block_end
);
9384 case DW_CFA_def_cfa_expression
:
9385 READ_ULEB (temp
, start
, block_end
);
9386 if ((size_t) (block_end
- start
) < temp
)
9391 case DW_CFA_expression
:
9392 case DW_CFA_val_expression
:
9393 READ_ULEB (reg
, start
, block_end
);
9394 READ_ULEB (temp
, start
, block_end
);
9395 if ((size_t) (block_end
- start
) < temp
)
9399 if (frame_need_space (fc
, reg
) >= 0)
9400 fc
->col_type
[reg
] = DW_CFA_undefined
;
9402 case DW_CFA_offset_extended_sf
:
9403 case DW_CFA_val_offset_sf
:
9404 READ_ULEB (reg
, start
, block_end
);
9405 SKIP_SLEB (start
, block_end
);
9406 if (frame_need_space (fc
, reg
) >= 0)
9407 fc
->col_type
[reg
] = DW_CFA_undefined
;
9409 case DW_CFA_def_cfa_sf
:
9410 SKIP_ULEB (start
, block_end
);
9411 SKIP_SLEB (start
, block_end
);
9413 case DW_CFA_def_cfa_offset_sf
:
9414 SKIP_SLEB (start
, block_end
);
9416 case DW_CFA_MIPS_advance_loc8
:
9417 if ((size_t) (block_end
- start
) < 8)
9422 case DW_CFA_GNU_args_size
:
9423 SKIP_ULEB (start
, block_end
);
9425 case DW_CFA_GNU_negative_offset_extended
:
9426 READ_ULEB (reg
, start
, block_end
);
9427 SKIP_ULEB (start
, block_end
);
9428 if (frame_need_space (fc
, reg
) >= 0)
9429 fc
->col_type
[reg
] = DW_CFA_undefined
;
9440 /* Now we know what registers are used, make a second pass over
9441 the chunk, this time actually printing out the info. */
9443 while (start
< block_end
)
9446 unsigned long ul
, roffs
;
9447 /* Note: It is tempting to use an unsigned long for 'reg' but there
9448 are various functions, notably frame_space_needed() that assume that
9449 reg is an unsigned int. */
9454 const char *reg_prefix
= "";
9461 /* Make a note if something other than DW_CFA_nop happens. */
9462 if (op
!= DW_CFA_nop
)
9465 /* Warning: if you add any more cases to this switch, be
9466 sure to add them to the corresponding switch above. */
9469 case DW_CFA_advance_loc
:
9470 if (do_debug_frames_interp
)
9471 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9473 printf (" DW_CFA_advance_loc: %d to %s\n",
9474 opa
* fc
->code_factor
,
9475 dwarf_vmatoa_1 (NULL
,
9476 fc
->pc_begin
+ opa
* fc
->code_factor
,
9478 fc
->pc_begin
+= opa
* fc
->code_factor
;
9482 READ_ULEB (roffs
, start
, block_end
);
9483 if (opa
>= (unsigned int) fc
->ncols
)
9484 reg_prefix
= bad_reg
;
9485 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9486 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
9487 reg_prefix
, regname (opa
, 0),
9488 roffs
* fc
->data_factor
);
9489 if (*reg_prefix
== '\0')
9491 fc
->col_type
[opa
] = DW_CFA_offset
;
9492 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
9496 case DW_CFA_restore
:
9497 if (opa
>= (unsigned int) fc
->ncols
)
9498 reg_prefix
= bad_reg
;
9499 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9500 printf (" DW_CFA_restore: %s%s\n",
9501 reg_prefix
, regname (opa
, 0));
9502 if (*reg_prefix
!= '\0')
9505 if (opa
>= (unsigned int) cie
->ncols
9506 || (do_debug_frames_interp
9507 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
9509 fc
->col_type
[opa
] = DW_CFA_undefined
;
9510 fc
->col_offset
[opa
] = 0;
9514 fc
->col_type
[opa
] = cie
->col_type
[opa
];
9515 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
9519 case DW_CFA_set_loc
:
9520 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
,
9522 if (do_debug_frames_interp
)
9523 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9525 printf (" DW_CFA_set_loc: %s\n",
9526 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
9530 case DW_CFA_advance_loc1
:
9531 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, block_end
);
9532 if (do_debug_frames_interp
)
9533 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9535 printf (" DW_CFA_advance_loc1: %ld to %s\n",
9536 (unsigned long) (ofs
* fc
->code_factor
),
9537 dwarf_vmatoa_1 (NULL
,
9538 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9540 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9543 case DW_CFA_advance_loc2
:
9544 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
9545 if (do_debug_frames_interp
)
9546 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9548 printf (" DW_CFA_advance_loc2: %ld to %s\n",
9549 (unsigned long) (ofs
* fc
->code_factor
),
9550 dwarf_vmatoa_1 (NULL
,
9551 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9553 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9556 case DW_CFA_advance_loc4
:
9557 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9558 if (do_debug_frames_interp
)
9559 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9561 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9562 (unsigned long) (ofs
* fc
->code_factor
),
9563 dwarf_vmatoa_1 (NULL
,
9564 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9566 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9569 case DW_CFA_offset_extended
:
9570 READ_ULEB (reg
, start
, block_end
);
9571 READ_ULEB (roffs
, start
, block_end
);
9572 if (reg
>= (unsigned int) fc
->ncols
)
9573 reg_prefix
= bad_reg
;
9574 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9575 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9576 reg_prefix
, regname (reg
, 0),
9577 roffs
* fc
->data_factor
);
9578 if (*reg_prefix
== '\0')
9580 fc
->col_type
[reg
] = DW_CFA_offset
;
9581 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9585 case DW_CFA_val_offset
:
9586 READ_ULEB (reg
, start
, block_end
);
9587 READ_ULEB (roffs
, start
, block_end
);
9588 if (reg
>= (unsigned int) fc
->ncols
)
9589 reg_prefix
= bad_reg
;
9590 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9591 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9592 reg_prefix
, regname (reg
, 0),
9593 roffs
* fc
->data_factor
);
9594 if (*reg_prefix
== '\0')
9596 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9597 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9601 case DW_CFA_restore_extended
:
9602 READ_ULEB (reg
, start
, block_end
);
9603 if (reg
>= (unsigned int) fc
->ncols
)
9604 reg_prefix
= bad_reg
;
9605 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9606 printf (" DW_CFA_restore_extended: %s%s\n",
9607 reg_prefix
, regname (reg
, 0));
9608 if (*reg_prefix
!= '\0')
9611 if (reg
>= (unsigned int) cie
->ncols
)
9613 fc
->col_type
[reg
] = DW_CFA_undefined
;
9614 fc
->col_offset
[reg
] = 0;
9618 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9619 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9623 case DW_CFA_undefined
:
9624 READ_ULEB (reg
, start
, block_end
);
9625 if (reg
>= (unsigned int) fc
->ncols
)
9626 reg_prefix
= bad_reg
;
9627 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9628 printf (" DW_CFA_undefined: %s%s\n",
9629 reg_prefix
, regname (reg
, 0));
9630 if (*reg_prefix
== '\0')
9632 fc
->col_type
[reg
] = DW_CFA_undefined
;
9633 fc
->col_offset
[reg
] = 0;
9637 case DW_CFA_same_value
:
9638 READ_ULEB (reg
, start
, block_end
);
9639 if (reg
>= (unsigned int) fc
->ncols
)
9640 reg_prefix
= bad_reg
;
9641 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9642 printf (" DW_CFA_same_value: %s%s\n",
9643 reg_prefix
, regname (reg
, 0));
9644 if (*reg_prefix
== '\0')
9646 fc
->col_type
[reg
] = DW_CFA_same_value
;
9647 fc
->col_offset
[reg
] = 0;
9651 case DW_CFA_register
:
9652 READ_ULEB (reg
, start
, block_end
);
9653 READ_ULEB (roffs
, start
, block_end
);
9654 if (reg
>= (unsigned int) fc
->ncols
)
9655 reg_prefix
= bad_reg
;
9656 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9658 printf (" DW_CFA_register: %s%s in ",
9659 reg_prefix
, regname (reg
, 0));
9660 puts (regname (roffs
, 0));
9662 if (*reg_prefix
== '\0')
9664 fc
->col_type
[reg
] = DW_CFA_register
;
9665 fc
->col_offset
[reg
] = roffs
;
9669 case DW_CFA_remember_state
:
9670 if (! do_debug_frames_interp
)
9671 printf (" DW_CFA_remember_state\n");
9672 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9673 rs
->cfa_offset
= fc
->cfa_offset
;
9674 rs
->cfa_reg
= fc
->cfa_reg
;
9676 rs
->cfa_exp
= fc
->cfa_exp
;
9677 rs
->ncols
= fc
->ncols
;
9678 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9679 sizeof (* rs
->col_type
));
9680 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9681 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9682 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9683 rs
->next
= remembered_state
;
9684 remembered_state
= rs
;
9687 case DW_CFA_restore_state
:
9688 if (! do_debug_frames_interp
)
9689 printf (" DW_CFA_restore_state\n");
9690 rs
= remembered_state
;
9693 remembered_state
= rs
->next
;
9694 fc
->cfa_offset
= rs
->cfa_offset
;
9695 fc
->cfa_reg
= rs
->cfa_reg
;
9697 fc
->cfa_exp
= rs
->cfa_exp
;
9698 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9700 warn (_("Invalid column number in saved frame state\n"));
9704 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9705 memcpy (fc
->col_offset
, rs
->col_offset
,
9706 rs
->ncols
* sizeof (* rs
->col_offset
));
9707 free (rs
->col_type
);
9708 free (rs
->col_offset
);
9711 else if (do_debug_frames_interp
)
9712 printf ("Mismatched DW_CFA_restore_state\n");
9715 case DW_CFA_def_cfa
:
9716 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9717 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9719 if (! do_debug_frames_interp
)
9720 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9721 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9724 case DW_CFA_def_cfa_register
:
9725 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9727 if (! do_debug_frames_interp
)
9728 printf (" DW_CFA_def_cfa_register: %s\n",
9729 regname (fc
->cfa_reg
, 0));
9732 case DW_CFA_def_cfa_offset
:
9733 READ_ULEB (fc
->cfa_offset
, start
, block_end
);
9734 if (! do_debug_frames_interp
)
9735 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9739 if (! do_debug_frames_interp
)
9740 printf (" DW_CFA_nop\n");
9743 case DW_CFA_def_cfa_expression
:
9744 READ_ULEB (ul
, start
, block_end
);
9745 if (ul
> (size_t) (block_end
- start
))
9747 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9750 if (! do_debug_frames_interp
)
9752 printf (" DW_CFA_def_cfa_expression (");
9753 decode_location_expression (start
, eh_addr_size
, 0, -1,
9761 case DW_CFA_expression
:
9762 READ_ULEB (reg
, start
, block_end
);
9763 READ_ULEB (ul
, start
, block_end
);
9764 if (reg
>= (unsigned int) fc
->ncols
)
9765 reg_prefix
= bad_reg
;
9766 /* PR 17512: file: 069-133014-0.006. */
9767 /* PR 17512: file: 98c02eb4. */
9768 if (ul
> (size_t) (block_end
- start
))
9770 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9773 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9775 printf (" DW_CFA_expression: %s%s (",
9776 reg_prefix
, regname (reg
, 0));
9777 decode_location_expression (start
, eh_addr_size
, 0, -1,
9781 if (*reg_prefix
== '\0')
9782 fc
->col_type
[reg
] = DW_CFA_expression
;
9786 case DW_CFA_val_expression
:
9787 READ_ULEB (reg
, start
, block_end
);
9788 READ_ULEB (ul
, start
, block_end
);
9789 if (reg
>= (unsigned int) fc
->ncols
)
9790 reg_prefix
= bad_reg
;
9791 if (ul
> (size_t) (block_end
- start
))
9793 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9796 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9798 printf (" DW_CFA_val_expression: %s%s (",
9799 reg_prefix
, regname (reg
, 0));
9800 decode_location_expression (start
, eh_addr_size
, 0, -1,
9804 if (*reg_prefix
== '\0')
9805 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9809 case DW_CFA_offset_extended_sf
:
9810 READ_ULEB (reg
, start
, block_end
);
9811 READ_SLEB (l
, start
, block_end
);
9812 if (frame_need_space (fc
, reg
) < 0)
9813 reg_prefix
= bad_reg
;
9814 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9815 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9816 reg_prefix
, regname (reg
, 0),
9817 (long)(l
* fc
->data_factor
));
9818 if (*reg_prefix
== '\0')
9820 fc
->col_type
[reg
] = DW_CFA_offset
;
9821 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9825 case DW_CFA_val_offset_sf
:
9826 READ_ULEB (reg
, start
, block_end
);
9827 READ_SLEB (l
, start
, block_end
);
9828 if (frame_need_space (fc
, reg
) < 0)
9829 reg_prefix
= bad_reg
;
9830 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9831 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9832 reg_prefix
, regname (reg
, 0),
9833 (long)(l
* fc
->data_factor
));
9834 if (*reg_prefix
== '\0')
9836 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9837 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9841 case DW_CFA_def_cfa_sf
:
9842 READ_ULEB (fc
->cfa_reg
, start
, block_end
);
9843 READ_SLEB (l
, start
, block_end
);
9844 l
*= fc
->data_factor
;
9847 if (! do_debug_frames_interp
)
9848 printf (" DW_CFA_def_cfa_sf: %s ofs %ld\n",
9849 regname (fc
->cfa_reg
, 0), (long) l
);
9852 case DW_CFA_def_cfa_offset_sf
:
9853 READ_SLEB (l
, start
, block_end
);
9854 l
*= fc
->data_factor
;
9856 if (! do_debug_frames_interp
)
9857 printf (" DW_CFA_def_cfa_offset_sf: %ld\n", (long) l
);
9860 case DW_CFA_MIPS_advance_loc8
:
9861 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9862 if (do_debug_frames_interp
)
9863 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9865 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9866 (unsigned long) (ofs
* fc
->code_factor
),
9867 dwarf_vmatoa_1 (NULL
,
9868 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9870 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9873 case DW_CFA_GNU_window_save
:
9874 if (! do_debug_frames_interp
)
9875 printf (" DW_CFA_GNU_window_save\n");
9878 case DW_CFA_GNU_args_size
:
9879 READ_ULEB (ul
, start
, block_end
);
9880 if (! do_debug_frames_interp
)
9881 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9884 case DW_CFA_GNU_negative_offset_extended
:
9885 READ_ULEB (reg
, start
, block_end
);
9886 READ_SLEB (l
, start
, block_end
);
9888 if (frame_need_space (fc
, reg
) < 0)
9889 reg_prefix
= bad_reg
;
9890 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9891 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9892 reg_prefix
, regname (reg
, 0),
9893 (long)(l
* fc
->data_factor
));
9894 if (*reg_prefix
== '\0')
9896 fc
->col_type
[reg
] = DW_CFA_offset
;
9897 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9902 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9903 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9905 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9910 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9911 if (do_debug_frames_interp
&& ! all_nops
)
9912 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9914 if (fde_fc
.col_type
!= NULL
)
9916 free (fde_fc
.col_type
);
9917 fde_fc
.col_type
= NULL
;
9919 if (fde_fc
.col_offset
!= NULL
)
9921 free (fde_fc
.col_offset
);
9922 fde_fc
.col_offset
= NULL
;
9926 eh_addr_size
= saved_eh_addr_size
;
9931 while (remembered_state
!= NULL
)
9933 rs
= remembered_state
;
9934 remembered_state
= rs
->next
;
9935 free (rs
->col_type
);
9936 free (rs
->col_offset
);
9937 rs
->next
= NULL
; /* Paranoia. */
9941 while (chunks
!= NULL
)
9945 free (rs
->col_type
);
9946 free (rs
->col_offset
);
9947 rs
->next
= NULL
; /* Paranoia. */
9951 while (forward_refs
!= NULL
)
9954 forward_refs
= rs
->next
;
9955 free (rs
->col_type
);
9956 free (rs
->col_offset
);
9957 rs
->next
= NULL
; /* Paranoia. */
9967 display_debug_names (struct dwarf_section
*section
, void *file
)
9969 unsigned char *hdrptr
= section
->start
;
9970 dwarf_vma unit_length
;
9971 unsigned char *unit_start
;
9972 const unsigned char *const section_end
= section
->start
+ section
->size
;
9973 unsigned char *unit_end
;
9975 introduce (section
, false);
9977 load_debug_section_with_follow (str
, file
);
9979 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9981 unsigned int offset_size
;
9982 uint16_t dwarf_version
, padding
;
9983 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9984 uint64_t bucket_count
, name_count
, abbrev_table_size
;
9985 uint32_t augmentation_string_size
;
9987 bool augmentation_printable
;
9988 const char *augmentation_string
;
9991 unit_start
= hdrptr
;
9993 /* Get and check the length of the block. */
9994 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9996 if (unit_length
== 0xffffffff)
9998 /* This section is 64-bit DWARF. */
9999 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
10005 if (unit_length
> (size_t) (section_end
- hdrptr
)
10006 || unit_length
< 2 + 2 + 4 * 7)
10009 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
10011 (unsigned long) (unit_start
- section
->start
),
10012 dwarf_vmatoa ("x", unit_length
));
10015 unit_end
= hdrptr
+ unit_length
;
10017 /* Get and check the version number. */
10018 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
10019 printf (_("Version %ld\n"), (long) dwarf_version
);
10021 /* Prior versions did not exist, and future versions may not be
10022 backwards compatible. */
10023 if (dwarf_version
!= 5)
10025 warn (_("Only DWARF version 5 .debug_names "
10026 "is currently supported.\n"));
10030 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
10032 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
10035 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
10036 if (comp_unit_count
== 0)
10037 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
10039 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
10040 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
10041 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
10042 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
10043 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
10045 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
10046 if (augmentation_string_size
% 4 != 0)
10048 warn (_("Augmentation string length %u must be rounded up "
10049 "to a multiple of 4 in .debug_names.\n"),
10050 augmentation_string_size
);
10051 augmentation_string_size
+= (-augmentation_string_size
) & 3;
10053 if (augmentation_string_size
> (size_t) (unit_end
- hdrptr
))
10056 printf (_("Augmentation string:"));
10058 augmentation_printable
= true;
10059 augmentation_string
= (const char *) hdrptr
;
10061 for (i
= 0; i
< augmentation_string_size
; i
++)
10065 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
10066 printf (" %02x", uc
);
10068 if (uc
!= 0 && !ISPRINT (uc
))
10069 augmentation_printable
= false;
10072 if (augmentation_printable
)
10076 i
< augmentation_string_size
&& augmentation_string
[i
];
10078 putchar (augmentation_string
[i
]);
10083 printf (_("CU table:\n"));
10084 if (_mul_overflow (comp_unit_count
, offset_size
, &total
)
10085 || total
> (size_t) (unit_end
- hdrptr
))
10087 for (i
= 0; i
< comp_unit_count
; i
++)
10089 uint64_t cu_offset
;
10091 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
10092 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
10096 printf (_("TU table:\n"));
10097 if (_mul_overflow (local_type_unit_count
, offset_size
, &total
)
10098 || total
> (size_t) (unit_end
- hdrptr
))
10100 for (i
= 0; i
< local_type_unit_count
; i
++)
10102 uint64_t tu_offset
;
10104 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
10105 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
10109 printf (_("Foreign TU table:\n"));
10110 if (_mul_overflow (foreign_type_unit_count
, 8, &total
)
10111 || total
> (size_t) (unit_end
- hdrptr
))
10113 for (i
= 0; i
< foreign_type_unit_count
; i
++)
10115 uint64_t signature
;
10117 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
10118 printf (_("[%3u] "), i
);
10119 print_dwarf_vma (signature
, 8);
10124 uint64_t xtra
= (bucket_count
* sizeof (uint32_t)
10125 + name_count
* (sizeof (uint32_t) + 2 * offset_size
)
10126 + abbrev_table_size
);
10127 if (xtra
> (size_t) (unit_end
- hdrptr
))
10129 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
10130 "for unit 0x%lx in the debug_names\n"),
10132 (long) (unit_end
- unit_start
),
10133 (long) (unit_start
- section
->start
));
10136 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
10137 hdrptr
+= bucket_count
* sizeof (uint32_t);
10138 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
10139 hdrptr
+= name_count
* sizeof (uint32_t);
10140 unsigned char *const name_table_string_offsets
= hdrptr
;
10141 hdrptr
+= name_count
* offset_size
;
10142 unsigned char *const name_table_entry_offsets
= hdrptr
;
10143 hdrptr
+= name_count
* offset_size
;
10144 unsigned char *const abbrev_table
= hdrptr
;
10145 hdrptr
+= abbrev_table_size
;
10146 const unsigned char *const abbrev_table_end
= hdrptr
;
10147 unsigned char *const entry_pool
= hdrptr
;
10149 size_t buckets_filled
= 0;
10151 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
10153 const uint32_t bucket
= hash_table_buckets
[bucketi
];
10158 printf (ngettext ("Used %zu of %lu bucket.\n",
10159 "Used %zu of %lu buckets.\n",
10161 buckets_filled
, (unsigned long) bucket_count
);
10163 if (bucket_count
!= 0)
10165 uint32_t hash_prev
= 0;
10166 size_t hash_clash_count
= 0;
10167 size_t longest_clash
= 0;
10168 size_t this_length
= 0;
10170 for (hashi
= 0; hashi
< name_count
; hashi
++)
10172 const uint32_t hash_this
= hash_table_hashes
[hashi
];
10176 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
10178 ++hash_clash_count
;
10180 longest_clash
= MAX (longest_clash
, this_length
);
10185 hash_prev
= hash_this
;
10187 printf (_("Out of %lu items there are %zu bucket clashes"
10188 " (longest of %zu entries).\n"),
10189 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
10190 assert (name_count
== buckets_filled
+ hash_clash_count
);
10193 struct abbrev_lookup_entry
10195 dwarf_vma abbrev_tag
;
10196 unsigned char *abbrev_lookup_ptr
;
10198 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
10199 size_t abbrev_lookup_used
= 0;
10200 size_t abbrev_lookup_allocated
= 0;
10202 unsigned char *abbrevptr
= abbrev_table
;
10205 dwarf_vma abbrev_tag
;
10207 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
10208 if (abbrev_tag
== 0)
10210 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
10212 abbrev_lookup_allocated
= MAX (0x100,
10213 abbrev_lookup_allocated
* 2);
10214 abbrev_lookup
= xrealloc (abbrev_lookup
,
10215 (abbrev_lookup_allocated
10216 * sizeof (*abbrev_lookup
)));
10218 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
10219 struct abbrev_lookup_entry
*entry
;
10220 for (entry
= abbrev_lookup
;
10221 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10223 if (entry
->abbrev_tag
== abbrev_tag
)
10225 warn (_("Duplicate abbreviation tag %lu "
10226 "in unit 0x%lx in the debug_names\n"),
10227 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
10230 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
10231 entry
->abbrev_tag
= abbrev_tag
;
10232 entry
->abbrev_lookup_ptr
= abbrevptr
;
10234 /* Skip DWARF tag. */
10235 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
10238 dwarf_vma xindex
, form
;
10240 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10241 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10242 if (xindex
== 0 && form
== 0)
10247 printf (_("\nSymbol table:\n"));
10249 for (namei
= 0; namei
< name_count
; ++namei
)
10251 uint64_t string_offset
, entry_offset
;
10254 p
= name_table_string_offsets
+ namei
* offset_size
;
10255 SAFE_BYTE_GET (string_offset
, p
, offset_size
, unit_end
);
10256 p
= name_table_entry_offsets
+ namei
* offset_size
;
10257 SAFE_BYTE_GET (entry_offset
, p
, offset_size
, unit_end
);
10259 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
10260 fetch_indirect_string (string_offset
));
10262 unsigned char *entryptr
= entry_pool
+ entry_offset
;
10264 /* We need to scan first whether there is a single or multiple
10265 entries. TAGNO is -2 for the first entry, it is -1 for the
10266 initial tag read of the second entry, then it becomes 0 for the
10267 first entry for real printing etc. */
10269 /* Initialize it due to a false compiler warning. */
10270 dwarf_vma second_abbrev_tag
= -1;
10273 dwarf_vma abbrev_tag
;
10274 dwarf_vma dwarf_tag
;
10275 const struct abbrev_lookup_entry
*entry
;
10277 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
10280 second_abbrev_tag
= abbrev_tag
;
10282 entryptr
= entry_pool
+ entry_offset
;
10285 if (abbrev_tag
== 0)
10289 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
10290 (unsigned long) abbrev_tag
);
10292 for (entry
= abbrev_lookup
;
10293 entry
< abbrev_lookup
+ abbrev_lookup_used
;
10295 if (entry
->abbrev_tag
== abbrev_tag
)
10297 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
10299 warn (_("Undefined abbreviation tag %lu "
10300 "in unit 0x%lx in the debug_names\n"),
10302 (long) (unit_start
- section
->start
));
10305 abbrevptr
= entry
->abbrev_lookup_ptr
;
10306 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
10308 printf (" %s", get_TAG_name (dwarf_tag
));
10311 dwarf_vma xindex
, form
;
10313 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
10314 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
10315 if (xindex
== 0 && form
== 0)
10319 printf (" %s", get_IDX_name (xindex
));
10320 entryptr
= read_and_display_attr_value (0, form
, 0,
10321 unit_start
, entryptr
, unit_end
,
10323 dwarf_version
, NULL
,
10324 (tagno
< 0), section
,
10330 printf (_(" <no entries>"));
10334 free (abbrev_lookup
);
10341 display_debug_links (struct dwarf_section
* section
,
10342 void * file ATTRIBUTE_UNUSED
)
10344 const unsigned char * filename
;
10345 unsigned int filelen
;
10347 introduce (section
, false);
10349 /* The .gnu_debuglink section is formatted as:
10350 (c-string) Filename.
10351 (padding) If needed to reach a 4 byte boundary.
10352 (uint32_t) CRC32 value.
10354 The .gun_debugaltlink section is formatted as:
10355 (c-string) Filename.
10356 (binary) Build-ID. */
10358 filename
= section
->start
;
10359 filelen
= strnlen ((const char *) filename
, section
->size
);
10360 if (filelen
== section
->size
)
10362 warn (_("The debuglink filename is corrupt/missing\n"));
10366 printf (_(" Separate debug info file: %s\n"), filename
);
10368 if (startswith (section
->name
, ".gnu_debuglink"))
10370 unsigned int crc32
;
10371 unsigned int crc_offset
;
10373 crc_offset
= filelen
+ 1;
10374 crc_offset
= (crc_offset
+ 3) & ~3;
10375 if (crc_offset
+ 4 > section
->size
)
10377 warn (_("CRC offset missing/truncated\n"));
10381 crc32
= byte_get (filename
+ crc_offset
, 4);
10383 printf (_(" CRC value: %#x\n"), crc32
);
10385 if (crc_offset
+ 4 < section
->size
)
10387 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
10388 (long)(section
->size
- (crc_offset
+ 4)));
10392 else /* startswith (section->name, ".gnu_debugaltlink") */
10394 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
10395 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
10396 bfd_size_type printed
;
10398 /* FIXME: Should we support smaller build-id notes ? */
10399 if (build_id_len
< 0x14)
10401 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
10405 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
10406 display_data (printed
, build_id
, build_id_len
);
10415 display_gdb_index (struct dwarf_section
*section
,
10416 void *file ATTRIBUTE_UNUSED
)
10418 unsigned char *start
= section
->start
;
10420 uint32_t cu_list_offset
, tu_list_offset
;
10421 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
10422 unsigned int cu_list_elements
, tu_list_elements
;
10423 unsigned int address_table_elements
, symbol_table_slots
;
10424 unsigned char *cu_list
, *tu_list
;
10425 unsigned char *address_table
, *symbol_table
, *constant_pool
;
10428 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
10430 introduce (section
, false);
10432 if (section
->size
< 6 * sizeof (uint32_t))
10434 warn (_("Truncated header in the %s section.\n"), section
->name
);
10438 version
= byte_get_little_endian (start
, 4);
10439 printf (_("Version %ld\n"), (long) version
);
10441 /* Prior versions are obsolete, and future versions may not be
10442 backwards compatible. */
10443 if (version
< 3 || version
> 8)
10445 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
10449 warn (_("The address table data in version 3 may be wrong.\n"));
10451 warn (_("Version 4 does not support case insensitive lookups.\n"));
10453 warn (_("Version 5 does not include inlined functions.\n"));
10455 warn (_("Version 6 does not include symbol attributes.\n"));
10456 /* Version 7 indices generated by Gold have bad type unit references,
10457 PR binutils/15021. But we don't know if the index was generated by
10458 Gold or not, so to avoid worrying users with gdb-generated indices
10459 we say nothing for version 7 here. */
10461 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
10462 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
10463 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
10464 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
10465 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
10467 if (cu_list_offset
> section
->size
10468 || tu_list_offset
> section
->size
10469 || address_table_offset
> section
->size
10470 || symbol_table_offset
> section
->size
10471 || constant_pool_offset
> section
->size
10472 || tu_list_offset
< cu_list_offset
10473 || address_table_offset
< tu_list_offset
10474 || symbol_table_offset
< address_table_offset
10475 || constant_pool_offset
< symbol_table_offset
)
10477 warn (_("Corrupt header in the %s section.\n"), section
->name
);
10481 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 16;
10482 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 24;
10483 address_table_elements
= (symbol_table_offset
- address_table_offset
) / 20;
10484 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
10486 cu_list
= start
+ cu_list_offset
;
10487 tu_list
= start
+ tu_list_offset
;
10488 address_table
= start
+ address_table_offset
;
10489 symbol_table
= start
+ symbol_table_offset
;
10490 constant_pool
= start
+ constant_pool_offset
;
10492 printf (_("\nCU table:\n"));
10493 for (i
= 0; i
< cu_list_elements
; i
++)
10495 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 16, 8);
10496 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 16 + 8, 8);
10498 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
,
10499 (unsigned long) cu_offset
,
10500 (unsigned long) (cu_offset
+ cu_length
- 1));
10503 printf (_("\nTU table:\n"));
10504 for (i
= 0; i
< tu_list_elements
; i
++)
10506 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 24, 8);
10507 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 24 + 8, 8);
10508 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 24 + 16, 8);
10510 printf (_("[%3u] 0x%lx 0x%lx "), i
,
10511 (unsigned long) tu_offset
,
10512 (unsigned long) type_offset
);
10513 print_dwarf_vma (signature
, 8);
10517 printf (_("\nAddress table:\n"));
10518 for (i
= 0; i
< address_table_elements
; i
++)
10520 uint64_t low
= byte_get_little_endian (address_table
+ i
* 20, 8);
10521 uint64_t high
= byte_get_little_endian (address_table
+ i
* 20 + 8, 8);
10522 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 20 + 16, 4);
10524 print_dwarf_vma (low
, 8);
10525 print_dwarf_vma (high
, 8);
10526 printf (_("%lu\n"), (unsigned long) cu_index
);
10529 printf (_("\nSymbol table:\n"));
10530 for (i
= 0; i
< symbol_table_slots
; ++i
)
10532 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10533 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10534 uint32_t num_cus
, cu
;
10536 if (name_offset
!= 0
10537 || cu_vector_offset
!= 0)
10541 /* PR 17531: file: 5b7b07ad. */
10542 if (name_offset
>= section
->size
- constant_pool_offset
)
10544 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10545 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10549 printf ("[%3u] %.*s:", i
,
10550 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10551 constant_pool
+ name_offset
);
10553 if (section
->size
- constant_pool_offset
< 4
10554 || cu_vector_offset
> section
->size
- constant_pool_offset
- 4)
10556 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10557 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10558 cu_vector_offset
, i
);
10562 num_cus
= byte_get_little_endian (constant_pool
+ cu_vector_offset
, 4);
10564 if ((uint64_t) num_cus
* 4 > section
->size
- (constant_pool_offset
10565 + cu_vector_offset
+ 4))
10567 printf ("<invalid number of CUs: %d>\n", num_cus
);
10568 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10576 for (j
= 0; j
< num_cus
; ++j
)
10579 gdb_index_symbol_kind kind
;
10581 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10582 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10583 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10584 cu
= GDB_INDEX_CU_VALUE (cu
);
10585 /* Convert to TU number if it's for a type unit. */
10586 if (cu
>= cu_list_elements
/ 2)
10587 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10588 (unsigned long) (cu
- cu_list_elements
/ 2));
10590 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10592 printf (" [%s, %s]",
10593 is_static
? _("static") : _("global"),
10594 get_gdb_index_symbol_kind_name (kind
));
10606 /* Pre-allocate enough space for the CU/TU sets needed. */
10609 prealloc_cu_tu_list (unsigned int nshndx
)
10611 if (shndx_pool
== NULL
)
10613 shndx_pool_size
= nshndx
;
10614 shndx_pool_used
= 0;
10615 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10616 sizeof (unsigned int));
10620 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10621 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10622 sizeof (unsigned int));
10627 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10629 if (shndx_pool_used
>= shndx_pool_size
)
10631 error (_("Internal error: out of space in the shndx pool.\n"));
10634 shndx_pool
[shndx_pool_used
++] = shndx
;
10638 end_cu_tu_entry (void)
10640 if (shndx_pool_used
>= shndx_pool_size
)
10642 error (_("Internal error: out of space in the shndx pool.\n"));
10645 shndx_pool
[shndx_pool_used
++] = 0;
10648 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10650 static const char *
10651 get_DW_SECT_short_name (unsigned int dw_sect
)
10653 static char buf
[16];
10659 case DW_SECT_TYPES
:
10661 case DW_SECT_ABBREV
:
10667 case DW_SECT_STR_OFFSETS
:
10669 case DW_SECT_MACINFO
:
10671 case DW_SECT_MACRO
:
10677 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10681 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10682 These sections are extensions for Fission.
10683 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10686 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10688 unsigned char *phdr
= section
->start
;
10689 unsigned char *limit
= phdr
+ section
->size
;
10690 unsigned char *phash
;
10691 unsigned char *pindex
;
10692 unsigned char *ppool
;
10693 unsigned int version
;
10694 unsigned int ncols
= 0;
10695 unsigned int nused
;
10696 unsigned int nslots
;
10699 dwarf_vma signature
;
10702 /* PR 17512: file: 002-168123-0.004. */
10705 warn (_("Section %s is empty\n"), section
->name
);
10708 /* PR 17512: file: 002-376-0.004. */
10709 if (section
->size
< 24)
10711 warn (_("Section %s is too small to contain a CU/TU header\n"),
10717 SAFE_BYTE_GET_AND_INC (version
, phash
, 4, limit
);
10719 SAFE_BYTE_GET_AND_INC (ncols
, phash
, 4, limit
);
10720 SAFE_BYTE_GET_AND_INC (nused
, phash
, 4, limit
);
10721 SAFE_BYTE_GET_AND_INC (nslots
, phash
, 4, limit
);
10723 pindex
= phash
+ (size_t) nslots
* 8;
10724 ppool
= pindex
+ (size_t) nslots
* 4;
10728 introduce (section
, false);
10730 printf (_(" Version: %u\n"), version
);
10732 printf (_(" Number of columns: %u\n"), ncols
);
10733 printf (_(" Number of used entries: %u\n"), nused
);
10734 printf (_(" Number of slots: %u\n\n"), nslots
);
10737 /* PR 17531: file: 45d69832. */
10738 if (_mul_overflow ((size_t) nslots
, 12, &total
)
10739 || total
> (size_t) (limit
- phash
))
10741 warn (ngettext ("Section %s is too small for %u slot\n",
10742 "Section %s is too small for %u slots\n",
10744 section
->name
, nslots
);
10751 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10752 for (i
= 0; i
< nslots
; i
++)
10754 unsigned char *shndx_list
;
10755 unsigned int shndx
;
10757 SAFE_BYTE_GET (signature
, phash
, 8, limit
);
10758 if (signature
!= 0)
10760 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10761 shndx_list
= ppool
+ j
* 4;
10762 /* PR 17531: file: 705e010d. */
10763 if (shndx_list
< ppool
)
10765 warn (_("Section index pool located before start of section\n"));
10770 printf (_(" [%3d] Signature: 0x%s Sections: "),
10771 i
, dwarf_vmatoa ("x", signature
));
10774 if (shndx_list
>= limit
)
10776 warn (_("Section %s too small for shndx pool\n"),
10780 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10784 printf (" %d", shndx
);
10786 add_shndx_to_cu_tu_entry (shndx
);
10792 end_cu_tu_entry ();
10798 else if (version
== 2)
10801 unsigned int dw_sect
;
10802 unsigned char *ph
= phash
;
10803 unsigned char *pi
= pindex
;
10804 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10805 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10807 struct cu_tu_set
*this_set
= NULL
;
10809 unsigned char *prow
;
10812 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10814 /* PR 17531: file: 0dd159bf.
10815 Check for integer overflow (can occur when size_t is 32-bit)
10816 with overlarge ncols or nused values. */
10818 || _mul_overflow ((size_t) ncols
, 4, &temp
)
10819 || _mul_overflow ((size_t) nused
+ 1, temp
, &total
)
10820 || total
> (size_t) (limit
- ppool
))
10822 warn (_("Section %s too small for offset and size tables\n"),
10829 printf (_(" Offset table\n"));
10830 printf (" slot %-16s ",
10831 is_tu_index
? _("signature") : _("dwo_id"));
10838 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10839 this_set
= tu_sets
;
10844 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10845 this_set
= cu_sets
;
10851 for (j
= 0; j
< ncols
; j
++)
10853 unsigned char *p
= ppool
+ j
* 4;
10854 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10855 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10860 for (i
= 0; i
< nslots
; i
++)
10862 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10864 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10867 /* PR 17531: file: a05f6ab3. */
10870 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10877 size_t num_copy
= sizeof (uint64_t);
10879 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10882 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10884 printf (_(" [%3d] 0x%s"),
10885 i
, dwarf_vmatoa ("x", signature
));
10886 for (j
= 0; j
< ncols
; j
++)
10888 unsigned char *p
= prow
+ j
* 4;
10889 SAFE_BYTE_GET (val
, p
, 4, limit
);
10891 printf (" %8d", val
);
10895 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10897 /* PR 17531: file: 10796eb3. */
10898 if (dw_sect
>= DW_SECT_MAX
)
10899 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10901 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10917 printf (_(" Size table\n"));
10918 printf (" slot %-16s ",
10919 is_tu_index
? _("signature") : _("dwo_id"));
10922 for (j
= 0; j
< ncols
; j
++)
10924 unsigned char *p
= ppool
+ j
* 4;
10925 SAFE_BYTE_GET (val
, p
, 4, limit
);
10927 printf (" %8s", get_DW_SECT_short_name (val
));
10933 for (i
= 0; i
< nslots
; i
++)
10935 SAFE_BYTE_GET (signature
, ph
, 8, limit
);
10937 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10940 prow
= psizes
+ (row
- 1) * ncols
* 4;
10943 printf (_(" [%3d] 0x%s"),
10944 i
, dwarf_vmatoa ("x", signature
));
10946 for (j
= 0; j
< ncols
; j
++)
10948 unsigned char *p
= prow
+ j
* 4;
10950 /* PR 28645: Check for overflow. Since we do not know how
10951 many populated rows there will be, we cannot just
10952 perform a single check at the start of this function. */
10953 if (p
> (limit
- 4))
10957 warn (_("Too many rows/columns in DWARF index section %s\n"),
10962 SAFE_BYTE_GET (val
, p
, 4, limit
);
10965 printf (" %8d", val
);
10969 SAFE_BYTE_GET (dw_sect
, p
, 4, limit
);
10970 if (dw_sect
>= DW_SECT_MAX
)
10971 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10973 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10985 else if (do_display
)
10986 printf (_(" Unsupported version (%d)\n"), version
);
10994 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10996 /* Load the CU and TU indexes if present. This will build a list of
10997 section sets that we can use to associate a .debug_info.dwo section
10998 with its associated .debug_abbrev.dwo section in a .dwp file. */
11001 load_cu_tu_indexes (void *file
)
11003 /* If we have already loaded (or tried to load) the CU and TU indexes
11004 then do not bother to repeat the task. */
11005 if (cu_tu_indexes_read
== -1)
11007 cu_tu_indexes_read
= true;
11009 if (load_debug_section_with_follow (dwp_cu_index
, file
))
11010 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
11011 cu_tu_indexes_read
= false;
11013 if (load_debug_section_with_follow (dwp_tu_index
, file
))
11014 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
11015 cu_tu_indexes_read
= false;
11018 return (bool) cu_tu_indexes_read
;
11021 /* Find the set of sections that includes section SHNDX. */
11024 find_cu_tu_set (void *file
, unsigned int shndx
)
11028 if (! load_cu_tu_indexes (file
))
11031 /* Find SHNDX in the shndx pool. */
11032 for (i
= 0; i
< shndx_pool_used
; i
++)
11033 if (shndx_pool
[i
] == shndx
)
11036 if (i
>= shndx_pool_used
)
11039 /* Now backup to find the first entry in the set. */
11040 while (i
> 0 && shndx_pool
[i
- 1] != 0)
11043 return shndx_pool
+ i
;
11046 /* Display a .debug_cu_index or .debug_tu_index section. */
11049 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
11051 return process_cu_tu_index (section
, 1);
11055 display_debug_not_supported (struct dwarf_section
*section
,
11056 void *file ATTRIBUTE_UNUSED
)
11058 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
11064 /* Like malloc, but takes two parameters like calloc.
11065 Verifies that the first parameter is not too large.
11066 Note: does *not* initialise the allocated memory to zero. */
11069 cmalloc (size_t nmemb
, size_t size
)
11071 /* Check for overflow. */
11072 if (nmemb
>= ~(size_t) 0 / size
)
11075 return xmalloc (nmemb
* size
);
11078 /* Like xmalloc, but takes two parameters like calloc.
11079 Verifies that the first parameter is not too large.
11080 Note: does *not* initialise the allocated memory to zero. */
11083 xcmalloc (size_t nmemb
, size_t size
)
11085 /* Check for overflow. */
11086 if (nmemb
>= ~(size_t) 0 / size
)
11089 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
11094 return xmalloc (nmemb
* size
);
11097 /* Like xrealloc, but takes three parameters.
11098 Verifies that the second parameter is not too large.
11099 Note: does *not* initialise any new memory to zero. */
11102 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
11104 /* Check for overflow. */
11105 if (nmemb
>= ~(size_t) 0 / size
)
11107 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
11112 return xrealloc (ptr
, nmemb
* size
);
11115 /* Like xcalloc, but verifies that the first parameter is not too large. */
11118 xcalloc2 (size_t nmemb
, size_t size
)
11120 /* Check for overflow. */
11121 if (nmemb
>= ~(size_t) 0 / size
)
11123 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
11128 return xcalloc (nmemb
, size
);
11131 static unsigned long
11132 calc_gnu_debuglink_crc32 (unsigned long crc
,
11133 const unsigned char * buf
,
11136 static const unsigned long crc32_table
[256] =
11138 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
11139 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
11140 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
11141 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
11142 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
11143 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
11144 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
11145 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
11146 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
11147 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
11148 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
11149 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
11150 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
11151 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
11152 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
11153 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
11154 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
11155 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
11156 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
11157 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
11158 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
11159 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
11160 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
11161 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
11162 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
11163 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
11164 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
11165 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
11166 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
11167 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
11168 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
11169 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
11170 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
11171 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
11172 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
11173 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
11174 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
11175 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
11176 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
11177 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
11178 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
11179 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
11180 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
11181 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
11182 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
11183 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
11184 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
11185 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
11186 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
11187 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
11188 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
11191 const unsigned char *end
;
11193 crc
= ~crc
& 0xffffffff;
11194 for (end
= buf
+ len
; buf
< end
; ++ buf
)
11195 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
11196 return ~crc
& 0xffffffff;
11199 typedef bool (*check_func_type
) (const char *, void *);
11200 typedef const char *(* parse_func_type
) (struct dwarf_section
*, void *);
11203 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
11205 static unsigned char buffer
[8 * 1024];
11207 bfd_size_type count
;
11208 unsigned long crc
= 0;
11211 sep_data
= open_debug_file (pathname
);
11212 if (sep_data
== NULL
)
11215 /* Yes - we are opening the file twice... */
11216 f
= fopen (pathname
, "rb");
11219 /* Paranoia: This should never happen. */
11220 close_debug_file (sep_data
);
11221 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
11225 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
11226 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
11230 if (crc
!= * (unsigned long *) crc_pointer
)
11232 close_debug_file (sep_data
);
11233 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
11241 static const char *
11242 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
11245 unsigned int crc_offset
;
11246 unsigned long * crc32
= (unsigned long *) data
;
11248 /* The name is first.
11249 The CRC value is stored after the filename, aligned up to 4 bytes. */
11250 name
= (const char *) section
->start
;
11252 crc_offset
= strnlen (name
, section
->size
) + 1;
11253 if (crc_offset
== 1)
11255 crc_offset
= (crc_offset
+ 3) & ~3;
11256 if (crc_offset
+ 4 > section
->size
)
11259 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
11264 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
11266 void * sep_data
= open_debug_file (filename
);
11268 if (sep_data
== NULL
)
11271 /* FIXME: We should now extract the build-id in the separate file
11277 typedef struct build_id_data
11280 const unsigned char * data
;
11283 static const char *
11284 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
11287 bfd_size_type namelen
;
11288 bfd_size_type id_len
;
11289 Build_id_data
* build_id_data
;
11291 /* The name is first.
11292 The build-id follows immediately, with no padding, up to the section's end. */
11294 name
= (const char *) section
->start
;
11295 namelen
= strnlen (name
, section
->size
) + 1;
11298 if (namelen
>= section
->size
)
11301 id_len
= section
->size
- namelen
;
11305 build_id_data
= (Build_id_data
*) data
;
11306 build_id_data
->len
= id_len
;
11307 build_id_data
->data
= section
->start
+ namelen
;
11313 add_separate_debug_file (const char * filename
, void * handle
)
11315 separate_info
* i
= xmalloc (sizeof * i
);
11317 i
->filename
= filename
;
11318 i
->handle
= handle
;
11319 i
->next
= first_separate_info
;
11320 first_separate_info
= i
;
11323 #if HAVE_LIBDEBUGINFOD
11324 /* Query debuginfod servers for the target debuglink or debugaltlink
11325 file. If successful, store the path of the file in filename and
11326 return TRUE, otherwise return FALSE. */
11329 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
11333 size_t build_id_len
;
11334 unsigned char * build_id
;
11336 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
11338 /* Get the build-id of file. */
11339 build_id
= get_build_id (file
);
11342 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
11344 /* Get the build-id of the debugaltlink file. */
11345 unsigned int filelen
;
11347 filelen
= strnlen ((const char *)section
->start
, section
->size
);
11348 if (filelen
== section
->size
)
11349 /* Corrupt debugaltlink. */
11352 build_id
= section
->start
+ filelen
+ 1;
11353 build_id_len
= section
->size
- (filelen
+ 1);
11355 if (build_id_len
== 0)
11364 debuginfod_client
* client
;
11366 client
= debuginfod_begin ();
11367 if (client
== NULL
)
11370 /* Query debuginfod servers for the target file. If found its path
11371 will be stored in filename. */
11372 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
11373 debuginfod_end (client
);
11375 /* Only free build_id if we allocated space for a hex string
11376 in get_build_id (). */
11377 if (build_id_len
== 0)
11382 /* File successfully retrieved. Close fd since we want to
11383 use open_debug_file () on filename instead. */
11391 #endif /* HAVE_LIBDEBUGINFOD */
11394 load_separate_debug_info (const char * main_filename
,
11395 struct dwarf_section
* xlink
,
11396 parse_func_type parse_func
,
11397 check_func_type check_func
,
11399 void * file ATTRIBUTE_UNUSED
)
11401 const char * separate_filename
;
11402 char * debug_filename
;
11404 size_t canon_dirlen
;
11406 char * canon_filename
;
11407 char * canon_debug_filename
;
11410 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
11412 warn (_("Corrupt debuglink section: %s\n"),
11413 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
11417 /* Attempt to locate the separate file.
11418 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
11420 canon_filename
= lrealpath (main_filename
);
11421 canon_dir
= xstrdup (canon_filename
);
11423 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
11424 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
11426 canon_dir
[canon_dirlen
] = '\0';
11429 #define DEBUGDIR "/lib/debug"
11431 #ifndef EXTRA_DEBUG_ROOT1
11432 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
11434 #ifndef EXTRA_DEBUG_ROOT2
11435 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
11438 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
11440 + strlen (".debug/")
11441 #ifdef EXTRA_DEBUG_ROOT1
11442 + strlen (EXTRA_DEBUG_ROOT1
)
11444 #ifdef EXTRA_DEBUG_ROOT2
11445 + strlen (EXTRA_DEBUG_ROOT2
)
11447 + strlen (separate_filename
)
11449 if (debug_filename
== NULL
)
11451 warn (_("Out of memory"));
11453 free (canon_filename
);
11457 /* First try in the current directory. */
11458 sprintf (debug_filename
, "%s", separate_filename
);
11459 if (check_func (debug_filename
, func_data
))
11462 /* Then try in a subdirectory called .debug. */
11463 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11464 if (check_func (debug_filename
, func_data
))
11467 /* Then try in the same directory as the original file. */
11468 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11469 if (check_func (debug_filename
, func_data
))
11472 /* And the .debug subdirectory of that directory. */
11473 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11474 if (check_func (debug_filename
, func_data
))
11477 #ifdef EXTRA_DEBUG_ROOT1
11478 /* Try the first extra debug file root. */
11479 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11480 if (check_func (debug_filename
, func_data
))
11483 /* Try the first extra debug file root. */
11484 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11485 if (check_func (debug_filename
, func_data
))
11489 #ifdef EXTRA_DEBUG_ROOT2
11490 /* Try the second extra debug file root. */
11491 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
11492 if (check_func (debug_filename
, func_data
))
11496 /* Then try in the global debug_filename directory. */
11497 strcpy (debug_filename
, DEBUGDIR
);
11498 dirlen
= strlen (DEBUGDIR
) - 1;
11499 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
11500 strcat (debug_filename
, "/");
11501 strcat (debug_filename
, (const char *) separate_filename
);
11503 if (check_func (debug_filename
, func_data
))
11506 #if HAVE_LIBDEBUGINFOD
11508 char * tmp_filename
;
11511 && debuginfod_fetch_separate_debug_info (xlink
,
11515 /* File successfully downloaded from server, replace
11516 debug_filename with the file's path. */
11517 free (debug_filename
);
11518 debug_filename
= tmp_filename
;
11524 if (do_debug_links
)
11526 /* Failed to find the file. */
11527 warn (_("could not find separate debug file '%s'\n"),
11528 separate_filename
);
11529 warn (_("tried: %s\n"), debug_filename
);
11531 #ifdef EXTRA_DEBUG_ROOT2
11532 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
,
11533 separate_filename
);
11534 warn (_("tried: %s\n"), debug_filename
);
11537 #ifdef EXTRA_DEBUG_ROOT1
11538 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
,
11539 canon_dir
, separate_filename
);
11540 warn (_("tried: %s\n"), debug_filename
);
11542 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
,
11543 separate_filename
);
11544 warn (_("tried: %s\n"), debug_filename
);
11547 sprintf (debug_filename
, "%s.debug/%s", canon_dir
,
11548 separate_filename
);
11549 warn (_("tried: %s\n"), debug_filename
);
11551 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11552 warn (_("tried: %s\n"), debug_filename
);
11554 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11555 warn (_("tried: %s\n"), debug_filename
);
11557 sprintf (debug_filename
, "%s", separate_filename
);
11558 warn (_("tried: %s\n"), debug_filename
);
11560 #if HAVE_LIBDEBUGINFOD
11561 if (use_debuginfod
)
11563 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11568 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11574 free (debug_filename
);
11575 free (canon_filename
);
11581 canon_debug_filename
= lrealpath (debug_filename
);
11582 self
= strcmp (canon_debug_filename
, canon_filename
) == 0;
11583 free (canon_filename
);
11584 free (canon_debug_filename
);
11587 free (debug_filename
);
11591 void * debug_handle
;
11593 /* Now open the file.... */
11594 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11596 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11597 free (debug_filename
);
11601 /* FIXME: We do not check to see if there are any other separate debug info
11602 files that would also match. */
11604 if (do_debug_links
)
11605 printf (_("\n%s: Found separate debug info file: %s\n"), main_filename
, debug_filename
);
11606 add_separate_debug_file (debug_filename
, debug_handle
);
11608 /* Do not free debug_filename - it might be referenced inside
11609 the structure returned by open_debug_file(). */
11610 return debug_handle
;
11613 /* Attempt to load a separate dwarf object file. */
11616 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11618 char * separate_filename
;
11619 void * separate_handle
;
11621 if (IS_ABSOLUTE_PATH (name
))
11622 separate_filename
= strdup (name
);
11624 /* FIXME: Skip adding / if dwo_dir ends in /. */
11625 separate_filename
= concat (dir
, "/", name
, NULL
);
11626 if (separate_filename
== NULL
)
11628 warn (_("Out of memory allocating dwo filename\n"));
11632 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11634 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11635 free (separate_filename
);
11639 /* FIXME: We should check the dwo_id. */
11641 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11643 add_separate_debug_file (separate_filename
, separate_handle
);
11644 /* Note - separate_filename will be freed in free_debug_memory(). */
11645 return separate_handle
;
11649 try_build_id_prefix (const char * prefix
, char * filename
, const unsigned char * data
, unsigned long id_len
)
11651 char * f
= filename
;
11653 f
+= sprintf (f
, "%s.build-id/%02x/", prefix
, (unsigned) *data
++);
11656 f
+= sprintf (f
, "%02x", (unsigned) *data
++);
11657 strcpy (f
, ".debug");
11659 return open_debug_file (filename
);
11662 /* Try to load a debug file based upon the build-id held in the .note.gnu.build-id section. */
11665 load_build_id_debug_file (const char * main_filename ATTRIBUTE_UNUSED
, void * main_file
)
11667 if (! load_debug_section (note_gnu_build_id
, main_file
))
11668 return; /* No .note.gnu.build-id section. */
11670 struct dwarf_section
* section
= & debug_displays
[note_gnu_build_id
].section
;
11671 if (section
== NULL
)
11673 warn (_("Unable to load the .note.gnu.build-id section\n"));
11677 if (section
->start
== NULL
|| section
->size
< 0x18)
11679 warn (_(".note.gnu.build-id section is corrupt/empty\n"));
11683 /* In theory we should extract the contents of the section into
11684 a note structure and then check the fields. For now though
11685 just use hard coded offsets instead:
11687 Field Bytes Contents
11690 Type 8..11 3 (NT_GNU_BUILD_ID)
11694 /* FIXME: Check the name size, name and type fields. */
11696 unsigned long build_id_size
;
11697 build_id_size
= byte_get (section
->start
+ 4, 4);
11698 if (build_id_size
< 8)
11700 warn (_(".note.gnu.build-id data size is too small\n"));
11704 if (build_id_size
> (section
->size
- 16))
11706 warn (_(".note.gnu.build-id data size is too bug\n"));
11711 filename
= xmalloc (strlen (".build-id/")
11712 + build_id_size
* 2 + 2
11713 + strlen (".debug")
11714 /* The next string should be the same as the longest
11715 name found in the prefixes[] array below. */
11716 + strlen ("/usrlib64/debug/usr")
11720 static const char * prefixes
[] =
11725 "/usr/lib/debug/usr/",
11726 "/usr/lib64/debug/",
11727 "/usr/lib64/debug/usr"
11729 long unsigned int i
;
11731 for (i
= 0; i
< ARRAY_SIZE (prefixes
); i
++)
11733 handle
= try_build_id_prefix (prefixes
[i
], filename
,
11734 section
->start
+ 16, build_id_size
);
11735 if (handle
!= NULL
)
11738 /* FIXME: TYhe BFD library also tries a global debugfile directory prefix. */
11739 if (handle
== NULL
)
11741 /* Failed to find a debug file associated with the build-id.
11742 This is not an error however, rather it just means that
11743 the debug info has probably not been loaded on the system,
11744 or that another method is being used to link to the debug
11750 add_separate_debug_file (filename
, handle
);
11753 /* Try to load a debug file pointed to by the .debug_sup section. */
11756 load_debug_sup_file (const char * main_filename
, void * file
)
11758 if (! load_debug_section (debug_sup
, file
))
11759 return; /* No .debug_sup section. */
11761 struct dwarf_section
* section
;
11762 section
= & debug_displays
[debug_sup
].section
;
11763 assert (section
!= NULL
);
11765 if (section
->start
== NULL
|| section
->size
< 5)
11767 warn (_(".debug_sup section is corrupt/empty\n"));
11771 if (section
->start
[2] != 0)
11772 return; /* This is a supplementary file. */
11774 const char * filename
= (const char *) section
->start
+ 3;
11775 if (strnlen (filename
, section
->size
- 3) == section
->size
- 3)
11777 warn (_("filename in .debug_sup section is corrupt\n"));
11781 if (filename
[0] != '/' && strchr (main_filename
, '/'))
11786 new_len
= asprintf (& new_name
, "%.*s/%s",
11787 (int) (strrchr (main_filename
, '/') - main_filename
),
11792 warn (_("unable to construct path for supplementary debug file"));
11797 filename
= new_name
;
11801 /* PR 27796: Make sure that we pass a filename that can be free'd to
11802 add_separate_debug_file(). */
11803 filename
= strdup (filename
);
11804 if (filename
== NULL
)
11806 warn (_("out of memory constructing filename for .debug_sup link\n"));
11811 void * handle
= open_debug_file (filename
);
11812 if (handle
== NULL
)
11814 warn (_("unable to open file '%s' referenced from .debug_sup section\n"), filename
);
11815 free ((void *) filename
);
11819 printf (_("%s: Found supplementary debug file: %s\n\n"), main_filename
, filename
);
11821 /* FIXME: Compare the checksums, if present. */
11822 add_separate_debug_file (filename
, handle
);
11825 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11826 Recursively check the loaded files for more of these sections.
11827 Also follow any links in .debug_sup sections.
11828 FIXME: Should also check for DWO_* entries in the newly loaded files. */
11831 check_for_and_load_links (void * file
, const char * filename
)
11833 void * handle
= NULL
;
11835 if (load_debug_section (gnu_debugaltlink
, file
))
11837 Build_id_data build_id_data
;
11839 handle
= load_separate_debug_info (filename
,
11840 & debug_displays
[gnu_debugaltlink
].section
,
11841 parse_gnu_debugaltlink
,
11842 check_gnu_debugaltlink
,
11847 assert (handle
== first_separate_info
->handle
);
11848 check_for_and_load_links (first_separate_info
->handle
,
11849 first_separate_info
->filename
);
11853 if (load_debug_section (gnu_debuglink
, file
))
11855 unsigned long crc32
;
11857 handle
= load_separate_debug_info (filename
,
11858 & debug_displays
[gnu_debuglink
].section
,
11859 parse_gnu_debuglink
,
11860 check_gnu_debuglink
,
11865 assert (handle
== first_separate_info
->handle
);
11866 check_for_and_load_links (first_separate_info
->handle
,
11867 first_separate_info
->filename
);
11871 load_debug_sup_file (filename
, file
);
11873 load_build_id_debug_file (filename
, file
);
11876 /* Load the separate debug info file(s) attached to FILE, if any exist.
11877 Returns TRUE if any were found, FALSE otherwise.
11878 If TRUE is returned then the linked list starting at first_separate_info
11879 will be populated with open file handles. */
11882 load_separate_debug_files (void * file
, const char * filename
)
11884 /* Skip this operation if we are not interested in debug links. */
11885 if (! do_follow_links
&& ! do_debug_links
)
11888 /* See if there are any dwo links. */
11889 if (load_debug_section (str
, file
)
11890 && load_debug_section (abbrev
, file
)
11891 && load_debug_section (info
, file
))
11895 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11898 bool introduced
= false;
11900 const char *dir
= NULL
;
11901 const char *id
= NULL
;
11902 const char *name
= NULL
;
11904 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11906 /* Accumulate NAME, DIR and ID fields. */
11907 switch (dwinfo
->type
)
11911 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11912 name
= dwinfo
->value
;
11916 /* There can be multiple DW_AT_comp_dir entries in a CU,
11917 so do not complain. */
11918 dir
= dwinfo
->value
;
11923 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11924 id
= dwinfo
->value
;
11928 error (_("Unexpected DWO INFO type"));
11932 /* If we have reached the end of our list, or we are changing
11933 CUs, then display the information that we have accumulated
11936 && (dwinfo
->next
== NULL
11937 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11939 if (do_debug_links
)
11943 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11944 debug_displays
[info
].section
.uncompressed_name
);
11948 printf (_(" Name: %s\n"), name
);
11949 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11951 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11953 printf (_(" ID: <not specified>\n"));
11957 if (do_follow_links
)
11958 load_dwo_file (filename
, name
, dir
, id
);
11960 name
= dir
= id
= NULL
;
11966 if (! do_follow_links
)
11967 /* The other debug links will be displayed by display_debug_links()
11968 so we do not need to do any further processing here. */
11971 /* FIXME: We do not check for the presence of both link sections in the same file. */
11972 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11973 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11975 check_for_and_load_links (file
, filename
);
11976 if (first_separate_info
!= NULL
)
11979 do_follow_links
= 0;
11984 free_debug_memory (void)
11988 free_all_abbrevs ();
11990 free (cu_abbrev_map
);
11991 cu_abbrev_map
= NULL
;
11992 next_free_abbrev_map_entry
= 0;
11996 shndx_pool_size
= 0;
11997 shndx_pool_used
= 0;
12005 memset (level_type_signed
, 0, sizeof level_type_signed
);
12006 cu_tu_indexes_read
= -1;
12008 for (i
= 0; i
< max
; i
++)
12009 free_debug_section ((enum dwarf_section_display_enum
) i
);
12011 if (debug_information
!= NULL
)
12013 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
12015 if (debug_information
[i
].max_loc_offsets
)
12017 free (debug_information
[i
].loc_offsets
);
12018 free (debug_information
[i
].have_frame_base
);
12020 if (debug_information
[i
].max_range_lists
)
12021 free (debug_information
[i
].range_lists
);
12023 free (debug_information
);
12024 debug_information
= NULL
;
12025 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
12029 separate_info
* next
;
12031 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
12033 close_debug_file (d
->handle
);
12034 free ((void *) d
->filename
);
12038 first_separate_info
= NULL
;
12043 /* Enable display of specific DWARF sections as determined by the comma
12044 separated strings in NAMES. Returns non-zero if any displaying was
12048 dwarf_select_sections_by_names (const char *names
)
12052 const char * option
;
12056 debug_dump_long_opts
;
12058 static const debug_dump_long_opts opts_table
[] =
12060 /* Please keep this table alpha- sorted. */
12061 { "Ranges", & do_debug_ranges
, 1 },
12062 { "abbrev", & do_debug_abbrevs
, 1 },
12063 { "addr", & do_debug_addr
, 1 },
12064 { "aranges", & do_debug_aranges
, 1 },
12065 { "cu_index", & do_debug_cu_index
, 1 },
12066 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
12067 #ifdef HAVE_LIBDEBUGINFOD
12068 { "do-not-use-debuginfod", & use_debuginfod
, 0 },
12070 { "follow-links", & do_follow_links
, 1 },
12071 { "frames", & do_debug_frames
, 1 },
12072 { "frames-interp", & do_debug_frames_interp
, 1 },
12073 /* The special .gdb_index section. */
12074 { "gdb_index", & do_gdb_index
, 1 },
12075 { "info", & do_debug_info
, 1 },
12076 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
12077 { "links", & do_debug_links
, 1 },
12078 { "loc", & do_debug_loc
, 1 },
12079 { "macro", & do_debug_macinfo
, 1 },
12080 { "no-follow-links", & do_follow_links
, 0 },
12081 { "pubnames", & do_debug_pubnames
, 1 },
12082 { "pubtypes", & do_debug_pubtypes
, 1 },
12083 /* This entry is for compatibility
12084 with earlier versions of readelf. */
12085 { "ranges", & do_debug_aranges
, 1 },
12086 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
12087 { "str", & do_debug_str
, 1 },
12088 { "str-offsets", & do_debug_str_offsets
, 1 },
12089 /* These trace_* sections are used by Itanium VMS. */
12090 { "trace_abbrev", & do_trace_abbrevs
, 1 },
12091 { "trace_aranges", & do_trace_aranges
, 1 },
12092 { "trace_info", & do_trace_info
, 1 },
12093 #ifdef HAVE_LIBDEBUGINFOD
12094 { "use-debuginfod", & use_debuginfod
, 1 },
12105 const debug_dump_long_opts
* entry
;
12107 for (entry
= opts_table
; entry
->option
; entry
++)
12109 size_t len
= strlen (entry
->option
);
12111 if (strncmp (p
, entry
->option
, len
) == 0
12112 && (p
[len
] == ',' || p
[len
] == '\0'))
12114 * entry
->variable
= entry
->val
;
12115 result
|= entry
->val
;
12117 /* The --debug-dump=frames-interp option also
12118 enables the --debug-dump=frames option. */
12119 if (do_debug_frames_interp
)
12120 do_debug_frames
= 1;
12127 if (entry
->option
== NULL
)
12129 warn (_("Unrecognized debug option '%s'\n"), p
);
12130 p
= strchr (p
, ',');
12142 /* Enable display of specific DWARF sections as determined by the characters
12143 in LETTERS. Returns non-zero if any displaying was enabled. */
12146 dwarf_select_sections_by_letters (const char *letters
)
12155 debug_dump_letter_opts
;
12157 static const debug_dump_letter_opts letter_table
[] =
12159 { 'A', & do_debug_addr
, 1, false},
12160 { 'a', & do_debug_abbrevs
, 1, false },
12161 { 'c', & do_debug_cu_index
, 1, false },
12162 #ifdef HAVE_LIBDEBUGINFOD
12163 { 'D', & use_debuginfod
, 1, false },
12164 { 'E', & use_debuginfod
, 0, false },
12166 { 'F', & do_debug_frames_interp
, 1, true }, /* Note the fall through. */
12167 { 'f', & do_debug_frames
, 1, false },
12168 { 'g', & do_gdb_index
, 1, false },
12169 { 'i', & do_debug_info
, 1, false },
12170 { 'K', & do_follow_links
, 1, false },
12171 { 'k', & do_debug_links
, 1, false },
12172 { 'L', & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
, false },
12173 { 'l', & do_debug_lines
, FLAG_DEBUG_LINES_RAW
, false },
12174 { 'm', & do_debug_macinfo
, 1, false },
12175 { 'N', & do_follow_links
, 0, false },
12176 { 'O', & do_debug_str_offsets
, 1, false },
12177 { 'o', & do_debug_loc
, 1, false },
12178 { 'p', & do_debug_pubnames
, 1, false },
12179 { 'R', & do_debug_ranges
, 1, false },
12180 { 'r', & do_debug_aranges
, 1, false },
12181 { 's', & do_debug_str
, 1, false },
12182 { 'T', & do_trace_aranges
, 1, false },
12183 { 't', & do_debug_pubtypes
, 1, false },
12184 { 'U', & do_trace_info
, 1, false },
12185 { 'u', & do_trace_abbrevs
, 1, false },
12186 { 0, NULL
, 0, false }
12193 const debug_dump_letter_opts
* entry
;
12195 for (entry
= letter_table
; entry
->letter
; entry
++)
12197 if (entry
->letter
== * letters
)
12199 * entry
->variable
|= entry
->val
;
12200 result
|= entry
->val
;
12207 if (entry
->letter
== 0)
12208 warn (_("Unrecognized debug letter option '%c'\n"), * letters
);
12217 dwarf_select_sections_all (void)
12220 do_debug_abbrevs
= 1;
12221 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
12222 do_debug_pubnames
= 1;
12223 do_debug_pubtypes
= 1;
12224 do_debug_aranges
= 1;
12225 do_debug_ranges
= 1;
12226 do_debug_frames
= 1;
12227 do_debug_macinfo
= 1;
12232 do_trace_abbrevs
= 1;
12233 do_trace_aranges
= 1;
12235 do_debug_cu_index
= 1;
12236 do_follow_links
= 1;
12237 do_debug_links
= 1;
12238 do_debug_str_offsets
= 1;
12241 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0
12242 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0
12244 /* N.B. The order here must match the order in section_display_enum. */
12246 struct dwarf_section_display debug_displays
[] =
12248 { { ".debug_abbrev", ".zdebug_abbrev", ".dwabrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12249 { { ".debug_aranges", ".zdebug_aranges", ".dwarnge", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, true },
12250 { { ".debug_frame", ".zdebug_frame", ".dwframe", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12251 { { ".debug_info", ".zdebug_info", ".dwinfo", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, true },
12252 { { ".debug_line", ".zdebug_line", ".dwline", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12253 { { ".debug_pubnames", ".zdebug_pubnames", ".dwpbnms", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, false },
12254 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, false },
12255 { { ".eh_frame", "", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, true },
12256 { { ".debug_macinfo", ".zdebug_macinfo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12257 { { ".debug_macro", ".zdebug_macro", ".dwmac", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12258 { { ".debug_str", ".zdebug_str", ".dwstr", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12259 { { ".debug_line_str", ".zdebug_line_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12260 { { ".debug_loc", ".zdebug_loc", ".dwloc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12261 { { ".debug_loclists", ".zdebug_loclists", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12262 { { ".debug_pubtypes", ".zdebug_pubtypes", ".dwpbtyp", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, false },
12263 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", "", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, false },
12264 { { ".debug_ranges", ".zdebug_ranges", ".dwrnges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12265 { { ".debug_rnglists", ".zdebug_rnglists", "", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, true },
12266 { { ".debug_static_func", ".zdebug_static_func", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12267 { { ".debug_static_vars", ".zdebug_static_vars", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12268 { { ".debug_types", ".zdebug_types", "", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, true },
12269 { { ".debug_weaknames", ".zdebug_weaknames", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12270 { { ".gdb_index", "", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, false },
12271 { { ".debug_names", "", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, false },
12272 { { ".trace_info", "", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, true },
12273 { { ".trace_abbrev", "", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, false },
12274 { { ".trace_aranges", "", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, false },
12275 { { ".debug_info.dwo", ".zdebug_info.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, true },
12276 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", "", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, false },
12277 { { ".debug_types.dwo", ".zdebug_types.dwo", "", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, true },
12278 { { ".debug_line.dwo", ".zdebug_line.dwo", "", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, true },
12279 { { ".debug_loc.dwo", ".zdebug_loc.dwo", "", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, true },
12280 { { ".debug_macro.dwo", ".zdebug_macro.dwo", "", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, true },
12281 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", "", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, false },
12282 { { ".debug_str.dwo", ".zdebug_str.dwo", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, true },
12283 { { ".debug_str_offsets", ".zdebug_str_offsets", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12284 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", "", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, true },
12285 { { ".debug_addr", ".zdebug_addr", "", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, true },
12286 { { ".debug_cu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12287 { { ".debug_tu_index", "", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, false },
12288 { { ".gnu_debuglink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12289 { { ".gnu_debugaltlink", "", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, false },
12290 { { ".debug_sup", "", "", NO_ABBREVS
}, display_debug_sup
, &do_debug_links
, false },
12291 /* Separate debug info files can containt their own .debug_str section,
12292 and this might be in *addition* to a .debug_str section already present
12293 in the main file. Hence we need to have two entries for .debug_str. */
12294 { { ".debug_str", ".zdebug_str", "", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, false },
12295 { { ".note.gnu.build-id", "", "", NO_ABBREVS
}, display_debug_not_supported
, NULL
, false },
12298 /* A static assertion. */
12299 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];