1 /* dwarf.c -- display DWARF contents of a BFD binary file
2 Copyright (C) 2005-2016 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 unsigned int amount = (AMOUNT); \
321 if (sizeof (VAL) < amount) \
323 error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\
324 amount, (int) sizeof (VAL)); \
325 amount = sizeof (VAL); \
327 if (((PTR) + amount) >= (END)) \
330 amount = (END) - (PTR); \
334 if (amount == 0 || amount > 8) \
337 VAL = byte_get ((PTR), amount); \
341 #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
344 SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
349 #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \
352 unsigned int amount = (AMOUNT); \
353 if (((PTR) + amount) >= (END)) \
356 amount = (END) - (PTR); \
361 VAL = byte_get_signed ((PTR), amount); \
367 #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
370 SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \
375 #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \
378 if (((PTR) + 8) <= (END)) \
380 byte_get_64 ((PTR), (HIGH), (LOW)); \
384 * (LOW) = * (HIGH) = 0; \
389 typedef struct State_Machine_Registers
397 unsigned char op_index
;
398 unsigned char end_sequence
;
399 /* This variable hold the number of the last entry seen
400 in the File Table. */
401 unsigned int last_file_entry
;
404 static SMR state_machine_regs
;
407 reset_state_machine (int is_stmt
)
409 state_machine_regs
.address
= 0;
410 state_machine_regs
.op_index
= 0;
411 state_machine_regs
.file
= 1;
412 state_machine_regs
.line
= 1;
413 state_machine_regs
.column
= 0;
414 state_machine_regs
.is_stmt
= is_stmt
;
415 state_machine_regs
.basic_block
= 0;
416 state_machine_regs
.end_sequence
= 0;
417 state_machine_regs
.last_file_entry
= 0;
420 /* Handled an extend line op.
421 Returns the number of bytes read. */
424 process_extended_line_op (unsigned char * data
,
428 unsigned char op_code
;
429 unsigned int bytes_read
;
432 unsigned char *orig_data
= data
;
435 len
= read_uleb128 (data
, & bytes_read
, end
);
438 if (len
== 0 || data
== end
|| len
> (uintptr_t) (end
- data
))
440 warn (_("Badly formed extended line op encountered!\n"));
447 printf (_(" Extended opcode %d: "), op_code
);
451 case DW_LNE_end_sequence
:
452 printf (_("End of Sequence\n\n"));
453 reset_state_machine (is_stmt
);
456 case DW_LNE_set_address
:
457 /* PR 17512: file: 002-100480-0.004. */
458 if (len
- bytes_read
- 1 > 8)
460 warn (_("Length (%d) of DW_LNE_set_address op is too long\n"),
461 len
- bytes_read
- 1);
465 SAFE_BYTE_GET (adr
, data
, len
- bytes_read
- 1, end
);
466 printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr
));
467 state_machine_regs
.address
= adr
;
468 state_machine_regs
.op_index
= 0;
471 case DW_LNE_define_file
:
472 printf (_("define new File Table entry\n"));
473 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
474 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
477 data
+= strnlen ((char *) data
, end
- data
) + 1;
478 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
480 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
482 printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
484 printf ("%s\n\n", name
);
486 if (((unsigned int) (data
- orig_data
) != len
) || data
== end
)
487 warn (_("DW_LNE_define_file: Bad opcode length\n"));
490 case DW_LNE_set_discriminator
:
491 printf (_("set Discriminator to %s\n"),
492 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
496 case DW_LNE_HP_negate_is_UV_update
:
497 printf ("DW_LNE_HP_negate_is_UV_update\n");
499 case DW_LNE_HP_push_context
:
500 printf ("DW_LNE_HP_push_context\n");
502 case DW_LNE_HP_pop_context
:
503 printf ("DW_LNE_HP_pop_context\n");
505 case DW_LNE_HP_set_file_line_column
:
506 printf ("DW_LNE_HP_set_file_line_column\n");
508 case DW_LNE_HP_set_routine_name
:
509 printf ("DW_LNE_HP_set_routine_name\n");
511 case DW_LNE_HP_set_sequence
:
512 printf ("DW_LNE_HP_set_sequence\n");
514 case DW_LNE_HP_negate_post_semantics
:
515 printf ("DW_LNE_HP_negate_post_semantics\n");
517 case DW_LNE_HP_negate_function_exit
:
518 printf ("DW_LNE_HP_negate_function_exit\n");
520 case DW_LNE_HP_negate_front_end_logical
:
521 printf ("DW_LNE_HP_negate_front_end_logical\n");
523 case DW_LNE_HP_define_proc
:
524 printf ("DW_LNE_HP_define_proc\n");
526 case DW_LNE_HP_source_file_correlation
:
528 unsigned char *edata
= data
+ len
- bytes_read
- 1;
530 printf ("DW_LNE_HP_source_file_correlation\n");
536 opc
= read_uleb128 (data
, & bytes_read
, edata
);
541 case DW_LNE_HP_SFC_formfeed
:
542 printf (" DW_LNE_HP_SFC_formfeed\n");
544 case DW_LNE_HP_SFC_set_listing_line
:
545 printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n",
547 read_uleb128 (data
, & bytes_read
, edata
)));
550 case DW_LNE_HP_SFC_associate
:
551 printf (" DW_LNE_HP_SFC_associate ");
554 read_uleb128 (data
, & bytes_read
, edata
)));
558 read_uleb128 (data
, & bytes_read
, edata
)));
562 read_uleb128 (data
, & bytes_read
, edata
)));
566 printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc
);
576 unsigned int rlen
= len
- bytes_read
- 1;
578 if (op_code
>= DW_LNE_lo_user
579 /* The test against DW_LNW_hi_user is redundant due to
580 the limited range of the unsigned char data type used
582 /*&& op_code <= DW_LNE_hi_user*/)
583 printf (_("user defined: "));
585 printf (_("UNKNOWN: "));
586 printf (_("length %d ["), rlen
);
588 printf (" %02x", *data
++);
597 static const unsigned char *
598 fetch_indirect_string (dwarf_vma offset
)
600 struct dwarf_section
*section
= &debug_displays
[str
].section
;
602 if (section
->start
== NULL
)
603 return (const unsigned char *) _("<no .debug_str section>");
605 if (offset
> section
->size
)
607 warn (_("DW_FORM_strp offset too big: %s\n"),
608 dwarf_vmatoa ("x", offset
));
609 return (const unsigned char *) _("<offset is too big>");
612 return (const unsigned char *) section
->start
+ offset
;
616 fetch_indexed_string (dwarf_vma idx
, struct cu_tu_set
*this_set
,
617 dwarf_vma offset_size
, int dwo
)
619 enum dwarf_section_display_enum str_sec_idx
= dwo
? str_dwo
: str
;
620 enum dwarf_section_display_enum idx_sec_idx
= dwo
? str_index_dwo
: str_index
;
621 struct dwarf_section
*index_section
= &debug_displays
[idx_sec_idx
].section
;
622 struct dwarf_section
*str_section
= &debug_displays
[str_sec_idx
].section
;
623 dwarf_vma index_offset
= idx
* offset_size
;
624 dwarf_vma str_offset
;
626 if (index_section
->start
== NULL
)
627 return (dwo
? _("<no .debug_str_offsets.dwo section>")
628 : _("<no .debug_str_offsets section>"));
630 if (this_set
!= NULL
)
631 index_offset
+= this_set
->section_offsets
[DW_SECT_STR_OFFSETS
];
632 if (index_offset
> index_section
->size
)
634 warn (_("DW_FORM_GNU_str_index offset too big: %s\n"),
635 dwarf_vmatoa ("x", index_offset
));
636 return _("<index offset is too big>");
639 if (str_section
->start
== NULL
)
640 return (dwo
? _("<no .debug_str.dwo section>")
641 : _("<no .debug_str section>"));
643 str_offset
= byte_get (index_section
->start
+ index_offset
, offset_size
);
644 str_offset
-= str_section
->address
;
645 if (str_offset
> str_section
->size
)
647 warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"),
648 dwarf_vmatoa ("x", str_offset
));
649 return _("<indirect index offset is too big>");
652 return (const char *) str_section
->start
+ str_offset
;
656 fetch_indexed_value (dwarf_vma offset
, dwarf_vma bytes
)
658 struct dwarf_section
*section
= &debug_displays
[debug_addr
].section
;
660 if (section
->start
== NULL
)
661 return (_("<no .debug_addr section>"));
663 if (offset
+ bytes
> section
->size
)
665 warn (_("Offset into section %s too big: %s\n"),
666 section
->name
, dwarf_vmatoa ("x", offset
));
667 return "<offset too big>";
670 return dwarf_vmatoa ("x", byte_get (section
->start
+ offset
, bytes
));
674 /* FIXME: There are better and more efficient ways to handle
675 these structures. For now though, I just want something that
676 is simple to implement. */
677 typedef struct abbrev_attr
679 unsigned long attribute
;
681 struct abbrev_attr
*next
;
685 typedef struct abbrev_entry
690 struct abbrev_attr
*first_attr
;
691 struct abbrev_attr
*last_attr
;
692 struct abbrev_entry
*next
;
696 static abbrev_entry
*first_abbrev
= NULL
;
697 static abbrev_entry
*last_abbrev
= NULL
;
704 for (abbrv
= first_abbrev
; abbrv
;)
706 abbrev_entry
*next_abbrev
= abbrv
->next
;
709 for (attr
= abbrv
->first_attr
; attr
;)
711 abbrev_attr
*next_attr
= attr
->next
;
721 last_abbrev
= first_abbrev
= NULL
;
725 add_abbrev (unsigned long number
, unsigned long tag
, int children
)
729 entry
= (abbrev_entry
*) malloc (sizeof (*entry
));
734 entry
->entry
= number
;
736 entry
->children
= children
;
737 entry
->first_attr
= NULL
;
738 entry
->last_attr
= NULL
;
741 if (first_abbrev
== NULL
)
742 first_abbrev
= entry
;
744 last_abbrev
->next
= entry
;
750 add_abbrev_attr (unsigned long attribute
, unsigned long form
)
754 attr
= (abbrev_attr
*) malloc (sizeof (*attr
));
759 attr
->attribute
= attribute
;
763 if (last_abbrev
->first_attr
== NULL
)
764 last_abbrev
->first_attr
= attr
;
766 last_abbrev
->last_attr
->next
= attr
;
768 last_abbrev
->last_attr
= attr
;
771 /* Processes the (partial) contents of a .debug_abbrev section.
772 Returns NULL if the end of the section was encountered.
773 Returns the address after the last byte read if the end of
774 an abbreviation set was found. */
776 static unsigned char *
777 process_abbrev_section (unsigned char *start
, unsigned char *end
)
779 if (first_abbrev
!= NULL
)
784 unsigned int bytes_read
;
787 unsigned long attribute
;
790 entry
= read_uleb128 (start
, & bytes_read
, end
);
793 /* A single zero is supposed to end the section according
794 to the standard. If there's more, then signal that to
801 tag
= read_uleb128 (start
, & bytes_read
, end
);
808 add_abbrev (entry
, tag
, children
);
814 attribute
= read_uleb128 (start
, & bytes_read
, end
);
819 form
= read_uleb128 (start
, & bytes_read
, end
);
824 add_abbrev_attr (attribute
, form
);
826 while (attribute
!= 0);
829 /* Report the missing single zero which ends the section. */
830 error (_(".debug_abbrev section not zero terminated\n"));
836 get_TAG_name (unsigned long tag
)
838 const char *name
= get_DW_TAG_name ((unsigned int)tag
);
842 static char buffer
[100];
844 snprintf (buffer
, sizeof (buffer
), _("Unknown TAG value: %lx"), tag
);
852 get_FORM_name (unsigned long form
)
857 return "DW_FORM value: 0";
859 name
= get_DW_FORM_name (form
);
862 static char buffer
[100];
864 snprintf (buffer
, sizeof (buffer
), _("Unknown FORM value: %lx"), form
);
871 static unsigned char *
872 display_block (unsigned char *data
,
874 const unsigned char * const end
)
878 printf (_(" %s byte block: "), dwarf_vmatoa ("u", length
));
880 return (unsigned char *) end
;
882 maxlen
= (dwarf_vma
) (end
- data
);
883 length
= length
> maxlen
? maxlen
: length
;
886 printf ("%lx ", (unsigned long) byte_get (data
++, 1));
892 decode_location_expression (unsigned char * data
,
893 unsigned int pointer_size
,
894 unsigned int offset_size
,
898 struct dwarf_section
* section
)
901 unsigned int bytes_read
;
903 dwarf_signed_vma svalue
;
904 unsigned char *end
= data
+ length
;
905 int need_frame_base
= 0;
914 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
915 printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue
));
918 printf ("DW_OP_deref");
921 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
922 printf ("DW_OP_const1u: %lu", (unsigned long) uvalue
);
925 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 1, end
);
926 printf ("DW_OP_const1s: %ld", (long) svalue
);
929 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
930 printf ("DW_OP_const2u: %lu", (unsigned long) uvalue
);
933 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
934 printf ("DW_OP_const2s: %ld", (long) svalue
);
937 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
938 printf ("DW_OP_const4u: %lu", (unsigned long) uvalue
);
941 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
942 printf ("DW_OP_const4s: %ld", (long) svalue
);
945 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
946 printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue
);
947 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
948 printf ("%lu", (unsigned long) uvalue
);
951 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
952 printf ("DW_OP_const8s: %ld ", (long) svalue
);
953 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
954 printf ("%ld", (long) svalue
);
957 printf ("DW_OP_constu: %s",
958 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
962 printf ("DW_OP_consts: %s",
963 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
967 printf ("DW_OP_dup");
970 printf ("DW_OP_drop");
973 printf ("DW_OP_over");
976 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
977 printf ("DW_OP_pick: %ld", (unsigned long) uvalue
);
980 printf ("DW_OP_swap");
983 printf ("DW_OP_rot");
986 printf ("DW_OP_xderef");
989 printf ("DW_OP_abs");
992 printf ("DW_OP_and");
995 printf ("DW_OP_div");
998 printf ("DW_OP_minus");
1001 printf ("DW_OP_mod");
1004 printf ("DW_OP_mul");
1007 printf ("DW_OP_neg");
1010 printf ("DW_OP_not");
1013 printf ("DW_OP_or");
1016 printf ("DW_OP_plus");
1018 case DW_OP_plus_uconst
:
1019 printf ("DW_OP_plus_uconst: %s",
1020 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1024 printf ("DW_OP_shl");
1027 printf ("DW_OP_shr");
1030 printf ("DW_OP_shra");
1033 printf ("DW_OP_xor");
1036 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1037 printf ("DW_OP_bra: %ld", (long) svalue
);
1040 printf ("DW_OP_eq");
1043 printf ("DW_OP_ge");
1046 printf ("DW_OP_gt");
1049 printf ("DW_OP_le");
1052 printf ("DW_OP_lt");
1055 printf ("DW_OP_ne");
1058 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1059 printf ("DW_OP_skip: %ld", (long) svalue
);
1094 printf ("DW_OP_lit%d", op
- DW_OP_lit0
);
1129 printf ("DW_OP_reg%d (%s)", op
- DW_OP_reg0
,
1130 regname (op
- DW_OP_reg0
, 1));
1165 printf ("DW_OP_breg%d (%s): %s",
1167 regname (op
- DW_OP_breg0
, 1),
1168 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1173 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1175 printf ("DW_OP_regx: %s (%s)",
1176 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1179 need_frame_base
= 1;
1180 printf ("DW_OP_fbreg: %s",
1181 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1185 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1187 printf ("DW_OP_bregx: %s (%s) %s",
1188 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1),
1189 dwarf_vmatoa ("d", read_sleb128 (data
, &bytes_read
, end
)));
1193 printf ("DW_OP_piece: %s",
1194 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1197 case DW_OP_deref_size
:
1198 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1199 printf ("DW_OP_deref_size: %ld", (long) uvalue
);
1201 case DW_OP_xderef_size
:
1202 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1203 printf ("DW_OP_xderef_size: %ld", (long) uvalue
);
1206 printf ("DW_OP_nop");
1209 /* DWARF 3 extensions. */
1210 case DW_OP_push_object_address
:
1211 printf ("DW_OP_push_object_address");
1214 /* XXX: Strictly speaking for 64-bit DWARF3 files
1215 this ought to be an 8-byte wide computation. */
1216 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 2, end
);
1217 printf ("DW_OP_call2: <0x%s>",
1218 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1221 /* XXX: Strictly speaking for 64-bit DWARF3 files
1222 this ought to be an 8-byte wide computation. */
1223 SAFE_SIGNED_BYTE_GET_AND_INC (svalue
, data
, 4, end
);
1224 printf ("DW_OP_call4: <0x%s>",
1225 dwarf_vmatoa ("x", svalue
+ cu_offset
));
1227 case DW_OP_call_ref
:
1228 /* XXX: Strictly speaking for 64-bit DWARF3 files
1229 this ought to be an 8-byte wide computation. */
1230 if (dwarf_version
== -1)
1232 printf (_("(DW_OP_call_ref in frame info)"));
1233 /* No way to tell where the next op is, so just bail. */
1234 return need_frame_base
;
1236 if (dwarf_version
== 2)
1238 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1242 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1244 printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue
));
1246 case DW_OP_form_tls_address
:
1247 printf ("DW_OP_form_tls_address");
1249 case DW_OP_call_frame_cfa
:
1250 printf ("DW_OP_call_frame_cfa");
1252 case DW_OP_bit_piece
:
1253 printf ("DW_OP_bit_piece: ");
1254 printf (_("size: %s "),
1255 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1257 printf (_("offset: %s "),
1258 dwarf_vmatoa ("u", read_uleb128 (data
, &bytes_read
, end
)));
1262 /* DWARF 4 extensions. */
1263 case DW_OP_stack_value
:
1264 printf ("DW_OP_stack_value");
1267 case DW_OP_implicit_value
:
1268 printf ("DW_OP_implicit_value");
1269 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1271 data
= display_block (data
, uvalue
, end
);
1274 /* GNU extensions. */
1275 case DW_OP_GNU_push_tls_address
:
1276 printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown"));
1278 case DW_OP_GNU_uninit
:
1279 printf ("DW_OP_GNU_uninit");
1280 /* FIXME: Is there data associated with this OP ? */
1282 case DW_OP_GNU_encoded_addr
:
1289 addr
= get_encoded_value (&data
, encoding
, section
, end
);
1291 printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding
);
1292 print_dwarf_vma (addr
, pointer_size
);
1295 case DW_OP_GNU_implicit_pointer
:
1296 /* XXX: Strictly speaking for 64-bit DWARF3 files
1297 this ought to be an 8-byte wide computation. */
1298 if (dwarf_version
== -1)
1300 printf (_("(DW_OP_GNU_implicit_pointer in frame info)"));
1301 /* No way to tell where the next op is, so just bail. */
1302 return need_frame_base
;
1304 if (dwarf_version
== 2)
1306 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1310 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1312 printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s",
1313 dwarf_vmatoa ("x", uvalue
),
1314 dwarf_vmatoa ("d", read_sleb128 (data
,
1315 &bytes_read
, end
)));
1318 case DW_OP_GNU_entry_value
:
1319 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1321 /* PR 17531: file: 0cc9cd00. */
1322 if (uvalue
> (dwarf_vma
) (end
- data
))
1323 uvalue
= end
- data
;
1324 printf ("DW_OP_GNU_entry_value: (");
1325 if (decode_location_expression (data
, pointer_size
, offset_size
,
1326 dwarf_version
, uvalue
,
1327 cu_offset
, section
))
1328 need_frame_base
= 1;
1334 case DW_OP_GNU_const_type
:
1335 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1337 printf ("DW_OP_GNU_const_type: <0x%s> ",
1338 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1339 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1340 data
= display_block (data
, uvalue
, end
);
1342 case DW_OP_GNU_regval_type
:
1343 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1345 printf ("DW_OP_GNU_regval_type: %s (%s)",
1346 dwarf_vmatoa ("u", uvalue
), regname (uvalue
, 1));
1347 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1349 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1351 case DW_OP_GNU_deref_type
:
1352 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1353 printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue
);
1354 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1356 printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1358 case DW_OP_GNU_convert
:
1359 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1361 printf ("DW_OP_GNU_convert <0x%s>",
1362 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1364 case DW_OP_GNU_reinterpret
:
1365 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1367 printf ("DW_OP_GNU_reinterpret <0x%s>",
1368 dwarf_vmatoa ("x", uvalue
? cu_offset
+ uvalue
: 0));
1370 case DW_OP_GNU_parameter_ref
:
1371 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1372 printf ("DW_OP_GNU_parameter_ref: <0x%s>",
1373 dwarf_vmatoa ("x", cu_offset
+ uvalue
));
1375 case DW_OP_GNU_addr_index
:
1376 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1378 printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1380 case DW_OP_GNU_const_index
:
1381 uvalue
= read_uleb128 (data
, &bytes_read
, end
);
1383 printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue
));
1386 /* HP extensions. */
1387 case DW_OP_HP_is_value
:
1388 printf ("DW_OP_HP_is_value");
1389 /* FIXME: Is there data associated with this OP ? */
1391 case DW_OP_HP_fltconst4
:
1392 printf ("DW_OP_HP_fltconst4");
1393 /* FIXME: Is there data associated with this OP ? */
1395 case DW_OP_HP_fltconst8
:
1396 printf ("DW_OP_HP_fltconst8");
1397 /* FIXME: Is there data associated with this OP ? */
1399 case DW_OP_HP_mod_range
:
1400 printf ("DW_OP_HP_mod_range");
1401 /* FIXME: Is there data associated with this OP ? */
1403 case DW_OP_HP_unmod_range
:
1404 printf ("DW_OP_HP_unmod_range");
1405 /* FIXME: Is there data associated with this OP ? */
1408 printf ("DW_OP_HP_tls");
1409 /* FIXME: Is there data associated with this OP ? */
1412 /* PGI (STMicroelectronics) extensions. */
1413 case DW_OP_PGI_omp_thread_num
:
1414 /* Pushes the thread number for the current thread as it would be
1415 returned by the standard OpenMP library function:
1416 omp_get_thread_num(). The "current thread" is the thread for
1417 which the expression is being evaluated. */
1418 printf ("DW_OP_PGI_omp_thread_num");
1422 if (op
>= DW_OP_lo_user
1423 && op
<= DW_OP_hi_user
)
1424 printf (_("(User defined location op)"));
1426 printf (_("(Unknown location op)"));
1427 /* No way to tell where the next op is, so just bail. */
1428 return need_frame_base
;
1431 /* Separate the ops. */
1436 return need_frame_base
;
1439 /* Find the CU or TU set corresponding to the given CU_OFFSET.
1440 This is used for DWARF package files. */
1442 static struct cu_tu_set
*
1443 find_cu_tu_set_v2 (dwarf_vma cu_offset
, int do_types
)
1445 struct cu_tu_set
*p
;
1447 unsigned int dw_sect
;
1453 dw_sect
= DW_SECT_TYPES
;
1459 dw_sect
= DW_SECT_INFO
;
1463 if (p
->section_offsets
[dw_sect
] == cu_offset
)
1471 /* Add INC to HIGH_BITS:LOW_BITS. */
1473 add64 (dwarf_vma
* high_bits
, dwarf_vma
* low_bits
, dwarf_vma inc
)
1475 dwarf_vma tmp
= * low_bits
;
1479 /* FIXME: There is probably a better way of handling this:
1481 We need to cope with dwarf_vma being a 32-bit or 64-bit
1482 type. Plus regardless of its size LOW_BITS is meant to
1483 only hold 32-bits, so if there is overflow or wrap around
1484 we must propagate into HIGH_BITS. */
1485 if (tmp
< * low_bits
)
1489 else if (sizeof (tmp
) > 8
1499 static unsigned char *
1500 read_and_display_attr_value (unsigned long attribute
,
1502 unsigned char * data
,
1503 unsigned char * end
,
1504 dwarf_vma cu_offset
,
1505 dwarf_vma pointer_size
,
1506 dwarf_vma offset_size
,
1508 debug_info
* debug_info_p
,
1510 struct dwarf_section
* section
,
1511 struct cu_tu_set
* this_set
)
1513 dwarf_vma uvalue
= 0;
1514 unsigned char *block_start
= NULL
;
1515 unsigned char * orig_data
= data
;
1516 unsigned int bytes_read
;
1518 if (data
> end
|| (data
== end
&& form
!= DW_FORM_flag_present
))
1520 warn (_("Corrupt attribute\n"));
1529 case DW_FORM_ref_addr
:
1530 if (dwarf_version
== 2)
1531 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1532 else if (dwarf_version
== 3 || dwarf_version
== 4)
1533 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1535 error (_("Internal error: DWARF version is not 2, 3 or 4.\n"));
1540 SAFE_BYTE_GET_AND_INC (uvalue
, data
, pointer_size
, end
);
1544 case DW_FORM_sec_offset
:
1545 case DW_FORM_GNU_ref_alt
:
1546 case DW_FORM_GNU_strp_alt
:
1547 SAFE_BYTE_GET_AND_INC (uvalue
, data
, offset_size
, end
);
1550 case DW_FORM_flag_present
:
1557 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 1, end
);
1562 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 2, end
);
1567 SAFE_BYTE_GET_AND_INC (uvalue
, data
, 4, end
);
1571 uvalue
= read_sleb128 (data
, & bytes_read
, end
);
1575 case DW_FORM_GNU_str_index
:
1576 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1580 case DW_FORM_ref_udata
:
1582 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1586 case DW_FORM_indirect
:
1587 form
= read_uleb128 (data
, & bytes_read
, end
);
1590 printf (" %s", get_FORM_name (form
));
1591 return read_and_display_attr_value (attribute
, form
, data
, end
,
1592 cu_offset
, pointer_size
,
1593 offset_size
, dwarf_version
,
1594 debug_info_p
, do_loc
,
1596 case DW_FORM_GNU_addr_index
:
1597 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1604 case DW_FORM_ref_addr
:
1606 printf (" <0x%s>", dwarf_vmatoa ("x",uvalue
));
1609 case DW_FORM_GNU_ref_alt
:
1611 printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue
));
1617 case DW_FORM_ref_udata
:
1619 printf (" <0x%s>", dwarf_vmatoa ("x", uvalue
+ cu_offset
));
1624 case DW_FORM_sec_offset
:
1626 printf (" 0x%s", dwarf_vmatoa ("x", uvalue
));
1629 case DW_FORM_flag_present
:
1636 printf (" %s", dwarf_vmatoa ("d", uvalue
));
1643 dwarf_vma high_bits
;
1647 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1649 if (form
== DW_FORM_ref8
)
1650 add64 (& high_bits
, & utmp
, cu_offset
);
1652 dwarf_vmatoa64 (high_bits
, utmp
, buf
, sizeof (buf
)));
1655 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1656 && num_debug_info_entries
== 0)
1658 if (sizeof (uvalue
) == 8)
1659 SAFE_BYTE_GET (uvalue
, data
, 8, end
);
1661 error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n"));
1667 case DW_FORM_string
:
1669 printf (" %.*s", (int) (end
- data
), data
);
1670 data
+= strnlen ((char *) data
, end
- data
) + 1;
1674 case DW_FORM_exprloc
:
1675 uvalue
= read_uleb128 (data
, & bytes_read
, end
);
1676 block_start
= data
+ bytes_read
;
1677 if (block_start
>= end
)
1679 warn (_("Block ends prematurely\n"));
1683 /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with
1684 gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute
1685 block_start + uvalue here. */
1686 data
= block_start
+ uvalue
;
1687 /* PR 17512: file: 008-103549-0.001:0.1. */
1688 if (block_start
+ uvalue
> end
|| data
< block_start
)
1690 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1691 uvalue
= end
- block_start
;
1694 data
= block_start
+ uvalue
;
1696 data
= display_block (block_start
, uvalue
, end
);
1699 case DW_FORM_block1
:
1700 SAFE_BYTE_GET (uvalue
, data
, 1, end
);
1701 block_start
= data
+ 1;
1702 if (block_start
>= end
)
1704 warn (_("Block ends prematurely\n"));
1708 data
= block_start
+ uvalue
;
1709 if (block_start
+ uvalue
> end
|| data
< block_start
)
1711 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1712 uvalue
= end
- block_start
;
1715 data
= block_start
+ uvalue
;
1717 data
= display_block (block_start
, uvalue
, end
);
1720 case DW_FORM_block2
:
1721 SAFE_BYTE_GET (uvalue
, data
, 2, end
);
1722 block_start
= data
+ 2;
1723 if (block_start
>= end
)
1725 warn (_("Block ends prematurely\n"));
1729 data
= block_start
+ uvalue
;
1730 if (block_start
+ uvalue
> end
|| data
< block_start
)
1732 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1733 uvalue
= end
- block_start
;
1736 data
= block_start
+ uvalue
;
1738 data
= display_block (block_start
, uvalue
, end
);
1741 case DW_FORM_block4
:
1742 SAFE_BYTE_GET (uvalue
, data
, 4, end
);
1743 block_start
= data
+ 4;
1744 /* PR 17512: file: 3371-3907-0.004. */
1745 if (block_start
>= end
)
1747 warn (_("Block ends prematurely\n"));
1751 data
= block_start
+ uvalue
;
1752 if (block_start
+ uvalue
> end
1753 /* PR 17531: file: 5b5f0592. */
1754 || data
< block_start
)
1756 warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue
);
1757 uvalue
= end
- block_start
;
1760 data
= block_start
+ uvalue
;
1762 data
= display_block (block_start
, uvalue
, end
);
1767 printf (_(" (indirect string, offset: 0x%s): %s"),
1768 dwarf_vmatoa ("x", uvalue
),
1769 fetch_indirect_string (uvalue
));
1772 case DW_FORM_GNU_str_index
:
1775 const char *suffix
= strrchr (section
->name
, '.');
1776 int dwo
= (suffix
&& strcmp (suffix
, ".dwo") == 0) ? 1 : 0;
1778 printf (_(" (indexed string: 0x%s): %s"),
1779 dwarf_vmatoa ("x", uvalue
),
1780 fetch_indexed_string (uvalue
, this_set
, offset_size
, dwo
));
1784 case DW_FORM_GNU_strp_alt
:
1786 printf (_(" (alt indirect string, offset: 0x%s)"),
1787 dwarf_vmatoa ("x", uvalue
));
1790 case DW_FORM_indirect
:
1791 /* Handled above. */
1794 case DW_FORM_ref_sig8
:
1797 dwarf_vma high_bits
;
1800 SAFE_BYTE_GET64 (data
, &high_bits
, &uvalue
, end
);
1801 printf (" signature: 0x%s",
1802 dwarf_vmatoa64 (high_bits
, uvalue
, buf
, sizeof (buf
)));
1807 case DW_FORM_GNU_addr_index
:
1809 printf (_(" (addr_index: 0x%s): %s"),
1810 dwarf_vmatoa ("x", uvalue
),
1811 fetch_indexed_value (uvalue
* pointer_size
, pointer_size
));
1815 warn (_("Unrecognized form: %lu\n"), form
);
1819 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
1820 && num_debug_info_entries
== 0
1821 && debug_info_p
!= NULL
)
1825 case DW_AT_frame_base
:
1826 have_frame_base
= 1;
1827 case DW_AT_location
:
1828 case DW_AT_string_length
:
1829 case DW_AT_return_addr
:
1830 case DW_AT_data_member_location
:
1831 case DW_AT_vtable_elem_location
:
1833 case DW_AT_static_link
:
1834 case DW_AT_use_location
:
1835 case DW_AT_GNU_call_site_value
:
1836 case DW_AT_GNU_call_site_data_value
:
1837 case DW_AT_GNU_call_site_target
:
1838 case DW_AT_GNU_call_site_target_clobbered
:
1839 if ((dwarf_version
< 4
1840 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1841 || form
== DW_FORM_sec_offset
)
1843 /* Process location list. */
1844 unsigned int lmax
= debug_info_p
->max_loc_offsets
;
1845 unsigned int num
= debug_info_p
->num_loc_offsets
;
1847 if (lmax
== 0 || num
>= lmax
)
1850 debug_info_p
->loc_offsets
= (dwarf_vma
*)
1851 xcrealloc (debug_info_p
->loc_offsets
,
1852 lmax
, sizeof (*debug_info_p
->loc_offsets
));
1853 debug_info_p
->have_frame_base
= (int *)
1854 xcrealloc (debug_info_p
->have_frame_base
,
1855 lmax
, sizeof (*debug_info_p
->have_frame_base
));
1856 debug_info_p
->max_loc_offsets
= lmax
;
1858 if (this_set
!= NULL
)
1859 uvalue
+= this_set
->section_offsets
[DW_SECT_LOC
];
1860 debug_info_p
->loc_offsets
[num
] = uvalue
;
1861 debug_info_p
->have_frame_base
[num
] = have_frame_base
;
1862 debug_info_p
->num_loc_offsets
++;
1867 if (need_base_address
)
1868 debug_info_p
->base_address
= uvalue
;
1871 case DW_AT_GNU_addr_base
:
1872 debug_info_p
->addr_base
= uvalue
;
1875 case DW_AT_GNU_ranges_base
:
1876 debug_info_p
->ranges_base
= uvalue
;
1880 if ((dwarf_version
< 4
1881 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
1882 || form
== DW_FORM_sec_offset
)
1884 /* Process range list. */
1885 unsigned int lmax
= debug_info_p
->max_range_lists
;
1886 unsigned int num
= debug_info_p
->num_range_lists
;
1888 if (lmax
== 0 || num
>= lmax
)
1891 debug_info_p
->range_lists
= (dwarf_vma
*)
1892 xcrealloc (debug_info_p
->range_lists
,
1893 lmax
, sizeof (*debug_info_p
->range_lists
));
1894 debug_info_p
->max_range_lists
= lmax
;
1896 debug_info_p
->range_lists
[num
] = uvalue
;
1897 debug_info_p
->num_range_lists
++;
1906 if (do_loc
|| attribute
== 0)
1909 /* For some attributes we can display further information. */
1916 case DW_INL_not_inlined
:
1917 printf (_("(not inlined)"));
1919 case DW_INL_inlined
:
1920 printf (_("(inlined)"));
1922 case DW_INL_declared_not_inlined
:
1923 printf (_("(declared as inline but ignored)"));
1925 case DW_INL_declared_inlined
:
1926 printf (_("(declared as inline and inlined)"));
1929 printf (_(" (Unknown inline attribute value: %s)"),
1930 dwarf_vmatoa ("x", uvalue
));
1935 case DW_AT_language
:
1939 /* Ordered by the numeric value of these constants. */
1940 case DW_LANG_C89
: printf ("(ANSI C)"); break;
1941 case DW_LANG_C
: printf ("(non-ANSI C)"); break;
1942 case DW_LANG_Ada83
: printf ("(Ada)"); break;
1943 case DW_LANG_C_plus_plus
: printf ("(C++)"); break;
1944 case DW_LANG_Cobol74
: printf ("(Cobol 74)"); break;
1945 case DW_LANG_Cobol85
: printf ("(Cobol 85)"); break;
1946 case DW_LANG_Fortran77
: printf ("(FORTRAN 77)"); break;
1947 case DW_LANG_Fortran90
: printf ("(Fortran 90)"); break;
1948 case DW_LANG_Pascal83
: printf ("(ANSI Pascal)"); break;
1949 case DW_LANG_Modula2
: printf ("(Modula 2)"); break;
1950 /* DWARF 2.1 values. */
1951 case DW_LANG_Java
: printf ("(Java)"); break;
1952 case DW_LANG_C99
: printf ("(ANSI C99)"); break;
1953 case DW_LANG_Ada95
: printf ("(ADA 95)"); break;
1954 case DW_LANG_Fortran95
: printf ("(Fortran 95)"); break;
1955 /* DWARF 3 values. */
1956 case DW_LANG_PLI
: printf ("(PLI)"); break;
1957 case DW_LANG_ObjC
: printf ("(Objective C)"); break;
1958 case DW_LANG_ObjC_plus_plus
: printf ("(Objective C++)"); break;
1959 case DW_LANG_UPC
: printf ("(Unified Parallel C)"); break;
1960 case DW_LANG_D
: printf ("(D)"); break;
1961 /* DWARF 4 values. */
1962 case DW_LANG_Python
: printf ("(Python)"); break;
1963 /* DWARF 5 values. */
1964 case DW_LANG_Go
: printf ("(Go)"); break;
1965 case DW_LANG_C_plus_plus_11
: printf ("(C++11)"); break;
1966 case DW_LANG_C11
: printf ("(C11)"); break;
1967 case DW_LANG_C_plus_plus_14
: printf ("(C++14)"); break;
1968 case DW_LANG_Fortran03
: printf ("(Fortran 03)"); break;
1969 case DW_LANG_Fortran08
: printf ("(Fortran 08)"); break;
1970 /* MIPS extension. */
1971 case DW_LANG_Mips_Assembler
: printf ("(MIPS assembler)"); break;
1972 /* UPC extension. */
1973 case DW_LANG_Upc
: printf ("(Unified Parallel C)"); break;
1975 if (uvalue
>= DW_LANG_lo_user
&& uvalue
<= DW_LANG_hi_user
)
1976 printf (_("(implementation defined: %s)"),
1977 dwarf_vmatoa ("x", uvalue
));
1979 printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue
));
1984 case DW_AT_encoding
:
1988 case DW_ATE_void
: printf ("(void)"); break;
1989 case DW_ATE_address
: printf ("(machine address)"); break;
1990 case DW_ATE_boolean
: printf ("(boolean)"); break;
1991 case DW_ATE_complex_float
: printf ("(complex float)"); break;
1992 case DW_ATE_float
: printf ("(float)"); break;
1993 case DW_ATE_signed
: printf ("(signed)"); break;
1994 case DW_ATE_signed_char
: printf ("(signed char)"); break;
1995 case DW_ATE_unsigned
: printf ("(unsigned)"); break;
1996 case DW_ATE_unsigned_char
: printf ("(unsigned char)"); break;
1997 /* DWARF 2.1 values: */
1998 case DW_ATE_imaginary_float
: printf ("(imaginary float)"); break;
1999 case DW_ATE_decimal_float
: printf ("(decimal float)"); break;
2000 /* DWARF 3 values: */
2001 case DW_ATE_packed_decimal
: printf ("(packed_decimal)"); break;
2002 case DW_ATE_numeric_string
: printf ("(numeric_string)"); break;
2003 case DW_ATE_edited
: printf ("(edited)"); break;
2004 case DW_ATE_signed_fixed
: printf ("(signed_fixed)"); break;
2005 case DW_ATE_unsigned_fixed
: printf ("(unsigned_fixed)"); break;
2006 /* HP extensions: */
2007 case DW_ATE_HP_float80
: printf ("(HP_float80)"); break;
2008 case DW_ATE_HP_complex_float80
: printf ("(HP_complex_float80)"); break;
2009 case DW_ATE_HP_float128
: printf ("(HP_float128)"); break;
2010 case DW_ATE_HP_complex_float128
:printf ("(HP_complex_float128)"); break;
2011 case DW_ATE_HP_floathpintel
: printf ("(HP_floathpintel)"); break;
2012 case DW_ATE_HP_imaginary_float80
: printf ("(HP_imaginary_float80)"); break;
2013 case DW_ATE_HP_imaginary_float128
: printf ("(HP_imaginary_float128)"); break;
2014 /* DWARF 4 values: */
2015 case DW_ATE_UTF
: printf ("(unicode string)"); break;
2018 if (uvalue
>= DW_ATE_lo_user
2019 && uvalue
<= DW_ATE_hi_user
)
2020 printf (_("(user defined type)"));
2022 printf (_("(unknown type)"));
2027 case DW_AT_accessibility
:
2031 case DW_ACCESS_public
: printf ("(public)"); break;
2032 case DW_ACCESS_protected
: printf ("(protected)"); break;
2033 case DW_ACCESS_private
: printf ("(private)"); break;
2035 printf (_("(unknown accessibility)"));
2040 case DW_AT_visibility
:
2044 case DW_VIS_local
: printf ("(local)"); break;
2045 case DW_VIS_exported
: printf ("(exported)"); break;
2046 case DW_VIS_qualified
: printf ("(qualified)"); break;
2047 default: printf (_("(unknown visibility)")); break;
2051 case DW_AT_virtuality
:
2055 case DW_VIRTUALITY_none
: printf ("(none)"); break;
2056 case DW_VIRTUALITY_virtual
: printf ("(virtual)"); break;
2057 case DW_VIRTUALITY_pure_virtual
:printf ("(pure_virtual)"); break;
2058 default: printf (_("(unknown virtuality)")); break;
2062 case DW_AT_identifier_case
:
2066 case DW_ID_case_sensitive
: printf ("(case_sensitive)"); break;
2067 case DW_ID_up_case
: printf ("(up_case)"); break;
2068 case DW_ID_down_case
: printf ("(down_case)"); break;
2069 case DW_ID_case_insensitive
: printf ("(case_insensitive)"); break;
2070 default: printf (_("(unknown case)")); break;
2074 case DW_AT_calling_convention
:
2078 case DW_CC_normal
: printf ("(normal)"); break;
2079 case DW_CC_program
: printf ("(program)"); break;
2080 case DW_CC_nocall
: printf ("(nocall)"); break;
2082 if (uvalue
>= DW_CC_lo_user
2083 && uvalue
<= DW_CC_hi_user
)
2084 printf (_("(user defined)"));
2086 printf (_("(unknown convention)"));
2090 case DW_AT_ordering
:
2094 case -1: printf (_("(undefined)")); break;
2095 case 0: printf ("(row major)"); break;
2096 case 1: printf ("(column major)"); break;
2100 case DW_AT_frame_base
:
2101 have_frame_base
= 1;
2102 case DW_AT_location
:
2103 case DW_AT_string_length
:
2104 case DW_AT_return_addr
:
2105 case DW_AT_data_member_location
:
2106 case DW_AT_vtable_elem_location
:
2108 case DW_AT_static_link
:
2109 case DW_AT_use_location
:
2110 case DW_AT_GNU_call_site_value
:
2111 case DW_AT_GNU_call_site_data_value
:
2112 case DW_AT_GNU_call_site_target
:
2113 case DW_AT_GNU_call_site_target_clobbered
:
2114 if ((dwarf_version
< 4
2115 && (form
== DW_FORM_data4
|| form
== DW_FORM_data8
))
2116 || form
== DW_FORM_sec_offset
)
2117 printf (_(" (location list)"));
2119 case DW_AT_allocated
:
2120 case DW_AT_associated
:
2121 case DW_AT_data_location
:
2123 case DW_AT_upper_bound
:
2124 case DW_AT_lower_bound
:
2127 int need_frame_base
;
2130 need_frame_base
= decode_location_expression (block_start
,
2135 cu_offset
, section
);
2137 if (need_frame_base
&& !have_frame_base
)
2138 printf (_(" [without DW_AT_frame_base]"));
2144 if (form
== DW_FORM_ref_sig8
2145 || form
== DW_FORM_GNU_ref_alt
)
2148 if (form
== DW_FORM_ref1
2149 || form
== DW_FORM_ref2
2150 || form
== DW_FORM_ref4
2151 || form
== DW_FORM_ref_udata
)
2152 uvalue
+= cu_offset
;
2154 if (uvalue
>= section
->size
)
2155 warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"),
2156 dwarf_vmatoa ("x", uvalue
),
2157 (unsigned long) (orig_data
- section
->start
));
2160 unsigned long abbrev_number
;
2161 abbrev_entry
* entry
;
2163 abbrev_number
= read_uleb128 (section
->start
+ uvalue
, NULL
, end
);
2165 printf (_("\t[Abbrev Number: %ld"), abbrev_number
);
2166 /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will
2167 use different abbrev table, and we don't track .debug_info chunks
2169 if (form
!= DW_FORM_ref_addr
)
2171 for (entry
= first_abbrev
; entry
!= NULL
; entry
= entry
->next
)
2172 if (entry
->entry
== abbrev_number
)
2175 printf (" (%s)", get_TAG_name (entry
->tag
));
2190 get_AT_name (unsigned long attribute
)
2195 return "DW_AT value: 0";
2197 /* One value is shared by the MIPS and HP extensions: */
2198 if (attribute
== DW_AT_MIPS_fde
)
2199 return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable";
2201 name
= get_DW_AT_name (attribute
);
2205 static char buffer
[100];
2207 snprintf (buffer
, sizeof (buffer
), _("Unknown AT value: %lx"),
2215 static unsigned char *
2216 read_and_display_attr (unsigned long attribute
,
2218 unsigned char * data
,
2219 unsigned char * end
,
2220 dwarf_vma cu_offset
,
2221 dwarf_vma pointer_size
,
2222 dwarf_vma offset_size
,
2224 debug_info
* debug_info_p
,
2226 struct dwarf_section
* section
,
2227 struct cu_tu_set
* this_set
)
2230 printf (" %-18s:", get_AT_name (attribute
));
2231 data
= read_and_display_attr_value (attribute
, form
, data
, end
,
2232 cu_offset
, pointer_size
, offset_size
,
2233 dwarf_version
, debug_info_p
,
2234 do_loc
, section
, this_set
);
2240 /* Process the contents of a .debug_info section. If do_loc is non-zero
2241 then we are scanning for location lists and we do not want to display
2242 anything to the user. If do_types is non-zero, we are processing
2243 a .debug_types section instead of a .debug_info section. */
2246 process_debug_info (struct dwarf_section
*section
,
2248 enum dwarf_section_display_enum abbrev_sec
,
2252 unsigned char *start
= section
->start
;
2253 unsigned char *end
= start
+ section
->size
;
2254 unsigned char *section_begin
;
2256 unsigned int num_units
= 0;
2258 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2259 && num_debug_info_entries
== 0
2264 /* First scan the section to get the number of comp units. */
2265 for (section_begin
= start
, num_units
= 0; section_begin
< end
;
2268 /* Read the first 4 bytes. For a 32-bit DWARF section, this
2269 will be the length. For a 64-bit DWARF section, it'll be
2270 the escape code 0xffffffff followed by an 8 byte length. */
2271 SAFE_BYTE_GET (length
, section_begin
, 4, end
);
2273 if (length
== 0xffffffff)
2275 SAFE_BYTE_GET (length
, section_begin
+ 4, 8, end
);
2276 section_begin
+= length
+ 12;
2278 else if (length
>= 0xfffffff0 && length
< 0xffffffff)
2280 warn (_("Reserved length value (0x%s) found in section %s\n"),
2281 dwarf_vmatoa ("x", length
), section
->name
);
2285 section_begin
+= length
+ 4;
2287 /* Negative values are illegal, they may even cause infinite
2288 looping. This can happen if we can't accurately apply
2289 relocations to an object file, or if the file is corrupt. */
2290 if ((signed long) length
<= 0 || section_begin
< start
)
2292 warn (_("Corrupt unit length (0x%s) found in section %s\n"),
2293 dwarf_vmatoa ("x", length
), section
->name
);
2300 error (_("No comp units in %s section ?\n"), section
->name
);
2304 /* Then allocate an array to hold the information. */
2305 debug_information
= (debug_info
*) cmalloc (num_units
,
2306 sizeof (* debug_information
));
2307 if (debug_information
== NULL
)
2309 error (_("Not enough memory for a debug info array of %u entries\n"),
2311 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
2314 /* PR 17531: file: 92ca3797.
2315 We cannot rely upon the debug_information array being initialised
2316 before it is used. A corrupt file could easily contain references
2317 to a unit for which information has not been made available. So
2318 we ensure that the array is zeroed here. */
2319 memset (debug_information
, 0, num_units
* sizeof (*debug_information
));
2321 alloc_num_debug_info_entries
= num_units
;
2326 if (dwarf_start_die
== 0)
2327 printf (_("Contents of the %s section:\n\n"), section
->name
);
2329 load_debug_section (str
, file
);
2330 load_debug_section (str_dwo
, file
);
2331 load_debug_section (str_index
, file
);
2332 load_debug_section (str_index_dwo
, file
);
2333 load_debug_section (debug_addr
, file
);
2336 load_debug_section (abbrev_sec
, file
);
2337 if (debug_displays
[abbrev_sec
].section
.start
== NULL
)
2339 warn (_("Unable to locate %s section!\n"),
2340 debug_displays
[abbrev_sec
].section
.name
);
2344 for (section_begin
= start
, unit
= 0; start
< end
; unit
++)
2346 DWARF2_Internal_CompUnit compunit
;
2347 unsigned char *hdrptr
;
2348 unsigned char *tags
;
2349 int level
, last_level
, saved_level
;
2350 dwarf_vma cu_offset
;
2351 unsigned int offset_size
;
2352 int initial_length_size
;
2353 dwarf_vma signature_high
= 0;
2354 dwarf_vma signature_low
= 0;
2355 dwarf_vma type_offset
= 0;
2356 struct cu_tu_set
*this_set
;
2357 dwarf_vma abbrev_base
;
2362 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 4, end
);
2364 if (compunit
.cu_length
== 0xffffffff)
2366 SAFE_BYTE_GET_AND_INC (compunit
.cu_length
, hdrptr
, 8, end
);
2368 initial_length_size
= 12;
2373 initial_length_size
= 4;
2376 SAFE_BYTE_GET_AND_INC (compunit
.cu_version
, hdrptr
, 2, end
);
2378 cu_offset
= start
- section_begin
;
2380 this_set
= find_cu_tu_set_v2 (cu_offset
, do_types
);
2382 SAFE_BYTE_GET_AND_INC (compunit
.cu_abbrev_offset
, hdrptr
, offset_size
, end
);
2384 if (this_set
== NULL
)
2387 abbrev_size
= debug_displays
[abbrev_sec
].section
.size
;
2391 abbrev_base
= this_set
->section_offsets
[DW_SECT_ABBREV
];
2392 abbrev_size
= this_set
->section_sizes
[DW_SECT_ABBREV
];
2395 SAFE_BYTE_GET_AND_INC (compunit
.cu_pointer_size
, hdrptr
, 1, end
);
2396 /* PR 17512: file: 001-108546-0.001:0.1. */
2397 if (compunit
.cu_pointer_size
< 2 || compunit
.cu_pointer_size
> 8)
2399 warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"),
2400 compunit
.cu_pointer_size
, offset_size
);
2401 compunit
.cu_pointer_size
= offset_size
;
2406 SAFE_BYTE_GET64 (hdrptr
, &signature_high
, &signature_low
, end
);
2408 SAFE_BYTE_GET_AND_INC (type_offset
, hdrptr
, offset_size
, end
);
2411 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2412 && num_debug_info_entries
== 0
2415 debug_information
[unit
].cu_offset
= cu_offset
;
2416 debug_information
[unit
].pointer_size
2417 = compunit
.cu_pointer_size
;
2418 debug_information
[unit
].offset_size
= offset_size
;
2419 debug_information
[unit
].dwarf_version
= compunit
.cu_version
;
2420 debug_information
[unit
].base_address
= 0;
2421 debug_information
[unit
].addr_base
= DEBUG_INFO_UNAVAILABLE
;
2422 debug_information
[unit
].ranges_base
= DEBUG_INFO_UNAVAILABLE
;
2423 debug_information
[unit
].loc_offsets
= NULL
;
2424 debug_information
[unit
].have_frame_base
= NULL
;
2425 debug_information
[unit
].max_loc_offsets
= 0;
2426 debug_information
[unit
].num_loc_offsets
= 0;
2427 debug_information
[unit
].range_lists
= NULL
;
2428 debug_information
[unit
].max_range_lists
= 0;
2429 debug_information
[unit
].num_range_lists
= 0;
2432 if (!do_loc
&& dwarf_start_die
== 0)
2434 printf (_(" Compilation Unit @ offset 0x%s:\n"),
2435 dwarf_vmatoa ("x", cu_offset
));
2436 printf (_(" Length: 0x%s (%s)\n"),
2437 dwarf_vmatoa ("x", compunit
.cu_length
),
2438 offset_size
== 8 ? "64-bit" : "32-bit");
2439 printf (_(" Version: %d\n"), compunit
.cu_version
);
2440 printf (_(" Abbrev Offset: 0x%s\n"),
2441 dwarf_vmatoa ("x", compunit
.cu_abbrev_offset
));
2442 printf (_(" Pointer Size: %d\n"), compunit
.cu_pointer_size
);
2447 printf (_(" Signature: 0x%s\n"),
2448 dwarf_vmatoa64 (signature_high
, signature_low
,
2449 buf
, sizeof (buf
)));
2450 printf (_(" Type Offset: 0x%s\n"),
2451 dwarf_vmatoa ("x", type_offset
));
2453 if (this_set
!= NULL
)
2455 dwarf_vma
*offsets
= this_set
->section_offsets
;
2456 size_t *sizes
= this_set
->section_sizes
;
2458 printf (_(" Section contributions:\n"));
2459 printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"),
2460 dwarf_vmatoa ("x", offsets
[DW_SECT_ABBREV
]),
2461 dwarf_vmatoa ("x", sizes
[DW_SECT_ABBREV
]));
2462 printf (_(" .debug_line.dwo: 0x%s 0x%s\n"),
2463 dwarf_vmatoa ("x", offsets
[DW_SECT_LINE
]),
2464 dwarf_vmatoa ("x", sizes
[DW_SECT_LINE
]));
2465 printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"),
2466 dwarf_vmatoa ("x", offsets
[DW_SECT_LOC
]),
2467 dwarf_vmatoa ("x", sizes
[DW_SECT_LOC
]));
2468 printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"),
2469 dwarf_vmatoa ("x", offsets
[DW_SECT_STR_OFFSETS
]),
2470 dwarf_vmatoa ("x", sizes
[DW_SECT_STR_OFFSETS
]));
2474 if (cu_offset
+ compunit
.cu_length
+ initial_length_size
2477 warn (_("Debug info is corrupted, length of CU at %s"
2478 " extends beyond end of section (length = %s)\n"),
2479 dwarf_vmatoa ("x", cu_offset
),
2480 dwarf_vmatoa ("x", compunit
.cu_length
));
2485 start
+= compunit
.cu_length
+ initial_length_size
;
2489 warn (_("Debug info is corrupt. CU at %s extends beyond end of section"),
2490 dwarf_vmatoa ("x", cu_offset
));
2494 if (compunit
.cu_version
!= 2
2495 && compunit
.cu_version
!= 3
2496 && compunit
.cu_version
!= 4)
2498 warn (_("CU at offset %s contains corrupt or "
2499 "unsupported version number: %d.\n"),
2500 dwarf_vmatoa ("x", cu_offset
), compunit
.cu_version
);
2506 /* Process the abbrevs used by this compilation unit. */
2507 if (compunit
.cu_abbrev_offset
>= abbrev_size
)
2508 warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"),
2509 (unsigned long) compunit
.cu_abbrev_offset
,
2510 (unsigned long) abbrev_size
);
2511 /* PR 17531: file:4bcd9ce9. */
2512 else if ((abbrev_base
+ abbrev_size
)
2513 > debug_displays
[abbrev_sec
].section
.size
)
2514 warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"),
2515 (unsigned long) abbrev_base
+ abbrev_size
,
2516 (unsigned long) debug_displays
[abbrev_sec
].section
.size
);
2518 process_abbrev_section
2519 (((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2520 + abbrev_base
+ compunit
.cu_abbrev_offset
),
2521 ((unsigned char *) debug_displays
[abbrev_sec
].section
.start
2522 + abbrev_base
+ abbrev_size
));
2527 while (tags
< start
)
2529 unsigned int bytes_read
;
2530 unsigned long abbrev_number
;
2531 unsigned long die_offset
;
2532 abbrev_entry
*entry
;
2534 int do_printing
= 1;
2536 die_offset
= tags
- section_begin
;
2538 abbrev_number
= read_uleb128 (tags
, & bytes_read
, start
);
2541 /* A null DIE marks the end of a list of siblings or it may also be
2542 a section padding. */
2543 if (abbrev_number
== 0)
2545 /* Check if it can be a section padding for the last CU. */
2546 if (level
== 0 && start
== end
)
2550 for (chk
= tags
; chk
< start
; chk
++)
2557 if (!do_loc
&& die_offset
>= dwarf_start_die
2558 && (dwarf_cutoff_level
== -1
2559 || level
< dwarf_cutoff_level
))
2560 printf (_(" <%d><%lx>: Abbrev Number: 0\n"),
2566 static unsigned num_bogus_warns
= 0;
2568 if (num_bogus_warns
< 3)
2570 warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"),
2571 die_offset
, section
->name
);
2573 if (num_bogus_warns
== 3)
2574 warn (_("Further warnings about bogus end-of-sibling markers suppressed\n"));
2577 if (dwarf_start_die
!= 0 && level
< saved_level
)
2584 if (dwarf_start_die
!= 0 && die_offset
< dwarf_start_die
)
2588 if (dwarf_start_die
!= 0 && die_offset
== dwarf_start_die
)
2589 saved_level
= level
;
2590 do_printing
= (dwarf_cutoff_level
== -1
2591 || level
< dwarf_cutoff_level
);
2593 printf (_(" <%d><%lx>: Abbrev Number: %lu"),
2594 level
, die_offset
, abbrev_number
);
2595 else if (dwarf_cutoff_level
== -1
2596 || last_level
< dwarf_cutoff_level
)
2597 printf (_(" <%d><%lx>: ...\n"), level
, die_offset
);
2602 /* Scan through the abbreviation list until we reach the
2604 for (entry
= first_abbrev
;
2605 entry
&& entry
->entry
!= abbrev_number
;
2606 entry
= entry
->next
)
2611 if (!do_loc
&& do_printing
)
2616 warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"),
2617 die_offset
, abbrev_number
);
2621 if (!do_loc
&& do_printing
)
2622 printf (" (%s)\n", get_TAG_name (entry
->tag
));
2627 need_base_address
= 0;
2629 case DW_TAG_compile_unit
:
2630 need_base_address
= 1;
2632 case DW_TAG_entry_point
:
2633 case DW_TAG_subprogram
:
2634 need_base_address
= 0;
2635 /* Assuming that there is no DW_AT_frame_base. */
2636 have_frame_base
= 0;
2640 for (attr
= entry
->first_attr
;
2641 attr
&& attr
->attribute
;
2646 if (! do_loc
&& do_printing
)
2647 /* Show the offset from where the tag was extracted. */
2648 printf (" <%lx>", (unsigned long)(tags
- section_begin
));
2650 if (debug_information
&& unit
< alloc_num_debug_info_entries
)
2651 arg
= debug_information
+ unit
;
2655 tags
= read_and_display_attr (attr
->attribute
,
2660 compunit
.cu_pointer_size
,
2662 compunit
.cu_version
,
2664 do_loc
|| ! do_printing
,
2669 if (entry
->children
)
2674 /* Set num_debug_info_entries here so that it can be used to check if
2675 we need to process .debug_loc and .debug_ranges sections. */
2676 if ((do_loc
|| do_debug_loc
|| do_debug_ranges
)
2677 && num_debug_info_entries
== 0
2680 if (num_units
> alloc_num_debug_info_entries
)
2681 num_debug_info_entries
= alloc_num_debug_info_entries
;
2683 num_debug_info_entries
= num_units
;
2692 /* Locate and scan the .debug_info section in the file and record the pointer
2693 sizes and offsets for the compilation units in it. Usually an executable
2694 will have just one pointer size, but this is not guaranteed, and so we try
2695 not to make any assumptions. Returns zero upon failure, or the number of
2696 compilation units upon success. */
2699 load_debug_info (void * file
)
2701 /* Reset the last pointer size so that we can issue correct error
2702 messages if we are displaying the contents of more than one section. */
2703 last_pointer_size
= 0;
2704 warned_about_missing_comp_units
= FALSE
;
2706 /* If we have already tried and failed to load the .debug_info
2707 section then do not bother to repeat the task. */
2708 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
2711 /* If we already have the information there is nothing else to do. */
2712 if (num_debug_info_entries
> 0)
2713 return num_debug_info_entries
;
2715 /* If this is a DWARF package file, load the CU and TU indexes. */
2716 load_cu_tu_indexes (file
);
2718 if (load_debug_section (info
, file
)
2719 && process_debug_info (&debug_displays
[info
].section
, file
, abbrev
, 1, 0))
2720 return num_debug_info_entries
;
2722 if (load_debug_section (info_dwo
, file
)
2723 && process_debug_info (&debug_displays
[info_dwo
].section
, file
,
2725 return num_debug_info_entries
;
2727 num_debug_info_entries
= DEBUG_INFO_UNAVAILABLE
;
2731 /* Read a DWARF .debug_line section header starting at DATA.
2732 Upon success returns an updated DATA pointer and the LINFO
2733 structure and the END_OF_SEQUENCE pointer will be filled in.
2734 Otherwise returns NULL. */
2736 static unsigned char *
2737 read_debug_line_header (struct dwarf_section
* section
,
2738 unsigned char * data
,
2739 unsigned char * end
,
2740 DWARF2_Internal_LineInfo
* linfo
,
2741 unsigned char ** end_of_sequence
)
2743 unsigned char *hdrptr
;
2744 unsigned int offset_size
;
2745 unsigned int initial_length_size
;
2747 /* Extract information from the Line Number Program Header.
2748 (section 6.2.4 in the Dwarf3 doc). */
2751 /* Get and check the length of the block. */
2752 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 4, end
);
2754 if (linfo
->li_length
== 0xffffffff)
2756 /* This section is 64-bit DWARF 3. */
2757 SAFE_BYTE_GET_AND_INC (linfo
->li_length
, hdrptr
, 8, end
);
2759 initial_length_size
= 12;
2764 initial_length_size
= 4;
2767 if (linfo
->li_length
+ initial_length_size
> section
->size
)
2769 /* If the length field has a relocation against it, then we should
2770 not complain if it is inaccurate (and probably negative). This
2771 happens in object files when the .debug_line section is actually
2772 comprised of several different .debug_line.* sections, (some of
2773 which may be removed by linker garbage collection), and a relocation
2774 is used to compute the correct length once that is done. */
2775 if (reloc_at (section
, (hdrptr
- section
->start
) - offset_size
))
2777 linfo
->li_length
= (end
- data
) - initial_length_size
;
2781 warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"),
2782 (long) linfo
->li_length
);
2787 /* Get and check the version number. */
2788 SAFE_BYTE_GET_AND_INC (linfo
->li_version
, hdrptr
, 2, end
);
2790 if (linfo
->li_version
!= 2
2791 && linfo
->li_version
!= 3
2792 && linfo
->li_version
!= 4)
2794 warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n"));
2798 SAFE_BYTE_GET_AND_INC (linfo
->li_prologue_length
, hdrptr
, offset_size
, end
);
2799 SAFE_BYTE_GET_AND_INC (linfo
->li_min_insn_length
, hdrptr
, 1, end
);
2801 if (linfo
->li_version
>= 4)
2803 SAFE_BYTE_GET_AND_INC (linfo
->li_max_ops_per_insn
, hdrptr
, 1, end
);
2805 if (linfo
->li_max_ops_per_insn
== 0)
2807 warn (_("Invalid maximum operations per insn.\n"));
2812 linfo
->li_max_ops_per_insn
= 1;
2814 SAFE_BYTE_GET_AND_INC (linfo
->li_default_is_stmt
, hdrptr
, 1, end
);
2815 SAFE_SIGNED_BYTE_GET_AND_INC (linfo
->li_line_base
, hdrptr
, 1, end
);
2816 SAFE_BYTE_GET_AND_INC (linfo
->li_line_range
, hdrptr
, 1, end
);
2817 SAFE_BYTE_GET_AND_INC (linfo
->li_opcode_base
, hdrptr
, 1, end
);
2819 * end_of_sequence
= data
+ linfo
->li_length
+ initial_length_size
;
2820 /* PR 17512: file:002-117414-0.004. */
2821 if (* end_of_sequence
> end
)
2823 warn (_("Line length %s extends beyond end of section\n"),
2824 dwarf_vmatoa ("u", linfo
->li_length
));
2825 * end_of_sequence
= end
;
2833 display_debug_lines_raw (struct dwarf_section
*section
,
2834 unsigned char *data
,
2837 unsigned char *start
= section
->start
;
2839 printf (_("Raw dump of debug contents of section %s:\n\n"),
2844 static DWARF2_Internal_LineInfo saved_linfo
;
2845 DWARF2_Internal_LineInfo linfo
;
2846 unsigned char *standard_opcodes
;
2847 unsigned char *end_of_sequence
;
2848 unsigned int last_dir_entry
= 0;
2851 if (const_strneq (section
->name
, ".debug_line.")
2852 /* Note: the following does not apply to .debug_line.dwo sections.
2853 These are full debug_line sections. */
2854 && strcmp (section
->name
, ".debug_line.dwo") != 0)
2856 /* Sections named .debug_line.<foo> are fragments of a .debug_line
2857 section containing just the Line Number Statements. They are
2858 created by the assembler and intended to be used alongside gcc's
2859 -ffunction-sections command line option. When the linker's
2860 garbage collection decides to discard a .text.<foo> section it
2861 can then also discard the line number information in .debug_line.<foo>.
2863 Since the section is a fragment it does not have the details
2864 needed to fill out a LineInfo structure, so instead we use the
2865 details from the last full debug_line section that we processed. */
2866 end_of_sequence
= end
;
2867 standard_opcodes
= NULL
;
2868 linfo
= saved_linfo
;
2869 /* PR 17531: file: 0522b371. */
2870 if (linfo
.li_line_range
== 0)
2872 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
2875 reset_state_machine (linfo
.li_default_is_stmt
);
2879 unsigned char * hdrptr
;
2881 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
2882 & end_of_sequence
)) == NULL
)
2885 printf (_(" Offset: 0x%lx\n"), (long)(data
- start
));
2886 printf (_(" Length: %ld\n"), (long) linfo
.li_length
);
2887 printf (_(" DWARF Version: %d\n"), linfo
.li_version
);
2888 printf (_(" Prologue Length: %d\n"), (int) linfo
.li_prologue_length
);
2889 printf (_(" Minimum Instruction Length: %d\n"), linfo
.li_min_insn_length
);
2890 if (linfo
.li_version
>= 4)
2891 printf (_(" Maximum Ops per Instruction: %d\n"), linfo
.li_max_ops_per_insn
);
2892 printf (_(" Initial value of 'is_stmt': %d\n"), linfo
.li_default_is_stmt
);
2893 printf (_(" Line Base: %d\n"), linfo
.li_line_base
);
2894 printf (_(" Line Range: %d\n"), linfo
.li_line_range
);
2895 printf (_(" Opcode Base: %d\n"), linfo
.li_opcode_base
);
2897 /* PR 17512: file: 1665-6428-0.004. */
2898 if (linfo
.li_line_range
== 0)
2900 warn (_("Line range of 0 is invalid, using 1 instead\n"));
2901 linfo
.li_line_range
= 1;
2904 reset_state_machine (linfo
.li_default_is_stmt
);
2906 /* Display the contents of the Opcodes table. */
2907 standard_opcodes
= hdrptr
;
2909 /* PR 17512: file: 002-417945-0.004. */
2910 if (standard_opcodes
+ linfo
.li_opcode_base
>= end
)
2912 warn (_("Line Base extends beyond end of section\n"));
2916 printf (_("\n Opcodes:\n"));
2918 for (i
= 1; i
< linfo
.li_opcode_base
; i
++)
2919 printf (_(" Opcode %d has %d args\n"), i
, standard_opcodes
[i
- 1]);
2921 /* Display the contents of the Directory table. */
2922 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
2925 printf (_("\n The Directory Table is empty.\n"));
2928 printf (_("\n The Directory Table (offset 0x%lx):\n"),
2929 (long)(data
- start
));
2931 while (data
< end
&& *data
!= 0)
2933 printf (" %d\t%.*s\n", ++last_dir_entry
, (int) (end
- data
), data
);
2935 data
+= strnlen ((char *) data
, end
- data
) + 1;
2938 /* PR 17512: file: 002-132094-0.004. */
2939 if (data
>= end
- 1)
2943 /* Skip the NUL at the end of the table. */
2946 /* Display the contents of the File Name table. */
2948 printf (_("\n The File Name Table is empty.\n"));
2951 printf (_("\n The File Name Table (offset 0x%lx):\n"),
2952 (long)(data
- start
));
2953 printf (_(" Entry\tDir\tTime\tSize\tName\n"));
2955 while (data
< end
&& *data
!= 0)
2957 unsigned char *name
;
2958 unsigned int bytes_read
;
2960 printf (" %d\t", ++state_machine_regs
.last_file_entry
);
2962 data
+= strnlen ((char *) data
, end
- data
) + 1;
2965 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2968 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2971 dwarf_vmatoa ("u", read_uleb128 (data
, & bytes_read
, end
)));
2973 printf ("%.*s\n", (int)(end
- name
), name
);
2977 warn (_("Corrupt file name table entry\n"));
2983 /* Skip the NUL at the end of the table. */
2986 saved_linfo
= linfo
;
2989 /* Now display the statements. */
2990 if (data
>= end_of_sequence
)
2991 printf (_(" No Line Number Statements.\n"));
2994 printf (_(" Line Number Statements:\n"));
2996 while (data
< end_of_sequence
)
2998 unsigned char op_code
;
2999 dwarf_signed_vma adv
;
3001 unsigned int bytes_read
;
3003 printf (" [0x%08lx]", (long)(data
- start
));
3007 if (op_code
>= linfo
.li_opcode_base
)
3009 op_code
-= linfo
.li_opcode_base
;
3010 uladv
= (op_code
/ linfo
.li_line_range
);
3011 if (linfo
.li_max_ops_per_insn
== 1)
3013 uladv
*= linfo
.li_min_insn_length
;
3014 state_machine_regs
.address
+= uladv
;
3015 printf (_(" Special opcode %d: "
3016 "advance Address by %s to 0x%s"),
3017 op_code
, dwarf_vmatoa ("u", uladv
),
3018 dwarf_vmatoa ("x", state_machine_regs
.address
));
3022 state_machine_regs
.address
3023 += ((state_machine_regs
.op_index
+ uladv
)
3024 / linfo
.li_max_ops_per_insn
)
3025 * linfo
.li_min_insn_length
;
3026 state_machine_regs
.op_index
3027 = (state_machine_regs
.op_index
+ uladv
)
3028 % linfo
.li_max_ops_per_insn
;
3029 printf (_(" Special opcode %d: "
3030 "advance Address by %s to 0x%s[%d]"),
3031 op_code
, dwarf_vmatoa ("u", uladv
),
3032 dwarf_vmatoa ("x", state_machine_regs
.address
),
3033 state_machine_regs
.op_index
);
3035 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3036 state_machine_regs
.line
+= adv
;
3037 printf (_(" and Line by %s to %d\n"),
3038 dwarf_vmatoa ("d", adv
), state_machine_regs
.line
);
3040 else switch (op_code
)
3042 case DW_LNS_extended_op
:
3043 data
+= process_extended_line_op (data
, linfo
.li_default_is_stmt
, end
);
3047 printf (_(" Copy\n"));
3050 case DW_LNS_advance_pc
:
3051 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3053 if (linfo
.li_max_ops_per_insn
== 1)
3055 uladv
*= linfo
.li_min_insn_length
;
3056 state_machine_regs
.address
+= uladv
;
3057 printf (_(" Advance PC by %s to 0x%s\n"),
3058 dwarf_vmatoa ("u", uladv
),
3059 dwarf_vmatoa ("x", state_machine_regs
.address
));
3063 state_machine_regs
.address
3064 += ((state_machine_regs
.op_index
+ uladv
)
3065 / linfo
.li_max_ops_per_insn
)
3066 * linfo
.li_min_insn_length
;
3067 state_machine_regs
.op_index
3068 = (state_machine_regs
.op_index
+ uladv
)
3069 % linfo
.li_max_ops_per_insn
;
3070 printf (_(" Advance PC by %s to 0x%s[%d]\n"),
3071 dwarf_vmatoa ("u", uladv
),
3072 dwarf_vmatoa ("x", state_machine_regs
.address
),
3073 state_machine_regs
.op_index
);
3077 case DW_LNS_advance_line
:
3078 adv
= read_sleb128 (data
, & bytes_read
, end
);
3080 state_machine_regs
.line
+= adv
;
3081 printf (_(" Advance Line by %s to %d\n"),
3082 dwarf_vmatoa ("d", adv
),
3083 state_machine_regs
.line
);
3086 case DW_LNS_set_file
:
3087 adv
= read_uleb128 (data
, & bytes_read
, end
);
3089 printf (_(" Set File Name to entry %s in the File Name Table\n"),
3090 dwarf_vmatoa ("d", adv
));
3091 state_machine_regs
.file
= adv
;
3094 case DW_LNS_set_column
:
3095 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3097 printf (_(" Set column to %s\n"),
3098 dwarf_vmatoa ("u", uladv
));
3099 state_machine_regs
.column
= uladv
;
3102 case DW_LNS_negate_stmt
:
3103 adv
= state_machine_regs
.is_stmt
;
3105 printf (_(" Set is_stmt to %s\n"), dwarf_vmatoa ("d", adv
));
3106 state_machine_regs
.is_stmt
= adv
;
3109 case DW_LNS_set_basic_block
:
3110 printf (_(" Set basic block\n"));
3111 state_machine_regs
.basic_block
= 1;
3114 case DW_LNS_const_add_pc
:
3115 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3116 if (linfo
.li_max_ops_per_insn
)
3118 uladv
*= linfo
.li_min_insn_length
;
3119 state_machine_regs
.address
+= uladv
;
3120 printf (_(" Advance PC by constant %s to 0x%s\n"),
3121 dwarf_vmatoa ("u", uladv
),
3122 dwarf_vmatoa ("x", state_machine_regs
.address
));
3126 state_machine_regs
.address
3127 += ((state_machine_regs
.op_index
+ uladv
)
3128 / linfo
.li_max_ops_per_insn
)
3129 * linfo
.li_min_insn_length
;
3130 state_machine_regs
.op_index
3131 = (state_machine_regs
.op_index
+ uladv
)
3132 % linfo
.li_max_ops_per_insn
;
3133 printf (_(" Advance PC by constant %s to 0x%s[%d]\n"),
3134 dwarf_vmatoa ("u", uladv
),
3135 dwarf_vmatoa ("x", state_machine_regs
.address
),
3136 state_machine_regs
.op_index
);
3140 case DW_LNS_fixed_advance_pc
:
3141 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3142 state_machine_regs
.address
+= uladv
;
3143 state_machine_regs
.op_index
= 0;
3144 printf (_(" Advance PC by fixed size amount %s to 0x%s\n"),
3145 dwarf_vmatoa ("u", uladv
),
3146 dwarf_vmatoa ("x", state_machine_regs
.address
));
3149 case DW_LNS_set_prologue_end
:
3150 printf (_(" Set prologue_end to true\n"));
3153 case DW_LNS_set_epilogue_begin
:
3154 printf (_(" Set epilogue_begin to true\n"));
3157 case DW_LNS_set_isa
:
3158 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3160 printf (_(" Set ISA to %s\n"), dwarf_vmatoa ("u", uladv
));
3164 printf (_(" Unknown opcode %d with operands: "), op_code
);
3166 if (standard_opcodes
!= NULL
)
3167 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3169 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3171 i
== 1 ? "" : ", ");
3187 unsigned char *name
;
3188 unsigned int directory_index
;
3189 unsigned int modification_date
;
3190 unsigned int length
;
3193 /* Output a decoded representation of the .debug_line section. */
3196 display_debug_lines_decoded (struct dwarf_section
*section
,
3197 unsigned char *data
,
3200 static DWARF2_Internal_LineInfo saved_linfo
;
3202 printf (_("Decoded dump of debug contents of section %s:\n\n"),
3207 /* This loop amounts to one iteration per compilation unit. */
3208 DWARF2_Internal_LineInfo linfo
;
3209 unsigned char *standard_opcodes
;
3210 unsigned char *end_of_sequence
;
3212 File_Entry
*file_table
= NULL
;
3213 unsigned int n_files
= 0;
3214 unsigned char **directory_table
= NULL
;
3215 unsigned int n_directories
= 0;
3217 if (const_strneq (section
->name
, ".debug_line.")
3218 /* Note: the following does not apply to .debug_line.dwo sections.
3219 These are full debug_line sections. */
3220 && strcmp (section
->name
, ".debug_line.dwo") != 0)
3222 /* See comment in display_debug_lines_raw(). */
3223 end_of_sequence
= end
;
3224 standard_opcodes
= NULL
;
3225 linfo
= saved_linfo
;
3226 /* PR 17531: file: 0522b371. */
3227 if (linfo
.li_line_range
== 0)
3229 warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n"));
3232 reset_state_machine (linfo
.li_default_is_stmt
);
3236 unsigned char *hdrptr
;
3238 if ((hdrptr
= read_debug_line_header (section
, data
, end
, & linfo
,
3239 & end_of_sequence
)) == NULL
)
3242 /* PR 17531: file: 0522b371. */
3243 if (linfo
.li_line_range
== 0)
3245 warn (_("Line range of 0 is invalid, using 1 instead\n"));
3246 linfo
.li_line_range
= 1;
3248 reset_state_machine (linfo
.li_default_is_stmt
);
3250 /* Save a pointer to the contents of the Opcodes table. */
3251 standard_opcodes
= hdrptr
;
3253 /* Traverse the Directory table just to count entries. */
3254 data
= standard_opcodes
+ linfo
.li_opcode_base
- 1;
3257 unsigned char *ptr_directory_table
= data
;
3261 data
+= strnlen ((char *) data
, end
- data
) + 1;
3265 /* Go through the directory table again to save the directories. */
3266 directory_table
= (unsigned char **)
3267 xmalloc (n_directories
* sizeof (unsigned char *));
3270 while (*ptr_directory_table
!= 0)
3272 directory_table
[i
] = ptr_directory_table
;
3273 ptr_directory_table
+= strnlen ((char *) ptr_directory_table
,
3274 ptr_directory_table
- end
) + 1;
3278 /* Skip the NUL at the end of the table. */
3281 /* Traverse the File Name table just to count the entries. */
3284 unsigned char *ptr_file_name_table
= data
;
3288 unsigned int bytes_read
;
3290 /* Skip Name, directory index, last modification time and length
3292 data
+= strnlen ((char *) data
, end
- data
) + 1;
3293 read_uleb128 (data
, & bytes_read
, end
);
3295 read_uleb128 (data
, & bytes_read
, end
);
3297 read_uleb128 (data
, & bytes_read
, end
);
3303 /* Go through the file table again to save the strings. */
3304 file_table
= (File_Entry
*) xmalloc (n_files
* sizeof (File_Entry
));
3307 while (*ptr_file_name_table
!= 0)
3309 unsigned int bytes_read
;
3311 file_table
[i
].name
= ptr_file_name_table
;
3312 ptr_file_name_table
+= strnlen ((char *) ptr_file_name_table
,
3313 end
- ptr_file_name_table
) + 1;
3315 /* We are not interested in directory, time or size. */
3316 file_table
[i
].directory_index
= read_uleb128 (ptr_file_name_table
,
3318 ptr_file_name_table
+= bytes_read
;
3319 file_table
[i
].modification_date
= read_uleb128 (ptr_file_name_table
,
3321 ptr_file_name_table
+= bytes_read
;
3322 file_table
[i
].length
= read_uleb128 (ptr_file_name_table
, & bytes_read
, end
);
3323 ptr_file_name_table
+= bytes_read
;
3328 /* Print the Compilation Unit's name and a header. */
3329 if (directory_table
== NULL
)
3331 printf (_("CU: %s:\n"), file_table
[0].name
);
3332 printf (_("File name Line number Starting address\n"));
3336 unsigned int ix
= file_table
[0].directory_index
;
3337 const char *directory
;
3342 else if (n_directories
== 0)
3343 directory
= _("<unknown>");
3344 else if (ix
> n_directories
)
3346 warn (_("directory index %u > number of directories %u\n"), ix
, n_directories
);
3347 directory
= _("<corrupt>");
3350 directory
= (char *) directory_table
[ix
- 1];
3352 if (do_wide
|| strlen (directory
) < 76)
3353 printf (_("CU: %s/%s:\n"), directory
, file_table
[0].name
);
3355 printf ("%s:\n", file_table
[0].name
);
3357 printf (_("File name Line number Starting address\n"));
3361 /* Skip the NUL at the end of the table. */
3364 saved_linfo
= linfo
;
3367 /* This loop iterates through the Dwarf Line Number Program. */
3368 while (data
< end_of_sequence
)
3370 unsigned char op_code
;
3372 unsigned long int uladv
;
3373 unsigned int bytes_read
;
3374 int is_special_opcode
= 0;
3378 if (op_code
>= linfo
.li_opcode_base
)
3380 op_code
-= linfo
.li_opcode_base
;
3381 uladv
= (op_code
/ linfo
.li_line_range
);
3382 if (linfo
.li_max_ops_per_insn
== 1)
3384 uladv
*= linfo
.li_min_insn_length
;
3385 state_machine_regs
.address
+= uladv
;
3389 state_machine_regs
.address
3390 += ((state_machine_regs
.op_index
+ uladv
)
3391 / linfo
.li_max_ops_per_insn
)
3392 * linfo
.li_min_insn_length
;
3393 state_machine_regs
.op_index
3394 = (state_machine_regs
.op_index
+ uladv
)
3395 % linfo
.li_max_ops_per_insn
;
3398 adv
= (op_code
% linfo
.li_line_range
) + linfo
.li_line_base
;
3399 state_machine_regs
.line
+= adv
;
3400 is_special_opcode
= 1;
3402 else switch (op_code
)
3404 case DW_LNS_extended_op
:
3406 unsigned int ext_op_code_len
;
3407 unsigned char ext_op_code
;
3408 unsigned char *op_code_data
= data
;
3410 ext_op_code_len
= read_uleb128 (op_code_data
, &bytes_read
,
3412 op_code_data
+= bytes_read
;
3414 if (ext_op_code_len
== 0)
3416 warn (_("Badly formed extended line op encountered!\n"));
3419 ext_op_code_len
+= bytes_read
;
3420 ext_op_code
= *op_code_data
++;
3422 switch (ext_op_code
)
3424 case DW_LNE_end_sequence
:
3425 reset_state_machine (linfo
.li_default_is_stmt
);
3427 case DW_LNE_set_address
:
3428 SAFE_BYTE_GET_AND_INC (state_machine_regs
.address
,
3430 ext_op_code_len
- bytes_read
- 1,
3432 state_machine_regs
.op_index
= 0;
3434 case DW_LNE_define_file
:
3436 file_table
= (File_Entry
*) xrealloc
3437 (file_table
, (n_files
+ 1) * sizeof (File_Entry
));
3439 ++state_machine_regs
.last_file_entry
;
3440 /* Source file name. */
3441 file_table
[n_files
].name
= op_code_data
;
3442 op_code_data
+= strlen ((char *) op_code_data
) + 1;
3443 /* Directory index. */
3444 file_table
[n_files
].directory_index
=
3445 read_uleb128 (op_code_data
, & bytes_read
,
3447 op_code_data
+= bytes_read
;
3448 /* Last modification time. */
3449 file_table
[n_files
].modification_date
=
3450 read_uleb128 (op_code_data
, & bytes_read
,
3452 op_code_data
+= bytes_read
;
3454 file_table
[n_files
].length
=
3455 read_uleb128 (op_code_data
, & bytes_read
,
3461 case DW_LNE_set_discriminator
:
3462 case DW_LNE_HP_set_sequence
:
3463 /* Simply ignored. */
3467 printf (_("UNKNOWN (%u): length %d\n"),
3468 ext_op_code
, ext_op_code_len
- bytes_read
);
3471 data
+= ext_op_code_len
;
3477 case DW_LNS_advance_pc
:
3478 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3480 if (linfo
.li_max_ops_per_insn
== 1)
3482 uladv
*= linfo
.li_min_insn_length
;
3483 state_machine_regs
.address
+= uladv
;
3487 state_machine_regs
.address
3488 += ((state_machine_regs
.op_index
+ uladv
)
3489 / linfo
.li_max_ops_per_insn
)
3490 * linfo
.li_min_insn_length
;
3491 state_machine_regs
.op_index
3492 = (state_machine_regs
.op_index
+ uladv
)
3493 % linfo
.li_max_ops_per_insn
;
3497 case DW_LNS_advance_line
:
3498 adv
= read_sleb128 (data
, & bytes_read
, end
);
3500 state_machine_regs
.line
+= adv
;
3503 case DW_LNS_set_file
:
3504 adv
= read_uleb128 (data
, & bytes_read
, end
);
3506 state_machine_regs
.file
= adv
;
3509 unsigned file
= state_machine_regs
.file
- 1;
3512 if (file_table
== NULL
|| n_files
== 0)
3513 printf (_("\n [Use file table entry %d]\n"), file
);
3515 else if (file
>= n_files
)
3517 warn (_("file index %u > number of files %u\n"), file
+ 1, n_files
);
3518 printf (_("\n <over large file table index %u>"), file
);
3520 else if ((dir
= file_table
[file
].directory_index
) == 0)
3521 /* If directory index is 0, that means current directory. */
3522 printf ("\n./%s:[++]\n", file_table
[file
].name
);
3523 else if (directory_table
== NULL
|| n_directories
== 0)
3524 printf (_("\n [Use file %s in directory table entry %d]\n"),
3525 file_table
[file
].name
, dir
);
3527 else if (dir
> n_directories
)
3529 warn (_("directory index %u > number of directories %u\n"), dir
, n_directories
);
3530 printf (_("\n <over large directory table entry %u>\n"), dir
);
3533 printf ("\n%s/%s:\n",
3534 /* The directory index starts counting at 1. */
3535 directory_table
[dir
- 1], file_table
[file
].name
);
3539 case DW_LNS_set_column
:
3540 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3542 state_machine_regs
.column
= uladv
;
3545 case DW_LNS_negate_stmt
:
3546 adv
= state_machine_regs
.is_stmt
;
3548 state_machine_regs
.is_stmt
= adv
;
3551 case DW_LNS_set_basic_block
:
3552 state_machine_regs
.basic_block
= 1;
3555 case DW_LNS_const_add_pc
:
3556 uladv
= ((255 - linfo
.li_opcode_base
) / linfo
.li_line_range
);
3557 if (linfo
.li_max_ops_per_insn
== 1)
3559 uladv
*= linfo
.li_min_insn_length
;
3560 state_machine_regs
.address
+= uladv
;
3564 state_machine_regs
.address
3565 += ((state_machine_regs
.op_index
+ uladv
)
3566 / linfo
.li_max_ops_per_insn
)
3567 * linfo
.li_min_insn_length
;
3568 state_machine_regs
.op_index
3569 = (state_machine_regs
.op_index
+ uladv
)
3570 % linfo
.li_max_ops_per_insn
;
3574 case DW_LNS_fixed_advance_pc
:
3575 SAFE_BYTE_GET_AND_INC (uladv
, data
, 2, end
);
3576 state_machine_regs
.address
+= uladv
;
3577 state_machine_regs
.op_index
= 0;
3580 case DW_LNS_set_prologue_end
:
3583 case DW_LNS_set_epilogue_begin
:
3586 case DW_LNS_set_isa
:
3587 uladv
= read_uleb128 (data
, & bytes_read
, end
);
3589 printf (_(" Set ISA to %lu\n"), uladv
);
3593 printf (_(" Unknown opcode %d with operands: "), op_code
);
3595 if (standard_opcodes
!= NULL
)
3596 for (i
= standard_opcodes
[op_code
- 1]; i
> 0 ; --i
)
3598 printf ("0x%s%s", dwarf_vmatoa ("x", read_uleb128 (data
,
3600 i
== 1 ? "" : ", ");
3607 /* Only Special opcodes, DW_LNS_copy and DW_LNE_end_sequence adds a row
3608 to the DWARF address/line matrix. */
3609 if ((is_special_opcode
) || (op_code
== DW_LNE_end_sequence
)
3610 || (op_code
== DW_LNS_copy
))
3612 const unsigned int MAX_FILENAME_LENGTH
= 35;
3614 char *newFileName
= NULL
;
3615 size_t fileNameLength
;
3619 unsigned indx
= state_machine_regs
.file
- 1;
3621 if (indx
>= n_files
)
3623 warn (_("corrupt file index %u encountered\n"), indx
);
3624 fileName
= _("<corrupt>");
3627 fileName
= (char *) file_table
[indx
].name
;
3630 fileName
= _("<unknown>");
3632 fileNameLength
= strlen (fileName
);
3634 if ((fileNameLength
> MAX_FILENAME_LENGTH
) && (!do_wide
))
3636 newFileName
= (char *) xmalloc (MAX_FILENAME_LENGTH
+ 1);
3637 /* Truncate file name */
3638 strncpy (newFileName
,
3639 fileName
+ fileNameLength
- MAX_FILENAME_LENGTH
,
3640 MAX_FILENAME_LENGTH
+ 1);
3644 newFileName
= (char *) xmalloc (fileNameLength
+ 1);
3645 strncpy (newFileName
, fileName
, fileNameLength
+ 1);
3648 if (!do_wide
|| (fileNameLength
<= MAX_FILENAME_LENGTH
))
3650 if (linfo
.li_max_ops_per_insn
== 1)
3651 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x\n",
3652 newFileName
, state_machine_regs
.line
,
3653 state_machine_regs
.address
);
3655 printf ("%-35s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3656 newFileName
, state_machine_regs
.line
,
3657 state_machine_regs
.address
,
3658 state_machine_regs
.op_index
);
3662 if (linfo
.li_max_ops_per_insn
== 1)
3663 printf ("%s %11d %#18" DWARF_VMA_FMT
"x\n",
3664 newFileName
, state_machine_regs
.line
,
3665 state_machine_regs
.address
);
3667 printf ("%s %11d %#18" DWARF_VMA_FMT
"x[%d]\n",
3668 newFileName
, state_machine_regs
.line
,
3669 state_machine_regs
.address
,
3670 state_machine_regs
.op_index
);
3673 if (op_code
== DW_LNE_end_sequence
)
3687 if (directory_table
)
3689 free (directory_table
);
3690 directory_table
= NULL
;
3701 display_debug_lines (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
3703 unsigned char *data
= section
->start
;
3704 unsigned char *end
= data
+ section
->size
;
3706 int retValDecoded
= 1;
3708 if (do_debug_lines
== 0)
3709 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
3711 if (do_debug_lines
& FLAG_DEBUG_LINES_RAW
)
3712 retValRaw
= display_debug_lines_raw (section
, data
, end
);
3714 if (do_debug_lines
& FLAG_DEBUG_LINES_DECODED
)
3715 retValDecoded
= display_debug_lines_decoded (section
, data
, end
);
3717 if (!retValRaw
|| !retValDecoded
)
3724 find_debug_info_for_offset (unsigned long offset
)
3728 if (num_debug_info_entries
== DEBUG_INFO_UNAVAILABLE
)
3731 for (i
= 0; i
< num_debug_info_entries
; i
++)
3732 if (debug_information
[i
].cu_offset
== offset
)
3733 return debug_information
+ i
;
3739 get_gdb_index_symbol_kind_name (gdb_index_symbol_kind kind
)
3741 /* See gdb/gdb-index.h. */
3742 static const char * const kinds
[] =
3754 return _ (kinds
[kind
]);
3758 display_debug_pubnames_worker (struct dwarf_section
*section
,
3759 void *file ATTRIBUTE_UNUSED
,
3762 DWARF2_Internal_PubNames names
;
3763 unsigned char *start
= section
->start
;
3764 unsigned char *end
= start
+ section
->size
;
3766 /* It does not matter if this load fails,
3767 we test for that later on. */
3768 load_debug_info (file
);
3770 printf (_("Contents of the %s section:\n\n"), section
->name
);
3774 unsigned char *data
;
3777 unsigned int offset_size
, initial_length_size
;
3781 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 4, end
);
3782 if (names
.pn_length
== 0xffffffff)
3784 SAFE_BYTE_GET_AND_INC (names
.pn_length
, data
, 8, end
);
3786 initial_length_size
= 12;
3791 initial_length_size
= 4;
3794 SAFE_BYTE_GET_AND_INC (names
.pn_version
, data
, 2, end
);
3795 SAFE_BYTE_GET_AND_INC (names
.pn_offset
, data
, offset_size
, end
);
3797 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
3798 && num_debug_info_entries
> 0
3799 && find_debug_info_for_offset (names
.pn_offset
) == NULL
)
3800 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
3801 (unsigned long) names
.pn_offset
, section
->name
);
3803 SAFE_BYTE_GET_AND_INC (names
.pn_size
, data
, offset_size
, end
);
3805 adr
= start
+ names
.pn_length
+ initial_length_size
;
3806 /* PR 17531: file: 7615b6b2. */
3807 if ((dwarf_signed_vma
) names
.pn_length
< 0
3808 /* PR 17531: file: a5dbeaa7. */
3811 warn (_("Negative length for public name: 0x%lx\n"), (long) names
.pn_length
);
3817 printf (_(" Length: %ld\n"),
3818 (long) names
.pn_length
);
3819 printf (_(" Version: %d\n"),
3821 printf (_(" Offset into .debug_info section: 0x%lx\n"),
3822 (unsigned long) names
.pn_offset
);
3823 printf (_(" Size of area in .debug_info section: %ld\n"),
3824 (long) names
.pn_size
);
3826 if (names
.pn_version
!= 2 && names
.pn_version
!= 3)
3828 static int warned
= 0;
3832 warn (_("Only DWARF 2 and 3 pubnames are currently supported\n"));
3840 printf (_("\n Offset Kind Name\n"));
3842 printf (_("\n Offset\tName\n"));
3846 bfd_size_type maxprint
;
3848 SAFE_BYTE_GET (offset
, data
, offset_size
, end
);
3852 data
+= offset_size
;
3855 maxprint
= (end
- data
) - 1;
3859 unsigned int kind_data
;
3860 gdb_index_symbol_kind kind
;
3861 const char *kind_name
;
3864 SAFE_BYTE_GET (kind_data
, data
, 1, end
);
3867 /* GCC computes the kind as the upper byte in the CU index
3868 word, and then right shifts it by the CU index size.
3869 Left shift KIND to where the gdb-index.h accessor macros
3871 kind_data
<<= GDB_INDEX_CU_BITSIZE
;
3872 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (kind_data
);
3873 kind_name
= get_gdb_index_symbol_kind_name (kind
);
3874 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (kind_data
);
3875 printf (" %-6lx %s,%-10s %.*s\n",
3876 (unsigned long) offset
, is_static
? _("s") : _("g"),
3877 kind_name
, (int) maxprint
, data
);
3880 printf (" %-6lx\t%.*s\n",
3881 (unsigned long) offset
, (int) maxprint
, data
);
3883 data
+= strnlen ((char *) data
, maxprint
) + 1;
3888 while (offset
!= 0);
3896 display_debug_pubnames (struct dwarf_section
*section
, void *file
)
3898 return display_debug_pubnames_worker (section
, file
, 0);
3902 display_debug_gnu_pubnames (struct dwarf_section
*section
, void *file
)
3904 return display_debug_pubnames_worker (section
, file
, 1);
3908 display_debug_macinfo (struct dwarf_section
*section
,
3909 void *file ATTRIBUTE_UNUSED
)
3911 unsigned char *start
= section
->start
;
3912 unsigned char *end
= start
+ section
->size
;
3913 unsigned char *curr
= start
;
3914 unsigned int bytes_read
;
3915 enum dwarf_macinfo_record_type op
;
3917 printf (_("Contents of the %s section:\n\n"), section
->name
);
3921 unsigned int lineno
;
3922 const unsigned char *string
;
3924 op
= (enum dwarf_macinfo_record_type
) *curr
;
3929 case DW_MACINFO_start_file
:
3931 unsigned int filenum
;
3933 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3935 filenum
= read_uleb128 (curr
, & bytes_read
, end
);
3938 printf (_(" DW_MACINFO_start_file - lineno: %d filenum: %d\n"),
3943 case DW_MACINFO_end_file
:
3944 printf (_(" DW_MACINFO_end_file\n"));
3947 case DW_MACINFO_define
:
3948 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3951 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3952 printf (_(" DW_MACINFO_define - lineno : %d macro : %s\n"),
3956 case DW_MACINFO_undef
:
3957 lineno
= read_uleb128 (curr
, & bytes_read
, end
);
3960 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3961 printf (_(" DW_MACINFO_undef - lineno : %d macro : %s\n"),
3965 case DW_MACINFO_vendor_ext
:
3967 unsigned int constant
;
3969 constant
= read_uleb128 (curr
, & bytes_read
, end
);
3972 curr
+= strnlen ((char *) string
, end
- string
) + 1;
3973 printf (_(" DW_MACINFO_vendor_ext - constant : %d string : %s\n"),
3983 /* Given LINE_OFFSET into the .debug_line section, attempt to return
3984 filename and dirname corresponding to file name table entry with index
3985 FILEIDX. Return NULL on failure. */
3987 static unsigned char *
3988 get_line_filename_and_dirname (dwarf_vma line_offset
,
3990 unsigned char **dir_name
)
3992 struct dwarf_section
*section
= &debug_displays
[line
].section
;
3993 unsigned char *hdrptr
, *dirtable
, *file_name
;
3994 unsigned int offset_size
, initial_length_size
;
3995 unsigned int version
, opcode_base
, bytes_read
;
3996 dwarf_vma length
, diridx
;
3997 const unsigned char * end
;
4000 if (section
->start
== NULL
4001 || line_offset
>= section
->size
4005 hdrptr
= section
->start
+ line_offset
;
4006 end
= section
->start
+ section
->size
;
4008 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 4, end
);
4009 if (length
== 0xffffffff)
4011 /* This section is 64-bit DWARF 3. */
4012 SAFE_BYTE_GET_AND_INC (length
, hdrptr
, 8, end
);
4014 initial_length_size
= 12;
4019 initial_length_size
= 4;
4021 if (length
+ initial_length_size
> section
->size
)
4024 SAFE_BYTE_GET_AND_INC (version
, hdrptr
, 2, end
);
4025 if (version
!= 2 && version
!= 3 && version
!= 4)
4027 hdrptr
+= offset_size
+ 1;/* Skip prologue_length and min_insn_length. */
4029 hdrptr
++; /* Skip max_ops_per_insn. */
4030 hdrptr
+= 3; /* Skip default_is_stmt, line_base, line_range. */
4032 SAFE_BYTE_GET_AND_INC (opcode_base
, hdrptr
, 1, end
);
4033 if (opcode_base
== 0)
4036 hdrptr
+= opcode_base
- 1;
4038 /* Skip over dirname table. */
4039 while (*hdrptr
!= '\0')
4040 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4041 hdrptr
++; /* Skip the NUL at the end of the table. */
4042 /* Now skip over preceding filename table entries. */
4043 for (; *hdrptr
!= '\0' && fileidx
> 1; fileidx
--)
4045 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4046 read_uleb128 (hdrptr
, &bytes_read
, end
);
4047 hdrptr
+= bytes_read
;
4048 read_uleb128 (hdrptr
, &bytes_read
, end
);
4049 hdrptr
+= bytes_read
;
4050 read_uleb128 (hdrptr
, &bytes_read
, end
);
4051 hdrptr
+= bytes_read
;
4053 if (hdrptr
== end
|| *hdrptr
== '\0')
4056 hdrptr
+= strnlen ((char *) hdrptr
, end
- hdrptr
) + 1;
4057 diridx
= read_uleb128 (hdrptr
, &bytes_read
, end
);
4060 for (; *dirtable
!= '\0' && diridx
> 1; diridx
--)
4061 dirtable
+= strnlen ((char *) dirtable
, end
- dirtable
) + 1;
4062 if (*dirtable
== '\0')
4064 *dir_name
= dirtable
;
4069 display_debug_macro (struct dwarf_section
*section
,
4072 unsigned char *start
= section
->start
;
4073 unsigned char *end
= start
+ section
->size
;
4074 unsigned char *curr
= start
;
4075 unsigned char *extended_op_buf
[256];
4076 unsigned int bytes_read
;
4078 load_debug_section (str
, file
);
4079 load_debug_section (line
, file
);
4081 printf (_("Contents of the %s section:\n\n"), section
->name
);
4085 unsigned int lineno
, version
, flags
;
4086 unsigned int offset_size
= 4;
4087 const unsigned char *string
;
4088 dwarf_vma line_offset
= 0, sec_offset
= curr
- start
, offset
;
4089 unsigned char **extended_ops
= NULL
;
4091 SAFE_BYTE_GET_AND_INC (version
, curr
, 2, end
);
4094 error (_("Only GNU extension to DWARF 4 of %s is currently supported.\n"),
4099 SAFE_BYTE_GET_AND_INC (flags
, curr
, 1, end
);
4102 printf (_(" Offset: 0x%lx\n"),
4103 (unsigned long) sec_offset
);
4104 printf (_(" Version: %d\n"), version
);
4105 printf (_(" Offset size: %d\n"), offset_size
);
4108 SAFE_BYTE_GET_AND_INC (line_offset
, curr
, offset_size
, end
);
4109 printf (_(" Offset into .debug_line: 0x%lx\n"),
4110 (unsigned long) line_offset
);
4114 unsigned int i
, count
, op
;
4117 SAFE_BYTE_GET_AND_INC (count
, curr
, 1, end
);
4119 memset (extended_op_buf
, 0, sizeof (extended_op_buf
));
4120 extended_ops
= extended_op_buf
;
4123 printf (_(" Extension opcode arguments:\n"));
4124 for (i
= 0; i
< count
; i
++)
4126 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4127 extended_ops
[op
] = curr
;
4128 nargs
= read_uleb128 (curr
, &bytes_read
, end
);
4131 printf (_(" DW_MACRO_GNU_%02x has no arguments\n"), op
);
4134 printf (_(" DW_MACRO_GNU_%02x arguments: "), op
);
4135 for (n
= 0; n
< nargs
; n
++)
4139 SAFE_BYTE_GET_AND_INC (form
, curr
, 1, end
);
4140 printf ("%s%s", get_FORM_name (form
),
4141 n
== nargs
- 1 ? "\n" : ", ");
4151 case DW_FORM_block1
:
4152 case DW_FORM_block2
:
4153 case DW_FORM_block4
:
4155 case DW_FORM_string
:
4157 case DW_FORM_sec_offset
:
4160 error (_("Invalid extension opcode form %s\n"),
4161 get_FORM_name (form
));
4177 error (_(".debug_macro section not zero terminated\n"));
4181 SAFE_BYTE_GET_AND_INC (op
, curr
, 1, end
);
4187 case DW_MACRO_GNU_start_file
:
4189 unsigned int filenum
;
4190 unsigned char *file_name
= NULL
, *dir_name
= NULL
;
4192 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4194 filenum
= read_uleb128 (curr
, &bytes_read
, end
);
4197 if ((flags
& 2) == 0)
4198 error (_("DW_MACRO_GNU_start_file used, but no .debug_line offset provided.\n"));
4201 = get_line_filename_and_dirname (line_offset
, filenum
,
4203 if (file_name
== NULL
)
4204 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d\n"),
4207 printf (_(" DW_MACRO_GNU_start_file - lineno: %d filenum: %d filename: %s%s%s\n"),
4209 dir_name
!= NULL
? (const char *) dir_name
: "",
4210 dir_name
!= NULL
? "/" : "", file_name
);
4214 case DW_MACRO_GNU_end_file
:
4215 printf (_(" DW_MACRO_GNU_end_file\n"));
4218 case DW_MACRO_GNU_define
:
4219 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4222 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4223 printf (_(" DW_MACRO_GNU_define - lineno : %d macro : %s\n"),
4227 case DW_MACRO_GNU_undef
:
4228 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4231 curr
+= strnlen ((char *) string
, end
- string
) + 1;
4232 printf (_(" DW_MACRO_GNU_undef - lineno : %d macro : %s\n"),
4236 case DW_MACRO_GNU_define_indirect
:
4237 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4239 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4240 string
= fetch_indirect_string (offset
);
4241 printf (_(" DW_MACRO_GNU_define_indirect - lineno : %d macro : %s\n"),
4245 case DW_MACRO_GNU_undef_indirect
:
4246 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4248 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4249 string
= fetch_indirect_string (offset
);
4250 printf (_(" DW_MACRO_GNU_undef_indirect - lineno : %d macro : %s\n"),
4254 case DW_MACRO_GNU_transparent_include
:
4255 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4256 printf (_(" DW_MACRO_GNU_transparent_include - offset : 0x%lx\n"),
4257 (unsigned long) offset
);
4260 case DW_MACRO_GNU_define_indirect_alt
:
4261 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4263 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4264 printf (_(" DW_MACRO_GNU_define_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4265 lineno
, (unsigned long) offset
);
4268 case DW_MACRO_GNU_undef_indirect_alt
:
4269 lineno
= read_uleb128 (curr
, &bytes_read
, end
);
4271 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4272 printf (_(" DW_MACRO_GNU_undef_indirect_alt - lineno : %d macro offset : 0x%lx\n"),
4273 lineno
, (unsigned long) offset
);
4276 case DW_MACRO_GNU_transparent_include_alt
:
4277 SAFE_BYTE_GET_AND_INC (offset
, curr
, offset_size
, end
);
4278 printf (_(" DW_MACRO_GNU_transparent_include_alt - offset : 0x%lx\n"),
4279 (unsigned long) offset
);
4283 if (extended_ops
== NULL
|| extended_ops
[op
] == NULL
)
4285 error (_(" Unknown macro opcode %02x seen\n"), op
);
4290 /* Skip over unhandled opcodes. */
4292 unsigned char *desc
= extended_ops
[op
];
4293 nargs
= read_uleb128 (desc
, &bytes_read
, end
);
4297 printf (_(" DW_MACRO_GNU_%02x\n"), op
);
4300 printf (_(" DW_MACRO_GNU_%02x -"), op
);
4301 for (n
= 0; n
< nargs
; n
++)
4305 SAFE_BYTE_GET_AND_INC (val
, desc
, 1, end
);
4307 = read_and_display_attr_value (0, val
,
4308 curr
, end
, 0, 0, offset_size
,
4309 version
, NULL
, 0, NULL
,
4327 display_debug_abbrev (struct dwarf_section
*section
,
4328 void *file ATTRIBUTE_UNUSED
)
4330 abbrev_entry
*entry
;
4331 unsigned char *start
= section
->start
;
4332 unsigned char *end
= start
+ section
->size
;
4334 printf (_("Contents of the %s section:\n\n"), section
->name
);
4338 unsigned char *last
;
4343 start
= process_abbrev_section (start
, end
);
4345 if (first_abbrev
== NULL
)
4348 printf (_(" Number TAG (0x%lx)\n"), (long) (last
- section
->start
));
4350 for (entry
= first_abbrev
; entry
; entry
= entry
->next
)
4354 printf (" %ld %s [%s]\n",
4356 get_TAG_name (entry
->tag
),
4357 entry
->children
? _("has children") : _("no children"));
4359 for (attr
= entry
->first_attr
; attr
; attr
= attr
->next
)
4360 printf (" %-18s %s\n",
4361 get_AT_name (attr
->attribute
),
4362 get_FORM_name (attr
->form
));
4372 /* Return true when ADDR is the maximum address, when addresses are
4373 POINTER_SIZE bytes long. */
4376 is_max_address (dwarf_vma addr
, unsigned int pointer_size
)
4378 dwarf_vma mask
= ~(~(dwarf_vma
) 1 << (pointer_size
* 8 - 1));
4379 return ((addr
& mask
) == mask
);
4382 /* Display a location list from a normal (ie, non-dwo) .debug_loc section. */
4385 display_loc_list (struct dwarf_section
*section
,
4386 unsigned char **start_ptr
,
4387 unsigned int debug_info_entry
,
4388 unsigned long offset
,
4389 unsigned long base_address
,
4392 unsigned char *start
= *start_ptr
;
4393 unsigned char *section_end
= section
->start
+ section
->size
;
4394 unsigned long cu_offset
;
4395 unsigned int pointer_size
;
4396 unsigned int offset_size
;
4401 unsigned short length
;
4402 int need_frame_base
;
4404 if (debug_info_entry
>= num_debug_info_entries
)
4406 warn (_("No debug information available for loc lists of entry: %u\n"),
4411 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4412 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4413 offset_size
= debug_information
[debug_info_entry
].offset_size
;
4414 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4416 if (pointer_size
< 2 || pointer_size
> 8)
4418 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4419 pointer_size
, debug_info_entry
);
4425 unsigned long off
= offset
+ (start
- *start_ptr
);
4427 if (start
+ 2 * pointer_size
> section_end
)
4429 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4434 printf (" %8.8lx ", off
);
4436 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, section_end
);
4437 SAFE_BYTE_GET_AND_INC (end
, start
, pointer_size
, section_end
);
4439 if (begin
== 0 && end
== 0)
4441 /* PR 18374: In a object file we can have a location list that
4442 starts with a begin and end of 0 because there are relocations
4443 that need to be applied to the addresses. Actually applying
4444 the relocations now does not help as they will probably resolve
4445 to 0, since the object file has not been fully linked. Real
4446 end of list markers will not have any relocations against them. */
4447 if (! reloc_at (section
, off
)
4448 && ! reloc_at (section
, off
+ pointer_size
))
4450 printf (_("<End of list>\n"));
4455 /* Check base address specifiers. */
4456 if (is_max_address (begin
, pointer_size
)
4457 && !is_max_address (end
, pointer_size
))
4460 print_dwarf_vma (begin
, pointer_size
);
4461 print_dwarf_vma (end
, pointer_size
);
4462 printf (_("(base address)\n"));
4466 if (start
+ 2 > section_end
)
4468 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4473 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4475 if (start
+ length
> section_end
)
4477 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4482 print_dwarf_vma (begin
+ base_address
, pointer_size
);
4483 print_dwarf_vma (end
+ base_address
, pointer_size
);
4486 need_frame_base
= decode_location_expression (start
,
4491 cu_offset
, section
);
4494 if (need_frame_base
&& !has_frame_base
)
4495 printf (_(" [without DW_AT_frame_base]"));
4498 fputs (_(" (start == end)"), stdout
);
4499 else if (begin
> end
)
4500 fputs (_(" (start > end)"), stdout
);
4510 /* Print a .debug_addr table index in decimal, surrounded by square brackets,
4511 right-adjusted in a field of length LEN, and followed by a space. */
4514 print_addr_index (unsigned int idx
, unsigned int len
)
4516 static char buf
[15];
4517 snprintf (buf
, sizeof (buf
), "[%d]", idx
);
4518 printf ("%*s ", len
, buf
);
4521 /* Display a location list from a .dwo section. It uses address indexes rather
4522 than embedded addresses. This code closely follows display_loc_list, but the
4523 two are sufficiently different that combining things is very ugly. */
4526 display_loc_list_dwo (struct dwarf_section
*section
,
4527 unsigned char **start_ptr
,
4528 unsigned int debug_info_entry
,
4529 unsigned long offset
,
4532 unsigned char *start
= *start_ptr
;
4533 unsigned char *section_end
= section
->start
+ section
->size
;
4534 unsigned long cu_offset
;
4535 unsigned int pointer_size
;
4536 unsigned int offset_size
;
4539 unsigned short length
;
4540 int need_frame_base
;
4542 unsigned int bytes_read
;
4544 if (debug_info_entry
>= num_debug_info_entries
)
4546 warn (_("No debug information for loc lists of entry: %u\n"),
4551 cu_offset
= debug_information
[debug_info_entry
].cu_offset
;
4552 pointer_size
= debug_information
[debug_info_entry
].pointer_size
;
4553 offset_size
= debug_information
[debug_info_entry
].offset_size
;
4554 dwarf_version
= debug_information
[debug_info_entry
].dwarf_version
;
4556 if (pointer_size
< 2 || pointer_size
> 8)
4558 warn (_("Invalid pointer size (%d) in debug info for entry %d\n"),
4559 pointer_size
, debug_info_entry
);
4565 printf (" %8.8lx ", offset
+ (start
- *start_ptr
));
4567 if (start
>= section_end
)
4569 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4574 SAFE_BYTE_GET_AND_INC (entry_type
, start
, 1, section_end
);
4577 case 0: /* A terminating entry. */
4579 printf (_("<End of list>\n"));
4581 case 1: /* A base-address entry. */
4582 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4583 start
+= bytes_read
;
4584 print_addr_index (idx
, 8);
4586 printf (_("(base address selection entry)\n"));
4588 case 2: /* A start/end entry. */
4589 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4590 start
+= bytes_read
;
4591 print_addr_index (idx
, 8);
4592 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4593 start
+= bytes_read
;
4594 print_addr_index (idx
, 8);
4596 case 3: /* A start/length entry. */
4597 idx
= read_uleb128 (start
, &bytes_read
, section_end
);
4598 start
+= bytes_read
;
4599 print_addr_index (idx
, 8);
4600 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4601 printf ("%08x ", idx
);
4603 case 4: /* An offset pair entry. */
4604 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4605 printf ("%08x ", idx
);
4606 SAFE_BYTE_GET_AND_INC (idx
, start
, 4, section_end
);
4607 printf ("%08x ", idx
);
4610 warn (_("Unknown location list entry type 0x%x.\n"), entry_type
);
4615 if (start
+ 2 > section_end
)
4617 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4622 SAFE_BYTE_GET_AND_INC (length
, start
, 2, section_end
);
4623 if (start
+ length
> section_end
)
4625 warn (_("Location list starting at offset 0x%lx is not terminated.\n"),
4631 need_frame_base
= decode_location_expression (start
,
4636 cu_offset
, section
);
4639 if (need_frame_base
&& !has_frame_base
)
4640 printf (_(" [without DW_AT_frame_base]"));
4650 /* Sort array of indexes in ascending order of loc_offsets[idx]. */
4652 static dwarf_vma
*loc_offsets
;
4655 loc_offsets_compar (const void *ap
, const void *bp
)
4657 dwarf_vma a
= loc_offsets
[*(const unsigned int *) ap
];
4658 dwarf_vma b
= loc_offsets
[*(const unsigned int *) bp
];
4660 return (a
> b
) - (b
> a
);
4664 display_debug_loc (struct dwarf_section
*section
, void *file
)
4666 unsigned char *start
= section
->start
;
4667 unsigned long bytes
;
4668 unsigned char *section_begin
= start
;
4669 unsigned int num_loc_list
= 0;
4670 unsigned long last_offset
= 0;
4671 unsigned int first
= 0;
4674 int seen_first_offset
= 0;
4675 int locs_sorted
= 1;
4676 unsigned char *next
;
4677 unsigned int *array
= NULL
;
4678 const char *suffix
= strrchr (section
->name
, '.');
4681 if (suffix
&& strcmp (suffix
, ".dwo") == 0)
4684 bytes
= section
->size
;
4688 printf (_("\nThe %s section is empty.\n"), section
->name
);
4692 if (load_debug_info (file
) == 0)
4694 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
4699 /* Check the order of location list in .debug_info section. If
4700 offsets of location lists are in the ascending order, we can
4701 use `debug_information' directly. */
4702 for (i
= 0; i
< num_debug_info_entries
; i
++)
4706 num
= debug_information
[i
].num_loc_offsets
;
4707 if (num
> num_loc_list
)
4710 /* Check if we can use `debug_information' directly. */
4711 if (locs_sorted
&& num
!= 0)
4713 if (!seen_first_offset
)
4715 /* This is the first location list. */
4716 last_offset
= debug_information
[i
].loc_offsets
[0];
4718 seen_first_offset
= 1;
4724 for (; j
< num
; j
++)
4727 debug_information
[i
].loc_offsets
[j
])
4732 last_offset
= debug_information
[i
].loc_offsets
[j
];
4737 if (!seen_first_offset
)
4738 error (_("No location lists in .debug_info section!\n"));
4740 if (debug_information
[first
].num_loc_offsets
> 0
4741 && debug_information
[first
].loc_offsets
[0] != 0)
4742 warn (_("Location lists in %s section start at 0x%s\n"),
4744 dwarf_vmatoa ("x", debug_information
[first
].loc_offsets
[0]));
4747 array
= (unsigned int *) xcmalloc (num_loc_list
, sizeof (unsigned int));
4748 printf (_("Contents of the %s section:\n\n"), section
->name
);
4749 if (reloc_at (section
, 0))
4750 printf (_(" Warning: This section has relocations - addresses seen here may not be accurate.\n\n"));
4751 printf (_(" Offset Begin End Expression\n"));
4753 seen_first_offset
= 0;
4754 for (i
= first
; i
< num_debug_info_entries
; i
++)
4756 unsigned long offset
;
4757 unsigned long base_address
;
4763 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4765 loc_offsets
= debug_information
[i
].loc_offsets
;
4766 qsort (array
, debug_information
[i
].num_loc_offsets
,
4767 sizeof (*array
), loc_offsets_compar
);
4770 for (k
= 0; k
< debug_information
[i
].num_loc_offsets
; k
++)
4772 j
= locs_sorted
? k
: array
[k
];
4774 && debug_information
[i
].loc_offsets
[locs_sorted
4775 ? k
- 1 : array
[k
- 1]]
4776 == debug_information
[i
].loc_offsets
[j
])
4778 has_frame_base
= debug_information
[i
].have_frame_base
[j
];
4779 offset
= debug_information
[i
].loc_offsets
[j
];
4780 next
= section_begin
+ offset
;
4781 base_address
= debug_information
[i
].base_address
;
4783 if (!seen_first_offset
)
4784 seen_first_offset
= 1;
4788 warn (_("There is a hole [0x%lx - 0x%lx] in .debug_loc section.\n"),
4789 (unsigned long) (start
- section_begin
),
4790 (unsigned long) offset
);
4791 else if (start
> next
)
4792 warn (_("There is an overlap [0x%lx - 0x%lx] in .debug_loc section.\n"),
4793 (unsigned long) (start
- section_begin
),
4794 (unsigned long) offset
);
4798 if (offset
>= bytes
)
4800 warn (_("Offset 0x%lx is bigger than .debug_loc section size.\n"),
4806 display_loc_list_dwo (section
, &start
, i
, offset
, has_frame_base
);
4808 display_loc_list (section
, &start
, i
, offset
, base_address
,
4813 if (start
< section
->start
+ section
->size
)
4814 warn (_("There are %ld unused bytes at the end of section %s\n"),
4815 (long) (section
->start
+ section
->size
- start
), section
->name
);
4822 display_debug_str (struct dwarf_section
*section
,
4823 void *file ATTRIBUTE_UNUSED
)
4825 unsigned char *start
= section
->start
;
4826 unsigned long bytes
= section
->size
;
4827 dwarf_vma addr
= section
->address
;
4831 printf (_("\nThe %s section is empty.\n"), section
->name
);
4835 printf (_("Contents of the %s section:\n\n"), section
->name
);
4843 lbytes
= (bytes
> 16 ? 16 : bytes
);
4845 printf (" 0x%8.8lx ", (unsigned long) addr
);
4847 for (j
= 0; j
< 16; j
++)
4850 printf ("%2.2x", start
[j
]);
4858 for (j
= 0; j
< lbytes
; j
++)
4861 if (k
>= ' ' && k
< 0x80)
4880 display_debug_info (struct dwarf_section
*section
, void *file
)
4882 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4886 display_debug_types (struct dwarf_section
*section
, void *file
)
4888 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 1);
4892 display_trace_info (struct dwarf_section
*section
, void *file
)
4894 return process_debug_info (section
, file
, section
->abbrev_sec
, 0, 0);
4898 display_debug_aranges (struct dwarf_section
*section
,
4899 void *file ATTRIBUTE_UNUSED
)
4901 unsigned char *start
= section
->start
;
4902 unsigned char *end
= start
+ section
->size
;
4904 printf (_("Contents of the %s section:\n\n"), section
->name
);
4906 /* It does not matter if this load fails,
4907 we test for that later on. */
4908 load_debug_info (file
);
4912 unsigned char *hdrptr
;
4913 DWARF2_Internal_ARange arange
;
4914 unsigned char *addr_ranges
;
4917 unsigned char address_size
;
4919 unsigned int offset_size
;
4920 unsigned int initial_length_size
;
4924 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 4, end
);
4925 if (arange
.ar_length
== 0xffffffff)
4927 SAFE_BYTE_GET_AND_INC (arange
.ar_length
, hdrptr
, 8, end
);
4929 initial_length_size
= 12;
4934 initial_length_size
= 4;
4937 SAFE_BYTE_GET_AND_INC (arange
.ar_version
, hdrptr
, 2, end
);
4938 SAFE_BYTE_GET_AND_INC (arange
.ar_info_offset
, hdrptr
, offset_size
, end
);
4940 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
4941 && num_debug_info_entries
> 0
4942 && find_debug_info_for_offset (arange
.ar_info_offset
) == NULL
)
4943 warn (_(".debug_info offset of 0x%lx in %s section does not point to a CU header.\n"),
4944 (unsigned long) arange
.ar_info_offset
, section
->name
);
4946 SAFE_BYTE_GET_AND_INC (arange
.ar_pointer_size
, hdrptr
, 1, end
);
4947 SAFE_BYTE_GET_AND_INC (arange
.ar_segment_size
, hdrptr
, 1, end
);
4949 if (arange
.ar_version
!= 2 && arange
.ar_version
!= 3)
4951 /* PR 19872: A version number of 0 probably means that there is
4952 padding at the end of the .debug_aranges section. Gold puts
4953 it there when performing an incremental link, for example.
4954 So do not generate a warning in this case. */
4955 if (arange
.ar_version
)
4956 warn (_("Only DWARF 2 and 3 aranges are currently supported.\n"));
4960 printf (_(" Length: %ld\n"),
4961 (long) arange
.ar_length
);
4962 printf (_(" Version: %d\n"), arange
.ar_version
);
4963 printf (_(" Offset into .debug_info: 0x%lx\n"),
4964 (unsigned long) arange
.ar_info_offset
);
4965 printf (_(" Pointer Size: %d\n"), arange
.ar_pointer_size
);
4966 printf (_(" Segment Size: %d\n"), arange
.ar_segment_size
);
4968 address_size
= arange
.ar_pointer_size
+ arange
.ar_segment_size
;
4970 /* PR 17512: file: 001-108546-0.001:0.1. */
4971 if (address_size
== 0 || address_size
> 8)
4973 error (_("Invalid address size in %s section!\n"),
4978 /* The DWARF spec does not require that the address size be a power
4979 of two, but we do. This will have to change if we ever encounter
4980 an uneven architecture. */
4981 if ((address_size
& (address_size
- 1)) != 0)
4983 warn (_("Pointer size + Segment size is not a power of two.\n"));
4987 if (address_size
> 4)
4988 printf (_("\n Address Length\n"));
4990 printf (_("\n Address Length\n"));
4992 addr_ranges
= hdrptr
;
4994 /* Must pad to an alignment boundary that is twice the address size. */
4995 excess
= (hdrptr
- start
) % (2 * address_size
);
4997 addr_ranges
+= (2 * address_size
) - excess
;
4999 hdrptr
= start
+ arange
.ar_length
+ initial_length_size
;
5000 if (hdrptr
< start
|| hdrptr
> end
)
5002 error (_("Excessive header length: %lx\n"), (long) arange
.ar_length
);
5007 while (addr_ranges
+ 2 * address_size
<= start
)
5009 SAFE_BYTE_GET_AND_INC (address
, addr_ranges
, address_size
, end
);
5010 SAFE_BYTE_GET_AND_INC (length
, addr_ranges
, address_size
, end
);
5013 print_dwarf_vma (address
, address_size
);
5014 print_dwarf_vma (length
, address_size
);
5024 /* Comparison function for qsort. */
5026 comp_addr_base (const void * v0
, const void * v1
)
5028 debug_info
* info0
= (debug_info
*) v0
;
5029 debug_info
* info1
= (debug_info
*) v1
;
5030 return info0
->addr_base
- info1
->addr_base
;
5033 /* Display the debug_addr section. */
5035 display_debug_addr (struct dwarf_section
*section
,
5038 debug_info
**debug_addr_info
;
5039 unsigned char *entry
;
5044 if (section
->size
== 0)
5046 printf (_("\nThe %s section is empty.\n"), section
->name
);
5050 if (load_debug_info (file
) == 0)
5052 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5057 printf (_("Contents of the %s section:\n\n"), section
->name
);
5059 /* PR 17531: file: cf38d01b.
5060 We use xcalloc because a corrupt file may not have initialised all of the
5061 fields in the debug_info structure, which means that the sort below might
5062 try to move uninitialised data. */
5063 debug_addr_info
= (debug_info
**) xcalloc ((num_debug_info_entries
+ 1),
5064 sizeof (debug_info
*));
5067 for (i
= 0; i
< num_debug_info_entries
; i
++)
5068 if (debug_information
[i
].addr_base
!= DEBUG_INFO_UNAVAILABLE
)
5070 /* PR 17531: file: cf38d01b. */
5071 if (debug_information
[i
].addr_base
>= section
->size
)
5072 warn (_("Corrupt address base (%lx) found in debug section %u\n"),
5073 (unsigned long) debug_information
[i
].addr_base
, i
);
5075 debug_addr_info
[count
++] = debug_information
+ i
;
5078 /* Add a sentinel to make iteration convenient. */
5079 debug_addr_info
[count
] = (debug_info
*) xmalloc (sizeof (debug_info
));
5080 debug_addr_info
[count
]->addr_base
= section
->size
;
5081 qsort (debug_addr_info
, count
, sizeof (debug_info
*), comp_addr_base
);
5083 for (i
= 0; i
< count
; i
++)
5086 unsigned int address_size
= debug_addr_info
[i
]->pointer_size
;
5088 printf (_(" For compilation unit at offset 0x%s:\n"),
5089 dwarf_vmatoa ("x", debug_addr_info
[i
]->cu_offset
));
5091 printf (_("\tIndex\tAddress\n"));
5092 entry
= section
->start
+ debug_addr_info
[i
]->addr_base
;
5093 end
= section
->start
+ debug_addr_info
[i
+ 1]->addr_base
;
5097 dwarf_vma base
= byte_get (entry
, address_size
);
5098 printf (_("\t%d:\t"), idx
);
5099 print_dwarf_vma (base
, address_size
);
5101 entry
+= address_size
;
5107 free (debug_addr_info
);
5111 /* Display the .debug_str_offsets and .debug_str_offsets.dwo sections. */
5113 display_debug_str_offsets (struct dwarf_section
*section
,
5114 void *file ATTRIBUTE_UNUSED
)
5116 if (section
->size
== 0)
5118 printf (_("\nThe %s section is empty.\n"), section
->name
);
5121 /* TODO: Dump the contents. This is made somewhat difficult by not knowing
5122 what the offset size is for this section. */
5126 /* Each debug_information[x].range_lists[y] gets this representation for
5127 sorting purposes. */
5131 /* The debug_information[x].range_lists[y] value. */
5132 unsigned long ranges_offset
;
5134 /* Original debug_information to find parameters of the data. */
5135 debug_info
*debug_info_p
;
5138 /* Sort struct range_entry in ascending order of its RANGES_OFFSET. */
5141 range_entry_compar (const void *ap
, const void *bp
)
5143 const struct range_entry
*a_re
= (const struct range_entry
*) ap
;
5144 const struct range_entry
*b_re
= (const struct range_entry
*) bp
;
5145 const unsigned long a
= a_re
->ranges_offset
;
5146 const unsigned long b
= b_re
->ranges_offset
;
5148 return (a
> b
) - (b
> a
);
5152 display_debug_ranges (struct dwarf_section
*section
,
5153 void *file ATTRIBUTE_UNUSED
)
5155 unsigned char *start
= section
->start
;
5156 unsigned char *last_start
= start
;
5157 unsigned long bytes
= section
->size
;
5158 unsigned char *section_begin
= start
;
5159 unsigned char *finish
= start
+ bytes
;
5160 unsigned int num_range_list
, i
;
5161 struct range_entry
*range_entries
, *range_entry_fill
;
5165 printf (_("\nThe %s section is empty.\n"), section
->name
);
5169 if (load_debug_info (file
) == 0)
5171 warn (_("Unable to load/parse the .debug_info section, so cannot interpret the %s section.\n"),
5177 for (i
= 0; i
< num_debug_info_entries
; i
++)
5178 num_range_list
+= debug_information
[i
].num_range_lists
;
5180 if (num_range_list
== 0)
5182 /* This can happen when the file was compiled with -gsplit-debug
5183 which removes references to range lists from the primary .o file. */
5184 printf (_("No range lists in .debug_info section.\n"));
5188 range_entries
= (struct range_entry
*)
5189 xmalloc (sizeof (*range_entries
) * num_range_list
);
5190 range_entry_fill
= range_entries
;
5192 for (i
= 0; i
< num_debug_info_entries
; i
++)
5194 debug_info
*debug_info_p
= &debug_information
[i
];
5197 for (j
= 0; j
< debug_info_p
->num_range_lists
; j
++)
5199 range_entry_fill
->ranges_offset
= debug_info_p
->range_lists
[j
];
5200 range_entry_fill
->debug_info_p
= debug_info_p
;
5205 qsort (range_entries
, num_range_list
, sizeof (*range_entries
),
5206 range_entry_compar
);
5208 if (dwarf_check
!= 0 && range_entries
[0].ranges_offset
!= 0)
5209 warn (_("Range lists in %s section start at 0x%lx\n"),
5210 section
->name
, range_entries
[0].ranges_offset
);
5212 printf (_("Contents of the %s section:\n\n"), section
->name
);
5213 printf (_(" Offset Begin End\n"));
5215 for (i
= 0; i
< num_range_list
; i
++)
5217 struct range_entry
*range_entry
= &range_entries
[i
];
5218 debug_info
*debug_info_p
= range_entry
->debug_info_p
;
5219 unsigned int pointer_size
;
5220 unsigned long offset
;
5221 unsigned char *next
;
5222 unsigned long base_address
;
5224 pointer_size
= debug_info_p
->pointer_size
;
5225 offset
= range_entry
->ranges_offset
;
5226 next
= section_begin
+ offset
;
5227 base_address
= debug_info_p
->base_address
;
5229 /* PR 17512: file: 001-101485-0.001:0.1. */
5230 if (pointer_size
< 2 || pointer_size
> 8)
5232 warn (_("Corrupt pointer size (%d) in debug entry at offset %8.8lx\n"),
5233 pointer_size
, offset
);
5237 if (dwarf_check
!= 0 && i
> 0)
5240 warn (_("There is a hole [0x%lx - 0x%lx] in %s section.\n"),
5241 (unsigned long) (start
- section_begin
),
5242 (unsigned long) (next
- section_begin
), section
->name
);
5243 else if (start
> next
)
5245 if (next
== last_start
)
5247 warn (_("There is an overlap [0x%lx - 0x%lx] in %s section.\n"),
5248 (unsigned long) (start
- section_begin
),
5249 (unsigned long) (next
- section_begin
), section
->name
);
5255 while (start
< finish
)
5260 SAFE_BYTE_GET_AND_INC (begin
, start
, pointer_size
, finish
);
5261 if (start
>= finish
)
5263 SAFE_SIGNED_BYTE_GET_AND_INC (end
, start
, pointer_size
, finish
);
5265 printf (" %8.8lx ", offset
);
5267 if (begin
== 0 && end
== 0)
5269 printf (_("<End of list>\n"));
5273 /* Check base address specifiers. */
5274 if (is_max_address (begin
, pointer_size
)
5275 && !is_max_address (end
, pointer_size
))
5278 print_dwarf_vma (begin
, pointer_size
);
5279 print_dwarf_vma (end
, pointer_size
);
5280 printf ("(base address)\n");
5284 print_dwarf_vma (begin
+ base_address
, pointer_size
);
5285 print_dwarf_vma (end
+ base_address
, pointer_size
);
5288 fputs (_("(start == end)"), stdout
);
5289 else if (begin
> end
)
5290 fputs (_("(start > end)"), stdout
);
5297 free (range_entries
);
5302 typedef struct Frame_Chunk
5304 struct Frame_Chunk
*next
;
5305 unsigned char *chunk_start
;
5307 /* DW_CFA_{undefined,same_value,offset,register,unreferenced} */
5308 short int *col_type
;
5311 unsigned int code_factor
;
5316 dwarf_vma cfa_offset
;
5318 unsigned char fde_encoding
;
5319 unsigned char cfa_exp
;
5320 unsigned char ptr_size
;
5321 unsigned char segment_size
;
5325 static const char *const *dwarf_regnames
;
5326 static unsigned int dwarf_regnames_count
;
5328 /* A marker for a col_type that means this column was never referenced
5329 in the frame info. */
5330 #define DW_CFA_unreferenced (-1)
5332 /* Return 0 if no more space is needed, 1 if more space is needed,
5333 -1 for invalid reg. */
5336 frame_need_space (Frame_Chunk
*fc
, unsigned int reg
)
5338 unsigned int prev
= fc
->ncols
;
5340 if (reg
< (unsigned int) fc
->ncols
)
5343 if (dwarf_regnames_count
5344 && reg
> dwarf_regnames_count
)
5347 fc
->ncols
= reg
+ 1;
5348 /* PR 17512: file: 10450-2643-0.004.
5349 If reg == -1 then this can happen... */
5353 /* PR 17512: file: 2844a11d. */
5354 if (fc
->ncols
> 1024)
5356 error (_("Unfeasibly large register number: %u\n"), reg
);
5358 /* FIXME: 1024 is an arbitrary limit. Increase it if
5359 we ever encounter a valid binary that exceeds it. */
5363 fc
->col_type
= (short int *) xcrealloc (fc
->col_type
, fc
->ncols
,
5364 sizeof (short int));
5365 fc
->col_offset
= (int *) xcrealloc (fc
->col_offset
, fc
->ncols
, sizeof (int));
5366 /* PR 17512: file:002-10025-0.005. */
5367 if (fc
->col_type
== NULL
|| fc
->col_offset
== NULL
)
5369 error (_("Out of memory allocating %u columns in dwarf frame arrays\n"),
5375 while (prev
< fc
->ncols
)
5377 fc
->col_type
[prev
] = DW_CFA_unreferenced
;
5378 fc
->col_offset
[prev
] = 0;
5384 static const char *const dwarf_regnames_i386
[] =
5386 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5387 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5388 "eip", "eflags", NULL
, /* 8 - 10 */
5389 "st0", "st1", "st2", "st3", /* 11 - 14 */
5390 "st4", "st5", "st6", "st7", /* 15 - 18 */
5391 NULL
, NULL
, /* 19 - 20 */
5392 "xmm0", "xmm1", "xmm2", "xmm3", /* 21 - 24 */
5393 "xmm4", "xmm5", "xmm6", "xmm7", /* 25 - 28 */
5394 "mm0", "mm1", "mm2", "mm3", /* 29 - 32 */
5395 "mm4", "mm5", "mm6", "mm7", /* 33 - 36 */
5396 "fcw", "fsw", "mxcsr", /* 37 - 39 */
5397 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
5398 "tr", "ldtr", /* 48 - 49 */
5399 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
5400 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
5401 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
5402 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
5403 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
5404 NULL
, NULL
, NULL
, /* 90 - 92 */
5405 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7" /* 93 - 100 */
5408 static const char *const dwarf_regnames_iamcu
[] =
5410 "eax", "ecx", "edx", "ebx", /* 0 - 3 */
5411 "esp", "ebp", "esi", "edi", /* 4 - 7 */
5412 "eip", "eflags", NULL
, /* 8 - 10 */
5413 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 11 - 18 */
5414 NULL
, NULL
, /* 19 - 20 */
5415 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 21 - 28 */
5416 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 29 - 36 */
5417 NULL
, NULL
, NULL
, /* 37 - 39 */
5418 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
, /* 40 - 47 */
5419 "tr", "ldtr", /* 48 - 49 */
5420 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 50 - 57 */
5421 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 58 - 65 */
5422 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 66 - 73 */
5423 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 74 - 81 */
5424 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 82 - 89 */
5425 NULL
, NULL
, NULL
, /* 90 - 92 */
5426 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
/* 93 - 100 */
5430 init_dwarf_regnames_i386 (void)
5432 dwarf_regnames
= dwarf_regnames_i386
;
5433 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_i386
);
5437 init_dwarf_regnames_iamcu (void)
5439 dwarf_regnames
= dwarf_regnames_iamcu
;
5440 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_iamcu
);
5443 static const char *const dwarf_regnames_x86_64
[] =
5445 "rax", "rdx", "rcx", "rbx",
5446 "rsi", "rdi", "rbp", "rsp",
5447 "r8", "r9", "r10", "r11",
5448 "r12", "r13", "r14", "r15",
5450 "xmm0", "xmm1", "xmm2", "xmm3",
5451 "xmm4", "xmm5", "xmm6", "xmm7",
5452 "xmm8", "xmm9", "xmm10", "xmm11",
5453 "xmm12", "xmm13", "xmm14", "xmm15",
5454 "st0", "st1", "st2", "st3",
5455 "st4", "st5", "st6", "st7",
5456 "mm0", "mm1", "mm2", "mm3",
5457 "mm4", "mm5", "mm6", "mm7",
5459 "es", "cs", "ss", "ds", "fs", "gs", NULL
, NULL
,
5460 "fs.base", "gs.base", NULL
, NULL
,
5462 "mxcsr", "fcw", "fsw",
5463 "xmm16", "xmm17", "xmm18", "xmm19",
5464 "xmm20", "xmm21", "xmm22", "xmm23",
5465 "xmm24", "xmm25", "xmm26", "xmm27",
5466 "xmm28", "xmm29", "xmm30", "xmm31",
5467 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 83 - 90 */
5468 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 91 - 98 */
5469 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 99 - 106 */
5470 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, /* 107 - 114 */
5471 NULL
, NULL
, NULL
, /* 115 - 117 */
5472 "k0", "k1", "k2", "k3", "k4", "k5", "k6", "k7"
5476 init_dwarf_regnames_x86_64 (void)
5478 dwarf_regnames
= dwarf_regnames_x86_64
;
5479 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_x86_64
);
5482 static const char *const dwarf_regnames_aarch64
[] =
5484 "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
5485 "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
5486 "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
5487 "x24", "x25", "x26", "x27", "x28", "x29", "x30", "sp",
5488 NULL
, "elr", NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5489 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5490 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5491 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5492 "v0", "v1", "v2", "v3", "v4", "v5", "v6", "v7",
5493 "v8", "v9", "v10", "v11", "v12", "v13", "v14", "v15",
5494 "v16", "v17", "v18", "v19", "v20", "v21", "v22", "v23",
5495 "v24", "v25", "v26", "v27", "v28", "v29", "v30", "v31",
5499 init_dwarf_regnames_aarch64 (void)
5501 dwarf_regnames
= dwarf_regnames_aarch64
;
5502 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_aarch64
);
5505 static const char *const dwarf_regnames_s390
[] =
5507 /* Avoid saying "r5 (r5)", so omit the names of r0-r15. */
5508 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5509 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
,
5510 "f0", "f2", "f4", "f6", "f1", "f3", "f5", "f7",
5511 "f8", "f10", "f12", "f14", "f9", "f11", "f13", "f15",
5512 "cr0", "cr1", "cr2", "cr3", "cr4", "cr5", "cr6", "cr7",
5513 "cr8", "cr9", "cr10", "cr11", "cr12", "cr13", "cr14", "cr15",
5514 "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
5515 "a8", "a9", "a10", "a11", "a12", "a13", "a14", "a15",
5518 "v16", "v18", "v20", "v22", "v17", "v19", "v21", "v23",
5519 "v24", "v26", "v28", "v30", "v25", "v27", "v29", "v31",
5523 init_dwarf_regnames_s390 (void)
5525 dwarf_regnames
= dwarf_regnames_s390
;
5526 dwarf_regnames_count
= ARRAY_SIZE (dwarf_regnames_s390
);
5530 init_dwarf_regnames (unsigned int e_machine
)
5535 init_dwarf_regnames_i386 ();
5539 init_dwarf_regnames_iamcu ();
5545 init_dwarf_regnames_x86_64 ();
5549 init_dwarf_regnames_aarch64 ();
5553 init_dwarf_regnames_s390 ();
5562 regname (unsigned int regno
, int row
)
5564 static char reg
[64];
5566 && regno
< dwarf_regnames_count
5567 && dwarf_regnames
[regno
] != NULL
)
5570 return dwarf_regnames
[regno
];
5571 snprintf (reg
, sizeof (reg
), "r%d (%s)", regno
,
5572 dwarf_regnames
[regno
]);
5575 snprintf (reg
, sizeof (reg
), "r%d", regno
);
5580 frame_display_row (Frame_Chunk
*fc
, int *need_col_headers
, unsigned int *max_regs
)
5585 if (*max_regs
< fc
->ncols
)
5586 *max_regs
= fc
->ncols
;
5588 if (*need_col_headers
)
5590 static const char *sloc
= " LOC";
5592 *need_col_headers
= 0;
5594 printf ("%-*s CFA ", eh_addr_size
* 2, sloc
);
5596 for (r
= 0; r
< *max_regs
; r
++)
5597 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5602 printf ("%-5s ", regname (r
, 1));
5608 print_dwarf_vma (fc
->pc_begin
, eh_addr_size
);
5610 strcpy (tmp
, "exp");
5612 sprintf (tmp
, "%s%+d", regname (fc
->cfa_reg
, 1), (int) fc
->cfa_offset
);
5613 printf ("%-8s ", tmp
);
5615 for (r
= 0; r
< fc
->ncols
; r
++)
5617 if (fc
->col_type
[r
] != DW_CFA_unreferenced
)
5619 switch (fc
->col_type
[r
])
5621 case DW_CFA_undefined
:
5624 case DW_CFA_same_value
:
5628 sprintf (tmp
, "c%+d", fc
->col_offset
[r
]);
5630 case DW_CFA_val_offset
:
5631 sprintf (tmp
, "v%+d", fc
->col_offset
[r
]);
5633 case DW_CFA_register
:
5634 sprintf (tmp
, "%s", regname (fc
->col_offset
[r
], 0));
5636 case DW_CFA_expression
:
5637 strcpy (tmp
, "exp");
5639 case DW_CFA_val_expression
:
5640 strcpy (tmp
, "vexp");
5643 strcpy (tmp
, "n/a");
5646 printf ("%-5s ", tmp
);
5652 #define GET(VAR, N) SAFE_BYTE_GET_AND_INC (VAR, start, N, end)
5653 #define LEB() read_uleb128 (start, & length_return, end); start += length_return
5654 #define SLEB() read_sleb128 (start, & length_return, end); start += length_return
5656 static unsigned char *
5657 read_cie (unsigned char *start
, unsigned char *end
,
5658 Frame_Chunk
**p_cie
, int *p_version
,
5659 unsigned long *p_aug_len
, unsigned char **p_aug
)
5663 unsigned int length_return
;
5664 unsigned char *augmentation_data
= NULL
;
5665 unsigned long augmentation_data_len
= 0;
5668 /* PR 17512: file: 001-228113-0.004. */
5672 fc
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
5673 memset (fc
, 0, sizeof (Frame_Chunk
));
5675 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
5676 fc
->col_offset
= (int *) xmalloc (sizeof (int));
5680 fc
->augmentation
= (char *) start
;
5681 /* PR 17512: file: 001-228113-0.004.
5682 Skip past augmentation name, but avoid running off the end of the data. */
5684 if (* start
++ == '\0')
5688 warn (_("No terminator for augmentation name\n"));
5692 if (strcmp (fc
->augmentation
, "eh") == 0)
5693 start
+= eh_addr_size
;
5697 GET (fc
->ptr_size
, 1);
5698 if (fc
->ptr_size
< 1 || fc
->ptr_size
> 8)
5700 warn (_("Invalid pointer size (%d) in CIE data\n"), fc
->ptr_size
);
5704 GET (fc
->segment_size
, 1);
5705 /* PR 17512: file: e99d2804. */
5706 if (fc
->segment_size
> 8 || fc
->segment_size
+ fc
->ptr_size
> 8)
5708 warn (_("Invalid segment size (%d) in CIE data\n"), fc
->segment_size
);
5712 eh_addr_size
= fc
->ptr_size
;
5716 fc
->ptr_size
= eh_addr_size
;
5717 fc
->segment_size
= 0;
5719 fc
->code_factor
= LEB ();
5720 fc
->data_factor
= SLEB ();
5730 if (fc
->augmentation
[0] == 'z')
5732 augmentation_data_len
= LEB ();
5733 augmentation_data
= start
;
5734 start
+= augmentation_data_len
;
5735 /* PR 17512: file: 11042-2589-0.004. */
5738 warn (_("Augmentation data too long: 0x%lx\n"), augmentation_data_len
);
5743 if (augmentation_data_len
)
5747 unsigned char *qend
;
5749 p
= (unsigned char *) fc
->augmentation
+ 1;
5750 q
= augmentation_data
;
5751 qend
= q
+ augmentation_data_len
;
5753 /* PR 17531: file: 015adfaa. */
5756 warn (_("Negative augmentation data length: 0x%lx"), augmentation_data_len
);
5757 augmentation_data_len
= 0;
5760 while (p
< end
&& q
< augmentation_data
+ augmentation_data_len
)
5765 q
+= 1 + size_of_encoded_value (*q
);
5767 fc
->fde_encoding
= *q
++;
5774 /* Note - it is OK if this loop terminates with q < qend.
5775 Padding may have been inserted to align the end of the CIE. */
5780 *p_version
= version
;
5783 *p_aug_len
= augmentation_data_len
;
5784 *p_aug
= augmentation_data
;
5790 display_debug_frames (struct dwarf_section
*section
,
5791 void *file ATTRIBUTE_UNUSED
)
5793 unsigned char *start
= section
->start
;
5794 unsigned char *end
= start
+ section
->size
;
5795 unsigned char *section_start
= start
;
5796 Frame_Chunk
*chunks
= 0, *forward_refs
= 0;
5797 Frame_Chunk
*remembered_state
= 0;
5799 int is_eh
= strcmp (section
->name
, ".eh_frame") == 0;
5800 unsigned int length_return
;
5801 unsigned int max_regs
= 0;
5802 const char *bad_reg
= _("bad register: ");
5803 unsigned int saved_eh_addr_size
= eh_addr_size
;
5805 printf (_("Contents of the %s section:\n"), section
->name
);
5809 unsigned char *saved_start
;
5810 unsigned char *block_end
;
5815 int need_col_headers
= 1;
5816 unsigned char *augmentation_data
= NULL
;
5817 unsigned long augmentation_data_len
= 0;
5818 unsigned int encoded_ptr_size
= saved_eh_addr_size
;
5819 unsigned int offset_size
;
5820 unsigned int initial_length_size
;
5821 bfd_boolean all_nops
;
5823 saved_start
= start
;
5825 SAFE_BYTE_GET_AND_INC (length
, start
, 4, end
);
5829 printf ("\n%08lx ZERO terminator\n\n",
5830 (unsigned long)(saved_start
- section_start
));
5831 /* Skip any zero terminators that directly follow.
5832 A corrupt section size could have loaded a whole
5833 slew of zero filled memory bytes. eg
5834 PR 17512: file: 070-19381-0.004. */
5835 while (start
< end
&& * start
== 0)
5840 if (length
== 0xffffffff)
5842 SAFE_BYTE_GET_AND_INC (length
, start
, 8, end
);
5844 initial_length_size
= 12;
5849 initial_length_size
= 4;
5852 block_end
= saved_start
+ length
+ initial_length_size
;
5853 if (block_end
> end
|| block_end
< start
)
5855 warn ("Invalid length 0x%s in FDE at %#08lx\n",
5856 dwarf_vmatoa_1 (NULL
, length
, offset_size
),
5857 (unsigned long) (saved_start
- section_start
));
5861 SAFE_BYTE_GET_AND_INC (cie_id
, start
, offset_size
, end
);
5863 if (is_eh
? (cie_id
== 0) : ((offset_size
== 4 && cie_id
== DW_CIE_ID
)
5864 || (offset_size
== 8 && cie_id
== DW64_CIE_ID
)))
5869 start
= read_cie (start
, end
, &cie
, &version
,
5870 &augmentation_data_len
, &augmentation_data
);
5871 /* PR 17512: file: 027-135133-0.005. */
5878 fc
->chunk_start
= saved_start
;
5879 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
5882 if (frame_need_space (fc
, mreg
) < 0)
5884 if (fc
->fde_encoding
)
5885 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
5887 printf ("\n%08lx ", (unsigned long) (saved_start
- section_start
));
5888 print_dwarf_vma (length
, fc
->ptr_size
);
5889 print_dwarf_vma (cie_id
, offset_size
);
5891 if (do_debug_frames_interp
)
5893 printf ("CIE \"%s\" cf=%d df=%d ra=%d\n", fc
->augmentation
,
5894 fc
->code_factor
, fc
->data_factor
, fc
->ra
);
5899 printf (" Version: %d\n", version
);
5900 printf (" Augmentation: \"%s\"\n", fc
->augmentation
);
5903 printf (" Pointer Size: %u\n", fc
->ptr_size
);
5904 printf (" Segment Size: %u\n", fc
->segment_size
);
5906 printf (" Code alignment factor: %u\n", fc
->code_factor
);
5907 printf (" Data alignment factor: %d\n", fc
->data_factor
);
5908 printf (" Return address column: %d\n", fc
->ra
);
5910 if (augmentation_data_len
)
5914 printf (" Augmentation data: ");
5915 for (i
= 0; i
< augmentation_data_len
; ++i
)
5916 /* FIXME: If do_wide is FALSE, then we should
5917 add carriage returns at 80 columns... */
5918 printf (" %02x", augmentation_data
[i
]);
5926 unsigned char *look_for
;
5927 static Frame_Chunk fde_fc
;
5928 unsigned long segment_selector
;
5932 dwarf_vma sign
= (dwarf_vma
) 1 << (offset_size
* 8 - 1);
5933 look_for
= start
- 4 - ((cie_id
^ sign
) - sign
);
5936 look_for
= section_start
+ cie_id
;
5938 if (look_for
<= saved_start
)
5940 for (cie
= chunks
; cie
; cie
= cie
->next
)
5941 if (cie
->chunk_start
== look_for
)
5946 for (cie
= forward_refs
; cie
; cie
= cie
->next
)
5947 if (cie
->chunk_start
== look_for
)
5951 unsigned int off_size
;
5952 unsigned char *cie_scan
;
5954 cie_scan
= look_for
;
5956 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 4, end
);
5957 if (length
== 0xffffffff)
5959 SAFE_BYTE_GET_AND_INC (length
, cie_scan
, 8, end
);
5966 SAFE_BYTE_GET_AND_INC (c_id
, cie_scan
, off_size
, end
);
5969 : ((off_size
== 4 && c_id
== DW_CIE_ID
)
5970 || (off_size
== 8 && c_id
== DW64_CIE_ID
)))
5975 read_cie (cie_scan
, end
, &cie
, &version
,
5976 &augmentation_data_len
, &augmentation_data
);
5977 /* PR 17512: file: 3450-2098-0.004. */
5980 warn (_("Failed to read CIE information\n"));
5983 cie
->next
= forward_refs
;
5985 cie
->chunk_start
= look_for
;
5986 mreg
= max_regs
> 0 ? max_regs
- 1 : 0;
5989 if (frame_need_space (cie
, mreg
) < 0)
5991 warn (_("Invalid max register\n"));
5994 if (cie
->fde_encoding
)
5996 = size_of_encoded_value (cie
->fde_encoding
);
6003 memset (fc
, 0, sizeof (Frame_Chunk
));
6007 warn ("Invalid CIE pointer 0x%s in FDE at %#08lx\n",
6008 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
6009 (unsigned long) (saved_start
- section_start
));
6011 fc
->col_type
= (short int *) xmalloc (sizeof (short int));
6012 fc
->col_offset
= (int *) xmalloc (sizeof (int));
6013 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1 : 0) < 0)
6015 warn (_("Invalid max register\n"));
6019 fc
->augmentation
= "";
6020 fc
->fde_encoding
= 0;
6021 fc
->ptr_size
= eh_addr_size
;
6022 fc
->segment_size
= 0;
6026 fc
->ncols
= cie
->ncols
;
6027 fc
->col_type
= (short int *) xcmalloc (fc
->ncols
, sizeof (short int));
6028 fc
->col_offset
= (int *) xcmalloc (fc
->ncols
, sizeof (int));
6029 memcpy (fc
->col_type
, cie
->col_type
, fc
->ncols
* sizeof (short int));
6030 memcpy (fc
->col_offset
, cie
->col_offset
, fc
->ncols
* sizeof (int));
6031 fc
->augmentation
= cie
->augmentation
;
6032 fc
->ptr_size
= cie
->ptr_size
;
6033 eh_addr_size
= cie
->ptr_size
;
6034 fc
->segment_size
= cie
->segment_size
;
6035 fc
->code_factor
= cie
->code_factor
;
6036 fc
->data_factor
= cie
->data_factor
;
6037 fc
->cfa_reg
= cie
->cfa_reg
;
6038 fc
->cfa_offset
= cie
->cfa_offset
;
6040 if (frame_need_space (fc
, max_regs
> 0 ? max_regs
- 1: 0) < 0)
6042 warn (_("Invalid max register\n"));
6045 fc
->fde_encoding
= cie
->fde_encoding
;
6048 if (fc
->fde_encoding
)
6049 encoded_ptr_size
= size_of_encoded_value (fc
->fde_encoding
);
6051 segment_selector
= 0;
6052 if (fc
->segment_size
)
6054 if (fc
->segment_size
> sizeof (segment_selector
))
6056 /* PR 17512: file: 9e196b3e. */
6057 warn (_("Probably corrupt segment size: %d - using 4 instead\n"), fc
->segment_size
);
6058 fc
->segment_size
= 4;
6060 SAFE_BYTE_GET_AND_INC (segment_selector
, start
, fc
->segment_size
, end
);
6063 fc
->pc_begin
= get_encoded_value (&start
, fc
->fde_encoding
, section
, end
);
6065 /* FIXME: It appears that sometimes the final pc_range value is
6066 encoded in less than encoded_ptr_size bytes. See the x86_64
6067 run of the "objcopy on compressed debug sections" test for an
6069 SAFE_BYTE_GET_AND_INC (fc
->pc_range
, start
, encoded_ptr_size
, end
);
6071 if (cie
->augmentation
[0] == 'z')
6073 augmentation_data_len
= LEB ();
6074 augmentation_data
= start
;
6075 start
+= augmentation_data_len
;
6076 /* PR 17512: file: 722-8446-0.004. */
6077 if (start
>= end
|| ((signed long) augmentation_data_len
) < 0)
6079 warn (_("Corrupt augmentation data length: %lx\n"),
6080 augmentation_data_len
);
6082 augmentation_data
= NULL
;
6083 augmentation_data_len
= 0;
6087 printf ("\n%08lx %s %s FDE cie=%08lx pc=",
6088 (unsigned long)(saved_start
- section_start
),
6089 dwarf_vmatoa_1 (NULL
, length
, fc
->ptr_size
),
6090 dwarf_vmatoa_1 (NULL
, cie_id
, offset_size
),
6091 (unsigned long)(cie
->chunk_start
- section_start
));
6093 if (fc
->segment_size
)
6094 printf ("%04lx:", segment_selector
);
6097 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
, fc
->ptr_size
),
6098 dwarf_vmatoa_1 (NULL
, fc
->pc_begin
+ fc
->pc_range
, fc
->ptr_size
));
6100 if (! do_debug_frames_interp
&& augmentation_data_len
)
6104 printf (" Augmentation data: ");
6105 for (i
= 0; i
< augmentation_data_len
; ++i
)
6106 printf (" %02x", augmentation_data
[i
]);
6112 /* At this point, fc is the current chunk, cie (if any) is set, and
6113 we're about to interpret instructions for the chunk. */
6114 /* ??? At present we need to do this always, since this sizes the
6115 fc->col_type and fc->col_offset arrays, which we write into always.
6116 We should probably split the interpreted and non-interpreted bits
6117 into two different routines, since there's so much that doesn't
6118 really overlap between them. */
6119 if (1 || do_debug_frames_interp
)
6121 /* Start by making a pass over the chunk, allocating storage
6122 and taking note of what registers are used. */
6123 unsigned char *tmp
= start
;
6125 while (start
< block_end
)
6127 unsigned int reg
, op
, opa
;
6129 unsigned char * new_start
;
6136 /* Warning: if you add any more cases to this switch, be
6137 sure to add them to the corresponding switch below. */
6140 case DW_CFA_advance_loc
:
6144 if (frame_need_space (fc
, opa
) >= 0)
6145 fc
->col_type
[opa
] = DW_CFA_undefined
;
6147 case DW_CFA_restore
:
6148 if (frame_need_space (fc
, opa
) >= 0)
6149 fc
->col_type
[opa
] = DW_CFA_undefined
;
6151 case DW_CFA_set_loc
:
6152 start
+= encoded_ptr_size
;
6154 case DW_CFA_advance_loc1
:
6157 case DW_CFA_advance_loc2
:
6160 case DW_CFA_advance_loc4
:
6163 case DW_CFA_offset_extended
:
6164 case DW_CFA_val_offset
:
6165 reg
= LEB (); LEB ();
6166 if (frame_need_space (fc
, reg
) >= 0)
6167 fc
->col_type
[reg
] = DW_CFA_undefined
;
6169 case DW_CFA_restore_extended
:
6171 if (frame_need_space (fc
, reg
) >= 0)
6172 fc
->col_type
[reg
] = DW_CFA_undefined
;
6174 case DW_CFA_undefined
:
6176 if (frame_need_space (fc
, reg
) >= 0)
6177 fc
->col_type
[reg
] = DW_CFA_undefined
;
6179 case DW_CFA_same_value
:
6181 if (frame_need_space (fc
, reg
) >= 0)
6182 fc
->col_type
[reg
] = DW_CFA_undefined
;
6184 case DW_CFA_register
:
6185 reg
= LEB (); LEB ();
6186 if (frame_need_space (fc
, reg
) >= 0)
6187 fc
->col_type
[reg
] = DW_CFA_undefined
;
6189 case DW_CFA_def_cfa
:
6192 case DW_CFA_def_cfa_register
:
6195 case DW_CFA_def_cfa_offset
:
6198 case DW_CFA_def_cfa_expression
:
6200 new_start
= start
+ temp
;
6201 if (new_start
< start
)
6203 warn (_("Corrupt CFA_def expression value: %lu\n"), temp
);
6209 case DW_CFA_expression
:
6210 case DW_CFA_val_expression
:
6213 new_start
= start
+ temp
;
6214 if (new_start
< start
)
6216 /* PR 17512: file:306-192417-0.005. */
6217 warn (_("Corrupt CFA expression value: %lu\n"), temp
);
6222 if (frame_need_space (fc
, reg
) >= 0)
6223 fc
->col_type
[reg
] = DW_CFA_undefined
;
6225 case DW_CFA_offset_extended_sf
:
6226 case DW_CFA_val_offset_sf
:
6227 reg
= LEB (); SLEB ();
6228 if (frame_need_space (fc
, reg
) >= 0)
6229 fc
->col_type
[reg
] = DW_CFA_undefined
;
6231 case DW_CFA_def_cfa_sf
:
6234 case DW_CFA_def_cfa_offset_sf
:
6237 case DW_CFA_MIPS_advance_loc8
:
6240 case DW_CFA_GNU_args_size
:
6243 case DW_CFA_GNU_negative_offset_extended
:
6244 reg
= LEB (); LEB ();
6245 if (frame_need_space (fc
, reg
) >= 0)
6246 fc
->col_type
[reg
] = DW_CFA_undefined
;
6257 /* Now we know what registers are used, make a second pass over
6258 the chunk, this time actually printing out the info. */
6260 while (start
< block_end
)
6262 unsigned char * tmp
;
6264 unsigned long ul
, reg
, roffs
;
6268 const char *reg_prefix
= "";
6275 /* Make a note if something other than DW_CFA_nop happens. */
6276 if (op
!= DW_CFA_nop
)
6279 /* Warning: if you add any more cases to this switch, be
6280 sure to add them to the corresponding switch above. */
6283 case DW_CFA_advance_loc
:
6284 if (do_debug_frames_interp
)
6285 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6287 printf (" DW_CFA_advance_loc: %d to %s\n",
6288 opa
* fc
->code_factor
,
6289 dwarf_vmatoa_1 (NULL
,
6290 fc
->pc_begin
+ opa
* fc
->code_factor
,
6292 fc
->pc_begin
+= opa
* fc
->code_factor
;
6297 if (opa
>= (unsigned int) fc
->ncols
)
6298 reg_prefix
= bad_reg
;
6299 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6300 printf (" DW_CFA_offset: %s%s at cfa%+ld\n",
6301 reg_prefix
, regname (opa
, 0),
6302 roffs
* fc
->data_factor
);
6303 if (*reg_prefix
== '\0')
6305 fc
->col_type
[opa
] = DW_CFA_offset
;
6306 fc
->col_offset
[opa
] = roffs
* fc
->data_factor
;
6310 case DW_CFA_restore
:
6311 if (opa
>= (unsigned int) cie
->ncols
6312 || opa
>= (unsigned int) fc
->ncols
)
6313 reg_prefix
= bad_reg
;
6314 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6315 printf (" DW_CFA_restore: %s%s\n",
6316 reg_prefix
, regname (opa
, 0));
6317 if (*reg_prefix
== '\0')
6319 fc
->col_type
[opa
] = cie
->col_type
[opa
];
6320 fc
->col_offset
[opa
] = cie
->col_offset
[opa
];
6321 if (do_debug_frames_interp
6322 && fc
->col_type
[opa
] == DW_CFA_unreferenced
)
6323 fc
->col_type
[opa
] = DW_CFA_undefined
;
6327 case DW_CFA_set_loc
:
6328 vma
= get_encoded_value (&start
, fc
->fde_encoding
, section
, block_end
);
6329 if (do_debug_frames_interp
)
6330 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6332 printf (" DW_CFA_set_loc: %s\n",
6333 dwarf_vmatoa_1 (NULL
, vma
, fc
->ptr_size
));
6337 case DW_CFA_advance_loc1
:
6338 SAFE_BYTE_GET_AND_INC (ofs
, start
, 1, end
);
6339 if (do_debug_frames_interp
)
6340 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6342 printf (" DW_CFA_advance_loc1: %ld to %s\n",
6343 (unsigned long) (ofs
* fc
->code_factor
),
6344 dwarf_vmatoa_1 (NULL
,
6345 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6347 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6350 case DW_CFA_advance_loc2
:
6351 SAFE_BYTE_GET_AND_INC (ofs
, start
, 2, block_end
);
6352 if (do_debug_frames_interp
)
6353 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6355 printf (" DW_CFA_advance_loc2: %ld to %s\n",
6356 (unsigned long) (ofs
* fc
->code_factor
),
6357 dwarf_vmatoa_1 (NULL
,
6358 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6360 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6363 case DW_CFA_advance_loc4
:
6364 SAFE_BYTE_GET_AND_INC (ofs
, start
, 4, block_end
);
6365 if (do_debug_frames_interp
)
6366 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6368 printf (" DW_CFA_advance_loc4: %ld to %s\n",
6369 (unsigned long) (ofs
* fc
->code_factor
),
6370 dwarf_vmatoa_1 (NULL
,
6371 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6373 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6376 case DW_CFA_offset_extended
:
6379 if (reg
>= (unsigned int) fc
->ncols
)
6380 reg_prefix
= bad_reg
;
6381 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6382 printf (" DW_CFA_offset_extended: %s%s at cfa%+ld\n",
6383 reg_prefix
, regname (reg
, 0),
6384 roffs
* fc
->data_factor
);
6385 if (*reg_prefix
== '\0')
6387 fc
->col_type
[reg
] = DW_CFA_offset
;
6388 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
6392 case DW_CFA_val_offset
:
6395 if (reg
>= (unsigned int) fc
->ncols
)
6396 reg_prefix
= bad_reg
;
6397 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6398 printf (" DW_CFA_val_offset: %s%s at cfa%+ld\n",
6399 reg_prefix
, regname (reg
, 0),
6400 roffs
* fc
->data_factor
);
6401 if (*reg_prefix
== '\0')
6403 fc
->col_type
[reg
] = DW_CFA_val_offset
;
6404 fc
->col_offset
[reg
] = roffs
* fc
->data_factor
;
6408 case DW_CFA_restore_extended
:
6410 if (reg
>= (unsigned int) cie
->ncols
6411 || reg
>= (unsigned int) fc
->ncols
)
6412 reg_prefix
= bad_reg
;
6413 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6414 printf (" DW_CFA_restore_extended: %s%s\n",
6415 reg_prefix
, regname (reg
, 0));
6416 if (*reg_prefix
== '\0')
6418 fc
->col_type
[reg
] = cie
->col_type
[reg
];
6419 fc
->col_offset
[reg
] = cie
->col_offset
[reg
];
6423 case DW_CFA_undefined
:
6425 if (reg
>= (unsigned int) fc
->ncols
)
6426 reg_prefix
= bad_reg
;
6427 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6428 printf (" DW_CFA_undefined: %s%s\n",
6429 reg_prefix
, regname (reg
, 0));
6430 if (*reg_prefix
== '\0')
6432 fc
->col_type
[reg
] = DW_CFA_undefined
;
6433 fc
->col_offset
[reg
] = 0;
6437 case DW_CFA_same_value
:
6439 if (reg
>= (unsigned int) fc
->ncols
)
6440 reg_prefix
= bad_reg
;
6441 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6442 printf (" DW_CFA_same_value: %s%s\n",
6443 reg_prefix
, regname (reg
, 0));
6444 if (*reg_prefix
== '\0')
6446 fc
->col_type
[reg
] = DW_CFA_same_value
;
6447 fc
->col_offset
[reg
] = 0;
6451 case DW_CFA_register
:
6454 if (reg
>= (unsigned int) fc
->ncols
)
6455 reg_prefix
= bad_reg
;
6456 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6458 printf (" DW_CFA_register: %s%s in ",
6459 reg_prefix
, regname (reg
, 0));
6460 puts (regname (roffs
, 0));
6462 if (*reg_prefix
== '\0')
6464 fc
->col_type
[reg
] = DW_CFA_register
;
6465 fc
->col_offset
[reg
] = roffs
;
6469 case DW_CFA_remember_state
:
6470 if (! do_debug_frames_interp
)
6471 printf (" DW_CFA_remember_state\n");
6472 rs
= (Frame_Chunk
*) xmalloc (sizeof (Frame_Chunk
));
6473 rs
->cfa_offset
= fc
->cfa_offset
;
6474 rs
->cfa_reg
= fc
->cfa_reg
;
6476 rs
->cfa_exp
= fc
->cfa_exp
;
6477 rs
->ncols
= fc
->ncols
;
6478 rs
->col_type
= (short int *) xcmalloc (rs
->ncols
,
6479 sizeof (* rs
->col_type
));
6480 rs
->col_offset
= (int *) xcmalloc (rs
->ncols
, sizeof (* rs
->col_offset
));
6481 memcpy (rs
->col_type
, fc
->col_type
, rs
->ncols
* sizeof (* fc
->col_type
));
6482 memcpy (rs
->col_offset
, fc
->col_offset
, rs
->ncols
* sizeof (* fc
->col_offset
));
6483 rs
->next
= remembered_state
;
6484 remembered_state
= rs
;
6487 case DW_CFA_restore_state
:
6488 if (! do_debug_frames_interp
)
6489 printf (" DW_CFA_restore_state\n");
6490 rs
= remembered_state
;
6493 remembered_state
= rs
->next
;
6494 fc
->cfa_offset
= rs
->cfa_offset
;
6495 fc
->cfa_reg
= rs
->cfa_reg
;
6497 fc
->cfa_exp
= rs
->cfa_exp
;
6498 if (frame_need_space (fc
, rs
->ncols
- 1) < 0)
6500 warn (_("Invalid column number in saved frame state\n"));
6504 memcpy (fc
->col_type
, rs
->col_type
, rs
->ncols
* sizeof (* rs
->col_type
));
6505 memcpy (fc
->col_offset
, rs
->col_offset
,
6506 rs
->ncols
* sizeof (* rs
->col_offset
));
6507 free (rs
->col_type
);
6508 free (rs
->col_offset
);
6511 else if (do_debug_frames_interp
)
6512 printf ("Mismatched DW_CFA_restore_state\n");
6515 case DW_CFA_def_cfa
:
6516 fc
->cfa_reg
= LEB ();
6517 fc
->cfa_offset
= LEB ();
6519 if (! do_debug_frames_interp
)
6520 printf (" DW_CFA_def_cfa: %s ofs %d\n",
6521 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
6524 case DW_CFA_def_cfa_register
:
6525 fc
->cfa_reg
= LEB ();
6527 if (! do_debug_frames_interp
)
6528 printf (" DW_CFA_def_cfa_register: %s\n",
6529 regname (fc
->cfa_reg
, 0));
6532 case DW_CFA_def_cfa_offset
:
6533 fc
->cfa_offset
= LEB ();
6534 if (! do_debug_frames_interp
)
6535 printf (" DW_CFA_def_cfa_offset: %d\n", (int) fc
->cfa_offset
);
6539 if (! do_debug_frames_interp
)
6540 printf (" DW_CFA_nop\n");
6543 case DW_CFA_def_cfa_expression
:
6545 if (start
>= block_end
|| ul
> (unsigned long) (block_end
- start
))
6547 printf (_(" DW_CFA_def_cfa_expression: <corrupt len %lu>\n"), ul
);
6550 if (! do_debug_frames_interp
)
6552 printf (" DW_CFA_def_cfa_expression (");
6553 decode_location_expression (start
, eh_addr_size
, 0, -1,
6561 case DW_CFA_expression
:
6564 if (reg
>= (unsigned int) fc
->ncols
)
6565 reg_prefix
= bad_reg
;
6566 /* PR 17512: file: 069-133014-0.006. */
6567 /* PR 17512: file: 98c02eb4. */
6569 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
6571 printf (_(" DW_CFA_expression: <corrupt len %lu>\n"), ul
);
6574 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6576 printf (" DW_CFA_expression: %s%s (",
6577 reg_prefix
, regname (reg
, 0));
6578 decode_location_expression (start
, eh_addr_size
, 0, -1,
6582 if (*reg_prefix
== '\0')
6583 fc
->col_type
[reg
] = DW_CFA_expression
;
6587 case DW_CFA_val_expression
:
6590 if (reg
>= (unsigned int) fc
->ncols
)
6591 reg_prefix
= bad_reg
;
6593 if (start
>= block_end
|| tmp
> block_end
|| tmp
< start
)
6595 printf (" DW_CFA_val_expression: <corrupt len %lu>\n", ul
);
6598 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6600 printf (" DW_CFA_val_expression: %s%s (",
6601 reg_prefix
, regname (reg
, 0));
6602 decode_location_expression (start
, eh_addr_size
, 0, -1,
6606 if (*reg_prefix
== '\0')
6607 fc
->col_type
[reg
] = DW_CFA_val_expression
;
6611 case DW_CFA_offset_extended_sf
:
6614 if (frame_need_space (fc
, reg
) < 0)
6615 reg_prefix
= bad_reg
;
6616 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6617 printf (" DW_CFA_offset_extended_sf: %s%s at cfa%+ld\n",
6618 reg_prefix
, regname (reg
, 0),
6619 (long)(l
* fc
->data_factor
));
6620 if (*reg_prefix
== '\0')
6622 fc
->col_type
[reg
] = DW_CFA_offset
;
6623 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6627 case DW_CFA_val_offset_sf
:
6630 if (frame_need_space (fc
, reg
) < 0)
6631 reg_prefix
= bad_reg
;
6632 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6633 printf (" DW_CFA_val_offset_sf: %s%s at cfa%+ld\n",
6634 reg_prefix
, regname (reg
, 0),
6635 (long)(l
* fc
->data_factor
));
6636 if (*reg_prefix
== '\0')
6638 fc
->col_type
[reg
] = DW_CFA_val_offset
;
6639 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6643 case DW_CFA_def_cfa_sf
:
6644 fc
->cfa_reg
= LEB ();
6645 fc
->cfa_offset
= SLEB ();
6646 fc
->cfa_offset
= fc
->cfa_offset
* fc
->data_factor
;
6648 if (! do_debug_frames_interp
)
6649 printf (" DW_CFA_def_cfa_sf: %s ofs %d\n",
6650 regname (fc
->cfa_reg
, 0), (int) fc
->cfa_offset
);
6653 case DW_CFA_def_cfa_offset_sf
:
6654 fc
->cfa_offset
= SLEB ();
6655 fc
->cfa_offset
*= fc
->data_factor
;
6656 if (! do_debug_frames_interp
)
6657 printf (" DW_CFA_def_cfa_offset_sf: %d\n", (int) fc
->cfa_offset
);
6660 case DW_CFA_MIPS_advance_loc8
:
6661 SAFE_BYTE_GET_AND_INC (ofs
, start
, 8, block_end
);
6662 if (do_debug_frames_interp
)
6663 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6665 printf (" DW_CFA_MIPS_advance_loc8: %ld to %s\n",
6666 (unsigned long) (ofs
* fc
->code_factor
),
6667 dwarf_vmatoa_1 (NULL
,
6668 fc
->pc_begin
+ ofs
* fc
->code_factor
,
6670 fc
->pc_begin
+= ofs
* fc
->code_factor
;
6673 case DW_CFA_GNU_window_save
:
6674 if (! do_debug_frames_interp
)
6675 printf (" DW_CFA_GNU_window_save\n");
6678 case DW_CFA_GNU_args_size
:
6680 if (! do_debug_frames_interp
)
6681 printf (" DW_CFA_GNU_args_size: %ld\n", ul
);
6684 case DW_CFA_GNU_negative_offset_extended
:
6687 if (frame_need_space (fc
, reg
) < 0)
6688 reg_prefix
= bad_reg
;
6689 if (! do_debug_frames_interp
|| *reg_prefix
!= '\0')
6690 printf (" DW_CFA_GNU_negative_offset_extended: %s%s at cfa%+ld\n",
6691 reg_prefix
, regname (reg
, 0),
6692 (long)(l
* fc
->data_factor
));
6693 if (*reg_prefix
== '\0')
6695 fc
->col_type
[reg
] = DW_CFA_offset
;
6696 fc
->col_offset
[reg
] = l
* fc
->data_factor
;
6701 if (op
>= DW_CFA_lo_user
&& op
<= DW_CFA_hi_user
)
6702 printf (_(" DW_CFA_??? (User defined call frame op: %#x)\n"), op
);
6704 warn (_("Unsupported or unknown Dwarf Call Frame Instruction number: %#x\n"), op
);
6709 /* Interpret the CFA - as long as it is not completely full of NOPs. */
6710 if (do_debug_frames_interp
&& ! all_nops
)
6711 frame_display_row (fc
, &need_col_headers
, &max_regs
);
6714 eh_addr_size
= saved_eh_addr_size
;
6727 display_gdb_index (struct dwarf_section
*section
,
6728 void *file ATTRIBUTE_UNUSED
)
6730 unsigned char *start
= section
->start
;
6732 uint32_t cu_list_offset
, tu_list_offset
;
6733 uint32_t address_table_offset
, symbol_table_offset
, constant_pool_offset
;
6734 unsigned int cu_list_elements
, tu_list_elements
;
6735 unsigned int address_table_size
, symbol_table_slots
;
6736 unsigned char *cu_list
, *tu_list
;
6737 unsigned char *address_table
, *symbol_table
, *constant_pool
;
6740 /* The documentation for the format of this file is in gdb/dwarf2read.c. */
6742 printf (_("Contents of the %s section:\n"), section
->name
);
6744 if (section
->size
< 6 * sizeof (uint32_t))
6746 warn (_("Truncated header in the %s section.\n"), section
->name
);
6750 version
= byte_get_little_endian (start
, 4);
6751 printf (_("Version %ld\n"), (long) version
);
6753 /* Prior versions are obsolete, and future versions may not be
6754 backwards compatible. */
6755 if (version
< 3 || version
> 8)
6757 warn (_("Unsupported version %lu.\n"), (unsigned long) version
);
6761 warn (_("The address table data in version 3 may be wrong.\n"));
6763 warn (_("Version 4 does not support case insensitive lookups.\n"));
6765 warn (_("Version 5 does not include inlined functions.\n"));
6767 warn (_("Version 6 does not include symbol attributes.\n"));
6768 /* Version 7 indices generated by Gold have bad type unit references,
6769 PR binutils/15021. But we don't know if the index was generated by
6770 Gold or not, so to avoid worrying users with gdb-generated indices
6771 we say nothing for version 7 here. */
6773 cu_list_offset
= byte_get_little_endian (start
+ 4, 4);
6774 tu_list_offset
= byte_get_little_endian (start
+ 8, 4);
6775 address_table_offset
= byte_get_little_endian (start
+ 12, 4);
6776 symbol_table_offset
= byte_get_little_endian (start
+ 16, 4);
6777 constant_pool_offset
= byte_get_little_endian (start
+ 20, 4);
6779 if (cu_list_offset
> section
->size
6780 || tu_list_offset
> section
->size
6781 || address_table_offset
> section
->size
6782 || symbol_table_offset
> section
->size
6783 || constant_pool_offset
> section
->size
)
6785 warn (_("Corrupt header in the %s section.\n"), section
->name
);
6789 /* PR 17531: file: 418d0a8a. */
6790 if (tu_list_offset
< cu_list_offset
)
6792 warn (_("TU offset (%x) is less than CU offset (%x)\n"),
6793 tu_list_offset
, cu_list_offset
);
6797 cu_list_elements
= (tu_list_offset
- cu_list_offset
) / 8;
6799 if (address_table_offset
< tu_list_offset
)
6801 warn (_("Address table offset (%x) is less than TU offset (%x)\n"),
6802 address_table_offset
, tu_list_offset
);
6806 tu_list_elements
= (address_table_offset
- tu_list_offset
) / 8;
6808 /* PR 17531: file: 18a47d3d. */
6809 if (symbol_table_offset
< address_table_offset
)
6811 warn (_("Symbol table offset (%xl) is less then Address table offset (%x)\n"),
6812 symbol_table_offset
, address_table_offset
);
6816 address_table_size
= symbol_table_offset
- address_table_offset
;
6818 if (constant_pool_offset
< symbol_table_offset
)
6820 warn (_("Constant pool offset (%x) is less than symbol table offset (%x)\n"),
6821 constant_pool_offset
, symbol_table_offset
);
6825 symbol_table_slots
= (constant_pool_offset
- symbol_table_offset
) / 8;
6827 cu_list
= start
+ cu_list_offset
;
6828 tu_list
= start
+ tu_list_offset
;
6829 address_table
= start
+ address_table_offset
;
6830 symbol_table
= start
+ symbol_table_offset
;
6831 constant_pool
= start
+ constant_pool_offset
;
6833 if (address_table
+ address_table_size
* (2 + 8 + 4) > section
->start
+ section
->size
)
6835 warn (_("Address table extends beyond end of section.\n"));
6839 printf (_("\nCU table:\n"));
6840 for (i
= 0; i
< cu_list_elements
; i
+= 2)
6842 uint64_t cu_offset
= byte_get_little_endian (cu_list
+ i
* 8, 8);
6843 uint64_t cu_length
= byte_get_little_endian (cu_list
+ i
* 8 + 8, 8);
6845 printf (_("[%3u] 0x%lx - 0x%lx\n"), i
/ 2,
6846 (unsigned long) cu_offset
,
6847 (unsigned long) (cu_offset
+ cu_length
- 1));
6850 printf (_("\nTU table:\n"));
6851 for (i
= 0; i
< tu_list_elements
; i
+= 3)
6853 uint64_t tu_offset
= byte_get_little_endian (tu_list
+ i
* 8, 8);
6854 uint64_t type_offset
= byte_get_little_endian (tu_list
+ i
* 8 + 8, 8);
6855 uint64_t signature
= byte_get_little_endian (tu_list
+ i
* 8 + 16, 8);
6857 printf (_("[%3u] 0x%lx 0x%lx "), i
/ 3,
6858 (unsigned long) tu_offset
,
6859 (unsigned long) type_offset
);
6860 print_dwarf_vma (signature
, 8);
6864 printf (_("\nAddress table:\n"));
6865 for (i
= 0; i
< address_table_size
&& i
<= address_table_size
- (2 * 8 + 4);
6868 uint64_t low
= byte_get_little_endian (address_table
+ i
, 8);
6869 uint64_t high
= byte_get_little_endian (address_table
+ i
+ 8, 8);
6870 uint32_t cu_index
= byte_get_little_endian (address_table
+ i
+ 16, 4);
6872 print_dwarf_vma (low
, 8);
6873 print_dwarf_vma (high
, 8);
6874 printf (_("%lu\n"), (unsigned long) cu_index
);
6877 printf (_("\nSymbol table:\n"));
6878 for (i
= 0; i
< symbol_table_slots
; ++i
)
6880 uint32_t name_offset
= byte_get_little_endian (symbol_table
+ i
* 8, 4);
6881 uint32_t cu_vector_offset
= byte_get_little_endian (symbol_table
+ i
* 8 + 4, 4);
6882 uint32_t num_cus
, cu
;
6884 if (name_offset
!= 0
6885 || cu_vector_offset
!= 0)
6888 unsigned char * adr
;
6890 adr
= constant_pool
+ name_offset
;
6891 /* PR 17531: file: 5b7b07ad. */
6892 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
)
6894 printf (_("[%3u] <corrupt offset: %x>"), i
, name_offset
);
6895 warn (_("Corrupt name offset of 0x%x found for symbol table slot %d\n"),
6899 printf ("[%3u] %.*s:", i
,
6900 (int) (section
->size
- (constant_pool_offset
+ name_offset
)),
6901 constant_pool
+ name_offset
);
6903 adr
= constant_pool
+ cu_vector_offset
;
6904 if (adr
< constant_pool
|| adr
>= section
->start
+ section
->size
- 3)
6906 printf (_("<invalid CU vector offset: %x>\n"), cu_vector_offset
);
6907 warn (_("Corrupt CU vector offset of 0x%x found for symbol table slot %d\n"),
6908 cu_vector_offset
, i
);
6912 num_cus
= byte_get_little_endian (adr
, 4);
6914 adr
= constant_pool
+ cu_vector_offset
+ 4 + num_cus
* 4;
6915 if (num_cus
* 4 < num_cus
6916 || adr
>= section
->start
+ section
->size
6917 || adr
< constant_pool
)
6919 printf ("<invalid number of CUs: %d>\n", num_cus
);
6920 warn (_("Invalid number of CUs (0x%x) for symbol table slot %d\n"),
6928 for (j
= 0; j
< num_cus
; ++j
)
6931 gdb_index_symbol_kind kind
;
6933 cu
= byte_get_little_endian (constant_pool
+ cu_vector_offset
+ 4 + j
* 4, 4);
6934 is_static
= GDB_INDEX_SYMBOL_STATIC_VALUE (cu
);
6935 kind
= GDB_INDEX_SYMBOL_KIND_VALUE (cu
);
6936 cu
= GDB_INDEX_CU_VALUE (cu
);
6937 /* Convert to TU number if it's for a type unit. */
6938 if (cu
>= cu_list_elements
/ 2)
6939 printf ("%cT%lu", num_cus
> 1 ? '\t' : ' ',
6940 (unsigned long) (cu
- cu_list_elements
/ 2));
6942 printf ("%c%lu", num_cus
> 1 ? '\t' : ' ', (unsigned long) cu
);
6944 printf (" [%s, %s]",
6945 is_static
? _("static") : _("global"),
6946 get_gdb_index_symbol_kind_name (kind
));
6958 /* Pre-allocate enough space for the CU/TU sets needed. */
6961 prealloc_cu_tu_list (unsigned int nshndx
)
6963 if (shndx_pool
== NULL
)
6965 shndx_pool_size
= nshndx
;
6966 shndx_pool_used
= 0;
6967 shndx_pool
= (unsigned int *) xcmalloc (shndx_pool_size
,
6968 sizeof (unsigned int));
6972 shndx_pool_size
= shndx_pool_used
+ nshndx
;
6973 shndx_pool
= (unsigned int *) xcrealloc (shndx_pool
, shndx_pool_size
,
6974 sizeof (unsigned int));
6979 add_shndx_to_cu_tu_entry (unsigned int shndx
)
6981 if (shndx_pool_used
>= shndx_pool_size
)
6983 error (_("Internal error: out of space in the shndx pool.\n"));
6986 shndx_pool
[shndx_pool_used
++] = shndx
;
6990 end_cu_tu_entry (void)
6992 if (shndx_pool_used
>= shndx_pool_size
)
6994 error (_("Internal error: out of space in the shndx pool.\n"));
6997 shndx_pool
[shndx_pool_used
++] = 0;
7000 /* Return the short name of a DWARF section given by a DW_SECT enumerator. */
7003 get_DW_SECT_short_name (unsigned int dw_sect
)
7005 static char buf
[16];
7013 case DW_SECT_ABBREV
:
7019 case DW_SECT_STR_OFFSETS
:
7021 case DW_SECT_MACINFO
:
7029 snprintf (buf
, sizeof (buf
), "%d", dw_sect
);
7033 /* Process a CU or TU index. If DO_DISPLAY is true, print the contents.
7034 These sections are extensions for Fission.
7035 See http://gcc.gnu.org/wiki/DebugFissionDWP. */
7038 process_cu_tu_index (struct dwarf_section
*section
, int do_display
)
7040 unsigned char *phdr
= section
->start
;
7041 unsigned char *limit
= phdr
+ section
->size
;
7042 unsigned char *phash
;
7043 unsigned char *pindex
;
7044 unsigned char *ppool
;
7045 unsigned int version
;
7046 unsigned int ncols
= 0;
7048 unsigned int nslots
;
7051 dwarf_vma signature_high
;
7052 dwarf_vma signature_low
;
7055 /* PR 17512: file: 002-168123-0.004. */
7058 warn (_("Section %s is empty\n"), section
->name
);
7061 /* PR 17512: file: 002-376-0.004. */
7062 if (section
->size
< 24)
7064 warn (_("Section %s is too small to contain a CU/TU header\n"),
7069 SAFE_BYTE_GET (version
, phdr
, 4, limit
);
7071 SAFE_BYTE_GET (ncols
, phdr
+ 4, 4, limit
);
7072 SAFE_BYTE_GET (nused
, phdr
+ 8, 4, limit
);
7073 SAFE_BYTE_GET (nslots
, phdr
+ 12, 4, limit
);
7076 pindex
= phash
+ nslots
* 8;
7077 ppool
= pindex
+ nslots
* 4;
7079 /* PR 17531: file: 45d69832. */
7080 if (pindex
< phash
|| ppool
< phdr
|| (pindex
== phash
&& nslots
!= 0))
7082 warn (_("Section %s is too small for %d slots\n"),
7083 section
->name
, nslots
);
7089 printf (_("Contents of the %s section:\n\n"), section
->name
);
7090 printf (_(" Version: %d\n"), version
);
7092 printf (_(" Number of columns: %d\n"), ncols
);
7093 printf (_(" Number of used entries: %d\n"), nused
);
7094 printf (_(" Number of slots: %d\n\n"), nslots
);
7097 if (ppool
> limit
|| ppool
< phdr
)
7099 warn (_("Section %s too small for %d hash table entries\n"),
7100 section
->name
, nslots
);
7107 prealloc_cu_tu_list ((limit
- ppool
) / 4);
7108 for (i
= 0; i
< nslots
; i
++)
7110 unsigned char *shndx_list
;
7113 SAFE_BYTE_GET64 (phash
, &signature_high
, &signature_low
, limit
);
7114 if (signature_high
!= 0 || signature_low
!= 0)
7116 SAFE_BYTE_GET (j
, pindex
, 4, limit
);
7117 shndx_list
= ppool
+ j
* 4;
7118 /* PR 17531: file: 705e010d. */
7119 if (shndx_list
< ppool
)
7121 warn (_("Section index pool located before start of section\n"));
7126 printf (_(" [%3d] Signature: 0x%s Sections: "),
7127 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
7128 buf
, sizeof (buf
)));
7131 if (shndx_list
>= limit
)
7133 warn (_("Section %s too small for shndx pool\n"),
7137 SAFE_BYTE_GET (shndx
, shndx_list
, 4, limit
);
7141 printf (" %d", shndx
);
7143 add_shndx_to_cu_tu_entry (shndx
);
7155 else if (version
== 2)
7158 unsigned int dw_sect
;
7159 unsigned char *ph
= phash
;
7160 unsigned char *pi
= pindex
;
7161 unsigned char *poffsets
= ppool
+ ncols
* 4;
7162 unsigned char *psizes
= poffsets
+ nused
* ncols
* 4;
7163 unsigned char *pend
= psizes
+ nused
* ncols
* 4;
7164 bfd_boolean is_tu_index
;
7165 struct cu_tu_set
*this_set
= NULL
;
7167 unsigned char *prow
;
7169 is_tu_index
= strcmp (section
->name
, ".debug_tu_index") == 0;
7171 /* PR 17531: file: 0dd159bf.
7172 Check for wraparound with an overlarge ncols value. */
7173 if (poffsets
< ppool
|| (unsigned int) ((poffsets
- ppool
) / 4) != ncols
)
7175 warn (_("Overlarge number of columns: %x\n"), ncols
);
7181 warn (_("Section %s too small for offset and size tables\n"),
7188 printf (_(" Offset table\n"));
7189 printf (" slot %-16s ",
7190 is_tu_index
? _("signature") : _("dwo_id"));
7197 tu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
7203 cu_sets
= xcalloc2 (nused
, sizeof (struct cu_tu_set
));
7210 for (j
= 0; j
< ncols
; j
++)
7212 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
7213 printf (" %8s", get_DW_SECT_short_name (dw_sect
));
7218 for (i
= 0; i
< nslots
; i
++)
7220 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
7222 SAFE_BYTE_GET (row
, pi
, 4, limit
);
7225 /* PR 17531: file: a05f6ab3. */
7228 warn (_("Row index (%u) is larger than number of used entries (%u)\n"),
7234 memcpy (&this_set
[row
- 1].signature
, ph
, sizeof (uint64_t));
7236 prow
= poffsets
+ (row
- 1) * ncols
* 4;
7237 /* PR 17531: file: b8ce60a8. */
7238 if (prow
< poffsets
|| prow
> limit
)
7240 warn (_("Row index (%u) * num columns (%u) > space remaining in section\n"),
7246 printf (_(" [%3d] 0x%s"),
7247 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
7248 buf
, sizeof (buf
)));
7249 for (j
= 0; j
< ncols
; j
++)
7251 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
7253 printf (" %8d", val
);
7256 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
7258 /* PR 17531: file: 10796eb3. */
7259 if (dw_sect
>= DW_SECT_MAX
)
7260 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
7262 this_set
[row
- 1].section_offsets
[dw_sect
] = val
;
7278 printf (_(" Size table\n"));
7279 printf (" slot %-16s ",
7280 is_tu_index
? _("signature") : _("dwo_id"));
7283 for (j
= 0; j
< ncols
; j
++)
7285 SAFE_BYTE_GET (val
, ppool
+ j
* 4, 4, limit
);
7287 printf (" %8s", get_DW_SECT_short_name (val
));
7293 for (i
= 0; i
< nslots
; i
++)
7295 SAFE_BYTE_GET64 (ph
, &signature_high
, &signature_low
, limit
);
7297 SAFE_BYTE_GET (row
, pi
, 4, limit
);
7300 prow
= psizes
+ (row
- 1) * ncols
* 4;
7303 printf (_(" [%3d] 0x%s"),
7304 i
, dwarf_vmatoa64 (signature_high
, signature_low
,
7305 buf
, sizeof (buf
)));
7307 for (j
= 0; j
< ncols
; j
++)
7309 SAFE_BYTE_GET (val
, prow
+ j
* 4, 4, limit
);
7311 printf (" %8d", val
);
7314 SAFE_BYTE_GET (dw_sect
, ppool
+ j
* 4, 4, limit
);
7315 if (dw_sect
>= DW_SECT_MAX
)
7316 warn (_("Overlarge Dwarf section index detected: %u\n"), dw_sect
);
7318 this_set
[row
- 1].section_sizes
[dw_sect
] = val
;
7330 else if (do_display
)
7331 printf (_(" Unsupported version (%d)\n"), version
);
7339 /* Load the CU and TU indexes if present. This will build a list of
7340 section sets that we can use to associate a .debug_info.dwo section
7341 with its associated .debug_abbrev.dwo section in a .dwp file. */
7344 load_cu_tu_indexes (void *file
)
7346 /* If we have already loaded (or tried to load) the CU and TU indexes
7347 then do not bother to repeat the task. */
7348 if (cu_tu_indexes_read
)
7351 if (load_debug_section (dwp_cu_index
, file
))
7352 process_cu_tu_index (&debug_displays
[dwp_cu_index
].section
, 0);
7354 if (load_debug_section (dwp_tu_index
, file
))
7355 process_cu_tu_index (&debug_displays
[dwp_tu_index
].section
, 0);
7357 cu_tu_indexes_read
= 1;
7360 /* Find the set of sections that includes section SHNDX. */
7363 find_cu_tu_set (void *file
, unsigned int shndx
)
7367 load_cu_tu_indexes (file
);
7369 /* Find SHNDX in the shndx pool. */
7370 for (i
= 0; i
< shndx_pool_used
; i
++)
7371 if (shndx_pool
[i
] == shndx
)
7374 if (i
>= shndx_pool_used
)
7377 /* Now backup to find the first entry in the set. */
7378 while (i
> 0 && shndx_pool
[i
- 1] != 0)
7381 return shndx_pool
+ i
;
7384 /* Display a .debug_cu_index or .debug_tu_index section. */
7387 display_cu_index (struct dwarf_section
*section
, void *file ATTRIBUTE_UNUSED
)
7389 return process_cu_tu_index (section
, 1);
7393 display_debug_not_supported (struct dwarf_section
*section
,
7394 void *file ATTRIBUTE_UNUSED
)
7396 printf (_("Displaying the debug contents of section %s is not yet supported.\n"),
7402 /* Like malloc, but takes two parameters like calloc.
7403 Verifies that the first parameter is not too large.
7404 Note: does *not* initialise the allocated memory to zero. */
7406 cmalloc (size_t nmemb
, size_t size
)
7408 /* Check for overflow. */
7409 if (nmemb
>= ~(size_t) 0 / size
)
7412 return xmalloc (nmemb
* size
);
7415 /* Like xmalloc, but takes two parameters like calloc.
7416 Verifies that the first parameter is not too large.
7417 Note: does *not* initialise the allocated memory to zero. */
7419 xcmalloc (size_t nmemb
, size_t size
)
7421 /* Check for overflow. */
7422 if (nmemb
>= ~(size_t) 0 / size
)
7425 _("Attempt to allocate an array with an excessive number of elements: 0x%lx\n"),
7430 return xmalloc (nmemb
* size
);
7433 /* Like xrealloc, but takes three parameters.
7434 Verifies that the second parameter is not too large.
7435 Note: does *not* initialise any new memory to zero. */
7437 xcrealloc (void *ptr
, size_t nmemb
, size_t size
)
7439 /* Check for overflow. */
7440 if (nmemb
>= ~(size_t) 0 / size
)
7443 _("Attempt to re-allocate an array with an excessive number of elements: 0x%lx\n"),
7448 return xrealloc (ptr
, nmemb
* size
);
7451 /* Like xcalloc, but verifies that the first parameter is not too large. */
7453 xcalloc2 (size_t nmemb
, size_t size
)
7455 /* Check for overflow. */
7456 if (nmemb
>= ~(size_t) 0 / size
)
7459 _("Attempt to allocate a zero'ed array with an excessive number of elements: 0x%lx\n"),
7464 return xcalloc (nmemb
, size
);
7468 free_debug_memory (void)
7474 for (i
= 0; i
< max
; i
++)
7475 free_debug_section ((enum dwarf_section_display_enum
) i
);
7477 if (debug_information
!= NULL
)
7479 if (num_debug_info_entries
!= DEBUG_INFO_UNAVAILABLE
)
7481 for (i
= 0; i
< num_debug_info_entries
; i
++)
7483 if (!debug_information
[i
].max_loc_offsets
)
7485 free (debug_information
[i
].loc_offsets
);
7486 free (debug_information
[i
].have_frame_base
);
7488 if (!debug_information
[i
].max_range_lists
)
7489 free (debug_information
[i
].range_lists
);
7492 free (debug_information
);
7493 debug_information
= NULL
;
7494 alloc_num_debug_info_entries
= num_debug_info_entries
= 0;
7499 dwarf_select_sections_by_names (const char *names
)
7503 const char * option
;
7507 debug_dump_long_opts
;
7509 static const debug_dump_long_opts opts_table
[] =
7511 /* Please keep this table alpha- sorted. */
7512 { "Ranges", & do_debug_ranges
, 1 },
7513 { "abbrev", & do_debug_abbrevs
, 1 },
7514 { "addr", & do_debug_addr
, 1 },
7515 { "aranges", & do_debug_aranges
, 1 },
7516 { "cu_index", & do_debug_cu_index
, 1 },
7517 { "decodedline", & do_debug_lines
, FLAG_DEBUG_LINES_DECODED
},
7518 { "frames", & do_debug_frames
, 1 },
7519 { "frames-interp", & do_debug_frames_interp
, 1 },
7520 /* The special .gdb_index section. */
7521 { "gdb_index", & do_gdb_index
, 1 },
7522 { "info", & do_debug_info
, 1 },
7523 { "line", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
}, /* For backwards compatibility. */
7524 { "loc", & do_debug_loc
, 1 },
7525 { "macro", & do_debug_macinfo
, 1 },
7526 { "pubnames", & do_debug_pubnames
, 1 },
7527 { "pubtypes", & do_debug_pubtypes
, 1 },
7528 /* This entry is for compatability
7529 with earlier versions of readelf. */
7530 { "ranges", & do_debug_aranges
, 1 },
7531 { "rawline", & do_debug_lines
, FLAG_DEBUG_LINES_RAW
},
7532 { "str", & do_debug_str
, 1 },
7533 /* These trace_* sections are used by Itanium VMS. */
7534 { "trace_abbrev", & do_trace_abbrevs
, 1 },
7535 { "trace_aranges", & do_trace_aranges
, 1 },
7536 { "trace_info", & do_trace_info
, 1 },
7545 const debug_dump_long_opts
* entry
;
7547 for (entry
= opts_table
; entry
->option
; entry
++)
7549 size_t len
= strlen (entry
->option
);
7551 if (strncmp (p
, entry
->option
, len
) == 0
7552 && (p
[len
] == ',' || p
[len
] == '\0'))
7554 * entry
->variable
|= entry
->val
;
7556 /* The --debug-dump=frames-interp option also
7557 enables the --debug-dump=frames option. */
7558 if (do_debug_frames_interp
)
7559 do_debug_frames
= 1;
7566 if (entry
->option
== NULL
)
7568 warn (_("Unrecognized debug option '%s'\n"), p
);
7569 p
= strchr (p
, ',');
7580 dwarf_select_sections_by_letters (const char *letters
)
7582 unsigned int lindex
= 0;
7584 while (letters
[lindex
])
7585 switch (letters
[lindex
++])
7592 do_debug_abbrevs
= 1;
7596 do_debug_lines
|= FLAG_DEBUG_LINES_RAW
;
7600 do_debug_lines
|= FLAG_DEBUG_LINES_DECODED
;
7604 do_debug_pubnames
= 1;
7608 do_debug_pubtypes
= 1;
7612 do_debug_aranges
= 1;
7616 do_debug_ranges
= 1;
7620 do_debug_frames_interp
= 1;
7622 do_debug_frames
= 1;
7626 do_debug_macinfo
= 1;
7638 warn (_("Unrecognized debug option '%s'\n"), letters
);
7644 dwarf_select_sections_all (void)
7647 do_debug_abbrevs
= 1;
7648 do_debug_lines
= FLAG_DEBUG_LINES_RAW
;
7649 do_debug_pubnames
= 1;
7650 do_debug_pubtypes
= 1;
7651 do_debug_aranges
= 1;
7652 do_debug_ranges
= 1;
7653 do_debug_frames
= 1;
7654 do_debug_macinfo
= 1;
7659 do_trace_abbrevs
= 1;
7660 do_trace_aranges
= 1;
7662 do_debug_cu_index
= 1;
7665 struct dwarf_section_display debug_displays
[] =
7667 { { ".debug_abbrev", ".zdebug_abbrev", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7668 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
7669 { { ".debug_aranges", ".zdebug_aranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7670 display_debug_aranges
, &do_debug_aranges
, TRUE
},
7671 { { ".debug_frame", ".zdebug_frame", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7672 display_debug_frames
, &do_debug_frames
, TRUE
},
7673 { { ".debug_info", ".zdebug_info", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
7674 display_debug_info
, &do_debug_info
, TRUE
},
7675 { { ".debug_line", ".zdebug_line", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7676 display_debug_lines
, &do_debug_lines
, TRUE
},
7677 { { ".debug_pubnames", ".zdebug_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7678 display_debug_pubnames
, &do_debug_pubnames
, FALSE
},
7679 { { ".debug_gnu_pubnames", ".zdebug_gnu_pubnames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7680 display_debug_gnu_pubnames
, &do_debug_pubnames
, FALSE
},
7681 { { ".eh_frame", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7682 display_debug_frames
, &do_debug_frames
, TRUE
},
7683 { { ".debug_macinfo", ".zdebug_macinfo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7684 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
7685 { { ".debug_macro", ".zdebug_macro", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7686 display_debug_macro
, &do_debug_macinfo
, TRUE
},
7687 { { ".debug_str", ".zdebug_str", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7688 display_debug_str
, &do_debug_str
, FALSE
},
7689 { { ".debug_loc", ".zdebug_loc", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7690 display_debug_loc
, &do_debug_loc
, TRUE
},
7691 { { ".debug_pubtypes", ".zdebug_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7692 display_debug_pubnames
, &do_debug_pubtypes
, FALSE
},
7693 { { ".debug_gnu_pubtypes", ".zdebug_gnu_pubtypes", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7694 display_debug_gnu_pubnames
, &do_debug_pubtypes
, FALSE
},
7695 { { ".debug_ranges", ".zdebug_ranges", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7696 display_debug_ranges
, &do_debug_ranges
, TRUE
},
7697 { { ".debug_static_func", ".zdebug_static_func", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7698 display_debug_not_supported
, NULL
, FALSE
},
7699 { { ".debug_static_vars", ".zdebug_static_vars", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7700 display_debug_not_supported
, NULL
, FALSE
},
7701 { { ".debug_types", ".zdebug_types", NULL
, NULL
, 0, 0, abbrev
, NULL
, 0, NULL
},
7702 display_debug_types
, &do_debug_info
, TRUE
},
7703 { { ".debug_weaknames", ".zdebug_weaknames", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7704 display_debug_not_supported
, NULL
, FALSE
},
7705 { { ".gdb_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7706 display_gdb_index
, &do_gdb_index
, FALSE
},
7707 { { ".trace_info", "", NULL
, NULL
, 0, 0, trace_abbrev
, NULL
, 0, NULL
},
7708 display_trace_info
, &do_trace_info
, TRUE
},
7709 { { ".trace_abbrev", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7710 display_debug_abbrev
, &do_trace_abbrevs
, FALSE
},
7711 { { ".trace_aranges", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7712 display_debug_aranges
, &do_trace_aranges
, FALSE
},
7713 { { ".debug_info.dwo", ".zdebug_info.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
7714 display_debug_info
, &do_debug_info
, TRUE
},
7715 { { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7716 display_debug_abbrev
, &do_debug_abbrevs
, FALSE
},
7717 { { ".debug_types.dwo", ".zdebug_types.dwo", NULL
, NULL
, 0, 0, abbrev_dwo
, NULL
, 0, NULL
},
7718 display_debug_types
, &do_debug_info
, TRUE
},
7719 { { ".debug_line.dwo", ".zdebug_line.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7720 display_debug_lines
, &do_debug_lines
, TRUE
},
7721 { { ".debug_loc.dwo", ".zdebug_loc.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7722 display_debug_loc
, &do_debug_loc
, TRUE
},
7723 { { ".debug_macro.dwo", ".zdebug_macro.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7724 display_debug_macro
, &do_debug_macinfo
, TRUE
},
7725 { { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7726 display_debug_macinfo
, &do_debug_macinfo
, FALSE
},
7727 { { ".debug_str.dwo", ".zdebug_str.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7728 display_debug_str
, &do_debug_str
, TRUE
},
7729 { { ".debug_str_offsets", ".zdebug_str_offsets", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7730 display_debug_str_offsets
, NULL
, FALSE
},
7731 { { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7732 display_debug_str_offsets
, NULL
, FALSE
},
7733 { { ".debug_addr", ".zdebug_addr", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7734 display_debug_addr
, &do_debug_addr
, TRUE
},
7735 { { ".debug_cu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7736 display_cu_index
, &do_debug_cu_index
, FALSE
},
7737 { { ".debug_tu_index", "", NULL
, NULL
, 0, 0, 0, NULL
, 0, NULL
},
7738 display_cu_index
, &do_debug_cu_index
, FALSE
},