1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2015 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"
32 static const char *regname (unsigned int regno
, int row
);
34 static int have_frame_base
;
35 static int need_base_address
;
37 static unsigned int last_pointer_size
= 0;
38 static int warned_about_missing_comp_units
= FALSE
;
40 static unsigned int num_debug_info_entries
= 0;
41 static unsigned int alloc_num_debug_info_entries
= 0;
42 static debug_info
*debug_information
= NULL
;
43 /* Special value for num_debug_info_entries to indicate
44 that the .debug_info section could not be loaded/parsed. */
45 #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1
47 unsigned int eh_addr_size
;
52 int do_debug_pubnames
;
53 int do_debug_pubtypes
;
57 int do_debug_frames_interp
;
66 int do_debug_cu_index
;
69 int dwarf_cutoff_level
= -1;
70 unsigned long dwarf_start_die
;
74 /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index
75 sections. For version 1 package files, each set is stored in SHNDX_POOL
76 as a zero-terminated list of section indexes comprising one set of debug
77 sections from a .dwo file. */
79 static int cu_tu_indexes_read
= 0;
80 static unsigned int *shndx_pool
= NULL
;
81 static unsigned int shndx_pool_size
= 0;
82 static unsigned int shndx_pool_used
= 0;
84 /* For version 2 package files, each set contains an array of section offsets
85 and an array of section sizes, giving the offset and size of the
86 contribution from a CU or TU within one of the debug sections.
87 When displaying debug info from a package file, we need to use these
88 tables to locate the corresponding contributions to each section. */
93 dwarf_vma section_offsets
[DW_SECT_MAX
];
94 size_t section_sizes
[DW_SECT_MAX
];
97 static int cu_count
= 0;
98 static int tu_count
= 0;
99 static struct cu_tu_set
*cu_sets
= NULL
;
100 static struct cu_tu_set
*tu_sets
= NULL
;
102 static void load_cu_tu_indexes (void *file
);
104 /* Values for do_debug_lines. */
105 #define FLAG_DEBUG_LINES_RAW 1
106 #define FLAG_DEBUG_LINES_DECODED 2
109 size_of_encoded_value (int encoding
)
111 switch (encoding
& 0x7)
114 case 0: return eh_addr_size
;
122 get_encoded_value (unsigned char **pdata
,
124 struct dwarf_section
*section
,
127 unsigned char * data
= * pdata
;
128 unsigned int size
= size_of_encoded_value (encoding
);
131 if (data
+ size
>= end
)
133 warn (_("Encoded value extends past end of section\n"));
138 /* PR 17512: file: 002-829853-0.004. */
141 warn (_("Encoded size of %d is too large to read\n"), size
);
146 /* PR 17512: file: 1085-5603-0.004. */
149 warn (_("Encoded size of 0 is too small to read\n"));
154 if (encoding
& DW_EH_PE_signed
)
155 val
= byte_get_signed (data
, size
);
157 val
= byte_get (data
, size
);
159 if ((encoding
& 0x70) == DW_EH_PE_pcrel
)
160 val
+= section
->address
+ (data
- section
->start
);
162 * pdata
= data
+ size
;
166 #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG
168 # define DWARF_VMA_FMT "ll"
169 # define DWARF_VMA_FMT_LONG "%16.16llx"
171 # define DWARF_VMA_FMT "I64"
172 # define DWARF_VMA_FMT_LONG "%016I64x"
175 # define DWARF_VMA_FMT "l"
176 # define DWARF_VMA_FMT_LONG "%16.16lx"
179 /* Convert a dwarf vma value into a string. Returns a pointer to a static
180 buffer containing the converted VALUE. The value is converted according
181 to the printf formating character FMTCH. If NUM_BYTES is non-zero then
182 it specifies the maximum number of bytes to be displayed in the converted
183 value and FMTCH is ignored - hex is always used. */
186 dwarf_vmatoa_1 (const char *fmtch
, dwarf_vma value
, unsigned num_bytes
)
188 /* As dwarf_vmatoa is used more then once in a printf call
189 for output, we are cycling through an fixed array of pointers
190 for return address. */
191 static int buf_pos
= 0;
192 static struct dwarf_vmatoa_buf
198 ret
= buf
[buf_pos
++].place
;
199 buf_pos
%= ARRAY_SIZE (buf
);
203 /* Printf does not have a way of specifiying a maximum field width for an
204 integer value, so we print the full value into a buffer and then select
205 the precision we need. */
206 snprintf (ret
, sizeof (buf
[0].place
), DWARF_VMA_FMT_LONG
, value
);
209 return ret
+ (16 - 2 * num_bytes
);
215 sprintf (fmt
, "%%%s%s", DWARF_VMA_FMT
, fmtch
);
216 snprintf (ret
, sizeof (buf
[0].place
), fmt
, value
);
221 static inline const char *
222 dwarf_vmatoa (const char * fmtch
, dwarf_vma value
)
224 return dwarf_vmatoa_1 (fmtch
, value
, 0);
227 /* Print a dwarf_vma value (typically an address, offset or length) in
228 hexadecimal format, followed by a space. The length of the VALUE (and
229 hence the precision displayed) is determined by the NUM_BYTES parameter. */
232 print_dwarf_vma (dwarf_vma value
, unsigned num_bytes
)
234 printf ("%s ", dwarf_vmatoa_1 (NULL
, value
, num_bytes
));
237 /* Format a 64-bit value, given as two 32-bit values, in hex.
238 For reentrancy, this uses a buffer provided by the caller. */
241 dwarf_vmatoa64 (dwarf_vma hvalue
, dwarf_vma lvalue
, char *buf
,
242 unsigned int buf_len
)
247 snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", lvalue
);
250 len
= snprintf (buf
, buf_len
, "%" DWARF_VMA_FMT
"x", hvalue
);
251 snprintf (buf
+ len
, buf_len
- len
,
252 "%08" DWARF_VMA_FMT
"x", lvalue
);
258 /* Read in a LEB128 encoded value starting at address DATA.
259 If SIGN is true, return a signed LEB128 value.
260 If LENGTH_RETURN is not NULL, return in it the number of bytes read.
261 No bytes will be read at address END or beyond. */
264 read_leb128 (unsigned char *data
,
265 unsigned int *length_return
,
267 const unsigned char * const end
)
269 dwarf_vma result
= 0;
270 unsigned int num_read
= 0;
271 unsigned int shift
= 0;
272 unsigned char byte
= 0;
279 result
|= ((dwarf_vma
) (byte
& 0x7f)) << shift
;
282 if ((byte
& 0x80) == 0)
285 /* PR 17512: file: 0ca183b8.
286 FIXME: Should we signal this error somehow ? */
287 if (shift
>= sizeof (result
) * 8)
291 if (length_return
!= NULL
)
292 *length_return
= num_read
;
294 if (sign
&& (shift
< 8 * sizeof (result
)) && (byte
& 0x40))
295 result
|= (dwarf_vma
) -1 << shift
;
300 /* Create a signed version to avoid painful typecasts. */
301 static inline dwarf_signed_vma
302 read_sleb128 (unsigned char * data
,
303 unsigned int * length_return
,
304 const unsigned char * const end
)
306 return (dwarf_signed_vma
) read_leb128 (data
, length_return
, TRUE
, end
);
309 static inline dwarf_vma
310 read_uleb128 (unsigned char * data
,
311 unsigned int * length_return
,
312 const unsigned char * const end
)
314 return read_leb128 (data
, length_return
, FALSE
, end
);
317 #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
320 int dummy [sizeof (VAL) < (AMOUNT) ? -1 : 1] ATTRIBUTE_UNUSED ; \
321 unsigned int amount = (AMOUNT); \
322 if (((PTR) + amount) >= (END)) \
325 amount = (END) - (PTR); \
329 if (amount == 0 || amount > 8) \
332 VAL = byte_get ((PTR), amount); \
336 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
339 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
344 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
347 unsigned int amount = (AMOUNT); \
348 if (((PTR) + amount) >= (END)) \
351 amount = (END) - (PTR); \
356 VAL = byte_get_signed ((PTR), amount); \
362 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
365 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
370 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
373 if (((PTR) + 8) <= (END)) \
375 byte_get_64 ((PTR), (HIGH), (LOW)); \
379 * (LOW) = * (HIGH) = 0; \
384 typedef struct State_Machine_Registers
392 unsigned char op_index
;
393 unsigned char end_sequence
;
394 /* This variable hold the number of the last entry seen
395 in the File Table. */
396 unsigned int last_file_entry
;
399 static SMR state_machine_regs
;
402 reset_state_machine (int is_stmt
)
404 state_machine_regs
.address
= 0;
405 state_machine_regs
.op_index
= 0;
406 state_machine_regs
.file
= 1;
407 state_machine_regs
.line
= 1;
408 state_machine_regs
.column
= 0;
409 state_machine_regs
.is_stmt
= is_stmt
;
410 state_machine_regs
.basic_block
= 0;
411 state_machine_regs
.end_sequence
= 0;
412 state_machine_regs
.last_file_entry
= 0;
415 /* Handled an extend line op.
416 Returns the number of bytes read. */
419 process_extended_line_op (unsigned char * data
,
423 unsigned char op_code
;
424 unsigned int bytes_read
;
427 unsigned char *orig_data
= data
;
430 len
= read_uleb128 (data
, & bytes_read
, end
);
433 if (len
== 0 || data
== end
|| len
> (uintptr_t) (end
- data
))
435 warn (_("Badly formed extended line op encountered!\n"));
442 printf (_(" Extended opcode %d: "), op_code
);
446 case DW_LNE_end_sequence
:
447 printf (_("End of Sequence\n\n"));
448 reset_state_machine (is_stmt
);
451 case DW_LNE_set_address
:
452 /* PR 17512: file: 002-100480-0.004. */
453 if (len
- bytes_read
- 1 > 8)
455 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
456 len
- bytes_read
- 1);
460 SAFE_BYTE_GET (adr
, data
, len
- bytes_read
- 1, end
);
461 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
462 state_machine_regs
.address
= adr
;
463 state_machine_regs
.op_index
= 0;
466 case DW_LNE_define_file
:
467 printf (_("define new File Table entry\n"));
468 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
469 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
472 data
+= strnlen ((char *) data
, end
- data
) + 1;
473 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
475 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
477 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
479 printf ("%s\n\n", name
);
481 if (((unsigned int) (data
- orig_data
) != len
) || data
== end
)
482 warn (_("DW_LNE_define_file: Bad opcode length\n"));
485 case DW_LNE_set_discriminator
:
486 printf (_("set Discriminator to %s\n"),
487 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
491 case DW_LNE_HP_negate_is_UV_update
:
492 printf ("DW_LNE_HP_negate_is_UV_update\n");
494 case DW_LNE_HP_push_context
:
495 printf ("DW_LNE_HP_push_context\n");
497 case DW_LNE_HP_pop_context
:
498 printf ("DW_LNE_HP_pop_context\n");
500 case DW_LNE_HP_set_file_line_column
:
501 printf ("DW_LNE_HP_set_file_line_column\n");
503 case DW_LNE_HP_set_routine_name
:
504 printf ("DW_LNE_HP_set_routine_name\n");
506 case DW_LNE_HP_set_sequence
:
507 printf ("DW_LNE_HP_set_sequence\n");
509 case DW_LNE_HP_negate_post_semantics
:
510 printf ("DW_LNE_HP_negate_post_semantics\n");
512 case DW_LNE_HP_negate_function_exit
:
513 printf ("DW_LNE_HP_negate_function_exit\n");
515 case DW_LNE_HP_negate_front_end_logical
:
516 printf ("DW_LNE_HP_negate_front_end_logical\n");
518 case DW_LNE_HP_define_proc
:
519 printf ("DW_LNE_HP_define_proc\n");
521 case DW_LNE_HP_source_file_correlation
:
523 unsigned char *edata
= data
+ len
- bytes_read
- 1;
525 printf ("DW_LNE_HP_source_file_correlation\n");
531 opc
= read_uleb128 (data
, & bytes_read
, edata
);
536 case DW_LNE_HP_SFC_formfeed
:
537 printf (" DW_LNE_HP_SFC_formfeed\n");
539 case DW_LNE_HP_SFC_set_listing_line
:
540 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
542 read_uleb128 (data
, & bytes_read
, edata
)));
545 case DW_LNE_HP_SFC_associate
:
546 printf (" DW_LNE_HP_SFC_associate ");
549 read_uleb128 (data
, & bytes_read
, edata
)));
553 read_uleb128 (data
, & bytes_read
, edata
)));
557 read_uleb128 (data
, & bytes_read
, edata
)));
561 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
571 unsigned int rlen
= len
- bytes_read
- 1;
573 if (op_code
>= DW_LNE_lo_user
574 /* The test against DW_LNW_hi_user is redundant due to
575 the limited range of the unsigned char data type used
577 /*&& op_code <= DW_LNE_hi_user*/)
578 printf (_("user defined: "));
580 printf (_("UNKNOWN: "));
581 printf (_("length %d ["), rlen
);
583 printf (" %02x", *data
++);
592 static const unsigned char *
593 fetch_indirect_string (dwarf_vma offset
)
595 struct dwarf_section
*section
= &debug_displays
[str
].section
;
597 if (section
->start
== NULL
)
598 return (const unsigned char *) _("<no .debug_str section>");
600 if (offset
> section
->size
)
602 warn (_("DW_FORM_strp offset too big: %s\n"),
603 dwarf_vmatoa ("x", offset
));
604 return (const unsigned char *) _("<offset is too big>");
607 return (const unsigned char *) section
->start
+ offset
;
611 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
612 dwarf_vma offset_size
, int dwo
)
614 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
615 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
616 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
617 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
618 dwarf_vma index_offset
= idx
* offset_size
;
619 dwarf_vma str_offset
;
621 if (index_section
->start
== NULL
)
622 return (dwo
? _("<no .debug_str_offsets.dwo section>")
623 : _("<no .debug_str_offsets section>"));
625 if (this_set
!= NULL
)
626 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
627 if (index_offset
> index_section
->size
)
629 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
630 dwarf_vmatoa ("x", index_offset
));
631 return _("<index offset is too big>");
634 if (str_section
->start
== NULL
)
635 return (dwo
? _("<no .debug_str.dwo section>")
636 : _("<no .debug_str section>"));
638 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
639 str_offset
-= str_section
->address
;
640 if (str_offset
> str_section
->size
)
642 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
643 dwarf_vmatoa ("x", str_offset
));
644 return _("<indirect index offset is too big>");
647 return (const char *) str_section
->start
+ str_offset
;
651 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
653 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
655 if (section
->start
== NULL
)
656 return (_("<no .debug_addr section>"));
658 if (offset
+ bytes
> section
->size
)
660 warn (_("Offset into section %s too big: %s\n"),
661 section
->name
, dwarf_vmatoa ("x", offset
));
662 return "<offset too big>";
665 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
669 /* FIXME: There are better and more efficient ways to handle
670 these structures. For now though, I just want something that
671 is simple to implement. */
672 typedef struct abbrev_attr
674 unsigned long attribute
;
676 struct abbrev_attr
*next
;
680 typedef struct abbrev_entry
685 struct abbrev_attr
*first_attr
;
686 struct abbrev_attr
*last_attr
;
687 struct abbrev_entry
*next
;
691 static abbrev_entry
*first_abbrev
= NULL
;
692 static abbrev_entry
*last_abbrev
= NULL
;
699 for (abbrv
= first_abbrev
; abbrv
;)
701 abbrev_entry
*next_abbrev
= abbrv
->next
;
704 for (attr
= abbrv
->first_attr
; attr
;)
706 abbrev_attr
*next_attr
= attr
->next
;
716 last_abbrev
= first_abbrev
= NULL
;
720 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
724 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
729 entry
->entry
= number
;
731 entry
->children
= children
;
732 entry
->first_attr
= NULL
;
733 entry
->last_attr
= NULL
;
736 if (first_abbrev
== NULL
)
737 first_abbrev
= entry
;
739 last_abbrev
->next
= entry
;
745 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
749 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
754 attr
->attribute
= attribute
;
758 if (last_abbrev
->first_attr
== NULL
)
759 last_abbrev
->first_attr
= attr
;
761 last_abbrev
->last_attr
->next
= attr
;
763 last_abbrev
->last_attr
= attr
;
766 /* Processes the (partial) contents of a .debug_abbrev section.
767 Returns NULL if the end of the section was encountered.
768 Returns the address after the last byte read if the end of
769 an abbreviation set was found. */
771 static unsigned char *
772 process_abbrev_section (unsigned char *start
, unsigned char *end
)
774 if (first_abbrev
!= NULL
)
779 unsigned int bytes_read
;
782 unsigned long attribute
;
785 entry
= read_uleb128 (start
, & bytes_read
, end
);
788 /* A single zero is supposed to end the section according
789 to the standard. If there's more, then signal that to
796 tag
= read_uleb128 (start
, & bytes_read
, end
);
803 add_abbrev (entry
, tag
, children
);
809 attribute
= read_uleb128 (start
, & bytes_read
, end
);
814 form
= read_uleb128 (start
, & bytes_read
, end
);
819 add_abbrev_attr (attribute
, form
);
821 while (attribute
!= 0);
824 /* Report the missing single zero which ends the section. */
825 error (_(".debug_abbrev section not zero terminated\n"));
831 get_TAG_name (unsigned long tag
)
833 const char *name
= get_DW_TAG_name ((unsigned int)tag
);
837 static char buffer
[100];
839 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
847 get_FORM_name (unsigned long form
)
852 return "DW_FORM value: 0";
854 name
= get_DW_FORM_name (form
);
857 static char buffer
[100];
859 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
866 static unsigned char *
867 display_block (unsigned char *data
,
869 const unsigned char * const end
)
873 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
875 return (unsigned char *) end
;
877 maxlen
= (dwarf_vma
) (end
- data
);
878 length
= length
> maxlen
? maxlen
: length
;
881 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
887 decode_location_expression (unsigned char * data
,
888 unsigned int pointer_size
,
889 unsigned int offset_size
,
893 struct dwarf_section
* section
)
896 unsigned int bytes_read
;
898 dwarf_signed_vma svalue
;
899 unsigned char *end
= data
+ length
;
900 int need_frame_base
= 0;
909 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
910 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
913 printf ("DW_OP_deref");
916 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
917 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
920 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
921 printf ("DW_OP_const1s: %ld", (long) svalue
);
924 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
925 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
928 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
929 printf ("DW_OP_const2s: %ld", (long) svalue
);
932 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
933 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
936 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
937 printf ("DW_OP_const4s: %ld", (long) svalue
);
940 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
941 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
942 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
943 printf ("%lu", (unsigned long) uvalue
);
946 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
947 printf ("DW_OP_const8s: %ld ", (long) svalue
);
948 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
949 printf ("%ld", (long) svalue
);
952 printf ("DW_OP_constu: %s",
953 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
957 printf ("DW_OP_consts: %s",
958 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
962 printf ("DW_OP_dup");
965 printf ("DW_OP_drop");
968 printf ("DW_OP_over");
971 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
972 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
975 printf ("DW_OP_swap");
978 printf ("DW_OP_rot");
981 printf ("DW_OP_xderef");
984 printf ("DW_OP_abs");
987 printf ("DW_OP_and");
990 printf ("DW_OP_div");
993 printf ("DW_OP_minus");
996 printf ("DW_OP_mod");
999 printf ("DW_OP_mul");
1002 printf ("DW_OP_neg");
1005 printf ("DW_OP_not");
1008 printf ("DW_OP_or");
1011 printf ("DW_OP_plus");
1013 case DW_OP_plus_uconst
:
1014 printf ("DW_OP_plus_uconst: %s",
1015 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1019 printf ("DW_OP_shl");
1022 printf ("DW_OP_shr");
1025 printf ("DW_OP_shra");
1028 printf ("DW_OP_xor");
1031 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1032 printf ("DW_OP_bra: %ld", (long) svalue
);
1035 printf ("DW_OP_eq");
1038 printf ("DW_OP_ge");
1041 printf ("DW_OP_gt");
1044 printf ("DW_OP_le");
1047 printf ("DW_OP_lt");
1050 printf ("DW_OP_ne");
1053 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1054 printf ("DW_OP_skip: %ld", (long) svalue
);
1089 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1124 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1125 regname (op
- DW_OP_reg0
, 1));
1160 printf ("DW_OP_breg%d (%s): %s",
1162 regname (op
- DW_OP_breg0
, 1),
1163 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1168 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1170 printf ("DW_OP_regx: %s (%s)",
1171 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1174 need_frame_base
= 1;
1175 printf ("DW_OP_fbreg: %s",
1176 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1180 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1182 printf ("DW_OP_bregx: %s (%s) %s",
1183 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1184 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1188 printf ("DW_OP_piece: %s",
1189 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1192 case DW_OP_deref_size
:
1193 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1194 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1196 case DW_OP_xderef_size
:
1197 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1198 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1201 printf ("DW_OP_nop");
1204 /* DWARF 3 extensions. */
1205 case DW_OP_push_object_address
:
1206 printf ("DW_OP_push_object_address");
1209 /* XXX: Strictly speaking for 64-bit DWARF3 files
1210 this ought to be an 8-byte wide computation. */
1211 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1212 printf ("DW_OP_call2: <0x%s>",
1213 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1216 /* XXX: Strictly speaking for 64-bit DWARF3 files
1217 this ought to be an 8-byte wide computation. */
1218 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1219 printf ("DW_OP_call4: <0x%s>",
1220 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1222 case DW_OP_call_ref
:
1223 /* XXX: Strictly speaking for 64-bit DWARF3 files
1224 this ought to be an 8-byte wide computation. */
1225 if (dwarf_version
== -1)
1227 printf (_("(DW_OP_call_ref in frame info)"));
1228 /* No way to tell where the next op is, so just bail. */
1229 return need_frame_base
;
1231 if (dwarf_version
== 2)
1233 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1237 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1239 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1241 case DW_OP_form_tls_address
:
1242 printf ("DW_OP_form_tls_address");
1244 case DW_OP_call_frame_cfa
:
1245 printf ("DW_OP_call_frame_cfa");
1247 case DW_OP_bit_piece
:
1248 printf ("DW_OP_bit_piece: ");
1249 printf (_("size: %s "),
1250 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1252 printf (_("offset: %s "),
1253 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1257 /* DWARF 4 extensions. */
1258 case DW_OP_stack_value
:
1259 printf ("DW_OP_stack_value");
1262 case DW_OP_implicit_value
:
1263 printf ("DW_OP_implicit_value");
1264 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1266 data
= display_block (data
, uvalue
, end
);
1269 /* GNU extensions. */
1270 case DW_OP_GNU_push_tls_address
:
1271 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1273 case DW_OP_GNU_uninit
:
1274 printf ("DW_OP_GNU_uninit");
1275 /* FIXME: Is there data associated with this OP ? */
1277 case DW_OP_GNU_encoded_addr
:
1284 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1286 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1287 print_dwarf_vma (addr
, pointer_size
);
1290 case DW_OP_GNU_implicit_pointer
:
1291 /* XXX: Strictly speaking for 64-bit DWARF3 files
1292 this ought to be an 8-byte wide computation. */
1293 if (dwarf_version
== -1)
1295 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1296 /* No way to tell where the next op is, so just bail. */
1297 return need_frame_base
;
1299 if (dwarf_version
== 2)
1301 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1305 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1307 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1308 dwarf_vmatoa ("x", uvalue
),
1309 dwarf_vmatoa ("d", read_sleb128 (data
,
1310 &bytes_read
, end
)));
1313 case DW_OP_GNU_entry_value
:
1314 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1316 /* PR 17531: file: 0cc9cd00. */
1317 if (uvalue
> (dwarf_vma
) (end
- data
))
1318 uvalue
= end
- data
;
1319 printf ("DW_OP_GNU_entry_value: (");
1320 if (decode_location_expression (data
, pointer_size
, offset_size
,
1321 dwarf_version
, uvalue
,
1322 cu_offset
, section
))
1323 need_frame_base
= 1;
1329 case DW_OP_GNU_const_type
:
1330 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1332 printf ("DW_OP_GNU_const_type: <0x%s> ",
1333 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1334 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1335 data
= display_block (data
, uvalue
, end
);
1337 case DW_OP_GNU_regval_type
:
1338 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1340 printf ("DW_OP_GNU_regval_type: %s (%s)",
1341 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1342 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1344 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1346 case DW_OP_GNU_deref_type
:
1347 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1348 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue
);
1349 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1351 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1353 case DW_OP_GNU_convert
:
1354 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1356 printf ("DW_OP_GNU_convert <0x%s>",
1357 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1359 case DW_OP_GNU_reinterpret
:
1360 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1362 printf ("DW_OP_GNU_reinterpret <0x%s>",
1363 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1365 case DW_OP_GNU_parameter_ref
:
1366 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1367 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1368 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1370 case DW_OP_GNU_addr_index
:
1371 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1373 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1375 case DW_OP_GNU_const_index
:
1376 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1378 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1381 /* HP extensions. */
1382 case DW_OP_HP_is_value
:
1383 printf ("DW_OP_HP_is_value");
1384 /* FIXME: Is there data associated with this OP ? */
1386 case DW_OP_HP_fltconst4
:
1387 printf ("DW_OP_HP_fltconst4");
1388 /* FIXME: Is there data associated with this OP ? */
1390 case DW_OP_HP_fltconst8
:
1391 printf ("DW_OP_HP_fltconst8");
1392 /* FIXME: Is there data associated with this OP ? */
1394 case DW_OP_HP_mod_range
:
1395 printf ("DW_OP_HP_mod_range");
1396 /* FIXME: Is there data associated with this OP ? */
1398 case DW_OP_HP_unmod_range
:
1399 printf ("DW_OP_HP_unmod_range");
1400 /* FIXME: Is there data associated with this OP ? */
1403 printf ("DW_OP_HP_tls");
1404 /* FIXME: Is there data associated with this OP ? */
1407 /* PGI (STMicroelectronics) extensions. */
1408 case DW_OP_PGI_omp_thread_num
:
1409 /* Pushes the thread number for the current thread as it would be
1410 returned by the standard OpenMP library function:
1411 omp_get_thread_num(). The "current thread" is the thread for
1412 which the expression is being evaluated. */
1413 printf ("DW_OP_PGI_omp_thread_num");
1417 if (op
>= DW_OP_lo_user
1418 && op
<= DW_OP_hi_user
)
1419 printf (_("(User defined location op)"));
1421 printf (_("(Unknown location op)"));
1422 /* No way to tell where the next op is, so just bail. */
1423 return need_frame_base
;
1426 /* Separate the ops. */
1431 return need_frame_base
;
1434 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1435 This is used for DWARF package files. */
1437 static struct cu_tu_set
*
1438 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1440 struct cu_tu_set
*p
;
1442 unsigned int dw_sect
;
1448 dw_sect
= DW_SECT_TYPES
;
1454 dw_sect
= DW_SECT_INFO
;
1458 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1466 /* Add INC to HIGH_BITS:LOW_BITS. */
1468 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1470 dwarf_vma tmp
= * low_bits
;
1474 /* FIXME: There is probably a better way of handling this:
1476 We need to cope with dwarf_vma being a 32-bit or 64-bit
1477 type. Plus regardless of its size LOW_BITS is meant to
1478 only hold 32-bits, so if there is overflow or wrap around
1479 we must propagate into HIGH_BITS. */
1480 if (tmp
< * low_bits
)
1484 else if (sizeof (tmp
) > 8
1494 static unsigned char *
1495 read_and_display_attr_value (unsigned long attribute
,
1497 unsigned char * data
,
1498 unsigned char * end
,
1499 dwarf_vma cu_offset
,
1500 dwarf_vma pointer_size
,
1501 dwarf_vma offset_size
,
1503 debug_info
* debug_info_p
,
1505 struct dwarf_section
* section
,
1506 struct cu_tu_set
* this_set
)
1508 dwarf_vma uvalue
= 0;
1509 unsigned char *block_start
= NULL
;
1510 unsigned char * orig_data
= data
;
1511 unsigned int bytes_read
;
1513 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
1515 warn (_("Corrupt attribute\n"));
1524 case DW_FORM_ref_addr
:
1525 if (dwarf_version
== 2)
1526 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1527 else if (dwarf_version
== 3 || dwarf_version
== 4)
1528 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1530 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1535 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1539 case DW_FORM_sec_offset
:
1540 case DW_FORM_GNU_ref_alt
:
1541 case DW_FORM_GNU_strp_alt
:
1542 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1545 case DW_FORM_flag_present
:
1552 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1557 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1562 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1566 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1570 case DW_FORM_GNU_str_index
:
1571 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1575 case DW_FORM_ref_udata
:
1577 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1581 case DW_FORM_indirect
:
1582 form
= read_uleb128 (data
, & bytes_read
, end
);
1585 printf (" %s", get_FORM_name (form
));
1586 return read_and_display_attr_value (attribute
, form
, data
, end
,
1587 cu_offset
, pointer_size
,
1588 offset_size
, dwarf_version
,
1589 debug_info_p
, do_loc
,
1591 case DW_FORM_GNU_addr_index
:
1592 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1599 case DW_FORM_ref_addr
:
1601 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1604 case DW_FORM_GNU_ref_alt
:
1606 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue
));
1612 case DW_FORM_ref_udata
:
1614 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1619 case DW_FORM_sec_offset
:
1621 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1624 case DW_FORM_flag_present
:
1631 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1638 dwarf_vma high_bits
;
1642 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1644 if (form
== DW_FORM_ref8
)
1645 add64 (& high_bits
, & utmp
, cu_offset
);
1647 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1650 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1651 && num_debug_info_entries
== 0)
1653 if (sizeof (uvalue
) == 8)
1654 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1656 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1662 case DW_FORM_string
:
1664 printf (" %.*s", (int) (end
- data
), data
);
1665 data
+= strnlen ((char *) data
, end
- data
) + 1;
1669 case DW_FORM_exprloc
:
1670 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1671 block_start
= data
+ bytes_read
;
1672 if (block_start
>= end
)
1674 warn (_("Block ends prematurely\n"));
1678 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1679 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1680 block_start + uvalue here. */
1681 data
= block_start
+ uvalue
;
1682 /* PR 17512: file: 008-103549-0.001:0.1. */
1683 if (block_start
+ uvalue
> end
|| data
< block_start
)
1685 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1686 uvalue
= end
- block_start
;
1689 data
= block_start
+ uvalue
;
1691 data
= display_block (block_start
, uvalue
, end
);
1694 case DW_FORM_block1
:
1695 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1696 block_start
= data
+ 1;
1697 if (block_start
>= end
)
1699 warn (_("Block ends prematurely\n"));
1703 data
= block_start
+ uvalue
;
1704 if (block_start
+ uvalue
> end
|| data
< block_start
)
1706 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1707 uvalue
= end
- block_start
;
1710 data
= block_start
+ uvalue
;
1712 data
= display_block (block_start
, uvalue
, end
);
1715 case DW_FORM_block2
:
1716 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1717 block_start
= data
+ 2;
1718 if (block_start
>= end
)
1720 warn (_("Block ends prematurely\n"));
1724 data
= block_start
+ uvalue
;
1725 if (block_start
+ uvalue
> end
|| data
< block_start
)
1727 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1728 uvalue
= end
- block_start
;
1731 data
= block_start
+ uvalue
;
1733 data
= display_block (block_start
, uvalue
, end
);
1736 case DW_FORM_block4
:
1737 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1738 block_start
= data
+ 4;
1739 /* PR 17512: file: 3371-3907-0.004. */
1740 if (block_start
>= end
)
1742 warn (_("Block ends prematurely\n"));
1746 data
= block_start
+ uvalue
;
1747 if (block_start
+ uvalue
> end
1748 /* PR 17531: file: 5b5f0592. */
1749 || data
< block_start
)
1751 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1752 uvalue
= end
- block_start
;
1755 data
= block_start
+ uvalue
;
1757 data
= display_block (block_start
, uvalue
, end
);
1762 printf (_(" (indirect string, offset: 0x%s): %s"),
1763 dwarf_vmatoa ("x", uvalue
),
1764 fetch_indirect_string (uvalue
));
1767 case DW_FORM_GNU_str_index
:
1770 const char *suffix
= strrchr (section
->name
, '.');
1771 int dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? 1 : 0;
1773 printf (_(" (indexed string: 0x%s): %s"),
1774 dwarf_vmatoa ("x", uvalue
),
1775 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
1779 case DW_FORM_GNU_strp_alt
:
1781 printf (_(" (alt indirect string, offset: 0x%s)"),
1782 dwarf_vmatoa ("x", uvalue
));
1785 case DW_FORM_indirect
:
1786 /* Handled above. */
1789 case DW_FORM_ref_sig8
:
1792 dwarf_vma high_bits
;
1795 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1796 printf (" signature: 0x%s",
1797 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1802 case DW_FORM_GNU_addr_index
:
1804 printf (_(" (addr_index: 0x%s): %s"),
1805 dwarf_vmatoa ("x", uvalue
),
1806 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
1810 warn (_("Unrecognized form: %lu\n"), form
);
1814 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1815 && num_debug_info_entries
== 0
1816 && debug_info_p
!= NULL
)
1820 case DW_AT_frame_base
:
1821 have_frame_base
= 1;
1822 case DW_AT_location
:
1823 case DW_AT_string_length
:
1824 case DW_AT_return_addr
:
1825 case DW_AT_data_member_location
:
1826 case DW_AT_vtable_elem_location
:
1828 case DW_AT_static_link
:
1829 case DW_AT_use_location
:
1830 case DW_AT_GNU_call_site_value
:
1831 case DW_AT_GNU_call_site_data_value
:
1832 case DW_AT_GNU_call_site_target
:
1833 case DW_AT_GNU_call_site_target_clobbered
:
1834 if ((dwarf_version
< 4
1835 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1836 || form
== DW_FORM_sec_offset
)
1838 /* Process location list. */
1839 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1840 unsigned int num
= debug_info_p
->num_loc_offsets
;
1842 if (lmax
== 0 || num
>= lmax
)
1845 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1846 xcrealloc (debug_info_p
->loc_offsets
,
1847 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1848 debug_info_p
->have_frame_base
= (int *)
1849 xcrealloc (debug_info_p
->have_frame_base
,
1850 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1851 debug_info_p
->max_loc_offsets
= lmax
;
1853 if (this_set
!= NULL
)
1854 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
1855 debug_info_p
->loc_offsets
[num
] = uvalue
;
1856 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1857 debug_info_p
->num_loc_offsets
++;
1862 if (need_base_address
)
1863 debug_info_p
->base_address
= uvalue
;
1866 case DW_AT_GNU_addr_base
:
1867 debug_info_p
->addr_base
= uvalue
;
1870 case DW_AT_GNU_ranges_base
:
1871 debug_info_p
->ranges_base
= uvalue
;
1875 if ((dwarf_version
< 4
1876 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1877 || form
== DW_FORM_sec_offset
)
1879 /* Process range list. */
1880 unsigned int lmax
= debug_info_p
->max_range_lists
;
1881 unsigned int num
= debug_info_p
->num_range_lists
;
1883 if (lmax
== 0 || num
>= lmax
)
1886 debug_info_p
->range_lists
= (dwarf_vma
*)
1887 xcrealloc (debug_info_p
->range_lists
,
1888 lmax
, sizeof (*debug_info_p
->range_lists
));
1889 debug_info_p
->max_range_lists
= lmax
;
1891 debug_info_p
->range_lists
[num
] = uvalue
;
1892 debug_info_p
->num_range_lists
++;
1901 if (do_loc
|| attribute
== 0)
1904 /* For some attributes we can display further information. */
1911 case DW_INL_not_inlined
:
1912 printf (_("(not inlined)"));
1914 case DW_INL_inlined
:
1915 printf (_("(inlined)"));
1917 case DW_INL_declared_not_inlined
:
1918 printf (_("(declared as inline but ignored)"));
1920 case DW_INL_declared_inlined
:
1921 printf (_("(declared as inline and inlined)"));
1924 printf (_(" (Unknown inline attribute value: %s)"),
1925 dwarf_vmatoa ("x", uvalue
));
1930 case DW_AT_language
:
1934 /* Ordered by the numeric value of these constants. */
1935 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1936 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1937 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1938 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1939 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1940 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1941 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1942 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1943 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1944 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1945 /* DWARF 2.1 values. */
1946 case DW_LANG_Java
: printf ("(Java)"); break;
1947 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1948 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1949 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1950 /* DWARF 3 values. */
1951 case DW_LANG_PLI
: printf ("(PLI)"); break;
1952 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1953 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1954 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1955 case DW_LANG_D
: printf ("(D)"); break;
1956 /* DWARF 4 values. */
1957 case DW_LANG_Python
: printf ("(Python)"); break;
1958 /* DWARF 5 values. */
1959 case DW_LANG_Go
: printf ("(Go)"); break;
1960 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
1961 case DW_LANG_C11
: printf ("(C11)"); break;
1962 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
1963 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
1964 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
1965 /* MIPS extension. */
1966 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1967 /* UPC extension. */
1968 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1970 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1971 printf (_("(implementation defined: %s)"),
1972 dwarf_vmatoa ("x", uvalue
));
1974 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
1979 case DW_AT_encoding
:
1983 case DW_ATE_void
: printf ("(void)"); break;
1984 case DW_ATE_address
: printf ("(machine address)"); break;
1985 case DW_ATE_boolean
: printf ("(boolean)"); break;
1986 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1987 case DW_ATE_float
: printf ("(float)"); break;
1988 case DW_ATE_signed
: printf ("(signed)"); break;
1989 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1990 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1991 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1992 /* DWARF 2.1 values: */
1993 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1994 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
1995 /* DWARF 3 values: */
1996 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
1997 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
1998 case DW_ATE_edited
: printf ("(edited)"); break;
1999 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2000 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2001 /* HP extensions: */
2002 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2003 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2004 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2005 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2006 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2007 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2008 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2009 /* DWARF 4 values: */
2010 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2013 if (uvalue
>= DW_ATE_lo_user
2014 && uvalue
<= DW_ATE_hi_user
)
2015 printf (_("(user defined type)"));
2017 printf (_("(unknown type)"));
2022 case DW_AT_accessibility
:
2026 case DW_ACCESS_public
: printf ("(public)"); break;
2027 case DW_ACCESS_protected
: printf ("(protected)"); break;
2028 case DW_ACCESS_private
: printf ("(private)"); break;
2030 printf (_("(unknown accessibility)"));
2035 case DW_AT_visibility
:
2039 case DW_VIS_local
: printf ("(local)"); break;
2040 case DW_VIS_exported
: printf ("(exported)"); break;
2041 case DW_VIS_qualified
: printf ("(qualified)"); break;
2042 default: printf (_("(unknown visibility)")); break;
2046 case DW_AT_virtuality
:
2050 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2051 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2052 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2053 default: printf (_("(unknown virtuality)")); break;
2057 case DW_AT_identifier_case
:
2061 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2062 case DW_ID_up_case
: printf ("(up_case)"); break;
2063 case DW_ID_down_case
: printf ("(down_case)"); break;
2064 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2065 default: printf (_("(unknown case)")); break;
2069 case DW_AT_calling_convention
:
2073 case DW_CC_normal
: printf ("(normal)"); break;
2074 case DW_CC_program
: printf ("(program)"); break;
2075 case DW_CC_nocall
: printf ("(nocall)"); break;
2077 if (uvalue
>= DW_CC_lo_user
2078 && uvalue
<= DW_CC_hi_user
)
2079 printf (_("(user defined)"));
2081 printf (_("(unknown convention)"));
2085 case DW_AT_ordering
:
2089 case -1: printf (_("(undefined)")); break;
2090 case 0: printf ("(row major)"); break;
2091 case 1: printf ("(column major)"); break;
2095 case DW_AT_frame_base
:
2096 have_frame_base
= 1;
2097 case DW_AT_location
:
2098 case DW_AT_string_length
:
2099 case DW_AT_return_addr
:
2100 case DW_AT_data_member_location
:
2101 case DW_AT_vtable_elem_location
:
2103 case DW_AT_static_link
:
2104 case DW_AT_use_location
:
2105 case DW_AT_GNU_call_site_value
:
2106 case DW_AT_GNU_call_site_data_value
:
2107 case DW_AT_GNU_call_site_target
:
2108 case DW_AT_GNU_call_site_target_clobbered
:
2109 if ((dwarf_version
< 4
2110 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2111 || form
== DW_FORM_sec_offset
)
2112 printf (_(" (location list)"));
2114 case DW_AT_allocated
:
2115 case DW_AT_associated
:
2116 case DW_AT_data_location
:
2118 case DW_AT_upper_bound
:
2119 case DW_AT_lower_bound
:
2122 int need_frame_base
;
2125 need_frame_base
= decode_location_expression (block_start
,
2130 cu_offset
, section
);
2132 if (need_frame_base
&& !have_frame_base
)
2133 printf (_(" [without DW_AT_frame_base]"));
2139 if (form
== DW_FORM_ref_sig8
2140 || form
== DW_FORM_GNU_ref_alt
)
2143 if (form
== DW_FORM_ref1
2144 || form
== DW_FORM_ref2
2145 || form
== DW_FORM_ref4
2146 || form
== DW_FORM_ref_udata
)
2147 uvalue
+= cu_offset
;
2149 if (uvalue
>= section
->size
)
2150 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2151 dwarf_vmatoa ("x", uvalue
),
2152 (unsigned long) (orig_data
- section
->start
));
2155 unsigned long abbrev_number
;
2156 abbrev_entry
* entry
;
2158 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2160 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2161 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2162 use different abbrev table, and we don't track .debug_info chunks
2164 if (form
!= DW_FORM_ref_addr
)
2166 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2167 if (entry
->entry
== abbrev_number
)
2170 printf (" (%s)", get_TAG_name (entry
->tag
));
2185 get_AT_name (unsigned long attribute
)
2190 return "DW_AT value: 0";
2192 /* One value is shared by the MIPS and HP extensions: */
2193 if (attribute
== DW_AT_MIPS_fde
)
2194 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2196 name
= get_DW_AT_name (attribute
);
2200 static char buffer
[100];
2202 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2210 static unsigned char *
2211 read_and_display_attr (unsigned long attribute
,
2213 unsigned char * data
,
2214 unsigned char * end
,
2215 dwarf_vma cu_offset
,
2216 dwarf_vma pointer_size
,
2217 dwarf_vma offset_size
,
2219 debug_info
* debug_info_p
,
2221 struct dwarf_section
* section
,
2222 struct cu_tu_set
* this_set
)
2225 printf (" %-18s:", get_AT_name (attribute
));
2226 data
= read_and_display_attr_value (attribute
, form
, data
, end
,
2227 cu_offset
, pointer_size
, offset_size
,
2228 dwarf_version
, debug_info_p
,
2229 do_loc
, section
, this_set
);
2235 /* Process the contents of a .debug_info section. If do_loc is non-zero
2236 then we are scanning for location lists and we do not want to display
2237 anything to the user. If do_types is non-zero, we are processing
2238 a .debug_types section instead of a .debug_info section. */
2241 process_debug_info (struct dwarf_section
*section
,
2243 enum dwarf_section_display_enum abbrev_sec
,
2247 unsigned char *start
= section
->start
;
2248 unsigned char *end
= start
+ section
->size
;
2249 unsigned char *section_begin
;
2251 unsigned int num_units
= 0;
2253 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2254 && num_debug_info_entries
== 0
2259 /* First scan the section to get the number of comp units. */
2260 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2263 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2264 will be the length. For a 64-bit DWARF section, it'll be
2265 the escape code 0xffffffff followed by an 8 byte length. */
2266 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2268 if (length
== 0xffffffff)
2270 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2271 section_begin
+= length
+ 12;
2273 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2275 warn (_("Reserved length value (0x%s) found in section %s\n"),
2276 dwarf_vmatoa ("x", length
), section
->name
);
2280 section_begin
+= length
+ 4;
2282 /* Negative values are illegal, they may even cause infinite
2283 looping. This can happen if we can't accurately apply
2284 relocations to an object file, or if the file is corrupt. */
2285 if ((signed long) length
<= 0 || section_begin
< start
)
2287 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2288 dwarf_vmatoa ("x", length
), section
->name
);
2295 error (_("No comp units in %s section ?\n"), section
->name
);
2299 /* Then allocate an array to hold the information. */
2300 debug_information
= (debug_info
*) cmalloc (num_units
,
2301 sizeof (* debug_information
));
2302 if (debug_information
== NULL
)
2304 error (_("Not enough memory for a debug info array of %u entries\n"),
2306 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
2309 /* PR 17531: file: 92ca3797.
2310 We cannot rely upon the debug_information array being initialised
2311 before it is used. A corrupt file could easily contain references
2312 to a unit for which information has not been made available. So
2313 we ensure that the array is zeroed here. */
2314 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
2316 alloc_num_debug_info_entries
= num_units
;
2321 if (dwarf_start_die
== 0)
2322 printf (_("Contents of the %s section:\n\n"), section
->name
);
2324 load_debug_section (str
, file
);
2325 load_debug_section (str_dwo
, file
);
2326 load_debug_section (str_index
, file
);
2327 load_debug_section (str_index_dwo
, file
);
2328 load_debug_section (debug_addr
, file
);
2331 load_debug_section (abbrev_sec
, file
);
2332 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2334 warn (_("Unable to locate %s section!\n"),
2335 debug_displays
[abbrev_sec
].section
.name
);
2339 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2341 DWARF2_Internal_CompUnit compunit
;
2342 unsigned char *hdrptr
;
2343 unsigned char *tags
;
2344 int level
, last_level
, saved_level
;
2345 dwarf_vma cu_offset
;
2346 unsigned int offset_size
;
2347 int initial_length_size
;
2348 dwarf_vma signature_high
= 0;
2349 dwarf_vma signature_low
= 0;
2350 dwarf_vma type_offset
= 0;
2351 struct cu_tu_set
*this_set
;
2352 dwarf_vma abbrev_base
;
2357 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2359 if (compunit
.cu_length
== 0xffffffff)
2361 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2363 initial_length_size
= 12;
2368 initial_length_size
= 4;
2371 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2373 cu_offset
= start
- section_begin
;
2375 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2377 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2379 if (this_set
== NULL
)
2382 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2386 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2387 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2390 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2391 /* PR 17512: file: 001-108546-0.001:0.1. */
2392 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
2394 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2395 compunit
.cu_pointer_size
, offset_size
);
2396 compunit
.cu_pointer_size
= offset_size
;
2401 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2403 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2406 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2407 && num_debug_info_entries
== 0
2410 debug_information
[unit
].cu_offset
= cu_offset
;
2411 debug_information
[unit
].pointer_size
2412 = compunit
.cu_pointer_size
;
2413 debug_information
[unit
].offset_size
= offset_size
;
2414 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2415 debug_information
[unit
].base_address
= 0;
2416 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2417 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2418 debug_information
[unit
].loc_offsets
= NULL
;
2419 debug_information
[unit
].have_frame_base
= NULL
;
2420 debug_information
[unit
].max_loc_offsets
= 0;
2421 debug_information
[unit
].num_loc_offsets
= 0;
2422 debug_information
[unit
].range_lists
= NULL
;
2423 debug_information
[unit
].max_range_lists
= 0;
2424 debug_information
[unit
].num_range_lists
= 0;
2427 if (!do_loc
&& dwarf_start_die
== 0)
2429 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2430 dwarf_vmatoa ("x", cu_offset
));
2431 printf (_(" Length: 0x%s (%s)\n"),
2432 dwarf_vmatoa ("x", compunit
.cu_length
),
2433 offset_size
== 8 ? "64-bit" : "32-bit");
2434 printf (_(" Version: %d\n"), compunit
.cu_version
);
2435 printf (_(" Abbrev Offset: 0x%s\n"),
2436 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2437 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2442 printf (_(" Signature: 0x%s\n"),
2443 dwarf_vmatoa64 (signature_high
, signature_low
,
2444 buf
, sizeof (buf
)));
2445 printf (_(" Type Offset: 0x%s\n"),
2446 dwarf_vmatoa ("x", type_offset
));
2448 if (this_set
!= NULL
)
2450 dwarf_vma
*offsets
= this_set
->section_offsets
;
2451 size_t *sizes
= this_set
->section_sizes
;
2453 printf (_(" Section contributions:\n"));
2454 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2455 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
2456 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
2457 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2458 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
2459 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
2460 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2461 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
2462 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
2463 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2464 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
2465 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
2469 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2472 warn (_("Debug info is corrupted, length of CU at %s"
2473 " extends beyond end of section (length = %s)\n"),
2474 dwarf_vmatoa ("x", cu_offset
),
2475 dwarf_vmatoa ("x", compunit
.cu_length
));
2480 start
+= compunit
.cu_length
+ initial_length_size
;
2484 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2485 dwarf_vmatoa ("x", cu_offset
));
2489 if (compunit
.cu_version
!= 2
2490 && compunit
.cu_version
!= 3
2491 && compunit
.cu_version
!= 4)
2493 warn (_("CU at offset %s contains corrupt or "
2494 "unsupported version number: %d.\n"),
2495 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2501 /* Process the abbrevs used by this compilation unit. */
2502 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
2503 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2504 (unsigned long) compunit
.cu_abbrev_offset
,
2505 (unsigned long) abbrev_size
);
2506 /* PR 17531: file:4bcd9ce9. */
2507 else if ((abbrev_base
+ abbrev_size
)
2508 > debug_displays
[abbrev_sec
].section
.size
)
2509 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2510 (unsigned long) abbrev_base
+ abbrev_size
,
2511 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2513 process_abbrev_section
2514 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2515 + abbrev_base
+ compunit
.cu_abbrev_offset
),
2516 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2517 + abbrev_base
+ abbrev_size
));
2522 while (tags
< start
)
2524 unsigned int bytes_read
;
2525 unsigned long abbrev_number
;
2526 unsigned long die_offset
;
2527 abbrev_entry
*entry
;
2529 int do_printing
= 1;
2531 die_offset
= tags
- section_begin
;
2533 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
2536 /* A null DIE marks the end of a list of siblings or it may also be
2537 a section padding. */
2538 if (abbrev_number
== 0)
2540 /* Check if it can be a section padding for the last CU. */
2541 if (level
== 0 && start
== end
)
2545 for (chk
= tags
; chk
< start
; chk
++)
2552 if (!do_loc
&& die_offset
>= dwarf_start_die
2553 && (dwarf_cutoff_level
== -1
2554 || level
< dwarf_cutoff_level
))
2555 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2561 static unsigned num_bogus_warns
= 0;
2563 if (num_bogus_warns
< 3)
2565 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2566 die_offset
, section
->name
);
2568 if (num_bogus_warns
== 3)
2569 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2572 if (dwarf_start_die
!= 0 && level
< saved_level
)
2579 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2583 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2584 saved_level
= level
;
2585 do_printing
= (dwarf_cutoff_level
== -1
2586 || level
< dwarf_cutoff_level
);
2588 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2589 level
, die_offset
, abbrev_number
);
2590 else if (dwarf_cutoff_level
== -1
2591 || last_level
< dwarf_cutoff_level
)
2592 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2597 /* Scan through the abbreviation list until we reach the
2599 for (entry
= first_abbrev
;
2600 entry
&& entry
->entry
!= abbrev_number
;
2601 entry
= entry
->next
)
2606 if (!do_loc
&& do_printing
)
2611 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2612 die_offset
, abbrev_number
);
2616 if (!do_loc
&& do_printing
)
2617 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2622 need_base_address
= 0;
2624 case DW_TAG_compile_unit
:
2625 need_base_address
= 1;
2627 case DW_TAG_entry_point
:
2628 case DW_TAG_subprogram
:
2629 need_base_address
= 0;
2630 /* Assuming that there is no DW_AT_frame_base. */
2631 have_frame_base
= 0;
2635 for (attr
= entry
->first_attr
;
2636 attr
&& attr
->attribute
;
2641 if (! do_loc
&& do_printing
)
2642 /* Show the offset from where the tag was extracted. */
2643 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2645 if (debug_information
&& unit
< alloc_num_debug_info_entries
)
2646 arg
= debug_information
+ unit
;
2650 tags
= read_and_display_attr (attr
->attribute
,
2655 compunit
.cu_pointer_size
,
2657 compunit
.cu_version
,
2659 do_loc
|| ! do_printing
,
2664 if (entry
->children
)
2669 /* Set num_debug_info_entries here so that it can be used to check if
2670 we need to process .debug_loc and .debug_ranges sections. */
2671 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2672 && num_debug_info_entries
== 0
2675 if (num_units
> alloc_num_debug_info_entries
)
2676 num_debug_info_entries
= alloc_num_debug_info_entries
;
2678 num_debug_info_entries
= num_units
;
2687 /* Locate and scan the .debug_info section in the file and record the pointer
2688 sizes and offsets for the compilation units in it. Usually an executable
2689 will have just one pointer size, but this is not guaranteed, and so we try
2690 not to make any assumptions. Returns zero upon failure, or the number of
2691 compilation units upon success. */
2694 load_debug_info (void * file
)
2696 /* Reset the last pointer size so that we can issue correct error
2697 messages if we are displaying the contents of more than one section. */
2698 last_pointer_size
= 0;
2699 warned_about_missing_comp_units
= FALSE
;
2701 /* If we have already tried and failed to load the .debug_info
2702 section then do not bother to repeat the task. */
2703 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2706 /* If we already have the information there is nothing else to do. */
2707 if (num_debug_info_entries
> 0)
2708 return num_debug_info_entries
;
2710 /* If this is a DWARF package file, load the CU and TU indexes. */
2711 load_cu_tu_indexes (file
);
2713 if (load_debug_section (info
, file
)
2714 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2715 return num_debug_info_entries
;
2717 if (load_debug_section (info_dwo
, file
)
2718 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
2720 return num_debug_info_entries
;
2722 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2726 /* Read a DWARF .debug_line section header starting at DATA.
2727 Upon success returns an updated DATA pointer and the LINFO
2728 structure and the END_OF_SEQUENCE pointer will be filled in.
2729 Otherwise returns NULL. */
2731 static unsigned char *
2732 read_debug_line_header (struct dwarf_section
* section
,
2733 unsigned char * data
,
2734 unsigned char * end
,
2735 DWARF2_Internal_LineInfo
* linfo
,
2736 unsigned char ** end_of_sequence
)
2738 unsigned char *hdrptr
;
2739 unsigned int offset_size
;
2740 unsigned int initial_length_size
;
2742 /* Extract information from the Line Number Program Header.
2743 (section 6.2.4 in the Dwarf3 doc). */
2746 /* Get and check the length of the block. */
2747 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
2749 if (linfo
->li_length
== 0xffffffff)
2751 /* This section is 64-bit DWARF 3. */
2752 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
2754 initial_length_size
= 12;
2759 initial_length_size
= 4;
2762 if (linfo
->li_length
+ initial_length_size
> section
->size
)
2764 /* If the length is just a bias against the initial_length_size then
2765 this means that the field has a relocation against it which has not
2766 been applied. (Ie we are dealing with an object file, not a linked
2767 binary). Do not complain but instead assume that the rest of the
2768 section applies to this particular header. */
2769 if (linfo
->li_length
== - initial_length_size
)
2771 linfo
->li_length
= section
->size
- initial_length_size
;
2775 warn (_("The line info appears to be corrupt - the section is too small\n"));
2780 /* Get and check the version number. */
2781 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
2783 if (linfo
->li_version
!= 2
2784 && linfo
->li_version
!= 3
2785 && linfo
->li_version
!= 4)
2787 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2791 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
, offset_size
, end
);
2792 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
2794 if (linfo
->li_version
>= 4)
2796 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
2798 if (linfo
->li_max_ops_per_insn
== 0)
2800 warn (_("Invalid maximum operations per insn.\n"));
2805 linfo
->li_max_ops_per_insn
= 1;
2807 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
2808 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
2809 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
2810 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
2812 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
2813 /* PR 17512: file:002-117414-0.004. */
2814 if (* end_of_sequence
> end
)
2816 warn (_("Line length %s extends beyond end of section\n"),
2817 dwarf_vmatoa ("u", linfo
->li_length
));
2818 * end_of_sequence
= end
;
2826 display_debug_lines_raw (struct dwarf_section
*section
,
2827 unsigned char *data
,
2830 unsigned char *start
= section
->start
;
2832 printf (_("Raw dump of debug contents of section %s:\n\n"),
2837 static DWARF2_Internal_LineInfo saved_linfo
;
2838 DWARF2_Internal_LineInfo linfo
;
2839 unsigned char *standard_opcodes
;
2840 unsigned char *end_of_sequence
;
2841 unsigned int last_dir_entry
= 0;
2844 if (const_strneq (section
->name
, ".debug_line.")
2845 /* Note: the following does not apply to .debug_line.dwo sections.
2846 These are full debug_line sections. */
2847 && strcmp (section
->name
, ".debug_line.dwo") != 0)
2849 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2850 section containing just the Line Number Statements. They are
2851 created by the assembler and intended to be used alongside gcc's
2852 -ffunction-sections command line option. When the linker's
2853 garbage collection decides to discard a .text.<foo> section it
2854 can then also discard the line number information in .debug_line.<foo>.
2856 Since the section is a fragment it does not have the details
2857 needed to fill out a LineInfo structure, so instead we use the
2858 details from the last full debug_line section that we processed. */
2859 end_of_sequence
= end
;
2860 standard_opcodes
= NULL
;
2861 linfo
= saved_linfo
;
2862 /* PR 17531: file: 0522b371. */
2863 if (linfo
.li_line_range
== 0)
2865 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
2868 reset_state_machine (linfo
.li_default_is_stmt
);
2872 unsigned char * hdrptr
;
2874 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
2875 & end_of_sequence
)) == NULL
)
2878 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
2879 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2880 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2881 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
2882 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2883 if (linfo
.li_version
>= 4)
2884 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2885 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2886 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2887 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2888 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2890 /* PR 17512: file: 1665-6428-0.004. */
2891 if (linfo
.li_line_range
== 0)
2893 warn (_("Line range of 0 is invalid, using 1 instead\n"));
2894 linfo
.li_line_range
= 1;
2897 reset_state_machine (linfo
.li_default_is_stmt
);
2899 /* Display the contents of the Opcodes table. */
2900 standard_opcodes
= hdrptr
;
2902 /* PR 17512: file: 002-417945-0.004. */
2903 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
2905 warn (_("Line Base extends beyond end of section\n"));
2909 printf (_("\n Opcodes:\n"));
2911 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2912 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2914 /* Display the contents of the Directory table. */
2915 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2918 printf (_("\n The Directory Table is empty.\n"));
2921 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2922 (long)(data
- start
));
2924 while (data
< end
&& *data
!= 0)
2926 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
2928 data
+= strnlen ((char *) data
, end
- data
) + 1;
2931 /* PR 17512: file: 002-132094-0.004. */
2932 if (data
>= end
- 1)
2936 /* Skip the NUL at the end of the table. */
2939 /* Display the contents of the File Name table. */
2941 printf (_("\n The File Name Table is empty.\n"));
2944 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2945 (long)(data
- start
));
2946 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2948 while (data
< end
&& *data
!= 0)
2950 unsigned char *name
;
2951 unsigned int bytes_read
;
2953 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2955 data
+= strnlen ((char *) data
, end
- data
) + 1;
2958 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2961 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2964 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2966 printf ("%.*s\n", (int)(end
- name
), name
);
2970 warn (_("Corrupt file name table entry\n"));
2976 /* Skip the NUL at the end of the table. */
2979 saved_linfo
= linfo
;
2982 /* Now display the statements. */
2983 if (data
>= end_of_sequence
)
2984 printf (_(" No Line Number Statements.\n"));
2987 printf (_(" Line Number Statements:\n"));
2989 while (data
< end_of_sequence
)
2991 unsigned char op_code
;
2992 dwarf_signed_vma adv
;
2994 unsigned int bytes_read
;
2996 printf (" [0x%08lx]", (long)(data
- start
));
3000 if (op_code
>= linfo
.li_opcode_base
)
3002 op_code
-= linfo
.li_opcode_base
;
3003 uladv
= (op_code
/ linfo
.li_line_range
);
3004 if (linfo
.li_max_ops_per_insn
== 1)
3006 uladv
*= linfo
.li_min_insn_length
;
3007 state_machine_regs
.address
+= uladv
;
3008 printf (_(" Special opcode %d: "
3009 "advance Address by %s to 0x%s"),
3010 op_code
, dwarf_vmatoa ("u", uladv
),
3011 dwarf_vmatoa ("x", state_machine_regs
.address
));
3015 state_machine_regs
.address
3016 += ((state_machine_regs
.op_index
+ uladv
)
3017 / linfo
.li_max_ops_per_insn
)
3018 * linfo
.li_min_insn_length
;
3019 state_machine_regs
.op_index
3020 = (state_machine_regs
.op_index
+ uladv
)
3021 % linfo
.li_max_ops_per_insn
;
3022 printf (_(" Special opcode %d: "
3023 "advance Address by %s to 0x%s[%d]"),
3024 op_code
, dwarf_vmatoa ("u", uladv
),
3025 dwarf_vmatoa ("x", state_machine_regs
.address
),
3026 state_machine_regs
.op_index
);
3028 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3029 state_machine_regs
.line
+= adv
;
3030 printf (_(" and Line by %s to %d\n"),
3031 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
3033 else switch (op_code
)
3035 case DW_LNS_extended_op
:
3036 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
3040 printf (_(" Copy\n"));
3043 case DW_LNS_advance_pc
:
3044 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3046 if (linfo
.li_max_ops_per_insn
== 1)
3048 uladv
*= linfo
.li_min_insn_length
;
3049 state_machine_regs
.address
+= uladv
;
3050 printf (_(" Advance PC by %s to 0x%s\n"),
3051 dwarf_vmatoa ("u", uladv
),
3052 dwarf_vmatoa ("x", state_machine_regs
.address
));
3056 state_machine_regs
.address
3057 += ((state_machine_regs
.op_index
+ uladv
)
3058 / linfo
.li_max_ops_per_insn
)
3059 * linfo
.li_min_insn_length
;
3060 state_machine_regs
.op_index
3061 = (state_machine_regs
.op_index
+ uladv
)
3062 % linfo
.li_max_ops_per_insn
;
3063 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3064 dwarf_vmatoa ("u", uladv
),
3065 dwarf_vmatoa ("x", state_machine_regs
.address
),
3066 state_machine_regs
.op_index
);
3070 case DW_LNS_advance_line
:
3071 adv
= read_sleb128 (data
, & bytes_read
, end
);
3073 state_machine_regs
.line
+= adv
;
3074 printf (_(" Advance Line by %s to %d\n"),
3075 dwarf_vmatoa ("d", adv
),
3076 state_machine_regs
.line
);
3079 case DW_LNS_set_file
:
3080 adv
= read_uleb128 (data
, & bytes_read
, end
);
3082 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3083 dwarf_vmatoa ("d", adv
));
3084 state_machine_regs
.file
= adv
;
3087 case DW_LNS_set_column
:
3088 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3090 printf (_(" Set column to %s\n"),
3091 dwarf_vmatoa ("u", uladv
));
3092 state_machine_regs
.column
= uladv
;
3095 case DW_LNS_negate_stmt
:
3096 adv
= state_machine_regs
.is_stmt
;
3098 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
3099 state_machine_regs
.is_stmt
= adv
;
3102 case DW_LNS_set_basic_block
:
3103 printf (_(" Set basic block\n"));
3104 state_machine_regs
.basic_block
= 1;
3107 case DW_LNS_const_add_pc
:
3108 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3109 if (linfo
.li_max_ops_per_insn
)
3111 uladv
*= linfo
.li_min_insn_length
;
3112 state_machine_regs
.address
+= uladv
;
3113 printf (_(" Advance PC by constant %s to 0x%s\n"),
3114 dwarf_vmatoa ("u", uladv
),
3115 dwarf_vmatoa ("x", state_machine_regs
.address
));
3119 state_machine_regs
.address
3120 += ((state_machine_regs
.op_index
+ uladv
)
3121 / linfo
.li_max_ops_per_insn
)
3122 * linfo
.li_min_insn_length
;
3123 state_machine_regs
.op_index
3124 = (state_machine_regs
.op_index
+ uladv
)
3125 % linfo
.li_max_ops_per_insn
;
3126 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3127 dwarf_vmatoa ("u", uladv
),
3128 dwarf_vmatoa ("x", state_machine_regs
.address
),
3129 state_machine_regs
.op_index
);
3133 case DW_LNS_fixed_advance_pc
:
3134 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3135 state_machine_regs
.address
+= uladv
;
3136 state_machine_regs
.op_index
= 0;
3137 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3138 dwarf_vmatoa ("u", uladv
),
3139 dwarf_vmatoa ("x", state_machine_regs
.address
));
3142 case DW_LNS_set_prologue_end
:
3143 printf (_(" Set prologue_end to true\n"));
3146 case DW_LNS_set_epilogue_begin
:
3147 printf (_(" Set epilogue_begin to true\n"));
3150 case DW_LNS_set_isa
:
3151 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3153 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
3157 printf (_(" Unknown opcode %d with operands: "), op_code
);
3159 if (standard_opcodes
!= NULL
)
3160 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3162 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3164 i
== 1 ? "" : ", ");
3180 unsigned char *name
;
3181 unsigned int directory_index
;
3182 unsigned int modification_date
;
3183 unsigned int length
;
3186 /* Output a decoded representation of the .debug_line section. */
3189 display_debug_lines_decoded (struct dwarf_section
*section
,
3190 unsigned char *data
,
3193 static DWARF2_Internal_LineInfo saved_linfo
;
3195 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3200 /* This loop amounts to one iteration per compilation unit. */
3201 DWARF2_Internal_LineInfo linfo
;
3202 unsigned char *standard_opcodes
;
3203 unsigned char *end_of_sequence
;
3205 File_Entry
*file_table
= NULL
;
3206 unsigned int n_files
= 0;
3207 unsigned char **directory_table
= NULL
;
3208 unsigned int n_directories
= 0;
3210 if (const_strneq (section
->name
, ".debug_line.")
3211 /* Note: the following does not apply to .debug_line.dwo sections.
3212 These are full debug_line sections. */
3213 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3215 /* See comment in display_debug_lines_raw(). */
3216 end_of_sequence
= end
;
3217 standard_opcodes
= NULL
;
3218 linfo
= saved_linfo
;
3219 /* PR 17531: file: 0522b371. */
3220 if (linfo
.li_line_range
== 0)
3222 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3225 reset_state_machine (linfo
.li_default_is_stmt
);
3229 unsigned char *hdrptr
;
3231 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3232 & end_of_sequence
)) == NULL
)
3235 /* PR 17531: file: 0522b371. */
3236 if (linfo
.li_line_range
== 0)
3238 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3239 linfo
.li_line_range
= 1;
3241 reset_state_machine (linfo
.li_default_is_stmt
);
3243 /* Save a pointer to the contents of the Opcodes table. */
3244 standard_opcodes
= hdrptr
;
3246 /* Traverse the Directory table just to count entries. */
3247 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3250 unsigned char *ptr_directory_table
= data
;
3254 data
+= strnlen ((char *) data
, end
- data
) + 1;
3258 /* Go through the directory table again to save the directories. */
3259 directory_table
= (unsigned char **)
3260 xmalloc (n_directories
* sizeof (unsigned char *));
3263 while (*ptr_directory_table
!= 0)
3265 directory_table
[i
] = ptr_directory_table
;
3266 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
3267 ptr_directory_table
- end
) + 1;
3271 /* Skip the NUL at the end of the table. */
3274 /* Traverse the File Name table just to count the entries. */
3277 unsigned char *ptr_file_name_table
= data
;
3281 unsigned int bytes_read
;
3283 /* Skip Name, directory index, last modification time and length
3285 data
+= strnlen ((char *) data
, end
- data
) + 1;
3286 read_uleb128 (data
, & bytes_read
, end
);
3288 read_uleb128 (data
, & bytes_read
, end
);
3290 read_uleb128 (data
, & bytes_read
, end
);
3296 /* Go through the file table again to save the strings. */
3297 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
3300 while (*ptr_file_name_table
!= 0)
3302 unsigned int bytes_read
;
3304 file_table
[i
].name
= ptr_file_name_table
;
3305 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
3306 end
- ptr_file_name_table
) + 1;
3308 /* We are not interested in directory, time or size. */
3309 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
3311 ptr_file_name_table
+= bytes_read
;
3312 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
3314 ptr_file_name_table
+= bytes_read
;
3315 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
3316 ptr_file_name_table
+= bytes_read
;
3321 /* Print the Compilation Unit's name and a header. */
3322 if (directory_table
== NULL
)
3324 printf (_("CU: %s:\n"), file_table
[0].name
);
3325 printf (_("File name Line number Starting address\n"));
3329 unsigned int ix
= file_table
[0].directory_index
;
3330 const char *directory
= ix
? (char *)directory_table
[ix
- 1] : ".";
3332 if (do_wide
|| strlen (directory
) < 76)
3333 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
3335 printf ("%s:\n", file_table
[0].name
);
3337 printf (_("File name Line number Starting address\n"));
3341 /* Skip the NUL at the end of the table. */
3344 saved_linfo
= linfo
;
3347 /* This loop iterates through the Dwarf Line Number Program. */
3348 while (data
< end_of_sequence
)
3350 unsigned char op_code
;
3352 unsigned long int uladv
;
3353 unsigned int bytes_read
;
3354 int is_special_opcode
= 0;
3358 if (op_code
>= linfo
.li_opcode_base
)
3360 op_code
-= linfo
.li_opcode_base
;
3361 uladv
= (op_code
/ linfo
.li_line_range
);
3362 if (linfo
.li_max_ops_per_insn
== 1)
3364 uladv
*= linfo
.li_min_insn_length
;
3365 state_machine_regs
.address
+= uladv
;
3369 state_machine_regs
.address
3370 += ((state_machine_regs
.op_index
+ uladv
)
3371 / linfo
.li_max_ops_per_insn
)
3372 * linfo
.li_min_insn_length
;
3373 state_machine_regs
.op_index
3374 = (state_machine_regs
.op_index
+ uladv
)
3375 % linfo
.li_max_ops_per_insn
;
3378 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3379 state_machine_regs
.line
+= adv
;
3380 is_special_opcode
= 1;
3382 else switch (op_code
)
3384 case DW_LNS_extended_op
:
3386 unsigned int ext_op_code_len
;
3387 unsigned char ext_op_code
;
3388 unsigned char *op_code_data
= data
;
3390 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
3392 op_code_data
+= bytes_read
;
3394 if (ext_op_code_len
== 0)
3396 warn (_("Badly formed extended line op encountered!\n"));
3399 ext_op_code_len
+= bytes_read
;
3400 ext_op_code
= *op_code_data
++;
3402 switch (ext_op_code
)
3404 case DW_LNE_end_sequence
:
3405 reset_state_machine (linfo
.li_default_is_stmt
);
3407 case DW_LNE_set_address
:
3408 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
3410 ext_op_code_len
- bytes_read
- 1,
3412 state_machine_regs
.op_index
= 0;
3414 case DW_LNE_define_file
:
3416 file_table
= (File_Entry
*) xrealloc
3417 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
3419 ++state_machine_regs
.last_file_entry
;
3420 /* Source file name. */
3421 file_table
[n_files
].name
= op_code_data
;
3422 op_code_data
+= strlen ((char *) op_code_data
) + 1;
3423 /* Directory index. */
3424 file_table
[n_files
].directory_index
=
3425 read_uleb128 (op_code_data
, & bytes_read
,
3427 op_code_data
+= bytes_read
;
3428 /* Last modification time. */
3429 file_table
[n_files
].modification_date
=
3430 read_uleb128 (op_code_data
, & bytes_read
,
3432 op_code_data
+= bytes_read
;
3434 file_table
[n_files
].length
=
3435 read_uleb128 (op_code_data
, & bytes_read
,
3441 case DW_LNE_set_discriminator
:
3442 case DW_LNE_HP_set_sequence
:
3443 /* Simply ignored. */
3447 printf (_("UNKNOWN (%u): length %d\n"),
3448 ext_op_code
, ext_op_code_len
- bytes_read
);
3451 data
+= ext_op_code_len
;
3457 case DW_LNS_advance_pc
:
3458 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3460 if (linfo
.li_max_ops_per_insn
== 1)
3462 uladv
*= linfo
.li_min_insn_length
;
3463 state_machine_regs
.address
+= uladv
;
3467 state_machine_regs
.address
3468 += ((state_machine_regs
.op_index
+ uladv
)
3469 / linfo
.li_max_ops_per_insn
)
3470 * linfo
.li_min_insn_length
;
3471 state_machine_regs
.op_index
3472 = (state_machine_regs
.op_index
+ uladv
)
3473 % linfo
.li_max_ops_per_insn
;
3477 case DW_LNS_advance_line
:
3478 adv
= read_sleb128 (data
, & bytes_read
, end
);
3480 state_machine_regs
.line
+= adv
;
3483 case DW_LNS_set_file
:
3484 adv
= read_uleb128 (data
, & bytes_read
, end
);
3486 state_machine_regs
.file
= adv
;
3488 if (file_table
== NULL
)
3489 printf (_("\n [Use file table entry %d]\n"), state_machine_regs
.file
- 1);
3490 else if (file_table
[state_machine_regs
.file
- 1].directory_index
== 0)
3491 /* If directory index is 0, that means current directory. */
3492 printf ("\n./%s:[++]\n",
3493 file_table
[state_machine_regs
.file
- 1].name
);
3494 else if (directory_table
== NULL
)
3495 printf (_("\n [Use directory table entry %d]\n"),
3496 file_table
[state_machine_regs
.file
- 1].directory_index
- 1);
3498 /* The directory index starts counting at 1. */
3499 printf ("\n%s/%s:\n",
3500 directory_table
[file_table
[state_machine_regs
.file
- 1].directory_index
- 1],
3501 file_table
[state_machine_regs
.file
- 1].name
);
3504 case DW_LNS_set_column
:
3505 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3507 state_machine_regs
.column
= uladv
;
3510 case DW_LNS_negate_stmt
:
3511 adv
= state_machine_regs
.is_stmt
;
3513 state_machine_regs
.is_stmt
= adv
;
3516 case DW_LNS_set_basic_block
:
3517 state_machine_regs
.basic_block
= 1;
3520 case DW_LNS_const_add_pc
:
3521 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3522 if (linfo
.li_max_ops_per_insn
== 1)
3524 uladv
*= linfo
.li_min_insn_length
;
3525 state_machine_regs
.address
+= uladv
;
3529 state_machine_regs
.address
3530 += ((state_machine_regs
.op_index
+ uladv
)
3531 / linfo
.li_max_ops_per_insn
)
3532 * linfo
.li_min_insn_length
;
3533 state_machine_regs
.op_index
3534 = (state_machine_regs
.op_index
+ uladv
)
3535 % linfo
.li_max_ops_per_insn
;
3539 case DW_LNS_fixed_advance_pc
:
3540 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3541 state_machine_regs
.address
+= uladv
;
3542 state_machine_regs
.op_index
= 0;
3545 case DW_LNS_set_prologue_end
:
3548 case DW_LNS_set_epilogue_begin
:
3551 case DW_LNS_set_isa
:
3552 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3554 printf (_(" Set ISA to %lu\n"), uladv
);
3558 printf (_(" Unknown opcode %d with operands: "), op_code
);
3560 if (standard_opcodes
!= NULL
)
3561 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3563 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3565 i
== 1 ? "" : ", ");
3572 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3573 to the DWARF address/line matrix. */
3574 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3575 || (op_code
== DW_LNS_copy
))
3577 const unsigned int MAX_FILENAME_LENGTH
= 35;
3579 char *newFileName
= NULL
;
3580 size_t fileNameLength
;
3583 fileName
= (char *) file_table
[state_machine_regs
.file
- 1].name
;
3585 fileName
= "<unknown>";
3587 fileNameLength
= strlen (fileName
);
3589 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3591 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3592 /* Truncate file name */
3593 strncpy (newFileName
,
3594 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3595 MAX_FILENAME_LENGTH
+ 1);
3599 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3600 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3603 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3605 if (linfo
.li_max_ops_per_insn
== 1)
3606 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3607 newFileName
, state_machine_regs
.line
,
3608 state_machine_regs
.address
);
3610 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3611 newFileName
, state_machine_regs
.line
,
3612 state_machine_regs
.address
,
3613 state_machine_regs
.op_index
);
3617 if (linfo
.li_max_ops_per_insn
== 1)
3618 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3619 newFileName
, state_machine_regs
.line
,
3620 state_machine_regs
.address
);
3622 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3623 newFileName
, state_machine_regs
.line
,
3624 state_machine_regs
.address
,
3625 state_machine_regs
.op_index
);
3628 if (op_code
== DW_LNE_end_sequence
)
3642 if (directory_table
)
3644 free (directory_table
);
3645 directory_table
= NULL
;
3656 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3658 unsigned char *data
= section
->start
;
3659 unsigned char *end
= data
+ section
->size
;
3661 int retValDecoded
= 1;
3663 if (do_debug_lines
== 0)
3664 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3666 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3667 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3669 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3670 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3672 if (!retValRaw
|| !retValDecoded
)
3679 find_debug_info_for_offset (unsigned long offset
)
3683 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3686 for (i
= 0; i
< num_debug_info_entries
; i
++)
3687 if (debug_information
[i
].cu_offset
== offset
)
3688 return debug_information
+ i
;
3694 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
3696 /* See gdb/gdb-index.h. */
3697 static const char * const kinds
[] =
3709 return _ (kinds
[kind
]);
3713 display_debug_pubnames_worker (struct dwarf_section
*section
,
3714 void *file ATTRIBUTE_UNUSED
,
3717 DWARF2_Internal_PubNames names
;
3718 unsigned char *start
= section
->start
;
3719 unsigned char *end
= start
+ section
->size
;
3721 /* It does not matter if this load fails,
3722 we test for that later on. */
3723 load_debug_info (file
);
3725 printf (_("Contents of the %s section:\n\n"), section
->name
);
3729 unsigned char *data
;
3732 unsigned int offset_size
, initial_length_size
;
3736 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 4, end
);
3737 if (names
.pn_length
== 0xffffffff)
3739 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 8, end
);
3741 initial_length_size
= 12;
3746 initial_length_size
= 4;
3749 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
3750 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
3752 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3753 && num_debug_info_entries
> 0
3754 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3755 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3756 (unsigned long) names
.pn_offset
, section
->name
);
3758 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
3760 adr
= start
+ names
.pn_length
+ initial_length_size
;
3761 /* PR 17531: file: 7615b6b2. */
3762 if ((dwarf_signed_vma
) names
.pn_length
< 0
3763 /* PR 17531: file: a5dbeaa7. */
3766 warn (_("Negative length for public name: 0x%lx\n"), (long) names
.pn_length
);
3772 printf (_(" Length: %ld\n"),
3773 (long) names
.pn_length
);
3774 printf (_(" Version: %d\n"),
3776 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3777 (unsigned long) names
.pn_offset
);
3778 printf (_(" Size of area in .debug_info section: %ld\n"),
3779 (long) names
.pn_size
);
3781 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3783 static int warned
= 0;
3787 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3795 printf (_("\n Offset Kind Name\n"));
3797 printf (_("\n Offset\tName\n"));
3801 bfd_size_type maxprint
;
3803 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
3807 data
+= offset_size
;
3810 maxprint
= (end
- data
) - 1;
3814 unsigned int kind_data
;
3815 gdb_index_symbol_kind kind
;
3816 const char *kind_name
;
3819 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
3822 /* GCC computes the kind as the upper byte in the CU index
3823 word, and then right shifts it by the CU index size.
3824 Left shift KIND to where the gdb-index.h accessor macros
3826 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
3827 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
3828 kind_name
= get_gdb_index_symbol_kind_name (kind
);
3829 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
3830 printf (" %-6lx %s,%-10s %.*s\n",
3831 (unsigned long) offset
, is_static
? _("s") : _("g"),
3832 kind_name
, (int) maxprint
, data
);
3835 printf (" %-6lx\t%.*s\n",
3836 (unsigned long) offset
, (int) maxprint
, data
);
3838 data
+= strnlen ((char *) data
, maxprint
) + 1;
3843 while (offset
!= 0);
3851 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
3853 return display_debug_pubnames_worker (section
, file
, 0);
3857 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
3859 return display_debug_pubnames_worker (section
, file
, 1);
3863 display_debug_macinfo (struct dwarf_section
*section
,
3864 void *file ATTRIBUTE_UNUSED
)
3866 unsigned char *start
= section
->start
;
3867 unsigned char *end
= start
+ section
->size
;
3868 unsigned char *curr
= start
;
3869 unsigned int bytes_read
;
3870 enum dwarf_macinfo_record_type op
;
3872 printf (_("Contents of the %s section:\n\n"), section
->name
);
3876 unsigned int lineno
;
3877 const unsigned char *string
;
3879 op
= (enum dwarf_macinfo_record_type
) *curr
;
3884 case DW_MACINFO_start_file
:
3886 unsigned int filenum
;
3888 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3890 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
3893 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3898 case DW_MACINFO_end_file
:
3899 printf (_(" DW_MACINFO_end_file\n"));
3902 case DW_MACINFO_define
:
3903 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3906 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3907 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3911 case DW_MACINFO_undef
:
3912 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3915 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3916 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3920 case DW_MACINFO_vendor_ext
:
3922 unsigned int constant
;
3924 constant
= read_uleb128 (curr
, & bytes_read
, end
);
3927 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3928 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3938 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3939 filename and dirname corresponding to file name table entry with index
3940 FILEIDX. Return NULL on failure. */
3942 static unsigned char *
3943 get_line_filename_and_dirname (dwarf_vma line_offset
,
3945 unsigned char **dir_name
)
3947 struct dwarf_section
*section
= &debug_displays
[line
].section
;
3948 unsigned char *hdrptr
, *dirtable
, *file_name
;
3949 unsigned int offset_size
, initial_length_size
;
3950 unsigned int version
, opcode_base
, bytes_read
;
3951 dwarf_vma length
, diridx
;
3952 const unsigned char * end
;
3955 if (section
->start
== NULL
3956 || line_offset
>= section
->size
3960 hdrptr
= section
->start
+ line_offset
;
3961 end
= section
->start
+ section
->size
;
3963 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
3964 if (length
== 0xffffffff)
3966 /* This section is 64-bit DWARF 3. */
3967 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
3969 initial_length_size
= 12;
3974 initial_length_size
= 4;
3976 if (length
+ initial_length_size
> section
->size
)
3979 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
3980 if (version
!= 2 && version
!= 3 && version
!= 4)
3982 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
3984 hdrptr
++; /* Skip max_ops_per_insn. */
3985 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
3987 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
3988 if (opcode_base
== 0)
3991 hdrptr
+= opcode_base
- 1;
3993 /* Skip over dirname table. */
3994 while (*hdrptr
!= '\0')
3995 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
3996 hdrptr
++; /* Skip the NUL at the end of the table. */
3997 /* Now skip over preceding filename table entries. */
3998 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
4000 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4001 read_uleb128 (hdrptr
, &bytes_read
, end
);
4002 hdrptr
+= bytes_read
;
4003 read_uleb128 (hdrptr
, &bytes_read
, end
);
4004 hdrptr
+= bytes_read
;
4005 read_uleb128 (hdrptr
, &bytes_read
, end
);
4006 hdrptr
+= bytes_read
;
4008 if (hdrptr
== end
|| *hdrptr
== '\0')
4011 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4012 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
4015 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
4016 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
4017 if (*dirtable
== '\0')
4019 *dir_name
= dirtable
;
4024 display_debug_macro (struct dwarf_section
*section
,
4027 unsigned char *start
= section
->start
;
4028 unsigned char *end
= start
+ section
->size
;
4029 unsigned char *curr
= start
;
4030 unsigned char *extended_op_buf
[256];
4031 unsigned int bytes_read
;
4033 load_debug_section (str
, file
);
4034 load_debug_section (line
, file
);
4036 printf (_("Contents of the %s section:\n\n"), section
->name
);
4040 unsigned int lineno
, version
, flags
;
4041 unsigned int offset_size
= 4;
4042 const unsigned char *string
;
4043 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
4044 unsigned char **extended_ops
= NULL
;
4046 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
4049 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
4054 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
4057 printf (_(" Offset: 0x%lx\n"),
4058 (unsigned long) sec_offset
);
4059 printf (_(" Version: %d\n"), version
);
4060 printf (_(" Offset size: %d\n"), offset_size
);
4063 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
4064 printf (_(" Offset into .debug_line: 0x%lx\n"),
4065 (unsigned long) line_offset
);
4069 unsigned int i
, count
, op
;
4072 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
4074 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
4075 extended_ops
= extended_op_buf
;
4078 printf (_(" Extension opcode arguments:\n"));
4079 for (i
= 0; i
< count
; i
++)
4081 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4082 extended_ops
[op
] = curr
;
4083 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
4086 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op
);
4089 printf (_(" DW_MACRO_GNU_%02x arguments: "), op
);
4090 for (n
= 0; n
< nargs
; n
++)
4094 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
4095 printf ("%s%s", get_FORM_name (form
),
4096 n
== nargs
- 1 ? "\n" : ", ");
4106 case DW_FORM_block1
:
4107 case DW_FORM_block2
:
4108 case DW_FORM_block4
:
4110 case DW_FORM_string
:
4112 case DW_FORM_sec_offset
:
4115 error (_("Invalid extension opcode form %s\n"),
4116 get_FORM_name (form
));
4132 error (_(".debug_macro section not zero terminated\n"));
4136 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4142 case DW_MACRO_GNU_start_file
:
4144 unsigned int filenum
;
4145 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
4147 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4149 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
4152 if ((flags
& 2) == 0)
4153 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
4156 = get_line_filename_and_dirname (line_offset
, filenum
,
4158 if (file_name
== NULL
)
4159 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
4162 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4164 dir_name
!= NULL
? (const char *) dir_name
: "",
4165 dir_name
!= NULL
? "/" : "", file_name
);
4169 case DW_MACRO_GNU_end_file
:
4170 printf (_(" DW_MACRO_GNU_end_file\n"));
4173 case DW_MACRO_GNU_define
:
4174 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4177 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4178 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
4182 case DW_MACRO_GNU_undef
:
4183 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4186 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4187 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
4191 case DW_MACRO_GNU_define_indirect
:
4192 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4194 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4195 string
= fetch_indirect_string (offset
);
4196 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
4200 case DW_MACRO_GNU_undef_indirect
:
4201 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4203 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4204 string
= fetch_indirect_string (offset
);
4205 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4209 case DW_MACRO_GNU_transparent_include
:
4210 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4211 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4212 (unsigned long) offset
);
4215 case DW_MACRO_GNU_define_indirect_alt
:
4216 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4218 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4219 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4220 lineno
, (unsigned long) offset
);
4223 case DW_MACRO_GNU_undef_indirect_alt
:
4224 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4226 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4227 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4228 lineno
, (unsigned long) offset
);
4231 case DW_MACRO_GNU_transparent_include_alt
:
4232 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4233 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4234 (unsigned long) offset
);
4238 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
4240 error (_(" Unknown macro opcode %02x seen\n"), op
);
4245 /* Skip over unhandled opcodes. */
4247 unsigned char *desc
= extended_ops
[op
];
4248 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
4252 printf (_(" DW_MACRO_GNU_%02x\n"), op
);
4255 printf (_(" DW_MACRO_GNU_%02x -"), op
);
4256 for (n
= 0; n
< nargs
; n
++)
4260 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
4262 = read_and_display_attr_value (0, val
,
4263 curr
, end
, 0, 0, offset_size
,
4264 version
, NULL
, 0, NULL
,
4282 display_debug_abbrev (struct dwarf_section
*section
,
4283 void *file ATTRIBUTE_UNUSED
)
4285 abbrev_entry
*entry
;
4286 unsigned char *start
= section
->start
;
4287 unsigned char *end
= start
+ section
->size
;
4289 printf (_("Contents of the %s section:\n\n"), section
->name
);
4293 unsigned char *last
;
4298 start
= process_abbrev_section (start
, end
);
4300 if (first_abbrev
== NULL
)
4303 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
4305 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4309 printf (" %ld %s [%s]\n",
4311 get_TAG_name (entry
->tag
),
4312 entry
->children
? _("has children") : _("no children"));
4314 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4315 printf (" %-18s %s\n",
4316 get_AT_name (attr
->attribute
),
4317 get_FORM_name (attr
->form
));
4327 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4330 display_loc_list (struct dwarf_section
*section
,
4331 unsigned char **start_ptr
,
4332 unsigned int debug_info_entry
,
4333 unsigned long offset
,
4334 unsigned long base_address
,
4337 unsigned char *start
= *start_ptr
;
4338 unsigned char *section_end
= section
->start
+ section
->size
;
4339 unsigned long cu_offset
;
4340 unsigned int pointer_size
;
4341 unsigned int offset_size
;
4346 unsigned short length
;
4347 int need_frame_base
;
4349 if (debug_info_entry
>= num_debug_info_entries
)
4351 warn (_("No debug information available for loc lists of entry: %u\n"),
4356 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4357 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4358 offset_size
= debug_information
[debug_info_entry
].offset_size
;
4359 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4361 if (pointer_size
< 2 || pointer_size
> 8)
4363 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4364 pointer_size
, debug_info_entry
);
4370 unsigned long off
= offset
+ (start
- *start_ptr
);
4372 if (start
+ 2 * pointer_size
> section_end
)
4374 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4379 printf (" %8.8lx ", off
);
4381 /* Note: we use sign extension here in order to be sure that we can detect
4382 the -1 escape value. Sign extension into the top 32 bits of a 32-bit
4383 address will not affect the values that we display since we always show
4384 hex values, and always the bottom 32-bits. */
4385 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
4386 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
4388 if (begin
== 0 && end
== 0)
4390 /* PR 18374: In a object file we can have a location list that
4391 starts with a begin and end of 0 because there are relocations
4392 that need to be applied to the addresses. Actually applying
4393 the relocations now does not help as they will probably resolve
4394 to 0, since the object file has not been fully linked. Real
4395 end of list markers will not have any relocations against them. */
4396 if (! reloc_at (section
, off
)
4397 && ! reloc_at (section
, off
+ pointer_size
))
4399 printf (_("<End of list>\n"));
4404 /* Check base address specifiers. */
4405 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
4408 print_dwarf_vma (begin
, pointer_size
);
4409 print_dwarf_vma (end
, pointer_size
);
4410 printf (_("(base address)\n"));
4414 if (start
+ 2 > section_end
)
4416 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4421 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4423 if (start
+ length
> section_end
)
4425 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4430 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4431 print_dwarf_vma (end
+ base_address
, pointer_size
);
4434 need_frame_base
= decode_location_expression (start
,
4439 cu_offset
, section
);
4442 if (need_frame_base
&& !has_frame_base
)
4443 printf (_(" [without DW_AT_frame_base]"));
4446 fputs (_(" (start == end)"), stdout
);
4447 else if (begin
> end
)
4448 fputs (_(" (start > end)"), stdout
);
4458 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4459 right-adjusted in a field of length LEN, and followed by a space. */
4462 print_addr_index (unsigned int idx
, unsigned int len
)
4464 static char buf
[15];
4465 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
4466 printf ("%*s ", len
, buf
);
4469 /* Display a location list from a .dwo section. It uses address indexes rather
4470 than embedded addresses. This code closely follows display_loc_list, but the
4471 two are sufficiently different that combining things is very ugly. */
4474 display_loc_list_dwo (struct dwarf_section
*section
,
4475 unsigned char **start_ptr
,
4476 unsigned int debug_info_entry
,
4477 unsigned long offset
,
4480 unsigned char *start
= *start_ptr
;
4481 unsigned char *section_end
= section
->start
+ section
->size
;
4482 unsigned long cu_offset
;
4483 unsigned int pointer_size
;
4484 unsigned int offset_size
;
4487 unsigned short length
;
4488 int need_frame_base
;
4490 unsigned int bytes_read
;
4492 if (debug_info_entry
>= num_debug_info_entries
)
4494 warn (_("No debug information for loc lists of entry: %u\n"),
4499 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4500 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4501 offset_size
= debug_information
[debug_info_entry
].offset_size
;
4502 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4504 if (pointer_size
< 2 || pointer_size
> 8)
4506 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4507 pointer_size
, debug_info_entry
);
4513 printf (" %8.8lx ", offset
+ (start
- *start_ptr
));
4515 if (start
>= section_end
)
4517 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4522 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
4525 case 0: /* A terminating entry. */
4527 printf (_("<End of list>\n"));
4529 case 1: /* A base-address entry. */
4530 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4531 start
+= bytes_read
;
4532 print_addr_index (idx
, 8);
4534 printf (_("(base address selection entry)\n"));
4536 case 2: /* A start/end entry. */
4537 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4538 start
+= bytes_read
;
4539 print_addr_index (idx
, 8);
4540 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4541 start
+= bytes_read
;
4542 print_addr_index (idx
, 8);
4544 case 3: /* A start/length entry. */
4545 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4546 start
+= bytes_read
;
4547 print_addr_index (idx
, 8);
4548 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4549 printf ("%08x ", idx
);
4551 case 4: /* An offset pair entry. */
4552 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4553 printf ("%08x ", idx
);
4554 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4555 printf ("%08x ", idx
);
4558 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
4563 if (start
+ 2 > section_end
)
4565 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4570 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4571 if (start
+ length
> section_end
)
4573 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4579 need_frame_base
= decode_location_expression (start
,
4584 cu_offset
, section
);
4587 if (need_frame_base
&& !has_frame_base
)
4588 printf (_(" [without DW_AT_frame_base]"));
4598 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4600 static dwarf_vma
*loc_offsets
;
4603 loc_offsets_compar (const void *ap
, const void *bp
)
4605 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
4606 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
4608 return (a
> b
) - (b
> a
);
4612 display_debug_loc (struct dwarf_section
*section
, void *file
)
4614 unsigned char *start
= section
->start
;
4615 unsigned long bytes
;
4616 unsigned char *section_begin
= start
;
4617 unsigned int num_loc_list
= 0;
4618 unsigned long last_offset
= 0;
4619 unsigned int first
= 0;
4622 int seen_first_offset
= 0;
4623 int locs_sorted
= 1;
4624 unsigned char *next
;
4625 unsigned int *array
= NULL
;
4626 const char *suffix
= strrchr (section
->name
, '.');
4629 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
4632 bytes
= section
->size
;
4636 printf (_("\nThe %s section is empty.\n"), section
->name
);
4640 if (load_debug_info (file
) == 0)
4642 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4647 /* Check the order of location list in .debug_info section. If
4648 offsets of location lists are in the ascending order, we can
4649 use `debug_information' directly. */
4650 for (i
= 0; i
< num_debug_info_entries
; i
++)
4654 num
= debug_information
[i
].num_loc_offsets
;
4655 if (num
> num_loc_list
)
4658 /* Check if we can use `debug_information' directly. */
4659 if (locs_sorted
&& num
!= 0)
4661 if (!seen_first_offset
)
4663 /* This is the first location list. */
4664 last_offset
= debug_information
[i
].loc_offsets
[0];
4666 seen_first_offset
= 1;
4672 for (; j
< num
; j
++)
4675 debug_information
[i
].loc_offsets
[j
])
4680 last_offset
= debug_information
[i
].loc_offsets
[j
];
4685 if (!seen_first_offset
)
4686 error (_("No location lists in .debug_info section!\n"));
4688 if (debug_information
[first
].num_loc_offsets
> 0
4689 && debug_information
[first
].loc_offsets
[0] != 0)
4690 warn (_("Location lists in %s section start at 0x%s\n"),
4692 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
4695 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
4696 printf (_("Contents of the %s section:\n\n"), section
->name
);
4697 if (reloc_at (section
, 0))
4698 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
4699 printf (_(" Offset Begin End Expression\n"));
4701 seen_first_offset
= 0;
4702 for (i
= first
; i
< num_debug_info_entries
; i
++)
4704 unsigned long offset
;
4705 unsigned long base_address
;
4711 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4713 loc_offsets
= debug_information
[i
].loc_offsets
;
4714 qsort (array
, debug_information
[i
].num_loc_offsets
,
4715 sizeof (*array
), loc_offsets_compar
);
4718 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4720 j
= locs_sorted
? k
: array
[k
];
4722 && debug_information
[i
].loc_offsets
[locs_sorted
4723 ? k
- 1 : array
[k
- 1]]
4724 == debug_information
[i
].loc_offsets
[j
])
4726 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
4727 offset
= debug_information
[i
].loc_offsets
[j
];
4728 next
= section_begin
+ offset
;
4729 base_address
= debug_information
[i
].base_address
;
4731 if (!seen_first_offset
)
4732 seen_first_offset
= 1;
4736 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4737 (unsigned long) (start
- section_begin
),
4738 (unsigned long) offset
);
4739 else if (start
> next
)
4740 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4741 (unsigned long) (start
- section_begin
),
4742 (unsigned long) offset
);
4746 if (offset
>= bytes
)
4748 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4754 display_loc_list_dwo (section
, &start
, i
, offset
, has_frame_base
);
4756 display_loc_list (section
, &start
, i
, offset
, base_address
,
4761 if (start
< section
->start
+ section
->size
)
4762 warn (_("There are %ld unused bytes at the end of section %s\n"),
4763 (long) (section
->start
+ section
->size
- start
), section
->name
);
4770 display_debug_str (struct dwarf_section
*section
,
4771 void *file ATTRIBUTE_UNUSED
)
4773 unsigned char *start
= section
->start
;
4774 unsigned long bytes
= section
->size
;
4775 dwarf_vma addr
= section
->address
;
4779 printf (_("\nThe %s section is empty.\n"), section
->name
);
4783 printf (_("Contents of the %s section:\n\n"), section
->name
);
4791 lbytes
= (bytes
> 16 ? 16 : bytes
);
4793 printf (" 0x%8.8lx ", (unsigned long) addr
);
4795 for (j
= 0; j
< 16; j
++)
4798 printf ("%2.2x", start
[j
]);
4806 for (j
= 0; j
< lbytes
; j
++)
4809 if (k
>= ' ' && k
< 0x80)
4828 display_debug_info (struct dwarf_section
*section
, void *file
)
4830 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4834 display_debug_types (struct dwarf_section
*section
, void *file
)
4836 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 1);
4840 display_trace_info (struct dwarf_section
*section
, void *file
)
4842 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4846 display_debug_aranges (struct dwarf_section
*section
,
4847 void *file ATTRIBUTE_UNUSED
)
4849 unsigned char *start
= section
->start
;
4850 unsigned char *end
= start
+ section
->size
;
4852 printf (_("Contents of the %s section:\n\n"), section
->name
);
4854 /* It does not matter if this load fails,
4855 we test for that later on. */
4856 load_debug_info (file
);
4860 unsigned char *hdrptr
;
4861 DWARF2_Internal_ARange arange
;
4862 unsigned char *addr_ranges
;
4865 unsigned char address_size
;
4867 unsigned int offset_size
;
4868 unsigned int initial_length_size
;
4872 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
4873 if (arange
.ar_length
== 0xffffffff)
4875 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
4877 initial_length_size
= 12;
4882 initial_length_size
= 4;
4885 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
4886 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
4888 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4889 && num_debug_info_entries
> 0
4890 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
4891 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4892 (unsigned long) arange
.ar_info_offset
, section
->name
);
4894 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
4895 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
4897 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
4899 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4903 printf (_(" Length: %ld\n"),
4904 (long) arange
.ar_length
);
4905 printf (_(" Version: %d\n"), arange
.ar_version
);
4906 printf (_(" Offset into .debug_info: 0x%lx\n"),
4907 (unsigned long) arange
.ar_info_offset
);
4908 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
4909 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
4911 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
4913 /* PR 17512: file: 001-108546-0.001:0.1. */
4914 if (address_size
== 0 || address_size
> 8)
4916 error (_("Invalid address size in %s section!\n"),
4921 /* The DWARF spec does not require that the address size be a power
4922 of two, but we do. This will have to change if we ever encounter
4923 an uneven architecture. */
4924 if ((address_size
& (address_size
- 1)) != 0)
4926 warn (_("Pointer size + Segment size is not a power of two.\n"));
4930 if (address_size
> 4)
4931 printf (_("\n Address Length\n"));
4933 printf (_("\n Address Length\n"));
4935 addr_ranges
= hdrptr
;
4937 /* Must pad to an alignment boundary that is twice the address size. */
4938 excess
= (hdrptr
- start
) % (2 * address_size
);
4940 addr_ranges
+= (2 * address_size
) - excess
;
4942 hdrptr
= start
+ arange
.ar_length
+ initial_length_size
;
4943 if (hdrptr
< start
|| hdrptr
> end
)
4945 error (_("Excessive header length: %lx\n"), (long) arange
.ar_length
);
4950 while (addr_ranges
+ 2 * address_size
<= start
)
4952 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
4953 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
4956 print_dwarf_vma (address
, address_size
);
4957 print_dwarf_vma (length
, address_size
);
4967 /* Comparison function for qsort. */
4969 comp_addr_base (const void * v0
, const void * v1
)
4971 debug_info
* info0
= (debug_info
*) v0
;
4972 debug_info
* info1
= (debug_info
*) v1
;
4973 return info0
->addr_base
- info1
->addr_base
;
4976 /* Display the debug_addr section. */
4978 display_debug_addr (struct dwarf_section
*section
,
4981 debug_info
**debug_addr_info
;
4982 unsigned char *entry
;
4987 if (section
->size
== 0)
4989 printf (_("\nThe %s section is empty.\n"), section
->name
);
4993 if (load_debug_info (file
) == 0)
4995 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5000 printf (_("Contents of the %s section:\n\n"), section
->name
);
5002 /* PR 17531: file: cf38d01b.
5003 We use xcalloc because a corrupt file may not have initialised all of the
5004 fields in the debug_info structure, which means that the sort below might
5005 try to move uninitialised data. */
5006 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
5007 sizeof (debug_info
*));
5010 for (i
= 0; i
< num_debug_info_entries
; i
++)
5011 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
5013 /* PR 17531: file: cf38d01b. */
5014 if (debug_information
[i
].addr_base
>= section
->size
)
5015 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
5016 (unsigned long) debug_information
[i
].addr_base
, i
);
5018 debug_addr_info
[count
++] = debug_information
+ i
;
5021 /* Add a sentinel to make iteration convenient. */
5022 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
5023 debug_addr_info
[count
]->addr_base
= section
->size
;
5024 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
5026 for (i
= 0; i
< count
; i
++)
5029 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
5031 printf (_(" For compilation unit at offset 0x%s:\n"),
5032 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
5034 printf (_("\tIndex\tAddress\n"));
5035 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
5036 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
5040 dwarf_vma base
= byte_get (entry
, address_size
);
5041 printf (_("\t%d:\t"), idx
);
5042 print_dwarf_vma (base
, address_size
);
5044 entry
+= address_size
;
5050 free (debug_addr_info
);
5054 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5056 display_debug_str_offsets (struct dwarf_section
*section
,
5057 void *file ATTRIBUTE_UNUSED
)
5059 if (section
->size
== 0)
5061 printf (_("\nThe %s section is empty.\n"), section
->name
);
5064 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5065 what the offset size is for this section. */
5069 /* Each debug_information[x].range_lists[y] gets this representation for
5070 sorting purposes. */
5074 /* The debug_information[x].range_lists[y] value. */
5075 unsigned long ranges_offset
;
5077 /* Original debug_information to find parameters of the data. */
5078 debug_info
*debug_info_p
;
5081 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5084 range_entry_compar (const void *ap
, const void *bp
)
5086 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
5087 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
5088 const unsigned long a
= a_re
->ranges_offset
;
5089 const unsigned long b
= b_re
->ranges_offset
;
5091 return (a
> b
) - (b
> a
);
5095 display_debug_ranges (struct dwarf_section
*section
,
5096 void *file ATTRIBUTE_UNUSED
)
5098 unsigned char *start
= section
->start
;
5099 unsigned char *last_start
= start
;
5100 unsigned long bytes
= section
->size
;
5101 unsigned char *section_begin
= start
;
5102 unsigned char *finish
= start
+ bytes
;
5103 unsigned int num_range_list
, i
;
5104 struct range_entry
*range_entries
, *range_entry_fill
;
5108 printf (_("\nThe %s section is empty.\n"), section
->name
);
5112 if (load_debug_info (file
) == 0)
5114 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5120 for (i
= 0; i
< num_debug_info_entries
; i
++)
5121 num_range_list
+= debug_information
[i
].num_range_lists
;
5123 if (num_range_list
== 0)
5125 /* This can happen when the file was compiled with -gsplit-debug
5126 which removes references to range lists from the primary .o file. */
5127 printf (_("No range lists in .debug_info section.\n"));
5131 range_entries
= (struct range_entry
*)
5132 xmalloc (sizeof (*range_entries
) * num_range_list
);
5133 range_entry_fill
= range_entries
;
5135 for (i
= 0; i
< num_debug_info_entries
; i
++)
5137 debug_info
*debug_info_p
= &debug_information
[i
];
5140 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
5142 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
5143 range_entry_fill
->debug_info_p
= debug_info_p
;
5148 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
5149 range_entry_compar
);
5151 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
5152 warn (_("Range lists in %s section start at 0x%lx\n"),
5153 section
->name
, range_entries
[0].ranges_offset
);
5155 printf (_("Contents of the %s section:\n\n"), section
->name
);
5156 printf (_(" Offset Begin End\n"));
5158 for (i
= 0; i
< num_range_list
; i
++)
5160 struct range_entry
*range_entry
= &range_entries
[i
];
5161 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
5162 unsigned int pointer_size
;
5163 unsigned long offset
;
5164 unsigned char *next
;
5165 unsigned long base_address
;
5167 pointer_size
= debug_info_p
->pointer_size
;
5168 offset
= range_entry
->ranges_offset
;
5169 next
= section_begin
+ offset
;
5170 base_address
= debug_info_p
->base_address
;
5172 /* PR 17512: file: 001-101485-0.001:0.1. */
5173 if (pointer_size
< 2 || pointer_size
> 8)
5175 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
5176 pointer_size
, offset
);
5180 if (dwarf_check
!= 0 && i
> 0)
5183 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
5184 (unsigned long) (start
- section_begin
),
5185 (unsigned long) (next
- section_begin
), section
->name
);
5186 else if (start
> next
)
5188 if (next
== last_start
)
5190 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
5191 (unsigned long) (start
- section_begin
),
5192 (unsigned long) (next
- section_begin
), section
->name
);
5198 while (start
< finish
)
5203 /* Note: we use sign extension here in order to be sure that
5204 we can detect the -1 escape value. Sign extension into the
5205 top 32 bits of a 32-bit address will not affect the values
5206 that we display since we always show hex values, and always
5207 the bottom 32-bits. */
5208 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
5209 if (start
>= finish
)
5211 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
5213 printf (" %8.8lx ", offset
);
5215 if (begin
== 0 && end
== 0)
5217 printf (_("<End of list>\n"));
5221 /* Check base address specifiers. */
5222 if (begin
== (dwarf_vma
) -1 && end
!= (dwarf_vma
) -1)
5225 print_dwarf_vma (begin
, pointer_size
);
5226 print_dwarf_vma (end
, pointer_size
);
5227 printf ("(base address)\n");
5231 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5232 print_dwarf_vma (end
+ base_address
, pointer_size
);
5235 fputs (_("(start == end)"), stdout
);
5236 else if (begin
> end
)
5237 fputs (_("(start > end)"), stdout
);
5244 free (range_entries
);
5249 typedef struct Frame_Chunk
5251 struct Frame_Chunk
*next
;
5252 unsigned char *chunk_start
;
5254 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
5255 short int *col_type
;
5258 unsigned int code_factor
;
5263 dwarf_vma cfa_offset
;
5265 unsigned char fde_encoding
;
5266 unsigned char cfa_exp
;
5267 unsigned char ptr_size
;
5268 unsigned char segment_size
;
5272 static const char *const *dwarf_regnames
;
5273 static unsigned int dwarf_regnames_count
;
5275 /* A marker for a col_type that means this column was never referenced
5276 in the frame info. */
5277 #define DW_CFA_unreferenced (-1)
5279 /* Return 0 if no more space is needed, 1 if more space is needed,
5280 -1 for invalid reg. */
5283 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
5285 unsigned int prev
= fc
->ncols
;
5287 if (reg
< (unsigned int) fc
->ncols
)
5290 if (dwarf_regnames_count
5291 && reg
> dwarf_regnames_count
)
5294 fc
->ncols
= reg
+ 1;
5295 /* PR 17512: file: 10450-2643-0.004.
5296 If reg == -1 then this can happen... */
5300 /* PR 17512: file: 2844a11d. */
5301 if (fc
->ncols
> 1024)
5303 error (_("Unfeasibly large register number: %u\n"), reg
);
5305 /* FIXME: 1024 is an arbitrary limit. Increase it if
5306 we ever encounter a valid binary that exceeds it. */
5310 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
5311 sizeof (short int));
5312 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
5313 /* PR 17512: file:002-10025-0.005. */
5314 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
5316 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
5322 while (prev
< fc
->ncols
)
5324 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
5325 fc
->col_offset
[prev
] = 0;
5331 static const char *const dwarf_regnames_i386
[] =
5333 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5334 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5335 "eip", "eflags", NULL
, /* 8 - 10 */
5336 "st0", "st1", "st2", "st3", /* 11 - 14 */
5337 "st4", "st5", "st6", "st7", /* 15 - 18 */
5338 NULL
, NULL
, /* 19 - 20 */
5339 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5340 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5341 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5342 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5343 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5344 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
5345 "tr", "ldtr", /* 48 - 49 */
5346 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
5347 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
5348 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
5349 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
5350 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
5351 NULL
, NULL
, NULL
, /* 90 - 92 */
5352 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5355 static const char *const dwarf_regnames_iamcu
[] =
5357 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5358 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5359 "eip", "eflags", NULL
, /* 8 - 10 */
5360 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
5361 NULL
, NULL
, /* 19 - 20 */
5362 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
5363 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
5364 NULL
, NULL
, NULL
, /* 37 - 39 */
5365 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
5366 "tr", "ldtr", /* 48 - 49 */
5367 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
5368 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
5369 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
5370 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
5371 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
5372 NULL
, NULL
, NULL
, /* 90 - 92 */
5373 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
5377 init_dwarf_regnames_i386 (void)
5379 dwarf_regnames
= dwarf_regnames_i386
;
5380 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
5384 init_dwarf_regnames_iamcu (void)
5386 dwarf_regnames
= dwarf_regnames_iamcu
;
5387 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
5390 static const char *const dwarf_regnames_x86_64
[] =
5392 "rax", "rdx", "rcx", "rbx",
5393 "rsi", "rdi", "rbp", "rsp",
5394 "r8", "r9", "r10", "r11",
5395 "r12", "r13", "r14", "r15",
5397 "xmm0", "xmm1", "xmm2", "xmm3",
5398 "xmm4", "xmm5", "xmm6", "xmm7",
5399 "xmm8", "xmm9", "xmm10", "xmm11",
5400 "xmm12", "xmm13", "xmm14", "xmm15",
5401 "st0", "st1", "st2", "st3",
5402 "st4", "st5", "st6", "st7",
5403 "mm0", "mm1", "mm2", "mm3",
5404 "mm4", "mm5", "mm6", "mm7",
5406 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
5407 "fs.base", "gs.base", NULL
, NULL
,
5409 "mxcsr", "fcw", "fsw",
5410 "xmm16", "xmm17", "xmm18", "xmm19",
5411 "xmm20", "xmm21", "xmm22", "xmm23",
5412 "xmm24", "xmm25", "xmm26", "xmm27",
5413 "xmm28", "xmm29", "xmm30", "xmm31",
5414 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
5415 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
5416 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
5417 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
5418 NULL
, NULL
, NULL
, /* 115 - 117 */
5419 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5423 init_dwarf_regnames_x86_64 (void)
5425 dwarf_regnames
= dwarf_regnames_x86_64
;
5426 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
5429 static const char *const dwarf_regnames_aarch64
[] =
5431 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
5432 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
5433 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
5434 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
5435 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5436 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5437 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5438 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5439 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
5440 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
5441 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
5442 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
5446 init_dwarf_regnames_aarch64 (void)
5448 dwarf_regnames
= dwarf_regnames_aarch64
;
5449 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
5453 init_dwarf_regnames (unsigned int e_machine
)
5458 init_dwarf_regnames_i386 ();
5462 init_dwarf_regnames_iamcu ();
5468 init_dwarf_regnames_x86_64 ();
5472 init_dwarf_regnames_aarch64 ();
5481 regname (unsigned int regno
, int row
)
5483 static char reg
[64];
5485 && regno
< dwarf_regnames_count
5486 && dwarf_regnames
[regno
] != NULL
)
5489 return dwarf_regnames
[regno
];
5490 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
5491 dwarf_regnames
[regno
]);
5494 snprintf (reg
, sizeof (reg
), "r%d", regno
);
5499 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
5504 if (*max_regs
< fc
->ncols
)
5505 *max_regs
= fc
->ncols
;
5507 if (*need_col_headers
)
5509 static const char *sloc
= " LOC";
5511 *need_col_headers
= 0;
5513 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
5515 for (r
= 0; r
< *max_regs
; r
++)
5516 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5521 printf ("%-5s ", regname (r
, 1));
5527 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
5529 strcpy (tmp
, "exp");
5531 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
5532 printf ("%-8s ", tmp
);
5534 for (r
= 0; r
< fc
->ncols
; r
++)
5536 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5538 switch (fc
->col_type
[r
])
5540 case DW_CFA_undefined
:
5543 case DW_CFA_same_value
:
5547 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
5549 case DW_CFA_val_offset
:
5550 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
5552 case DW_CFA_register
:
5553 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
5555 case DW_CFA_expression
:
5556 strcpy (tmp
, "exp");
5558 case DW_CFA_val_expression
:
5559 strcpy (tmp
, "vexp");
5562 strcpy (tmp
, "n/a");
5565 printf ("%-5s ", tmp
);
5571 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
5572 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5573 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5575 static unsigned char *
5576 read_cie (unsigned char *start
, unsigned char *end
,
5577 Frame_Chunk
**p_cie
, int *p_version
,
5578 unsigned long *p_aug_len
, unsigned char **p_aug
)
5582 unsigned int length_return
;
5583 unsigned char *augmentation_data
= NULL
;
5584 unsigned long augmentation_data_len
= 0;
5587 /* PR 17512: file: 001-228113-0.004. */
5591 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
5592 memset (fc
, 0, sizeof (Frame_Chunk
));
5594 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
5595 fc
->col_offset
= (int *) xmalloc (sizeof (int));
5599 fc
->augmentation
= (char *) start
;
5600 /* PR 17512: file: 001-228113-0.004.
5601 Skip past augmentation name, but avoid running off the end of the data. */
5603 if (* start
++ == '\0')
5607 warn (_("No terminator for augmentation name\n"));
5611 if (strcmp (fc
->augmentation
, "eh") == 0)
5612 start
+= eh_addr_size
;
5616 GET (fc
->ptr_size
, 1);
5617 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
5619 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
5623 GET (fc
->segment_size
, 1);
5624 /* PR 17512: file: e99d2804. */
5625 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
5627 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
5631 eh_addr_size
= fc
->ptr_size
;
5635 fc
->ptr_size
= eh_addr_size
;
5636 fc
->segment_size
= 0;
5638 fc
->code_factor
= LEB ();
5639 fc
->data_factor
= SLEB ();
5649 if (fc
->augmentation
[0] == 'z')
5651 augmentation_data_len
= LEB ();
5652 augmentation_data
= start
;
5653 start
+= augmentation_data_len
;
5654 /* PR 17512: file: 11042-2589-0.004. */
5657 warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len
);
5662 if (augmentation_data_len
)
5666 unsigned char *qend
;
5668 p
= (unsigned char *) fc
->augmentation
+ 1;
5669 q
= augmentation_data
;
5670 qend
= q
+ augmentation_data_len
;
5672 /* PR 17531: file: 015adfaa. */
5675 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len
);
5676 augmentation_data_len
= 0;
5679 while (p
< end
&& q
< augmentation_data
+ augmentation_data_len
)
5684 q
+= 1 + size_of_encoded_value (*q
);
5686 fc
->fde_encoding
= *q
++;
5693 /* Note - it is OK if this loop terminates with q < qend.
5694 Padding may have been inserted to align the end of the CIE. */
5699 *p_version
= version
;
5702 *p_aug_len
= augmentation_data_len
;
5703 *p_aug
= augmentation_data
;
5709 display_debug_frames (struct dwarf_section
*section
,
5710 void *file ATTRIBUTE_UNUSED
)
5712 unsigned char *start
= section
->start
;
5713 unsigned char *end
= start
+ section
->size
;
5714 unsigned char *section_start
= start
;
5715 Frame_Chunk
*chunks
= 0, *forward_refs
= 0;
5716 Frame_Chunk
*remembered_state
= 0;
5718 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
5719 unsigned int length_return
;
5720 unsigned int max_regs
= 0;
5721 const char *bad_reg
= _("bad register: ");
5722 unsigned int saved_eh_addr_size
= eh_addr_size
;
5724 printf (_("Contents of the %s section:\n"), section
->name
);
5728 unsigned char *saved_start
;
5729 unsigned char *block_end
;
5734 int need_col_headers
= 1;
5735 unsigned char *augmentation_data
= NULL
;
5736 unsigned long augmentation_data_len
= 0;
5737 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
5738 unsigned int offset_size
;
5739 unsigned int initial_length_size
;
5741 saved_start
= start
;
5743 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
5747 printf ("\n%08lx ZERO terminator\n\n",
5748 (unsigned long)(saved_start
- section_start
));
5749 /* Skip any zero terminators that directly follow.
5750 A corrupt section size could have loaded a whole
5751 slew of zero filled memory bytes. eg
5752 PR 17512: file: 070-19381-0.004. */
5753 while (start
< end
&& * start
== 0)
5758 if (length
== 0xffffffff)
5760 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
5762 initial_length_size
= 12;
5767 initial_length_size
= 4;
5770 block_end
= saved_start
+ length
+ initial_length_size
;
5771 if (block_end
> end
|| block_end
< start
)
5773 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5774 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
5775 (unsigned long) (saved_start
- section_start
));
5779 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
5781 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
5782 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
5787 start
= read_cie (start
, end
, &cie
, &version
,
5788 &augmentation_data_len
, &augmentation_data
);
5789 /* PR 17512: file: 027-135133-0.005. */
5796 fc
->chunk_start
= saved_start
;
5797 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
5800 if (frame_need_space (fc
, mreg
) < 0)
5802 if (fc
->fde_encoding
)
5803 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
5805 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
5806 print_dwarf_vma (length
, fc
->ptr_size
);
5807 print_dwarf_vma (cie_id
, offset_size
);
5809 if (do_debug_frames_interp
)
5811 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
5812 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
5817 printf (" Version: %d\n", version
);
5818 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
5821 printf (" Pointer Size: %u\n", fc
->ptr_size
);
5822 printf (" Segment Size: %u\n", fc
->segment_size
);
5824 printf (" Code alignment factor: %u\n", fc
->code_factor
);
5825 printf (" Data alignment factor: %d\n", fc
->data_factor
);
5826 printf (" Return address column: %d\n", fc
->ra
);
5828 if (augmentation_data_len
)
5832 printf (" Augmentation data: ");
5833 for (i
= 0; i
< augmentation_data_len
; ++i
)
5834 /* FIXME: If do_wide is FALSE, then we should
5835 add carriage returns at 80 columns... */
5836 printf (" %02x", augmentation_data
[i
]);
5844 unsigned char *look_for
;
5845 static Frame_Chunk fde_fc
;
5846 unsigned long segment_selector
;
5850 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
5851 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
5854 look_for
= section_start
+ cie_id
;
5856 if (look_for
<= saved_start
)
5858 for (cie
= chunks
; cie
; cie
= cie
->next
)
5859 if (cie
->chunk_start
== look_for
)
5864 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
5865 if (cie
->chunk_start
== look_for
)
5869 unsigned int off_size
;
5870 unsigned char *cie_scan
;
5872 cie_scan
= look_for
;
5874 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
5875 if (length
== 0xffffffff)
5877 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
5884 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
5887 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
5888 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
5893 read_cie (cie_scan
, end
, &cie
, &version
,
5894 &augmentation_data_len
, &augmentation_data
);
5895 /* PR 17512: file: 3450-2098-0.004. */
5898 warn (_("Failed to read CIE information\n"));
5901 cie
->next
= forward_refs
;
5903 cie
->chunk_start
= look_for
;
5904 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
5907 if (frame_need_space (cie
, mreg
) < 0)
5909 warn (_("Invalid max register\n"));
5912 if (cie
->fde_encoding
)
5914 = size_of_encoded_value (cie
->fde_encoding
);
5921 memset (fc
, 0, sizeof (Frame_Chunk
));
5925 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
5926 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
5927 (unsigned long) (saved_start
- section_start
));
5929 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
5930 fc
->col_offset
= (int *) xmalloc (sizeof (int));
5931 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
5933 warn (_("Invalid max register\n"));
5937 fc
->augmentation
= "";
5938 fc
->fde_encoding
= 0;
5939 fc
->ptr_size
= eh_addr_size
;
5940 fc
->segment_size
= 0;
5944 fc
->ncols
= cie
->ncols
;
5945 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
5946 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
5947 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
5948 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
5949 fc
->augmentation
= cie
->augmentation
;
5950 fc
->ptr_size
= cie
->ptr_size
;
5951 eh_addr_size
= cie
->ptr_size
;
5952 fc
->segment_size
= cie
->segment_size
;
5953 fc
->code_factor
= cie
->code_factor
;
5954 fc
->data_factor
= cie
->data_factor
;
5955 fc
->cfa_reg
= cie
->cfa_reg
;
5956 fc
->cfa_offset
= cie
->cfa_offset
;
5958 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
5960 warn (_("Invalid max register\n"));
5963 fc
->fde_encoding
= cie
->fde_encoding
;
5966 if (fc
->fde_encoding
)
5967 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
5969 segment_selector
= 0;
5970 if (fc
->segment_size
)
5972 if (fc
->segment_size
> sizeof (segment_selector
))
5974 /* PR 17512: file: 9e196b3e. */
5975 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
5976 fc
->segment_size
= 4;
5978 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
5981 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
5983 /* FIXME: It appears that sometimes the final pc_range value is
5984 encoded in less than encoded_ptr_size bytes. See the x86_64
5985 run of the "objcopy on compressed debug sections" test for an
5987 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
5989 if (cie
->augmentation
[0] == 'z')
5991 augmentation_data_len
= LEB ();
5992 augmentation_data
= start
;
5993 start
+= augmentation_data_len
;
5994 /* PR 17512: file: 722-8446-0.004. */
5995 if (start
>= end
|| ((signed long) augmentation_data_len
) < 0)
5997 warn (_("Corrupt augmentation data length: %lx\n"),
5998 augmentation_data_len
);
6000 augmentation_data
= NULL
;
6001 augmentation_data_len
= 0;
6005 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
6006 (unsigned long)(saved_start
- section_start
),
6007 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
6008 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
6009 (unsigned long)(cie
->chunk_start
- section_start
));
6011 if (fc
->segment_size
)
6012 printf ("%04lx:", segment_selector
);
6015 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
6016 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
6018 if (! do_debug_frames_interp
&& augmentation_data_len
)
6022 printf (" Augmentation data: ");
6023 for (i
= 0; i
< augmentation_data_len
; ++i
)
6024 printf (" %02x", augmentation_data
[i
]);
6030 /* At this point, fc is the current chunk, cie (if any) is set, and
6031 we're about to interpret instructions for the chunk. */
6032 /* ??? At present we need to do this always, since this sizes the
6033 fc->col_type and fc->col_offset arrays, which we write into always.
6034 We should probably split the interpreted and non-interpreted bits
6035 into two different routines, since there's so much that doesn't
6036 really overlap between them. */
6037 if (1 || do_debug_frames_interp
)
6039 /* Start by making a pass over the chunk, allocating storage
6040 and taking note of what registers are used. */
6041 unsigned char *tmp
= start
;
6043 while (start
< block_end
)
6045 unsigned int reg
, op
, opa
;
6047 unsigned char * new_start
;
6054 /* Warning: if you add any more cases to this switch, be
6055 sure to add them to the corresponding switch below. */
6058 case DW_CFA_advance_loc
:
6062 if (frame_need_space (fc
, opa
) >= 0)
6063 fc
->col_type
[opa
] = DW_CFA_undefined
;
6065 case DW_CFA_restore
:
6066 if (frame_need_space (fc
, opa
) >= 0)
6067 fc
->col_type
[opa
] = DW_CFA_undefined
;
6069 case DW_CFA_set_loc
:
6070 start
+= encoded_ptr_size
;
6072 case DW_CFA_advance_loc1
:
6075 case DW_CFA_advance_loc2
:
6078 case DW_CFA_advance_loc4
:
6081 case DW_CFA_offset_extended
:
6082 case DW_CFA_val_offset
:
6083 reg
= LEB (); LEB ();
6084 if (frame_need_space (fc
, reg
) >= 0)
6085 fc
->col_type
[reg
] = DW_CFA_undefined
;
6087 case DW_CFA_restore_extended
:
6089 if (frame_need_space (fc
, reg
) >= 0)
6090 fc
->col_type
[reg
] = DW_CFA_undefined
;
6092 case DW_CFA_undefined
:
6094 if (frame_need_space (fc
, reg
) >= 0)
6095 fc
->col_type
[reg
] = DW_CFA_undefined
;
6097 case DW_CFA_same_value
:
6099 if (frame_need_space (fc
, reg
) >= 0)
6100 fc
->col_type
[reg
] = DW_CFA_undefined
;
6102 case DW_CFA_register
:
6103 reg
= LEB (); LEB ();
6104 if (frame_need_space (fc
, reg
) >= 0)
6105 fc
->col_type
[reg
] = DW_CFA_undefined
;
6107 case DW_CFA_def_cfa
:
6110 case DW_CFA_def_cfa_register
:
6113 case DW_CFA_def_cfa_offset
:
6116 case DW_CFA_def_cfa_expression
:
6118 new_start
= start
+ temp
;
6119 if (new_start
< start
)
6121 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
6127 case DW_CFA_expression
:
6128 case DW_CFA_val_expression
:
6131 new_start
= start
+ temp
;
6132 if (new_start
< start
)
6134 /* PR 17512: file:306-192417-0.005. */
6135 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
6140 if (frame_need_space (fc
, reg
) >= 0)
6141 fc
->col_type
[reg
] = DW_CFA_undefined
;
6143 case DW_CFA_offset_extended_sf
:
6144 case DW_CFA_val_offset_sf
:
6145 reg
= LEB (); SLEB ();
6146 if (frame_need_space (fc
, reg
) >= 0)
6147 fc
->col_type
[reg
] = DW_CFA_undefined
;
6149 case DW_CFA_def_cfa_sf
:
6152 case DW_CFA_def_cfa_offset_sf
:
6155 case DW_CFA_MIPS_advance_loc8
:
6158 case DW_CFA_GNU_args_size
:
6161 case DW_CFA_GNU_negative_offset_extended
:
6162 reg
= LEB (); LEB ();
6163 if (frame_need_space (fc
, reg
) >= 0)
6164 fc
->col_type
[reg
] = DW_CFA_undefined
;
6173 /* Now we know what registers are used, make a second pass over
6174 the chunk, this time actually printing out the info. */
6176 while (start
< block_end
)
6178 unsigned char * tmp
;
6180 unsigned long ul
, reg
, roffs
;
6184 const char *reg_prefix
= "";
6191 /* Warning: if you add any more cases to this switch, be
6192 sure to add them to the corresponding switch above. */
6195 case DW_CFA_advance_loc
:
6196 if (do_debug_frames_interp
)
6197 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6199 printf (" DW_CFA_advance_loc: %d to %s\n",
6200 opa
* fc
->code_factor
,
6201 dwarf_vmatoa_1 (NULL
,
6202 fc
->pc_begin
+ opa
* fc
->code_factor
,
6204 fc
->pc_begin
+= opa
* fc
->code_factor
;
6209 if (opa
>= (unsigned int) fc
->ncols
)
6210 reg_prefix
= bad_reg
;
6211 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6212 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
6213 reg_prefix
, regname (opa
, 0),
6214 roffs
* fc
->data_factor
);
6215 if (*reg_prefix
== '\0')
6217 fc
->col_type
[opa
] = DW_CFA_offset
;
6218 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
6222 case DW_CFA_restore
:
6223 if (opa
>= (unsigned int) cie
->ncols
6224 || opa
>= (unsigned int) fc
->ncols
)
6225 reg_prefix
= bad_reg
;
6226 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6227 printf (" DW_CFA_restore: %s%s\n",
6228 reg_prefix
, regname (opa
, 0));
6229 if (*reg_prefix
== '\0')
6231 fc
->col_type
[opa
] = cie
->col_type
[opa
];
6232 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
6233 if (do_debug_frames_interp
6234 && fc
->col_type
[opa
] == DW_CFA_unreferenced
)
6235 fc
->col_type
[opa
] = DW_CFA_undefined
;
6239 case DW_CFA_set_loc
:
6240 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
6241 if (do_debug_frames_interp
)
6242 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6244 printf (" DW_CFA_set_loc: %s\n",
6245 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
6249 case DW_CFA_advance_loc1
:
6250 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
6251 if (do_debug_frames_interp
)
6252 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6254 printf (" DW_CFA_advance_loc1: %ld to %s\n",
6255 (unsigned long) (ofs
* fc
->code_factor
),
6256 dwarf_vmatoa_1 (NULL
,
6257 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6259 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6262 case DW_CFA_advance_loc2
:
6263 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
6264 if (do_debug_frames_interp
)
6265 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6267 printf (" DW_CFA_advance_loc2: %ld to %s\n",
6268 (unsigned long) (ofs
* fc
->code_factor
),
6269 dwarf_vmatoa_1 (NULL
,
6270 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6272 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6275 case DW_CFA_advance_loc4
:
6276 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
6277 if (do_debug_frames_interp
)
6278 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6280 printf (" DW_CFA_advance_loc4: %ld to %s\n",
6281 (unsigned long) (ofs
* fc
->code_factor
),
6282 dwarf_vmatoa_1 (NULL
,
6283 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6285 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6288 case DW_CFA_offset_extended
:
6291 if (reg
>= (unsigned int) fc
->ncols
)
6292 reg_prefix
= bad_reg
;
6293 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6294 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
6295 reg_prefix
, regname (reg
, 0),
6296 roffs
* fc
->data_factor
);
6297 if (*reg_prefix
== '\0')
6299 fc
->col_type
[reg
] = DW_CFA_offset
;
6300 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
6304 case DW_CFA_val_offset
:
6307 if (reg
>= (unsigned int) fc
->ncols
)
6308 reg_prefix
= bad_reg
;
6309 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6310 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
6311 reg_prefix
, regname (reg
, 0),
6312 roffs
* fc
->data_factor
);
6313 if (*reg_prefix
== '\0')
6315 fc
->col_type
[reg
] = DW_CFA_val_offset
;
6316 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
6320 case DW_CFA_restore_extended
:
6322 if (reg
>= (unsigned int) cie
->ncols
6323 || reg
>= (unsigned int) fc
->ncols
)
6324 reg_prefix
= bad_reg
;
6325 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6326 printf (" DW_CFA_restore_extended: %s%s\n",
6327 reg_prefix
, regname (reg
, 0));
6328 if (*reg_prefix
== '\0')
6330 fc
->col_type
[reg
] = cie
->col_type
[reg
];
6331 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
6335 case DW_CFA_undefined
:
6337 if (reg
>= (unsigned int) fc
->ncols
)
6338 reg_prefix
= bad_reg
;
6339 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6340 printf (" DW_CFA_undefined: %s%s\n",
6341 reg_prefix
, regname (reg
, 0));
6342 if (*reg_prefix
== '\0')
6344 fc
->col_type
[reg
] = DW_CFA_undefined
;
6345 fc
->col_offset
[reg
] = 0;
6349 case DW_CFA_same_value
:
6351 if (reg
>= (unsigned int) fc
->ncols
)
6352 reg_prefix
= bad_reg
;
6353 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6354 printf (" DW_CFA_same_value: %s%s\n",
6355 reg_prefix
, regname (reg
, 0));
6356 if (*reg_prefix
== '\0')
6358 fc
->col_type
[reg
] = DW_CFA_same_value
;
6359 fc
->col_offset
[reg
] = 0;
6363 case DW_CFA_register
:
6366 if (reg
>= (unsigned int) fc
->ncols
)
6367 reg_prefix
= bad_reg
;
6368 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6370 printf (" DW_CFA_register: %s%s in ",
6371 reg_prefix
, regname (reg
, 0));
6372 puts (regname (roffs
, 0));
6374 if (*reg_prefix
== '\0')
6376 fc
->col_type
[reg
] = DW_CFA_register
;
6377 fc
->col_offset
[reg
] = roffs
;
6381 case DW_CFA_remember_state
:
6382 if (! do_debug_frames_interp
)
6383 printf (" DW_CFA_remember_state\n");
6384 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
6385 rs
->cfa_offset
= fc
->cfa_offset
;
6386 rs
->cfa_reg
= fc
->cfa_reg
;
6388 rs
->cfa_exp
= fc
->cfa_exp
;
6389 rs
->ncols
= fc
->ncols
;
6390 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
6391 sizeof (* rs
->col_type
));
6392 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
6393 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
6394 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
6395 rs
->next
= remembered_state
;
6396 remembered_state
= rs
;
6399 case DW_CFA_restore_state
:
6400 if (! do_debug_frames_interp
)
6401 printf (" DW_CFA_restore_state\n");
6402 rs
= remembered_state
;
6405 remembered_state
= rs
->next
;
6406 fc
->cfa_offset
= rs
->cfa_offset
;
6407 fc
->cfa_reg
= rs
->cfa_reg
;
6409 fc
->cfa_exp
= rs
->cfa_exp
;
6410 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
6412 warn (_("Invalid column number in saved frame state\n"));
6416 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
6417 memcpy (fc
->col_offset
, rs
->col_offset
,
6418 rs
->ncols
* sizeof (* rs
->col_offset
));
6419 free (rs
->col_type
);
6420 free (rs
->col_offset
);
6423 else if (do_debug_frames_interp
)
6424 printf ("Mismatched DW_CFA_restore_state\n");
6427 case DW_CFA_def_cfa
:
6428 fc
->cfa_reg
= LEB ();
6429 fc
->cfa_offset
= LEB ();
6431 if (! do_debug_frames_interp
)
6432 printf (" DW_CFA_def_cfa: %s ofs %d\n",
6433 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
6436 case DW_CFA_def_cfa_register
:
6437 fc
->cfa_reg
= LEB ();
6439 if (! do_debug_frames_interp
)
6440 printf (" DW_CFA_def_cfa_register: %s\n",
6441 regname (fc
->cfa_reg
, 0));
6444 case DW_CFA_def_cfa_offset
:
6445 fc
->cfa_offset
= LEB ();
6446 if (! do_debug_frames_interp
)
6447 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
6451 if (! do_debug_frames_interp
)
6452 printf (" DW_CFA_nop\n");
6455 case DW_CFA_def_cfa_expression
:
6457 if (start
>= block_end
|| start
+ ul
> block_end
|| start
+ ul
< start
)
6459 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
6462 if (! do_debug_frames_interp
)
6464 printf (" DW_CFA_def_cfa_expression (");
6465 decode_location_expression (start
, eh_addr_size
, 0, -1,
6473 case DW_CFA_expression
:
6476 if (reg
>= (unsigned int) fc
->ncols
)
6477 reg_prefix
= bad_reg
;
6478 /* PR 17512: file: 069-133014-0.006. */
6479 /* PR 17512: file: 98c02eb4. */
6481 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
6483 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
6486 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6488 printf (" DW_CFA_expression: %s%s (",
6489 reg_prefix
, regname (reg
, 0));
6490 decode_location_expression (start
, eh_addr_size
, 0, -1,
6494 if (*reg_prefix
== '\0')
6495 fc
->col_type
[reg
] = DW_CFA_expression
;
6499 case DW_CFA_val_expression
:
6502 if (reg
>= (unsigned int) fc
->ncols
)
6503 reg_prefix
= bad_reg
;
6505 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
6507 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
6510 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6512 printf (" DW_CFA_val_expression: %s%s (",
6513 reg_prefix
, regname (reg
, 0));
6514 decode_location_expression (start
, eh_addr_size
, 0, -1,
6518 if (*reg_prefix
== '\0')
6519 fc
->col_type
[reg
] = DW_CFA_val_expression
;
6523 case DW_CFA_offset_extended_sf
:
6526 if (frame_need_space (fc
, reg
) < 0)
6527 reg_prefix
= bad_reg
;
6528 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6529 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
6530 reg_prefix
, regname (reg
, 0),
6531 (long)(l
* fc
->data_factor
));
6532 if (*reg_prefix
== '\0')
6534 fc
->col_type
[reg
] = DW_CFA_offset
;
6535 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6539 case DW_CFA_val_offset_sf
:
6542 if (frame_need_space (fc
, reg
) < 0)
6543 reg_prefix
= bad_reg
;
6544 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6545 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
6546 reg_prefix
, regname (reg
, 0),
6547 (long)(l
* fc
->data_factor
));
6548 if (*reg_prefix
== '\0')
6550 fc
->col_type
[reg
] = DW_CFA_val_offset
;
6551 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6555 case DW_CFA_def_cfa_sf
:
6556 fc
->cfa_reg
= LEB ();
6557 fc
->cfa_offset
= SLEB ();
6558 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
6560 if (! do_debug_frames_interp
)
6561 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
6562 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
6565 case DW_CFA_def_cfa_offset_sf
:
6566 fc
->cfa_offset
= SLEB ();
6567 fc
->cfa_offset
*= fc
->data_factor
;
6568 if (! do_debug_frames_interp
)
6569 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
6572 case DW_CFA_MIPS_advance_loc8
:
6573 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
6574 if (do_debug_frames_interp
)
6575 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6577 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
6578 (unsigned long) (ofs
* fc
->code_factor
),
6579 dwarf_vmatoa_1 (NULL
,
6580 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6582 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6585 case DW_CFA_GNU_window_save
:
6586 if (! do_debug_frames_interp
)
6587 printf (" DW_CFA_GNU_window_save\n");
6590 case DW_CFA_GNU_args_size
:
6592 if (! do_debug_frames_interp
)
6593 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
6596 case DW_CFA_GNU_negative_offset_extended
:
6599 if (frame_need_space (fc
, reg
) < 0)
6600 reg_prefix
= bad_reg
;
6601 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6602 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6603 reg_prefix
, regname (reg
, 0),
6604 (long)(l
* fc
->data_factor
));
6605 if (*reg_prefix
== '\0')
6607 fc
->col_type
[reg
] = DW_CFA_offset
;
6608 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6613 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
6614 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
6616 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
6621 if (do_debug_frames_interp
)
6622 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6625 eh_addr_size
= saved_eh_addr_size
;
6638 display_gdb_index (struct dwarf_section
*section
,
6639 void *file ATTRIBUTE_UNUSED
)
6641 unsigned char *start
= section
->start
;
6643 uint32_t cu_list_offset
, tu_list_offset
;
6644 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
6645 unsigned int cu_list_elements
, tu_list_elements
;
6646 unsigned int address_table_size
, symbol_table_slots
;
6647 unsigned char *cu_list
, *tu_list
;
6648 unsigned char *address_table
, *symbol_table
, *constant_pool
;
6651 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6653 printf (_("Contents of the %s section:\n"), section
->name
);
6655 if (section
->size
< 6 * sizeof (uint32_t))
6657 warn (_("Truncated header in the %s section.\n"), section
->name
);
6661 version
= byte_get_little_endian (start
, 4);
6662 printf (_("Version %ld\n"), (long) version
);
6664 /* Prior versions are obsolete, and future versions may not be
6665 backwards compatible. */
6666 if (version
< 3 || version
> 8)
6668 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
6672 warn (_("The address table data in version 3 may be wrong.\n"));
6674 warn (_("Version 4 does not support case insensitive lookups.\n"));
6676 warn (_("Version 5 does not include inlined functions.\n"));
6678 warn (_("Version 6 does not include symbol attributes.\n"));
6679 /* Version 7 indices generated by Gold have bad type unit references,
6680 PR binutils/15021. But we don't know if the index was generated by
6681 Gold or not, so to avoid worrying users with gdb-generated indices
6682 we say nothing for version 7 here. */
6684 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
6685 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
6686 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
6687 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
6688 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
6690 if (cu_list_offset
> section
->size
6691 || tu_list_offset
> section
->size
6692 || address_table_offset
> section
->size
6693 || symbol_table_offset
> section
->size
6694 || constant_pool_offset
> section
->size
)
6696 warn (_("Corrupt header in the %s section.\n"), section
->name
);
6700 /* PR 17531: file: 418d0a8a. */
6701 if (tu_list_offset
< cu_list_offset
)
6703 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
6704 tu_list_offset
, cu_list_offset
);
6708 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
6710 if (address_table_offset
< tu_list_offset
)
6712 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
6713 address_table_offset
, tu_list_offset
);
6717 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
6719 /* PR 17531: file: 18a47d3d. */
6720 if (symbol_table_offset
< address_table_offset
)
6722 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
6723 symbol_table_offset
, address_table_offset
);
6727 address_table_size
= symbol_table_offset
- address_table_offset
;
6729 if (constant_pool_offset
< symbol_table_offset
)
6731 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
6732 constant_pool_offset
, symbol_table_offset
);
6736 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
6738 cu_list
= start
+ cu_list_offset
;
6739 tu_list
= start
+ tu_list_offset
;
6740 address_table
= start
+ address_table_offset
;
6741 symbol_table
= start
+ symbol_table_offset
;
6742 constant_pool
= start
+ constant_pool_offset
;
6744 if (address_table
+ address_table_size
* (2 + 8 + 4) > section
->start
+ section
->size
)
6746 warn (_("Address table extends beyond end of section.\n"));
6750 printf (_("\nCU table:\n"));
6751 for (i
= 0; i
< cu_list_elements
; i
+= 2)
6753 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
6754 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
6756 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
6757 (unsigned long) cu_offset
,
6758 (unsigned long) (cu_offset
+ cu_length
- 1));
6761 printf (_("\nTU table:\n"));
6762 for (i
= 0; i
< tu_list_elements
; i
+= 3)
6764 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
6765 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
6766 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
6768 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
6769 (unsigned long) tu_offset
,
6770 (unsigned long) type_offset
);
6771 print_dwarf_vma (signature
, 8);
6775 printf (_("\nAddress table:\n"));
6776 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
6779 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
6780 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
6781 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
6783 print_dwarf_vma (low
, 8);
6784 print_dwarf_vma (high
, 8);
6785 printf (_("%lu\n"), (unsigned long) cu_index
);
6788 printf (_("\nSymbol table:\n"));
6789 for (i
= 0; i
< symbol_table_slots
; ++i
)
6791 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
6792 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
6793 uint32_t num_cus
, cu
;
6795 if (name_offset
!= 0
6796 || cu_vector_offset
!= 0)
6799 unsigned char * adr
;
6801 adr
= constant_pool
+ name_offset
;
6802 /* PR 17531: file: 5b7b07ad. */
6803 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
6805 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
6806 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
6810 printf ("[%3u] %.*s:", i
,
6811 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
6812 constant_pool
+ name_offset
);
6814 adr
= constant_pool
+ cu_vector_offset
;
6815 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
6817 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
6818 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
6819 cu_vector_offset
, i
);
6823 num_cus
= byte_get_little_endian (adr
, 4);
6825 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
6826 if (num_cus
* 4 < num_cus
6827 || adr
>= section
->start
+ section
->size
6828 || adr
< constant_pool
)
6830 printf ("<invalid number of CUs: %d>\n", num_cus
);
6831 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
6839 for (j
= 0; j
< num_cus
; ++j
)
6842 gdb_index_symbol_kind kind
;
6844 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
6845 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
6846 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
6847 cu
= GDB_INDEX_CU_VALUE (cu
);
6848 /* Convert to TU number if it's for a type unit. */
6849 if (cu
>= cu_list_elements
/ 2)
6850 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
6851 (unsigned long) (cu
- cu_list_elements
/ 2));
6853 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
6855 printf (" [%s, %s]",
6856 is_static
? _("static") : _("global"),
6857 get_gdb_index_symbol_kind_name (kind
));
6869 /* Pre-allocate enough space for the CU/TU sets needed. */
6872 prealloc_cu_tu_list (unsigned int nshndx
)
6874 if (shndx_pool
== NULL
)
6876 shndx_pool_size
= nshndx
;
6877 shndx_pool_used
= 0;
6878 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
6879 sizeof (unsigned int));
6883 shndx_pool_size
= shndx_pool_used
+ nshndx
;
6884 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
6885 sizeof (unsigned int));
6890 add_shndx_to_cu_tu_entry (unsigned int shndx
)
6892 if (shndx_pool_used
>= shndx_pool_size
)
6894 error (_("Internal error: out of space in the shndx pool.\n"));
6897 shndx_pool
[shndx_pool_used
++] = shndx
;
6901 end_cu_tu_entry (void)
6903 if (shndx_pool_used
>= shndx_pool_size
)
6905 error (_("Internal error: out of space in the shndx pool.\n"));
6908 shndx_pool
[shndx_pool_used
++] = 0;
6911 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
6914 get_DW_SECT_short_name (unsigned int dw_sect
)
6916 static char buf
[16];
6924 case DW_SECT_ABBREV
:
6930 case DW_SECT_STR_OFFSETS
:
6932 case DW_SECT_MACINFO
:
6940 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
6944 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
6945 These sections are extensions for Fission.
6946 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
6949 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
6951 unsigned char *phdr
= section
->start
;
6952 unsigned char *limit
= phdr
+ section
->size
;
6953 unsigned char *phash
;
6954 unsigned char *pindex
;
6955 unsigned char *ppool
;
6956 unsigned int version
;
6957 unsigned int ncols
= 0;
6959 unsigned int nslots
;
6962 dwarf_vma signature_high
;
6963 dwarf_vma signature_low
;
6966 /* PR 17512: file: 002-168123-0.004. */
6969 warn (_("Section %s is empty\n"), section
->name
);
6972 /* PR 17512: file: 002-376-0.004. */
6973 if (section
->size
< 24)
6975 warn (_("Section %s is too small to contain a CU/TU header\n"),
6980 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
6982 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
6983 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
6984 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
6987 pindex
= phash
+ nslots
* 8;
6988 ppool
= pindex
+ nslots
* 4;
6990 /* PR 17531: file: 45d69832. */
6991 if (pindex
< phash
|| ppool
< phdr
|| (pindex
== phash
&& nslots
!= 0))
6993 warn (_("Section %s is too small for %d slots\n"),
6994 section
->name
, nslots
);
7000 printf (_("Contents of the %s section:\n\n"), section
->name
);
7001 printf (_(" Version: %d\n"), version
);
7003 printf (_(" Number of columns: %d\n"), ncols
);
7004 printf (_(" Number of used entries: %d\n"), nused
);
7005 printf (_(" Number of slots: %d\n\n"), nslots
);
7008 if (ppool
> limit
|| ppool
< phdr
)
7010 warn (_("Section %s too small for %d hash table entries\n"),
7011 section
->name
, nslots
);
7018 prealloc_cu_tu_list ((limit
- ppool
) / 4);
7019 for (i
= 0; i
< nslots
; i
++)
7021 unsigned char *shndx_list
;
7024 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
7025 if (signature_high
!= 0 || signature_low
!= 0)
7027 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
7028 shndx_list
= ppool
+ j
* 4;
7029 /* PR 17531: file: 705e010d. */
7030 if (shndx_list
< ppool
)
7032 warn (_("Section index pool located before start of section\n"));
7037 printf (_(" [%3d] Signature: 0x%s Sections: "),
7038 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
7039 buf
, sizeof (buf
)));
7042 if (shndx_list
>= limit
)
7044 warn (_("Section %s too small for shndx pool\n"),
7048 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
7052 printf (" %d", shndx
);
7054 add_shndx_to_cu_tu_entry (shndx
);
7066 else if (version
== 2)
7069 unsigned int dw_sect
;
7070 unsigned char *ph
= phash
;
7071 unsigned char *pi
= pindex
;
7072 unsigned char *poffsets
= ppool
+ ncols
* 4;
7073 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
7074 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
7075 bfd_boolean is_tu_index
;
7076 struct cu_tu_set
*this_set
= NULL
;
7078 unsigned char *prow
;
7080 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
7082 /* PR 17531: file: 0dd159bf.
7083 Check for wraparound with an overlarge ncols value. */
7084 if (poffsets
< ppool
|| (unsigned int) ((poffsets
- ppool
) / 4) != ncols
)
7086 warn (_("Overlarge number of columns: %x\n"), ncols
);
7092 warn (_("Section %s too small for offset and size tables\n"),
7099 printf (_(" Offset table\n"));
7100 printf (" slot %-16s ",
7101 is_tu_index
? _("signature") : _("dwo_id"));
7108 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
7114 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
7121 for (j
= 0; j
< ncols
; j
++)
7123 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
7124 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
7129 for (i
= 0; i
< nslots
; i
++)
7131 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
7133 SAFE_BYTE_GET (row
, pi
, 4, limit
);
7136 /* PR 17531: file: a05f6ab3. */
7139 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
7145 memcpy (&this_set
[row
- 1].signature
, ph
, sizeof (uint64_t));
7147 prow
= poffsets
+ (row
- 1) * ncols
* 4;
7148 /* PR 17531: file: b8ce60a8. */
7149 if (prow
< poffsets
|| prow
> limit
)
7151 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
7157 printf (_(" [%3d] 0x%s"),
7158 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
7159 buf
, sizeof (buf
)));
7160 for (j
= 0; j
< ncols
; j
++)
7162 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
7164 printf (" %8d", val
);
7167 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
7169 /* PR 17531: file: 10796eb3. */
7170 if (dw_sect
>= DW_SECT_MAX
)
7171 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
7173 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
7189 printf (_(" Size table\n"));
7190 printf (" slot %-16s ",
7191 is_tu_index
? _("signature") : _("dwo_id"));
7194 for (j
= 0; j
< ncols
; j
++)
7196 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
7198 printf (" %8s", get_DW_SECT_short_name (val
));
7204 for (i
= 0; i
< nslots
; i
++)
7206 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
7208 SAFE_BYTE_GET (row
, pi
, 4, limit
);
7211 prow
= psizes
+ (row
- 1) * ncols
* 4;
7214 printf (_(" [%3d] 0x%s"),
7215 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
7216 buf
, sizeof (buf
)));
7218 for (j
= 0; j
< ncols
; j
++)
7220 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
7222 printf (" %8d", val
);
7225 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
7226 if (dw_sect
>= DW_SECT_MAX
)
7227 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
7229 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
7241 else if (do_display
)
7242 printf (_(" Unsupported version (%d)\n"), version
);
7250 /* Load the CU and TU indexes if present. This will build a list of
7251 section sets that we can use to associate a .debug_info.dwo section
7252 with its associated .debug_abbrev.dwo section in a .dwp file. */
7255 load_cu_tu_indexes (void *file
)
7257 /* If we have already loaded (or tried to load) the CU and TU indexes
7258 then do not bother to repeat the task. */
7259 if (cu_tu_indexes_read
)
7262 if (load_debug_section (dwp_cu_index
, file
))
7263 process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0);
7265 if (load_debug_section (dwp_tu_index
, file
))
7266 process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0);
7268 cu_tu_indexes_read
= 1;
7271 /* Find the set of sections that includes section SHNDX. */
7274 find_cu_tu_set (void *file
, unsigned int shndx
)
7278 load_cu_tu_indexes (file
);
7280 /* Find SHNDX in the shndx pool. */
7281 for (i
= 0; i
< shndx_pool_used
; i
++)
7282 if (shndx_pool
[i
] == shndx
)
7285 if (i
>= shndx_pool_used
)
7288 /* Now backup to find the first entry in the set. */
7289 while (i
> 0 && shndx_pool
[i
- 1] != 0)
7292 return shndx_pool
+ i
;
7295 /* Display a .debug_cu_index or .debug_tu_index section. */
7298 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
7300 return process_cu_tu_index (section
, 1);
7304 display_debug_not_supported (struct dwarf_section
*section
,
7305 void *file ATTRIBUTE_UNUSED
)
7307 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7313 /* Like malloc, but takes two parameters like calloc.
7314 Verifies that the first parameter is not too large.
7315 Note: does *not* initialise the allocated memory to zero. */
7317 cmalloc (size_t nmemb
, size_t size
)
7319 /* Check for overflow. */
7320 if (nmemb
>= ~(size_t) 0 / size
)
7323 return xmalloc (nmemb
* size
);
7326 /* Like xmalloc, but takes two parameters like calloc.
7327 Verifies that the first parameter is not too large.
7328 Note: does *not* initialise the allocated memory to zero. */
7330 xcmalloc (size_t nmemb
, size_t size
)
7332 /* Check for overflow. */
7333 if (nmemb
>= ~(size_t) 0 / size
)
7336 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
7341 return xmalloc (nmemb
* size
);
7344 /* Like xrealloc, but takes three parameters.
7345 Verifies that the second parameter is not too large.
7346 Note: does *not* initialise any new memory to zero. */
7348 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
7350 /* Check for overflow. */
7351 if (nmemb
>= ~(size_t) 0 / size
)
7354 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
7359 return xrealloc (ptr
, nmemb
* size
);
7362 /* Like xcalloc, but verifies that the first parameter is not too large. */
7364 xcalloc2 (size_t nmemb
, size_t size
)
7366 /* Check for overflow. */
7367 if (nmemb
>= ~(size_t) 0 / size
)
7370 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
7375 return xcalloc (nmemb
, size
);
7379 free_debug_memory (void)
7385 for (i
= 0; i
< max
; i
++)
7386 free_debug_section ((enum dwarf_section_display_enum
) i
);
7388 if (debug_information
!= NULL
)
7390 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
7392 for (i
= 0; i
< num_debug_info_entries
; i
++)
7394 if (!debug_information
[i
].max_loc_offsets
)
7396 free (debug_information
[i
].loc_offsets
);
7397 free (debug_information
[i
].have_frame_base
);
7399 if (!debug_information
[i
].max_range_lists
)
7400 free (debug_information
[i
].range_lists
);
7403 free (debug_information
);
7404 debug_information
= NULL
;
7405 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
7410 dwarf_select_sections_by_names (const char *names
)
7414 const char * option
;
7418 debug_dump_long_opts
;
7420 static const debug_dump_long_opts opts_table
[] =
7422 /* Please keep this table alpha- sorted. */
7423 { "Ranges", & do_debug_ranges
, 1 },
7424 { "abbrev", & do_debug_abbrevs
, 1 },
7425 { "addr", & do_debug_addr
, 1 },
7426 { "aranges", & do_debug_aranges
, 1 },
7427 { "cu_index", & do_debug_cu_index
, 1 },
7428 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
7429 { "frames", & do_debug_frames
, 1 },
7430 { "frames-interp", & do_debug_frames_interp
, 1 },
7431 /* The special .gdb_index section. */
7432 { "gdb_index", & do_gdb_index
, 1 },
7433 { "info", & do_debug_info
, 1 },
7434 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
7435 { "loc", & do_debug_loc
, 1 },
7436 { "macro", & do_debug_macinfo
, 1 },
7437 { "pubnames", & do_debug_pubnames
, 1 },
7438 { "pubtypes", & do_debug_pubtypes
, 1 },
7439 /* This entry is for compatability
7440 with earlier versions of readelf. */
7441 { "ranges", & do_debug_aranges
, 1 },
7442 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
7443 { "str", & do_debug_str
, 1 },
7444 /* These trace_* sections are used by Itanium VMS. */
7445 { "trace_abbrev", & do_trace_abbrevs
, 1 },
7446 { "trace_aranges", & do_trace_aranges
, 1 },
7447 { "trace_info", & do_trace_info
, 1 },
7456 const debug_dump_long_opts
* entry
;
7458 for (entry
= opts_table
; entry
->option
; entry
++)
7460 size_t len
= strlen (entry
->option
);
7462 if (strncmp (p
, entry
->option
, len
) == 0
7463 && (p
[len
] == ',' || p
[len
] == '\0'))
7465 * entry
->variable
|= entry
->val
;
7467 /* The --debug-dump=frames-interp option also
7468 enables the --debug-dump=frames option. */
7469 if (do_debug_frames_interp
)
7470 do_debug_frames
= 1;
7477 if (entry
->option
== NULL
)
7479 warn (_("Unrecognized debug option '%s'\n"), p
);
7480 p
= strchr (p
, ',');
7491 dwarf_select_sections_by_letters (const char *letters
)
7493 unsigned int lindex
= 0;
7495 while (letters
[lindex
])
7496 switch (letters
[lindex
++])
7503 do_debug_abbrevs
= 1;
7507 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
7511 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
7515 do_debug_pubnames
= 1;
7519 do_debug_pubtypes
= 1;
7523 do_debug_aranges
= 1;
7527 do_debug_ranges
= 1;
7531 do_debug_frames_interp
= 1;
7533 do_debug_frames
= 1;
7537 do_debug_macinfo
= 1;
7549 warn (_("Unrecognized debug option '%s'\n"), letters
);
7555 dwarf_select_sections_all (void)
7558 do_debug_abbrevs
= 1;
7559 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
7560 do_debug_pubnames
= 1;
7561 do_debug_pubtypes
= 1;
7562 do_debug_aranges
= 1;
7563 do_debug_ranges
= 1;
7564 do_debug_frames
= 1;
7565 do_debug_macinfo
= 1;
7570 do_trace_abbrevs
= 1;
7571 do_trace_aranges
= 1;
7573 do_debug_cu_index
= 1;
7576 struct dwarf_section_display debug_displays
[] =
7578 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7579 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
7580 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7581 display_debug_aranges
, &do_debug_aranges
, TRUE
},
7582 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7583 display_debug_frames
, &do_debug_frames
, TRUE
},
7584 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
7585 display_debug_info
, &do_debug_info
, TRUE
},
7586 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7587 display_debug_lines
, &do_debug_lines
, TRUE
},
7588 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7589 display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
7590 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7591 display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
7592 { { ".eh_frame", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7593 display_debug_frames
, &do_debug_frames
, TRUE
},
7594 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7595 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
7596 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7597 display_debug_macro
, &do_debug_macinfo
, TRUE
},
7598 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7599 display_debug_str
, &do_debug_str
, FALSE
},
7600 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7601 display_debug_loc
, &do_debug_loc
, TRUE
},
7602 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7603 display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
7604 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7605 display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
7606 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7607 display_debug_ranges
, &do_debug_ranges
, TRUE
},
7608 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7609 display_debug_not_supported
, NULL
, FALSE
},
7610 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7611 display_debug_not_supported
, NULL
, FALSE
},
7612 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
7613 display_debug_types
, &do_debug_info
, TRUE
},
7614 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7615 display_debug_not_supported
, NULL
, FALSE
},
7616 { { ".gdb_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7617 display_gdb_index
, &do_gdb_index
, FALSE
},
7618 { { ".trace_info", "", NULL
, NULL
, 0, 0, trace_abbrev
, NULL
, 0, NULL
},
7619 display_trace_info
, &do_trace_info
, TRUE
},
7620 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7621 display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
7622 { { ".trace_aranges", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7623 display_debug_aranges
, &do_trace_aranges
, FALSE
},
7624 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
7625 display_debug_info
, &do_debug_info
, TRUE
},
7626 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7627 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
7628 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
7629 display_debug_types
, &do_debug_info
, TRUE
},
7630 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7631 display_debug_lines
, &do_debug_lines
, TRUE
},
7632 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7633 display_debug_loc
, &do_debug_loc
, TRUE
},
7634 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7635 display_debug_macro
, &do_debug_macinfo
, TRUE
},
7636 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7637 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
7638 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7639 display_debug_str
, &do_debug_str
, TRUE
},
7640 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7641 display_debug_str_offsets
, NULL
, FALSE
},
7642 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7643 display_debug_str_offsets
, NULL
, FALSE
},
7644 { { ".debug_addr", ".zdebug_addr", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7645 display_debug_addr
, &do_debug_addr
, TRUE
},
7646 { { ".debug_cu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7647 display_cu_index
, &do_debug_cu_index
, FALSE
},
7648 { { ".debug_tu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7649 display_cu_index
, &do_debug_cu_index
, FALSE
},