1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2017 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"
35 #define MAX(a, b) ((a) > (b) ? (a) : (b))
36 #define MIN(a, b) ((a) < (b) ? (a) : (b))
38 static const char *regname (unsigned int regno
, int row
);
40 static int have_frame_base
;
41 static int need_base_address
;
43 static unsigned int num_debug_info_entries
= 0;
44 static unsigned int alloc_num_debug_info_entries
= 0;
45 static debug_info
*debug_information
= NULL
;
46 /* Special value for num_debug_info_entries to indicate
47 that the .debug_info section could not be loaded/parsed. */
48 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
50 unsigned int eh_addr_size
;
55 int do_debug_pubnames
;
56 int do_debug_pubtypes
;
60 int do_debug_frames_interp
;
69 int do_debug_cu_index
;
72 int dwarf_cutoff_level
= -1;
73 unsigned long dwarf_start_die
;
77 /* Convenient constant, to avoid having to cast -1 to dwarf_vma when
78 testing whether e.g. a locview list is present. */
79 static const dwarf_vma vm1
= -1;
81 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
82 sections. For version 1 package files, each set is stored in SHNDX_POOL
83 as a zero-terminated list of section indexes comprising one set of debug
84 sections from a .dwo file. */
86 static unsigned int *shndx_pool
= NULL
;
87 static unsigned int shndx_pool_size
= 0;
88 static unsigned int shndx_pool_used
= 0;
90 /* For version 2 package files, each set contains an array of section offsets
91 and an array of section sizes, giving the offset and size of the
92 contribution from a CU or TU within one of the debug sections.
93 When displaying debug info from a package file, we need to use these
94 tables to locate the corresponding contributions to each section. */
99 dwarf_vma section_offsets
[DW_SECT_MAX
];
100 size_t section_sizes
[DW_SECT_MAX
];
103 static int cu_count
= 0;
104 static int tu_count
= 0;
105 static struct cu_tu_set
*cu_sets
= NULL
;
106 static struct cu_tu_set
*tu_sets
= NULL
;
108 static bfd_boolean
load_cu_tu_indexes (void *);
110 /* Values for do_debug_lines. */
111 #define FLAG_DEBUG_LINES_RAW 1
112 #define FLAG_DEBUG_LINES_DECODED 2
115 size_of_encoded_value (int encoding
)
117 switch (encoding
& 0x7)
120 case 0: return eh_addr_size
;
128 get_encoded_value (unsigned char **pdata
,
130 struct dwarf_section
*section
,
133 unsigned char * data
= * pdata
;
134 unsigned int size
= size_of_encoded_value (encoding
);
137 if (data
+ size
>= end
)
139 warn (_("Encoded value extends past end of section\n"));
144 /* PR 17512: file: 002-829853-0.004. */
147 warn (_("Encoded size of %d is too large to read\n"), size
);
152 /* PR 17512: file: 1085-5603-0.004. */
155 warn (_("Encoded size of 0 is too small to read\n"));
160 if (encoding
& DW_EH_PE_signed
)
161 val
= byte_get_signed (data
, size
);
163 val
= byte_get (data
, size
);
165 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
166 val
+= section
->address
+ (data
- section
->start
);
168 * pdata
= data
+ size
;
172 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
174 # define DWARF_VMA_FMT "ll"
175 # define DWARF_VMA_FMT_LONG "%16.16llx"
177 # define DWARF_VMA_FMT "I64"
178 # define DWARF_VMA_FMT_LONG "%016I64x"
181 # define DWARF_VMA_FMT "l"
182 # define DWARF_VMA_FMT_LONG "%16.16lx"
185 /* Convert a dwarf vma value into a string. Returns a pointer to a static
186 buffer containing the converted VALUE. The value is converted according
187 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
188 it specifies the maximum number of bytes to be displayed in the converted
189 value and FMTCH is ignored - hex is always used. */
192 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
194 /* As dwarf_vmatoa is used more then once in a printf call
195 for output, we are cycling through an fixed array of pointers
196 for return address. */
197 static int buf_pos
= 0;
198 static struct dwarf_vmatoa_buf
204 ret
= buf
[buf_pos
++].place
;
205 buf_pos
%= ARRAY_SIZE (buf
);
209 /* Printf does not have a way of specifying a maximum field width for an
210 integer value, so we print the full value into a buffer and then select
211 the precision we need. */
212 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
215 return ret
+ (16 - 2 * num_bytes
);
222 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
224 sprintf (fmt
, "%%%s", DWARF_VMA_FMT
);
225 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
230 static inline const char *
231 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
233 return dwarf_vmatoa_1 (fmtch
, value
, 0);
236 /* Print a dwarf_vma value (typically an address, offset or length) in
237 hexadecimal format, followed by a space. The length of the VALUE (and
238 hence the precision displayed) is determined by the NUM_BYTES parameter. */
241 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
243 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
246 /* Print a view number in hexadecimal value, with the same width
247 print_dwarf_vma would have printed it with the same num_bytes.
248 Print blanks for zero view, unless force is nonzero. */
251 print_dwarf_view (dwarf_vma value
, unsigned num_bytes
, int force
)
259 assert (value
== (unsigned long) value
);
261 printf ("v%0*lx ", len
- 1, (unsigned long) value
);
263 printf ("%*s", len
+ 1, "");
266 /* Format a 64-bit value, given as two 32-bit values, in hex.
267 For reentrancy, this uses a buffer provided by the caller. */
270 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
271 unsigned int buf_len
)
276 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
279 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
280 snprintf (buf
+ len
, buf_len
- len
,
281 "%08" DWARF_VMA_FMT
"x", lvalue
);
287 /* Read in a LEB128 encoded value starting at address DATA.
288 If SIGN is true, return a signed LEB128 value.
289 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
290 No bytes will be read at address END or beyond. */
293 read_leb128 (unsigned char *data
,
294 unsigned int *length_return
,
296 const unsigned char * const end
)
298 dwarf_vma result
= 0;
299 unsigned int num_read
= 0;
300 unsigned int shift
= 0;
301 unsigned char byte
= 0;
308 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
311 if ((byte
& 0x80) == 0)
314 /* PR 17512: file: 0ca183b8.
315 FIXME: Should we signal this error somehow ? */
316 if (shift
>= sizeof (result
) * 8)
320 if (length_return
!= NULL
)
321 *length_return
= num_read
;
323 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
324 result
|= -((dwarf_vma
) 1 << shift
);
329 /* Create a signed version to avoid painful typecasts. */
330 static inline dwarf_signed_vma
331 read_sleb128 (unsigned char * data
,
332 unsigned int * length_return
,
333 const unsigned char * const end
)
335 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, TRUE
, end
);
338 static inline dwarf_vma
339 read_uleb128 (unsigned char * data
,
340 unsigned int * length_return
,
341 const unsigned char * const end
)
343 return read_leb128 (data
, length_return
, FALSE
, end
);
346 #define SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
347 #define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
349 #define READ_ULEB(var) \
354 (var) = _val = read_uleb128 (start, &length_return, end); \
356 error (_("Internal error: %s:%d: LEB value (%s) " \
357 "too large for containing variable\n"), \
358 __FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \
359 start += length_return; \
363 #define READ_SLEB(var) \
366 dwarf_signed_vma _val; \
368 (var) = _val = read_sleb128 (start, &length_return, end); \
370 error (_("Internal error: %s:%d: LEB value (%s) " \
371 "too large for containing variable\n"), \
372 __FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \
373 start += length_return; \
377 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
380 unsigned int amount = (AMOUNT); \
381 if (sizeof (VAL) < amount) \
383 error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
384 amount, (int) sizeof (VAL)); \
385 amount = sizeof (VAL); \
387 if (((PTR) + amount) >= (END)) \
390 amount = (END) - (PTR); \
394 if (amount == 0 || amount > 8) \
397 VAL = byte_get ((PTR), amount); \
401 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
404 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
409 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
412 unsigned int amount = (AMOUNT); \
413 if (((PTR) + amount) >= (END)) \
416 amount = (END) - (PTR); \
421 VAL = byte_get_signed ((PTR), amount); \
427 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
430 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
435 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
438 if (((PTR) + 8) <= (END)) \
440 byte_get_64 ((PTR), (HIGH), (LOW)); \
444 * (LOW) = * (HIGH) = 0; \
449 typedef struct State_Machine_Registers
458 unsigned char op_index
;
459 unsigned char end_sequence
;
460 /* This variable hold the number of the last entry seen
461 in the File Table. */
462 unsigned int last_file_entry
;
465 static SMR state_machine_regs
;
468 reset_state_machine (int is_stmt
)
470 state_machine_regs
.address
= 0;
471 state_machine_regs
.view
= 0;
472 state_machine_regs
.op_index
= 0;
473 state_machine_regs
.file
= 1;
474 state_machine_regs
.line
= 1;
475 state_machine_regs
.column
= 0;
476 state_machine_regs
.is_stmt
= is_stmt
;
477 state_machine_regs
.basic_block
= 0;
478 state_machine_regs
.end_sequence
= 0;
479 state_machine_regs
.last_file_entry
= 0;
482 /* Handled an extend line op.
483 Returns the number of bytes read. */
486 process_extended_line_op (unsigned char * data
,
490 unsigned char op_code
;
491 unsigned int bytes_read
;
494 unsigned char *orig_data
= data
;
497 len
= read_uleb128 (data
, & bytes_read
, end
);
500 if (len
== 0 || data
== end
|| len
> (uintptr_t) (end
- data
))
502 warn (_("Badly formed extended line op encountered!\n"));
509 printf (_(" Extended opcode %d: "), op_code
);
513 case DW_LNE_end_sequence
:
514 printf (_("End of Sequence\n\n"));
515 reset_state_machine (is_stmt
);
518 case DW_LNE_set_address
:
519 /* PR 17512: file: 002-100480-0.004. */
520 if (len
- bytes_read
- 1 > 8)
522 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
523 len
- bytes_read
- 1);
527 SAFE_BYTE_GET (adr
, data
, len
- bytes_read
- 1, end
);
528 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
529 state_machine_regs
.address
= adr
;
530 state_machine_regs
.view
= 0;
531 state_machine_regs
.op_index
= 0;
534 case DW_LNE_define_file
:
535 printf (_("define new File Table entry\n"));
536 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
537 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
543 l
= strnlen ((char *) data
, end
- data
);
545 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
547 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
549 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
551 printf ("%.*s\n\n", (int) l
, name
);
554 if (((unsigned int) (data
- orig_data
) != len
) || data
== end
)
555 warn (_("DW_LNE_define_file: Bad opcode length\n"));
558 case DW_LNE_set_discriminator
:
559 printf (_("set Discriminator to %s\n"),
560 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
564 case DW_LNE_HP_negate_is_UV_update
:
565 printf ("DW_LNE_HP_negate_is_UV_update\n");
567 case DW_LNE_HP_push_context
:
568 printf ("DW_LNE_HP_push_context\n");
570 case DW_LNE_HP_pop_context
:
571 printf ("DW_LNE_HP_pop_context\n");
573 case DW_LNE_HP_set_file_line_column
:
574 printf ("DW_LNE_HP_set_file_line_column\n");
576 case DW_LNE_HP_set_routine_name
:
577 printf ("DW_LNE_HP_set_routine_name\n");
579 case DW_LNE_HP_set_sequence
:
580 printf ("DW_LNE_HP_set_sequence\n");
582 case DW_LNE_HP_negate_post_semantics
:
583 printf ("DW_LNE_HP_negate_post_semantics\n");
585 case DW_LNE_HP_negate_function_exit
:
586 printf ("DW_LNE_HP_negate_function_exit\n");
588 case DW_LNE_HP_negate_front_end_logical
:
589 printf ("DW_LNE_HP_negate_front_end_logical\n");
591 case DW_LNE_HP_define_proc
:
592 printf ("DW_LNE_HP_define_proc\n");
594 case DW_LNE_HP_source_file_correlation
:
596 unsigned char *edata
= data
+ len
- bytes_read
- 1;
598 printf ("DW_LNE_HP_source_file_correlation\n");
604 opc
= read_uleb128 (data
, & bytes_read
, edata
);
609 case DW_LNE_HP_SFC_formfeed
:
610 printf (" DW_LNE_HP_SFC_formfeed\n");
612 case DW_LNE_HP_SFC_set_listing_line
:
613 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
615 read_uleb128 (data
, & bytes_read
, edata
)));
618 case DW_LNE_HP_SFC_associate
:
619 printf (" DW_LNE_HP_SFC_associate ");
622 read_uleb128 (data
, & bytes_read
, edata
)));
626 read_uleb128 (data
, & bytes_read
, edata
)));
630 read_uleb128 (data
, & bytes_read
, edata
)));
634 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
644 unsigned int rlen
= len
- bytes_read
- 1;
646 if (op_code
>= DW_LNE_lo_user
647 /* The test against DW_LNW_hi_user is redundant due to
648 the limited range of the unsigned char data type used
650 /*&& op_code <= DW_LNE_hi_user*/)
651 printf (_("user defined: "));
653 printf (_("UNKNOWN: "));
654 printf (_("length %d ["), rlen
);
656 printf (" %02x", *data
++);
665 static const unsigned char *
666 fetch_indirect_string (dwarf_vma offset
)
668 struct dwarf_section
*section
= &debug_displays
[str
].section
;
669 const unsigned char * ret
;
671 if (section
->start
== NULL
)
672 return (const unsigned char *) _("<no .debug_str section>");
674 if (offset
>= section
->size
)
676 warn (_("DW_FORM_strp offset too big: %s\n"),
677 dwarf_vmatoa ("x", offset
));
678 return (const unsigned char *) _("<offset is too big>");
681 ret
= section
->start
+ offset
;
682 /* Unfortunately we cannot rely upon the .debug_str section ending with a
683 NUL byte. Since our caller is expecting to receive a well formed C
684 string we test for the lack of a terminating byte here. */
685 if (strnlen ((const char *) ret
, section
->size
- offset
)
686 == section
->size
- offset
)
687 ret
= (const unsigned char *)
688 _("<no NUL byte at end of .debug_str section>");
693 static const unsigned char *
694 fetch_indirect_line_string (dwarf_vma offset
)
696 struct dwarf_section
*section
= &debug_displays
[line_str
].section
;
697 const unsigned char * ret
;
699 if (section
->start
== NULL
)
700 return (const unsigned char *) _("<no .debug_line_str section>");
702 if (offset
>= section
->size
)
704 warn (_("DW_FORM_line_strp offset too big: %s\n"),
705 dwarf_vmatoa ("x", offset
));
706 return (const unsigned char *) _("<offset is too big>");
709 ret
= section
->start
+ offset
;
710 /* Unfortunately we cannot rely upon the .debug_line_str section ending
711 with a NUL byte. Since our caller is expecting to receive a well formed
712 C string we test for the lack of a terminating byte here. */
713 if (strnlen ((const char *) ret
, section
->size
- offset
)
714 == section
->size
- offset
)
715 ret
= (const unsigned char *)
716 _("<no NUL byte at end of .debug_line_str section>");
722 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
723 dwarf_vma offset_size
, int dwo
)
725 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
726 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
727 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
728 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
729 dwarf_vma index_offset
= idx
* offset_size
;
730 dwarf_vma str_offset
;
733 if (index_section
->start
== NULL
)
734 return (dwo
? _("<no .debug_str_offsets.dwo section>")
735 : _("<no .debug_str_offsets section>"));
737 if (this_set
!= NULL
)
738 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
739 if (index_offset
>= index_section
->size
)
741 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
742 dwarf_vmatoa ("x", index_offset
));
743 return _("<index offset is too big>");
746 if (str_section
->start
== NULL
)
747 return (dwo
? _("<no .debug_str.dwo section>")
748 : _("<no .debug_str section>"));
750 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
751 str_offset
-= str_section
->address
;
752 if (str_offset
>= str_section
->size
)
754 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
755 dwarf_vmatoa ("x", str_offset
));
756 return _("<indirect index offset is too big>");
759 ret
= (const char *) str_section
->start
+ str_offset
;
760 /* Unfortunately we cannot rely upon str_section ending with a NUL byte.
761 Since our caller is expecting to receive a well formed C string we test
762 for the lack of a terminating byte here. */
763 if (strnlen (ret
, str_section
->size
- str_offset
)
764 == str_section
->size
- str_offset
)
765 ret
= (const char *) _("<no NUL byte at end of section>");
771 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
773 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
775 if (section
->start
== NULL
)
776 return (_("<no .debug_addr section>"));
778 if (offset
+ bytes
> section
->size
)
780 warn (_("Offset into section %s too big: %s\n"),
781 section
->name
, dwarf_vmatoa ("x", offset
));
782 return "<offset too big>";
785 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
789 /* FIXME: There are better and more efficient ways to handle
790 these structures. For now though, I just want something that
791 is simple to implement. */
792 typedef struct abbrev_attr
794 unsigned long attribute
;
796 bfd_signed_vma implicit_const
;
797 struct abbrev_attr
*next
;
801 typedef struct abbrev_entry
806 struct abbrev_attr
*first_attr
;
807 struct abbrev_attr
*last_attr
;
808 struct abbrev_entry
*next
;
812 static abbrev_entry
*first_abbrev
= NULL
;
813 static abbrev_entry
*last_abbrev
= NULL
;
820 for (abbrv
= first_abbrev
; abbrv
;)
822 abbrev_entry
*next_abbrev
= abbrv
->next
;
825 for (attr
= abbrv
->first_attr
; attr
;)
827 abbrev_attr
*next_attr
= attr
->next
;
837 last_abbrev
= first_abbrev
= NULL
;
841 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
845 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
850 entry
->entry
= number
;
852 entry
->children
= children
;
853 entry
->first_attr
= NULL
;
854 entry
->last_attr
= NULL
;
857 if (first_abbrev
== NULL
)
858 first_abbrev
= entry
;
860 last_abbrev
->next
= entry
;
866 add_abbrev_attr (unsigned long attribute
, unsigned long form
,
867 bfd_signed_vma implicit_const
)
871 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
876 attr
->attribute
= attribute
;
878 attr
->implicit_const
= implicit_const
;
881 if (last_abbrev
->first_attr
== NULL
)
882 last_abbrev
->first_attr
= attr
;
884 last_abbrev
->last_attr
->next
= attr
;
886 last_abbrev
->last_attr
= attr
;
889 /* Processes the (partial) contents of a .debug_abbrev section.
890 Returns NULL if the end of the section was encountered.
891 Returns the address after the last byte read if the end of
892 an abbreviation set was found. */
894 static unsigned char *
895 process_abbrev_section (unsigned char *start
, unsigned char *end
)
897 if (first_abbrev
!= NULL
)
902 unsigned int bytes_read
;
905 unsigned long attribute
;
908 entry
= read_uleb128 (start
, & bytes_read
, end
);
911 /* A single zero is supposed to end the section according
912 to the standard. If there's more, then signal that to
919 tag
= read_uleb128 (start
, & bytes_read
, end
);
926 add_abbrev (entry
, tag
, children
);
931 /* Initialize it due to a false compiler warning. */
932 bfd_signed_vma implicit_const
= -1;
934 attribute
= read_uleb128 (start
, & bytes_read
, end
);
939 form
= read_uleb128 (start
, & bytes_read
, end
);
944 if (form
== DW_FORM_implicit_const
)
946 implicit_const
= read_sleb128 (start
, & bytes_read
, end
);
952 add_abbrev_attr (attribute
, form
, implicit_const
);
954 while (attribute
!= 0);
957 /* Report the missing single zero which ends the section. */
958 error (_(".debug_abbrev section not zero terminated\n"));
964 get_TAG_name (unsigned long tag
)
966 const char *name
= get_DW_TAG_name ((unsigned int)tag
);
970 static char buffer
[100];
972 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
980 get_FORM_name (unsigned long form
)
985 return "DW_FORM value: 0";
987 name
= get_DW_FORM_name (form
);
990 static char buffer
[100];
992 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1000 get_IDX_name (unsigned long idx
)
1002 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1006 static char buffer
[100];
1008 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1015 static unsigned char *
1016 display_block (unsigned char *data
,
1018 const unsigned char * const end
, char delimiter
)
1022 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1024 return (unsigned char *) end
;
1026 maxlen
= (dwarf_vma
) (end
- data
);
1027 length
= length
> maxlen
? maxlen
: length
;
1030 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1036 decode_location_expression (unsigned char * data
,
1037 unsigned int pointer_size
,
1038 unsigned int offset_size
,
1041 dwarf_vma cu_offset
,
1042 struct dwarf_section
* section
)
1045 unsigned int bytes_read
;
1047 dwarf_signed_vma svalue
;
1048 unsigned char *end
= data
+ length
;
1049 int need_frame_base
= 0;
1058 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1059 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1062 printf ("DW_OP_deref");
1065 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1066 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1069 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1070 printf ("DW_OP_const1s: %ld", (long) svalue
);
1073 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1074 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1077 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1078 printf ("DW_OP_const2s: %ld", (long) svalue
);
1081 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1082 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1085 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1086 printf ("DW_OP_const4s: %ld", (long) svalue
);
1089 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1090 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1091 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1092 printf ("%lu", (unsigned long) uvalue
);
1095 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1096 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1097 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1098 printf ("%ld", (long) svalue
);
1101 printf ("DW_OP_constu: %s",
1102 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1106 printf ("DW_OP_consts: %s",
1107 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1111 printf ("DW_OP_dup");
1114 printf ("DW_OP_drop");
1117 printf ("DW_OP_over");
1120 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1121 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1124 printf ("DW_OP_swap");
1127 printf ("DW_OP_rot");
1130 printf ("DW_OP_xderef");
1133 printf ("DW_OP_abs");
1136 printf ("DW_OP_and");
1139 printf ("DW_OP_div");
1142 printf ("DW_OP_minus");
1145 printf ("DW_OP_mod");
1148 printf ("DW_OP_mul");
1151 printf ("DW_OP_neg");
1154 printf ("DW_OP_not");
1157 printf ("DW_OP_or");
1160 printf ("DW_OP_plus");
1162 case DW_OP_plus_uconst
:
1163 printf ("DW_OP_plus_uconst: %s",
1164 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1168 printf ("DW_OP_shl");
1171 printf ("DW_OP_shr");
1174 printf ("DW_OP_shra");
1177 printf ("DW_OP_xor");
1180 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1181 printf ("DW_OP_bra: %ld", (long) svalue
);
1184 printf ("DW_OP_eq");
1187 printf ("DW_OP_ge");
1190 printf ("DW_OP_gt");
1193 printf ("DW_OP_le");
1196 printf ("DW_OP_lt");
1199 printf ("DW_OP_ne");
1202 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1203 printf ("DW_OP_skip: %ld", (long) svalue
);
1238 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1273 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1274 regname (op
- DW_OP_reg0
, 1));
1309 printf ("DW_OP_breg%d (%s): %s",
1311 regname (op
- DW_OP_breg0
, 1),
1312 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1317 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1319 printf ("DW_OP_regx: %s (%s)",
1320 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1323 need_frame_base
= 1;
1324 printf ("DW_OP_fbreg: %s",
1325 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1329 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1331 printf ("DW_OP_bregx: %s (%s) %s",
1332 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1333 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1337 printf ("DW_OP_piece: %s",
1338 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1341 case DW_OP_deref_size
:
1342 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1343 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1345 case DW_OP_xderef_size
:
1346 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1347 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1350 printf ("DW_OP_nop");
1353 /* DWARF 3 extensions. */
1354 case DW_OP_push_object_address
:
1355 printf ("DW_OP_push_object_address");
1358 /* XXX: Strictly speaking for 64-bit DWARF3 files
1359 this ought to be an 8-byte wide computation. */
1360 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1361 printf ("DW_OP_call2: <0x%s>",
1362 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1365 /* XXX: Strictly speaking for 64-bit DWARF3 files
1366 this ought to be an 8-byte wide computation. */
1367 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1368 printf ("DW_OP_call4: <0x%s>",
1369 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1371 case DW_OP_call_ref
:
1372 /* XXX: Strictly speaking for 64-bit DWARF3 files
1373 this ought to be an 8-byte wide computation. */
1374 if (dwarf_version
== -1)
1376 printf (_("(DW_OP_call_ref in frame info)"));
1377 /* No way to tell where the next op is, so just bail. */
1378 return need_frame_base
;
1380 if (dwarf_version
== 2)
1382 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1386 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1388 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1390 case DW_OP_form_tls_address
:
1391 printf ("DW_OP_form_tls_address");
1393 case DW_OP_call_frame_cfa
:
1394 printf ("DW_OP_call_frame_cfa");
1396 case DW_OP_bit_piece
:
1397 printf ("DW_OP_bit_piece: ");
1398 printf (_("size: %s "),
1399 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1401 printf (_("offset: %s "),
1402 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1406 /* DWARF 4 extensions. */
1407 case DW_OP_stack_value
:
1408 printf ("DW_OP_stack_value");
1411 case DW_OP_implicit_value
:
1412 printf ("DW_OP_implicit_value");
1413 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1415 data
= display_block (data
, uvalue
, end
, ' ');
1418 /* GNU extensions. */
1419 case DW_OP_GNU_push_tls_address
:
1420 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1422 case DW_OP_GNU_uninit
:
1423 printf ("DW_OP_GNU_uninit");
1424 /* FIXME: Is there data associated with this OP ? */
1426 case DW_OP_GNU_encoded_addr
:
1433 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1435 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1436 print_dwarf_vma (addr
, pointer_size
);
1439 case DW_OP_implicit_pointer
:
1440 case DW_OP_GNU_implicit_pointer
:
1441 /* XXX: Strictly speaking for 64-bit DWARF3 files
1442 this ought to be an 8-byte wide computation. */
1443 if (dwarf_version
== -1)
1445 printf (_("(%s in frame info)"),
1446 (op
== DW_OP_implicit_pointer
1447 ? "DW_OP_implicit_pointer"
1448 : "DW_OP_GNU_implicit_pointer"));
1449 /* No way to tell where the next op is, so just bail. */
1450 return need_frame_base
;
1452 if (dwarf_version
== 2)
1454 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1458 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1460 printf ("%s: <0x%s> %s",
1461 (op
== DW_OP_implicit_pointer
1462 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1463 dwarf_vmatoa ("x", uvalue
),
1464 dwarf_vmatoa ("d", read_sleb128 (data
,
1465 &bytes_read
, end
)));
1468 case DW_OP_entry_value
:
1469 case DW_OP_GNU_entry_value
:
1470 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1472 /* PR 17531: file: 0cc9cd00. */
1473 if (uvalue
> (dwarf_vma
) (end
- data
))
1474 uvalue
= end
- data
;
1475 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1476 : "DW_OP_GNU_entry_value"));
1477 if (decode_location_expression (data
, pointer_size
, offset_size
,
1478 dwarf_version
, uvalue
,
1479 cu_offset
, section
))
1480 need_frame_base
= 1;
1486 case DW_OP_const_type
:
1487 case DW_OP_GNU_const_type
:
1488 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1490 printf ("%s: <0x%s> ",
1491 (op
== DW_OP_const_type
? "DW_OP_const_type"
1492 : "DW_OP_GNU_const_type"),
1493 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1494 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1495 data
= display_block (data
, uvalue
, end
, ' ');
1497 case DW_OP_regval_type
:
1498 case DW_OP_GNU_regval_type
:
1499 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1501 printf ("%s: %s (%s)",
1502 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1503 : "DW_OP_GNU_regval_type"),
1504 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1505 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1507 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1509 case DW_OP_deref_type
:
1510 case DW_OP_GNU_deref_type
:
1511 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1513 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1514 : "DW_OP_GNU_deref_type"),
1516 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1518 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1521 case DW_OP_GNU_convert
:
1522 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1524 printf ("%s <0x%s>",
1525 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1526 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1528 case DW_OP_reinterpret
:
1529 case DW_OP_GNU_reinterpret
:
1530 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1532 printf ("%s <0x%s>",
1533 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1534 : "DW_OP_GNU_reinterpret"),
1535 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1537 case DW_OP_GNU_parameter_ref
:
1538 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1539 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1540 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1542 case DW_OP_GNU_addr_index
:
1543 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1545 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1547 case DW_OP_GNU_const_index
:
1548 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1550 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1553 /* HP extensions. */
1554 case DW_OP_HP_is_value
:
1555 printf ("DW_OP_HP_is_value");
1556 /* FIXME: Is there data associated with this OP ? */
1558 case DW_OP_HP_fltconst4
:
1559 printf ("DW_OP_HP_fltconst4");
1560 /* FIXME: Is there data associated with this OP ? */
1562 case DW_OP_HP_fltconst8
:
1563 printf ("DW_OP_HP_fltconst8");
1564 /* FIXME: Is there data associated with this OP ? */
1566 case DW_OP_HP_mod_range
:
1567 printf ("DW_OP_HP_mod_range");
1568 /* FIXME: Is there data associated with this OP ? */
1570 case DW_OP_HP_unmod_range
:
1571 printf ("DW_OP_HP_unmod_range");
1572 /* FIXME: Is there data associated with this OP ? */
1575 printf ("DW_OP_HP_tls");
1576 /* FIXME: Is there data associated with this OP ? */
1579 /* PGI (STMicroelectronics) extensions. */
1580 case DW_OP_PGI_omp_thread_num
:
1581 /* Pushes the thread number for the current thread as it would be
1582 returned by the standard OpenMP library function:
1583 omp_get_thread_num(). The "current thread" is the thread for
1584 which the expression is being evaluated. */
1585 printf ("DW_OP_PGI_omp_thread_num");
1589 if (op
>= DW_OP_lo_user
1590 && op
<= DW_OP_hi_user
)
1591 printf (_("(User defined location op 0x%x)"), op
);
1593 printf (_("(Unknown location op 0x%x)"), op
);
1594 /* No way to tell where the next op is, so just bail. */
1595 return need_frame_base
;
1598 /* Separate the ops. */
1603 return need_frame_base
;
1606 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1607 This is used for DWARF package files. */
1609 static struct cu_tu_set
*
1610 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1612 struct cu_tu_set
*p
;
1614 unsigned int dw_sect
;
1620 dw_sect
= DW_SECT_TYPES
;
1626 dw_sect
= DW_SECT_INFO
;
1630 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1638 /* Add INC to HIGH_BITS:LOW_BITS. */
1640 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1642 dwarf_vma tmp
= * low_bits
;
1646 /* FIXME: There is probably a better way of handling this:
1648 We need to cope with dwarf_vma being a 32-bit or 64-bit
1649 type. Plus regardless of its size LOW_BITS is meant to
1650 only hold 32-bits, so if there is overflow or wrap around
1651 we must propagate into HIGH_BITS. */
1652 if (tmp
< * low_bits
)
1656 else if (sizeof (tmp
) > 8
1666 static unsigned char *
1667 read_and_display_attr_value (unsigned long attribute
,
1669 dwarf_signed_vma implicit_const
,
1670 unsigned char * data
,
1671 unsigned char * end
,
1672 dwarf_vma cu_offset
,
1673 dwarf_vma pointer_size
,
1674 dwarf_vma offset_size
,
1676 debug_info
* debug_info_p
,
1678 struct dwarf_section
* section
,
1679 struct cu_tu_set
* this_set
, char delimiter
)
1681 dwarf_vma uvalue
= 0;
1682 unsigned char *block_start
= NULL
;
1683 unsigned char * orig_data
= data
;
1684 unsigned int bytes_read
;
1686 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
1688 warn (_("Corrupt attribute\n"));
1697 case DW_FORM_ref_addr
:
1698 if (dwarf_version
== 2)
1699 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1700 else if (dwarf_version
== 3 || dwarf_version
== 4)
1701 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1703 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1708 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1712 case DW_FORM_line_strp
:
1713 case DW_FORM_sec_offset
:
1714 case DW_FORM_GNU_ref_alt
:
1715 case DW_FORM_GNU_strp_alt
:
1716 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1719 case DW_FORM_flag_present
:
1726 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1731 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1736 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1740 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1744 case DW_FORM_GNU_str_index
:
1745 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1749 case DW_FORM_ref_udata
:
1751 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1755 case DW_FORM_indirect
:
1756 form
= read_uleb128 (data
, & bytes_read
, end
);
1759 printf ("%c%s", delimiter
, get_FORM_name (form
));
1760 if (form
== DW_FORM_implicit_const
)
1762 implicit_const
= read_sleb128 (data
, & bytes_read
, end
);
1765 return read_and_display_attr_value (attribute
, form
, implicit_const
, data
,
1766 end
, cu_offset
, pointer_size
,
1767 offset_size
, dwarf_version
,
1768 debug_info_p
, do_loc
,
1769 section
, this_set
, delimiter
);
1770 case DW_FORM_GNU_addr_index
:
1771 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1778 case DW_FORM_ref_addr
:
1780 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1783 case DW_FORM_GNU_ref_alt
:
1785 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1791 case DW_FORM_ref_udata
:
1793 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1798 case DW_FORM_sec_offset
:
1800 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
1803 case DW_FORM_flag_present
:
1810 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
1813 case DW_FORM_implicit_const
:
1815 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
1822 dwarf_vma high_bits
;
1826 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1828 if (form
== DW_FORM_ref8
)
1829 add64 (& high_bits
, & utmp
, cu_offset
);
1830 printf ("%c0x%s", delimiter
,
1831 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1834 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1835 && num_debug_info_entries
== 0)
1837 if (sizeof (uvalue
) == 8)
1838 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1840 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1846 case DW_FORM_data16
:
1849 dwarf_vma left_high_bits
, left_low_bits
;
1850 dwarf_vma right_high_bits
, right_low_bits
;
1852 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
1853 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
1854 if (byte_get
== byte_get_little_endian
)
1857 left_high_bits
^= right_high_bits
;
1858 right_high_bits
^= left_high_bits
;
1859 left_high_bits
^= right_high_bits
;
1860 left_low_bits
^= right_low_bits
;
1861 right_low_bits
^= left_low_bits
;
1862 left_low_bits
^= right_low_bits
;
1864 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
1865 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
1866 left_high_bits
, left_low_bits
, right_high_bits
,
1872 case DW_FORM_string
:
1874 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
1875 data
+= strnlen ((char *) data
, end
- data
) + 1;
1879 case DW_FORM_exprloc
:
1880 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1881 block_start
= data
+ bytes_read
;
1882 if (block_start
>= end
)
1884 warn (_("Block ends prematurely\n"));
1888 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1889 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1890 block_start + uvalue here. */
1891 data
= block_start
+ uvalue
;
1892 /* PR 17512: file: 008-103549-0.001:0.1. */
1893 if (block_start
+ uvalue
> end
|| data
< block_start
)
1895 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1896 uvalue
= end
- block_start
;
1899 data
= block_start
+ uvalue
;
1901 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1904 case DW_FORM_block1
:
1905 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1906 block_start
= data
+ 1;
1907 if (block_start
>= end
)
1909 warn (_("Block ends prematurely\n"));
1913 data
= block_start
+ uvalue
;
1914 if (block_start
+ uvalue
> end
|| data
< block_start
)
1916 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1917 uvalue
= end
- block_start
;
1920 data
= block_start
+ uvalue
;
1922 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1925 case DW_FORM_block2
:
1926 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1927 block_start
= data
+ 2;
1928 if (block_start
>= end
)
1930 warn (_("Block ends prematurely\n"));
1934 data
= block_start
+ uvalue
;
1935 if (block_start
+ uvalue
> end
|| data
< block_start
)
1937 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1938 uvalue
= end
- block_start
;
1941 data
= block_start
+ uvalue
;
1943 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1946 case DW_FORM_block4
:
1947 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1948 block_start
= data
+ 4;
1949 /* PR 17512: file: 3371-3907-0.004. */
1950 if (block_start
>= end
)
1952 warn (_("Block ends prematurely\n"));
1956 data
= block_start
+ uvalue
;
1957 if (block_start
+ uvalue
> end
1958 /* PR 17531: file: 5b5f0592. */
1959 || data
< block_start
)
1961 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1962 uvalue
= end
- block_start
;
1965 data
= block_start
+ uvalue
;
1967 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1972 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
1973 dwarf_vmatoa ("x", uvalue
),
1974 fetch_indirect_string (uvalue
));
1977 case DW_FORM_line_strp
:
1979 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
1980 dwarf_vmatoa ("x", uvalue
),
1981 fetch_indirect_line_string (uvalue
));
1984 case DW_FORM_GNU_str_index
:
1987 const char *suffix
= strrchr (section
->name
, '.');
1988 int dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? 1 : 0;
1990 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
1991 dwarf_vmatoa ("x", uvalue
),
1992 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
1996 case DW_FORM_GNU_strp_alt
:
1998 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter
,
1999 dwarf_vmatoa ("x", uvalue
));
2002 case DW_FORM_indirect
:
2003 /* Handled above. */
2006 case DW_FORM_ref_sig8
:
2009 dwarf_vma high_bits
;
2012 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2013 printf ("%csignature: 0x%s", delimiter
,
2014 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2019 case DW_FORM_GNU_addr_index
:
2021 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2022 dwarf_vmatoa ("x", uvalue
),
2023 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2027 warn (_("Unrecognized form: %lu\n"), form
);
2031 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2032 && num_debug_info_entries
== 0
2033 && debug_info_p
!= NULL
)
2037 case DW_AT_frame_base
:
2038 have_frame_base
= 1;
2040 case DW_AT_location
:
2041 case DW_AT_GNU_locviews
:
2042 case DW_AT_string_length
:
2043 case DW_AT_return_addr
:
2044 case DW_AT_data_member_location
:
2045 case DW_AT_vtable_elem_location
:
2047 case DW_AT_static_link
:
2048 case DW_AT_use_location
:
2049 case DW_AT_call_value
:
2050 case DW_AT_GNU_call_site_value
:
2051 case DW_AT_call_data_value
:
2052 case DW_AT_GNU_call_site_data_value
:
2053 case DW_AT_call_target
:
2054 case DW_AT_GNU_call_site_target
:
2055 case DW_AT_call_target_clobbered
:
2056 case DW_AT_GNU_call_site_target_clobbered
:
2057 if ((dwarf_version
< 4
2058 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2059 || form
== DW_FORM_sec_offset
)
2061 /* Process location list. */
2062 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2063 unsigned int num
= debug_info_p
->num_loc_offsets
;
2065 if (lmax
== 0 || num
>= lmax
)
2068 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2069 xcrealloc (debug_info_p
->loc_offsets
,
2070 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2071 debug_info_p
->loc_views
= (dwarf_vma
*)
2072 xcrealloc (debug_info_p
->loc_views
,
2073 lmax
, sizeof (*debug_info_p
->loc_views
));
2074 debug_info_p
->have_frame_base
= (int *)
2075 xcrealloc (debug_info_p
->have_frame_base
,
2076 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2077 debug_info_p
->max_loc_offsets
= lmax
;
2079 if (this_set
!= NULL
)
2080 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2081 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2082 if (attribute
!= DW_AT_GNU_locviews
)
2084 debug_info_p
->loc_offsets
[num
] = uvalue
;
2085 debug_info_p
->num_loc_offsets
++;
2086 assert (debug_info_p
->num_loc_offsets
2087 - debug_info_p
->num_loc_views
<= 1);
2091 assert (debug_info_p
->num_loc_views
<= num
);
2092 num
= debug_info_p
->num_loc_views
;
2093 debug_info_p
->loc_views
[num
] = uvalue
;
2094 debug_info_p
->num_loc_views
++;
2095 assert (debug_info_p
->num_loc_views
2096 - debug_info_p
->num_loc_offsets
<= 1);
2102 if (need_base_address
)
2103 debug_info_p
->base_address
= uvalue
;
2106 case DW_AT_GNU_addr_base
:
2107 debug_info_p
->addr_base
= uvalue
;
2110 case DW_AT_GNU_ranges_base
:
2111 debug_info_p
->ranges_base
= uvalue
;
2115 if ((dwarf_version
< 4
2116 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2117 || form
== DW_FORM_sec_offset
)
2119 /* Process range list. */
2120 unsigned int lmax
= debug_info_p
->max_range_lists
;
2121 unsigned int num
= debug_info_p
->num_range_lists
;
2123 if (lmax
== 0 || num
>= lmax
)
2126 debug_info_p
->range_lists
= (dwarf_vma
*)
2127 xcrealloc (debug_info_p
->range_lists
,
2128 lmax
, sizeof (*debug_info_p
->range_lists
));
2129 debug_info_p
->max_range_lists
= lmax
;
2131 debug_info_p
->range_lists
[num
] = uvalue
;
2132 debug_info_p
->num_range_lists
++;
2141 if (do_loc
|| attribute
== 0)
2144 /* For some attributes we can display further information. */
2151 case DW_INL_not_inlined
:
2152 printf (_("(not inlined)"));
2154 case DW_INL_inlined
:
2155 printf (_("(inlined)"));
2157 case DW_INL_declared_not_inlined
:
2158 printf (_("(declared as inline but ignored)"));
2160 case DW_INL_declared_inlined
:
2161 printf (_("(declared as inline and inlined)"));
2164 printf (_(" (Unknown inline attribute value: %s)"),
2165 dwarf_vmatoa ("x", uvalue
));
2170 case DW_AT_language
:
2174 /* Ordered by the numeric value of these constants. */
2175 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2176 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2177 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2178 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2179 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2180 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2181 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2182 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2183 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2184 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2185 /* DWARF 2.1 values. */
2186 case DW_LANG_Java
: printf ("(Java)"); break;
2187 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2188 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2189 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2190 /* DWARF 3 values. */
2191 case DW_LANG_PLI
: printf ("(PLI)"); break;
2192 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2193 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2194 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2195 case DW_LANG_D
: printf ("(D)"); break;
2196 /* DWARF 4 values. */
2197 case DW_LANG_Python
: printf ("(Python)"); break;
2198 /* DWARF 5 values. */
2199 case DW_LANG_Go
: printf ("(Go)"); break;
2200 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2201 case DW_LANG_C11
: printf ("(C11)"); break;
2202 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2203 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2204 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2205 /* MIPS extension. */
2206 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2207 /* UPC extension. */
2208 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2210 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2211 printf (_("(implementation defined: %s)"),
2212 dwarf_vmatoa ("x", uvalue
));
2214 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2219 case DW_AT_encoding
:
2223 case DW_ATE_void
: printf ("(void)"); break;
2224 case DW_ATE_address
: printf ("(machine address)"); break;
2225 case DW_ATE_boolean
: printf ("(boolean)"); break;
2226 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2227 case DW_ATE_float
: printf ("(float)"); break;
2228 case DW_ATE_signed
: printf ("(signed)"); break;
2229 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2230 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2231 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2232 /* DWARF 2.1 values: */
2233 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2234 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2235 /* DWARF 3 values: */
2236 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2237 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2238 case DW_ATE_edited
: printf ("(edited)"); break;
2239 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2240 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2241 /* HP extensions: */
2242 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2243 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2244 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2245 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2246 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2247 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2248 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2249 /* DWARF 4 values: */
2250 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2253 if (uvalue
>= DW_ATE_lo_user
2254 && uvalue
<= DW_ATE_hi_user
)
2255 printf (_("(user defined type)"));
2257 printf (_("(unknown type)"));
2262 case DW_AT_accessibility
:
2266 case DW_ACCESS_public
: printf ("(public)"); break;
2267 case DW_ACCESS_protected
: printf ("(protected)"); break;
2268 case DW_ACCESS_private
: printf ("(private)"); break;
2270 printf (_("(unknown accessibility)"));
2275 case DW_AT_visibility
:
2279 case DW_VIS_local
: printf ("(local)"); break;
2280 case DW_VIS_exported
: printf ("(exported)"); break;
2281 case DW_VIS_qualified
: printf ("(qualified)"); break;
2282 default: printf (_("(unknown visibility)")); break;
2286 case DW_AT_virtuality
:
2290 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2291 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2292 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2293 default: printf (_("(unknown virtuality)")); break;
2297 case DW_AT_identifier_case
:
2301 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2302 case DW_ID_up_case
: printf ("(up_case)"); break;
2303 case DW_ID_down_case
: printf ("(down_case)"); break;
2304 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2305 default: printf (_("(unknown case)")); break;
2309 case DW_AT_calling_convention
:
2313 case DW_CC_normal
: printf ("(normal)"); break;
2314 case DW_CC_program
: printf ("(program)"); break;
2315 case DW_CC_nocall
: printf ("(nocall)"); break;
2317 if (uvalue
>= DW_CC_lo_user
2318 && uvalue
<= DW_CC_hi_user
)
2319 printf (_("(user defined)"));
2321 printf (_("(unknown convention)"));
2325 case DW_AT_ordering
:
2329 case -1: printf (_("(undefined)")); break;
2330 case 0: printf ("(row major)"); break;
2331 case 1: printf ("(column major)"); break;
2335 case DW_AT_frame_base
:
2336 have_frame_base
= 1;
2338 case DW_AT_location
:
2339 case DW_AT_string_length
:
2340 case DW_AT_return_addr
:
2341 case DW_AT_data_member_location
:
2342 case DW_AT_vtable_elem_location
:
2344 case DW_AT_static_link
:
2345 case DW_AT_use_location
:
2346 case DW_AT_call_value
:
2347 case DW_AT_GNU_call_site_value
:
2348 case DW_AT_call_data_value
:
2349 case DW_AT_GNU_call_site_data_value
:
2350 case DW_AT_call_target
:
2351 case DW_AT_GNU_call_site_target
:
2352 case DW_AT_call_target_clobbered
:
2353 case DW_AT_GNU_call_site_target_clobbered
:
2354 if ((dwarf_version
< 4
2355 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2356 || form
== DW_FORM_sec_offset
)
2357 printf (_(" (location list)"));
2359 case DW_AT_allocated
:
2360 case DW_AT_associated
:
2361 case DW_AT_data_location
:
2363 case DW_AT_upper_bound
:
2364 case DW_AT_lower_bound
:
2367 int need_frame_base
;
2370 need_frame_base
= decode_location_expression (block_start
,
2375 cu_offset
, section
);
2377 if (need_frame_base
&& !have_frame_base
)
2378 printf (_(" [without DW_AT_frame_base]"));
2384 if (form
== DW_FORM_ref_sig8
2385 || form
== DW_FORM_GNU_ref_alt
)
2388 if (form
== DW_FORM_ref1
2389 || form
== DW_FORM_ref2
2390 || form
== DW_FORM_ref4
2391 || form
== DW_FORM_ref_udata
)
2392 uvalue
+= cu_offset
;
2394 if (uvalue
>= section
->size
)
2395 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2396 dwarf_vmatoa ("x", uvalue
),
2397 (unsigned long) (orig_data
- section
->start
));
2400 unsigned long abbrev_number
;
2401 abbrev_entry
* entry
;
2403 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2405 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2406 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2407 use different abbrev table, and we don't track .debug_info chunks
2409 if (form
!= DW_FORM_ref_addr
)
2411 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2412 if (entry
->entry
== abbrev_number
)
2415 printf (" (%s)", get_TAG_name (entry
->tag
));
2430 get_AT_name (unsigned long attribute
)
2435 return "DW_AT value: 0";
2437 /* One value is shared by the MIPS and HP extensions: */
2438 if (attribute
== DW_AT_MIPS_fde
)
2439 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2441 name
= get_DW_AT_name (attribute
);
2445 static char buffer
[100];
2447 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2455 static unsigned char *
2456 read_and_display_attr (unsigned long attribute
,
2458 dwarf_signed_vma implicit_const
,
2459 unsigned char * data
,
2460 unsigned char * end
,
2461 dwarf_vma cu_offset
,
2462 dwarf_vma pointer_size
,
2463 dwarf_vma offset_size
,
2465 debug_info
* debug_info_p
,
2467 struct dwarf_section
* section
,
2468 struct cu_tu_set
* this_set
)
2471 printf (" %-18s:", get_AT_name (attribute
));
2472 data
= read_and_display_attr_value (attribute
, form
, implicit_const
, data
, end
,
2473 cu_offset
, pointer_size
, offset_size
,
2474 dwarf_version
, debug_info_p
,
2475 do_loc
, section
, this_set
, ' ');
2481 /* Process the contents of a .debug_info section. If do_loc is non-zero
2482 then we are scanning for location lists and we do not want to display
2483 anything to the user. If do_types is non-zero, we are processing
2484 a .debug_types section instead of a .debug_info section. */
2487 process_debug_info (struct dwarf_section
*section
,
2489 enum dwarf_section_display_enum abbrev_sec
,
2493 unsigned char *start
= section
->start
;
2494 unsigned char *end
= start
+ section
->size
;
2495 unsigned char *section_begin
;
2497 unsigned int num_units
= 0;
2499 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2500 && num_debug_info_entries
== 0
2505 /* First scan the section to get the number of comp units. */
2506 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2509 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2510 will be the length. For a 64-bit DWARF section, it'll be
2511 the escape code 0xffffffff followed by an 8 byte length. */
2512 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2514 if (length
== 0xffffffff)
2516 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2517 section_begin
+= length
+ 12;
2519 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2521 warn (_("Reserved length value (0x%s) found in section %s\n"),
2522 dwarf_vmatoa ("x", length
), section
->name
);
2526 section_begin
+= length
+ 4;
2528 /* Negative values are illegal, they may even cause infinite
2529 looping. This can happen if we can't accurately apply
2530 relocations to an object file, or if the file is corrupt. */
2531 if ((signed long) length
<= 0 || section_begin
< start
)
2533 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2534 dwarf_vmatoa ("x", length
), section
->name
);
2541 error (_("No comp units in %s section ?\n"), section
->name
);
2545 /* Then allocate an array to hold the information. */
2546 debug_information
= (debug_info
*) cmalloc (num_units
,
2547 sizeof (* debug_information
));
2548 if (debug_information
== NULL
)
2550 error (_("Not enough memory for a debug info array of %u entries\n"),
2552 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
2555 /* PR 17531: file: 92ca3797.
2556 We cannot rely upon the debug_information array being initialised
2557 before it is used. A corrupt file could easily contain references
2558 to a unit for which information has not been made available. So
2559 we ensure that the array is zeroed here. */
2560 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
2562 alloc_num_debug_info_entries
= num_units
;
2567 if (dwarf_start_die
== 0)
2568 printf (_("Contents of the %s section:\n\n"), section
->name
);
2570 load_debug_section (str
, file
);
2571 load_debug_section (line_str
, file
);
2572 load_debug_section (str_dwo
, file
);
2573 load_debug_section (str_index
, file
);
2574 load_debug_section (str_index_dwo
, file
);
2575 load_debug_section (debug_addr
, file
);
2578 load_debug_section (abbrev_sec
, file
);
2579 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2581 warn (_("Unable to locate %s section!\n"),
2582 debug_displays
[abbrev_sec
].section
.name
);
2586 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2588 DWARF2_Internal_CompUnit compunit
;
2589 unsigned char *hdrptr
;
2590 unsigned char *tags
;
2591 int level
, last_level
, saved_level
;
2592 dwarf_vma cu_offset
;
2593 unsigned int offset_size
;
2594 int initial_length_size
;
2595 dwarf_vma signature_high
= 0;
2596 dwarf_vma signature_low
= 0;
2597 dwarf_vma type_offset
= 0;
2598 struct cu_tu_set
*this_set
;
2599 dwarf_vma abbrev_base
;
2604 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2606 if (compunit
.cu_length
== 0xffffffff)
2608 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2610 initial_length_size
= 12;
2615 initial_length_size
= 4;
2618 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2620 cu_offset
= start
- section_begin
;
2622 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2624 if (compunit
.cu_version
< 5)
2626 compunit
.cu_unit_type
= DW_UT_compile
;
2627 /* Initialize it due to a false compiler warning. */
2628 compunit
.cu_pointer_size
= -1;
2632 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
2633 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
2635 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2638 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2640 if (this_set
== NULL
)
2643 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2647 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2648 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2651 if (compunit
.cu_version
< 5)
2652 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2654 /* PR 17512: file: 001-108546-0.001:0.1. */
2655 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
2657 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2658 compunit
.cu_pointer_size
, offset_size
);
2659 compunit
.cu_pointer_size
= offset_size
;
2664 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2666 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2669 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2670 && num_debug_info_entries
== 0
2673 debug_information
[unit
].cu_offset
= cu_offset
;
2674 debug_information
[unit
].pointer_size
2675 = compunit
.cu_pointer_size
;
2676 debug_information
[unit
].offset_size
= offset_size
;
2677 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2678 debug_information
[unit
].base_address
= 0;
2679 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2680 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2681 debug_information
[unit
].loc_offsets
= NULL
;
2682 debug_information
[unit
].have_frame_base
= NULL
;
2683 debug_information
[unit
].max_loc_offsets
= 0;
2684 debug_information
[unit
].num_loc_offsets
= 0;
2685 debug_information
[unit
].range_lists
= NULL
;
2686 debug_information
[unit
].max_range_lists
= 0;
2687 debug_information
[unit
].num_range_lists
= 0;
2690 if (!do_loc
&& dwarf_start_die
== 0)
2692 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2693 dwarf_vmatoa ("x", cu_offset
));
2694 printf (_(" Length: 0x%s (%s)\n"),
2695 dwarf_vmatoa ("x", compunit
.cu_length
),
2696 offset_size
== 8 ? "64-bit" : "32-bit");
2697 printf (_(" Version: %d\n"), compunit
.cu_version
);
2698 printf (_(" Abbrev Offset: 0x%s\n"),
2699 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2700 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2705 printf (_(" Signature: 0x%s\n"),
2706 dwarf_vmatoa64 (signature_high
, signature_low
,
2707 buf
, sizeof (buf
)));
2708 printf (_(" Type Offset: 0x%s\n"),
2709 dwarf_vmatoa ("x", type_offset
));
2711 if (this_set
!= NULL
)
2713 dwarf_vma
*offsets
= this_set
->section_offsets
;
2714 size_t *sizes
= this_set
->section_sizes
;
2716 printf (_(" Section contributions:\n"));
2717 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2718 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
2719 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
2720 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2721 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
2722 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
2723 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2724 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
2725 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
2726 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2727 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
2728 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
2732 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2735 warn (_("Debug info is corrupted, length of CU at %s"
2736 " extends beyond end of section (length = %s)\n"),
2737 dwarf_vmatoa ("x", cu_offset
),
2738 dwarf_vmatoa ("x", compunit
.cu_length
));
2743 start
+= compunit
.cu_length
+ initial_length_size
;
2747 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2748 dwarf_vmatoa ("x", cu_offset
));
2752 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
2754 warn (_("CU at offset %s contains corrupt or "
2755 "unsupported version number: %d.\n"),
2756 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2760 if (compunit
.cu_unit_type
!= DW_UT_compile
2761 && compunit
.cu_unit_type
!= DW_UT_type
)
2763 warn (_("CU at offset %s contains corrupt or "
2764 "unsupported unit type: %d.\n"),
2765 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
2771 /* Process the abbrevs used by this compilation unit. */
2772 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
2773 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2774 (unsigned long) compunit
.cu_abbrev_offset
,
2775 (unsigned long) abbrev_size
);
2776 /* PR 17531: file:4bcd9ce9. */
2777 else if ((abbrev_base
+ abbrev_size
)
2778 > debug_displays
[abbrev_sec
].section
.size
)
2779 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2780 (unsigned long) abbrev_base
+ abbrev_size
,
2781 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2783 process_abbrev_section
2784 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2785 + abbrev_base
+ compunit
.cu_abbrev_offset
),
2786 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2787 + abbrev_base
+ abbrev_size
));
2792 while (tags
< start
)
2794 unsigned int bytes_read
;
2795 unsigned long abbrev_number
;
2796 unsigned long die_offset
;
2797 abbrev_entry
*entry
;
2799 int do_printing
= 1;
2801 die_offset
= tags
- section_begin
;
2803 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
2806 /* A null DIE marks the end of a list of siblings or it may also be
2807 a section padding. */
2808 if (abbrev_number
== 0)
2810 /* Check if it can be a section padding for the last CU. */
2811 if (level
== 0 && start
== end
)
2815 for (chk
= tags
; chk
< start
; chk
++)
2822 if (!do_loc
&& die_offset
>= dwarf_start_die
2823 && (dwarf_cutoff_level
== -1
2824 || level
< dwarf_cutoff_level
))
2825 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2831 static unsigned num_bogus_warns
= 0;
2833 if (num_bogus_warns
< 3)
2835 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2836 die_offset
, section
->name
);
2838 if (num_bogus_warns
== 3)
2839 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2842 if (dwarf_start_die
!= 0 && level
< saved_level
)
2849 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2853 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2854 saved_level
= level
;
2855 do_printing
= (dwarf_cutoff_level
== -1
2856 || level
< dwarf_cutoff_level
);
2858 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2859 level
, die_offset
, abbrev_number
);
2860 else if (dwarf_cutoff_level
== -1
2861 || last_level
< dwarf_cutoff_level
)
2862 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2867 /* Scan through the abbreviation list until we reach the
2869 for (entry
= first_abbrev
;
2870 entry
&& entry
->entry
!= abbrev_number
;
2871 entry
= entry
->next
)
2876 if (!do_loc
&& do_printing
)
2881 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2882 die_offset
, abbrev_number
);
2886 if (!do_loc
&& do_printing
)
2887 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2892 need_base_address
= 0;
2894 case DW_TAG_compile_unit
:
2895 need_base_address
= 1;
2897 case DW_TAG_entry_point
:
2898 case DW_TAG_subprogram
:
2899 need_base_address
= 0;
2900 /* Assuming that there is no DW_AT_frame_base. */
2901 have_frame_base
= 0;
2905 debug_info
*debug_info_p
=
2906 (debug_information
&& unit
< alloc_num_debug_info_entries
)
2907 ? debug_information
+ unit
: NULL
;
2909 assert (!debug_info_p
2910 || (debug_info_p
->num_loc_offsets
2911 == debug_info_p
->num_loc_views
));
2913 for (attr
= entry
->first_attr
;
2914 attr
&& attr
->attribute
;
2917 if (! do_loc
&& do_printing
)
2918 /* Show the offset from where the tag was extracted. */
2919 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2921 tags
= read_and_display_attr (attr
->attribute
,
2923 attr
->implicit_const
,
2927 compunit
.cu_pointer_size
,
2929 compunit
.cu_version
,
2931 do_loc
|| ! do_printing
,
2936 /* If a locview attribute appears before a location one,
2937 make sure we don't associate it with an earlier
2940 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
2943 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
2944 debug_info_p
->num_loc_views
++;
2945 assert (debug_info_p
->num_loc_views
2946 == debug_info_p
->num_loc_offsets
);
2953 warn(_("DIE has locviews without loclist\n"));
2954 debug_info_p
->num_loc_views
--;
2961 if (entry
->children
)
2966 /* Set num_debug_info_entries here so that it can be used to check if
2967 we need to process .debug_loc and .debug_ranges sections. */
2968 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2969 && num_debug_info_entries
== 0
2972 if (num_units
> alloc_num_debug_info_entries
)
2973 num_debug_info_entries
= alloc_num_debug_info_entries
;
2975 num_debug_info_entries
= num_units
;
2984 /* Locate and scan the .debug_info section in the file and record the pointer
2985 sizes and offsets for the compilation units in it. Usually an executable
2986 will have just one pointer size, but this is not guaranteed, and so we try
2987 not to make any assumptions. Returns zero upon failure, or the number of
2988 compilation units upon success. */
2991 load_debug_info (void * file
)
2993 /* If we have already tried and failed to load the .debug_info
2994 section then do not bother to repeat the task. */
2995 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2998 /* If we already have the information there is nothing else to do. */
2999 if (num_debug_info_entries
> 0)
3000 return num_debug_info_entries
;
3002 /* If this is a DWARF package file, load the CU and TU indexes. */
3003 (void) load_cu_tu_indexes (file
);
3005 if (load_debug_section (info
, file
)
3006 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
3007 return num_debug_info_entries
;
3009 if (load_debug_section (info_dwo
, file
)
3010 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3012 return num_debug_info_entries
;
3014 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3018 /* Read a DWARF .debug_line section header starting at DATA.
3019 Upon success returns an updated DATA pointer and the LINFO
3020 structure and the END_OF_SEQUENCE pointer will be filled in.
3021 Otherwise returns NULL. */
3023 static unsigned char *
3024 read_debug_line_header (struct dwarf_section
* section
,
3025 unsigned char * data
,
3026 unsigned char * end
,
3027 DWARF2_Internal_LineInfo
* linfo
,
3028 unsigned char ** end_of_sequence
)
3030 unsigned char *hdrptr
;
3031 unsigned int initial_length_size
;
3032 unsigned char address_size
, segment_selector_size
;
3034 /* Extract information from the Line Number Program Header.
3035 (section 6.2.4 in the Dwarf3 doc). */
3038 /* Get and check the length of the block. */
3039 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
3041 if (linfo
->li_length
== 0xffffffff)
3043 /* This section is 64-bit DWARF 3. */
3044 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
3045 linfo
->li_offset_size
= 8;
3046 initial_length_size
= 12;
3050 linfo
->li_offset_size
= 4;
3051 initial_length_size
= 4;
3054 if (linfo
->li_length
+ initial_length_size
> section
->size
)
3056 /* If the length field has a relocation against it, then we should
3057 not complain if it is inaccurate (and probably negative). This
3058 happens in object files when the .debug_line section is actually
3059 comprised of several different .debug_line.* sections, (some of
3060 which may be removed by linker garbage collection), and a relocation
3061 is used to compute the correct length once that is done. */
3062 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
3064 linfo
->li_length
= (end
- data
) - initial_length_size
;
3068 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3069 (long) linfo
->li_length
);
3074 /* Get and check the version number. */
3075 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
3077 if (linfo
->li_version
!= 2
3078 && linfo
->li_version
!= 3
3079 && linfo
->li_version
!= 4
3080 && linfo
->li_version
!= 5)
3082 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3083 "is currently supported.\n"));
3087 if (linfo
->li_version
>= 5)
3089 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
3091 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
3092 if (segment_selector_size
!= 0)
3094 warn (_("The %s section contains "
3095 "unsupported segment selector size: %d.\n"),
3096 section
->name
, segment_selector_size
);
3101 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
3102 linfo
->li_offset_size
, end
);
3103 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
3105 if (linfo
->li_version
>= 4)
3107 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
3109 if (linfo
->li_max_ops_per_insn
== 0)
3111 warn (_("Invalid maximum operations per insn.\n"));
3116 linfo
->li_max_ops_per_insn
= 1;
3118 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
3119 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
3120 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
3121 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
3123 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
3124 /* PR 17512: file:002-117414-0.004. */
3125 if (* end_of_sequence
> end
)
3127 warn (_("Line length %s extends beyond end of section\n"),
3128 dwarf_vmatoa ("u", linfo
->li_length
));
3129 * end_of_sequence
= end
;
3136 static unsigned char *
3137 display_formatted_table (unsigned char *data
,
3138 unsigned char *start
, unsigned char *end
,
3139 const DWARF2_Internal_LineInfo
*linfo
,
3140 struct dwarf_section
*section
, const char *what
)
3142 unsigned char *format_start
, format_count
, *format
, formati
;
3143 dwarf_vma data_count
, datai
;
3144 unsigned int bytes_read
, namepass
, last_entry
= 0;
3146 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3147 format_start
= data
;
3148 for (formati
= 0; formati
< format_count
; formati
++)
3150 read_uleb128 (data
, & bytes_read
, end
);
3152 read_uleb128 (data
, & bytes_read
, end
);
3156 warn (_("Corrupt %s format table entry\n"), what
);
3161 data_count
= read_uleb128 (data
, & bytes_read
, end
);
3165 warn (_("Corrupt %s list\n"), what
);
3169 if (data_count
== 0)
3171 printf (_("\n The %s Table is empty.\n"), what
);
3175 printf (_("\n The %s Table (offset 0x%lx):\n"), what
,
3176 (long)(data
- start
));
3178 printf (_(" Entry"));
3179 /* Delay displaying name as the last entry for better screen layout. */
3180 for (namepass
= 0; namepass
< 2; namepass
++)
3182 format
= format_start
;
3183 for (formati
= 0; formati
< format_count
; formati
++)
3185 dwarf_vma content_type
;
3187 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3188 format
+= bytes_read
;
3189 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
3190 switch (content_type
)
3193 printf (_("\tName"));
3195 case DW_LNCT_directory_index
:
3196 printf (_("\tDir"));
3198 case DW_LNCT_timestamp
:
3199 printf (_("\tTime"));
3202 printf (_("\tSize"));
3205 printf (_("\tMD5"));
3208 printf (_("\t(Unknown format content type %s)"),
3209 dwarf_vmatoa ("u", content_type
));
3211 read_uleb128 (format
, & bytes_read
, end
);
3212 format
+= bytes_read
;
3217 for (datai
= 0; datai
< data_count
; datai
++)
3219 unsigned char *datapass
= data
;
3221 printf (" %d", last_entry
++);
3222 /* Delay displaying name as the last entry for better screen layout. */
3223 for (namepass
= 0; namepass
< 2; namepass
++)
3225 format
= format_start
;
3227 for (formati
= 0; formati
< format_count
; formati
++)
3229 dwarf_vma content_type
, form
;
3231 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3232 format
+= bytes_read
;
3233 form
= read_uleb128 (format
, & bytes_read
, end
);
3234 format
+= bytes_read
;
3235 data
= read_and_display_attr_value (0, form
, 0, data
, end
, 0, 0,
3236 linfo
->li_offset_size
,
3237 linfo
->li_version
, NULL
,
3238 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3239 section
, NULL
, '\t');
3244 warn (_("Corrupt %s entries list\n"), what
);
3253 display_debug_lines_raw (struct dwarf_section
*section
,
3254 unsigned char *data
,
3255 unsigned char *end
, void *file
)
3257 unsigned char *start
= section
->start
;
3258 int verbose_view
= 0;
3260 printf (_("Raw dump of debug contents of section %s:\n\n"),
3265 static DWARF2_Internal_LineInfo saved_linfo
;
3266 DWARF2_Internal_LineInfo linfo
;
3267 unsigned char *standard_opcodes
;
3268 unsigned char *end_of_sequence
;
3271 if (const_strneq (section
->name
, ".debug_line.")
3272 /* Note: the following does not apply to .debug_line.dwo sections.
3273 These are full debug_line sections. */
3274 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3276 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3277 section containing just the Line Number Statements. They are
3278 created by the assembler and intended to be used alongside gcc's
3279 -ffunction-sections command line option. When the linker's
3280 garbage collection decides to discard a .text.<foo> section it
3281 can then also discard the line number information in .debug_line.<foo>.
3283 Since the section is a fragment it does not have the details
3284 needed to fill out a LineInfo structure, so instead we use the
3285 details from the last full debug_line section that we processed. */
3286 end_of_sequence
= end
;
3287 standard_opcodes
= NULL
;
3288 linfo
= saved_linfo
;
3289 /* PR 17531: file: 0522b371. */
3290 if (linfo
.li_line_range
== 0)
3292 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3295 reset_state_machine (linfo
.li_default_is_stmt
);
3299 unsigned char * hdrptr
;
3301 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3302 & end_of_sequence
)) == NULL
)
3305 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
3306 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
3307 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
3308 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
3309 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
3310 if (linfo
.li_version
>= 4)
3311 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
3312 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
3313 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
3314 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
3315 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
3317 /* PR 17512: file: 1665-6428-0.004. */
3318 if (linfo
.li_line_range
== 0)
3320 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3321 linfo
.li_line_range
= 1;
3324 reset_state_machine (linfo
.li_default_is_stmt
);
3326 /* Display the contents of the Opcodes table. */
3327 standard_opcodes
= hdrptr
;
3329 /* PR 17512: file: 002-417945-0.004. */
3330 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
3332 warn (_("Line Base extends beyond end of section\n"));
3336 printf (_("\n Opcodes:\n"));
3338 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
3339 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
3341 /* Display the contents of the Directory table. */
3342 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3344 if (linfo
.li_version
>= 5)
3346 load_debug_section (line_str
, file
);
3348 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3350 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3356 printf (_("\n The Directory Table is empty.\n"));
3359 unsigned int last_dir_entry
= 0;
3361 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3362 (long)(data
- start
));
3364 while (data
< end
&& *data
!= 0)
3366 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
3368 data
+= strnlen ((char *) data
, end
- data
) + 1;
3371 /* PR 17512: file: 002-132094-0.004. */
3372 if (data
>= end
- 1)
3376 /* Skip the NUL at the end of the table. */
3379 /* Display the contents of the File Name table. */
3381 printf (_("\n The File Name Table is empty.\n"));
3384 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3385 (long)(data
- start
));
3386 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3388 while (data
< end
&& *data
!= 0)
3390 unsigned char *name
;
3391 unsigned int bytes_read
;
3393 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
3395 data
+= strnlen ((char *) data
, end
- data
) + 1;
3398 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3401 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3404 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3406 printf ("%.*s\n", (int)(end
- name
), name
);
3410 warn (_("Corrupt file name table entry\n"));
3416 /* Skip the NUL at the end of the table. */
3421 saved_linfo
= linfo
;
3424 /* Now display the statements. */
3425 if (data
>= end_of_sequence
)
3426 printf (_(" No Line Number Statements.\n"));
3429 printf (_(" Line Number Statements:\n"));
3431 while (data
< end_of_sequence
)
3433 unsigned char op_code
;
3434 dwarf_signed_vma adv
;
3436 unsigned int bytes_read
;
3438 printf (" [0x%08lx]", (long)(data
- start
));
3442 if (op_code
>= linfo
.li_opcode_base
)
3444 op_code
-= linfo
.li_opcode_base
;
3445 uladv
= (op_code
/ linfo
.li_line_range
);
3446 if (linfo
.li_max_ops_per_insn
== 1)
3448 uladv
*= linfo
.li_min_insn_length
;
3449 state_machine_regs
.address
+= uladv
;
3451 state_machine_regs
.view
= 0;
3452 printf (_(" Special opcode %d: "
3453 "advance Address by %s to 0x%s%s"),
3454 op_code
, dwarf_vmatoa ("u", uladv
),
3455 dwarf_vmatoa ("x", state_machine_regs
.address
),
3456 verbose_view
&& uladv
3457 ? _(" (reset view)") : "");
3462 = ((state_machine_regs
.op_index
+ uladv
)
3463 / linfo
.li_max_ops_per_insn
)
3464 * linfo
.li_min_insn_length
;
3466 state_machine_regs
.address
+= addrdelta
;
3467 state_machine_regs
.op_index
3468 = (state_machine_regs
.op_index
+ uladv
)
3469 % linfo
.li_max_ops_per_insn
;
3471 state_machine_regs
.view
= 0;
3472 printf (_(" Special opcode %d: "
3473 "advance Address by %s to 0x%s[%d]%s"),
3474 op_code
, dwarf_vmatoa ("u", uladv
),
3475 dwarf_vmatoa ("x", state_machine_regs
.address
),
3476 state_machine_regs
.op_index
,
3477 verbose_view
&& addrdelta
3478 ? _(" (reset view)") : "");
3480 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3481 state_machine_regs
.line
+= adv
;
3482 printf (_(" and Line by %s to %d"),
3483 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
3484 if (verbose_view
|| state_machine_regs
.view
)
3485 printf (_(" (view %u)\n"), state_machine_regs
.view
);
3488 state_machine_regs
.view
++;
3490 else switch (op_code
)
3492 case DW_LNS_extended_op
:
3493 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
3497 printf (_(" Copy"));
3498 if (verbose_view
|| state_machine_regs
.view
)
3499 printf (_(" (view %u)\n"), state_machine_regs
.view
);
3502 state_machine_regs
.view
++;
3505 case DW_LNS_advance_pc
:
3506 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3508 if (linfo
.li_max_ops_per_insn
== 1)
3510 uladv
*= linfo
.li_min_insn_length
;
3511 state_machine_regs
.address
+= uladv
;
3513 state_machine_regs
.view
= 0;
3514 printf (_(" Advance PC by %s to 0x%s%s\n"),
3515 dwarf_vmatoa ("u", uladv
),
3516 dwarf_vmatoa ("x", state_machine_regs
.address
),
3517 verbose_view
&& uladv
3518 ? _(" (reset view)") : "");
3523 = ((state_machine_regs
.op_index
+ uladv
)
3524 / linfo
.li_max_ops_per_insn
)
3525 * linfo
.li_min_insn_length
;
3526 state_machine_regs
.address
3528 state_machine_regs
.op_index
3529 = (state_machine_regs
.op_index
+ uladv
)
3530 % linfo
.li_max_ops_per_insn
;
3532 state_machine_regs
.view
= 0;
3533 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
3534 dwarf_vmatoa ("u", uladv
),
3535 dwarf_vmatoa ("x", state_machine_regs
.address
),
3536 state_machine_regs
.op_index
,
3537 verbose_view
&& addrdelta
3538 ? _(" (reset view)") : "");
3542 case DW_LNS_advance_line
:
3543 adv
= read_sleb128 (data
, & bytes_read
, end
);
3545 state_machine_regs
.line
+= adv
;
3546 printf (_(" Advance Line by %s to %d\n"),
3547 dwarf_vmatoa ("d", adv
),
3548 state_machine_regs
.line
);
3551 case DW_LNS_set_file
:
3552 adv
= read_uleb128 (data
, & bytes_read
, end
);
3554 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3555 dwarf_vmatoa ("d", adv
));
3556 state_machine_regs
.file
= adv
;
3559 case DW_LNS_set_column
:
3560 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3562 printf (_(" Set column to %s\n"),
3563 dwarf_vmatoa ("u", uladv
));
3564 state_machine_regs
.column
= uladv
;
3567 case DW_LNS_negate_stmt
:
3568 adv
= state_machine_regs
.is_stmt
;
3570 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
3571 state_machine_regs
.is_stmt
= adv
;
3574 case DW_LNS_set_basic_block
:
3575 printf (_(" Set basic block\n"));
3576 state_machine_regs
.basic_block
= 1;
3579 case DW_LNS_const_add_pc
:
3580 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3581 if (linfo
.li_max_ops_per_insn
)
3583 uladv
*= linfo
.li_min_insn_length
;
3584 state_machine_regs
.address
+= uladv
;
3586 state_machine_regs
.view
= 0;
3587 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
3588 dwarf_vmatoa ("u", uladv
),
3589 dwarf_vmatoa ("x", state_machine_regs
.address
),
3590 verbose_view
&& uladv
3591 ? _(" (reset view)") : "");
3596 = ((state_machine_regs
.op_index
+ uladv
)
3597 / linfo
.li_max_ops_per_insn
)
3598 * linfo
.li_min_insn_length
;
3599 state_machine_regs
.address
3601 state_machine_regs
.op_index
3602 = (state_machine_regs
.op_index
+ uladv
)
3603 % linfo
.li_max_ops_per_insn
;
3605 state_machine_regs
.view
= 0;
3606 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
3607 dwarf_vmatoa ("u", uladv
),
3608 dwarf_vmatoa ("x", state_machine_regs
.address
),
3609 state_machine_regs
.op_index
,
3610 verbose_view
&& addrdelta
3611 ? _(" (reset view)") : "");
3615 case DW_LNS_fixed_advance_pc
:
3616 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3617 state_machine_regs
.address
+= uladv
;
3618 state_machine_regs
.op_index
= 0;
3619 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3620 dwarf_vmatoa ("u", uladv
),
3621 dwarf_vmatoa ("x", state_machine_regs
.address
));
3622 /* Do NOT reset view. */
3625 case DW_LNS_set_prologue_end
:
3626 printf (_(" Set prologue_end to true\n"));
3629 case DW_LNS_set_epilogue_begin
:
3630 printf (_(" Set epilogue_begin to true\n"));
3633 case DW_LNS_set_isa
:
3634 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3636 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
3640 printf (_(" Unknown opcode %d with operands: "), op_code
);
3642 if (standard_opcodes
!= NULL
)
3643 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3645 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3647 i
== 1 ? "" : ", ");
3663 unsigned char *name
;
3664 unsigned int directory_index
;
3665 unsigned int modification_date
;
3666 unsigned int length
;
3669 /* Output a decoded representation of the .debug_line section. */
3672 display_debug_lines_decoded (struct dwarf_section
*section
,
3673 unsigned char *data
,
3674 unsigned char *end
, void *fileptr
)
3676 static DWARF2_Internal_LineInfo saved_linfo
;
3678 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3683 /* This loop amounts to one iteration per compilation unit. */
3684 DWARF2_Internal_LineInfo linfo
;
3685 unsigned char *standard_opcodes
;
3686 unsigned char *end_of_sequence
;
3688 File_Entry
*file_table
= NULL
;
3689 unsigned int n_files
= 0;
3690 unsigned char **directory_table
= NULL
;
3691 dwarf_vma n_directories
= 0;
3693 if (const_strneq (section
->name
, ".debug_line.")
3694 /* Note: the following does not apply to .debug_line.dwo sections.
3695 These are full debug_line sections. */
3696 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3698 /* See comment in display_debug_lines_raw(). */
3699 end_of_sequence
= end
;
3700 standard_opcodes
= NULL
;
3701 linfo
= saved_linfo
;
3702 /* PR 17531: file: 0522b371. */
3703 if (linfo
.li_line_range
== 0)
3705 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3708 reset_state_machine (linfo
.li_default_is_stmt
);
3712 unsigned char *hdrptr
;
3714 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3715 & end_of_sequence
)) == NULL
)
3718 /* PR 17531: file: 0522b371. */
3719 if (linfo
.li_line_range
== 0)
3721 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3722 linfo
.li_line_range
= 1;
3724 reset_state_machine (linfo
.li_default_is_stmt
);
3726 /* Save a pointer to the contents of the Opcodes table. */
3727 standard_opcodes
= hdrptr
;
3729 /* Traverse the Directory table just to count entries. */
3730 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3734 warn (_("opcode base of %d extends beyond end of section\n"),
3735 linfo
.li_opcode_base
);
3739 if (linfo
.li_version
>= 5)
3741 unsigned char *format_start
, format_count
, *format
;
3742 dwarf_vma formati
, entryi
;
3743 unsigned int bytes_read
;
3745 load_debug_section (line_str
, fileptr
);
3747 /* Skip directories format. */
3748 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3749 format_start
= data
;
3750 for (formati
= 0; formati
< format_count
; formati
++)
3752 read_uleb128 (data
, & bytes_read
, end
);
3754 read_uleb128 (data
, & bytes_read
, end
);
3758 n_directories
= read_uleb128 (data
, & bytes_read
, end
);
3762 warn (_("Corrupt directories list\n"));
3766 directory_table
= (unsigned char **)
3767 xmalloc (n_directories
* sizeof (unsigned char *));
3769 for (entryi
= 0; entryi
< n_directories
; entryi
++)
3771 unsigned char **pathp
= &directory_table
[entryi
];
3773 format
= format_start
;
3774 for (formati
= 0; formati
< format_count
; formati
++)
3776 dwarf_vma content_type
, form
;
3779 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3780 format
+= bytes_read
;
3781 form
= read_uleb128 (format
, & bytes_read
, end
);
3782 format
+= bytes_read
;
3785 warn (_("Corrupt directories list\n"));
3788 switch (content_type
)
3793 case DW_FORM_string
:
3796 case DW_FORM_line_strp
:
3797 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
3799 /* Remove const by the cast. */
3800 *pathp
= (unsigned char *)
3801 fetch_indirect_line_string (uvalue
);
3806 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
3808 linfo
.li_offset_size
,
3815 warn (_("Corrupt directories list\n"));
3820 /* Skip files format. */
3821 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3822 format_start
= data
;
3823 for (formati
= 0; formati
< format_count
; formati
++)
3825 read_uleb128 (data
, & bytes_read
, end
);
3827 read_uleb128 (data
, & bytes_read
, end
);
3831 n_files
= read_uleb128 (data
, & bytes_read
, end
);
3835 warn (_("Corrupt file name list\n"));
3839 file_table
= (File_Entry
*) xcalloc (1, n_files
3840 * sizeof (File_Entry
));
3842 for (entryi
= 0; entryi
< n_files
; entryi
++)
3844 File_Entry
*file
= &file_table
[entryi
];
3846 format
= format_start
;
3847 for (formati
= 0; formati
< format_count
; formati
++)
3849 dwarf_vma content_type
, form
;
3852 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3853 format
+= bytes_read
;
3854 form
= read_uleb128 (format
, & bytes_read
, end
);
3855 format
+= bytes_read
;
3858 warn (_("Corrupt file name list\n"));
3861 switch (content_type
)
3866 case DW_FORM_string
:
3869 case DW_FORM_line_strp
:
3870 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
3872 /* Remove const by the cast. */
3873 file
->name
= (unsigned char *)
3874 fetch_indirect_line_string (uvalue
);
3878 case DW_LNCT_directory_index
:
3882 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
3886 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
3890 file
->directory_index
= read_uleb128 (data
, NULL
,
3896 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
3898 linfo
.li_offset_size
,
3905 warn (_("Corrupt file name list\n"));
3914 unsigned char *ptr_directory_table
= data
;
3916 while (data
< end
&& *data
!= 0)
3918 data
+= strnlen ((char *) data
, end
- data
) + 1;
3925 warn (_("directory table ends unexpectedly\n"));
3930 /* Go through the directory table again to save the directories. */
3931 directory_table
= (unsigned char **)
3932 xmalloc (n_directories
* sizeof (unsigned char *));
3935 while (*ptr_directory_table
!= 0)
3937 directory_table
[i
] = ptr_directory_table
;
3938 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
3939 ptr_directory_table
- end
) + 1;
3943 /* Skip the NUL at the end of the table. */
3946 /* Traverse the File Name table just to count the entries. */
3947 if (data
< end
&& *data
!= 0)
3949 unsigned char *ptr_file_name_table
= data
;
3951 while (data
< end
&& *data
!= 0)
3953 unsigned int bytes_read
;
3955 /* Skip Name, directory index, last modification time and length
3957 data
+= strnlen ((char *) data
, end
- data
) + 1;
3958 read_uleb128 (data
, & bytes_read
, end
);
3960 read_uleb128 (data
, & bytes_read
, end
);
3962 read_uleb128 (data
, & bytes_read
, end
);
3970 warn (_("file table ends unexpectedly\n"));
3975 /* Go through the file table again to save the strings. */
3976 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
3979 while (*ptr_file_name_table
!= 0)
3981 unsigned int bytes_read
;
3983 file_table
[i
].name
= ptr_file_name_table
;
3984 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
3985 end
- ptr_file_name_table
) + 1;
3987 /* We are not interested in directory, time or size. */
3988 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
3990 ptr_file_name_table
+= bytes_read
;
3991 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
3993 ptr_file_name_table
+= bytes_read
;
3994 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
3995 ptr_file_name_table
+= bytes_read
;
4001 /* Skip the NUL at the end of the table. */
4005 /* Print the Compilation Unit's name and a header. */
4006 if (file_table
== NULL
)
4008 else if (directory_table
== NULL
)
4009 printf (_("CU: %s:\n"), file_table
[0].name
);
4012 unsigned int ix
= file_table
[0].directory_index
;
4013 const char *directory
;
4018 else if (n_directories
== 0)
4019 directory
= _("<unknown>");
4020 else if (ix
> n_directories
)
4022 warn (_("directory index %u > number of directories %s\n"),
4023 ix
, dwarf_vmatoa ("u", n_directories
));
4024 directory
= _("<corrupt>");
4027 directory
= (char *) directory_table
[ix
- 1];
4029 if (do_wide
|| strlen (directory
) < 76)
4030 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
4032 printf ("%s:\n", file_table
[0].name
);
4035 printf (_("File name Line number Starting address View\n"));
4036 saved_linfo
= linfo
;
4039 /* This loop iterates through the Dwarf Line Number Program. */
4040 while (data
< end_of_sequence
)
4042 unsigned char op_code
;
4045 unsigned long int uladv
;
4046 unsigned int bytes_read
;
4047 int is_special_opcode
= 0;
4052 if (op_code
>= linfo
.li_opcode_base
)
4054 op_code
-= linfo
.li_opcode_base
;
4055 uladv
= (op_code
/ linfo
.li_line_range
);
4056 if (linfo
.li_max_ops_per_insn
== 1)
4058 uladv
*= linfo
.li_min_insn_length
;
4059 state_machine_regs
.address
+= uladv
;
4061 state_machine_regs
.view
= 0;
4066 = ((state_machine_regs
.op_index
+ uladv
)
4067 / linfo
.li_max_ops_per_insn
)
4068 * linfo
.li_min_insn_length
;
4069 state_machine_regs
.address
4071 state_machine_regs
.op_index
4072 = (state_machine_regs
.op_index
+ uladv
)
4073 % linfo
.li_max_ops_per_insn
;
4075 state_machine_regs
.view
= 0;
4078 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4079 state_machine_regs
.line
+= adv
;
4080 is_special_opcode
= 1;
4081 /* Increment view after printing this row. */
4083 else switch (op_code
)
4085 case DW_LNS_extended_op
:
4087 unsigned int ext_op_code_len
;
4088 unsigned char ext_op_code
;
4089 unsigned char *op_code_data
= data
;
4091 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
4093 op_code_data
+= bytes_read
;
4095 if (ext_op_code_len
== 0)
4097 warn (_("Badly formed extended line op encountered!\n"));
4100 ext_op_code_len
+= bytes_read
;
4101 ext_op_code
= *op_code_data
++;
4105 switch (ext_op_code
)
4107 case DW_LNE_end_sequence
:
4108 /* Reset stuff after printing this row. */
4110 case DW_LNE_set_address
:
4111 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
4113 ext_op_code_len
- bytes_read
- 1,
4115 state_machine_regs
.op_index
= 0;
4116 state_machine_regs
.view
= 0;
4118 case DW_LNE_define_file
:
4120 file_table
= (File_Entry
*) xrealloc
4121 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
4123 ++state_machine_regs
.last_file_entry
;
4124 /* Source file name. */
4125 file_table
[n_files
].name
= op_code_data
;
4126 op_code_data
+= strlen ((char *) op_code_data
) + 1;
4127 /* Directory index. */
4128 file_table
[n_files
].directory_index
=
4129 read_uleb128 (op_code_data
, & bytes_read
,
4131 op_code_data
+= bytes_read
;
4132 /* Last modification time. */
4133 file_table
[n_files
].modification_date
=
4134 read_uleb128 (op_code_data
, & bytes_read
,
4136 op_code_data
+= bytes_read
;
4138 file_table
[n_files
].length
=
4139 read_uleb128 (op_code_data
, & bytes_read
,
4145 case DW_LNE_set_discriminator
:
4146 case DW_LNE_HP_set_sequence
:
4147 /* Simply ignored. */
4151 printf (_("UNKNOWN (%u): length %d\n"),
4152 ext_op_code
, ext_op_code_len
- bytes_read
);
4155 data
+= ext_op_code_len
;
4159 /* Increment view after printing this row. */
4162 case DW_LNS_advance_pc
:
4163 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4165 if (linfo
.li_max_ops_per_insn
== 1)
4167 uladv
*= linfo
.li_min_insn_length
;
4168 state_machine_regs
.address
+= uladv
;
4170 state_machine_regs
.view
= 0;
4175 = ((state_machine_regs
.op_index
+ uladv
)
4176 / linfo
.li_max_ops_per_insn
)
4177 * linfo
.li_min_insn_length
;
4178 state_machine_regs
.address
4180 state_machine_regs
.op_index
4181 = (state_machine_regs
.op_index
+ uladv
)
4182 % linfo
.li_max_ops_per_insn
;
4184 state_machine_regs
.view
= 0;
4188 case DW_LNS_advance_line
:
4189 adv
= read_sleb128 (data
, & bytes_read
, end
);
4191 state_machine_regs
.line
+= adv
;
4194 case DW_LNS_set_file
:
4195 adv
= read_uleb128 (data
, & bytes_read
, end
);
4197 state_machine_regs
.file
= adv
;
4200 unsigned file
= state_machine_regs
.file
- 1;
4203 if (file_table
== NULL
|| n_files
== 0)
4204 printf (_("\n [Use file table entry %d]\n"), file
);
4206 else if (file
>= n_files
)
4208 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
4209 printf (_("\n <over large file table index %u>"), file
);
4211 else if ((dir
= file_table
[file
].directory_index
) == 0)
4212 /* If directory index is 0, that means current directory. */
4213 printf ("\n./%s:[++]\n", file_table
[file
].name
);
4214 else if (directory_table
== NULL
|| n_directories
== 0)
4215 printf (_("\n [Use file %s in directory table entry %d]\n"),
4216 file_table
[file
].name
, dir
);
4218 else if (dir
> n_directories
)
4220 warn (_("directory index %u > number of directories %s\n"),
4221 dir
, dwarf_vmatoa ("u", n_directories
));
4222 printf (_("\n <over large directory table entry %u>\n"), dir
);
4225 printf ("\n%s/%s:\n",
4226 /* The directory index starts counting at 1. */
4227 directory_table
[dir
- 1], file_table
[file
].name
);
4231 case DW_LNS_set_column
:
4232 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4234 state_machine_regs
.column
= uladv
;
4237 case DW_LNS_negate_stmt
:
4238 adv
= state_machine_regs
.is_stmt
;
4240 state_machine_regs
.is_stmt
= adv
;
4243 case DW_LNS_set_basic_block
:
4244 state_machine_regs
.basic_block
= 1;
4247 case DW_LNS_const_add_pc
:
4248 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4249 if (linfo
.li_max_ops_per_insn
== 1)
4251 uladv
*= linfo
.li_min_insn_length
;
4252 state_machine_regs
.address
+= uladv
;
4254 state_machine_regs
.view
= 0;
4259 = ((state_machine_regs
.op_index
+ uladv
)
4260 / linfo
.li_max_ops_per_insn
)
4261 * linfo
.li_min_insn_length
;
4262 state_machine_regs
.address
4264 state_machine_regs
.op_index
4265 = (state_machine_regs
.op_index
+ uladv
)
4266 % linfo
.li_max_ops_per_insn
;
4268 state_machine_regs
.view
= 0;
4272 case DW_LNS_fixed_advance_pc
:
4273 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4274 state_machine_regs
.address
+= uladv
;
4275 state_machine_regs
.op_index
= 0;
4276 /* Do NOT reset view. */
4279 case DW_LNS_set_prologue_end
:
4282 case DW_LNS_set_epilogue_begin
:
4285 case DW_LNS_set_isa
:
4286 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4288 printf (_(" Set ISA to %lu\n"), uladv
);
4292 printf (_(" Unknown opcode %d with operands: "), op_code
);
4294 if (standard_opcodes
!= NULL
)
4295 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4297 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
4299 i
== 1 ? "" : ", ");
4306 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4307 to the DWARF address/line matrix. */
4308 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
4309 || (xop
== DW_LNS_copy
))
4311 const unsigned int MAX_FILENAME_LENGTH
= 35;
4313 char *newFileName
= NULL
;
4314 size_t fileNameLength
;
4318 unsigned indx
= state_machine_regs
.file
- 1;
4320 if (indx
>= n_files
)
4322 warn (_("corrupt file index %u encountered\n"), indx
);
4323 fileName
= _("<corrupt>");
4326 fileName
= (char *) file_table
[indx
].name
;
4329 fileName
= _("<unknown>");
4331 fileNameLength
= strlen (fileName
);
4333 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
4335 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
4336 /* Truncate file name */
4337 strncpy (newFileName
,
4338 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
4339 MAX_FILENAME_LENGTH
+ 1);
4343 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
4344 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
4347 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
4349 if (linfo
.li_max_ops_per_insn
== 1)
4350 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
4351 newFileName
, state_machine_regs
.line
,
4352 state_machine_regs
.address
);
4354 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4355 newFileName
, state_machine_regs
.line
,
4356 state_machine_regs
.address
,
4357 state_machine_regs
.op_index
);
4361 if (linfo
.li_max_ops_per_insn
== 1)
4362 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
4363 newFileName
, state_machine_regs
.line
,
4364 state_machine_regs
.address
);
4366 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4367 newFileName
, state_machine_regs
.line
,
4368 state_machine_regs
.address
,
4369 state_machine_regs
.op_index
);
4372 if (state_machine_regs
.view
)
4373 printf (" %6u\n", state_machine_regs
.view
);
4376 state_machine_regs
.view
++;
4378 if (xop
== -DW_LNE_end_sequence
)
4380 reset_state_machine (linfo
.li_default_is_stmt
);
4395 if (directory_table
)
4397 free (directory_table
);
4398 directory_table
= NULL
;
4409 display_debug_lines (struct dwarf_section
*section
, void *file
)
4411 unsigned char *data
= section
->start
;
4412 unsigned char *end
= data
+ section
->size
;
4414 int retValDecoded
= 1;
4416 if (do_debug_lines
== 0)
4417 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
4419 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
4420 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
4422 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
4423 retValDecoded
= display_debug_lines_decoded (section
, data
, end
, file
);
4425 if (!retValRaw
|| !retValDecoded
)
4432 find_debug_info_for_offset (unsigned long offset
)
4436 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4439 for (i
= 0; i
< num_debug_info_entries
; i
++)
4440 if (debug_information
[i
].cu_offset
== offset
)
4441 return debug_information
+ i
;
4447 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
4449 /* See gdb/gdb-index.h. */
4450 static const char * const kinds
[] =
4462 return _ (kinds
[kind
]);
4466 display_debug_pubnames_worker (struct dwarf_section
*section
,
4467 void *file ATTRIBUTE_UNUSED
,
4470 DWARF2_Internal_PubNames names
;
4471 unsigned char *start
= section
->start
;
4472 unsigned char *end
= start
+ section
->size
;
4474 /* It does not matter if this load fails,
4475 we test for that later on. */
4476 load_debug_info (file
);
4478 printf (_("Contents of the %s section:\n\n"), section
->name
);
4482 unsigned char *data
;
4485 unsigned int offset_size
, initial_length_size
;
4489 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 4, end
);
4490 if (names
.pn_length
== 0xffffffff)
4492 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 8, end
);
4494 initial_length_size
= 12;
4499 initial_length_size
= 4;
4502 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
4503 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
4505 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4506 && num_debug_info_entries
> 0
4507 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
4508 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4509 (unsigned long) names
.pn_offset
, section
->name
);
4511 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
4513 adr
= start
+ names
.pn_length
+ initial_length_size
;
4514 /* PR 17531: file: 7615b6b2. */
4515 if ((dwarf_signed_vma
) names
.pn_length
< 0
4516 /* PR 17531: file: a5dbeaa7. */
4519 warn (_("Negative length for public name: 0x%lx\n"), (long) names
.pn_length
);
4525 printf (_(" Length: %ld\n"),
4526 (long) names
.pn_length
);
4527 printf (_(" Version: %d\n"),
4529 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4530 (unsigned long) names
.pn_offset
);
4531 printf (_(" Size of area in .debug_info section: %ld\n"),
4532 (long) names
.pn_size
);
4534 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
4536 static int warned
= 0;
4540 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4548 printf (_("\n Offset Kind Name\n"));
4550 printf (_("\n Offset\tName\n"));
4554 bfd_size_type maxprint
;
4556 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
4560 data
+= offset_size
;
4563 maxprint
= (end
- data
) - 1;
4567 unsigned int kind_data
;
4568 gdb_index_symbol_kind kind
;
4569 const char *kind_name
;
4572 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
4575 /* GCC computes the kind as the upper byte in the CU index
4576 word, and then right shifts it by the CU index size.
4577 Left shift KIND to where the gdb-index.h accessor macros
4579 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
4580 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
4581 kind_name
= get_gdb_index_symbol_kind_name (kind
);
4582 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
4583 printf (" %-6lx %s,%-10s %.*s\n",
4584 (unsigned long) offset
, is_static
? _("s") : _("g"),
4585 kind_name
, (int) maxprint
, data
);
4588 printf (" %-6lx\t%.*s\n",
4589 (unsigned long) offset
, (int) maxprint
, data
);
4591 data
+= strnlen ((char *) data
, maxprint
) + 1;
4596 while (offset
!= 0);
4604 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
4606 return display_debug_pubnames_worker (section
, file
, 0);
4610 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
4612 return display_debug_pubnames_worker (section
, file
, 1);
4616 display_debug_macinfo (struct dwarf_section
*section
,
4617 void *file ATTRIBUTE_UNUSED
)
4619 unsigned char *start
= section
->start
;
4620 unsigned char *end
= start
+ section
->size
;
4621 unsigned char *curr
= start
;
4622 unsigned int bytes_read
;
4623 enum dwarf_macinfo_record_type op
;
4625 printf (_("Contents of the %s section:\n\n"), section
->name
);
4629 unsigned int lineno
;
4630 const unsigned char *string
;
4632 op
= (enum dwarf_macinfo_record_type
) *curr
;
4637 case DW_MACINFO_start_file
:
4639 unsigned int filenum
;
4641 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4643 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
4646 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4651 case DW_MACINFO_end_file
:
4652 printf (_(" DW_MACINFO_end_file\n"));
4655 case DW_MACINFO_define
:
4656 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4659 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4660 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4664 case DW_MACINFO_undef
:
4665 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4668 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4669 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4673 case DW_MACINFO_vendor_ext
:
4675 unsigned int constant
;
4677 constant
= read_uleb128 (curr
, & bytes_read
, end
);
4680 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4681 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4691 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4692 filename and dirname corresponding to file name table entry with index
4693 FILEIDX. Return NULL on failure. */
4695 static unsigned char *
4696 get_line_filename_and_dirname (dwarf_vma line_offset
,
4698 unsigned char **dir_name
)
4700 struct dwarf_section
*section
= &debug_displays
[line
].section
;
4701 unsigned char *hdrptr
, *dirtable
, *file_name
;
4702 unsigned int offset_size
, initial_length_size
;
4703 unsigned int version
, opcode_base
, bytes_read
;
4704 dwarf_vma length
, diridx
;
4705 const unsigned char * end
;
4708 if (section
->start
== NULL
4709 || line_offset
>= section
->size
4713 hdrptr
= section
->start
+ line_offset
;
4714 end
= section
->start
+ section
->size
;
4716 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
4717 if (length
== 0xffffffff)
4719 /* This section is 64-bit DWARF 3. */
4720 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
4722 initial_length_size
= 12;
4727 initial_length_size
= 4;
4729 if (length
+ initial_length_size
> section
->size
)
4732 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
4733 if (version
!= 2 && version
!= 3 && version
!= 4)
4735 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
4737 hdrptr
++; /* Skip max_ops_per_insn. */
4738 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
4740 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
4741 if (opcode_base
== 0)
4744 hdrptr
+= opcode_base
- 1;
4746 /* Skip over dirname table. */
4747 while (*hdrptr
!= '\0')
4748 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4749 hdrptr
++; /* Skip the NUL at the end of the table. */
4750 /* Now skip over preceding filename table entries. */
4751 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
4753 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4754 read_uleb128 (hdrptr
, &bytes_read
, end
);
4755 hdrptr
+= bytes_read
;
4756 read_uleb128 (hdrptr
, &bytes_read
, end
);
4757 hdrptr
+= bytes_read
;
4758 read_uleb128 (hdrptr
, &bytes_read
, end
);
4759 hdrptr
+= bytes_read
;
4761 if (hdrptr
== end
|| *hdrptr
== '\0')
4764 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4765 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
4768 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
4769 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
4770 if (*dirtable
== '\0')
4772 *dir_name
= dirtable
;
4777 display_debug_macro (struct dwarf_section
*section
,
4780 unsigned char *start
= section
->start
;
4781 unsigned char *end
= start
+ section
->size
;
4782 unsigned char *curr
= start
;
4783 unsigned char *extended_op_buf
[256];
4784 unsigned int bytes_read
;
4786 load_debug_section (str
, file
);
4787 load_debug_section (line
, file
);
4789 printf (_("Contents of the %s section:\n\n"), section
->name
);
4793 unsigned int lineno
, version
, flags
;
4794 unsigned int offset_size
= 4;
4795 const unsigned char *string
;
4796 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
4797 unsigned char **extended_ops
= NULL
;
4799 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
4800 if (version
!= 4 && version
!= 5)
4802 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4807 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
4810 printf (_(" Offset: 0x%lx\n"),
4811 (unsigned long) sec_offset
);
4812 printf (_(" Version: %d\n"), version
);
4813 printf (_(" Offset size: %d\n"), offset_size
);
4816 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
4817 printf (_(" Offset into .debug_line: 0x%lx\n"),
4818 (unsigned long) line_offset
);
4822 unsigned int i
, count
, op
;
4825 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
4827 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
4828 extended_ops
= extended_op_buf
;
4831 printf (_(" Extension opcode arguments:\n"));
4832 for (i
= 0; i
< count
; i
++)
4834 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4835 extended_ops
[op
] = curr
;
4836 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
4839 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
4842 printf (_(" DW_MACRO_%02x arguments: "), op
);
4843 for (n
= 0; n
< nargs
; n
++)
4847 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
4848 printf ("%s%s", get_FORM_name (form
),
4849 n
== nargs
- 1 ? "\n" : ", ");
4859 case DW_FORM_block1
:
4860 case DW_FORM_block2
:
4861 case DW_FORM_block4
:
4863 case DW_FORM_string
:
4865 case DW_FORM_sec_offset
:
4868 error (_("Invalid extension opcode form %s\n"),
4869 get_FORM_name (form
));
4885 error (_(".debug_macro section not zero terminated\n"));
4889 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4895 case DW_MACRO_start_file
:
4897 unsigned int filenum
;
4898 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
4900 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4902 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
4905 if ((flags
& 2) == 0)
4906 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4909 = get_line_filename_and_dirname (line_offset
, filenum
,
4911 if (file_name
== NULL
)
4912 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4915 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4917 dir_name
!= NULL
? (const char *) dir_name
: "",
4918 dir_name
!= NULL
? "/" : "", file_name
);
4922 case DW_MACRO_end_file
:
4923 printf (_(" DW_MACRO_end_file\n"));
4926 case DW_MACRO_define
:
4927 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4930 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4931 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
4935 case DW_MACRO_undef
:
4936 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4939 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4940 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
4944 case DW_MACRO_define_strp
:
4945 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4947 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4948 string
= fetch_indirect_string (offset
);
4949 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
4953 case DW_MACRO_undef_strp
:
4954 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4956 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4957 string
= fetch_indirect_string (offset
);
4958 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
4962 case DW_MACRO_import
:
4963 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4964 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
4965 (unsigned long) offset
);
4968 case DW_MACRO_define_sup
:
4969 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4971 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4972 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
4973 lineno
, (unsigned long) offset
);
4976 case DW_MACRO_undef_sup
:
4977 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4979 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4980 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
4981 lineno
, (unsigned long) offset
);
4984 case DW_MACRO_import_sup
:
4985 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4986 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
4987 (unsigned long) offset
);
4991 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
4993 error (_(" Unknown macro opcode %02x seen\n"), op
);
4998 /* Skip over unhandled opcodes. */
5000 unsigned char *desc
= extended_ops
[op
];
5001 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
5005 printf (_(" DW_MACRO_%02x\n"), op
);
5008 printf (_(" DW_MACRO_%02x -"), op
);
5009 for (n
= 0; n
< nargs
; n
++)
5013 /* DW_FORM_implicit_const is not expected here. */
5014 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
5016 = read_and_display_attr_value (0, val
, 0,
5017 curr
, end
, 0, 0, offset_size
,
5018 version
, NULL
, 0, NULL
,
5036 display_debug_abbrev (struct dwarf_section
*section
,
5037 void *file ATTRIBUTE_UNUSED
)
5039 abbrev_entry
*entry
;
5040 unsigned char *start
= section
->start
;
5041 unsigned char *end
= start
+ section
->size
;
5043 printf (_("Contents of the %s section:\n\n"), section
->name
);
5047 unsigned char *last
;
5052 start
= process_abbrev_section (start
, end
);
5054 if (first_abbrev
== NULL
)
5057 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
5059 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5063 printf (" %ld %s [%s]\n",
5065 get_TAG_name (entry
->tag
),
5066 entry
->children
? _("has children") : _("no children"));
5068 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5070 printf (" %-18s %s",
5071 get_AT_name (attr
->attribute
),
5072 get_FORM_name (attr
->form
));
5073 if (attr
->form
== DW_FORM_implicit_const
)
5074 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
5086 /* Return true when ADDR is the maximum address, when addresses are
5087 POINTER_SIZE bytes long. */
5090 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
5092 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
5093 return ((addr
& mask
) == mask
);
5096 /* Display a view pair list starting at *VSTART_PTR and ending at
5097 VLISTEND within SECTION. */
5100 display_view_pair_list (struct dwarf_section
*section
,
5101 unsigned char **vstart_ptr
,
5102 unsigned int debug_info_entry
,
5103 unsigned char *vlistend
)
5105 unsigned char *vstart
= *vstart_ptr
;
5106 unsigned char *section_end
= section
->start
+ section
->size
;
5107 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5109 if (vlistend
< section_end
)
5110 section_end
= vlistend
;
5114 while (vstart
< section_end
)
5116 dwarf_vma off
= vstart
- section
->start
;
5117 dwarf_vma vbegin
, vend
;
5119 unsigned int bytes_read
;
5120 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5121 vstart
+= bytes_read
;
5122 if (vstart
== section_end
)
5124 vstart
-= bytes_read
;
5128 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5129 vstart
+= bytes_read
;
5131 printf (" %8.8lx ", (unsigned long) off
);
5133 print_dwarf_view (vbegin
, pointer_size
, 1);
5134 print_dwarf_view (vend
, pointer_size
, 1);
5135 printf (_("location view pair\n"));
5139 *vstart_ptr
= vstart
;
5142 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5145 display_loc_list (struct dwarf_section
*section
,
5146 unsigned char **start_ptr
,
5147 unsigned int debug_info_entry
,
5149 dwarf_vma base_address
,
5150 unsigned char **vstart_ptr
,
5153 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5154 unsigned char *section_end
= section
->start
+ section
->size
;
5155 unsigned long cu_offset
;
5156 unsigned int pointer_size
;
5157 unsigned int offset_size
;
5162 unsigned short length
;
5163 int need_frame_base
;
5165 if (debug_info_entry
>= num_debug_info_entries
)
5167 warn (_("No debug information available for loc lists of entry: %u\n"),
5172 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5173 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5174 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5175 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5177 if (pointer_size
< 2 || pointer_size
> 8)
5179 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5180 pointer_size
, debug_info_entry
);
5186 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5187 dwarf_vma vbegin
= vm1
, vend
= vm1
;
5189 if (start
+ 2 * pointer_size
> section_end
)
5191 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5192 (unsigned long) offset
);
5196 printf (" %8.8lx ", (unsigned long) off
);
5198 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
5199 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
5201 if (begin
== 0 && end
== 0)
5203 /* PR 18374: In a object file we can have a location list that
5204 starts with a begin and end of 0 because there are relocations
5205 that need to be applied to the addresses. Actually applying
5206 the relocations now does not help as they will probably resolve
5207 to 0, since the object file has not been fully linked. Real
5208 end of list markers will not have any relocations against them. */
5209 if (! reloc_at (section
, off
)
5210 && ! reloc_at (section
, off
+ pointer_size
))
5212 printf (_("<End of list>\n"));
5217 /* Check base address specifiers. */
5218 if (is_max_address (begin
, pointer_size
)
5219 && !is_max_address (end
, pointer_size
))
5222 print_dwarf_vma (begin
, pointer_size
);
5223 print_dwarf_vma (end
, pointer_size
);
5224 printf (_("(base address)\n"));
5230 unsigned int bytes_read
;
5232 off
= offset
+ (vstart
- *start_ptr
);
5234 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5235 vstart
+= bytes_read
;
5236 print_dwarf_view (vbegin
, pointer_size
, 1);
5238 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5239 vstart
+= bytes_read
;
5240 print_dwarf_view (vend
, pointer_size
, 1);
5242 printf (_("views at %8.8lx for:\n %*s "),
5243 (unsigned long) off
, 8, "");
5246 if (start
+ 2 > section_end
)
5248 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5249 (unsigned long) offset
);
5253 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5255 if (start
+ length
> section_end
)
5257 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5258 (unsigned long) offset
);
5262 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5263 print_dwarf_vma (end
+ base_address
, pointer_size
);
5266 need_frame_base
= decode_location_expression (start
,
5271 cu_offset
, section
);
5274 if (need_frame_base
&& !has_frame_base
)
5275 printf (_(" [without DW_AT_frame_base]"));
5277 if (begin
== end
&& vbegin
== vend
)
5278 fputs (_(" (start == end)"), stdout
);
5279 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5280 fputs (_(" (start > end)"), stdout
);
5288 *vstart_ptr
= vstart
;
5291 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5294 display_loclists_list (struct dwarf_section
*section
,
5295 unsigned char **start_ptr
,
5296 unsigned int debug_info_entry
,
5298 dwarf_vma base_address
,
5299 unsigned char **vstart_ptr
,
5302 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5303 unsigned char *section_end
= section
->start
+ section
->size
;
5304 unsigned long cu_offset
;
5305 unsigned int pointer_size
;
5306 unsigned int offset_size
;
5308 unsigned int bytes_read
;
5310 /* Initialize it due to a false compiler warning. */
5311 dwarf_vma begin
= -1, vbegin
= -1;
5312 dwarf_vma end
= -1, vend
= -1;
5314 int need_frame_base
;
5316 if (debug_info_entry
>= num_debug_info_entries
)
5318 warn (_("No debug information available for "
5319 "loclists lists of entry: %u\n"),
5324 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5325 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5326 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5327 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5329 if (pointer_size
< 2 || pointer_size
> 8)
5331 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5332 pointer_size
, debug_info_entry
);
5338 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5339 enum dwarf_location_list_entry_type llet
;
5341 if (start
+ 1 > section_end
)
5343 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5344 (unsigned long) offset
);
5348 printf (" %8.8lx ", (unsigned long) off
);
5350 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
5352 if (vstart
&& llet
== DW_LLE_offset_pair
)
5354 off
= offset
+ (vstart
- *start_ptr
);
5356 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5357 vstart
+= bytes_read
;
5358 print_dwarf_view (vbegin
, pointer_size
, 1);
5360 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5361 vstart
+= bytes_read
;
5362 print_dwarf_view (vend
, pointer_size
, 1);
5364 printf (_("views at %8.8lx for:\n %*s "),
5365 (unsigned long) off
, 8, "");
5370 case DW_LLE_end_of_list
:
5371 printf (_("<End of list>\n"));
5373 case DW_LLE_offset_pair
:
5374 begin
= read_uleb128 (start
, &bytes_read
, section_end
);
5375 start
+= bytes_read
;
5376 end
= read_uleb128 (start
, &bytes_read
, section_end
);
5377 start
+= bytes_read
;
5379 case DW_LLE_base_address
:
5380 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
5382 print_dwarf_vma (base_address
, pointer_size
);
5383 printf (_("(base address)\n"));
5385 #ifdef DW_LLE_view_pair
5386 case DW_LLE_view_pair
:
5388 printf (_("View pair entry in loclist with locviews attribute\n"));
5389 vbegin
= read_uleb128 (start
, &bytes_read
, section_end
);
5390 start
+= bytes_read
;
5391 print_dwarf_view (vbegin
, pointer_size
, 1);
5393 vend
= read_uleb128 (start
, &bytes_read
, section_end
);
5394 start
+= bytes_read
;
5395 print_dwarf_view (vend
, pointer_size
, 1);
5397 printf (_("views for:\n"));
5401 error (_("Invalid location list entry type %d\n"), llet
);
5404 if (llet
== DW_LLE_end_of_list
)
5406 if (llet
!= DW_LLE_offset_pair
)
5409 if (start
+ 2 > section_end
)
5411 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5412 (unsigned long) offset
);
5416 length
= read_uleb128 (start
, &bytes_read
, section_end
);
5417 start
+= bytes_read
;
5419 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5420 print_dwarf_vma (end
+ base_address
, pointer_size
);
5423 need_frame_base
= decode_location_expression (start
,
5428 cu_offset
, section
);
5431 if (need_frame_base
&& !has_frame_base
)
5432 printf (_(" [without DW_AT_frame_base]"));
5434 if (begin
== end
&& vbegin
== vend
)
5435 fputs (_(" (start == end)"), stdout
);
5436 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5437 fputs (_(" (start > end)"), stdout
);
5445 if (vbegin
!= vm1
|| vend
!= vm1
)
5446 printf (_("Trailing view pair not used in a range"));
5449 *vstart_ptr
= vstart
;
5452 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5453 right-adjusted in a field of length LEN, and followed by a space. */
5456 print_addr_index (unsigned int idx
, unsigned int len
)
5458 static char buf
[15];
5459 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
5460 printf ("%*s ", len
, buf
);
5463 /* Display a location list from a .dwo section. It uses address indexes rather
5464 than embedded addresses. This code closely follows display_loc_list, but the
5465 two are sufficiently different that combining things is very ugly. */
5468 display_loc_list_dwo (struct dwarf_section
*section
,
5469 unsigned char **start_ptr
,
5470 unsigned int debug_info_entry
,
5472 unsigned char **vstart_ptr
,
5475 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5476 unsigned char *section_end
= section
->start
+ section
->size
;
5477 unsigned long cu_offset
;
5478 unsigned int pointer_size
;
5479 unsigned int offset_size
;
5482 unsigned short length
;
5483 int need_frame_base
;
5485 unsigned int bytes_read
;
5487 if (debug_info_entry
>= num_debug_info_entries
)
5489 warn (_("No debug information for loc lists of entry: %u\n"),
5494 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5495 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5496 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5497 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5499 if (pointer_size
< 2 || pointer_size
> 8)
5501 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5502 pointer_size
, debug_info_entry
);
5508 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
5510 if (start
>= section_end
)
5512 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5513 (unsigned long) offset
);
5517 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
5530 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
5532 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5533 vstart
+= bytes_read
;
5534 print_dwarf_view (view
, 8, 1);
5536 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5537 vstart
+= bytes_read
;
5538 print_dwarf_view (view
, 8, 1);
5540 printf (_("views at %8.8lx for:\n %*s "),
5541 (unsigned long) off
, 8, "");
5549 case 0: /* A terminating entry. */
5551 *vstart_ptr
= vstart
;
5552 printf (_("<End of list>\n"));
5554 case 1: /* A base-address entry. */
5555 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5556 start
+= bytes_read
;
5557 print_addr_index (idx
, 8);
5558 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
5559 printf (_("(base address selection entry)\n"));
5561 case 2: /* A start/end entry. */
5562 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5563 start
+= bytes_read
;
5564 print_addr_index (idx
, 8);
5565 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5566 start
+= bytes_read
;
5567 print_addr_index (idx
, 8);
5569 case 3: /* A start/length entry. */
5570 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5571 start
+= bytes_read
;
5572 print_addr_index (idx
, 8);
5573 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5574 printf ("%08x ", idx
);
5576 case 4: /* An offset pair entry. */
5577 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5578 printf ("%08x ", idx
);
5579 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5580 printf ("%08x ", idx
);
5583 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
5585 *vstart_ptr
= vstart
;
5589 if (start
+ 2 > section_end
)
5591 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5592 (unsigned long) offset
);
5596 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5597 if (start
+ length
> section_end
)
5599 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5600 (unsigned long) offset
);
5605 need_frame_base
= decode_location_expression (start
,
5610 cu_offset
, section
);
5613 if (need_frame_base
&& !has_frame_base
)
5614 printf (_(" [without DW_AT_frame_base]"));
5622 *vstart_ptr
= vstart
;
5625 /* Sort array of indexes in ascending order of loc_offsets[idx] and
5628 static dwarf_vma
*loc_offsets
, *loc_views
;
5631 loc_offsets_compar (const void *ap
, const void *bp
)
5633 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
5634 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
5636 int ret
= (a
> b
) - (b
> a
);
5640 a
= loc_views
[*(const unsigned int *) ap
];
5641 b
= loc_views
[*(const unsigned int *) bp
];
5643 ret
= (a
> b
) - (b
> a
);
5649 display_debug_loc (struct dwarf_section
*section
, void *file
)
5651 unsigned char *start
= section
->start
, *vstart
= NULL
;
5652 unsigned long bytes
;
5653 unsigned char *section_begin
= start
;
5654 unsigned int num_loc_list
= 0;
5655 unsigned long last_offset
= 0;
5656 unsigned long last_view
= 0;
5657 unsigned int first
= 0;
5660 int seen_first_offset
= 0;
5661 int locs_sorted
= 1;
5662 unsigned char *next
= start
, *vnext
= vstart
;
5663 unsigned int *array
= NULL
;
5664 const char *suffix
= strrchr (section
->name
, '.');
5666 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
5667 dwarf_vma expected_start
= 0;
5669 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
5672 bytes
= section
->size
;
5676 printf (_("\nThe %s section is empty.\n"), section
->name
);
5682 unsigned char *hdrptr
= section_begin
;
5683 dwarf_vma ll_length
;
5684 unsigned short ll_version
;
5685 unsigned char *end
= section_begin
+ section
->size
;
5686 unsigned char address_size
, segment_selector_size
;
5687 uint32_t offset_entry_count
;
5689 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
5690 if (ll_length
== 0xffffffff)
5691 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
5693 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
5694 if (ll_version
!= 5)
5696 warn (_("The %s section contains corrupt or "
5697 "unsupported version number: %d.\n"),
5698 section
->name
, ll_version
);
5702 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
5704 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
5705 if (segment_selector_size
!= 0)
5707 warn (_("The %s section contains "
5708 "unsupported segment selector size: %d.\n"),
5709 section
->name
, segment_selector_size
);
5713 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
5714 if (offset_entry_count
!= 0)
5716 warn (_("The %s section contains "
5717 "unsupported offset entry count: %d.\n"),
5718 section
->name
, offset_entry_count
);
5722 expected_start
= hdrptr
- section_begin
;
5725 if (load_debug_info (file
) == 0)
5727 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5732 /* Check the order of location list in .debug_info section. If
5733 offsets of location lists are in the ascending order, we can
5734 use `debug_information' directly. */
5735 for (i
= 0; i
< num_debug_info_entries
; i
++)
5739 num
= debug_information
[i
].num_loc_offsets
;
5740 if (num
> num_loc_list
)
5743 /* Check if we can use `debug_information' directly. */
5744 if (locs_sorted
&& num
!= 0)
5746 if (!seen_first_offset
)
5748 /* This is the first location list. */
5749 last_offset
= debug_information
[i
].loc_offsets
[0];
5750 last_view
= debug_information
[i
].loc_views
[0];
5752 seen_first_offset
= 1;
5758 for (; j
< num
; j
++)
5761 debug_information
[i
].loc_offsets
[j
]
5762 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
5763 && last_view
> debug_information
[i
].loc_views
[j
]))
5768 last_offset
= debug_information
[i
].loc_offsets
[j
];
5769 last_view
= debug_information
[i
].loc_views
[j
];
5774 if (!seen_first_offset
)
5775 error (_("No location lists in .debug_info section!\n"));
5777 if (debug_information
[first
].num_loc_offsets
> 0
5778 && debug_information
[first
].loc_offsets
[0] != expected_start
5779 && debug_information
[first
].loc_views
[0] != expected_start
)
5780 warn (_("Location lists in %s section start at 0x%s\n"),
5782 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
5785 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
5786 printf (_("Contents of the %s section:\n\n"), section
->name
);
5787 if (reloc_at (section
, 0))
5788 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5789 printf (_(" Offset Begin End Expression\n"));
5791 seen_first_offset
= 0;
5792 for (i
= first
; i
< num_debug_info_entries
; i
++)
5794 dwarf_vma offset
, voffset
;
5795 dwarf_vma base_address
;
5801 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
5803 loc_offsets
= debug_information
[i
].loc_offsets
;
5804 loc_views
= debug_information
[i
].loc_views
;
5805 qsort (array
, debug_information
[i
].num_loc_offsets
,
5806 sizeof (*array
), loc_offsets_compar
);
5809 int adjacent_view_loclists
= 1;
5810 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
5812 j
= locs_sorted
? k
: array
[k
];
5814 && (debug_information
[i
].loc_offsets
[locs_sorted
5815 ? k
- 1 : array
[k
- 1]]
5816 == debug_information
[i
].loc_offsets
[j
])
5817 && (debug_information
[i
].loc_views
[locs_sorted
5818 ? k
- 1 : array
[k
- 1]]
5819 == debug_information
[i
].loc_views
[j
]))
5821 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
5822 offset
= debug_information
[i
].loc_offsets
[j
];
5823 next
= section_begin
+ offset
;
5824 voffset
= debug_information
[i
].loc_views
[j
];
5826 vnext
= section_begin
+ voffset
;
5829 base_address
= debug_information
[i
].base_address
;
5831 if (vnext
&& vnext
< next
)
5834 display_view_pair_list (section
, &vstart
, i
, next
);
5839 if (!seen_first_offset
|| !adjacent_view_loclists
)
5840 seen_first_offset
= 1;
5844 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5845 (unsigned long) (start
- section_begin
),
5846 (unsigned long) offset
);
5847 else if (start
> next
)
5848 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5849 (unsigned long) (start
- section_begin
),
5850 (unsigned long) offset
);
5855 if (offset
>= bytes
)
5857 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5858 (unsigned long) offset
);
5862 if (vnext
&& voffset
>= bytes
)
5864 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
5865 (unsigned long) voffset
);
5872 display_loc_list_dwo (section
, &start
, i
, offset
,
5873 &vstart
, has_frame_base
);
5875 display_loc_list (section
, &start
, i
, offset
, base_address
,
5876 &vstart
, has_frame_base
);
5881 warn (_("DWO is not yet supported.\n"));
5883 display_loclists_list (section
, &start
, i
, offset
, base_address
,
5884 &vstart
, has_frame_base
);
5887 /* FIXME: this arrangement is quite simplistic. Nothing
5888 requires locview lists to be adjacent to corresponding
5889 loclists, and a single loclist could be augmented by
5890 different locview lists, and vice-versa, unlikely as it
5891 is that it would make sense to do so. Hopefully we'll
5892 have view pair support built into loclists before we ever
5893 need to address all these possibilities. */
5894 if (adjacent_view_loclists
&& vnext
5895 && vnext
!= start
&& vstart
!= next
)
5897 adjacent_view_loclists
= 0;
5898 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
5901 if (vnext
&& vnext
== start
)
5902 display_view_pair_list (section
, &start
, i
, vstart
);
5906 if (start
< section
->start
+ section
->size
)
5907 warn (_("There are %ld unused bytes at the end of section %s\n"),
5908 (long) (section
->start
+ section
->size
- start
), section
->name
);
5915 display_debug_str (struct dwarf_section
*section
,
5916 void *file ATTRIBUTE_UNUSED
)
5918 unsigned char *start
= section
->start
;
5919 unsigned long bytes
= section
->size
;
5920 dwarf_vma addr
= section
->address
;
5924 printf (_("\nThe %s section is empty.\n"), section
->name
);
5928 printf (_("Contents of the %s section:\n\n"), section
->name
);
5936 lbytes
= (bytes
> 16 ? 16 : bytes
);
5938 printf (" 0x%8.8lx ", (unsigned long) addr
);
5940 for (j
= 0; j
< 16; j
++)
5943 printf ("%2.2x", start
[j
]);
5951 for (j
= 0; j
< lbytes
; j
++)
5954 if (k
>= ' ' && k
< 0x80)
5973 display_debug_info (struct dwarf_section
*section
, void *file
)
5975 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
5979 display_debug_types (struct dwarf_section
*section
, void *file
)
5981 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 1);
5985 display_trace_info (struct dwarf_section
*section
, void *file
)
5987 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
5991 display_debug_aranges (struct dwarf_section
*section
,
5992 void *file ATTRIBUTE_UNUSED
)
5994 unsigned char *start
= section
->start
;
5995 unsigned char *end
= start
+ section
->size
;
5997 printf (_("Contents of the %s section:\n\n"), section
->name
);
5999 /* It does not matter if this load fails,
6000 we test for that later on. */
6001 load_debug_info (file
);
6005 unsigned char *hdrptr
;
6006 DWARF2_Internal_ARange arange
;
6007 unsigned char *addr_ranges
;
6010 unsigned char address_size
;
6012 unsigned int offset_size
;
6013 unsigned int initial_length_size
;
6017 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
6018 if (arange
.ar_length
== 0xffffffff)
6020 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
6022 initial_length_size
= 12;
6027 initial_length_size
= 4;
6030 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
6031 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
6033 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6034 && num_debug_info_entries
> 0
6035 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
6036 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6037 (unsigned long) arange
.ar_info_offset
, section
->name
);
6039 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
6040 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
6042 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
6044 /* PR 19872: A version number of 0 probably means that there is
6045 padding at the end of the .debug_aranges section. Gold puts
6046 it there when performing an incremental link, for example.
6047 So do not generate a warning in this case. */
6048 if (arange
.ar_version
)
6049 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6053 printf (_(" Length: %ld\n"),
6054 (long) arange
.ar_length
);
6055 printf (_(" Version: %d\n"), arange
.ar_version
);
6056 printf (_(" Offset into .debug_info: 0x%lx\n"),
6057 (unsigned long) arange
.ar_info_offset
);
6058 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6059 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6061 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
6063 /* PR 17512: file: 001-108546-0.001:0.1. */
6064 if (address_size
== 0 || address_size
> 8)
6066 error (_("Invalid address size in %s section!\n"),
6071 /* The DWARF spec does not require that the address size be a power
6072 of two, but we do. This will have to change if we ever encounter
6073 an uneven architecture. */
6074 if ((address_size
& (address_size
- 1)) != 0)
6076 warn (_("Pointer size + Segment size is not a power of two.\n"));
6080 if (address_size
> 4)
6081 printf (_("\n Address Length\n"));
6083 printf (_("\n Address Length\n"));
6085 addr_ranges
= hdrptr
;
6087 /* Must pad to an alignment boundary that is twice the address size. */
6088 excess
= (hdrptr
- start
) % (2 * address_size
);
6090 addr_ranges
+= (2 * address_size
) - excess
;
6092 hdrptr
= start
+ arange
.ar_length
+ initial_length_size
;
6093 if (hdrptr
< start
|| hdrptr
> end
)
6095 error (_("Excessive header length: %lx\n"), (long) arange
.ar_length
);
6100 while (addr_ranges
+ 2 * address_size
<= start
)
6102 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
6103 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
6106 print_dwarf_vma (address
, address_size
);
6107 print_dwarf_vma (length
, address_size
);
6117 /* Comparison function for qsort. */
6119 comp_addr_base (const void * v0
, const void * v1
)
6121 debug_info
* info0
= (debug_info
*) v0
;
6122 debug_info
* info1
= (debug_info
*) v1
;
6123 return info0
->addr_base
- info1
->addr_base
;
6126 /* Display the debug_addr section. */
6128 display_debug_addr (struct dwarf_section
*section
,
6131 debug_info
**debug_addr_info
;
6132 unsigned char *entry
;
6137 if (section
->size
== 0)
6139 printf (_("\nThe %s section is empty.\n"), section
->name
);
6143 if (load_debug_info (file
) == 0)
6145 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6150 printf (_("Contents of the %s section:\n\n"), section
->name
);
6152 /* PR 17531: file: cf38d01b.
6153 We use xcalloc because a corrupt file may not have initialised all of the
6154 fields in the debug_info structure, which means that the sort below might
6155 try to move uninitialised data. */
6156 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
6157 sizeof (debug_info
*));
6160 for (i
= 0; i
< num_debug_info_entries
; i
++)
6161 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
6163 /* PR 17531: file: cf38d01b. */
6164 if (debug_information
[i
].addr_base
>= section
->size
)
6165 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6166 (unsigned long) debug_information
[i
].addr_base
, i
);
6168 debug_addr_info
[count
++] = debug_information
+ i
;
6171 /* Add a sentinel to make iteration convenient. */
6172 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
6173 debug_addr_info
[count
]->addr_base
= section
->size
;
6174 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
6176 for (i
= 0; i
< count
; i
++)
6179 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
6181 printf (_(" For compilation unit at offset 0x%s:\n"),
6182 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
6184 printf (_("\tIndex\tAddress\n"));
6185 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
6186 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
6190 dwarf_vma base
= byte_get (entry
, address_size
);
6191 printf (_("\t%d:\t"), idx
);
6192 print_dwarf_vma (base
, address_size
);
6194 entry
+= address_size
;
6200 free (debug_addr_info
);
6204 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6206 display_debug_str_offsets (struct dwarf_section
*section
,
6207 void *file ATTRIBUTE_UNUSED
)
6209 if (section
->size
== 0)
6211 printf (_("\nThe %s section is empty.\n"), section
->name
);
6214 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6215 what the offset size is for this section. */
6219 /* Each debug_information[x].range_lists[y] gets this representation for
6220 sorting purposes. */
6224 /* The debug_information[x].range_lists[y] value. */
6225 dwarf_vma ranges_offset
;
6227 /* Original debug_information to find parameters of the data. */
6228 debug_info
*debug_info_p
;
6231 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6234 range_entry_compar (const void *ap
, const void *bp
)
6236 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
6237 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
6238 const dwarf_vma a
= a_re
->ranges_offset
;
6239 const dwarf_vma b
= b_re
->ranges_offset
;
6241 return (a
> b
) - (b
> a
);
6245 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
6246 unsigned int pointer_size
, unsigned long offset
,
6247 unsigned long base_address
)
6249 while (start
< finish
)
6254 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6255 if (start
>= finish
)
6257 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6259 printf (" %8.8lx ", offset
);
6261 if (begin
== 0 && end
== 0)
6263 printf (_("<End of list>\n"));
6267 /* Check base address specifiers. */
6268 if (is_max_address (begin
, pointer_size
)
6269 && !is_max_address (end
, pointer_size
))
6272 print_dwarf_vma (begin
, pointer_size
);
6273 print_dwarf_vma (end
, pointer_size
);
6274 printf ("(base address)\n");
6278 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6279 print_dwarf_vma (end
+ base_address
, pointer_size
);
6282 fputs (_("(start == end)"), stdout
);
6283 else if (begin
> end
)
6284 fputs (_("(start > end)"), stdout
);
6291 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
6292 unsigned int pointer_size
, unsigned long offset
,
6293 unsigned long base_address
)
6295 unsigned char *next
= start
;
6299 unsigned long off
= offset
+ (start
- next
);
6300 enum dwarf_range_list_entry rlet
;
6301 /* Initialize it due to a false compiler warning. */
6302 dwarf_vma begin
= -1, length
, end
= -1;
6303 unsigned int bytes_read
;
6305 if (start
+ 1 > finish
)
6307 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6312 printf (" %8.8lx ", off
);
6314 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
6318 case DW_RLE_end_of_list
:
6319 printf (_("<End of list>\n"));
6321 case DW_RLE_base_address
:
6322 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
6323 print_dwarf_vma (base_address
, pointer_size
);
6324 printf (_("(base address)\n"));
6326 case DW_RLE_start_length
:
6327 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6328 length
= read_uleb128 (start
, &bytes_read
, finish
);
6329 start
+= bytes_read
;
6330 end
= begin
+ length
;
6332 case DW_RLE_offset_pair
:
6333 begin
= read_uleb128 (start
, &bytes_read
, finish
);
6334 start
+= bytes_read
;
6335 end
= read_uleb128 (start
, &bytes_read
, finish
);
6336 start
+= bytes_read
;
6338 case DW_RLE_start_end
:
6339 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6340 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6343 error (_("Invalid range list entry type %d\n"), rlet
);
6344 rlet
= DW_RLE_end_of_list
;
6347 if (rlet
== DW_RLE_end_of_list
)
6349 if (rlet
== DW_RLE_base_address
)
6352 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6353 print_dwarf_vma (end
+ base_address
, pointer_size
);
6356 fputs (_("(start == end)"), stdout
);
6357 else if (begin
> end
)
6358 fputs (_("(start > end)"), stdout
);
6365 display_debug_ranges (struct dwarf_section
*section
,
6366 void *file ATTRIBUTE_UNUSED
)
6368 unsigned char *start
= section
->start
;
6369 unsigned char *last_start
= start
;
6370 unsigned long bytes
= section
->size
;
6371 unsigned char *section_begin
= start
;
6372 unsigned char *finish
= start
+ bytes
;
6373 unsigned int num_range_list
, i
;
6374 struct range_entry
*range_entries
, *range_entry_fill
;
6375 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
6376 /* Initialize it due to a false compiler warning. */
6377 unsigned char address_size
= 0;
6381 printf (_("\nThe %s section is empty.\n"), section
->name
);
6387 dwarf_vma initial_length
;
6388 unsigned int initial_length_size
;
6389 unsigned char segment_selector_size
;
6390 unsigned int offset_size
, offset_entry_count
;
6391 unsigned short version
;
6393 /* Get and check the length of the block. */
6394 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
6396 if (initial_length
== 0xffffffff)
6398 /* This section is 64-bit DWARF 3. */
6399 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
6401 initial_length_size
= 12;
6406 initial_length_size
= 4;
6409 if (initial_length
+ initial_length_size
> section
->size
)
6411 /* If the length field has a relocation against it, then we should
6412 not complain if it is inaccurate (and probably negative).
6413 It is copied from .debug_line handling code. */
6414 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
6416 initial_length
= (finish
- start
) - initial_length_size
;
6420 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6421 (long) initial_length
);
6426 /* Get and check the version number. */
6427 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
6431 warn (_("Only DWARF version 5 debug_rnglists info "
6432 "is currently supported.\n"));
6436 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
6438 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
6439 if (segment_selector_size
!= 0)
6441 warn (_("The %s section contains "
6442 "unsupported segment selector size: %d.\n"),
6443 section
->name
, segment_selector_size
);
6447 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
6448 if (offset_entry_count
!= 0)
6450 warn (_("The %s section contains "
6451 "unsupported offset entry count: %u.\n"),
6452 section
->name
, offset_entry_count
);
6457 if (load_debug_info (file
) == 0)
6459 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6465 for (i
= 0; i
< num_debug_info_entries
; i
++)
6466 num_range_list
+= debug_information
[i
].num_range_lists
;
6468 if (num_range_list
== 0)
6470 /* This can happen when the file was compiled with -gsplit-debug
6471 which removes references to range lists from the primary .o file. */
6472 printf (_("No range lists in .debug_info section.\n"));
6476 range_entries
= (struct range_entry
*)
6477 xmalloc (sizeof (*range_entries
) * num_range_list
);
6478 range_entry_fill
= range_entries
;
6480 for (i
= 0; i
< num_debug_info_entries
; i
++)
6482 debug_info
*debug_info_p
= &debug_information
[i
];
6485 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
6487 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
6488 range_entry_fill
->debug_info_p
= debug_info_p
;
6493 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
6494 range_entry_compar
);
6496 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
6497 warn (_("Range lists in %s section start at 0x%lx\n"),
6498 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
6500 printf (_("Contents of the %s section:\n\n"), section
->name
);
6501 printf (_(" Offset Begin End\n"));
6503 for (i
= 0; i
< num_range_list
; i
++)
6505 struct range_entry
*range_entry
= &range_entries
[i
];
6506 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
6507 unsigned int pointer_size
;
6509 unsigned char *next
;
6510 dwarf_vma base_address
;
6512 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
6513 offset
= range_entry
->ranges_offset
;
6514 next
= section_begin
+ offset
;
6515 base_address
= debug_info_p
->base_address
;
6517 /* PR 17512: file: 001-101485-0.001:0.1. */
6518 if (pointer_size
< 2 || pointer_size
> 8)
6520 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6521 pointer_size
, (unsigned long) offset
);
6525 if (dwarf_check
!= 0 && i
> 0)
6528 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6529 (unsigned long) (start
- section_begin
),
6530 (unsigned long) (next
- section_begin
), section
->name
);
6531 else if (start
> next
)
6533 if (next
== last_start
)
6535 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6536 (unsigned long) (start
- section_begin
),
6537 (unsigned long) (next
- section_begin
), section
->name
);
6543 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
6544 (start
, finish
, pointer_size
, offset
, base_address
);
6548 free (range_entries
);
6553 typedef struct Frame_Chunk
6555 struct Frame_Chunk
*next
;
6556 unsigned char *chunk_start
;
6558 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6559 short int *col_type
;
6562 unsigned int code_factor
;
6567 dwarf_vma cfa_offset
;
6569 unsigned char fde_encoding
;
6570 unsigned char cfa_exp
;
6571 unsigned char ptr_size
;
6572 unsigned char segment_size
;
6576 static const char *const *dwarf_regnames
;
6577 static unsigned int dwarf_regnames_count
;
6579 /* A marker for a col_type that means this column was never referenced
6580 in the frame info. */
6581 #define DW_CFA_unreferenced (-1)
6583 /* Return 0 if no more space is needed, 1 if more space is needed,
6584 -1 for invalid reg. */
6587 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
6589 unsigned int prev
= fc
->ncols
;
6591 if (reg
< (unsigned int) fc
->ncols
)
6594 if (dwarf_regnames_count
6595 && reg
> dwarf_regnames_count
)
6598 fc
->ncols
= reg
+ 1;
6599 /* PR 17512: file: 10450-2643-0.004.
6600 If reg == -1 then this can happen... */
6604 /* PR 17512: file: 2844a11d. */
6605 if (fc
->ncols
> 1024)
6607 error (_("Unfeasibly large register number: %u\n"), reg
);
6609 /* FIXME: 1024 is an arbitrary limit. Increase it if
6610 we ever encounter a valid binary that exceeds it. */
6614 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
6615 sizeof (short int));
6616 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
6617 /* PR 17512: file:002-10025-0.005. */
6618 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
6620 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6626 while (prev
< fc
->ncols
)
6628 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
6629 fc
->col_offset
[prev
] = 0;
6635 static const char *const dwarf_regnames_i386
[] =
6637 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6638 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6639 "eip", "eflags", NULL
, /* 8 - 10 */
6640 "st0", "st1", "st2", "st3", /* 11 - 14 */
6641 "st4", "st5", "st6", "st7", /* 15 - 18 */
6642 NULL
, NULL
, /* 19 - 20 */
6643 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6644 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6645 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6646 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6647 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6648 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6649 "tr", "ldtr", /* 48 - 49 */
6650 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6651 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6652 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6653 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6654 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6655 NULL
, NULL
, NULL
, /* 90 - 92 */
6656 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6659 static const char *const dwarf_regnames_iamcu
[] =
6661 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6662 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6663 "eip", "eflags", NULL
, /* 8 - 10 */
6664 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
6665 NULL
, NULL
, /* 19 - 20 */
6666 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
6667 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
6668 NULL
, NULL
, NULL
, /* 37 - 39 */
6669 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6670 "tr", "ldtr", /* 48 - 49 */
6671 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6672 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6673 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6674 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6675 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6676 NULL
, NULL
, NULL
, /* 90 - 92 */
6677 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
6681 init_dwarf_regnames_i386 (void)
6683 dwarf_regnames
= dwarf_regnames_i386
;
6684 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
6688 init_dwarf_regnames_iamcu (void)
6690 dwarf_regnames
= dwarf_regnames_iamcu
;
6691 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
6694 static const char *const dwarf_regnames_x86_64
[] =
6696 "rax", "rdx", "rcx", "rbx",
6697 "rsi", "rdi", "rbp", "rsp",
6698 "r8", "r9", "r10", "r11",
6699 "r12", "r13", "r14", "r15",
6701 "xmm0", "xmm1", "xmm2", "xmm3",
6702 "xmm4", "xmm5", "xmm6", "xmm7",
6703 "xmm8", "xmm9", "xmm10", "xmm11",
6704 "xmm12", "xmm13", "xmm14", "xmm15",
6705 "st0", "st1", "st2", "st3",
6706 "st4", "st5", "st6", "st7",
6707 "mm0", "mm1", "mm2", "mm3",
6708 "mm4", "mm5", "mm6", "mm7",
6710 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
6711 "fs.base", "gs.base", NULL
, NULL
,
6713 "mxcsr", "fcw", "fsw",
6714 "xmm16", "xmm17", "xmm18", "xmm19",
6715 "xmm20", "xmm21", "xmm22", "xmm23",
6716 "xmm24", "xmm25", "xmm26", "xmm27",
6717 "xmm28", "xmm29", "xmm30", "xmm31",
6718 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
6719 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
6720 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
6721 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
6722 NULL
, NULL
, NULL
, /* 115 - 117 */
6723 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6727 init_dwarf_regnames_x86_64 (void)
6729 dwarf_regnames
= dwarf_regnames_x86_64
;
6730 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
6733 static const char *const dwarf_regnames_aarch64
[] =
6735 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6736 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6737 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6738 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6739 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6740 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6741 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6742 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6743 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6744 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6745 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6746 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6750 init_dwarf_regnames_aarch64 (void)
6752 dwarf_regnames
= dwarf_regnames_aarch64
;
6753 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
6756 static const char *const dwarf_regnames_s390
[] =
6758 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6759 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6760 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6761 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6762 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6763 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6764 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6765 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6766 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6769 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6770 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6774 init_dwarf_regnames_s390 (void)
6776 dwarf_regnames
= dwarf_regnames_s390
;
6777 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
6781 init_dwarf_regnames (unsigned int e_machine
)
6786 init_dwarf_regnames_i386 ();
6790 init_dwarf_regnames_iamcu ();
6796 init_dwarf_regnames_x86_64 ();
6800 init_dwarf_regnames_aarch64 ();
6804 init_dwarf_regnames_s390 ();
6813 regname (unsigned int regno
, int row
)
6815 static char reg
[64];
6818 && regno
< dwarf_regnames_count
6819 && dwarf_regnames
[regno
] != NULL
)
6822 return dwarf_regnames
[regno
];
6823 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
6824 dwarf_regnames
[regno
]);
6827 snprintf (reg
, sizeof (reg
), "r%d", regno
);
6832 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
6837 if (*max_regs
!= fc
->ncols
)
6838 *max_regs
= fc
->ncols
;
6840 if (*need_col_headers
)
6842 static const char *sloc
= " LOC";
6844 *need_col_headers
= 0;
6846 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
6848 for (r
= 0; r
< *max_regs
; r
++)
6849 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
6854 printf ("%-5s ", regname (r
, 1));
6860 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
6862 strcpy (tmp
, "exp");
6864 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
6865 printf ("%-8s ", tmp
);
6867 for (r
= 0; r
< fc
->ncols
; r
++)
6869 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
6871 switch (fc
->col_type
[r
])
6873 case DW_CFA_undefined
:
6876 case DW_CFA_same_value
:
6880 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
6882 case DW_CFA_val_offset
:
6883 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
6885 case DW_CFA_register
:
6886 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
6888 case DW_CFA_expression
:
6889 strcpy (tmp
, "exp");
6891 case DW_CFA_val_expression
:
6892 strcpy (tmp
, "vexp");
6895 strcpy (tmp
, "n/a");
6898 printf ("%-5s ", tmp
);
6904 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6906 static unsigned char *
6907 read_cie (unsigned char *start
, unsigned char *end
,
6908 Frame_Chunk
**p_cie
, int *p_version
,
6909 unsigned long *p_aug_len
, unsigned char **p_aug
)
6913 unsigned int length_return
;
6914 unsigned char *augmentation_data
= NULL
;
6915 unsigned long augmentation_data_len
= 0;
6918 /* PR 17512: file: 001-228113-0.004. */
6922 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
6923 memset (fc
, 0, sizeof (Frame_Chunk
));
6925 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
6926 fc
->col_offset
= (int *) xmalloc (sizeof (int));
6930 fc
->augmentation
= (char *) start
;
6931 /* PR 17512: file: 001-228113-0.004.
6932 Skip past augmentation name, but avoid running off the end of the data. */
6934 if (* start
++ == '\0')
6938 warn (_("No terminator for augmentation name\n"));
6942 if (strcmp (fc
->augmentation
, "eh") == 0)
6943 start
+= eh_addr_size
;
6947 GET (fc
->ptr_size
, 1);
6948 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
6950 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
6954 GET (fc
->segment_size
, 1);
6955 /* PR 17512: file: e99d2804. */
6956 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
6958 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
6962 eh_addr_size
= fc
->ptr_size
;
6966 fc
->ptr_size
= eh_addr_size
;
6967 fc
->segment_size
= 0;
6969 READ_ULEB (fc
->code_factor
);
6970 READ_SLEB (fc
->data_factor
);
6980 if (fc
->augmentation
[0] == 'z')
6982 READ_ULEB (augmentation_data_len
);
6983 augmentation_data
= start
;
6984 start
+= augmentation_data_len
;
6985 /* PR 17512: file: 11042-2589-0.004. */
6988 warn (_("Augmentation data too long: %#lx, expected at most %#lx\n"),
6989 augmentation_data_len
, (long)((end
- start
) + augmentation_data_len
));
6994 if (augmentation_data_len
)
6998 unsigned char *qend
;
7000 p
= (unsigned char *) fc
->augmentation
+ 1;
7001 q
= augmentation_data
;
7002 qend
= q
+ augmentation_data_len
;
7004 /* PR 17531: file: 015adfaa. */
7007 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len
);
7008 augmentation_data_len
= 0;
7011 while (p
< end
&& q
< augmentation_data
+ augmentation_data_len
)
7016 q
+= 1 + size_of_encoded_value (*q
);
7018 fc
->fde_encoding
= *q
++;
7025 /* Note - it is OK if this loop terminates with q < qend.
7026 Padding may have been inserted to align the end of the CIE. */
7031 *p_version
= version
;
7034 *p_aug_len
= augmentation_data_len
;
7035 *p_aug
= augmentation_data
;
7041 display_debug_frames (struct dwarf_section
*section
,
7042 void *file ATTRIBUTE_UNUSED
)
7044 unsigned char *start
= section
->start
;
7045 unsigned char *end
= start
+ section
->size
;
7046 unsigned char *section_start
= start
;
7047 Frame_Chunk
*chunks
= 0, *forward_refs
= 0;
7048 Frame_Chunk
*remembered_state
= 0;
7050 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
7051 unsigned int length_return
;
7052 unsigned int max_regs
= 0;
7053 const char *bad_reg
= _("bad register: ");
7054 unsigned int saved_eh_addr_size
= eh_addr_size
;
7056 printf (_("Contents of the %s section:\n"), section
->name
);
7060 unsigned char *saved_start
;
7061 unsigned char *block_end
;
7066 int need_col_headers
= 1;
7067 unsigned char *augmentation_data
= NULL
;
7068 unsigned long augmentation_data_len
= 0;
7069 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
7070 unsigned int offset_size
;
7071 unsigned int initial_length_size
;
7072 bfd_boolean all_nops
;
7074 saved_start
= start
;
7076 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7080 printf ("\n%08lx ZERO terminator\n\n",
7081 (unsigned long)(saved_start
- section_start
));
7082 /* Skip any zero terminators that directly follow.
7083 A corrupt section size could have loaded a whole
7084 slew of zero filled memory bytes. eg
7085 PR 17512: file: 070-19381-0.004. */
7086 while (start
< end
&& * start
== 0)
7091 if (length
== 0xffffffff)
7093 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7095 initial_length_size
= 12;
7100 initial_length_size
= 4;
7103 block_end
= saved_start
+ length
+ initial_length_size
;
7104 if (block_end
> end
|| block_end
< start
)
7106 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7107 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
7108 (unsigned long) (saved_start
- section_start
));
7112 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
7114 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
7115 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
7120 start
= read_cie (start
, end
, &cie
, &version
,
7121 &augmentation_data_len
, &augmentation_data
);
7122 /* PR 17512: file: 027-135133-0.005. */
7129 fc
->chunk_start
= saved_start
;
7130 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7133 if (frame_need_space (fc
, mreg
) < 0)
7135 if (fc
->fde_encoding
)
7136 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7138 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
7139 print_dwarf_vma (length
, fc
->ptr_size
);
7140 print_dwarf_vma (cie_id
, offset_size
);
7142 if (do_debug_frames_interp
)
7144 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
7145 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
7150 printf (" Version: %d\n", version
);
7151 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
7154 printf (" Pointer Size: %u\n", fc
->ptr_size
);
7155 printf (" Segment Size: %u\n", fc
->segment_size
);
7157 printf (" Code alignment factor: %u\n", fc
->code_factor
);
7158 printf (" Data alignment factor: %d\n", fc
->data_factor
);
7159 printf (" Return address column: %d\n", fc
->ra
);
7161 if (augmentation_data_len
)
7165 printf (" Augmentation data: ");
7166 for (i
= 0; i
< augmentation_data_len
; ++i
)
7167 /* FIXME: If do_wide is FALSE, then we should
7168 add carriage returns at 80 columns... */
7169 printf (" %02x", augmentation_data
[i
]);
7177 unsigned char *look_for
;
7178 static Frame_Chunk fde_fc
;
7179 unsigned long segment_selector
;
7183 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
7184 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
7187 look_for
= section_start
+ cie_id
;
7189 if (look_for
<= saved_start
)
7191 for (cie
= chunks
; cie
; cie
= cie
->next
)
7192 if (cie
->chunk_start
== look_for
)
7197 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
7198 if (cie
->chunk_start
== look_for
)
7202 unsigned int off_size
;
7203 unsigned char *cie_scan
;
7205 cie_scan
= look_for
;
7207 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
7208 if (length
== 0xffffffff)
7210 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
7217 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
7220 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
7221 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
7226 read_cie (cie_scan
, end
, &cie
, &version
,
7227 &augmentation_data_len
, &augmentation_data
);
7228 /* PR 17512: file: 3450-2098-0.004. */
7231 warn (_("Failed to read CIE information\n"));
7234 cie
->next
= forward_refs
;
7236 cie
->chunk_start
= look_for
;
7237 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7240 if (frame_need_space (cie
, mreg
) < 0)
7242 warn (_("Invalid max register\n"));
7245 if (cie
->fde_encoding
)
7247 = size_of_encoded_value (cie
->fde_encoding
);
7254 memset (fc
, 0, sizeof (Frame_Chunk
));
7258 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7259 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
7260 (unsigned long) (saved_start
- section_start
));
7262 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7263 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7264 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
7266 warn (_("Invalid max register\n"));
7270 fc
->augmentation
= "";
7271 fc
->fde_encoding
= 0;
7272 fc
->ptr_size
= eh_addr_size
;
7273 fc
->segment_size
= 0;
7277 fc
->ncols
= cie
->ncols
;
7278 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
7279 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
7280 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
7281 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
7282 fc
->augmentation
= cie
->augmentation
;
7283 fc
->ptr_size
= cie
->ptr_size
;
7284 eh_addr_size
= cie
->ptr_size
;
7285 fc
->segment_size
= cie
->segment_size
;
7286 fc
->code_factor
= cie
->code_factor
;
7287 fc
->data_factor
= cie
->data_factor
;
7288 fc
->cfa_reg
= cie
->cfa_reg
;
7289 fc
->cfa_offset
= cie
->cfa_offset
;
7291 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
7293 warn (_("Invalid max register\n"));
7296 fc
->fde_encoding
= cie
->fde_encoding
;
7299 if (fc
->fde_encoding
)
7300 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7302 segment_selector
= 0;
7303 if (fc
->segment_size
)
7305 if (fc
->segment_size
> sizeof (segment_selector
))
7307 /* PR 17512: file: 9e196b3e. */
7308 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
7309 fc
->segment_size
= 4;
7311 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
7314 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
7316 /* FIXME: It appears that sometimes the final pc_range value is
7317 encoded in less than encoded_ptr_size bytes. See the x86_64
7318 run of the "objcopy on compressed debug sections" test for an
7320 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
7322 if (cie
->augmentation
[0] == 'z')
7324 READ_ULEB (augmentation_data_len
);
7325 augmentation_data
= start
;
7326 start
+= augmentation_data_len
;
7327 /* PR 17512: file: 722-8446-0.004. */
7328 if (start
>= end
|| ((signed long) augmentation_data_len
) < 0)
7330 warn (_("Corrupt augmentation data length: %lx\n"),
7331 augmentation_data_len
);
7333 augmentation_data
= NULL
;
7334 augmentation_data_len
= 0;
7338 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7339 (unsigned long)(saved_start
- section_start
),
7340 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
7341 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
7342 (unsigned long)(cie
->chunk_start
- section_start
));
7344 if (fc
->segment_size
)
7345 printf ("%04lx:", segment_selector
);
7348 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
7349 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
7351 if (! do_debug_frames_interp
&& augmentation_data_len
)
7355 printf (" Augmentation data: ");
7356 for (i
= 0; i
< augmentation_data_len
; ++i
)
7357 printf (" %02x", augmentation_data
[i
]);
7363 /* At this point, fc is the current chunk, cie (if any) is set, and
7364 we're about to interpret instructions for the chunk. */
7365 /* ??? At present we need to do this always, since this sizes the
7366 fc->col_type and fc->col_offset arrays, which we write into always.
7367 We should probably split the interpreted and non-interpreted bits
7368 into two different routines, since there's so much that doesn't
7369 really overlap between them. */
7370 if (1 || do_debug_frames_interp
)
7372 /* Start by making a pass over the chunk, allocating storage
7373 and taking note of what registers are used. */
7374 unsigned char *tmp
= start
;
7376 while (start
< block_end
)
7378 unsigned int reg
, op
, opa
;
7380 unsigned char * new_start
;
7387 /* Warning: if you add any more cases to this switch, be
7388 sure to add them to the corresponding switch below. */
7391 case DW_CFA_advance_loc
:
7395 if (frame_need_space (fc
, opa
) >= 0)
7396 fc
->col_type
[opa
] = DW_CFA_undefined
;
7398 case DW_CFA_restore
:
7399 if (frame_need_space (fc
, opa
) >= 0)
7400 fc
->col_type
[opa
] = DW_CFA_undefined
;
7402 case DW_CFA_set_loc
:
7403 start
+= encoded_ptr_size
;
7405 case DW_CFA_advance_loc1
:
7408 case DW_CFA_advance_loc2
:
7411 case DW_CFA_advance_loc4
:
7414 case DW_CFA_offset_extended
:
7415 case DW_CFA_val_offset
:
7418 if (frame_need_space (fc
, reg
) >= 0)
7419 fc
->col_type
[reg
] = DW_CFA_undefined
;
7421 case DW_CFA_restore_extended
:
7423 if (frame_need_space (fc
, reg
) >= 0)
7424 fc
->col_type
[reg
] = DW_CFA_undefined
;
7426 case DW_CFA_undefined
:
7428 if (frame_need_space (fc
, reg
) >= 0)
7429 fc
->col_type
[reg
] = DW_CFA_undefined
;
7431 case DW_CFA_same_value
:
7433 if (frame_need_space (fc
, reg
) >= 0)
7434 fc
->col_type
[reg
] = DW_CFA_undefined
;
7436 case DW_CFA_register
:
7439 if (frame_need_space (fc
, reg
) >= 0)
7440 fc
->col_type
[reg
] = DW_CFA_undefined
;
7442 case DW_CFA_def_cfa
:
7446 case DW_CFA_def_cfa_register
:
7449 case DW_CFA_def_cfa_offset
:
7452 case DW_CFA_def_cfa_expression
:
7454 new_start
= start
+ temp
;
7455 if (new_start
< start
)
7457 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
7463 case DW_CFA_expression
:
7464 case DW_CFA_val_expression
:
7467 new_start
= start
+ temp
;
7468 if (new_start
< start
)
7470 /* PR 17512: file:306-192417-0.005. */
7471 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
7476 if (frame_need_space (fc
, reg
) >= 0)
7477 fc
->col_type
[reg
] = DW_CFA_undefined
;
7479 case DW_CFA_offset_extended_sf
:
7480 case DW_CFA_val_offset_sf
:
7483 if (frame_need_space (fc
, reg
) >= 0)
7484 fc
->col_type
[reg
] = DW_CFA_undefined
;
7486 case DW_CFA_def_cfa_sf
:
7490 case DW_CFA_def_cfa_offset_sf
:
7493 case DW_CFA_MIPS_advance_loc8
:
7496 case DW_CFA_GNU_args_size
:
7499 case DW_CFA_GNU_negative_offset_extended
:
7502 if (frame_need_space (fc
, reg
) >= 0)
7503 fc
->col_type
[reg
] = DW_CFA_undefined
;
7514 /* Now we know what registers are used, make a second pass over
7515 the chunk, this time actually printing out the info. */
7517 while (start
< block_end
)
7519 unsigned char * tmp
;
7521 unsigned long ul
, roffs
;
7522 /* Note: It is tempting to use an unsigned long for 'reg' but there
7523 are various functions, notably frame_space_needed() that assume that
7524 reg is an unsigned int. */
7529 const char *reg_prefix
= "";
7536 /* Make a note if something other than DW_CFA_nop happens. */
7537 if (op
!= DW_CFA_nop
)
7540 /* Warning: if you add any more cases to this switch, be
7541 sure to add them to the corresponding switch above. */
7544 case DW_CFA_advance_loc
:
7545 if (do_debug_frames_interp
)
7546 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7548 printf (" DW_CFA_advance_loc: %d to %s\n",
7549 opa
* fc
->code_factor
,
7550 dwarf_vmatoa_1 (NULL
,
7551 fc
->pc_begin
+ opa
* fc
->code_factor
,
7553 fc
->pc_begin
+= opa
* fc
->code_factor
;
7558 if (opa
>= (unsigned int) fc
->ncols
)
7559 reg_prefix
= bad_reg
;
7560 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7561 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7562 reg_prefix
, regname (opa
, 0),
7563 roffs
* fc
->data_factor
);
7564 if (*reg_prefix
== '\0')
7566 fc
->col_type
[opa
] = DW_CFA_offset
;
7567 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
7571 case DW_CFA_restore
:
7572 if (opa
>= (unsigned int) fc
->ncols
)
7573 reg_prefix
= bad_reg
;
7574 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7575 printf (" DW_CFA_restore: %s%s\n",
7576 reg_prefix
, regname (opa
, 0));
7577 if (*reg_prefix
!= '\0')
7580 if (opa
>= (unsigned int) cie
->ncols
7581 || (do_debug_frames_interp
7582 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
7584 fc
->col_type
[opa
] = DW_CFA_undefined
;
7585 fc
->col_offset
[opa
] = 0;
7589 fc
->col_type
[opa
] = cie
->col_type
[opa
];
7590 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
7594 case DW_CFA_set_loc
:
7595 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
7596 if (do_debug_frames_interp
)
7597 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7599 printf (" DW_CFA_set_loc: %s\n",
7600 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
7604 case DW_CFA_advance_loc1
:
7605 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
7606 if (do_debug_frames_interp
)
7607 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7609 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7610 (unsigned long) (ofs
* fc
->code_factor
),
7611 dwarf_vmatoa_1 (NULL
,
7612 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7614 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7617 case DW_CFA_advance_loc2
:
7618 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
7619 if (do_debug_frames_interp
)
7620 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7622 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7623 (unsigned long) (ofs
* fc
->code_factor
),
7624 dwarf_vmatoa_1 (NULL
,
7625 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7627 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7630 case DW_CFA_advance_loc4
:
7631 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
7632 if (do_debug_frames_interp
)
7633 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7635 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7636 (unsigned long) (ofs
* fc
->code_factor
),
7637 dwarf_vmatoa_1 (NULL
,
7638 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7640 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7643 case DW_CFA_offset_extended
:
7646 if (reg
>= (unsigned int) fc
->ncols
)
7647 reg_prefix
= bad_reg
;
7648 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7649 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7650 reg_prefix
, regname (reg
, 0),
7651 roffs
* fc
->data_factor
);
7652 if (*reg_prefix
== '\0')
7654 fc
->col_type
[reg
] = DW_CFA_offset
;
7655 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
7659 case DW_CFA_val_offset
:
7662 if (reg
>= (unsigned int) fc
->ncols
)
7663 reg_prefix
= bad_reg
;
7664 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7665 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7666 reg_prefix
, regname (reg
, 0),
7667 roffs
* fc
->data_factor
);
7668 if (*reg_prefix
== '\0')
7670 fc
->col_type
[reg
] = DW_CFA_val_offset
;
7671 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
7675 case DW_CFA_restore_extended
:
7677 if (reg
>= (unsigned int) fc
->ncols
)
7678 reg_prefix
= bad_reg
;
7679 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7680 printf (" DW_CFA_restore_extended: %s%s\n",
7681 reg_prefix
, regname (reg
, 0));
7682 if (*reg_prefix
!= '\0')
7685 if (reg
>= (unsigned int) cie
->ncols
)
7687 fc
->col_type
[reg
] = DW_CFA_undefined
;
7688 fc
->col_offset
[reg
] = 0;
7692 fc
->col_type
[reg
] = cie
->col_type
[reg
];
7693 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
7697 case DW_CFA_undefined
:
7699 if (reg
>= (unsigned int) fc
->ncols
)
7700 reg_prefix
= bad_reg
;
7701 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7702 printf (" DW_CFA_undefined: %s%s\n",
7703 reg_prefix
, regname (reg
, 0));
7704 if (*reg_prefix
== '\0')
7706 fc
->col_type
[reg
] = DW_CFA_undefined
;
7707 fc
->col_offset
[reg
] = 0;
7711 case DW_CFA_same_value
:
7713 if (reg
>= (unsigned int) fc
->ncols
)
7714 reg_prefix
= bad_reg
;
7715 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7716 printf (" DW_CFA_same_value: %s%s\n",
7717 reg_prefix
, regname (reg
, 0));
7718 if (*reg_prefix
== '\0')
7720 fc
->col_type
[reg
] = DW_CFA_same_value
;
7721 fc
->col_offset
[reg
] = 0;
7725 case DW_CFA_register
:
7728 if (reg
>= (unsigned int) fc
->ncols
)
7729 reg_prefix
= bad_reg
;
7730 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7732 printf (" DW_CFA_register: %s%s in ",
7733 reg_prefix
, regname (reg
, 0));
7734 puts (regname (roffs
, 0));
7736 if (*reg_prefix
== '\0')
7738 fc
->col_type
[reg
] = DW_CFA_register
;
7739 fc
->col_offset
[reg
] = roffs
;
7743 case DW_CFA_remember_state
:
7744 if (! do_debug_frames_interp
)
7745 printf (" DW_CFA_remember_state\n");
7746 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7747 rs
->cfa_offset
= fc
->cfa_offset
;
7748 rs
->cfa_reg
= fc
->cfa_reg
;
7750 rs
->cfa_exp
= fc
->cfa_exp
;
7751 rs
->ncols
= fc
->ncols
;
7752 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
7753 sizeof (* rs
->col_type
));
7754 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
7755 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
7756 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
7757 rs
->next
= remembered_state
;
7758 remembered_state
= rs
;
7761 case DW_CFA_restore_state
:
7762 if (! do_debug_frames_interp
)
7763 printf (" DW_CFA_restore_state\n");
7764 rs
= remembered_state
;
7767 remembered_state
= rs
->next
;
7768 fc
->cfa_offset
= rs
->cfa_offset
;
7769 fc
->cfa_reg
= rs
->cfa_reg
;
7771 fc
->cfa_exp
= rs
->cfa_exp
;
7772 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
7774 warn (_("Invalid column number in saved frame state\n"));
7778 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
7779 memcpy (fc
->col_offset
, rs
->col_offset
,
7780 rs
->ncols
* sizeof (* rs
->col_offset
));
7781 free (rs
->col_type
);
7782 free (rs
->col_offset
);
7785 else if (do_debug_frames_interp
)
7786 printf ("Mismatched DW_CFA_restore_state\n");
7789 case DW_CFA_def_cfa
:
7790 READ_SLEB (fc
->cfa_reg
);
7791 READ_ULEB (fc
->cfa_offset
);
7793 if (! do_debug_frames_interp
)
7794 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7795 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
7798 case DW_CFA_def_cfa_register
:
7799 READ_SLEB (fc
->cfa_reg
);
7801 if (! do_debug_frames_interp
)
7802 printf (" DW_CFA_def_cfa_register: %s\n",
7803 regname (fc
->cfa_reg
, 0));
7806 case DW_CFA_def_cfa_offset
:
7807 READ_ULEB (fc
->cfa_offset
);
7808 if (! do_debug_frames_interp
)
7809 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
7813 if (! do_debug_frames_interp
)
7814 printf (" DW_CFA_nop\n");
7817 case DW_CFA_def_cfa_expression
:
7819 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
7821 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
7824 if (! do_debug_frames_interp
)
7826 printf (" DW_CFA_def_cfa_expression (");
7827 decode_location_expression (start
, eh_addr_size
, 0, -1,
7835 case DW_CFA_expression
:
7838 if (reg
>= (unsigned int) fc
->ncols
)
7839 reg_prefix
= bad_reg
;
7840 /* PR 17512: file: 069-133014-0.006. */
7841 /* PR 17512: file: 98c02eb4. */
7843 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
7845 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
7848 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7850 printf (" DW_CFA_expression: %s%s (",
7851 reg_prefix
, regname (reg
, 0));
7852 decode_location_expression (start
, eh_addr_size
, 0, -1,
7856 if (*reg_prefix
== '\0')
7857 fc
->col_type
[reg
] = DW_CFA_expression
;
7861 case DW_CFA_val_expression
:
7864 if (reg
>= (unsigned int) fc
->ncols
)
7865 reg_prefix
= bad_reg
;
7867 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
7869 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
7872 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7874 printf (" DW_CFA_val_expression: %s%s (",
7875 reg_prefix
, regname (reg
, 0));
7876 decode_location_expression (start
, eh_addr_size
, 0, -1,
7880 if (*reg_prefix
== '\0')
7881 fc
->col_type
[reg
] = DW_CFA_val_expression
;
7885 case DW_CFA_offset_extended_sf
:
7888 if (frame_need_space (fc
, reg
) < 0)
7889 reg_prefix
= bad_reg
;
7890 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7891 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7892 reg_prefix
, regname (reg
, 0),
7893 (long)(l
* fc
->data_factor
));
7894 if (*reg_prefix
== '\0')
7896 fc
->col_type
[reg
] = DW_CFA_offset
;
7897 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
7901 case DW_CFA_val_offset_sf
:
7904 if (frame_need_space (fc
, reg
) < 0)
7905 reg_prefix
= bad_reg
;
7906 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7907 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
7908 reg_prefix
, regname (reg
, 0),
7909 (long)(l
* fc
->data_factor
));
7910 if (*reg_prefix
== '\0')
7912 fc
->col_type
[reg
] = DW_CFA_val_offset
;
7913 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
7917 case DW_CFA_def_cfa_sf
:
7918 READ_SLEB (fc
->cfa_reg
);
7919 READ_ULEB (fc
->cfa_offset
);
7920 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
7922 if (! do_debug_frames_interp
)
7923 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
7924 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
7927 case DW_CFA_def_cfa_offset_sf
:
7928 READ_ULEB (fc
->cfa_offset
);
7929 fc
->cfa_offset
*= fc
->data_factor
;
7930 if (! do_debug_frames_interp
)
7931 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
7934 case DW_CFA_MIPS_advance_loc8
:
7935 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
7936 if (do_debug_frames_interp
)
7937 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7939 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
7940 (unsigned long) (ofs
* fc
->code_factor
),
7941 dwarf_vmatoa_1 (NULL
,
7942 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7944 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7947 case DW_CFA_GNU_window_save
:
7948 if (! do_debug_frames_interp
)
7949 printf (" DW_CFA_GNU_window_save\n");
7952 case DW_CFA_GNU_args_size
:
7954 if (! do_debug_frames_interp
)
7955 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
7958 case DW_CFA_GNU_negative_offset_extended
:
7962 if (frame_need_space (fc
, reg
) < 0)
7963 reg_prefix
= bad_reg
;
7964 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7965 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
7966 reg_prefix
, regname (reg
, 0),
7967 (long)(l
* fc
->data_factor
));
7968 if (*reg_prefix
== '\0')
7970 fc
->col_type
[reg
] = DW_CFA_offset
;
7971 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
7976 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
7977 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
7979 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
7984 /* Interpret the CFA - as long as it is not completely full of NOPs. */
7985 if (do_debug_frames_interp
&& ! all_nops
)
7986 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7989 eh_addr_size
= saved_eh_addr_size
;
8000 display_debug_names (struct dwarf_section
*section
, void *file
)
8002 unsigned char *hdrptr
= section
->start
;
8003 dwarf_vma unit_length
;
8004 unsigned char *unit_start
;
8005 const unsigned char *const section_end
= section
->start
+ section
->size
;
8006 unsigned char *unit_end
;
8008 printf (_("Contents of the %s section:\n"), section
->name
);
8010 load_debug_section (str
, file
);
8012 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
8014 unsigned int offset_size
;
8015 uint16_t dwarf_version
, padding
;
8016 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
8017 uint32_t bucket_count
, name_count
, abbrev_table_size
;
8018 uint32_t augmentation_string_size
;
8021 unit_start
= hdrptr
;
8023 /* Get and check the length of the block. */
8024 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
8026 if (unit_length
== 0xffffffff)
8028 /* This section is 64-bit DWARF. */
8029 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
8034 unit_end
= hdrptr
+ unit_length
;
8036 if ((hdrptr
- section
->start
) + unit_length
> section
->size
)
8038 warn (_("The length field (0x%lx) for unit 0x%lx in the debug_names "
8039 "header is wrong - the section is too small\n"),
8040 (long) unit_length
, (long) (unit_start
- section
->start
));
8044 /* Get and check the version number. */
8045 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
8046 printf (_("Version %ld\n"), (long) dwarf_version
);
8048 /* Prior versions did not exist, and future versions may not be
8049 backwards compatible. */
8050 if (dwarf_version
!= 5)
8052 warn (_("Only DWARF version 5 .debug_names "
8053 "is currently supported.\n"));
8057 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
8059 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8062 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
8063 if (comp_unit_count
== 0)
8064 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8066 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
8067 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
8068 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
8069 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
8070 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
8072 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
8073 if (augmentation_string_size
% 4 != 0)
8075 warn (_("Augmentation string length %u must be rounded up "
8076 "to a multiple of 4 in .debug_names.\n"),
8077 augmentation_string_size
);
8078 augmentation_string_size
+= (-augmentation_string_size
) & 3;
8080 printf (_("Augmentation string:"));
8081 for (i
= 0; i
< augmentation_string_size
; i
++)
8085 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
8086 printf (" %02x", uc
);
8091 printf (_("CU table:\n"));
8092 for (i
= 0; i
< comp_unit_count
; i
++)
8096 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
8097 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
8101 printf (_("TU table:\n"));
8102 for (i
= 0; i
< local_type_unit_count
; i
++)
8106 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
8107 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
8111 printf (_("Foreign TU table:\n"));
8112 for (i
= 0; i
< foreign_type_unit_count
; i
++)
8116 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
8117 printf (_("[%3u] "), i
);
8118 print_dwarf_vma (signature
, 8);
8123 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
8124 hdrptr
+= bucket_count
* sizeof (uint32_t);
8125 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
8126 hdrptr
+= name_count
* sizeof (uint32_t);
8127 unsigned char *const name_table_string_offsets
= hdrptr
;
8128 hdrptr
+= name_count
* offset_size
;
8129 unsigned char *const name_table_entry_offsets
= hdrptr
;
8130 hdrptr
+= name_count
* offset_size
;
8131 unsigned char *const abbrev_table
= hdrptr
;
8132 hdrptr
+= abbrev_table_size
;
8133 const unsigned char *const abbrev_table_end
= hdrptr
;
8134 unsigned char *const entry_pool
= hdrptr
;
8135 if (hdrptr
> unit_end
)
8137 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8138 "for unit 0x%lx in the debug_names\n"),
8139 (long) (hdrptr
- section
->start
),
8140 (long) (unit_end
- section
->start
),
8141 (long) (unit_start
- section
->start
));
8145 size_t buckets_filled
= 0;
8147 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
8149 const uint32_t bucket
= hash_table_buckets
[bucketi
];
8154 printf (_("Used %zu of %lu buckets.\n"), buckets_filled
,
8155 (unsigned long) bucket_count
);
8157 uint32_t hash_prev
= 0;
8158 size_t hash_clash_count
= 0;
8159 size_t longest_clash
= 0;
8160 size_t this_length
= 0;
8162 for (hashi
= 0; hashi
< name_count
; hashi
++)
8164 const uint32_t hash_this
= hash_table_hashes
[hashi
];
8168 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
8172 longest_clash
= MAX (longest_clash
, this_length
);
8177 hash_prev
= hash_this
;
8179 printf (_("Out of %lu items there are %zu bucket clashes"
8180 " (longest of %zu entries).\n"),
8181 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
8182 assert (name_count
== buckets_filled
+ hash_clash_count
);
8184 struct abbrev_lookup_entry
8186 dwarf_vma abbrev_tag
;
8187 unsigned char *abbrev_lookup_ptr
;
8189 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
8190 size_t abbrev_lookup_used
= 0;
8191 size_t abbrev_lookup_allocated
= 0;
8193 unsigned char *abbrevptr
= abbrev_table
;
8196 unsigned int bytes_read
;
8197 const dwarf_vma abbrev_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
8199 abbrevptr
+= bytes_read
;
8200 if (abbrev_tag
== 0)
8202 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
8204 abbrev_lookup_allocated
= MAX (0x100,
8205 abbrev_lookup_allocated
* 2);
8206 abbrev_lookup
= xrealloc (abbrev_lookup
,
8207 (abbrev_lookup_allocated
8208 * sizeof (*abbrev_lookup
)));
8210 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
8211 struct abbrev_lookup_entry
*entry
;
8212 for (entry
= abbrev_lookup
;
8213 entry
< abbrev_lookup
+ abbrev_lookup_used
;
8215 if (entry
->abbrev_tag
== abbrev_tag
)
8217 warn (_("Duplicate abbreviation tag %lu "
8218 "in unit 0x%lx in the debug_names\n"),
8219 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
8222 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
8223 entry
->abbrev_tag
= abbrev_tag
;
8224 entry
->abbrev_lookup_ptr
= abbrevptr
;
8226 /* Skip DWARF tag. */
8227 read_uleb128 (abbrevptr
, &bytes_read
, abbrev_table_end
);
8228 abbrevptr
+= bytes_read
;
8231 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
8234 abbrevptr
+= bytes_read
;
8235 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
8237 abbrevptr
+= bytes_read
;
8238 if (xindex
== 0 && form
== 0)
8243 printf (_("\nSymbol table:\n"));
8245 for (namei
= 0; namei
< name_count
; ++namei
)
8247 uint64_t string_offset
, entry_offset
;
8249 SAFE_BYTE_GET (string_offset
,
8250 name_table_string_offsets
+ namei
* offset_size
,
8251 offset_size
, unit_end
);
8252 SAFE_BYTE_GET (entry_offset
,
8253 name_table_entry_offsets
+ namei
* offset_size
,
8254 offset_size
, unit_end
);
8256 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
8257 fetch_indirect_string (string_offset
));
8259 unsigned char *entryptr
= entry_pool
+ entry_offset
;
8261 // We need to scan first whether there is a single or multiple
8262 // entries. TAGNO is -2 for the first entry, it is -1 for the
8263 // initial tag read of the second entry, then it becomes 0 for the
8264 // first entry for real printing etc.
8266 /* Initialize it due to a false compiler warning. */
8267 dwarf_vma second_abbrev_tag
= -1;
8270 unsigned int bytes_read
;
8271 const dwarf_vma abbrev_tag
= read_uleb128 (entryptr
, &bytes_read
,
8273 entryptr
+= bytes_read
;
8276 second_abbrev_tag
= abbrev_tag
;
8278 entryptr
= entry_pool
+ entry_offset
;
8281 if (abbrev_tag
== 0)
8285 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
8286 (unsigned long) abbrev_tag
);
8288 const struct abbrev_lookup_entry
*entry
;
8289 for (entry
= abbrev_lookup
;
8290 entry
< abbrev_lookup
+ abbrev_lookup_used
;
8292 if (entry
->abbrev_tag
== abbrev_tag
)
8294 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
8296 warn (_("Undefined abbreviation tag %lu "
8297 "in unit 0x%lx in the debug_names\n"),
8299 (long) (unit_start
- section
->start
));
8302 abbrevptr
= entry
->abbrev_lookup_ptr
;
8303 const dwarf_vma dwarf_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
8305 abbrevptr
+= bytes_read
;
8307 printf (" %s", get_TAG_name (dwarf_tag
));
8310 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
8313 abbrevptr
+= bytes_read
;
8314 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
8316 abbrevptr
+= bytes_read
;
8317 if (xindex
== 0 && form
== 0)
8321 printf (" %s", get_IDX_name (xindex
));
8322 entryptr
= read_and_display_attr_value (0, form
, 0, entryptr
,
8325 dwarf_version
, NULL
,
8332 printf (_(" <no entries>"));
8336 free (abbrev_lookup
);
8343 display_gdb_index (struct dwarf_section
*section
,
8344 void *file ATTRIBUTE_UNUSED
)
8346 unsigned char *start
= section
->start
;
8348 uint32_t cu_list_offset
, tu_list_offset
;
8349 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
8350 unsigned int cu_list_elements
, tu_list_elements
;
8351 unsigned int address_table_size
, symbol_table_slots
;
8352 unsigned char *cu_list
, *tu_list
;
8353 unsigned char *address_table
, *symbol_table
, *constant_pool
;
8356 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8358 printf (_("Contents of the %s section:\n"), section
->name
);
8360 if (section
->size
< 6 * sizeof (uint32_t))
8362 warn (_("Truncated header in the %s section.\n"), section
->name
);
8366 version
= byte_get_little_endian (start
, 4);
8367 printf (_("Version %ld\n"), (long) version
);
8369 /* Prior versions are obsolete, and future versions may not be
8370 backwards compatible. */
8371 if (version
< 3 || version
> 8)
8373 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
8377 warn (_("The address table data in version 3 may be wrong.\n"));
8379 warn (_("Version 4 does not support case insensitive lookups.\n"));
8381 warn (_("Version 5 does not include inlined functions.\n"));
8383 warn (_("Version 6 does not include symbol attributes.\n"));
8384 /* Version 7 indices generated by Gold have bad type unit references,
8385 PR binutils/15021. But we don't know if the index was generated by
8386 Gold or not, so to avoid worrying users with gdb-generated indices
8387 we say nothing for version 7 here. */
8389 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
8390 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
8391 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
8392 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
8393 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
8395 if (cu_list_offset
> section
->size
8396 || tu_list_offset
> section
->size
8397 || address_table_offset
> section
->size
8398 || symbol_table_offset
> section
->size
8399 || constant_pool_offset
> section
->size
)
8401 warn (_("Corrupt header in the %s section.\n"), section
->name
);
8405 /* PR 17531: file: 418d0a8a. */
8406 if (tu_list_offset
< cu_list_offset
)
8408 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8409 tu_list_offset
, cu_list_offset
);
8413 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
8415 if (address_table_offset
< tu_list_offset
)
8417 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8418 address_table_offset
, tu_list_offset
);
8422 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
8424 /* PR 17531: file: 18a47d3d. */
8425 if (symbol_table_offset
< address_table_offset
)
8427 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
8428 symbol_table_offset
, address_table_offset
);
8432 address_table_size
= symbol_table_offset
- address_table_offset
;
8434 if (constant_pool_offset
< symbol_table_offset
)
8436 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8437 constant_pool_offset
, symbol_table_offset
);
8441 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
8443 cu_list
= start
+ cu_list_offset
;
8444 tu_list
= start
+ tu_list_offset
;
8445 address_table
= start
+ address_table_offset
;
8446 symbol_table
= start
+ symbol_table_offset
;
8447 constant_pool
= start
+ constant_pool_offset
;
8449 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
8451 warn (_("Address table extends beyond end of section.\n"));
8455 printf (_("\nCU table:\n"));
8456 for (i
= 0; i
< cu_list_elements
; i
+= 2)
8458 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
8459 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
8461 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
8462 (unsigned long) cu_offset
,
8463 (unsigned long) (cu_offset
+ cu_length
- 1));
8466 printf (_("\nTU table:\n"));
8467 for (i
= 0; i
< tu_list_elements
; i
+= 3)
8469 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
8470 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
8471 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
8473 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
8474 (unsigned long) tu_offset
,
8475 (unsigned long) type_offset
);
8476 print_dwarf_vma (signature
, 8);
8480 printf (_("\nAddress table:\n"));
8481 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
8484 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
8485 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
8486 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
8488 print_dwarf_vma (low
, 8);
8489 print_dwarf_vma (high
, 8);
8490 printf (_("%lu\n"), (unsigned long) cu_index
);
8493 printf (_("\nSymbol table:\n"));
8494 for (i
= 0; i
< symbol_table_slots
; ++i
)
8496 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
8497 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
8498 uint32_t num_cus
, cu
;
8500 if (name_offset
!= 0
8501 || cu_vector_offset
!= 0)
8504 unsigned char * adr
;
8506 adr
= constant_pool
+ name_offset
;
8507 /* PR 17531: file: 5b7b07ad. */
8508 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
8510 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
8511 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8515 printf ("[%3u] %.*s:", i
,
8516 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
8517 constant_pool
+ name_offset
);
8519 adr
= constant_pool
+ cu_vector_offset
;
8520 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
8522 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
8523 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8524 cu_vector_offset
, i
);
8528 num_cus
= byte_get_little_endian (adr
, 4);
8530 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
8531 if (num_cus
* 4 < num_cus
8532 || adr
>= section
->start
+ section
->size
8533 || adr
< constant_pool
)
8535 printf ("<invalid number of CUs: %d>\n", num_cus
);
8536 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8544 for (j
= 0; j
< num_cus
; ++j
)
8547 gdb_index_symbol_kind kind
;
8549 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
8550 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
8551 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
8552 cu
= GDB_INDEX_CU_VALUE (cu
);
8553 /* Convert to TU number if it's for a type unit. */
8554 if (cu
>= cu_list_elements
/ 2)
8555 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
8556 (unsigned long) (cu
- cu_list_elements
/ 2));
8558 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
8560 printf (" [%s, %s]",
8561 is_static
? _("static") : _("global"),
8562 get_gdb_index_symbol_kind_name (kind
));
8574 /* Pre-allocate enough space for the CU/TU sets needed. */
8577 prealloc_cu_tu_list (unsigned int nshndx
)
8579 if (shndx_pool
== NULL
)
8581 shndx_pool_size
= nshndx
;
8582 shndx_pool_used
= 0;
8583 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
8584 sizeof (unsigned int));
8588 shndx_pool_size
= shndx_pool_used
+ nshndx
;
8589 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
8590 sizeof (unsigned int));
8595 add_shndx_to_cu_tu_entry (unsigned int shndx
)
8597 if (shndx_pool_used
>= shndx_pool_size
)
8599 error (_("Internal error: out of space in the shndx pool.\n"));
8602 shndx_pool
[shndx_pool_used
++] = shndx
;
8606 end_cu_tu_entry (void)
8608 if (shndx_pool_used
>= shndx_pool_size
)
8610 error (_("Internal error: out of space in the shndx pool.\n"));
8613 shndx_pool
[shndx_pool_used
++] = 0;
8616 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8619 get_DW_SECT_short_name (unsigned int dw_sect
)
8621 static char buf
[16];
8629 case DW_SECT_ABBREV
:
8635 case DW_SECT_STR_OFFSETS
:
8637 case DW_SECT_MACINFO
:
8645 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
8649 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
8650 These sections are extensions for Fission.
8651 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
8654 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
8656 unsigned char *phdr
= section
->start
;
8657 unsigned char *limit
= phdr
+ section
->size
;
8658 unsigned char *phash
;
8659 unsigned char *pindex
;
8660 unsigned char *ppool
;
8661 unsigned int version
;
8662 unsigned int ncols
= 0;
8664 unsigned int nslots
;
8667 dwarf_vma signature_high
;
8668 dwarf_vma signature_low
;
8671 /* PR 17512: file: 002-168123-0.004. */
8674 warn (_("Section %s is empty\n"), section
->name
);
8677 /* PR 17512: file: 002-376-0.004. */
8678 if (section
->size
< 24)
8680 warn (_("Section %s is too small to contain a CU/TU header\n"),
8685 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
8687 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
8688 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
8689 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
8692 pindex
= phash
+ nslots
* 8;
8693 ppool
= pindex
+ nslots
* 4;
8695 /* PR 17531: file: 45d69832. */
8696 if (pindex
< phash
|| ppool
< phdr
|| (pindex
== phash
&& nslots
!= 0))
8698 warn (_("Section %s is too small for %d slots\n"),
8699 section
->name
, nslots
);
8705 printf (_("Contents of the %s section:\n\n"), section
->name
);
8706 printf (_(" Version: %d\n"), version
);
8708 printf (_(" Number of columns: %d\n"), ncols
);
8709 printf (_(" Number of used entries: %d\n"), nused
);
8710 printf (_(" Number of slots: %d\n\n"), nslots
);
8713 if (ppool
> limit
|| ppool
< phdr
)
8715 warn (_("Section %s too small for %d hash table entries\n"),
8716 section
->name
, nslots
);
8723 prealloc_cu_tu_list ((limit
- ppool
) / 4);
8724 for (i
= 0; i
< nslots
; i
++)
8726 unsigned char *shndx_list
;
8729 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
8730 if (signature_high
!= 0 || signature_low
!= 0)
8732 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
8733 shndx_list
= ppool
+ j
* 4;
8734 /* PR 17531: file: 705e010d. */
8735 if (shndx_list
< ppool
)
8737 warn (_("Section index pool located before start of section\n"));
8742 printf (_(" [%3d] Signature: 0x%s Sections: "),
8743 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
8744 buf
, sizeof (buf
)));
8747 if (shndx_list
>= limit
)
8749 warn (_("Section %s too small for shndx pool\n"),
8753 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
8757 printf (" %d", shndx
);
8759 add_shndx_to_cu_tu_entry (shndx
);
8771 else if (version
== 2)
8774 unsigned int dw_sect
;
8775 unsigned char *ph
= phash
;
8776 unsigned char *pi
= pindex
;
8777 unsigned char *poffsets
= ppool
+ ncols
* 4;
8778 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
8779 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
8780 bfd_boolean is_tu_index
;
8781 struct cu_tu_set
*this_set
= NULL
;
8783 unsigned char *prow
;
8785 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
8787 /* PR 17531: file: 0dd159bf.
8788 Check for wraparound with an overlarge ncols value. */
8789 if (poffsets
< ppool
|| (unsigned int) ((poffsets
- ppool
) / 4) != ncols
)
8791 warn (_("Overlarge number of columns: %x\n"), ncols
);
8797 warn (_("Section %s too small for offset and size tables\n"),
8804 printf (_(" Offset table\n"));
8805 printf (" slot %-16s ",
8806 is_tu_index
? _("signature") : _("dwo_id"));
8813 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
8819 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
8826 for (j
= 0; j
< ncols
; j
++)
8828 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
8829 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
8834 for (i
= 0; i
< nslots
; i
++)
8836 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
8838 SAFE_BYTE_GET (row
, pi
, 4, limit
);
8841 /* PR 17531: file: a05f6ab3. */
8844 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8850 memcpy (&this_set
[row
- 1].signature
, ph
, sizeof (uint64_t));
8852 prow
= poffsets
+ (row
- 1) * ncols
* 4;
8853 /* PR 17531: file: b8ce60a8. */
8854 if (prow
< poffsets
|| prow
> limit
)
8856 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8862 printf (_(" [%3d] 0x%s"),
8863 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
8864 buf
, sizeof (buf
)));
8865 for (j
= 0; j
< ncols
; j
++)
8867 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
8869 printf (" %8d", val
);
8872 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
8874 /* PR 17531: file: 10796eb3. */
8875 if (dw_sect
>= DW_SECT_MAX
)
8876 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
8878 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
8894 printf (_(" Size table\n"));
8895 printf (" slot %-16s ",
8896 is_tu_index
? _("signature") : _("dwo_id"));
8899 for (j
= 0; j
< ncols
; j
++)
8901 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
8903 printf (" %8s", get_DW_SECT_short_name (val
));
8909 for (i
= 0; i
< nslots
; i
++)
8911 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
8913 SAFE_BYTE_GET (row
, pi
, 4, limit
);
8916 prow
= psizes
+ (row
- 1) * ncols
* 4;
8919 printf (_(" [%3d] 0x%s"),
8920 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
8921 buf
, sizeof (buf
)));
8923 for (j
= 0; j
< ncols
; j
++)
8925 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
8927 printf (" %8d", val
);
8930 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
8931 if (dw_sect
>= DW_SECT_MAX
)
8932 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
8934 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
8946 else if (do_display
)
8947 printf (_(" Unsupported version (%d)\n"), version
);
8955 /* Load the CU and TU indexes if present. This will build a list of
8956 section sets that we can use to associate a .debug_info.dwo section
8957 with its associated .debug_abbrev.dwo section in a .dwp file. */
8960 load_cu_tu_indexes (void *file
)
8962 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
8964 /* If we have already loaded (or tried to load) the CU and TU indexes
8965 then do not bother to repeat the task. */
8966 if (cu_tu_indexes_read
== -1)
8968 cu_tu_indexes_read
= TRUE
;
8970 if (load_debug_section (dwp_cu_index
, file
))
8971 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
8972 cu_tu_indexes_read
= FALSE
;
8974 if (load_debug_section (dwp_tu_index
, file
))
8975 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
8976 cu_tu_indexes_read
= FALSE
;
8979 return (bfd_boolean
) cu_tu_indexes_read
;
8982 /* Find the set of sections that includes section SHNDX. */
8985 find_cu_tu_set (void *file
, unsigned int shndx
)
8989 if (! load_cu_tu_indexes (file
))
8992 /* Find SHNDX in the shndx pool. */
8993 for (i
= 0; i
< shndx_pool_used
; i
++)
8994 if (shndx_pool
[i
] == shndx
)
8997 if (i
>= shndx_pool_used
)
9000 /* Now backup to find the first entry in the set. */
9001 while (i
> 0 && shndx_pool
[i
- 1] != 0)
9004 return shndx_pool
+ i
;
9007 /* Display a .debug_cu_index or .debug_tu_index section. */
9010 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
9012 return process_cu_tu_index (section
, 1);
9016 display_debug_not_supported (struct dwarf_section
*section
,
9017 void *file ATTRIBUTE_UNUSED
)
9019 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9025 /* Like malloc, but takes two parameters like calloc.
9026 Verifies that the first parameter is not too large.
9027 Note: does *not* initialise the allocated memory to zero. */
9029 cmalloc (size_t nmemb
, size_t size
)
9031 /* Check for overflow. */
9032 if (nmemb
>= ~(size_t) 0 / size
)
9035 return xmalloc (nmemb
* size
);
9038 /* Like xmalloc, but takes two parameters like calloc.
9039 Verifies that the first parameter is not too large.
9040 Note: does *not* initialise the allocated memory to zero. */
9042 xcmalloc (size_t nmemb
, size_t size
)
9044 /* Check for overflow. */
9045 if (nmemb
>= ~(size_t) 0 / size
)
9048 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9053 return xmalloc (nmemb
* size
);
9056 /* Like xrealloc, but takes three parameters.
9057 Verifies that the second parameter is not too large.
9058 Note: does *not* initialise any new memory to zero. */
9060 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
9062 /* Check for overflow. */
9063 if (nmemb
>= ~(size_t) 0 / size
)
9066 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9071 return xrealloc (ptr
, nmemb
* size
);
9074 /* Like xcalloc, but verifies that the first parameter is not too large. */
9076 xcalloc2 (size_t nmemb
, size_t size
)
9078 /* Check for overflow. */
9079 if (nmemb
>= ~(size_t) 0 / size
)
9082 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9087 return xcalloc (nmemb
, size
);
9091 free_debug_memory (void)
9097 for (i
= 0; i
< max
; i
++)
9098 free_debug_section ((enum dwarf_section_display_enum
) i
);
9100 if (debug_information
!= NULL
)
9102 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
9104 for (i
= 0; i
< num_debug_info_entries
; i
++)
9106 if (!debug_information
[i
].max_loc_offsets
)
9108 free (debug_information
[i
].loc_offsets
);
9109 free (debug_information
[i
].have_frame_base
);
9111 if (!debug_information
[i
].max_range_lists
)
9112 free (debug_information
[i
].range_lists
);
9115 free (debug_information
);
9116 debug_information
= NULL
;
9117 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
9122 dwarf_select_sections_by_names (const char *names
)
9126 const char * option
;
9130 debug_dump_long_opts
;
9132 static const debug_dump_long_opts opts_table
[] =
9134 /* Please keep this table alpha- sorted. */
9135 { "Ranges", & do_debug_ranges
, 1 },
9136 { "abbrev", & do_debug_abbrevs
, 1 },
9137 { "addr", & do_debug_addr
, 1 },
9138 { "aranges", & do_debug_aranges
, 1 },
9139 { "cu_index", & do_debug_cu_index
, 1 },
9140 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
9141 { "frames", & do_debug_frames
, 1 },
9142 { "frames-interp", & do_debug_frames_interp
, 1 },
9143 /* The special .gdb_index section. */
9144 { "gdb_index", & do_gdb_index
, 1 },
9145 { "info", & do_debug_info
, 1 },
9146 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
9147 { "loc", & do_debug_loc
, 1 },
9148 { "macro", & do_debug_macinfo
, 1 },
9149 { "pubnames", & do_debug_pubnames
, 1 },
9150 { "pubtypes", & do_debug_pubtypes
, 1 },
9151 /* This entry is for compatibility
9152 with earlier versions of readelf. */
9153 { "ranges", & do_debug_aranges
, 1 },
9154 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
9155 { "str", & do_debug_str
, 1 },
9156 /* These trace_* sections are used by Itanium VMS. */
9157 { "trace_abbrev", & do_trace_abbrevs
, 1 },
9158 { "trace_aranges", & do_trace_aranges
, 1 },
9159 { "trace_info", & do_trace_info
, 1 },
9168 const debug_dump_long_opts
* entry
;
9170 for (entry
= opts_table
; entry
->option
; entry
++)
9172 size_t len
= strlen (entry
->option
);
9174 if (strncmp (p
, entry
->option
, len
) == 0
9175 && (p
[len
] == ',' || p
[len
] == '\0'))
9177 * entry
->variable
|= entry
->val
;
9179 /* The --debug-dump=frames-interp option also
9180 enables the --debug-dump=frames option. */
9181 if (do_debug_frames_interp
)
9182 do_debug_frames
= 1;
9189 if (entry
->option
== NULL
)
9191 warn (_("Unrecognized debug option '%s'\n"), p
);
9192 p
= strchr (p
, ',');
9203 dwarf_select_sections_by_letters (const char *letters
)
9205 unsigned int lindex
= 0;
9207 while (letters
[lindex
])
9208 switch (letters
[lindex
++])
9215 do_debug_abbrevs
= 1;
9219 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
9223 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
9227 do_debug_pubnames
= 1;
9231 do_debug_pubtypes
= 1;
9235 do_debug_aranges
= 1;
9239 do_debug_ranges
= 1;
9243 do_debug_frames_interp
= 1;
9246 do_debug_frames
= 1;
9250 do_debug_macinfo
= 1;
9262 warn (_("Unrecognized debug option '%s'\n"), letters
);
9268 dwarf_select_sections_all (void)
9271 do_debug_abbrevs
= 1;
9272 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
9273 do_debug_pubnames
= 1;
9274 do_debug_pubtypes
= 1;
9275 do_debug_aranges
= 1;
9276 do_debug_ranges
= 1;
9277 do_debug_frames
= 1;
9278 do_debug_macinfo
= 1;
9283 do_trace_abbrevs
= 1;
9284 do_trace_aranges
= 1;
9286 do_debug_cu_index
= 1;
9289 struct dwarf_section_display debug_displays
[] =
9291 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9292 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
9293 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9294 display_debug_aranges
, &do_debug_aranges
, TRUE
},
9295 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9296 display_debug_frames
, &do_debug_frames
, TRUE
},
9297 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
9298 display_debug_info
, &do_debug_info
, TRUE
},
9299 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9300 display_debug_lines
, &do_debug_lines
, TRUE
},
9301 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9302 display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
9303 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9304 display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
9305 { { ".eh_frame", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9306 display_debug_frames
, &do_debug_frames
, TRUE
},
9307 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9308 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
9309 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9310 display_debug_macro
, &do_debug_macinfo
, TRUE
},
9311 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9312 display_debug_str
, &do_debug_str
, FALSE
},
9313 { { ".debug_line_str", ".zdebug_line_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9314 display_debug_str
, &do_debug_str
, FALSE
},
9315 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9316 display_debug_loc
, &do_debug_loc
, TRUE
},
9317 { { ".debug_loclists", ".zdebug_loclists", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9318 display_debug_loc
, &do_debug_loc
, TRUE
},
9319 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9320 display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
9321 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9322 display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
9323 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9324 display_debug_ranges
, &do_debug_ranges
, TRUE
},
9325 { { ".debug_rnglists", ".zdebug_rnglists", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9326 display_debug_ranges
, &do_debug_ranges
, TRUE
},
9327 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9328 display_debug_not_supported
, NULL
, FALSE
},
9329 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9330 display_debug_not_supported
, NULL
, FALSE
},
9331 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
9332 display_debug_types
, &do_debug_info
, TRUE
},
9333 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9334 display_debug_not_supported
, NULL
, FALSE
},
9335 { { ".gdb_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9336 display_gdb_index
, &do_gdb_index
, FALSE
},
9337 { { ".debug_names", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9338 display_debug_names
, &do_gdb_index
, FALSE
},
9339 { { ".trace_info", "", NULL
, NULL
, 0, 0, trace_abbrev
, NULL
, 0, NULL
},
9340 display_trace_info
, &do_trace_info
, TRUE
},
9341 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9342 display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
9343 { { ".trace_aranges", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9344 display_debug_aranges
, &do_trace_aranges
, FALSE
},
9345 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
9346 display_debug_info
, &do_debug_info
, TRUE
},
9347 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9348 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
9349 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
9350 display_debug_types
, &do_debug_info
, TRUE
},
9351 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9352 display_debug_lines
, &do_debug_lines
, TRUE
},
9353 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9354 display_debug_loc
, &do_debug_loc
, TRUE
},
9355 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9356 display_debug_macro
, &do_debug_macinfo
, TRUE
},
9357 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9358 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
9359 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9360 display_debug_str
, &do_debug_str
, TRUE
},
9361 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9362 display_debug_str_offsets
, NULL
, FALSE
},
9363 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9364 display_debug_str_offsets
, NULL
, FALSE
},
9365 { { ".debug_addr", ".zdebug_addr", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9366 display_debug_addr
, &do_debug_addr
, TRUE
},
9367 { { ".debug_cu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9368 display_cu_index
, &do_debug_cu_index
, FALSE
},
9369 { { ".debug_tu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9370 display_cu_index
, &do_debug_cu_index
, FALSE
},
9373 /* A static assertion. */
9374 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];