1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2020 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
24 #include "bfd_stdint.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
41 #define MAX(a, b) ((a) > (b) ? (a) : (b))
42 #define MIN(a, b) ((a) < (b) ? (a) : (b))
44 static const char *regname (unsigned int regno
, int row
);
45 static const char *regname_internal_by_table_only (unsigned int regno
);
47 static int have_frame_base
;
48 static int need_base_address
;
50 static unsigned int num_debug_info_entries
= 0;
51 static unsigned int alloc_num_debug_info_entries
= 0;
52 static debug_info
*debug_information
= NULL
;
53 /* Special value for num_debug_info_entries to indicate
54 that the .debug_info section could not be loaded/parsed. */
55 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
57 /* A .debug_info section can contain multiple links to separate
58 DWO object files. We use these structures to record these links. */
66 typedef struct dwo_info
71 struct dwo_info
* next
;
74 static dwo_info
* first_dwo_info
= NULL
;
75 static bfd_boolean need_dwo_info
;
77 separate_info
* first_separate_info
= NULL
;
79 unsigned int eh_addr_size
;
84 int do_debug_pubnames
;
85 int do_debug_pubtypes
;
89 int do_debug_frames_interp
;
92 int do_debug_str_offsets
;
99 int do_debug_cu_index
;
103 bfd_boolean do_checks
;
105 int dwarf_cutoff_level
= -1;
106 unsigned long dwarf_start_die
;
110 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
111 testing whether e.g. a locview list is present. */
112 static const dwarf_vma vm1
= -1;
114 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
115 sections. For version 1 package files, each set is stored in SHNDX_POOL
116 as a zero-terminated list of section indexes comprising one set of debug
117 sections from a .dwo file. */
119 static unsigned int *shndx_pool
= NULL
;
120 static unsigned int shndx_pool_size
= 0;
121 static unsigned int shndx_pool_used
= 0;
123 /* For version 2 package files, each set contains an array of section offsets
124 and an array of section sizes, giving the offset and size of the
125 contribution from a CU or TU within one of the debug sections.
126 When displaying debug info from a package file, we need to use these
127 tables to locate the corresponding contributions to each section. */
132 dwarf_vma section_offsets
[DW_SECT_MAX
];
133 size_t section_sizes
[DW_SECT_MAX
];
136 static int cu_count
= 0;
137 static int tu_count
= 0;
138 static struct cu_tu_set
*cu_sets
= NULL
;
139 static struct cu_tu_set
*tu_sets
= NULL
;
141 static bfd_boolean
load_cu_tu_indexes (void *);
143 /* An array that indicates for a given level of CU nesting whether
144 the latest DW_AT_type seen for that level was a signed type or
146 #define MAX_CU_NESTING (1 << 8)
147 static bfd_boolean level_type_signed
[MAX_CU_NESTING
];
149 /* Values for do_debug_lines. */
150 #define FLAG_DEBUG_LINES_RAW 1
151 #define FLAG_DEBUG_LINES_DECODED 2
154 size_of_encoded_value (int encoding
)
156 switch (encoding
& 0x7)
159 case 0: return eh_addr_size
;
167 get_encoded_value (unsigned char **pdata
,
169 struct dwarf_section
*section
,
172 unsigned char * data
= * pdata
;
173 unsigned int size
= size_of_encoded_value (encoding
);
176 if (data
+ size
>= end
)
178 warn (_("Encoded value extends past end of section\n"));
183 /* PR 17512: file: 002-829853-0.004. */
186 warn (_("Encoded size of %d is too large to read\n"), size
);
191 /* PR 17512: file: 1085-5603-0.004. */
194 warn (_("Encoded size of 0 is too small to read\n"));
199 if (encoding
& DW_EH_PE_signed
)
200 val
= byte_get_signed (data
, size
);
202 val
= byte_get (data
, size
);
204 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
205 val
+= section
->address
+ (data
- section
->start
);
207 * pdata
= data
+ size
;
211 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
213 # define DWARF_VMA_FMT "ll"
214 # define DWARF_VMA_FMT_LONG "%16.16llx"
216 # define DWARF_VMA_FMT "I64"
217 # define DWARF_VMA_FMT_LONG "%016I64x"
220 # define DWARF_VMA_FMT "l"
221 # define DWARF_VMA_FMT_LONG "%16.16lx"
224 /* Convert a dwarf vma value into a string. Returns a pointer to a static
225 buffer containing the converted VALUE. The value is converted according
226 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
227 it specifies the maximum number of bytes to be displayed in the converted
228 value and FMTCH is ignored - hex is always used. */
231 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
233 /* As dwarf_vmatoa is used more then once in a printf call
234 for output, we are cycling through an fixed array of pointers
235 for return address. */
236 static int buf_pos
= 0;
237 static struct dwarf_vmatoa_buf
243 ret
= buf
[buf_pos
++].place
;
244 buf_pos
%= ARRAY_SIZE (buf
);
248 /* Printf does not have a way of specifying a maximum field width for an
249 integer value, so we print the full value into a buffer and then select
250 the precision we need. */
251 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
254 return ret
+ (16 - 2 * num_bytes
);
261 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
263 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
264 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
269 static inline const char *
270 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
272 return dwarf_vmatoa_1 (fmtch
, value
, 0);
275 /* Print a dwarf_vma value (typically an address, offset or length) in
276 hexadecimal format, followed by a space. The length of the VALUE (and
277 hence the precision displayed) is determined by the NUM_BYTES parameter. */
280 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
282 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
285 /* Print a view number in hexadecimal value, with the same width
286 print_dwarf_vma would have printed it with the same num_bytes.
287 Print blanks for zero view, unless force is nonzero. */
290 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
298 assert (value
== (unsigned long) value
);
300 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
302 printf ("%*s", len
+ 1, "");
305 /* Format a 64-bit value, given as two 32-bit values, in hex.
306 For reentrancy, this uses a buffer provided by the caller. */
309 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
310 unsigned int buf_len
)
315 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
318 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
319 snprintf (buf
+ len
, buf_len
- len
,
320 "%08" DWARF_VMA_FMT
"x", lvalue
);
326 /* Read in a LEB128 encoded value starting at address DATA.
327 If SIGN is true, return a signed LEB128 value.
328 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
329 If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the
330 terminating byte was not found and with bit 1 set if the value
331 overflows a dwarf_vma.
332 No bytes will be read at address END or beyond. */
335 read_leb128 (unsigned char *data
,
336 const unsigned char *const end
,
338 unsigned int *length_return
,
341 dwarf_vma result
= 0;
342 unsigned int num_read
= 0;
343 unsigned int shift
= 0;
348 unsigned char byte
= *data
++;
349 bfd_boolean cont
= (byte
& 0x80) ? TRUE
: FALSE
;
354 if (shift
< sizeof (result
) * 8)
356 result
|= ((dwarf_vma
) byte
) << shift
;
359 if ((((dwarf_signed_vma
) result
>> shift
) & 0x7f) != byte
)
363 else if ((result
>> shift
) != byte
)
379 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
380 result
|= -((dwarf_vma
) 1 << shift
);
385 if (length_return
!= NULL
)
386 *length_return
= num_read
;
387 if (status_return
!= NULL
)
388 *status_return
= status
;
393 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
394 Checks to make sure that the read will not reach or pass END
395 and that VAL is big enough to hold AMOUNT bytes. */
396 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
399 unsigned int amount = (AMOUNT); \
400 if (sizeof (VAL) < amount) \
402 error (ngettext ("internal error: attempt to read %d byte " \
403 "of data in to %d sized variable", \
404 "internal error: attempt to read %d bytes " \
405 "of data in to %d sized variable", \
407 amount, (int) sizeof (VAL)); \
408 amount = sizeof (VAL); \
410 if (((PTR) + amount) >= (END)) \
413 amount = (END) - (PTR); \
417 if (amount == 0 || amount > 8) \
420 VAL = byte_get ((PTR), amount); \
424 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
425 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
428 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
433 /* Like SAFE_BYTE_GET, but reads a signed value. */
434 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
437 unsigned int amount = (AMOUNT); \
438 if (((PTR) + amount) >= (END)) \
441 amount = (END) - (PTR); \
446 VAL = byte_get_signed ((PTR), amount); \
452 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
453 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
456 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
461 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
464 if (((PTR) + 8) <= (END)) \
466 byte_get_64 ((PTR), (HIGH), (LOW)); \
470 * (LOW) = * (HIGH) = 0; \
475 typedef struct State_Machine_Registers
484 unsigned char op_index
;
485 unsigned char end_sequence
;
486 /* This variable hold the number of the last entry seen
487 in the File Table. */
488 unsigned int last_file_entry
;
491 static SMR state_machine_regs
;
494 reset_state_machine (int is_stmt
)
496 state_machine_regs
.address
= 0;
497 state_machine_regs
.view
= 0;
498 state_machine_regs
.op_index
= 0;
499 state_machine_regs
.file
= 1;
500 state_machine_regs
.line
= 1;
501 state_machine_regs
.column
= 0;
502 state_machine_regs
.is_stmt
= is_stmt
;
503 state_machine_regs
.basic_block
= 0;
504 state_machine_regs
.end_sequence
= 0;
505 state_machine_regs
.last_file_entry
= 0;
508 /* Handled an extend line op.
509 Returns the number of bytes read. */
512 process_extended_line_op (unsigned char * data
,
516 unsigned char op_code
;
517 size_t len
, header_len
;
519 unsigned char *orig_data
= data
;
522 READ_ULEB (len
, data
, end
);
523 header_len
= data
- orig_data
;
525 if (len
== 0 || data
== end
|| len
> (size_t) (end
- data
))
527 warn (_("Badly formed extended line op encountered!\n"));
533 printf (_(" Extended opcode %d: "), op_code
);
537 case DW_LNE_end_sequence
:
538 printf (_("End of Sequence\n\n"));
539 reset_state_machine (is_stmt
);
542 case DW_LNE_set_address
:
543 /* PR 17512: file: 002-100480-0.004. */
546 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
547 (unsigned long) len
- 1);
551 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
552 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
553 state_machine_regs
.address
= adr
;
554 state_machine_regs
.view
= 0;
555 state_machine_regs
.op_index
= 0;
558 case DW_LNE_define_file
:
559 printf (_("define new File Table entry\n"));
560 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
561 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
567 l
= strnlen ((char *) data
, end
- data
);
569 READ_ULEB (val
, data
, end
);
570 printf ("%s\t", dwarf_vmatoa ("u", val
));
571 READ_ULEB (val
, data
, end
);
572 printf ("%s\t", dwarf_vmatoa ("u", val
));
573 READ_ULEB (val
, data
, end
);
574 printf ("%s\t", dwarf_vmatoa ("u", val
));
575 printf ("%.*s\n\n", (int) l
, name
);
578 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
== end
)
579 warn (_("DW_LNE_define_file: Bad opcode length\n"));
582 case DW_LNE_set_discriminator
:
583 READ_ULEB (val
, data
, end
);
584 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
588 case DW_LNE_HP_negate_is_UV_update
:
589 printf ("DW_LNE_HP_negate_is_UV_update\n");
591 case DW_LNE_HP_push_context
:
592 printf ("DW_LNE_HP_push_context\n");
594 case DW_LNE_HP_pop_context
:
595 printf ("DW_LNE_HP_pop_context\n");
597 case DW_LNE_HP_set_file_line_column
:
598 printf ("DW_LNE_HP_set_file_line_column\n");
600 case DW_LNE_HP_set_routine_name
:
601 printf ("DW_LNE_HP_set_routine_name\n");
603 case DW_LNE_HP_set_sequence
:
604 printf ("DW_LNE_HP_set_sequence\n");
606 case DW_LNE_HP_negate_post_semantics
:
607 printf ("DW_LNE_HP_negate_post_semantics\n");
609 case DW_LNE_HP_negate_function_exit
:
610 printf ("DW_LNE_HP_negate_function_exit\n");
612 case DW_LNE_HP_negate_front_end_logical
:
613 printf ("DW_LNE_HP_negate_front_end_logical\n");
615 case DW_LNE_HP_define_proc
:
616 printf ("DW_LNE_HP_define_proc\n");
618 case DW_LNE_HP_source_file_correlation
:
620 unsigned char *edata
= data
+ len
- 1;
622 printf ("DW_LNE_HP_source_file_correlation\n");
628 READ_ULEB (opc
, data
, edata
);
632 case DW_LNE_HP_SFC_formfeed
:
633 printf (" DW_LNE_HP_SFC_formfeed\n");
635 case DW_LNE_HP_SFC_set_listing_line
:
636 READ_ULEB (val
, data
, edata
);
637 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
638 dwarf_vmatoa ("u", val
));
640 case DW_LNE_HP_SFC_associate
:
641 printf (" DW_LNE_HP_SFC_associate ");
642 READ_ULEB (val
, data
, edata
);
643 printf ("(%s", dwarf_vmatoa ("u", val
));
644 READ_ULEB (val
, data
, edata
);
645 printf (",%s", dwarf_vmatoa ("u", val
));
646 READ_ULEB (val
, data
, edata
);
647 printf (",%s)\n", dwarf_vmatoa ("u", val
));
650 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
660 unsigned int rlen
= len
- 1;
662 if (op_code
>= DW_LNE_lo_user
663 /* The test against DW_LNW_hi_user is redundant due to
664 the limited range of the unsigned char data type used
666 /*&& op_code <= DW_LNE_hi_user*/)
667 printf (_("user defined: "));
669 printf (_("UNKNOWN: "));
670 printf (_("length %d ["), rlen
);
672 printf (" %02x", *data
++);
678 return len
+ header_len
;
681 static const unsigned char *
682 fetch_indirect_string (dwarf_vma offset
)
684 struct dwarf_section
*section
= &debug_displays
[str
].section
;
685 const unsigned char * ret
;
687 if (section
->start
== NULL
)
688 return (const unsigned char *) _("<no .debug_str section>");
690 if (offset
>= section
->size
)
692 warn (_("DW_FORM_strp offset too big: %s\n"),
693 dwarf_vmatoa ("x", offset
));
694 return (const unsigned char *) _("<offset is too big>");
697 ret
= section
->start
+ offset
;
698 /* Unfortunately we cannot rely upon the .debug_str section ending with a
699 NUL byte. Since our caller is expecting to receive a well formed C
700 string we test for the lack of a terminating byte here. */
701 if (strnlen ((const char *) ret
, section
->size
- offset
)
702 == section
->size
- offset
)
703 ret
= (const unsigned char *)
704 _("<no NUL byte at end of .debug_str section>");
709 static const unsigned char *
710 fetch_indirect_line_string (dwarf_vma offset
)
712 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
713 const unsigned char * ret
;
715 if (section
->start
== NULL
)
716 return (const unsigned char *) _("<no .debug_line_str section>");
718 if (offset
>= section
->size
)
720 warn (_("DW_FORM_line_strp offset too big: %s\n"),
721 dwarf_vmatoa ("x", offset
));
722 return (const unsigned char *) _("<offset is too big>");
725 ret
= section
->start
+ offset
;
726 /* Unfortunately we cannot rely upon the .debug_line_str section ending
727 with a NUL byte. Since our caller is expecting to receive a well formed
728 C string we test for the lack of a terminating byte here. */
729 if (strnlen ((const char *) ret
, section
->size
- offset
)
730 == section
->size
- offset
)
731 ret
= (const unsigned char *)
732 _("<no NUL byte at end of .debug_line_str section>");
738 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
739 dwarf_vma offset_size
, bfd_boolean dwo
)
741 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
742 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
743 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
744 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
745 dwarf_vma index_offset
;
746 dwarf_vma str_offset
;
748 unsigned char *curr
= index_section
->start
;
749 const unsigned char *end
= curr
+ index_section
->size
;
752 if (index_section
->start
== NULL
)
753 return (dwo
? _("<no .debug_str_offsets.dwo section>")
754 : _("<no .debug_str_offsets section>"));
756 if (str_section
->start
== NULL
)
757 return (dwo
? _("<no .debug_str.dwo section>")
758 : _("<no .debug_str section>"));
760 /* FIXME: We should cache the length... */
761 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
762 if (length
== 0xffffffff)
764 if (offset_size
!= 8)
765 warn (_("Expected offset size of 8 but given %s"), dwarf_vmatoa ("x", offset_size
));
766 SAFE_BYTE_GET_AND_INC (length
, curr
, 8, end
);
768 else if (offset_size
!= 4)
770 warn (_("Expected offset size of 4 but given %s"), dwarf_vmatoa ("x", offset_size
));
775 /* This is probably an old style .debug_str_offset section which
776 just contains offsets and no header (and the first offset is 0). */
777 curr
= index_section
->start
;
778 length
= index_section
->size
;
782 /* Skip the version and padding bytes.
783 We assume that they are correct. */
786 /* FIXME: The code below assumes that there is only one table
787 in the .debug_str_offsets section, so check that now. */
788 if ((offset_size
== 4 && curr
+ length
< (end
- 8))
789 || (offset_size
== 8 && curr
+ length
< (end
- 16)))
791 warn (_("index table size is too small %s vs %s\n"),
792 dwarf_vmatoa ("x", length
),
793 dwarf_vmatoa ("x", index_section
->size
));
794 return _("<table too small>");
798 index_offset
= idx
* offset_size
;
800 if (this_set
!= NULL
)
801 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
803 if (index_offset
>= length
)
805 warn (_("DW_FORM_GNU_str_index offset too big: %s vs %s\n"),
806 dwarf_vmatoa ("x", index_offset
),
807 dwarf_vmatoa ("x", length
));
808 return _("<index offset is too big>");
811 str_offset
= byte_get (curr
+ index_offset
, offset_size
);
812 str_offset
-= str_section
->address
;
813 if (str_offset
>= str_section
->size
)
815 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
816 dwarf_vmatoa ("x", str_offset
));
817 return _("<indirect index offset is too big>");
820 ret
= (const char *) str_section
->start
+ str_offset
;
821 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
822 Since our caller is expecting to receive a well formed C string we test
823 for the lack of a terminating byte here. */
824 if (strnlen (ret
, str_section
->size
- str_offset
)
825 == str_section
->size
- str_offset
)
826 ret
= (const char *) _("<no NUL byte at end of section>");
832 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
834 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
836 if (section
->start
== NULL
)
837 return (_("<no .debug_addr section>"));
839 if (offset
+ bytes
> section
->size
)
841 warn (_("Offset into section %s too big: %s\n"),
842 section
->name
, dwarf_vmatoa ("x", offset
));
843 return "<offset too big>";
846 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
850 /* FIXME: There are better and more efficient ways to handle
851 these structures. For now though, I just want something that
852 is simple to implement. */
853 /* Records a single attribute in an abbrev. */
854 typedef struct abbrev_attr
856 unsigned long attribute
;
858 bfd_signed_vma implicit_const
;
859 struct abbrev_attr
* next
;
863 /* Records a single abbrev. */
864 typedef struct abbrev_entry
866 unsigned long number
;
869 struct abbrev_attr
* first_attr
;
870 struct abbrev_attr
* last_attr
;
871 struct abbrev_entry
* next
;
875 /* Records a set of abbreviations. */
876 typedef struct abbrev_list
878 abbrev_entry
* first_abbrev
;
879 abbrev_entry
* last_abbrev
;
880 dwarf_vma abbrev_base
;
881 dwarf_vma abbrev_offset
;
882 struct abbrev_list
* next
;
883 unsigned char * start_of_next_abbrevs
;
887 /* Records all the abbrevs found so far. */
888 static struct abbrev_list
* abbrev_lists
= NULL
;
890 typedef struct abbrev_map
897 /* Maps between CU offsets and abbrev sets. */
898 static abbrev_map
* cu_abbrev_map
= NULL
;
899 static unsigned long num_abbrev_map_entries
= 0;
900 static unsigned long next_free_abbrev_map_entry
= 0;
902 #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8
903 #define ABBREV_MAP_ENTRIES_INCREMENT 8
906 record_abbrev_list_for_cu (dwarf_vma start
, dwarf_vma end
, abbrev_list
* list
)
908 if (cu_abbrev_map
== NULL
)
910 num_abbrev_map_entries
= INITIAL_NUM_ABBREV_MAP_ENTRIES
;
911 cu_abbrev_map
= xmalloc (num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
913 else if (next_free_abbrev_map_entry
== num_abbrev_map_entries
)
915 num_abbrev_map_entries
+= ABBREV_MAP_ENTRIES_INCREMENT
;
916 cu_abbrev_map
= xrealloc (cu_abbrev_map
, num_abbrev_map_entries
* sizeof (* cu_abbrev_map
));
919 cu_abbrev_map
[next_free_abbrev_map_entry
].start
= start
;
920 cu_abbrev_map
[next_free_abbrev_map_entry
].end
= end
;
921 cu_abbrev_map
[next_free_abbrev_map_entry
].list
= list
;
922 next_free_abbrev_map_entry
++;
926 free_all_abbrevs (void)
930 for (list
= abbrev_lists
; list
!= NULL
;)
932 abbrev_list
* next
= list
->next
;
933 abbrev_entry
* abbrv
;
935 for (abbrv
= list
->first_abbrev
; abbrv
!= NULL
;)
937 abbrev_entry
* next_abbrev
= abbrv
->next
;
940 for (attr
= abbrv
->first_attr
; attr
;)
942 abbrev_attr
*next_attr
= attr
->next
;
960 new_abbrev_list (dwarf_vma abbrev_base
, dwarf_vma abbrev_offset
)
962 abbrev_list
* list
= (abbrev_list
*) xcalloc (sizeof * list
, 1);
964 list
->abbrev_base
= abbrev_base
;
965 list
->abbrev_offset
= abbrev_offset
;
967 list
->next
= abbrev_lists
;
974 find_abbrev_list_by_abbrev_offset (dwarf_vma abbrev_base
,
975 dwarf_vma abbrev_offset
)
979 for (list
= abbrev_lists
; list
!= NULL
; list
= list
->next
)
980 if (list
->abbrev_base
== abbrev_base
981 && list
->abbrev_offset
== abbrev_offset
)
987 /* Find the abbreviation map for the CU that includes OFFSET.
988 OFFSET is an absolute offset from the start of the .debug_info section. */
989 /* FIXME: This function is going to slow down readelf & objdump.
990 Consider using a better algorithm to mitigate this effect. */
993 find_abbrev_map_by_offset (dwarf_vma offset
)
997 for (i
= 0; i
< next_free_abbrev_map_entry
; i
++)
998 if (cu_abbrev_map
[i
].start
<= offset
999 && cu_abbrev_map
[i
].end
> offset
)
1000 return cu_abbrev_map
+ i
;
1006 add_abbrev (unsigned long number
,
1011 abbrev_entry
* entry
;
1013 entry
= (abbrev_entry
*) xmalloc (sizeof (*entry
));
1015 entry
->number
= number
;
1017 entry
->children
= children
;
1018 entry
->first_attr
= NULL
;
1019 entry
->last_attr
= NULL
;
1022 assert (list
!= NULL
);
1024 if (list
->first_abbrev
== NULL
)
1025 list
->first_abbrev
= entry
;
1027 list
->last_abbrev
->next
= entry
;
1029 list
->last_abbrev
= entry
;
1033 add_abbrev_attr (unsigned long attribute
,
1035 bfd_signed_vma implicit_const
,
1040 attr
= (abbrev_attr
*) xmalloc (sizeof (*attr
));
1042 attr
->attribute
= attribute
;
1044 attr
->implicit_const
= implicit_const
;
1047 assert (list
!= NULL
&& list
->last_abbrev
!= NULL
);
1049 if (list
->last_abbrev
->first_attr
== NULL
)
1050 list
->last_abbrev
->first_attr
= attr
;
1052 list
->last_abbrev
->last_attr
->next
= attr
;
1054 list
->last_abbrev
->last_attr
= attr
;
1057 /* Processes the (partial) contents of a .debug_abbrev section.
1058 Returns NULL if the end of the section was encountered.
1059 Returns the address after the last byte read if the end of
1060 an abbreviation set was found. */
1062 static unsigned char *
1063 process_abbrev_set (unsigned char * start
,
1064 const unsigned char * end
,
1069 unsigned long entry
;
1071 unsigned long attribute
;
1074 READ_ULEB (entry
, start
, end
);
1076 /* A single zero is supposed to end the set according
1077 to the standard. If there's more, then signal that to
1084 READ_ULEB (tag
, start
, end
);
1088 children
= *start
++;
1090 add_abbrev (entry
, tag
, children
, list
);
1095 /* Initialize it due to a false compiler warning. */
1096 bfd_signed_vma implicit_const
= -1;
1098 READ_ULEB (attribute
, start
, end
);
1102 READ_ULEB (form
, start
, end
);
1106 if (form
== DW_FORM_implicit_const
)
1108 READ_SLEB (implicit_const
, start
, end
);
1113 add_abbrev_attr (attribute
, form
, implicit_const
, list
);
1115 while (attribute
!= 0);
1118 /* Report the missing single zero which ends the section. */
1119 error (_(".debug_abbrev section not zero terminated\n"));
1125 get_TAG_name (unsigned long tag
)
1127 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
1131 static char buffer
[100];
1133 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
1134 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
1136 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
1144 get_FORM_name (unsigned long form
)
1149 return "DW_FORM value: 0";
1151 name
= get_DW_FORM_name (form
);
1154 static char buffer
[100];
1156 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1164 get_IDX_name (unsigned long idx
)
1166 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1170 static char buffer
[100];
1172 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1179 static unsigned char *
1180 display_block (unsigned char *data
,
1182 const unsigned char * const end
, char delimiter
)
1186 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1188 return (unsigned char *) end
;
1190 maxlen
= (dwarf_vma
) (end
- data
);
1191 length
= length
> maxlen
? maxlen
: length
;
1194 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1200 decode_location_expression (unsigned char * data
,
1201 unsigned int pointer_size
,
1202 unsigned int offset_size
,
1205 dwarf_vma cu_offset
,
1206 struct dwarf_section
* section
)
1210 dwarf_signed_vma svalue
;
1211 unsigned char *end
= data
+ length
;
1212 int need_frame_base
= 0;
1221 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1222 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1225 printf ("DW_OP_deref");
1228 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1229 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1232 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1233 printf ("DW_OP_const1s: %ld", (long) svalue
);
1236 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1237 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1240 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1241 printf ("DW_OP_const2s: %ld", (long) svalue
);
1244 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1245 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1248 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1249 printf ("DW_OP_const4s: %ld", (long) svalue
);
1252 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1253 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1254 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1255 printf ("%lu", (unsigned long) uvalue
);
1258 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1259 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1260 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1261 printf ("%ld", (long) svalue
);
1264 READ_ULEB (uvalue
, data
, end
);
1265 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1268 READ_SLEB (svalue
, data
, end
);
1269 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1272 printf ("DW_OP_dup");
1275 printf ("DW_OP_drop");
1278 printf ("DW_OP_over");
1281 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1282 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1285 printf ("DW_OP_swap");
1288 printf ("DW_OP_rot");
1291 printf ("DW_OP_xderef");
1294 printf ("DW_OP_abs");
1297 printf ("DW_OP_and");
1300 printf ("DW_OP_div");
1303 printf ("DW_OP_minus");
1306 printf ("DW_OP_mod");
1309 printf ("DW_OP_mul");
1312 printf ("DW_OP_neg");
1315 printf ("DW_OP_not");
1318 printf ("DW_OP_or");
1321 printf ("DW_OP_plus");
1323 case DW_OP_plus_uconst
:
1324 READ_ULEB (uvalue
, data
, end
);
1325 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1328 printf ("DW_OP_shl");
1331 printf ("DW_OP_shr");
1334 printf ("DW_OP_shra");
1337 printf ("DW_OP_xor");
1340 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1341 printf ("DW_OP_bra: %ld", (long) svalue
);
1344 printf ("DW_OP_eq");
1347 printf ("DW_OP_ge");
1350 printf ("DW_OP_gt");
1353 printf ("DW_OP_le");
1356 printf ("DW_OP_lt");
1359 printf ("DW_OP_ne");
1362 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1363 printf ("DW_OP_skip: %ld", (long) svalue
);
1398 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1433 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1434 regname (op
- DW_OP_reg0
, 1));
1469 READ_SLEB (svalue
, data
, end
);
1470 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1471 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1475 READ_ULEB (uvalue
, data
, end
);
1476 printf ("DW_OP_regx: %s (%s)",
1477 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1480 need_frame_base
= 1;
1481 READ_SLEB (svalue
, data
, end
);
1482 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1485 READ_ULEB (uvalue
, data
, end
);
1486 READ_SLEB (svalue
, data
, end
);
1487 printf ("DW_OP_bregx: %s (%s) %s",
1488 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1489 dwarf_vmatoa ("d", svalue
));
1492 READ_ULEB (uvalue
, data
, end
);
1493 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1495 case DW_OP_deref_size
:
1496 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1497 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1499 case DW_OP_xderef_size
:
1500 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1501 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1504 printf ("DW_OP_nop");
1507 /* DWARF 3 extensions. */
1508 case DW_OP_push_object_address
:
1509 printf ("DW_OP_push_object_address");
1512 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1513 this ought to be an 8-byte wide computation. */
1514 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1515 printf ("DW_OP_call2: <0x%s>",
1516 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1519 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1520 this ought to be an 8-byte wide computation. */
1521 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1522 printf ("DW_OP_call4: <0x%s>",
1523 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1525 case DW_OP_call_ref
:
1526 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1527 this ought to be an 8-byte wide computation. */
1528 if (dwarf_version
== -1)
1530 printf (_("(DW_OP_call_ref in frame info)"));
1531 /* No way to tell where the next op is, so just bail. */
1532 return need_frame_base
;
1534 if (dwarf_version
== 2)
1536 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1540 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1542 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1544 case DW_OP_form_tls_address
:
1545 printf ("DW_OP_form_tls_address");
1547 case DW_OP_call_frame_cfa
:
1548 printf ("DW_OP_call_frame_cfa");
1550 case DW_OP_bit_piece
:
1551 printf ("DW_OP_bit_piece: ");
1552 READ_ULEB (uvalue
, data
, end
);
1553 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1554 READ_ULEB (uvalue
, data
, end
);
1555 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1558 /* DWARF 4 extensions. */
1559 case DW_OP_stack_value
:
1560 printf ("DW_OP_stack_value");
1563 case DW_OP_implicit_value
:
1564 printf ("DW_OP_implicit_value");
1565 READ_ULEB (uvalue
, data
, end
);
1566 data
= display_block (data
, uvalue
, end
, ' ');
1569 /* GNU extensions. */
1570 case DW_OP_GNU_push_tls_address
:
1571 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1573 case DW_OP_GNU_uninit
:
1574 printf ("DW_OP_GNU_uninit");
1575 /* FIXME: Is there data associated with this OP ? */
1577 case DW_OP_GNU_encoded_addr
:
1584 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1586 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1587 print_dwarf_vma (addr
, pointer_size
);
1590 case DW_OP_implicit_pointer
:
1591 case DW_OP_GNU_implicit_pointer
:
1592 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1593 this ought to be an 8-byte wide computation. */
1594 if (dwarf_version
== -1)
1596 printf (_("(%s in frame info)"),
1597 (op
== DW_OP_implicit_pointer
1598 ? "DW_OP_implicit_pointer"
1599 : "DW_OP_GNU_implicit_pointer"));
1600 /* No way to tell where the next op is, so just bail. */
1601 return need_frame_base
;
1603 if (dwarf_version
== 2)
1605 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1609 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1611 READ_SLEB (svalue
, data
, end
);
1612 printf ("%s: <0x%s> %s",
1613 (op
== DW_OP_implicit_pointer
1614 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1615 dwarf_vmatoa ("x", uvalue
),
1616 dwarf_vmatoa ("d", svalue
));
1618 case DW_OP_entry_value
:
1619 case DW_OP_GNU_entry_value
:
1620 READ_ULEB (uvalue
, data
, end
);
1621 /* PR 17531: file: 0cc9cd00. */
1622 if (uvalue
> (dwarf_vma
) (end
- data
))
1623 uvalue
= end
- data
;
1624 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1625 : "DW_OP_GNU_entry_value"));
1626 if (decode_location_expression (data
, pointer_size
, offset_size
,
1627 dwarf_version
, uvalue
,
1628 cu_offset
, section
))
1629 need_frame_base
= 1;
1635 case DW_OP_const_type
:
1636 case DW_OP_GNU_const_type
:
1637 READ_ULEB (uvalue
, data
, end
);
1638 printf ("%s: <0x%s> ",
1639 (op
== DW_OP_const_type
? "DW_OP_const_type"
1640 : "DW_OP_GNU_const_type"),
1641 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1642 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1643 data
= display_block (data
, uvalue
, end
, ' ');
1645 case DW_OP_regval_type
:
1646 case DW_OP_GNU_regval_type
:
1647 READ_ULEB (uvalue
, data
, end
);
1648 printf ("%s: %s (%s)",
1649 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1650 : "DW_OP_GNU_regval_type"),
1651 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1652 READ_ULEB (uvalue
, data
, end
);
1653 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1655 case DW_OP_deref_type
:
1656 case DW_OP_GNU_deref_type
:
1657 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1659 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1660 : "DW_OP_GNU_deref_type"),
1662 READ_ULEB (uvalue
, data
, end
);
1663 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1666 case DW_OP_GNU_convert
:
1667 READ_ULEB (uvalue
, data
, end
);
1668 printf ("%s <0x%s>",
1669 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1670 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1672 case DW_OP_reinterpret
:
1673 case DW_OP_GNU_reinterpret
:
1674 READ_ULEB (uvalue
, data
, end
);
1675 printf ("%s <0x%s>",
1676 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1677 : "DW_OP_GNU_reinterpret"),
1678 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1680 case DW_OP_GNU_parameter_ref
:
1681 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1682 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1683 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1685 case DW_OP_GNU_addr_index
:
1686 READ_ULEB (uvalue
, data
, end
);
1687 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1689 case DW_OP_GNU_const_index
:
1690 READ_ULEB (uvalue
, data
, end
);
1691 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1693 case DW_OP_GNU_variable_value
:
1694 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1695 this ought to be an 8-byte wide computation. */
1696 if (dwarf_version
== -1)
1698 printf (_("(DW_OP_GNU_variable_value in frame info)"));
1699 /* No way to tell where the next op is, so just bail. */
1700 return need_frame_base
;
1702 if (dwarf_version
== 2)
1704 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1708 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1710 printf ("DW_OP_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1713 /* HP extensions. */
1714 case DW_OP_HP_is_value
:
1715 printf ("DW_OP_HP_is_value");
1716 /* FIXME: Is there data associated with this OP ? */
1718 case DW_OP_HP_fltconst4
:
1719 printf ("DW_OP_HP_fltconst4");
1720 /* FIXME: Is there data associated with this OP ? */
1722 case DW_OP_HP_fltconst8
:
1723 printf ("DW_OP_HP_fltconst8");
1724 /* FIXME: Is there data associated with this OP ? */
1726 case DW_OP_HP_mod_range
:
1727 printf ("DW_OP_HP_mod_range");
1728 /* FIXME: Is there data associated with this OP ? */
1730 case DW_OP_HP_unmod_range
:
1731 printf ("DW_OP_HP_unmod_range");
1732 /* FIXME: Is there data associated with this OP ? */
1735 printf ("DW_OP_HP_tls");
1736 /* FIXME: Is there data associated with this OP ? */
1739 /* PGI (STMicroelectronics) extensions. */
1740 case DW_OP_PGI_omp_thread_num
:
1741 /* Pushes the thread number for the current thread as it would be
1742 returned by the standard OpenMP library function:
1743 omp_get_thread_num(). The "current thread" is the thread for
1744 which the expression is being evaluated. */
1745 printf ("DW_OP_PGI_omp_thread_num");
1749 if (op
>= DW_OP_lo_user
1750 && op
<= DW_OP_hi_user
)
1751 printf (_("(User defined location op 0x%x)"), op
);
1753 printf (_("(Unknown location op 0x%x)"), op
);
1754 /* No way to tell where the next op is, so just bail. */
1755 return need_frame_base
;
1758 /* Separate the ops. */
1763 return need_frame_base
;
1766 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1767 This is used for DWARF package files. */
1769 static struct cu_tu_set
*
1770 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1772 struct cu_tu_set
*p
;
1774 unsigned int dw_sect
;
1780 dw_sect
= DW_SECT_TYPES
;
1786 dw_sect
= DW_SECT_INFO
;
1790 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1798 /* Add INC to HIGH_BITS:LOW_BITS. */
1800 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1802 dwarf_vma tmp
= * low_bits
;
1806 /* FIXME: There is probably a better way of handling this:
1808 We need to cope with dwarf_vma being a 32-bit or 64-bit
1809 type. Plus regardless of its size LOW_BITS is meant to
1810 only hold 32-bits, so if there is overflow or wrap around
1811 we must propagate into HIGH_BITS. */
1812 if (tmp
< * low_bits
)
1816 else if (sizeof (tmp
) > 8
1827 fetch_alt_indirect_string (dwarf_vma offset
)
1831 if (! do_follow_links
)
1834 if (first_separate_info
== NULL
)
1835 return _("<no links available>");
1837 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1839 struct dwarf_section
* section
;
1842 if (! load_debug_section (separate_debug_str
, i
->handle
))
1845 section
= &debug_displays
[separate_debug_str
].section
;
1847 if (section
->start
== NULL
)
1850 if (offset
>= section
->size
)
1853 ret
= (const char *) (section
->start
+ offset
);
1854 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1855 NUL byte. Since our caller is expecting to receive a well formed C
1856 string we test for the lack of a terminating byte here. */
1857 if (strnlen ((const char *) ret
, section
->size
- offset
)
1858 == section
->size
- offset
)
1859 return _("<no NUL byte at end of alt .debug_str section>");
1864 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1865 dwarf_vmatoa ("x", offset
));
1866 return _("<offset is too big>");
1870 get_AT_name (unsigned long attribute
)
1875 return "DW_AT value: 0";
1877 /* One value is shared by the MIPS and HP extensions: */
1878 if (attribute
== DW_AT_MIPS_fde
)
1879 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1881 name
= get_DW_AT_name (attribute
);
1885 static char buffer
[100];
1887 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1896 add_dwo_info (const char * value
, dwarf_vma cu_offset
, dwo_type type
)
1898 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1900 dwinfo
->type
= type
;
1901 dwinfo
->value
= value
;
1902 dwinfo
->cu_offset
= cu_offset
;
1903 dwinfo
->next
= first_dwo_info
;
1904 first_dwo_info
= dwinfo
;
1908 add_dwo_name (const char * name
, dwarf_vma cu_offset
)
1910 add_dwo_info (name
, cu_offset
, DWO_NAME
);
1914 add_dwo_dir (const char * dir
, dwarf_vma cu_offset
)
1916 add_dwo_info (dir
, cu_offset
, DWO_DIR
);
1920 add_dwo_id (const char * id
, dwarf_vma cu_offset
)
1922 add_dwo_info (id
, cu_offset
, DWO_ID
);
1926 free_dwo_info (void)
1931 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1933 next
= dwinfo
->next
;
1936 first_dwo_info
= NULL
;
1939 /* Ensure that START + UVALUE is less than END.
1940 Return an adjusted UVALUE if necessary to ensure this relationship. */
1942 static inline dwarf_vma
1943 check_uvalue (const unsigned char * start
,
1945 const unsigned char * end
)
1947 dwarf_vma max_uvalue
= end
- start
;
1949 /* See PR 17512: file: 008-103549-0.001:0.1.
1950 and PR 24829 for examples of where these tests are triggered. */
1951 if (uvalue
> max_uvalue
)
1953 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1954 uvalue
= max_uvalue
;
1960 static unsigned char *
1961 skip_attr_bytes (unsigned long form
,
1962 unsigned char * data
,
1963 unsigned const char * end
,
1964 dwarf_vma pointer_size
,
1965 dwarf_vma offset_size
,
1967 dwarf_vma
* value_return
)
1969 dwarf_signed_vma svalue
;
1970 dwarf_vma uvalue
= 0;
1976 case DW_FORM_ref_addr
:
1977 if (dwarf_version
== 2)
1978 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1979 else if (dwarf_version
> 2)
1980 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1986 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1990 case DW_FORM_line_strp
:
1991 case DW_FORM_sec_offset
:
1992 case DW_FORM_GNU_ref_alt
:
1993 case DW_FORM_GNU_strp_alt
:
1994 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1997 case DW_FORM_flag_present
:
2004 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2009 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2014 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2018 READ_SLEB (svalue
, data
, end
);
2022 case DW_FORM_ref_udata
:
2024 case DW_FORM_GNU_str_index
:
2025 case DW_FORM_GNU_addr_index
:
2026 READ_ULEB (uvalue
, data
, end
);
2031 dwarf_vma high_bits
;
2033 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2035 if (sizeof (uvalue
) > 4)
2036 uvalue
+= high_bits
<< 32;
2037 else if (high_bits
!= 0)
2039 /* FIXME: What to do ? */
2046 case DW_FORM_ref_sig8
:
2050 case DW_FORM_data16
:
2054 case DW_FORM_string
:
2055 data
+= strnlen ((char *) data
, end
- data
) + 1;
2059 case DW_FORM_exprloc
:
2060 READ_ULEB (uvalue
, data
, end
);
2064 case DW_FORM_block1
:
2065 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
2069 case DW_FORM_block2
:
2070 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
2074 case DW_FORM_block4
:
2075 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
2079 case DW_FORM_indirect
:
2080 READ_ULEB (form
, data
, end
);
2081 if (form
== DW_FORM_implicit_const
)
2082 SKIP_ULEB (data
, end
);
2083 return skip_attr_bytes (form
, data
, end
, pointer_size
, offset_size
, dwarf_version
, value_return
);
2089 * value_return
= uvalue
;
2091 data
= (unsigned char *) end
;
2095 /* Given form FORM with value UVALUE, locate and return the abbreviation
2096 associated with it. */
2098 static abbrev_entry
*
2099 get_type_abbrev_from_form (unsigned long form
,
2100 unsigned long uvalue
,
2101 dwarf_vma cu_offset
,
2102 const struct dwarf_section
* section
,
2103 unsigned long * abbrev_num_return
,
2104 unsigned char ** data_return
,
2105 unsigned long * cu_offset_return
)
2107 unsigned long abbrev_number
;
2109 abbrev_entry
* entry
;
2110 unsigned char * data
;
2112 if (abbrev_num_return
!= NULL
)
2113 * abbrev_num_return
= 0;
2114 if (data_return
!= NULL
)
2115 * data_return
= NULL
;
2119 case DW_FORM_GNU_ref_alt
:
2120 /* FIXME: We are unable to handle this form at the moment. */
2123 case DW_FORM_ref_addr
:
2124 if (uvalue
>= section
->size
)
2126 warn (_("Unable to resolve ref_addr form: uvalue %lx > section size %lx (%s)\n"),
2127 uvalue
, (long) section
->size
, section
->name
);
2136 case DW_FORM_ref_udata
:
2137 if (uvalue
+ cu_offset
> section
->size
)
2139 warn (_("Unable to resolve ref form: uvalue %lx + cu_offset %lx > section size %lx\n"),
2140 uvalue
, (long) cu_offset
, (long) section
->size
);
2143 uvalue
+= cu_offset
;
2146 /* FIXME: Are there other DW_FORMs that can be used by types ? */
2149 warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form
);
2153 data
= (unsigned char *) section
->start
+ uvalue
;
2154 map
= find_abbrev_map_by_offset (uvalue
);
2158 warn (_("Unable to find abbreviations for CU offset %#lx\n"), uvalue
);
2161 if (map
->list
== NULL
)
2163 warn (_("Empty abbreviation list encountered for CU offset %lx\n"), uvalue
);
2167 if (cu_offset_return
!= NULL
)
2169 if (form
== DW_FORM_ref_addr
)
2170 * cu_offset_return
= map
->start
;
2172 * cu_offset_return
= cu_offset
;
2175 READ_ULEB (abbrev_number
, data
, section
->start
+ section
->size
);
2177 for (entry
= map
->list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2178 if (entry
->number
== abbrev_number
)
2181 if (abbrev_num_return
!= NULL
)
2182 * abbrev_num_return
= abbrev_number
;
2184 if (data_return
!= NULL
)
2185 * data_return
= data
;
2188 warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number
);
2193 /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY
2194 can be determined to be a signed type. The data for ENTRY can be
2195 found starting at DATA. */
2198 get_type_signedness (abbrev_entry
* entry
,
2199 const struct dwarf_section
* section
,
2200 unsigned char * data
,
2201 unsigned const char * end
,
2202 dwarf_vma cu_offset
,
2203 dwarf_vma pointer_size
,
2204 dwarf_vma offset_size
,
2206 bfd_boolean
* is_signed
,
2207 unsigned int nesting
)
2211 * is_signed
= FALSE
;
2213 #define MAX_NESTING 20
2214 if (nesting
> MAX_NESTING
)
2216 /* FIXME: Warn - or is this expected ?
2217 NB/ We need to avoid infinite recursion. */
2221 for (attr
= entry
->first_attr
;
2222 attr
!= NULL
&& attr
->attribute
;
2225 unsigned char * orig_data
= data
;
2226 dwarf_vma uvalue
= 0;
2228 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
2229 offset_size
, dwarf_version
, & uvalue
);
2233 switch (attr
->attribute
)
2235 case DW_AT_linkage_name
:
2239 if (attr
->form
== DW_FORM_strp
)
2240 printf (", %s", fetch_indirect_string (uvalue
));
2241 else if (attr
->form
== DW_FORM_string
)
2242 printf (", %s", orig_data
);
2249 abbrev_entry
* type_abbrev
;
2250 unsigned char * type_data
;
2251 unsigned long type_cu_offset
;
2253 type_abbrev
= get_type_abbrev_from_form (attr
->form
,
2257 NULL
/* abbrev num return */,
2260 if (type_abbrev
== NULL
)
2263 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2264 pointer_size
, offset_size
, dwarf_version
,
2265 is_signed
, nesting
+ 1);
2269 case DW_AT_encoding
:
2270 /* Determine signness. */
2273 case DW_ATE_address
:
2274 /* FIXME - some architectures have signed addresses. */
2275 case DW_ATE_boolean
:
2276 case DW_ATE_unsigned
:
2277 case DW_ATE_unsigned_char
:
2278 case DW_ATE_unsigned_fixed
:
2279 * is_signed
= FALSE
;
2283 case DW_ATE_complex_float
:
2286 case DW_ATE_signed_char
:
2287 case DW_ATE_imaginary_float
:
2288 case DW_ATE_decimal_float
:
2289 case DW_ATE_signed_fixed
:
2299 read_and_print_leb128 (unsigned char * data
,
2300 unsigned int * bytes_read
,
2301 unsigned const char * end
,
2302 bfd_boolean is_signed
)
2305 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2307 report_leb_status (status
, __FILE__
, __LINE__
);
2309 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2313 display_discr_list (unsigned long form
,
2315 unsigned char * data
,
2316 unsigned const char * end
,
2321 printf ("[default]");
2328 case DW_FORM_block1
:
2329 case DW_FORM_block2
:
2330 case DW_FORM_block4
:
2331 /* Move data pointer back to the start of the byte array. */
2335 printf ("<corrupt>\n");
2336 warn (_("corrupt discr_list - not using a block form\n"));
2342 printf ("<corrupt>\n");
2343 warn (_("corrupt discr_list - block not long enough\n"));
2347 bfd_boolean is_signed
=
2348 (level
> 0 && level
<= MAX_CU_NESTING
)
2349 ? level_type_signed
[level
- 1] : FALSE
;
2354 unsigned char discriminant
;
2355 unsigned int bytes_read
;
2357 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2361 assert (uvalue
> 0);
2362 switch (discriminant
)
2366 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2367 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2368 uvalue
-= bytes_read
;
2374 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2375 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2376 uvalue
-= bytes_read
;
2380 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2381 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2382 uvalue
-= bytes_read
;
2387 printf ("<corrupt>\n");
2388 warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"),
2398 printf (")(signed)");
2400 printf (")(unsigned)");
2403 static unsigned char *
2404 read_and_display_attr_value (unsigned long attribute
,
2406 dwarf_signed_vma implicit_const
,
2407 unsigned char * start
,
2408 unsigned char * data
,
2409 unsigned char * end
,
2410 dwarf_vma cu_offset
,
2411 dwarf_vma pointer_size
,
2412 dwarf_vma offset_size
,
2414 debug_info
* debug_info_p
,
2416 struct dwarf_section
* section
,
2417 struct cu_tu_set
* this_set
,
2421 dwarf_signed_vma svalue
;
2422 dwarf_vma uvalue
= 0;
2423 unsigned char * block_start
= NULL
;
2424 unsigned char * orig_data
= data
;
2426 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2428 warn (_("Corrupt attribute\n"));
2432 if (do_wide
&& ! do_loc
)
2434 /* PR 26847: Display the name of the form. */
2435 const char * name
= get_FORM_name (form
);
2437 /* For convenience we skip the DW_FORM_ prefix to the name. */
2439 name
+= 8; /* strlen ("DW_FORM_") */
2440 printf ("%c(%s)", delimiter
, name
);
2448 case DW_FORM_ref_addr
:
2449 if (dwarf_version
== 2)
2450 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2451 else if (dwarf_version
> 2)
2452 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2454 error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n"));
2458 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2462 case DW_FORM_line_strp
:
2463 case DW_FORM_sec_offset
:
2464 case DW_FORM_GNU_ref_alt
:
2465 case DW_FORM_GNU_strp_alt
:
2466 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2469 case DW_FORM_flag_present
:
2476 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2481 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2486 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2490 READ_SLEB (svalue
, data
, end
);
2494 case DW_FORM_GNU_str_index
:
2495 case DW_FORM_ref_udata
:
2497 case DW_FORM_GNU_addr_index
:
2498 READ_ULEB (uvalue
, data
, end
);
2501 case DW_FORM_indirect
:
2502 READ_ULEB (form
, data
, end
);
2504 printf ("%c%s", delimiter
, get_FORM_name (form
));
2505 if (form
== DW_FORM_implicit_const
)
2506 READ_SLEB (implicit_const
, data
, end
);
2507 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2509 cu_offset
, pointer_size
,
2510 offset_size
, dwarf_version
,
2511 debug_info_p
, do_loc
,
2512 section
, this_set
, delimiter
, level
);
2517 case DW_FORM_ref_addr
:
2519 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2522 case DW_FORM_GNU_ref_alt
:
2526 /* We have already printed the form name. */
2527 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2529 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
));
2531 /* FIXME: Follow the reference... */
2537 case DW_FORM_ref_udata
:
2539 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2544 case DW_FORM_sec_offset
:
2546 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2549 case DW_FORM_flag_present
:
2556 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2559 case DW_FORM_implicit_const
:
2561 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2568 dwarf_vma high_bits
;
2572 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2574 if (form
== DW_FORM_ref8
)
2575 add64 (& high_bits
, & utmp
, cu_offset
);
2576 printf ("%c0x%s", delimiter
,
2577 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2580 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2581 && num_debug_info_entries
== 0)
2583 if (sizeof (uvalue
) == 8)
2584 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2586 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2592 case DW_FORM_data16
:
2595 dwarf_vma left_high_bits
, left_low_bits
;
2596 dwarf_vma right_high_bits
, right_low_bits
;
2598 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2599 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2600 if (byte_get
== byte_get_little_endian
)
2603 left_high_bits
^= right_high_bits
;
2604 right_high_bits
^= left_high_bits
;
2605 left_high_bits
^= right_high_bits
;
2606 left_low_bits
^= right_low_bits
;
2607 right_low_bits
^= left_low_bits
;
2608 left_low_bits
^= right_low_bits
;
2610 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2611 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2612 left_high_bits
, left_low_bits
, right_high_bits
,
2618 case DW_FORM_string
:
2620 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2621 data
+= strnlen ((char *) data
, end
- data
) + 1;
2625 case DW_FORM_exprloc
:
2626 READ_ULEB (uvalue
, data
, end
);
2629 if (block_start
>= end
)
2631 warn (_("Block ends prematurely\n"));
2636 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2639 data
= block_start
+ uvalue
;
2641 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2644 case DW_FORM_block1
:
2645 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2648 case DW_FORM_block2
:
2649 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2652 case DW_FORM_block4
:
2653 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2660 /* We have already displayed the form name. */
2661 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2662 dwarf_vmatoa ("x", uvalue
),
2663 fetch_indirect_string (uvalue
));
2665 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2666 dwarf_vmatoa ("x", uvalue
),
2667 fetch_indirect_string (uvalue
));
2671 case DW_FORM_line_strp
:
2675 /* We have already displayed the form name. */
2676 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2677 dwarf_vmatoa ("x", uvalue
),
2678 fetch_indirect_line_string (uvalue
));
2680 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2681 dwarf_vmatoa ("x", uvalue
),
2682 fetch_indirect_line_string (uvalue
));
2686 case DW_FORM_GNU_str_index
:
2689 const char * suffix
= strrchr (section
->name
, '.');
2690 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
2693 /* We have already displayed the form name. */
2694 printf (_("%c(offset: 0x%s): %s"), delimiter
,
2695 dwarf_vmatoa ("x", uvalue
),
2696 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2698 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2699 dwarf_vmatoa ("x", uvalue
),
2700 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2704 case DW_FORM_GNU_strp_alt
:
2708 /* We have already displayed the form name. */
2709 printf (_("%c(offset: 0x%s) %s"), delimiter
,
2710 dwarf_vmatoa ("x", uvalue
),
2711 fetch_alt_indirect_string (uvalue
));
2713 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2714 dwarf_vmatoa ("x", uvalue
),
2715 fetch_alt_indirect_string (uvalue
));
2719 case DW_FORM_indirect
:
2720 /* Handled above. */
2723 case DW_FORM_ref_sig8
:
2726 dwarf_vma high_bits
;
2729 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2731 /* We have already displayed the form name. */
2732 printf ("%c: 0x%s", delimiter
,
2733 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2735 printf ("%csignature: 0x%s", delimiter
,
2736 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2741 case DW_FORM_GNU_addr_index
:
2745 /* We have already displayed the form name. */
2746 printf (_("%c(index: 0x%s): %s"), delimiter
,
2747 dwarf_vmatoa ("x", uvalue
),
2748 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2750 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2751 dwarf_vmatoa ("x", uvalue
),
2752 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2757 warn (_("Unrecognized form: %lu\n"), form
);
2761 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2762 && num_debug_info_entries
== 0
2763 && debug_info_p
!= NULL
)
2767 case DW_AT_frame_base
:
2768 have_frame_base
= 1;
2770 case DW_AT_location
:
2771 case DW_AT_GNU_locviews
:
2772 case DW_AT_string_length
:
2773 case DW_AT_return_addr
:
2774 case DW_AT_data_member_location
:
2775 case DW_AT_vtable_elem_location
:
2777 case DW_AT_static_link
:
2778 case DW_AT_use_location
:
2779 case DW_AT_call_value
:
2780 case DW_AT_GNU_call_site_value
:
2781 case DW_AT_call_data_value
:
2782 case DW_AT_GNU_call_site_data_value
:
2783 case DW_AT_call_target
:
2784 case DW_AT_GNU_call_site_target
:
2785 case DW_AT_call_target_clobbered
:
2786 case DW_AT_GNU_call_site_target_clobbered
:
2787 if ((dwarf_version
< 4
2788 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2789 || form
== DW_FORM_sec_offset
)
2791 /* Process location list. */
2792 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2793 unsigned int num
= debug_info_p
->num_loc_offsets
;
2795 if (lmax
== 0 || num
>= lmax
)
2798 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2799 xcrealloc (debug_info_p
->loc_offsets
,
2800 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2801 debug_info_p
->loc_views
= (dwarf_vma
*)
2802 xcrealloc (debug_info_p
->loc_views
,
2803 lmax
, sizeof (*debug_info_p
->loc_views
));
2804 debug_info_p
->have_frame_base
= (int *)
2805 xcrealloc (debug_info_p
->have_frame_base
,
2806 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2807 debug_info_p
->max_loc_offsets
= lmax
;
2809 if (this_set
!= NULL
)
2810 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2811 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2812 if (attribute
!= DW_AT_GNU_locviews
)
2814 /* Corrupt DWARF info can produce more offsets than views.
2815 See PR 23062 for an example. */
2816 if (debug_info_p
->num_loc_offsets
2817 > debug_info_p
->num_loc_views
)
2818 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2821 debug_info_p
->loc_offsets
[num
] = uvalue
;
2822 debug_info_p
->num_loc_offsets
++;
2827 assert (debug_info_p
->num_loc_views
<= num
);
2828 num
= debug_info_p
->num_loc_views
;
2829 if (num
> debug_info_p
->num_loc_offsets
)
2830 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2833 debug_info_p
->loc_views
[num
] = uvalue
;
2834 debug_info_p
->num_loc_views
++;
2841 if (need_base_address
)
2842 debug_info_p
->base_address
= uvalue
;
2845 case DW_AT_GNU_addr_base
:
2846 debug_info_p
->addr_base
= uvalue
;
2849 case DW_AT_GNU_ranges_base
:
2850 debug_info_p
->ranges_base
= uvalue
;
2854 if ((dwarf_version
< 4
2855 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2856 || form
== DW_FORM_sec_offset
)
2858 /* Process range list. */
2859 unsigned int lmax
= debug_info_p
->max_range_lists
;
2860 unsigned int num
= debug_info_p
->num_range_lists
;
2862 if (lmax
== 0 || num
>= lmax
)
2865 debug_info_p
->range_lists
= (dwarf_vma
*)
2866 xcrealloc (debug_info_p
->range_lists
,
2867 lmax
, sizeof (*debug_info_p
->range_lists
));
2868 debug_info_p
->max_range_lists
= lmax
;
2870 debug_info_p
->range_lists
[num
] = uvalue
;
2871 debug_info_p
->num_range_lists
++;
2875 case DW_AT_GNU_dwo_name
:
2876 case DW_AT_dwo_name
:
2881 add_dwo_name ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2883 case DW_FORM_GNU_strp_alt
:
2884 add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue
), cu_offset
);
2886 case DW_FORM_GNU_str_index
:
2887 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
), cu_offset
);
2889 case DW_FORM_string
:
2890 add_dwo_name ((const char *) orig_data
, cu_offset
);
2893 warn (_("Unsupported form (%s) for attribute %s\n"),
2894 get_FORM_name (form
), get_AT_name (attribute
));
2899 case DW_AT_comp_dir
:
2900 /* FIXME: Also extract a build-id in a CU/TU. */
2905 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
), cu_offset
);
2907 case DW_FORM_GNU_strp_alt
:
2908 add_dwo_dir (fetch_alt_indirect_string (uvalue
), cu_offset
);
2910 case DW_FORM_line_strp
:
2911 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
), cu_offset
);
2913 case DW_FORM_GNU_str_index
:
2914 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
), cu_offset
);
2916 case DW_FORM_string
:
2917 add_dwo_dir ((const char *) orig_data
, cu_offset
);
2920 warn (_("Unsupported form (%s) for attribute %s\n"),
2921 get_FORM_name (form
), get_AT_name (attribute
));
2926 case DW_AT_GNU_dwo_id
:
2931 /* FIXME: Record the length of the ID as well ? */
2932 add_dwo_id ((const char *) (data
- 8), cu_offset
);
2935 warn (_("Unsupported form (%s) for attribute %s\n"),
2936 get_FORM_name (form
), get_AT_name (attribute
));
2946 if (do_loc
|| attribute
== 0)
2949 /* For some attributes we can display further information. */
2953 if (level
>= 0 && level
< MAX_CU_NESTING
2954 && uvalue
< (size_t) (end
- start
))
2956 bfd_boolean is_signed
= FALSE
;
2957 abbrev_entry
* type_abbrev
;
2958 unsigned char * type_data
;
2959 unsigned long type_cu_offset
;
2961 type_abbrev
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
2962 section
, NULL
, & type_data
, & type_cu_offset
);
2963 if (type_abbrev
!= NULL
)
2965 get_type_signedness (type_abbrev
, section
, type_data
, end
, type_cu_offset
,
2966 pointer_size
, offset_size
, dwarf_version
,
2969 level_type_signed
[level
] = is_signed
;
2977 case DW_INL_not_inlined
:
2978 printf (_("(not inlined)"));
2980 case DW_INL_inlined
:
2981 printf (_("(inlined)"));
2983 case DW_INL_declared_not_inlined
:
2984 printf (_("(declared as inline but ignored)"));
2986 case DW_INL_declared_inlined
:
2987 printf (_("(declared as inline and inlined)"));
2990 printf (_(" (Unknown inline attribute value: %s)"),
2991 dwarf_vmatoa ("x", uvalue
));
2996 case DW_AT_language
:
3000 /* Ordered by the numeric value of these constants. */
3001 case DW_LANG_C89
: printf ("(ANSI C)"); break;
3002 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
3003 case DW_LANG_Ada83
: printf ("(Ada)"); break;
3004 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
3005 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
3006 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
3007 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
3008 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
3009 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
3010 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
3011 /* DWARF 2.1 values. */
3012 case DW_LANG_Java
: printf ("(Java)"); break;
3013 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
3014 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
3015 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
3016 /* DWARF 3 values. */
3017 case DW_LANG_PLI
: printf ("(PLI)"); break;
3018 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
3019 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
3020 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
3021 case DW_LANG_D
: printf ("(D)"); break;
3022 /* DWARF 4 values. */
3023 case DW_LANG_Python
: printf ("(Python)"); break;
3024 /* DWARF 5 values. */
3025 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
3026 case DW_LANG_Go
: printf ("(Go)"); break;
3027 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
3028 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
3029 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
3030 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
3031 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
3032 case DW_LANG_Rust
: printf ("(Rust)"); break;
3033 case DW_LANG_C11
: printf ("(C11)"); break;
3034 case DW_LANG_Swift
: printf ("(Swift)"); break;
3035 case DW_LANG_Julia
: printf ("(Julia)"); break;
3036 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
3037 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
3038 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
3039 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
3040 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
3041 /* MIPS extension. */
3042 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
3043 /* UPC extension. */
3044 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
3046 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
3047 printf (_("(implementation defined: %s)"),
3048 dwarf_vmatoa ("x", uvalue
));
3050 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
3055 case DW_AT_encoding
:
3059 case DW_ATE_void
: printf ("(void)"); break;
3060 case DW_ATE_address
: printf ("(machine address)"); break;
3061 case DW_ATE_boolean
: printf ("(boolean)"); break;
3062 case DW_ATE_complex_float
: printf ("(complex float)"); break;
3063 case DW_ATE_float
: printf ("(float)"); break;
3064 case DW_ATE_signed
: printf ("(signed)"); break;
3065 case DW_ATE_signed_char
: printf ("(signed char)"); break;
3066 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
3067 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
3068 /* DWARF 2.1 values: */
3069 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
3070 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
3071 /* DWARF 3 values: */
3072 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
3073 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
3074 case DW_ATE_edited
: printf ("(edited)"); break;
3075 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
3076 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
3077 /* DWARF 4 values: */
3078 case DW_ATE_UTF
: printf ("(unicode string)"); break;
3079 /* DWARF 5 values: */
3080 case DW_ATE_UCS
: printf ("(UCS)"); break;
3081 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
3083 /* HP extensions: */
3084 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
3085 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
3086 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
3087 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
3088 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
3089 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
3090 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
3093 if (uvalue
>= DW_ATE_lo_user
3094 && uvalue
<= DW_ATE_hi_user
)
3095 printf (_("(user defined type)"));
3097 printf (_("(unknown type)"));
3102 case DW_AT_accessibility
:
3106 case DW_ACCESS_public
: printf ("(public)"); break;
3107 case DW_ACCESS_protected
: printf ("(protected)"); break;
3108 case DW_ACCESS_private
: printf ("(private)"); break;
3110 printf (_("(unknown accessibility)"));
3115 case DW_AT_visibility
:
3119 case DW_VIS_local
: printf ("(local)"); break;
3120 case DW_VIS_exported
: printf ("(exported)"); break;
3121 case DW_VIS_qualified
: printf ("(qualified)"); break;
3122 default: printf (_("(unknown visibility)")); break;
3126 case DW_AT_endianity
:
3130 case DW_END_default
: printf ("(default)"); break;
3131 case DW_END_big
: printf ("(big)"); break;
3132 case DW_END_little
: printf ("(little)"); break;
3134 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
3135 printf (_("(user specified)"));
3137 printf (_("(unknown endianity)"));
3142 case DW_AT_virtuality
:
3146 case DW_VIRTUALITY_none
: printf ("(none)"); break;
3147 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
3148 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
3149 default: printf (_("(unknown virtuality)")); break;
3153 case DW_AT_identifier_case
:
3157 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
3158 case DW_ID_up_case
: printf ("(up_case)"); break;
3159 case DW_ID_down_case
: printf ("(down_case)"); break;
3160 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
3161 default: printf (_("(unknown case)")); break;
3165 case DW_AT_calling_convention
:
3169 case DW_CC_normal
: printf ("(normal)"); break;
3170 case DW_CC_program
: printf ("(program)"); break;
3171 case DW_CC_nocall
: printf ("(nocall)"); break;
3172 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
3173 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
3174 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
3175 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
3177 if (uvalue
>= DW_CC_lo_user
3178 && uvalue
<= DW_CC_hi_user
)
3179 printf (_("(user defined)"));
3181 printf (_("(unknown convention)"));
3185 case DW_AT_ordering
:
3190 case -1: printf (_("(undefined)")); break;
3191 case 0: printf ("(row major)"); break;
3192 case 1: printf ("(column major)"); break;
3196 case DW_AT_decimal_sign
:
3200 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
3201 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
3202 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
3203 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
3204 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
3205 default: printf (_("(unrecognised)")); break;
3209 case DW_AT_defaulted
:
3213 case DW_DEFAULTED_no
: printf (_("(no)")); break;
3214 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
3215 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
3216 default: printf (_("(unrecognised)")); break;
3220 case DW_AT_discr_list
:
3222 display_discr_list (form
, uvalue
, data
, end
, level
);
3225 case DW_AT_frame_base
:
3226 have_frame_base
= 1;
3228 case DW_AT_location
:
3229 case DW_AT_string_length
:
3230 case DW_AT_return_addr
:
3231 case DW_AT_data_member_location
:
3232 case DW_AT_vtable_elem_location
:
3234 case DW_AT_static_link
:
3235 case DW_AT_use_location
:
3236 case DW_AT_call_value
:
3237 case DW_AT_GNU_call_site_value
:
3238 case DW_AT_call_data_value
:
3239 case DW_AT_GNU_call_site_data_value
:
3240 case DW_AT_call_target
:
3241 case DW_AT_GNU_call_site_target
:
3242 case DW_AT_call_target_clobbered
:
3243 case DW_AT_GNU_call_site_target_clobbered
:
3244 if ((dwarf_version
< 4
3245 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
3246 || form
== DW_FORM_sec_offset
)
3247 printf (_(" (location list)"));
3249 case DW_AT_allocated
:
3250 case DW_AT_associated
:
3251 case DW_AT_data_location
:
3253 case DW_AT_upper_bound
:
3254 case DW_AT_lower_bound
:
3257 int need_frame_base
;
3260 need_frame_base
= decode_location_expression (block_start
,
3265 cu_offset
, section
);
3267 if (need_frame_base
&& !have_frame_base
)
3268 printf (_(" [without DW_AT_frame_base]"));
3272 case DW_AT_data_bit_offset
:
3273 case DW_AT_byte_size
:
3274 case DW_AT_bit_size
:
3275 case DW_AT_string_length_byte_size
:
3276 case DW_AT_string_length_bit_size
:
3277 case DW_AT_bit_stride
:
3278 if (form
== DW_FORM_exprloc
)
3281 (void) decode_location_expression (block_start
, pointer_size
,
3282 offset_size
, dwarf_version
,
3283 uvalue
, cu_offset
, section
);
3290 unsigned long abbrev_number
;
3291 abbrev_entry
*entry
;
3293 entry
= get_type_abbrev_from_form (form
, uvalue
, cu_offset
,
3294 section
, & abbrev_number
, NULL
, NULL
);
3297 if (form
!= DW_FORM_GNU_ref_alt
)
3298 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
3299 dwarf_vmatoa ("x", uvalue
),
3300 (unsigned long) (orig_data
- section
->start
));
3304 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
3305 printf (" (%s)", get_TAG_name (entry
->tag
));
3318 static unsigned char *
3319 read_and_display_attr (unsigned long attribute
,
3321 dwarf_signed_vma implicit_const
,
3322 unsigned char * start
,
3323 unsigned char * data
,
3324 unsigned char * end
,
3325 dwarf_vma cu_offset
,
3326 dwarf_vma pointer_size
,
3327 dwarf_vma offset_size
,
3329 debug_info
* debug_info_p
,
3331 struct dwarf_section
* section
,
3332 struct cu_tu_set
* this_set
,
3336 printf (" %-18s:", get_AT_name (attribute
));
3337 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
3339 cu_offset
, pointer_size
, offset_size
,
3340 dwarf_version
, debug_info_p
,
3341 do_loc
, section
, this_set
, ' ', level
);
3347 /* Like load_debug_section, but if the ordinary call fails, and we are
3348 following debug links, then attempt to load the requested section
3349 from one of the separate debug info files. */
3352 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3355 if (load_debug_section (sec_enum
, handle
))
3357 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3359 /* See if we can associate a filename with this section. */
3362 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3363 if (i
->handle
== handle
)
3365 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3373 if (do_follow_links
)
3377 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3379 if (load_debug_section (sec_enum
, i
->handle
))
3381 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3383 /* FIXME: We should check to see if any of the remaining debug info
3384 files also contain this section, and, umm, do something about it. */
3394 introduce (struct dwarf_section
* section
, bfd_boolean raw
)
3398 if (do_follow_links
&& section
->filename
)
3399 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3400 section
->name
, section
->filename
);
3402 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3406 if (do_follow_links
&& section
->filename
)
3407 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3408 section
->name
, section
->filename
);
3410 printf (_("Contents of the %s section:\n\n"), section
->name
);
3414 /* Process the contents of a .debug_info section.
3415 If do_loc is TRUE then we are scanning for location lists and dwo tags
3416 and we do not want to display anything to the user.
3417 If do_types is TRUE, we are processing a .debug_types section instead of
3418 a .debug_info section.
3419 The information displayed is restricted by the values in DWARF_START_DIE
3420 and DWARF_CUTOFF_LEVEL.
3421 Returns TRUE upon success. Otherwise an error or warning message is
3422 printed and FALSE is returned. */
3425 process_debug_info (struct dwarf_section
* section
,
3427 enum dwarf_section_display_enum abbrev_sec
,
3429 bfd_boolean do_types
)
3431 unsigned char *start
= section
->start
;
3432 unsigned char *end
= start
+ section
->size
;
3433 unsigned char *section_begin
;
3435 unsigned int num_units
= 0;
3437 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3438 && num_debug_info_entries
== 0
3443 /* First scan the section to get the number of comp units. */
3444 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3447 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3448 will be the length. For a 64-bit DWARF section, it'll be
3449 the escape code 0xffffffff followed by an 8 byte length. */
3450 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3452 if (length
== 0xffffffff)
3454 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3455 section_begin
+= length
+ 12;
3457 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3459 warn (_("Reserved length value (0x%s) found in section %s\n"),
3460 dwarf_vmatoa ("x", length
), section
->name
);
3464 section_begin
+= length
+ 4;
3466 /* Negative values are illegal, they may even cause infinite
3467 looping. This can happen if we can't accurately apply
3468 relocations to an object file, or if the file is corrupt. */
3469 if ((signed long) length
<= 0 || section_begin
< start
)
3471 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3472 dwarf_vmatoa ("x", length
), section
->name
);
3479 error (_("No comp units in %s section ?\n"), section
->name
);
3483 /* Then allocate an array to hold the information. */
3484 debug_information
= (debug_info
*) cmalloc (num_units
,
3485 sizeof (* debug_information
));
3486 if (debug_information
== NULL
)
3488 error (_("Not enough memory for a debug info array of %u entries\n"),
3490 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3494 /* PR 17531: file: 92ca3797.
3495 We cannot rely upon the debug_information array being initialised
3496 before it is used. A corrupt file could easily contain references
3497 to a unit for which information has not been made available. So
3498 we ensure that the array is zeroed here. */
3499 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3501 alloc_num_debug_info_entries
= num_units
;
3506 load_debug_section_with_follow (str
, file
);
3507 load_debug_section_with_follow (line_str
, file
);
3508 load_debug_section_with_follow (str_dwo
, file
);
3509 load_debug_section_with_follow (str_index
, file
);
3510 load_debug_section_with_follow (str_index_dwo
, file
);
3511 load_debug_section_with_follow (debug_addr
, file
);
3514 load_debug_section_with_follow (abbrev_sec
, file
);
3515 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3517 warn (_("Unable to locate %s section!\n"),
3518 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3522 if (!do_loc
&& dwarf_start_die
== 0)
3523 introduce (section
, FALSE
);
3525 free_all_abbrevs ();
3526 free (cu_abbrev_map
);
3527 cu_abbrev_map
= NULL
;
3528 next_free_abbrev_map_entry
= 0;
3530 /* In order to be able to resolve DW_FORM_ref_attr forms we need
3531 to load *all* of the abbrevs for all CUs in this .debug_info
3532 section. This does effectively mean that we (partially) read
3533 every CU header twice. */
3534 for (section_begin
= start
; start
< end
;)
3536 DWARF2_Internal_CompUnit compunit
;
3537 unsigned char * hdrptr
;
3538 dwarf_vma abbrev_base
;
3540 dwarf_vma cu_offset
;
3541 unsigned int offset_size
;
3542 unsigned int initial_length_size
;
3543 struct cu_tu_set
* this_set
;
3548 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3550 if (compunit
.cu_length
== 0xffffffff)
3552 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3554 initial_length_size
= 12;
3559 initial_length_size
= 4;
3562 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3564 cu_offset
= start
- section_begin
;
3566 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3568 if (compunit
.cu_version
< 5)
3570 compunit
.cu_unit_type
= DW_UT_compile
;
3571 /* Initialize it due to a false compiler warning. */
3572 compunit
.cu_pointer_size
= -1;
3576 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3577 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3579 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3582 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3584 if (this_set
== NULL
)
3587 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3591 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3592 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3595 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3596 compunit
.cu_abbrev_offset
);
3599 unsigned char * next
;
3601 list
= new_abbrev_list (abbrev_base
,
3602 compunit
.cu_abbrev_offset
);
3603 next
= process_abbrev_set
3604 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3605 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3606 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3607 + abbrev_base
+ abbrev_size
),
3609 list
->start_of_next_abbrevs
= next
;
3612 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3613 + initial_length_size
;
3614 record_abbrev_list_for_cu (cu_offset
, start
- section_begin
, list
);
3617 for (start
= section_begin
, unit
= 0; start
< end
; unit
++)
3619 DWARF2_Internal_CompUnit compunit
;
3620 unsigned char *hdrptr
;
3621 unsigned char *tags
;
3622 int level
, last_level
, saved_level
;
3623 dwarf_vma cu_offset
;
3624 unsigned long sec_off
;
3625 unsigned int offset_size
;
3626 unsigned int initial_length_size
;
3627 dwarf_vma signature_high
= 0;
3628 dwarf_vma signature_low
= 0;
3629 dwarf_vma type_offset
= 0;
3630 struct cu_tu_set
*this_set
;
3631 dwarf_vma abbrev_base
;
3633 abbrev_list
* list
= NULL
;
3637 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3639 if (compunit
.cu_length
== 0xffffffff)
3641 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3643 initial_length_size
= 12;
3648 initial_length_size
= 4;
3651 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3653 cu_offset
= start
- section_begin
;
3655 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3657 if (compunit
.cu_version
< 5)
3659 compunit
.cu_unit_type
= DW_UT_compile
;
3660 /* Initialize it due to a false compiler warning. */
3661 compunit
.cu_pointer_size
= -1;
3665 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3666 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3668 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3671 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3673 if (this_set
== NULL
)
3676 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3680 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3681 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3684 if (compunit
.cu_version
< 5)
3685 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3687 /* PR 17512: file: 001-108546-0.001:0.1. */
3688 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3690 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3691 compunit
.cu_pointer_size
, offset_size
);
3692 compunit
.cu_pointer_size
= offset_size
;
3697 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3699 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3702 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3703 + initial_length_size
))
3705 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3706 + initial_length_size
;
3710 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3711 && num_debug_info_entries
== 0
3712 && alloc_num_debug_info_entries
> unit
3715 debug_information
[unit
].cu_offset
= cu_offset
;
3716 debug_information
[unit
].pointer_size
3717 = compunit
.cu_pointer_size
;
3718 debug_information
[unit
].offset_size
= offset_size
;
3719 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3720 debug_information
[unit
].base_address
= 0;
3721 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3722 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3723 debug_information
[unit
].loc_offsets
= NULL
;
3724 debug_information
[unit
].have_frame_base
= NULL
;
3725 debug_information
[unit
].max_loc_offsets
= 0;
3726 debug_information
[unit
].num_loc_offsets
= 0;
3727 debug_information
[unit
].range_lists
= NULL
;
3728 debug_information
[unit
].max_range_lists
= 0;
3729 debug_information
[unit
].num_range_lists
= 0;
3732 if (!do_loc
&& dwarf_start_die
== 0)
3734 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3735 dwarf_vmatoa ("x", cu_offset
));
3736 printf (_(" Length: 0x%s (%s)\n"),
3737 dwarf_vmatoa ("x", compunit
.cu_length
),
3738 offset_size
== 8 ? "64-bit" : "32-bit");
3739 printf (_(" Version: %d\n"), compunit
.cu_version
);
3740 if (compunit
.cu_version
>= 5)
3741 printf (_(" Unit Type: %s (%x)\n"),
3742 get_DW_UT_name (compunit
.cu_unit_type
) ?: "???",
3743 compunit
.cu_unit_type
);
3744 printf (_(" Abbrev Offset: 0x%s\n"),
3745 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3746 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3751 printf (_(" Signature: 0x%s\n"),
3752 dwarf_vmatoa64 (signature_high
, signature_low
,
3753 buf
, sizeof (buf
)));
3754 printf (_(" Type Offset: 0x%s\n"),
3755 dwarf_vmatoa ("x", type_offset
));
3757 if (this_set
!= NULL
)
3759 dwarf_vma
*offsets
= this_set
->section_offsets
;
3760 size_t *sizes
= this_set
->section_sizes
;
3762 printf (_(" Section contributions:\n"));
3763 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3764 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3765 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3766 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3767 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3768 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3769 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3770 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3771 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3772 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3773 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3774 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3778 sec_off
= cu_offset
+ initial_length_size
;
3779 if (sec_off
+ compunit
.cu_length
< sec_off
3780 || sec_off
+ compunit
.cu_length
> section
->size
)
3782 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3784 (unsigned long) cu_offset
,
3785 dwarf_vmatoa ("x", compunit
.cu_length
));
3791 start
+= compunit
.cu_length
+ initial_length_size
;
3793 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3795 warn (_("CU at offset %s contains corrupt or "
3796 "unsupported version number: %d.\n"),
3797 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3801 if (compunit
.cu_unit_type
!= DW_UT_compile
3802 && compunit
.cu_unit_type
!= DW_UT_partial
3803 && compunit
.cu_unit_type
!= DW_UT_type
)
3805 warn (_("CU at offset %s contains corrupt or "
3806 "unsupported unit type: %d.\n"),
3807 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3811 /* Process the abbrevs used by this compilation unit. */
3812 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3813 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3814 (unsigned long) compunit
.cu_abbrev_offset
,
3815 (unsigned long) abbrev_size
);
3816 /* PR 17531: file:4bcd9ce9. */
3817 else if ((abbrev_base
+ abbrev_size
)
3818 > debug_displays
[abbrev_sec
].section
.size
)
3819 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3820 (unsigned long) abbrev_base
+ abbrev_size
,
3821 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3824 list
= find_abbrev_list_by_abbrev_offset (abbrev_base
,
3825 compunit
.cu_abbrev_offset
);
3828 unsigned char * next
;
3830 list
= new_abbrev_list (abbrev_base
,
3831 compunit
.cu_abbrev_offset
);
3832 next
= process_abbrev_set
3833 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3834 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3835 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3836 + abbrev_base
+ abbrev_size
),
3838 list
->start_of_next_abbrevs
= next
;
3845 while (tags
< start
)
3847 unsigned long abbrev_number
;
3848 unsigned long die_offset
;
3849 abbrev_entry
*entry
;
3851 int do_printing
= 1;
3853 die_offset
= tags
- section_begin
;
3855 READ_ULEB (abbrev_number
, tags
, start
);
3857 /* A null DIE marks the end of a list of siblings or it may also be
3858 a section padding. */
3859 if (abbrev_number
== 0)
3861 /* Check if it can be a section padding for the last CU. */
3862 if (level
== 0 && start
== end
)
3866 for (chk
= tags
; chk
< start
; chk
++)
3873 if (!do_loc
&& die_offset
>= dwarf_start_die
3874 && (dwarf_cutoff_level
== -1
3875 || level
< dwarf_cutoff_level
))
3876 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3882 static unsigned num_bogus_warns
= 0;
3884 if (num_bogus_warns
< 3)
3886 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3887 die_offset
, section
->name
);
3889 if (num_bogus_warns
== 3)
3890 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3893 if (dwarf_start_die
!= 0 && level
< saved_level
)
3900 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3904 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3905 saved_level
= level
;
3906 do_printing
= (dwarf_cutoff_level
== -1
3907 || level
< dwarf_cutoff_level
);
3909 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3910 level
, die_offset
, abbrev_number
);
3911 else if (dwarf_cutoff_level
== -1
3912 || last_level
< dwarf_cutoff_level
)
3913 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3918 /* Scan through the abbreviation list until we reach the
3923 for (entry
= list
->first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
3924 if (entry
->number
== abbrev_number
)
3929 if (!do_loc
&& do_printing
)
3934 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3935 die_offset
, abbrev_number
);
3939 if (!do_loc
&& do_printing
)
3940 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3945 need_base_address
= 0;
3947 case DW_TAG_compile_unit
:
3948 need_base_address
= 1;
3949 need_dwo_info
= do_loc
;
3951 case DW_TAG_entry_point
:
3952 case DW_TAG_subprogram
:
3953 need_base_address
= 0;
3954 /* Assuming that there is no DW_AT_frame_base. */
3955 have_frame_base
= 0;
3959 debug_info
*debug_info_p
=
3960 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3961 ? debug_information
+ unit
: NULL
;
3963 assert (!debug_info_p
3964 || (debug_info_p
->num_loc_offsets
3965 == debug_info_p
->num_loc_views
));
3967 for (attr
= entry
->first_attr
;
3968 attr
&& attr
->attribute
;
3971 if (! do_loc
&& do_printing
)
3972 /* Show the offset from where the tag was extracted. */
3973 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3974 tags
= read_and_display_attr (attr
->attribute
,
3976 attr
->implicit_const
,
3981 compunit
.cu_pointer_size
,
3983 compunit
.cu_version
,
3985 do_loc
|| ! do_printing
,
3991 /* If a locview attribute appears before a location one,
3992 make sure we don't associate it with an earlier
3995 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3998 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3999 debug_info_p
->num_loc_views
++;
4000 assert (debug_info_p
->num_loc_views
4001 == debug_info_p
->num_loc_offsets
);
4008 warn(_("DIE has locviews without loclist\n"));
4009 debug_info_p
->num_loc_views
--;
4016 if (entry
->children
)
4021 /* Set num_debug_info_entries here so that it can be used to check if
4022 we need to process .debug_loc and .debug_ranges sections. */
4023 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
4024 && num_debug_info_entries
== 0
4027 if (num_units
> alloc_num_debug_info_entries
)
4028 num_debug_info_entries
= alloc_num_debug_info_entries
;
4030 num_debug_info_entries
= num_units
;
4039 /* Locate and scan the .debug_info section in the file and record the pointer
4040 sizes and offsets for the compilation units in it. Usually an executable
4041 will have just one pointer size, but this is not guaranteed, and so we try
4042 not to make any assumptions. Returns zero upon failure, or the number of
4043 compilation units upon success. */
4046 load_debug_info (void * file
)
4048 /* If we have already tried and failed to load the .debug_info
4049 section then do not bother to repeat the task. */
4050 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4053 /* If we already have the information there is nothing else to do. */
4054 if (num_debug_info_entries
> 0)
4055 return num_debug_info_entries
;
4057 /* If this is a DWARF package file, load the CU and TU indexes. */
4058 (void) load_cu_tu_indexes (file
);
4060 if (load_debug_section_with_follow (info
, file
)
4061 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
4062 return num_debug_info_entries
;
4064 if (load_debug_section_with_follow (info_dwo
, file
)
4065 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
4066 abbrev_dwo
, TRUE
, FALSE
))
4067 return num_debug_info_entries
;
4069 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
4073 /* Read a DWARF .debug_line section header starting at DATA.
4074 Upon success returns an updated DATA pointer and the LINFO
4075 structure and the END_OF_SEQUENCE pointer will be filled in.
4076 Otherwise returns NULL. */
4078 static unsigned char *
4079 read_debug_line_header (struct dwarf_section
* section
,
4080 unsigned char * data
,
4081 unsigned char * end
,
4082 DWARF2_Internal_LineInfo
* linfo
,
4083 unsigned char ** end_of_sequence
)
4085 unsigned char *hdrptr
;
4086 unsigned int initial_length_size
;
4088 /* Extract information from the Line Number Program Header.
4089 (section 6.2.4 in the Dwarf3 doc). */
4092 /* Get and check the length of the block. */
4093 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
4095 if (linfo
->li_length
== 0xffffffff)
4097 /* This section is 64-bit DWARF 3. */
4098 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
4099 linfo
->li_offset_size
= 8;
4100 initial_length_size
= 12;
4104 linfo
->li_offset_size
= 4;
4105 initial_length_size
= 4;
4108 if (linfo
->li_length
+ initial_length_size
> section
->size
)
4110 /* If the length field has a relocation against it, then we should
4111 not complain if it is inaccurate (and probably negative). This
4112 happens in object files when the .debug_line section is actually
4113 comprised of several different .debug_line.* sections, (some of
4114 which may be removed by linker garbage collection), and a relocation
4115 is used to compute the correct length once that is done. */
4116 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
4118 linfo
->li_length
= (end
- data
) - initial_length_size
;
4122 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
4123 (long) linfo
->li_length
);
4128 /* Get and check the version number. */
4129 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
4131 if (linfo
->li_version
!= 2
4132 && linfo
->li_version
!= 3
4133 && linfo
->li_version
!= 4
4134 && linfo
->li_version
!= 5)
4136 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
4137 "is currently supported.\n"));
4141 if (linfo
->li_version
>= 5)
4143 SAFE_BYTE_GET_AND_INC (linfo
->li_address_size
, hdrptr
, 1, end
);
4145 SAFE_BYTE_GET_AND_INC (linfo
->li_segment_size
, hdrptr
, 1, end
);
4146 if (linfo
->li_segment_size
!= 0)
4148 warn (_("The %s section contains "
4149 "unsupported segment selector size: %d.\n"),
4150 section
->name
, linfo
->li_segment_size
);
4155 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
4156 linfo
->li_offset_size
, end
);
4157 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
4159 if (linfo
->li_version
>= 4)
4161 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
4163 if (linfo
->li_max_ops_per_insn
== 0)
4165 warn (_("Invalid maximum operations per insn.\n"));
4170 linfo
->li_max_ops_per_insn
= 1;
4172 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
4173 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
4174 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
4175 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
4177 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
4178 /* PR 17512: file:002-117414-0.004. */
4179 if (* end_of_sequence
> end
)
4181 warn (_("Line length %s extends beyond end of section\n"),
4182 dwarf_vmatoa ("u", linfo
->li_length
));
4183 * end_of_sequence
= end
;
4190 static unsigned char *
4191 display_formatted_table (unsigned char * data
,
4192 unsigned char * start
,
4193 unsigned char * end
,
4194 const DWARF2_Internal_LineInfo
* linfo
,
4195 struct dwarf_section
* section
,
4198 unsigned char *format_start
, format_count
, *format
, formati
;
4199 dwarf_vma data_count
, datai
;
4200 unsigned int namepass
, last_entry
= 0;
4201 const char * table_name
= is_dir
? N_("Directory Table") : N_("File Name Table");
4203 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4204 if (do_checks
&& format_count
> 5)
4205 warn (_("Unexpectedly large number of columns in the %s (%u)\n"),
4206 table_name
, format_count
);
4208 format_start
= data
;
4209 for (formati
= 0; formati
< format_count
; formati
++)
4211 SKIP_ULEB (data
, end
);
4212 SKIP_ULEB (data
, end
);
4215 warn (_("%s: Corrupt format description entry\n"), table_name
);
4220 READ_ULEB (data_count
, data
, end
);
4221 if (data_count
== 0)
4223 printf (_("\n The %s is empty.\n"), table_name
);
4226 else if (data
== end
)
4228 warn (_("%s: Corrupt entry count - expected %s but none found\n"),
4229 table_name
, dwarf_vmatoa ("x", data_count
));
4233 else if (format_count
== 0)
4235 warn (_("%s: format count is zero, but the table is not empty\n"),
4240 printf (_("\n The %s (offset 0x%lx, lines %s, columns %u):\n"),
4241 table_name
, (long) (data
- start
), dwarf_vmatoa ("u", data_count
),
4244 printf (_(" Entry"));
4245 /* Delay displaying name as the last entry for better screen layout. */
4246 for (namepass
= 0; namepass
< 2; namepass
++)
4248 format
= format_start
;
4249 for (formati
= 0; formati
< format_count
; formati
++)
4251 dwarf_vma content_type
;
4253 READ_ULEB (content_type
, format
, end
);
4254 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
4255 switch (content_type
)
4258 printf (_("\tName"));
4260 case DW_LNCT_directory_index
:
4261 printf (_("\tDir"));
4263 case DW_LNCT_timestamp
:
4264 printf (_("\tTime"));
4267 printf (_("\tSize"));
4270 printf (_("\tMD5\t\t\t"));
4273 printf (_("\t(Unknown format content type %s)"),
4274 dwarf_vmatoa ("u", content_type
));
4276 SKIP_ULEB (format
, end
);
4281 for (datai
= 0; datai
< data_count
; datai
++)
4283 unsigned char *datapass
= data
;
4285 printf (" %d", last_entry
++);
4286 /* Delay displaying name as the last entry for better screen layout. */
4287 for (namepass
= 0; namepass
< 2; namepass
++)
4289 format
= format_start
;
4291 for (formati
= 0; formati
< format_count
; formati
++)
4293 dwarf_vma content_type
, form
;
4295 READ_ULEB (content_type
, format
, end
);
4296 READ_ULEB (form
, format
, end
);
4297 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
4298 0, 0, linfo
->li_offset_size
,
4299 linfo
->li_version
, NULL
,
4300 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
4301 section
, NULL
, '\t', -1);
4305 if (data
== end
&& (datai
< data_count
- 1))
4307 warn (_("\n%s: Corrupt entries list\n"), table_name
);
4316 display_debug_lines_raw (struct dwarf_section
* section
,
4317 unsigned char * data
,
4318 unsigned char * end
,
4321 unsigned char *start
= section
->start
;
4322 int verbose_view
= 0;
4324 introduce (section
, TRUE
);
4328 static DWARF2_Internal_LineInfo saved_linfo
;
4329 DWARF2_Internal_LineInfo linfo
;
4330 unsigned char *standard_opcodes
;
4331 unsigned char *end_of_sequence
;
4334 if (const_strneq (section
->name
, ".debug_line.")
4335 /* Note: the following does not apply to .debug_line.dwo sections.
4336 These are full debug_line sections. */
4337 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4339 /* Sections named .debug_line.<foo> are fragments of a .debug_line
4340 section containing just the Line Number Statements. They are
4341 created by the assembler and intended to be used alongside gcc's
4342 -ffunction-sections command line option. When the linker's
4343 garbage collection decides to discard a .text.<foo> section it
4344 can then also discard the line number information in .debug_line.<foo>.
4346 Since the section is a fragment it does not have the details
4347 needed to fill out a LineInfo structure, so instead we use the
4348 details from the last full debug_line section that we processed. */
4349 end_of_sequence
= end
;
4350 standard_opcodes
= NULL
;
4351 linfo
= saved_linfo
;
4352 /* PR 17531: file: 0522b371. */
4353 if (linfo
.li_line_range
== 0)
4355 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4358 reset_state_machine (linfo
.li_default_is_stmt
);
4362 unsigned char * hdrptr
;
4364 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4365 & end_of_sequence
)) == NULL
)
4368 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
4369 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
4370 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
4371 if (linfo
.li_version
>= 5)
4373 printf (_(" Address size (bytes): %d\n"), linfo
.li_address_size
);
4374 printf (_(" Segment selector (bytes): %d\n"), linfo
.li_segment_size
);
4376 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
4377 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
4378 if (linfo
.li_version
>= 4)
4379 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
4380 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
4381 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
4382 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
4383 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
4385 /* PR 17512: file: 1665-6428-0.004. */
4386 if (linfo
.li_line_range
== 0)
4388 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4389 linfo
.li_line_range
= 1;
4392 reset_state_machine (linfo
.li_default_is_stmt
);
4394 /* Display the contents of the Opcodes table. */
4395 standard_opcodes
= hdrptr
;
4397 /* PR 17512: file: 002-417945-0.004. */
4398 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
4400 warn (_("Line Base extends beyond end of section\n"));
4404 printf (_("\n Opcodes:\n"));
4406 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
4407 printf (ngettext (" Opcode %d has %d arg\n",
4408 " Opcode %d has %d args\n",
4409 standard_opcodes
[i
- 1]),
4410 i
, standard_opcodes
[i
- 1]);
4412 /* Display the contents of the Directory table. */
4413 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4415 if (linfo
.li_version
>= 5)
4417 load_debug_section_with_follow (line_str
, file
);
4419 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4421 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
4427 printf (_("\n The Directory Table is empty.\n"));
4430 unsigned int last_dir_entry
= 0;
4432 printf (_("\n The Directory Table (offset 0x%lx):\n"),
4433 (long)(data
- start
));
4435 while (data
< end
&& *data
!= 0)
4437 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
4439 data
+= strnlen ((char *) data
, end
- data
) + 1;
4442 /* PR 17512: file: 002-132094-0.004. */
4443 if (data
>= end
- 1)
4447 /* Skip the NUL at the end of the table. */
4450 /* Display the contents of the File Name table. */
4452 printf (_("\n The File Name Table is empty.\n"));
4455 printf (_("\n The File Name Table (offset 0x%lx):\n"),
4456 (long)(data
- start
));
4457 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
4459 while (data
< end
&& *data
!= 0)
4461 unsigned char *name
;
4464 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4466 data
+= strnlen ((char *) data
, end
- data
) + 1;
4468 READ_ULEB (val
, data
, end
);
4469 printf ("%s\t", dwarf_vmatoa ("u", val
));
4470 READ_ULEB (val
, data
, end
);
4471 printf ("%s\t", dwarf_vmatoa ("u", val
));
4472 READ_ULEB (val
, data
, end
);
4473 printf ("%s\t", dwarf_vmatoa ("u", val
));
4474 printf ("%.*s\n", (int)(end
- name
), name
);
4478 warn (_("Corrupt file name table entry\n"));
4484 /* Skip the NUL at the end of the table. */
4489 saved_linfo
= linfo
;
4492 /* Now display the statements. */
4493 if (data
>= end_of_sequence
)
4494 printf (_(" No Line Number Statements.\n"));
4497 printf (_(" Line Number Statements:\n"));
4499 while (data
< end_of_sequence
)
4501 unsigned char op_code
;
4502 dwarf_signed_vma adv
;
4505 printf (" [0x%08lx]", (long)(data
- start
));
4509 if (op_code
>= linfo
.li_opcode_base
)
4511 op_code
-= linfo
.li_opcode_base
;
4512 uladv
= (op_code
/ linfo
.li_line_range
);
4513 if (linfo
.li_max_ops_per_insn
== 1)
4515 uladv
*= linfo
.li_min_insn_length
;
4516 state_machine_regs
.address
+= uladv
;
4518 state_machine_regs
.view
= 0;
4519 printf (_(" Special opcode %d: "
4520 "advance Address by %s to 0x%s%s"),
4521 op_code
, dwarf_vmatoa ("u", uladv
),
4522 dwarf_vmatoa ("x", state_machine_regs
.address
),
4523 verbose_view
&& uladv
4524 ? _(" (reset view)") : "");
4529 = ((state_machine_regs
.op_index
+ uladv
)
4530 / linfo
.li_max_ops_per_insn
)
4531 * linfo
.li_min_insn_length
;
4533 state_machine_regs
.address
+= addrdelta
;
4534 state_machine_regs
.op_index
4535 = (state_machine_regs
.op_index
+ uladv
)
4536 % linfo
.li_max_ops_per_insn
;
4538 state_machine_regs
.view
= 0;
4539 printf (_(" Special opcode %d: "
4540 "advance Address by %s to 0x%s[%d]%s"),
4541 op_code
, dwarf_vmatoa ("u", uladv
),
4542 dwarf_vmatoa ("x", state_machine_regs
.address
),
4543 state_machine_regs
.op_index
,
4544 verbose_view
&& addrdelta
4545 ? _(" (reset view)") : "");
4547 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4548 state_machine_regs
.line
+= adv
;
4549 printf (_(" and Line by %s to %d"),
4550 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4551 if (verbose_view
|| state_machine_regs
.view
)
4552 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4555 state_machine_regs
.view
++;
4560 case DW_LNS_extended_op
:
4561 data
+= process_extended_line_op (data
,
4562 linfo
.li_default_is_stmt
,
4567 printf (_(" Copy"));
4568 if (verbose_view
|| state_machine_regs
.view
)
4569 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4572 state_machine_regs
.view
++;
4575 case DW_LNS_advance_pc
:
4576 READ_ULEB (uladv
, data
, end
);
4577 if (linfo
.li_max_ops_per_insn
== 1)
4579 uladv
*= linfo
.li_min_insn_length
;
4580 state_machine_regs
.address
+= uladv
;
4582 state_machine_regs
.view
= 0;
4583 printf (_(" Advance PC by %s to 0x%s%s\n"),
4584 dwarf_vmatoa ("u", uladv
),
4585 dwarf_vmatoa ("x", state_machine_regs
.address
),
4586 verbose_view
&& uladv
4587 ? _(" (reset view)") : "");
4592 = ((state_machine_regs
.op_index
+ uladv
)
4593 / linfo
.li_max_ops_per_insn
)
4594 * linfo
.li_min_insn_length
;
4595 state_machine_regs
.address
4597 state_machine_regs
.op_index
4598 = (state_machine_regs
.op_index
+ uladv
)
4599 % linfo
.li_max_ops_per_insn
;
4601 state_machine_regs
.view
= 0;
4602 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4603 dwarf_vmatoa ("u", uladv
),
4604 dwarf_vmatoa ("x", state_machine_regs
.address
),
4605 state_machine_regs
.op_index
,
4606 verbose_view
&& addrdelta
4607 ? _(" (reset view)") : "");
4611 case DW_LNS_advance_line
:
4612 READ_SLEB (adv
, data
, end
);
4613 state_machine_regs
.line
+= adv
;
4614 printf (_(" Advance Line by %s to %d\n"),
4615 dwarf_vmatoa ("d", adv
),
4616 state_machine_regs
.line
);
4619 case DW_LNS_set_file
:
4620 READ_ULEB (uladv
, data
, end
);
4621 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4622 dwarf_vmatoa ("u", uladv
));
4623 state_machine_regs
.file
= uladv
;
4626 case DW_LNS_set_column
:
4627 READ_ULEB (uladv
, data
, end
);
4628 printf (_(" Set column to %s\n"),
4629 dwarf_vmatoa ("u", uladv
));
4630 state_machine_regs
.column
= uladv
;
4633 case DW_LNS_negate_stmt
:
4634 adv
= state_machine_regs
.is_stmt
;
4636 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4637 state_machine_regs
.is_stmt
= adv
;
4640 case DW_LNS_set_basic_block
:
4641 printf (_(" Set basic block\n"));
4642 state_machine_regs
.basic_block
= 1;
4645 case DW_LNS_const_add_pc
:
4646 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4647 if (linfo
.li_max_ops_per_insn
)
4649 uladv
*= linfo
.li_min_insn_length
;
4650 state_machine_regs
.address
+= uladv
;
4652 state_machine_regs
.view
= 0;
4653 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4654 dwarf_vmatoa ("u", uladv
),
4655 dwarf_vmatoa ("x", state_machine_regs
.address
),
4656 verbose_view
&& uladv
4657 ? _(" (reset view)") : "");
4662 = ((state_machine_regs
.op_index
+ uladv
)
4663 / linfo
.li_max_ops_per_insn
)
4664 * linfo
.li_min_insn_length
;
4665 state_machine_regs
.address
4667 state_machine_regs
.op_index
4668 = (state_machine_regs
.op_index
+ uladv
)
4669 % linfo
.li_max_ops_per_insn
;
4671 state_machine_regs
.view
= 0;
4672 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4673 dwarf_vmatoa ("u", uladv
),
4674 dwarf_vmatoa ("x", state_machine_regs
.address
),
4675 state_machine_regs
.op_index
,
4676 verbose_view
&& addrdelta
4677 ? _(" (reset view)") : "");
4681 case DW_LNS_fixed_advance_pc
:
4682 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4683 state_machine_regs
.address
+= uladv
;
4684 state_machine_regs
.op_index
= 0;
4685 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4686 dwarf_vmatoa ("u", uladv
),
4687 dwarf_vmatoa ("x", state_machine_regs
.address
));
4688 /* Do NOT reset view. */
4691 case DW_LNS_set_prologue_end
:
4692 printf (_(" Set prologue_end to true\n"));
4695 case DW_LNS_set_epilogue_begin
:
4696 printf (_(" Set epilogue_begin to true\n"));
4699 case DW_LNS_set_isa
:
4700 READ_ULEB (uladv
, data
, end
);
4701 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4705 printf (_(" Unknown opcode %d with operands: "), op_code
);
4707 if (standard_opcodes
!= NULL
)
4708 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4710 READ_ULEB (uladv
, data
, end
);
4711 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4712 i
== 1 ? "" : ", ");
4727 unsigned char *name
;
4728 unsigned int directory_index
;
4729 unsigned int modification_date
;
4730 unsigned int length
;
4733 /* Output a decoded representation of the .debug_line section. */
4736 display_debug_lines_decoded (struct dwarf_section
* section
,
4737 unsigned char * start
,
4738 unsigned char * data
,
4739 unsigned char * end
,
4742 static DWARF2_Internal_LineInfo saved_linfo
;
4744 introduce (section
, FALSE
);
4748 /* This loop amounts to one iteration per compilation unit. */
4749 DWARF2_Internal_LineInfo linfo
;
4750 unsigned char *standard_opcodes
;
4751 unsigned char *end_of_sequence
;
4753 File_Entry
*file_table
= NULL
;
4754 unsigned int n_files
= 0;
4755 unsigned char **directory_table
= NULL
;
4756 dwarf_vma n_directories
= 0;
4758 if (const_strneq (section
->name
, ".debug_line.")
4759 /* Note: the following does not apply to .debug_line.dwo sections.
4760 These are full debug_line sections. */
4761 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4763 /* See comment in display_debug_lines_raw(). */
4764 end_of_sequence
= end
;
4765 standard_opcodes
= NULL
;
4766 linfo
= saved_linfo
;
4767 /* PR 17531: file: 0522b371. */
4768 if (linfo
.li_line_range
== 0)
4770 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4773 reset_state_machine (linfo
.li_default_is_stmt
);
4777 unsigned char *hdrptr
;
4779 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4780 & end_of_sequence
)) == NULL
)
4783 /* PR 17531: file: 0522b371. */
4784 if (linfo
.li_line_range
== 0)
4786 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4787 linfo
.li_line_range
= 1;
4789 reset_state_machine (linfo
.li_default_is_stmt
);
4791 /* Save a pointer to the contents of the Opcodes table. */
4792 standard_opcodes
= hdrptr
;
4794 /* Traverse the Directory table just to count entries. */
4795 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4799 warn (_("opcode base of %d extends beyond end of section\n"),
4800 linfo
.li_opcode_base
);
4804 if (linfo
.li_version
>= 5)
4806 unsigned char *format_start
, format_count
, *format
;
4807 dwarf_vma formati
, entryi
;
4809 load_debug_section_with_follow (line_str
, fileptr
);
4811 /* Skip directories format. */
4812 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4813 if (do_checks
&& format_count
> 1)
4814 warn (_("Unexpectedly large number of columns in the directory name table (%u)\n"),
4816 format_start
= data
;
4817 for (formati
= 0; formati
< format_count
; formati
++)
4819 SKIP_ULEB (data
, end
);
4820 SKIP_ULEB (data
, end
);
4823 READ_ULEB (n_directories
, data
, end
);
4826 warn (_("Corrupt directories list\n"));
4830 if (n_directories
== 0)
4831 directory_table
= NULL
;
4833 directory_table
= (unsigned char **)
4834 xmalloc (n_directories
* sizeof (unsigned char *));
4836 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4838 unsigned char **pathp
= &directory_table
[entryi
];
4840 format
= format_start
;
4841 for (formati
= 0; formati
< format_count
; formati
++)
4843 dwarf_vma content_type
, form
;
4846 READ_ULEB (content_type
, format
, end
);
4847 READ_ULEB (form
, format
, end
);
4850 warn (_("Corrupt directories list\n"));
4853 switch (content_type
)
4858 case DW_FORM_string
:
4861 case DW_FORM_line_strp
:
4862 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4864 /* Remove const by the cast. */
4865 *pathp
= (unsigned char *)
4866 fetch_indirect_line_string (uvalue
);
4871 data
= read_and_display_attr_value (0, form
, 0, start
,
4873 linfo
.li_offset_size
,
4880 warn (_("Corrupt directories list\n"));
4885 /* Skip files format. */
4886 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4887 if (do_checks
&& format_count
> 5)
4888 warn (_("Unexpectedly large number of columns in the file name table (%u)\n"),
4890 format_start
= data
;
4891 for (formati
= 0; formati
< format_count
; formati
++)
4893 SKIP_ULEB (data
, end
);
4894 SKIP_ULEB (data
, end
);
4897 READ_ULEB (n_files
, data
, end
);
4898 if (data
== end
&& n_files
> 0)
4900 warn (_("Corrupt file name list\n"));
4907 file_table
= (File_Entry
*) xcalloc (1, n_files
4908 * sizeof (File_Entry
));
4910 for (entryi
= 0; entryi
< n_files
; entryi
++)
4912 File_Entry
*file
= &file_table
[entryi
];
4914 format
= format_start
;
4915 for (formati
= 0; formati
< format_count
; formati
++)
4917 dwarf_vma content_type
, form
;
4921 READ_ULEB (content_type
, format
, end
);
4922 READ_ULEB (form
, format
, end
);
4925 warn (_("Corrupt file name list\n"));
4928 switch (content_type
)
4933 case DW_FORM_string
:
4936 case DW_FORM_line_strp
:
4937 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4939 /* Remove const by the cast. */
4940 file
->name
= (unsigned char *)
4941 fetch_indirect_line_string (uvalue
);
4945 case DW_LNCT_directory_index
:
4949 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4953 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4958 READ_ULEB (file
->directory_index
, tmp
, end
);
4963 data
= read_and_display_attr_value (0, form
, 0, start
,
4965 linfo
.li_offset_size
,
4972 warn (_("Corrupt file name list\n"));
4981 unsigned char *ptr_directory_table
= data
;
4983 while (data
< end
&& *data
!= 0)
4985 data
+= strnlen ((char *) data
, end
- data
) + 1;
4992 warn (_("directory table ends unexpectedly\n"));
4997 /* Go through the directory table again to save the directories. */
4998 directory_table
= (unsigned char **)
4999 xmalloc (n_directories
* sizeof (unsigned char *));
5002 while (*ptr_directory_table
!= 0)
5004 directory_table
[i
] = ptr_directory_table
;
5005 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
5006 ptr_directory_table
- end
) + 1;
5010 /* Skip the NUL at the end of the table. */
5013 /* Traverse the File Name table just to count the entries. */
5014 if (data
< end
&& *data
!= 0)
5016 unsigned char *ptr_file_name_table
= data
;
5018 while (data
< end
&& *data
!= 0)
5020 /* Skip Name, directory index, last modification
5021 time and length of file. */
5022 data
+= strnlen ((char *) data
, end
- data
) + 1;
5023 SKIP_ULEB (data
, end
);
5024 SKIP_ULEB (data
, end
);
5025 SKIP_ULEB (data
, end
);
5031 warn (_("file table ends unexpectedly\n"));
5036 /* Go through the file table again to save the strings. */
5037 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
5040 while (*ptr_file_name_table
!= 0)
5042 file_table
[i
].name
= ptr_file_name_table
;
5043 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
5044 end
- ptr_file_name_table
) + 1;
5046 /* We are not interested in directory, time or size. */
5047 READ_ULEB (file_table
[i
].directory_index
,
5048 ptr_file_name_table
, end
);
5049 READ_ULEB (file_table
[i
].modification_date
,
5050 ptr_file_name_table
, end
);
5051 READ_ULEB (file_table
[i
].length
,
5052 ptr_file_name_table
, end
);
5058 /* Skip the NUL at the end of the table. */
5062 /* Print the Compilation Unit's name and a header. */
5063 if (file_table
== NULL
)
5064 printf (_("CU: No directory table\n"));
5065 else if (directory_table
== NULL
)
5066 printf (_("CU: %s:\n"), file_table
[0].name
);
5069 unsigned int ix
= file_table
[0].directory_index
;
5070 const char *directory
;
5075 else if (n_directories
== 0)
5076 directory
= _("<unknown>");
5077 else if (ix
> n_directories
)
5079 warn (_("directory index %u > number of directories %s\n"),
5080 ix
, dwarf_vmatoa ("u", n_directories
));
5081 directory
= _("<corrupt>");
5084 directory
= (char *) directory_table
[ix
- 1];
5086 if (do_wide
|| strlen (directory
) < 76)
5087 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
5089 printf ("%s:\n", file_table
[0].name
);
5093 printf (_("File name Line number Starting address View Stmt\n"));
5095 printf (_("CU: Empty file name table\n"));
5096 saved_linfo
= linfo
;
5099 /* This loop iterates through the Dwarf Line Number Program. */
5100 while (data
< end_of_sequence
)
5102 unsigned char op_code
;
5105 unsigned long int uladv
;
5106 int is_special_opcode
= 0;
5111 if (op_code
>= linfo
.li_opcode_base
)
5113 op_code
-= linfo
.li_opcode_base
;
5114 uladv
= (op_code
/ linfo
.li_line_range
);
5115 if (linfo
.li_max_ops_per_insn
== 1)
5117 uladv
*= linfo
.li_min_insn_length
;
5118 state_machine_regs
.address
+= uladv
;
5120 state_machine_regs
.view
= 0;
5125 = ((state_machine_regs
.op_index
+ uladv
)
5126 / linfo
.li_max_ops_per_insn
)
5127 * linfo
.li_min_insn_length
;
5128 state_machine_regs
.address
5130 state_machine_regs
.op_index
5131 = (state_machine_regs
.op_index
+ uladv
)
5132 % linfo
.li_max_ops_per_insn
;
5134 state_machine_regs
.view
= 0;
5137 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
5138 state_machine_regs
.line
+= adv
;
5139 is_special_opcode
= 1;
5140 /* Increment view after printing this row. */
5145 case DW_LNS_extended_op
:
5147 unsigned int ext_op_code_len
;
5148 unsigned char ext_op_code
;
5149 unsigned char *op_code_end
;
5150 unsigned char *op_code_data
= data
;
5152 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
5153 op_code_end
= op_code_data
+ ext_op_code_len
;
5154 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
5156 warn (_("Badly formed extended line op encountered!\n"));
5159 ext_op_code
= *op_code_data
++;
5163 switch (ext_op_code
)
5165 case DW_LNE_end_sequence
:
5166 /* Reset stuff after printing this row. */
5168 case DW_LNE_set_address
:
5169 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
5171 op_code_end
- op_code_data
,
5173 state_machine_regs
.op_index
= 0;
5174 state_machine_regs
.view
= 0;
5176 case DW_LNE_define_file
:
5177 file_table
= (File_Entry
*) xrealloc
5178 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
5180 ++state_machine_regs
.last_file_entry
;
5181 /* Source file name. */
5182 file_table
[n_files
].name
= op_code_data
;
5183 op_code_data
+= strlen ((char *) op_code_data
) + 1;
5184 /* Directory index. */
5185 READ_ULEB (file_table
[n_files
].directory_index
,
5186 op_code_data
, op_code_end
);
5187 /* Last modification time. */
5188 READ_ULEB (file_table
[n_files
].modification_date
,
5189 op_code_data
, op_code_end
);
5191 READ_ULEB (file_table
[n_files
].length
,
5192 op_code_data
, op_code_end
);
5196 case DW_LNE_set_discriminator
:
5197 case DW_LNE_HP_set_sequence
:
5198 /* Simply ignored. */
5202 printf (_("UNKNOWN (%u): length %ld\n"),
5203 ext_op_code
, (long int) (op_code_data
- data
));
5210 /* Increment view after printing this row. */
5213 case DW_LNS_advance_pc
:
5214 READ_ULEB (uladv
, data
, end
);
5215 if (linfo
.li_max_ops_per_insn
== 1)
5217 uladv
*= linfo
.li_min_insn_length
;
5218 state_machine_regs
.address
+= uladv
;
5220 state_machine_regs
.view
= 0;
5225 = ((state_machine_regs
.op_index
+ uladv
)
5226 / linfo
.li_max_ops_per_insn
)
5227 * linfo
.li_min_insn_length
;
5228 state_machine_regs
.address
5230 state_machine_regs
.op_index
5231 = (state_machine_regs
.op_index
+ uladv
)
5232 % linfo
.li_max_ops_per_insn
;
5234 state_machine_regs
.view
= 0;
5238 case DW_LNS_advance_line
:
5239 READ_SLEB (adv
, data
, end
);
5240 state_machine_regs
.line
+= adv
;
5243 case DW_LNS_set_file
:
5244 READ_ULEB (uladv
, data
, end
);
5245 state_machine_regs
.file
= uladv
;
5248 unsigned file
= state_machine_regs
.file
- 1;
5251 if (file_table
== NULL
|| n_files
== 0)
5252 printf (_("\n [Use file table entry %d]\n"), file
);
5254 else if (file
>= n_files
)
5256 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
5257 printf (_("\n <over large file table index %u>"), file
);
5259 else if ((dir
= file_table
[file
].directory_index
) == 0)
5260 /* If directory index is 0, that means current directory. */
5261 printf ("\n./%s:[++]\n", file_table
[file
].name
);
5262 else if (directory_table
== NULL
|| n_directories
== 0)
5263 printf (_("\n [Use file %s in directory table entry %d]\n"),
5264 file_table
[file
].name
, dir
);
5266 else if (dir
> n_directories
)
5268 warn (_("directory index %u > number of directories %s\n"),
5269 dir
, dwarf_vmatoa ("u", n_directories
));
5270 printf (_("\n <over large directory table entry %u>\n"), dir
);
5273 printf ("\n%s/%s:\n",
5274 /* The directory index starts counting at 1. */
5275 directory_table
[dir
- 1], file_table
[file
].name
);
5279 case DW_LNS_set_column
:
5280 READ_ULEB (uladv
, data
, end
);
5281 state_machine_regs
.column
= uladv
;
5284 case DW_LNS_negate_stmt
:
5285 adv
= state_machine_regs
.is_stmt
;
5287 state_machine_regs
.is_stmt
= adv
;
5290 case DW_LNS_set_basic_block
:
5291 state_machine_regs
.basic_block
= 1;
5294 case DW_LNS_const_add_pc
:
5295 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
5296 if (linfo
.li_max_ops_per_insn
== 1)
5298 uladv
*= linfo
.li_min_insn_length
;
5299 state_machine_regs
.address
+= uladv
;
5301 state_machine_regs
.view
= 0;
5306 = ((state_machine_regs
.op_index
+ uladv
)
5307 / linfo
.li_max_ops_per_insn
)
5308 * linfo
.li_min_insn_length
;
5309 state_machine_regs
.address
5311 state_machine_regs
.op_index
5312 = (state_machine_regs
.op_index
+ uladv
)
5313 % linfo
.li_max_ops_per_insn
;
5315 state_machine_regs
.view
= 0;
5319 case DW_LNS_fixed_advance_pc
:
5320 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
5321 state_machine_regs
.address
+= uladv
;
5322 state_machine_regs
.op_index
= 0;
5323 /* Do NOT reset view. */
5326 case DW_LNS_set_prologue_end
:
5329 case DW_LNS_set_epilogue_begin
:
5332 case DW_LNS_set_isa
:
5333 READ_ULEB (uladv
, data
, end
);
5334 printf (_(" Set ISA to %lu\n"), uladv
);
5338 printf (_(" Unknown opcode %d with operands: "), op_code
);
5340 if (standard_opcodes
!= NULL
)
5341 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
5345 READ_ULEB (val
, data
, end
);
5346 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
5347 i
== 1 ? "" : ", ");
5353 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
5354 to the DWARF address/line matrix. */
5355 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
5356 || (xop
== DW_LNS_copy
))
5358 const unsigned int MAX_FILENAME_LENGTH
= 35;
5360 char *newFileName
= NULL
;
5361 size_t fileNameLength
;
5365 unsigned indx
= state_machine_regs
.file
- 1;
5367 if (indx
>= n_files
)
5369 warn (_("corrupt file index %u encountered\n"), indx
);
5370 fileName
= _("<corrupt>");
5373 fileName
= (char *) file_table
[indx
].name
;
5376 fileName
= _("<unknown>");
5378 fileNameLength
= strlen (fileName
);
5380 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
5382 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
5383 /* Truncate file name */
5384 strncpy (newFileName
,
5385 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
5386 MAX_FILENAME_LENGTH
+ 1);
5387 /* FIXME: This is to pacify gcc-10 which can warn that the
5388 strncpy above might leave a non-NUL terminated string
5389 in newFileName. It won't, but gcc's analysis doesn't
5390 quite go far enough to discover this. */
5391 newFileName
[MAX_FILENAME_LENGTH
] = 0;
5395 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
5396 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
5399 /* A row with end_seq set to true has a meaningful address, but
5400 the other information in the same row is not significant.
5401 In such a row, print line as "-", and don't print
5403 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
5405 if (linfo
.li_max_ops_per_insn
== 1)
5407 if (xop
== -DW_LNE_end_sequence
)
5408 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x",
5410 state_machine_regs
.address
);
5412 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
5413 newFileName
, state_machine_regs
.line
,
5414 state_machine_regs
.address
);
5418 if (xop
== -DW_LNE_end_sequence
)
5419 printf ("%-35s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5421 state_machine_regs
.address
,
5422 state_machine_regs
.op_index
);
5424 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5425 newFileName
, state_machine_regs
.line
,
5426 state_machine_regs
.address
,
5427 state_machine_regs
.op_index
);
5432 if (linfo
.li_max_ops_per_insn
== 1)
5434 if (xop
== -DW_LNE_end_sequence
)
5435 printf ("%s %11s %#18" DWARF_VMA_FMT
"x",
5437 state_machine_regs
.address
);
5439 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
5440 newFileName
, state_machine_regs
.line
,
5441 state_machine_regs
.address
);
5445 if (xop
== -DW_LNE_end_sequence
)
5446 printf ("%s %11s %#18" DWARF_VMA_FMT
"x[%d]",
5448 state_machine_regs
.address
,
5449 state_machine_regs
.op_index
);
5451 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
5452 newFileName
, state_machine_regs
.line
,
5453 state_machine_regs
.address
,
5454 state_machine_regs
.op_index
);
5458 if (xop
!= -DW_LNE_end_sequence
)
5460 if (state_machine_regs
.view
)
5461 printf (" %6u", state_machine_regs
.view
);
5465 if (state_machine_regs
.is_stmt
)
5470 state_machine_regs
.view
++;
5472 if (xop
== -DW_LNE_end_sequence
)
5474 reset_state_machine (linfo
.li_default_is_stmt
);
5489 if (directory_table
)
5491 free (directory_table
);
5492 directory_table
= NULL
;
5503 display_debug_lines (struct dwarf_section
*section
, void *file
)
5505 unsigned char *data
= section
->start
;
5506 unsigned char *end
= data
+ section
->size
;
5508 int retValDecoded
= 1;
5510 if (do_debug_lines
== 0)
5511 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
5513 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
5514 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5516 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5517 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5519 if (!retValRaw
|| !retValDecoded
)
5526 find_debug_info_for_offset (unsigned long offset
)
5530 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5533 for (i
= 0; i
< num_debug_info_entries
; i
++)
5534 if (debug_information
[i
].cu_offset
== offset
)
5535 return debug_information
+ i
;
5541 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5543 /* See gdb/gdb-index.h. */
5544 static const char * const kinds
[] =
5556 return _ (kinds
[kind
]);
5560 display_debug_pubnames_worker (struct dwarf_section
*section
,
5561 void *file ATTRIBUTE_UNUSED
,
5564 DWARF2_Internal_PubNames names
;
5565 unsigned char *start
= section
->start
;
5566 unsigned char *end
= start
+ section
->size
;
5568 /* It does not matter if this load fails,
5569 we test for that later on. */
5570 load_debug_info (file
);
5572 introduce (section
, FALSE
);
5576 unsigned char *data
;
5577 unsigned long sec_off
;
5578 unsigned int offset_size
, initial_length_size
;
5580 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5581 if (names
.pn_length
== 0xffffffff)
5583 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5585 initial_length_size
= 12;
5590 initial_length_size
= 4;
5593 sec_off
= start
- section
->start
;
5594 if (sec_off
+ names
.pn_length
< sec_off
5595 || sec_off
+ names
.pn_length
> section
->size
)
5597 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5599 sec_off
- initial_length_size
,
5600 dwarf_vmatoa ("x", names
.pn_length
));
5605 start
+= names
.pn_length
;
5607 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5608 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5610 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5611 && num_debug_info_entries
> 0
5612 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5613 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5614 (unsigned long) names
.pn_offset
, section
->name
);
5616 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5618 printf (_(" Length: %ld\n"),
5619 (long) names
.pn_length
);
5620 printf (_(" Version: %d\n"),
5622 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5623 (unsigned long) names
.pn_offset
);
5624 printf (_(" Size of area in .debug_info section: %ld\n"),
5625 (long) names
.pn_size
);
5627 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5629 static int warned
= 0;
5633 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5641 printf (_("\n Offset Kind Name\n"));
5643 printf (_("\n Offset\tName\n"));
5647 bfd_size_type maxprint
;
5650 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5655 data
+= offset_size
;
5658 maxprint
= (end
- data
) - 1;
5662 unsigned int kind_data
;
5663 gdb_index_symbol_kind kind
;
5664 const char *kind_name
;
5667 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5670 /* GCC computes the kind as the upper byte in the CU index
5671 word, and then right shifts it by the CU index size.
5672 Left shift KIND to where the gdb-index.h accessor macros
5674 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5675 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5676 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5677 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5678 printf (" %-6lx %s,%-10s %.*s\n",
5679 (unsigned long) offset
, is_static
? _("s") : _("g"),
5680 kind_name
, (int) maxprint
, data
);
5683 printf (" %-6lx\t%.*s\n",
5684 (unsigned long) offset
, (int) maxprint
, data
);
5686 data
+= strnlen ((char *) data
, maxprint
) + 1;
5697 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5699 return display_debug_pubnames_worker (section
, file
, 0);
5703 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5705 return display_debug_pubnames_worker (section
, file
, 1);
5709 display_debug_macinfo (struct dwarf_section
*section
,
5710 void *file ATTRIBUTE_UNUSED
)
5712 unsigned char *start
= section
->start
;
5713 unsigned char *end
= start
+ section
->size
;
5714 unsigned char *curr
= start
;
5715 enum dwarf_macinfo_record_type op
;
5717 introduce (section
, FALSE
);
5721 unsigned int lineno
;
5722 const unsigned char *string
;
5724 op
= (enum dwarf_macinfo_record_type
) *curr
;
5729 case DW_MACINFO_start_file
:
5731 unsigned int filenum
;
5733 READ_ULEB (lineno
, curr
, end
);
5734 READ_ULEB (filenum
, curr
, end
);
5735 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5740 case DW_MACINFO_end_file
:
5741 printf (_(" DW_MACINFO_end_file\n"));
5744 case DW_MACINFO_define
:
5745 READ_ULEB (lineno
, curr
, end
);
5747 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5748 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5752 case DW_MACINFO_undef
:
5753 READ_ULEB (lineno
, curr
, end
);
5755 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5756 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5760 case DW_MACINFO_vendor_ext
:
5762 unsigned int constant
;
5764 READ_ULEB (constant
, curr
, end
);
5766 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5767 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5777 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5778 filename and dirname corresponding to file name table entry with index
5779 FILEIDX. Return NULL on failure. */
5781 static unsigned char *
5782 get_line_filename_and_dirname (dwarf_vma line_offset
,
5784 unsigned char **dir_name
)
5786 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5787 unsigned char *hdrptr
, *dirtable
, *file_name
;
5788 unsigned int offset_size
, initial_length_size
;
5789 unsigned int version
, opcode_base
;
5790 dwarf_vma length
, diridx
;
5791 const unsigned char * end
;
5794 if (section
->start
== NULL
5795 || line_offset
>= section
->size
5799 hdrptr
= section
->start
+ line_offset
;
5800 end
= section
->start
+ section
->size
;
5802 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5803 if (length
== 0xffffffff)
5805 /* This section is 64-bit DWARF 3. */
5806 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5808 initial_length_size
= 12;
5813 initial_length_size
= 4;
5815 if (length
+ initial_length_size
< length
5816 || length
+ initial_length_size
> section
->size
)
5819 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5820 if (version
!= 2 && version
!= 3 && version
!= 4)
5822 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5824 hdrptr
++; /* Skip max_ops_per_insn. */
5825 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5827 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5828 if (opcode_base
== 0)
5831 hdrptr
+= opcode_base
- 1;
5836 /* Skip over dirname table. */
5837 while (*hdrptr
!= '\0')
5839 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5843 hdrptr
++; /* Skip the NUL at the end of the table. */
5845 /* Now skip over preceding filename table entries. */
5846 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5848 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5849 SKIP_ULEB (hdrptr
, end
);
5850 SKIP_ULEB (hdrptr
, end
);
5851 SKIP_ULEB (hdrptr
, end
);
5853 if (hdrptr
>= end
|| *hdrptr
== '\0')
5857 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5860 READ_ULEB (diridx
, hdrptr
, end
);
5863 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5864 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5865 if (dirtable
>= end
|| *dirtable
== '\0')
5867 *dir_name
= dirtable
;
5872 display_debug_macro (struct dwarf_section
*section
,
5875 unsigned char *start
= section
->start
;
5876 unsigned char *end
= start
+ section
->size
;
5877 unsigned char *curr
= start
;
5878 unsigned char *extended_op_buf
[256];
5880 load_debug_section_with_follow (str
, file
);
5881 load_debug_section_with_follow (line
, file
);
5882 load_debug_section_with_follow (str_index
, file
);
5884 introduce (section
, FALSE
);
5888 unsigned int lineno
, version
, flags
;
5889 unsigned int offset_size
= 4;
5890 const unsigned char *string
;
5891 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5892 unsigned char **extended_ops
= NULL
;
5894 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5895 if (version
!= 4 && version
!= 5)
5897 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5902 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5905 printf (_(" Offset: 0x%lx\n"),
5906 (unsigned long) sec_offset
);
5907 printf (_(" Version: %d\n"), version
);
5908 printf (_(" Offset size: %d\n"), offset_size
);
5911 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5912 printf (_(" Offset into .debug_line: 0x%lx\n"),
5913 (unsigned long) line_offset
);
5917 unsigned int i
, count
, op
;
5920 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5922 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5923 extended_ops
= extended_op_buf
;
5926 printf (_(" Extension opcode arguments:\n"));
5927 for (i
= 0; i
< count
; i
++)
5929 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5930 extended_ops
[op
] = curr
;
5931 READ_ULEB (nargs
, curr
, end
);
5933 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5936 printf (_(" DW_MACRO_%02x arguments: "), op
);
5937 for (n
= 0; n
< nargs
; n
++)
5941 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5942 printf ("%s%s", get_FORM_name (form
),
5943 n
== nargs
- 1 ? "\n" : ", ");
5953 case DW_FORM_block1
:
5954 case DW_FORM_block2
:
5955 case DW_FORM_block4
:
5957 case DW_FORM_string
:
5959 case DW_FORM_sec_offset
:
5962 error (_("Invalid extension opcode form %s\n"),
5963 get_FORM_name (form
));
5979 error (_(".debug_macro section not zero terminated\n"));
5983 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5989 case DW_MACRO_define
:
5990 READ_ULEB (lineno
, curr
, end
);
5992 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5993 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5997 case DW_MACRO_undef
:
5998 READ_ULEB (lineno
, curr
, end
);
6000 curr
+= strnlen ((char *) string
, end
- string
) + 1;
6001 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
6005 case DW_MACRO_start_file
:
6007 unsigned int filenum
;
6008 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
6010 READ_ULEB (lineno
, curr
, end
);
6011 READ_ULEB (filenum
, curr
, end
);
6013 if ((flags
& 2) == 0)
6014 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
6017 = get_line_filename_and_dirname (line_offset
, filenum
,
6019 if (file_name
== NULL
)
6020 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
6023 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
6025 dir_name
!= NULL
? (const char *) dir_name
: "",
6026 dir_name
!= NULL
? "/" : "", file_name
);
6030 case DW_MACRO_end_file
:
6031 printf (_(" DW_MACRO_end_file\n"));
6034 case DW_MACRO_define_strp
:
6035 READ_ULEB (lineno
, curr
, end
);
6036 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6037 string
= fetch_indirect_string (offset
);
6038 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
6042 case DW_MACRO_undef_strp
:
6043 READ_ULEB (lineno
, curr
, end
);
6044 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6045 string
= fetch_indirect_string (offset
);
6046 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
6050 case DW_MACRO_import
:
6051 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6052 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
6053 (unsigned long) offset
);
6056 case DW_MACRO_define_sup
:
6057 READ_ULEB (lineno
, curr
, end
);
6058 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6059 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
6060 lineno
, (unsigned long) offset
);
6063 case DW_MACRO_undef_sup
:
6064 READ_ULEB (lineno
, curr
, end
);
6065 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6066 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
6067 lineno
, (unsigned long) offset
);
6070 case DW_MACRO_import_sup
:
6071 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
6072 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
6073 (unsigned long) offset
);
6076 case DW_MACRO_define_strx
:
6077 case DW_MACRO_undef_strx
:
6078 READ_ULEB (lineno
, curr
, end
);
6079 READ_ULEB (offset
, curr
, end
);
6080 string
= (const unsigned char *)
6081 fetch_indexed_string (offset
, NULL
, offset_size
, FALSE
);
6082 if (op
== DW_MACRO_define_strx
)
6083 printf (" DW_MACRO_define_strx ");
6085 printf (" DW_MACRO_undef_strx ");
6087 printf (_("(with offset %s) "), dwarf_vmatoa ("x", offset
));
6088 printf (_("lineno : %d macro : %s\n"),
6093 if (op
>= DW_MACRO_lo_user
&& op
<= DW_MACRO_hi_user
)
6095 printf (_(" <Target Specific macro op: %#x - UNHANDLED"), op
);
6099 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
6101 error (_(" Unknown macro opcode %02x seen\n"), op
);
6106 /* Skip over unhandled opcodes. */
6108 unsigned char *desc
= extended_ops
[op
];
6109 READ_ULEB (nargs
, desc
, end
);
6112 printf (_(" DW_MACRO_%02x\n"), op
);
6115 printf (_(" DW_MACRO_%02x -"), op
);
6116 for (n
= 0; n
< nargs
; n
++)
6120 /* DW_FORM_implicit_const is not expected here. */
6121 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
6123 = read_and_display_attr_value (0, val
, 0,
6124 start
, curr
, end
, 0, 0, offset_size
,
6125 version
, NULL
, 0, NULL
,
6143 display_debug_abbrev (struct dwarf_section
*section
,
6144 void *file ATTRIBUTE_UNUSED
)
6146 abbrev_entry
*entry
;
6147 unsigned char *start
= section
->start
;
6148 const unsigned char *end
= start
+ section
->size
;
6150 introduce (section
, FALSE
);
6157 offset
= start
- section
->start
;
6158 list
= find_abbrev_list_by_abbrev_offset (0, offset
);
6161 list
= new_abbrev_list (0, offset
);
6162 start
= process_abbrev_set (start
, end
, list
);
6163 list
->start_of_next_abbrevs
= start
;
6166 start
= list
->start_of_next_abbrevs
;
6168 if (list
->first_abbrev
== NULL
)
6171 printf (_(" Number TAG (0x%lx)\n"), (long) offset
);
6173 for (entry
= list
->first_abbrev
; entry
; entry
= entry
->next
)
6177 printf (" %ld %s [%s]\n",
6179 get_TAG_name (entry
->tag
),
6180 entry
->children
? _("has children") : _("no children"));
6182 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
6184 printf (" %-18s %s",
6185 get_AT_name (attr
->attribute
),
6186 get_FORM_name (attr
->form
));
6187 if (attr
->form
== DW_FORM_implicit_const
)
6188 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
6200 /* Return true when ADDR is the maximum address, when addresses are
6201 POINTER_SIZE bytes long. */
6204 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
6206 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
6207 return ((addr
& mask
) == mask
);
6210 /* Display a view pair list starting at *VSTART_PTR and ending at
6211 VLISTEND within SECTION. */
6214 display_view_pair_list (struct dwarf_section
*section
,
6215 unsigned char **vstart_ptr
,
6216 unsigned int debug_info_entry
,
6217 unsigned char *vlistend
)
6219 unsigned char *vstart
= *vstart_ptr
;
6220 unsigned char *section_end
= section
->start
+ section
->size
;
6221 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6223 if (vlistend
< section_end
)
6224 section_end
= vlistend
;
6228 while (vstart
< section_end
)
6230 dwarf_vma off
= vstart
- section
->start
;
6231 dwarf_vma vbegin
, vend
;
6233 READ_ULEB (vbegin
, vstart
, section_end
);
6234 if (vstart
== section_end
)
6237 READ_ULEB (vend
, vstart
, section_end
);
6238 printf (" %8.8lx ", (unsigned long) off
);
6240 print_dwarf_view (vbegin
, pointer_size
, 1);
6241 print_dwarf_view (vend
, pointer_size
, 1);
6242 printf (_("location view pair\n"));
6246 *vstart_ptr
= vstart
;
6249 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
6252 display_loc_list (struct dwarf_section
*section
,
6253 unsigned char **start_ptr
,
6254 unsigned int debug_info_entry
,
6256 dwarf_vma base_address
,
6257 unsigned char **vstart_ptr
,
6260 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6261 unsigned char *section_end
= section
->start
+ section
->size
;
6262 unsigned long cu_offset
;
6263 unsigned int pointer_size
;
6264 unsigned int offset_size
;
6269 unsigned short length
;
6270 int need_frame_base
;
6272 if (debug_info_entry
>= num_debug_info_entries
)
6274 warn (_("No debug information available for loc lists of entry: %u\n"),
6279 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6280 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6281 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6282 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6284 if (pointer_size
< 2 || pointer_size
> 8)
6286 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6287 pointer_size
, debug_info_entry
);
6293 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6294 dwarf_vma vbegin
= vm1
, vend
= vm1
;
6296 if (start
+ 2 * pointer_size
> section_end
)
6298 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6299 (unsigned long) offset
);
6303 printf (" %8.8lx ", (unsigned long) off
);
6305 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6306 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6308 if (begin
== 0 && end
== 0)
6310 /* PR 18374: In a object file we can have a location list that
6311 starts with a begin and end of 0 because there are relocations
6312 that need to be applied to the addresses. Actually applying
6313 the relocations now does not help as they will probably resolve
6314 to 0, since the object file has not been fully linked. Real
6315 end of list markers will not have any relocations against them. */
6316 if (! reloc_at (section
, off
)
6317 && ! reloc_at (section
, off
+ pointer_size
))
6319 printf (_("<End of list>\n"));
6324 /* Check base address specifiers. */
6325 if (is_max_address (begin
, pointer_size
)
6326 && !is_max_address (end
, pointer_size
))
6329 print_dwarf_vma (begin
, pointer_size
);
6330 print_dwarf_vma (end
, pointer_size
);
6331 printf (_("(base address)\n"));
6337 off
= offset
+ (vstart
- *start_ptr
);
6339 READ_ULEB (vbegin
, vstart
, section_end
);
6340 print_dwarf_view (vbegin
, pointer_size
, 1);
6342 READ_ULEB (vend
, vstart
, section_end
);
6343 print_dwarf_view (vend
, pointer_size
, 1);
6345 printf (_("views at %8.8lx for:\n %*s "),
6346 (unsigned long) off
, 8, "");
6349 if (start
+ 2 > section_end
)
6351 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6352 (unsigned long) offset
);
6356 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6358 if (start
+ length
> section_end
)
6360 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6361 (unsigned long) offset
);
6365 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6366 print_dwarf_vma (end
+ base_address
, pointer_size
);
6369 need_frame_base
= decode_location_expression (start
,
6374 cu_offset
, section
);
6377 if (need_frame_base
&& !has_frame_base
)
6378 printf (_(" [without DW_AT_frame_base]"));
6380 if (begin
== end
&& vbegin
== vend
)
6381 fputs (_(" (start == end)"), stdout
);
6382 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6383 fputs (_(" (start > end)"), stdout
);
6391 *vstart_ptr
= vstart
;
6394 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
6397 display_loclists_list (struct dwarf_section
*section
,
6398 unsigned char **start_ptr
,
6399 unsigned int debug_info_entry
,
6401 dwarf_vma base_address
,
6402 unsigned char **vstart_ptr
,
6405 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6406 unsigned char *section_end
= section
->start
+ section
->size
;
6407 unsigned long cu_offset
;
6408 unsigned int pointer_size
;
6409 unsigned int offset_size
;
6412 /* Initialize it due to a false compiler warning. */
6413 dwarf_vma begin
= -1, vbegin
= -1;
6414 dwarf_vma end
= -1, vend
= -1;
6416 int need_frame_base
;
6418 if (debug_info_entry
>= num_debug_info_entries
)
6420 warn (_("No debug information available for "
6421 "loclists lists of entry: %u\n"),
6426 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6427 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6428 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6429 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6431 if (pointer_size
< 2 || pointer_size
> 8)
6433 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6434 pointer_size
, debug_info_entry
);
6440 dwarf_vma off
= offset
+ (start
- *start_ptr
);
6441 enum dwarf_location_list_entry_type llet
;
6443 if (start
+ 1 > section_end
)
6445 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6446 (unsigned long) offset
);
6450 printf (" %8.8lx ", (unsigned long) off
);
6452 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
6454 if (vstart
&& (llet
== DW_LLE_offset_pair
6455 || llet
== DW_LLE_start_end
6456 || llet
== DW_LLE_start_length
))
6458 off
= offset
+ (vstart
- *start_ptr
);
6460 READ_ULEB (vbegin
, vstart
, section_end
);
6461 print_dwarf_view (vbegin
, pointer_size
, 1);
6463 READ_ULEB (vend
, vstart
, section_end
);
6464 print_dwarf_view (vend
, pointer_size
, 1);
6466 printf (_("views at %8.8lx for:\n %*s "),
6467 (unsigned long) off
, 8, "");
6472 case DW_LLE_end_of_list
:
6473 printf (_("<End of list>\n"));
6475 case DW_LLE_offset_pair
:
6476 READ_ULEB (begin
, start
, section_end
);
6477 begin
+= base_address
;
6478 READ_ULEB (end
, start
, section_end
);
6479 end
+= base_address
;
6481 case DW_LLE_start_end
:
6482 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6483 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
6485 case DW_LLE_start_length
:
6486 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
6487 READ_ULEB (end
, start
, section_end
);
6490 case DW_LLE_base_address
:
6491 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
6493 print_dwarf_vma (base_address
, pointer_size
);
6494 printf (_("(base address)\n"));
6496 #ifdef DW_LLE_view_pair
6497 case DW_LLE_view_pair
:
6499 printf (_("View pair entry in loclist with locviews attribute\n"));
6500 READ_ULEB (vbegin
, start
, section_end
);
6501 print_dwarf_view (vbegin
, pointer_size
, 1);
6503 READ_ULEB (vend
, start
, section_end
);
6504 print_dwarf_view (vend
, pointer_size
, 1);
6506 printf (_("views for:\n"));
6510 error (_("Invalid location list entry type %d\n"), llet
);
6513 if (llet
== DW_LLE_end_of_list
)
6515 if (llet
!= DW_LLE_offset_pair
6516 && llet
!= DW_LLE_start_end
6517 && llet
!= DW_LLE_start_length
)
6520 if (start
+ 2 > section_end
)
6522 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6523 (unsigned long) offset
);
6527 READ_ULEB (length
, start
, section_end
);
6529 print_dwarf_vma (begin
, pointer_size
);
6530 print_dwarf_vma (end
, pointer_size
);
6533 need_frame_base
= decode_location_expression (start
,
6538 cu_offset
, section
);
6541 if (need_frame_base
&& !has_frame_base
)
6542 printf (_(" [without DW_AT_frame_base]"));
6544 if (begin
== end
&& vbegin
== vend
)
6545 fputs (_(" (start == end)"), stdout
);
6546 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
6547 fputs (_(" (start > end)"), stdout
);
6555 if (vbegin
!= vm1
|| vend
!= vm1
)
6556 printf (_("Trailing view pair not used in a range"));
6559 *vstart_ptr
= vstart
;
6562 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6563 right-adjusted in a field of length LEN, and followed by a space. */
6566 print_addr_index (unsigned int idx
, unsigned int len
)
6568 static char buf
[15];
6569 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6570 printf ("%*s ", len
, buf
);
6573 /* Display a location list from a .dwo section. It uses address indexes rather
6574 than embedded addresses. This code closely follows display_loc_list, but the
6575 two are sufficiently different that combining things is very ugly. */
6578 display_loc_list_dwo (struct dwarf_section
*section
,
6579 unsigned char **start_ptr
,
6580 unsigned int debug_info_entry
,
6582 unsigned char **vstart_ptr
,
6585 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6586 unsigned char *section_end
= section
->start
+ section
->size
;
6587 unsigned long cu_offset
;
6588 unsigned int pointer_size
;
6589 unsigned int offset_size
;
6592 unsigned short length
;
6593 int need_frame_base
;
6596 if (debug_info_entry
>= num_debug_info_entries
)
6598 warn (_("No debug information for loc lists of entry: %u\n"),
6603 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6604 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6605 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6606 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6608 if (pointer_size
< 2 || pointer_size
> 8)
6610 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6611 pointer_size
, debug_info_entry
);
6617 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6619 if (start
>= section_end
)
6621 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6622 (unsigned long) offset
);
6626 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6639 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6641 READ_ULEB (view
, vstart
, section_end
);
6642 print_dwarf_view (view
, 8, 1);
6644 READ_ULEB (view
, vstart
, section_end
);
6645 print_dwarf_view (view
, 8, 1);
6647 printf (_("views at %8.8lx for:\n %*s "),
6648 (unsigned long) off
, 8, "");
6656 case 0: /* A terminating entry. */
6658 *vstart_ptr
= vstart
;
6659 printf (_("<End of list>\n"));
6661 case 1: /* A base-address entry. */
6662 READ_ULEB (idx
, start
, section_end
);
6663 print_addr_index (idx
, 8);
6664 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6665 printf (_("(base address selection entry)\n"));
6667 case 2: /* A start/end entry. */
6668 READ_ULEB (idx
, start
, section_end
);
6669 print_addr_index (idx
, 8);
6670 READ_ULEB (idx
, start
, section_end
);
6671 print_addr_index (idx
, 8);
6673 case 3: /* A start/length entry. */
6674 READ_ULEB (idx
, start
, section_end
);
6675 print_addr_index (idx
, 8);
6676 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6677 printf ("%08x ", idx
);
6679 case 4: /* An offset pair entry. */
6680 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6681 printf ("%08x ", idx
);
6682 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6683 printf ("%08x ", idx
);
6686 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6688 *vstart_ptr
= vstart
;
6692 if (start
+ 2 > section_end
)
6694 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6695 (unsigned long) offset
);
6699 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6700 if (start
+ length
> section_end
)
6702 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6703 (unsigned long) offset
);
6708 need_frame_base
= decode_location_expression (start
,
6713 cu_offset
, section
);
6716 if (need_frame_base
&& !has_frame_base
)
6717 printf (_(" [without DW_AT_frame_base]"));
6725 *vstart_ptr
= vstart
;
6728 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6731 static dwarf_vma
*loc_offsets
, *loc_views
;
6734 loc_offsets_compar (const void *ap
, const void *bp
)
6736 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6737 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6739 int ret
= (a
> b
) - (b
> a
);
6743 a
= loc_views
[*(const unsigned int *) ap
];
6744 b
= loc_views
[*(const unsigned int *) bp
];
6746 ret
= (a
> b
) - (b
> a
);
6752 display_debug_loc (struct dwarf_section
*section
, void *file
)
6754 unsigned char *start
= section
->start
, *vstart
= NULL
;
6755 unsigned long bytes
;
6756 unsigned char *section_begin
= start
;
6757 unsigned int num_loc_list
= 0;
6758 unsigned long last_offset
= 0;
6759 unsigned long last_view
= 0;
6760 unsigned int first
= 0;
6763 int seen_first_offset
= 0;
6764 int locs_sorted
= 1;
6765 unsigned char *next
= start
, *vnext
= vstart
;
6766 unsigned int *array
= NULL
;
6767 const char *suffix
= strrchr (section
->name
, '.');
6768 bfd_boolean is_dwo
= FALSE
;
6769 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6770 dwarf_vma expected_start
= 0;
6772 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6775 bytes
= section
->size
;
6779 printf (_("\nThe %s section is empty.\n"), section
->name
);
6785 unsigned char *hdrptr
= section_begin
;
6786 dwarf_vma ll_length
;
6787 unsigned short ll_version
;
6788 unsigned char *end
= section_begin
+ section
->size
;
6789 unsigned char address_size
, segment_selector_size
;
6790 uint32_t offset_entry_count
;
6792 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6793 if (ll_length
== 0xffffffff)
6794 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6796 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6797 if (ll_version
!= 5)
6799 warn (_("The %s section contains corrupt or "
6800 "unsupported version number: %d.\n"),
6801 section
->name
, ll_version
);
6805 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6807 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6808 if (segment_selector_size
!= 0)
6810 warn (_("The %s section contains "
6811 "unsupported segment selector size: %d.\n"),
6812 section
->name
, segment_selector_size
);
6816 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6817 if (offset_entry_count
!= 0)
6819 warn (_("The %s section contains "
6820 "unsupported offset entry count: %d.\n"),
6821 section
->name
, offset_entry_count
);
6825 expected_start
= hdrptr
- section_begin
;
6828 if (load_debug_info (file
) == 0)
6830 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6835 /* Check the order of location list in .debug_info section. If
6836 offsets of location lists are in the ascending order, we can
6837 use `debug_information' directly. */
6838 for (i
= 0; i
< num_debug_info_entries
; i
++)
6842 num
= debug_information
[i
].num_loc_offsets
;
6843 if (num
> num_loc_list
)
6846 /* Check if we can use `debug_information' directly. */
6847 if (locs_sorted
&& num
!= 0)
6849 if (!seen_first_offset
)
6851 /* This is the first location list. */
6852 last_offset
= debug_information
[i
].loc_offsets
[0];
6853 last_view
= debug_information
[i
].loc_views
[0];
6855 seen_first_offset
= 1;
6861 for (; j
< num
; j
++)
6864 debug_information
[i
].loc_offsets
[j
]
6865 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6866 && last_view
> debug_information
[i
].loc_views
[j
]))
6871 last_offset
= debug_information
[i
].loc_offsets
[j
];
6872 last_view
= debug_information
[i
].loc_views
[j
];
6877 if (!seen_first_offset
)
6878 error (_("No location lists in .debug_info section!\n"));
6880 if (debug_information
[first
].num_loc_offsets
> 0
6881 && debug_information
[first
].loc_offsets
[0] != expected_start
6882 && debug_information
[first
].loc_views
[0] != expected_start
)
6883 warn (_("Location lists in %s section start at 0x%s\n"),
6885 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6888 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6890 introduce (section
, FALSE
);
6892 if (reloc_at (section
, 0))
6893 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6895 printf (_(" Offset Begin End Expression\n"));
6897 seen_first_offset
= 0;
6898 for (i
= first
; i
< num_debug_info_entries
; i
++)
6900 dwarf_vma offset
, voffset
;
6901 dwarf_vma base_address
;
6907 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6909 loc_offsets
= debug_information
[i
].loc_offsets
;
6910 loc_views
= debug_information
[i
].loc_views
;
6911 qsort (array
, debug_information
[i
].num_loc_offsets
,
6912 sizeof (*array
), loc_offsets_compar
);
6915 int adjacent_view_loclists
= 1;
6916 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6918 j
= locs_sorted
? k
: array
[k
];
6920 && (debug_information
[i
].loc_offsets
[locs_sorted
6921 ? k
- 1 : array
[k
- 1]]
6922 == debug_information
[i
].loc_offsets
[j
])
6923 && (debug_information
[i
].loc_views
[locs_sorted
6924 ? k
- 1 : array
[k
- 1]]
6925 == debug_information
[i
].loc_views
[j
]))
6927 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6928 offset
= debug_information
[i
].loc_offsets
[j
];
6929 next
= section_begin
+ offset
;
6930 voffset
= debug_information
[i
].loc_views
[j
];
6932 vnext
= section_begin
+ voffset
;
6935 base_address
= debug_information
[i
].base_address
;
6937 if (vnext
&& vnext
< next
)
6940 display_view_pair_list (section
, &vstart
, i
, next
);
6945 if (!seen_first_offset
|| !adjacent_view_loclists
)
6946 seen_first_offset
= 1;
6950 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6951 (unsigned long) (start
- section_begin
),
6952 (unsigned long) offset
);
6953 else if (start
> next
)
6954 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6955 (unsigned long) (start
- section_begin
),
6956 (unsigned long) offset
);
6961 if (offset
>= bytes
)
6963 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6964 (unsigned long) offset
);
6968 if (vnext
&& voffset
>= bytes
)
6970 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6971 (unsigned long) voffset
);
6978 display_loc_list_dwo (section
, &start
, i
, offset
,
6979 &vstart
, has_frame_base
);
6981 display_loc_list (section
, &start
, i
, offset
, base_address
,
6982 &vstart
, has_frame_base
);
6987 warn (_("DWO is not yet supported.\n"));
6989 display_loclists_list (section
, &start
, i
, offset
, base_address
,
6990 &vstart
, has_frame_base
);
6993 /* FIXME: this arrangement is quite simplistic. Nothing
6994 requires locview lists to be adjacent to corresponding
6995 loclists, and a single loclist could be augmented by
6996 different locview lists, and vice-versa, unlikely as it
6997 is that it would make sense to do so. Hopefully we'll
6998 have view pair support built into loclists before we ever
6999 need to address all these possibilities. */
7000 if (adjacent_view_loclists
&& vnext
7001 && vnext
!= start
&& vstart
!= next
)
7003 adjacent_view_loclists
= 0;
7004 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
7007 if (vnext
&& vnext
== start
)
7008 display_view_pair_list (section
, &start
, i
, vstart
);
7012 if (start
< section
->start
+ section
->size
)
7013 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
7014 "There are %ld unused bytes at the end of section %s\n",
7015 (long) (section
->start
+ section
->size
- start
)),
7016 (long) (section
->start
+ section
->size
- start
), section
->name
);
7023 display_debug_str (struct dwarf_section
*section
,
7024 void *file ATTRIBUTE_UNUSED
)
7026 unsigned char *start
= section
->start
;
7027 unsigned long bytes
= section
->size
;
7028 dwarf_vma addr
= section
->address
;
7032 printf (_("\nThe %s section is empty.\n"), section
->name
);
7036 introduce (section
, FALSE
);
7044 lbytes
= (bytes
> 16 ? 16 : bytes
);
7046 printf (" 0x%8.8lx ", (unsigned long) addr
);
7048 for (j
= 0; j
< 16; j
++)
7051 printf ("%2.2x", start
[j
]);
7059 for (j
= 0; j
< lbytes
; j
++)
7062 if (k
>= ' ' && k
< 0x80)
7081 display_debug_info (struct dwarf_section
*section
, void *file
)
7083 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, FALSE
);
7087 display_debug_types (struct dwarf_section
*section
, void *file
)
7089 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
7093 display_trace_info (struct dwarf_section
*section
, void *file
)
7095 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
7099 display_debug_aranges (struct dwarf_section
*section
,
7100 void *file ATTRIBUTE_UNUSED
)
7102 unsigned char *start
= section
->start
;
7103 unsigned char *end
= start
+ section
->size
;
7105 introduce (section
, FALSE
);
7107 /* It does not matter if this load fails,
7108 we test for that later on. */
7109 load_debug_info (file
);
7113 unsigned char *hdrptr
;
7114 DWARF2_Internal_ARange arange
;
7115 unsigned char *addr_ranges
;
7118 unsigned long sec_off
;
7119 unsigned char address_size
;
7121 unsigned int offset_size
;
7122 unsigned int initial_length_size
;
7126 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
7127 if (arange
.ar_length
== 0xffffffff)
7129 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
7131 initial_length_size
= 12;
7136 initial_length_size
= 4;
7139 sec_off
= hdrptr
- section
->start
;
7140 if (sec_off
+ arange
.ar_length
< sec_off
7141 || sec_off
+ arange
.ar_length
> section
->size
)
7143 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
7145 sec_off
- initial_length_size
,
7146 dwarf_vmatoa ("x", arange
.ar_length
));
7150 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
7151 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
7153 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
7154 && num_debug_info_entries
> 0
7155 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
7156 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
7157 (unsigned long) arange
.ar_info_offset
, section
->name
);
7159 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
7160 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
7162 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
7164 /* PR 19872: A version number of 0 probably means that there is
7165 padding at the end of the .debug_aranges section. Gold puts
7166 it there when performing an incremental link, for example.
7167 So do not generate a warning in this case. */
7168 if (arange
.ar_version
)
7169 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
7173 printf (_(" Length: %ld\n"),
7174 (long) arange
.ar_length
);
7175 printf (_(" Version: %d\n"), arange
.ar_version
);
7176 printf (_(" Offset into .debug_info: 0x%lx\n"),
7177 (unsigned long) arange
.ar_info_offset
);
7178 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
7179 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
7181 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
7183 /* PR 17512: file: 001-108546-0.001:0.1. */
7184 if (address_size
== 0 || address_size
> 8)
7186 error (_("Invalid address size in %s section!\n"),
7191 /* The DWARF spec does not require that the address size be a power
7192 of two, but we do. This will have to change if we ever encounter
7193 an uneven architecture. */
7194 if ((address_size
& (address_size
- 1)) != 0)
7196 warn (_("Pointer size + Segment size is not a power of two.\n"));
7200 if (address_size
> 4)
7201 printf (_("\n Address Length\n"));
7203 printf (_("\n Address Length\n"));
7205 addr_ranges
= hdrptr
;
7207 /* Must pad to an alignment boundary that is twice the address size. */
7208 excess
= (hdrptr
- start
) % (2 * address_size
);
7210 addr_ranges
+= (2 * address_size
) - excess
;
7212 start
+= arange
.ar_length
+ initial_length_size
;
7214 while (addr_ranges
+ 2 * address_size
<= start
)
7216 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
7217 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
7220 print_dwarf_vma (address
, address_size
);
7221 print_dwarf_vma (length
, address_size
);
7231 /* Comparison function for qsort. */
7233 comp_addr_base (const void * v0
, const void * v1
)
7235 debug_info
*info0
= *(debug_info
**) v0
;
7236 debug_info
*info1
= *(debug_info
**) v1
;
7237 return info0
->addr_base
- info1
->addr_base
;
7240 /* Display the debug_addr section. */
7242 display_debug_addr (struct dwarf_section
*section
,
7245 debug_info
**debug_addr_info
;
7246 unsigned char *entry
;
7251 if (section
->size
== 0)
7253 printf (_("\nThe %s section is empty.\n"), section
->name
);
7257 if (load_debug_info (file
) == 0)
7259 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7264 introduce (section
, FALSE
);
7266 /* PR 17531: file: cf38d01b.
7267 We use xcalloc because a corrupt file may not have initialised all of the
7268 fields in the debug_info structure, which means that the sort below might
7269 try to move uninitialised data. */
7270 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
7271 sizeof (debug_info
*));
7274 for (i
= 0; i
< num_debug_info_entries
; i
++)
7275 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
7277 /* PR 17531: file: cf38d01b. */
7278 if (debug_information
[i
].addr_base
>= section
->size
)
7279 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
7280 (unsigned long) debug_information
[i
].addr_base
, i
);
7282 debug_addr_info
[count
++] = debug_information
+ i
;
7285 /* Add a sentinel to make iteration convenient. */
7286 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
7287 debug_addr_info
[count
]->addr_base
= section
->size
;
7288 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
7290 for (i
= 0; i
< count
; i
++)
7293 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
7295 printf (_(" For compilation unit at offset 0x%s:\n"),
7296 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
7298 printf (_("\tIndex\tAddress\n"));
7299 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
7300 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
7304 dwarf_vma base
= byte_get (entry
, address_size
);
7305 printf (_("\t%d:\t"), idx
);
7306 print_dwarf_vma (base
, address_size
);
7308 entry
+= address_size
;
7314 free (debug_addr_info
);
7318 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
7321 display_debug_str_offsets (struct dwarf_section
*section
,
7322 void *file ATTRIBUTE_UNUSED
)
7326 if (section
->size
== 0)
7328 printf (_("\nThe %s section is empty.\n"), section
->name
);
7332 unsigned char *start
= section
->start
;
7333 unsigned char *end
= start
+ section
->size
;
7334 unsigned char *curr
= start
;
7336 const char * suffix
= strrchr (section
->name
, '.');
7337 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
7340 load_debug_section_with_follow (str_dwo
, file
);
7342 load_debug_section_with_follow (str
, file
);
7344 introduce (section
, FALSE
);
7349 dwarf_vma entry_length
;
7351 SAFE_BYTE_GET_AND_INC (length
, curr
, 4, end
);
7352 /* FIXME: We assume that this means 64-bit DWARF is being used. */
7353 if (length
== 0xffffffff)
7355 SAFE_BYTE_GET (length
, curr
, 8, end
);
7363 /* This is probably an old style .debug_str_offset section which
7364 just contains offsets and no header (and the first offset is 0). */
7365 length
= section
->size
;
7366 curr
= section
->start
;
7368 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7369 printf (_(" Index Offset [String]\n"));
7374 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
7376 warn (_("Unexpected version number in str_offset header: %#x\n"), version
);
7379 SAFE_BYTE_GET_AND_INC (padding
, curr
, 2, end
);
7381 warn (_("Unexpected value in str_offset header's padding field: %#x\n"), padding
);
7383 printf (_(" Length: %#lx\n"), (unsigned long) length
);
7384 printf (_(" Version: %#lx\n"), (unsigned long) version
);
7385 printf (_(" Index Offset [String]\n"));
7388 for (idx
= 0; length
>= entry_length
&& curr
< end
; idx
++)
7391 const unsigned char * string
;
7393 SAFE_BYTE_GET_AND_INC (offset
, curr
, entry_length
, end
);
7395 string
= (const unsigned char *)
7396 fetch_indexed_string (idx
, NULL
, entry_length
, dwo
);
7398 string
= fetch_indirect_string (offset
);
7400 printf (" %8lu %8s %s\n", idx
, dwarf_vmatoa ("x", offset
),
7408 /* Each debug_information[x].range_lists[y] gets this representation for
7409 sorting purposes. */
7413 /* The debug_information[x].range_lists[y] value. */
7414 dwarf_vma ranges_offset
;
7416 /* Original debug_information to find parameters of the data. */
7417 debug_info
*debug_info_p
;
7420 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
7423 range_entry_compar (const void *ap
, const void *bp
)
7425 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
7426 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
7427 const dwarf_vma a
= a_re
->ranges_offset
;
7428 const dwarf_vma b
= b_re
->ranges_offset
;
7430 return (a
> b
) - (b
> a
);
7434 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
7435 unsigned int pointer_size
, unsigned long offset
,
7436 unsigned long base_address
)
7438 while (start
< finish
)
7443 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7444 if (start
>= finish
)
7446 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7448 printf (" %8.8lx ", offset
);
7450 if (begin
== 0 && end
== 0)
7452 printf (_("<End of list>\n"));
7456 /* Check base address specifiers. */
7457 if (is_max_address (begin
, pointer_size
)
7458 && !is_max_address (end
, pointer_size
))
7461 print_dwarf_vma (begin
, pointer_size
);
7462 print_dwarf_vma (end
, pointer_size
);
7463 printf ("(base address)\n");
7467 print_dwarf_vma (begin
+ base_address
, pointer_size
);
7468 print_dwarf_vma (end
+ base_address
, pointer_size
);
7471 fputs (_("(start == end)"), stdout
);
7472 else if (begin
> end
)
7473 fputs (_("(start > end)"), stdout
);
7480 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
7481 unsigned int pointer_size
, unsigned long offset
,
7482 unsigned long base_address
)
7484 unsigned char *next
= start
;
7488 unsigned long off
= offset
+ (start
- next
);
7489 enum dwarf_range_list_entry rlet
;
7490 /* Initialize it due to a false compiler warning. */
7491 dwarf_vma begin
= -1, length
, end
= -1;
7493 if (start
+ 1 > finish
)
7495 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
7500 printf (" %8.8lx ", off
);
7502 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
7506 case DW_RLE_end_of_list
:
7507 printf (_("<End of list>\n"));
7509 case DW_RLE_base_address
:
7510 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
7511 print_dwarf_vma (base_address
, pointer_size
);
7512 printf (_("(base address)\n"));
7514 case DW_RLE_start_length
:
7515 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7516 READ_ULEB (length
, start
, finish
);
7517 end
= begin
+ length
;
7519 case DW_RLE_offset_pair
:
7520 READ_ULEB (begin
, start
, finish
);
7521 READ_ULEB (end
, start
, finish
);
7523 case DW_RLE_start_end
:
7524 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
7525 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
7528 error (_("Invalid range list entry type %d\n"), rlet
);
7529 rlet
= DW_RLE_end_of_list
;
7532 if (rlet
== DW_RLE_end_of_list
)
7534 if (rlet
== DW_RLE_base_address
)
7537 /* Only a DW_RLE_offset_pair needs the base address added. */
7538 if (rlet
== DW_RLE_offset_pair
)
7540 begin
+= base_address
;
7541 end
+= base_address
;
7544 print_dwarf_vma (begin
, pointer_size
);
7545 print_dwarf_vma (end
, pointer_size
);
7548 fputs (_("(start == end)"), stdout
);
7549 else if (begin
> end
)
7550 fputs (_("(start > end)"), stdout
);
7557 display_debug_ranges (struct dwarf_section
*section
,
7558 void *file ATTRIBUTE_UNUSED
)
7560 unsigned char *start
= section
->start
;
7561 unsigned char *last_start
= start
;
7562 unsigned long bytes
= section
->size
;
7563 unsigned char *section_begin
= start
;
7564 unsigned char *finish
= start
+ bytes
;
7565 unsigned int num_range_list
, i
;
7566 struct range_entry
*range_entries
, *range_entry_fill
;
7567 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
7568 /* Initialize it due to a false compiler warning. */
7569 unsigned char address_size
= 0;
7570 dwarf_vma last_offset
= 0;
7574 printf (_("\nThe %s section is empty.\n"), section
->name
);
7580 dwarf_vma initial_length
;
7581 unsigned int initial_length_size
;
7582 unsigned char segment_selector_size
;
7583 unsigned int offset_size
, offset_entry_count
;
7584 unsigned short version
;
7586 /* Get and check the length of the block. */
7587 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
7589 if (initial_length
== 0xffffffff)
7591 /* This section is 64-bit DWARF 3. */
7592 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
7594 initial_length_size
= 12;
7599 initial_length_size
= 4;
7602 if (initial_length
+ initial_length_size
> section
->size
)
7604 /* If the length field has a relocation against it, then we should
7605 not complain if it is inaccurate (and probably negative).
7606 It is copied from .debug_line handling code. */
7607 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
7609 initial_length
= (finish
- start
) - initial_length_size
;
7613 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
7614 (long) initial_length
);
7619 /* Get and check the version number. */
7620 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
7624 warn (_("Only DWARF version 5 debug_rnglists info "
7625 "is currently supported.\n"));
7629 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
7631 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
7632 if (segment_selector_size
!= 0)
7634 warn (_("The %s section contains "
7635 "unsupported segment selector size: %d.\n"),
7636 section
->name
, segment_selector_size
);
7640 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
7641 if (offset_entry_count
!= 0)
7643 warn (_("The %s section contains "
7644 "unsupported offset entry count: %u.\n"),
7645 section
->name
, offset_entry_count
);
7650 if (load_debug_info (file
) == 0)
7652 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7658 for (i
= 0; i
< num_debug_info_entries
; i
++)
7659 num_range_list
+= debug_information
[i
].num_range_lists
;
7661 if (num_range_list
== 0)
7663 /* This can happen when the file was compiled with -gsplit-debug
7664 which removes references to range lists from the primary .o file. */
7665 printf (_("No range lists in .debug_info section.\n"));
7669 range_entries
= (struct range_entry
*)
7670 xmalloc (sizeof (*range_entries
) * num_range_list
);
7671 range_entry_fill
= range_entries
;
7673 for (i
= 0; i
< num_debug_info_entries
; i
++)
7675 debug_info
*debug_info_p
= &debug_information
[i
];
7678 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7680 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7681 range_entry_fill
->debug_info_p
= debug_info_p
;
7686 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7687 range_entry_compar
);
7689 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7690 warn (_("Range lists in %s section start at 0x%lx\n"),
7691 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7693 introduce (section
, FALSE
);
7695 printf (_(" Offset Begin End\n"));
7697 for (i
= 0; i
< num_range_list
; i
++)
7699 struct range_entry
*range_entry
= &range_entries
[i
];
7700 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7701 unsigned int pointer_size
;
7703 unsigned char *next
;
7704 dwarf_vma base_address
;
7706 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7707 offset
= range_entry
->ranges_offset
;
7708 next
= section_begin
+ offset
;
7709 base_address
= debug_info_p
->base_address
;
7711 /* PR 17512: file: 001-101485-0.001:0.1. */
7712 if (pointer_size
< 2 || pointer_size
> 8)
7714 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7715 pointer_size
, (unsigned long) offset
);
7719 if (next
< section_begin
|| next
>= finish
)
7721 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7722 (unsigned long) offset
, i
);
7726 /* If multiple DWARF entities reference the same range then we will
7727 have multiple entries in the `range_entries' list for the same
7728 offset. Thanks to the sort above these will all be consecutive in
7729 the `range_entries' list, so we can easily ignore duplicates
7731 if (i
> 0 && last_offset
== offset
)
7733 last_offset
= offset
;
7735 if (dwarf_check
!= 0 && i
> 0)
7738 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7739 (unsigned long) (start
- section_begin
),
7740 (unsigned long) (next
- section_begin
), section
->name
);
7741 else if (start
> next
)
7743 if (next
== last_start
)
7745 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7746 (unsigned long) (start
- section_begin
),
7747 (unsigned long) (next
- section_begin
), section
->name
);
7754 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7755 (start
, finish
, pointer_size
, offset
, base_address
);
7759 free (range_entries
);
7764 typedef struct Frame_Chunk
7766 struct Frame_Chunk
*next
;
7767 unsigned char *chunk_start
;
7769 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7770 short int *col_type
;
7773 unsigned int code_factor
;
7777 unsigned int cfa_reg
;
7778 dwarf_vma cfa_offset
;
7780 unsigned char fde_encoding
;
7781 unsigned char cfa_exp
;
7782 unsigned char ptr_size
;
7783 unsigned char segment_size
;
7787 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7788 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7789 static const char *const *dwarf_regnames
;
7790 static unsigned int dwarf_regnames_count
;
7793 /* A marker for a col_type that means this column was never referenced
7794 in the frame info. */
7795 #define DW_CFA_unreferenced (-1)
7797 /* Return 0 if no more space is needed, 1 if more space is needed,
7798 -1 for invalid reg. */
7801 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7803 unsigned int prev
= fc
->ncols
;
7805 if (reg
< (unsigned int) fc
->ncols
)
7808 if (dwarf_regnames_count
> 0
7809 && reg
> dwarf_regnames_count
)
7812 fc
->ncols
= reg
+ 1;
7813 /* PR 17512: file: 10450-2643-0.004.
7814 If reg == -1 then this can happen... */
7818 /* PR 17512: file: 2844a11d. */
7819 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7821 error (_("Unfeasibly large register number: %u\n"), reg
);
7823 /* FIXME: 1024 is an arbitrary limit. Increase it if
7824 we ever encounter a valid binary that exceeds it. */
7828 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7829 sizeof (short int));
7830 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7831 /* PR 17512: file:002-10025-0.005. */
7832 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7834 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7840 while (prev
< fc
->ncols
)
7842 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7843 fc
->col_offset
[prev
] = 0;
7849 static const char *const dwarf_regnames_i386
[] =
7851 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7852 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7853 "eip", "eflags", NULL
, /* 8 - 10 */
7854 "st0", "st1", "st2", "st3", /* 11 - 14 */
7855 "st4", "st5", "st6", "st7", /* 15 - 18 */
7856 NULL
, NULL
, /* 19 - 20 */
7857 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7858 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7859 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7860 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7861 "fcw", "fsw", "mxcsr", /* 37 - 39 */
7862 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7863 "tr", "ldtr", /* 48 - 49 */
7864 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7865 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7866 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7867 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7868 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7869 NULL
, NULL
, NULL
, /* 90 - 92 */
7870 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
7873 static const char *const dwarf_regnames_iamcu
[] =
7875 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7876 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7877 "eip", "eflags", NULL
, /* 8 - 10 */
7878 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
7879 NULL
, NULL
, /* 19 - 20 */
7880 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
7881 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
7882 NULL
, NULL
, NULL
, /* 37 - 39 */
7883 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7884 "tr", "ldtr", /* 48 - 49 */
7885 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7886 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7887 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7888 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7889 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7890 NULL
, NULL
, NULL
, /* 90 - 92 */
7891 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
7895 init_dwarf_regnames_i386 (void)
7897 dwarf_regnames
= dwarf_regnames_i386
;
7898 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
7899 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7903 init_dwarf_regnames_iamcu (void)
7905 dwarf_regnames
= dwarf_regnames_iamcu
;
7906 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
7907 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7910 static const char *const dwarf_regnames_x86_64
[] =
7912 "rax", "rdx", "rcx", "rbx",
7913 "rsi", "rdi", "rbp", "rsp",
7914 "r8", "r9", "r10", "r11",
7915 "r12", "r13", "r14", "r15",
7917 "xmm0", "xmm1", "xmm2", "xmm3",
7918 "xmm4", "xmm5", "xmm6", "xmm7",
7919 "xmm8", "xmm9", "xmm10", "xmm11",
7920 "xmm12", "xmm13", "xmm14", "xmm15",
7921 "st0", "st1", "st2", "st3",
7922 "st4", "st5", "st6", "st7",
7923 "mm0", "mm1", "mm2", "mm3",
7924 "mm4", "mm5", "mm6", "mm7",
7926 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
7927 "fs.base", "gs.base", NULL
, NULL
,
7929 "mxcsr", "fcw", "fsw",
7930 "xmm16", "xmm17", "xmm18", "xmm19",
7931 "xmm20", "xmm21", "xmm22", "xmm23",
7932 "xmm24", "xmm25", "xmm26", "xmm27",
7933 "xmm28", "xmm29", "xmm30", "xmm31",
7934 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
7935 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
7936 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
7937 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
7938 NULL
, NULL
, NULL
, /* 115 - 117 */
7939 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7943 init_dwarf_regnames_x86_64 (void)
7945 dwarf_regnames
= dwarf_regnames_x86_64
;
7946 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
7947 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7950 static const char *const dwarf_regnames_aarch64
[] =
7952 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7953 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7954 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7955 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7956 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7957 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
7958 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
7959 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
7960 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7961 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7962 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7963 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7964 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
7965 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
7966 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
7967 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
7971 init_dwarf_regnames_aarch64 (void)
7973 dwarf_regnames
= dwarf_regnames_aarch64
;
7974 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
7975 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7978 static const char *const dwarf_regnames_s390
[] =
7980 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7981 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7982 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7983 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7984 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7985 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7986 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7987 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7988 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7991 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7992 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7996 init_dwarf_regnames_s390 (void)
7998 dwarf_regnames
= dwarf_regnames_s390
;
7999 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
8000 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
8003 static const char *const dwarf_regnames_riscv
[] =
8005 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
8006 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
8007 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
8008 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
8009 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
8010 "fs0", "fs1", /* 40 - 41 */
8011 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
8012 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
8013 "fs10", "fs11", /* 58 - 59 */
8014 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
8017 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
8018 the large number of CSRs. */
8021 regname_internal_riscv (unsigned int regno
)
8023 const char *name
= NULL
;
8025 /* Lookup in the table first, this covers GPR and FPR. */
8026 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
8027 name
= dwarf_regnames_riscv
[regno
];
8028 else if (regno
>= 4096 && regno
<= 8191)
8030 /* This might be a CSR, these live in a sparse number space from 4096
8031 to 8191 These numbers are defined in the RISC-V ELF ABI
8035 #define DECLARE_CSR(NAME,VALUE,CLASS,DEFINE_VER,ABORT_VER) \
8036 case VALUE + 4096: name = #NAME; break;
8037 #include "opcode/riscv-opc.h"
8042 static char csr_name
[10];
8043 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
8054 init_dwarf_regnames_riscv (void)
8056 dwarf_regnames
= NULL
;
8057 dwarf_regnames_count
= 8192;
8058 dwarf_regnames_lookup_func
= regname_internal_riscv
;
8062 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
8064 dwarf_regnames_lookup_func
= NULL
;
8069 init_dwarf_regnames_i386 ();
8073 init_dwarf_regnames_iamcu ();
8079 init_dwarf_regnames_x86_64 ();
8083 init_dwarf_regnames_aarch64 ();
8087 init_dwarf_regnames_s390 ();
8091 init_dwarf_regnames_riscv ();
8099 /* Initialize the DWARF register name lookup state based on the
8100 architecture and specific machine type of a BFD. */
8103 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
8106 dwarf_regnames_lookup_func
= NULL
;
8113 case bfd_mach_x86_64
:
8114 case bfd_mach_x86_64_intel_syntax
:
8115 case bfd_mach_x64_32
:
8116 case bfd_mach_x64_32_intel_syntax
:
8117 init_dwarf_regnames_x86_64 ();
8121 init_dwarf_regnames_i386 ();
8126 case bfd_arch_iamcu
:
8127 init_dwarf_regnames_iamcu ();
8130 case bfd_arch_aarch64
:
8131 init_dwarf_regnames_aarch64();
8135 init_dwarf_regnames_s390 ();
8138 case bfd_arch_riscv
:
8139 init_dwarf_regnames_riscv ();
8148 regname_internal_by_table_only (unsigned int regno
)
8150 if (dwarf_regnames
!= NULL
8151 && regno
< dwarf_regnames_count
8152 && dwarf_regnames
[regno
] != NULL
)
8153 return dwarf_regnames
[regno
];
8159 regname (unsigned int regno
, int name_only_p
)
8161 static char reg
[64];
8163 const char *name
= NULL
;
8165 if (dwarf_regnames_lookup_func
!= NULL
)
8166 name
= dwarf_regnames_lookup_func (regno
);
8172 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
8175 snprintf (reg
, sizeof (reg
), "r%d", regno
);
8180 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
8185 if (*max_regs
!= fc
->ncols
)
8186 *max_regs
= fc
->ncols
;
8188 if (*need_col_headers
)
8190 static const char *sloc
= " LOC";
8192 *need_col_headers
= 0;
8194 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
8196 for (r
= 0; r
< *max_regs
; r
++)
8197 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8202 printf ("%-5s ", regname (r
, 1));
8208 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
8210 strcpy (tmp
, "exp");
8212 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
8213 printf ("%-8s ", tmp
);
8215 for (r
= 0; r
< fc
->ncols
; r
++)
8217 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
8219 switch (fc
->col_type
[r
])
8221 case DW_CFA_undefined
:
8224 case DW_CFA_same_value
:
8228 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
8230 case DW_CFA_val_offset
:
8231 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
8233 case DW_CFA_register
:
8234 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
8236 case DW_CFA_expression
:
8237 strcpy (tmp
, "exp");
8239 case DW_CFA_val_expression
:
8240 strcpy (tmp
, "vexp");
8243 strcpy (tmp
, "n/a");
8246 printf ("%-5s ", tmp
);
8252 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
8254 static unsigned char *
8255 read_cie (unsigned char *start
, unsigned char *end
,
8256 Frame_Chunk
**p_cie
, int *p_version
,
8257 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
8261 unsigned char *augmentation_data
= NULL
;
8262 bfd_size_type augmentation_data_len
= 0;
8265 /* PR 17512: file: 001-228113-0.004. */
8269 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8270 memset (fc
, 0, sizeof (Frame_Chunk
));
8272 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8273 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8277 fc
->augmentation
= (char *) start
;
8278 /* PR 17512: file: 001-228113-0.004.
8279 Skip past augmentation name, but avoid running off the end of the data. */
8281 if (* start
++ == '\0')
8285 warn (_("No terminator for augmentation name\n"));
8289 if (strcmp (fc
->augmentation
, "eh") == 0)
8290 start
+= eh_addr_size
;
8294 GET (fc
->ptr_size
, 1);
8295 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
8297 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
8301 GET (fc
->segment_size
, 1);
8302 /* PR 17512: file: e99d2804. */
8303 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
8305 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
8309 eh_addr_size
= fc
->ptr_size
;
8313 fc
->ptr_size
= eh_addr_size
;
8314 fc
->segment_size
= 0;
8317 READ_ULEB (fc
->code_factor
, start
, end
);
8318 READ_SLEB (fc
->data_factor
, start
, end
);
8326 READ_ULEB (fc
->ra
, start
, end
);
8329 if (fc
->augmentation
[0] == 'z')
8331 READ_ULEB (augmentation_data_len
, start
, end
);
8332 augmentation_data
= start
;
8333 /* PR 17512: file: 11042-2589-0.004. */
8334 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8336 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
8337 dwarf_vmatoa ("x", augmentation_data_len
),
8338 (unsigned long) (end
- start
));
8341 start
+= augmentation_data_len
;
8344 if (augmentation_data_len
)
8348 unsigned char *qend
;
8350 p
= (unsigned char *) fc
->augmentation
+ 1;
8351 q
= augmentation_data
;
8352 qend
= q
+ augmentation_data_len
;
8354 while (p
< end
&& q
< qend
)
8359 q
+= 1 + size_of_encoded_value (*q
);
8361 fc
->fde_encoding
= *q
++;
8370 /* Note - it is OK if this loop terminates with q < qend.
8371 Padding may have been inserted to align the end of the CIE. */
8376 *p_version
= version
;
8379 *p_aug_len
= augmentation_data_len
;
8380 *p_aug
= augmentation_data
;
8385 free (fc
->col_offset
);
8386 free (fc
->col_type
);
8391 /* Prints out the contents on the DATA array formatted as unsigned bytes.
8392 If do_wide is not enabled, then formats the output to fit into 80 columns.
8393 PRINTED contains the number of characters already written to the current
8397 display_data (bfd_size_type printed
,
8398 const unsigned char * data
,
8399 const bfd_size_type len
)
8401 if (do_wide
|| len
< ((80 - printed
) / 3))
8402 for (printed
= 0; printed
< len
; ++printed
)
8403 printf (" %02x", data
[printed
]);
8406 for (printed
= 0; printed
< len
; ++printed
)
8408 if (printed
% (80 / 3) == 0)
8410 printf (" %02x", data
[printed
]);
8415 /* Prints out the contents on the augmentation data array.
8416 If do_wide is not enabled, then formats the output to fit into 80 columns. */
8419 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
8423 i
= printf (_(" Augmentation data: "));
8424 display_data (i
, data
, len
);
8428 display_debug_frames (struct dwarf_section
*section
,
8429 void *file ATTRIBUTE_UNUSED
)
8431 unsigned char *start
= section
->start
;
8432 unsigned char *end
= start
+ section
->size
;
8433 unsigned char *section_start
= start
;
8434 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
8435 Frame_Chunk
*remembered_state
= NULL
;
8437 bfd_boolean is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
8438 unsigned int max_regs
= 0;
8439 const char *bad_reg
= _("bad register: ");
8440 unsigned int saved_eh_addr_size
= eh_addr_size
;
8442 introduce (section
, FALSE
);
8446 unsigned char *saved_start
;
8447 unsigned char *block_end
;
8452 int need_col_headers
= 1;
8453 unsigned char *augmentation_data
= NULL
;
8454 bfd_size_type augmentation_data_len
= 0;
8455 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
8456 unsigned int offset_size
;
8457 unsigned int initial_length_size
;
8458 bfd_boolean all_nops
;
8459 static Frame_Chunk fde_fc
;
8461 saved_start
= start
;
8463 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
8467 printf ("\n%08lx ZERO terminator\n\n",
8468 (unsigned long)(saved_start
- section_start
));
8469 /* Skip any zero terminators that directly follow.
8470 A corrupt section size could have loaded a whole
8471 slew of zero filled memory bytes. eg
8472 PR 17512: file: 070-19381-0.004. */
8473 while (start
< end
&& * start
== 0)
8478 if (length
== 0xffffffff)
8480 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
8482 initial_length_size
= 12;
8487 initial_length_size
= 4;
8490 block_end
= saved_start
+ length
+ initial_length_size
;
8491 if (block_end
> end
|| block_end
< start
)
8493 warn ("Invalid length 0x%s in FDE at %#08lx\n",
8494 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
8495 (unsigned long) (saved_start
- section_start
));
8499 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
8501 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
8502 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
8507 start
= read_cie (start
, end
, &cie
, &version
,
8508 &augmentation_data_len
, &augmentation_data
);
8509 /* PR 17512: file: 027-135133-0.005. */
8516 fc
->chunk_start
= saved_start
;
8517 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8520 if (frame_need_space (fc
, mreg
) < 0)
8522 if (fc
->fde_encoding
)
8523 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8525 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
8526 print_dwarf_vma (length
, fc
->ptr_size
);
8527 print_dwarf_vma (cie_id
, offset_size
);
8529 if (do_debug_frames_interp
)
8531 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
8532 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
8537 printf (" Version: %d\n", version
);
8538 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
8541 printf (" Pointer Size: %u\n", fc
->ptr_size
);
8542 printf (" Segment Size: %u\n", fc
->segment_size
);
8544 printf (" Code alignment factor: %u\n", fc
->code_factor
);
8545 printf (" Data alignment factor: %d\n", fc
->data_factor
);
8546 printf (" Return address column: %d\n", fc
->ra
);
8548 if (augmentation_data_len
)
8549 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8556 unsigned char *look_for
;
8557 unsigned long segment_selector
;
8561 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
8562 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
8565 look_for
= section_start
+ cie_id
;
8567 if (look_for
<= saved_start
)
8569 for (cie
= chunks
; cie
; cie
= cie
->next
)
8570 if (cie
->chunk_start
== look_for
)
8575 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
8576 if (cie
->chunk_start
== look_for
)
8580 unsigned int off_size
;
8581 unsigned char *cie_scan
;
8583 cie_scan
= look_for
;
8585 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
8586 if (length
== 0xffffffff)
8588 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
8595 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
8598 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
8599 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
8604 read_cie (cie_scan
, end
, &cie
, &version
,
8605 &augmentation_data_len
, &augmentation_data
);
8606 /* PR 17512: file: 3450-2098-0.004. */
8609 warn (_("Failed to read CIE information\n"));
8612 cie
->next
= forward_refs
;
8614 cie
->chunk_start
= look_for
;
8615 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
8618 if (frame_need_space (cie
, mreg
) < 0)
8620 warn (_("Invalid max register\n"));
8623 if (cie
->fde_encoding
)
8625 = size_of_encoded_value (cie
->fde_encoding
);
8632 memset (fc
, 0, sizeof (Frame_Chunk
));
8636 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
8637 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8638 (unsigned long) (saved_start
- section_start
));
8640 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
8641 fc
->col_offset
= (int *) xmalloc (sizeof (int));
8642 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
8644 warn (_("Invalid max register\n"));
8648 fc
->augmentation
= "";
8649 fc
->fde_encoding
= 0;
8650 fc
->ptr_size
= eh_addr_size
;
8651 fc
->segment_size
= 0;
8655 fc
->ncols
= cie
->ncols
;
8656 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8657 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8658 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8659 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8660 fc
->augmentation
= cie
->augmentation
;
8661 fc
->ptr_size
= cie
->ptr_size
;
8662 eh_addr_size
= cie
->ptr_size
;
8663 fc
->segment_size
= cie
->segment_size
;
8664 fc
->code_factor
= cie
->code_factor
;
8665 fc
->data_factor
= cie
->data_factor
;
8666 fc
->cfa_reg
= cie
->cfa_reg
;
8667 fc
->cfa_offset
= cie
->cfa_offset
;
8669 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8671 warn (_("Invalid max register\n"));
8674 fc
->fde_encoding
= cie
->fde_encoding
;
8677 if (fc
->fde_encoding
)
8678 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8680 segment_selector
= 0;
8681 if (fc
->segment_size
)
8683 if (fc
->segment_size
> sizeof (segment_selector
))
8685 /* PR 17512: file: 9e196b3e. */
8686 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8687 fc
->segment_size
= 4;
8689 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8692 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8694 /* FIXME: It appears that sometimes the final pc_range value is
8695 encoded in less than encoded_ptr_size bytes. See the x86_64
8696 run of the "objcopy on compressed debug sections" test for an
8698 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8700 if (cie
->augmentation
[0] == 'z')
8702 READ_ULEB (augmentation_data_len
, start
, end
);
8703 augmentation_data
= start
;
8704 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8705 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8707 warn (_("Augmentation data too long: 0x%s, "
8708 "expected at most %#lx\n"),
8709 dwarf_vmatoa ("x", augmentation_data_len
),
8710 (unsigned long) (end
- start
));
8712 augmentation_data
= NULL
;
8713 augmentation_data_len
= 0;
8715 start
+= augmentation_data_len
;
8718 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8719 (unsigned long)(saved_start
- section_start
),
8720 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8721 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8722 (unsigned long)(cie
->chunk_start
- section_start
));
8724 if (fc
->segment_size
)
8725 printf ("%04lx:", segment_selector
);
8728 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8729 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8731 if (! do_debug_frames_interp
&& augmentation_data_len
)
8733 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8738 /* At this point, fc is the current chunk, cie (if any) is set, and
8739 we're about to interpret instructions for the chunk. */
8740 /* ??? At present we need to do this always, since this sizes the
8741 fc->col_type and fc->col_offset arrays, which we write into always.
8742 We should probably split the interpreted and non-interpreted bits
8743 into two different routines, since there's so much that doesn't
8744 really overlap between them. */
8745 if (1 || do_debug_frames_interp
)
8747 /* Start by making a pass over the chunk, allocating storage
8748 and taking note of what registers are used. */
8749 unsigned char *tmp
= start
;
8751 while (start
< block_end
)
8753 unsigned int reg
, op
, opa
;
8755 unsigned char * new_start
;
8762 /* Warning: if you add any more cases to this switch, be
8763 sure to add them to the corresponding switch below. */
8766 case DW_CFA_advance_loc
:
8769 SKIP_ULEB (start
, end
);
8770 if (frame_need_space (fc
, opa
) >= 0)
8771 fc
->col_type
[opa
] = DW_CFA_undefined
;
8773 case DW_CFA_restore
:
8774 if (frame_need_space (fc
, opa
) >= 0)
8775 fc
->col_type
[opa
] = DW_CFA_undefined
;
8777 case DW_CFA_set_loc
:
8778 start
+= encoded_ptr_size
;
8780 case DW_CFA_advance_loc1
:
8783 case DW_CFA_advance_loc2
:
8786 case DW_CFA_advance_loc4
:
8789 case DW_CFA_offset_extended
:
8790 case DW_CFA_val_offset
:
8791 READ_ULEB (reg
, start
, end
);
8792 SKIP_ULEB (start
, end
);
8793 if (frame_need_space (fc
, reg
) >= 0)
8794 fc
->col_type
[reg
] = DW_CFA_undefined
;
8796 case DW_CFA_restore_extended
:
8797 READ_ULEB (reg
, start
, end
);
8798 if (frame_need_space (fc
, reg
) >= 0)
8799 fc
->col_type
[reg
] = DW_CFA_undefined
;
8801 case DW_CFA_undefined
:
8802 READ_ULEB (reg
, start
, end
);
8803 if (frame_need_space (fc
, reg
) >= 0)
8804 fc
->col_type
[reg
] = DW_CFA_undefined
;
8806 case DW_CFA_same_value
:
8807 READ_ULEB (reg
, start
, end
);
8808 if (frame_need_space (fc
, reg
) >= 0)
8809 fc
->col_type
[reg
] = DW_CFA_undefined
;
8811 case DW_CFA_register
:
8812 READ_ULEB (reg
, start
, end
);
8813 SKIP_ULEB (start
, end
);
8814 if (frame_need_space (fc
, reg
) >= 0)
8815 fc
->col_type
[reg
] = DW_CFA_undefined
;
8817 case DW_CFA_def_cfa
:
8818 SKIP_ULEB (start
, end
);
8819 SKIP_ULEB (start
, end
);
8821 case DW_CFA_def_cfa_register
:
8822 SKIP_ULEB (start
, end
);
8824 case DW_CFA_def_cfa_offset
:
8825 SKIP_ULEB (start
, end
);
8827 case DW_CFA_def_cfa_expression
:
8828 READ_ULEB (temp
, start
, end
);
8829 new_start
= start
+ temp
;
8830 if (new_start
< start
)
8832 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8838 case DW_CFA_expression
:
8839 case DW_CFA_val_expression
:
8840 READ_ULEB (reg
, start
, end
);
8841 READ_ULEB (temp
, start
, end
);
8842 new_start
= start
+ temp
;
8843 if (new_start
< start
)
8845 /* PR 17512: file:306-192417-0.005. */
8846 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8851 if (frame_need_space (fc
, reg
) >= 0)
8852 fc
->col_type
[reg
] = DW_CFA_undefined
;
8854 case DW_CFA_offset_extended_sf
:
8855 case DW_CFA_val_offset_sf
:
8856 READ_ULEB (reg
, start
, end
);
8857 SKIP_SLEB (start
, end
);
8858 if (frame_need_space (fc
, reg
) >= 0)
8859 fc
->col_type
[reg
] = DW_CFA_undefined
;
8861 case DW_CFA_def_cfa_sf
:
8862 SKIP_ULEB (start
, end
);
8863 SKIP_SLEB (start
, end
);
8865 case DW_CFA_def_cfa_offset_sf
:
8866 SKIP_SLEB (start
, end
);
8868 case DW_CFA_MIPS_advance_loc8
:
8871 case DW_CFA_GNU_args_size
:
8872 SKIP_ULEB (start
, end
);
8874 case DW_CFA_GNU_negative_offset_extended
:
8875 READ_ULEB (reg
, start
, end
);
8876 SKIP_ULEB (start
, end
);
8877 if (frame_need_space (fc
, reg
) >= 0)
8878 fc
->col_type
[reg
] = DW_CFA_undefined
;
8889 /* Now we know what registers are used, make a second pass over
8890 the chunk, this time actually printing out the info. */
8892 while (start
< block_end
)
8894 unsigned char * tmp
;
8896 unsigned long ul
, roffs
;
8897 /* Note: It is tempting to use an unsigned long for 'reg' but there
8898 are various functions, notably frame_space_needed() that assume that
8899 reg is an unsigned int. */
8904 const char *reg_prefix
= "";
8911 /* Make a note if something other than DW_CFA_nop happens. */
8912 if (op
!= DW_CFA_nop
)
8915 /* Warning: if you add any more cases to this switch, be
8916 sure to add them to the corresponding switch above. */
8919 case DW_CFA_advance_loc
:
8920 if (do_debug_frames_interp
)
8921 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8923 printf (" DW_CFA_advance_loc: %d to %s\n",
8924 opa
* fc
->code_factor
,
8925 dwarf_vmatoa_1 (NULL
,
8926 fc
->pc_begin
+ opa
* fc
->code_factor
,
8928 fc
->pc_begin
+= opa
* fc
->code_factor
;
8932 READ_ULEB (roffs
, start
, end
);
8933 if (opa
>= (unsigned int) fc
->ncols
)
8934 reg_prefix
= bad_reg
;
8935 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8936 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
8937 reg_prefix
, regname (opa
, 0),
8938 roffs
* fc
->data_factor
);
8939 if (*reg_prefix
== '\0')
8941 fc
->col_type
[opa
] = DW_CFA_offset
;
8942 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8946 case DW_CFA_restore
:
8947 if (opa
>= (unsigned int) fc
->ncols
)
8948 reg_prefix
= bad_reg
;
8949 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8950 printf (" DW_CFA_restore: %s%s\n",
8951 reg_prefix
, regname (opa
, 0));
8952 if (*reg_prefix
!= '\0')
8955 if (opa
>= (unsigned int) cie
->ncols
8956 || (do_debug_frames_interp
8957 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
8959 fc
->col_type
[opa
] = DW_CFA_undefined
;
8960 fc
->col_offset
[opa
] = 0;
8964 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8965 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8969 case DW_CFA_set_loc
:
8970 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
8971 if (do_debug_frames_interp
)
8972 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8974 printf (" DW_CFA_set_loc: %s\n",
8975 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
8979 case DW_CFA_advance_loc1
:
8980 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
8981 if (do_debug_frames_interp
)
8982 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8984 printf (" DW_CFA_advance_loc1: %ld to %s\n",
8985 (unsigned long) (ofs
* fc
->code_factor
),
8986 dwarf_vmatoa_1 (NULL
,
8987 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8989 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8992 case DW_CFA_advance_loc2
:
8993 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
8994 if (do_debug_frames_interp
)
8995 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8997 printf (" DW_CFA_advance_loc2: %ld to %s\n",
8998 (unsigned long) (ofs
* fc
->code_factor
),
8999 dwarf_vmatoa_1 (NULL
,
9000 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9002 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9005 case DW_CFA_advance_loc4
:
9006 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
9007 if (do_debug_frames_interp
)
9008 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9010 printf (" DW_CFA_advance_loc4: %ld to %s\n",
9011 (unsigned long) (ofs
* fc
->code_factor
),
9012 dwarf_vmatoa_1 (NULL
,
9013 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9015 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9018 case DW_CFA_offset_extended
:
9019 READ_ULEB (reg
, start
, end
);
9020 READ_ULEB (roffs
, start
, end
);
9021 if (reg
>= (unsigned int) fc
->ncols
)
9022 reg_prefix
= bad_reg
;
9023 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9024 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
9025 reg_prefix
, regname (reg
, 0),
9026 roffs
* fc
->data_factor
);
9027 if (*reg_prefix
== '\0')
9029 fc
->col_type
[reg
] = DW_CFA_offset
;
9030 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9034 case DW_CFA_val_offset
:
9035 READ_ULEB (reg
, start
, end
);
9036 READ_ULEB (roffs
, start
, end
);
9037 if (reg
>= (unsigned int) fc
->ncols
)
9038 reg_prefix
= bad_reg
;
9039 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9040 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
9041 reg_prefix
, regname (reg
, 0),
9042 roffs
* fc
->data_factor
);
9043 if (*reg_prefix
== '\0')
9045 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9046 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
9050 case DW_CFA_restore_extended
:
9051 READ_ULEB (reg
, start
, end
);
9052 if (reg
>= (unsigned int) fc
->ncols
)
9053 reg_prefix
= bad_reg
;
9054 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9055 printf (" DW_CFA_restore_extended: %s%s\n",
9056 reg_prefix
, regname (reg
, 0));
9057 if (*reg_prefix
!= '\0')
9060 if (reg
>= (unsigned int) cie
->ncols
)
9062 fc
->col_type
[reg
] = DW_CFA_undefined
;
9063 fc
->col_offset
[reg
] = 0;
9067 fc
->col_type
[reg
] = cie
->col_type
[reg
];
9068 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
9072 case DW_CFA_undefined
:
9073 READ_ULEB (reg
, start
, end
);
9074 if (reg
>= (unsigned int) fc
->ncols
)
9075 reg_prefix
= bad_reg
;
9076 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9077 printf (" DW_CFA_undefined: %s%s\n",
9078 reg_prefix
, regname (reg
, 0));
9079 if (*reg_prefix
== '\0')
9081 fc
->col_type
[reg
] = DW_CFA_undefined
;
9082 fc
->col_offset
[reg
] = 0;
9086 case DW_CFA_same_value
:
9087 READ_ULEB (reg
, start
, end
);
9088 if (reg
>= (unsigned int) fc
->ncols
)
9089 reg_prefix
= bad_reg
;
9090 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9091 printf (" DW_CFA_same_value: %s%s\n",
9092 reg_prefix
, regname (reg
, 0));
9093 if (*reg_prefix
== '\0')
9095 fc
->col_type
[reg
] = DW_CFA_same_value
;
9096 fc
->col_offset
[reg
] = 0;
9100 case DW_CFA_register
:
9101 READ_ULEB (reg
, start
, end
);
9102 READ_ULEB (roffs
, start
, end
);
9103 if (reg
>= (unsigned int) fc
->ncols
)
9104 reg_prefix
= bad_reg
;
9105 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9107 printf (" DW_CFA_register: %s%s in ",
9108 reg_prefix
, regname (reg
, 0));
9109 puts (regname (roffs
, 0));
9111 if (*reg_prefix
== '\0')
9113 fc
->col_type
[reg
] = DW_CFA_register
;
9114 fc
->col_offset
[reg
] = roffs
;
9118 case DW_CFA_remember_state
:
9119 if (! do_debug_frames_interp
)
9120 printf (" DW_CFA_remember_state\n");
9121 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
9122 rs
->cfa_offset
= fc
->cfa_offset
;
9123 rs
->cfa_reg
= fc
->cfa_reg
;
9125 rs
->cfa_exp
= fc
->cfa_exp
;
9126 rs
->ncols
= fc
->ncols
;
9127 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
9128 sizeof (* rs
->col_type
));
9129 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
9130 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
9131 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
9132 rs
->next
= remembered_state
;
9133 remembered_state
= rs
;
9136 case DW_CFA_restore_state
:
9137 if (! do_debug_frames_interp
)
9138 printf (" DW_CFA_restore_state\n");
9139 rs
= remembered_state
;
9142 remembered_state
= rs
->next
;
9143 fc
->cfa_offset
= rs
->cfa_offset
;
9144 fc
->cfa_reg
= rs
->cfa_reg
;
9146 fc
->cfa_exp
= rs
->cfa_exp
;
9147 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
9149 warn (_("Invalid column number in saved frame state\n"));
9153 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
9154 memcpy (fc
->col_offset
, rs
->col_offset
,
9155 rs
->ncols
* sizeof (* rs
->col_offset
));
9156 free (rs
->col_type
);
9157 free (rs
->col_offset
);
9160 else if (do_debug_frames_interp
)
9161 printf ("Mismatched DW_CFA_restore_state\n");
9164 case DW_CFA_def_cfa
:
9165 READ_ULEB (fc
->cfa_reg
, start
, end
);
9166 READ_ULEB (fc
->cfa_offset
, start
, end
);
9168 if (! do_debug_frames_interp
)
9169 printf (" DW_CFA_def_cfa: %s ofs %d\n",
9170 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9173 case DW_CFA_def_cfa_register
:
9174 READ_ULEB (fc
->cfa_reg
, start
, end
);
9176 if (! do_debug_frames_interp
)
9177 printf (" DW_CFA_def_cfa_register: %s\n",
9178 regname (fc
->cfa_reg
, 0));
9181 case DW_CFA_def_cfa_offset
:
9182 READ_ULEB (fc
->cfa_offset
, start
, end
);
9183 if (! do_debug_frames_interp
)
9184 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
9188 if (! do_debug_frames_interp
)
9189 printf (" DW_CFA_nop\n");
9192 case DW_CFA_def_cfa_expression
:
9193 READ_ULEB (ul
, start
, end
);
9194 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
9196 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
9199 if (! do_debug_frames_interp
)
9201 printf (" DW_CFA_def_cfa_expression (");
9202 decode_location_expression (start
, eh_addr_size
, 0, -1,
9210 case DW_CFA_expression
:
9211 READ_ULEB (reg
, start
, end
);
9212 READ_ULEB (ul
, start
, end
);
9213 if (reg
>= (unsigned int) fc
->ncols
)
9214 reg_prefix
= bad_reg
;
9215 /* PR 17512: file: 069-133014-0.006. */
9216 /* PR 17512: file: 98c02eb4. */
9218 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9220 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
9223 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9225 printf (" DW_CFA_expression: %s%s (",
9226 reg_prefix
, regname (reg
, 0));
9227 decode_location_expression (start
, eh_addr_size
, 0, -1,
9231 if (*reg_prefix
== '\0')
9232 fc
->col_type
[reg
] = DW_CFA_expression
;
9236 case DW_CFA_val_expression
:
9237 READ_ULEB (reg
, start
, end
);
9238 READ_ULEB (ul
, start
, end
);
9239 if (reg
>= (unsigned int) fc
->ncols
)
9240 reg_prefix
= bad_reg
;
9242 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
9244 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
9247 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9249 printf (" DW_CFA_val_expression: %s%s (",
9250 reg_prefix
, regname (reg
, 0));
9251 decode_location_expression (start
, eh_addr_size
, 0, -1,
9255 if (*reg_prefix
== '\0')
9256 fc
->col_type
[reg
] = DW_CFA_val_expression
;
9260 case DW_CFA_offset_extended_sf
:
9261 READ_ULEB (reg
, start
, end
);
9262 READ_SLEB (l
, start
, end
);
9263 if (frame_need_space (fc
, reg
) < 0)
9264 reg_prefix
= bad_reg
;
9265 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9266 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
9267 reg_prefix
, regname (reg
, 0),
9268 (long)(l
* fc
->data_factor
));
9269 if (*reg_prefix
== '\0')
9271 fc
->col_type
[reg
] = DW_CFA_offset
;
9272 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9276 case DW_CFA_val_offset_sf
:
9277 READ_ULEB (reg
, start
, end
);
9278 READ_SLEB (l
, start
, end
);
9279 if (frame_need_space (fc
, reg
) < 0)
9280 reg_prefix
= bad_reg
;
9281 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9282 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
9283 reg_prefix
, regname (reg
, 0),
9284 (long)(l
* fc
->data_factor
));
9285 if (*reg_prefix
== '\0')
9287 fc
->col_type
[reg
] = DW_CFA_val_offset
;
9288 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9292 case DW_CFA_def_cfa_sf
:
9293 READ_ULEB (fc
->cfa_reg
, start
, end
);
9294 READ_ULEB (fc
->cfa_offset
, start
, end
);
9295 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
9297 if (! do_debug_frames_interp
)
9298 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
9299 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
9302 case DW_CFA_def_cfa_offset_sf
:
9303 READ_ULEB (fc
->cfa_offset
, start
, end
);
9304 fc
->cfa_offset
*= fc
->data_factor
;
9305 if (! do_debug_frames_interp
)
9306 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
9309 case DW_CFA_MIPS_advance_loc8
:
9310 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
9311 if (do_debug_frames_interp
)
9312 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9314 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
9315 (unsigned long) (ofs
* fc
->code_factor
),
9316 dwarf_vmatoa_1 (NULL
,
9317 fc
->pc_begin
+ ofs
* fc
->code_factor
,
9319 fc
->pc_begin
+= ofs
* fc
->code_factor
;
9322 case DW_CFA_GNU_window_save
:
9323 if (! do_debug_frames_interp
)
9324 printf (" DW_CFA_GNU_window_save\n");
9327 case DW_CFA_GNU_args_size
:
9328 READ_ULEB (ul
, start
, end
);
9329 if (! do_debug_frames_interp
)
9330 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
9333 case DW_CFA_GNU_negative_offset_extended
:
9334 READ_ULEB (reg
, start
, end
);
9335 READ_SLEB (l
, start
, end
);
9337 if (frame_need_space (fc
, reg
) < 0)
9338 reg_prefix
= bad_reg
;
9339 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
9340 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
9341 reg_prefix
, regname (reg
, 0),
9342 (long)(l
* fc
->data_factor
));
9343 if (*reg_prefix
== '\0')
9345 fc
->col_type
[reg
] = DW_CFA_offset
;
9346 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
9351 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
9352 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
9354 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
9359 /* Interpret the CFA - as long as it is not completely full of NOPs. */
9360 if (do_debug_frames_interp
&& ! all_nops
)
9361 frame_display_row (fc
, &need_col_headers
, &max_regs
);
9363 if (fde_fc
.col_type
!= NULL
)
9365 free (fde_fc
.col_type
);
9366 fde_fc
.col_type
= NULL
;
9368 if (fde_fc
.col_offset
!= NULL
)
9370 free (fde_fc
.col_offset
);
9371 fde_fc
.col_offset
= NULL
;
9375 eh_addr_size
= saved_eh_addr_size
;
9380 while (remembered_state
!= NULL
)
9382 rs
= remembered_state
;
9383 remembered_state
= rs
->next
;
9384 free (rs
->col_type
);
9385 free (rs
->col_offset
);
9386 rs
->next
= NULL
; /* Paranoia. */
9390 while (chunks
!= NULL
)
9394 free (rs
->col_type
);
9395 free (rs
->col_offset
);
9396 rs
->next
= NULL
; /* Paranoia. */
9400 while (forward_refs
!= NULL
)
9403 forward_refs
= rs
->next
;
9404 free (rs
->col_type
);
9405 free (rs
->col_offset
);
9406 rs
->next
= NULL
; /* Paranoia. */
9416 display_debug_names (struct dwarf_section
*section
, void *file
)
9418 unsigned char *hdrptr
= section
->start
;
9419 dwarf_vma unit_length
;
9420 unsigned char *unit_start
;
9421 const unsigned char *const section_end
= section
->start
+ section
->size
;
9422 unsigned char *unit_end
;
9424 introduce (section
, FALSE
);
9426 load_debug_section_with_follow (str
, file
);
9428 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
9430 unsigned int offset_size
;
9431 uint16_t dwarf_version
, padding
;
9432 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
9433 uint32_t bucket_count
, name_count
, abbrev_table_size
;
9434 uint32_t augmentation_string_size
;
9436 unsigned long sec_off
;
9437 bfd_boolean augmentation_printable
;
9438 const char *augmentation_string
;
9440 unit_start
= hdrptr
;
9442 /* Get and check the length of the block. */
9443 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
9445 if (unit_length
== 0xffffffff)
9447 /* This section is 64-bit DWARF. */
9448 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
9453 unit_end
= hdrptr
+ unit_length
;
9455 sec_off
= hdrptr
- section
->start
;
9456 if (sec_off
+ unit_length
< sec_off
9457 || sec_off
+ unit_length
> section
->size
)
9459 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
9461 (unsigned long) (unit_start
- section
->start
),
9462 dwarf_vmatoa ("x", unit_length
));
9466 /* Get and check the version number. */
9467 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
9468 printf (_("Version %ld\n"), (long) dwarf_version
);
9470 /* Prior versions did not exist, and future versions may not be
9471 backwards compatible. */
9472 if (dwarf_version
!= 5)
9474 warn (_("Only DWARF version 5 .debug_names "
9475 "is currently supported.\n"));
9479 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
9481 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
9484 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
9485 if (comp_unit_count
== 0)
9486 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
9488 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
9489 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
9490 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
9491 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
9492 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
9494 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
9495 if (augmentation_string_size
% 4 != 0)
9497 warn (_("Augmentation string length %u must be rounded up "
9498 "to a multiple of 4 in .debug_names.\n"),
9499 augmentation_string_size
);
9500 augmentation_string_size
+= (-augmentation_string_size
) & 3;
9503 printf (_("Augmentation string:"));
9505 augmentation_printable
= TRUE
;
9506 augmentation_string
= (const char *) hdrptr
;
9508 for (i
= 0; i
< augmentation_string_size
; i
++)
9512 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
9513 printf (" %02x", uc
);
9515 if (uc
!= 0 && !ISPRINT (uc
))
9516 augmentation_printable
= FALSE
;
9519 if (augmentation_printable
)
9523 i
< augmentation_string_size
&& augmentation_string
[i
];
9525 putchar (augmentation_string
[i
]);
9530 printf (_("CU table:\n"));
9531 for (i
= 0; i
< comp_unit_count
; i
++)
9535 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
9536 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
9540 printf (_("TU table:\n"));
9541 for (i
= 0; i
< local_type_unit_count
; i
++)
9545 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
9546 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
9550 printf (_("Foreign TU table:\n"));
9551 for (i
= 0; i
< foreign_type_unit_count
; i
++)
9555 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
9556 printf (_("[%3u] "), i
);
9557 print_dwarf_vma (signature
, 8);
9562 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
9563 hdrptr
+= bucket_count
* sizeof (uint32_t);
9564 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
9565 hdrptr
+= name_count
* sizeof (uint32_t);
9566 unsigned char *const name_table_string_offsets
= hdrptr
;
9567 hdrptr
+= name_count
* offset_size
;
9568 unsigned char *const name_table_entry_offsets
= hdrptr
;
9569 hdrptr
+= name_count
* offset_size
;
9570 unsigned char *const abbrev_table
= hdrptr
;
9571 hdrptr
+= abbrev_table_size
;
9572 const unsigned char *const abbrev_table_end
= hdrptr
;
9573 unsigned char *const entry_pool
= hdrptr
;
9574 if (hdrptr
> unit_end
)
9576 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
9577 "for unit 0x%lx in the debug_names\n"),
9578 (long) (hdrptr
- section
->start
),
9579 (long) (unit_end
- section
->start
),
9580 (long) (unit_start
- section
->start
));
9584 size_t buckets_filled
= 0;
9586 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
9588 const uint32_t bucket
= hash_table_buckets
[bucketi
];
9593 printf (ngettext ("Used %zu of %lu bucket.\n",
9594 "Used %zu of %lu buckets.\n",
9596 buckets_filled
, (unsigned long) bucket_count
);
9598 uint32_t hash_prev
= 0;
9599 size_t hash_clash_count
= 0;
9600 size_t longest_clash
= 0;
9601 size_t this_length
= 0;
9603 for (hashi
= 0; hashi
< name_count
; hashi
++)
9605 const uint32_t hash_this
= hash_table_hashes
[hashi
];
9609 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
9613 longest_clash
= MAX (longest_clash
, this_length
);
9618 hash_prev
= hash_this
;
9620 printf (_("Out of %lu items there are %zu bucket clashes"
9621 " (longest of %zu entries).\n"),
9622 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
9623 assert (name_count
== buckets_filled
+ hash_clash_count
);
9625 struct abbrev_lookup_entry
9627 dwarf_vma abbrev_tag
;
9628 unsigned char *abbrev_lookup_ptr
;
9630 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
9631 size_t abbrev_lookup_used
= 0;
9632 size_t abbrev_lookup_allocated
= 0;
9634 unsigned char *abbrevptr
= abbrev_table
;
9637 dwarf_vma abbrev_tag
;
9639 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
9640 if (abbrev_tag
== 0)
9642 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
9644 abbrev_lookup_allocated
= MAX (0x100,
9645 abbrev_lookup_allocated
* 2);
9646 abbrev_lookup
= xrealloc (abbrev_lookup
,
9647 (abbrev_lookup_allocated
9648 * sizeof (*abbrev_lookup
)));
9650 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9651 struct abbrev_lookup_entry
*entry
;
9652 for (entry
= abbrev_lookup
;
9653 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9655 if (entry
->abbrev_tag
== abbrev_tag
)
9657 warn (_("Duplicate abbreviation tag %lu "
9658 "in unit 0x%lx in the debug_names\n"),
9659 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9662 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9663 entry
->abbrev_tag
= abbrev_tag
;
9664 entry
->abbrev_lookup_ptr
= abbrevptr
;
9666 /* Skip DWARF tag. */
9667 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9670 dwarf_vma xindex
, form
;
9672 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9673 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9674 if (xindex
== 0 && form
== 0)
9679 printf (_("\nSymbol table:\n"));
9681 for (namei
= 0; namei
< name_count
; ++namei
)
9683 uint64_t string_offset
, entry_offset
;
9685 SAFE_BYTE_GET (string_offset
,
9686 name_table_string_offsets
+ namei
* offset_size
,
9687 offset_size
, unit_end
);
9688 SAFE_BYTE_GET (entry_offset
,
9689 name_table_entry_offsets
+ namei
* offset_size
,
9690 offset_size
, unit_end
);
9692 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9693 fetch_indirect_string (string_offset
));
9695 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9697 /* We need to scan first whether there is a single or multiple
9698 entries. TAGNO is -2 for the first entry, it is -1 for the
9699 initial tag read of the second entry, then it becomes 0 for the
9700 first entry for real printing etc. */
9702 /* Initialize it due to a false compiler warning. */
9703 dwarf_vma second_abbrev_tag
= -1;
9706 dwarf_vma abbrev_tag
;
9707 dwarf_vma dwarf_tag
;
9708 const struct abbrev_lookup_entry
*entry
;
9710 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9713 second_abbrev_tag
= abbrev_tag
;
9715 entryptr
= entry_pool
+ entry_offset
;
9718 if (abbrev_tag
== 0)
9722 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9723 (unsigned long) abbrev_tag
);
9725 for (entry
= abbrev_lookup
;
9726 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9728 if (entry
->abbrev_tag
== abbrev_tag
)
9730 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9732 warn (_("Undefined abbreviation tag %lu "
9733 "in unit 0x%lx in the debug_names\n"),
9735 (long) (unit_start
- section
->start
));
9738 abbrevptr
= entry
->abbrev_lookup_ptr
;
9739 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9741 printf (" %s", get_TAG_name (dwarf_tag
));
9744 dwarf_vma xindex
, form
;
9746 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9747 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9748 if (xindex
== 0 && form
== 0)
9752 printf (" %s", get_IDX_name (xindex
));
9753 entryptr
= read_and_display_attr_value (0, form
, 0,
9754 unit_start
, entryptr
, unit_end
,
9756 dwarf_version
, NULL
,
9763 printf (_(" <no entries>"));
9767 free (abbrev_lookup
);
9774 display_debug_links (struct dwarf_section
* section
,
9775 void * file ATTRIBUTE_UNUSED
)
9777 const unsigned char * filename
;
9778 unsigned int filelen
;
9780 introduce (section
, FALSE
);
9782 /* The .gnu_debuglink section is formatted as:
9783 (c-string) Filename.
9784 (padding) If needed to reach a 4 byte boundary.
9785 (uint32_t) CRC32 value.
9787 The .gun_debugaltlink section is formatted as:
9788 (c-string) Filename.
9789 (binary) Build-ID. */
9791 filename
= section
->start
;
9792 filelen
= strnlen ((const char *) filename
, section
->size
);
9793 if (filelen
== section
->size
)
9795 warn (_("The debuglink filename is corrupt/missing\n"));
9799 printf (_(" Separate debug info file: %s\n"), filename
);
9801 if (const_strneq (section
->name
, ".gnu_debuglink"))
9804 unsigned int crc_offset
;
9806 crc_offset
= filelen
+ 1;
9807 crc_offset
= (crc_offset
+ 3) & ~3;
9808 if (crc_offset
+ 4 > section
->size
)
9810 warn (_("CRC offset missing/truncated\n"));
9814 crc32
= byte_get (filename
+ crc_offset
, 4);
9816 printf (_(" CRC value: %#x\n"), crc32
);
9818 if (crc_offset
+ 4 < section
->size
)
9820 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9821 (long)(section
->size
- (crc_offset
+ 4)));
9825 else /* const_strneq (section->name, ".gnu_debugaltlink") */
9827 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9828 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9829 bfd_size_type printed
;
9831 /* FIXME: Should we support smaller build-id notes ? */
9832 if (build_id_len
< 0x14)
9834 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9838 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9839 display_data (printed
, build_id
, build_id_len
);
9848 display_gdb_index (struct dwarf_section
*section
,
9849 void *file ATTRIBUTE_UNUSED
)
9851 unsigned char *start
= section
->start
;
9853 uint32_t cu_list_offset
, tu_list_offset
;
9854 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
9855 unsigned int cu_list_elements
, tu_list_elements
;
9856 unsigned int address_table_size
, symbol_table_slots
;
9857 unsigned char *cu_list
, *tu_list
;
9858 unsigned char *address_table
, *symbol_table
, *constant_pool
;
9861 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
9863 introduce (section
, FALSE
);
9865 if (section
->size
< 6 * sizeof (uint32_t))
9867 warn (_("Truncated header in the %s section.\n"), section
->name
);
9871 version
= byte_get_little_endian (start
, 4);
9872 printf (_("Version %ld\n"), (long) version
);
9874 /* Prior versions are obsolete, and future versions may not be
9875 backwards compatible. */
9876 if (version
< 3 || version
> 8)
9878 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
9882 warn (_("The address table data in version 3 may be wrong.\n"));
9884 warn (_("Version 4 does not support case insensitive lookups.\n"));
9886 warn (_("Version 5 does not include inlined functions.\n"));
9888 warn (_("Version 6 does not include symbol attributes.\n"));
9889 /* Version 7 indices generated by Gold have bad type unit references,
9890 PR binutils/15021. But we don't know if the index was generated by
9891 Gold or not, so to avoid worrying users with gdb-generated indices
9892 we say nothing for version 7 here. */
9894 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
9895 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
9896 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
9897 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
9898 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
9900 if (cu_list_offset
> section
->size
9901 || tu_list_offset
> section
->size
9902 || address_table_offset
> section
->size
9903 || symbol_table_offset
> section
->size
9904 || constant_pool_offset
> section
->size
)
9906 warn (_("Corrupt header in the %s section.\n"), section
->name
);
9910 /* PR 17531: file: 418d0a8a. */
9911 if (tu_list_offset
< cu_list_offset
)
9913 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
9914 tu_list_offset
, cu_list_offset
);
9918 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
9920 if (address_table_offset
< tu_list_offset
)
9922 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
9923 address_table_offset
, tu_list_offset
);
9927 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
9929 /* PR 17531: file: 18a47d3d. */
9930 if (symbol_table_offset
< address_table_offset
)
9932 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
9933 symbol_table_offset
, address_table_offset
);
9937 address_table_size
= symbol_table_offset
- address_table_offset
;
9939 if (constant_pool_offset
< symbol_table_offset
)
9941 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
9942 constant_pool_offset
, symbol_table_offset
);
9946 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
9948 cu_list
= start
+ cu_list_offset
;
9949 tu_list
= start
+ tu_list_offset
;
9950 address_table
= start
+ address_table_offset
;
9951 symbol_table
= start
+ symbol_table_offset
;
9952 constant_pool
= start
+ constant_pool_offset
;
9954 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
9956 warn (_("Address table extends beyond end of section.\n"));
9960 printf (_("\nCU table:\n"));
9961 for (i
= 0; i
< cu_list_elements
; i
+= 2)
9963 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
9964 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
9966 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
9967 (unsigned long) cu_offset
,
9968 (unsigned long) (cu_offset
+ cu_length
- 1));
9971 printf (_("\nTU table:\n"));
9972 for (i
= 0; i
< tu_list_elements
; i
+= 3)
9974 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
9975 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
9976 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
9978 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
9979 (unsigned long) tu_offset
,
9980 (unsigned long) type_offset
);
9981 print_dwarf_vma (signature
, 8);
9985 printf (_("\nAddress table:\n"));
9986 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
9989 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
9990 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
9991 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
9993 print_dwarf_vma (low
, 8);
9994 print_dwarf_vma (high
, 8);
9995 printf (_("%lu\n"), (unsigned long) cu_index
);
9998 printf (_("\nSymbol table:\n"));
9999 for (i
= 0; i
< symbol_table_slots
; ++i
)
10001 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
10002 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
10003 uint32_t num_cus
, cu
;
10005 if (name_offset
!= 0
10006 || cu_vector_offset
!= 0)
10009 unsigned char * adr
;
10011 adr
= constant_pool
+ name_offset
;
10012 /* PR 17531: file: 5b7b07ad. */
10013 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
10015 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
10016 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
10020 printf ("[%3u] %.*s:", i
,
10021 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
10022 constant_pool
+ name_offset
);
10024 adr
= constant_pool
+ cu_vector_offset
;
10025 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
10027 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
10028 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
10029 cu_vector_offset
, i
);
10033 num_cus
= byte_get_little_endian (adr
, 4);
10035 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
10036 if (num_cus
* 4 < num_cus
10037 || adr
>= section
->start
+ section
->size
10038 || adr
< constant_pool
)
10040 printf ("<invalid number of CUs: %d>\n", num_cus
);
10041 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
10049 for (j
= 0; j
< num_cus
; ++j
)
10052 gdb_index_symbol_kind kind
;
10054 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
10055 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
10056 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
10057 cu
= GDB_INDEX_CU_VALUE (cu
);
10058 /* Convert to TU number if it's for a type unit. */
10059 if (cu
>= cu_list_elements
/ 2)
10060 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
10061 (unsigned long) (cu
- cu_list_elements
/ 2));
10063 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
10065 printf (" [%s, %s]",
10066 is_static
? _("static") : _("global"),
10067 get_gdb_index_symbol_kind_name (kind
));
10079 /* Pre-allocate enough space for the CU/TU sets needed. */
10082 prealloc_cu_tu_list (unsigned int nshndx
)
10084 if (shndx_pool
== NULL
)
10086 shndx_pool_size
= nshndx
;
10087 shndx_pool_used
= 0;
10088 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
10089 sizeof (unsigned int));
10093 shndx_pool_size
= shndx_pool_used
+ nshndx
;
10094 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
10095 sizeof (unsigned int));
10100 add_shndx_to_cu_tu_entry (unsigned int shndx
)
10102 if (shndx_pool_used
>= shndx_pool_size
)
10104 error (_("Internal error: out of space in the shndx pool.\n"));
10107 shndx_pool
[shndx_pool_used
++] = shndx
;
10111 end_cu_tu_entry (void)
10113 if (shndx_pool_used
>= shndx_pool_size
)
10115 error (_("Internal error: out of space in the shndx pool.\n"));
10118 shndx_pool
[shndx_pool_used
++] = 0;
10121 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
10123 static const char *
10124 get_DW_SECT_short_name (unsigned int dw_sect
)
10126 static char buf
[16];
10132 case DW_SECT_TYPES
:
10134 case DW_SECT_ABBREV
:
10140 case DW_SECT_STR_OFFSETS
:
10142 case DW_SECT_MACINFO
:
10144 case DW_SECT_MACRO
:
10150 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
10154 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
10155 These sections are extensions for Fission.
10156 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
10159 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
10161 unsigned char *phdr
= section
->start
;
10162 unsigned char *limit
= phdr
+ section
->size
;
10163 unsigned char *phash
;
10164 unsigned char *pindex
;
10165 unsigned char *ppool
;
10166 unsigned int version
;
10167 unsigned int ncols
= 0;
10168 unsigned int nused
;
10169 unsigned int nslots
;
10172 dwarf_vma signature_high
;
10173 dwarf_vma signature_low
;
10176 /* PR 17512: file: 002-168123-0.004. */
10179 warn (_("Section %s is empty\n"), section
->name
);
10182 /* PR 17512: file: 002-376-0.004. */
10183 if (section
->size
< 24)
10185 warn (_("Section %s is too small to contain a CU/TU header\n"),
10190 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
10192 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
10193 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
10194 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
10197 pindex
= phash
+ (size_t) nslots
* 8;
10198 ppool
= pindex
+ (size_t) nslots
* 4;
10202 introduce (section
, FALSE
);
10204 printf (_(" Version: %u\n"), version
);
10206 printf (_(" Number of columns: %u\n"), ncols
);
10207 printf (_(" Number of used entries: %u\n"), nused
);
10208 printf (_(" Number of slots: %u\n\n"), nslots
);
10211 /* PR 17531: file: 45d69832. */
10212 if ((size_t) nslots
* 8 / 8 != nslots
10213 || phash
< phdr
|| phash
> limit
10214 || pindex
< phash
|| pindex
> limit
10215 || ppool
< pindex
|| ppool
> limit
)
10217 warn (ngettext ("Section %s is too small for %u slot\n",
10218 "Section %s is too small for %u slots\n",
10220 section
->name
, nslots
);
10227 prealloc_cu_tu_list ((limit
- ppool
) / 4);
10228 for (i
= 0; i
< nslots
; i
++)
10230 unsigned char *shndx_list
;
10231 unsigned int shndx
;
10233 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
10234 if (signature_high
!= 0 || signature_low
!= 0)
10236 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
10237 shndx_list
= ppool
+ j
* 4;
10238 /* PR 17531: file: 705e010d. */
10239 if (shndx_list
< ppool
)
10241 warn (_("Section index pool located before start of section\n"));
10246 printf (_(" [%3d] Signature: 0x%s Sections: "),
10247 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10248 buf
, sizeof (buf
)));
10251 if (shndx_list
>= limit
)
10253 warn (_("Section %s too small for shndx pool\n"),
10257 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
10261 printf (" %d", shndx
);
10263 add_shndx_to_cu_tu_entry (shndx
);
10269 end_cu_tu_entry ();
10275 else if (version
== 2)
10278 unsigned int dw_sect
;
10279 unsigned char *ph
= phash
;
10280 unsigned char *pi
= pindex
;
10281 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
10282 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
10283 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
10284 bfd_boolean is_tu_index
;
10285 struct cu_tu_set
*this_set
= NULL
;
10287 unsigned char *prow
;
10289 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
10291 /* PR 17531: file: 0dd159bf.
10292 Check for integer overflow (can occur when size_t is 32-bit)
10293 with overlarge ncols or nused values. */
10295 && ((size_t) ncols
* 4 / 4 != ncols
10296 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
10297 || poffsets
< ppool
|| poffsets
> limit
10298 || psizes
< poffsets
|| psizes
> limit
10299 || pend
< psizes
|| pend
> limit
))
10301 warn (_("Section %s too small for offset and size tables\n"),
10308 printf (_(" Offset table\n"));
10309 printf (" slot %-16s ",
10310 is_tu_index
? _("signature") : _("dwo_id"));
10317 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10318 this_set
= tu_sets
;
10323 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
10324 this_set
= cu_sets
;
10330 for (j
= 0; j
< ncols
; j
++)
10332 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10333 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
10338 for (i
= 0; i
< nslots
; i
++)
10340 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10342 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10345 /* PR 17531: file: a05f6ab3. */
10348 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
10355 size_t num_copy
= sizeof (uint64_t);
10357 /* PR 23064: Beware of buffer overflow. */
10358 if (ph
+ num_copy
< limit
)
10359 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
10362 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
10367 prow
= poffsets
+ (row
- 1) * ncols
* 4;
10368 /* PR 17531: file: b8ce60a8. */
10369 if (prow
< poffsets
|| prow
> limit
)
10371 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
10377 printf (_(" [%3d] 0x%s"),
10378 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10379 buf
, sizeof (buf
)));
10380 for (j
= 0; j
< ncols
; j
++)
10382 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10384 printf (" %8d", val
);
10387 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10389 /* PR 17531: file: 10796eb3. */
10390 if (dw_sect
>= DW_SECT_MAX
)
10391 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10393 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
10409 printf (_(" Size table\n"));
10410 printf (" slot %-16s ",
10411 is_tu_index
? _("signature") : _("dwo_id"));
10414 for (j
= 0; j
< ncols
; j
++)
10416 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
10418 printf (" %8s", get_DW_SECT_short_name (val
));
10424 for (i
= 0; i
< nslots
; i
++)
10426 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
10428 SAFE_BYTE_GET (row
, pi
, 4, limit
);
10431 prow
= psizes
+ (row
- 1) * ncols
* 4;
10434 printf (_(" [%3d] 0x%s"),
10435 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
10436 buf
, sizeof (buf
)));
10438 for (j
= 0; j
< ncols
; j
++)
10440 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
10442 printf (" %8d", val
);
10445 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
10446 if (dw_sect
>= DW_SECT_MAX
)
10447 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
10449 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
10461 else if (do_display
)
10462 printf (_(" Unsupported version (%d)\n"), version
);
10470 /* Load the CU and TU indexes if present. This will build a list of
10471 section sets that we can use to associate a .debug_info.dwo section
10472 with its associated .debug_abbrev.dwo section in a .dwp file. */
10475 load_cu_tu_indexes (void *file
)
10477 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
10479 /* If we have already loaded (or tried to load) the CU and TU indexes
10480 then do not bother to repeat the task. */
10481 if (cu_tu_indexes_read
== -1)
10483 cu_tu_indexes_read
= TRUE
;
10485 if (load_debug_section_with_follow (dwp_cu_index
, file
))
10486 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
10487 cu_tu_indexes_read
= FALSE
;
10489 if (load_debug_section_with_follow (dwp_tu_index
, file
))
10490 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
10491 cu_tu_indexes_read
= FALSE
;
10494 return (bfd_boolean
) cu_tu_indexes_read
;
10497 /* Find the set of sections that includes section SHNDX. */
10500 find_cu_tu_set (void *file
, unsigned int shndx
)
10504 if (! load_cu_tu_indexes (file
))
10507 /* Find SHNDX in the shndx pool. */
10508 for (i
= 0; i
< shndx_pool_used
; i
++)
10509 if (shndx_pool
[i
] == shndx
)
10512 if (i
>= shndx_pool_used
)
10515 /* Now backup to find the first entry in the set. */
10516 while (i
> 0 && shndx_pool
[i
- 1] != 0)
10519 return shndx_pool
+ i
;
10522 /* Display a .debug_cu_index or .debug_tu_index section. */
10525 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
10527 return process_cu_tu_index (section
, 1);
10531 display_debug_not_supported (struct dwarf_section
*section
,
10532 void *file ATTRIBUTE_UNUSED
)
10534 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
10540 /* Like malloc, but takes two parameters like calloc.
10541 Verifies that the first parameter is not too large.
10542 Note: does *not* initialise the allocated memory to zero. */
10545 cmalloc (size_t nmemb
, size_t size
)
10547 /* Check for overflow. */
10548 if (nmemb
>= ~(size_t) 0 / size
)
10551 return xmalloc (nmemb
* size
);
10554 /* Like xmalloc, but takes two parameters like calloc.
10555 Verifies that the first parameter is not too large.
10556 Note: does *not* initialise the allocated memory to zero. */
10559 xcmalloc (size_t nmemb
, size_t size
)
10561 /* Check for overflow. */
10562 if (nmemb
>= ~(size_t) 0 / size
)
10565 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
10570 return xmalloc (nmemb
* size
);
10573 /* Like xrealloc, but takes three parameters.
10574 Verifies that the second parameter is not too large.
10575 Note: does *not* initialise any new memory to zero. */
10578 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
10580 /* Check for overflow. */
10581 if (nmemb
>= ~(size_t) 0 / size
)
10583 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
10588 return xrealloc (ptr
, nmemb
* size
);
10591 /* Like xcalloc, but verifies that the first parameter is not too large. */
10594 xcalloc2 (size_t nmemb
, size_t size
)
10596 /* Check for overflow. */
10597 if (nmemb
>= ~(size_t) 0 / size
)
10599 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
10604 return xcalloc (nmemb
, size
);
10607 static unsigned long
10608 calc_gnu_debuglink_crc32 (unsigned long crc
,
10609 const unsigned char * buf
,
10612 static const unsigned long crc32_table
[256] =
10614 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
10615 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
10616 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
10617 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
10618 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
10619 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
10620 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
10621 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
10622 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
10623 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
10624 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
10625 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
10626 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
10627 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
10628 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
10629 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
10630 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
10631 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
10632 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
10633 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
10634 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
10635 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
10636 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
10637 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
10638 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
10639 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
10640 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
10641 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
10642 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
10643 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
10644 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
10645 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
10646 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
10647 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
10648 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
10649 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10650 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10651 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10652 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10653 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10654 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10655 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10656 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10657 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10658 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10659 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10660 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10661 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10662 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10663 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10664 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10667 const unsigned char *end
;
10669 crc
= ~crc
& 0xffffffff;
10670 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10671 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10672 return ~crc
& 0xffffffff;
10675 typedef bfd_boolean (* check_func_type
) (const char *, void *);
10676 typedef const char * (* parse_func_type
) (struct dwarf_section
*, void *);
10679 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10681 static unsigned char buffer
[8 * 1024];
10683 bfd_size_type count
;
10684 unsigned long crc
= 0;
10687 sep_data
= open_debug_file (pathname
);
10688 if (sep_data
== NULL
)
10691 /* Yes - we are opening the file twice... */
10692 f
= fopen (pathname
, "rb");
10695 /* Paranoia: This should never happen. */
10696 close_debug_file (sep_data
);
10697 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10701 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10702 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10706 if (crc
!= * (unsigned long *) crc_pointer
)
10708 close_debug_file (sep_data
);
10709 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10717 static const char *
10718 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10721 unsigned int crc_offset
;
10722 unsigned long * crc32
= (unsigned long *) data
;
10724 /* The name is first.
10725 The CRC value is stored after the filename, aligned up to 4 bytes. */
10726 name
= (const char *) section
->start
;
10728 crc_offset
= strnlen (name
, section
->size
) + 1;
10729 crc_offset
= (crc_offset
+ 3) & ~3;
10730 if (crc_offset
+ 4 > section
->size
)
10733 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10738 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10740 void * sep_data
= open_debug_file (filename
);
10742 if (sep_data
== NULL
)
10745 /* FIXME: We should now extract the build-id in the separate file
10751 typedef struct build_id_data
10754 const unsigned char * data
;
10757 static const char *
10758 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10761 bfd_size_type namelen
;
10762 bfd_size_type id_len
;
10763 Build_id_data
* build_id_data
;
10765 /* The name is first.
10766 The build-id follows immediately, with no padding, up to the section's end. */
10768 name
= (const char *) section
->start
;
10769 namelen
= strnlen (name
, section
->size
) + 1;
10770 if (namelen
>= section
->size
)
10773 id_len
= section
->size
- namelen
;
10777 build_id_data
= (Build_id_data
*) data
;
10778 build_id_data
->len
= id_len
;
10779 build_id_data
->data
= section
->start
+ namelen
;
10785 add_separate_debug_file (const char * filename
, void * handle
)
10787 separate_info
* i
= xmalloc (sizeof * i
);
10789 i
->filename
= filename
;
10790 i
->handle
= handle
;
10791 i
->next
= first_separate_info
;
10792 first_separate_info
= i
;
10795 #if HAVE_LIBDEBUGINFOD
10796 /* Query debuginfod servers for the target debuglink or debugaltlink
10797 file. If successful, store the path of the file in filename and
10798 return TRUE, otherwise return FALSE. */
10801 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10805 size_t build_id_len
;
10806 unsigned char * build_id
;
10808 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10810 /* Get the build-id of file. */
10811 build_id
= get_build_id (file
);
10814 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10816 /* Get the build-id of the debugaltlink file. */
10817 unsigned int filelen
;
10819 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10820 if (filelen
== section
->size
)
10821 /* Corrupt debugaltlink. */
10824 build_id
= section
->start
+ filelen
+ 1;
10825 build_id_len
= section
->size
- (filelen
+ 1);
10827 if (build_id_len
== 0)
10836 debuginfod_client
* client
;
10838 client
= debuginfod_begin ();
10839 if (client
== NULL
)
10842 /* Query debuginfod servers for the target file. If found its path
10843 will be stored in filename. */
10844 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
10845 debuginfod_end (client
);
10847 /* Only free build_id if we allocated space for a hex string
10848 in get_build_id (). */
10849 if (build_id_len
== 0)
10854 /* File successfully retrieved. Close fd since we want to
10855 use open_debug_file () on filename instead. */
10866 load_separate_debug_info (const char * main_filename
,
10867 struct dwarf_section
* xlink
,
10868 parse_func_type parse_func
,
10869 check_func_type check_func
,
10871 void * file ATTRIBUTE_UNUSED
)
10873 const char * separate_filename
;
10874 char * debug_filename
;
10876 size_t canon_dirlen
;
10879 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
10881 warn (_("Corrupt debuglink section: %s\n"),
10882 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
10886 /* Attempt to locate the separate file.
10887 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
10889 canon_dir
= lrealpath (main_filename
);
10891 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
10892 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
10894 canon_dir
[canon_dirlen
] = '\0';
10897 #define DEBUGDIR "/lib/debug"
10899 #ifndef EXTRA_DEBUG_ROOT1
10900 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
10902 #ifndef EXTRA_DEBUG_ROOT2
10903 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
10906 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
10908 + strlen (".debug/")
10909 #ifdef EXTRA_DEBUG_ROOT1
10910 + strlen (EXTRA_DEBUG_ROOT1
)
10912 #ifdef EXTRA_DEBUG_ROOT2
10913 + strlen (EXTRA_DEBUG_ROOT2
)
10915 + strlen (separate_filename
)
10917 if (debug_filename
== NULL
)
10919 warn (_("Out of memory"));
10924 /* First try in the current directory. */
10925 sprintf (debug_filename
, "%s", separate_filename
);
10926 if (check_func (debug_filename
, func_data
))
10929 /* Then try in a subdirectory called .debug. */
10930 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10931 if (check_func (debug_filename
, func_data
))
10934 /* Then try in the same directory as the original file. */
10935 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10936 if (check_func (debug_filename
, func_data
))
10939 /* And the .debug subdirectory of that directory. */
10940 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10941 if (check_func (debug_filename
, func_data
))
10944 #ifdef EXTRA_DEBUG_ROOT1
10945 /* Try the first extra debug file root. */
10946 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10947 if (check_func (debug_filename
, func_data
))
10950 /* Try the first extra debug file root. */
10951 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10952 if (check_func (debug_filename
, func_data
))
10956 #ifdef EXTRA_DEBUG_ROOT2
10957 /* Try the second extra debug file root. */
10958 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10959 if (check_func (debug_filename
, func_data
))
10963 /* Then try in the global debug_filename directory. */
10964 strcpy (debug_filename
, DEBUGDIR
);
10965 dirlen
= strlen (DEBUGDIR
) - 1;
10966 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
10967 strcat (debug_filename
, "/");
10968 strcat (debug_filename
, (const char *) separate_filename
);
10970 if (check_func (debug_filename
, func_data
))
10973 #if HAVE_LIBDEBUGINFOD
10975 char * tmp_filename
;
10977 if (debuginfod_fetch_separate_debug_info (xlink
,
10981 /* File successfully downloaded from server, replace
10982 debug_filename with the file's path. */
10983 free (debug_filename
);
10984 debug_filename
= tmp_filename
;
10990 /* Failed to find the file. */
10991 warn (_("could not find separate debug file '%s'\n"), separate_filename
);
10992 warn (_("tried: %s\n"), debug_filename
);
10994 #ifdef EXTRA_DEBUG_ROOT2
10995 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10996 warn (_("tried: %s\n"), debug_filename
);
10999 #ifdef EXTRA_DEBUG_ROOT1
11000 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
11001 warn (_("tried: %s\n"), debug_filename
);
11003 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
11004 warn (_("tried: %s\n"), debug_filename
);
11007 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
11008 warn (_("tried: %s\n"), debug_filename
);
11010 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
11011 warn (_("tried: %s\n"), debug_filename
);
11013 sprintf (debug_filename
, ".debug/%s", separate_filename
);
11014 warn (_("tried: %s\n"), debug_filename
);
11016 sprintf (debug_filename
, "%s", separate_filename
);
11017 warn (_("tried: %s\n"), debug_filename
);
11019 #if HAVE_LIBDEBUGINFOD
11021 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
11025 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
11030 free (debug_filename
);
11036 void * debug_handle
;
11038 /* Now open the file.... */
11039 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
11041 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
11042 free (debug_filename
);
11046 /* FIXME: We do not check to see if there are any other separate debug info
11047 files that would also match. */
11049 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename
, debug_filename
);
11050 add_separate_debug_file (debug_filename
, debug_handle
);
11052 /* Do not free debug_filename - it might be referenced inside
11053 the structure returned by open_debug_file(). */
11054 return debug_handle
;
11057 /* Attempt to load a separate dwarf object file. */
11060 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
11062 char * separate_filename
;
11063 void * separate_handle
;
11065 /* FIXME: Skip adding / if dwo_dir ends in /. */
11066 separate_filename
= concat (dir
, "/", name
, NULL
);
11067 if (separate_filename
== NULL
)
11069 warn (_("Out of memory allocating dwo filename\n"));
11073 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
11075 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
11076 free (separate_filename
);
11080 /* FIXME: We should check the dwo_id. */
11082 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
11083 add_separate_debug_file (separate_filename
, separate_handle
);
11084 /* Note - separate_filename will be freed in free_debug_memory(). */
11085 return separate_handle
;
11088 /* Load a debuglink section and/or a debugaltlink section, if either are present.
11089 Recursively check the loaded files for more of these sections.
11090 FIXME: Should also check for DWO_* entries in the newlu loaded files. */
11093 check_for_and_load_links (void * file
, const char * filename
)
11095 void * handle
= NULL
;
11097 if (load_debug_section (gnu_debugaltlink
, file
))
11099 Build_id_data build_id_data
;
11101 handle
= load_separate_debug_info (filename
,
11102 & debug_displays
[gnu_debugaltlink
].section
,
11103 parse_gnu_debugaltlink
,
11104 check_gnu_debugaltlink
,
11109 assert (handle
== first_separate_info
->handle
);
11110 check_for_and_load_links (first_separate_info
->handle
,
11111 first_separate_info
->filename
);
11115 if (load_debug_section (gnu_debuglink
, file
))
11117 unsigned long crc32
;
11119 handle
= load_separate_debug_info (filename
,
11120 & debug_displays
[gnu_debuglink
].section
,
11121 parse_gnu_debuglink
,
11122 check_gnu_debuglink
,
11127 assert (handle
== first_separate_info
->handle
);
11128 check_for_and_load_links (first_separate_info
->handle
,
11129 first_separate_info
->filename
);
11134 /* Load the separate debug info file(s) attached to FILE, if any exist.
11135 Returns TRUE if any were found, FALSE otherwise.
11136 If TRUE is returned then the linked list starting at first_separate_info
11137 will be populated with open file handles. */
11140 load_separate_debug_files (void * file
, const char * filename
)
11142 /* Skip this operation if we are not interested in debug links. */
11143 if (! do_follow_links
&& ! do_debug_links
)
11146 /* See if there are any dwo links. */
11147 if (load_debug_section (str
, file
)
11148 && load_debug_section (abbrev
, file
)
11149 && load_debug_section (info
, file
))
11153 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
,
11156 bfd_boolean introduced
= FALSE
;
11158 const char * dir
= NULL
;
11159 const char * id
= NULL
;
11160 const char * name
= NULL
;
11162 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
11164 /* Accumulate NAME, DIR and ID fields. */
11165 switch (dwinfo
->type
)
11169 warn (_("Multiple DWO_NAMEs encountered for the same CU\n"));
11170 name
= dwinfo
->value
;
11174 /* There can be multiple DW_AT_comp_dir entries in a CU,
11175 so do not complain. */
11176 dir
= dwinfo
->value
;
11181 warn (_("multiple DWO_IDs encountered for the same CU\n"));
11182 id
= dwinfo
->value
;
11186 error (_("Unexpected DWO INFO type"));
11190 /* If we have reached the end of our list, or we are changing
11191 CUs, then display the information that we have accumulated
11194 && (dwinfo
->next
== NULL
11195 || dwinfo
->next
->cu_offset
!= dwinfo
->cu_offset
))
11197 if (do_debug_links
)
11201 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
11202 debug_displays
[info
].section
.uncompressed_name
);
11206 printf (_(" Name: %s\n"), name
);
11207 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
11209 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
11211 printf (_(" ID: <not specified>\n"));
11215 if (do_follow_links
)
11216 load_dwo_file (filename
, name
, dir
, id
);
11218 name
= dir
= id
= NULL
;
11224 if (! do_follow_links
)
11225 /* The other debug links will be displayed by display_debug_links()
11226 so we do not need to do any further processing here. */
11229 /* FIXME: We do not check for the presence of both link sections in the same file. */
11230 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
11231 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
11233 check_for_and_load_links (file
, filename
);
11234 if (first_separate_info
!= NULL
)
11237 do_follow_links
= 0;
11242 free_debug_memory (void)
11246 free_all_abbrevs ();
11248 free (cu_abbrev_map
);
11249 cu_abbrev_map
= NULL
;
11250 next_free_abbrev_map_entry
= 0;
11252 for (i
= 0; i
< max
; i
++)
11253 free_debug_section ((enum dwarf_section_display_enum
) i
);
11255 if (debug_information
!= NULL
)
11257 for (i
= 0; i
< alloc_num_debug_info_entries
; i
++)
11259 if (debug_information
[i
].max_loc_offsets
)
11261 free (debug_information
[i
].loc_offsets
);
11262 free (debug_information
[i
].have_frame_base
);
11264 if (debug_information
[i
].max_range_lists
)
11265 free (debug_information
[i
].range_lists
);
11267 free (debug_information
);
11268 debug_information
= NULL
;
11269 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
11273 separate_info
* next
;
11275 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
11277 close_debug_file (d
->handle
);
11278 free ((void *) d
->filename
);
11282 first_separate_info
= NULL
;
11288 dwarf_select_sections_by_names (const char *names
)
11292 const char * option
;
11296 debug_dump_long_opts
;
11298 static const debug_dump_long_opts opts_table
[] =
11300 /* Please keep this table alpha- sorted. */
11301 { "Ranges", & do_debug_ranges
, 1 },
11302 { "abbrev", & do_debug_abbrevs
, 1 },
11303 { "addr", & do_debug_addr
, 1 },
11304 { "aranges", & do_debug_aranges
, 1 },
11305 { "cu_index", & do_debug_cu_index
, 1 },
11306 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
11307 { "follow-links", & do_follow_links
, 1 },
11308 { "frames", & do_debug_frames
, 1 },
11309 { "frames-interp", & do_debug_frames_interp
, 1 },
11310 /* The special .gdb_index section. */
11311 { "gdb_index", & do_gdb_index
, 1 },
11312 { "info", & do_debug_info
, 1 },
11313 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
11314 { "links", & do_debug_links
, 1 },
11315 { "loc", & do_debug_loc
, 1 },
11316 { "macro", & do_debug_macinfo
, 1 },
11317 { "pubnames", & do_debug_pubnames
, 1 },
11318 { "pubtypes", & do_debug_pubtypes
, 1 },
11319 /* This entry is for compatibility
11320 with earlier versions of readelf. */
11321 { "ranges", & do_debug_aranges
, 1 },
11322 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
11323 { "str", & do_debug_str
, 1 },
11324 { "str-offsets", & do_debug_str_offsets
, 1 },
11325 /* These trace_* sections are used by Itanium VMS. */
11326 { "trace_abbrev", & do_trace_abbrevs
, 1 },
11327 { "trace_aranges", & do_trace_aranges
, 1 },
11328 { "trace_info", & do_trace_info
, 1 },
11337 const debug_dump_long_opts
* entry
;
11339 for (entry
= opts_table
; entry
->option
; entry
++)
11341 size_t len
= strlen (entry
->option
);
11343 if (strncmp (p
, entry
->option
, len
) == 0
11344 && (p
[len
] == ',' || p
[len
] == '\0'))
11346 * entry
->variable
|= entry
->val
;
11348 /* The --debug-dump=frames-interp option also
11349 enables the --debug-dump=frames option. */
11350 if (do_debug_frames_interp
)
11351 do_debug_frames
= 1;
11358 if (entry
->option
== NULL
)
11360 warn (_("Unrecognized debug option '%s'\n"), p
);
11361 p
= strchr (p
, ',');
11372 dwarf_select_sections_by_letters (const char *letters
)
11374 unsigned int lindex
= 0;
11376 while (letters
[lindex
])
11377 switch (letters
[lindex
++])
11379 case 'A': do_debug_addr
= 1; break;
11380 case 'a': do_debug_abbrevs
= 1; break;
11381 case 'c': do_debug_cu_index
= 1; break;
11382 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
11383 case 'f': do_debug_frames
= 1; break;
11384 case 'g': do_gdb_index
= 1; break;
11385 case 'i': do_debug_info
= 1; break;
11386 case 'K': do_follow_links
= 1; break;
11387 case 'k': do_debug_links
= 1; break;
11388 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
11389 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
11390 case 'm': do_debug_macinfo
= 1; break;
11391 case 'O': do_debug_str_offsets
= 1; break;
11392 case 'o': do_debug_loc
= 1; break;
11393 case 'p': do_debug_pubnames
= 1; break;
11394 case 'R': do_debug_ranges
= 1; break;
11395 case 'r': do_debug_aranges
= 1; break;
11396 case 's': do_debug_str
= 1; break;
11397 case 'T': do_trace_aranges
= 1; break;
11398 case 't': do_debug_pubtypes
= 1; break;
11399 case 'U': do_trace_info
= 1; break;
11400 case 'u': do_trace_abbrevs
= 1; break;
11403 warn (_("Unrecognized debug option '%s'\n"), letters
);
11409 dwarf_select_sections_all (void)
11412 do_debug_abbrevs
= 1;
11413 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
11414 do_debug_pubnames
= 1;
11415 do_debug_pubtypes
= 1;
11416 do_debug_aranges
= 1;
11417 do_debug_ranges
= 1;
11418 do_debug_frames
= 1;
11419 do_debug_macinfo
= 1;
11424 do_trace_abbrevs
= 1;
11425 do_trace_aranges
= 1;
11427 do_debug_cu_index
= 1;
11428 do_follow_links
= 1;
11429 do_debug_links
= 1;
11430 do_debug_str_offsets
= 1;
11433 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
11434 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
11436 /* N.B. The order here must match the order in section_display_enum. */
11438 struct dwarf_section_display debug_displays
[] =
11440 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
11441 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, TRUE
},
11442 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
11443 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, TRUE
},
11444 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
11445 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
11446 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
11447 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
11448 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
11449 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
11450 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11451 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11452 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11453 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11454 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
11455 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
11456 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
11457 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
11458 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
11459 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
11460 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, TRUE
},
11461 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
11462 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, FALSE
},
11463 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, FALSE
},
11464 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, TRUE
},
11465 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
11466 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, FALSE
},
11467 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, TRUE
},
11468 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
11469 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, TRUE
},
11470 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
11471 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
11472 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
11473 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
11474 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, TRUE
},
11475 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
11476 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, &do_debug_str_offsets
, TRUE
},
11477 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, TRUE
},
11478 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
11479 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
11480 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
11481 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
11482 /* Separate debug info files can containt their own .debug_str section,
11483 and this might be in *addition* to a .debug_str section already present
11484 in the main file. Hence we need to have two entries for .debug_str. */
11485 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
11488 /* A static assertion. */
11489 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];