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 if (tag
>= DW_TAG_lo_user
&& tag
<= DW_TAG_hi_user
)
973 snprintf (buffer
, sizeof (buffer
), _("User TAG value: %#lx"), tag
);
975 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %#lx"), tag
);
983 get_FORM_name (unsigned long form
)
988 return "DW_FORM value: 0";
990 name
= get_DW_FORM_name (form
);
993 static char buffer
[100];
995 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
1003 get_IDX_name (unsigned long idx
)
1005 const char *name
= get_DW_IDX_name ((unsigned int) idx
);
1009 static char buffer
[100];
1011 snprintf (buffer
, sizeof (buffer
), _("Unknown IDX value: %lx"), idx
);
1018 static unsigned char *
1019 display_block (unsigned char *data
,
1021 const unsigned char * const end
, char delimiter
)
1025 printf (_("%c%s byte block: "), delimiter
, dwarf_vmatoa ("u", length
));
1027 return (unsigned char *) end
;
1029 maxlen
= (dwarf_vma
) (end
- data
);
1030 length
= length
> maxlen
? maxlen
: length
;
1033 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
1039 decode_location_expression (unsigned char * data
,
1040 unsigned int pointer_size
,
1041 unsigned int offset_size
,
1044 dwarf_vma cu_offset
,
1045 struct dwarf_section
* section
)
1048 unsigned int bytes_read
;
1050 dwarf_signed_vma svalue
;
1051 unsigned char *end
= data
+ length
;
1052 int need_frame_base
= 0;
1061 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1062 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
1065 printf ("DW_OP_deref");
1068 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1069 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
1072 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
1073 printf ("DW_OP_const1s: %ld", (long) svalue
);
1076 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1077 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
1080 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1081 printf ("DW_OP_const2s: %ld", (long) svalue
);
1084 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1085 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
1088 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1089 printf ("DW_OP_const4s: %ld", (long) svalue
);
1092 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1093 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
1094 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1095 printf ("%lu", (unsigned long) uvalue
);
1098 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1099 printf ("DW_OP_const8s: %ld ", (long) svalue
);
1100 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1101 printf ("%ld", (long) svalue
);
1104 printf ("DW_OP_constu: %s",
1105 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1109 printf ("DW_OP_consts: %s",
1110 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1114 printf ("DW_OP_dup");
1117 printf ("DW_OP_drop");
1120 printf ("DW_OP_over");
1123 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1124 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
1127 printf ("DW_OP_swap");
1130 printf ("DW_OP_rot");
1133 printf ("DW_OP_xderef");
1136 printf ("DW_OP_abs");
1139 printf ("DW_OP_and");
1142 printf ("DW_OP_div");
1145 printf ("DW_OP_minus");
1148 printf ("DW_OP_mod");
1151 printf ("DW_OP_mul");
1154 printf ("DW_OP_neg");
1157 printf ("DW_OP_not");
1160 printf ("DW_OP_or");
1163 printf ("DW_OP_plus");
1165 case DW_OP_plus_uconst
:
1166 printf ("DW_OP_plus_uconst: %s",
1167 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1171 printf ("DW_OP_shl");
1174 printf ("DW_OP_shr");
1177 printf ("DW_OP_shra");
1180 printf ("DW_OP_xor");
1183 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1184 printf ("DW_OP_bra: %ld", (long) svalue
);
1187 printf ("DW_OP_eq");
1190 printf ("DW_OP_ge");
1193 printf ("DW_OP_gt");
1196 printf ("DW_OP_le");
1199 printf ("DW_OP_lt");
1202 printf ("DW_OP_ne");
1205 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1206 printf ("DW_OP_skip: %ld", (long) svalue
);
1241 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1276 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1277 regname (op
- DW_OP_reg0
, 1));
1312 printf ("DW_OP_breg%d (%s): %s",
1314 regname (op
- DW_OP_breg0
, 1),
1315 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1320 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1322 printf ("DW_OP_regx: %s (%s)",
1323 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1326 need_frame_base
= 1;
1327 printf ("DW_OP_fbreg: %s",
1328 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1332 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1334 printf ("DW_OP_bregx: %s (%s) %s",
1335 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1336 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1340 printf ("DW_OP_piece: %s",
1341 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1344 case DW_OP_deref_size
:
1345 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1346 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1348 case DW_OP_xderef_size
:
1349 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1350 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1353 printf ("DW_OP_nop");
1356 /* DWARF 3 extensions. */
1357 case DW_OP_push_object_address
:
1358 printf ("DW_OP_push_object_address");
1361 /* XXX: Strictly speaking for 64-bit DWARF3 files
1362 this ought to be an 8-byte wide computation. */
1363 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1364 printf ("DW_OP_call2: <0x%s>",
1365 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1368 /* XXX: Strictly speaking for 64-bit DWARF3 files
1369 this ought to be an 8-byte wide computation. */
1370 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1371 printf ("DW_OP_call4: <0x%s>",
1372 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1374 case DW_OP_call_ref
:
1375 /* XXX: Strictly speaking for 64-bit DWARF3 files
1376 this ought to be an 8-byte wide computation. */
1377 if (dwarf_version
== -1)
1379 printf (_("(DW_OP_call_ref in frame info)"));
1380 /* No way to tell where the next op is, so just bail. */
1381 return need_frame_base
;
1383 if (dwarf_version
== 2)
1385 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1389 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1391 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1393 case DW_OP_form_tls_address
:
1394 printf ("DW_OP_form_tls_address");
1396 case DW_OP_call_frame_cfa
:
1397 printf ("DW_OP_call_frame_cfa");
1399 case DW_OP_bit_piece
:
1400 printf ("DW_OP_bit_piece: ");
1401 printf (_("size: %s "),
1402 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1404 printf (_("offset: %s "),
1405 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1409 /* DWARF 4 extensions. */
1410 case DW_OP_stack_value
:
1411 printf ("DW_OP_stack_value");
1414 case DW_OP_implicit_value
:
1415 printf ("DW_OP_implicit_value");
1416 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1418 data
= display_block (data
, uvalue
, end
, ' ');
1421 /* GNU extensions. */
1422 case DW_OP_GNU_push_tls_address
:
1423 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1425 case DW_OP_GNU_uninit
:
1426 printf ("DW_OP_GNU_uninit");
1427 /* FIXME: Is there data associated with this OP ? */
1429 case DW_OP_GNU_encoded_addr
:
1436 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1438 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1439 print_dwarf_vma (addr
, pointer_size
);
1442 case DW_OP_implicit_pointer
:
1443 case DW_OP_GNU_implicit_pointer
:
1444 /* XXX: Strictly speaking for 64-bit DWARF3 files
1445 this ought to be an 8-byte wide computation. */
1446 if (dwarf_version
== -1)
1448 printf (_("(%s in frame info)"),
1449 (op
== DW_OP_implicit_pointer
1450 ? "DW_OP_implicit_pointer"
1451 : "DW_OP_GNU_implicit_pointer"));
1452 /* No way to tell where the next op is, so just bail. */
1453 return need_frame_base
;
1455 if (dwarf_version
== 2)
1457 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1461 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1463 printf ("%s: <0x%s> %s",
1464 (op
== DW_OP_implicit_pointer
1465 ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
1466 dwarf_vmatoa ("x", uvalue
),
1467 dwarf_vmatoa ("d", read_sleb128 (data
,
1468 &bytes_read
, end
)));
1471 case DW_OP_entry_value
:
1472 case DW_OP_GNU_entry_value
:
1473 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1475 /* PR 17531: file: 0cc9cd00. */
1476 if (uvalue
> (dwarf_vma
) (end
- data
))
1477 uvalue
= end
- data
;
1478 printf ("%s: (", (op
== DW_OP_entry_value
? "DW_OP_entry_value"
1479 : "DW_OP_GNU_entry_value"));
1480 if (decode_location_expression (data
, pointer_size
, offset_size
,
1481 dwarf_version
, uvalue
,
1482 cu_offset
, section
))
1483 need_frame_base
= 1;
1489 case DW_OP_const_type
:
1490 case DW_OP_GNU_const_type
:
1491 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1493 printf ("%s: <0x%s> ",
1494 (op
== DW_OP_const_type
? "DW_OP_const_type"
1495 : "DW_OP_GNU_const_type"),
1496 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1497 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1498 data
= display_block (data
, uvalue
, end
, ' ');
1500 case DW_OP_regval_type
:
1501 case DW_OP_GNU_regval_type
:
1502 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1504 printf ("%s: %s (%s)",
1505 (op
== DW_OP_regval_type
? "DW_OP_regval_type"
1506 : "DW_OP_GNU_regval_type"),
1507 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1508 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1510 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1512 case DW_OP_deref_type
:
1513 case DW_OP_GNU_deref_type
:
1514 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1516 (op
== DW_OP_deref_type
? "DW_OP_deref_type"
1517 : "DW_OP_GNU_deref_type"),
1519 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1521 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1524 case DW_OP_GNU_convert
:
1525 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1527 printf ("%s <0x%s>",
1528 (op
== DW_OP_convert
? "DW_OP_convert" : "DW_OP_GNU_convert"),
1529 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1531 case DW_OP_reinterpret
:
1532 case DW_OP_GNU_reinterpret
:
1533 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1535 printf ("%s <0x%s>",
1536 (op
== DW_OP_reinterpret
? "DW_OP_reinterpret"
1537 : "DW_OP_GNU_reinterpret"),
1538 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1540 case DW_OP_GNU_parameter_ref
:
1541 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1542 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1543 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1545 case DW_OP_GNU_addr_index
:
1546 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1548 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1550 case DW_OP_GNU_const_index
:
1551 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1553 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1556 /* HP extensions. */
1557 case DW_OP_HP_is_value
:
1558 printf ("DW_OP_HP_is_value");
1559 /* FIXME: Is there data associated with this OP ? */
1561 case DW_OP_HP_fltconst4
:
1562 printf ("DW_OP_HP_fltconst4");
1563 /* FIXME: Is there data associated with this OP ? */
1565 case DW_OP_HP_fltconst8
:
1566 printf ("DW_OP_HP_fltconst8");
1567 /* FIXME: Is there data associated with this OP ? */
1569 case DW_OP_HP_mod_range
:
1570 printf ("DW_OP_HP_mod_range");
1571 /* FIXME: Is there data associated with this OP ? */
1573 case DW_OP_HP_unmod_range
:
1574 printf ("DW_OP_HP_unmod_range");
1575 /* FIXME: Is there data associated with this OP ? */
1578 printf ("DW_OP_HP_tls");
1579 /* FIXME: Is there data associated with this OP ? */
1582 /* PGI (STMicroelectronics) extensions. */
1583 case DW_OP_PGI_omp_thread_num
:
1584 /* Pushes the thread number for the current thread as it would be
1585 returned by the standard OpenMP library function:
1586 omp_get_thread_num(). The "current thread" is the thread for
1587 which the expression is being evaluated. */
1588 printf ("DW_OP_PGI_omp_thread_num");
1592 if (op
>= DW_OP_lo_user
1593 && op
<= DW_OP_hi_user
)
1594 printf (_("(User defined location op 0x%x)"), op
);
1596 printf (_("(Unknown location op 0x%x)"), op
);
1597 /* No way to tell where the next op is, so just bail. */
1598 return need_frame_base
;
1601 /* Separate the ops. */
1606 return need_frame_base
;
1609 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1610 This is used for DWARF package files. */
1612 static struct cu_tu_set
*
1613 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1615 struct cu_tu_set
*p
;
1617 unsigned int dw_sect
;
1623 dw_sect
= DW_SECT_TYPES
;
1629 dw_sect
= DW_SECT_INFO
;
1633 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1641 /* Add INC to HIGH_BITS:LOW_BITS. */
1643 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1645 dwarf_vma tmp
= * low_bits
;
1649 /* FIXME: There is probably a better way of handling this:
1651 We need to cope with dwarf_vma being a 32-bit or 64-bit
1652 type. Plus regardless of its size LOW_BITS is meant to
1653 only hold 32-bits, so if there is overflow or wrap around
1654 we must propagate into HIGH_BITS. */
1655 if (tmp
< * low_bits
)
1659 else if (sizeof (tmp
) > 8
1669 static unsigned char *
1670 read_and_display_attr_value (unsigned long attribute
,
1672 dwarf_signed_vma implicit_const
,
1673 unsigned char * data
,
1674 unsigned char * end
,
1675 dwarf_vma cu_offset
,
1676 dwarf_vma pointer_size
,
1677 dwarf_vma offset_size
,
1679 debug_info
* debug_info_p
,
1681 struct dwarf_section
* section
,
1682 struct cu_tu_set
* this_set
, char delimiter
)
1684 dwarf_vma uvalue
= 0;
1685 unsigned char *block_start
= NULL
;
1686 unsigned char * orig_data
= data
;
1687 unsigned int bytes_read
;
1689 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
1691 warn (_("Corrupt attribute\n"));
1700 case DW_FORM_ref_addr
:
1701 if (dwarf_version
== 2)
1702 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1703 else if (dwarf_version
== 3 || dwarf_version
== 4)
1704 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1706 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1711 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1715 case DW_FORM_line_strp
:
1716 case DW_FORM_sec_offset
:
1717 case DW_FORM_GNU_ref_alt
:
1718 case DW_FORM_GNU_strp_alt
:
1719 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1722 case DW_FORM_flag_present
:
1729 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1734 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1739 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1743 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1747 case DW_FORM_GNU_str_index
:
1748 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1752 case DW_FORM_ref_udata
:
1754 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1758 case DW_FORM_indirect
:
1759 form
= read_uleb128 (data
, & bytes_read
, end
);
1762 printf ("%c%s", delimiter
, get_FORM_name (form
));
1763 if (form
== DW_FORM_implicit_const
)
1765 implicit_const
= read_sleb128 (data
, & bytes_read
, end
);
1768 return read_and_display_attr_value (attribute
, form
, implicit_const
, data
,
1769 end
, cu_offset
, pointer_size
,
1770 offset_size
, dwarf_version
,
1771 debug_info_p
, do_loc
,
1772 section
, this_set
, delimiter
);
1773 case DW_FORM_GNU_addr_index
:
1774 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1781 case DW_FORM_ref_addr
:
1783 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1786 case DW_FORM_GNU_ref_alt
:
1788 printf ("%c<alt 0x%s>", delimiter
, dwarf_vmatoa ("x",uvalue
));
1794 case DW_FORM_ref_udata
:
1796 printf ("%c<0x%s>", delimiter
, dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1801 case DW_FORM_sec_offset
:
1803 printf ("%c0x%s", delimiter
, dwarf_vmatoa ("x", uvalue
));
1806 case DW_FORM_flag_present
:
1813 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", uvalue
));
1816 case DW_FORM_implicit_const
:
1818 printf ("%c%s", delimiter
, dwarf_vmatoa ("d", implicit_const
));
1825 dwarf_vma high_bits
;
1829 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1831 if (form
== DW_FORM_ref8
)
1832 add64 (& high_bits
, & utmp
, cu_offset
);
1833 printf ("%c0x%s", delimiter
,
1834 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1837 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1838 && num_debug_info_entries
== 0)
1840 if (sizeof (uvalue
) == 8)
1841 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1843 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1849 case DW_FORM_data16
:
1852 dwarf_vma left_high_bits
, left_low_bits
;
1853 dwarf_vma right_high_bits
, right_low_bits
;
1855 SAFE_BYTE_GET64 (data
, &left_high_bits
, &left_low_bits
, end
);
1856 SAFE_BYTE_GET64 (data
+ 8, &right_high_bits
, &right_low_bits
, end
);
1857 if (byte_get
== byte_get_little_endian
)
1860 left_high_bits
^= right_high_bits
;
1861 right_high_bits
^= left_high_bits
;
1862 left_high_bits
^= right_high_bits
;
1863 left_low_bits
^= right_low_bits
;
1864 right_low_bits
^= left_low_bits
;
1865 left_low_bits
^= right_low_bits
;
1867 printf (" 0x%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x"
1868 "%08" DWARF_VMA_FMT
"x%08" DWARF_VMA_FMT
"x",
1869 left_high_bits
, left_low_bits
, right_high_bits
,
1875 case DW_FORM_string
:
1877 printf ("%c%.*s", delimiter
, (int) (end
- data
), data
);
1878 data
+= strnlen ((char *) data
, end
- data
) + 1;
1882 case DW_FORM_exprloc
:
1883 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1884 block_start
= data
+ bytes_read
;
1885 if (block_start
>= end
)
1887 warn (_("Block ends prematurely\n"));
1891 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1892 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1893 block_start + uvalue here. */
1894 data
= block_start
+ uvalue
;
1895 /* PR 17512: file: 008-103549-0.001:0.1. */
1896 if (block_start
+ uvalue
> end
|| data
< block_start
)
1898 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1899 uvalue
= end
- block_start
;
1902 data
= block_start
+ uvalue
;
1904 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1907 case DW_FORM_block1
:
1908 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1909 block_start
= data
+ 1;
1910 if (block_start
>= end
)
1912 warn (_("Block ends prematurely\n"));
1916 data
= block_start
+ uvalue
;
1917 if (block_start
+ uvalue
> end
|| data
< block_start
)
1919 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1920 uvalue
= end
- block_start
;
1923 data
= block_start
+ uvalue
;
1925 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1928 case DW_FORM_block2
:
1929 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1930 block_start
= data
+ 2;
1931 if (block_start
>= end
)
1933 warn (_("Block ends prematurely\n"));
1937 data
= block_start
+ uvalue
;
1938 if (block_start
+ uvalue
> end
|| data
< block_start
)
1940 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1941 uvalue
= end
- block_start
;
1944 data
= block_start
+ uvalue
;
1946 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1949 case DW_FORM_block4
:
1950 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1951 block_start
= data
+ 4;
1952 /* PR 17512: file: 3371-3907-0.004. */
1953 if (block_start
>= end
)
1955 warn (_("Block ends prematurely\n"));
1959 data
= block_start
+ uvalue
;
1960 if (block_start
+ uvalue
> end
1961 /* PR 17531: file: 5b5f0592. */
1962 || data
< block_start
)
1964 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1965 uvalue
= end
- block_start
;
1968 data
= block_start
+ uvalue
;
1970 data
= display_block (block_start
, uvalue
, end
, delimiter
);
1975 printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter
,
1976 dwarf_vmatoa ("x", uvalue
),
1977 fetch_indirect_string (uvalue
));
1980 case DW_FORM_line_strp
:
1982 printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter
,
1983 dwarf_vmatoa ("x", uvalue
),
1984 fetch_indirect_line_string (uvalue
));
1987 case DW_FORM_GNU_str_index
:
1990 const char *suffix
= strrchr (section
->name
, '.');
1991 int dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? 1 : 0;
1993 printf (_("%c(indexed string: 0x%s): %s"), delimiter
,
1994 dwarf_vmatoa ("x", uvalue
),
1995 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
1999 case DW_FORM_GNU_strp_alt
:
2001 printf (_("%c(alt indirect string, offset: 0x%s)"), delimiter
,
2002 dwarf_vmatoa ("x", uvalue
));
2005 case DW_FORM_indirect
:
2006 /* Handled above. */
2009 case DW_FORM_ref_sig8
:
2012 dwarf_vma high_bits
;
2015 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
2016 printf ("%csignature: 0x%s", delimiter
,
2017 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
2022 case DW_FORM_GNU_addr_index
:
2024 printf (_("%c(addr_index: 0x%s): %s"), delimiter
,
2025 dwarf_vmatoa ("x", uvalue
),
2026 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
2030 warn (_("Unrecognized form: %lu\n"), form
);
2034 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2035 && num_debug_info_entries
== 0
2036 && debug_info_p
!= NULL
)
2040 case DW_AT_frame_base
:
2041 have_frame_base
= 1;
2043 case DW_AT_location
:
2044 case DW_AT_GNU_locviews
:
2045 case DW_AT_string_length
:
2046 case DW_AT_return_addr
:
2047 case DW_AT_data_member_location
:
2048 case DW_AT_vtable_elem_location
:
2050 case DW_AT_static_link
:
2051 case DW_AT_use_location
:
2052 case DW_AT_call_value
:
2053 case DW_AT_GNU_call_site_value
:
2054 case DW_AT_call_data_value
:
2055 case DW_AT_GNU_call_site_data_value
:
2056 case DW_AT_call_target
:
2057 case DW_AT_GNU_call_site_target
:
2058 case DW_AT_call_target_clobbered
:
2059 case DW_AT_GNU_call_site_target_clobbered
:
2060 if ((dwarf_version
< 4
2061 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2062 || form
== DW_FORM_sec_offset
)
2064 /* Process location list. */
2065 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
2066 unsigned int num
= debug_info_p
->num_loc_offsets
;
2068 if (lmax
== 0 || num
>= lmax
)
2071 debug_info_p
->loc_offsets
= (dwarf_vma
*)
2072 xcrealloc (debug_info_p
->loc_offsets
,
2073 lmax
, sizeof (*debug_info_p
->loc_offsets
));
2074 debug_info_p
->loc_views
= (dwarf_vma
*)
2075 xcrealloc (debug_info_p
->loc_views
,
2076 lmax
, sizeof (*debug_info_p
->loc_views
));
2077 debug_info_p
->have_frame_base
= (int *)
2078 xcrealloc (debug_info_p
->have_frame_base
,
2079 lmax
, sizeof (*debug_info_p
->have_frame_base
));
2080 debug_info_p
->max_loc_offsets
= lmax
;
2082 if (this_set
!= NULL
)
2083 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
2084 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
2085 if (attribute
!= DW_AT_GNU_locviews
)
2087 debug_info_p
->loc_offsets
[num
] = uvalue
;
2088 debug_info_p
->num_loc_offsets
++;
2089 assert (debug_info_p
->num_loc_offsets
2090 - debug_info_p
->num_loc_views
<= 1);
2094 assert (debug_info_p
->num_loc_views
<= num
);
2095 num
= debug_info_p
->num_loc_views
;
2096 debug_info_p
->loc_views
[num
] = uvalue
;
2097 debug_info_p
->num_loc_views
++;
2098 assert (debug_info_p
->num_loc_views
2099 - debug_info_p
->num_loc_offsets
<= 1);
2105 if (need_base_address
)
2106 debug_info_p
->base_address
= uvalue
;
2109 case DW_AT_GNU_addr_base
:
2110 debug_info_p
->addr_base
= uvalue
;
2113 case DW_AT_GNU_ranges_base
:
2114 debug_info_p
->ranges_base
= uvalue
;
2118 if ((dwarf_version
< 4
2119 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2120 || form
== DW_FORM_sec_offset
)
2122 /* Process range list. */
2123 unsigned int lmax
= debug_info_p
->max_range_lists
;
2124 unsigned int num
= debug_info_p
->num_range_lists
;
2126 if (lmax
== 0 || num
>= lmax
)
2129 debug_info_p
->range_lists
= (dwarf_vma
*)
2130 xcrealloc (debug_info_p
->range_lists
,
2131 lmax
, sizeof (*debug_info_p
->range_lists
));
2132 debug_info_p
->max_range_lists
= lmax
;
2134 debug_info_p
->range_lists
[num
] = uvalue
;
2135 debug_info_p
->num_range_lists
++;
2144 if (do_loc
|| attribute
== 0)
2147 /* For some attributes we can display further information. */
2154 case DW_INL_not_inlined
:
2155 printf (_("(not inlined)"));
2157 case DW_INL_inlined
:
2158 printf (_("(inlined)"));
2160 case DW_INL_declared_not_inlined
:
2161 printf (_("(declared as inline but ignored)"));
2163 case DW_INL_declared_inlined
:
2164 printf (_("(declared as inline and inlined)"));
2167 printf (_(" (Unknown inline attribute value: %s)"),
2168 dwarf_vmatoa ("x", uvalue
));
2173 case DW_AT_language
:
2177 /* Ordered by the numeric value of these constants. */
2178 case DW_LANG_C89
: printf ("(ANSI C)"); break;
2179 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
2180 case DW_LANG_Ada83
: printf ("(Ada)"); break;
2181 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
2182 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
2183 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
2184 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
2185 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
2186 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
2187 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
2188 /* DWARF 2.1 values. */
2189 case DW_LANG_Java
: printf ("(Java)"); break;
2190 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
2191 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
2192 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
2193 /* DWARF 3 values. */
2194 case DW_LANG_PLI
: printf ("(PLI)"); break;
2195 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
2196 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
2197 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
2198 case DW_LANG_D
: printf ("(D)"); break;
2199 /* DWARF 4 values. */
2200 case DW_LANG_Python
: printf ("(Python)"); break;
2201 /* DWARF 5 values. */
2202 case DW_LANG_Go
: printf ("(Go)"); break;
2203 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
2204 case DW_LANG_C11
: printf ("(C11)"); break;
2205 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
2206 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
2207 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
2208 /* MIPS extension. */
2209 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
2210 /* UPC extension. */
2211 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
2213 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
2214 printf (_("(implementation defined: %s)"),
2215 dwarf_vmatoa ("x", uvalue
));
2217 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
2222 case DW_AT_encoding
:
2226 case DW_ATE_void
: printf ("(void)"); break;
2227 case DW_ATE_address
: printf ("(machine address)"); break;
2228 case DW_ATE_boolean
: printf ("(boolean)"); break;
2229 case DW_ATE_complex_float
: printf ("(complex float)"); break;
2230 case DW_ATE_float
: printf ("(float)"); break;
2231 case DW_ATE_signed
: printf ("(signed)"); break;
2232 case DW_ATE_signed_char
: printf ("(signed char)"); break;
2233 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
2234 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
2235 /* DWARF 2.1 values: */
2236 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
2237 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2238 /* DWARF 3 values: */
2239 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2240 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2241 case DW_ATE_edited
: printf ("(edited)"); break;
2242 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2243 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2244 /* DWARF 4 values: */
2245 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2246 /* DWARF 5 values: */
2247 case DW_ATE_UCS
: printf ("(UCS)"); break;
2248 case DW_ATE_ASCII
: printf ("(ASCII)"); break;
2250 /* HP extensions: */
2251 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2252 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2253 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2254 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2255 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2256 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2257 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2260 if (uvalue
>= DW_ATE_lo_user
2261 && uvalue
<= DW_ATE_hi_user
)
2262 printf (_("(user defined type)"));
2264 printf (_("(unknown type)"));
2269 case DW_AT_accessibility
:
2273 case DW_ACCESS_public
: printf ("(public)"); break;
2274 case DW_ACCESS_protected
: printf ("(protected)"); break;
2275 case DW_ACCESS_private
: printf ("(private)"); break;
2277 printf (_("(unknown accessibility)"));
2282 case DW_AT_visibility
:
2286 case DW_VIS_local
: printf ("(local)"); break;
2287 case DW_VIS_exported
: printf ("(exported)"); break;
2288 case DW_VIS_qualified
: printf ("(qualified)"); break;
2289 default: printf (_("(unknown visibility)")); break;
2293 case DW_AT_endianity
:
2297 case DW_END_default
: printf ("(default)"); break;
2298 case DW_END_big
: printf ("(big)"); break;
2299 case DW_END_little
: printf ("(little)"); break;
2301 if (uvalue
>= DW_END_lo_user
&& uvalue
<= DW_END_hi_user
)
2302 printf (_("(user specified)"));
2304 printf (_("(unknown endianity)"));
2309 case DW_AT_virtuality
:
2313 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2314 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2315 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2316 default: printf (_("(unknown virtuality)")); break;
2320 case DW_AT_identifier_case
:
2324 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2325 case DW_ID_up_case
: printf ("(up_case)"); break;
2326 case DW_ID_down_case
: printf ("(down_case)"); break;
2327 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2328 default: printf (_("(unknown case)")); break;
2332 case DW_AT_calling_convention
:
2336 case DW_CC_normal
: printf ("(normal)"); break;
2337 case DW_CC_program
: printf ("(program)"); break;
2338 case DW_CC_nocall
: printf ("(nocall)"); break;
2339 case DW_CC_pass_by_reference
: printf ("(pass by ref)"); break;
2340 case DW_CC_pass_by_value
: printf ("(pass by value)"); break;
2341 case DW_CC_GNU_renesas_sh
: printf ("(Rensas SH)"); break;
2342 case DW_CC_GNU_borland_fastcall_i386
: printf ("(Borland fastcall i386)"); break;
2344 if (uvalue
>= DW_CC_lo_user
2345 && uvalue
<= DW_CC_hi_user
)
2346 printf (_("(user defined)"));
2348 printf (_("(unknown convention)"));
2352 case DW_AT_ordering
:
2357 case -1: printf (_("(undefined)")); break;
2358 case 0: printf ("(row major)"); break;
2359 case 1: printf ("(column major)"); break;
2363 case DW_AT_decimal_sign
:
2367 case DW_DS_unsigned
: printf (_("(unsigned)")); break;
2368 case DW_DS_leading_overpunch
: printf (_("(leading overpunch)")); break;
2369 case DW_DS_trailing_overpunch
: printf (_("(trailing overpunch)")); break;
2370 case DW_DS_leading_separate
: printf (_("(leading separate)")); break;
2371 case DW_DS_trailing_separate
: printf (_("(trailing separate)")); break;
2372 default: printf (_("(unrecognised)")); break;
2376 case DW_AT_defaulted
:
2380 case DW_DEFAULTED_no
: printf (_("(no)")); break;
2381 case DW_DEFAULTED_in_class
: printf (_("(in class)")); break;
2382 case DW_DEFAULTED_out_of_class
: printf (_("(out of class)")); break;
2383 default: printf (_("(unrecognised)")); break;
2387 case DW_AT_discr_list
:
2391 case DW_DSC_label
: printf (_("(label)")); break;
2392 case DW_DSC_range
: printf (_("(range)")); break;
2393 default: printf (_("(unrecognised)")); break;
2397 case DW_AT_frame_base
:
2398 have_frame_base
= 1;
2400 case DW_AT_location
:
2401 case DW_AT_string_length
:
2402 case DW_AT_return_addr
:
2403 case DW_AT_data_member_location
:
2404 case DW_AT_vtable_elem_location
:
2406 case DW_AT_static_link
:
2407 case DW_AT_use_location
:
2408 case DW_AT_call_value
:
2409 case DW_AT_GNU_call_site_value
:
2410 case DW_AT_call_data_value
:
2411 case DW_AT_GNU_call_site_data_value
:
2412 case DW_AT_call_target
:
2413 case DW_AT_GNU_call_site_target
:
2414 case DW_AT_call_target_clobbered
:
2415 case DW_AT_GNU_call_site_target_clobbered
:
2416 if ((dwarf_version
< 4
2417 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2418 || form
== DW_FORM_sec_offset
)
2419 printf (_(" (location list)"));
2421 case DW_AT_allocated
:
2422 case DW_AT_associated
:
2423 case DW_AT_data_location
:
2425 case DW_AT_upper_bound
:
2426 case DW_AT_lower_bound
:
2429 int need_frame_base
;
2432 need_frame_base
= decode_location_expression (block_start
,
2437 cu_offset
, section
);
2439 if (need_frame_base
&& !have_frame_base
)
2440 printf (_(" [without DW_AT_frame_base]"));
2446 if (form
== DW_FORM_ref_sig8
2447 || form
== DW_FORM_GNU_ref_alt
)
2450 if (form
== DW_FORM_ref1
2451 || form
== DW_FORM_ref2
2452 || form
== DW_FORM_ref4
2453 || form
== DW_FORM_ref_udata
)
2454 uvalue
+= cu_offset
;
2456 if (uvalue
>= section
->size
)
2457 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2458 dwarf_vmatoa ("x", uvalue
),
2459 (unsigned long) (orig_data
- section
->start
));
2462 unsigned long abbrev_number
;
2463 abbrev_entry
* entry
;
2465 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2467 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2468 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2469 use different abbrev table, and we don't track .debug_info chunks
2471 if (form
!= DW_FORM_ref_addr
)
2473 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2474 if (entry
->entry
== abbrev_number
)
2477 printf (" (%s)", get_TAG_name (entry
->tag
));
2492 get_AT_name (unsigned long attribute
)
2497 return "DW_AT value: 0";
2499 /* One value is shared by the MIPS and HP extensions: */
2500 if (attribute
== DW_AT_MIPS_fde
)
2501 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2503 name
= get_DW_AT_name (attribute
);
2507 static char buffer
[100];
2509 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2517 static unsigned char *
2518 read_and_display_attr (unsigned long attribute
,
2520 dwarf_signed_vma implicit_const
,
2521 unsigned char * data
,
2522 unsigned char * end
,
2523 dwarf_vma cu_offset
,
2524 dwarf_vma pointer_size
,
2525 dwarf_vma offset_size
,
2527 debug_info
* debug_info_p
,
2529 struct dwarf_section
* section
,
2530 struct cu_tu_set
* this_set
)
2533 printf (" %-18s:", get_AT_name (attribute
));
2534 data
= read_and_display_attr_value (attribute
, form
, implicit_const
, data
, end
,
2535 cu_offset
, pointer_size
, offset_size
,
2536 dwarf_version
, debug_info_p
,
2537 do_loc
, section
, this_set
, ' ');
2543 /* Process the contents of a .debug_info section. If do_loc is non-zero
2544 then we are scanning for location lists and we do not want to display
2545 anything to the user. If do_types is non-zero, we are processing
2546 a .debug_types section instead of a .debug_info section. */
2549 process_debug_info (struct dwarf_section
*section
,
2551 enum dwarf_section_display_enum abbrev_sec
,
2555 unsigned char *start
= section
->start
;
2556 unsigned char *end
= start
+ section
->size
;
2557 unsigned char *section_begin
;
2559 unsigned int num_units
= 0;
2561 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2562 && num_debug_info_entries
== 0
2567 /* First scan the section to get the number of comp units. */
2568 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2571 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2572 will be the length. For a 64-bit DWARF section, it'll be
2573 the escape code 0xffffffff followed by an 8 byte length. */
2574 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2576 if (length
== 0xffffffff)
2578 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2579 section_begin
+= length
+ 12;
2581 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2583 warn (_("Reserved length value (0x%s) found in section %s\n"),
2584 dwarf_vmatoa ("x", length
), section
->name
);
2588 section_begin
+= length
+ 4;
2590 /* Negative values are illegal, they may even cause infinite
2591 looping. This can happen if we can't accurately apply
2592 relocations to an object file, or if the file is corrupt. */
2593 if ((signed long) length
<= 0 || section_begin
< start
)
2595 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2596 dwarf_vmatoa ("x", length
), section
->name
);
2603 error (_("No comp units in %s section ?\n"), section
->name
);
2607 /* Then allocate an array to hold the information. */
2608 debug_information
= (debug_info
*) cmalloc (num_units
,
2609 sizeof (* debug_information
));
2610 if (debug_information
== NULL
)
2612 error (_("Not enough memory for a debug info array of %u entries\n"),
2614 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
2617 /* PR 17531: file: 92ca3797.
2618 We cannot rely upon the debug_information array being initialised
2619 before it is used. A corrupt file could easily contain references
2620 to a unit for which information has not been made available. So
2621 we ensure that the array is zeroed here. */
2622 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
2624 alloc_num_debug_info_entries
= num_units
;
2629 if (dwarf_start_die
== 0)
2630 printf (_("Contents of the %s section:\n\n"), section
->name
);
2632 load_debug_section (str
, file
);
2633 load_debug_section (line_str
, file
);
2634 load_debug_section (str_dwo
, file
);
2635 load_debug_section (str_index
, file
);
2636 load_debug_section (str_index_dwo
, file
);
2637 load_debug_section (debug_addr
, file
);
2640 load_debug_section (abbrev_sec
, file
);
2641 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2643 warn (_("Unable to locate %s section!\n"),
2644 debug_displays
[abbrev_sec
].section
.name
);
2648 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2650 DWARF2_Internal_CompUnit compunit
;
2651 unsigned char *hdrptr
;
2652 unsigned char *tags
;
2653 int level
, last_level
, saved_level
;
2654 dwarf_vma cu_offset
;
2655 unsigned long sec_off
;
2656 unsigned int offset_size
;
2657 unsigned int initial_length_size
;
2658 dwarf_vma signature_high
= 0;
2659 dwarf_vma signature_low
= 0;
2660 dwarf_vma type_offset
= 0;
2661 struct cu_tu_set
*this_set
;
2662 dwarf_vma abbrev_base
;
2667 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2669 if (compunit
.cu_length
== 0xffffffff)
2671 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2673 initial_length_size
= 12;
2678 initial_length_size
= 4;
2681 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2683 cu_offset
= start
- section_begin
;
2685 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2687 if (compunit
.cu_version
< 5)
2689 compunit
.cu_unit_type
= DW_UT_compile
;
2690 /* Initialize it due to a false compiler warning. */
2691 compunit
.cu_pointer_size
= -1;
2695 SAFE_BYTE_GET_AND_INC (compunit
.cu_unit_type
, hdrptr
, 1, end
);
2696 do_types
= (compunit
.cu_unit_type
== DW_UT_type
);
2698 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2701 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2703 if (this_set
== NULL
)
2706 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2710 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2711 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2714 if (compunit
.cu_version
< 5)
2715 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2717 /* PR 17512: file: 001-108546-0.001:0.1. */
2718 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
2720 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2721 compunit
.cu_pointer_size
, offset_size
);
2722 compunit
.cu_pointer_size
= offset_size
;
2727 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2729 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2732 if (dwarf_start_die
> (cu_offset
+ compunit
.cu_length
2733 + initial_length_size
))
2735 start
= section_begin
+ cu_offset
+ compunit
.cu_length
2736 + initial_length_size
;
2740 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2741 && num_debug_info_entries
== 0
2744 debug_information
[unit
].cu_offset
= cu_offset
;
2745 debug_information
[unit
].pointer_size
2746 = compunit
.cu_pointer_size
;
2747 debug_information
[unit
].offset_size
= offset_size
;
2748 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2749 debug_information
[unit
].base_address
= 0;
2750 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2751 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2752 debug_information
[unit
].loc_offsets
= NULL
;
2753 debug_information
[unit
].have_frame_base
= NULL
;
2754 debug_information
[unit
].max_loc_offsets
= 0;
2755 debug_information
[unit
].num_loc_offsets
= 0;
2756 debug_information
[unit
].range_lists
= NULL
;
2757 debug_information
[unit
].max_range_lists
= 0;
2758 debug_information
[unit
].num_range_lists
= 0;
2761 if (!do_loc
&& dwarf_start_die
== 0)
2763 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2764 dwarf_vmatoa ("x", cu_offset
));
2765 printf (_(" Length: 0x%s (%s)\n"),
2766 dwarf_vmatoa ("x", compunit
.cu_length
),
2767 offset_size
== 8 ? "64-bit" : "32-bit");
2768 printf (_(" Version: %d\n"), compunit
.cu_version
);
2769 printf (_(" Abbrev Offset: 0x%s\n"),
2770 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2771 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2776 printf (_(" Signature: 0x%s\n"),
2777 dwarf_vmatoa64 (signature_high
, signature_low
,
2778 buf
, sizeof (buf
)));
2779 printf (_(" Type Offset: 0x%s\n"),
2780 dwarf_vmatoa ("x", type_offset
));
2782 if (this_set
!= NULL
)
2784 dwarf_vma
*offsets
= this_set
->section_offsets
;
2785 size_t *sizes
= this_set
->section_sizes
;
2787 printf (_(" Section contributions:\n"));
2788 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2789 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
2790 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
2791 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2792 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
2793 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
2794 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2795 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
2796 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
2797 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2798 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
2799 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
2803 sec_off
= cu_offset
+ initial_length_size
;
2804 if (sec_off
+ compunit
.cu_length
< sec_off
2805 || sec_off
+ compunit
.cu_length
> section
->size
)
2807 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
2809 (unsigned long) cu_offset
,
2810 dwarf_vmatoa ("x", compunit
.cu_length
));
2816 start
+= compunit
.cu_length
+ initial_length_size
;
2818 if (compunit
.cu_version
< 2 || compunit
.cu_version
> 5)
2820 warn (_("CU at offset %s contains corrupt or "
2821 "unsupported version number: %d.\n"),
2822 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2826 if (compunit
.cu_unit_type
!= DW_UT_compile
2827 && compunit
.cu_unit_type
!= DW_UT_type
)
2829 warn (_("CU at offset %s contains corrupt or "
2830 "unsupported unit type: %d.\n"),
2831 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_unit_type
);
2837 /* Process the abbrevs used by this compilation unit. */
2838 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
2839 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2840 (unsigned long) compunit
.cu_abbrev_offset
,
2841 (unsigned long) abbrev_size
);
2842 /* PR 17531: file:4bcd9ce9. */
2843 else if ((abbrev_base
+ abbrev_size
)
2844 > debug_displays
[abbrev_sec
].section
.size
)
2845 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2846 (unsigned long) abbrev_base
+ abbrev_size
,
2847 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2849 process_abbrev_section
2850 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2851 + abbrev_base
+ compunit
.cu_abbrev_offset
),
2852 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2853 + abbrev_base
+ abbrev_size
));
2858 while (tags
< start
)
2860 unsigned int bytes_read
;
2861 unsigned long abbrev_number
;
2862 unsigned long die_offset
;
2863 abbrev_entry
*entry
;
2865 int do_printing
= 1;
2867 die_offset
= tags
- section_begin
;
2869 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
2872 /* A null DIE marks the end of a list of siblings or it may also be
2873 a section padding. */
2874 if (abbrev_number
== 0)
2876 /* Check if it can be a section padding for the last CU. */
2877 if (level
== 0 && start
== end
)
2881 for (chk
= tags
; chk
< start
; chk
++)
2888 if (!do_loc
&& die_offset
>= dwarf_start_die
2889 && (dwarf_cutoff_level
== -1
2890 || level
< dwarf_cutoff_level
))
2891 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2897 static unsigned num_bogus_warns
= 0;
2899 if (num_bogus_warns
< 3)
2901 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2902 die_offset
, section
->name
);
2904 if (num_bogus_warns
== 3)
2905 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2908 if (dwarf_start_die
!= 0 && level
< saved_level
)
2915 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2919 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2920 saved_level
= level
;
2921 do_printing
= (dwarf_cutoff_level
== -1
2922 || level
< dwarf_cutoff_level
);
2924 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2925 level
, die_offset
, abbrev_number
);
2926 else if (dwarf_cutoff_level
== -1
2927 || last_level
< dwarf_cutoff_level
)
2928 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2933 /* Scan through the abbreviation list until we reach the
2935 for (entry
= first_abbrev
;
2936 entry
&& entry
->entry
!= abbrev_number
;
2937 entry
= entry
->next
)
2942 if (!do_loc
&& do_printing
)
2947 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2948 die_offset
, abbrev_number
);
2952 if (!do_loc
&& do_printing
)
2953 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2958 need_base_address
= 0;
2960 case DW_TAG_compile_unit
:
2961 need_base_address
= 1;
2963 case DW_TAG_entry_point
:
2964 case DW_TAG_subprogram
:
2965 need_base_address
= 0;
2966 /* Assuming that there is no DW_AT_frame_base. */
2967 have_frame_base
= 0;
2971 debug_info
*debug_info_p
=
2972 (debug_information
&& unit
< alloc_num_debug_info_entries
)
2973 ? debug_information
+ unit
: NULL
;
2975 assert (!debug_info_p
2976 || (debug_info_p
->num_loc_offsets
2977 == debug_info_p
->num_loc_views
));
2979 for (attr
= entry
->first_attr
;
2980 attr
&& attr
->attribute
;
2983 if (! do_loc
&& do_printing
)
2984 /* Show the offset from where the tag was extracted. */
2985 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2987 tags
= read_and_display_attr (attr
->attribute
,
2989 attr
->implicit_const
,
2993 compunit
.cu_pointer_size
,
2995 compunit
.cu_version
,
2997 do_loc
|| ! do_printing
,
3002 /* If a locview attribute appears before a location one,
3003 make sure we don't associate it with an earlier
3006 switch (debug_info_p
->num_loc_offsets
- debug_info_p
->num_loc_views
)
3009 debug_info_p
->loc_views
[debug_info_p
->num_loc_views
] = vm1
;
3010 debug_info_p
->num_loc_views
++;
3011 assert (debug_info_p
->num_loc_views
3012 == debug_info_p
->num_loc_offsets
);
3019 warn(_("DIE has locviews without loclist\n"));
3020 debug_info_p
->num_loc_views
--;
3027 if (entry
->children
)
3032 /* Set num_debug_info_entries here so that it can be used to check if
3033 we need to process .debug_loc and .debug_ranges sections. */
3034 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
3035 && num_debug_info_entries
== 0
3038 if (num_units
> alloc_num_debug_info_entries
)
3039 num_debug_info_entries
= alloc_num_debug_info_entries
;
3041 num_debug_info_entries
= num_units
;
3050 /* Locate and scan the .debug_info section in the file and record the pointer
3051 sizes and offsets for the compilation units in it. Usually an executable
3052 will have just one pointer size, but this is not guaranteed, and so we try
3053 not to make any assumptions. Returns zero upon failure, or the number of
3054 compilation units upon success. */
3057 load_debug_info (void * file
)
3059 /* If we have already tried and failed to load the .debug_info
3060 section then do not bother to repeat the task. */
3061 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3064 /* If we already have the information there is nothing else to do. */
3065 if (num_debug_info_entries
> 0)
3066 return num_debug_info_entries
;
3068 /* If this is a DWARF package file, load the CU and TU indexes. */
3069 (void) load_cu_tu_indexes (file
);
3071 if (load_debug_section (info
, file
)
3072 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
3073 return num_debug_info_entries
;
3075 if (load_debug_section (info_dwo
, file
)
3076 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
3078 return num_debug_info_entries
;
3080 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
3084 /* Read a DWARF .debug_line section header starting at DATA.
3085 Upon success returns an updated DATA pointer and the LINFO
3086 structure and the END_OF_SEQUENCE pointer will be filled in.
3087 Otherwise returns NULL. */
3089 static unsigned char *
3090 read_debug_line_header (struct dwarf_section
* section
,
3091 unsigned char * data
,
3092 unsigned char * end
,
3093 DWARF2_Internal_LineInfo
* linfo
,
3094 unsigned char ** end_of_sequence
)
3096 unsigned char *hdrptr
;
3097 unsigned int initial_length_size
;
3098 unsigned char address_size
, segment_selector_size
;
3100 /* Extract information from the Line Number Program Header.
3101 (section 6.2.4 in the Dwarf3 doc). */
3104 /* Get and check the length of the block. */
3105 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
3107 if (linfo
->li_length
== 0xffffffff)
3109 /* This section is 64-bit DWARF 3. */
3110 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
3111 linfo
->li_offset_size
= 8;
3112 initial_length_size
= 12;
3116 linfo
->li_offset_size
= 4;
3117 initial_length_size
= 4;
3120 if (linfo
->li_length
+ initial_length_size
> section
->size
)
3122 /* If the length field has a relocation against it, then we should
3123 not complain if it is inaccurate (and probably negative). This
3124 happens in object files when the .debug_line section is actually
3125 comprised of several different .debug_line.* sections, (some of
3126 which may be removed by linker garbage collection), and a relocation
3127 is used to compute the correct length once that is done. */
3128 if (reloc_at (section
, (hdrptr
- section
->start
) - linfo
->li_offset_size
))
3130 linfo
->li_length
= (end
- data
) - initial_length_size
;
3134 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
3135 (long) linfo
->li_length
);
3140 /* Get and check the version number. */
3141 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
3143 if (linfo
->li_version
!= 2
3144 && linfo
->li_version
!= 3
3145 && linfo
->li_version
!= 4
3146 && linfo
->li_version
!= 5)
3148 warn (_("Only DWARF version 2, 3, 4 and 5 line info "
3149 "is currently supported.\n"));
3153 if (linfo
->li_version
>= 5)
3155 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
3157 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
3158 if (segment_selector_size
!= 0)
3160 warn (_("The %s section contains "
3161 "unsupported segment selector size: %d.\n"),
3162 section
->name
, segment_selector_size
);
3167 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
,
3168 linfo
->li_offset_size
, end
);
3169 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
3171 if (linfo
->li_version
>= 4)
3173 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
3175 if (linfo
->li_max_ops_per_insn
== 0)
3177 warn (_("Invalid maximum operations per insn.\n"));
3182 linfo
->li_max_ops_per_insn
= 1;
3184 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
3185 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
3186 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
3187 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
3189 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
3190 /* PR 17512: file:002-117414-0.004. */
3191 if (* end_of_sequence
> end
)
3193 warn (_("Line length %s extends beyond end of section\n"),
3194 dwarf_vmatoa ("u", linfo
->li_length
));
3195 * end_of_sequence
= end
;
3202 static unsigned char *
3203 display_formatted_table (unsigned char *data
,
3204 unsigned char *start
, unsigned char *end
,
3205 const DWARF2_Internal_LineInfo
*linfo
,
3206 struct dwarf_section
*section
, const char *what
)
3208 unsigned char *format_start
, format_count
, *format
, formati
;
3209 dwarf_vma data_count
, datai
;
3210 unsigned int bytes_read
, namepass
, last_entry
= 0;
3212 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3213 format_start
= data
;
3214 for (formati
= 0; formati
< format_count
; formati
++)
3216 read_uleb128 (data
, & bytes_read
, end
);
3218 read_uleb128 (data
, & bytes_read
, end
);
3222 warn (_("Corrupt %s format table entry\n"), what
);
3227 data_count
= read_uleb128 (data
, & bytes_read
, end
);
3231 warn (_("Corrupt %s list\n"), what
);
3235 if (data_count
== 0)
3237 printf (_("\n The %s Table is empty.\n"), what
);
3241 printf (_("\n The %s Table (offset 0x%lx):\n"), what
,
3242 (long)(data
- start
));
3244 printf (_(" Entry"));
3245 /* Delay displaying name as the last entry for better screen layout. */
3246 for (namepass
= 0; namepass
< 2; namepass
++)
3248 format
= format_start
;
3249 for (formati
= 0; formati
< format_count
; formati
++)
3251 dwarf_vma content_type
;
3253 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3254 format
+= bytes_read
;
3255 if ((content_type
== DW_LNCT_path
) == (namepass
== 1))
3256 switch (content_type
)
3259 printf (_("\tName"));
3261 case DW_LNCT_directory_index
:
3262 printf (_("\tDir"));
3264 case DW_LNCT_timestamp
:
3265 printf (_("\tTime"));
3268 printf (_("\tSize"));
3271 printf (_("\tMD5"));
3274 printf (_("\t(Unknown format content type %s)"),
3275 dwarf_vmatoa ("u", content_type
));
3277 read_uleb128 (format
, & bytes_read
, end
);
3278 format
+= bytes_read
;
3283 for (datai
= 0; datai
< data_count
; datai
++)
3285 unsigned char *datapass
= data
;
3287 printf (" %d", last_entry
++);
3288 /* Delay displaying name as the last entry for better screen layout. */
3289 for (namepass
= 0; namepass
< 2; namepass
++)
3291 format
= format_start
;
3293 for (formati
= 0; formati
< format_count
; formati
++)
3295 dwarf_vma content_type
, form
;
3297 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3298 format
+= bytes_read
;
3299 form
= read_uleb128 (format
, & bytes_read
, end
);
3300 format
+= bytes_read
;
3301 data
= read_and_display_attr_value (0, form
, 0, data
, end
, 0, 0,
3302 linfo
->li_offset_size
,
3303 linfo
->li_version
, NULL
,
3304 ((content_type
== DW_LNCT_path
) != (namepass
== 1)),
3305 section
, NULL
, '\t');
3310 warn (_("Corrupt %s entries list\n"), what
);
3319 display_debug_lines_raw (struct dwarf_section
*section
,
3320 unsigned char *data
,
3321 unsigned char *end
, void *file
)
3323 unsigned char *start
= section
->start
;
3324 int verbose_view
= 0;
3326 printf (_("Raw dump of debug contents of section %s:\n\n"),
3331 static DWARF2_Internal_LineInfo saved_linfo
;
3332 DWARF2_Internal_LineInfo linfo
;
3333 unsigned char *standard_opcodes
;
3334 unsigned char *end_of_sequence
;
3337 if (const_strneq (section
->name
, ".debug_line.")
3338 /* Note: the following does not apply to .debug_line.dwo sections.
3339 These are full debug_line sections. */
3340 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3342 /* Sections named .debug_line.<foo> are fragments of a .debug_line
3343 section containing just the Line Number Statements. They are
3344 created by the assembler and intended to be used alongside gcc's
3345 -ffunction-sections command line option. When the linker's
3346 garbage collection decides to discard a .text.<foo> section it
3347 can then also discard the line number information in .debug_line.<foo>.
3349 Since the section is a fragment it does not have the details
3350 needed to fill out a LineInfo structure, so instead we use the
3351 details from the last full debug_line section that we processed. */
3352 end_of_sequence
= end
;
3353 standard_opcodes
= NULL
;
3354 linfo
= saved_linfo
;
3355 /* PR 17531: file: 0522b371. */
3356 if (linfo
.li_line_range
== 0)
3358 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3361 reset_state_machine (linfo
.li_default_is_stmt
);
3365 unsigned char * hdrptr
;
3367 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3368 & end_of_sequence
)) == NULL
)
3371 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
3372 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
3373 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
3374 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
3375 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
3376 if (linfo
.li_version
>= 4)
3377 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
3378 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
3379 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
3380 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
3381 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
3383 /* PR 17512: file: 1665-6428-0.004. */
3384 if (linfo
.li_line_range
== 0)
3386 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3387 linfo
.li_line_range
= 1;
3390 reset_state_machine (linfo
.li_default_is_stmt
);
3392 /* Display the contents of the Opcodes table. */
3393 standard_opcodes
= hdrptr
;
3395 /* PR 17512: file: 002-417945-0.004. */
3396 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
3398 warn (_("Line Base extends beyond end of section\n"));
3402 printf (_("\n Opcodes:\n"));
3404 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
3405 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
3407 /* Display the contents of the Directory table. */
3408 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3410 if (linfo
.li_version
>= 5)
3412 load_debug_section (line_str
, file
);
3414 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3416 data
= display_formatted_table (data
, start
, end
, &linfo
, section
,
3422 printf (_("\n The Directory Table is empty.\n"));
3425 unsigned int last_dir_entry
= 0;
3427 printf (_("\n The Directory Table (offset 0x%lx):\n"),
3428 (long)(data
- start
));
3430 while (data
< end
&& *data
!= 0)
3432 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
3434 data
+= strnlen ((char *) data
, end
- data
) + 1;
3437 /* PR 17512: file: 002-132094-0.004. */
3438 if (data
>= end
- 1)
3442 /* Skip the NUL at the end of the table. */
3445 /* Display the contents of the File Name table. */
3447 printf (_("\n The File Name Table is empty.\n"));
3450 printf (_("\n The File Name Table (offset 0x%lx):\n"),
3451 (long)(data
- start
));
3452 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
3454 while (data
< end
&& *data
!= 0)
3456 unsigned char *name
;
3457 unsigned int bytes_read
;
3459 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
3461 data
+= strnlen ((char *) data
, end
- data
) + 1;
3464 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3467 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3470 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
3472 printf ("%.*s\n", (int)(end
- name
), name
);
3476 warn (_("Corrupt file name table entry\n"));
3482 /* Skip the NUL at the end of the table. */
3487 saved_linfo
= linfo
;
3490 /* Now display the statements. */
3491 if (data
>= end_of_sequence
)
3492 printf (_(" No Line Number Statements.\n"));
3495 printf (_(" Line Number Statements:\n"));
3497 while (data
< end_of_sequence
)
3499 unsigned char op_code
;
3500 dwarf_signed_vma adv
;
3502 unsigned int bytes_read
;
3504 printf (" [0x%08lx]", (long)(data
- start
));
3508 if (op_code
>= linfo
.li_opcode_base
)
3510 op_code
-= linfo
.li_opcode_base
;
3511 uladv
= (op_code
/ linfo
.li_line_range
);
3512 if (linfo
.li_max_ops_per_insn
== 1)
3514 uladv
*= linfo
.li_min_insn_length
;
3515 state_machine_regs
.address
+= uladv
;
3517 state_machine_regs
.view
= 0;
3518 printf (_(" Special opcode %d: "
3519 "advance Address by %s to 0x%s%s"),
3520 op_code
, dwarf_vmatoa ("u", uladv
),
3521 dwarf_vmatoa ("x", state_machine_regs
.address
),
3522 verbose_view
&& uladv
3523 ? _(" (reset view)") : "");
3528 = ((state_machine_regs
.op_index
+ uladv
)
3529 / linfo
.li_max_ops_per_insn
)
3530 * linfo
.li_min_insn_length
;
3532 state_machine_regs
.address
+= addrdelta
;
3533 state_machine_regs
.op_index
3534 = (state_machine_regs
.op_index
+ uladv
)
3535 % linfo
.li_max_ops_per_insn
;
3537 state_machine_regs
.view
= 0;
3538 printf (_(" Special opcode %d: "
3539 "advance Address by %s to 0x%s[%d]%s"),
3540 op_code
, dwarf_vmatoa ("u", uladv
),
3541 dwarf_vmatoa ("x", state_machine_regs
.address
),
3542 state_machine_regs
.op_index
,
3543 verbose_view
&& addrdelta
3544 ? _(" (reset view)") : "");
3546 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3547 state_machine_regs
.line
+= adv
;
3548 printf (_(" and Line by %s to %d"),
3549 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
3550 if (verbose_view
|| state_machine_regs
.view
)
3551 printf (_(" (view %u)\n"), state_machine_regs
.view
);
3554 state_machine_regs
.view
++;
3556 else switch (op_code
)
3558 case DW_LNS_extended_op
:
3559 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
3563 printf (_(" Copy"));
3564 if (verbose_view
|| state_machine_regs
.view
)
3565 printf (_(" (view %u)\n"), state_machine_regs
.view
);
3568 state_machine_regs
.view
++;
3571 case DW_LNS_advance_pc
:
3572 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3574 if (linfo
.li_max_ops_per_insn
== 1)
3576 uladv
*= linfo
.li_min_insn_length
;
3577 state_machine_regs
.address
+= uladv
;
3579 state_machine_regs
.view
= 0;
3580 printf (_(" Advance PC by %s to 0x%s%s\n"),
3581 dwarf_vmatoa ("u", uladv
),
3582 dwarf_vmatoa ("x", state_machine_regs
.address
),
3583 verbose_view
&& uladv
3584 ? _(" (reset view)") : "");
3589 = ((state_machine_regs
.op_index
+ uladv
)
3590 / linfo
.li_max_ops_per_insn
)
3591 * linfo
.li_min_insn_length
;
3592 state_machine_regs
.address
3594 state_machine_regs
.op_index
3595 = (state_machine_regs
.op_index
+ uladv
)
3596 % linfo
.li_max_ops_per_insn
;
3598 state_machine_regs
.view
= 0;
3599 printf (_(" Advance PC by %s to 0x%s[%d]%s\n"),
3600 dwarf_vmatoa ("u", uladv
),
3601 dwarf_vmatoa ("x", state_machine_regs
.address
),
3602 state_machine_regs
.op_index
,
3603 verbose_view
&& addrdelta
3604 ? _(" (reset view)") : "");
3608 case DW_LNS_advance_line
:
3609 adv
= read_sleb128 (data
, & bytes_read
, end
);
3611 state_machine_regs
.line
+= adv
;
3612 printf (_(" Advance Line by %s to %d\n"),
3613 dwarf_vmatoa ("d", adv
),
3614 state_machine_regs
.line
);
3617 case DW_LNS_set_file
:
3618 adv
= read_uleb128 (data
, & bytes_read
, end
);
3620 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3621 dwarf_vmatoa ("d", adv
));
3622 state_machine_regs
.file
= adv
;
3625 case DW_LNS_set_column
:
3626 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3628 printf (_(" Set column to %s\n"),
3629 dwarf_vmatoa ("u", uladv
));
3630 state_machine_regs
.column
= uladv
;
3633 case DW_LNS_negate_stmt
:
3634 adv
= state_machine_regs
.is_stmt
;
3636 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
3637 state_machine_regs
.is_stmt
= adv
;
3640 case DW_LNS_set_basic_block
:
3641 printf (_(" Set basic block\n"));
3642 state_machine_regs
.basic_block
= 1;
3645 case DW_LNS_const_add_pc
:
3646 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3647 if (linfo
.li_max_ops_per_insn
)
3649 uladv
*= linfo
.li_min_insn_length
;
3650 state_machine_regs
.address
+= uladv
;
3652 state_machine_regs
.view
= 0;
3653 printf (_(" Advance PC by constant %s to 0x%s%s\n"),
3654 dwarf_vmatoa ("u", uladv
),
3655 dwarf_vmatoa ("x", state_machine_regs
.address
),
3656 verbose_view
&& uladv
3657 ? _(" (reset view)") : "");
3662 = ((state_machine_regs
.op_index
+ uladv
)
3663 / linfo
.li_max_ops_per_insn
)
3664 * linfo
.li_min_insn_length
;
3665 state_machine_regs
.address
3667 state_machine_regs
.op_index
3668 = (state_machine_regs
.op_index
+ uladv
)
3669 % linfo
.li_max_ops_per_insn
;
3671 state_machine_regs
.view
= 0;
3672 printf (_(" Advance PC by constant %s to 0x%s[%d]%s\n"),
3673 dwarf_vmatoa ("u", uladv
),
3674 dwarf_vmatoa ("x", state_machine_regs
.address
),
3675 state_machine_regs
.op_index
,
3676 verbose_view
&& addrdelta
3677 ? _(" (reset view)") : "");
3681 case DW_LNS_fixed_advance_pc
:
3682 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3683 state_machine_regs
.address
+= uladv
;
3684 state_machine_regs
.op_index
= 0;
3685 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3686 dwarf_vmatoa ("u", uladv
),
3687 dwarf_vmatoa ("x", state_machine_regs
.address
));
3688 /* Do NOT reset view. */
3691 case DW_LNS_set_prologue_end
:
3692 printf (_(" Set prologue_end to true\n"));
3695 case DW_LNS_set_epilogue_begin
:
3696 printf (_(" Set epilogue_begin to true\n"));
3699 case DW_LNS_set_isa
:
3700 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3702 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
3706 printf (_(" Unknown opcode %d with operands: "), op_code
);
3708 if (standard_opcodes
!= NULL
)
3709 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3711 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3713 i
== 1 ? "" : ", ");
3729 unsigned char *name
;
3730 unsigned int directory_index
;
3731 unsigned int modification_date
;
3732 unsigned int length
;
3735 /* Output a decoded representation of the .debug_line section. */
3738 display_debug_lines_decoded (struct dwarf_section
*section
,
3739 unsigned char *data
,
3740 unsigned char *end
, void *fileptr
)
3742 static DWARF2_Internal_LineInfo saved_linfo
;
3744 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3749 /* This loop amounts to one iteration per compilation unit. */
3750 DWARF2_Internal_LineInfo linfo
;
3751 unsigned char *standard_opcodes
;
3752 unsigned char *end_of_sequence
;
3754 File_Entry
*file_table
= NULL
;
3755 unsigned int n_files
= 0;
3756 unsigned char **directory_table
= NULL
;
3757 dwarf_vma n_directories
= 0;
3759 if (const_strneq (section
->name
, ".debug_line.")
3760 /* Note: the following does not apply to .debug_line.dwo sections.
3761 These are full debug_line sections. */
3762 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3764 /* See comment in display_debug_lines_raw(). */
3765 end_of_sequence
= end
;
3766 standard_opcodes
= NULL
;
3767 linfo
= saved_linfo
;
3768 /* PR 17531: file: 0522b371. */
3769 if (linfo
.li_line_range
== 0)
3771 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3774 reset_state_machine (linfo
.li_default_is_stmt
);
3778 unsigned char *hdrptr
;
3780 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3781 & end_of_sequence
)) == NULL
)
3784 /* PR 17531: file: 0522b371. */
3785 if (linfo
.li_line_range
== 0)
3787 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3788 linfo
.li_line_range
= 1;
3790 reset_state_machine (linfo
.li_default_is_stmt
);
3792 /* Save a pointer to the contents of the Opcodes table. */
3793 standard_opcodes
= hdrptr
;
3795 /* Traverse the Directory table just to count entries. */
3796 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3800 warn (_("opcode base of %d extends beyond end of section\n"),
3801 linfo
.li_opcode_base
);
3805 if (linfo
.li_version
>= 5)
3807 unsigned char *format_start
, format_count
, *format
;
3808 dwarf_vma formati
, entryi
;
3809 unsigned int bytes_read
;
3811 load_debug_section (line_str
, fileptr
);
3813 /* Skip directories format. */
3814 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3815 format_start
= data
;
3816 for (formati
= 0; formati
< format_count
; formati
++)
3818 read_uleb128 (data
, & bytes_read
, end
);
3820 read_uleb128 (data
, & bytes_read
, end
);
3824 n_directories
= read_uleb128 (data
, & bytes_read
, end
);
3828 warn (_("Corrupt directories list\n"));
3832 directory_table
= (unsigned char **)
3833 xmalloc (n_directories
* sizeof (unsigned char *));
3835 for (entryi
= 0; entryi
< n_directories
; entryi
++)
3837 unsigned char **pathp
= &directory_table
[entryi
];
3839 format
= format_start
;
3840 for (formati
= 0; formati
< format_count
; formati
++)
3842 dwarf_vma content_type
, form
;
3845 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3846 format
+= bytes_read
;
3847 form
= read_uleb128 (format
, & bytes_read
, end
);
3848 format
+= bytes_read
;
3851 warn (_("Corrupt directories list\n"));
3854 switch (content_type
)
3859 case DW_FORM_string
:
3862 case DW_FORM_line_strp
:
3863 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
3865 /* Remove const by the cast. */
3866 *pathp
= (unsigned char *)
3867 fetch_indirect_line_string (uvalue
);
3872 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
3874 linfo
.li_offset_size
,
3881 warn (_("Corrupt directories list\n"));
3886 /* Skip files format. */
3887 SAFE_BYTE_GET_AND_INC (format_count
, data
, 1, end
);
3888 format_start
= data
;
3889 for (formati
= 0; formati
< format_count
; formati
++)
3891 read_uleb128 (data
, & bytes_read
, end
);
3893 read_uleb128 (data
, & bytes_read
, end
);
3897 n_files
= read_uleb128 (data
, & bytes_read
, end
);
3901 warn (_("Corrupt file name list\n"));
3905 file_table
= (File_Entry
*) xcalloc (1, n_files
3906 * sizeof (File_Entry
));
3908 for (entryi
= 0; entryi
< n_files
; entryi
++)
3910 File_Entry
*file
= &file_table
[entryi
];
3912 format
= format_start
;
3913 for (formati
= 0; formati
< format_count
; formati
++)
3915 dwarf_vma content_type
, form
;
3918 content_type
= read_uleb128 (format
, & bytes_read
, end
);
3919 format
+= bytes_read
;
3920 form
= read_uleb128 (format
, & bytes_read
, end
);
3921 format
+= bytes_read
;
3924 warn (_("Corrupt file name list\n"));
3927 switch (content_type
)
3932 case DW_FORM_string
:
3935 case DW_FORM_line_strp
:
3936 SAFE_BYTE_GET (uvalue
, data
, linfo
.li_offset_size
,
3938 /* Remove const by the cast. */
3939 file
->name
= (unsigned char *)
3940 fetch_indirect_line_string (uvalue
);
3944 case DW_LNCT_directory_index
:
3948 SAFE_BYTE_GET (file
->directory_index
, data
, 1,
3952 SAFE_BYTE_GET (file
->directory_index
, data
, 2,
3956 file
->directory_index
= read_uleb128 (data
, NULL
,
3962 data
= read_and_display_attr_value (0, form
, 0, data
, end
,
3964 linfo
.li_offset_size
,
3971 warn (_("Corrupt file name list\n"));
3980 unsigned char *ptr_directory_table
= data
;
3982 while (data
< end
&& *data
!= 0)
3984 data
+= strnlen ((char *) data
, end
- data
) + 1;
3991 warn (_("directory table ends unexpectedly\n"));
3996 /* Go through the directory table again to save the directories. */
3997 directory_table
= (unsigned char **)
3998 xmalloc (n_directories
* sizeof (unsigned char *));
4001 while (*ptr_directory_table
!= 0)
4003 directory_table
[i
] = ptr_directory_table
;
4004 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
4005 ptr_directory_table
- end
) + 1;
4009 /* Skip the NUL at the end of the table. */
4012 /* Traverse the File Name table just to count the entries. */
4013 if (data
< end
&& *data
!= 0)
4015 unsigned char *ptr_file_name_table
= data
;
4017 while (data
< end
&& *data
!= 0)
4019 unsigned int bytes_read
;
4021 /* Skip Name, directory index, last modification time and length
4023 data
+= strnlen ((char *) data
, end
- data
) + 1;
4024 read_uleb128 (data
, & bytes_read
, end
);
4026 read_uleb128 (data
, & bytes_read
, end
);
4028 read_uleb128 (data
, & bytes_read
, end
);
4036 warn (_("file table ends unexpectedly\n"));
4041 /* Go through the file table again to save the strings. */
4042 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
4045 while (*ptr_file_name_table
!= 0)
4047 unsigned int bytes_read
;
4049 file_table
[i
].name
= ptr_file_name_table
;
4050 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
4051 end
- ptr_file_name_table
) + 1;
4053 /* We are not interested in directory, time or size. */
4054 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
4056 ptr_file_name_table
+= bytes_read
;
4057 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
4059 ptr_file_name_table
+= bytes_read
;
4060 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
4061 ptr_file_name_table
+= bytes_read
;
4067 /* Skip the NUL at the end of the table. */
4071 /* Print the Compilation Unit's name and a header. */
4072 if (file_table
== NULL
)
4074 else if (directory_table
== NULL
)
4075 printf (_("CU: %s:\n"), file_table
[0].name
);
4078 unsigned int ix
= file_table
[0].directory_index
;
4079 const char *directory
;
4084 else if (n_directories
== 0)
4085 directory
= _("<unknown>");
4086 else if (ix
> n_directories
)
4088 warn (_("directory index %u > number of directories %s\n"),
4089 ix
, dwarf_vmatoa ("u", n_directories
));
4090 directory
= _("<corrupt>");
4093 directory
= (char *) directory_table
[ix
- 1];
4095 if (do_wide
|| strlen (directory
) < 76)
4096 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
4098 printf ("%s:\n", file_table
[0].name
);
4101 printf (_("File name Line number Starting address View\n"));
4102 saved_linfo
= linfo
;
4105 /* This loop iterates through the Dwarf Line Number Program. */
4106 while (data
< end_of_sequence
)
4108 unsigned char op_code
;
4111 unsigned long int uladv
;
4112 unsigned int bytes_read
;
4113 int is_special_opcode
= 0;
4118 if (op_code
>= linfo
.li_opcode_base
)
4120 op_code
-= linfo
.li_opcode_base
;
4121 uladv
= (op_code
/ linfo
.li_line_range
);
4122 if (linfo
.li_max_ops_per_insn
== 1)
4124 uladv
*= linfo
.li_min_insn_length
;
4125 state_machine_regs
.address
+= uladv
;
4127 state_machine_regs
.view
= 0;
4132 = ((state_machine_regs
.op_index
+ uladv
)
4133 / linfo
.li_max_ops_per_insn
)
4134 * linfo
.li_min_insn_length
;
4135 state_machine_regs
.address
4137 state_machine_regs
.op_index
4138 = (state_machine_regs
.op_index
+ uladv
)
4139 % linfo
.li_max_ops_per_insn
;
4141 state_machine_regs
.view
= 0;
4144 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
4145 state_machine_regs
.line
+= adv
;
4146 is_special_opcode
= 1;
4147 /* Increment view after printing this row. */
4149 else switch (op_code
)
4151 case DW_LNS_extended_op
:
4153 unsigned int ext_op_code_len
;
4154 unsigned char ext_op_code
;
4155 unsigned char *op_code_data
= data
;
4157 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
4159 op_code_data
+= bytes_read
;
4161 if (ext_op_code_len
== 0)
4163 warn (_("Badly formed extended line op encountered!\n"));
4166 ext_op_code_len
+= bytes_read
;
4167 ext_op_code
= *op_code_data
++;
4171 switch (ext_op_code
)
4173 case DW_LNE_end_sequence
:
4174 /* Reset stuff after printing this row. */
4176 case DW_LNE_set_address
:
4177 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
4179 ext_op_code_len
- bytes_read
- 1,
4181 state_machine_regs
.op_index
= 0;
4182 state_machine_regs
.view
= 0;
4184 case DW_LNE_define_file
:
4186 file_table
= (File_Entry
*) xrealloc
4187 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
4189 ++state_machine_regs
.last_file_entry
;
4190 /* Source file name. */
4191 file_table
[n_files
].name
= op_code_data
;
4192 op_code_data
+= strlen ((char *) op_code_data
) + 1;
4193 /* Directory index. */
4194 file_table
[n_files
].directory_index
=
4195 read_uleb128 (op_code_data
, & bytes_read
,
4197 op_code_data
+= bytes_read
;
4198 /* Last modification time. */
4199 file_table
[n_files
].modification_date
=
4200 read_uleb128 (op_code_data
, & bytes_read
,
4202 op_code_data
+= bytes_read
;
4204 file_table
[n_files
].length
=
4205 read_uleb128 (op_code_data
, & bytes_read
,
4211 case DW_LNE_set_discriminator
:
4212 case DW_LNE_HP_set_sequence
:
4213 /* Simply ignored. */
4217 printf (_("UNKNOWN (%u): length %d\n"),
4218 ext_op_code
, ext_op_code_len
- bytes_read
);
4221 data
+= ext_op_code_len
;
4225 /* Increment view after printing this row. */
4228 case DW_LNS_advance_pc
:
4229 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4231 if (linfo
.li_max_ops_per_insn
== 1)
4233 uladv
*= linfo
.li_min_insn_length
;
4234 state_machine_regs
.address
+= uladv
;
4236 state_machine_regs
.view
= 0;
4241 = ((state_machine_regs
.op_index
+ uladv
)
4242 / linfo
.li_max_ops_per_insn
)
4243 * linfo
.li_min_insn_length
;
4244 state_machine_regs
.address
4246 state_machine_regs
.op_index
4247 = (state_machine_regs
.op_index
+ uladv
)
4248 % linfo
.li_max_ops_per_insn
;
4250 state_machine_regs
.view
= 0;
4254 case DW_LNS_advance_line
:
4255 adv
= read_sleb128 (data
, & bytes_read
, end
);
4257 state_machine_regs
.line
+= adv
;
4260 case DW_LNS_set_file
:
4261 adv
= read_uleb128 (data
, & bytes_read
, end
);
4263 state_machine_regs
.file
= adv
;
4266 unsigned file
= state_machine_regs
.file
- 1;
4269 if (file_table
== NULL
|| n_files
== 0)
4270 printf (_("\n [Use file table entry %d]\n"), file
);
4272 else if (file
>= n_files
)
4274 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
4275 printf (_("\n <over large file table index %u>"), file
);
4277 else if ((dir
= file_table
[file
].directory_index
) == 0)
4278 /* If directory index is 0, that means current directory. */
4279 printf ("\n./%s:[++]\n", file_table
[file
].name
);
4280 else if (directory_table
== NULL
|| n_directories
== 0)
4281 printf (_("\n [Use file %s in directory table entry %d]\n"),
4282 file_table
[file
].name
, dir
);
4284 else if (dir
> n_directories
)
4286 warn (_("directory index %u > number of directories %s\n"),
4287 dir
, dwarf_vmatoa ("u", n_directories
));
4288 printf (_("\n <over large directory table entry %u>\n"), dir
);
4291 printf ("\n%s/%s:\n",
4292 /* The directory index starts counting at 1. */
4293 directory_table
[dir
- 1], file_table
[file
].name
);
4297 case DW_LNS_set_column
:
4298 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4300 state_machine_regs
.column
= uladv
;
4303 case DW_LNS_negate_stmt
:
4304 adv
= state_machine_regs
.is_stmt
;
4306 state_machine_regs
.is_stmt
= adv
;
4309 case DW_LNS_set_basic_block
:
4310 state_machine_regs
.basic_block
= 1;
4313 case DW_LNS_const_add_pc
:
4314 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
4315 if (linfo
.li_max_ops_per_insn
== 1)
4317 uladv
*= linfo
.li_min_insn_length
;
4318 state_machine_regs
.address
+= uladv
;
4320 state_machine_regs
.view
= 0;
4325 = ((state_machine_regs
.op_index
+ uladv
)
4326 / linfo
.li_max_ops_per_insn
)
4327 * linfo
.li_min_insn_length
;
4328 state_machine_regs
.address
4330 state_machine_regs
.op_index
4331 = (state_machine_regs
.op_index
+ uladv
)
4332 % linfo
.li_max_ops_per_insn
;
4334 state_machine_regs
.view
= 0;
4338 case DW_LNS_fixed_advance_pc
:
4339 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
4340 state_machine_regs
.address
+= uladv
;
4341 state_machine_regs
.op_index
= 0;
4342 /* Do NOT reset view. */
4345 case DW_LNS_set_prologue_end
:
4348 case DW_LNS_set_epilogue_begin
:
4351 case DW_LNS_set_isa
:
4352 uladv
= read_uleb128 (data
, & bytes_read
, end
);
4354 printf (_(" Set ISA to %lu\n"), uladv
);
4358 printf (_(" Unknown opcode %d with operands: "), op_code
);
4360 if (standard_opcodes
!= NULL
)
4361 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
4363 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
4365 i
== 1 ? "" : ", ");
4372 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
4373 to the DWARF address/line matrix. */
4374 if ((is_special_opcode
) || (xop
== -DW_LNE_end_sequence
)
4375 || (xop
== DW_LNS_copy
))
4377 const unsigned int MAX_FILENAME_LENGTH
= 35;
4379 char *newFileName
= NULL
;
4380 size_t fileNameLength
;
4384 unsigned indx
= state_machine_regs
.file
- 1;
4386 if (indx
>= n_files
)
4388 warn (_("corrupt file index %u encountered\n"), indx
);
4389 fileName
= _("<corrupt>");
4392 fileName
= (char *) file_table
[indx
].name
;
4395 fileName
= _("<unknown>");
4397 fileNameLength
= strlen (fileName
);
4399 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
4401 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
4402 /* Truncate file name */
4403 strncpy (newFileName
,
4404 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
4405 MAX_FILENAME_LENGTH
+ 1);
4409 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
4410 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
4413 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
4415 if (linfo
.li_max_ops_per_insn
== 1)
4416 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x",
4417 newFileName
, state_machine_regs
.line
,
4418 state_machine_regs
.address
);
4420 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4421 newFileName
, state_machine_regs
.line
,
4422 state_machine_regs
.address
,
4423 state_machine_regs
.op_index
);
4427 if (linfo
.li_max_ops_per_insn
== 1)
4428 printf ("%s %11d %#18" DWARF_VMA_FMT
"x",
4429 newFileName
, state_machine_regs
.line
,
4430 state_machine_regs
.address
);
4432 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]",
4433 newFileName
, state_machine_regs
.line
,
4434 state_machine_regs
.address
,
4435 state_machine_regs
.op_index
);
4438 if (state_machine_regs
.view
)
4439 printf (" %6u\n", state_machine_regs
.view
);
4442 state_machine_regs
.view
++;
4444 if (xop
== -DW_LNE_end_sequence
)
4446 reset_state_machine (linfo
.li_default_is_stmt
);
4461 if (directory_table
)
4463 free (directory_table
);
4464 directory_table
= NULL
;
4475 display_debug_lines (struct dwarf_section
*section
, void *file
)
4477 unsigned char *data
= section
->start
;
4478 unsigned char *end
= data
+ section
->size
;
4480 int retValDecoded
= 1;
4482 if (do_debug_lines
== 0)
4483 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
4485 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
4486 retValRaw
= display_debug_lines_raw (section
, data
, end
, file
);
4488 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
4489 retValDecoded
= display_debug_lines_decoded (section
, data
, end
, file
);
4491 if (!retValRaw
|| !retValDecoded
)
4498 find_debug_info_for_offset (unsigned long offset
)
4502 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
4505 for (i
= 0; i
< num_debug_info_entries
; i
++)
4506 if (debug_information
[i
].cu_offset
== offset
)
4507 return debug_information
+ i
;
4513 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
4515 /* See gdb/gdb-index.h. */
4516 static const char * const kinds
[] =
4528 return _ (kinds
[kind
]);
4532 display_debug_pubnames_worker (struct dwarf_section
*section
,
4533 void *file ATTRIBUTE_UNUSED
,
4536 DWARF2_Internal_PubNames names
;
4537 unsigned char *start
= section
->start
;
4538 unsigned char *end
= start
+ section
->size
;
4540 /* It does not matter if this load fails,
4541 we test for that later on. */
4542 load_debug_info (file
);
4544 printf (_("Contents of the %s section:\n\n"), section
->name
);
4548 unsigned char *data
;
4549 unsigned long sec_off
;
4550 unsigned int offset_size
, initial_length_size
;
4552 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 4, end
);
4553 if (names
.pn_length
== 0xffffffff)
4555 SAFE_BYTE_GET_AND_INC (names
.pn_length
, start
, 8, end
);
4557 initial_length_size
= 12;
4562 initial_length_size
= 4;
4565 sec_off
= start
- section
->start
;
4566 if (sec_off
+ names
.pn_length
< sec_off
4567 || sec_off
+ names
.pn_length
> section
->size
)
4569 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
4571 sec_off
- initial_length_size
,
4572 dwarf_vmatoa ("x", names
.pn_length
));
4577 start
+= names
.pn_length
;
4579 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
4580 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
4582 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4583 && num_debug_info_entries
> 0
4584 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
4585 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4586 (unsigned long) names
.pn_offset
, section
->name
);
4588 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
4590 printf (_(" Length: %ld\n"),
4591 (long) names
.pn_length
);
4592 printf (_(" Version: %d\n"),
4594 printf (_(" Offset into .debug_info section: 0x%lx\n"),
4595 (unsigned long) names
.pn_offset
);
4596 printf (_(" Size of area in .debug_info section: %ld\n"),
4597 (long) names
.pn_size
);
4599 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
4601 static int warned
= 0;
4605 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
4613 printf (_("\n Offset Kind Name\n"));
4615 printf (_("\n Offset\tName\n"));
4619 bfd_size_type maxprint
;
4622 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
4627 data
+= offset_size
;
4630 maxprint
= (end
- data
) - 1;
4634 unsigned int kind_data
;
4635 gdb_index_symbol_kind kind
;
4636 const char *kind_name
;
4639 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
4642 /* GCC computes the kind as the upper byte in the CU index
4643 word, and then right shifts it by the CU index size.
4644 Left shift KIND to where the gdb-index.h accessor macros
4646 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
4647 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
4648 kind_name
= get_gdb_index_symbol_kind_name (kind
);
4649 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
4650 printf (" %-6lx %s,%-10s %.*s\n",
4651 (unsigned long) offset
, is_static
? _("s") : _("g"),
4652 kind_name
, (int) maxprint
, data
);
4655 printf (" %-6lx\t%.*s\n",
4656 (unsigned long) offset
, (int) maxprint
, data
);
4658 data
+= strnlen ((char *) data
, maxprint
) + 1;
4669 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
4671 return display_debug_pubnames_worker (section
, file
, 0);
4675 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
4677 return display_debug_pubnames_worker (section
, file
, 1);
4681 display_debug_macinfo (struct dwarf_section
*section
,
4682 void *file ATTRIBUTE_UNUSED
)
4684 unsigned char *start
= section
->start
;
4685 unsigned char *end
= start
+ section
->size
;
4686 unsigned char *curr
= start
;
4687 unsigned int bytes_read
;
4688 enum dwarf_macinfo_record_type op
;
4690 printf (_("Contents of the %s section:\n\n"), section
->name
);
4694 unsigned int lineno
;
4695 const unsigned char *string
;
4697 op
= (enum dwarf_macinfo_record_type
) *curr
;
4702 case DW_MACINFO_start_file
:
4704 unsigned int filenum
;
4706 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4708 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
4711 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
4716 case DW_MACINFO_end_file
:
4717 printf (_(" DW_MACINFO_end_file\n"));
4720 case DW_MACINFO_define
:
4721 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4724 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4725 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
4729 case DW_MACINFO_undef
:
4730 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
4733 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4734 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
4738 case DW_MACINFO_vendor_ext
:
4740 unsigned int constant
;
4742 constant
= read_uleb128 (curr
, & bytes_read
, end
);
4745 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4746 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
4756 /* Given LINE_OFFSET into the .debug_line section, attempt to return
4757 filename and dirname corresponding to file name table entry with index
4758 FILEIDX. Return NULL on failure. */
4760 static unsigned char *
4761 get_line_filename_and_dirname (dwarf_vma line_offset
,
4763 unsigned char **dir_name
)
4765 struct dwarf_section
*section
= &debug_displays
[line
].section
;
4766 unsigned char *hdrptr
, *dirtable
, *file_name
;
4767 unsigned int offset_size
, initial_length_size
;
4768 unsigned int version
, opcode_base
, bytes_read
;
4769 dwarf_vma length
, diridx
;
4770 const unsigned char * end
;
4773 if (section
->start
== NULL
4774 || line_offset
>= section
->size
4778 hdrptr
= section
->start
+ line_offset
;
4779 end
= section
->start
+ section
->size
;
4781 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
4782 if (length
== 0xffffffff)
4784 /* This section is 64-bit DWARF 3. */
4785 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
4787 initial_length_size
= 12;
4792 initial_length_size
= 4;
4794 if (length
+ initial_length_size
< length
4795 || length
+ initial_length_size
> section
->size
)
4798 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
4799 if (version
!= 2 && version
!= 3 && version
!= 4)
4801 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
4803 hdrptr
++; /* Skip max_ops_per_insn. */
4804 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
4806 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
4807 if (opcode_base
== 0)
4810 hdrptr
+= opcode_base
- 1;
4815 /* Skip over dirname table. */
4816 while (*hdrptr
!= '\0')
4818 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4822 hdrptr
++; /* Skip the NUL at the end of the table. */
4824 /* Now skip over preceding filename table entries. */
4825 for (; hdrptr
< end
&& *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
4827 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4828 read_uleb128 (hdrptr
, &bytes_read
, end
);
4829 hdrptr
+= bytes_read
;
4830 read_uleb128 (hdrptr
, &bytes_read
, end
);
4831 hdrptr
+= bytes_read
;
4832 read_uleb128 (hdrptr
, &bytes_read
, end
);
4833 hdrptr
+= bytes_read
;
4835 if (hdrptr
>= end
|| *hdrptr
== '\0')
4839 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4842 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
4845 for (; dirtable
< end
&& *dirtable
!= '\0' && diridx
> 1; diridx
--)
4846 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
4847 if (dirtable
>= end
|| *dirtable
== '\0')
4849 *dir_name
= dirtable
;
4854 display_debug_macro (struct dwarf_section
*section
,
4857 unsigned char *start
= section
->start
;
4858 unsigned char *end
= start
+ section
->size
;
4859 unsigned char *curr
= start
;
4860 unsigned char *extended_op_buf
[256];
4861 unsigned int bytes_read
;
4863 load_debug_section (str
, file
);
4864 load_debug_section (line
, file
);
4866 printf (_("Contents of the %s section:\n\n"), section
->name
);
4870 unsigned int lineno
, version
, flags
;
4871 unsigned int offset_size
= 4;
4872 const unsigned char *string
;
4873 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
4874 unsigned char **extended_ops
= NULL
;
4876 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
4877 if (version
!= 4 && version
!= 5)
4879 error (_("Only GNU extension to DWARF 4 or 5 of %s is currently supported.\n"),
4884 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
4887 printf (_(" Offset: 0x%lx\n"),
4888 (unsigned long) sec_offset
);
4889 printf (_(" Version: %d\n"), version
);
4890 printf (_(" Offset size: %d\n"), offset_size
);
4893 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
4894 printf (_(" Offset into .debug_line: 0x%lx\n"),
4895 (unsigned long) line_offset
);
4899 unsigned int i
, count
, op
;
4902 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
4904 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
4905 extended_ops
= extended_op_buf
;
4908 printf (_(" Extension opcode arguments:\n"));
4909 for (i
= 0; i
< count
; i
++)
4911 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4912 extended_ops
[op
] = curr
;
4913 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
4916 printf (_(" DW_MACRO_%02x has no arguments\n"), op
);
4919 printf (_(" DW_MACRO_%02x arguments: "), op
);
4920 for (n
= 0; n
< nargs
; n
++)
4924 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
4925 printf ("%s%s", get_FORM_name (form
),
4926 n
== nargs
- 1 ? "\n" : ", ");
4936 case DW_FORM_block1
:
4937 case DW_FORM_block2
:
4938 case DW_FORM_block4
:
4940 case DW_FORM_string
:
4942 case DW_FORM_sec_offset
:
4945 error (_("Invalid extension opcode form %s\n"),
4946 get_FORM_name (form
));
4962 error (_(".debug_macro section not zero terminated\n"));
4966 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4972 case DW_MACRO_start_file
:
4974 unsigned int filenum
;
4975 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
4977 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4979 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
4982 if ((flags
& 2) == 0)
4983 error (_("DW_MACRO_start_file used, but no .debug_line offset provided.\n"));
4986 = get_line_filename_and_dirname (line_offset
, filenum
,
4988 if (file_name
== NULL
)
4989 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d\n"),
4992 printf (_(" DW_MACRO_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4994 dir_name
!= NULL
? (const char *) dir_name
: "",
4995 dir_name
!= NULL
? "/" : "", file_name
);
4999 case DW_MACRO_end_file
:
5000 printf (_(" DW_MACRO_end_file\n"));
5003 case DW_MACRO_define
:
5004 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5007 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5008 printf (_(" DW_MACRO_define - lineno : %d macro : %s\n"),
5012 case DW_MACRO_undef
:
5013 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5016 curr
+= strnlen ((char *) string
, end
- string
) + 1;
5017 printf (_(" DW_MACRO_undef - lineno : %d macro : %s\n"),
5021 case DW_MACRO_define_strp
:
5022 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5024 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5025 string
= fetch_indirect_string (offset
);
5026 printf (_(" DW_MACRO_define_strp - lineno : %d macro : %s\n"),
5030 case DW_MACRO_undef_strp
:
5031 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5033 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5034 string
= fetch_indirect_string (offset
);
5035 printf (_(" DW_MACRO_undef_strp - lineno : %d macro : %s\n"),
5039 case DW_MACRO_import
:
5040 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5041 printf (_(" DW_MACRO_import - offset : 0x%lx\n"),
5042 (unsigned long) offset
);
5045 case DW_MACRO_define_sup
:
5046 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5048 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5049 printf (_(" DW_MACRO_define_sup - lineno : %d macro offset : 0x%lx\n"),
5050 lineno
, (unsigned long) offset
);
5053 case DW_MACRO_undef_sup
:
5054 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
5056 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5057 printf (_(" DW_MACRO_undef_sup - lineno : %d macro offset : 0x%lx\n"),
5058 lineno
, (unsigned long) offset
);
5061 case DW_MACRO_import_sup
:
5062 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
5063 printf (_(" DW_MACRO_import_sup - offset : 0x%lx\n"),
5064 (unsigned long) offset
);
5068 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
5070 error (_(" Unknown macro opcode %02x seen\n"), op
);
5075 /* Skip over unhandled opcodes. */
5077 unsigned char *desc
= extended_ops
[op
];
5078 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
5082 printf (_(" DW_MACRO_%02x\n"), op
);
5085 printf (_(" DW_MACRO_%02x -"), op
);
5086 for (n
= 0; n
< nargs
; n
++)
5090 /* DW_FORM_implicit_const is not expected here. */
5091 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
5093 = read_and_display_attr_value (0, val
, 0,
5094 curr
, end
, 0, 0, offset_size
,
5095 version
, NULL
, 0, NULL
,
5113 display_debug_abbrev (struct dwarf_section
*section
,
5114 void *file ATTRIBUTE_UNUSED
)
5116 abbrev_entry
*entry
;
5117 unsigned char *start
= section
->start
;
5118 unsigned char *end
= start
+ section
->size
;
5120 printf (_("Contents of the %s section:\n\n"), section
->name
);
5124 unsigned char *last
;
5129 start
= process_abbrev_section (start
, end
);
5131 if (first_abbrev
== NULL
)
5134 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
5136 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
5140 printf (" %ld %s [%s]\n",
5142 get_TAG_name (entry
->tag
),
5143 entry
->children
? _("has children") : _("no children"));
5145 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
5147 printf (" %-18s %s",
5148 get_AT_name (attr
->attribute
),
5149 get_FORM_name (attr
->form
));
5150 if (attr
->form
== DW_FORM_implicit_const
)
5151 printf (": %" BFD_VMA_FMT
"d", attr
->implicit_const
);
5163 /* Return true when ADDR is the maximum address, when addresses are
5164 POINTER_SIZE bytes long. */
5167 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
5169 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
5170 return ((addr
& mask
) == mask
);
5173 /* Display a view pair list starting at *VSTART_PTR and ending at
5174 VLISTEND within SECTION. */
5177 display_view_pair_list (struct dwarf_section
*section
,
5178 unsigned char **vstart_ptr
,
5179 unsigned int debug_info_entry
,
5180 unsigned char *vlistend
)
5182 unsigned char *vstart
= *vstart_ptr
;
5183 unsigned char *section_end
= section
->start
+ section
->size
;
5184 unsigned int pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5186 if (vlistend
< section_end
)
5187 section_end
= vlistend
;
5191 while (vstart
< section_end
)
5193 dwarf_vma off
= vstart
- section
->start
;
5194 dwarf_vma vbegin
, vend
;
5196 unsigned int bytes_read
;
5197 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5198 vstart
+= bytes_read
;
5199 if (vstart
== section_end
)
5201 vstart
-= bytes_read
;
5205 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5206 vstart
+= bytes_read
;
5208 printf (" %8.8lx ", (unsigned long) off
);
5210 print_dwarf_view (vbegin
, pointer_size
, 1);
5211 print_dwarf_view (vend
, pointer_size
, 1);
5212 printf (_("location view pair\n"));
5216 *vstart_ptr
= vstart
;
5219 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
5222 display_loc_list (struct dwarf_section
*section
,
5223 unsigned char **start_ptr
,
5224 unsigned int debug_info_entry
,
5226 dwarf_vma base_address
,
5227 unsigned char **vstart_ptr
,
5230 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5231 unsigned char *section_end
= section
->start
+ section
->size
;
5232 unsigned long cu_offset
;
5233 unsigned int pointer_size
;
5234 unsigned int offset_size
;
5239 unsigned short length
;
5240 int need_frame_base
;
5242 if (debug_info_entry
>= num_debug_info_entries
)
5244 warn (_("No debug information available for loc lists of entry: %u\n"),
5249 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5250 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5251 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5252 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5254 if (pointer_size
< 2 || pointer_size
> 8)
5256 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5257 pointer_size
, debug_info_entry
);
5263 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5264 dwarf_vma vbegin
= vm1
, vend
= vm1
;
5266 if (start
+ 2 * pointer_size
> section_end
)
5268 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5269 (unsigned long) offset
);
5273 printf (" %8.8lx ", (unsigned long) off
);
5275 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
5276 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
5278 if (begin
== 0 && end
== 0)
5280 /* PR 18374: In a object file we can have a location list that
5281 starts with a begin and end of 0 because there are relocations
5282 that need to be applied to the addresses. Actually applying
5283 the relocations now does not help as they will probably resolve
5284 to 0, since the object file has not been fully linked. Real
5285 end of list markers will not have any relocations against them. */
5286 if (! reloc_at (section
, off
)
5287 && ! reloc_at (section
, off
+ pointer_size
))
5289 printf (_("<End of list>\n"));
5294 /* Check base address specifiers. */
5295 if (is_max_address (begin
, pointer_size
)
5296 && !is_max_address (end
, pointer_size
))
5299 print_dwarf_vma (begin
, pointer_size
);
5300 print_dwarf_vma (end
, pointer_size
);
5301 printf (_("(base address)\n"));
5307 unsigned int bytes_read
;
5309 off
= offset
+ (vstart
- *start_ptr
);
5311 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5312 vstart
+= bytes_read
;
5313 print_dwarf_view (vbegin
, pointer_size
, 1);
5315 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5316 vstart
+= bytes_read
;
5317 print_dwarf_view (vend
, pointer_size
, 1);
5319 printf (_("views at %8.8lx for:\n %*s "),
5320 (unsigned long) off
, 8, "");
5323 if (start
+ 2 > section_end
)
5325 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5326 (unsigned long) offset
);
5330 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5332 if (start
+ length
> section_end
)
5334 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5335 (unsigned long) offset
);
5339 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5340 print_dwarf_vma (end
+ base_address
, pointer_size
);
5343 need_frame_base
= decode_location_expression (start
,
5348 cu_offset
, section
);
5351 if (need_frame_base
&& !has_frame_base
)
5352 printf (_(" [without DW_AT_frame_base]"));
5354 if (begin
== end
&& vbegin
== vend
)
5355 fputs (_(" (start == end)"), stdout
);
5356 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5357 fputs (_(" (start > end)"), stdout
);
5365 *vstart_ptr
= vstart
;
5368 /* Display a location list from a normal (ie, non-dwo) .debug_loclists section. */
5371 display_loclists_list (struct dwarf_section
*section
,
5372 unsigned char **start_ptr
,
5373 unsigned int debug_info_entry
,
5375 dwarf_vma base_address
,
5376 unsigned char **vstart_ptr
,
5379 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5380 unsigned char *section_end
= section
->start
+ section
->size
;
5381 unsigned long cu_offset
;
5382 unsigned int pointer_size
;
5383 unsigned int offset_size
;
5385 unsigned int bytes_read
;
5387 /* Initialize it due to a false compiler warning. */
5388 dwarf_vma begin
= -1, vbegin
= -1;
5389 dwarf_vma end
= -1, vend
= -1;
5391 int need_frame_base
;
5393 if (debug_info_entry
>= num_debug_info_entries
)
5395 warn (_("No debug information available for "
5396 "loclists lists of entry: %u\n"),
5401 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5402 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5403 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5404 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5406 if (pointer_size
< 2 || pointer_size
> 8)
5408 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5409 pointer_size
, debug_info_entry
);
5415 dwarf_vma off
= offset
+ (start
- *start_ptr
);
5416 enum dwarf_location_list_entry_type llet
;
5418 if (start
+ 1 > section_end
)
5420 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5421 (unsigned long) offset
);
5425 printf (" %8.8lx ", (unsigned long) off
);
5427 SAFE_BYTE_GET_AND_INC (llet
, start
, 1, section_end
);
5429 if (vstart
&& llet
== DW_LLE_offset_pair
)
5431 off
= offset
+ (vstart
- *start_ptr
);
5433 vbegin
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5434 vstart
+= bytes_read
;
5435 print_dwarf_view (vbegin
, pointer_size
, 1);
5437 vend
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5438 vstart
+= bytes_read
;
5439 print_dwarf_view (vend
, pointer_size
, 1);
5441 printf (_("views at %8.8lx for:\n %*s "),
5442 (unsigned long) off
, 8, "");
5447 case DW_LLE_end_of_list
:
5448 printf (_("<End of list>\n"));
5450 case DW_LLE_offset_pair
:
5451 begin
= read_uleb128 (start
, &bytes_read
, section_end
);
5452 start
+= bytes_read
;
5453 end
= read_uleb128 (start
, &bytes_read
, section_end
);
5454 start
+= bytes_read
;
5456 case DW_LLE_base_address
:
5457 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
,
5459 print_dwarf_vma (base_address
, pointer_size
);
5460 printf (_("(base address)\n"));
5462 #ifdef DW_LLE_view_pair
5463 case DW_LLE_view_pair
:
5465 printf (_("View pair entry in loclist with locviews attribute\n"));
5466 vbegin
= read_uleb128 (start
, &bytes_read
, section_end
);
5467 start
+= bytes_read
;
5468 print_dwarf_view (vbegin
, pointer_size
, 1);
5470 vend
= read_uleb128 (start
, &bytes_read
, section_end
);
5471 start
+= bytes_read
;
5472 print_dwarf_view (vend
, pointer_size
, 1);
5474 printf (_("views for:\n"));
5478 error (_("Invalid location list entry type %d\n"), llet
);
5481 if (llet
== DW_LLE_end_of_list
)
5483 if (llet
!= DW_LLE_offset_pair
)
5486 if (start
+ 2 > section_end
)
5488 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5489 (unsigned long) offset
);
5493 length
= read_uleb128 (start
, &bytes_read
, section_end
);
5494 start
+= bytes_read
;
5496 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5497 print_dwarf_vma (end
+ base_address
, pointer_size
);
5500 need_frame_base
= decode_location_expression (start
,
5505 cu_offset
, section
);
5508 if (need_frame_base
&& !has_frame_base
)
5509 printf (_(" [without DW_AT_frame_base]"));
5511 if (begin
== end
&& vbegin
== vend
)
5512 fputs (_(" (start == end)"), stdout
);
5513 else if (begin
> end
|| (begin
== end
&& vbegin
> vend
))
5514 fputs (_(" (start > end)"), stdout
);
5522 if (vbegin
!= vm1
|| vend
!= vm1
)
5523 printf (_("Trailing view pair not used in a range"));
5526 *vstart_ptr
= vstart
;
5529 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
5530 right-adjusted in a field of length LEN, and followed by a space. */
5533 print_addr_index (unsigned int idx
, unsigned int len
)
5535 static char buf
[15];
5536 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
5537 printf ("%*s ", len
, buf
);
5540 /* Display a location list from a .dwo section. It uses address indexes rather
5541 than embedded addresses. This code closely follows display_loc_list, but the
5542 two are sufficiently different that combining things is very ugly. */
5545 display_loc_list_dwo (struct dwarf_section
*section
,
5546 unsigned char **start_ptr
,
5547 unsigned int debug_info_entry
,
5549 unsigned char **vstart_ptr
,
5552 unsigned char *start
= *start_ptr
, *vstart
= *vstart_ptr
;
5553 unsigned char *section_end
= section
->start
+ section
->size
;
5554 unsigned long cu_offset
;
5555 unsigned int pointer_size
;
5556 unsigned int offset_size
;
5559 unsigned short length
;
5560 int need_frame_base
;
5562 unsigned int bytes_read
;
5564 if (debug_info_entry
>= num_debug_info_entries
)
5566 warn (_("No debug information for loc lists of entry: %u\n"),
5571 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
5572 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
5573 offset_size
= debug_information
[debug_info_entry
].offset_size
;
5574 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
5576 if (pointer_size
< 2 || pointer_size
> 8)
5578 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
5579 pointer_size
, debug_info_entry
);
5585 printf (" %8.8lx ", (unsigned long) (offset
+ (start
- *start_ptr
)));
5587 if (start
>= section_end
)
5589 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5590 (unsigned long) offset
);
5594 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
5607 dwarf_vma off
= offset
+ (vstart
- *start_ptr
);
5609 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5610 vstart
+= bytes_read
;
5611 print_dwarf_view (view
, 8, 1);
5613 view
= read_uleb128 (vstart
, &bytes_read
, section_end
);
5614 vstart
+= bytes_read
;
5615 print_dwarf_view (view
, 8, 1);
5617 printf (_("views at %8.8lx for:\n %*s "),
5618 (unsigned long) off
, 8, "");
5626 case 0: /* A terminating entry. */
5628 *vstart_ptr
= vstart
;
5629 printf (_("<End of list>\n"));
5631 case 1: /* A base-address entry. */
5632 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5633 start
+= bytes_read
;
5634 print_addr_index (idx
, 8);
5635 printf ("%*s", 9 + (vstart
? 2 * 6 : 0), "");
5636 printf (_("(base address selection entry)\n"));
5638 case 2: /* A start/end entry. */
5639 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5640 start
+= bytes_read
;
5641 print_addr_index (idx
, 8);
5642 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5643 start
+= bytes_read
;
5644 print_addr_index (idx
, 8);
5646 case 3: /* A start/length entry. */
5647 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
5648 start
+= bytes_read
;
5649 print_addr_index (idx
, 8);
5650 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5651 printf ("%08x ", idx
);
5653 case 4: /* An offset pair entry. */
5654 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5655 printf ("%08x ", idx
);
5656 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
5657 printf ("%08x ", idx
);
5660 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
5662 *vstart_ptr
= vstart
;
5666 if (start
+ 2 > section_end
)
5668 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5669 (unsigned long) offset
);
5673 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
5674 if (start
+ length
> section_end
)
5676 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
5677 (unsigned long) offset
);
5682 need_frame_base
= decode_location_expression (start
,
5687 cu_offset
, section
);
5690 if (need_frame_base
&& !has_frame_base
)
5691 printf (_(" [without DW_AT_frame_base]"));
5699 *vstart_ptr
= vstart
;
5702 /* Sort array of indexes in ascending order of loc_offsets[idx] and
5705 static dwarf_vma
*loc_offsets
, *loc_views
;
5708 loc_offsets_compar (const void *ap
, const void *bp
)
5710 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
5711 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
5713 int ret
= (a
> b
) - (b
> a
);
5717 a
= loc_views
[*(const unsigned int *) ap
];
5718 b
= loc_views
[*(const unsigned int *) bp
];
5720 ret
= (a
> b
) - (b
> a
);
5726 display_debug_loc (struct dwarf_section
*section
, void *file
)
5728 unsigned char *start
= section
->start
, *vstart
= NULL
;
5729 unsigned long bytes
;
5730 unsigned char *section_begin
= start
;
5731 unsigned int num_loc_list
= 0;
5732 unsigned long last_offset
= 0;
5733 unsigned long last_view
= 0;
5734 unsigned int first
= 0;
5737 int seen_first_offset
= 0;
5738 int locs_sorted
= 1;
5739 unsigned char *next
= start
, *vnext
= vstart
;
5740 unsigned int *array
= NULL
;
5741 const char *suffix
= strrchr (section
->name
, '.');
5743 int is_loclists
= strstr (section
->name
, "debug_loclists") != NULL
;
5744 dwarf_vma expected_start
= 0;
5746 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
5749 bytes
= section
->size
;
5753 printf (_("\nThe %s section is empty.\n"), section
->name
);
5759 unsigned char *hdrptr
= section_begin
;
5760 dwarf_vma ll_length
;
5761 unsigned short ll_version
;
5762 unsigned char *end
= section_begin
+ section
->size
;
5763 unsigned char address_size
, segment_selector_size
;
5764 uint32_t offset_entry_count
;
5766 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 4, end
);
5767 if (ll_length
== 0xffffffff)
5768 SAFE_BYTE_GET_AND_INC (ll_length
, hdrptr
, 8, end
);
5770 SAFE_BYTE_GET_AND_INC (ll_version
, hdrptr
, 2, end
);
5771 if (ll_version
!= 5)
5773 warn (_("The %s section contains corrupt or "
5774 "unsupported version number: %d.\n"),
5775 section
->name
, ll_version
);
5779 SAFE_BYTE_GET_AND_INC (address_size
, hdrptr
, 1, end
);
5781 SAFE_BYTE_GET_AND_INC (segment_selector_size
, hdrptr
, 1, end
);
5782 if (segment_selector_size
!= 0)
5784 warn (_("The %s section contains "
5785 "unsupported segment selector size: %d.\n"),
5786 section
->name
, segment_selector_size
);
5790 SAFE_BYTE_GET_AND_INC (offset_entry_count
, hdrptr
, 4, end
);
5791 if (offset_entry_count
!= 0)
5793 warn (_("The %s section contains "
5794 "unsupported offset entry count: %d.\n"),
5795 section
->name
, offset_entry_count
);
5799 expected_start
= hdrptr
- section_begin
;
5802 if (load_debug_info (file
) == 0)
5804 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5809 /* Check the order of location list in .debug_info section. If
5810 offsets of location lists are in the ascending order, we can
5811 use `debug_information' directly. */
5812 for (i
= 0; i
< num_debug_info_entries
; i
++)
5816 num
= debug_information
[i
].num_loc_offsets
;
5817 if (num
> num_loc_list
)
5820 /* Check if we can use `debug_information' directly. */
5821 if (locs_sorted
&& num
!= 0)
5823 if (!seen_first_offset
)
5825 /* This is the first location list. */
5826 last_offset
= debug_information
[i
].loc_offsets
[0];
5827 last_view
= debug_information
[i
].loc_views
[0];
5829 seen_first_offset
= 1;
5835 for (; j
< num
; j
++)
5838 debug_information
[i
].loc_offsets
[j
]
5839 || (last_offset
== debug_information
[i
].loc_offsets
[j
]
5840 && last_view
> debug_information
[i
].loc_views
[j
]))
5845 last_offset
= debug_information
[i
].loc_offsets
[j
];
5846 last_view
= debug_information
[i
].loc_views
[j
];
5851 if (!seen_first_offset
)
5852 error (_("No location lists in .debug_info section!\n"));
5854 if (debug_information
[first
].num_loc_offsets
> 0
5855 && debug_information
[first
].loc_offsets
[0] != expected_start
5856 && debug_information
[first
].loc_views
[0] != expected_start
)
5857 warn (_("Location lists in %s section start at 0x%s\n"),
5859 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
5862 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
5863 printf (_("Contents of the %s section:\n\n"), section
->name
);
5864 if (reloc_at (section
, 0))
5865 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
5866 printf (_(" Offset Begin End Expression\n"));
5868 seen_first_offset
= 0;
5869 for (i
= first
; i
< num_debug_info_entries
; i
++)
5871 dwarf_vma offset
, voffset
;
5872 dwarf_vma base_address
;
5878 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
5880 loc_offsets
= debug_information
[i
].loc_offsets
;
5881 loc_views
= debug_information
[i
].loc_views
;
5882 qsort (array
, debug_information
[i
].num_loc_offsets
,
5883 sizeof (*array
), loc_offsets_compar
);
5886 int adjacent_view_loclists
= 1;
5887 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
5889 j
= locs_sorted
? k
: array
[k
];
5891 && (debug_information
[i
].loc_offsets
[locs_sorted
5892 ? k
- 1 : array
[k
- 1]]
5893 == debug_information
[i
].loc_offsets
[j
])
5894 && (debug_information
[i
].loc_views
[locs_sorted
5895 ? k
- 1 : array
[k
- 1]]
5896 == debug_information
[i
].loc_views
[j
]))
5898 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
5899 offset
= debug_information
[i
].loc_offsets
[j
];
5900 next
= section_begin
+ offset
;
5901 voffset
= debug_information
[i
].loc_views
[j
];
5903 vnext
= section_begin
+ voffset
;
5906 base_address
= debug_information
[i
].base_address
;
5908 if (vnext
&& vnext
< next
)
5911 display_view_pair_list (section
, &vstart
, i
, next
);
5916 if (!seen_first_offset
|| !adjacent_view_loclists
)
5917 seen_first_offset
= 1;
5921 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
5922 (unsigned long) (start
- section_begin
),
5923 (unsigned long) offset
);
5924 else if (start
> next
)
5925 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
5926 (unsigned long) (start
- section_begin
),
5927 (unsigned long) offset
);
5932 if (offset
>= bytes
)
5934 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
5935 (unsigned long) offset
);
5939 if (vnext
&& voffset
>= bytes
)
5941 warn (_("View Offset 0x%lx is bigger than .debug_loc section size.\n"),
5942 (unsigned long) voffset
);
5949 display_loc_list_dwo (section
, &start
, i
, offset
,
5950 &vstart
, has_frame_base
);
5952 display_loc_list (section
, &start
, i
, offset
, base_address
,
5953 &vstart
, has_frame_base
);
5958 warn (_("DWO is not yet supported.\n"));
5960 display_loclists_list (section
, &start
, i
, offset
, base_address
,
5961 &vstart
, has_frame_base
);
5964 /* FIXME: this arrangement is quite simplistic. Nothing
5965 requires locview lists to be adjacent to corresponding
5966 loclists, and a single loclist could be augmented by
5967 different locview lists, and vice-versa, unlikely as it
5968 is that it would make sense to do so. Hopefully we'll
5969 have view pair support built into loclists before we ever
5970 need to address all these possibilities. */
5971 if (adjacent_view_loclists
&& vnext
5972 && vnext
!= start
&& vstart
!= next
)
5974 adjacent_view_loclists
= 0;
5975 warn (_("Hole and overlap detection requires adjacent view lists and loclists.\n"));
5978 if (vnext
&& vnext
== start
)
5979 display_view_pair_list (section
, &start
, i
, vstart
);
5983 if (start
< section
->start
+ section
->size
)
5984 warn (_("There are %ld unused bytes at the end of section %s\n"),
5985 (long) (section
->start
+ section
->size
- start
), section
->name
);
5992 display_debug_str (struct dwarf_section
*section
,
5993 void *file ATTRIBUTE_UNUSED
)
5995 unsigned char *start
= section
->start
;
5996 unsigned long bytes
= section
->size
;
5997 dwarf_vma addr
= section
->address
;
6001 printf (_("\nThe %s section is empty.\n"), section
->name
);
6005 printf (_("Contents of the %s section:\n\n"), section
->name
);
6013 lbytes
= (bytes
> 16 ? 16 : bytes
);
6015 printf (" 0x%8.8lx ", (unsigned long) addr
);
6017 for (j
= 0; j
< 16; j
++)
6020 printf ("%2.2x", start
[j
]);
6028 for (j
= 0; j
< lbytes
; j
++)
6031 if (k
>= ' ' && k
< 0x80)
6050 display_debug_info (struct dwarf_section
*section
, void *file
)
6052 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
6056 display_debug_types (struct dwarf_section
*section
, void *file
)
6058 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 1);
6062 display_trace_info (struct dwarf_section
*section
, void *file
)
6064 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
6068 display_debug_aranges (struct dwarf_section
*section
,
6069 void *file ATTRIBUTE_UNUSED
)
6071 unsigned char *start
= section
->start
;
6072 unsigned char *end
= start
+ section
->size
;
6074 printf (_("Contents of the %s section:\n\n"), section
->name
);
6076 /* It does not matter if this load fails,
6077 we test for that later on. */
6078 load_debug_info (file
);
6082 unsigned char *hdrptr
;
6083 DWARF2_Internal_ARange arange
;
6084 unsigned char *addr_ranges
;
6087 unsigned long sec_off
;
6088 unsigned char address_size
;
6090 unsigned int offset_size
;
6091 unsigned int initial_length_size
;
6095 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
6096 if (arange
.ar_length
== 0xffffffff)
6098 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
6100 initial_length_size
= 12;
6105 initial_length_size
= 4;
6108 sec_off
= hdrptr
- section
->start
;
6109 if (sec_off
+ arange
.ar_length
< sec_off
6110 || sec_off
+ arange
.ar_length
> section
->size
)
6112 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
6114 sec_off
- initial_length_size
,
6115 dwarf_vmatoa ("x", arange
.ar_length
));
6119 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
6120 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
6122 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
6123 && num_debug_info_entries
> 0
6124 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
6125 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
6126 (unsigned long) arange
.ar_info_offset
, section
->name
);
6128 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
6129 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
6131 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
6133 /* PR 19872: A version number of 0 probably means that there is
6134 padding at the end of the .debug_aranges section. Gold puts
6135 it there when performing an incremental link, for example.
6136 So do not generate a warning in this case. */
6137 if (arange
.ar_version
)
6138 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
6142 printf (_(" Length: %ld\n"),
6143 (long) arange
.ar_length
);
6144 printf (_(" Version: %d\n"), arange
.ar_version
);
6145 printf (_(" Offset into .debug_info: 0x%lx\n"),
6146 (unsigned long) arange
.ar_info_offset
);
6147 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
6148 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
6150 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
6152 /* PR 17512: file: 001-108546-0.001:0.1. */
6153 if (address_size
== 0 || address_size
> 8)
6155 error (_("Invalid address size in %s section!\n"),
6160 /* The DWARF spec does not require that the address size be a power
6161 of two, but we do. This will have to change if we ever encounter
6162 an uneven architecture. */
6163 if ((address_size
& (address_size
- 1)) != 0)
6165 warn (_("Pointer size + Segment size is not a power of two.\n"));
6169 if (address_size
> 4)
6170 printf (_("\n Address Length\n"));
6172 printf (_("\n Address Length\n"));
6174 addr_ranges
= hdrptr
;
6176 /* Must pad to an alignment boundary that is twice the address size. */
6177 excess
= (hdrptr
- start
) % (2 * address_size
);
6179 addr_ranges
+= (2 * address_size
) - excess
;
6181 start
+= arange
.ar_length
+ initial_length_size
;
6183 while (addr_ranges
+ 2 * address_size
<= start
)
6185 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
6186 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
6189 print_dwarf_vma (address
, address_size
);
6190 print_dwarf_vma (length
, address_size
);
6200 /* Comparison function for qsort. */
6202 comp_addr_base (const void * v0
, const void * v1
)
6204 debug_info
* info0
= (debug_info
*) v0
;
6205 debug_info
* info1
= (debug_info
*) v1
;
6206 return info0
->addr_base
- info1
->addr_base
;
6209 /* Display the debug_addr section. */
6211 display_debug_addr (struct dwarf_section
*section
,
6214 debug_info
**debug_addr_info
;
6215 unsigned char *entry
;
6220 if (section
->size
== 0)
6222 printf (_("\nThe %s section is empty.\n"), section
->name
);
6226 if (load_debug_info (file
) == 0)
6228 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6233 printf (_("Contents of the %s section:\n\n"), section
->name
);
6235 /* PR 17531: file: cf38d01b.
6236 We use xcalloc because a corrupt file may not have initialised all of the
6237 fields in the debug_info structure, which means that the sort below might
6238 try to move uninitialised data. */
6239 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
6240 sizeof (debug_info
*));
6243 for (i
= 0; i
< num_debug_info_entries
; i
++)
6244 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
6246 /* PR 17531: file: cf38d01b. */
6247 if (debug_information
[i
].addr_base
>= section
->size
)
6248 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
6249 (unsigned long) debug_information
[i
].addr_base
, i
);
6251 debug_addr_info
[count
++] = debug_information
+ i
;
6254 /* Add a sentinel to make iteration convenient. */
6255 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
6256 debug_addr_info
[count
]->addr_base
= section
->size
;
6257 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
6259 for (i
= 0; i
< count
; i
++)
6262 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
6264 printf (_(" For compilation unit at offset 0x%s:\n"),
6265 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
6267 printf (_("\tIndex\tAddress\n"));
6268 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
6269 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
6273 dwarf_vma base
= byte_get (entry
, address_size
);
6274 printf (_("\t%d:\t"), idx
);
6275 print_dwarf_vma (base
, address_size
);
6277 entry
+= address_size
;
6283 free (debug_addr_info
);
6287 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
6289 display_debug_str_offsets (struct dwarf_section
*section
,
6290 void *file ATTRIBUTE_UNUSED
)
6292 if (section
->size
== 0)
6294 printf (_("\nThe %s section is empty.\n"), section
->name
);
6297 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
6298 what the offset size is for this section. */
6302 /* Each debug_information[x].range_lists[y] gets this representation for
6303 sorting purposes. */
6307 /* The debug_information[x].range_lists[y] value. */
6308 dwarf_vma ranges_offset
;
6310 /* Original debug_information to find parameters of the data. */
6311 debug_info
*debug_info_p
;
6314 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
6317 range_entry_compar (const void *ap
, const void *bp
)
6319 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
6320 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
6321 const dwarf_vma a
= a_re
->ranges_offset
;
6322 const dwarf_vma b
= b_re
->ranges_offset
;
6324 return (a
> b
) - (b
> a
);
6328 display_debug_ranges_list (unsigned char *start
, unsigned char *finish
,
6329 unsigned int pointer_size
, unsigned long offset
,
6330 unsigned long base_address
)
6332 while (start
< finish
)
6337 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6338 if (start
>= finish
)
6340 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6342 printf (" %8.8lx ", offset
);
6344 if (begin
== 0 && end
== 0)
6346 printf (_("<End of list>\n"));
6350 /* Check base address specifiers. */
6351 if (is_max_address (begin
, pointer_size
)
6352 && !is_max_address (end
, pointer_size
))
6355 print_dwarf_vma (begin
, pointer_size
);
6356 print_dwarf_vma (end
, pointer_size
);
6357 printf ("(base address)\n");
6361 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6362 print_dwarf_vma (end
+ base_address
, pointer_size
);
6365 fputs (_("(start == end)"), stdout
);
6366 else if (begin
> end
)
6367 fputs (_("(start > end)"), stdout
);
6374 display_debug_rnglists_list (unsigned char *start
, unsigned char *finish
,
6375 unsigned int pointer_size
, unsigned long offset
,
6376 unsigned long base_address
)
6378 unsigned char *next
= start
;
6382 unsigned long off
= offset
+ (start
- next
);
6383 enum dwarf_range_list_entry rlet
;
6384 /* Initialize it due to a false compiler warning. */
6385 dwarf_vma begin
= -1, length
, end
= -1;
6386 unsigned int bytes_read
;
6388 if (start
+ 1 > finish
)
6390 warn (_("Range list starting at offset 0x%lx is not terminated.\n"),
6395 printf (" %8.8lx ", off
);
6397 SAFE_BYTE_GET_AND_INC (rlet
, start
, 1, finish
);
6401 case DW_RLE_end_of_list
:
6402 printf (_("<End of list>\n"));
6404 case DW_RLE_base_address
:
6405 SAFE_BYTE_GET_AND_INC (base_address
, start
, pointer_size
, finish
);
6406 print_dwarf_vma (base_address
, pointer_size
);
6407 printf (_("(base address)\n"));
6409 case DW_RLE_start_length
:
6410 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6411 length
= read_uleb128 (start
, &bytes_read
, finish
);
6412 start
+= bytes_read
;
6413 end
= begin
+ length
;
6415 case DW_RLE_offset_pair
:
6416 begin
= read_uleb128 (start
, &bytes_read
, finish
);
6417 start
+= bytes_read
;
6418 end
= read_uleb128 (start
, &bytes_read
, finish
);
6419 start
+= bytes_read
;
6421 case DW_RLE_start_end
:
6422 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
6423 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
6426 error (_("Invalid range list entry type %d\n"), rlet
);
6427 rlet
= DW_RLE_end_of_list
;
6430 if (rlet
== DW_RLE_end_of_list
)
6432 if (rlet
== DW_RLE_base_address
)
6435 print_dwarf_vma (begin
+ base_address
, pointer_size
);
6436 print_dwarf_vma (end
+ base_address
, pointer_size
);
6439 fputs (_("(start == end)"), stdout
);
6440 else if (begin
> end
)
6441 fputs (_("(start > end)"), stdout
);
6448 display_debug_ranges (struct dwarf_section
*section
,
6449 void *file ATTRIBUTE_UNUSED
)
6451 unsigned char *start
= section
->start
;
6452 unsigned char *last_start
= start
;
6453 unsigned long bytes
= section
->size
;
6454 unsigned char *section_begin
= start
;
6455 unsigned char *finish
= start
+ bytes
;
6456 unsigned int num_range_list
, i
;
6457 struct range_entry
*range_entries
, *range_entry_fill
;
6458 int is_rnglists
= strstr (section
->name
, "debug_rnglists") != NULL
;
6459 /* Initialize it due to a false compiler warning. */
6460 unsigned char address_size
= 0;
6464 printf (_("\nThe %s section is empty.\n"), section
->name
);
6470 dwarf_vma initial_length
;
6471 unsigned int initial_length_size
;
6472 unsigned char segment_selector_size
;
6473 unsigned int offset_size
, offset_entry_count
;
6474 unsigned short version
;
6476 /* Get and check the length of the block. */
6477 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 4, finish
);
6479 if (initial_length
== 0xffffffff)
6481 /* This section is 64-bit DWARF 3. */
6482 SAFE_BYTE_GET_AND_INC (initial_length
, start
, 8, finish
);
6484 initial_length_size
= 12;
6489 initial_length_size
= 4;
6492 if (initial_length
+ initial_length_size
> section
->size
)
6494 /* If the length field has a relocation against it, then we should
6495 not complain if it is inaccurate (and probably negative).
6496 It is copied from .debug_line handling code. */
6497 if (reloc_at (section
, (start
- section
->start
) - offset_size
))
6499 initial_length
= (finish
- start
) - initial_length_size
;
6503 warn (_("The length field (0x%lx) in the debug_rnglists header is wrong - the section is too small\n"),
6504 (long) initial_length
);
6509 /* Get and check the version number. */
6510 SAFE_BYTE_GET_AND_INC (version
, start
, 2, finish
);
6514 warn (_("Only DWARF version 5 debug_rnglists info "
6515 "is currently supported.\n"));
6519 SAFE_BYTE_GET_AND_INC (address_size
, start
, 1, finish
);
6521 SAFE_BYTE_GET_AND_INC (segment_selector_size
, start
, 1, finish
);
6522 if (segment_selector_size
!= 0)
6524 warn (_("The %s section contains "
6525 "unsupported segment selector size: %d.\n"),
6526 section
->name
, segment_selector_size
);
6530 SAFE_BYTE_GET_AND_INC (offset_entry_count
, start
, 4, finish
);
6531 if (offset_entry_count
!= 0)
6533 warn (_("The %s section contains "
6534 "unsupported offset entry count: %u.\n"),
6535 section
->name
, offset_entry_count
);
6540 if (load_debug_info (file
) == 0)
6542 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
6548 for (i
= 0; i
< num_debug_info_entries
; i
++)
6549 num_range_list
+= debug_information
[i
].num_range_lists
;
6551 if (num_range_list
== 0)
6553 /* This can happen when the file was compiled with -gsplit-debug
6554 which removes references to range lists from the primary .o file. */
6555 printf (_("No range lists in .debug_info section.\n"));
6559 range_entries
= (struct range_entry
*)
6560 xmalloc (sizeof (*range_entries
) * num_range_list
);
6561 range_entry_fill
= range_entries
;
6563 for (i
= 0; i
< num_debug_info_entries
; i
++)
6565 debug_info
*debug_info_p
= &debug_information
[i
];
6568 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
6570 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
6571 range_entry_fill
->debug_info_p
= debug_info_p
;
6576 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
6577 range_entry_compar
);
6579 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
6580 warn (_("Range lists in %s section start at 0x%lx\n"),
6581 section
->name
, (unsigned long) range_entries
[0].ranges_offset
);
6583 printf (_("Contents of the %s section:\n\n"), section
->name
);
6584 printf (_(" Offset Begin End\n"));
6586 for (i
= 0; i
< num_range_list
; i
++)
6588 struct range_entry
*range_entry
= &range_entries
[i
];
6589 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
6590 unsigned int pointer_size
;
6592 unsigned char *next
;
6593 dwarf_vma base_address
;
6595 pointer_size
= (is_rnglists
? address_size
: debug_info_p
->pointer_size
);
6596 offset
= range_entry
->ranges_offset
;
6597 next
= section_begin
+ offset
;
6598 base_address
= debug_info_p
->base_address
;
6600 /* PR 17512: file: 001-101485-0.001:0.1. */
6601 if (pointer_size
< 2 || pointer_size
> 8)
6603 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
6604 pointer_size
, (unsigned long) offset
);
6608 if (dwarf_check
!= 0 && i
> 0)
6611 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
6612 (unsigned long) (start
- section_begin
),
6613 (unsigned long) (next
- section_begin
), section
->name
);
6614 else if (start
> next
)
6616 if (next
== last_start
)
6618 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
6619 (unsigned long) (start
- section_begin
),
6620 (unsigned long) (next
- section_begin
), section
->name
);
6626 (is_rnglists
? display_debug_rnglists_list
: display_debug_ranges_list
)
6627 (start
, finish
, pointer_size
, offset
, base_address
);
6631 free (range_entries
);
6636 typedef struct Frame_Chunk
6638 struct Frame_Chunk
*next
;
6639 unsigned char *chunk_start
;
6641 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
6642 short int *col_type
;
6645 unsigned int code_factor
;
6649 unsigned int cfa_reg
;
6650 dwarf_vma cfa_offset
;
6652 unsigned char fde_encoding
;
6653 unsigned char cfa_exp
;
6654 unsigned char ptr_size
;
6655 unsigned char segment_size
;
6659 static const char *const *dwarf_regnames
;
6660 static unsigned int dwarf_regnames_count
;
6662 /* A marker for a col_type that means this column was never referenced
6663 in the frame info. */
6664 #define DW_CFA_unreferenced (-1)
6666 /* Return 0 if no more space is needed, 1 if more space is needed,
6667 -1 for invalid reg. */
6670 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
6672 unsigned int prev
= fc
->ncols
;
6674 if (reg
< (unsigned int) fc
->ncols
)
6677 if (dwarf_regnames_count
6678 && reg
> dwarf_regnames_count
)
6681 fc
->ncols
= reg
+ 1;
6682 /* PR 17512: file: 10450-2643-0.004.
6683 If reg == -1 then this can happen... */
6687 /* PR 17512: file: 2844a11d. */
6688 if (fc
->ncols
> 1024)
6690 error (_("Unfeasibly large register number: %u\n"), reg
);
6692 /* FIXME: 1024 is an arbitrary limit. Increase it if
6693 we ever encounter a valid binary that exceeds it. */
6697 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
6698 sizeof (short int));
6699 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
6700 /* PR 17512: file:002-10025-0.005. */
6701 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
6703 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
6709 while (prev
< fc
->ncols
)
6711 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
6712 fc
->col_offset
[prev
] = 0;
6718 static const char *const dwarf_regnames_i386
[] =
6720 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6721 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6722 "eip", "eflags", NULL
, /* 8 - 10 */
6723 "st0", "st1", "st2", "st3", /* 11 - 14 */
6724 "st4", "st5", "st6", "st7", /* 15 - 18 */
6725 NULL
, NULL
, /* 19 - 20 */
6726 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
6727 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
6728 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
6729 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
6730 "fcw", "fsw", "mxcsr", /* 37 - 39 */
6731 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6732 "tr", "ldtr", /* 48 - 49 */
6733 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6734 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6735 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6736 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6737 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6738 NULL
, NULL
, NULL
, /* 90 - 92 */
6739 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
6742 static const char *const dwarf_regnames_iamcu
[] =
6744 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
6745 "esp", "ebp", "esi", "edi", /* 4 - 7 */
6746 "eip", "eflags", NULL
, /* 8 - 10 */
6747 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
6748 NULL
, NULL
, /* 19 - 20 */
6749 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
6750 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
6751 NULL
, NULL
, NULL
, /* 37 - 39 */
6752 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
6753 "tr", "ldtr", /* 48 - 49 */
6754 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
6755 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
6756 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
6757 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
6758 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
6759 NULL
, NULL
, NULL
, /* 90 - 92 */
6760 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
6764 init_dwarf_regnames_i386 (void)
6766 dwarf_regnames
= dwarf_regnames_i386
;
6767 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
6771 init_dwarf_regnames_iamcu (void)
6773 dwarf_regnames
= dwarf_regnames_iamcu
;
6774 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
6777 static const char *const dwarf_regnames_x86_64
[] =
6779 "rax", "rdx", "rcx", "rbx",
6780 "rsi", "rdi", "rbp", "rsp",
6781 "r8", "r9", "r10", "r11",
6782 "r12", "r13", "r14", "r15",
6784 "xmm0", "xmm1", "xmm2", "xmm3",
6785 "xmm4", "xmm5", "xmm6", "xmm7",
6786 "xmm8", "xmm9", "xmm10", "xmm11",
6787 "xmm12", "xmm13", "xmm14", "xmm15",
6788 "st0", "st1", "st2", "st3",
6789 "st4", "st5", "st6", "st7",
6790 "mm0", "mm1", "mm2", "mm3",
6791 "mm4", "mm5", "mm6", "mm7",
6793 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
6794 "fs.base", "gs.base", NULL
, NULL
,
6796 "mxcsr", "fcw", "fsw",
6797 "xmm16", "xmm17", "xmm18", "xmm19",
6798 "xmm20", "xmm21", "xmm22", "xmm23",
6799 "xmm24", "xmm25", "xmm26", "xmm27",
6800 "xmm28", "xmm29", "xmm30", "xmm31",
6801 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
6802 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
6803 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
6804 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
6805 NULL
, NULL
, NULL
, /* 115 - 117 */
6806 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
6810 init_dwarf_regnames_x86_64 (void)
6812 dwarf_regnames
= dwarf_regnames_x86_64
;
6813 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
6816 static const char *const dwarf_regnames_aarch64
[] =
6818 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
6819 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
6820 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
6821 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
6822 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6823 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6824 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6825 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6826 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
6827 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
6828 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
6829 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
6833 init_dwarf_regnames_aarch64 (void)
6835 dwarf_regnames
= dwarf_regnames_aarch64
;
6836 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
6839 static const char *const dwarf_regnames_s390
[] =
6841 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
6842 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6843 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
6844 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
6845 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
6846 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
6847 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
6848 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
6849 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
6852 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
6853 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
6857 init_dwarf_regnames_s390 (void)
6859 dwarf_regnames
= dwarf_regnames_s390
;
6860 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
6864 init_dwarf_regnames (unsigned int e_machine
)
6869 init_dwarf_regnames_i386 ();
6873 init_dwarf_regnames_iamcu ();
6879 init_dwarf_regnames_x86_64 ();
6883 init_dwarf_regnames_aarch64 ();
6887 init_dwarf_regnames_s390 ();
6896 regname (unsigned int regno
, int row
)
6898 static char reg
[64];
6901 && regno
< dwarf_regnames_count
6902 && dwarf_regnames
[regno
] != NULL
)
6905 return dwarf_regnames
[regno
];
6906 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
6907 dwarf_regnames
[regno
]);
6910 snprintf (reg
, sizeof (reg
), "r%d", regno
);
6915 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
6920 if (*max_regs
!= fc
->ncols
)
6921 *max_regs
= fc
->ncols
;
6923 if (*need_col_headers
)
6925 static const char *sloc
= " LOC";
6927 *need_col_headers
= 0;
6929 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
6931 for (r
= 0; r
< *max_regs
; r
++)
6932 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
6937 printf ("%-5s ", regname (r
, 1));
6943 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
6945 strcpy (tmp
, "exp");
6947 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
6948 printf ("%-8s ", tmp
);
6950 for (r
= 0; r
< fc
->ncols
; r
++)
6952 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
6954 switch (fc
->col_type
[r
])
6956 case DW_CFA_undefined
:
6959 case DW_CFA_same_value
:
6963 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
6965 case DW_CFA_val_offset
:
6966 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
6968 case DW_CFA_register
:
6969 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
6971 case DW_CFA_expression
:
6972 strcpy (tmp
, "exp");
6974 case DW_CFA_val_expression
:
6975 strcpy (tmp
, "vexp");
6978 strcpy (tmp
, "n/a");
6981 printf ("%-5s ", tmp
);
6987 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
6989 static unsigned char *
6990 read_cie (unsigned char *start
, unsigned char *end
,
6991 Frame_Chunk
**p_cie
, int *p_version
,
6992 bfd_size_type
*p_aug_len
, unsigned char **p_aug
)
6996 unsigned int length_return
;
6997 unsigned char *augmentation_data
= NULL
;
6998 bfd_size_type augmentation_data_len
= 0;
7001 /* PR 17512: file: 001-228113-0.004. */
7005 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7006 memset (fc
, 0, sizeof (Frame_Chunk
));
7008 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7009 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7013 fc
->augmentation
= (char *) start
;
7014 /* PR 17512: file: 001-228113-0.004.
7015 Skip past augmentation name, but avoid running off the end of the data. */
7017 if (* start
++ == '\0')
7021 warn (_("No terminator for augmentation name\n"));
7025 if (strcmp (fc
->augmentation
, "eh") == 0)
7026 start
+= eh_addr_size
;
7030 GET (fc
->ptr_size
, 1);
7031 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
7033 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
7037 GET (fc
->segment_size
, 1);
7038 /* PR 17512: file: e99d2804. */
7039 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
7041 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
7045 eh_addr_size
= fc
->ptr_size
;
7049 fc
->ptr_size
= eh_addr_size
;
7050 fc
->segment_size
= 0;
7052 READ_ULEB (fc
->code_factor
);
7053 READ_SLEB (fc
->data_factor
);
7063 if (fc
->augmentation
[0] == 'z')
7065 READ_ULEB (augmentation_data_len
);
7066 augmentation_data
= start
;
7067 /* PR 17512: file: 11042-2589-0.004. */
7068 if (augmentation_data_len
> (bfd_size_type
) (end
- start
))
7070 warn (_("Augmentation data too long: 0x%s, expected at most %#lx\n"),
7071 dwarf_vmatoa ("x", augmentation_data_len
),
7072 (unsigned long) (end
- start
));
7075 start
+= augmentation_data_len
;
7078 if (augmentation_data_len
)
7082 unsigned char *qend
;
7084 p
= (unsigned char *) fc
->augmentation
+ 1;
7085 q
= augmentation_data
;
7086 qend
= q
+ augmentation_data_len
;
7088 while (p
< end
&& q
< qend
)
7093 q
+= 1 + size_of_encoded_value (*q
);
7095 fc
->fde_encoding
= *q
++;
7102 /* Note - it is OK if this loop terminates with q < qend.
7103 Padding may have been inserted to align the end of the CIE. */
7108 *p_version
= version
;
7111 *p_aug_len
= augmentation_data_len
;
7112 *p_aug
= augmentation_data
;
7117 /* Prints out the contents on the augmentation data array.
7118 If do_wide is not enabled, then formats the output to fit into 80 columns. */
7121 display_augmentation_data (const unsigned char * data
, const bfd_size_type len
)
7125 i
= printf (_(" Augmentation data: "));
7127 if (do_wide
|| len
< ((80 - i
) / 3))
7128 for (i
= 0; i
< len
; ++i
)
7129 printf (" %02x", data
[i
]);
7132 for (i
= 0; i
< len
; ++i
)
7134 if (i
% (80 / 3) == 0)
7136 printf (" %02x", data
[i
]);
7143 display_debug_frames (struct dwarf_section
*section
,
7144 void *file ATTRIBUTE_UNUSED
)
7146 unsigned char *start
= section
->start
;
7147 unsigned char *end
= start
+ section
->size
;
7148 unsigned char *section_start
= start
;
7149 Frame_Chunk
*chunks
= 0, *forward_refs
= 0;
7150 Frame_Chunk
*remembered_state
= 0;
7152 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
7153 unsigned int length_return
;
7154 unsigned int max_regs
= 0;
7155 const char *bad_reg
= _("bad register: ");
7156 unsigned int saved_eh_addr_size
= eh_addr_size
;
7158 printf (_("Contents of the %s section:\n"), section
->name
);
7162 unsigned char *saved_start
;
7163 unsigned char *block_end
;
7168 int need_col_headers
= 1;
7169 unsigned char *augmentation_data
= NULL
;
7170 bfd_size_type augmentation_data_len
= 0;
7171 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
7172 unsigned int offset_size
;
7173 unsigned int initial_length_size
;
7174 bfd_boolean all_nops
;
7176 saved_start
= start
;
7178 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
7182 printf ("\n%08lx ZERO terminator\n\n",
7183 (unsigned long)(saved_start
- section_start
));
7184 /* Skip any zero terminators that directly follow.
7185 A corrupt section size could have loaded a whole
7186 slew of zero filled memory bytes. eg
7187 PR 17512: file: 070-19381-0.004. */
7188 while (start
< end
&& * start
== 0)
7193 if (length
== 0xffffffff)
7195 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
7197 initial_length_size
= 12;
7202 initial_length_size
= 4;
7205 block_end
= saved_start
+ length
+ initial_length_size
;
7206 if (block_end
> end
|| block_end
< start
)
7208 warn ("Invalid length 0x%s in FDE at %#08lx\n",
7209 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
7210 (unsigned long) (saved_start
- section_start
));
7214 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
7216 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
7217 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
7222 start
= read_cie (start
, end
, &cie
, &version
,
7223 &augmentation_data_len
, &augmentation_data
);
7224 /* PR 17512: file: 027-135133-0.005. */
7231 fc
->chunk_start
= saved_start
;
7232 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7235 if (frame_need_space (fc
, mreg
) < 0)
7237 if (fc
->fde_encoding
)
7238 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7240 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
7241 print_dwarf_vma (length
, fc
->ptr_size
);
7242 print_dwarf_vma (cie_id
, offset_size
);
7244 if (do_debug_frames_interp
)
7246 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
7247 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
7252 printf (" Version: %d\n", version
);
7253 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
7256 printf (" Pointer Size: %u\n", fc
->ptr_size
);
7257 printf (" Segment Size: %u\n", fc
->segment_size
);
7259 printf (" Code alignment factor: %u\n", fc
->code_factor
);
7260 printf (" Data alignment factor: %d\n", fc
->data_factor
);
7261 printf (" Return address column: %d\n", fc
->ra
);
7263 if (augmentation_data_len
)
7264 display_augmentation_data (augmentation_data
, augmentation_data_len
);
7271 unsigned char *look_for
;
7272 static Frame_Chunk fde_fc
;
7273 unsigned long segment_selector
;
7277 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
7278 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
7281 look_for
= section_start
+ cie_id
;
7283 if (look_for
<= saved_start
)
7285 for (cie
= chunks
; cie
; cie
= cie
->next
)
7286 if (cie
->chunk_start
== look_for
)
7291 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
7292 if (cie
->chunk_start
== look_for
)
7296 unsigned int off_size
;
7297 unsigned char *cie_scan
;
7299 cie_scan
= look_for
;
7301 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
7302 if (length
== 0xffffffff)
7304 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
7311 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
7314 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
7315 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
7320 read_cie (cie_scan
, end
, &cie
, &version
,
7321 &augmentation_data_len
, &augmentation_data
);
7322 /* PR 17512: file: 3450-2098-0.004. */
7325 warn (_("Failed to read CIE information\n"));
7328 cie
->next
= forward_refs
;
7330 cie
->chunk_start
= look_for
;
7331 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
7334 if (frame_need_space (cie
, mreg
) < 0)
7336 warn (_("Invalid max register\n"));
7339 if (cie
->fde_encoding
)
7341 = size_of_encoded_value (cie
->fde_encoding
);
7348 memset (fc
, 0, sizeof (Frame_Chunk
));
7352 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
7353 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
7354 (unsigned long) (saved_start
- section_start
));
7356 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
7357 fc
->col_offset
= (int *) xmalloc (sizeof (int));
7358 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
7360 warn (_("Invalid max register\n"));
7364 fc
->augmentation
= "";
7365 fc
->fde_encoding
= 0;
7366 fc
->ptr_size
= eh_addr_size
;
7367 fc
->segment_size
= 0;
7371 fc
->ncols
= cie
->ncols
;
7372 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
7373 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
7374 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
7375 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
7376 fc
->augmentation
= cie
->augmentation
;
7377 fc
->ptr_size
= cie
->ptr_size
;
7378 eh_addr_size
= cie
->ptr_size
;
7379 fc
->segment_size
= cie
->segment_size
;
7380 fc
->code_factor
= cie
->code_factor
;
7381 fc
->data_factor
= cie
->data_factor
;
7382 fc
->cfa_reg
= cie
->cfa_reg
;
7383 fc
->cfa_offset
= cie
->cfa_offset
;
7385 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
7387 warn (_("Invalid max register\n"));
7390 fc
->fde_encoding
= cie
->fde_encoding
;
7393 if (fc
->fde_encoding
)
7394 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
7396 segment_selector
= 0;
7397 if (fc
->segment_size
)
7399 if (fc
->segment_size
> sizeof (segment_selector
))
7401 /* PR 17512: file: 9e196b3e. */
7402 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
7403 fc
->segment_size
= 4;
7405 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
7408 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
7410 /* FIXME: It appears that sometimes the final pc_range value is
7411 encoded in less than encoded_ptr_size bytes. See the x86_64
7412 run of the "objcopy on compressed debug sections" test for an
7414 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
7416 if (cie
->augmentation
[0] == 'z')
7418 READ_ULEB (augmentation_data_len
);
7419 augmentation_data
= start
;
7420 start
+= augmentation_data_len
;
7421 /* PR 17512 file: 722-8446-0.004 and PR 22386. */
7423 || ((bfd_signed_vma
) augmentation_data_len
) < 0
7424 || augmentation_data
> start
)
7426 warn (_("Corrupt augmentation data length: 0x%s\n"),
7427 dwarf_vmatoa ("x", augmentation_data_len
));
7429 augmentation_data
= NULL
;
7430 augmentation_data_len
= 0;
7434 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
7435 (unsigned long)(saved_start
- section_start
),
7436 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
7437 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
7438 (unsigned long)(cie
->chunk_start
- section_start
));
7440 if (fc
->segment_size
)
7441 printf ("%04lx:", segment_selector
);
7444 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
7445 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
7447 if (! do_debug_frames_interp
&& augmentation_data_len
)
7449 display_augmentation_data (augmentation_data
, augmentation_data_len
);
7454 /* At this point, fc is the current chunk, cie (if any) is set, and
7455 we're about to interpret instructions for the chunk. */
7456 /* ??? At present we need to do this always, since this sizes the
7457 fc->col_type and fc->col_offset arrays, which we write into always.
7458 We should probably split the interpreted and non-interpreted bits
7459 into two different routines, since there's so much that doesn't
7460 really overlap between them. */
7461 if (1 || do_debug_frames_interp
)
7463 /* Start by making a pass over the chunk, allocating storage
7464 and taking note of what registers are used. */
7465 unsigned char *tmp
= start
;
7467 while (start
< block_end
)
7469 unsigned int reg
, op
, opa
;
7471 unsigned char * new_start
;
7478 /* Warning: if you add any more cases to this switch, be
7479 sure to add them to the corresponding switch below. */
7482 case DW_CFA_advance_loc
:
7486 if (frame_need_space (fc
, opa
) >= 0)
7487 fc
->col_type
[opa
] = DW_CFA_undefined
;
7489 case DW_CFA_restore
:
7490 if (frame_need_space (fc
, opa
) >= 0)
7491 fc
->col_type
[opa
] = DW_CFA_undefined
;
7493 case DW_CFA_set_loc
:
7494 start
+= encoded_ptr_size
;
7496 case DW_CFA_advance_loc1
:
7499 case DW_CFA_advance_loc2
:
7502 case DW_CFA_advance_loc4
:
7505 case DW_CFA_offset_extended
:
7506 case DW_CFA_val_offset
:
7509 if (frame_need_space (fc
, reg
) >= 0)
7510 fc
->col_type
[reg
] = DW_CFA_undefined
;
7512 case DW_CFA_restore_extended
:
7514 if (frame_need_space (fc
, reg
) >= 0)
7515 fc
->col_type
[reg
] = DW_CFA_undefined
;
7517 case DW_CFA_undefined
:
7519 if (frame_need_space (fc
, reg
) >= 0)
7520 fc
->col_type
[reg
] = DW_CFA_undefined
;
7522 case DW_CFA_same_value
:
7524 if (frame_need_space (fc
, reg
) >= 0)
7525 fc
->col_type
[reg
] = DW_CFA_undefined
;
7527 case DW_CFA_register
:
7530 if (frame_need_space (fc
, reg
) >= 0)
7531 fc
->col_type
[reg
] = DW_CFA_undefined
;
7533 case DW_CFA_def_cfa
:
7537 case DW_CFA_def_cfa_register
:
7540 case DW_CFA_def_cfa_offset
:
7543 case DW_CFA_def_cfa_expression
:
7545 new_start
= start
+ temp
;
7546 if (new_start
< start
)
7548 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
7554 case DW_CFA_expression
:
7555 case DW_CFA_val_expression
:
7558 new_start
= start
+ temp
;
7559 if (new_start
< start
)
7561 /* PR 17512: file:306-192417-0.005. */
7562 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
7567 if (frame_need_space (fc
, reg
) >= 0)
7568 fc
->col_type
[reg
] = DW_CFA_undefined
;
7570 case DW_CFA_offset_extended_sf
:
7571 case DW_CFA_val_offset_sf
:
7574 if (frame_need_space (fc
, reg
) >= 0)
7575 fc
->col_type
[reg
] = DW_CFA_undefined
;
7577 case DW_CFA_def_cfa_sf
:
7581 case DW_CFA_def_cfa_offset_sf
:
7584 case DW_CFA_MIPS_advance_loc8
:
7587 case DW_CFA_GNU_args_size
:
7590 case DW_CFA_GNU_negative_offset_extended
:
7593 if (frame_need_space (fc
, reg
) >= 0)
7594 fc
->col_type
[reg
] = DW_CFA_undefined
;
7605 /* Now we know what registers are used, make a second pass over
7606 the chunk, this time actually printing out the info. */
7608 while (start
< block_end
)
7610 unsigned char * tmp
;
7612 unsigned long ul
, roffs
;
7613 /* Note: It is tempting to use an unsigned long for 'reg' but there
7614 are various functions, notably frame_space_needed() that assume that
7615 reg is an unsigned int. */
7620 const char *reg_prefix
= "";
7627 /* Make a note if something other than DW_CFA_nop happens. */
7628 if (op
!= DW_CFA_nop
)
7631 /* Warning: if you add any more cases to this switch, be
7632 sure to add them to the corresponding switch above. */
7635 case DW_CFA_advance_loc
:
7636 if (do_debug_frames_interp
)
7637 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7639 printf (" DW_CFA_advance_loc: %d to %s\n",
7640 opa
* fc
->code_factor
,
7641 dwarf_vmatoa_1 (NULL
,
7642 fc
->pc_begin
+ opa
* fc
->code_factor
,
7644 fc
->pc_begin
+= opa
* fc
->code_factor
;
7649 if (opa
>= (unsigned int) fc
->ncols
)
7650 reg_prefix
= bad_reg
;
7651 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7652 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
7653 reg_prefix
, regname (opa
, 0),
7654 roffs
* fc
->data_factor
);
7655 if (*reg_prefix
== '\0')
7657 fc
->col_type
[opa
] = DW_CFA_offset
;
7658 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
7662 case DW_CFA_restore
:
7663 if (opa
>= (unsigned int) fc
->ncols
)
7664 reg_prefix
= bad_reg
;
7665 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7666 printf (" DW_CFA_restore: %s%s\n",
7667 reg_prefix
, regname (opa
, 0));
7668 if (*reg_prefix
!= '\0')
7671 if (opa
>= (unsigned int) cie
->ncols
7672 || (do_debug_frames_interp
7673 && cie
->col_type
[opa
] == DW_CFA_unreferenced
))
7675 fc
->col_type
[opa
] = DW_CFA_undefined
;
7676 fc
->col_offset
[opa
] = 0;
7680 fc
->col_type
[opa
] = cie
->col_type
[opa
];
7681 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
7685 case DW_CFA_set_loc
:
7686 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
7687 if (do_debug_frames_interp
)
7688 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7690 printf (" DW_CFA_set_loc: %s\n",
7691 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
7695 case DW_CFA_advance_loc1
:
7696 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
7697 if (do_debug_frames_interp
)
7698 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7700 printf (" DW_CFA_advance_loc1: %ld to %s\n",
7701 (unsigned long) (ofs
* fc
->code_factor
),
7702 dwarf_vmatoa_1 (NULL
,
7703 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7705 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7708 case DW_CFA_advance_loc2
:
7709 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
7710 if (do_debug_frames_interp
)
7711 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7713 printf (" DW_CFA_advance_loc2: %ld to %s\n",
7714 (unsigned long) (ofs
* fc
->code_factor
),
7715 dwarf_vmatoa_1 (NULL
,
7716 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7718 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7721 case DW_CFA_advance_loc4
:
7722 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
7723 if (do_debug_frames_interp
)
7724 frame_display_row (fc
, &need_col_headers
, &max_regs
);
7726 printf (" DW_CFA_advance_loc4: %ld to %s\n",
7727 (unsigned long) (ofs
* fc
->code_factor
),
7728 dwarf_vmatoa_1 (NULL
,
7729 fc
->pc_begin
+ ofs
* fc
->code_factor
,
7731 fc
->pc_begin
+= ofs
* fc
->code_factor
;
7734 case DW_CFA_offset_extended
:
7737 if (reg
>= (unsigned int) fc
->ncols
)
7738 reg_prefix
= bad_reg
;
7739 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7740 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
7741 reg_prefix
, regname (reg
, 0),
7742 roffs
* fc
->data_factor
);
7743 if (*reg_prefix
== '\0')
7745 fc
->col_type
[reg
] = DW_CFA_offset
;
7746 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
7750 case DW_CFA_val_offset
:
7753 if (reg
>= (unsigned int) fc
->ncols
)
7754 reg_prefix
= bad_reg
;
7755 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7756 printf (" DW_CFA_val_offset: %s%s is cfa%+ld\n",
7757 reg_prefix
, regname (reg
, 0),
7758 roffs
* fc
->data_factor
);
7759 if (*reg_prefix
== '\0')
7761 fc
->col_type
[reg
] = DW_CFA_val_offset
;
7762 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
7766 case DW_CFA_restore_extended
:
7768 if (reg
>= (unsigned int) fc
->ncols
)
7769 reg_prefix
= bad_reg
;
7770 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7771 printf (" DW_CFA_restore_extended: %s%s\n",
7772 reg_prefix
, regname (reg
, 0));
7773 if (*reg_prefix
!= '\0')
7776 if (reg
>= (unsigned int) cie
->ncols
)
7778 fc
->col_type
[reg
] = DW_CFA_undefined
;
7779 fc
->col_offset
[reg
] = 0;
7783 fc
->col_type
[reg
] = cie
->col_type
[reg
];
7784 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
7788 case DW_CFA_undefined
:
7790 if (reg
>= (unsigned int) fc
->ncols
)
7791 reg_prefix
= bad_reg
;
7792 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7793 printf (" DW_CFA_undefined: %s%s\n",
7794 reg_prefix
, regname (reg
, 0));
7795 if (*reg_prefix
== '\0')
7797 fc
->col_type
[reg
] = DW_CFA_undefined
;
7798 fc
->col_offset
[reg
] = 0;
7802 case DW_CFA_same_value
:
7804 if (reg
>= (unsigned int) fc
->ncols
)
7805 reg_prefix
= bad_reg
;
7806 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7807 printf (" DW_CFA_same_value: %s%s\n",
7808 reg_prefix
, regname (reg
, 0));
7809 if (*reg_prefix
== '\0')
7811 fc
->col_type
[reg
] = DW_CFA_same_value
;
7812 fc
->col_offset
[reg
] = 0;
7816 case DW_CFA_register
:
7819 if (reg
>= (unsigned int) fc
->ncols
)
7820 reg_prefix
= bad_reg
;
7821 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7823 printf (" DW_CFA_register: %s%s in ",
7824 reg_prefix
, regname (reg
, 0));
7825 puts (regname (roffs
, 0));
7827 if (*reg_prefix
== '\0')
7829 fc
->col_type
[reg
] = DW_CFA_register
;
7830 fc
->col_offset
[reg
] = roffs
;
7834 case DW_CFA_remember_state
:
7835 if (! do_debug_frames_interp
)
7836 printf (" DW_CFA_remember_state\n");
7837 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
7838 rs
->cfa_offset
= fc
->cfa_offset
;
7839 rs
->cfa_reg
= fc
->cfa_reg
;
7841 rs
->cfa_exp
= fc
->cfa_exp
;
7842 rs
->ncols
= fc
->ncols
;
7843 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
7844 sizeof (* rs
->col_type
));
7845 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
7846 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
7847 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
7848 rs
->next
= remembered_state
;
7849 remembered_state
= rs
;
7852 case DW_CFA_restore_state
:
7853 if (! do_debug_frames_interp
)
7854 printf (" DW_CFA_restore_state\n");
7855 rs
= remembered_state
;
7858 remembered_state
= rs
->next
;
7859 fc
->cfa_offset
= rs
->cfa_offset
;
7860 fc
->cfa_reg
= rs
->cfa_reg
;
7862 fc
->cfa_exp
= rs
->cfa_exp
;
7863 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
7865 warn (_("Invalid column number in saved frame state\n"));
7869 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
7870 memcpy (fc
->col_offset
, rs
->col_offset
,
7871 rs
->ncols
* sizeof (* rs
->col_offset
));
7872 free (rs
->col_type
);
7873 free (rs
->col_offset
);
7876 else if (do_debug_frames_interp
)
7877 printf ("Mismatched DW_CFA_restore_state\n");
7880 case DW_CFA_def_cfa
:
7881 READ_ULEB (fc
->cfa_reg
);
7882 READ_ULEB (fc
->cfa_offset
);
7884 if (! do_debug_frames_interp
)
7885 printf (" DW_CFA_def_cfa: %s ofs %d\n",
7886 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
7889 case DW_CFA_def_cfa_register
:
7890 READ_ULEB (fc
->cfa_reg
);
7892 if (! do_debug_frames_interp
)
7893 printf (" DW_CFA_def_cfa_register: %s\n",
7894 regname (fc
->cfa_reg
, 0));
7897 case DW_CFA_def_cfa_offset
:
7898 READ_ULEB (fc
->cfa_offset
);
7899 if (! do_debug_frames_interp
)
7900 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
7904 if (! do_debug_frames_interp
)
7905 printf (" DW_CFA_nop\n");
7908 case DW_CFA_def_cfa_expression
:
7910 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
7912 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
7915 if (! do_debug_frames_interp
)
7917 printf (" DW_CFA_def_cfa_expression (");
7918 decode_location_expression (start
, eh_addr_size
, 0, -1,
7926 case DW_CFA_expression
:
7929 if (reg
>= (unsigned int) fc
->ncols
)
7930 reg_prefix
= bad_reg
;
7931 /* PR 17512: file: 069-133014-0.006. */
7932 /* PR 17512: file: 98c02eb4. */
7934 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
7936 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
7939 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7941 printf (" DW_CFA_expression: %s%s (",
7942 reg_prefix
, regname (reg
, 0));
7943 decode_location_expression (start
, eh_addr_size
, 0, -1,
7947 if (*reg_prefix
== '\0')
7948 fc
->col_type
[reg
] = DW_CFA_expression
;
7952 case DW_CFA_val_expression
:
7955 if (reg
>= (unsigned int) fc
->ncols
)
7956 reg_prefix
= bad_reg
;
7958 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
7960 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
7963 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7965 printf (" DW_CFA_val_expression: %s%s (",
7966 reg_prefix
, regname (reg
, 0));
7967 decode_location_expression (start
, eh_addr_size
, 0, -1,
7971 if (*reg_prefix
== '\0')
7972 fc
->col_type
[reg
] = DW_CFA_val_expression
;
7976 case DW_CFA_offset_extended_sf
:
7979 if (frame_need_space (fc
, reg
) < 0)
7980 reg_prefix
= bad_reg
;
7981 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7982 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
7983 reg_prefix
, regname (reg
, 0),
7984 (long)(l
* fc
->data_factor
));
7985 if (*reg_prefix
== '\0')
7987 fc
->col_type
[reg
] = DW_CFA_offset
;
7988 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
7992 case DW_CFA_val_offset_sf
:
7995 if (frame_need_space (fc
, reg
) < 0)
7996 reg_prefix
= bad_reg
;
7997 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
7998 printf (" DW_CFA_val_offset_sf: %s%s is cfa%+ld\n",
7999 reg_prefix
, regname (reg
, 0),
8000 (long)(l
* fc
->data_factor
));
8001 if (*reg_prefix
== '\0')
8003 fc
->col_type
[reg
] = DW_CFA_val_offset
;
8004 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8008 case DW_CFA_def_cfa_sf
:
8009 READ_ULEB (fc
->cfa_reg
);
8010 READ_ULEB (fc
->cfa_offset
);
8011 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
8013 if (! do_debug_frames_interp
)
8014 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
8015 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
8018 case DW_CFA_def_cfa_offset_sf
:
8019 READ_ULEB (fc
->cfa_offset
);
8020 fc
->cfa_offset
*= fc
->data_factor
;
8021 if (! do_debug_frames_interp
)
8022 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
8025 case DW_CFA_MIPS_advance_loc8
:
8026 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
8027 if (do_debug_frames_interp
)
8028 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8030 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
8031 (unsigned long) (ofs
* fc
->code_factor
),
8032 dwarf_vmatoa_1 (NULL
,
8033 fc
->pc_begin
+ ofs
* fc
->code_factor
,
8035 fc
->pc_begin
+= ofs
* fc
->code_factor
;
8038 case DW_CFA_GNU_window_save
:
8039 if (! do_debug_frames_interp
)
8040 printf (" DW_CFA_GNU_window_save\n");
8043 case DW_CFA_GNU_args_size
:
8045 if (! do_debug_frames_interp
)
8046 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
8049 case DW_CFA_GNU_negative_offset_extended
:
8053 if (frame_need_space (fc
, reg
) < 0)
8054 reg_prefix
= bad_reg
;
8055 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
8056 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
8057 reg_prefix
, regname (reg
, 0),
8058 (long)(l
* fc
->data_factor
));
8059 if (*reg_prefix
== '\0')
8061 fc
->col_type
[reg
] = DW_CFA_offset
;
8062 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
8067 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
8068 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
8070 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
8075 /* Interpret the CFA - as long as it is not completely full of NOPs. */
8076 if (do_debug_frames_interp
&& ! all_nops
)
8077 frame_display_row (fc
, &need_col_headers
, &max_regs
);
8080 eh_addr_size
= saved_eh_addr_size
;
8091 display_debug_names (struct dwarf_section
*section
, void *file
)
8093 unsigned char *hdrptr
= section
->start
;
8094 dwarf_vma unit_length
;
8095 unsigned char *unit_start
;
8096 const unsigned char *const section_end
= section
->start
+ section
->size
;
8097 unsigned char *unit_end
;
8099 printf (_("Contents of the %s section:\n"), section
->name
);
8101 load_debug_section (str
, file
);
8103 for (; hdrptr
< section_end
; hdrptr
= unit_end
)
8105 unsigned int offset_size
;
8106 uint16_t dwarf_version
, padding
;
8107 uint32_t comp_unit_count
, local_type_unit_count
, foreign_type_unit_count
;
8108 uint32_t bucket_count
, name_count
, abbrev_table_size
;
8109 uint32_t augmentation_string_size
;
8111 unsigned long sec_off
;
8113 unit_start
= hdrptr
;
8115 /* Get and check the length of the block. */
8116 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 4, section_end
);
8118 if (unit_length
== 0xffffffff)
8120 /* This section is 64-bit DWARF. */
8121 SAFE_BYTE_GET_AND_INC (unit_length
, hdrptr
, 8, section_end
);
8126 unit_end
= hdrptr
+ unit_length
;
8128 sec_off
= hdrptr
- section
->start
;
8129 if (sec_off
+ unit_length
< sec_off
8130 || sec_off
+ unit_length
> section
->size
)
8132 warn (_("Debug info is corrupted, %s header at %#lx has length %s\n"),
8134 (unsigned long) (unit_start
- section
->start
),
8135 dwarf_vmatoa ("x", unit_length
));
8139 /* Get and check the version number. */
8140 SAFE_BYTE_GET_AND_INC (dwarf_version
, hdrptr
, 2, unit_end
);
8141 printf (_("Version %ld\n"), (long) dwarf_version
);
8143 /* Prior versions did not exist, and future versions may not be
8144 backwards compatible. */
8145 if (dwarf_version
!= 5)
8147 warn (_("Only DWARF version 5 .debug_names "
8148 "is currently supported.\n"));
8152 SAFE_BYTE_GET_AND_INC (padding
, hdrptr
, 2, unit_end
);
8154 warn (_("Padding field of .debug_names must be 0 (found 0x%x)\n"),
8157 SAFE_BYTE_GET_AND_INC (comp_unit_count
, hdrptr
, 4, unit_end
);
8158 if (comp_unit_count
== 0)
8159 warn (_("Compilation unit count must be >= 1 in .debug_names\n"));
8161 SAFE_BYTE_GET_AND_INC (local_type_unit_count
, hdrptr
, 4, unit_end
);
8162 SAFE_BYTE_GET_AND_INC (foreign_type_unit_count
, hdrptr
, 4, unit_end
);
8163 SAFE_BYTE_GET_AND_INC (bucket_count
, hdrptr
, 4, unit_end
);
8164 SAFE_BYTE_GET_AND_INC (name_count
, hdrptr
, 4, unit_end
);
8165 SAFE_BYTE_GET_AND_INC (abbrev_table_size
, hdrptr
, 4, unit_end
);
8167 SAFE_BYTE_GET_AND_INC (augmentation_string_size
, hdrptr
, 4, unit_end
);
8168 if (augmentation_string_size
% 4 != 0)
8170 warn (_("Augmentation string length %u must be rounded up "
8171 "to a multiple of 4 in .debug_names.\n"),
8172 augmentation_string_size
);
8173 augmentation_string_size
+= (-augmentation_string_size
) & 3;
8175 printf (_("Augmentation string:"));
8176 for (i
= 0; i
< augmentation_string_size
; i
++)
8180 SAFE_BYTE_GET_AND_INC (uc
, hdrptr
, 1, unit_end
);
8181 printf (" %02x", uc
);
8186 printf (_("CU table:\n"));
8187 for (i
= 0; i
< comp_unit_count
; i
++)
8191 SAFE_BYTE_GET_AND_INC (cu_offset
, hdrptr
, offset_size
, unit_end
);
8192 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) cu_offset
);
8196 printf (_("TU table:\n"));
8197 for (i
= 0; i
< local_type_unit_count
; i
++)
8201 SAFE_BYTE_GET_AND_INC (tu_offset
, hdrptr
, offset_size
, unit_end
);
8202 printf (_("[%3u] 0x%lx\n"), i
, (unsigned long) tu_offset
);
8206 printf (_("Foreign TU table:\n"));
8207 for (i
= 0; i
< foreign_type_unit_count
; i
++)
8211 SAFE_BYTE_GET_AND_INC (signature
, hdrptr
, 8, unit_end
);
8212 printf (_("[%3u] "), i
);
8213 print_dwarf_vma (signature
, 8);
8218 const uint32_t *const hash_table_buckets
= (uint32_t *) hdrptr
;
8219 hdrptr
+= bucket_count
* sizeof (uint32_t);
8220 const uint32_t *const hash_table_hashes
= (uint32_t *) hdrptr
;
8221 hdrptr
+= name_count
* sizeof (uint32_t);
8222 unsigned char *const name_table_string_offsets
= hdrptr
;
8223 hdrptr
+= name_count
* offset_size
;
8224 unsigned char *const name_table_entry_offsets
= hdrptr
;
8225 hdrptr
+= name_count
* offset_size
;
8226 unsigned char *const abbrev_table
= hdrptr
;
8227 hdrptr
+= abbrev_table_size
;
8228 const unsigned char *const abbrev_table_end
= hdrptr
;
8229 unsigned char *const entry_pool
= hdrptr
;
8230 if (hdrptr
> unit_end
)
8232 warn (_("Entry pool offset (0x%lx) exceeds unit size 0x%lx "
8233 "for unit 0x%lx in the debug_names\n"),
8234 (long) (hdrptr
- section
->start
),
8235 (long) (unit_end
- section
->start
),
8236 (long) (unit_start
- section
->start
));
8240 size_t buckets_filled
= 0;
8242 for (bucketi
= 0; bucketi
< bucket_count
; bucketi
++)
8244 const uint32_t bucket
= hash_table_buckets
[bucketi
];
8249 printf (_("Used %zu of %lu buckets.\n"), buckets_filled
,
8250 (unsigned long) bucket_count
);
8252 uint32_t hash_prev
= 0;
8253 size_t hash_clash_count
= 0;
8254 size_t longest_clash
= 0;
8255 size_t this_length
= 0;
8257 for (hashi
= 0; hashi
< name_count
; hashi
++)
8259 const uint32_t hash_this
= hash_table_hashes
[hashi
];
8263 if (hash_prev
% bucket_count
== hash_this
% bucket_count
)
8267 longest_clash
= MAX (longest_clash
, this_length
);
8272 hash_prev
= hash_this
;
8274 printf (_("Out of %lu items there are %zu bucket clashes"
8275 " (longest of %zu entries).\n"),
8276 (unsigned long) name_count
, hash_clash_count
, longest_clash
);
8277 assert (name_count
== buckets_filled
+ hash_clash_count
);
8279 struct abbrev_lookup_entry
8281 dwarf_vma abbrev_tag
;
8282 unsigned char *abbrev_lookup_ptr
;
8284 struct abbrev_lookup_entry
*abbrev_lookup
= NULL
;
8285 size_t abbrev_lookup_used
= 0;
8286 size_t abbrev_lookup_allocated
= 0;
8288 unsigned char *abbrevptr
= abbrev_table
;
8291 unsigned int bytes_read
;
8292 const dwarf_vma abbrev_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
8294 abbrevptr
+= bytes_read
;
8295 if (abbrev_tag
== 0)
8297 if (abbrev_lookup_used
== abbrev_lookup_allocated
)
8299 abbrev_lookup_allocated
= MAX (0x100,
8300 abbrev_lookup_allocated
* 2);
8301 abbrev_lookup
= xrealloc (abbrev_lookup
,
8302 (abbrev_lookup_allocated
8303 * sizeof (*abbrev_lookup
)));
8305 assert (abbrev_lookup_used
< abbrev_lookup_allocated
);
8306 struct abbrev_lookup_entry
*entry
;
8307 for (entry
= abbrev_lookup
;
8308 entry
< abbrev_lookup
+ abbrev_lookup_used
;
8310 if (entry
->abbrev_tag
== abbrev_tag
)
8312 warn (_("Duplicate abbreviation tag %lu "
8313 "in unit 0x%lx in the debug_names\n"),
8314 (long) abbrev_tag
, (long) (unit_start
- section
->start
));
8317 entry
= &abbrev_lookup
[abbrev_lookup_used
++];
8318 entry
->abbrev_tag
= abbrev_tag
;
8319 entry
->abbrev_lookup_ptr
= abbrevptr
;
8321 /* Skip DWARF tag. */
8322 read_uleb128 (abbrevptr
, &bytes_read
, abbrev_table_end
);
8323 abbrevptr
+= bytes_read
;
8326 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
8329 abbrevptr
+= bytes_read
;
8330 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
8332 abbrevptr
+= bytes_read
;
8333 if (xindex
== 0 && form
== 0)
8338 printf (_("\nSymbol table:\n"));
8340 for (namei
= 0; namei
< name_count
; ++namei
)
8342 uint64_t string_offset
, entry_offset
;
8344 SAFE_BYTE_GET (string_offset
,
8345 name_table_string_offsets
+ namei
* offset_size
,
8346 offset_size
, unit_end
);
8347 SAFE_BYTE_GET (entry_offset
,
8348 name_table_entry_offsets
+ namei
* offset_size
,
8349 offset_size
, unit_end
);
8351 printf ("[%3u] #%08x %s:", namei
, hash_table_hashes
[namei
],
8352 fetch_indirect_string (string_offset
));
8354 unsigned char *entryptr
= entry_pool
+ entry_offset
;
8356 // We need to scan first whether there is a single or multiple
8357 // entries. TAGNO is -2 for the first entry, it is -1 for the
8358 // initial tag read of the second entry, then it becomes 0 for the
8359 // first entry for real printing etc.
8361 /* Initialize it due to a false compiler warning. */
8362 dwarf_vma second_abbrev_tag
= -1;
8365 unsigned int bytes_read
;
8366 const dwarf_vma abbrev_tag
= read_uleb128 (entryptr
, &bytes_read
,
8368 entryptr
+= bytes_read
;
8371 second_abbrev_tag
= abbrev_tag
;
8373 entryptr
= entry_pool
+ entry_offset
;
8376 if (abbrev_tag
== 0)
8380 (tagno
== 0 && second_abbrev_tag
== 0 ? " " : "\n\t"),
8381 (unsigned long) abbrev_tag
);
8383 const struct abbrev_lookup_entry
*entry
;
8384 for (entry
= abbrev_lookup
;
8385 entry
< abbrev_lookup
+ abbrev_lookup_used
;
8387 if (entry
->abbrev_tag
== abbrev_tag
)
8389 if (entry
>= abbrev_lookup
+ abbrev_lookup_used
)
8391 warn (_("Undefined abbreviation tag %lu "
8392 "in unit 0x%lx in the debug_names\n"),
8394 (long) (unit_start
- section
->start
));
8397 abbrevptr
= entry
->abbrev_lookup_ptr
;
8398 const dwarf_vma dwarf_tag
= read_uleb128 (abbrevptr
, &bytes_read
,
8400 abbrevptr
+= bytes_read
;
8402 printf (" %s", get_TAG_name (dwarf_tag
));
8405 const dwarf_vma xindex
= read_uleb128 (abbrevptr
,
8408 abbrevptr
+= bytes_read
;
8409 const dwarf_vma form
= read_uleb128 (abbrevptr
, &bytes_read
,
8411 abbrevptr
+= bytes_read
;
8412 if (xindex
== 0 && form
== 0)
8416 printf (" %s", get_IDX_name (xindex
));
8417 entryptr
= read_and_display_attr_value (0, form
, 0, entryptr
,
8420 dwarf_version
, NULL
,
8427 printf (_(" <no entries>"));
8431 free (abbrev_lookup
);
8438 display_gdb_index (struct dwarf_section
*section
,
8439 void *file ATTRIBUTE_UNUSED
)
8441 unsigned char *start
= section
->start
;
8443 uint32_t cu_list_offset
, tu_list_offset
;
8444 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
8445 unsigned int cu_list_elements
, tu_list_elements
;
8446 unsigned int address_table_size
, symbol_table_slots
;
8447 unsigned char *cu_list
, *tu_list
;
8448 unsigned char *address_table
, *symbol_table
, *constant_pool
;
8451 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
8453 printf (_("Contents of the %s section:\n"), section
->name
);
8455 if (section
->size
< 6 * sizeof (uint32_t))
8457 warn (_("Truncated header in the %s section.\n"), section
->name
);
8461 version
= byte_get_little_endian (start
, 4);
8462 printf (_("Version %ld\n"), (long) version
);
8464 /* Prior versions are obsolete, and future versions may not be
8465 backwards compatible. */
8466 if (version
< 3 || version
> 8)
8468 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
8472 warn (_("The address table data in version 3 may be wrong.\n"));
8474 warn (_("Version 4 does not support case insensitive lookups.\n"));
8476 warn (_("Version 5 does not include inlined functions.\n"));
8478 warn (_("Version 6 does not include symbol attributes.\n"));
8479 /* Version 7 indices generated by Gold have bad type unit references,
8480 PR binutils/15021. But we don't know if the index was generated by
8481 Gold or not, so to avoid worrying users with gdb-generated indices
8482 we say nothing for version 7 here. */
8484 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
8485 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
8486 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
8487 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
8488 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
8490 if (cu_list_offset
> section
->size
8491 || tu_list_offset
> section
->size
8492 || address_table_offset
> section
->size
8493 || symbol_table_offset
> section
->size
8494 || constant_pool_offset
> section
->size
)
8496 warn (_("Corrupt header in the %s section.\n"), section
->name
);
8500 /* PR 17531: file: 418d0a8a. */
8501 if (tu_list_offset
< cu_list_offset
)
8503 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
8504 tu_list_offset
, cu_list_offset
);
8508 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
8510 if (address_table_offset
< tu_list_offset
)
8512 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
8513 address_table_offset
, tu_list_offset
);
8517 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
8519 /* PR 17531: file: 18a47d3d. */
8520 if (symbol_table_offset
< address_table_offset
)
8522 warn (_("Symbol table offset (%x) is less then Address table offset (%x)\n"),
8523 symbol_table_offset
, address_table_offset
);
8527 address_table_size
= symbol_table_offset
- address_table_offset
;
8529 if (constant_pool_offset
< symbol_table_offset
)
8531 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
8532 constant_pool_offset
, symbol_table_offset
);
8536 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
8538 cu_list
= start
+ cu_list_offset
;
8539 tu_list
= start
+ tu_list_offset
;
8540 address_table
= start
+ address_table_offset
;
8541 symbol_table
= start
+ symbol_table_offset
;
8542 constant_pool
= start
+ constant_pool_offset
;
8544 if (address_table
+ address_table_size
> section
->start
+ section
->size
)
8546 warn (_("Address table extends beyond end of section.\n"));
8550 printf (_("\nCU table:\n"));
8551 for (i
= 0; i
< cu_list_elements
; i
+= 2)
8553 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
8554 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
8556 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
8557 (unsigned long) cu_offset
,
8558 (unsigned long) (cu_offset
+ cu_length
- 1));
8561 printf (_("\nTU table:\n"));
8562 for (i
= 0; i
< tu_list_elements
; i
+= 3)
8564 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
8565 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
8566 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
8568 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
8569 (unsigned long) tu_offset
,
8570 (unsigned long) type_offset
);
8571 print_dwarf_vma (signature
, 8);
8575 printf (_("\nAddress table:\n"));
8576 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
8579 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
8580 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
8581 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
8583 print_dwarf_vma (low
, 8);
8584 print_dwarf_vma (high
, 8);
8585 printf (_("%lu\n"), (unsigned long) cu_index
);
8588 printf (_("\nSymbol table:\n"));
8589 for (i
= 0; i
< symbol_table_slots
; ++i
)
8591 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
8592 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
8593 uint32_t num_cus
, cu
;
8595 if (name_offset
!= 0
8596 || cu_vector_offset
!= 0)
8599 unsigned char * adr
;
8601 adr
= constant_pool
+ name_offset
;
8602 /* PR 17531: file: 5b7b07ad. */
8603 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
8605 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
8606 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
8610 printf ("[%3u] %.*s:", i
,
8611 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
8612 constant_pool
+ name_offset
);
8614 adr
= constant_pool
+ cu_vector_offset
;
8615 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
8617 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
8618 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
8619 cu_vector_offset
, i
);
8623 num_cus
= byte_get_little_endian (adr
, 4);
8625 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
8626 if (num_cus
* 4 < num_cus
8627 || adr
>= section
->start
+ section
->size
8628 || adr
< constant_pool
)
8630 printf ("<invalid number of CUs: %d>\n", num_cus
);
8631 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
8639 for (j
= 0; j
< num_cus
; ++j
)
8642 gdb_index_symbol_kind kind
;
8644 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
8645 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
8646 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
8647 cu
= GDB_INDEX_CU_VALUE (cu
);
8648 /* Convert to TU number if it's for a type unit. */
8649 if (cu
>= cu_list_elements
/ 2)
8650 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
8651 (unsigned long) (cu
- cu_list_elements
/ 2));
8653 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
8655 printf (" [%s, %s]",
8656 is_static
? _("static") : _("global"),
8657 get_gdb_index_symbol_kind_name (kind
));
8669 /* Pre-allocate enough space for the CU/TU sets needed. */
8672 prealloc_cu_tu_list (unsigned int nshndx
)
8674 if (shndx_pool
== NULL
)
8676 shndx_pool_size
= nshndx
;
8677 shndx_pool_used
= 0;
8678 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
8679 sizeof (unsigned int));
8683 shndx_pool_size
= shndx_pool_used
+ nshndx
;
8684 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
8685 sizeof (unsigned int));
8690 add_shndx_to_cu_tu_entry (unsigned int shndx
)
8692 if (shndx_pool_used
>= shndx_pool_size
)
8694 error (_("Internal error: out of space in the shndx pool.\n"));
8697 shndx_pool
[shndx_pool_used
++] = shndx
;
8701 end_cu_tu_entry (void)
8703 if (shndx_pool_used
>= shndx_pool_size
)
8705 error (_("Internal error: out of space in the shndx pool.\n"));
8708 shndx_pool
[shndx_pool_used
++] = 0;
8711 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
8714 get_DW_SECT_short_name (unsigned int dw_sect
)
8716 static char buf
[16];
8724 case DW_SECT_ABBREV
:
8730 case DW_SECT_STR_OFFSETS
:
8732 case DW_SECT_MACINFO
:
8740 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
8744 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
8745 These sections are extensions for Fission.
8746 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
8749 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
8751 unsigned char *phdr
= section
->start
;
8752 unsigned char *limit
= phdr
+ section
->size
;
8753 unsigned char *phash
;
8754 unsigned char *pindex
;
8755 unsigned char *ppool
;
8756 unsigned int version
;
8757 unsigned int ncols
= 0;
8759 unsigned int nslots
;
8762 dwarf_vma signature_high
;
8763 dwarf_vma signature_low
;
8766 /* PR 17512: file: 002-168123-0.004. */
8769 warn (_("Section %s is empty\n"), section
->name
);
8772 /* PR 17512: file: 002-376-0.004. */
8773 if (section
->size
< 24)
8775 warn (_("Section %s is too small to contain a CU/TU header\n"),
8780 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
8782 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
8783 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
8784 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
8787 pindex
= phash
+ nslots
* 8;
8788 ppool
= pindex
+ nslots
* 4;
8790 /* PR 17531: file: 45d69832. */
8791 if (pindex
< phash
|| ppool
< phdr
|| (pindex
== phash
&& nslots
!= 0))
8793 warn (_("Section %s is too small for %d slots\n"),
8794 section
->name
, nslots
);
8800 printf (_("Contents of the %s section:\n\n"), section
->name
);
8801 printf (_(" Version: %d\n"), version
);
8803 printf (_(" Number of columns: %d\n"), ncols
);
8804 printf (_(" Number of used entries: %d\n"), nused
);
8805 printf (_(" Number of slots: %d\n\n"), nslots
);
8808 if (ppool
> limit
|| ppool
< phdr
)
8810 warn (_("Section %s too small for %d hash table entries\n"),
8811 section
->name
, nslots
);
8818 prealloc_cu_tu_list ((limit
- ppool
) / 4);
8819 for (i
= 0; i
< nslots
; i
++)
8821 unsigned char *shndx_list
;
8824 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
8825 if (signature_high
!= 0 || signature_low
!= 0)
8827 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
8828 shndx_list
= ppool
+ j
* 4;
8829 /* PR 17531: file: 705e010d. */
8830 if (shndx_list
< ppool
)
8832 warn (_("Section index pool located before start of section\n"));
8837 printf (_(" [%3d] Signature: 0x%s Sections: "),
8838 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
8839 buf
, sizeof (buf
)));
8842 if (shndx_list
>= limit
)
8844 warn (_("Section %s too small for shndx pool\n"),
8848 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
8852 printf (" %d", shndx
);
8854 add_shndx_to_cu_tu_entry (shndx
);
8866 else if (version
== 2)
8869 unsigned int dw_sect
;
8870 unsigned char *ph
= phash
;
8871 unsigned char *pi
= pindex
;
8872 unsigned char *poffsets
= ppool
+ ncols
* 4;
8873 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
8874 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
8875 bfd_boolean is_tu_index
;
8876 struct cu_tu_set
*this_set
= NULL
;
8878 unsigned char *prow
;
8880 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
8882 /* PR 17531: file: 0dd159bf.
8883 Check for wraparound with an overlarge ncols value. */
8884 if (poffsets
< ppool
|| (unsigned int) ((poffsets
- ppool
) / 4) != ncols
)
8886 warn (_("Overlarge number of columns: %x\n"), ncols
);
8892 warn (_("Section %s too small for offset and size tables\n"),
8899 printf (_(" Offset table\n"));
8900 printf (" slot %-16s ",
8901 is_tu_index
? _("signature") : _("dwo_id"));
8908 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
8914 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
8921 for (j
= 0; j
< ncols
; j
++)
8923 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
8924 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
8929 for (i
= 0; i
< nslots
; i
++)
8931 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
8933 SAFE_BYTE_GET (row
, pi
, 4, limit
);
8936 /* PR 17531: file: a05f6ab3. */
8939 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
8945 memcpy (&this_set
[row
- 1].signature
, ph
, sizeof (uint64_t));
8947 prow
= poffsets
+ (row
- 1) * ncols
* 4;
8948 /* PR 17531: file: b8ce60a8. */
8949 if (prow
< poffsets
|| prow
> limit
)
8951 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
8957 printf (_(" [%3d] 0x%s"),
8958 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
8959 buf
, sizeof (buf
)));
8960 for (j
= 0; j
< ncols
; j
++)
8962 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
8964 printf (" %8d", val
);
8967 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
8969 /* PR 17531: file: 10796eb3. */
8970 if (dw_sect
>= DW_SECT_MAX
)
8971 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
8973 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
8989 printf (_(" Size table\n"));
8990 printf (" slot %-16s ",
8991 is_tu_index
? _("signature") : _("dwo_id"));
8994 for (j
= 0; j
< ncols
; j
++)
8996 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
8998 printf (" %8s", get_DW_SECT_short_name (val
));
9004 for (i
= 0; i
< nslots
; i
++)
9006 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
9008 SAFE_BYTE_GET (row
, pi
, 4, limit
);
9011 prow
= psizes
+ (row
- 1) * ncols
* 4;
9014 printf (_(" [%3d] 0x%s"),
9015 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
9016 buf
, sizeof (buf
)));
9018 for (j
= 0; j
< ncols
; j
++)
9020 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
9022 printf (" %8d", val
);
9025 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
9026 if (dw_sect
>= DW_SECT_MAX
)
9027 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
9029 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
9041 else if (do_display
)
9042 printf (_(" Unsupported version (%d)\n"), version
);
9050 /* Load the CU and TU indexes if present. This will build a list of
9051 section sets that we can use to associate a .debug_info.dwo section
9052 with its associated .debug_abbrev.dwo section in a .dwp file. */
9055 load_cu_tu_indexes (void *file
)
9057 static int cu_tu_indexes_read
= -1; /* Tri-state variable. */
9059 /* If we have already loaded (or tried to load) the CU and TU indexes
9060 then do not bother to repeat the task. */
9061 if (cu_tu_indexes_read
== -1)
9063 cu_tu_indexes_read
= TRUE
;
9065 if (load_debug_section (dwp_cu_index
, file
))
9066 if (! process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0))
9067 cu_tu_indexes_read
= FALSE
;
9069 if (load_debug_section (dwp_tu_index
, file
))
9070 if (! process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0))
9071 cu_tu_indexes_read
= FALSE
;
9074 return (bfd_boolean
) cu_tu_indexes_read
;
9077 /* Find the set of sections that includes section SHNDX. */
9080 find_cu_tu_set (void *file
, unsigned int shndx
)
9084 if (! load_cu_tu_indexes (file
))
9087 /* Find SHNDX in the shndx pool. */
9088 for (i
= 0; i
< shndx_pool_used
; i
++)
9089 if (shndx_pool
[i
] == shndx
)
9092 if (i
>= shndx_pool_used
)
9095 /* Now backup to find the first entry in the set. */
9096 while (i
> 0 && shndx_pool
[i
- 1] != 0)
9099 return shndx_pool
+ i
;
9102 /* Display a .debug_cu_index or .debug_tu_index section. */
9105 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
9107 return process_cu_tu_index (section
, 1);
9111 display_debug_not_supported (struct dwarf_section
*section
,
9112 void *file ATTRIBUTE_UNUSED
)
9114 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
9120 /* Like malloc, but takes two parameters like calloc.
9121 Verifies that the first parameter is not too large.
9122 Note: does *not* initialise the allocated memory to zero. */
9124 cmalloc (size_t nmemb
, size_t size
)
9126 /* Check for overflow. */
9127 if (nmemb
>= ~(size_t) 0 / size
)
9130 return xmalloc (nmemb
* size
);
9133 /* Like xmalloc, but takes two parameters like calloc.
9134 Verifies that the first parameter is not too large.
9135 Note: does *not* initialise the allocated memory to zero. */
9137 xcmalloc (size_t nmemb
, size_t size
)
9139 /* Check for overflow. */
9140 if (nmemb
>= ~(size_t) 0 / size
)
9143 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
9148 return xmalloc (nmemb
* size
);
9151 /* Like xrealloc, but takes three parameters.
9152 Verifies that the second parameter is not too large.
9153 Note: does *not* initialise any new memory to zero. */
9155 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
9157 /* Check for overflow. */
9158 if (nmemb
>= ~(size_t) 0 / size
)
9161 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
9166 return xrealloc (ptr
, nmemb
* size
);
9169 /* Like xcalloc, but verifies that the first parameter is not too large. */
9171 xcalloc2 (size_t nmemb
, size_t size
)
9173 /* Check for overflow. */
9174 if (nmemb
>= ~(size_t) 0 / size
)
9177 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
9182 return xcalloc (nmemb
, size
);
9186 free_debug_memory (void)
9192 for (i
= 0; i
< max
; i
++)
9193 free_debug_section ((enum dwarf_section_display_enum
) i
);
9195 if (debug_information
!= NULL
)
9197 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
9199 for (i
= 0; i
< num_debug_info_entries
; i
++)
9201 if (!debug_information
[i
].max_loc_offsets
)
9203 free (debug_information
[i
].loc_offsets
);
9204 free (debug_information
[i
].have_frame_base
);
9206 if (!debug_information
[i
].max_range_lists
)
9207 free (debug_information
[i
].range_lists
);
9210 free (debug_information
);
9211 debug_information
= NULL
;
9212 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
9217 dwarf_select_sections_by_names (const char *names
)
9221 const char * option
;
9225 debug_dump_long_opts
;
9227 static const debug_dump_long_opts opts_table
[] =
9229 /* Please keep this table alpha- sorted. */
9230 { "Ranges", & do_debug_ranges
, 1 },
9231 { "abbrev", & do_debug_abbrevs
, 1 },
9232 { "addr", & do_debug_addr
, 1 },
9233 { "aranges", & do_debug_aranges
, 1 },
9234 { "cu_index", & do_debug_cu_index
, 1 },
9235 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
9236 { "frames", & do_debug_frames
, 1 },
9237 { "frames-interp", & do_debug_frames_interp
, 1 },
9238 /* The special .gdb_index section. */
9239 { "gdb_index", & do_gdb_index
, 1 },
9240 { "info", & do_debug_info
, 1 },
9241 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
9242 { "loc", & do_debug_loc
, 1 },
9243 { "macro", & do_debug_macinfo
, 1 },
9244 { "pubnames", & do_debug_pubnames
, 1 },
9245 { "pubtypes", & do_debug_pubtypes
, 1 },
9246 /* This entry is for compatibility
9247 with earlier versions of readelf. */
9248 { "ranges", & do_debug_aranges
, 1 },
9249 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
9250 { "str", & do_debug_str
, 1 },
9251 /* These trace_* sections are used by Itanium VMS. */
9252 { "trace_abbrev", & do_trace_abbrevs
, 1 },
9253 { "trace_aranges", & do_trace_aranges
, 1 },
9254 { "trace_info", & do_trace_info
, 1 },
9263 const debug_dump_long_opts
* entry
;
9265 for (entry
= opts_table
; entry
->option
; entry
++)
9267 size_t len
= strlen (entry
->option
);
9269 if (strncmp (p
, entry
->option
, len
) == 0
9270 && (p
[len
] == ',' || p
[len
] == '\0'))
9272 * entry
->variable
|= entry
->val
;
9274 /* The --debug-dump=frames-interp option also
9275 enables the --debug-dump=frames option. */
9276 if (do_debug_frames_interp
)
9277 do_debug_frames
= 1;
9284 if (entry
->option
== NULL
)
9286 warn (_("Unrecognized debug option '%s'\n"), p
);
9287 p
= strchr (p
, ',');
9298 dwarf_select_sections_by_letters (const char *letters
)
9300 unsigned int lindex
= 0;
9302 while (letters
[lindex
])
9303 switch (letters
[lindex
++])
9310 do_debug_abbrevs
= 1;
9314 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
9318 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
9322 do_debug_pubnames
= 1;
9326 do_debug_pubtypes
= 1;
9330 do_debug_aranges
= 1;
9334 do_debug_ranges
= 1;
9338 do_debug_frames_interp
= 1;
9341 do_debug_frames
= 1;
9345 do_debug_macinfo
= 1;
9357 warn (_("Unrecognized debug option '%s'\n"), letters
);
9363 dwarf_select_sections_all (void)
9366 do_debug_abbrevs
= 1;
9367 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
9368 do_debug_pubnames
= 1;
9369 do_debug_pubtypes
= 1;
9370 do_debug_aranges
= 1;
9371 do_debug_ranges
= 1;
9372 do_debug_frames
= 1;
9373 do_debug_macinfo
= 1;
9378 do_trace_abbrevs
= 1;
9379 do_trace_aranges
= 1;
9381 do_debug_cu_index
= 1;
9384 struct dwarf_section_display debug_displays
[] =
9386 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9387 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
9388 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9389 display_debug_aranges
, &do_debug_aranges
, TRUE
},
9390 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9391 display_debug_frames
, &do_debug_frames
, TRUE
},
9392 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
9393 display_debug_info
, &do_debug_info
, TRUE
},
9394 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9395 display_debug_lines
, &do_debug_lines
, TRUE
},
9396 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9397 display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
9398 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9399 display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
9400 { { ".eh_frame", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9401 display_debug_frames
, &do_debug_frames
, TRUE
},
9402 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9403 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
9404 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9405 display_debug_macro
, &do_debug_macinfo
, TRUE
},
9406 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9407 display_debug_str
, &do_debug_str
, FALSE
},
9408 { { ".debug_line_str", ".zdebug_line_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9409 display_debug_str
, &do_debug_str
, FALSE
},
9410 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9411 display_debug_loc
, &do_debug_loc
, TRUE
},
9412 { { ".debug_loclists", ".zdebug_loclists", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9413 display_debug_loc
, &do_debug_loc
, TRUE
},
9414 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9415 display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
9416 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9417 display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
9418 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9419 display_debug_ranges
, &do_debug_ranges
, TRUE
},
9420 { { ".debug_rnglists", ".zdebug_rnglists", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9421 display_debug_ranges
, &do_debug_ranges
, TRUE
},
9422 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9423 display_debug_not_supported
, NULL
, FALSE
},
9424 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9425 display_debug_not_supported
, NULL
, FALSE
},
9426 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
9427 display_debug_types
, &do_debug_info
, TRUE
},
9428 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9429 display_debug_not_supported
, NULL
, FALSE
},
9430 { { ".gdb_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9431 display_gdb_index
, &do_gdb_index
, FALSE
},
9432 { { ".debug_names", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9433 display_debug_names
, &do_gdb_index
, FALSE
},
9434 { { ".trace_info", "", NULL
, NULL
, 0, 0, trace_abbrev
, NULL
, 0, NULL
},
9435 display_trace_info
, &do_trace_info
, TRUE
},
9436 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9437 display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
9438 { { ".trace_aranges", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9439 display_debug_aranges
, &do_trace_aranges
, FALSE
},
9440 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
9441 display_debug_info
, &do_debug_info
, TRUE
},
9442 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9443 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
9444 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
9445 display_debug_types
, &do_debug_info
, TRUE
},
9446 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9447 display_debug_lines
, &do_debug_lines
, TRUE
},
9448 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9449 display_debug_loc
, &do_debug_loc
, TRUE
},
9450 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9451 display_debug_macro
, &do_debug_macinfo
, TRUE
},
9452 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9453 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
9454 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9455 display_debug_str
, &do_debug_str
, TRUE
},
9456 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9457 display_debug_str_offsets
, NULL
, FALSE
},
9458 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9459 display_debug_str_offsets
, NULL
, FALSE
},
9460 { { ".debug_addr", ".zdebug_addr", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9461 display_debug_addr
, &do_debug_addr
, TRUE
},
9462 { { ".debug_cu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9463 display_cu_index
, &do_debug_cu_index
, FALSE
},
9464 { { ".debug_tu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
9465 display_cu_index
, &do_debug_cu_index
, FALSE
},
9468 /* A static assertion. */
9469 extern int debug_displays_assert
[ARRAY_SIZE (debug_displays
) == max
? 1 : -1];