| /* dwarf.c -- display DWARF contents of a BFD binary file |
| Copyright (C) 2005-2016 Free Software Foundation, Inc. |
| |
| This file is part of GNU Binutils. |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by |
| the Free Software Foundation; either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the Free Software |
| Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
| 02110-1301, USA. */ |
| |
| #include "sysdep.h" |
| #include "libiberty.h" |
| #include "bfd.h" |
| #include "bfd_stdint.h" |
| #include "bucomm.h" |
| #include "elfcomm.h" |
| #include "elf/common.h" |
| #include "dwarf2.h" |
| #include "dwarf.h" |
| #include "gdb/gdb-index.h" |
| |
| static const char *regname (unsigned int regno, int row); |
| |
| static int have_frame_base; |
| static int need_base_address; |
| |
| static unsigned int last_pointer_size = 0; |
| static int warned_about_missing_comp_units = FALSE; |
| |
| static unsigned int num_debug_info_entries = 0; |
| static unsigned int alloc_num_debug_info_entries = 0; |
| static debug_info *debug_information = NULL; |
| /* Special value for num_debug_info_entries to indicate |
| that the .debug_info section could not be loaded/parsed. */ |
| #define DEBUG_INFO_UNAVAILABLE (unsigned int) -1 |
| |
| unsigned int eh_addr_size; |
| |
| int do_debug_info; |
| int do_debug_abbrevs; |
| int do_debug_lines; |
| int do_debug_pubnames; |
| int do_debug_pubtypes; |
| int do_debug_aranges; |
| int do_debug_ranges; |
| int do_debug_frames; |
| int do_debug_frames_interp; |
| int do_debug_macinfo; |
| int do_debug_str; |
| int do_debug_loc; |
| int do_gdb_index; |
| int do_trace_info; |
| int do_trace_abbrevs; |
| int do_trace_aranges; |
| int do_debug_addr; |
| int do_debug_cu_index; |
| int do_wide; |
| |
| int dwarf_cutoff_level = -1; |
| unsigned long dwarf_start_die; |
| |
| int dwarf_check = 0; |
| |
| /* Collection of CU/TU section sets from .debug_cu_index and .debug_tu_index |
| sections. For version 1 package files, each set is stored in SHNDX_POOL |
| as a zero-terminated list of section indexes comprising one set of debug |
| sections from a .dwo file. */ |
| |
| static int cu_tu_indexes_read = 0; |
| static unsigned int *shndx_pool = NULL; |
| static unsigned int shndx_pool_size = 0; |
| static unsigned int shndx_pool_used = 0; |
| |
| /* For version 2 package files, each set contains an array of section offsets |
| and an array of section sizes, giving the offset and size of the |
| contribution from a CU or TU within one of the debug sections. |
| When displaying debug info from a package file, we need to use these |
| tables to locate the corresponding contributions to each section. */ |
| |
| struct cu_tu_set |
| { |
| uint64_t signature; |
| dwarf_vma section_offsets[DW_SECT_MAX]; |
| size_t section_sizes[DW_SECT_MAX]; |
| }; |
| |
| static int cu_count = 0; |
| static int tu_count = 0; |
| static struct cu_tu_set *cu_sets = NULL; |
| static struct cu_tu_set *tu_sets = NULL; |
| |
| static void load_cu_tu_indexes (void *file); |
| |
| /* Values for do_debug_lines. */ |
| #define FLAG_DEBUG_LINES_RAW 1 |
| #define FLAG_DEBUG_LINES_DECODED 2 |
| |
| static unsigned int |
| size_of_encoded_value (int encoding) |
| { |
| switch (encoding & 0x7) |
| { |
| default: /* ??? */ |
| case 0: return eh_addr_size; |
| case 2: return 2; |
| case 3: return 4; |
| case 4: return 8; |
| } |
| } |
| |
| static dwarf_vma |
| get_encoded_value (unsigned char **pdata, |
| int encoding, |
| struct dwarf_section *section, |
| unsigned char * end) |
| { |
| unsigned char * data = * pdata; |
| unsigned int size = size_of_encoded_value (encoding); |
| dwarf_vma val; |
| |
| if (data + size >= end) |
| { |
| warn (_("Encoded value extends past end of section\n")); |
| * pdata = end; |
| return 0; |
| } |
| |
| /* PR 17512: file: 002-829853-0.004. */ |
| if (size > 8) |
| { |
| warn (_("Encoded size of %d is too large to read\n"), size); |
| * pdata = end; |
| return 0; |
| } |
| |
| /* PR 17512: file: 1085-5603-0.004. */ |
| if (size == 0) |
| { |
| warn (_("Encoded size of 0 is too small to read\n")); |
| * pdata = end; |
| return 0; |
| } |
| |
| if (encoding & DW_EH_PE_signed) |
| val = byte_get_signed (data, size); |
| else |
| val = byte_get (data, size); |
| |
| if ((encoding & 0x70) == DW_EH_PE_pcrel) |
| val += section->address + (data - section->start); |
| |
| * pdata = data + size; |
| return val; |
| } |
| |
| #if defined HAVE_LONG_LONG && SIZEOF_LONG_LONG > SIZEOF_LONG |
| # ifndef __MINGW32__ |
| # define DWARF_VMA_FMT "ll" |
| # define DWARF_VMA_FMT_LONG "%16.16llx" |
| # else |
| # define DWARF_VMA_FMT "I64" |
| # define DWARF_VMA_FMT_LONG "%016I64x" |
| # endif |
| #else |
| # define DWARF_VMA_FMT "l" |
| # define DWARF_VMA_FMT_LONG "%16.16lx" |
| #endif |
| |
| /* Convert a dwarf vma value into a string. Returns a pointer to a static |
| buffer containing the converted VALUE. The value is converted according |
| to the printf formating character FMTCH. If NUM_BYTES is non-zero then |
| it specifies the maximum number of bytes to be displayed in the converted |
| value and FMTCH is ignored - hex is always used. */ |
| |
| static const char * |
| dwarf_vmatoa_1 (const char *fmtch, dwarf_vma value, unsigned num_bytes) |
| { |
| /* As dwarf_vmatoa is used more then once in a printf call |
| for output, we are cycling through an fixed array of pointers |
| for return address. */ |
| static int buf_pos = 0; |
| static struct dwarf_vmatoa_buf |
| { |
| char place[64]; |
| } buf[16]; |
| char *ret; |
| |
| ret = buf[buf_pos++].place; |
| buf_pos %= ARRAY_SIZE (buf); |
| |
| if (num_bytes) |
| { |
| /* Printf does not have a way of specifying a maximum field width for an |
| integer value, so we print the full value into a buffer and then select |
| the precision we need. */ |
| snprintf (ret, sizeof (buf[0].place), DWARF_VMA_FMT_LONG, value); |
| if (num_bytes > 8) |
| num_bytes = 8; |
| return ret + (16 - 2 * num_bytes); |
| } |
| else |
| { |
| char fmt[32]; |
| |
| sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch); |
| snprintf (ret, sizeof (buf[0].place), fmt, value); |
| return ret; |
| } |
| } |
| |
| static inline const char * |
| dwarf_vmatoa (const char * fmtch, dwarf_vma value) |
| { |
| return dwarf_vmatoa_1 (fmtch, value, 0); |
| } |
| |
| /* Print a dwarf_vma value (typically an address, offset or length) in |
| hexadecimal format, followed by a space. The length of the VALUE (and |
| hence the precision displayed) is determined by the NUM_BYTES parameter. */ |
| |
| static void |
| print_dwarf_vma (dwarf_vma value, unsigned num_bytes) |
| { |
| printf ("%s ", dwarf_vmatoa_1 (NULL, value, num_bytes)); |
| } |
| |
| /* Format a 64-bit value, given as two 32-bit values, in hex. |
| For reentrancy, this uses a buffer provided by the caller. */ |
| |
| static const char * |
| dwarf_vmatoa64 (dwarf_vma hvalue, dwarf_vma lvalue, char *buf, |
| unsigned int buf_len) |
| { |
| int len = 0; |
| |
| if (hvalue == 0) |
| snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", lvalue); |
| else |
| { |
| len = snprintf (buf, buf_len, "%" DWARF_VMA_FMT "x", hvalue); |
| snprintf (buf + len, buf_len - len, |
| "%08" DWARF_VMA_FMT "x", lvalue); |
| } |
| |
| return buf; |
| } |
| |
| /* Read in a LEB128 encoded value starting at address DATA. |
| If SIGN is true, return a signed LEB128 value. |
| If LENGTH_RETURN is not NULL, return in it the number of bytes read. |
| No bytes will be read at address END or beyond. */ |
| |
| dwarf_vma |
| read_leb128 (unsigned char *data, |
| unsigned int *length_return, |
| bfd_boolean sign, |
| const unsigned char * const end) |
| { |
| dwarf_vma result = 0; |
| unsigned int num_read = 0; |
| unsigned int shift = 0; |
| unsigned char byte = 0; |
| |
| while (data < end) |
| { |
| byte = *data++; |
| num_read++; |
| |
| result |= ((dwarf_vma) (byte & 0x7f)) << shift; |
| |
| shift += 7; |
| if ((byte & 0x80) == 0) |
| break; |
| |
| /* PR 17512: file: 0ca183b8. |
| FIXME: Should we signal this error somehow ? */ |
| if (shift >= sizeof (result) * 8) |
| break; |
| } |
| |
| if (length_return != NULL) |
| *length_return = num_read; |
| |
| if (sign && (shift < 8 * sizeof (result)) && (byte & 0x40)) |
| result |= -((dwarf_vma) 1 << shift); |
| |
| return result; |
| } |
| |
| /* Create a signed version to avoid painful typecasts. */ |
| static inline dwarf_signed_vma |
| read_sleb128 (unsigned char * data, |
| unsigned int * length_return, |
| const unsigned char * const end) |
| { |
| return (dwarf_signed_vma) read_leb128 (data, length_return, TRUE, end); |
| } |
| |
| static inline dwarf_vma |
| read_uleb128 (unsigned char * data, |
| unsigned int * length_return, |
| const unsigned char * const end) |
| { |
| return read_leb128 (data, length_return, FALSE, end); |
| } |
| |
| #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
| do \ |
| { \ |
| unsigned int amount = (AMOUNT); \ |
| if (sizeof (VAL) < amount) \ |
| { \ |
| error (_("internal error: attempt to read %d bytes of data in to %d sized variable"),\ |
| amount, (int) sizeof (VAL)); \ |
| amount = sizeof (VAL); \ |
| } \ |
| if (((PTR) + amount) >= (END)) \ |
| { \ |
| if ((PTR) < (END)) \ |
| amount = (END) - (PTR); \ |
| else \ |
| amount = 0; \ |
| } \ |
| if (amount == 0 || amount > 8) \ |
| VAL = 0; \ |
| else \ |
| VAL = byte_get ((PTR), amount); \ |
| } \ |
| while (0) |
| |
| #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
| do \ |
| { \ |
| SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \ |
| PTR += AMOUNT; \ |
| } \ |
| while (0) |
| |
| #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
| do \ |
| { \ |
| unsigned int amount = (AMOUNT); \ |
| if (((PTR) + amount) >= (END)) \ |
| { \ |
| if ((PTR) < (END)) \ |
| amount = (END) - (PTR); \ |
| else \ |
| amount = 0; \ |
| } \ |
| if (amount) \ |
| VAL = byte_get_signed ((PTR), amount); \ |
| else \ |
| VAL = 0; \ |
| } \ |
| while (0) |
| |
| #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
| do \ |
| { \ |
| SAFE_SIGNED_BYTE_GET (VAL, PTR, AMOUNT, END); \ |
| PTR += AMOUNT; \ |
| } \ |
| while (0) |
| |
| #define SAFE_BYTE_GET64(PTR, HIGH, LOW, END) \ |
| do \ |
| { \ |
| if (((PTR) + 8) <= (END)) \ |
| { \ |
| byte_get_64 ((PTR), (HIGH), (LOW)); \ |
| } \ |
| else \ |
| { \ |
| * (LOW) = * (HIGH) = 0; \ |
| } \ |
| } \ |
| while (0) |
| |
| typedef struct State_Machine_Registers |
| { |
| dwarf_vma address; |
| unsigned int file; |
| unsigned int line; |
| unsigned int column; |
| int is_stmt; |
| int basic_block; |
| unsigned char op_index; |
| unsigned char end_sequence; |
| /* This variable hold the number of the last entry seen |
| in the File Table. */ |
| unsigned int last_file_entry; |
| } SMR; |
| |
| static SMR state_machine_regs; |
| |
| static void |
| reset_state_machine (int is_stmt) |
| { |
| state_machine_regs.address = 0; |
| state_machine_regs.op_index = 0; |
| state_machine_regs.file = 1; |
| state_machine_regs.line = 1; |
| state_machine_regs.column = 0; |
| state_machine_regs.is_stmt = is_stmt; |
| state_machine_regs.basic_block = 0; |
| state_machine_regs.end_sequence = 0; |
| state_machine_regs.last_file_entry = 0; |
| } |
| |
| /* Handled an extend line op. |
| Returns the number of bytes read. */ |
| |
| static int |
| process_extended_line_op (unsigned char * data, |
| int is_stmt, |
| unsigned char * end) |
| { |
| unsigned char op_code; |
| unsigned int bytes_read; |
| unsigned int len; |
| unsigned char *name; |
| unsigned char *orig_data = data; |
| dwarf_vma adr; |
| |
| len = read_uleb128 (data, & bytes_read, end); |
| data += bytes_read; |
| |
| if (len == 0 || data == end || len > (uintptr_t) (end - data)) |
| { |
| warn (_("Badly formed extended line op encountered!\n")); |
| return bytes_read; |
| } |
| |
| len += bytes_read; |
| op_code = *data++; |
| |
| printf (_(" Extended opcode %d: "), op_code); |
| |
| switch (op_code) |
| { |
| case DW_LNE_end_sequence: |
| printf (_("End of Sequence\n\n")); |
| reset_state_machine (is_stmt); |
| break; |
| |
| case DW_LNE_set_address: |
| /* PR 17512: file: 002-100480-0.004. */ |
| if (len - bytes_read - 1 > 8) |
| { |
| warn (_("Length (%d) of DW_LNE_set_address op is too long\n"), |
| len - bytes_read - 1); |
| adr = 0; |
| } |
| else |
| SAFE_BYTE_GET (adr, data, len - bytes_read - 1, end); |
| printf (_("set Address to 0x%s\n"), dwarf_vmatoa ("x", adr)); |
| state_machine_regs.address = adr; |
| state_machine_regs.op_index = 0; |
| break; |
| |
| case DW_LNE_define_file: |
| printf (_("define new File Table entry\n")); |
| printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
| printf (" %d\t", ++state_machine_regs.last_file_entry); |
| |
| name = data; |
| data += strnlen ((char *) data, end - data) + 1; |
| printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| data += bytes_read; |
| printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| data += bytes_read; |
| printf ("%s\t", dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| data += bytes_read; |
| printf ("%s\n\n", name); |
| |
| if (((unsigned int) (data - orig_data) != len) || data == end) |
| warn (_("DW_LNE_define_file: Bad opcode length\n")); |
| break; |
| |
| case DW_LNE_set_discriminator: |
| printf (_("set Discriminator to %s\n"), |
| dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| break; |
| |
| /* HP extensions. */ |
| case DW_LNE_HP_negate_is_UV_update: |
| printf ("DW_LNE_HP_negate_is_UV_update\n"); |
| break; |
| case DW_LNE_HP_push_context: |
| printf ("DW_LNE_HP_push_context\n"); |
| break; |
| case DW_LNE_HP_pop_context: |
| printf ("DW_LNE_HP_pop_context\n"); |
| break; |
| case DW_LNE_HP_set_file_line_column: |
| printf ("DW_LNE_HP_set_file_line_column\n"); |
| break; |
| case DW_LNE_HP_set_routine_name: |
| printf ("DW_LNE_HP_set_routine_name\n"); |
| break; |
| case DW_LNE_HP_set_sequence: |
| printf ("DW_LNE_HP_set_sequence\n"); |
| break; |
| case DW_LNE_HP_negate_post_semantics: |
| printf ("DW_LNE_HP_negate_post_semantics\n"); |
| break; |
| case DW_LNE_HP_negate_function_exit: |
| printf ("DW_LNE_HP_negate_function_exit\n"); |
| break; |
| case DW_LNE_HP_negate_front_end_logical: |
| printf ("DW_LNE_HP_negate_front_end_logical\n"); |
| break; |
| case DW_LNE_HP_define_proc: |
| printf ("DW_LNE_HP_define_proc\n"); |
| break; |
| case DW_LNE_HP_source_file_correlation: |
| { |
| unsigned char *edata = data + len - bytes_read - 1; |
| |
| printf ("DW_LNE_HP_source_file_correlation\n"); |
| |
| while (data < edata) |
| { |
| unsigned int opc; |
| |
| opc = read_uleb128 (data, & bytes_read, edata); |
| data += bytes_read; |
| |
| switch (opc) |
| { |
| case DW_LNE_HP_SFC_formfeed: |
| printf (" DW_LNE_HP_SFC_formfeed\n"); |
| break; |
| case DW_LNE_HP_SFC_set_listing_line: |
| printf (" DW_LNE_HP_SFC_set_listing_line (%s)\n", |
| dwarf_vmatoa ("u", |
| read_uleb128 (data, & bytes_read, edata))); |
| data += bytes_read; |
| break; |
| case DW_LNE_HP_SFC_associate: |
| printf (" DW_LNE_HP_SFC_associate "); |
| printf ("(%s", |
| dwarf_vmatoa ("u", |
| read_uleb128 (data, & bytes_read, edata))); |
| data += bytes_read; |
| printf (",%s", |
| dwarf_vmatoa ("u", |
| read_uleb128 (data, & bytes_read, edata))); |
| data += bytes_read; |
| printf (",%s)\n", |
| dwarf_vmatoa ("u", |
| read_uleb128 (data, & bytes_read, edata))); |
| data += bytes_read; |
| break; |
| default: |
| printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); |
| data = edata; |
| break; |
| } |
| } |
| } |
| break; |
| |
| default: |
| { |
| unsigned int rlen = len - bytes_read - 1; |
| |
| if (op_code >= DW_LNE_lo_user |
| /* The test against DW_LNW_hi_user is redundant due to |
| the limited range of the unsigned char data type used |
| for op_code. */ |
| /*&& op_code <= DW_LNE_hi_user*/) |
| printf (_("user defined: ")); |
| else |
| printf (_("UNKNOWN: ")); |
| printf (_("length %d ["), rlen); |
| for (; rlen; rlen--) |
| printf (" %02x", *data++); |
| printf ("]\n"); |
| } |
| break; |
| } |
| |
| return len; |
| } |
| |
| static const unsigned char * |
| fetch_indirect_string (dwarf_vma offset) |
| { |
| struct dwarf_section *section = &debug_displays [str].section; |
| |
| if (section->start == NULL) |
| return (const unsigned char *) _("<no .debug_str section>"); |
| |
| if (offset > section->size) |
| { |
| warn (_("DW_FORM_strp offset too big: %s\n"), |
| dwarf_vmatoa ("x", offset)); |
| return (const unsigned char *) _("<offset is too big>"); |
| } |
| |
| return (const unsigned char *) section->start + offset; |
| } |
| |
| static const char * |
| fetch_indexed_string (dwarf_vma idx, struct cu_tu_set *this_set, |
| dwarf_vma offset_size, int dwo) |
| { |
| enum dwarf_section_display_enum str_sec_idx = dwo ? str_dwo : str; |
| enum dwarf_section_display_enum idx_sec_idx = dwo ? str_index_dwo : str_index; |
| struct dwarf_section *index_section = &debug_displays [idx_sec_idx].section; |
| struct dwarf_section *str_section = &debug_displays [str_sec_idx].section; |
| dwarf_vma index_offset = idx * offset_size; |
| dwarf_vma str_offset; |
| |
| if (index_section->start == NULL) |
| return (dwo ? _("<no .debug_str_offsets.dwo section>") |
| : _("<no .debug_str_offsets section>")); |
| |
| if (this_set != NULL) |
| index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]; |
| if (index_offset > index_section->size) |
| { |
| warn (_("DW_FORM_GNU_str_index offset too big: %s\n"), |
| dwarf_vmatoa ("x", index_offset)); |
| return _("<index offset is too big>"); |
| } |
| |
| if (str_section->start == NULL) |
| return (dwo ? _("<no .debug_str.dwo section>") |
| : _("<no .debug_str section>")); |
| |
| str_offset = byte_get (index_section->start + index_offset, offset_size); |
| str_offset -= str_section->address; |
| if (str_offset > str_section->size) |
| { |
| warn (_("DW_FORM_GNU_str_index indirect offset too big: %s\n"), |
| dwarf_vmatoa ("x", str_offset)); |
| return _("<indirect index offset is too big>"); |
| } |
| |
| return (const char *) str_section->start + str_offset; |
| } |
| |
| static const char * |
| fetch_indexed_value (dwarf_vma offset, dwarf_vma bytes) |
| { |
| struct dwarf_section *section = &debug_displays [debug_addr].section; |
| |
| if (section->start == NULL) |
| return (_("<no .debug_addr section>")); |
| |
| if (offset + bytes > section->size) |
| { |
| warn (_("Offset into section %s too big: %s\n"), |
| section->name, dwarf_vmatoa ("x", offset)); |
| return "<offset too big>"; |
| } |
| |
| return dwarf_vmatoa ("x", byte_get (section->start + offset, bytes)); |
| } |
| |
| |
| /* FIXME: There are better and more efficient ways to handle |
| these structures. For now though, I just want something that |
| is simple to implement. */ |
| typedef struct abbrev_attr |
| { |
| unsigned long attribute; |
| unsigned long form; |
| struct abbrev_attr *next; |
| } |
| abbrev_attr; |
| |
| typedef struct abbrev_entry |
| { |
| unsigned long entry; |
| unsigned long tag; |
| int children; |
| struct abbrev_attr *first_attr; |
| struct abbrev_attr *last_attr; |
| struct abbrev_entry *next; |
| } |
| abbrev_entry; |
| |
| static abbrev_entry *first_abbrev = NULL; |
| static abbrev_entry *last_abbrev = NULL; |
| |
| static void |
| free_abbrevs (void) |
| { |
| abbrev_entry *abbrv; |
| |
| for (abbrv = first_abbrev; abbrv;) |
| { |
| abbrev_entry *next_abbrev = abbrv->next; |
| abbrev_attr *attr; |
| |
| for (attr = abbrv->first_attr; attr;) |
| { |
| abbrev_attr *next_attr = attr->next; |
| |
| free (attr); |
| attr = next_attr; |
| } |
| |
| free (abbrv); |
| abbrv = next_abbrev; |
| } |
| |
| last_abbrev = first_abbrev = NULL; |
| } |
| |
| static void |
| add_abbrev (unsigned long number, unsigned long tag, int children) |
| { |
| abbrev_entry *entry; |
| |
| entry = (abbrev_entry *) malloc (sizeof (*entry)); |
| if (entry == NULL) |
| /* ugg */ |
| return; |
| |
| entry->entry = number; |
| entry->tag = tag; |
| entry->children = children; |
| entry->first_attr = NULL; |
| entry->last_attr = NULL; |
| entry->next = NULL; |
| |
| if (first_abbrev == NULL) |
| first_abbrev = entry; |
| else |
| last_abbrev->next = entry; |
| |
| last_abbrev = entry; |
| } |
| |
| static void |
| add_abbrev_attr (unsigned long attribute, unsigned long form) |
| { |
| abbrev_attr *attr; |
| |
| attr = (abbrev_attr *) malloc (sizeof (*attr)); |
| if (attr == NULL) |
| /* ugg */ |
| return; |
| |
| attr->attribute = attribute; |
| attr->form = form; |
| attr->next = NULL; |
| |
| if (last_abbrev->first_attr == NULL) |
| last_abbrev->first_attr = attr; |
| else |
| last_abbrev->last_attr->next = attr; |
| |
| last_abbrev->last_attr = attr; |
| } |
| |
| /* Processes the (partial) contents of a .debug_abbrev section. |
| Returns NULL if the end of the section was encountered. |
| Returns the address after the last byte read if the end of |
| an abbreviation set was found. */ |
| |
| static unsigned char * |
| process_abbrev_section (unsigned char *start, unsigned char *end) |
| { |
| if (first_abbrev != NULL) |
| return NULL; |
| |
| while (start < end) |
| { |
| unsigned int bytes_read; |
| unsigned long entry; |
| unsigned long tag; |
| unsigned long attribute; |
| int children; |
| |
| entry = read_uleb128 (start, & bytes_read, end); |
| start += bytes_read; |
| |
| /* A single zero is supposed to end the section according |
| to the standard. If there's more, then signal that to |
| the caller. */ |
| if (start == end) |
| return NULL; |
| if (entry == 0) |
| return start; |
| |
| tag = read_uleb128 (start, & bytes_read, end); |
| start += bytes_read; |
| if (start == end) |
| return NULL; |
| |
| children = *start++; |
| |
| add_abbrev (entry, tag, children); |
| |
| do |
| { |
| unsigned long form; |
| |
| attribute = read_uleb128 (start, & bytes_read, end); |
| start += bytes_read; |
| if (start == end) |
| break; |
| |
| form = read_uleb128 (start, & bytes_read, end); |
| start += bytes_read; |
| if (start == end) |
| break; |
| |
| add_abbrev_attr (attribute, form); |
| } |
| while (attribute != 0); |
| } |
| |
| /* Report the missing single zero which ends the section. */ |
| error (_(".debug_abbrev section not zero terminated\n")); |
| |
| return NULL; |
| } |
| |
| static const char * |
| get_TAG_name (unsigned long tag) |
| { |
| const char *name = get_DW_TAG_name ((unsigned int)tag); |
| |
| if (name == NULL) |
| { |
| static char buffer[100]; |
| |
| snprintf (buffer, sizeof (buffer), _("Unknown TAG value: %lx"), tag); |
| return buffer; |
| } |
| |
| return name; |
| } |
| |
| static const char * |
| get_FORM_name (unsigned long form) |
| { |
| const char *name; |
| |
| if (form == 0) |
| return "DW_FORM value: 0"; |
| |
| name = get_DW_FORM_name (form); |
| if (name == NULL) |
| { |
| static char buffer[100]; |
| |
| snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
| return buffer; |
| } |
| |
| return name; |
| } |
| |
| static unsigned char * |
| display_block (unsigned char *data, |
| dwarf_vma length, |
| const unsigned char * const end) |
| { |
| dwarf_vma maxlen; |
| |
| printf (_(" %s byte block: "), dwarf_vmatoa ("u", length)); |
| if (data > end) |
| return (unsigned char *) end; |
| |
| maxlen = (dwarf_vma) (end - data); |
| length = length > maxlen ? maxlen : length; |
| |
| while (length --) |
| printf ("%lx ", (unsigned long) byte_get (data++, 1)); |
| |
| return data; |
| } |
| |
| static int |
| decode_location_expression (unsigned char * data, |
| unsigned int pointer_size, |
| unsigned int offset_size, |
| int dwarf_version, |
| dwarf_vma length, |
| dwarf_vma cu_offset, |
| struct dwarf_section * section) |
| { |
| unsigned op; |
| unsigned int bytes_read; |
| dwarf_vma uvalue; |
| dwarf_signed_vma svalue; |
| unsigned char *end = data + length; |
| int need_frame_base = 0; |
| |
| while (data < end) |
| { |
| op = *data++; |
| |
| switch (op) |
| { |
| case DW_OP_addr: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| printf ("DW_OP_addr: %s", dwarf_vmatoa ("x", uvalue)); |
| break; |
| case DW_OP_deref: |
| printf ("DW_OP_deref"); |
| break; |
| case DW_OP_const1u: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| printf ("DW_OP_const1u: %lu", (unsigned long) uvalue); |
| break; |
| case DW_OP_const1s: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
| printf ("DW_OP_const1s: %ld", (long) svalue); |
| break; |
| case DW_OP_const2u: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
| printf ("DW_OP_const2u: %lu", (unsigned long) uvalue); |
| break; |
| case DW_OP_const2s: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
| printf ("DW_OP_const2s: %ld", (long) svalue); |
| break; |
| case DW_OP_const4u: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| printf ("DW_OP_const4u: %lu", (unsigned long) uvalue); |
| break; |
| case DW_OP_const4s: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
| printf ("DW_OP_const4s: %ld", (long) svalue); |
| break; |
| case DW_OP_const8u: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| printf ("DW_OP_const8u: %lu ", (unsigned long) uvalue); |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| printf ("%lu", (unsigned long) uvalue); |
| break; |
| case DW_OP_const8s: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
| printf ("DW_OP_const8s: %ld ", (long) svalue); |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
| printf ("%ld", (long) svalue); |
| break; |
| case DW_OP_constu: |
| printf ("DW_OP_constu: %s", |
| dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| data += bytes_read; |
| break; |
| case DW_OP_consts: |
| printf ("DW_OP_consts: %s", |
| dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
| data += bytes_read; |
| break; |
| case DW_OP_dup: |
| printf ("DW_OP_dup"); |
| break; |
| case DW_OP_drop: |
| printf ("DW_OP_drop"); |
| break; |
| case DW_OP_over: |
| printf ("DW_OP_over"); |
| break; |
| case DW_OP_pick: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| printf ("DW_OP_pick: %ld", (unsigned long) uvalue); |
| break; |
| case DW_OP_swap: |
| printf ("DW_OP_swap"); |
| break; |
| case DW_OP_rot: |
| printf ("DW_OP_rot"); |
| break; |
| case DW_OP_xderef: |
| printf ("DW_OP_xderef"); |
| break; |
| case DW_OP_abs: |
| printf ("DW_OP_abs"); |
| break; |
| case DW_OP_and: |
| printf ("DW_OP_and"); |
| break; |
| case DW_OP_div: |
| printf ("DW_OP_div"); |
| break; |
| case DW_OP_minus: |
| printf ("DW_OP_minus"); |
| break; |
| case DW_OP_mod: |
| printf ("DW_OP_mod"); |
| break; |
| case DW_OP_mul: |
| printf ("DW_OP_mul"); |
| break; |
| case DW_OP_neg: |
| printf ("DW_OP_neg"); |
| break; |
| case DW_OP_not: |
| printf ("DW_OP_not"); |
| break; |
| case DW_OP_or: |
| printf ("DW_OP_or"); |
| break; |
| case DW_OP_plus: |
| printf ("DW_OP_plus"); |
| break; |
| case DW_OP_plus_uconst: |
| printf ("DW_OP_plus_uconst: %s", |
| dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| data += bytes_read; |
| break; |
| case DW_OP_shl: |
| printf ("DW_OP_shl"); |
| break; |
| case DW_OP_shr: |
| printf ("DW_OP_shr"); |
| break; |
| case DW_OP_shra: |
| printf ("DW_OP_shra"); |
| break; |
| case DW_OP_xor: |
| printf ("DW_OP_xor"); |
| break; |
| case DW_OP_bra: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
| printf ("DW_OP_bra: %ld", (long) svalue); |
| break; |
| case DW_OP_eq: |
| printf ("DW_OP_eq"); |
| break; |
| case DW_OP_ge: |
| printf ("DW_OP_ge"); |
| break; |
| case DW_OP_gt: |
| printf ("DW_OP_gt"); |
| break; |
| case DW_OP_le: |
| printf ("DW_OP_le"); |
| break; |
| case DW_OP_lt: |
| printf ("DW_OP_lt"); |
| break; |
| case DW_OP_ne: |
| printf ("DW_OP_ne"); |
| break; |
| case DW_OP_skip: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
| printf ("DW_OP_skip: %ld", (long) svalue); |
| break; |
| |
| case DW_OP_lit0: |
| case DW_OP_lit1: |
| case DW_OP_lit2: |
| case DW_OP_lit3: |
| case DW_OP_lit4: |
| case DW_OP_lit5: |
| case DW_OP_lit6: |
| case DW_OP_lit7: |
| case DW_OP_lit8: |
| case DW_OP_lit9: |
| case DW_OP_lit10: |
| case DW_OP_lit11: |
| case DW_OP_lit12: |
| case DW_OP_lit13: |
| case DW_OP_lit14: |
| case DW_OP_lit15: |
| case DW_OP_lit16: |
| case DW_OP_lit17: |
| case DW_OP_lit18: |
| case DW_OP_lit19: |
| case DW_OP_lit20: |
| case DW_OP_lit21: |
| case DW_OP_lit22: |
| case DW_OP_lit23: |
| case DW_OP_lit24: |
| case DW_OP_lit25: |
| case DW_OP_lit26: |
| case DW_OP_lit27: |
| case DW_OP_lit28: |
| case DW_OP_lit29: |
| case DW_OP_lit30: |
| case DW_OP_lit31: |
| printf ("DW_OP_lit%d", op - DW_OP_lit0); |
| break; |
| |
| case DW_OP_reg0: |
| case DW_OP_reg1: |
| case DW_OP_reg2: |
| case DW_OP_reg3: |
| case DW_OP_reg4: |
| case DW_OP_reg5: |
| case DW_OP_reg6: |
| case DW_OP_reg7: |
| case DW_OP_reg8: |
| case DW_OP_reg9: |
| case DW_OP_reg10: |
| case DW_OP_reg11: |
| case DW_OP_reg12: |
| case DW_OP_reg13: |
| case DW_OP_reg14: |
| case DW_OP_reg15: |
| case DW_OP_reg16: |
| case DW_OP_reg17: |
| case DW_OP_reg18: |
| case DW_OP_reg19: |
| case DW_OP_reg20: |
| case DW_OP_reg21: |
| case DW_OP_reg22: |
| case DW_OP_reg23: |
| case DW_OP_reg24: |
| case DW_OP_reg25: |
| case DW_OP_reg26: |
| case DW_OP_reg27: |
| case DW_OP_reg28: |
| case DW_OP_reg29: |
| case DW_OP_reg30: |
| case DW_OP_reg31: |
| printf ("DW_OP_reg%d (%s)", op - DW_OP_reg0, |
| regname (op - DW_OP_reg0, 1)); |
| break; |
| |
| case DW_OP_breg0: |
| case DW_OP_breg1: |
| case DW_OP_breg2: |
| case DW_OP_breg3: |
| case DW_OP_breg4: |
| case DW_OP_breg5: |
| case DW_OP_breg6: |
| case DW_OP_breg7: |
| case DW_OP_breg8: |
| case DW_OP_breg9: |
| case DW_OP_breg10: |
| case DW_OP_breg11: |
| case DW_OP_breg12: |
| case DW_OP_breg13: |
| case DW_OP_breg14: |
| case DW_OP_breg15: |
| case DW_OP_breg16: |
| case DW_OP_breg17: |
| case DW_OP_breg18: |
| case DW_OP_breg19: |
| case DW_OP_breg20: |
| case DW_OP_breg21: |
| case DW_OP_breg22: |
| case DW_OP_breg23: |
| case DW_OP_breg24: |
| case DW_OP_breg25: |
| case DW_OP_breg26: |
| case DW_OP_breg27: |
| case DW_OP_breg28: |
| case DW_OP_breg29: |
| case DW_OP_breg30: |
| case DW_OP_breg31: |
| printf ("DW_OP_breg%d (%s): %s", |
| op - DW_OP_breg0, |
| regname (op - DW_OP_breg0, 1), |
| dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
| data += bytes_read; |
| break; |
| |
| case DW_OP_regx: |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf ("DW_OP_regx: %s (%s)", |
| dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
| break; |
| case DW_OP_fbreg: |
| need_frame_base = 1; |
| printf ("DW_OP_fbreg: %s", |
| dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
| data += bytes_read; |
| break; |
| case DW_OP_bregx: |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf ("DW_OP_bregx: %s (%s) %s", |
| dwarf_vmatoa ("u", uvalue), regname (uvalue, 1), |
| dwarf_vmatoa ("d", read_sleb128 (data, &bytes_read, end))); |
| data += bytes_read; |
| break; |
| case DW_OP_piece: |
| printf ("DW_OP_piece: %s", |
| dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| data += bytes_read; |
| break; |
| case DW_OP_deref_size: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| printf ("DW_OP_deref_size: %ld", (long) uvalue); |
| break; |
| case DW_OP_xderef_size: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| printf ("DW_OP_xderef_size: %ld", (long) uvalue); |
| break; |
| case DW_OP_nop: |
| printf ("DW_OP_nop"); |
| break; |
| |
| /* DWARF 3 extensions. */ |
| case DW_OP_push_object_address: |
| printf ("DW_OP_push_object_address"); |
| break; |
| case DW_OP_call2: |
| /* XXX: Strictly speaking for 64-bit DWARF3 files |
| this ought to be an 8-byte wide computation. */ |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
| printf ("DW_OP_call2: <0x%s>", |
| dwarf_vmatoa ("x", svalue + cu_offset)); |
| break; |
| case DW_OP_call4: |
| /* XXX: Strictly speaking for 64-bit DWARF3 files |
| this ought to be an 8-byte wide computation. */ |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
| printf ("DW_OP_call4: <0x%s>", |
| dwarf_vmatoa ("x", svalue + cu_offset)); |
| break; |
| case DW_OP_call_ref: |
| /* XXX: Strictly speaking for 64-bit DWARF3 files |
| this ought to be an 8-byte wide computation. */ |
| if (dwarf_version == -1) |
| { |
| printf (_("(DW_OP_call_ref in frame info)")); |
| /* No way to tell where the next op is, so just bail. */ |
| return need_frame_base; |
| } |
| if (dwarf_version == 2) |
| { |
| SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| } |
| else |
| { |
| SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| } |
| printf ("DW_OP_call_ref: <0x%s>", dwarf_vmatoa ("x", uvalue)); |
| break; |
| case DW_OP_form_tls_address: |
| printf ("DW_OP_form_tls_address"); |
| break; |
| case DW_OP_call_frame_cfa: |
| printf ("DW_OP_call_frame_cfa"); |
| break; |
| case DW_OP_bit_piece: |
| printf ("DW_OP_bit_piece: "); |
| printf (_("size: %s "), |
| dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| data += bytes_read; |
| printf (_("offset: %s "), |
| dwarf_vmatoa ("u", read_uleb128 (data, &bytes_read, end))); |
| data += bytes_read; |
| break; |
| |
| /* DWARF 4 extensions. */ |
| case DW_OP_stack_value: |
| printf ("DW_OP_stack_value"); |
| break; |
| |
| case DW_OP_implicit_value: |
| printf ("DW_OP_implicit_value"); |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| data = display_block (data, uvalue, end); |
| break; |
| |
| /* GNU extensions. */ |
| case DW_OP_GNU_push_tls_address: |
| printf (_("DW_OP_GNU_push_tls_address or DW_OP_HP_unknown")); |
| break; |
| case DW_OP_GNU_uninit: |
| printf ("DW_OP_GNU_uninit"); |
| /* FIXME: Is there data associated with this OP ? */ |
| break; |
| case DW_OP_GNU_encoded_addr: |
| { |
| int encoding = 0; |
| dwarf_vma addr; |
| |
| if (data < end) |
| encoding = *data++; |
| addr = get_encoded_value (&data, encoding, section, end); |
| |
| printf ("DW_OP_GNU_encoded_addr: fmt:%02x addr:", encoding); |
| print_dwarf_vma (addr, pointer_size); |
| } |
| break; |
| case DW_OP_GNU_implicit_pointer: |
| /* XXX: Strictly speaking for 64-bit DWARF3 files |
| this ought to be an 8-byte wide computation. */ |
| if (dwarf_version == -1) |
| { |
| printf (_("(DW_OP_GNU_implicit_pointer in frame info)")); |
| /* No way to tell where the next op is, so just bail. */ |
| return need_frame_base; |
| } |
| if (dwarf_version == 2) |
| { |
| SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| } |
| else |
| { |
| SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| } |
| printf ("DW_OP_GNU_implicit_pointer: <0x%s> %s", |
| dwarf_vmatoa ("x", uvalue), |
| dwarf_vmatoa ("d", read_sleb128 (data, |
| &bytes_read, end))); |
| data += bytes_read; |
| break; |
| case DW_OP_GNU_entry_value: |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| /* PR 17531: file: 0cc9cd00. */ |
| if (uvalue > (dwarf_vma) (end - data)) |
| uvalue = end - data; |
| printf ("DW_OP_GNU_entry_value: ("); |
| if (decode_location_expression (data, pointer_size, offset_size, |
| dwarf_version, uvalue, |
| cu_offset, section)) |
| need_frame_base = 1; |
| putchar (')'); |
| data += uvalue; |
| if (data > end) |
| data = end; |
| break; |
| case DW_OP_GNU_const_type: |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf ("DW_OP_GNU_const_type: <0x%s> ", |
| dwarf_vmatoa ("x", cu_offset + uvalue)); |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| data = display_block (data, uvalue, end); |
| break; |
| case DW_OP_GNU_regval_type: |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf ("DW_OP_GNU_regval_type: %s (%s)", |
| dwarf_vmatoa ("u", uvalue), regname (uvalue, 1)); |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
| break; |
| case DW_OP_GNU_deref_type: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| printf ("DW_OP_GNU_deref_type: %ld", (long) uvalue); |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf (" <0x%s>", dwarf_vmatoa ("x", cu_offset + uvalue)); |
| break; |
| case DW_OP_GNU_convert: |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf ("DW_OP_GNU_convert <0x%s>", |
| dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
| break; |
| case DW_OP_GNU_reinterpret: |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf ("DW_OP_GNU_reinterpret <0x%s>", |
| dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0)); |
| break; |
| case DW_OP_GNU_parameter_ref: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| printf ("DW_OP_GNU_parameter_ref: <0x%s>", |
| dwarf_vmatoa ("x", cu_offset + uvalue)); |
| break; |
| case DW_OP_GNU_addr_index: |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf ("DW_OP_GNU_addr_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
| break; |
| case DW_OP_GNU_const_index: |
| uvalue = read_uleb128 (data, &bytes_read, end); |
| data += bytes_read; |
| printf ("DW_OP_GNU_const_index <0x%s>", dwarf_vmatoa ("x", uvalue)); |
| break; |
| |
| /* HP extensions. */ |
| case DW_OP_HP_is_value: |
| printf ("DW_OP_HP_is_value"); |
| /* FIXME: Is there data associated with this OP ? */ |
| break; |
| case DW_OP_HP_fltconst4: |
| printf ("DW_OP_HP_fltconst4"); |
| /* FIXME: Is there data associated with this OP ? */ |
| break; |
| case DW_OP_HP_fltconst8: |
| printf ("DW_OP_HP_fltconst8"); |
| /* FIXME: Is there data associated with this OP ? */ |
| break; |
| case DW_OP_HP_mod_range: |
| printf ("DW_OP_HP_mod_range"); |
| /* FIXME: Is there data associated with this OP ? */ |
| break; |
| case DW_OP_HP_unmod_range: |
| printf ("DW_OP_HP_unmod_range"); |
| /* FIXME: Is there data associated with this OP ? */ |
| break; |
| case DW_OP_HP_tls: |
| printf ("DW_OP_HP_tls"); |
| /* FIXME: Is there data associated with this OP ? */ |
| break; |
| |
| /* PGI (STMicroelectronics) extensions. */ |
| case DW_OP_PGI_omp_thread_num: |
| /* Pushes the thread number for the current thread as it would be |
| returned by the standard OpenMP library function: |
| omp_get_thread_num(). The "current thread" is the thread for |
| which the expression is being evaluated. */ |
| printf ("DW_OP_PGI_omp_thread_num"); |
| break; |
| |
| default: |
| if (op >= DW_OP_lo_user |
| && op <= DW_OP_hi_user) |
| printf (_("(User defined location op)")); |
| else |
| printf (_("(Unknown location op)")); |
| /* No way to tell where the next op is, so just bail. */ |
| return need_frame_base; |
| } |
| |
| /* Separate the ops. */ |
| if (data < end) |
| printf ("; "); |
| } |
| |
| return need_frame_base; |
| } |
| |
| /* Find the CU or TU set corresponding to the given CU_OFFSET. |
| This is used for DWARF package files. */ |
| |
| static struct cu_tu_set * |
| find_cu_tu_set_v2 (dwarf_vma cu_offset, int do_types) |
| { |
| struct cu_tu_set *p; |
| unsigned int nsets; |
| unsigned int dw_sect; |
| |
| if (do_types) |
| { |
| p = tu_sets; |
| nsets = tu_count; |
| dw_sect = DW_SECT_TYPES; |
| } |
| else |
| { |
| p = cu_sets; |
| nsets = cu_count; |
| dw_sect = DW_SECT_INFO; |
| } |
| while (nsets > 0) |
| { |
| if (p->section_offsets [dw_sect] == cu_offset) |
| return p; |
| p++; |
| nsets--; |
| } |
| return NULL; |
| } |
| |
| /* Add INC to HIGH_BITS:LOW_BITS. */ |
| static void |
| add64 (dwarf_vma * high_bits, dwarf_vma * low_bits, dwarf_vma inc) |
| { |
| dwarf_vma tmp = * low_bits; |
| |
| tmp += inc; |
| |
| /* FIXME: There is probably a better way of handling this: |
| |
| We need to cope with dwarf_vma being a 32-bit or 64-bit |
| type. Plus regardless of its size LOW_BITS is meant to |
| only hold 32-bits, so if there is overflow or wrap around |
| we must propagate into HIGH_BITS. */ |
| if (tmp < * low_bits) |
| { |
| ++ * high_bits; |
| } |
| else if (sizeof (tmp) > 8 |
| && (tmp >> 31) > 1) |
| { |
| ++ * high_bits; |
| tmp &= 0xFFFFFFFF; |
| } |
| |
| * low_bits = tmp; |
| } |
| |
| static unsigned char * |
| read_and_display_attr_value (unsigned long attribute, |
| unsigned long form, |
| unsigned char * data, |
| unsigned char * end, |
| dwarf_vma cu_offset, |
| dwarf_vma pointer_size, |
| dwarf_vma offset_size, |
| int dwarf_version, |
| debug_info * debug_info_p, |
| int do_loc, |
| struct dwarf_section * section, |
| struct cu_tu_set * this_set) |
| { |
| dwarf_vma uvalue = 0; |
| unsigned char *block_start = NULL; |
| unsigned char * orig_data = data; |
| unsigned int bytes_read; |
| |
| if (data > end || (data == end && form != DW_FORM_flag_present)) |
| { |
| warn (_("Corrupt attribute\n")); |
| return data; |
| } |
| |
| switch (form) |
| { |
| default: |
| break; |
| |
| case DW_FORM_ref_addr: |
| if (dwarf_version == 2) |
| SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| else if (dwarf_version == 3 || dwarf_version == 4) |
| SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| else |
| error (_("Internal error: DWARF version is not 2, 3 or 4.\n")); |
| |
| break; |
| |
| case DW_FORM_addr: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| break; |
| |
| case DW_FORM_strp: |
| case DW_FORM_sec_offset: |
| case DW_FORM_GNU_ref_alt: |
| case DW_FORM_GNU_strp_alt: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| break; |
| |
| case DW_FORM_flag_present: |
| uvalue = 1; |
| break; |
| |
| case DW_FORM_ref1: |
| case DW_FORM_flag: |
| case DW_FORM_data1: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| break; |
| |
| case DW_FORM_ref2: |
| case DW_FORM_data2: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
| break; |
| |
| case DW_FORM_ref4: |
| case DW_FORM_data4: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| break; |
| |
| case DW_FORM_sdata: |
| uvalue = read_sleb128 (data, & bytes_read, end); |
| data += bytes_read; |
| break; |
| |
| case DW_FORM_GNU_str_index: |
| uvalue = read_uleb128 (data, & bytes_read, end); |
| data += bytes_read; |
| break; |
| |
| case DW_FORM_ref_udata: |
| case DW_FORM_udata: |
| uvalue = read_uleb128 (data, & bytes_read, end); |
| data += bytes_read; |
| break; |
| |
| case DW_FORM_indirect: |
| form = read_uleb128 (data, & bytes_read, end); |
| data += bytes_read; |
| if (!do_loc) |
| printf (" %s", get_FORM_name (form)); |
| return read_and_display_attr_value (attribute, form, data, end, |
| cu_offset, pointer_size, |
| offset_size, dwarf_version, |
| debug_info_p, do_loc, |
| section, this_set); |
| case DW_FORM_GNU_addr_index: |
| uvalue = read_uleb128 (data, & bytes_read, end); |
| data += bytes_read; |
| break; |
| } |
| |
| switch (form) |
| { |
| case DW_FORM_ref_addr: |
| if (!do_loc) |
| printf (" <0x%s>", dwarf_vmatoa ("x",uvalue)); |
| break; |
| |
| case DW_FORM_GNU_ref_alt: |
| if (!do_loc) |
| printf (" <alt 0x%s>", dwarf_vmatoa ("x",uvalue)); |
| break; |
| |
| case DW_FORM_ref1: |
| case DW_FORM_ref2: |
| case DW_FORM_ref4: |
| case DW_FORM_ref_udata: |
| if (!do_loc) |
| printf (" <0x%s>", dwarf_vmatoa ("x", uvalue + cu_offset)); |
| break; |
| |
| case DW_FORM_data4: |
| case DW_FORM_addr: |
| case DW_FORM_sec_offset: |
| if (!do_loc) |
| printf (" 0x%s", dwarf_vmatoa ("x", uvalue)); |
| break; |
| |
| case DW_FORM_flag_present: |
| case DW_FORM_flag: |
| case DW_FORM_data1: |
| case DW_FORM_data2: |
| case DW_FORM_sdata: |
| case DW_FORM_udata: |
| if (!do_loc) |
| printf (" %s", dwarf_vmatoa ("d", uvalue)); |
| break; |
| |
| case DW_FORM_ref8: |
| case DW_FORM_data8: |
| if (!do_loc) |
| { |
| dwarf_vma high_bits; |
| dwarf_vma utmp; |
| char buf[64]; |
| |
| SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
| utmp = uvalue; |
| if (form == DW_FORM_ref8) |
| add64 (& high_bits, & utmp, cu_offset); |
| printf (" 0x%s", |
| dwarf_vmatoa64 (high_bits, utmp, buf, sizeof (buf))); |
| } |
| |
| if ((do_loc || do_debug_loc || do_debug_ranges) |
| && num_debug_info_entries == 0) |
| { |
| if (sizeof (uvalue) == 8) |
| SAFE_BYTE_GET (uvalue, data, 8, end); |
| else |
| error (_("DW_FORM_data8 is unsupported when sizeof (dwarf_vma) != 8\n")); |
| } |
| |
| data += 8; |
| break; |
| |
| case DW_FORM_string: |
| if (!do_loc) |
| printf (" %.*s", (int) (end - data), data); |
| data += strnlen ((char *) data, end - data) + 1; |
| break; |
| |
| case DW_FORM_block: |
| case DW_FORM_exprloc: |
| uvalue = read_uleb128 (data, & bytes_read, end); |
| block_start = data + bytes_read; |
| if (block_start >= end) |
| { |
| warn (_("Block ends prematurely\n")); |
| uvalue = 0; |
| block_start = end; |
| } |
| /* FIXME: Testing "(block_start + uvalue) < block_start" miscompiles with |
| gcc 4.8.3 running on an x86_64 host in 32-bit mode. So we pre-compute |
| block_start + uvalue here. */ |
| data = block_start + uvalue; |
| /* PR 17512: file: 008-103549-0.001:0.1. */ |
| if (block_start + uvalue > end || data < block_start) |
| { |
| warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); |
| uvalue = end - block_start; |
| } |
| if (do_loc) |
| data = block_start + uvalue; |
| else |
| data = display_block (block_start, uvalue, end); |
| break; |
| |
| case DW_FORM_block1: |
| SAFE_BYTE_GET (uvalue, data, 1, end); |
| block_start = data + 1; |
| if (block_start >= end) |
| { |
| warn (_("Block ends prematurely\n")); |
| uvalue = 0; |
| block_start = end; |
| } |
| data = block_start + uvalue; |
| if (block_start + uvalue > end || data < block_start) |
| { |
| warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); |
| uvalue = end - block_start; |
| } |
| if (do_loc) |
| data = block_start + uvalue; |
| else |
| data = display_block (block_start, uvalue, end); |
| break; |
| |
| case DW_FORM_block2: |
| SAFE_BYTE_GET (uvalue, data, 2, end); |
| block_start = data + 2; |
| if (block_start >= end) |
| { |
| warn (_("Block ends prematurely\n")); |
| uvalue = 0; |
| block_start = end; |
| } |
| data = block_start + uvalue; |
| if (block_start + uvalue > end || data < block_start) |
| { |
| warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); |
| uvalue = end - block_start; |
| } |
| if (do_loc) |
| data = block_start + uvalue; |
| else |
| data = display_block (block_start, uvalue, end); |
| break; |
| |
| case DW_FORM_block4: |
| SAFE_BYTE_GET (uvalue, data, 4, end); |
| block_start = data + 4; |
| /* PR 17512: file: 3371-3907-0.004. */ |
| if (block_start >= end) |
| { |
| warn (_("Block ends prematurely\n")); |
| uvalue = 0; |
| block_start = end; |
| } |
| data = block_start + uvalue; |
| if (block_start + uvalue > end |
| /* PR 17531: file: 5b5f0592. */ |
| || data < block_start) |
| { |
| warn (_("Corrupt attribute block length: %lx\n"), (long) uvalue); |
| uvalue = end - block_start; |
| } |
| if (do_loc) |
| data = block_start + uvalue; |
| else |
| data = display_block (block_start, uvalue, end); |
| break; |
| |
| case DW_FORM_strp: |
| if (!do_loc) |
| printf (_(" (indirect string, offset: 0x%s): %s"), |
| dwarf_vmatoa ("x", uvalue), |
| fetch_indirect_string (uvalue)); |
| break; |
| |
| case DW_FORM_GNU_str_index: |
| if (!do_loc) |
| { |
| const char *suffix = strrchr (section->name, '.'); |
| int dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? 1 : 0; |
| |
| printf (_(" (indexed string: 0x%s): %s"), |
| dwarf_vmatoa ("x", uvalue), |
| fetch_indexed_string (uvalue, this_set, offset_size, dwo)); |
| } |
| break; |
| |
| case DW_FORM_GNU_strp_alt: |
| if (!do_loc) |
| printf (_(" (alt indirect string, offset: 0x%s)"), |
| dwarf_vmatoa ("x", uvalue)); |
| break; |
| |
| case DW_FORM_indirect: |
| /* Handled above. */ |
| break; |
| |
| case DW_FORM_ref_sig8: |
| if (!do_loc) |
| { |
| dwarf_vma high_bits; |
| char buf[64]; |
| |
| SAFE_BYTE_GET64 (data, &high_bits, &uvalue, end); |
| printf (" signature: 0x%s", |
| dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf))); |
| } |
| data += 8; |
| break; |
| |
| case DW_FORM_GNU_addr_index: |
| if (!do_loc) |
| printf (_(" (addr_index: 0x%s): %s"), |
| dwarf_vmatoa ("x", uvalue), |
| fetch_indexed_value (uvalue * pointer_size, pointer_size)); |
| break; |
| |
| default: |
| warn (_("Unrecognized form: %lu\n"), form); |
| break; |
| } |
| |
| if ((do_loc || do_debug_loc || do_debug_ranges) |
| && num_debug_info_entries == 0 |
| && debug_info_p != NULL) |
| { |
| switch (attribute) |
| { |
| case DW_AT_frame_base: |
| have_frame_base = 1; |
| /* Fall through. */ |
| case DW_AT_location: |
| case DW_AT_string_length: |
| case DW_AT_return_addr: |
| case DW_AT_data_member_location: |
| case DW_AT_vtable_elem_location: |
| case DW_AT_segment: |
| case DW_AT_static_link: |
| case DW_AT_use_location: |
| case DW_AT_GNU_call_site_value: |
| case DW_AT_GNU_call_site_data_value: |
| case DW_AT_GNU_call_site_target: |
| case DW_AT_GNU_call_site_target_clobbered: |
| if ((dwarf_version < 4 |
| && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
| || form == DW_FORM_sec_offset) |
| { |
| /* Process location list. */ |
| unsigned int lmax = debug_info_p->max_loc_offsets; |
| unsigned int num = debug_info_p->num_loc_offsets; |
| |
| if (lmax == 0 || num >= lmax) |
| { |
| lmax += 1024; |
| debug_info_p->loc_offsets = (dwarf_vma *) |
| xcrealloc (debug_info_p->loc_offsets, |
| lmax, sizeof (*debug_info_p->loc_offsets)); |
| debug_info_p->have_frame_base = (int *) |
| xcrealloc (debug_info_p->have_frame_base, |
| lmax, sizeof (*debug_info_p->have_frame_base)); |
| debug_info_p->max_loc_offsets = lmax; |
| } |
| if (this_set != NULL) |
| uvalue += this_set->section_offsets [DW_SECT_LOC]; |
| debug_info_p->loc_offsets [num] = uvalue; |
| debug_info_p->have_frame_base [num] = have_frame_base; |
| debug_info_p->num_loc_offsets++; |
| } |
| break; |
| |
| case DW_AT_low_pc: |
| if (need_base_address) |
| debug_info_p->base_address = uvalue; |
| break; |
| |
| case DW_AT_GNU_addr_base: |
| debug_info_p->addr_base = uvalue; |
| break; |
| |
| case DW_AT_GNU_ranges_base: |
| debug_info_p->ranges_base = uvalue; |
| break; |
| |
| case DW_AT_ranges: |
| if ((dwarf_version < 4 |
| && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
| || form == DW_FORM_sec_offset) |
| { |
| /* Process range list. */ |
| unsigned int lmax = debug_info_p->max_range_lists; |
| unsigned int num = debug_info_p->num_range_lists; |
| |
| if (lmax == 0 || num >= lmax) |
| { |
| lmax += 1024; |
| debug_info_p->range_lists = (dwarf_vma *) |
| xcrealloc (debug_info_p->range_lists, |
| lmax, sizeof (*debug_info_p->range_lists)); |
| debug_info_p->max_range_lists = lmax; |
| } |
| debug_info_p->range_lists [num] = uvalue; |
| debug_info_p->num_range_lists++; |
| } |
| break; |
| |
| default: |
| break; |
| } |
| } |
| |
| if (do_loc || attribute == 0) |
| return data; |
| |
| /* For some attributes we can display further information. */ |
| switch (attribute) |
| { |
| case DW_AT_inline: |
| printf ("\t"); |
| switch (uvalue) |
| { |
| case DW_INL_not_inlined: |
| printf (_("(not inlined)")); |
| break; |
| case DW_INL_inlined: |
| printf (_("(inlined)")); |
| break; |
| case DW_INL_declared_not_inlined: |
| printf (_("(declared as inline but ignored)")); |
| break; |
| case DW_INL_declared_inlined: |
| printf (_("(declared as inline and inlined)")); |
| break; |
| default: |
| printf (_(" (Unknown inline attribute value: %s)"), |
| dwarf_vmatoa ("x", uvalue)); |
| break; |
| } |
| break; |
| |
| case DW_AT_language: |
| printf ("\t"); |
| switch (uvalue) |
| { |
| /* Ordered by the numeric value of these constants. */ |
| case DW_LANG_C89: printf ("(ANSI C)"); break; |
| case DW_LANG_C: printf ("(non-ANSI C)"); break; |
| case DW_LANG_Ada83: printf ("(Ada)"); break; |
| case DW_LANG_C_plus_plus: printf ("(C++)"); break; |
| case DW_LANG_Cobol74: printf ("(Cobol 74)"); break; |
| case DW_LANG_Cobol85: printf ("(Cobol 85)"); break; |
| case DW_LANG_Fortran77: printf ("(FORTRAN 77)"); break; |
| case DW_LANG_Fortran90: printf ("(Fortran 90)"); break; |
| case DW_LANG_Pascal83: printf ("(ANSI Pascal)"); break; |
| case DW_LANG_Modula2: printf ("(Modula 2)"); break; |
| /* DWARF 2.1 values. */ |
| case DW_LANG_Java: printf ("(Java)"); break; |
| case DW_LANG_C99: printf ("(ANSI C99)"); break; |
| case DW_LANG_Ada95: printf ("(ADA 95)"); break; |
| case DW_LANG_Fortran95: printf ("(Fortran 95)"); break; |
| /* DWARF 3 values. */ |
| case DW_LANG_PLI: printf ("(PLI)"); break; |
| case DW_LANG_ObjC: printf ("(Objective C)"); break; |
| case DW_LANG_ObjC_plus_plus: printf ("(Objective C++)"); break; |
| case DW_LANG_UPC: printf ("(Unified Parallel C)"); break; |
| case DW_LANG_D: printf ("(D)"); break; |
| /* DWARF 4 values. */ |
| case DW_LANG_Python: printf ("(Python)"); break; |
| /* DWARF 5 values. */ |
| case DW_LANG_Go: printf ("(Go)"); break; |
| case DW_LANG_C_plus_plus_11: printf ("(C++11)"); break; |
| case DW_LANG_C11: printf ("(C11)"); break; |
| case DW_LANG_C_plus_plus_14: printf ("(C++14)"); break; |
| case DW_LANG_Fortran03: printf ("(Fortran 03)"); break; |
| case DW_LANG_Fortran08: printf ("(Fortran 08)"); break; |
| /* MIPS extension. */ |
| case DW_LANG_Mips_Assembler: printf ("(MIPS assembler)"); break; |
| /* UPC extension. */ |
| case DW_LANG_Upc: printf ("(Unified Parallel C)"); break; |
| default: |
| if (uvalue >= DW_LANG_lo_user && uvalue <= DW_LANG_hi_user) |
| printf (_("(implementation defined: %s)"), |
| dwarf_vmatoa ("x", uvalue)); |
| else |
| printf (_("(Unknown: %s)"), dwarf_vmatoa ("x", uvalue)); |
| break; |
| } |
| break; |
| |
| case DW_AT_encoding: |
| printf ("\t"); |
| switch (uvalue) |
| { |
| case DW_ATE_void: printf ("(void)"); break; |
| case DW_ATE_address: printf ("(machine address)"); break; |
| case DW_ATE_boolean: printf ("(boolean)"); break; |
| case DW_ATE_complex_float: printf ("(complex float)"); break; |
| case DW_ATE_float: printf ("(float)"); break; |
| case DW_ATE_signed: printf ("(signed)"); break; |
| case DW_ATE_signed_char: printf ("(signed char)"); break; |
| case DW_ATE_unsigned: printf ("(unsigned)"); break; |
| case DW_ATE_unsigned_char: printf ("(unsigned char)"); break; |
| /* DWARF 2.1 values: */ |
| case DW_ATE_imaginary_float: printf ("(imaginary float)"); break; |
| case DW_ATE_decimal_float: printf ("(decimal float)"); break; |
| /* DWARF 3 values: */ |
| case DW_ATE_packed_decimal: printf ("(packed_decimal)"); break; |
| case DW_ATE_numeric_string: printf ("(numeric_string)"); break; |
| case DW_ATE_edited: printf ("(edited)"); break; |
| case DW_ATE_signed_fixed: printf ("(signed_fixed)"); break; |
| case DW_ATE_unsigned_fixed: printf ("(unsigned_fixed)"); break; |
| /* HP extensions: */ |
| case DW_ATE_HP_float80: printf ("(HP_float80)"); break; |
| case DW_ATE_HP_complex_float80: printf ("(HP_complex_float80)"); break; |
| case DW_ATE_HP_float128: printf ("(HP_float128)"); break; |
| case DW_ATE_HP_complex_float128:printf ("(HP_complex_float128)"); break; |
| case DW_ATE_HP_floathpintel: printf ("(HP_floathpintel)"); break; |
| case DW_ATE_HP_imaginary_float80: printf ("(HP_imaginary_float80)"); break; |
| case DW_ATE_HP_imaginary_float128: printf ("(HP_imaginary_float128)"); break; |
| /* DWARF 4 values: */ |
| case DW_ATE_UTF: printf ("(unicode string)"); break; |
| |
| default: |
| if (uvalue >= DW_ATE_lo_user |
| && uvalue <= DW_ATE_hi_user) |
| printf (_("(user defined type)")); |
| else |
| printf (_("(unknown type)")); |
| break; |
| } |
| break; |
| |
| case DW_AT_accessibility: |
| printf ("\t"); |
| switch (uvalue) |
| { |
| case DW_ACCESS_public: printf ("(public)"); break; |
| case DW_ACCESS_protected: printf ("(protected)"); break; |
| case DW_ACCESS_private: printf ("(private)"); break; |
| default: |
| printf (_("(unknown accessibility)")); |
| break; |
| } |
| break; |
| |
| case DW_AT_visibility: |
| printf ("\t"); |
| switch (uvalue) |
| { |
| case DW_VIS_local: printf ("(local)"); break; |
| case DW_VIS_exported: printf ("(exported)"); break; |
| case DW_VIS_qualified: printf ("(qualified)"); break; |
| default: printf (_("(unknown visibility)")); break; |
| } |
| break; |
| |
| case DW_AT_virtuality: |
| printf ("\t"); |
| switch (uvalue) |
| { |
| case DW_VIRTUALITY_none: printf ("(none)"); break; |
| case DW_VIRTUALITY_virtual: printf ("(virtual)"); break; |
| case DW_VIRTUALITY_pure_virtual:printf ("(pure_virtual)"); break; |
| default: printf (_("(unknown virtuality)")); break; |
| } |
| break; |
| |
| case DW_AT_identifier_case: |
| printf ("\t"); |
| switch (uvalue) |
| { |
| case DW_ID_case_sensitive: printf ("(case_sensitive)"); break; |
| case DW_ID_up_case: printf ("(up_case)"); break; |
| case DW_ID_down_case: printf ("(down_case)"); break; |
| case DW_ID_case_insensitive: printf ("(case_insensitive)"); break; |
| default: printf (_("(unknown case)")); break; |
| } |
| break; |
| |
| case DW_AT_calling_convention: |
| printf ("\t"); |
| switch (uvalue) |
| { |
| case DW_CC_normal: printf ("(normal)"); break; |
| case DW_CC_program: printf ("(program)"); break; |
| case DW_CC_nocall: printf ("(nocall)"); break; |
| default: |
| if (uvalue >= DW_CC_lo_user |
| && uvalue <= DW_CC_hi_user) |
| printf (_("(user defined)")); |
| else |
| printf (_("(unknown convention)")); |
| } |
| break; |
| |
| case DW_AT_ordering: |
| printf ("\t"); |
| switch (uvalue) |
| { |
| case -1: printf (_("(undefined)")); break; |
| case 0: printf ("(row major)"); break; |
| case 1: printf ("(column major)"); break; |
| } |
| break; |
| |
| case DW_AT_frame_base: |
| have_frame_base = 1; |
| /* Fall through. */ |
| case DW_AT_location: |
| case DW_AT_string_length: |
| case DW_AT_return_addr: |
| case DW_AT_data_member_location: |
| case DW_AT_vtable_elem_location: |
| case DW_AT_segment: |
| case DW_AT_static_link: |
| case DW_AT_use_location: |
| case DW_AT_GNU_call_site_value: |
| case DW_AT_GNU_call_site_data_value: |
| case DW_AT_GNU_call_site_target: |
| case DW_AT_GNU_call_site_target_clobbered: |
| if ((dwarf_version < 4 |
| && (form == DW_FORM_data4 || form == DW_FORM_data8)) |
| || form == DW_FORM_sec_offset) |
| printf (_(" (location list)")); |
| /* Fall through. */ |
| case DW_AT_allocated: |
| case DW_AT_associated: |
| case DW_AT_data_location: |
| case DW_AT_stride: |
| case DW_AT_upper_bound: |
| case DW_AT_lower_bound: |
| if (block_start) |
| { |
| int need_frame_base; |
| |
| printf ("\t("); |
| need_frame_base = decode_location_expression (block_start, |
| pointer_size, |
| offset_size, |
| dwarf_version, |
| uvalue, |
| cu_offset, section); |
| printf (")"); |
| if (need_frame_base && !have_frame_base) |
| printf (_(" [without DW_AT_frame_base]")); |
| } |
| break; |
| |
| case DW_AT_import: |
| { |
| if (form == DW_FORM_ref_sig8 |
| || form == DW_FORM_GNU_ref_alt) |
| break; |
| |
| if (form == DW_FORM_ref1 |
| || form == DW_FORM_ref2 |
| || form == DW_FORM_ref4 |
| || form == DW_FORM_ref_udata) |
| uvalue += cu_offset; |
| |
| if (uvalue >= section->size) |
| warn (_("Offset %s used as value for DW_AT_import attribute of DIE at offset 0x%lx is too big.\n"), |
| dwarf_vmatoa ("x", uvalue), |
| (unsigned long) (orig_data - section->start)); |
| else |
| { |
| unsigned long abbrev_number; |
| abbrev_entry * entry; |
| |
| abbrev_number = read_uleb128 (section->start + uvalue, NULL, end); |
| |
| printf (_("\t[Abbrev Number: %ld"), abbrev_number); |
| /* Don't look up abbrev for DW_FORM_ref_addr, as it very often will |
| use different abbrev table, and we don't track .debug_info chunks |
| yet. */ |
| if (form != DW_FORM_ref_addr) |
| { |
| for (entry = first_abbrev; entry != NULL; entry = entry->next) |
| if (entry->entry == abbrev_number) |
| break; |
| if (entry != NULL) |
| printf (" (%s)", get_TAG_name (entry->tag)); |
| } |
| printf ("]"); |
| } |
| } |
| break; |
| |
| default: |
| break; |
| } |
| |
| return data; |
| } |
| |
| static const char * |
| get_AT_name (unsigned long attribute) |
| { |
| const char *name; |
| |
| if (attribute == 0) |
| return "DW_AT value: 0"; |
| |
| /* One value is shared by the MIPS and HP extensions: */ |
| if (attribute == DW_AT_MIPS_fde) |
| return "DW_AT_MIPS_fde or DW_AT_HP_unmodifiable"; |
| |
| name = get_DW_AT_name (attribute); |
| |
| if (name == NULL) |
| { |
| static char buffer[100]; |
| |
| snprintf (buffer, sizeof (buffer), _("Unknown AT value: %lx"), |
| attribute); |
| return buffer; |
| } |
| |
| return name; |
| } |
| |
| static unsigned char * |
| read_and_display_attr (unsigned long attribute, |
| unsigned long form, |
| unsigned char * data, |
| unsigned char * end, |
| dwarf_vma cu_offset, |
| dwarf_vma pointer_size, |
| dwarf_vma offset_size, |
| int dwarf_version, |
| debug_info * debug_info_p, |
| int do_loc, |
| struct dwarf_section * section, |
| struct cu_tu_set * this_set) |
| { |
| if (!do_loc) |
| printf (" %-18s:", get_AT_name (attribute)); |
| data = read_and_display_attr_value (attribute, form, data, end, |
| cu_offset, pointer_size, offset_size, |
| dwarf_version, debug_info_p, |
| do_loc, section, this_set); |
| if (!do_loc) |
| printf ("\n"); |
| return data; |
| } |
| |
| /* Process the contents of a .debug_info section. If do_loc is non-zero |
| then we are scanning for location lists and we do not want to display |
| anything to the user. If do_types is non-zero, we are processing |
| a .debug_types section instead of a .debug_info section. */ |
| |
| static int |
| process_debug_info (struct dwarf_section *section, |
| void *file, |
| enum dwarf_section_display_enum abbrev_sec, |
| int do_loc, |
| int do_types) |
| { |
| unsigned char *start = section->start; |
| unsigned char *end = start + section->size; |
| unsigned char *section_begin; |
| unsigned int unit; |
| unsigned int num_units = 0; |
| |
| if ((do_loc || do_debug_loc || do_debug_ranges) |
| && num_debug_info_entries == 0 |
| && ! do_types) |
| { |
| dwarf_vma length; |
| |
| /* First scan the section to get the number of comp units. */ |
| for (section_begin = start, num_units = 0; section_begin < end; |
| num_units ++) |
| { |
| /* Read the first 4 bytes. For a 32-bit DWARF section, this |
| will be the length. For a 64-bit DWARF section, it'll be |
| the escape code 0xffffffff followed by an 8 byte length. */ |
| SAFE_BYTE_GET (length, section_begin, 4, end); |
| |
| if (length == 0xffffffff) |
| { |
| SAFE_BYTE_GET (length, section_begin + 4, 8, end); |
| section_begin += length + 12; |
| } |
| else if (length >= 0xfffffff0 && length < 0xffffffff) |
| { |
| warn (_("Reserved length value (0x%s) found in section %s\n"), |
| dwarf_vmatoa ("x", length), section->name); |
| return 0; |
| } |
| else |
| section_begin += length + 4; |
| |
| /* Negative values are illegal, they may even cause infinite |
| looping. This can happen if we can't accurately apply |
| relocations to an object file, or if the file is corrupt. */ |
| if ((signed long) length <= 0 || section_begin < start) |
| { |
| warn (_("Corrupt unit length (0x%s) found in section %s\n"), |
| dwarf_vmatoa ("x", length), section->name); |
| return 0; |
| } |
| } |
| |
| if (num_units == 0) |
| { |
| error (_("No comp units in %s section ?\n"), section->name); |
| return 0; |
| } |
| |
| /* Then allocate an array to hold the information. */ |
| debug_information = (debug_info *) cmalloc (num_units, |
| sizeof (* debug_information)); |
| if (debug_information == NULL) |
| { |
| error (_("Not enough memory for a debug info array of %u entries\n"), |
| num_units); |
| alloc_num_debug_info_entries = num_debug_info_entries = 0; |
| return 0; |
| } |
| /* PR 17531: file: 92ca3797. |
| We cannot rely upon the debug_information array being initialised |
| before it is used. A corrupt file could easily contain references |
| to a unit for which information has not been made available. So |
| we ensure that the array is zeroed here. */ |
| memset (debug_information, 0, num_units * sizeof (*debug_information)); |
| |
| alloc_num_debug_info_entries = num_units; |
| } |
| |
| if (!do_loc) |
| { |
| if (dwarf_start_die == 0) |
| printf (_("Contents of the %s section:\n\n"), section->name); |
| |
| load_debug_section (str, file); |
| load_debug_section (str_dwo, file); |
| load_debug_section (str_index, file); |
| load_debug_section (str_index_dwo, file); |
| load_debug_section (debug_addr, file); |
| } |
| |
| load_debug_section (abbrev_sec, file); |
| if (debug_displays [abbrev_sec].section.start == NULL) |
| { |
| warn (_("Unable to locate %s section!\n"), |
| debug_displays [abbrev_sec].section.name); |
| return 0; |
| } |
| |
| for (section_begin = start, unit = 0; start < end; unit++) |
| { |
| DWARF2_Internal_CompUnit compunit; |
| unsigned char *hdrptr; |
| unsigned char *tags; |
| int level, last_level, saved_level; |
| dwarf_vma cu_offset; |
| unsigned int offset_size; |
| int initial_length_size; |
| dwarf_vma signature_high = 0; |
| dwarf_vma signature_low = 0; |
| dwarf_vma type_offset = 0; |
| struct cu_tu_set *this_set; |
| dwarf_vma abbrev_base; |
| size_t abbrev_size; |
| |
| hdrptr = start; |
| |
| SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 4, end); |
| |
| if (compunit.cu_length == 0xffffffff) |
| { |
| SAFE_BYTE_GET_AND_INC (compunit.cu_length, hdrptr, 8, end); |
| offset_size = 8; |
| initial_length_size = 12; |
| } |
| else |
| { |
| offset_size = 4; |
| initial_length_size = 4; |
| } |
| |
| SAFE_BYTE_GET_AND_INC (compunit.cu_version, hdrptr, 2, end); |
| |
| cu_offset = start - section_begin; |
| |
| this_set = find_cu_tu_set_v2 (cu_offset, do_types); |
| |
| SAFE_BYTE_GET_AND_INC (compunit.cu_abbrev_offset, hdrptr, offset_size, end); |
| |
| if (this_set == NULL) |
| { |
| abbrev_base = 0; |
| abbrev_size = debug_displays [abbrev_sec].section.size; |
| } |
| else |
| { |
| abbrev_base = this_set->section_offsets [DW_SECT_ABBREV]; |
| abbrev_size = this_set->section_sizes [DW_SECT_ABBREV]; |
| } |
| |
| SAFE_BYTE_GET_AND_INC (compunit.cu_pointer_size, hdrptr, 1, end); |
| /* PR 17512: file: 001-108546-0.001:0.1. */ |
| if (compunit.cu_pointer_size < 2 || compunit.cu_pointer_size > 8) |
| { |
| warn (_("Invalid pointer size (%d) in compunit header, using %d instead\n"), |
| compunit.cu_pointer_size, offset_size); |
| compunit.cu_pointer_size = offset_size; |
| } |
| |
| if (do_types) |
| { |
| SAFE_BYTE_GET64 (hdrptr, &signature_high, &signature_low, end); |
| hdrptr += 8; |
| SAFE_BYTE_GET_AND_INC (type_offset, hdrptr, offset_size, end); |
| } |
| |
| if ((do_loc || do_debug_loc || do_debug_ranges) |
| && num_debug_info_entries == 0 |
| && ! do_types) |
| { |
| debug_information [unit].cu_offset = cu_offset; |
| debug_information [unit].pointer_size |
| = compunit.cu_pointer_size; |
| debug_information [unit].offset_size = offset_size; |
| debug_information [unit].dwarf_version = compunit.cu_version; |
| debug_information [unit].base_address = 0; |
| debug_information [unit].addr_base = DEBUG_INFO_UNAVAILABLE; |
| debug_information [unit].ranges_base = DEBUG_INFO_UNAVAILABLE; |
| debug_information [unit].loc_offsets = NULL; |
| debug_information [unit].have_frame_base = NULL; |
| debug_information [unit].max_loc_offsets = 0; |
| debug_information [unit].num_loc_offsets = 0; |
| debug_information [unit].range_lists = NULL; |
| debug_information [unit].max_range_lists= 0; |
| debug_information [unit].num_range_lists = 0; |
| } |
| |
| if (!do_loc && dwarf_start_die == 0) |
| { |
| printf (_(" Compilation Unit @ offset 0x%s:\n"), |
| dwarf_vmatoa ("x", cu_offset)); |
| printf (_(" Length: 0x%s (%s)\n"), |
| dwarf_vmatoa ("x", compunit.cu_length), |
| offset_size == 8 ? "64-bit" : "32-bit"); |
| printf (_(" Version: %d\n"), compunit.cu_version); |
| printf (_(" Abbrev Offset: 0x%s\n"), |
| dwarf_vmatoa ("x", compunit.cu_abbrev_offset)); |
| printf (_(" Pointer Size: %d\n"), compunit.cu_pointer_size); |
| if (do_types) |
| { |
| char buf[64]; |
| |
| printf (_(" Signature: 0x%s\n"), |
| dwarf_vmatoa64 (signature_high, signature_low, |
| buf, sizeof (buf))); |
| printf (_(" Type Offset: 0x%s\n"), |
| dwarf_vmatoa ("x", type_offset)); |
| } |
| if (this_set != NULL) |
| { |
| dwarf_vma *offsets = this_set->section_offsets; |
| size_t *sizes = this_set->section_sizes; |
| |
| printf (_(" Section contributions:\n")); |
| printf (_(" .debug_abbrev.dwo: 0x%s 0x%s\n"), |
| dwarf_vmatoa ("x", offsets [DW_SECT_ABBREV]), |
| dwarf_vmatoa ("x", sizes [DW_SECT_ABBREV])); |
| printf (_(" .debug_line.dwo: 0x%s 0x%s\n"), |
| dwarf_vmatoa ("x", offsets [DW_SECT_LINE]), |
| dwarf_vmatoa ("x", sizes [DW_SECT_LINE])); |
| printf (_(" .debug_loc.dwo: 0x%s 0x%s\n"), |
| dwarf_vmatoa ("x", offsets [DW_SECT_LOC]), |
| dwarf_vmatoa ("x", sizes [DW_SECT_LOC])); |
| printf (_(" .debug_str_offsets.dwo: 0x%s 0x%s\n"), |
| dwarf_vmatoa ("x", offsets [DW_SECT_STR_OFFSETS]), |
| dwarf_vmatoa ("x", sizes [DW_SECT_STR_OFFSETS])); |
| } |
| } |
| |
| if (cu_offset + compunit.cu_length + initial_length_size |
| > section->size) |
| { |
| warn (_("Debug info is corrupted, length of CU at %s" |
| " extends beyond end of section (length = %s)\n"), |
| dwarf_vmatoa ("x", cu_offset), |
| dwarf_vmatoa ("x", compunit.cu_length)); |
| num_units = unit; |
| break; |
| } |
| tags = hdrptr; |
| start += compunit.cu_length + initial_length_size; |
| |
| if (start > end) |
| { |
| warn (_("Debug info is corrupt. CU at %s extends beyond end of section"), |
| dwarf_vmatoa ("x", cu_offset)); |
| start = end; |
| } |
| |
| if (compunit.cu_version != 2 |
| && compunit.cu_version != 3 |
| && compunit.cu_version != 4) |
| { |
| warn (_("CU at offset %s contains corrupt or " |
| "unsupported version number: %d.\n"), |
| dwarf_vmatoa ("x", cu_offset), compunit.cu_version); |
| continue; |
| } |
| |
| free_abbrevs (); |
| |
| /* Process the abbrevs used by this compilation unit. */ |
| if (compunit.cu_abbrev_offset >= abbrev_size) |
| warn (_("Debug info is corrupted, abbrev offset (%lx) is larger than abbrev section size (%lx)\n"), |
| (unsigned long) compunit.cu_abbrev_offset, |
| (unsigned long) abbrev_size); |
| /* PR 17531: file:4bcd9ce9. */ |
| else if ((abbrev_base + abbrev_size) |
| > debug_displays [abbrev_sec].section.size) |
| warn (_("Debug info is corrupted, abbrev size (%lx) is larger than abbrev section size (%lx)\n"), |
| (unsigned long) abbrev_base + abbrev_size, |
| (unsigned long) debug_displays [abbrev_sec].section.size); |
| else |
| process_abbrev_section |
| (((unsigned char *) debug_displays [abbrev_sec].section.start |
| + abbrev_base + compunit.cu_abbrev_offset), |
| ((unsigned char *) debug_displays [abbrev_sec].section.start |
| + abbrev_base + abbrev_size)); |
| |
| level = 0; |
| last_level = level; |
| saved_level = -1; |
| while (tags < start) |
| { |
| unsigned int bytes_read; |
| unsigned long abbrev_number; |
| unsigned long die_offset; |
| abbrev_entry *entry; |
| abbrev_attr *attr; |
| int do_printing = 1; |
| |
| die_offset = tags - section_begin; |
| |
| abbrev_number = read_uleb128 (tags, & bytes_read, start); |
| tags += bytes_read; |
| |
| /* A null DIE marks the end of a list of siblings or it may also be |
| a section padding. */ |
| if (abbrev_number == 0) |
| { |
| /* Check if it can be a section padding for the last CU. */ |
| if (level == 0 && start == end) |
| { |
| unsigned char *chk; |
| |
| for (chk = tags; chk < start; chk++) |
| if (*chk != 0) |
| break; |
| if (chk == start) |
| break; |
| } |
| |
| if (!do_loc && die_offset >= dwarf_start_die |
| && (dwarf_cutoff_level == -1 |
| || level < dwarf_cutoff_level)) |
| printf (_(" <%d><%lx>: Abbrev Number: 0\n"), |
| level, die_offset); |
| |
| --level; |
| if (level < 0) |
| { |
| static unsigned num_bogus_warns = 0; |
| |
| if (num_bogus_warns < 3) |
| { |
| warn (_("Bogus end-of-siblings marker detected at offset %lx in %s section\n"), |
| die_offset, section->name); |
| num_bogus_warns ++; |
| if (num_bogus_warns == 3) |
| warn (_("Further warnings about bogus end-of-sibling markers suppressed\n")); |
| } |
| } |
| if (dwarf_start_die != 0 && level < saved_level) |
| return 1; |
| continue; |
| } |
| |
| if (!do_loc) |
| { |
| if (dwarf_start_die != 0 && die_offset < dwarf_start_die) |
| do_printing = 0; |
| else |
| { |
| if (dwarf_start_die != 0 && die_offset == dwarf_start_die) |
| saved_level = level; |
| do_printing = (dwarf_cutoff_level == -1 |
| || level < dwarf_cutoff_level); |
| if (do_printing) |
| printf (_(" <%d><%lx>: Abbrev Number: %lu"), |
| level, die_offset, abbrev_number); |
| else if (dwarf_cutoff_level == -1 |
| || last_level < dwarf_cutoff_level) |
| printf (_(" <%d><%lx>: ...\n"), level, die_offset); |
| last_level = level; |
| } |
| } |
| |
| /* Scan through the abbreviation list until we reach the |
| correct entry. */ |
| for (entry = first_abbrev; |
| entry && entry->entry != abbrev_number; |
| entry = entry->next) |
| continue; |
| |
| if (entry == NULL) |
| { |
| if (!do_loc && do_printing) |
| { |
| printf ("\n"); |
| fflush (stdout); |
| } |
| warn (_("DIE at offset 0x%lx refers to abbreviation number %lu which does not exist\n"), |
| die_offset, abbrev_number); |
| return 0; |
| } |
| |
| if (!do_loc && do_printing) |
| printf (" (%s)\n", get_TAG_name (entry->tag)); |
| |
| switch (entry->tag) |
| { |
| default: |
| need_base_address = 0; |
| break; |
| case DW_TAG_compile_unit: |
| need_base_address = 1; |
| break; |
| case DW_TAG_entry_point: |
| case DW_TAG_subprogram: |
| need_base_address = 0; |
| /* Assuming that there is no DW_AT_frame_base. */ |
| have_frame_base = 0; |
| break; |
| } |
| |
| for (attr = entry->first_attr; |
| attr && attr->attribute; |
| attr = attr->next) |
| { |
| debug_info *arg; |
| |
| if (! do_loc && do_printing) |
| /* Show the offset from where the tag was extracted. */ |
| printf (" <%lx>", (unsigned long)(tags - section_begin)); |
| |
| if (debug_information && unit < alloc_num_debug_info_entries) |
| arg = debug_information + unit; |
| else |
| arg = NULL; |
| |
| tags = read_and_display_attr (attr->attribute, |
| attr->form, |
| tags, |
| end, |
| cu_offset, |
| compunit.cu_pointer_size, |
| offset_size, |
| compunit.cu_version, |
| arg, |
| do_loc || ! do_printing, |
| section, |
| this_set); |
| } |
| |
| if (entry->children) |
| ++level; |
| } |
| } |
| |
| /* Set num_debug_info_entries here so that it can be used to check if |
| we need to process .debug_loc and .debug_ranges sections. */ |
| if ((do_loc || do_debug_loc || do_debug_ranges) |
| && num_debug_info_entries == 0 |
| && ! do_types) |
| { |
| if (num_units > alloc_num_debug_info_entries) |
| num_debug_info_entries = alloc_num_debug_info_entries; |
| else |
| num_debug_info_entries = num_units; |
| } |
| |
| if (!do_loc) |
| printf ("\n"); |
| |
| return 1; |
| } |
| |
| /* Locate and scan the .debug_info section in the file and record the pointer |
| sizes and offsets for the compilation units in it. Usually an executable |
| will have just one pointer size, but this is not guaranteed, and so we try |
| not to make any assumptions. Returns zero upon failure, or the number of |
| compilation units upon success. */ |
| |
| static unsigned int |
| load_debug_info (void * file) |
| { |
| /* Reset the last pointer size so that we can issue correct error |
| messages if we are displaying the contents of more than one section. */ |
| last_pointer_size = 0; |
| warned_about_missing_comp_units = FALSE; |
| |
| /* If we have already tried and failed to load the .debug_info |
| section then do not bother to repeat the task. */ |
| if (num_debug_info_entries == DEBUG_INFO_UNAVAILABLE) |
| return 0; |
| |
| /* If we already have the information there is nothing else to do. */ |
| if (num_debug_info_entries > 0) |
| return num_debug_info_entries; |
| |
| /* If this is a DWARF package file, load the CU and TU indexes. */ |
| load_cu_tu_indexes (file); |
| |
| if (load_debug_section (info, file) |
| && process_debug_info (&debug_displays [info].section, file, abbrev, 1, 0)) |
| return num_debug_info_entries; |
| |
| if (load_debug_section (info_dwo, file) |
| && process_debug_info (&debug_displays [info_dwo].section, file, |
| abbrev_dwo, 1, 0)) |
| return num_debug_info_entries; |
| |
| num_debug_info_entries = DEBUG_INFO_UNAVAILABLE; |
| return 0; |
| } |
| |
| /* Read a DWARF .debug_line section header starting at DATA. |
| Upon success returns an updated DATA pointer and the LINFO |
| structure and the END_OF_SEQUENCE pointer will be filled in. |
| Otherwise returns NULL. */ |
| |
| static unsigned char * |
| read_debug_line_header (struct dwarf_section * section, |
| unsigned char * data, |
| unsigned char * end, |
| DWARF2_Internal_LineInfo * linfo, |
| unsigned char ** end_of_sequence) |
| { |
| unsigned char *hdrptr; |
| unsigned int offset_size; |
| unsigned int initial_length_size; |
| |
| /* Extract information from the Line Number Program Header. |
| (section 6.2.4 in the Dwarf3 doc). */ |
| hdrptr = data; |
| |
| /* Get and check the length of the block. */ |
| SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 4, end); |
| |
| if (linfo->li_length == 0xffffffff) |
| { |
| /* This section is 64-bit DWARF 3. */ |
| SAFE_BYTE_GET_AND_INC (linfo->li_length, hdrptr, 8, end); |
| offset_size = 8; |
| initial_length_size = 12; |
| } |
| else |
| { |
| offset_size = 4; |
| initial_length_size = 4; |
| } |
| |
| if (linfo->li_length + initial_length_size > section->size) |
| { |
| /* If the length field has a relocation against it, then we should |
| not complain if it is inaccurate (and probably negative). This |
| happens in object files when the .debug_line section is actually |
| comprised of several different .debug_line.* sections, (some of |
| which may be removed by linker garbage collection), and a relocation |
| is used to compute the correct length once that is done. */ |
| if (reloc_at (section, (hdrptr - section->start) - offset_size)) |
| { |
| linfo->li_length = (end - data) - initial_length_size; |
| } |
| else |
| { |
| warn (_("The length field (0x%lx) in the debug_line header is wrong - the section is too small\n"), |
| (long) linfo->li_length); |
| return NULL; |
| } |
| } |
| |
| /* Get and check the version number. */ |
| SAFE_BYTE_GET_AND_INC (linfo->li_version, hdrptr, 2, end); |
| |
| if (linfo->li_version != 2 |
| && linfo->li_version != 3 |
| && linfo->li_version != 4) |
| { |
| warn (_("Only DWARF version 2, 3 and 4 line info is currently supported.\n")); |
| return NULL; |
| } |
| |
| SAFE_BYTE_GET_AND_INC (linfo->li_prologue_length, hdrptr, offset_size, end); |
| SAFE_BYTE_GET_AND_INC (linfo->li_min_insn_length, hdrptr, 1, end); |
| |
| if (linfo->li_version >= 4) |
| { |
| SAFE_BYTE_GET_AND_INC (linfo->li_max_ops_per_insn, hdrptr, 1, end); |
| |
| if (linfo->li_max_ops_per_insn == 0) |
| { |
| warn (_("Invalid maximum operations per insn.\n")); |
| return NULL; |
| } |
| } |
| else |
| linfo->li_max_ops_per_insn = 1; |
| |
| SAFE_BYTE_GET_AND_INC (linfo->li_default_is_stmt, hdrptr, 1, end); |
| SAFE_SIGNED_BYTE_GET_AND_INC (linfo->li_line_base, hdrptr, 1, end); |
| SAFE_BYTE_GET_AND_INC (linfo->li_line_range, hdrptr, 1, end); |
| SAFE_BYTE_GET_AND_INC (linfo->li_opcode_base, hdrptr, 1, end); |
| |
| * end_of_sequence = data + linfo->li_length + initial_length_size; |
| /* PR 17512: file:002-117414-0.004. */ |
| if (* end_of_sequence > end) |
| { |
| warn (_("Line length %s extends beyond end of section\n"), |
| dwarf_vmatoa ("u", linfo->li_length)); |
| * end_of_sequence = end; |
| return NULL; |
| } |
| |
| return hdrptr; |
| } |
| |
| static int |
| display_debug_lines_raw (struct dwarf_section *section, |
| unsigned char *data, |
| unsigned char *end) |
| { |
| unsigned char *start = section->start; |
| |
| printf (_("Raw dump of debug contents of section %s:\n\n"), |
| section->name); |
| |
| while (data < end) |
| { |
| static DWARF2_Internal_LineInfo saved_linfo; |
| DWARF2_Internal_LineInfo linfo; |
| unsigned char *standard_opcodes; |
| unsigned char *end_of_sequence; |
| unsigned int last_dir_entry = 0; |
| int i; |
| |
| if (const_strneq (section->name, ".debug_line.") |
| /* Note: the following does not apply to .debug_line.dwo sections. |
| These are full debug_line sections. */ |
| && strcmp (section->name, ".debug_line.dwo") != 0) |
| { |
| /* Sections named .debug_line.<foo> are fragments of a .debug_line |
| section containing just the Line Number Statements. They are |
| created by the assembler and intended to be used alongside gcc's |
| -ffunction-sections command line option. When the linker's |
| garbage collection decides to discard a .text.<foo> section it |
| can then also discard the line number information in .debug_line.<foo>. |
| |
| Since the section is a fragment it does not have the details |
| needed to fill out a LineInfo structure, so instead we use the |
| details from the last full debug_line section that we processed. */ |
| end_of_sequence = end; |
| standard_opcodes = NULL; |
| linfo = saved_linfo; |
| /* PR 17531: file: 0522b371. */ |
| if (linfo.li_line_range == 0) |
| { |
| warn (_("Partial .debug_line. section encountered without a prior full .debug_line section\n")); |
| return 0; |
| } |
| reset_state_machine (linfo.li_default_is_stmt); |
| } |
| else |
| { |
| unsigned char * hdrptr; |
| |
| if ((hdrptr = read_debug_line_header (section, data, end, & linfo, |
| & end_of_sequence)) == NULL) |
| return 0; |
| |
| printf (_(" Offset: 0x%lx\n"), (long)(data - start)); |
| printf (_(" Length: %ld\n"), (long) linfo.li_length); |
| printf (_(" DWARF Version: %d\n"), linfo.li_version); |
| printf (_(" Prologue Length: %d\n"), (int) linfo.li_prologue_length); |
| printf (_(" Minimum Instruction Length: %d\n"), linfo.li_min_insn_length); |
| if (linfo.li_version >= 4) |
| printf (_(" Maximum Ops per Instruction: %d\n"), linfo.li_max_ops_per_insn); |
| printf (_(" Initial value of 'is_stmt': %d\n"), linfo.li_default_is_stmt); |
| printf (_(" Line Base: %d\n"), linfo.li_line_base); |
| printf (_(" Line Range: %d\n"), linfo.li_line_range); |
| printf (_(" Opcode Base: %d\n"), linfo.li_opcode_base); |
| |
| /* PR 17512: file: 1665-6428-0.004. */ |
| if (linfo.li_line_range == 0) |
| { |
| warn (_("Line range of 0 is invalid, using 1 instead\n")); |
| linfo.li_line_range = 1; |
| } |
| |
| reset_state_machine (linfo.li_default_is_stmt); |
| |
| /* Display the contents of the Opcodes table. */ |
| standard_opcodes = hdrptr; |
| |
| /* PR 17512: file: 002-417945-0.004. */ |
| if (standard_opcodes + linfo.li_opcode_base >= end) |
| { |
| warn (_("Line Base extends beyond end of section\n")); |
| return 0; |
| } |
| |
| printf (_("\n Opcodes:\n")); |
| |
| for (i = 1; i < linfo.li_opcode_base; i++) |
| printf (_(" Opcode %d has %d args\n"), i, standard_opcodes[i - 1]); |
| |
| /* Display the contents of the Directory table. */ |
| data = standard_opcodes + linfo.li_opcode_base - 1; |
| |
| if (*data == 0) |
| printf (_("\n The Directory Table is empty.\n")); |
| else |
| { |
| printf (_("\n The Directory Table (offset 0x%lx):\n"), |
| (long)(data - start)); |
| |
| while (data < end && *data != 0) |
| { |
| printf (" %d\t%.*s\n", ++last_dir_entry, (int) (end - data), data); |
| |
| data += strnlen ((char *) data, end - data) + 1; |
| } |
| |
| /* PR 17512: file: 002-132094-0.004. */ |
| if (data >= end - 1) |
| break; |
| } |
| |
| /* Skip the NUL at the end of the table. */ |
| data++; |
| |
| /* Display the contents of the File Name table. */ |
| if (*data == 0) |
| printf (_("\n The File Name Table is empty.\n")); |
| else |
| { |
| printf (_("\n The File Name Table (offset 0x%lx):\n"), |
| (long)(data - start)); |
| printf (_(" Entry\tDir\tTime\tSize\tName\n")); |
| |
| while (data < end && *data != 0) |
| { |
| unsigned char *name; |
| unsigned int bytes_read; |
| |
| printf (" %d\t", ++state_machine_regs.last_file_entry); |
| name = data; |
| data += strnlen ((char *) data, end - data) + 1; |
| |
| printf ("%s\t", |
| dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| data += bytes_read; |
| printf ("%s\t", |
| dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| data += bytes_read; |
| printf ("%s\t", |
| dwarf_vmatoa ("u", read_uleb128 (data, & bytes_read, end))); |
| data += bytes_read; |
| printf ("%.*s\n", (int)(end - name), name); |
| |
| if (data == end) |
| { |
| warn (_("Corrupt file name table entry\n")); |
| break; |
| } |
| } |
| } |
| |
| /* Skip the NUL at the end of the table. */ |
| data++; |
| putchar ('\n'); |
| saved_linfo = linfo; |
| } |
| |
| /* Now display the statements. */ |
| if (data >= end_of_sequence) |
| printf (_(" No Line Number Statements.\n")); |
| else |
| { |
| printf (_(" Line Number Statements:\n")); |
| |
| while (data < end_of_sequence) |
| { |
| unsigned char op_code; |
| dwarf_signed_vma adv; |
| dwarf_vma uladv; |
| unsigned int bytes_read; |
| |
| printf (" [0x%08lx]", (long)(data - start)); |
| |
| op_code = *data++; |
| |
| if (op_code >= linfo.li_opcode_base) |
| { |
| op_code -= linfo.li_opcode_base; |
| uladv = (op_code / linfo.li_line_range); |
| if (linfo.li_max_ops_per_insn == 1) |
| { |
| uladv *= linfo.li_min_insn_length; |
| state_machine_regs.address += uladv; |
| printf (_(" Special opcode %d: " |
| "advance Address by %s to 0x%s"), |
| op_code, dwarf_vmatoa ("u", uladv), |
| dwarf_vmatoa ("x", state_machine_regs.address)); |
| } |
| else |
| { |
| state_machine_regs.address |
| += ((state_machine_regs.op_index + uladv) |
| / linfo.li_max_ops_per_insn) |
| * linfo.li_min_insn_length; |
| state_machine_regs.op_index |
| = (state_machine_regs.op_index + uladv) |
| % linfo.li_max_ops_per_insn; |
| printf (_(" Special opcode %d: " |
| "advance Address by %s to 0x%s[%d]"), |
| op_code, dwarf_vmatoa ("u", uladv), |
| dwarf_vmatoa ("x", state_machine_regs.address), |
| state_machine_regs.op_index); |
| } |
| adv = (op_code % linfo.li_line_range) + linfo.li_line_base; |
| state_machine_regs.line += adv; |
| printf (_(" and Line by %s to %d\n"), |
| dwarf_vmatoa ("d", adv), state_machine_regs.line); |
| } |
| else switch (op_code) |
| { |
| case DW_LNS_extended_op: |
| data += process_extended_line_op (data, linfo.li_default_is_stmt, end); |
| break; |
| |
| case DW_LNS_copy: |
| printf (_(" Copy\n")); |
| break; |
| |
| case DW_LNS_advance_pc: |
| uladv = read_uleb128 (data, & bytes_read, end); |
| data += bytes_read; |
| if (linfo.li_max_ops_per_insn == 1) |
| { |
| uladv *= linfo.li_min_insn_length; |
| state_machine_regs.address += uladv; |
| printf (_(" Advance PC by %s to 0x%s\n"), |
| dwarf_vmatoa ("u", uladv), |
| dwarf_vmatoa ("x", state_machine_regs.address)); |
| } |
| else |
| { |
| state_machine_regs.address |
| += ((state_machine_regs.op_index + uladv) |
| / linfo.li_max_ops_per_insn) |
| * linfo.li_min_insn_length; |
| state_machine_regs.op_index |
| = (state_machine_regs.op_index + uladv) |
| % linfo.li_max_ops_per_insn; |
| printf (_(" Advance PC by %s to 0x%s[%d]\n"), |
| dwarf_vmatoa ("u", uladv), |
| dwarf_vmatoa ("x", state_machine_regs.address), |
| state_machine_regs.op_index); |
| } |
| break; |
| |
| case DW_LNS_advance_line: |
| adv = read_sleb128 (data, & bytes_read, end); |
| data += bytes_read; |
| state_machine_regs.line += adv; |
| printf (_(" Advance Line by %s to %d\n"), |
| dwarf_vmatoa ("d", adv), |
| state_machine_regs.line); |
| break; |
|