1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2020 Free Software Foundation, Inc.
4 This file is part of GNU Binutils.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 #include "libiberty.h"
24 #include "bfd_stdint.h"
27 #include "elf/common.h"
30 #include "gdb/gdb-index.h"
31 #include "filenames.h"
32 #include "safe-ctype.h"
35 #ifdef HAVE_LIBDEBUGINFOD
36 #include <elfutils/debuginfod.h>
41 #define MAX(a, b) ((a) > (b) ? (a) : (b))
42 #define MIN(a, b) ((a) < (b) ? (a) : (b))
44 static const char *regname (unsigned int regno
, int row
);
45 static const char *regname_internal_by_table_only (unsigned int regno
);
47 static int have_frame_base
;
48 static int need_base_address
;
50 static unsigned int num_debug_info_entries
= 0;
51 static unsigned int alloc_num_debug_info_entries
= 0;
52 static debug_info
*debug_information
= NULL
;
53 /* Special value for num_debug_info_entries to indicate
54 that the .debug_info section could not be loaded/parsed. */
55 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
57 /* A .debug_info section can contain multiple links to separate
58 DWO object files. We use these structures to record these links. */
66 typedef struct dwo_info
70 struct dwo_info
* next
;
73 static dwo_info
* first_dwo_info
= NULL
;
74 static bfd_boolean need_dwo_info
;
76 separate_info
* first_separate_info
= NULL
;
78 unsigned int eh_addr_size
;
83 int do_debug_pubnames
;
84 int do_debug_pubtypes
;
88 int do_debug_frames_interp
;
97 int do_debug_cu_index
;
102 int dwarf_cutoff_level
= -1;
103 unsigned long dwarf_start_die
;
107 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
108 testing whether e.g. a locview list is present. */
109 static const dwarf_vma vm1
= -1;
111 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
112 sections. For version 1 package files, each set is stored in SHNDX_POOL
113 as a zero-terminated list of section indexes comprising one set of debug
114 sections from a .dwo file. */
116 static unsigned int *shndx_pool
= NULL
;
117 static unsigned int shndx_pool_size
= 0;
118 static unsigned int shndx_pool_used
= 0;
120 /* For version 2 package files, each set contains an array of section offsets
121 and an array of section sizes, giving the offset and size of the
122 contribution from a CU or TU within one of the debug sections.
123 When displaying debug info from a package file, we need to use these
124 tables to locate the corresponding contributions to each section. */
129 dwarf_vma section_offsets
[DW_SECT_MAX
];
130 size_t section_sizes
[DW_SECT_MAX
];
133 static int cu_count
= 0;
134 static int tu_count
= 0;
135 static struct cu_tu_set
*cu_sets
= NULL
;
136 static struct cu_tu_set
*tu_sets
= NULL
;
138 static bfd_boolean
load_cu_tu_indexes (void *);
140 /* An array that indicates for a given level of CU nesting whether
141 the latest DW_AT_type seen for that level was a signed type or
143 #define MAX_CU_NESTING (1 << 8)
144 static bfd_boolean level_type_signed
[MAX_CU_NESTING
];
146 /* Values for do_debug_lines. */
147 #define FLAG_DEBUG_LINES_RAW 1
148 #define FLAG_DEBUG_LINES_DECODED 2
151 size_of_encoded_value (int encoding
)
153 switch (encoding
& 0x7)
156 case 0: return eh_addr_size
;
164 get_encoded_value (unsigned char **pdata
,
166 struct dwarf_section
*section
,
169 unsigned char * data
= * pdata
;
170 unsigned int size
= size_of_encoded_value (encoding
);
173 if (data
+ size
>= end
)
175 warn (_("Encoded value extends past end of section\n"));
180 /* PR 17512: file: 002-829853-0.004. */
183 warn (_("Encoded size of %d is too large to read\n"), size
);
188 /* PR 17512: file: 1085-5603-0.004. */
191 warn (_("Encoded size of 0 is too small to read\n"));
196 if (encoding
& DW_EH_PE_signed
)
197 val
= byte_get_signed (data
, size
);
199 val
= byte_get (data
, size
);
201 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
202 val
+= section
->address
+ (data
- section
->start
);
204 * pdata
= data
+ size
;
208 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
210 # define DWARF_VMA_FMT "ll"
211 # define DWARF_VMA_FMT_LONG "%16.16llx"
213 # define DWARF_VMA_FMT "I64"
214 # define DWARF_VMA_FMT_LONG "%016I64x"
217 # define DWARF_VMA_FMT "l"
218 # define DWARF_VMA_FMT_LONG "%16.16lx"
221 /* Convert a dwarf vma value into a string. Returns a pointer to a static
222 buffer containing the converted VALUE. The value is converted according
223 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
224 it specifies the maximum number of bytes to be displayed in the converted
225 value and FMTCH is ignored - hex is always used. */
228 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
230 /* As dwarf_vmatoa is used more then once in a printf call
231 for output, we are cycling through an fixed array of pointers
232 for return address. */
233 static int buf_pos
= 0;
234 static struct dwarf_vmatoa_buf
240 ret
= buf
[buf_pos
++].place
;
241 buf_pos
%= ARRAY_SIZE (buf
);
245 /* Printf does not have a way of specifying a maximum field width for an
246 integer value, so we print the full value into a buffer and then select
247 the precision we need. */
248 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
251 return ret
+ (16 - 2 * num_bytes
);
258 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
260 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
261 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
266 static inline const char *
267 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
269 return dwarf_vmatoa_1 (fmtch
, value
, 0);
272 /* Print a dwarf_vma value (typically an address, offset or length) in
273 hexadecimal format, followed by a space. The length of the VALUE (and
274 hence the precision displayed) is determined by the NUM_BYTES parameter. */
277 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
279 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
282 /* Print a view number in hexadecimal value, with the same width
283 print_dwarf_vma would have printed it with the same num_bytes.
284 Print blanks for zero view, unless force is nonzero. */
287 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
295 assert (value
== (unsigned long) value
);
297 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
299 printf ("%*s", len
+ 1, "");
302 /* Format a 64-bit value, given as two 32-bit values, in hex.
303 For reentrancy, this uses a buffer provided by the caller. */
306 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
307 unsigned int buf_len
)
312 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
315 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
316 snprintf (buf
+ len
, buf_len
- len
,
317 "%08" DWARF_VMA_FMT
"x", lvalue
);
323 /* Read in a LEB128 encoded value starting at address DATA.
324 If SIGN is true, return a signed LEB128 value.
325 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
326 If STATUS_RETURN in not NULL, return with bit 0 (LSB) set if the
327 terminating byte was not found and with bit 1 set if the value
328 overflows a dwarf_vma.
329 No bytes will be read at address END or beyond. */
332 read_leb128 (unsigned char *data
,
333 const unsigned char *const end
,
335 unsigned int *length_return
,
338 dwarf_vma result
= 0;
339 unsigned int num_read
= 0;
340 unsigned int shift
= 0;
345 unsigned char byte
= *data
++;
348 if (shift
< sizeof (result
) * 8)
350 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
351 if ((result
>> shift
) != (byte
& 0x7f))
356 else if ((byte
& 0x7f) != 0)
359 if ((byte
& 0x80) == 0)
362 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
363 result
|= -((dwarf_vma
) 1 << shift
);
368 if (length_return
!= NULL
)
369 *length_return
= num_read
;
370 if (status_return
!= NULL
)
371 *status_return
= status
;
376 /* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
377 Checks to make sure that the read will not reach or pass END
378 and that VAL is big enough to hold AMOUNT bytes. */
379 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
382 unsigned int amount = (AMOUNT); \
383 if (sizeof (VAL) < amount) \
385 error (ngettext ("internal error: attempt to read %d byte " \
386 "of data in to %d sized variable", \
387 "internal error: attempt to read %d bytes " \
388 "of data in to %d sized variable", \
390 amount, (int) sizeof (VAL)); \
391 amount = sizeof (VAL); \
393 if (((PTR) + amount) >= (END)) \
396 amount = (END) - (PTR); \
400 if (amount == 0 || amount > 8) \
403 VAL = byte_get ((PTR), amount); \
407 /* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
408 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
411 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
416 /* Like SAFE_BYTE_GET, but reads a signed value. */
417 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
420 unsigned int amount = (AMOUNT); \
421 if (((PTR) + amount) >= (END)) \
424 amount = (END) - (PTR); \
429 VAL = byte_get_signed ((PTR), amount); \
435 /* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
436 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
439 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
444 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
447 if (((PTR) + 8) <= (END)) \
449 byte_get_64 ((PTR), (HIGH), (LOW)); \
453 * (LOW) = * (HIGH) = 0; \
458 typedef struct State_Machine_Registers
467 unsigned char op_index
;
468 unsigned char end_sequence
;
469 /* This variable hold the number of the last entry seen
470 in the File Table. */
471 unsigned int last_file_entry
;
474 static SMR state_machine_regs
;
477 reset_state_machine (int is_stmt
)
479 state_machine_regs
.address
= 0;
480 state_machine_regs
.view
= 0;
481 state_machine_regs
.op_index
= 0;
482 state_machine_regs
.file
= 1;
483 state_machine_regs
.line
= 1;
484 state_machine_regs
.column
= 0;
485 state_machine_regs
.is_stmt
= is_stmt
;
486 state_machine_regs
.basic_block
= 0;
487 state_machine_regs
.end_sequence
= 0;
488 state_machine_regs
.last_file_entry
= 0;
491 /* Handled an extend line op.
492 Returns the number of bytes read. */
495 process_extended_line_op (unsigned char * data
,
499 unsigned char op_code
;
500 size_t len
, header_len
;
502 unsigned char *orig_data
= data
;
505 READ_ULEB (len
, data
, end
);
506 header_len
= data
- orig_data
;
508 if (len
== 0 || data
== end
|| len
> (size_t) (end
- data
))
510 warn (_("Badly formed extended line op encountered!\n"));
516 printf (_(" Extended opcode %d: "), op_code
);
520 case DW_LNE_end_sequence
:
521 printf (_("End of Sequence\n\n"));
522 reset_state_machine (is_stmt
);
525 case DW_LNE_set_address
:
526 /* PR 17512: file: 002-100480-0.004. */
529 warn (_("Length (%lu) of DW_LNE_set_address op is too long\n"),
530 (unsigned long) len
- 1);
534 SAFE_BYTE_GET (adr
, data
, len
- 1, end
);
535 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
536 state_machine_regs
.address
= adr
;
537 state_machine_regs
.view
= 0;
538 state_machine_regs
.op_index
= 0;
541 case DW_LNE_define_file
:
542 printf (_("define new File Table entry\n"));
543 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
544 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
550 l
= strnlen ((char *) data
, end
- data
);
552 READ_ULEB (val
, data
, end
);
553 printf ("%s\t", dwarf_vmatoa ("u", val
));
554 READ_ULEB (val
, data
, end
);
555 printf ("%s\t", dwarf_vmatoa ("u", val
));
556 READ_ULEB (val
, data
, end
);
557 printf ("%s\t", dwarf_vmatoa ("u", val
));
558 printf ("%.*s\n\n", (int) l
, name
);
561 if (((size_t) (data
- orig_data
) != len
+ header_len
) || data
== end
)
562 warn (_("DW_LNE_define_file: Bad opcode length\n"));
565 case DW_LNE_set_discriminator
:
566 READ_ULEB (val
, data
, end
);
567 printf (_("set Discriminator to %s\n"), dwarf_vmatoa ("u", val
));
571 case DW_LNE_HP_negate_is_UV_update
:
572 printf ("DW_LNE_HP_negate_is_UV_update\n");
574 case DW_LNE_HP_push_context
:
575 printf ("DW_LNE_HP_push_context\n");
577 case DW_LNE_HP_pop_context
:
578 printf ("DW_LNE_HP_pop_context\n");
580 case DW_LNE_HP_set_file_line_column
:
581 printf ("DW_LNE_HP_set_file_line_column\n");
583 case DW_LNE_HP_set_routine_name
:
584 printf ("DW_LNE_HP_set_routine_name\n");
586 case DW_LNE_HP_set_sequence
:
587 printf ("DW_LNE_HP_set_sequence\n");
589 case DW_LNE_HP_negate_post_semantics
:
590 printf ("DW_LNE_HP_negate_post_semantics\n");
592 case DW_LNE_HP_negate_function_exit
:
593 printf ("DW_LNE_HP_negate_function_exit\n");
595 case DW_LNE_HP_negate_front_end_logical
:
596 printf ("DW_LNE_HP_negate_front_end_logical\n");
598 case DW_LNE_HP_define_proc
:
599 printf ("DW_LNE_HP_define_proc\n");
601 case DW_LNE_HP_source_file_correlation
:
603 unsigned char *edata
= data
+ len
- 1;
605 printf ("DW_LNE_HP_source_file_correlation\n");
611 READ_ULEB (opc
, data
, edata
);
615 case DW_LNE_HP_SFC_formfeed
:
616 printf (" DW_LNE_HP_SFC_formfeed\n");
618 case DW_LNE_HP_SFC_set_listing_line
:
619 READ_ULEB (val
, data
, edata
);
620 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
621 dwarf_vmatoa ("u", val
));
623 case DW_LNE_HP_SFC_associate
:
624 printf (" DW_LNE_HP_SFC_associate ");
625 READ_ULEB (val
, data
, edata
);
626 printf ("(%s", dwarf_vmatoa ("u", val
));
627 READ_ULEB (val
, data
, edata
);
628 printf (",%s", dwarf_vmatoa ("u", val
));
629 READ_ULEB (val
, data
, edata
);
630 printf (",%s)\n", dwarf_vmatoa ("u", val
));
633 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
643 unsigned int rlen
= len
- 1;
645 if (op_code
>= DW_LNE_lo_user
646 /* The test against DW_LNW_hi_user is redundant due to
647 the limited range of the unsigned char data type used
649 /*&& op_code <= DW_LNE_hi_user*/)
650 printf (_("user defined: "));
652 printf (_("UNKNOWN: "));
653 printf (_("length %d ["), rlen
);
655 printf (" %02x", *data
++);
661 return len
+ header_len
;
664 static const unsigned char *
665 fetch_indirect_string (dwarf_vma offset
)
667 struct dwarf_section
*section
= &debug_displays
[str
].section
;
668 const unsigned char * ret
;
670 if (section
->start
== NULL
)
671 return (const unsigned char *) _("<no .debug_str section>");
673 if (offset
>= section
->size
)
675 warn (_("DW_FORM_strp offset too big: %s\n"),
676 dwarf_vmatoa ("x", offset
));
677 return (const unsigned char *) _("<offset is too big>");
680 ret
= section
->start
+ offset
;
681 /* Unfortunately we cannot rely upon the .debug_str section ending with a
682 NUL byte. Since our caller is expecting to receive a well formed C
683 string we test for the lack of a terminating byte here. */
684 if (strnlen ((const char *) ret
, section
->size
- offset
)
685 == section
->size
- offset
)
686 ret
= (const unsigned char *)
687 _("<no NUL byte at end of .debug_str section>");
692 static const unsigned char *
693 fetch_indirect_line_string (dwarf_vma offset
)
695 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
696 const unsigned char * ret
;
698 if (section
->start
== NULL
)
699 return (const unsigned char *) _("<no .debug_line_str section>");
701 if (offset
>= section
->size
)
703 warn (_("DW_FORM_line_strp offset too big: %s\n"),
704 dwarf_vmatoa ("x", offset
));
705 return (const unsigned char *) _("<offset is too big>");
708 ret
= section
->start
+ offset
;
709 /* Unfortunately we cannot rely upon the .debug_line_str section ending
710 with a NUL byte. Since our caller is expecting to receive a well formed
711 C string we test for the lack of a terminating byte here. */
712 if (strnlen ((const char *) ret
, section
->size
- offset
)
713 == section
->size
- offset
)
714 ret
= (const unsigned char *)
715 _("<no NUL byte at end of .debug_line_str section>");
721 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
722 dwarf_vma offset_size
, bfd_boolean dwo
)
724 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
725 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
726 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
727 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
728 dwarf_vma index_offset
= idx
* offset_size
;
729 dwarf_vma str_offset
;
732 if (index_section
->start
== NULL
)
733 return (dwo
? _("<no .debug_str_offsets.dwo section>")
734 : _("<no .debug_str_offsets section>"));
736 if (this_set
!= NULL
)
737 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
738 if (index_offset
>= index_section
->size
)
740 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
741 dwarf_vmatoa ("x", index_offset
));
742 return _("<index offset is too big>");
745 if (str_section
->start
== NULL
)
746 return (dwo
? _("<no .debug_str.dwo section>")
747 : _("<no .debug_str section>"));
749 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
750 str_offset
-= str_section
->address
;
751 if (str_offset
>= str_section
->size
)
753 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
754 dwarf_vmatoa ("x", str_offset
));
755 return _("<indirect index offset is too big>");
758 ret
= (const char *) str_section
->start
+ str_offset
;
759 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
760 Since our caller is expecting to receive a well formed C string we test
761 for the lack of a terminating byte here. */
762 if (strnlen (ret
, str_section
->size
- str_offset
)
763 == str_section
->size
- str_offset
)
764 ret
= (const char *) _("<no NUL byte at end of section>");
770 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
772 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
774 if (section
->start
== NULL
)
775 return (_("<no .debug_addr section>"));
777 if (offset
+ bytes
> section
->size
)
779 warn (_("Offset into section %s too big: %s\n"),
780 section
->name
, dwarf_vmatoa ("x", offset
));
781 return "<offset too big>";
784 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
788 /* FIXME: There are better and more efficient ways to handle
789 these structures. For now though, I just want something that
790 is simple to implement. */
791 typedef struct abbrev_attr
793 unsigned long attribute
;
795 bfd_signed_vma implicit_const
;
796 struct abbrev_attr
*next
;
800 typedef struct abbrev_entry
805 struct abbrev_attr
*first_attr
;
806 struct abbrev_attr
*last_attr
;
807 struct abbrev_entry
*next
;
811 static abbrev_entry
*first_abbrev
= NULL
;
812 static abbrev_entry
*last_abbrev
= NULL
;
819 for (abbrv
= first_abbrev
; abbrv
;)
821 abbrev_entry
*next_abbrev
= abbrv
->next
;
824 for (attr
= abbrv
->first_attr
; attr
;)
826 abbrev_attr
*next_attr
= attr
->next
;
836 last_abbrev
= first_abbrev
= NULL
;
840 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
844 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
849 entry
->entry
= number
;
851 entry
->children
= children
;
852 entry
->first_attr
= NULL
;
853 entry
->last_attr
= NULL
;
856 if (first_abbrev
== NULL
)
857 first_abbrev
= entry
;
859 last_abbrev
->next
= entry
;
865 add_abbrev_attr (unsigned long attribute
, unsigned long form
,
866 bfd_signed_vma implicit_const
)
870 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
875 attr
->attribute
= attribute
;
877 attr
->implicit_const
= implicit_const
;
880 if (last_abbrev
->first_attr
== NULL
)
881 last_abbrev
->first_attr
= attr
;
883 last_abbrev
->last_attr
->next
= attr
;
885 last_abbrev
->last_attr
= attr
;
888 /* Processes the (partial) contents of a .debug_abbrev section.
889 Returns NULL if the end of the section was encountered.
890 Returns the address after the last byte read if the end of
891 an abbreviation set was found. */
893 static unsigned char *
894 process_abbrev_section (unsigned char *start
, unsigned char *end
)
896 if (first_abbrev
!= NULL
)
903 unsigned long attribute
;
906 READ_ULEB (entry
, start
, end
);
908 /* A single zero is supposed to end the section according
909 to the standard. If there's more, then signal that to
916 READ_ULEB (tag
, start
, end
);
922 add_abbrev (entry
, tag
, children
);
927 /* Initialize it due to a false compiler warning. */
928 bfd_signed_vma implicit_const
= -1;
930 READ_ULEB (attribute
, start
, end
);
934 READ_ULEB (form
, start
, end
);
938 if (form
== DW_FORM_implicit_const
)
940 READ_SLEB (implicit_const
, start
, end
);
945 add_abbrev_attr (attribute
, form
, implicit_const
);
947 while (attribute
!= 0);
950 /* Report the missing single zero which ends the section. */
951 error (_(".debug_abbrev section not zero terminated\n"));
957 get_TAG_name (unsigned long tag
)
959 const char *name
= get_DW_TAG_name ((unsigned int) tag
);
963 static char buffer
[100];
965 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
966 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
968 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
976 get_FORM_name (unsigned long form
)
981 return "DW_FORM value: 0";
983 name
= get_DW_FORM_name (form
);
986 static char buffer
[100];
988 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
996 get_IDX_name (unsigned long idx
)
998 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1002 static char buffer
[100];
1004 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1011 static unsigned char *
1012 display_block (unsigned char *data
,
1014 const unsigned char * const end
, char delimiter
)
1018 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1020 return (unsigned char *) end
;
1022 maxlen
= (dwarf_vma
) (end
- data
);
1023 length
= length
> maxlen
? maxlen
: length
;
1026 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1032 decode_location_expression (unsigned char * data
,
1033 unsigned int pointer_size
,
1034 unsigned int offset_size
,
1037 dwarf_vma cu_offset
,
1038 struct dwarf_section
* section
)
1042 dwarf_signed_vma svalue
;
1043 unsigned char *end
= data
+ length
;
1044 int need_frame_base
= 0;
1053 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1054 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1057 printf ("DW_OP_deref");
1060 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1061 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1064 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1065 printf ("DW_OP_const1s: %ld", (long) svalue
);
1068 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1069 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1072 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1073 printf ("DW_OP_const2s: %ld", (long) svalue
);
1076 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1077 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1080 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1081 printf ("DW_OP_const4s: %ld", (long) svalue
);
1084 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1085 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1086 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1087 printf ("%lu", (unsigned long) uvalue
);
1090 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1091 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1092 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1093 printf ("%ld", (long) svalue
);
1096 READ_ULEB (uvalue
, data
, end
);
1097 printf ("DW_OP_constu: %s", dwarf_vmatoa ("u", uvalue
));
1100 READ_SLEB (svalue
, data
, end
);
1101 printf ("DW_OP_consts: %s", dwarf_vmatoa ("d", svalue
));
1104 printf ("DW_OP_dup");
1107 printf ("DW_OP_drop");
1110 printf ("DW_OP_over");
1113 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1114 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1117 printf ("DW_OP_swap");
1120 printf ("DW_OP_rot");
1123 printf ("DW_OP_xderef");
1126 printf ("DW_OP_abs");
1129 printf ("DW_OP_and");
1132 printf ("DW_OP_div");
1135 printf ("DW_OP_minus");
1138 printf ("DW_OP_mod");
1141 printf ("DW_OP_mul");
1144 printf ("DW_OP_neg");
1147 printf ("DW_OP_not");
1150 printf ("DW_OP_or");
1153 printf ("DW_OP_plus");
1155 case DW_OP_plus_uconst
:
1156 READ_ULEB (uvalue
, data
, end
);
1157 printf ("DW_OP_plus_uconst: %s", dwarf_vmatoa ("u", uvalue
));
1160 printf ("DW_OP_shl");
1163 printf ("DW_OP_shr");
1166 printf ("DW_OP_shra");
1169 printf ("DW_OP_xor");
1172 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1173 printf ("DW_OP_bra: %ld", (long) svalue
);
1176 printf ("DW_OP_eq");
1179 printf ("DW_OP_ge");
1182 printf ("DW_OP_gt");
1185 printf ("DW_OP_le");
1188 printf ("DW_OP_lt");
1191 printf ("DW_OP_ne");
1194 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1195 printf ("DW_OP_skip: %ld", (long) svalue
);
1230 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1265 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1266 regname (op
- DW_OP_reg0
, 1));
1301 READ_SLEB (svalue
, data
, end
);
1302 printf ("DW_OP_breg%d (%s): %s", op
- DW_OP_breg0
,
1303 regname (op
- DW_OP_breg0
, 1), dwarf_vmatoa ("d", svalue
));
1307 READ_ULEB (uvalue
, data
, end
);
1308 printf ("DW_OP_regx: %s (%s)",
1309 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1312 need_frame_base
= 1;
1313 READ_SLEB (svalue
, data
, end
);
1314 printf ("DW_OP_fbreg: %s", dwarf_vmatoa ("d", svalue
));
1317 READ_ULEB (uvalue
, data
, end
);
1318 READ_SLEB (svalue
, data
, end
);
1319 printf ("DW_OP_bregx: %s (%s) %s",
1320 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1321 dwarf_vmatoa ("d", svalue
));
1324 READ_ULEB (uvalue
, data
, end
);
1325 printf ("DW_OP_piece: %s", dwarf_vmatoa ("u", uvalue
));
1327 case DW_OP_deref_size
:
1328 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1329 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1331 case DW_OP_xderef_size
:
1332 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1333 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1336 printf ("DW_OP_nop");
1339 /* DWARF 3 extensions. */
1340 case DW_OP_push_object_address
:
1341 printf ("DW_OP_push_object_address");
1344 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1345 this ought to be an 8-byte wide computation. */
1346 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1347 printf ("DW_OP_call2: <0x%s>",
1348 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1351 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1352 this ought to be an 8-byte wide computation. */
1353 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1354 printf ("DW_OP_call4: <0x%s>",
1355 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1357 case DW_OP_call_ref
:
1358 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1359 this ought to be an 8-byte wide computation. */
1360 if (dwarf_version
== -1)
1362 printf (_("(DW_OP_call_ref in frame info)"));
1363 /* No way to tell where the next op is, so just bail. */
1364 return need_frame_base
;
1366 if (dwarf_version
== 2)
1368 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1372 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1374 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1376 case DW_OP_form_tls_address
:
1377 printf ("DW_OP_form_tls_address");
1379 case DW_OP_call_frame_cfa
:
1380 printf ("DW_OP_call_frame_cfa");
1382 case DW_OP_bit_piece
:
1383 printf ("DW_OP_bit_piece: ");
1384 READ_ULEB (uvalue
, data
, end
);
1385 printf (_("size: %s "), dwarf_vmatoa ("u", uvalue
));
1386 READ_ULEB (uvalue
, data
, end
);
1387 printf (_("offset: %s "), dwarf_vmatoa ("u", uvalue
));
1390 /* DWARF 4 extensions. */
1391 case DW_OP_stack_value
:
1392 printf ("DW_OP_stack_value");
1395 case DW_OP_implicit_value
:
1396 printf ("DW_OP_implicit_value");
1397 READ_ULEB (uvalue
, data
, end
);
1398 data
= display_block (data
, uvalue
, end
, ' ');
1401 /* GNU extensions. */
1402 case DW_OP_GNU_push_tls_address
:
1403 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1405 case DW_OP_GNU_uninit
:
1406 printf ("DW_OP_GNU_uninit");
1407 /* FIXME: Is there data associated with this OP ? */
1409 case DW_OP_GNU_encoded_addr
:
1416 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1418 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1419 print_dwarf_vma (addr
, pointer_size
);
1422 case DW_OP_implicit_pointer
:
1423 case DW_OP_GNU_implicit_pointer
:
1424 /* FIXME: Strictly speaking for 64-bit DWARF3 files
1425 this ought to be an 8-byte wide computation. */
1426 if (dwarf_version
== -1)
1428 printf (_("(%s in frame info)"),
1429 (op
== DW_OP_implicit_pointer
1430 ? "DW_OP_implicit_pointer"
1431 : "DW_OP_GNU_implicit_pointer"));
1432 /* No way to tell where the next op is, so just bail. */
1433 return need_frame_base
;
1435 if (dwarf_version
== 2)
1437 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1441 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1443 READ_SLEB (svalue
, data
, end
);
1444 printf ("%s: <0x%s> %s",
1445 (op
== DW_OP_implicit_pointer
1446 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1447 dwarf_vmatoa ("x", uvalue
),
1448 dwarf_vmatoa ("d", svalue
));
1450 case DW_OP_entry_value
:
1451 case DW_OP_GNU_entry_value
:
1452 READ_ULEB (uvalue
, data
, end
);
1453 /* PR 17531: file: 0cc9cd00. */
1454 if (uvalue
> (dwarf_vma
) (end
- data
))
1455 uvalue
= end
- data
;
1456 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1457 : "DW_OP_GNU_entry_value"));
1458 if (decode_location_expression (data
, pointer_size
, offset_size
,
1459 dwarf_version
, uvalue
,
1460 cu_offset
, section
))
1461 need_frame_base
= 1;
1467 case DW_OP_const_type
:
1468 case DW_OP_GNU_const_type
:
1469 READ_ULEB (uvalue
, data
, end
);
1470 printf ("%s: <0x%s> ",
1471 (op
== DW_OP_const_type
? "DW_OP_const_type"
1472 : "DW_OP_GNU_const_type"),
1473 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1474 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1475 data
= display_block (data
, uvalue
, end
, ' ');
1477 case DW_OP_regval_type
:
1478 case DW_OP_GNU_regval_type
:
1479 READ_ULEB (uvalue
, data
, end
);
1480 printf ("%s: %s (%s)",
1481 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1482 : "DW_OP_GNU_regval_type"),
1483 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1484 READ_ULEB (uvalue
, data
, end
);
1485 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1487 case DW_OP_deref_type
:
1488 case DW_OP_GNU_deref_type
:
1489 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1491 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1492 : "DW_OP_GNU_deref_type"),
1494 READ_ULEB (uvalue
, data
, end
);
1495 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1498 case DW_OP_GNU_convert
:
1499 READ_ULEB (uvalue
, data
, end
);
1500 printf ("%s <0x%s>",
1501 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1502 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1504 case DW_OP_reinterpret
:
1505 case DW_OP_GNU_reinterpret
:
1506 READ_ULEB (uvalue
, data
, end
);
1507 printf ("%s <0x%s>",
1508 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1509 : "DW_OP_GNU_reinterpret"),
1510 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1512 case DW_OP_GNU_parameter_ref
:
1513 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1514 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1515 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1517 case DW_OP_GNU_addr_index
:
1518 READ_ULEB (uvalue
, data
, end
);
1519 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1521 case DW_OP_GNU_const_index
:
1522 READ_ULEB (uvalue
, data
, end
);
1523 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1525 case DW_OP_GNU_variable_value
:
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_GNU_variable_value 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_GNU_variable_value: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1545 /* HP extensions. */
1546 case DW_OP_HP_is_value
:
1547 printf ("DW_OP_HP_is_value");
1548 /* FIXME: Is there data associated with this OP ? */
1550 case DW_OP_HP_fltconst4
:
1551 printf ("DW_OP_HP_fltconst4");
1552 /* FIXME: Is there data associated with this OP ? */
1554 case DW_OP_HP_fltconst8
:
1555 printf ("DW_OP_HP_fltconst8");
1556 /* FIXME: Is there data associated with this OP ? */
1558 case DW_OP_HP_mod_range
:
1559 printf ("DW_OP_HP_mod_range");
1560 /* FIXME: Is there data associated with this OP ? */
1562 case DW_OP_HP_unmod_range
:
1563 printf ("DW_OP_HP_unmod_range");
1564 /* FIXME: Is there data associated with this OP ? */
1567 printf ("DW_OP_HP_tls");
1568 /* FIXME: Is there data associated with this OP ? */
1571 /* PGI (STMicroelectronics) extensions. */
1572 case DW_OP_PGI_omp_thread_num
:
1573 /* Pushes the thread number for the current thread as it would be
1574 returned by the standard OpenMP library function:
1575 omp_get_thread_num(). The "current thread" is the thread for
1576 which the expression is being evaluated. */
1577 printf ("DW_OP_PGI_omp_thread_num");
1581 if (op
>= DW_OP_lo_user
1582 && op
<= DW_OP_hi_user
)
1583 printf (_("(User defined location op 0x%x)"), op
);
1585 printf (_("(Unknown location op 0x%x)"), op
);
1586 /* No way to tell where the next op is, so just bail. */
1587 return need_frame_base
;
1590 /* Separate the ops. */
1595 return need_frame_base
;
1598 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1599 This is used for DWARF package files. */
1601 static struct cu_tu_set
*
1602 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1604 struct cu_tu_set
*p
;
1606 unsigned int dw_sect
;
1612 dw_sect
= DW_SECT_TYPES
;
1618 dw_sect
= DW_SECT_INFO
;
1622 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1630 /* Add INC to HIGH_BITS:LOW_BITS. */
1632 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1634 dwarf_vma tmp
= * low_bits
;
1638 /* FIXME: There is probably a better way of handling this:
1640 We need to cope with dwarf_vma being a 32-bit or 64-bit
1641 type. Plus regardless of its size LOW_BITS is meant to
1642 only hold 32-bits, so if there is overflow or wrap around
1643 we must propagate into HIGH_BITS. */
1644 if (tmp
< * low_bits
)
1648 else if (sizeof (tmp
) > 8
1659 fetch_alt_indirect_string (dwarf_vma offset
)
1663 if (! do_follow_links
)
1666 if (first_separate_info
== NULL
)
1667 return _("<no links available>");
1669 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
1671 struct dwarf_section
* section
;
1674 if (! load_debug_section (separate_debug_str
, i
->handle
))
1677 section
= &debug_displays
[separate_debug_str
].section
;
1679 if (section
->start
== NULL
)
1682 if (offset
>= section
->size
)
1685 ret
= (const char *) (section
->start
+ offset
);
1686 /* Unfortunately we cannot rely upon the .debug_str section ending with a
1687 NUL byte. Since our caller is expecting to receive a well formed C
1688 string we test for the lack of a terminating byte here. */
1689 if (strnlen ((const char *) ret
, section
->size
- offset
)
1690 == section
->size
- offset
)
1691 return _("<no NUL byte at end of alt .debug_str section>");
1696 warn (_("DW_FORM_GNU_strp_alt offset (%s) too big or no string sections available\n"),
1697 dwarf_vmatoa ("x", offset
));
1698 return _("<offset is too big>");
1702 get_AT_name (unsigned long attribute
)
1707 return "DW_AT value: 0";
1709 /* One value is shared by the MIPS and HP extensions: */
1710 if (attribute
== DW_AT_MIPS_fde
)
1711 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
1713 name
= get_DW_AT_name (attribute
);
1717 static char buffer
[100];
1719 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
1728 add_dwo_info (const char * field
, dwo_type type
)
1730 dwo_info
* dwinfo
= xmalloc (sizeof * dwinfo
);
1732 dwinfo
->type
= type
;
1733 dwinfo
->value
= field
;
1734 dwinfo
->next
= first_dwo_info
;
1735 first_dwo_info
= dwinfo
;
1739 add_dwo_name (const char * name
)
1741 add_dwo_info (name
, DWO_NAME
);
1745 add_dwo_dir (const char * dir
)
1747 add_dwo_info (dir
, DWO_DIR
);
1751 add_dwo_id (const char * id
)
1753 add_dwo_info (id
, DWO_ID
);
1757 free_dwo_info (void)
1762 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= next
)
1764 next
= dwinfo
->next
;
1767 first_dwo_info
= NULL
;
1770 /* Ensure that START + UVALUE is less than END.
1771 Return an adjusted UVALUE if necessary to ensure this relationship. */
1773 static inline dwarf_vma
1774 check_uvalue (const unsigned char * start
,
1776 const unsigned char * end
)
1778 dwarf_vma max_uvalue
= end
- start
;
1780 /* See PR 17512: file: 008-103549-0.001:0.1.
1781 and PR 24829 for examples of where these tests are triggered. */
1782 if (uvalue
> max_uvalue
)
1784 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1785 uvalue
= max_uvalue
;
1791 static unsigned char *
1792 skip_attr_bytes (unsigned long form
,
1793 unsigned char * data
,
1794 unsigned const char * end
,
1795 dwarf_vma pointer_size
,
1796 dwarf_vma offset_size
,
1798 dwarf_vma
* value_return
)
1800 dwarf_signed_vma svalue
;
1801 dwarf_vma uvalue
= 0;
1807 case DW_FORM_ref_addr
:
1808 if (dwarf_version
== 2)
1809 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1810 else if (dwarf_version
== 3 || dwarf_version
== 4)
1811 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1817 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1821 case DW_FORM_line_strp
:
1822 case DW_FORM_sec_offset
:
1823 case DW_FORM_GNU_ref_alt
:
1824 case DW_FORM_GNU_strp_alt
:
1825 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1828 case DW_FORM_flag_present
:
1835 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1840 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1845 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1849 READ_SLEB (svalue
, data
, end
);
1853 case DW_FORM_ref_udata
:
1855 case DW_FORM_GNU_str_index
:
1856 case DW_FORM_GNU_addr_index
:
1857 READ_ULEB (uvalue
, data
, end
);
1865 case DW_FORM_data16
:
1869 case DW_FORM_string
:
1870 data
+= strnlen ((char *) data
, end
- data
) + 1;
1874 case DW_FORM_exprloc
:
1875 READ_ULEB (uvalue
, data
, end
);
1878 case DW_FORM_block1
:
1879 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1883 case DW_FORM_block2
:
1884 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1888 case DW_FORM_block4
:
1889 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1893 case DW_FORM_ref_sig8
:
1897 case DW_FORM_indirect
:
1898 /* FIXME: Handle this form. */
1903 * value_return
= uvalue
;
1905 data
= (unsigned char *) end
;
1909 /* Return IS_SIGNED set to TRUE if the type at
1910 DATA can be determined to be a signed type. */
1913 get_type_signedness (unsigned char * start
,
1914 unsigned char * data
,
1915 unsigned const char * end
,
1916 dwarf_vma pointer_size
,
1917 dwarf_vma offset_size
,
1919 bfd_boolean
* is_signed
,
1920 bfd_boolean is_nested
)
1922 unsigned long abbrev_number
;
1923 abbrev_entry
* entry
;
1926 * is_signed
= FALSE
;
1928 READ_ULEB (abbrev_number
, data
, end
);
1930 for (entry
= first_abbrev
;
1931 entry
!= NULL
&& entry
->entry
!= abbrev_number
;
1932 entry
= entry
->next
)
1936 /* FIXME: Issue a warning ? */
1939 for (attr
= entry
->first_attr
;
1940 attr
!= NULL
&& attr
->attribute
;
1943 dwarf_vma uvalue
= 0;
1945 data
= skip_attr_bytes (attr
->form
, data
, end
, pointer_size
,
1946 offset_size
, dwarf_version
, & uvalue
);
1950 switch (attr
->attribute
)
1952 #if 0 /* FIXME: It would be nice to print the name of the type,
1953 but this would mean updating a lot of binutils tests. */
1955 if (attr
->form
== DW_FORM_strp
)
1956 printf ("%s", fetch_indirect_string (uvalue
));
1963 /* FIXME: Warn - or is this expected ?
1964 NB/ We need to avoid infinite recursion. */
1967 if (uvalue
>= (size_t) (end
- start
))
1969 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
1970 offset_size
, dwarf_version
, is_signed
, TRUE
);
1973 case DW_AT_encoding
:
1974 /* Determine signness. */
1977 case DW_ATE_address
:
1978 /* FIXME - some architectures have signed addresses. */
1979 case DW_ATE_boolean
:
1980 case DW_ATE_unsigned
:
1981 case DW_ATE_unsigned_char
:
1982 case DW_ATE_unsigned_fixed
:
1983 * is_signed
= FALSE
;
1987 case DW_ATE_complex_float
:
1990 case DW_ATE_signed_char
:
1991 case DW_ATE_imaginary_float
:
1992 case DW_ATE_decimal_float
:
1993 case DW_ATE_signed_fixed
:
2003 read_and_print_leb128 (unsigned char * data
,
2004 unsigned int * bytes_read
,
2005 unsigned const char * end
,
2006 bfd_boolean is_signed
)
2009 dwarf_vma val
= read_leb128 (data
, end
, is_signed
, bytes_read
, &status
);
2011 report_leb_status (status
);
2013 printf ("%s", dwarf_vmatoa (is_signed
? "d" : "u", val
));
2017 display_discr_list (unsigned long form
,
2019 unsigned char * data
,
2020 unsigned const char * end
,
2025 printf ("[default]");
2032 case DW_FORM_block1
:
2033 case DW_FORM_block2
:
2034 case DW_FORM_block4
:
2035 /* Move data pointer back to the start of the byte array. */
2039 printf ("<corrupt>\n");
2040 warn (_("corrupt discr_list - not using a block form\n"));
2046 printf ("<corrupt>\n");
2047 warn (_("corrupt discr_list - block not long enough\n"));
2051 bfd_boolean is_signed
=
2052 (level
> 0 && level
<= MAX_CU_NESTING
)
2053 ? level_type_signed
[level
- 1] : FALSE
;
2058 unsigned char discriminant
;
2059 unsigned int bytes_read
;
2061 SAFE_BYTE_GET (discriminant
, data
, 1, end
);
2065 assert (uvalue
> 0);
2066 switch (discriminant
)
2070 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2071 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2072 uvalue
-= bytes_read
;
2078 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2079 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2080 uvalue
-= bytes_read
;
2084 read_and_print_leb128 (data
, & bytes_read
, end
, is_signed
);
2085 assert (bytes_read
<= uvalue
&& bytes_read
> 0);
2086 uvalue
-= bytes_read
;
2091 printf ("<corrupt>\n");
2092 warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"),
2102 printf (")(signed)");
2104 printf (")(unsigned)");
2107 static unsigned char *
2108 read_and_display_attr_value (unsigned long attribute
,
2110 dwarf_signed_vma implicit_const
,
2111 unsigned char * start
,
2112 unsigned char * data
,
2113 unsigned char * end
,
2114 dwarf_vma cu_offset
,
2115 dwarf_vma pointer_size
,
2116 dwarf_vma offset_size
,
2118 debug_info
* debug_info_p
,
2120 struct dwarf_section
* section
,
2121 struct cu_tu_set
* this_set
,
2125 dwarf_signed_vma svalue
;
2126 dwarf_vma uvalue
= 0;
2127 unsigned char * block_start
= NULL
;
2128 unsigned char * orig_data
= data
;
2130 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
2132 warn (_("Corrupt attribute\n"));
2141 case DW_FORM_ref_addr
:
2142 if (dwarf_version
== 2)
2143 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2144 else if (dwarf_version
== 3 || dwarf_version
== 4)
2145 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2147 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
2152 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
2156 case DW_FORM_line_strp
:
2157 case DW_FORM_sec_offset
:
2158 case DW_FORM_GNU_ref_alt
:
2159 case DW_FORM_GNU_strp_alt
:
2160 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
2163 case DW_FORM_flag_present
:
2170 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2175 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2180 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2184 READ_SLEB (svalue
, data
, end
);
2188 case DW_FORM_GNU_str_index
:
2189 case DW_FORM_ref_udata
:
2191 case DW_FORM_GNU_addr_index
:
2192 READ_ULEB (uvalue
, data
, end
);
2195 case DW_FORM_indirect
:
2196 READ_ULEB (form
, data
, end
);
2198 printf ("%c%s", delimiter
, get_FORM_name (form
));
2199 if (form
== DW_FORM_implicit_const
)
2200 READ_SLEB (implicit_const
, data
, end
);
2201 return read_and_display_attr_value (attribute
, form
, implicit_const
,
2203 cu_offset
, pointer_size
,
2204 offset_size
, dwarf_version
,
2205 debug_info_p
, do_loc
,
2206 section
, this_set
, delimiter
, level
);
2211 case DW_FORM_ref_addr
:
2213 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2216 case DW_FORM_GNU_ref_alt
:
2218 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
2219 /* FIXME: Follow the reference... */
2225 case DW_FORM_ref_udata
:
2227 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
2232 case DW_FORM_sec_offset
:
2234 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
2237 case DW_FORM_flag_present
:
2244 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
2247 case DW_FORM_implicit_const
:
2249 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
2256 dwarf_vma high_bits
;
2260 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2262 if (form
== DW_FORM_ref8
)
2263 add64 (& high_bits
, & utmp
, cu_offset
);
2264 printf ("%c0x%s", delimiter
,
2265 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
2268 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2269 && num_debug_info_entries
== 0)
2271 if (sizeof (uvalue
) == 8)
2272 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
2274 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
2280 case DW_FORM_data16
:
2283 dwarf_vma left_high_bits
, left_low_bits
;
2284 dwarf_vma right_high_bits
, right_low_bits
;
2286 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
2287 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
2288 if (byte_get
== byte_get_little_endian
)
2291 left_high_bits
^= right_high_bits
;
2292 right_high_bits
^= left_high_bits
;
2293 left_high_bits
^= right_high_bits
;
2294 left_low_bits
^= right_low_bits
;
2295 right_low_bits
^= left_low_bits
;
2296 left_low_bits
^= right_low_bits
;
2298 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
2299 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
2300 left_high_bits
, left_low_bits
, right_high_bits
,
2306 case DW_FORM_string
:
2308 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
2309 data
+= strnlen ((char *) data
, end
- data
) + 1;
2313 case DW_FORM_exprloc
:
2314 READ_ULEB (uvalue
, data
, end
);
2317 if (block_start
>= end
)
2319 warn (_("Block ends prematurely\n"));
2324 uvalue
= check_uvalue (block_start
, uvalue
, end
);
2327 data
= block_start
+ uvalue
;
2329 data
= display_block (block_start
, uvalue
, end
, delimiter
);
2332 case DW_FORM_block1
:
2333 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
2336 case DW_FORM_block2
:
2337 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
2340 case DW_FORM_block4
:
2341 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
2346 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
2347 dwarf_vmatoa ("x", uvalue
),
2348 fetch_indirect_string (uvalue
));
2351 case DW_FORM_line_strp
:
2353 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
2354 dwarf_vmatoa ("x", uvalue
),
2355 fetch_indirect_line_string (uvalue
));
2358 case DW_FORM_GNU_str_index
:
2361 const char * suffix
= strrchr (section
->name
, '.');
2362 bfd_boolean dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? TRUE
: FALSE
;
2364 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
2365 dwarf_vmatoa ("x", uvalue
),
2366 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
2370 case DW_FORM_GNU_strp_alt
:
2373 printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter
,
2374 dwarf_vmatoa ("x", uvalue
),
2375 fetch_alt_indirect_string (uvalue
));
2379 case DW_FORM_indirect
:
2380 /* Handled above. */
2383 case DW_FORM_ref_sig8
:
2386 dwarf_vma high_bits
;
2389 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2390 printf ("%csignature: 0x%s", delimiter
,
2391 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2396 case DW_FORM_GNU_addr_index
:
2398 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2399 dwarf_vmatoa ("x", uvalue
),
2400 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2404 warn (_("Unrecognized form: %lu\n"), form
);
2408 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2409 && num_debug_info_entries
== 0
2410 && debug_info_p
!= NULL
)
2414 case DW_AT_frame_base
:
2415 have_frame_base
= 1;
2417 case DW_AT_location
:
2418 case DW_AT_GNU_locviews
:
2419 case DW_AT_string_length
:
2420 case DW_AT_return_addr
:
2421 case DW_AT_data_member_location
:
2422 case DW_AT_vtable_elem_location
:
2424 case DW_AT_static_link
:
2425 case DW_AT_use_location
:
2426 case DW_AT_call_value
:
2427 case DW_AT_GNU_call_site_value
:
2428 case DW_AT_call_data_value
:
2429 case DW_AT_GNU_call_site_data_value
:
2430 case DW_AT_call_target
:
2431 case DW_AT_GNU_call_site_target
:
2432 case DW_AT_call_target_clobbered
:
2433 case DW_AT_GNU_call_site_target_clobbered
:
2434 if ((dwarf_version
< 4
2435 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2436 || form
== DW_FORM_sec_offset
)
2438 /* Process location list. */
2439 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2440 unsigned int num
= debug_info_p
->num_loc_offsets
;
2442 if (lmax
== 0 || num
>= lmax
)
2445 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2446 xcrealloc (debug_info_p
->loc_offsets
,
2447 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2448 debug_info_p
->loc_views
= (dwarf_vma
*)
2449 xcrealloc (debug_info_p
->loc_views
,
2450 lmax
, sizeof (*debug_info_p
->loc_views
));
2451 debug_info_p
->have_frame_base
= (int *)
2452 xcrealloc (debug_info_p
->have_frame_base
,
2453 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2454 debug_info_p
->max_loc_offsets
= lmax
;
2456 if (this_set
!= NULL
)
2457 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2458 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2459 if (attribute
!= DW_AT_GNU_locviews
)
2461 /* Corrupt DWARF info can produce more offsets than views.
2462 See PR 23062 for an example. */
2463 if (debug_info_p
->num_loc_offsets
2464 > debug_info_p
->num_loc_views
)
2465 warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n"));
2468 debug_info_p
->loc_offsets
[num
] = uvalue
;
2469 debug_info_p
->num_loc_offsets
++;
2474 assert (debug_info_p
->num_loc_views
<= num
);
2475 num
= debug_info_p
->num_loc_views
;
2476 if (num
> debug_info_p
->num_loc_offsets
)
2477 warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n"));
2480 debug_info_p
->loc_views
[num
] = uvalue
;
2481 debug_info_p
->num_loc_views
++;
2488 if (need_base_address
)
2489 debug_info_p
->base_address
= uvalue
;
2492 case DW_AT_GNU_addr_base
:
2493 debug_info_p
->addr_base
= uvalue
;
2496 case DW_AT_GNU_ranges_base
:
2497 debug_info_p
->ranges_base
= uvalue
;
2501 if ((dwarf_version
< 4
2502 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2503 || form
== DW_FORM_sec_offset
)
2505 /* Process range list. */
2506 unsigned int lmax
= debug_info_p
->max_range_lists
;
2507 unsigned int num
= debug_info_p
->num_range_lists
;
2509 if (lmax
== 0 || num
>= lmax
)
2512 debug_info_p
->range_lists
= (dwarf_vma
*)
2513 xcrealloc (debug_info_p
->range_lists
,
2514 lmax
, sizeof (*debug_info_p
->range_lists
));
2515 debug_info_p
->max_range_lists
= lmax
;
2517 debug_info_p
->range_lists
[num
] = uvalue
;
2518 debug_info_p
->num_range_lists
++;
2522 case DW_AT_GNU_dwo_name
:
2523 case DW_AT_dwo_name
:
2528 add_dwo_name ((const char *) fetch_indirect_string (uvalue
));
2530 case DW_FORM_GNU_str_index
:
2531 add_dwo_name (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2533 case DW_FORM_string
:
2534 add_dwo_name ((const char *) orig_data
);
2537 warn (_("Unsupported form (%s) for attribute %s\n"),
2538 get_FORM_name (form
), get_AT_name (attribute
));
2543 case DW_AT_comp_dir
:
2544 /* FIXME: Also extract a build-id in a CU/TU. */
2549 add_dwo_dir ((const char *) fetch_indirect_string (uvalue
));
2551 case DW_FORM_line_strp
:
2552 add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue
));
2554 case DW_FORM_GNU_str_index
:
2555 add_dwo_dir (fetch_indexed_string (uvalue
, this_set
, offset_size
, FALSE
));
2557 case DW_FORM_string
:
2558 add_dwo_dir ((const char *) orig_data
);
2561 warn (_("Unsupported form (%s) for attribute %s\n"),
2562 get_FORM_name (form
), get_AT_name (attribute
));
2567 case DW_AT_GNU_dwo_id
:
2572 /* FIXME: Record the length of the ID as well ? */
2573 add_dwo_id ((const char *) (data
- 8));
2576 warn (_("Unsupported form (%s) for attribute %s\n"),
2577 get_FORM_name (form
), get_AT_name (attribute
));
2587 if (do_loc
|| attribute
== 0)
2590 /* For some attributes we can display further information. */
2594 if (level
>= 0 && level
< MAX_CU_NESTING
2595 && uvalue
< (size_t) (end
- start
))
2597 bfd_boolean is_signed
= FALSE
;
2599 get_type_signedness (start
, start
+ uvalue
, end
, pointer_size
,
2600 offset_size
, dwarf_version
, & is_signed
, FALSE
);
2601 level_type_signed
[level
] = is_signed
;
2609 case DW_INL_not_inlined
:
2610 printf (_("(not inlined)"));
2612 case DW_INL_inlined
:
2613 printf (_("(inlined)"));
2615 case DW_INL_declared_not_inlined
:
2616 printf (_("(declared as inline but ignored)"));
2618 case DW_INL_declared_inlined
:
2619 printf (_("(declared as inline and inlined)"));
2622 printf (_(" (Unknown inline attribute value: %s)"),
2623 dwarf_vmatoa ("x", uvalue
));
2628 case DW_AT_language
:
2632 /* Ordered by the numeric value of these constants. */
2633 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2634 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2635 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2636 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2637 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2638 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2639 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2640 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2641 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2642 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2643 /* DWARF 2.1 values. */
2644 case DW_LANG_Java
: printf ("(Java)"); break;
2645 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2646 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2647 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2648 /* DWARF 3 values. */
2649 case DW_LANG_PLI
: printf ("(PLI)"); break;
2650 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2651 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2652 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2653 case DW_LANG_D
: printf ("(D)"); break;
2654 /* DWARF 4 values. */
2655 case DW_LANG_Python
: printf ("(Python)"); break;
2656 /* DWARF 5 values. */
2657 case DW_LANG_OpenCL
: printf ("(OpenCL)"); break;
2658 case DW_LANG_Go
: printf ("(Go)"); break;
2659 case DW_LANG_Modula3
: printf ("(Modula 3)"); break;
2660 case DW_LANG_Haskell
: printf ("(Haskell)"); break;
2661 case DW_LANG_C_plus_plus_03
: printf ("(C++03)"); break;
2662 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2663 case DW_LANG_OCaml
: printf ("(OCaml)"); break;
2664 case DW_LANG_Rust
: printf ("(Rust)"); break;
2665 case DW_LANG_C11
: printf ("(C11)"); break;
2666 case DW_LANG_Swift
: printf ("(Swift)"); break;
2667 case DW_LANG_Julia
: printf ("(Julia)"); break;
2668 case DW_LANG_Dylan
: printf ("(Dylan)"); break;
2669 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2670 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2671 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2672 case DW_LANG_RenderScript
: printf ("(RenderScript)"); break;
2673 /* MIPS extension. */
2674 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2675 /* UPC extension. */
2676 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2678 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2679 printf (_("(implementation defined: %s)"),
2680 dwarf_vmatoa ("x", uvalue
));
2682 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2687 case DW_AT_encoding
:
2691 case DW_ATE_void
: printf ("(void)"); break;
2692 case DW_ATE_address
: printf ("(machine address)"); break;
2693 case DW_ATE_boolean
: printf ("(boolean)"); break;
2694 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2695 case DW_ATE_float
: printf ("(float)"); break;
2696 case DW_ATE_signed
: printf ("(signed)"); break;
2697 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2698 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2699 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2700 /* DWARF 2.1 values: */
2701 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2702 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2703 /* DWARF 3 values: */
2704 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2705 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2706 case DW_ATE_edited
: printf ("(edited)"); break;
2707 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2708 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2709 /* DWARF 4 values: */
2710 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2711 /* DWARF 5 values: */
2712 case DW_ATE_UCS
: printf ("(UCS)"); break;
2713 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
2715 /* HP extensions: */
2716 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2717 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2718 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2719 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2720 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2721 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2722 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2725 if (uvalue
>= DW_ATE_lo_user
2726 && uvalue
<= DW_ATE_hi_user
)
2727 printf (_("(user defined type)"));
2729 printf (_("(unknown type)"));
2734 case DW_AT_accessibility
:
2738 case DW_ACCESS_public
: printf ("(public)"); break;
2739 case DW_ACCESS_protected
: printf ("(protected)"); break;
2740 case DW_ACCESS_private
: printf ("(private)"); break;
2742 printf (_("(unknown accessibility)"));
2747 case DW_AT_visibility
:
2751 case DW_VIS_local
: printf ("(local)"); break;
2752 case DW_VIS_exported
: printf ("(exported)"); break;
2753 case DW_VIS_qualified
: printf ("(qualified)"); break;
2754 default: printf (_("(unknown visibility)")); break;
2758 case DW_AT_endianity
:
2762 case DW_END_default
: printf ("(default)"); break;
2763 case DW_END_big
: printf ("(big)"); break;
2764 case DW_END_little
: printf ("(little)"); break;
2766 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
2767 printf (_("(user specified)"));
2769 printf (_("(unknown endianity)"));
2774 case DW_AT_virtuality
:
2778 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2779 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2780 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2781 default: printf (_("(unknown virtuality)")); break;
2785 case DW_AT_identifier_case
:
2789 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2790 case DW_ID_up_case
: printf ("(up_case)"); break;
2791 case DW_ID_down_case
: printf ("(down_case)"); break;
2792 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2793 default: printf (_("(unknown case)")); break;
2797 case DW_AT_calling_convention
:
2801 case DW_CC_normal
: printf ("(normal)"); break;
2802 case DW_CC_program
: printf ("(program)"); break;
2803 case DW_CC_nocall
: printf ("(nocall)"); break;
2804 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
2805 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
2806 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
2807 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
2809 if (uvalue
>= DW_CC_lo_user
2810 && uvalue
<= DW_CC_hi_user
)
2811 printf (_("(user defined)"));
2813 printf (_("(unknown convention)"));
2817 case DW_AT_ordering
:
2822 case -1: printf (_("(undefined)")); break;
2823 case 0: printf ("(row major)"); break;
2824 case 1: printf ("(column major)"); break;
2828 case DW_AT_decimal_sign
:
2832 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
2833 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
2834 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
2835 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
2836 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
2837 default: printf (_("(unrecognised)")); break;
2841 case DW_AT_defaulted
:
2845 case DW_DEFAULTED_no
: printf (_("(no)")); break;
2846 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
2847 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
2848 default: printf (_("(unrecognised)")); break;
2852 case DW_AT_discr_list
:
2854 display_discr_list (form
, uvalue
, data
, end
, level
);
2857 case DW_AT_frame_base
:
2858 have_frame_base
= 1;
2860 case DW_AT_location
:
2861 case DW_AT_string_length
:
2862 case DW_AT_return_addr
:
2863 case DW_AT_data_member_location
:
2864 case DW_AT_vtable_elem_location
:
2866 case DW_AT_static_link
:
2867 case DW_AT_use_location
:
2868 case DW_AT_call_value
:
2869 case DW_AT_GNU_call_site_value
:
2870 case DW_AT_call_data_value
:
2871 case DW_AT_GNU_call_site_data_value
:
2872 case DW_AT_call_target
:
2873 case DW_AT_GNU_call_site_target
:
2874 case DW_AT_call_target_clobbered
:
2875 case DW_AT_GNU_call_site_target_clobbered
:
2876 if ((dwarf_version
< 4
2877 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2878 || form
== DW_FORM_sec_offset
)
2879 printf (_(" (location list)"));
2881 case DW_AT_allocated
:
2882 case DW_AT_associated
:
2883 case DW_AT_data_location
:
2885 case DW_AT_upper_bound
:
2886 case DW_AT_lower_bound
:
2889 int need_frame_base
;
2892 need_frame_base
= decode_location_expression (block_start
,
2897 cu_offset
, section
);
2899 if (need_frame_base
&& !have_frame_base
)
2900 printf (_(" [without DW_AT_frame_base]"));
2904 case DW_AT_data_bit_offset
:
2905 case DW_AT_byte_size
:
2906 case DW_AT_bit_size
:
2907 case DW_AT_string_length_byte_size
:
2908 case DW_AT_string_length_bit_size
:
2909 case DW_AT_bit_stride
:
2910 if (form
== DW_FORM_exprloc
)
2913 (void) decode_location_expression (block_start
, pointer_size
,
2914 offset_size
, dwarf_version
,
2915 uvalue
, cu_offset
, section
);
2922 if (form
== DW_FORM_ref_sig8
2923 || form
== DW_FORM_GNU_ref_alt
)
2926 if (form
== DW_FORM_ref1
2927 || form
== DW_FORM_ref2
2928 || form
== DW_FORM_ref4
2929 || form
== DW_FORM_ref_udata
)
2930 uvalue
+= cu_offset
;
2932 if (uvalue
>= section
->size
)
2933 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2934 dwarf_vmatoa ("x", uvalue
),
2935 (unsigned long) (orig_data
- section
->start
));
2938 unsigned long abbrev_number
;
2939 abbrev_entry
*entry
;
2940 unsigned char *p
= section
->start
+ uvalue
;
2942 READ_ULEB (abbrev_number
, p
, end
);
2944 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2945 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2946 use different abbrev table, and we don't track .debug_info chunks
2948 if (form
!= DW_FORM_ref_addr
)
2950 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2951 if (entry
->entry
== abbrev_number
)
2954 printf (" (%s)", get_TAG_name (entry
->tag
));
2968 static unsigned char *
2969 read_and_display_attr (unsigned long attribute
,
2971 dwarf_signed_vma implicit_const
,
2972 unsigned char * start
,
2973 unsigned char * data
,
2974 unsigned char * end
,
2975 dwarf_vma cu_offset
,
2976 dwarf_vma pointer_size
,
2977 dwarf_vma offset_size
,
2979 debug_info
* debug_info_p
,
2981 struct dwarf_section
* section
,
2982 struct cu_tu_set
* this_set
,
2986 printf (" %-18s:", get_AT_name (attribute
));
2987 data
= read_and_display_attr_value (attribute
, form
, implicit_const
,
2989 cu_offset
, pointer_size
, offset_size
,
2990 dwarf_version
, debug_info_p
,
2991 do_loc
, section
, this_set
, ' ', level
);
2997 /* Like load_debug_section, but if the ordinary call fails, and we are
2998 following debug links, then attempt to load the requested section
2999 from one of the separate debug info files. */
3002 load_debug_section_with_follow (enum dwarf_section_display_enum sec_enum
,
3005 if (load_debug_section (sec_enum
, handle
))
3007 if (debug_displays
[sec_enum
].section
.filename
== NULL
)
3009 /* See if we can associate a filename with this section. */
3012 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3013 if (i
->handle
== handle
)
3015 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3023 if (do_follow_links
)
3027 for (i
= first_separate_info
; i
!= NULL
; i
= i
->next
)
3029 if (load_debug_section (sec_enum
, i
->handle
))
3031 debug_displays
[sec_enum
].section
.filename
= i
->filename
;
3033 /* FIXME: We should check to see if any of the remaining debug info
3034 files also contain this section, and, umm, do something about it. */
3044 introduce (struct dwarf_section
* section
, bfd_boolean raw
)
3048 if (do_follow_links
&& section
->filename
)
3049 printf (_("Raw dump of debug contents of section %s (loaded from %s):\n\n"),
3050 section
->name
, section
->filename
);
3052 printf (_("Raw dump of debug contents of section %s:\n\n"), section
->name
);
3056 if (do_follow_links
&& section
->filename
)
3057 printf (_("Contents of the %s section (loaded from %s):\n\n"),
3058 section
->name
, section
->filename
);
3060 printf (_("Contents of the %s section:\n\n"), section
->name
);
3064 /* Process the contents of a .debug_info section.
3065 If do_loc is TRUE then we are scanning for location lists and dwo tags
3066 and we do not want to display anything to the user.
3067 If do_types is TRUE, we are processing a .debug_types section instead of
3068 a .debug_info section.
3069 The information displayed is restricted by the values in DWARF_START_DIE
3070 and DWARF_CUTOFF_LEVEL.
3071 Returns TRUE upon success. Otherwise an error or warning message is
3072 printed and FALSE is returned. */
3075 process_debug_info (struct dwarf_section
* section
,
3077 enum dwarf_section_display_enum abbrev_sec
,
3079 bfd_boolean do_types
)
3081 unsigned char *start
= section
->start
;
3082 unsigned char *end
= start
+ section
->size
;
3083 unsigned char *section_begin
;
3085 unsigned int num_units
= 0;
3087 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3088 && num_debug_info_entries
== 0
3093 /* First scan the section to get the number of comp units. */
3094 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
3097 /* Read the first 4 bytes. For a 32-bit DWARF section, this
3098 will be the length. For a 64-bit DWARF section, it'll be
3099 the escape code 0xffffffff followed by an 8 byte length. */
3100 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
3102 if (length
== 0xffffffff)
3104 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
3105 section_begin
+= length
+ 12;
3107 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
3109 warn (_("Reserved length value (0x%s) found in section %s\n"),
3110 dwarf_vmatoa ("x", length
), section
->name
);
3114 section_begin
+= length
+ 4;
3116 /* Negative values are illegal, they may even cause infinite
3117 looping. This can happen if we can't accurately apply
3118 relocations to an object file, or if the file is corrupt. */
3119 if ((signed long) length
<= 0 || section_begin
< start
)
3121 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
3122 dwarf_vmatoa ("x", length
), section
->name
);
3129 error (_("No comp units in %s section ?\n"), section
->name
);
3133 /* Then allocate an array to hold the information. */
3134 debug_information
= (debug_info
*) cmalloc (num_units
,
3135 sizeof (* debug_information
));
3136 if (debug_information
== NULL
)
3138 error (_("Not enough memory for a debug info array of %u entries\n"),
3140 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
3144 /* PR 17531: file: 92ca3797.
3145 We cannot rely upon the debug_information array being initialised
3146 before it is used. A corrupt file could easily contain references
3147 to a unit for which information has not been made available. So
3148 we ensure that the array is zeroed here. */
3149 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
3151 alloc_num_debug_info_entries
= num_units
;
3156 load_debug_section_with_follow (str
, file
);
3157 load_debug_section_with_follow (line_str
, file
);
3158 load_debug_section_with_follow (str_dwo
, file
);
3159 load_debug_section_with_follow (str_index
, file
);
3160 load_debug_section_with_follow (str_index_dwo
, file
);
3161 load_debug_section_with_follow (debug_addr
, file
);
3164 load_debug_section_with_follow (abbrev_sec
, file
);
3165 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
3167 warn (_("Unable to locate %s section!\n"),
3168 debug_displays
[abbrev_sec
].section
.uncompressed_name
);
3172 if (!do_loc
&& dwarf_start_die
== 0)
3173 introduce (section
, FALSE
);
3175 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
3177 DWARF2_Internal_CompUnit compunit
;
3178 unsigned char *hdrptr
;
3179 unsigned char *tags
;
3180 int level
, last_level
, saved_level
;
3181 dwarf_vma cu_offset
;
3182 unsigned long sec_off
;
3183 unsigned int offset_size
;
3184 unsigned int initial_length_size
;
3185 dwarf_vma signature_high
= 0;
3186 dwarf_vma signature_low
= 0;
3187 dwarf_vma type_offset
= 0;
3188 struct cu_tu_set
*this_set
;
3189 dwarf_vma abbrev_base
;
3194 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
3196 if (compunit
.cu_length
== 0xffffffff)
3198 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
3200 initial_length_size
= 12;
3205 initial_length_size
= 4;
3208 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
3210 cu_offset
= start
- section_begin
;
3212 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
3214 if (compunit
.cu_version
< 5)
3216 compunit
.cu_unit_type
= DW_UT_compile
;
3217 /* Initialize it due to a false compiler warning. */
3218 compunit
.cu_pointer_size
= -1;
3222 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
3223 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
3225 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3228 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
3230 if (this_set
== NULL
)
3233 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
3237 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
3238 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
3241 if (compunit
.cu_version
< 5)
3242 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
3244 /* PR 17512: file: 001-108546-0.001:0.1. */
3245 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
3247 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
3248 compunit
.cu_pointer_size
, offset_size
);
3249 compunit
.cu_pointer_size
= offset_size
;
3254 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
3256 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
3259 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
3260 + initial_length_size
))
3262 start
= section_begin
+ cu_offset
+ compunit
.cu_length
3263 + initial_length_size
;
3267 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3268 && num_debug_info_entries
== 0
3271 debug_information
[unit
].cu_offset
= cu_offset
;
3272 debug_information
[unit
].pointer_size
3273 = compunit
.cu_pointer_size
;
3274 debug_information
[unit
].offset_size
= offset_size
;
3275 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
3276 debug_information
[unit
].base_address
= 0;
3277 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
3278 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
3279 debug_information
[unit
].loc_offsets
= NULL
;
3280 debug_information
[unit
].have_frame_base
= NULL
;
3281 debug_information
[unit
].max_loc_offsets
= 0;
3282 debug_information
[unit
].num_loc_offsets
= 0;
3283 debug_information
[unit
].range_lists
= NULL
;
3284 debug_information
[unit
].max_range_lists
= 0;
3285 debug_information
[unit
].num_range_lists
= 0;
3288 if (!do_loc
&& dwarf_start_die
== 0)
3290 printf (_(" Compilation Unit @ offset 0x%s:\n"),
3291 dwarf_vmatoa ("x", cu_offset
));
3292 printf (_(" Length: 0x%s (%s)\n"),
3293 dwarf_vmatoa ("x", compunit
.cu_length
),
3294 offset_size
== 8 ? "64-bit" : "32-bit");
3295 printf (_(" Version: %d\n"), compunit
.cu_version
);
3296 printf (_(" Abbrev Offset: 0x%s\n"),
3297 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
3298 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
3303 printf (_(" Signature: 0x%s\n"),
3304 dwarf_vmatoa64 (signature_high
, signature_low
,
3305 buf
, sizeof (buf
)));
3306 printf (_(" Type Offset: 0x%s\n"),
3307 dwarf_vmatoa ("x", type_offset
));
3309 if (this_set
!= NULL
)
3311 dwarf_vma
*offsets
= this_set
->section_offsets
;
3312 size_t *sizes
= this_set
->section_sizes
;
3314 printf (_(" Section contributions:\n"));
3315 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
3316 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
3317 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
3318 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
3319 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
3320 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
3321 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
3322 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
3323 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
3324 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
3325 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
3326 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
3330 sec_off
= cu_offset
+ initial_length_size
;
3331 if (sec_off
+ compunit
.cu_length
< sec_off
3332 || sec_off
+ compunit
.cu_length
> section
->size
)
3334 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
3336 (unsigned long) cu_offset
,
3337 dwarf_vmatoa ("x", compunit
.cu_length
));
3343 start
+= compunit
.cu_length
+ initial_length_size
;
3345 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
3347 warn (_("CU at offset %s contains corrupt or "
3348 "unsupported version number: %d.\n"),
3349 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
3353 if (compunit
.cu_unit_type
!= DW_UT_compile
3354 && compunit
.cu_unit_type
!= DW_UT_type
)
3356 warn (_("CU at offset %s contains corrupt or "
3357 "unsupported unit type: %d.\n"),
3358 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
3364 /* Process the abbrevs used by this compilation unit. */
3365 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
3366 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
3367 (unsigned long) compunit
.cu_abbrev_offset
,
3368 (unsigned long) abbrev_size
);
3369 /* PR 17531: file:4bcd9ce9. */
3370 else if ((abbrev_base
+ abbrev_size
)
3371 > debug_displays
[abbrev_sec
].section
.size
)
3372 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
3373 (unsigned long) abbrev_base
+ abbrev_size
,
3374 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
3376 process_abbrev_section
3377 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3378 + abbrev_base
+ compunit
.cu_abbrev_offset
),
3379 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
3380 + abbrev_base
+ abbrev_size
));
3385 while (tags
< start
)
3387 unsigned long abbrev_number
;
3388 unsigned long die_offset
;
3389 abbrev_entry
*entry
;
3391 int do_printing
= 1;
3393 die_offset
= tags
- section_begin
;
3395 READ_ULEB (abbrev_number
, tags
, start
);
3397 /* A null DIE marks the end of a list of siblings or it may also be
3398 a section padding. */
3399 if (abbrev_number
== 0)
3401 /* Check if it can be a section padding for the last CU. */
3402 if (level
== 0 && start
== end
)
3406 for (chk
= tags
; chk
< start
; chk
++)
3413 if (!do_loc
&& die_offset
>= dwarf_start_die
3414 && (dwarf_cutoff_level
== -1
3415 || level
< dwarf_cutoff_level
))
3416 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
3422 static unsigned num_bogus_warns
= 0;
3424 if (num_bogus_warns
< 3)
3426 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
3427 die_offset
, section
->name
);
3429 if (num_bogus_warns
== 3)
3430 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
3433 if (dwarf_start_die
!= 0 && level
< saved_level
)
3440 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
3444 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
3445 saved_level
= level
;
3446 do_printing
= (dwarf_cutoff_level
== -1
3447 || level
< dwarf_cutoff_level
);
3449 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
3450 level
, die_offset
, abbrev_number
);
3451 else if (dwarf_cutoff_level
== -1
3452 || last_level
< dwarf_cutoff_level
)
3453 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
3458 /* Scan through the abbreviation list until we reach the
3460 for (entry
= first_abbrev
;
3461 entry
&& entry
->entry
!= abbrev_number
;
3462 entry
= entry
->next
)
3467 if (!do_loc
&& do_printing
)
3472 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
3473 die_offset
, abbrev_number
);
3477 if (!do_loc
&& do_printing
)
3478 printf (" (%s)\n", get_TAG_name (entry
->tag
));
3483 need_base_address
= 0;
3485 case DW_TAG_compile_unit
:
3486 need_base_address
= 1;
3487 need_dwo_info
= do_loc
;
3489 case DW_TAG_entry_point
:
3490 case DW_TAG_subprogram
:
3491 need_base_address
= 0;
3492 /* Assuming that there is no DW_AT_frame_base. */
3493 have_frame_base
= 0;
3497 debug_info
*debug_info_p
=
3498 (debug_information
&& unit
< alloc_num_debug_info_entries
)
3499 ? debug_information
+ unit
: NULL
;
3501 assert (!debug_info_p
3502 || (debug_info_p
->num_loc_offsets
3503 == debug_info_p
->num_loc_views
));
3505 for (attr
= entry
->first_attr
;
3506 attr
&& attr
->attribute
;
3509 if (! do_loc
&& do_printing
)
3510 /* Show the offset from where the tag was extracted. */
3511 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
3512 tags
= read_and_display_attr (attr
->attribute
,
3514 attr
->implicit_const
,
3519 compunit
.cu_pointer_size
,
3521 compunit
.cu_version
,
3523 do_loc
|| ! do_printing
,
3529 /* If a locview attribute appears before a location one,
3530 make sure we don't associate it with an earlier
3533 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3536 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3537 debug_info_p
->num_loc_views
++;
3538 assert (debug_info_p
->num_loc_views
3539 == debug_info_p
->num_loc_offsets
);
3546 warn(_("DIE has locviews without loclist\n"));
3547 debug_info_p
->num_loc_views
--;
3554 if (entry
->children
)
3559 /* Set num_debug_info_entries here so that it can be used to check if
3560 we need to process .debug_loc and .debug_ranges sections. */
3561 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3562 && num_debug_info_entries
== 0
3565 if (num_units
> alloc_num_debug_info_entries
)
3566 num_debug_info_entries
= alloc_num_debug_info_entries
;
3568 num_debug_info_entries
= num_units
;
3577 /* Locate and scan the .debug_info section in the file and record the pointer
3578 sizes and offsets for the compilation units in it. Usually an executable
3579 will have just one pointer size, but this is not guaranteed, and so we try
3580 not to make any assumptions. Returns zero upon failure, or the number of
3581 compilation units upon success. */
3584 load_debug_info (void * file
)
3586 /* If we have already tried and failed to load the .debug_info
3587 section then do not bother to repeat the task. */
3588 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3591 /* If we already have the information there is nothing else to do. */
3592 if (num_debug_info_entries
> 0)
3593 return num_debug_info_entries
;
3595 /* If this is a DWARF package file, load the CU and TU indexes. */
3596 (void) load_cu_tu_indexes (file
);
3598 if (load_debug_section_with_follow (info
, file
)
3599 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
3600 return num_debug_info_entries
;
3602 if (load_debug_section_with_follow (info_dwo
, file
)
3603 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3604 abbrev_dwo
, TRUE
, FALSE
))
3605 return num_debug_info_entries
;
3607 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3611 /* Read a DWARF .debug_line section header starting at DATA.
3612 Upon success returns an updated DATA pointer and the LINFO
3613 structure and the END_OF_SEQUENCE pointer will be filled in.
3614 Otherwise returns NULL. */
3616 static unsigned char *
3617 read_debug_line_header (struct dwarf_section
* section
,
3618 unsigned char * data
,
3619 unsigned char * end
,
3620 DWARF2_Internal_LineInfo
* linfo
,
3621 unsigned char ** end_of_sequence
)
3623 unsigned char *hdrptr
;
3624 unsigned int initial_length_size
;
3625 unsigned char address_size
, segment_selector_size
;
3627 /* Extract information from the Line Number Program Header.
3628 (section 6.2.4 in the Dwarf3 doc). */
3631 /* Get and check the length of the block. */
3632 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
3634 if (linfo
->li_length
== 0xffffffff)
3636 /* This section is 64-bit DWARF 3. */
3637 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
3638 linfo
->li_offset_size
= 8;
3639 initial_length_size
= 12;
3643 linfo
->li_offset_size
= 4;
3644 initial_length_size
= 4;
3647 if (linfo
->li_length
+ initial_length_size
> section
->size
)
3649 /* If the length field has a relocation against it, then we should
3650 not complain if it is inaccurate (and probably negative). This
3651 happens in object files when the .debug_line section is actually
3652 comprised of several different .debug_line.* sections, (some of
3653 which may be removed by linker garbage collection), and a relocation
3654 is used to compute the correct length once that is done. */
3655 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
3657 linfo
->li_length
= (end
- data
) - initial_length_size
;
3661 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3662 (long) linfo
->li_length
);
3667 /* Get and check the version number. */
3668 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
3670 if (linfo
->li_version
!= 2
3671 && linfo
->li_version
!= 3
3672 && linfo
->li_version
!= 4
3673 && linfo
->li_version
!= 5)
3675 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3676 "is currently supported.\n"));
3680 if (linfo
->li_version
>= 5)
3682 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
3684 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
3685 if (segment_selector_size
!= 0)
3687 warn (_("The %s section contains "
3688 "unsupported segment selector size: %d.\n"),
3689 section
->name
, segment_selector_size
);
3694 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
3695 linfo
->li_offset_size
, end
);
3696 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
3698 if (linfo
->li_version
>= 4)
3700 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
3702 if (linfo
->li_max_ops_per_insn
== 0)
3704 warn (_("Invalid maximum operations per insn.\n"));
3709 linfo
->li_max_ops_per_insn
= 1;
3711 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
3712 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
3713 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
3714 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
3716 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
3717 /* PR 17512: file:002-117414-0.004. */
3718 if (* end_of_sequence
> end
)
3720 warn (_("Line length %s extends beyond end of section\n"),
3721 dwarf_vmatoa ("u", linfo
->li_length
));
3722 * end_of_sequence
= end
;
3729 static unsigned char *
3730 display_formatted_table (unsigned char * data
,
3731 unsigned char * start
,
3732 unsigned char * end
,
3733 const DWARF2_Internal_LineInfo
* linfo
,
3734 struct dwarf_section
* section
,
3737 unsigned char *format_start
, format_count
, *format
, formati
;
3738 dwarf_vma data_count
, datai
;
3739 unsigned int namepass
, last_entry
= 0;
3741 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3742 format_start
= data
;
3743 for (formati
= 0; formati
< format_count
; formati
++)
3745 SKIP_ULEB (data
, end
);
3746 SKIP_ULEB (data
, end
);
3750 warn (_("Corrupt directory format table entry\n"));
3752 warn (_("Corrupt file name format table entry\n"));
3757 READ_ULEB (data_count
, data
, end
);
3761 warn (_("Corrupt directory list\n"));
3763 warn (_("Corrupt file name list\n"));
3767 if (data_count
== 0)
3770 printf (_("\n The Directory Table is empty.\n"));
3772 printf (_("\n The File Name Table is empty.\n"));
3777 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3778 (long) (data
- start
));
3780 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3781 (long) (data
- start
));
3783 printf (_(" Entry"));
3784 /* Delay displaying name as the last entry for better screen layout. */
3785 for (namepass
= 0; namepass
< 2; namepass
++)
3787 format
= format_start
;
3788 for (formati
= 0; formati
< format_count
; formati
++)
3790 dwarf_vma content_type
;
3792 READ_ULEB (content_type
, format
, end
);
3793 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
3794 switch (content_type
)
3797 printf (_("\tName"));
3799 case DW_LNCT_directory_index
:
3800 printf (_("\tDir"));
3802 case DW_LNCT_timestamp
:
3803 printf (_("\tTime"));
3806 printf (_("\tSize"));
3809 printf (_("\tMD5"));
3812 printf (_("\t(Unknown format content type %s)"),
3813 dwarf_vmatoa ("u", content_type
));
3815 SKIP_ULEB (format
, end
);
3820 for (datai
= 0; datai
< data_count
; datai
++)
3822 unsigned char *datapass
= data
;
3824 printf (" %d", last_entry
++);
3825 /* Delay displaying name as the last entry for better screen layout. */
3826 for (namepass
= 0; namepass
< 2; namepass
++)
3828 format
= format_start
;
3830 for (formati
= 0; formati
< format_count
; formati
++)
3832 dwarf_vma content_type
, form
;
3834 READ_ULEB (content_type
, format
, end
);
3835 READ_ULEB (form
, format
, end
);
3836 data
= read_and_display_attr_value (0, form
, 0, start
, data
, end
,
3837 0, 0, linfo
->li_offset_size
,
3838 linfo
->li_version
, NULL
,
3839 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3840 section
, NULL
, '\t', -1);
3846 warn (_("Corrupt directory entries list\n"));
3848 warn (_("Corrupt file name entries list\n"));
3857 display_debug_lines_raw (struct dwarf_section
* section
,
3858 unsigned char * data
,
3859 unsigned char * end
,
3862 unsigned char *start
= section
->start
;
3863 int verbose_view
= 0;
3865 introduce (section
, TRUE
);
3869 static DWARF2_Internal_LineInfo saved_linfo
;
3870 DWARF2_Internal_LineInfo linfo
;
3871 unsigned char *standard_opcodes
;
3872 unsigned char *end_of_sequence
;
3875 if (const_strneq (section
->name
, ".debug_line.")
3876 /* Note: the following does not apply to .debug_line.dwo sections.
3877 These are full debug_line sections. */
3878 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3880 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3881 section containing just the Line Number Statements. They are
3882 created by the assembler and intended to be used alongside gcc's
3883 -ffunction-sections command line option. When the linker's
3884 garbage collection decides to discard a .text.<foo> section it
3885 can then also discard the line number information in .debug_line.<foo>.
3887 Since the section is a fragment it does not have the details
3888 needed to fill out a LineInfo structure, so instead we use the
3889 details from the last full debug_line section that we processed. */
3890 end_of_sequence
= end
;
3891 standard_opcodes
= NULL
;
3892 linfo
= saved_linfo
;
3893 /* PR 17531: file: 0522b371. */
3894 if (linfo
.li_line_range
== 0)
3896 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3899 reset_state_machine (linfo
.li_default_is_stmt
);
3903 unsigned char * hdrptr
;
3905 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3906 & end_of_sequence
)) == NULL
)
3909 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
3910 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
3911 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
3912 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
3913 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
3914 if (linfo
.li_version
>= 4)
3915 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
3916 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
3917 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
3918 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
3919 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
3921 /* PR 17512: file: 1665-6428-0.004. */
3922 if (linfo
.li_line_range
== 0)
3924 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3925 linfo
.li_line_range
= 1;
3928 reset_state_machine (linfo
.li_default_is_stmt
);
3930 /* Display the contents of the Opcodes table. */
3931 standard_opcodes
= hdrptr
;
3933 /* PR 17512: file: 002-417945-0.004. */
3934 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
3936 warn (_("Line Base extends beyond end of section\n"));
3940 printf (_("\n Opcodes:\n"));
3942 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
3943 printf (ngettext (" Opcode %d has %d arg\n",
3944 " Opcode %d has %d args\n",
3945 standard_opcodes
[i
- 1]),
3946 i
, standard_opcodes
[i
- 1]);
3948 /* Display the contents of the Directory table. */
3949 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3951 if (linfo
.li_version
>= 5)
3953 load_debug_section_with_follow (line_str
, file
);
3955 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3957 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3963 printf (_("\n The Directory Table is empty.\n"));
3966 unsigned int last_dir_entry
= 0;
3968 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3969 (long)(data
- start
));
3971 while (data
< end
&& *data
!= 0)
3973 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
3975 data
+= strnlen ((char *) data
, end
- data
) + 1;
3978 /* PR 17512: file: 002-132094-0.004. */
3979 if (data
>= end
- 1)
3983 /* Skip the NUL at the end of the table. */
3986 /* Display the contents of the File Name table. */
3988 printf (_("\n The File Name Table is empty.\n"));
3991 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3992 (long)(data
- start
));
3993 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3995 while (data
< end
&& *data
!= 0)
3997 unsigned char *name
;
4000 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
4002 data
+= strnlen ((char *) data
, end
- data
) + 1;
4004 READ_ULEB (val
, data
, end
);
4005 printf ("%s\t", dwarf_vmatoa ("u", val
));
4006 READ_ULEB (val
, data
, end
);
4007 printf ("%s\t", dwarf_vmatoa ("u", val
));
4008 READ_ULEB (val
, data
, end
);
4009 printf ("%s\t", dwarf_vmatoa ("u", val
));
4010 printf ("%.*s\n", (int)(end
- name
), name
);
4014 warn (_("Corrupt file name table entry\n"));
4020 /* Skip the NUL at the end of the table. */
4025 saved_linfo
= linfo
;
4028 /* Now display the statements. */
4029 if (data
>= end_of_sequence
)
4030 printf (_(" No Line Number Statements.\n"));
4033 printf (_(" Line Number Statements:\n"));
4035 while (data
< end_of_sequence
)
4037 unsigned char op_code
;
4038 dwarf_signed_vma adv
;
4041 printf (" [0x%08lx]", (long)(data
- start
));
4045 if (op_code
>= linfo
.li_opcode_base
)
4047 op_code
-= linfo
.li_opcode_base
;
4048 uladv
= (op_code
/ linfo
.li_line_range
);
4049 if (linfo
.li_max_ops_per_insn
== 1)
4051 uladv
*= linfo
.li_min_insn_length
;
4052 state_machine_regs
.address
+= uladv
;
4054 state_machine_regs
.view
= 0;
4055 printf (_(" Special opcode %d: "
4056 "advance Address by %s to 0x%s%s"),
4057 op_code
, dwarf_vmatoa ("u", uladv
),
4058 dwarf_vmatoa ("x", state_machine_regs
.address
),
4059 verbose_view
&& uladv
4060 ? _(" (reset view)") : "");
4065 = ((state_machine_regs
.op_index
+ uladv
)
4066 / linfo
.li_max_ops_per_insn
)
4067 * linfo
.li_min_insn_length
;
4069 state_machine_regs
.address
+= addrdelta
;
4070 state_machine_regs
.op_index
4071 = (state_machine_regs
.op_index
+ uladv
)
4072 % linfo
.li_max_ops_per_insn
;
4074 state_machine_regs
.view
= 0;
4075 printf (_(" Special opcode %d: "
4076 "advance Address by %s to 0x%s[%d]%s"),
4077 op_code
, dwarf_vmatoa ("u", uladv
),
4078 dwarf_vmatoa ("x", state_machine_regs
.address
),
4079 state_machine_regs
.op_index
,
4080 verbose_view
&& addrdelta
4081 ? _(" (reset view)") : "");
4083 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4084 state_machine_regs
.line
+= adv
;
4085 printf (_(" and Line by %s to %d"),
4086 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
4087 if (verbose_view
|| state_machine_regs
.view
)
4088 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4091 state_machine_regs
.view
++;
4096 case DW_LNS_extended_op
:
4097 data
+= process_extended_line_op (data
,
4098 linfo
.li_default_is_stmt
,
4103 printf (_(" Copy"));
4104 if (verbose_view
|| state_machine_regs
.view
)
4105 printf (_(" (view %u)\n"), state_machine_regs
.view
);
4108 state_machine_regs
.view
++;
4111 case DW_LNS_advance_pc
:
4112 READ_ULEB (uladv
, data
, end
);
4113 if (linfo
.li_max_ops_per_insn
== 1)
4115 uladv
*= linfo
.li_min_insn_length
;
4116 state_machine_regs
.address
+= uladv
;
4118 state_machine_regs
.view
= 0;
4119 printf (_(" Advance PC by %s to 0x%s%s\n"),
4120 dwarf_vmatoa ("u", uladv
),
4121 dwarf_vmatoa ("x", state_machine_regs
.address
),
4122 verbose_view
&& uladv
4123 ? _(" (reset view)") : "");
4128 = ((state_machine_regs
.op_index
+ uladv
)
4129 / linfo
.li_max_ops_per_insn
)
4130 * linfo
.li_min_insn_length
;
4131 state_machine_regs
.address
4133 state_machine_regs
.op_index
4134 = (state_machine_regs
.op_index
+ uladv
)
4135 % linfo
.li_max_ops_per_insn
;
4137 state_machine_regs
.view
= 0;
4138 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
4139 dwarf_vmatoa ("u", uladv
),
4140 dwarf_vmatoa ("x", state_machine_regs
.address
),
4141 state_machine_regs
.op_index
,
4142 verbose_view
&& addrdelta
4143 ? _(" (reset view)") : "");
4147 case DW_LNS_advance_line
:
4148 READ_SLEB (adv
, data
, end
);
4149 state_machine_regs
.line
+= adv
;
4150 printf (_(" Advance Line by %s to %d\n"),
4151 dwarf_vmatoa ("d", adv
),
4152 state_machine_regs
.line
);
4155 case DW_LNS_set_file
:
4156 READ_ULEB (uladv
, data
, end
);
4157 printf (_(" Set File Name to entry %s in the File Name Table\n"),
4158 dwarf_vmatoa ("u", uladv
));
4159 state_machine_regs
.file
= uladv
;
4162 case DW_LNS_set_column
:
4163 READ_ULEB (uladv
, data
, end
);
4164 printf (_(" Set column to %s\n"),
4165 dwarf_vmatoa ("u", uladv
));
4166 state_machine_regs
.column
= uladv
;
4169 case DW_LNS_negate_stmt
:
4170 adv
= state_machine_regs
.is_stmt
;
4172 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
4173 state_machine_regs
.is_stmt
= adv
;
4176 case DW_LNS_set_basic_block
:
4177 printf (_(" Set basic block\n"));
4178 state_machine_regs
.basic_block
= 1;
4181 case DW_LNS_const_add_pc
:
4182 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4183 if (linfo
.li_max_ops_per_insn
)
4185 uladv
*= linfo
.li_min_insn_length
;
4186 state_machine_regs
.address
+= uladv
;
4188 state_machine_regs
.view
= 0;
4189 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
4190 dwarf_vmatoa ("u", uladv
),
4191 dwarf_vmatoa ("x", state_machine_regs
.address
),
4192 verbose_view
&& uladv
4193 ? _(" (reset view)") : "");
4198 = ((state_machine_regs
.op_index
+ uladv
)
4199 / linfo
.li_max_ops_per_insn
)
4200 * linfo
.li_min_insn_length
;
4201 state_machine_regs
.address
4203 state_machine_regs
.op_index
4204 = (state_machine_regs
.op_index
+ uladv
)
4205 % linfo
.li_max_ops_per_insn
;
4207 state_machine_regs
.view
= 0;
4208 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
4209 dwarf_vmatoa ("u", uladv
),
4210 dwarf_vmatoa ("x", state_machine_regs
.address
),
4211 state_machine_regs
.op_index
,
4212 verbose_view
&& addrdelta
4213 ? _(" (reset view)") : "");
4217 case DW_LNS_fixed_advance_pc
:
4218 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4219 state_machine_regs
.address
+= uladv
;
4220 state_machine_regs
.op_index
= 0;
4221 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
4222 dwarf_vmatoa ("u", uladv
),
4223 dwarf_vmatoa ("x", state_machine_regs
.address
));
4224 /* Do NOT reset view. */
4227 case DW_LNS_set_prologue_end
:
4228 printf (_(" Set prologue_end to true\n"));
4231 case DW_LNS_set_epilogue_begin
:
4232 printf (_(" Set epilogue_begin to true\n"));
4235 case DW_LNS_set_isa
:
4236 READ_ULEB (uladv
, data
, end
);
4237 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
4241 printf (_(" Unknown opcode %d with operands: "), op_code
);
4243 if (standard_opcodes
!= NULL
)
4244 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4246 READ_ULEB (uladv
, data
, end
);
4247 printf ("0x%s%s", dwarf_vmatoa ("x", uladv
),
4248 i
== 1 ? "" : ", ");
4263 unsigned char *name
;
4264 unsigned int directory_index
;
4265 unsigned int modification_date
;
4266 unsigned int length
;
4269 /* Output a decoded representation of the .debug_line section. */
4272 display_debug_lines_decoded (struct dwarf_section
* section
,
4273 unsigned char * start
,
4274 unsigned char * data
,
4275 unsigned char * end
,
4278 static DWARF2_Internal_LineInfo saved_linfo
;
4280 introduce (section
, FALSE
);
4284 /* This loop amounts to one iteration per compilation unit. */
4285 DWARF2_Internal_LineInfo linfo
;
4286 unsigned char *standard_opcodes
;
4287 unsigned char *end_of_sequence
;
4289 File_Entry
*file_table
= NULL
;
4290 unsigned int n_files
= 0;
4291 unsigned char **directory_table
= NULL
;
4292 dwarf_vma n_directories
= 0;
4294 if (const_strneq (section
->name
, ".debug_line.")
4295 /* Note: the following does not apply to .debug_line.dwo sections.
4296 These are full debug_line sections. */
4297 && strcmp (section
->name
, ".debug_line.dwo") != 0)
4299 /* See comment in display_debug_lines_raw(). */
4300 end_of_sequence
= end
;
4301 standard_opcodes
= NULL
;
4302 linfo
= saved_linfo
;
4303 /* PR 17531: file: 0522b371. */
4304 if (linfo
.li_line_range
== 0)
4306 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
4309 reset_state_machine (linfo
.li_default_is_stmt
);
4313 unsigned char *hdrptr
;
4315 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
4316 & end_of_sequence
)) == NULL
)
4319 /* PR 17531: file: 0522b371. */
4320 if (linfo
.li_line_range
== 0)
4322 warn (_("Line range of 0 is invalid, using 1 instead\n"));
4323 linfo
.li_line_range
= 1;
4325 reset_state_machine (linfo
.li_default_is_stmt
);
4327 /* Save a pointer to the contents of the Opcodes table. */
4328 standard_opcodes
= hdrptr
;
4330 /* Traverse the Directory table just to count entries. */
4331 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
4335 warn (_("opcode base of %d extends beyond end of section\n"),
4336 linfo
.li_opcode_base
);
4340 if (linfo
.li_version
>= 5)
4342 unsigned char *format_start
, format_count
, *format
;
4343 dwarf_vma formati
, entryi
;
4345 load_debug_section_with_follow (line_str
, fileptr
);
4347 /* Skip directories format. */
4348 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4349 format_start
= data
;
4350 for (formati
= 0; formati
< format_count
; formati
++)
4352 SKIP_ULEB (data
, end
);
4353 SKIP_ULEB (data
, end
);
4356 READ_ULEB (n_directories
, data
, end
);
4359 warn (_("Corrupt directories list\n"));
4363 directory_table
= (unsigned char **)
4364 xmalloc (n_directories
* sizeof (unsigned char *));
4366 for (entryi
= 0; entryi
< n_directories
; entryi
++)
4368 unsigned char **pathp
= &directory_table
[entryi
];
4370 format
= format_start
;
4371 for (formati
= 0; formati
< format_count
; formati
++)
4373 dwarf_vma content_type
, form
;
4376 READ_ULEB (content_type
, format
, end
);
4377 READ_ULEB (form
, format
, end
);
4380 warn (_("Corrupt directories list\n"));
4383 switch (content_type
)
4388 case DW_FORM_string
:
4391 case DW_FORM_line_strp
:
4392 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4394 /* Remove const by the cast. */
4395 *pathp
= (unsigned char *)
4396 fetch_indirect_line_string (uvalue
);
4401 data
= read_and_display_attr_value (0, form
, 0, start
,
4403 linfo
.li_offset_size
,
4410 warn (_("Corrupt directories list\n"));
4415 /* Skip files format. */
4416 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
4417 format_start
= data
;
4418 for (formati
= 0; formati
< format_count
; formati
++)
4420 SKIP_ULEB (data
, end
);
4421 SKIP_ULEB (data
, end
);
4424 READ_ULEB (n_files
, data
, end
);
4427 warn (_("Corrupt file name list\n"));
4431 file_table
= (File_Entry
*) xcalloc (1, n_files
4432 * sizeof (File_Entry
));
4434 for (entryi
= 0; entryi
< n_files
; entryi
++)
4436 File_Entry
*file
= &file_table
[entryi
];
4438 format
= format_start
;
4439 for (formati
= 0; formati
< format_count
; formati
++)
4441 dwarf_vma content_type
, form
;
4445 READ_ULEB (content_type
, format
, end
);
4446 READ_ULEB (form
, format
, end
);
4449 warn (_("Corrupt file name list\n"));
4452 switch (content_type
)
4457 case DW_FORM_string
:
4460 case DW_FORM_line_strp
:
4461 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
4463 /* Remove const by the cast. */
4464 file
->name
= (unsigned char *)
4465 fetch_indirect_line_string (uvalue
);
4469 case DW_LNCT_directory_index
:
4473 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
4477 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
4482 READ_ULEB (file
->directory_index
, tmp
, end
);
4487 data
= read_and_display_attr_value (0, form
, 0, start
,
4489 linfo
.li_offset_size
,
4496 warn (_("Corrupt file name list\n"));
4505 unsigned char *ptr_directory_table
= data
;
4507 while (data
< end
&& *data
!= 0)
4509 data
+= strnlen ((char *) data
, end
- data
) + 1;
4516 warn (_("directory table ends unexpectedly\n"));
4521 /* Go through the directory table again to save the directories. */
4522 directory_table
= (unsigned char **)
4523 xmalloc (n_directories
* sizeof (unsigned char *));
4526 while (*ptr_directory_table
!= 0)
4528 directory_table
[i
] = ptr_directory_table
;
4529 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
4530 ptr_directory_table
- end
) + 1;
4534 /* Skip the NUL at the end of the table. */
4537 /* Traverse the File Name table just to count the entries. */
4538 if (data
< end
&& *data
!= 0)
4540 unsigned char *ptr_file_name_table
= data
;
4542 while (data
< end
&& *data
!= 0)
4544 /* Skip Name, directory index, last modification
4545 time and length of file. */
4546 data
+= strnlen ((char *) data
, end
- data
) + 1;
4547 SKIP_ULEB (data
, end
);
4548 SKIP_ULEB (data
, end
);
4549 SKIP_ULEB (data
, end
);
4555 warn (_("file table ends unexpectedly\n"));
4560 /* Go through the file table again to save the strings. */
4561 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
4564 while (*ptr_file_name_table
!= 0)
4566 file_table
[i
].name
= ptr_file_name_table
;
4567 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
4568 end
- ptr_file_name_table
) + 1;
4570 /* We are not interested in directory, time or size. */
4571 READ_ULEB (file_table
[i
].directory_index
,
4572 ptr_file_name_table
, end
);
4573 READ_ULEB (file_table
[i
].modification_date
,
4574 ptr_file_name_table
, end
);
4575 READ_ULEB (file_table
[i
].length
,
4576 ptr_file_name_table
, end
);
4582 /* Skip the NUL at the end of the table. */
4586 /* Print the Compilation Unit's name and a header. */
4587 if (file_table
== NULL
)
4589 else if (directory_table
== NULL
)
4590 printf (_("CU: %s:\n"), file_table
[0].name
);
4593 unsigned int ix
= file_table
[0].directory_index
;
4594 const char *directory
;
4599 else if (n_directories
== 0)
4600 directory
= _("<unknown>");
4601 else if (ix
> n_directories
)
4603 warn (_("directory index %u > number of directories %s\n"),
4604 ix
, dwarf_vmatoa ("u", n_directories
));
4605 directory
= _("<corrupt>");
4608 directory
= (char *) directory_table
[ix
- 1];
4610 if (do_wide
|| strlen (directory
) < 76)
4611 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
4613 printf ("%s:\n", file_table
[0].name
);
4616 printf (_("File name Line number Starting address View Stmt\n"));
4617 saved_linfo
= linfo
;
4620 /* This loop iterates through the Dwarf Line Number Program. */
4621 while (data
< end_of_sequence
)
4623 unsigned char op_code
;
4626 unsigned long int uladv
;
4627 int is_special_opcode
= 0;
4632 if (op_code
>= linfo
.li_opcode_base
)
4634 op_code
-= linfo
.li_opcode_base
;
4635 uladv
= (op_code
/ linfo
.li_line_range
);
4636 if (linfo
.li_max_ops_per_insn
== 1)
4638 uladv
*= linfo
.li_min_insn_length
;
4639 state_machine_regs
.address
+= uladv
;
4641 state_machine_regs
.view
= 0;
4646 = ((state_machine_regs
.op_index
+ uladv
)
4647 / linfo
.li_max_ops_per_insn
)
4648 * linfo
.li_min_insn_length
;
4649 state_machine_regs
.address
4651 state_machine_regs
.op_index
4652 = (state_machine_regs
.op_index
+ uladv
)
4653 % linfo
.li_max_ops_per_insn
;
4655 state_machine_regs
.view
= 0;
4658 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4659 state_machine_regs
.line
+= adv
;
4660 is_special_opcode
= 1;
4661 /* Increment view after printing this row. */
4666 case DW_LNS_extended_op
:
4668 unsigned int ext_op_code_len
;
4669 unsigned char ext_op_code
;
4670 unsigned char *op_code_end
;
4671 unsigned char *op_code_data
= data
;
4673 READ_ULEB (ext_op_code_len
, op_code_data
, end_of_sequence
);
4674 op_code_end
= op_code_data
+ ext_op_code_len
;
4675 if (ext_op_code_len
== 0 || op_code_end
> end_of_sequence
)
4677 warn (_("Badly formed extended line op encountered!\n"));
4680 ext_op_code
= *op_code_data
++;
4684 switch (ext_op_code
)
4686 case DW_LNE_end_sequence
:
4687 /* Reset stuff after printing this row. */
4689 case DW_LNE_set_address
:
4690 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
4692 op_code_end
- op_code_data
,
4694 state_machine_regs
.op_index
= 0;
4695 state_machine_regs
.view
= 0;
4697 case DW_LNE_define_file
:
4698 file_table
= (File_Entry
*) xrealloc
4699 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
4701 ++state_machine_regs
.last_file_entry
;
4702 /* Source file name. */
4703 file_table
[n_files
].name
= op_code_data
;
4704 op_code_data
+= strlen ((char *) op_code_data
) + 1;
4705 /* Directory index. */
4706 READ_ULEB (file_table
[n_files
].directory_index
,
4707 op_code_data
, op_code_end
);
4708 /* Last modification time. */
4709 READ_ULEB (file_table
[n_files
].modification_date
,
4710 op_code_data
, op_code_end
);
4712 READ_ULEB (file_table
[n_files
].length
,
4713 op_code_data
, op_code_end
);
4717 case DW_LNE_set_discriminator
:
4718 case DW_LNE_HP_set_sequence
:
4719 /* Simply ignored. */
4723 printf (_("UNKNOWN (%u): length %ld\n"),
4724 ext_op_code
, (long int) (op_code_data
- data
));
4731 /* Increment view after printing this row. */
4734 case DW_LNS_advance_pc
:
4735 READ_ULEB (uladv
, data
, end
);
4736 if (linfo
.li_max_ops_per_insn
== 1)
4738 uladv
*= linfo
.li_min_insn_length
;
4739 state_machine_regs
.address
+= uladv
;
4741 state_machine_regs
.view
= 0;
4746 = ((state_machine_regs
.op_index
+ uladv
)
4747 / linfo
.li_max_ops_per_insn
)
4748 * linfo
.li_min_insn_length
;
4749 state_machine_regs
.address
4751 state_machine_regs
.op_index
4752 = (state_machine_regs
.op_index
+ uladv
)
4753 % linfo
.li_max_ops_per_insn
;
4755 state_machine_regs
.view
= 0;
4759 case DW_LNS_advance_line
:
4760 READ_SLEB (adv
, data
, end
);
4761 state_machine_regs
.line
+= adv
;
4764 case DW_LNS_set_file
:
4765 READ_ULEB (uladv
, data
, end
);
4766 state_machine_regs
.file
= uladv
;
4769 unsigned file
= state_machine_regs
.file
- 1;
4772 if (file_table
== NULL
|| n_files
== 0)
4773 printf (_("\n [Use file table entry %d]\n"), file
);
4775 else if (file
>= n_files
)
4777 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
4778 printf (_("\n <over large file table index %u>"), file
);
4780 else if ((dir
= file_table
[file
].directory_index
) == 0)
4781 /* If directory index is 0, that means current directory. */
4782 printf ("\n./%s:[++]\n", file_table
[file
].name
);
4783 else if (directory_table
== NULL
|| n_directories
== 0)
4784 printf (_("\n [Use file %s in directory table entry %d]\n"),
4785 file_table
[file
].name
, dir
);
4787 else if (dir
> n_directories
)
4789 warn (_("directory index %u > number of directories %s\n"),
4790 dir
, dwarf_vmatoa ("u", n_directories
));
4791 printf (_("\n <over large directory table entry %u>\n"), dir
);
4794 printf ("\n%s/%s:\n",
4795 /* The directory index starts counting at 1. */
4796 directory_table
[dir
- 1], file_table
[file
].name
);
4800 case DW_LNS_set_column
:
4801 READ_ULEB (uladv
, data
, end
);
4802 state_machine_regs
.column
= uladv
;
4805 case DW_LNS_negate_stmt
:
4806 adv
= state_machine_regs
.is_stmt
;
4808 state_machine_regs
.is_stmt
= adv
;
4811 case DW_LNS_set_basic_block
:
4812 state_machine_regs
.basic_block
= 1;
4815 case DW_LNS_const_add_pc
:
4816 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4817 if (linfo
.li_max_ops_per_insn
== 1)
4819 uladv
*= linfo
.li_min_insn_length
;
4820 state_machine_regs
.address
+= uladv
;
4822 state_machine_regs
.view
= 0;
4827 = ((state_machine_regs
.op_index
+ uladv
)
4828 / linfo
.li_max_ops_per_insn
)
4829 * linfo
.li_min_insn_length
;
4830 state_machine_regs
.address
4832 state_machine_regs
.op_index
4833 = (state_machine_regs
.op_index
+ uladv
)
4834 % linfo
.li_max_ops_per_insn
;
4836 state_machine_regs
.view
= 0;
4840 case DW_LNS_fixed_advance_pc
:
4841 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4842 state_machine_regs
.address
+= uladv
;
4843 state_machine_regs
.op_index
= 0;
4844 /* Do NOT reset view. */
4847 case DW_LNS_set_prologue_end
:
4850 case DW_LNS_set_epilogue_begin
:
4853 case DW_LNS_set_isa
:
4854 READ_ULEB (uladv
, data
, end
);
4855 printf (_(" Set ISA to %lu\n"), uladv
);
4859 printf (_(" Unknown opcode %d with operands: "), op_code
);
4861 if (standard_opcodes
!= NULL
)
4862 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4866 READ_ULEB (val
, data
, end
);
4867 printf ("0x%s%s", dwarf_vmatoa ("x", val
),
4868 i
== 1 ? "" : ", ");
4874 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4875 to the DWARF address/line matrix. */
4876 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
4877 || (xop
== DW_LNS_copy
))
4879 const unsigned int MAX_FILENAME_LENGTH
= 35;
4881 char *newFileName
= NULL
;
4882 size_t fileNameLength
;
4886 unsigned indx
= state_machine_regs
.file
- 1;
4888 if (indx
>= n_files
)
4890 warn (_("corrupt file index %u encountered\n"), indx
);
4891 fileName
= _("<corrupt>");
4894 fileName
= (char *) file_table
[indx
].name
;
4897 fileName
= _("<unknown>");
4899 fileNameLength
= strlen (fileName
);
4901 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
4903 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
4904 /* Truncate file name */
4905 strncpy (newFileName
,
4906 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
4907 MAX_FILENAME_LENGTH
+ 1);
4908 /* FIXME: This is to pacify gcc-10 which can warn that the
4909 strncpy above might leave a non-NUL terminated string
4910 in newFileName. It won't, but gcc's analysis doesn't
4911 quite go far enough to discover this. */
4912 newFileName
[MAX_FILENAME_LENGTH
] = 0;
4916 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
4917 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
4920 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
4922 if (linfo
.li_max_ops_per_insn
== 1)
4923 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
4924 newFileName
, state_machine_regs
.line
,
4925 state_machine_regs
.address
);
4927 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4928 newFileName
, state_machine_regs
.line
,
4929 state_machine_regs
.address
,
4930 state_machine_regs
.op_index
);
4934 if (linfo
.li_max_ops_per_insn
== 1)
4935 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
4936 newFileName
, state_machine_regs
.line
,
4937 state_machine_regs
.address
);
4939 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4940 newFileName
, state_machine_regs
.line
,
4941 state_machine_regs
.address
,
4942 state_machine_regs
.op_index
);
4945 if (state_machine_regs
.view
)
4946 printf (" %6u", state_machine_regs
.view
);
4950 if (state_machine_regs
.is_stmt
)
4954 state_machine_regs
.view
++;
4956 if (xop
== -DW_LNE_end_sequence
)
4958 reset_state_machine (linfo
.li_default_is_stmt
);
4973 if (directory_table
)
4975 free (directory_table
);
4976 directory_table
= NULL
;
4987 display_debug_lines (struct dwarf_section
*section
, void *file
)
4989 unsigned char *data
= section
->start
;
4990 unsigned char *end
= data
+ section
->size
;
4992 int retValDecoded
= 1;
4994 if (do_debug_lines
== 0)
4995 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
4997 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
4998 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
5000 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
5001 retValDecoded
= display_debug_lines_decoded (section
, data
, data
, end
, file
);
5003 if (!retValRaw
|| !retValDecoded
)
5010 find_debug_info_for_offset (unsigned long offset
)
5014 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
5017 for (i
= 0; i
< num_debug_info_entries
; i
++)
5018 if (debug_information
[i
].cu_offset
== offset
)
5019 return debug_information
+ i
;
5025 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
5027 /* See gdb/gdb-index.h. */
5028 static const char * const kinds
[] =
5040 return _ (kinds
[kind
]);
5044 display_debug_pubnames_worker (struct dwarf_section
*section
,
5045 void *file ATTRIBUTE_UNUSED
,
5048 DWARF2_Internal_PubNames names
;
5049 unsigned char *start
= section
->start
;
5050 unsigned char *end
= start
+ section
->size
;
5052 /* It does not matter if this load fails,
5053 we test for that later on. */
5054 load_debug_info (file
);
5056 introduce (section
, FALSE
);
5060 unsigned char *data
;
5061 unsigned long sec_off
;
5062 unsigned int offset_size
, initial_length_size
;
5064 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
5065 if (names
.pn_length
== 0xffffffff)
5067 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
5069 initial_length_size
= 12;
5074 initial_length_size
= 4;
5077 sec_off
= start
- section
->start
;
5078 if (sec_off
+ names
.pn_length
< sec_off
5079 || sec_off
+ names
.pn_length
> section
->size
)
5081 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
5083 sec_off
- initial_length_size
,
5084 dwarf_vmatoa ("x", names
.pn_length
));
5089 start
+= names
.pn_length
;
5091 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
5092 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
5094 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
5095 && num_debug_info_entries
> 0
5096 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
5097 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
5098 (unsigned long) names
.pn_offset
, section
->name
);
5100 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
5102 printf (_(" Length: %ld\n"),
5103 (long) names
.pn_length
);
5104 printf (_(" Version: %d\n"),
5106 printf (_(" Offset into .debug_info section: 0x%lx\n"),
5107 (unsigned long) names
.pn_offset
);
5108 printf (_(" Size of area in .debug_info section: %ld\n"),
5109 (long) names
.pn_size
);
5111 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
5113 static int warned
= 0;
5117 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
5125 printf (_("\n Offset Kind Name\n"));
5127 printf (_("\n Offset\tName\n"));
5131 bfd_size_type maxprint
;
5134 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
5139 data
+= offset_size
;
5142 maxprint
= (end
- data
) - 1;
5146 unsigned int kind_data
;
5147 gdb_index_symbol_kind kind
;
5148 const char *kind_name
;
5151 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
5154 /* GCC computes the kind as the upper byte in the CU index
5155 word, and then right shifts it by the CU index size.
5156 Left shift KIND to where the gdb-index.h accessor macros
5158 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
5159 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
5160 kind_name
= get_gdb_index_symbol_kind_name (kind
);
5161 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
5162 printf (" %-6lx %s,%-10s %.*s\n",
5163 (unsigned long) offset
, is_static
? _("s") : _("g"),
5164 kind_name
, (int) maxprint
, data
);
5167 printf (" %-6lx\t%.*s\n",
5168 (unsigned long) offset
, (int) maxprint
, data
);
5170 data
+= strnlen ((char *) data
, maxprint
) + 1;
5181 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
5183 return display_debug_pubnames_worker (section
, file
, 0);
5187 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
5189 return display_debug_pubnames_worker (section
, file
, 1);
5193 display_debug_macinfo (struct dwarf_section
*section
,
5194 void *file ATTRIBUTE_UNUSED
)
5196 unsigned char *start
= section
->start
;
5197 unsigned char *end
= start
+ section
->size
;
5198 unsigned char *curr
= start
;
5199 enum dwarf_macinfo_record_type op
;
5201 introduce (section
, FALSE
);
5205 unsigned int lineno
;
5206 const unsigned char *string
;
5208 op
= (enum dwarf_macinfo_record_type
) *curr
;
5213 case DW_MACINFO_start_file
:
5215 unsigned int filenum
;
5217 READ_ULEB (lineno
, curr
, end
);
5218 READ_ULEB (filenum
, curr
, end
);
5219 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
5224 case DW_MACINFO_end_file
:
5225 printf (_(" DW_MACINFO_end_file\n"));
5228 case DW_MACINFO_define
:
5229 READ_ULEB (lineno
, curr
, end
);
5231 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5232 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
5236 case DW_MACINFO_undef
:
5237 READ_ULEB (lineno
, curr
, end
);
5239 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5240 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
5244 case DW_MACINFO_vendor_ext
:
5246 unsigned int constant
;
5248 READ_ULEB (constant
, curr
, end
);
5250 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5251 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
5261 /* Given LINE_OFFSET into the .debug_line section, attempt to return
5262 filename and dirname corresponding to file name table entry with index
5263 FILEIDX. Return NULL on failure. */
5265 static unsigned char *
5266 get_line_filename_and_dirname (dwarf_vma line_offset
,
5268 unsigned char **dir_name
)
5270 struct dwarf_section
*section
= &debug_displays
[line
].section
;
5271 unsigned char *hdrptr
, *dirtable
, *file_name
;
5272 unsigned int offset_size
, initial_length_size
;
5273 unsigned int version
, opcode_base
;
5274 dwarf_vma length
, diridx
;
5275 const unsigned char * end
;
5278 if (section
->start
== NULL
5279 || line_offset
>= section
->size
5283 hdrptr
= section
->start
+ line_offset
;
5284 end
= section
->start
+ section
->size
;
5286 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
5287 if (length
== 0xffffffff)
5289 /* This section is 64-bit DWARF 3. */
5290 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
5292 initial_length_size
= 12;
5297 initial_length_size
= 4;
5299 if (length
+ initial_length_size
< length
5300 || length
+ initial_length_size
> section
->size
)
5303 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
5304 if (version
!= 2 && version
!= 3 && version
!= 4)
5306 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
5308 hdrptr
++; /* Skip max_ops_per_insn. */
5309 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
5311 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
5312 if (opcode_base
== 0)
5315 hdrptr
+= opcode_base
- 1;
5320 /* Skip over dirname table. */
5321 while (*hdrptr
!= '\0')
5323 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5327 hdrptr
++; /* Skip the NUL at the end of the table. */
5329 /* Now skip over preceding filename table entries. */
5330 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
5332 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5333 SKIP_ULEB (hdrptr
, end
);
5334 SKIP_ULEB (hdrptr
, end
);
5335 SKIP_ULEB (hdrptr
, end
);
5337 if (hdrptr
>= end
|| *hdrptr
== '\0')
5341 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
5344 READ_ULEB (diridx
, hdrptr
, end
);
5347 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
5348 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
5349 if (dirtable
>= end
|| *dirtable
== '\0')
5351 *dir_name
= dirtable
;
5356 display_debug_macro (struct dwarf_section
*section
,
5359 unsigned char *start
= section
->start
;
5360 unsigned char *end
= start
+ section
->size
;
5361 unsigned char *curr
= start
;
5362 unsigned char *extended_op_buf
[256];
5364 load_debug_section_with_follow (str
, file
);
5365 load_debug_section_with_follow (line
, file
);
5367 introduce (section
, FALSE
);
5371 unsigned int lineno
, version
, flags
;
5372 unsigned int offset_size
= 4;
5373 const unsigned char *string
;
5374 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
5375 unsigned char **extended_ops
= NULL
;
5377 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
5378 if (version
!= 4 && version
!= 5)
5380 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
5385 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
5388 printf (_(" Offset: 0x%lx\n"),
5389 (unsigned long) sec_offset
);
5390 printf (_(" Version: %d\n"), version
);
5391 printf (_(" Offset size: %d\n"), offset_size
);
5394 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
5395 printf (_(" Offset into .debug_line: 0x%lx\n"),
5396 (unsigned long) line_offset
);
5400 unsigned int i
, count
, op
;
5403 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
5405 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
5406 extended_ops
= extended_op_buf
;
5409 printf (_(" Extension opcode arguments:\n"));
5410 for (i
= 0; i
< count
; i
++)
5412 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5413 extended_ops
[op
] = curr
;
5414 READ_ULEB (nargs
, curr
, end
);
5416 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
5419 printf (_(" DW_MACRO_%02x arguments: "), op
);
5420 for (n
= 0; n
< nargs
; n
++)
5424 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
5425 printf ("%s%s", get_FORM_name (form
),
5426 n
== nargs
- 1 ? "\n" : ", ");
5436 case DW_FORM_block1
:
5437 case DW_FORM_block2
:
5438 case DW_FORM_block4
:
5440 case DW_FORM_string
:
5442 case DW_FORM_sec_offset
:
5445 error (_("Invalid extension opcode form %s\n"),
5446 get_FORM_name (form
));
5462 error (_(".debug_macro section not zero terminated\n"));
5466 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
5472 case DW_MACRO_start_file
:
5474 unsigned int filenum
;
5475 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
5477 READ_ULEB (lineno
, curr
, end
);
5478 READ_ULEB (filenum
, curr
, end
);
5480 if ((flags
& 2) == 0)
5481 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
5484 = get_line_filename_and_dirname (line_offset
, filenum
,
5486 if (file_name
== NULL
)
5487 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
5490 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
5492 dir_name
!= NULL
? (const char *) dir_name
: "",
5493 dir_name
!= NULL
? "/" : "", file_name
);
5497 case DW_MACRO_end_file
:
5498 printf (_(" DW_MACRO_end_file\n"));
5501 case DW_MACRO_define
:
5502 READ_ULEB (lineno
, curr
, end
);
5504 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5505 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5509 case DW_MACRO_undef
:
5510 READ_ULEB (lineno
, curr
, end
);
5512 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5513 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5517 case DW_MACRO_define_strp
:
5518 READ_ULEB (lineno
, curr
, end
);
5519 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5520 string
= fetch_indirect_string (offset
);
5521 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5525 case DW_MACRO_undef_strp
:
5526 READ_ULEB (lineno
, curr
, end
);
5527 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5528 string
= fetch_indirect_string (offset
);
5529 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5533 case DW_MACRO_import
:
5534 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5535 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5536 (unsigned long) offset
);
5539 case DW_MACRO_define_sup
:
5540 READ_ULEB (lineno
, curr
, end
);
5541 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5542 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5543 lineno
, (unsigned long) offset
);
5546 case DW_MACRO_undef_sup
:
5547 READ_ULEB (lineno
, curr
, end
);
5548 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5549 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5550 lineno
, (unsigned long) offset
);
5553 case DW_MACRO_import_sup
:
5554 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5555 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5556 (unsigned long) offset
);
5560 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
5562 error (_(" Unknown macro opcode %02x seen\n"), op
);
5567 /* Skip over unhandled opcodes. */
5569 unsigned char *desc
= extended_ops
[op
];
5570 READ_ULEB (nargs
, desc
, end
);
5573 printf (_(" DW_MACRO_%02x\n"), op
);
5576 printf (_(" DW_MACRO_%02x -"), op
);
5577 for (n
= 0; n
< nargs
; n
++)
5581 /* DW_FORM_implicit_const is not expected here. */
5582 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
5584 = read_and_display_attr_value (0, val
, 0,
5585 start
, curr
, end
, 0, 0, offset_size
,
5586 version
, NULL
, 0, NULL
,
5604 display_debug_abbrev (struct dwarf_section
*section
,
5605 void *file ATTRIBUTE_UNUSED
)
5607 abbrev_entry
*entry
;
5608 unsigned char *start
= section
->start
;
5609 unsigned char *end
= start
+ section
->size
;
5611 introduce (section
, FALSE
);
5615 unsigned char *last
;
5620 start
= process_abbrev_section (start
, end
);
5622 if (first_abbrev
== NULL
)
5625 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
5627 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5631 printf (" %ld %s [%s]\n",
5633 get_TAG_name (entry
->tag
),
5634 entry
->children
? _("has children") : _("no children"));
5636 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5638 printf (" %-18s %s",
5639 get_AT_name (attr
->attribute
),
5640 get_FORM_name (attr
->form
));
5641 if (attr
->form
== DW_FORM_implicit_const
)
5642 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
5654 /* Return true when ADDR is the maximum address, when addresses are
5655 POINTER_SIZE bytes long. */
5658 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
5660 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
5661 return ((addr
& mask
) == mask
);
5664 /* Display a view pair list starting at *VSTART_PTR and ending at
5665 VLISTEND within SECTION. */
5668 display_view_pair_list (struct dwarf_section
*section
,
5669 unsigned char **vstart_ptr
,
5670 unsigned int debug_info_entry
,
5671 unsigned char *vlistend
)
5673 unsigned char *vstart
= *vstart_ptr
;
5674 unsigned char *section_end
= section
->start
+ section
->size
;
5675 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5677 if (vlistend
< section_end
)
5678 section_end
= vlistend
;
5682 while (vstart
< section_end
)
5684 dwarf_vma off
= vstart
- section
->start
;
5685 dwarf_vma vbegin
, vend
;
5687 READ_ULEB (vbegin
, vstart
, section_end
);
5688 if (vstart
== section_end
)
5691 READ_ULEB (vend
, vstart
, section_end
);
5692 printf (" %8.8lx ", (unsigned long) off
);
5694 print_dwarf_view (vbegin
, pointer_size
, 1);
5695 print_dwarf_view (vend
, pointer_size
, 1);
5696 printf (_("location view pair\n"));
5700 *vstart_ptr
= vstart
;
5703 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5706 display_loc_list (struct dwarf_section
*section
,
5707 unsigned char **start_ptr
,
5708 unsigned int debug_info_entry
,
5710 dwarf_vma base_address
,
5711 unsigned char **vstart_ptr
,
5714 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5715 unsigned char *section_end
= section
->start
+ section
->size
;
5716 unsigned long cu_offset
;
5717 unsigned int pointer_size
;
5718 unsigned int offset_size
;
5723 unsigned short length
;
5724 int need_frame_base
;
5726 if (debug_info_entry
>= num_debug_info_entries
)
5728 warn (_("No debug information available for loc lists of entry: %u\n"),
5733 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5734 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5735 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5736 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5738 if (pointer_size
< 2 || pointer_size
> 8)
5740 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5741 pointer_size
, debug_info_entry
);
5747 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5748 dwarf_vma vbegin
= vm1
, vend
= vm1
;
5750 if (start
+ 2 * pointer_size
> section_end
)
5752 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5753 (unsigned long) offset
);
5757 printf (" %8.8lx ", (unsigned long) off
);
5759 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
5760 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
5762 if (begin
== 0 && end
== 0)
5764 /* PR 18374: In a object file we can have a location list that
5765 starts with a begin and end of 0 because there are relocations
5766 that need to be applied to the addresses. Actually applying
5767 the relocations now does not help as they will probably resolve
5768 to 0, since the object file has not been fully linked. Real
5769 end of list markers will not have any relocations against them. */
5770 if (! reloc_at (section
, off
)
5771 && ! reloc_at (section
, off
+ pointer_size
))
5773 printf (_("<End of list>\n"));
5778 /* Check base address specifiers. */
5779 if (is_max_address (begin
, pointer_size
)
5780 && !is_max_address (end
, pointer_size
))
5783 print_dwarf_vma (begin
, pointer_size
);
5784 print_dwarf_vma (end
, pointer_size
);
5785 printf (_("(base address)\n"));
5791 off
= offset
+ (vstart
- *start_ptr
);
5793 READ_ULEB (vbegin
, vstart
, section_end
);
5794 print_dwarf_view (vbegin
, pointer_size
, 1);
5796 READ_ULEB (vend
, vstart
, section_end
);
5797 print_dwarf_view (vend
, pointer_size
, 1);
5799 printf (_("views at %8.8lx for:\n %*s "),
5800 (unsigned long) off
, 8, "");
5803 if (start
+ 2 > section_end
)
5805 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5806 (unsigned long) offset
);
5810 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5812 if (start
+ length
> section_end
)
5814 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5815 (unsigned long) offset
);
5819 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5820 print_dwarf_vma (end
+ base_address
, pointer_size
);
5823 need_frame_base
= decode_location_expression (start
,
5828 cu_offset
, section
);
5831 if (need_frame_base
&& !has_frame_base
)
5832 printf (_(" [without DW_AT_frame_base]"));
5834 if (begin
== end
&& vbegin
== vend
)
5835 fputs (_(" (start == end)"), stdout
);
5836 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5837 fputs (_(" (start > end)"), stdout
);
5845 *vstart_ptr
= vstart
;
5848 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5851 display_loclists_list (struct dwarf_section
*section
,
5852 unsigned char **start_ptr
,
5853 unsigned int debug_info_entry
,
5855 dwarf_vma base_address
,
5856 unsigned char **vstart_ptr
,
5859 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5860 unsigned char *section_end
= section
->start
+ section
->size
;
5861 unsigned long cu_offset
;
5862 unsigned int pointer_size
;
5863 unsigned int offset_size
;
5866 /* Initialize it due to a false compiler warning. */
5867 dwarf_vma begin
= -1, vbegin
= -1;
5868 dwarf_vma end
= -1, vend
= -1;
5870 int need_frame_base
;
5872 if (debug_info_entry
>= num_debug_info_entries
)
5874 warn (_("No debug information available for "
5875 "loclists lists of entry: %u\n"),
5880 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5881 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5882 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5883 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5885 if (pointer_size
< 2 || pointer_size
> 8)
5887 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5888 pointer_size
, debug_info_entry
);
5894 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5895 enum dwarf_location_list_entry_type llet
;
5897 if (start
+ 1 > section_end
)
5899 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5900 (unsigned long) offset
);
5904 printf (" %8.8lx ", (unsigned long) off
);
5906 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
5908 if (vstart
&& llet
== DW_LLE_offset_pair
)
5910 off
= offset
+ (vstart
- *start_ptr
);
5912 READ_ULEB (vbegin
, vstart
, section_end
);
5913 print_dwarf_view (vbegin
, pointer_size
, 1);
5915 READ_ULEB (vend
, vstart
, section_end
);
5916 print_dwarf_view (vend
, pointer_size
, 1);
5918 printf (_("views at %8.8lx for:\n %*s "),
5919 (unsigned long) off
, 8, "");
5924 case DW_LLE_end_of_list
:
5925 printf (_("<End of list>\n"));
5927 case DW_LLE_offset_pair
:
5928 READ_ULEB (begin
, start
, section_end
);
5929 READ_ULEB (end
, start
, section_end
);
5931 case DW_LLE_base_address
:
5932 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
5934 print_dwarf_vma (base_address
, pointer_size
);
5935 printf (_("(base address)\n"));
5937 #ifdef DW_LLE_view_pair
5938 case DW_LLE_view_pair
:
5940 printf (_("View pair entry in loclist with locviews attribute\n"));
5941 READ_ULEB (vbegin
, start
, section_end
);
5942 print_dwarf_view (vbegin
, pointer_size
, 1);
5944 READ_ULEB (vend
, start
, section_end
);
5945 print_dwarf_view (vend
, pointer_size
, 1);
5947 printf (_("views for:\n"));
5951 error (_("Invalid location list entry type %d\n"), llet
);
5954 if (llet
== DW_LLE_end_of_list
)
5956 if (llet
!= DW_LLE_offset_pair
)
5959 if (start
+ 2 > section_end
)
5961 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5962 (unsigned long) offset
);
5966 READ_ULEB (length
, start
, section_end
);
5968 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5969 print_dwarf_vma (end
+ base_address
, pointer_size
);
5972 need_frame_base
= decode_location_expression (start
,
5977 cu_offset
, section
);
5980 if (need_frame_base
&& !has_frame_base
)
5981 printf (_(" [without DW_AT_frame_base]"));
5983 if (begin
== end
&& vbegin
== vend
)
5984 fputs (_(" (start == end)"), stdout
);
5985 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5986 fputs (_(" (start > end)"), stdout
);
5994 if (vbegin
!= vm1
|| vend
!= vm1
)
5995 printf (_("Trailing view pair not used in a range"));
5998 *vstart_ptr
= vstart
;
6001 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
6002 right-adjusted in a field of length LEN, and followed by a space. */
6005 print_addr_index (unsigned int idx
, unsigned int len
)
6007 static char buf
[15];
6008 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
6009 printf ("%*s ", len
, buf
);
6012 /* Display a location list from a .dwo section. It uses address indexes rather
6013 than embedded addresses. This code closely follows display_loc_list, but the
6014 two are sufficiently different that combining things is very ugly. */
6017 display_loc_list_dwo (struct dwarf_section
*section
,
6018 unsigned char **start_ptr
,
6019 unsigned int debug_info_entry
,
6021 unsigned char **vstart_ptr
,
6024 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
6025 unsigned char *section_end
= section
->start
+ section
->size
;
6026 unsigned long cu_offset
;
6027 unsigned int pointer_size
;
6028 unsigned int offset_size
;
6031 unsigned short length
;
6032 int need_frame_base
;
6035 if (debug_info_entry
>= num_debug_info_entries
)
6037 warn (_("No debug information for loc lists of entry: %u\n"),
6042 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
6043 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
6044 offset_size
= debug_information
[debug_info_entry
].offset_size
;
6045 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
6047 if (pointer_size
< 2 || pointer_size
> 8)
6049 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
6050 pointer_size
, debug_info_entry
);
6056 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
6058 if (start
>= section_end
)
6060 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6061 (unsigned long) offset
);
6065 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
6078 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
6080 READ_ULEB (view
, vstart
, section_end
);
6081 print_dwarf_view (view
, 8, 1);
6083 READ_ULEB (view
, vstart
, section_end
);
6084 print_dwarf_view (view
, 8, 1);
6086 printf (_("views at %8.8lx for:\n %*s "),
6087 (unsigned long) off
, 8, "");
6095 case 0: /* A terminating entry. */
6097 *vstart_ptr
= vstart
;
6098 printf (_("<End of list>\n"));
6100 case 1: /* A base-address entry. */
6101 READ_ULEB (idx
, start
, section_end
);
6102 print_addr_index (idx
, 8);
6103 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
6104 printf (_("(base address selection entry)\n"));
6106 case 2: /* A start/end entry. */
6107 READ_ULEB (idx
, start
, section_end
);
6108 print_addr_index (idx
, 8);
6109 READ_ULEB (idx
, start
, section_end
);
6110 print_addr_index (idx
, 8);
6112 case 3: /* A start/length entry. */
6113 READ_ULEB (idx
, start
, section_end
);
6114 print_addr_index (idx
, 8);
6115 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6116 printf ("%08x ", idx
);
6118 case 4: /* An offset pair entry. */
6119 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6120 printf ("%08x ", idx
);
6121 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
6122 printf ("%08x ", idx
);
6125 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
6127 *vstart_ptr
= vstart
;
6131 if (start
+ 2 > section_end
)
6133 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6134 (unsigned long) offset
);
6138 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
6139 if (start
+ length
> section_end
)
6141 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
6142 (unsigned long) offset
);
6147 need_frame_base
= decode_location_expression (start
,
6152 cu_offset
, section
);
6155 if (need_frame_base
&& !has_frame_base
)
6156 printf (_(" [without DW_AT_frame_base]"));
6164 *vstart_ptr
= vstart
;
6167 /* Sort array of indexes in ascending order of loc_offsets[idx] and
6170 static dwarf_vma
*loc_offsets
, *loc_views
;
6173 loc_offsets_compar (const void *ap
, const void *bp
)
6175 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
6176 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
6178 int ret
= (a
> b
) - (b
> a
);
6182 a
= loc_views
[*(const unsigned int *) ap
];
6183 b
= loc_views
[*(const unsigned int *) bp
];
6185 ret
= (a
> b
) - (b
> a
);
6191 display_debug_loc (struct dwarf_section
*section
, void *file
)
6193 unsigned char *start
= section
->start
, *vstart
= NULL
;
6194 unsigned long bytes
;
6195 unsigned char *section_begin
= start
;
6196 unsigned int num_loc_list
= 0;
6197 unsigned long last_offset
= 0;
6198 unsigned long last_view
= 0;
6199 unsigned int first
= 0;
6202 int seen_first_offset
= 0;
6203 int locs_sorted
= 1;
6204 unsigned char *next
= start
, *vnext
= vstart
;
6205 unsigned int *array
= NULL
;
6206 const char *suffix
= strrchr (section
->name
, '.');
6207 bfd_boolean is_dwo
= FALSE
;
6208 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
6209 dwarf_vma expected_start
= 0;
6211 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
6214 bytes
= section
->size
;
6218 printf (_("\nThe %s section is empty.\n"), section
->name
);
6224 unsigned char *hdrptr
= section_begin
;
6225 dwarf_vma ll_length
;
6226 unsigned short ll_version
;
6227 unsigned char *end
= section_begin
+ section
->size
;
6228 unsigned char address_size
, segment_selector_size
;
6229 uint32_t offset_entry_count
;
6231 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
6232 if (ll_length
== 0xffffffff)
6233 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
6235 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
6236 if (ll_version
!= 5)
6238 warn (_("The %s section contains corrupt or "
6239 "unsupported version number: %d.\n"),
6240 section
->name
, ll_version
);
6244 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
6246 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
6247 if (segment_selector_size
!= 0)
6249 warn (_("The %s section contains "
6250 "unsupported segment selector size: %d.\n"),
6251 section
->name
, segment_selector_size
);
6255 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
6256 if (offset_entry_count
!= 0)
6258 warn (_("The %s section contains "
6259 "unsupported offset entry count: %d.\n"),
6260 section
->name
, offset_entry_count
);
6264 expected_start
= hdrptr
- section_begin
;
6267 if (load_debug_info (file
) == 0)
6269 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6274 /* Check the order of location list in .debug_info section. If
6275 offsets of location lists are in the ascending order, we can
6276 use `debug_information' directly. */
6277 for (i
= 0; i
< num_debug_info_entries
; i
++)
6281 num
= debug_information
[i
].num_loc_offsets
;
6282 if (num
> num_loc_list
)
6285 /* Check if we can use `debug_information' directly. */
6286 if (locs_sorted
&& num
!= 0)
6288 if (!seen_first_offset
)
6290 /* This is the first location list. */
6291 last_offset
= debug_information
[i
].loc_offsets
[0];
6292 last_view
= debug_information
[i
].loc_views
[0];
6294 seen_first_offset
= 1;
6300 for (; j
< num
; j
++)
6303 debug_information
[i
].loc_offsets
[j
]
6304 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
6305 && last_view
> debug_information
[i
].loc_views
[j
]))
6310 last_offset
= debug_information
[i
].loc_offsets
[j
];
6311 last_view
= debug_information
[i
].loc_views
[j
];
6316 if (!seen_first_offset
)
6317 error (_("No location lists in .debug_info section!\n"));
6319 if (debug_information
[first
].num_loc_offsets
> 0
6320 && debug_information
[first
].loc_offsets
[0] != expected_start
6321 && debug_information
[first
].loc_views
[0] != expected_start
)
6322 warn (_("Location lists in %s section start at 0x%s\n"),
6324 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
6327 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
6329 introduce (section
, FALSE
);
6331 if (reloc_at (section
, 0))
6332 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
6334 printf (_(" Offset Begin End Expression\n"));
6336 seen_first_offset
= 0;
6337 for (i
= first
; i
< num_debug_info_entries
; i
++)
6339 dwarf_vma offset
, voffset
;
6340 dwarf_vma base_address
;
6346 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6348 loc_offsets
= debug_information
[i
].loc_offsets
;
6349 loc_views
= debug_information
[i
].loc_views
;
6350 qsort (array
, debug_information
[i
].num_loc_offsets
,
6351 sizeof (*array
), loc_offsets_compar
);
6354 int adjacent_view_loclists
= 1;
6355 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
6357 j
= locs_sorted
? k
: array
[k
];
6359 && (debug_information
[i
].loc_offsets
[locs_sorted
6360 ? k
- 1 : array
[k
- 1]]
6361 == debug_information
[i
].loc_offsets
[j
])
6362 && (debug_information
[i
].loc_views
[locs_sorted
6363 ? k
- 1 : array
[k
- 1]]
6364 == debug_information
[i
].loc_views
[j
]))
6366 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
6367 offset
= debug_information
[i
].loc_offsets
[j
];
6368 next
= section_begin
+ offset
;
6369 voffset
= debug_information
[i
].loc_views
[j
];
6371 vnext
= section_begin
+ voffset
;
6374 base_address
= debug_information
[i
].base_address
;
6376 if (vnext
&& vnext
< next
)
6379 display_view_pair_list (section
, &vstart
, i
, next
);
6384 if (!seen_first_offset
|| !adjacent_view_loclists
)
6385 seen_first_offset
= 1;
6389 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
6390 (unsigned long) (start
- section_begin
),
6391 (unsigned long) offset
);
6392 else if (start
> next
)
6393 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
6394 (unsigned long) (start
- section_begin
),
6395 (unsigned long) offset
);
6400 if (offset
>= bytes
)
6402 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
6403 (unsigned long) offset
);
6407 if (vnext
&& voffset
>= bytes
)
6409 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
6410 (unsigned long) voffset
);
6417 display_loc_list_dwo (section
, &start
, i
, offset
,
6418 &vstart
, has_frame_base
);
6420 display_loc_list (section
, &start
, i
, offset
, base_address
,
6421 &vstart
, has_frame_base
);
6426 warn (_("DWO is not yet supported.\n"));
6428 display_loclists_list (section
, &start
, i
, offset
, base_address
,
6429 &vstart
, has_frame_base
);
6432 /* FIXME: this arrangement is quite simplistic. Nothing
6433 requires locview lists to be adjacent to corresponding
6434 loclists, and a single loclist could be augmented by
6435 different locview lists, and vice-versa, unlikely as it
6436 is that it would make sense to do so. Hopefully we'll
6437 have view pair support built into loclists before we ever
6438 need to address all these possibilities. */
6439 if (adjacent_view_loclists
&& vnext
6440 && vnext
!= start
&& vstart
!= next
)
6442 adjacent_view_loclists
= 0;
6443 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
6446 if (vnext
&& vnext
== start
)
6447 display_view_pair_list (section
, &start
, i
, vstart
);
6451 if (start
< section
->start
+ section
->size
)
6452 warn (ngettext ("There is %ld unused byte at the end of section %s\n",
6453 "There are %ld unused bytes at the end of section %s\n",
6454 (long) (section
->start
+ section
->size
- start
)),
6455 (long) (section
->start
+ section
->size
- start
), section
->name
);
6462 display_debug_str (struct dwarf_section
*section
,
6463 void *file ATTRIBUTE_UNUSED
)
6465 unsigned char *start
= section
->start
;
6466 unsigned long bytes
= section
->size
;
6467 dwarf_vma addr
= section
->address
;
6471 printf (_("\nThe %s section is empty.\n"), section
->name
);
6475 introduce (section
, FALSE
);
6483 lbytes
= (bytes
> 16 ? 16 : bytes
);
6485 printf (" 0x%8.8lx ", (unsigned long) addr
);
6487 for (j
= 0; j
< 16; j
++)
6490 printf ("%2.2x", start
[j
]);
6498 for (j
= 0; j
< lbytes
; j
++)
6501 if (k
>= ' ' && k
< 0x80)
6520 display_debug_info (struct dwarf_section
*section
, void *file
)
6522 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, FALSE
);
6526 display_debug_types (struct dwarf_section
*section
, void *file
)
6528 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6532 display_trace_info (struct dwarf_section
*section
, void *file
)
6534 return process_debug_info (section
, file
, section
->abbrev_sec
, FALSE
, TRUE
);
6538 display_debug_aranges (struct dwarf_section
*section
,
6539 void *file ATTRIBUTE_UNUSED
)
6541 unsigned char *start
= section
->start
;
6542 unsigned char *end
= start
+ section
->size
;
6544 introduce (section
, FALSE
);
6546 /* It does not matter if this load fails,
6547 we test for that later on. */
6548 load_debug_info (file
);
6552 unsigned char *hdrptr
;
6553 DWARF2_Internal_ARange arange
;
6554 unsigned char *addr_ranges
;
6557 unsigned long sec_off
;
6558 unsigned char address_size
;
6560 unsigned int offset_size
;
6561 unsigned int initial_length_size
;
6565 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
6566 if (arange
.ar_length
== 0xffffffff)
6568 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
6570 initial_length_size
= 12;
6575 initial_length_size
= 4;
6578 sec_off
= hdrptr
- section
->start
;
6579 if (sec_off
+ arange
.ar_length
< sec_off
6580 || sec_off
+ arange
.ar_length
> section
->size
)
6582 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6584 sec_off
- initial_length_size
,
6585 dwarf_vmatoa ("x", arange
.ar_length
));
6589 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
6590 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
6592 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6593 && num_debug_info_entries
> 0
6594 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
6595 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6596 (unsigned long) arange
.ar_info_offset
, section
->name
);
6598 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
6599 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
6601 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
6603 /* PR 19872: A version number of 0 probably means that there is
6604 padding at the end of the .debug_aranges section. Gold puts
6605 it there when performing an incremental link, for example.
6606 So do not generate a warning in this case. */
6607 if (arange
.ar_version
)
6608 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6612 printf (_(" Length: %ld\n"),
6613 (long) arange
.ar_length
);
6614 printf (_(" Version: %d\n"), arange
.ar_version
);
6615 printf (_(" Offset into .debug_info: 0x%lx\n"),
6616 (unsigned long) arange
.ar_info_offset
);
6617 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6618 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6620 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
6622 /* PR 17512: file: 001-108546-0.001:0.1. */
6623 if (address_size
== 0 || address_size
> 8)
6625 error (_("Invalid address size in %s section!\n"),
6630 /* The DWARF spec does not require that the address size be a power
6631 of two, but we do. This will have to change if we ever encounter
6632 an uneven architecture. */
6633 if ((address_size
& (address_size
- 1)) != 0)
6635 warn (_("Pointer size + Segment size is not a power of two.\n"));
6639 if (address_size
> 4)
6640 printf (_("\n Address Length\n"));
6642 printf (_("\n Address Length\n"));
6644 addr_ranges
= hdrptr
;
6646 /* Must pad to an alignment boundary that is twice the address size. */
6647 excess
= (hdrptr
- start
) % (2 * address_size
);
6649 addr_ranges
+= (2 * address_size
) - excess
;
6651 start
+= arange
.ar_length
+ initial_length_size
;
6653 while (addr_ranges
+ 2 * address_size
<= start
)
6655 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
6656 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
6659 print_dwarf_vma (address
, address_size
);
6660 print_dwarf_vma (length
, address_size
);
6670 /* Comparison function for qsort. */
6672 comp_addr_base (const void * v0
, const void * v1
)
6674 debug_info
*info0
= *(debug_info
**) v0
;
6675 debug_info
*info1
= *(debug_info
**) v1
;
6676 return info0
->addr_base
- info1
->addr_base
;
6679 /* Display the debug_addr section. */
6681 display_debug_addr (struct dwarf_section
*section
,
6684 debug_info
**debug_addr_info
;
6685 unsigned char *entry
;
6690 if (section
->size
== 0)
6692 printf (_("\nThe %s section is empty.\n"), section
->name
);
6696 if (load_debug_info (file
) == 0)
6698 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6703 introduce (section
, FALSE
);
6705 /* PR 17531: file: cf38d01b.
6706 We use xcalloc because a corrupt file may not have initialised all of the
6707 fields in the debug_info structure, which means that the sort below might
6708 try to move uninitialised data. */
6709 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
6710 sizeof (debug_info
*));
6713 for (i
= 0; i
< num_debug_info_entries
; i
++)
6714 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
6716 /* PR 17531: file: cf38d01b. */
6717 if (debug_information
[i
].addr_base
>= section
->size
)
6718 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6719 (unsigned long) debug_information
[i
].addr_base
, i
);
6721 debug_addr_info
[count
++] = debug_information
+ i
;
6724 /* Add a sentinel to make iteration convenient. */
6725 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
6726 debug_addr_info
[count
]->addr_base
= section
->size
;
6727 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
6729 for (i
= 0; i
< count
; i
++)
6732 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
6734 printf (_(" For compilation unit at offset 0x%s:\n"),
6735 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
6737 printf (_("\tIndex\tAddress\n"));
6738 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
6739 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
6743 dwarf_vma base
= byte_get (entry
, address_size
);
6744 printf (_("\t%d:\t"), idx
);
6745 print_dwarf_vma (base
, address_size
);
6747 entry
+= address_size
;
6753 free (debug_addr_info
);
6757 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6760 display_debug_str_offsets (struct dwarf_section
*section
,
6761 void *file ATTRIBUTE_UNUSED
)
6763 if (section
->size
== 0)
6765 printf (_("\nThe %s section is empty.\n"), section
->name
);
6768 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6769 what the offset size is for this section. */
6773 /* Each debug_information[x].range_lists[y] gets this representation for
6774 sorting purposes. */
6778 /* The debug_information[x].range_lists[y] value. */
6779 dwarf_vma ranges_offset
;
6781 /* Original debug_information to find parameters of the data. */
6782 debug_info
*debug_info_p
;
6785 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6788 range_entry_compar (const void *ap
, const void *bp
)
6790 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
6791 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
6792 const dwarf_vma a
= a_re
->ranges_offset
;
6793 const dwarf_vma b
= b_re
->ranges_offset
;
6795 return (a
> b
) - (b
> a
);
6799 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
6800 unsigned int pointer_size
, unsigned long offset
,
6801 unsigned long base_address
)
6803 while (start
< finish
)
6808 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6809 if (start
>= finish
)
6811 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6814 printf (" %8.8lx ", offset
);
6816 if (begin
== 0 && end
== 0)
6818 printf (_("<End of list>\n"));
6822 /* Check base address specifiers. */
6823 if (is_max_address (begin
, pointer_size
)
6824 && !is_max_address (end
, pointer_size
))
6827 print_dwarf_vma (begin
, pointer_size
);
6828 print_dwarf_vma (end
, pointer_size
);
6829 printf ("(base address)\n");
6833 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6834 print_dwarf_vma (end
+ base_address
, pointer_size
);
6837 fputs (_("(start == end)"), stdout
);
6838 else if (begin
> end
)
6839 fputs (_("(start > end)"), stdout
);
6846 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
6847 unsigned int pointer_size
, unsigned long offset
,
6848 unsigned long base_address
)
6850 unsigned char *next
= start
;
6854 unsigned long off
= offset
+ (start
- next
);
6855 enum dwarf_range_list_entry rlet
;
6856 /* Initialize it due to a false compiler warning. */
6857 dwarf_vma begin
= -1, length
, end
= -1;
6859 if (start
+ 1 > finish
)
6861 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6866 printf (" %8.8lx ", off
);
6868 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
6872 case DW_RLE_end_of_list
:
6873 printf (_("<End of list>\n"));
6875 case DW_RLE_base_address
:
6876 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
6877 print_dwarf_vma (base_address
, pointer_size
);
6878 printf (_("(base address)\n"));
6880 case DW_RLE_start_length
:
6881 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6882 READ_ULEB (length
, start
, finish
);
6883 end
= begin
+ length
;
6885 case DW_RLE_offset_pair
:
6886 READ_ULEB (begin
, start
, finish
);
6887 READ_ULEB (end
, start
, finish
);
6889 case DW_RLE_start_end
:
6890 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6891 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6894 error (_("Invalid range list entry type %d\n"), rlet
);
6895 rlet
= DW_RLE_end_of_list
;
6898 if (rlet
== DW_RLE_end_of_list
)
6900 if (rlet
== DW_RLE_base_address
)
6903 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6904 print_dwarf_vma (end
+ base_address
, pointer_size
);
6907 fputs (_("(start == end)"), stdout
);
6908 else if (begin
> end
)
6909 fputs (_("(start > end)"), stdout
);
6916 display_debug_ranges (struct dwarf_section
*section
,
6917 void *file ATTRIBUTE_UNUSED
)
6919 unsigned char *start
= section
->start
;
6920 unsigned char *last_start
= start
;
6921 unsigned long bytes
= section
->size
;
6922 unsigned char *section_begin
= start
;
6923 unsigned char *finish
= start
+ bytes
;
6924 unsigned int num_range_list
, i
;
6925 struct range_entry
*range_entries
, *range_entry_fill
;
6926 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
6927 /* Initialize it due to a false compiler warning. */
6928 unsigned char address_size
= 0;
6932 printf (_("\nThe %s section is empty.\n"), section
->name
);
6938 dwarf_vma initial_length
;
6939 unsigned int initial_length_size
;
6940 unsigned char segment_selector_size
;
6941 unsigned int offset_size
, offset_entry_count
;
6942 unsigned short version
;
6944 /* Get and check the length of the block. */
6945 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
6947 if (initial_length
== 0xffffffff)
6949 /* This section is 64-bit DWARF 3. */
6950 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
6952 initial_length_size
= 12;
6957 initial_length_size
= 4;
6960 if (initial_length
+ initial_length_size
> section
->size
)
6962 /* If the length field has a relocation against it, then we should
6963 not complain if it is inaccurate (and probably negative).
6964 It is copied from .debug_line handling code. */
6965 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
6967 initial_length
= (finish
- start
) - initial_length_size
;
6971 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6972 (long) initial_length
);
6977 /* Get and check the version number. */
6978 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
6982 warn (_("Only DWARF version 5 debug_rnglists info "
6983 "is currently supported.\n"));
6987 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
6989 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
6990 if (segment_selector_size
!= 0)
6992 warn (_("The %s section contains "
6993 "unsupported segment selector size: %d.\n"),
6994 section
->name
, segment_selector_size
);
6998 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
6999 if (offset_entry_count
!= 0)
7001 warn (_("The %s section contains "
7002 "unsupported offset entry count: %u.\n"),
7003 section
->name
, offset_entry_count
);
7008 if (load_debug_info (file
) == 0)
7010 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
7016 for (i
= 0; i
< num_debug_info_entries
; i
++)
7017 num_range_list
+= debug_information
[i
].num_range_lists
;
7019 if (num_range_list
== 0)
7021 /* This can happen when the file was compiled with -gsplit-debug
7022 which removes references to range lists from the primary .o file. */
7023 printf (_("No range lists in .debug_info section.\n"));
7027 range_entries
= (struct range_entry
*)
7028 xmalloc (sizeof (*range_entries
) * num_range_list
);
7029 range_entry_fill
= range_entries
;
7031 for (i
= 0; i
< num_debug_info_entries
; i
++)
7033 debug_info
*debug_info_p
= &debug_information
[i
];
7036 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
7038 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
7039 range_entry_fill
->debug_info_p
= debug_info_p
;
7044 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
7045 range_entry_compar
);
7047 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
7048 warn (_("Range lists in %s section start at 0x%lx\n"),
7049 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
7051 introduce (section
, FALSE
);
7053 printf (_(" Offset Begin End\n"));
7055 for (i
= 0; i
< num_range_list
; i
++)
7057 struct range_entry
*range_entry
= &range_entries
[i
];
7058 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
7059 unsigned int pointer_size
;
7061 unsigned char *next
;
7062 dwarf_vma base_address
;
7064 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
7065 offset
= range_entry
->ranges_offset
;
7066 next
= section_begin
+ offset
;
7067 base_address
= debug_info_p
->base_address
;
7069 /* PR 17512: file: 001-101485-0.001:0.1. */
7070 if (pointer_size
< 2 || pointer_size
> 8)
7072 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
7073 pointer_size
, (unsigned long) offset
);
7077 if (next
< section_begin
|| next
>= finish
)
7079 warn (_("Corrupt offset (%#8.8lx) in range entry %u\n"),
7080 (unsigned long) offset
, i
);
7084 if (dwarf_check
!= 0 && i
> 0)
7087 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
7088 (unsigned long) (start
- section_begin
),
7089 (unsigned long) (next
- section_begin
), section
->name
);
7090 else if (start
> next
)
7092 if (next
== last_start
)
7094 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
7095 (unsigned long) (start
- section_begin
),
7096 (unsigned long) (next
- section_begin
), section
->name
);
7103 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
7104 (start
, finish
, pointer_size
, offset
, base_address
);
7108 free (range_entries
);
7113 typedef struct Frame_Chunk
7115 struct Frame_Chunk
*next
;
7116 unsigned char *chunk_start
;
7118 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
7119 short int *col_type
;
7122 unsigned int code_factor
;
7126 unsigned int cfa_reg
;
7127 dwarf_vma cfa_offset
;
7129 unsigned char fde_encoding
;
7130 unsigned char cfa_exp
;
7131 unsigned char ptr_size
;
7132 unsigned char segment_size
;
7136 typedef const char *(*dwarf_regname_lookup_ftype
) (unsigned int);
7137 static dwarf_regname_lookup_ftype dwarf_regnames_lookup_func
;
7138 static const char *const *dwarf_regnames
;
7139 static unsigned int dwarf_regnames_count
;
7142 /* A marker for a col_type that means this column was never referenced
7143 in the frame info. */
7144 #define DW_CFA_unreferenced (-1)
7146 /* Return 0 if no more space is needed, 1 if more space is needed,
7147 -1 for invalid reg. */
7150 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
7152 unsigned int prev
= fc
->ncols
;
7154 if (reg
< (unsigned int) fc
->ncols
)
7157 if (dwarf_regnames_count
> 0
7158 && reg
> dwarf_regnames_count
)
7161 fc
->ncols
= reg
+ 1;
7162 /* PR 17512: file: 10450-2643-0.004.
7163 If reg == -1 then this can happen... */
7167 /* PR 17512: file: 2844a11d. */
7168 if (fc
->ncols
> 1024 && dwarf_regnames_count
== 0)
7170 error (_("Unfeasibly large register number: %u\n"), reg
);
7172 /* FIXME: 1024 is an arbitrary limit. Increase it if
7173 we ever encounter a valid binary that exceeds it. */
7177 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
7178 sizeof (short int));
7179 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
7180 /* PR 17512: file:002-10025-0.005. */
7181 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
7183 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
7189 while (prev
< fc
->ncols
)
7191 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
7192 fc
->col_offset
[prev
] = 0;
7198 static const char *const dwarf_regnames_i386
[] =
7200 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7201 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7202 "eip", "eflags", NULL
, /* 8 - 10 */
7203 "st0", "st1", "st2", "st3", /* 11 - 14 */
7204 "st4", "st5", "st6", "st7", /* 15 - 18 */
7205 NULL
, NULL
, /* 19 - 20 */
7206 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
7207 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
7208 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
7209 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
7210 "fcw", "fsw", "mxcsr", /* 37 - 39 */
7211 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7212 "tr", "ldtr", /* 48 - 49 */
7213 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7214 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7215 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7216 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7217 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7218 NULL
, NULL
, NULL
, /* 90 - 92 */
7219 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
7222 static const char *const dwarf_regnames_iamcu
[] =
7224 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
7225 "esp", "ebp", "esi", "edi", /* 4 - 7 */
7226 "eip", "eflags", NULL
, /* 8 - 10 */
7227 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
7228 NULL
, NULL
, /* 19 - 20 */
7229 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
7230 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
7231 NULL
, NULL
, NULL
, /* 37 - 39 */
7232 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
7233 "tr", "ldtr", /* 48 - 49 */
7234 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
7235 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
7236 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
7237 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
7238 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
7239 NULL
, NULL
, NULL
, /* 90 - 92 */
7240 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
7244 init_dwarf_regnames_i386 (void)
7246 dwarf_regnames
= dwarf_regnames_i386
;
7247 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
7248 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7252 init_dwarf_regnames_iamcu (void)
7254 dwarf_regnames
= dwarf_regnames_iamcu
;
7255 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
7256 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7259 static const char *const dwarf_regnames_x86_64
[] =
7261 "rax", "rdx", "rcx", "rbx",
7262 "rsi", "rdi", "rbp", "rsp",
7263 "r8", "r9", "r10", "r11",
7264 "r12", "r13", "r14", "r15",
7266 "xmm0", "xmm1", "xmm2", "xmm3",
7267 "xmm4", "xmm5", "xmm6", "xmm7",
7268 "xmm8", "xmm9", "xmm10", "xmm11",
7269 "xmm12", "xmm13", "xmm14", "xmm15",
7270 "st0", "st1", "st2", "st3",
7271 "st4", "st5", "st6", "st7",
7272 "mm0", "mm1", "mm2", "mm3",
7273 "mm4", "mm5", "mm6", "mm7",
7275 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
7276 "fs.base", "gs.base", NULL
, NULL
,
7278 "mxcsr", "fcw", "fsw",
7279 "xmm16", "xmm17", "xmm18", "xmm19",
7280 "xmm20", "xmm21", "xmm22", "xmm23",
7281 "xmm24", "xmm25", "xmm26", "xmm27",
7282 "xmm28", "xmm29", "xmm30", "xmm31",
7283 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
7284 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
7285 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
7286 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
7287 NULL
, NULL
, NULL
, /* 115 - 117 */
7288 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
7292 init_dwarf_regnames_x86_64 (void)
7294 dwarf_regnames
= dwarf_regnames_x86_64
;
7295 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
7296 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7299 static const char *const dwarf_regnames_aarch64
[] =
7301 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
7302 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
7303 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
7304 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
7305 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7306 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, "vg", "ffr",
7307 "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
7308 "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
7309 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
7310 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
7311 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
7312 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
7313 "z0", "z1", "z2", "z3", "z4", "z5", "z6", "z7",
7314 "z8", "z9", "z10", "z11", "z12", "z13", "z14", "z15",
7315 "z16", "z17", "z18", "z19", "z20", "z21", "z22", "z23",
7316 "z24", "z25", "z26", "z27", "z28", "z29", "z30", "z31",
7320 init_dwarf_regnames_aarch64 (void)
7322 dwarf_regnames
= dwarf_regnames_aarch64
;
7323 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
7324 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7327 static const char *const dwarf_regnames_s390
[] =
7329 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
7330 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7331 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
7332 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
7333 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
7334 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
7335 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
7336 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
7337 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
7340 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
7341 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
7345 init_dwarf_regnames_s390 (void)
7347 dwarf_regnames
= dwarf_regnames_s390
;
7348 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
7349 dwarf_regnames_lookup_func
= regname_internal_by_table_only
;
7352 static const char *const dwarf_regnames_riscv
[] =
7354 "zero", "ra", "sp", "gp", "tp", "t0", "t1", "t2", /* 0 - 7 */
7355 "s0", "s1", "a0", "a1", "a2", "a3", "a4", "a5", /* 8 - 15 */
7356 "a6", "a7", "s2", "s3", "s4", "s5", "s6", "s7", /* 16 - 23 */
7357 "s8", "s9", "s10", "s11", "t3", "t4", "t5", "t6", /* 24 - 31 */
7358 "ft0", "ft1", "ft2", "ft3", "ft4", "ft5", "ft6", "ft7", /* 32 - 39 */
7359 "fs0", "fs1", /* 40 - 41 */
7360 "fa0", "fa1", "fa2", "fa3", "fa4", "fa5", "fa6", "fa7", /* 42 - 49 */
7361 "fs2", "fs3", "fs4", "fs5", "fs6", "fs7", "fs8", "fs9", /* 50 - 57 */
7362 "fs10", "fs11", /* 58 - 59 */
7363 "ft8", "ft9", "ft10", "ft11" /* 60 - 63 */
7366 /* A RISC-V replacement for REGNAME_INTERNAL_BY_TABLE_ONLY which handles
7367 the large number of CSRs. */
7370 regname_internal_riscv (unsigned int regno
)
7372 const char *name
= NULL
;
7374 /* Lookup in the table first, this covers GPR and FPR. */
7375 if (regno
< ARRAY_SIZE (dwarf_regnames_riscv
))
7376 name
= dwarf_regnames_riscv
[regno
];
7377 else if (regno
>= 4096 && regno
<= 8191)
7379 /* This might be a CSR, these live in a sparse number space from 4096
7380 to 8191 These numbers are defined in the RISC-V ELF ABI
7384 #define DECLARE_CSR(NAME,VALUE) case VALUE + 4096: name = #NAME; break;
7385 #include "opcode/riscv-opc.h"
7390 static char csr_name
[10];
7391 snprintf (csr_name
, sizeof (csr_name
), "csr%d", (regno
- 4096));
7402 init_dwarf_regnames_riscv (void)
7404 dwarf_regnames
= NULL
;
7405 dwarf_regnames_count
= 8192;
7406 dwarf_regnames_lookup_func
= regname_internal_riscv
;
7410 init_dwarf_regnames_by_elf_machine_code (unsigned int e_machine
)
7412 dwarf_regnames_lookup_func
= NULL
;
7417 init_dwarf_regnames_i386 ();
7421 init_dwarf_regnames_iamcu ();
7427 init_dwarf_regnames_x86_64 ();
7431 init_dwarf_regnames_aarch64 ();
7435 init_dwarf_regnames_s390 ();
7439 init_dwarf_regnames_riscv ();
7447 /* Initialize the DWARF register name lookup state based on the
7448 architecture and specific machine type of a BFD. */
7451 init_dwarf_regnames_by_bfd_arch_and_mach (enum bfd_architecture arch
,
7454 dwarf_regnames_lookup_func
= NULL
;
7461 case bfd_mach_x86_64
:
7462 case bfd_mach_x86_64_intel_syntax
:
7463 case bfd_mach_x86_64_nacl
:
7464 case bfd_mach_x64_32
:
7465 case bfd_mach_x64_32_intel_syntax
:
7466 case bfd_mach_x64_32_nacl
:
7467 init_dwarf_regnames_x86_64 ();
7471 init_dwarf_regnames_i386 ();
7476 case bfd_arch_iamcu
:
7477 init_dwarf_regnames_iamcu ();
7480 case bfd_arch_aarch64
:
7481 init_dwarf_regnames_aarch64();
7485 init_dwarf_regnames_s390 ();
7488 case bfd_arch_riscv
:
7489 init_dwarf_regnames_riscv ();
7498 regname_internal_by_table_only (unsigned int regno
)
7500 if (dwarf_regnames
!= NULL
7501 && regno
< dwarf_regnames_count
7502 && dwarf_regnames
[regno
] != NULL
)
7503 return dwarf_regnames
[regno
];
7509 regname (unsigned int regno
, int name_only_p
)
7511 static char reg
[64];
7513 const char *name
= NULL
;
7515 if (dwarf_regnames_lookup_func
!= NULL
)
7516 name
= dwarf_regnames_lookup_func (regno
);
7522 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
, name
);
7525 snprintf (reg
, sizeof (reg
), "r%d", regno
);
7530 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
7535 if (*max_regs
!= fc
->ncols
)
7536 *max_regs
= fc
->ncols
;
7538 if (*need_col_headers
)
7540 static const char *sloc
= " LOC";
7542 *need_col_headers
= 0;
7544 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
7546 for (r
= 0; r
< *max_regs
; r
++)
7547 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7552 printf ("%-5s ", regname (r
, 1));
7558 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
7560 strcpy (tmp
, "exp");
7562 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
7563 printf ("%-8s ", tmp
);
7565 for (r
= 0; r
< fc
->ncols
; r
++)
7567 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
7569 switch (fc
->col_type
[r
])
7571 case DW_CFA_undefined
:
7574 case DW_CFA_same_value
:
7578 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
7580 case DW_CFA_val_offset
:
7581 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
7583 case DW_CFA_register
:
7584 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
7586 case DW_CFA_expression
:
7587 strcpy (tmp
, "exp");
7589 case DW_CFA_val_expression
:
7590 strcpy (tmp
, "vexp");
7593 strcpy (tmp
, "n/a");
7596 printf ("%-5s ", tmp
);
7602 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
7604 static unsigned char *
7605 read_cie (unsigned char *start
, unsigned char *end
,
7606 Frame_Chunk
**p_cie
, int *p_version
,
7607 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
7611 unsigned char *augmentation_data
= NULL
;
7612 bfd_size_type augmentation_data_len
= 0;
7615 /* PR 17512: file: 001-228113-0.004. */
7619 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7620 memset (fc
, 0, sizeof (Frame_Chunk
));
7622 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7623 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7627 fc
->augmentation
= (char *) start
;
7628 /* PR 17512: file: 001-228113-0.004.
7629 Skip past augmentation name, but avoid running off the end of the data. */
7631 if (* start
++ == '\0')
7635 warn (_("No terminator for augmentation name\n"));
7639 if (strcmp (fc
->augmentation
, "eh") == 0)
7640 start
+= eh_addr_size
;
7644 GET (fc
->ptr_size
, 1);
7645 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
7647 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
7651 GET (fc
->segment_size
, 1);
7652 /* PR 17512: file: e99d2804. */
7653 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
7655 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
7659 eh_addr_size
= fc
->ptr_size
;
7663 fc
->ptr_size
= eh_addr_size
;
7664 fc
->segment_size
= 0;
7667 READ_ULEB (fc
->code_factor
, start
, end
);
7668 READ_SLEB (fc
->data_factor
, start
, end
);
7676 READ_ULEB (fc
->ra
, start
, end
);
7679 if (fc
->augmentation
[0] == 'z')
7681 READ_ULEB (augmentation_data_len
, start
, end
);
7682 augmentation_data
= start
;
7683 /* PR 17512: file: 11042-2589-0.004. */
7684 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
7686 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7687 dwarf_vmatoa ("x", augmentation_data_len
),
7688 (unsigned long) (end
- start
));
7691 start
+= augmentation_data_len
;
7694 if (augmentation_data_len
)
7698 unsigned char *qend
;
7700 p
= (unsigned char *) fc
->augmentation
+ 1;
7701 q
= augmentation_data
;
7702 qend
= q
+ augmentation_data_len
;
7704 while (p
< end
&& q
< qend
)
7709 q
+= 1 + size_of_encoded_value (*q
);
7711 fc
->fde_encoding
= *q
++;
7720 /* Note - it is OK if this loop terminates with q < qend.
7721 Padding may have been inserted to align the end of the CIE. */
7726 *p_version
= version
;
7729 *p_aug_len
= augmentation_data_len
;
7730 *p_aug
= augmentation_data
;
7735 free (fc
->col_offset
);
7736 free (fc
->col_type
);
7741 /* Prints out the contents on the DATA array formatted as unsigned bytes.
7742 If do_wide is not enabled, then formats the output to fit into 80 columns.
7743 PRINTED contains the number of characters already written to the current
7747 display_data (bfd_size_type printed
,
7748 const unsigned char * data
,
7749 const bfd_size_type len
)
7751 if (do_wide
|| len
< ((80 - printed
) / 3))
7752 for (printed
= 0; printed
< len
; ++printed
)
7753 printf (" %02x", data
[printed
]);
7756 for (printed
= 0; printed
< len
; ++printed
)
7758 if (printed
% (80 / 3) == 0)
7760 printf (" %02x", data
[printed
]);
7765 /* Prints out the contents on the augmentation data array.
7766 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7769 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
7773 i
= printf (_(" Augmentation data: "));
7774 display_data (i
, data
, len
);
7778 display_debug_frames (struct dwarf_section
*section
,
7779 void *file ATTRIBUTE_UNUSED
)
7781 unsigned char *start
= section
->start
;
7782 unsigned char *end
= start
+ section
->size
;
7783 unsigned char *section_start
= start
;
7784 Frame_Chunk
*chunks
= NULL
, *forward_refs
= NULL
;
7785 Frame_Chunk
*remembered_state
= NULL
;
7787 bfd_boolean is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
7788 unsigned int max_regs
= 0;
7789 const char *bad_reg
= _("bad register: ");
7790 unsigned int saved_eh_addr_size
= eh_addr_size
;
7792 introduce (section
, FALSE
);
7796 unsigned char *saved_start
;
7797 unsigned char *block_end
;
7802 int need_col_headers
= 1;
7803 unsigned char *augmentation_data
= NULL
;
7804 bfd_size_type augmentation_data_len
= 0;
7805 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
7806 unsigned int offset_size
;
7807 unsigned int initial_length_size
;
7808 bfd_boolean all_nops
;
7809 static Frame_Chunk fde_fc
;
7811 saved_start
= start
;
7813 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7817 printf ("\n%08lx ZERO terminator\n\n",
7818 (unsigned long)(saved_start
- section_start
));
7819 /* Skip any zero terminators that directly follow.
7820 A corrupt section size could have loaded a whole
7821 slew of zero filled memory bytes. eg
7822 PR 17512: file: 070-19381-0.004. */
7823 while (start
< end
&& * start
== 0)
7828 if (length
== 0xffffffff)
7830 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7832 initial_length_size
= 12;
7837 initial_length_size
= 4;
7840 block_end
= saved_start
+ length
+ initial_length_size
;
7841 if (block_end
> end
|| block_end
< start
)
7843 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7844 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
7845 (unsigned long) (saved_start
- section_start
));
7849 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
7851 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
7852 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
7857 start
= read_cie (start
, end
, &cie
, &version
,
7858 &augmentation_data_len
, &augmentation_data
);
7859 /* PR 17512: file: 027-135133-0.005. */
7866 fc
->chunk_start
= saved_start
;
7867 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7870 if (frame_need_space (fc
, mreg
) < 0)
7872 if (fc
->fde_encoding
)
7873 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7875 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
7876 print_dwarf_vma (length
, fc
->ptr_size
);
7877 print_dwarf_vma (cie_id
, offset_size
);
7879 if (do_debug_frames_interp
)
7881 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
7882 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
7887 printf (" Version: %d\n", version
);
7888 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
7891 printf (" Pointer Size: %u\n", fc
->ptr_size
);
7892 printf (" Segment Size: %u\n", fc
->segment_size
);
7894 printf (" Code alignment factor: %u\n", fc
->code_factor
);
7895 printf (" Data alignment factor: %d\n", fc
->data_factor
);
7896 printf (" Return address column: %d\n", fc
->ra
);
7898 if (augmentation_data_len
)
7899 display_augmentation_data (augmentation_data
, augmentation_data_len
);
7906 unsigned char *look_for
;
7907 unsigned long segment_selector
;
7911 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
7912 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
7915 look_for
= section_start
+ cie_id
;
7917 if (look_for
<= saved_start
)
7919 for (cie
= chunks
; cie
; cie
= cie
->next
)
7920 if (cie
->chunk_start
== look_for
)
7925 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
7926 if (cie
->chunk_start
== look_for
)
7930 unsigned int off_size
;
7931 unsigned char *cie_scan
;
7933 cie_scan
= look_for
;
7935 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
7936 if (length
== 0xffffffff)
7938 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
7945 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
7948 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
7949 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
7954 read_cie (cie_scan
, end
, &cie
, &version
,
7955 &augmentation_data_len
, &augmentation_data
);
7956 /* PR 17512: file: 3450-2098-0.004. */
7959 warn (_("Failed to read CIE information\n"));
7962 cie
->next
= forward_refs
;
7964 cie
->chunk_start
= look_for
;
7965 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7968 if (frame_need_space (cie
, mreg
) < 0)
7970 warn (_("Invalid max register\n"));
7973 if (cie
->fde_encoding
)
7975 = size_of_encoded_value (cie
->fde_encoding
);
7982 memset (fc
, 0, sizeof (Frame_Chunk
));
7986 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7987 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
7988 (unsigned long) (saved_start
- section_start
));
7990 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7991 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7992 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
7994 warn (_("Invalid max register\n"));
7998 fc
->augmentation
= "";
7999 fc
->fde_encoding
= 0;
8000 fc
->ptr_size
= eh_addr_size
;
8001 fc
->segment_size
= 0;
8005 fc
->ncols
= cie
->ncols
;
8006 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
8007 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
8008 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
8009 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
8010 fc
->augmentation
= cie
->augmentation
;
8011 fc
->ptr_size
= cie
->ptr_size
;
8012 eh_addr_size
= cie
->ptr_size
;
8013 fc
->segment_size
= cie
->segment_size
;
8014 fc
->code_factor
= cie
->code_factor
;
8015 fc
->data_factor
= cie
->data_factor
;
8016 fc
->cfa_reg
= cie
->cfa_reg
;
8017 fc
->cfa_offset
= cie
->cfa_offset
;
8019 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
8021 warn (_("Invalid max register\n"));
8024 fc
->fde_encoding
= cie
->fde_encoding
;
8027 if (fc
->fde_encoding
)
8028 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
8030 segment_selector
= 0;
8031 if (fc
->segment_size
)
8033 if (fc
->segment_size
> sizeof (segment_selector
))
8035 /* PR 17512: file: 9e196b3e. */
8036 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
8037 fc
->segment_size
= 4;
8039 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
8042 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
8044 /* FIXME: It appears that sometimes the final pc_range value is
8045 encoded in less than encoded_ptr_size bytes. See the x86_64
8046 run of the "objcopy on compressed debug sections" test for an
8048 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
8050 if (cie
->augmentation
[0] == 'z')
8052 READ_ULEB (augmentation_data_len
, start
, end
);
8053 augmentation_data
= start
;
8054 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
8055 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
8057 warn (_("Augmentation data too long: 0x%s, "
8058 "expected at most %#lx\n"),
8059 dwarf_vmatoa ("x", augmentation_data_len
),
8060 (unsigned long) (end
- start
));
8062 augmentation_data
= NULL
;
8063 augmentation_data_len
= 0;
8065 start
+= augmentation_data_len
;
8068 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
8069 (unsigned long)(saved_start
- section_start
),
8070 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
8071 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
8072 (unsigned long)(cie
->chunk_start
- section_start
));
8074 if (fc
->segment_size
)
8075 printf ("%04lx:", segment_selector
);
8078 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
8079 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
8081 if (! do_debug_frames_interp
&& augmentation_data_len
)
8083 display_augmentation_data (augmentation_data
, augmentation_data_len
);
8088 /* At this point, fc is the current chunk, cie (if any) is set, and
8089 we're about to interpret instructions for the chunk. */
8090 /* ??? At present we need to do this always, since this sizes the
8091 fc->col_type and fc->col_offset arrays, which we write into always.
8092 We should probably split the interpreted and non-interpreted bits
8093 into two different routines, since there's so much that doesn't
8094 really overlap between them. */
8095 if (1 || do_debug_frames_interp
)
8097 /* Start by making a pass over the chunk, allocating storage
8098 and taking note of what registers are used. */
8099 unsigned char *tmp
= start
;
8101 while (start
< block_end
)
8103 unsigned int reg
, op
, opa
;
8105 unsigned char * new_start
;
8112 /* Warning: if you add any more cases to this switch, be
8113 sure to add them to the corresponding switch below. */
8116 case DW_CFA_advance_loc
:
8119 SKIP_ULEB (start
, end
);
8120 if (frame_need_space (fc
, opa
) >= 0)
8121 fc
->col_type
[opa
] = DW_CFA_undefined
;
8123 case DW_CFA_restore
:
8124 if (frame_need_space (fc
, opa
) >= 0)
8125 fc
->col_type
[opa
] = DW_CFA_undefined
;
8127 case DW_CFA_set_loc
:
8128 start
+= encoded_ptr_size
;
8130 case DW_CFA_advance_loc1
:
8133 case DW_CFA_advance_loc2
:
8136 case DW_CFA_advance_loc4
:
8139 case DW_CFA_offset_extended
:
8140 case DW_CFA_val_offset
:
8141 READ_ULEB (reg
, start
, end
);
8142 SKIP_ULEB (start
, end
);
8143 if (frame_need_space (fc
, reg
) >= 0)
8144 fc
->col_type
[reg
] = DW_CFA_undefined
;
8146 case DW_CFA_restore_extended
:
8147 READ_ULEB (reg
, start
, end
);
8148 if (frame_need_space (fc
, reg
) >= 0)
8149 fc
->col_type
[reg
] = DW_CFA_undefined
;
8151 case DW_CFA_undefined
:
8152 READ_ULEB (reg
, start
, end
);
8153 if (frame_need_space (fc
, reg
) >= 0)
8154 fc
->col_type
[reg
] = DW_CFA_undefined
;
8156 case DW_CFA_same_value
:
8157 READ_ULEB (reg
, start
, end
);
8158 if (frame_need_space (fc
, reg
) >= 0)
8159 fc
->col_type
[reg
] = DW_CFA_undefined
;
8161 case DW_CFA_register
:
8162 READ_ULEB (reg
, start
, end
);
8163 SKIP_ULEB (start
, end
);
8164 if (frame_need_space (fc
, reg
) >= 0)
8165 fc
->col_type
[reg
] = DW_CFA_undefined
;
8167 case DW_CFA_def_cfa
:
8168 SKIP_ULEB (start
, end
);
8169 SKIP_ULEB (start
, end
);
8171 case DW_CFA_def_cfa_register
:
8172 SKIP_ULEB (start
, end
);
8174 case DW_CFA_def_cfa_offset
:
8175 SKIP_ULEB (start
, end
);
8177 case DW_CFA_def_cfa_expression
:
8178 READ_ULEB (temp
, start
, end
);
8179 new_start
= start
+ temp
;
8180 if (new_start
< start
)
8182 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
8188 case DW_CFA_expression
:
8189 case DW_CFA_val_expression
:
8190 READ_ULEB (reg
, start
, end
);
8191 READ_ULEB (temp
, start
, end
);
8192 new_start
= start
+ temp
;
8193 if (new_start
< start
)
8195 /* PR 17512: file:306-192417-0.005. */
8196 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
8201 if (frame_need_space (fc
, reg
) >= 0)
8202 fc
->col_type
[reg
] = DW_CFA_undefined
;
8204 case DW_CFA_offset_extended_sf
:
8205 case DW_CFA_val_offset_sf
:
8206 READ_ULEB (reg
, start
, end
);
8207 SKIP_SLEB (start
, end
);
8208 if (frame_need_space (fc
, reg
) >= 0)
8209 fc
->col_type
[reg
] = DW_CFA_undefined
;
8211 case DW_CFA_def_cfa_sf
:
8212 SKIP_ULEB (start
, end
);
8213 SKIP_SLEB (start
, end
);
8215 case DW_CFA_def_cfa_offset_sf
:
8216 SKIP_SLEB (start
, end
);
8218 case DW_CFA_MIPS_advance_loc8
:
8221 case DW_CFA_GNU_args_size
:
8222 SKIP_ULEB (start
, end
);
8224 case DW_CFA_GNU_negative_offset_extended
:
8225 READ_ULEB (reg
, start
, end
);
8226 SKIP_ULEB (start
, end
);
8227 if (frame_need_space (fc
, reg
) >= 0)
8228 fc
->col_type
[reg
] = DW_CFA_undefined
;
8239 /* Now we know what registers are used, make a second pass over
8240 the chunk, this time actually printing out the info. */
8242 while (start
< block_end
)
8244 unsigned char * tmp
;
8246 unsigned long ul
, roffs
;
8247 /* Note: It is tempting to use an unsigned long for 'reg' but there
8248 are various functions, notably frame_space_needed() that assume that
8249 reg is an unsigned int. */
8254 const char *reg_prefix
= "";
8261 /* Make a note if something other than DW_CFA_nop happens. */
8262 if (op
!= DW_CFA_nop
)
8265 /* Warning: if you add any more cases to this switch, be
8266 sure to add them to the corresponding switch above. */
8269 case DW_CFA_advance_loc
:
8270 if (do_debug_frames_interp
)
8271 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8273 printf (" DW_CFA_advance_loc: %d to %s\n",
8274 opa
* fc
->code_factor
,
8275 dwarf_vmatoa_1 (NULL
,
8276 fc
->pc_begin
+ opa
* fc
->code_factor
,
8278 fc
->pc_begin
+= opa
* fc
->code_factor
;
8282 READ_ULEB (roffs
, start
, end
);
8283 if (opa
>= (unsigned int) fc
->ncols
)
8284 reg_prefix
= bad_reg
;
8285 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8286 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
8287 reg_prefix
, regname (opa
, 0),
8288 roffs
* fc
->data_factor
);
8289 if (*reg_prefix
== '\0')
8291 fc
->col_type
[opa
] = DW_CFA_offset
;
8292 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
8296 case DW_CFA_restore
:
8297 if (opa
>= (unsigned int) fc
->ncols
)
8298 reg_prefix
= bad_reg
;
8299 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8300 printf (" DW_CFA_restore: %s%s\n",
8301 reg_prefix
, regname (opa
, 0));
8302 if (*reg_prefix
!= '\0')
8305 if (opa
>= (unsigned int) cie
->ncols
8306 || (do_debug_frames_interp
8307 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
8309 fc
->col_type
[opa
] = DW_CFA_undefined
;
8310 fc
->col_offset
[opa
] = 0;
8314 fc
->col_type
[opa
] = cie
->col_type
[opa
];
8315 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
8319 case DW_CFA_set_loc
:
8320 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
8321 if (do_debug_frames_interp
)
8322 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8324 printf (" DW_CFA_set_loc: %s\n",
8325 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
8329 case DW_CFA_advance_loc1
:
8330 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
8331 if (do_debug_frames_interp
)
8332 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8334 printf (" DW_CFA_advance_loc1: %ld to %s\n",
8335 (unsigned long) (ofs
* fc
->code_factor
),
8336 dwarf_vmatoa_1 (NULL
,
8337 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8339 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8342 case DW_CFA_advance_loc2
:
8343 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
8344 if (do_debug_frames_interp
)
8345 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8347 printf (" DW_CFA_advance_loc2: %ld to %s\n",
8348 (unsigned long) (ofs
* fc
->code_factor
),
8349 dwarf_vmatoa_1 (NULL
,
8350 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8352 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8355 case DW_CFA_advance_loc4
:
8356 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
8357 if (do_debug_frames_interp
)
8358 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8360 printf (" DW_CFA_advance_loc4: %ld to %s\n",
8361 (unsigned long) (ofs
* fc
->code_factor
),
8362 dwarf_vmatoa_1 (NULL
,
8363 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8365 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8368 case DW_CFA_offset_extended
:
8369 READ_ULEB (reg
, start
, end
);
8370 READ_ULEB (roffs
, start
, end
);
8371 if (reg
>= (unsigned int) fc
->ncols
)
8372 reg_prefix
= bad_reg
;
8373 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8374 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
8375 reg_prefix
, regname (reg
, 0),
8376 roffs
* fc
->data_factor
);
8377 if (*reg_prefix
== '\0')
8379 fc
->col_type
[reg
] = DW_CFA_offset
;
8380 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8384 case DW_CFA_val_offset
:
8385 READ_ULEB (reg
, start
, end
);
8386 READ_ULEB (roffs
, start
, end
);
8387 if (reg
>= (unsigned int) fc
->ncols
)
8388 reg_prefix
= bad_reg
;
8389 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8390 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
8391 reg_prefix
, regname (reg
, 0),
8392 roffs
* fc
->data_factor
);
8393 if (*reg_prefix
== '\0')
8395 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8396 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
8400 case DW_CFA_restore_extended
:
8401 READ_ULEB (reg
, start
, end
);
8402 if (reg
>= (unsigned int) fc
->ncols
)
8403 reg_prefix
= bad_reg
;
8404 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8405 printf (" DW_CFA_restore_extended: %s%s\n",
8406 reg_prefix
, regname (reg
, 0));
8407 if (*reg_prefix
!= '\0')
8410 if (reg
>= (unsigned int) cie
->ncols
)
8412 fc
->col_type
[reg
] = DW_CFA_undefined
;
8413 fc
->col_offset
[reg
] = 0;
8417 fc
->col_type
[reg
] = cie
->col_type
[reg
];
8418 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
8422 case DW_CFA_undefined
:
8423 READ_ULEB (reg
, start
, end
);
8424 if (reg
>= (unsigned int) fc
->ncols
)
8425 reg_prefix
= bad_reg
;
8426 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8427 printf (" DW_CFA_undefined: %s%s\n",
8428 reg_prefix
, regname (reg
, 0));
8429 if (*reg_prefix
== '\0')
8431 fc
->col_type
[reg
] = DW_CFA_undefined
;
8432 fc
->col_offset
[reg
] = 0;
8436 case DW_CFA_same_value
:
8437 READ_ULEB (reg
, start
, end
);
8438 if (reg
>= (unsigned int) fc
->ncols
)
8439 reg_prefix
= bad_reg
;
8440 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8441 printf (" DW_CFA_same_value: %s%s\n",
8442 reg_prefix
, regname (reg
, 0));
8443 if (*reg_prefix
== '\0')
8445 fc
->col_type
[reg
] = DW_CFA_same_value
;
8446 fc
->col_offset
[reg
] = 0;
8450 case DW_CFA_register
:
8451 READ_ULEB (reg
, start
, end
);
8452 READ_ULEB (roffs
, start
, end
);
8453 if (reg
>= (unsigned int) fc
->ncols
)
8454 reg_prefix
= bad_reg
;
8455 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8457 printf (" DW_CFA_register: %s%s in ",
8458 reg_prefix
, regname (reg
, 0));
8459 puts (regname (roffs
, 0));
8461 if (*reg_prefix
== '\0')
8463 fc
->col_type
[reg
] = DW_CFA_register
;
8464 fc
->col_offset
[reg
] = roffs
;
8468 case DW_CFA_remember_state
:
8469 if (! do_debug_frames_interp
)
8470 printf (" DW_CFA_remember_state\n");
8471 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
8472 rs
->cfa_offset
= fc
->cfa_offset
;
8473 rs
->cfa_reg
= fc
->cfa_reg
;
8475 rs
->cfa_exp
= fc
->cfa_exp
;
8476 rs
->ncols
= fc
->ncols
;
8477 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
8478 sizeof (* rs
->col_type
));
8479 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
8480 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
8481 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
8482 rs
->next
= remembered_state
;
8483 remembered_state
= rs
;
8486 case DW_CFA_restore_state
:
8487 if (! do_debug_frames_interp
)
8488 printf (" DW_CFA_restore_state\n");
8489 rs
= remembered_state
;
8492 remembered_state
= rs
->next
;
8493 fc
->cfa_offset
= rs
->cfa_offset
;
8494 fc
->cfa_reg
= rs
->cfa_reg
;
8496 fc
->cfa_exp
= rs
->cfa_exp
;
8497 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
8499 warn (_("Invalid column number in saved frame state\n"));
8503 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
8504 memcpy (fc
->col_offset
, rs
->col_offset
,
8505 rs
->ncols
* sizeof (* rs
->col_offset
));
8506 free (rs
->col_type
);
8507 free (rs
->col_offset
);
8510 else if (do_debug_frames_interp
)
8511 printf ("Mismatched DW_CFA_restore_state\n");
8514 case DW_CFA_def_cfa
:
8515 READ_ULEB (fc
->cfa_reg
, start
, end
);
8516 READ_ULEB (fc
->cfa_offset
, start
, end
);
8518 if (! do_debug_frames_interp
)
8519 printf (" DW_CFA_def_cfa: %s ofs %d\n",
8520 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8523 case DW_CFA_def_cfa_register
:
8524 READ_ULEB (fc
->cfa_reg
, start
, end
);
8526 if (! do_debug_frames_interp
)
8527 printf (" DW_CFA_def_cfa_register: %s\n",
8528 regname (fc
->cfa_reg
, 0));
8531 case DW_CFA_def_cfa_offset
:
8532 READ_ULEB (fc
->cfa_offset
, start
, end
);
8533 if (! do_debug_frames_interp
)
8534 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
8538 if (! do_debug_frames_interp
)
8539 printf (" DW_CFA_nop\n");
8542 case DW_CFA_def_cfa_expression
:
8543 READ_ULEB (ul
, start
, end
);
8544 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
8546 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
8549 if (! do_debug_frames_interp
)
8551 printf (" DW_CFA_def_cfa_expression (");
8552 decode_location_expression (start
, eh_addr_size
, 0, -1,
8560 case DW_CFA_expression
:
8561 READ_ULEB (reg
, start
, end
);
8562 READ_ULEB (ul
, start
, end
);
8563 if (reg
>= (unsigned int) fc
->ncols
)
8564 reg_prefix
= bad_reg
;
8565 /* PR 17512: file: 069-133014-0.006. */
8566 /* PR 17512: file: 98c02eb4. */
8568 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8570 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
8573 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8575 printf (" DW_CFA_expression: %s%s (",
8576 reg_prefix
, regname (reg
, 0));
8577 decode_location_expression (start
, eh_addr_size
, 0, -1,
8581 if (*reg_prefix
== '\0')
8582 fc
->col_type
[reg
] = DW_CFA_expression
;
8586 case DW_CFA_val_expression
:
8587 READ_ULEB (reg
, start
, end
);
8588 READ_ULEB (ul
, start
, end
);
8589 if (reg
>= (unsigned int) fc
->ncols
)
8590 reg_prefix
= bad_reg
;
8592 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
8594 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
8597 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8599 printf (" DW_CFA_val_expression: %s%s (",
8600 reg_prefix
, regname (reg
, 0));
8601 decode_location_expression (start
, eh_addr_size
, 0, -1,
8605 if (*reg_prefix
== '\0')
8606 fc
->col_type
[reg
] = DW_CFA_val_expression
;
8610 case DW_CFA_offset_extended_sf
:
8611 READ_ULEB (reg
, start
, end
);
8612 READ_SLEB (l
, start
, end
);
8613 if (frame_need_space (fc
, reg
) < 0)
8614 reg_prefix
= bad_reg
;
8615 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8616 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
8617 reg_prefix
, regname (reg
, 0),
8618 (long)(l
* fc
->data_factor
));
8619 if (*reg_prefix
== '\0')
8621 fc
->col_type
[reg
] = DW_CFA_offset
;
8622 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8626 case DW_CFA_val_offset_sf
:
8627 READ_ULEB (reg
, start
, end
);
8628 READ_SLEB (l
, start
, end
);
8629 if (frame_need_space (fc
, reg
) < 0)
8630 reg_prefix
= bad_reg
;
8631 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8632 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
8633 reg_prefix
, regname (reg
, 0),
8634 (long)(l
* fc
->data_factor
));
8635 if (*reg_prefix
== '\0')
8637 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8638 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8642 case DW_CFA_def_cfa_sf
:
8643 READ_ULEB (fc
->cfa_reg
, start
, end
);
8644 READ_ULEB (fc
->cfa_offset
, start
, end
);
8645 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
8647 if (! do_debug_frames_interp
)
8648 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8649 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8652 case DW_CFA_def_cfa_offset_sf
:
8653 READ_ULEB (fc
->cfa_offset
, start
, end
);
8654 fc
->cfa_offset
*= fc
->data_factor
;
8655 if (! do_debug_frames_interp
)
8656 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
8659 case DW_CFA_MIPS_advance_loc8
:
8660 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
8661 if (do_debug_frames_interp
)
8662 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8664 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8665 (unsigned long) (ofs
* fc
->code_factor
),
8666 dwarf_vmatoa_1 (NULL
,
8667 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8669 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8672 case DW_CFA_GNU_window_save
:
8673 if (! do_debug_frames_interp
)
8674 printf (" DW_CFA_GNU_window_save\n");
8677 case DW_CFA_GNU_args_size
:
8678 READ_ULEB (ul
, start
, end
);
8679 if (! do_debug_frames_interp
)
8680 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
8683 case DW_CFA_GNU_negative_offset_extended
:
8684 READ_ULEB (reg
, start
, end
);
8685 READ_SLEB (l
, start
, end
);
8687 if (frame_need_space (fc
, reg
) < 0)
8688 reg_prefix
= bad_reg
;
8689 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8690 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8691 reg_prefix
, regname (reg
, 0),
8692 (long)(l
* fc
->data_factor
));
8693 if (*reg_prefix
== '\0')
8695 fc
->col_type
[reg
] = DW_CFA_offset
;
8696 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8701 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
8702 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
8704 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
8709 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8710 if (do_debug_frames_interp
&& ! all_nops
)
8711 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8713 if (fde_fc
.col_type
!= NULL
)
8715 free (fde_fc
.col_type
);
8716 fde_fc
.col_type
= NULL
;
8718 if (fde_fc
.col_offset
!= NULL
)
8720 free (fde_fc
.col_offset
);
8721 fde_fc
.col_offset
= NULL
;
8725 eh_addr_size
= saved_eh_addr_size
;
8730 while (remembered_state
!= NULL
)
8732 rs
= remembered_state
;
8733 remembered_state
= rs
->next
;
8734 free (rs
->col_type
);
8735 free (rs
->col_offset
);
8736 rs
->next
= NULL
; /* Paranoia. */
8740 while (chunks
!= NULL
)
8744 free (rs
->col_type
);
8745 free (rs
->col_offset
);
8746 rs
->next
= NULL
; /* Paranoia. */
8750 while (forward_refs
!= NULL
)
8753 forward_refs
= rs
->next
;
8754 free (rs
->col_type
);
8755 free (rs
->col_offset
);
8756 rs
->next
= NULL
; /* Paranoia. */
8766 display_debug_names (struct dwarf_section
*section
, void *file
)
8768 unsigned char *hdrptr
= section
->start
;
8769 dwarf_vma unit_length
;
8770 unsigned char *unit_start
;
8771 const unsigned char *const section_end
= section
->start
+ section
->size
;
8772 unsigned char *unit_end
;
8774 introduce (section
, FALSE
);
8776 load_debug_section_with_follow (str
, file
);
8778 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
8780 unsigned int offset_size
;
8781 uint16_t dwarf_version
, padding
;
8782 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
8783 uint32_t bucket_count
, name_count
, abbrev_table_size
;
8784 uint32_t augmentation_string_size
;
8786 unsigned long sec_off
;
8787 bfd_boolean augmentation_printable
;
8788 const char *augmentation_string
;
8790 unit_start
= hdrptr
;
8792 /* Get and check the length of the block. */
8793 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
8795 if (unit_length
== 0xffffffff)
8797 /* This section is 64-bit DWARF. */
8798 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
8803 unit_end
= hdrptr
+ unit_length
;
8805 sec_off
= hdrptr
- section
->start
;
8806 if (sec_off
+ unit_length
< sec_off
8807 || sec_off
+ unit_length
> section
->size
)
8809 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8811 (unsigned long) (unit_start
- section
->start
),
8812 dwarf_vmatoa ("x", unit_length
));
8816 /* Get and check the version number. */
8817 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
8818 printf (_("Version %ld\n"), (long) dwarf_version
);
8820 /* Prior versions did not exist, and future versions may not be
8821 backwards compatible. */
8822 if (dwarf_version
!= 5)
8824 warn (_("Only DWARF version 5 .debug_names "
8825 "is currently supported.\n"));
8829 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
8831 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8834 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
8835 if (comp_unit_count
== 0)
8836 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8838 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
8839 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
8840 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
8841 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
8842 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
8844 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
8845 if (augmentation_string_size
% 4 != 0)
8847 warn (_("Augmentation string length %u must be rounded up "
8848 "to a multiple of 4 in .debug_names.\n"),
8849 augmentation_string_size
);
8850 augmentation_string_size
+= (-augmentation_string_size
) & 3;
8853 printf (_("Augmentation string:"));
8855 augmentation_printable
= TRUE
;
8856 augmentation_string
= (const char *) hdrptr
;
8858 for (i
= 0; i
< augmentation_string_size
; i
++)
8862 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
8863 printf (" %02x", uc
);
8865 if (uc
!= 0 && !ISPRINT (uc
))
8866 augmentation_printable
= FALSE
;
8869 if (augmentation_printable
)
8873 i
< augmentation_string_size
&& augmentation_string
[i
];
8875 putchar (augmentation_string
[i
]);
8880 printf (_("CU table:\n"));
8881 for (i
= 0; i
< comp_unit_count
; i
++)
8885 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
8886 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
8890 printf (_("TU table:\n"));
8891 for (i
= 0; i
< local_type_unit_count
; i
++)
8895 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
8896 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
8900 printf (_("Foreign TU table:\n"));
8901 for (i
= 0; i
< foreign_type_unit_count
; i
++)
8905 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
8906 printf (_("[%3u] "), i
);
8907 print_dwarf_vma (signature
, 8);
8912 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
8913 hdrptr
+= bucket_count
* sizeof (uint32_t);
8914 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
8915 hdrptr
+= name_count
* sizeof (uint32_t);
8916 unsigned char *const name_table_string_offsets
= hdrptr
;
8917 hdrptr
+= name_count
* offset_size
;
8918 unsigned char *const name_table_entry_offsets
= hdrptr
;
8919 hdrptr
+= name_count
* offset_size
;
8920 unsigned char *const abbrev_table
= hdrptr
;
8921 hdrptr
+= abbrev_table_size
;
8922 const unsigned char *const abbrev_table_end
= hdrptr
;
8923 unsigned char *const entry_pool
= hdrptr
;
8924 if (hdrptr
> unit_end
)
8926 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8927 "for unit 0x%lx in the debug_names\n"),
8928 (long) (hdrptr
- section
->start
),
8929 (long) (unit_end
- section
->start
),
8930 (long) (unit_start
- section
->start
));
8934 size_t buckets_filled
= 0;
8936 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
8938 const uint32_t bucket
= hash_table_buckets
[bucketi
];
8943 printf (ngettext ("Used %zu of %lu bucket.\n",
8944 "Used %zu of %lu buckets.\n",
8946 buckets_filled
, (unsigned long) bucket_count
);
8948 uint32_t hash_prev
= 0;
8949 size_t hash_clash_count
= 0;
8950 size_t longest_clash
= 0;
8951 size_t this_length
= 0;
8953 for (hashi
= 0; hashi
< name_count
; hashi
++)
8955 const uint32_t hash_this
= hash_table_hashes
[hashi
];
8959 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
8963 longest_clash
= MAX (longest_clash
, this_length
);
8968 hash_prev
= hash_this
;
8970 printf (_("Out of %lu items there are %zu bucket clashes"
8971 " (longest of %zu entries).\n"),
8972 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
8973 assert (name_count
== buckets_filled
+ hash_clash_count
);
8975 struct abbrev_lookup_entry
8977 dwarf_vma abbrev_tag
;
8978 unsigned char *abbrev_lookup_ptr
;
8980 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
8981 size_t abbrev_lookup_used
= 0;
8982 size_t abbrev_lookup_allocated
= 0;
8984 unsigned char *abbrevptr
= abbrev_table
;
8987 dwarf_vma abbrev_tag
;
8989 READ_ULEB (abbrev_tag
, abbrevptr
, abbrev_table_end
);
8990 if (abbrev_tag
== 0)
8992 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
8994 abbrev_lookup_allocated
= MAX (0x100,
8995 abbrev_lookup_allocated
* 2);
8996 abbrev_lookup
= xrealloc (abbrev_lookup
,
8997 (abbrev_lookup_allocated
8998 * sizeof (*abbrev_lookup
)));
9000 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
9001 struct abbrev_lookup_entry
*entry
;
9002 for (entry
= abbrev_lookup
;
9003 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9005 if (entry
->abbrev_tag
== abbrev_tag
)
9007 warn (_("Duplicate abbreviation tag %lu "
9008 "in unit 0x%lx in the debug_names\n"),
9009 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
9012 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
9013 entry
->abbrev_tag
= abbrev_tag
;
9014 entry
->abbrev_lookup_ptr
= abbrevptr
;
9016 /* Skip DWARF tag. */
9017 SKIP_ULEB (abbrevptr
, abbrev_table_end
);
9020 dwarf_vma xindex
, form
;
9022 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9023 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9024 if (xindex
== 0 && form
== 0)
9029 printf (_("\nSymbol table:\n"));
9031 for (namei
= 0; namei
< name_count
; ++namei
)
9033 uint64_t string_offset
, entry_offset
;
9035 SAFE_BYTE_GET (string_offset
,
9036 name_table_string_offsets
+ namei
* offset_size
,
9037 offset_size
, unit_end
);
9038 SAFE_BYTE_GET (entry_offset
,
9039 name_table_entry_offsets
+ namei
* offset_size
,
9040 offset_size
, unit_end
);
9042 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
9043 fetch_indirect_string (string_offset
));
9045 unsigned char *entryptr
= entry_pool
+ entry_offset
;
9047 // We need to scan first whether there is a single or multiple
9048 // entries. TAGNO is -2 for the first entry, it is -1 for the
9049 // initial tag read of the second entry, then it becomes 0 for the
9050 // first entry for real printing etc.
9052 /* Initialize it due to a false compiler warning. */
9053 dwarf_vma second_abbrev_tag
= -1;
9056 dwarf_vma abbrev_tag
;
9057 dwarf_vma dwarf_tag
;
9058 const struct abbrev_lookup_entry
*entry
;
9060 READ_ULEB (abbrev_tag
, entryptr
, unit_end
);
9063 second_abbrev_tag
= abbrev_tag
;
9065 entryptr
= entry_pool
+ entry_offset
;
9068 if (abbrev_tag
== 0)
9072 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
9073 (unsigned long) abbrev_tag
);
9075 for (entry
= abbrev_lookup
;
9076 entry
< abbrev_lookup
+ abbrev_lookup_used
;
9078 if (entry
->abbrev_tag
== abbrev_tag
)
9080 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
9082 warn (_("Undefined abbreviation tag %lu "
9083 "in unit 0x%lx in the debug_names\n"),
9085 (long) (unit_start
- section
->start
));
9088 abbrevptr
= entry
->abbrev_lookup_ptr
;
9089 READ_ULEB (dwarf_tag
, abbrevptr
, abbrev_table_end
);
9091 printf (" %s", get_TAG_name (dwarf_tag
));
9094 dwarf_vma xindex
, form
;
9096 READ_ULEB (xindex
, abbrevptr
, abbrev_table_end
);
9097 READ_ULEB (form
, abbrevptr
, abbrev_table_end
);
9098 if (xindex
== 0 && form
== 0)
9102 printf (" %s", get_IDX_name (xindex
));
9103 entryptr
= read_and_display_attr_value (0, form
, 0,
9104 unit_start
, entryptr
, unit_end
,
9106 dwarf_version
, NULL
,
9113 printf (_(" <no entries>"));
9117 free (abbrev_lookup
);
9124 display_debug_links (struct dwarf_section
* section
,
9125 void * file ATTRIBUTE_UNUSED
)
9127 const unsigned char * filename
;
9128 unsigned int filelen
;
9130 introduce (section
, FALSE
);
9132 /* The .gnu_debuglink section is formatted as:
9133 (c-string) Filename.
9134 (padding) If needed to reach a 4 byte boundary.
9135 (uint32_t) CRC32 value.
9137 The .gun_debugaltlink section is formatted as:
9138 (c-string) Filename.
9139 (binary) Build-ID. */
9141 filename
= section
->start
;
9142 filelen
= strnlen ((const char *) filename
, section
->size
);
9143 if (filelen
== section
->size
)
9145 warn (_("The debuglink filename is corrupt/missing\n"));
9149 printf (_(" Separate debug info file: %s\n"), filename
);
9151 if (const_strneq (section
->name
, ".gnu_debuglink"))
9154 unsigned int crc_offset
;
9156 crc_offset
= filelen
+ 1;
9157 crc_offset
= (crc_offset
+ 3) & ~3;
9158 if (crc_offset
+ 4 > section
->size
)
9160 warn (_("CRC offset missing/truncated\n"));
9164 crc32
= byte_get (filename
+ crc_offset
, 4);
9166 printf (_(" CRC value: %#x\n"), crc32
);
9168 if (crc_offset
+ 4 < section
->size
)
9170 warn (_("There are %#lx extraneous bytes at the end of the section\n"),
9171 (long)(section
->size
- (crc_offset
+ 4)));
9175 else /* const_strneq (section->name, ".gnu_debugaltlink") */
9177 const unsigned char * build_id
= section
->start
+ filelen
+ 1;
9178 bfd_size_type build_id_len
= section
->size
- (filelen
+ 1);
9179 bfd_size_type printed
;
9181 /* FIXME: Should we support smaller build-id notes ? */
9182 if (build_id_len
< 0x14)
9184 warn (_("Build-ID is too short (%#lx bytes)\n"), (long) build_id_len
);
9188 printed
= printf (_(" Build-ID (%#lx bytes):"), (long) build_id_len
);
9189 display_data (printed
, build_id
, build_id_len
);
9198 display_gdb_index (struct dwarf_section
*section
,
9199 void *file ATTRIBUTE_UNUSED
)
9201 unsigned char *start
= section
->start
;
9203 uint32_t cu_list_offset
, tu_list_offset
;
9204 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
9205 unsigned int cu_list_elements
, tu_list_elements
;
9206 unsigned int address_table_size
, symbol_table_slots
;
9207 unsigned char *cu_list
, *tu_list
;
9208 unsigned char *address_table
, *symbol_table
, *constant_pool
;
9211 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
9213 introduce (section
, FALSE
);
9215 if (section
->size
< 6 * sizeof (uint32_t))
9217 warn (_("Truncated header in the %s section.\n"), section
->name
);
9221 version
= byte_get_little_endian (start
, 4);
9222 printf (_("Version %ld\n"), (long) version
);
9224 /* Prior versions are obsolete, and future versions may not be
9225 backwards compatible. */
9226 if (version
< 3 || version
> 8)
9228 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
9232 warn (_("The address table data in version 3 may be wrong.\n"));
9234 warn (_("Version 4 does not support case insensitive lookups.\n"));
9236 warn (_("Version 5 does not include inlined functions.\n"));
9238 warn (_("Version 6 does not include symbol attributes.\n"));
9239 /* Version 7 indices generated by Gold have bad type unit references,
9240 PR binutils/15021. But we don't know if the index was generated by
9241 Gold or not, so to avoid worrying users with gdb-generated indices
9242 we say nothing for version 7 here. */
9244 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
9245 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
9246 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
9247 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
9248 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
9250 if (cu_list_offset
> section
->size
9251 || tu_list_offset
> section
->size
9252 || address_table_offset
> section
->size
9253 || symbol_table_offset
> section
->size
9254 || constant_pool_offset
> section
->size
)
9256 warn (_("Corrupt header in the %s section.\n"), section
->name
);
9260 /* PR 17531: file: 418d0a8a. */
9261 if (tu_list_offset
< cu_list_offset
)
9263 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
9264 tu_list_offset
, cu_list_offset
);
9268 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
9270 if (address_table_offset
< tu_list_offset
)
9272 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
9273 address_table_offset
, tu_list_offset
);
9277 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
9279 /* PR 17531: file: 18a47d3d. */
9280 if (symbol_table_offset
< address_table_offset
)
9282 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
9283 symbol_table_offset
, address_table_offset
);
9287 address_table_size
= symbol_table_offset
- address_table_offset
;
9289 if (constant_pool_offset
< symbol_table_offset
)
9291 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
9292 constant_pool_offset
, symbol_table_offset
);
9296 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
9298 cu_list
= start
+ cu_list_offset
;
9299 tu_list
= start
+ tu_list_offset
;
9300 address_table
= start
+ address_table_offset
;
9301 symbol_table
= start
+ symbol_table_offset
;
9302 constant_pool
= start
+ constant_pool_offset
;
9304 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
9306 warn (_("Address table extends beyond end of section.\n"));
9310 printf (_("\nCU table:\n"));
9311 for (i
= 0; i
< cu_list_elements
; i
+= 2)
9313 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
9314 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
9316 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
9317 (unsigned long) cu_offset
,
9318 (unsigned long) (cu_offset
+ cu_length
- 1));
9321 printf (_("\nTU table:\n"));
9322 for (i
= 0; i
< tu_list_elements
; i
+= 3)
9324 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
9325 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
9326 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
9328 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
9329 (unsigned long) tu_offset
,
9330 (unsigned long) type_offset
);
9331 print_dwarf_vma (signature
, 8);
9335 printf (_("\nAddress table:\n"));
9336 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
9339 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
9340 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
9341 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
9343 print_dwarf_vma (low
, 8);
9344 print_dwarf_vma (high
, 8);
9345 printf (_("%lu\n"), (unsigned long) cu_index
);
9348 printf (_("\nSymbol table:\n"));
9349 for (i
= 0; i
< symbol_table_slots
; ++i
)
9351 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
9352 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
9353 uint32_t num_cus
, cu
;
9355 if (name_offset
!= 0
9356 || cu_vector_offset
!= 0)
9359 unsigned char * adr
;
9361 adr
= constant_pool
+ name_offset
;
9362 /* PR 17531: file: 5b7b07ad. */
9363 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
9365 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
9366 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
9370 printf ("[%3u] %.*s:", i
,
9371 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
9372 constant_pool
+ name_offset
);
9374 adr
= constant_pool
+ cu_vector_offset
;
9375 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
9377 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
9378 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
9379 cu_vector_offset
, i
);
9383 num_cus
= byte_get_little_endian (adr
, 4);
9385 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
9386 if (num_cus
* 4 < num_cus
9387 || adr
>= section
->start
+ section
->size
9388 || adr
< constant_pool
)
9390 printf ("<invalid number of CUs: %d>\n", num_cus
);
9391 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
9399 for (j
= 0; j
< num_cus
; ++j
)
9402 gdb_index_symbol_kind kind
;
9404 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
9405 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
9406 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
9407 cu
= GDB_INDEX_CU_VALUE (cu
);
9408 /* Convert to TU number if it's for a type unit. */
9409 if (cu
>= cu_list_elements
/ 2)
9410 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
9411 (unsigned long) (cu
- cu_list_elements
/ 2));
9413 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
9415 printf (" [%s, %s]",
9416 is_static
? _("static") : _("global"),
9417 get_gdb_index_symbol_kind_name (kind
));
9429 /* Pre-allocate enough space for the CU/TU sets needed. */
9432 prealloc_cu_tu_list (unsigned int nshndx
)
9434 if (shndx_pool
== NULL
)
9436 shndx_pool_size
= nshndx
;
9437 shndx_pool_used
= 0;
9438 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
9439 sizeof (unsigned int));
9443 shndx_pool_size
= shndx_pool_used
+ nshndx
;
9444 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
9445 sizeof (unsigned int));
9450 add_shndx_to_cu_tu_entry (unsigned int shndx
)
9452 if (shndx_pool_used
>= shndx_pool_size
)
9454 error (_("Internal error: out of space in the shndx pool.\n"));
9457 shndx_pool
[shndx_pool_used
++] = shndx
;
9461 end_cu_tu_entry (void)
9463 if (shndx_pool_used
>= shndx_pool_size
)
9465 error (_("Internal error: out of space in the shndx pool.\n"));
9468 shndx_pool
[shndx_pool_used
++] = 0;
9471 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
9474 get_DW_SECT_short_name (unsigned int dw_sect
)
9476 static char buf
[16];
9484 case DW_SECT_ABBREV
:
9490 case DW_SECT_STR_OFFSETS
:
9492 case DW_SECT_MACINFO
:
9500 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
9504 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
9505 These sections are extensions for Fission.
9506 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
9509 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
9511 unsigned char *phdr
= section
->start
;
9512 unsigned char *limit
= phdr
+ section
->size
;
9513 unsigned char *phash
;
9514 unsigned char *pindex
;
9515 unsigned char *ppool
;
9516 unsigned int version
;
9517 unsigned int ncols
= 0;
9519 unsigned int nslots
;
9522 dwarf_vma signature_high
;
9523 dwarf_vma signature_low
;
9526 /* PR 17512: file: 002-168123-0.004. */
9529 warn (_("Section %s is empty\n"), section
->name
);
9532 /* PR 17512: file: 002-376-0.004. */
9533 if (section
->size
< 24)
9535 warn (_("Section %s is too small to contain a CU/TU header\n"),
9540 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
9542 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
9543 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
9544 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
9547 pindex
= phash
+ (size_t) nslots
* 8;
9548 ppool
= pindex
+ (size_t) nslots
* 4;
9552 introduce (section
, FALSE
);
9554 printf (_(" Version: %u\n"), version
);
9556 printf (_(" Number of columns: %u\n"), ncols
);
9557 printf (_(" Number of used entries: %u\n"), nused
);
9558 printf (_(" Number of slots: %u\n\n"), nslots
);
9561 /* PR 17531: file: 45d69832. */
9562 if ((size_t) nslots
* 8 / 8 != nslots
9563 || phash
< phdr
|| phash
> limit
9564 || pindex
< phash
|| pindex
> limit
9565 || ppool
< pindex
|| ppool
> limit
)
9567 warn (ngettext ("Section %s is too small for %u slot\n",
9568 "Section %s is too small for %u slots\n",
9570 section
->name
, nslots
);
9577 prealloc_cu_tu_list ((limit
- ppool
) / 4);
9578 for (i
= 0; i
< nslots
; i
++)
9580 unsigned char *shndx_list
;
9583 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
9584 if (signature_high
!= 0 || signature_low
!= 0)
9586 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
9587 shndx_list
= ppool
+ j
* 4;
9588 /* PR 17531: file: 705e010d. */
9589 if (shndx_list
< ppool
)
9591 warn (_("Section index pool located before start of section\n"));
9596 printf (_(" [%3d] Signature: 0x%s Sections: "),
9597 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9598 buf
, sizeof (buf
)));
9601 if (shndx_list
>= limit
)
9603 warn (_("Section %s too small for shndx pool\n"),
9607 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
9611 printf (" %d", shndx
);
9613 add_shndx_to_cu_tu_entry (shndx
);
9625 else if (version
== 2)
9628 unsigned int dw_sect
;
9629 unsigned char *ph
= phash
;
9630 unsigned char *pi
= pindex
;
9631 unsigned char *poffsets
= ppool
+ (size_t) ncols
* 4;
9632 unsigned char *psizes
= poffsets
+ (size_t) nused
* ncols
* 4;
9633 unsigned char *pend
= psizes
+ (size_t) nused
* ncols
* 4;
9634 bfd_boolean is_tu_index
;
9635 struct cu_tu_set
*this_set
= NULL
;
9637 unsigned char *prow
;
9639 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
9641 /* PR 17531: file: 0dd159bf.
9642 Check for integer overflow (can occur when size_t is 32-bit)
9643 with overlarge ncols or nused values. */
9645 && ((size_t) ncols
* 4 / 4 != ncols
9646 || (size_t) nused
* ncols
* 4 / ((size_t) ncols
* 4) != nused
9647 || poffsets
< ppool
|| poffsets
> limit
9648 || psizes
< poffsets
|| psizes
> limit
9649 || pend
< psizes
|| pend
> limit
))
9651 warn (_("Section %s too small for offset and size tables\n"),
9658 printf (_(" Offset table\n"));
9659 printf (" slot %-16s ",
9660 is_tu_index
? _("signature") : _("dwo_id"));
9667 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9673 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
9680 for (j
= 0; j
< ncols
; j
++)
9682 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9683 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
9688 for (i
= 0; i
< nslots
; i
++)
9690 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9692 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9695 /* PR 17531: file: a05f6ab3. */
9698 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
9705 size_t num_copy
= sizeof (uint64_t);
9707 /* PR 23064: Beware of buffer overflow. */
9708 if (ph
+ num_copy
< limit
)
9709 memcpy (&this_set
[row
- 1].signature
, ph
, num_copy
);
9712 warn (_("Signature (%p) extends beyond end of space in section\n"), ph
);
9717 prow
= poffsets
+ (row
- 1) * ncols
* 4;
9718 /* PR 17531: file: b8ce60a8. */
9719 if (prow
< poffsets
|| prow
> limit
)
9721 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
9727 printf (_(" [%3d] 0x%s"),
9728 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9729 buf
, sizeof (buf
)));
9730 for (j
= 0; j
< ncols
; j
++)
9732 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9734 printf (" %8d", val
);
9737 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9739 /* PR 17531: file: 10796eb3. */
9740 if (dw_sect
>= DW_SECT_MAX
)
9741 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9743 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
9759 printf (_(" Size table\n"));
9760 printf (" slot %-16s ",
9761 is_tu_index
? _("signature") : _("dwo_id"));
9764 for (j
= 0; j
< ncols
; j
++)
9766 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
9768 printf (" %8s", get_DW_SECT_short_name (val
));
9774 for (i
= 0; i
< nslots
; i
++)
9776 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9778 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9781 prow
= psizes
+ (row
- 1) * ncols
* 4;
9784 printf (_(" [%3d] 0x%s"),
9785 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9786 buf
, sizeof (buf
)));
9788 for (j
= 0; j
< ncols
; j
++)
9790 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9792 printf (" %8d", val
);
9795 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9796 if (dw_sect
>= DW_SECT_MAX
)
9797 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9799 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
9811 else if (do_display
)
9812 printf (_(" Unsupported version (%d)\n"), version
);
9820 /* Load the CU and TU indexes if present. This will build a list of
9821 section sets that we can use to associate a .debug_info.dwo section
9822 with its associated .debug_abbrev.dwo section in a .dwp file. */
9825 load_cu_tu_indexes (void *file
)
9827 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
9829 /* If we have already loaded (or tried to load) the CU and TU indexes
9830 then do not bother to repeat the task. */
9831 if (cu_tu_indexes_read
== -1)
9833 cu_tu_indexes_read
= TRUE
;
9835 if (load_debug_section_with_follow (dwp_cu_index
, file
))
9836 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
9837 cu_tu_indexes_read
= FALSE
;
9839 if (load_debug_section_with_follow (dwp_tu_index
, file
))
9840 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
9841 cu_tu_indexes_read
= FALSE
;
9844 return (bfd_boolean
) cu_tu_indexes_read
;
9847 /* Find the set of sections that includes section SHNDX. */
9850 find_cu_tu_set (void *file
, unsigned int shndx
)
9854 if (! load_cu_tu_indexes (file
))
9857 /* Find SHNDX in the shndx pool. */
9858 for (i
= 0; i
< shndx_pool_used
; i
++)
9859 if (shndx_pool
[i
] == shndx
)
9862 if (i
>= shndx_pool_used
)
9865 /* Now backup to find the first entry in the set. */
9866 while (i
> 0 && shndx_pool
[i
- 1] != 0)
9869 return shndx_pool
+ i
;
9872 /* Display a .debug_cu_index or .debug_tu_index section. */
9875 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
9877 return process_cu_tu_index (section
, 1);
9881 display_debug_not_supported (struct dwarf_section
*section
,
9882 void *file ATTRIBUTE_UNUSED
)
9884 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9890 /* Like malloc, but takes two parameters like calloc.
9891 Verifies that the first parameter is not too large.
9892 Note: does *not* initialise the allocated memory to zero. */
9895 cmalloc (size_t nmemb
, size_t size
)
9897 /* Check for overflow. */
9898 if (nmemb
>= ~(size_t) 0 / size
)
9901 return xmalloc (nmemb
* size
);
9904 /* Like xmalloc, but takes two parameters like calloc.
9905 Verifies that the first parameter is not too large.
9906 Note: does *not* initialise the allocated memory to zero. */
9909 xcmalloc (size_t nmemb
, size_t size
)
9911 /* Check for overflow. */
9912 if (nmemb
>= ~(size_t) 0 / size
)
9915 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9920 return xmalloc (nmemb
* size
);
9923 /* Like xrealloc, but takes three parameters.
9924 Verifies that the second parameter is not too large.
9925 Note: does *not* initialise any new memory to zero. */
9928 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
9930 /* Check for overflow. */
9931 if (nmemb
>= ~(size_t) 0 / size
)
9933 error (_("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9938 return xrealloc (ptr
, nmemb
* size
);
9941 /* Like xcalloc, but verifies that the first parameter is not too large. */
9944 xcalloc2 (size_t nmemb
, size_t size
)
9946 /* Check for overflow. */
9947 if (nmemb
>= ~(size_t) 0 / size
)
9949 error (_("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9954 return xcalloc (nmemb
, size
);
9957 static unsigned long
9958 calc_gnu_debuglink_crc32 (unsigned long crc
,
9959 const unsigned char * buf
,
9962 static const unsigned long crc32_table
[256] =
9964 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
9965 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
9966 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
9967 0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
9968 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
9969 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
9970 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
9971 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
9972 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
9973 0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
9974 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
9975 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
9976 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
9977 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
9978 0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
9979 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
9980 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
9981 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
9982 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
9983 0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
9984 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
9985 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
9986 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
9987 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
9988 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
9989 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
9990 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
9991 0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
9992 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
9993 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
9994 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
9995 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
9996 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
9997 0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
9998 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
9999 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
10000 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
10001 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
10002 0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
10003 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
10004 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
10005 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
10006 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
10007 0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
10008 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
10009 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
10010 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
10011 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
10012 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
10013 0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
10014 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
10017 const unsigned char *end
;
10019 crc
= ~crc
& 0xffffffff;
10020 for (end
= buf
+ len
; buf
< end
; ++ buf
)
10021 crc
= crc32_table
[(crc
^ *buf
) & 0xff] ^ (crc
>> 8);
10022 return ~crc
& 0xffffffff;
10025 typedef bfd_boolean (* check_func_type
) (const char *, void *);
10026 typedef const char * (* parse_func_type
) (struct dwarf_section
*, void *);
10029 check_gnu_debuglink (const char * pathname
, void * crc_pointer
)
10031 static unsigned char buffer
[8 * 1024];
10033 bfd_size_type count
;
10034 unsigned long crc
= 0;
10037 sep_data
= open_debug_file (pathname
);
10038 if (sep_data
== NULL
)
10041 /* Yes - we are opening the file twice... */
10042 f
= fopen (pathname
, "rb");
10045 /* Paranoia: This should never happen. */
10046 close_debug_file (sep_data
);
10047 warn (_("Unable to reopen separate debug info file: %s\n"), pathname
);
10051 while ((count
= fread (buffer
, 1, sizeof (buffer
), f
)) > 0)
10052 crc
= calc_gnu_debuglink_crc32 (crc
, buffer
, count
);
10056 if (crc
!= * (unsigned long *) crc_pointer
)
10058 close_debug_file (sep_data
);
10059 warn (_("Separate debug info file %s found, but CRC does not match - ignoring\n"),
10067 static const char *
10068 parse_gnu_debuglink (struct dwarf_section
* section
, void * data
)
10071 unsigned int crc_offset
;
10072 unsigned long * crc32
= (unsigned long *) data
;
10074 /* The name is first.
10075 The CRC value is stored after the filename, aligned up to 4 bytes. */
10076 name
= (const char *) section
->start
;
10079 crc_offset
= strnlen (name
, section
->size
) + 1;
10080 crc_offset
= (crc_offset
+ 3) & ~3;
10081 if (crc_offset
+ 4 > section
->size
)
10084 * crc32
= byte_get (section
->start
+ crc_offset
, 4);
10089 check_gnu_debugaltlink (const char * filename
, void * data ATTRIBUTE_UNUSED
)
10091 void * sep_data
= open_debug_file (filename
);
10093 if (sep_data
== NULL
)
10096 /* FIXME: We should now extract the build-id in the separate file
10102 typedef struct build_id_data
10105 const unsigned char * data
;
10108 static const char *
10109 parse_gnu_debugaltlink (struct dwarf_section
* section
, void * data
)
10112 bfd_size_type namelen
;
10113 bfd_size_type id_len
;
10114 Build_id_data
* build_id_data
;
10116 /* The name is first.
10117 The build-id follows immediately, with no padding, up to the section's end. */
10119 name
= (const char *) section
->start
;
10120 namelen
= strnlen (name
, section
->size
) + 1;
10121 if (namelen
>= section
->size
)
10124 id_len
= section
->size
- namelen
;
10128 build_id_data
= calloc (1, sizeof * build_id_data
);
10129 if (build_id_data
== NULL
)
10132 build_id_data
->len
= id_len
;
10133 build_id_data
->data
= section
->start
+ namelen
;
10135 * (Build_id_data
**) data
= build_id_data
;
10141 add_separate_debug_file (const char * filename
, void * handle
)
10143 separate_info
* i
= xmalloc (sizeof * i
);
10145 i
->filename
= filename
;
10146 i
->handle
= handle
;
10147 i
->next
= first_separate_info
;
10148 first_separate_info
= i
;
10151 #if HAVE_LIBDEBUGINFOD
10152 /* Query debuginfod servers for the target debuglink or debugaltlink
10153 file. If successful, store the path of the file in filename and
10154 return TRUE, otherwise return FALSE. */
10157 debuginfod_fetch_separate_debug_info (struct dwarf_section
* section
,
10161 size_t build_id_len
;
10162 unsigned char * build_id
;
10164 if (strcmp (section
->uncompressed_name
, ".gnu_debuglink") == 0)
10166 /* Get the build-id of file. */
10167 build_id
= get_build_id (file
);
10170 else if (strcmp (section
->uncompressed_name
, ".gnu_debugaltlink") == 0)
10172 /* Get the build-id of the debugaltlink file. */
10173 unsigned int filelen
;
10175 filelen
= strnlen ((const char *)section
->start
, section
->size
);
10176 if (filelen
== section
->size
)
10177 /* Corrupt debugaltlink. */
10180 build_id
= section
->start
+ filelen
+ 1;
10181 build_id_len
= section
->size
- (filelen
+ 1);
10183 if (build_id_len
== 0)
10192 debuginfod_client
* client
;
10194 client
= debuginfod_begin ();
10195 if (client
== NULL
)
10198 /* Query debuginfod servers for the target file. If found its path
10199 will be stored in filename. */
10200 fd
= debuginfod_find_debuginfo (client
, build_id
, build_id_len
, filename
);
10201 debuginfod_end (client
);
10203 /* Only free build_id if we allocated space for a hex string
10204 in get_build_id (). */
10205 if (build_id_len
== 0)
10210 /* File successfully retrieved. Close fd since we want to
10211 use open_debug_file () on filename instead. */
10222 load_separate_debug_info (const char * main_filename
,
10223 struct dwarf_section
* xlink
,
10224 parse_func_type parse_func
,
10225 check_func_type check_func
,
10227 void * file ATTRIBUTE_UNUSED
)
10229 const char * separate_filename
;
10230 char * debug_filename
;
10232 size_t canon_dirlen
;
10235 if ((separate_filename
= parse_func (xlink
, func_data
)) == NULL
)
10237 warn (_("Corrupt debuglink section: %s\n"),
10238 xlink
->name
? xlink
->name
: xlink
->uncompressed_name
);
10242 /* Attempt to locate the separate file.
10243 This should duplicate the logic in bfd/opncls.c:find_separate_debug_file(). */
10245 canon_dir
= lrealpath (main_filename
);
10247 for (canon_dirlen
= strlen (canon_dir
); canon_dirlen
> 0; canon_dirlen
--)
10248 if (IS_DIR_SEPARATOR (canon_dir
[canon_dirlen
- 1]))
10250 canon_dir
[canon_dirlen
] = '\0';
10253 #define DEBUGDIR "/lib/debug"
10255 #ifndef EXTRA_DEBUG_ROOT1
10256 #define EXTRA_DEBUG_ROOT1 "/usr/lib/debug"
10258 #ifndef EXTRA_DEBUG_ROOT2
10259 #define EXTRA_DEBUG_ROOT2 "/usr/lib/debug/usr"
10262 debug_filename
= (char *) malloc (strlen (DEBUGDIR
) + 1
10264 + strlen (".debug/")
10265 #ifdef EXTRA_DEBUG_ROOT1
10266 + strlen (EXTRA_DEBUG_ROOT1
)
10268 #ifdef EXTRA_DEBUG_ROOT2
10269 + strlen (EXTRA_DEBUG_ROOT2
)
10271 + strlen (separate_filename
)
10273 if (debug_filename
== NULL
)
10275 warn (_("Out of memory"));
10280 /* First try in the current directory. */
10281 sprintf (debug_filename
, "%s", separate_filename
);
10282 if (check_func (debug_filename
, func_data
))
10285 /* Then try in a subdirectory called .debug. */
10286 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10287 if (check_func (debug_filename
, func_data
))
10290 /* Then try in the same directory as the original file. */
10291 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10292 if (check_func (debug_filename
, func_data
))
10295 /* And the .debug subdirectory of that directory. */
10296 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10297 if (check_func (debug_filename
, func_data
))
10300 #ifdef EXTRA_DEBUG_ROOT1
10301 /* Try the first extra debug file root. */
10302 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10303 if (check_func (debug_filename
, func_data
))
10306 /* Try the first extra debug file root. */
10307 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10308 if (check_func (debug_filename
, func_data
))
10312 #ifdef EXTRA_DEBUG_ROOT2
10313 /* Try the second extra debug file root. */
10314 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10315 if (check_func (debug_filename
, func_data
))
10319 /* Then try in the global debug_filename directory. */
10320 strcpy (debug_filename
, DEBUGDIR
);
10321 dirlen
= strlen (DEBUGDIR
) - 1;
10322 if (dirlen
> 0 && DEBUGDIR
[dirlen
] != '/')
10323 strcat (debug_filename
, "/");
10324 strcat (debug_filename
, (const char *) separate_filename
);
10326 if (check_func (debug_filename
, func_data
))
10329 #if HAVE_LIBDEBUGINFOD
10331 char * tmp_filename
;
10333 if (debuginfod_fetch_separate_debug_info (xlink
,
10337 /* File successfully downloaded from server, replace
10338 debug_filename with the file's path. */
10339 free (debug_filename
);
10340 debug_filename
= tmp_filename
;
10346 /* Failed to find the file. */
10347 warn (_("could not find separate debug file '%s'\n"), separate_filename
);
10348 warn (_("tried: %s\n"), debug_filename
);
10350 #ifdef EXTRA_DEBUG_ROOT2
10351 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT2
, separate_filename
);
10352 warn (_("tried: %s\n"), debug_filename
);
10355 #ifdef EXTRA_DEBUG_ROOT1
10356 sprintf (debug_filename
, "%s/%s/%s", EXTRA_DEBUG_ROOT1
, canon_dir
, separate_filename
);
10357 warn (_("tried: %s\n"), debug_filename
);
10359 sprintf (debug_filename
, "%s/%s", EXTRA_DEBUG_ROOT1
, separate_filename
);
10360 warn (_("tried: %s\n"), debug_filename
);
10363 sprintf (debug_filename
, "%s.debug/%s", canon_dir
, separate_filename
);
10364 warn (_("tried: %s\n"), debug_filename
);
10366 sprintf (debug_filename
, "%s%s", canon_dir
, separate_filename
);
10367 warn (_("tried: %s\n"), debug_filename
);
10369 sprintf (debug_filename
, ".debug/%s", separate_filename
);
10370 warn (_("tried: %s\n"), debug_filename
);
10372 sprintf (debug_filename
, "%s", separate_filename
);
10373 warn (_("tried: %s\n"), debug_filename
);
10375 #if HAVE_LIBDEBUGINFOD
10377 char *urls
= getenv (DEBUGINFOD_URLS_ENV_VAR
);
10381 warn (_("tried: DEBUGINFOD_URLS=%s\n"), urls
);
10386 free (debug_filename
);
10392 void * debug_handle
;
10394 /* Now open the file.... */
10395 if ((debug_handle
= open_debug_file (debug_filename
)) == NULL
)
10397 warn (_("failed to open separate debug file: %s\n"), debug_filename
);
10398 free (debug_filename
);
10402 /* FIXME: We do not check to see if there are any other separate debug info
10403 files that would also match. */
10405 printf (_("%s: Found separate debug info file: %s\n\n"), main_filename
, debug_filename
);
10406 add_separate_debug_file (debug_filename
, debug_handle
);
10408 /* Do not free debug_filename - it might be referenced inside
10409 the structure returned by open_debug_file(). */
10410 return debug_handle
;
10413 /* Attempt to load a separate dwarf object file. */
10416 load_dwo_file (const char * main_filename
, const char * name
, const char * dir
, const char * id ATTRIBUTE_UNUSED
)
10418 char * separate_filename
;
10419 void * separate_handle
;
10421 /* FIXME: Skip adding / if dwo_dir ends in /. */
10422 separate_filename
= concat (dir
, "/", name
, NULL
);
10423 if (separate_filename
== NULL
)
10425 warn (_("Out of memory allocating dwo filename\n"));
10429 if ((separate_handle
= open_debug_file (separate_filename
)) == NULL
)
10431 warn (_("Unable to load dwo file: %s\n"), separate_filename
);
10432 free (separate_filename
);
10436 /* FIXME: We should check the dwo_id. */
10438 printf (_("%s: Found separate debug object file: %s\n\n"), main_filename
, separate_filename
);
10439 add_separate_debug_file (separate_filename
, separate_handle
);
10440 /* Note - separate_filename will be freed in free_debug_memory(). */
10441 return separate_handle
;
10444 /* Load the separate debug info file(s) attached to FILE, if any exist.
10445 Returns TRUE if any were found, FALSE otherwise.
10446 If TRUE is returned then the linked list starting at first_separate_info
10447 will be populated with open file handles. */
10450 load_separate_debug_files (void * file
, const char * filename
)
10452 /* Skip this operation if we are not interested in debug links. */
10453 if (! do_follow_links
&& ! do_debug_links
)
10456 /* See if there are any dwo links. */
10457 if (load_debug_section (str
, file
)
10458 && load_debug_section (abbrev
, file
)
10459 && load_debug_section (info
, file
))
10463 if (process_debug_info (& debug_displays
[info
].section
, file
, abbrev
, TRUE
, FALSE
))
10465 bfd_boolean introduced
= FALSE
;
10467 const char * dir
= NULL
;
10468 const char * id
= NULL
;
10470 for (dwinfo
= first_dwo_info
; dwinfo
!= NULL
; dwinfo
= dwinfo
->next
)
10472 switch (dwinfo
->type
)
10475 if (do_debug_links
)
10479 printf (_("The %s section contains link(s) to dwo file(s):\n\n"),
10480 debug_displays
[info
].section
.uncompressed_name
);
10484 printf (_(" Name: %s\n"), dwinfo
->value
);
10485 printf (_(" Directory: %s\n"), dir
? dir
: _("<not-found>"));
10487 display_data (printf (_(" ID: ")), (unsigned char *) id
, 8);
10489 printf (_(" ID: <unknown>\n"));
10493 if (do_follow_links
)
10494 load_dwo_file (filename
, dwinfo
->value
, dir
, id
);
10498 dir
= dwinfo
->value
;
10502 id
= dwinfo
->value
;
10506 error (_("Unexpected DWO INFO type"));
10513 if (! do_follow_links
)
10514 /* The other debug links will be displayed by display_debug_links()
10515 so we do not need to do any further processing here. */
10518 /* FIXME: We do not check for the presence of both link sections in the same file. */
10519 /* FIXME: We do not check the separate debug info file to see if it too contains debuglinks. */
10520 /* FIXME: We do not check for the presence of multiple, same-name debuglink sections. */
10521 /* FIXME: We do not check for the presence of a dwo link as well as a debuglink. */
10523 if (load_debug_section (gnu_debugaltlink
, file
))
10525 Build_id_data
* build_id_data
;
10527 load_separate_debug_info (filename
,
10528 & debug_displays
[gnu_debugaltlink
].section
,
10529 parse_gnu_debugaltlink
,
10530 check_gnu_debugaltlink
,
10535 if (load_debug_section (gnu_debuglink
, file
))
10537 unsigned long crc32
;
10539 load_separate_debug_info (filename
,
10540 & debug_displays
[gnu_debuglink
].section
,
10541 parse_gnu_debuglink
,
10542 check_gnu_debuglink
,
10547 if (first_separate_info
!= NULL
)
10550 do_follow_links
= 0;
10555 free_debug_memory (void)
10561 for (i
= 0; i
< max
; i
++)
10562 free_debug_section ((enum dwarf_section_display_enum
) i
);
10564 if (debug_information
!= NULL
)
10566 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
10568 for (i
= 0; i
< num_debug_info_entries
; i
++)
10570 if (!debug_information
[i
].max_loc_offsets
)
10572 free (debug_information
[i
].loc_offsets
);
10573 free (debug_information
[i
].have_frame_base
);
10575 if (!debug_information
[i
].max_range_lists
)
10576 free (debug_information
[i
].range_lists
);
10579 free (debug_information
);
10580 debug_information
= NULL
;
10581 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
10585 separate_info
* next
;
10587 for (d
= first_separate_info
; d
!= NULL
; d
= next
)
10589 close_debug_file (d
->handle
);
10590 free ((void *) d
->filename
);
10594 first_separate_info
= NULL
;
10600 dwarf_select_sections_by_names (const char *names
)
10604 const char * option
;
10608 debug_dump_long_opts
;
10610 static const debug_dump_long_opts opts_table
[] =
10612 /* Please keep this table alpha- sorted. */
10613 { "Ranges", & do_debug_ranges
, 1 },
10614 { "abbrev", & do_debug_abbrevs
, 1 },
10615 { "addr", & do_debug_addr
, 1 },
10616 { "aranges", & do_debug_aranges
, 1 },
10617 { "cu_index", & do_debug_cu_index
, 1 },
10618 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
10619 { "follow-links", & do_follow_links
, 1 },
10620 { "frames", & do_debug_frames
, 1 },
10621 { "frames-interp", & do_debug_frames_interp
, 1 },
10622 /* The special .gdb_index section. */
10623 { "gdb_index", & do_gdb_index
, 1 },
10624 { "info", & do_debug_info
, 1 },
10625 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
10626 { "links", & do_debug_links
, 1 },
10627 { "loc", & do_debug_loc
, 1 },
10628 { "macro", & do_debug_macinfo
, 1 },
10629 { "pubnames", & do_debug_pubnames
, 1 },
10630 { "pubtypes", & do_debug_pubtypes
, 1 },
10631 /* This entry is for compatibility
10632 with earlier versions of readelf. */
10633 { "ranges", & do_debug_aranges
, 1 },
10634 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
10635 { "str", & do_debug_str
, 1 },
10636 /* These trace_* sections are used by Itanium VMS. */
10637 { "trace_abbrev", & do_trace_abbrevs
, 1 },
10638 { "trace_aranges", & do_trace_aranges
, 1 },
10639 { "trace_info", & do_trace_info
, 1 },
10648 const debug_dump_long_opts
* entry
;
10650 for (entry
= opts_table
; entry
->option
; entry
++)
10652 size_t len
= strlen (entry
->option
);
10654 if (strncmp (p
, entry
->option
, len
) == 0
10655 && (p
[len
] == ',' || p
[len
] == '\0'))
10657 * entry
->variable
|= entry
->val
;
10659 /* The --debug-dump=frames-interp option also
10660 enables the --debug-dump=frames option. */
10661 if (do_debug_frames_interp
)
10662 do_debug_frames
= 1;
10669 if (entry
->option
== NULL
)
10671 warn (_("Unrecognized debug option '%s'\n"), p
);
10672 p
= strchr (p
, ',');
10683 dwarf_select_sections_by_letters (const char *letters
)
10685 unsigned int lindex
= 0;
10687 while (letters
[lindex
])
10688 switch (letters
[lindex
++])
10690 case 'A': do_debug_addr
= 1; break;
10691 case 'a': do_debug_abbrevs
= 1; break;
10692 case 'c': do_debug_cu_index
= 1; break;
10693 case 'F': do_debug_frames_interp
= 1; /* Fall through. */
10694 case 'f': do_debug_frames
= 1; break;
10695 case 'g': do_gdb_index
= 1; break;
10696 case 'i': do_debug_info
= 1; break;
10697 case 'K': do_follow_links
= 1; break;
10698 case 'k': do_debug_links
= 1; break;
10699 case 'l': do_debug_lines
|= FLAG_DEBUG_LINES_RAW
; break;
10700 case 'L': do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
; break;
10701 case 'm': do_debug_macinfo
= 1; break;
10702 case 'o': do_debug_loc
= 1; break;
10703 case 'p': do_debug_pubnames
= 1; break;
10704 case 'R': do_debug_ranges
= 1; break;
10705 case 'r': do_debug_aranges
= 1; break;
10706 case 's': do_debug_str
= 1; break;
10707 case 'T': do_trace_aranges
= 1; break;
10708 case 't': do_debug_pubtypes
= 1; break;
10709 case 'U': do_trace_info
= 1; break;
10710 case 'u': do_trace_abbrevs
= 1; break;
10713 warn (_("Unrecognized debug option '%s'\n"), letters
);
10719 dwarf_select_sections_all (void)
10722 do_debug_abbrevs
= 1;
10723 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
10724 do_debug_pubnames
= 1;
10725 do_debug_pubtypes
= 1;
10726 do_debug_aranges
= 1;
10727 do_debug_ranges
= 1;
10728 do_debug_frames
= 1;
10729 do_debug_macinfo
= 1;
10734 do_trace_abbrevs
= 1;
10735 do_trace_aranges
= 1;
10737 do_debug_cu_index
= 1;
10738 do_follow_links
= 1;
10739 do_debug_links
= 1;
10742 #define NO_ABBREVS NULL, NULL, NULL, 0, 0, 0, NULL, 0, NULL
10743 #define ABBREV(N) NULL, NULL, NULL, 0, 0, N, NULL, 0, NULL
10745 /* N.B. The order here must match the order in section_display_enum. */
10747 struct dwarf_section_display debug_displays
[] =
10749 { { ".debug_abbrev", ".zdebug_abbrev", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10750 { { ".debug_aranges", ".zdebug_aranges", NO_ABBREVS
}, display_debug_aranges
, &do_debug_aranges
, TRUE
},
10751 { { ".debug_frame", ".zdebug_frame", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10752 { { ".debug_info", ".zdebug_info", ABBREV (abbrev
)}, display_debug_info
, &do_debug_info
, TRUE
},
10753 { { ".debug_line", ".zdebug_line", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10754 { { ".debug_pubnames", ".zdebug_pubnames", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
10755 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
10756 { { ".eh_frame", "", NO_ABBREVS
}, display_debug_frames
, &do_debug_frames
, TRUE
},
10757 { { ".debug_macinfo", ".zdebug_macinfo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10758 { { ".debug_macro", ".zdebug_macro", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10759 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10760 { { ".debug_line_str", ".zdebug_line_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10761 { { ".debug_loc", ".zdebug_loc", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10762 { { ".debug_loclists", ".zdebug_loclists", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10763 { { ".debug_pubtypes", ".zdebug_pubtypes", NO_ABBREVS
}, display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
10764 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NO_ABBREVS
}, display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
10765 { { ".debug_ranges", ".zdebug_ranges", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10766 { { ".debug_rnglists", ".zdebug_rnglists", NO_ABBREVS
}, display_debug_ranges
, &do_debug_ranges
, TRUE
},
10767 { { ".debug_static_func", ".zdebug_static_func", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10768 { { ".debug_static_vars", ".zdebug_static_vars", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10769 { { ".debug_types", ".zdebug_types", ABBREV (abbrev
) }, display_debug_types
, &do_debug_info
, TRUE
},
10770 { { ".debug_weaknames", ".zdebug_weaknames", NO_ABBREVS
}, display_debug_not_supported
, NULL
, FALSE
},
10771 { { ".gdb_index", "", NO_ABBREVS
}, display_gdb_index
, &do_gdb_index
, FALSE
},
10772 { { ".debug_names", "", NO_ABBREVS
}, display_debug_names
, &do_gdb_index
, FALSE
},
10773 { { ".trace_info", "", ABBREV (trace_abbrev
) }, display_trace_info
, &do_trace_info
, TRUE
},
10774 { { ".trace_abbrev", "", NO_ABBREVS
}, display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
10775 { { ".trace_aranges", "", NO_ABBREVS
}, display_debug_aranges
, &do_trace_aranges
, FALSE
},
10776 { { ".debug_info.dwo", ".zdebug_info.dwo", ABBREV (abbrev_dwo
) }, display_debug_info
, &do_debug_info
, TRUE
},
10777 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NO_ABBREVS
}, display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
10778 { { ".debug_types.dwo", ".zdebug_types.dwo", ABBREV (abbrev_dwo
) }, display_debug_types
, &do_debug_info
, TRUE
},
10779 { { ".debug_line.dwo", ".zdebug_line.dwo", NO_ABBREVS
}, display_debug_lines
, &do_debug_lines
, TRUE
},
10780 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NO_ABBREVS
}, display_debug_loc
, &do_debug_loc
, TRUE
},
10781 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NO_ABBREVS
}, display_debug_macro
, &do_debug_macinfo
, TRUE
},
10782 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NO_ABBREVS
}, display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
10783 { { ".debug_str.dwo", ".zdebug_str.dwo", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, TRUE
},
10784 { { ".debug_str_offsets", ".zdebug_str_offsets", NO_ABBREVS
}, display_debug_str_offsets
, NULL
, FALSE
},
10785 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NO_ABBREVS
}, display_debug_str_offsets
, NULL
, FALSE
},
10786 { { ".debug_addr", ".zdebug_addr", NO_ABBREVS
}, display_debug_addr
, &do_debug_addr
, TRUE
},
10787 { { ".debug_cu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10788 { { ".debug_tu_index", "", NO_ABBREVS
}, display_cu_index
, &do_debug_cu_index
, FALSE
},
10789 { { ".gnu_debuglink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10790 { { ".gnu_debugaltlink", "", NO_ABBREVS
}, display_debug_links
, &do_debug_links
, FALSE
},
10791 /* Separate debug info files can containt their own .debug_str section,
10792 and this might be in *addition* to a .debug_str section already present
10793 in the main file. Hence we need to have two entries for .debug_str. */
10794 { { ".debug_str", ".zdebug_str", NO_ABBREVS
}, display_debug_str
, &do_debug_str
, FALSE
},
10797 /* A static assertion. */
10798 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];