| /* dwarf.c -- display DWARF contents of a BFD binary file |
| Copyright (C) 2005-2024 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 <stdint.h> |
| #include "bucomm.h" |
| #include "elfcomm.h" |
| #include "elf/common.h" |
| #include "dwarf2.h" |
| #include "dwarf.h" |
| #include "gdb/gdb-index.h" |
| #include "filenames.h" |
| #include "safe-ctype.h" |
| #include <assert.h> |
| |
| #ifdef HAVE_LIBDEBUGINFOD |
| #include <elfutils/debuginfod.h> |
| #endif |
| |
| #include <limits.h> |
| #ifndef CHAR_BIT |
| #define CHAR_BIT 8 |
| #endif |
| |
| #ifndef ENABLE_CHECKING |
| #define ENABLE_CHECKING 0 |
| #endif |
| |
| #undef MAX |
| #undef MIN |
| #define MAX(a, b) ((a) > (b) ? (a) : (b)) |
| #define MIN(a, b) ((a) < (b) ? (a) : (b)) |
| |
| static const char *regname (unsigned int regno, int row); |
| static const char *regname_internal_by_table_only (unsigned int regno); |
| |
| static int have_frame_base; |
| static int frame_base_level = -1; /* To support nested DW_TAG_subprogram's. */ |
| static int need_base_address; |
| |
| 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 |
| |
| /* A .debug_info section can contain multiple links to separate |
| DWO object files. We use these structures to record these links. */ |
| typedef enum dwo_type |
| { |
| DWO_NAME, |
| DWO_DIR, |
| DWO_ID |
| } dwo_type; |
| |
| typedef struct dwo_info |
| { |
| dwo_type type; |
| const char * value; |
| uint64_t cu_offset; |
| struct dwo_info * next; |
| } dwo_info; |
| |
| static dwo_info *first_dwo_info = NULL; |
| static bool need_dwo_info; |
| |
| separate_info * first_separate_info = NULL; |
| |
| 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_str_offsets; |
| 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 do_debug_links; |
| int do_follow_links = DEFAULT_FOR_FOLLOW_LINKS; |
| #ifdef HAVE_LIBDEBUGINFOD |
| int use_debuginfod = 1; |
| #endif |
| bool do_checks; |
| |
| 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 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; |
| uint64_t 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 bool load_cu_tu_indexes (void *); |
| |
| /* An array that indicates for a given level of CU nesting whether |
| the latest DW_AT_type seen for that level was a signed type or |
| an unsigned type. */ |
| #define MAX_CU_NESTING (1 << 8) |
| static bool level_type_signed[MAX_CU_NESTING]; |
| |
| /* 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 uint64_t |
| 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); |
| uint64_t val; |
| |
| if (data >= end || size > (size_t) (end - data)) |
| { |
| 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; |
| } |
| |
| /* Print a uint64_t value (typically an address, offset or length) in |
| hexadecimal format, followed by a space. The precision displayed is |
| determined by the NUM_BYTES parameter. */ |
| |
| static void |
| print_hex (uint64_t value, unsigned num_bytes) |
| { |
| if (num_bytes == 0) |
| num_bytes = 2; |
| |
| printf ("%0*" PRIx64 " ", num_bytes * 2, |
| value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); |
| } |
| |
| /* Like print_hex, but no trailing space. */ |
| |
| static void |
| print_hex_ns (uint64_t value, unsigned num_bytes) |
| { |
| if (num_bytes == 0) |
| num_bytes = 2; |
| |
| printf ("%0*" PRIx64, num_bytes * 2, |
| value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); |
| } |
| |
| /* Print a view number in hexadecimal value, with the same width as |
| print_hex would have printed it. */ |
| |
| static void |
| print_view (uint64_t value, unsigned num_bytes) |
| { |
| if (num_bytes == 0) |
| num_bytes = 2; |
| |
| printf ("v%0*" PRIx64 " ", num_bytes * 2 - 1, |
| value & ~(~(uint64_t) 0 << num_bytes * 4 << num_bytes * 4)); |
| } |
| |
| static const char * |
| null_name (const char *p) |
| { |
| if (p == NULL) |
| p = _("unknown"); |
| return p; |
| } |
| |
| /* 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. |
| If STATUS_RETURN is not NULL, return with bit 0 (LSB) set if the |
| terminating byte was not found and with bit 1 set if the value |
| overflows a uint64_t. |
| No bytes will be read at address END or beyond. */ |
| |
| uint64_t |
| read_leb128 (unsigned char *data, |
| const unsigned char *const end, |
| bool sign, |
| unsigned int *length_return, |
| int *status_return) |
| { |
| uint64_t result = 0; |
| unsigned int num_read = 0; |
| unsigned int shift = 0; |
| int status = 1; |
| |
| while (data < end) |
| { |
| unsigned char byte = *data++; |
| unsigned char lost, mask; |
| |
| num_read++; |
| |
| if (shift < CHAR_BIT * sizeof (result)) |
| { |
| result |= ((uint64_t) (byte & 0x7f)) << shift; |
| /* These bits overflowed. */ |
| lost = byte ^ (result >> shift); |
| /* And this is the mask of possible overflow bits. */ |
| mask = 0x7f ^ ((uint64_t) 0x7f << shift >> shift); |
| shift += 7; |
| } |
| else |
| { |
| lost = byte; |
| mask = 0x7f; |
| } |
| if ((lost & mask) != (sign && (int64_t) result < 0 ? mask : 0)) |
| status |= 2; |
| |
| if ((byte & 0x80) == 0) |
| { |
| status &= ~1; |
| if (sign && shift < CHAR_BIT * sizeof (result) && (byte & 0x40)) |
| result |= -((uint64_t) 1 << shift); |
| break; |
| } |
| } |
| |
| if (length_return != NULL) |
| *length_return = num_read; |
| if (status_return != NULL) |
| *status_return = status; |
| |
| return result; |
| } |
| |
| /* Read AMOUNT bytes from PTR and store them in VAL. |
| Checks to make sure that the read will not reach or pass END. |
| FUNC chooses whether the value read is unsigned or signed, and may |
| be either byte_get or byte_get_signed. If INC is true, PTR is |
| incremented after reading the value. |
| This macro cannot protect against PTR values derived from user input. |
| The C standard sections 6.5.6 and 6.5.8 say attempts to do so using |
| pointers is undefined behaviour. */ |
| #define SAFE_BYTE_GET_INTERNAL(VAL, PTR, AMOUNT, END, FUNC, INC) \ |
| do \ |
| { \ |
| size_t amount = (AMOUNT); \ |
| if (sizeof (VAL) < amount) \ |
| { \ |
| error (ngettext ("internal error: attempt to read %d byte " \ |
| "of data in to %d sized variable", \ |
| "internal error: attempt to read %d bytes " \ |
| "of data in to %d sized variable", \ |
| amount), \ |
| (int) amount, (int) sizeof (VAL)); \ |
| amount = sizeof (VAL); \ |
| } \ |
| if (ENABLE_CHECKING) \ |
| assert ((PTR) <= (END)); \ |
| size_t avail = (END) - (PTR); \ |
| if ((PTR) > (END)) \ |
| avail = 0; \ |
| if (amount > avail) \ |
| amount = avail; \ |
| if (amount == 0) \ |
| (VAL) = 0; \ |
| else \ |
| (VAL) = (FUNC) ((PTR), amount); \ |
| if (INC) \ |
| (PTR) += amount; \ |
| } \ |
| while (0) |
| |
| #define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
| SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, false) |
| |
| #define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
| SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get, true) |
| |
| #define SAFE_SIGNED_BYTE_GET(VAL, PTR, AMOUNT, END) \ |
| SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, false) |
| |
| #define SAFE_SIGNED_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \ |
| SAFE_BYTE_GET_INTERNAL (VAL, PTR, AMOUNT, END, byte_get_signed, true) |
| |
| typedef struct State_Machine_Registers |
| { |
| uint64_t address; |
| unsigned int view; |
| 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.view = 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 size_t |
| process_extended_line_op (unsigned char * data, |
| int is_stmt, |
| unsigned char * end) |
| { |
| unsigned char op_code; |
| size_t len, header_len; |
| unsigned char *name; |
| unsigned char *orig_data = data; |
| uint64_t adr, val; |
| |
| READ_ULEB (len, data, end); |
| header_len = data - orig_data; |
| |
| if (len == 0 || data >= end || len > (size_t) (end - data)) |
| { |
| warn (_("Badly formed extended line op encountered!\n")); |
| return header_len; |
| } |
| |
| 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 - 1 > 8) |
| { |
| warn (_("Length (%zu) of DW_LNE_set_address op is too long\n"), |
| len - 1); |
| adr = 0; |
| } |
| else |
| SAFE_BYTE_GET (adr, data, len - 1, end); |
| printf (_("set Address to %#" PRIx64 "\n"), adr); |
| state_machine_regs.address = adr; |
| state_machine_regs.view = 0; |
| 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); |
| |
| { |
| size_t l; |
| |
| name = data; |
| l = strnlen ((char *) data, end - data); |
| data += l; |
| if (data < end) |
| data++; |
| READ_ULEB (val, data, end); |
| printf ("%" PRIu64 "\t", val); |
| READ_ULEB (val, data, end); |
| printf ("%" PRIu64 "\t", val); |
| READ_ULEB (val, data, end); |
| printf ("%" PRIu64 "\t", val); |
| printf ("%.*s\n\n", (int) l, name); |
| } |
| |
| if (((size_t) (data - orig_data) != len + header_len) || data >= end) |
| warn (_("DW_LNE_define_file: Bad opcode length\n")); |
| break; |
| |
| case DW_LNE_set_discriminator: |
| READ_ULEB (val, data, end); |
| printf (_("set Discriminator to %" PRIu64 "\n"), val); |
| 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 - 1; |
| |
| printf ("DW_LNE_HP_source_file_correlation\n"); |
| |
| while (data < edata) |
| { |
| unsigned int opc; |
| |
| READ_ULEB (opc, data, edata); |
| |
| switch (opc) |
| { |
| case DW_LNE_HP_SFC_formfeed: |
| printf (" DW_LNE_HP_SFC_formfeed\n"); |
| break; |
| case DW_LNE_HP_SFC_set_listing_line: |
| READ_ULEB (val, data, edata); |
| printf (" DW_LNE_HP_SFC_set_listing_line (%" PRIu64 ")\n", |
| val); |
| break; |
| case DW_LNE_HP_SFC_associate: |
| printf (" DW_LNE_HP_SFC_associate "); |
| READ_ULEB (val, data, edata); |
| printf ("(%" PRIu64 , val); |
| READ_ULEB (val, data, edata); |
| printf (",%" PRIu64, val); |
| READ_ULEB (val, data, edata); |
| printf (",%" PRIu64 ")\n", val); |
| break; |
| default: |
| printf (_(" UNKNOWN DW_LNE_HP_SFC opcode (%u)\n"), opc); |
| data = edata; |
| break; |
| } |
| } |
| } |
| break; |
| |
| default: |
| { |
| unsigned int rlen = len - 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 + header_len; |
| } |
| |
| static const unsigned char * |
| fetch_indirect_string (uint64_t offset) |
| { |
| struct dwarf_section *section = &debug_displays [str].section; |
| const unsigned char * ret; |
| |
| if (section->start == NULL) |
| return (const unsigned char *) _("<no .debug_str section>"); |
| |
| if (offset >= section->size) |
| { |
| warn (_("DW_FORM_strp offset too big: %#" PRIx64 "\n"), offset); |
| return (const unsigned char *) _("<offset is too big>"); |
| } |
| |
| ret = section->start + offset; |
| /* Unfortunately we cannot rely upon the .debug_str section ending with a |
| NUL byte. Since our caller is expecting to receive a well formed C |
| string we test for the lack of a terminating byte here. */ |
| if (strnlen ((const char *) ret, section->size - offset) |
| == section->size - offset) |
| ret = (const unsigned char *) |
| _("<no NUL byte at end of .debug_str section>"); |
| |
| return ret; |
| } |
| |
| static const unsigned char * |
| fetch_indirect_line_string (uint64_t offset) |
| { |
| struct dwarf_section *section = &debug_displays [line_str].section; |
| const unsigned char * ret; |
| |
| if (section->start == NULL) |
| return (const unsigned char *) _("<no .debug_line_str section>"); |
| |
| if (offset >= section->size) |
| { |
| warn (_("DW_FORM_line_strp offset too big: %#" PRIx64 "\n"), offset); |
| return (const unsigned char *) _("<offset is too big>"); |
| } |
| |
| ret = section->start + offset; |
| /* Unfortunately we cannot rely upon the .debug_line_str section ending |
| with a NUL byte. Since our caller is expecting to receive a well formed |
| C string we test for the lack of a terminating byte here. */ |
| if (strnlen ((const char *) ret, section->size - offset) |
| == section->size - offset) |
| ret = (const unsigned char *) |
| _("<no NUL byte at end of .debug_line_str section>"); |
| |
| return ret; |
| } |
| |
| static const char * |
| fetch_indexed_string (uint64_t idx, |
| struct cu_tu_set *this_set, |
| uint64_t offset_size, |
| bool dwo, |
| uint64_t str_offsets_base) |
| { |
| 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; |
| uint64_t index_offset; |
| uint64_t str_offset; |
| const char * ret; |
| |
| if (index_section->start == NULL) |
| return (dwo ? _("<no .debug_str_offsets.dwo section>") |
| : _("<no .debug_str_offsets section>")); |
| |
| if (str_section->start == NULL) |
| return (dwo ? _("<no .debug_str.dwo section>") |
| : _("<no .debug_str section>")); |
| |
| if (_mul_overflow (idx, offset_size, &index_offset) |
| || (this_set != NULL |
| && ((index_offset += this_set->section_offsets [DW_SECT_STR_OFFSETS]) |
| < this_set->section_offsets [DW_SECT_STR_OFFSETS])) |
| || (index_offset += str_offsets_base) < str_offsets_base |
| || index_offset + offset_size < offset_size |
| || index_offset + offset_size > index_section->size) |
| { |
| warn (_("string index of %" PRIu64 " converts to an offset of %#" PRIx64 |
| " which is too big for section %s\n"), |
| idx, index_offset, str_section->name); |
| |
| return _("<string index too big>"); |
| } |
| |
| str_offset = byte_get (index_section->start + index_offset, offset_size); |
| |
| str_offset -= str_section->address; |
| if (str_offset >= str_section->size) |
| { |
| warn (_("indirect offset too big: %#" PRIx64 "\n"), str_offset); |
| return _("<indirect index offset is too big>"); |
| } |
| |
| ret = (const char *) str_section->start + str_offset; |
| |
| /* Unfortunately we cannot rely upon str_section ending with a NUL byte. |
| Since our caller is expecting to receive a well formed C string we test |
| for the lack of a terminating byte here. */ |
| if (strnlen (ret, str_section->size - str_offset) |
| == str_section->size - str_offset) |
| return _("<no NUL byte at end of section>"); |
| |
| return ret; |
| } |
| |
| static uint64_t |
| fetch_indexed_addr (uint64_t offset, uint32_t num_bytes) |
| { |
| struct dwarf_section *section = &debug_displays [debug_addr].section; |
| |
| if (section->start == NULL) |
| { |
| warn (_("Cannot fetch indexed address: the .debug_addr section is missing\n")); |
| return 0; |
| } |
| |
| if (offset + num_bytes > section->size) |
| { |
| warn (_("Offset into section %s too big: %#" PRIx64 "\n"), |
| section->name, offset); |
| return 0; |
| } |
| |
| return byte_get (section->start + offset, num_bytes); |
| } |
| |
| /* This is for resolving DW_FORM_rnglistx and DW_FORM_loclistx. |
| |
| The memory layout is: base_address (taken from the CU's top DIE) points at a table of offsets, |
| relative to the section start. |
| The table of offsets contains the offsets of objects of interest relative to the table of offsets. |
| IDX is the index of the desired object in said table of offsets. |
| |
| This returns the offset of the desired object relative to the section start or -1 upon failure. */ |
| |
| static uint64_t |
| fetch_indexed_offset (uint64_t idx, |
| enum dwarf_section_display_enum sec_enum, |
| uint64_t base_address, |
| uint64_t offset_size) |
| { |
| uint64_t offset_of_offset = base_address + idx * offset_size; |
| struct dwarf_section *section = &debug_displays [sec_enum].section; |
| |
| if (section->start == NULL) |
| { |
| warn (_("Unable to locate %s section\n"), section->uncompressed_name); |
| return -1; |
| } |
| |
| if (section->size < 4) |
| { |
| warn (_("Section %s is too small to contain an value indexed from another section!\n"), |
| section->name); |
| return -1; |
| } |
| |
| if (offset_of_offset + offset_size >= section->size) |
| { |
| warn (_("Offset of %#" PRIx64 " is too big for section %s\n"), |
| offset_of_offset, section->name); |
| return -1; |
| } |
| |
| return base_address + byte_get (section->start + offset_of_offset, offset_size); |
| } |
| |
| /* FIXME: There are better and more efficient ways to handle |
| these structures. For now though, I just want something that |
| is simple to implement. */ |
| /* Records a single attribute in an abbrev. */ |
| typedef struct abbrev_attr |
| { |
| unsigned long attribute; |
| unsigned long form; |
| int64_t implicit_const; |
| struct abbrev_attr *next; |
| } |
| abbrev_attr; |
| |
| /* Records a single abbrev. */ |
| typedef struct abbrev_entry |
| { |
| unsigned long number; |
| unsigned long tag; |
| int children; |
| struct abbrev_attr * first_attr; |
| struct abbrev_attr * last_attr; |
| struct abbrev_entry * next; |
| } |
| abbrev_entry; |
| |
| /* Records a set of abbreviations. */ |
| typedef struct abbrev_list |
| { |
| abbrev_entry * first_abbrev; |
| abbrev_entry * last_abbrev; |
| unsigned char * raw; |
| struct abbrev_list * next; |
| unsigned char * start_of_next_abbrevs; |
| } |
| abbrev_list; |
| |
| /* Records all the abbrevs found so far. */ |
| static struct abbrev_list * abbrev_lists = NULL; |
| |
| typedef struct abbrev_map |
| { |
| uint64_t start; |
| uint64_t end; |
| abbrev_list *list; |
| } abbrev_map; |
| |
| /* Maps between CU offsets and abbrev sets. */ |
| static abbrev_map * cu_abbrev_map = NULL; |
| static unsigned long num_abbrev_map_entries = 0; |
| static unsigned long next_free_abbrev_map_entry = 0; |
| |
| #define INITIAL_NUM_ABBREV_MAP_ENTRIES 8 |
| #define ABBREV_MAP_ENTRIES_INCREMENT 8 |
| |
| static void |
| record_abbrev_list_for_cu (uint64_t start, uint64_t end, |
| abbrev_list *list, abbrev_list *free_list) |
| { |
| if (free_list != NULL) |
| { |
| list->next = abbrev_lists; |
| abbrev_lists = list; |
| } |
| |
| if (cu_abbrev_map == NULL) |
| { |
| num_abbrev_map_entries = INITIAL_NUM_ABBREV_MAP_ENTRIES; |
| cu_abbrev_map = xmalloc (num_abbrev_map_entries * sizeof (* cu_abbrev_map)); |
| } |
| else if (next_free_abbrev_map_entry == num_abbrev_map_entries) |
| { |
| num_abbrev_map_entries += ABBREV_MAP_ENTRIES_INCREMENT; |
| cu_abbrev_map = xrealloc (cu_abbrev_map, num_abbrev_map_entries * sizeof (* cu_abbrev_map)); |
| } |
| |
| cu_abbrev_map[next_free_abbrev_map_entry].start = start; |
| cu_abbrev_map[next_free_abbrev_map_entry].end = end; |
| cu_abbrev_map[next_free_abbrev_map_entry].list = list; |
| next_free_abbrev_map_entry ++; |
| } |
| |
| static abbrev_list * |
| free_abbrev_list (abbrev_list *list) |
| { |
| abbrev_entry *abbrv = list->first_abbrev; |
| |
| while (abbrv) |
| { |
| abbrev_attr *attr = abbrv->first_attr; |
| |
| while (attr) |
| { |
| abbrev_attr *next_attr = attr->next; |
| free (attr); |
| attr = next_attr; |
| } |
| |
| abbrev_entry *next_abbrev = abbrv->next; |
| free (abbrv); |
| abbrv = next_abbrev; |
| } |
| |
| abbrev_list *next = list->next; |
| free (list); |
| return next; |
| } |
| |
| static void |
| free_all_abbrevs (void) |
| { |
| while (abbrev_lists) |
| abbrev_lists = free_abbrev_list (abbrev_lists); |
| |
| free (cu_abbrev_map); |
| cu_abbrev_map = NULL; |
| next_free_abbrev_map_entry = 0; |
| } |
| |
| static abbrev_list * |
| find_abbrev_list_by_raw_abbrev (unsigned char *raw) |
| { |
| abbrev_list * list; |
| |
| for (list = abbrev_lists; list != NULL; list = list->next) |
| if (list->raw == raw) |
| return list; |
| |
| return NULL; |
| } |
| |
| /* Find the abbreviation map for the CU that includes OFFSET. |
| OFFSET is an absolute offset from the start of the .debug_info section. */ |
| /* FIXME: This function is going to slow down readelf & objdump. |
| Not caching abbrevs is likely the answer. */ |
| |
| static abbrev_map * |
| find_abbrev_map_by_offset (uint64_t offset) |
| { |
| unsigned long i; |
| |
| for (i = 0; i < next_free_abbrev_map_entry; i++) |
| if (cu_abbrev_map[i].start <= offset |
| && cu_abbrev_map[i].end > offset) |
| return cu_abbrev_map + i; |
| |
| return NULL; |
| } |
| |
| static void |
| add_abbrev (unsigned long number, |
| unsigned long tag, |
| int children, |
| abbrev_list * list) |
| { |
| abbrev_entry * entry; |
| |
| entry = (abbrev_entry *) xmalloc (sizeof (*entry)); |
| |
| entry->number = number; |
| entry->tag = tag; |
| entry->children = children; |
| entry->first_attr = NULL; |
| entry->last_attr = NULL; |
| entry->next = NULL; |
| |
| assert (list != NULL); |
| |
| if (list->first_abbrev == NULL) |
| list->first_abbrev = entry; |
| else |
| list->last_abbrev->next = entry; |
| |
| list->last_abbrev = entry; |
| } |
| |
| static void |
| add_abbrev_attr (unsigned long attribute, |
| unsigned long form, |
| int64_t implicit_const, |
| abbrev_list *list) |
| { |
| abbrev_attr *attr; |
| |
| attr = (abbrev_attr *) xmalloc (sizeof (*attr)); |
| |
| attr->attribute = attribute; |
| attr->form = form; |
| attr->implicit_const = implicit_const; |
| attr->next = NULL; |
| |
| assert (list != NULL && list->last_abbrev != NULL); |
| |
| if (list->last_abbrev->first_attr == NULL) |
| list->last_abbrev->first_attr = attr; |
| else |
| list->last_abbrev->last_attr->next = attr; |
| |
| list->last_abbrev->last_attr = attr; |
| } |
| |
| /* Return processed (partial) contents of a .debug_abbrev section. |
| Returns NULL on errors. */ |
| |
| static abbrev_list * |
| process_abbrev_set (struct dwarf_section *section, |
| unsigned char *start, |
| unsigned char *end) |
| { |
| abbrev_list *list = xmalloc (sizeof (*list)); |
| list->first_abbrev = NULL; |
| list->last_abbrev = NULL; |
| list->raw = start; |
| list->next = NULL; |
| |
| while (start < end) |
| { |
| unsigned long entry; |
| unsigned long tag; |
| unsigned long attribute; |
| int children; |
| |
| READ_ULEB (entry, start, end); |
| |
| /* A single zero is supposed to end the set according |
| to the standard. If there's more, then signal that to |
| the caller. */ |
| if (start == end || entry == 0) |
| { |
| list->start_of_next_abbrevs = start != end ? start : NULL; |
| return list; |
| } |
| |
| READ_ULEB (tag, start, end); |
| if (start == end) |
| return free_abbrev_list (list); |
| |
| children = *start++; |
| |
| add_abbrev (entry, tag, children, list); |
| |
| do |
| { |
| unsigned long form; |
| /* Initialize it due to a false compiler warning. */ |
| int64_t implicit_const = -1; |
| |
| READ_ULEB (attribute, start, end); |
| if (start == end) |
| break; |
| |
| READ_ULEB (form, start, end); |
| if (start == end) |
| break; |
| |
| if (form == DW_FORM_implicit_const) |
| { |
| READ_SLEB (implicit_const, start, end); |
| if (start == end) |
| break; |
| } |
| |
| add_abbrev_attr (attribute, form, implicit_const, list); |
| } |
| while (attribute != 0); |
| } |
| |
| /* Report the missing single zero which ends the section. */ |
| error (_("%s section not zero terminated\n"), section->name); |
| |
| return free_abbrev_list (list); |
| } |
| |
| /* Return a sequence of abbrevs in SECTION starting at ABBREV_BASE |
| plus ABBREV_OFFSET and finishing at ABBREV_BASE + ABBREV_SIZE. |
| If FREE_LIST is non-NULL search the already decoded abbrevs on |
| abbrev_lists first and if found set *FREE_LIST to NULL. If |
| searching doesn't find a matching abbrev, set *FREE_LIST to the |
| newly allocated list. If FREE_LIST is NULL, no search is done and |
| the returned abbrev_list is always newly allocated. */ |
| |
| static abbrev_list * |
| find_and_process_abbrev_set (struct dwarf_section *section, |
| uint64_t abbrev_base, |
| uint64_t abbrev_size, |
| uint64_t abbrev_offset, |
| abbrev_list **free_list) |
| { |
| if (free_list) |
| *free_list = NULL; |
| |
| if (abbrev_base >= section->size |
| || abbrev_size > section->size - abbrev_base) |
| { |
| /* PR 17531: file:4bcd9ce9. */ |
| warn (_("Debug info is corrupted, abbrev size (%#" PRIx64 ")" |
| " is larger than abbrev section size (%#" PRIx64 ")\n"), |
| abbrev_base + abbrev_size, section->size); |
| return NULL; |
| } |
| if (abbrev_offset >= abbrev_size) |
| { |
| warn (_("Debug info is corrupted, abbrev offset (%#" PRIx64 ")" |
| " is larger than abbrev section size (%#" PRIx64 ")\n"), |
| abbrev_offset, abbrev_size); |
| return NULL; |
| } |
| |
| unsigned char *start = section->start + abbrev_base + abbrev_offset; |
| unsigned char *end = section->start + abbrev_base + abbrev_size; |
| abbrev_list *list = NULL; |
| if (free_list) |
| list = find_abbrev_list_by_raw_abbrev (start); |
| if (list == NULL) |
| { |
| list = process_abbrev_set (section, start, end); |
| if (free_list) |
| *free_list = list; |
| } |
| return list; |
| } |
| |
| static const char * |
| get_TAG_name (uint64_t tag) |
| { |
| const char *name = NULL; |
| |
| if ((unsigned int) tag == tag) |
| name = get_DW_TAG_name ((unsigned int) tag); |
| if (name == NULL) |
| { |
| static char buffer[100]; |
| |
| if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user) |
| snprintf (buffer, sizeof (buffer), |
| _("User TAG value: %#" PRIx64), tag); |
| else |
| snprintf (buffer, sizeof (buffer), |
| _("Unknown TAG value: %#" PRIx64), tag); |
| return buffer; |
| } |
| |
| return name; |
| } |
| |
| static const char * |
| get_FORM_name (unsigned long form) |
| { |
| const char *name = NULL; |
| |
| if (form == 0) |
| return "DW_FORM value: 0"; |
| |
| if ((unsigned int) form == form) |
| name = get_DW_FORM_name ((unsigned int) form); |
| if (name == NULL) |
| { |
| static char buffer[100]; |
| |
| snprintf (buffer, sizeof (buffer), _("Unknown FORM value: %lx"), form); |
| return buffer; |
| } |
| |
| return name; |
| } |
| |
| static const char * |
| get_IDX_name (unsigned long idx) |
| { |
| const char *name = NULL; |
| |
| if ((unsigned int) idx == idx) |
| name = get_DW_IDX_name ((unsigned int) idx); |
| if (name == NULL) |
| { |
| static char buffer[100]; |
| |
| snprintf (buffer, sizeof (buffer), _("Unknown IDX value: %lx"), idx); |
| return buffer; |
| } |
| |
| return name; |
| } |
| |
| static unsigned char * |
| display_block (unsigned char *data, |
| uint64_t length, |
| const unsigned char * const end, char delimiter) |
| { |
| size_t maxlen; |
| |
| printf (_("%c%" PRIu64 " byte block: "), delimiter, length); |
| if (data > end) |
| return (unsigned char *) end; |
| |
| maxlen = end - data; |
| length = length > maxlen ? maxlen : length; |
| |
| while (length --) |
| printf ("%" PRIx64 " ", 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, |
| uint64_t length, |
| uint64_t cu_offset, |
| struct dwarf_section * section) |
| { |
| unsigned op; |
| uint64_t uvalue; |
| int64_t 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: %" PRIx64, 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: %" PRIu64, uvalue); |
| break; |
| case DW_OP_const1s: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 1, end); |
| printf ("DW_OP_const1s: %" PRId64, svalue); |
| break; |
| case DW_OP_const2u: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
| printf ("DW_OP_const2u: %" PRIu64, uvalue); |
| break; |
| case DW_OP_const2s: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 2, end); |
| printf ("DW_OP_const2s: %" PRId64, svalue); |
| break; |
| case DW_OP_const4u: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| printf ("DW_OP_const4u: %" PRIu64, uvalue); |
| break; |
| case DW_OP_const4s: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 4, end); |
| printf ("DW_OP_const4s: %" PRId64, svalue); |
| break; |
| case DW_OP_const8u: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
| printf ("DW_OP_const8u: %" PRIu64, uvalue); |
| break; |
| case DW_OP_const8s: |
| SAFE_SIGNED_BYTE_GET_AND_INC (svalue, data, 8, end); |
| printf ("DW_OP_const8s: %" PRId64, svalue); |
| break; |
| case DW_OP_constu: |
| READ_ULEB (uvalue, data, end); |
| printf ("DW_OP_constu: %" PRIu64, uvalue); |
| break; |
| case DW_OP_consts: |
| READ_SLEB (svalue, data, end); |
| printf ("DW_OP_consts: %" PRId64, svalue); |
| 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: %" PRIu64, 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: |
| READ_ULEB (uvalue, data, end); |
| printf ("DW_OP_plus_uconst: %" PRIu64, uvalue); |
| 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: %" PRId64, 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: %" PRId64, 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: |
| READ_SLEB (svalue, data, end); |
| printf ("DW_OP_breg%d (%s): %" PRId64, |
| op - DW_OP_breg0, regname (op - DW_OP_breg0, 1), svalue); |
| break; |
| |
| case DW_OP_regx: |
| READ_ULEB (uvalue, data, end); |
| printf ("DW_OP_regx: %" PRIu64 " (%s)", |
| uvalue, regname (uvalue, 1)); |
| break; |
| case DW_OP_fbreg: |
| need_frame_base = 1; |
| READ_SLEB (svalue, data, end); |
| printf ("DW_OP_fbreg: %" PRId64, svalue); |
| break; |
| case DW_OP_bregx: |
| READ_ULEB (uvalue, data, end); |
| READ_SLEB (svalue, data, end); |
| printf ("DW_OP_bregx: %" PRIu64 " (%s) %" PRId64, |
| uvalue, regname (uvalue, 1), svalue); |
| break; |
| case DW_OP_piece: |
| READ_ULEB (uvalue, data, end); |
| printf ("DW_OP_piece: %" PRIu64, uvalue); |
| break; |
| case DW_OP_deref_size: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| printf ("DW_OP_deref_size: %" PRIu64, uvalue); |
| break; |
| case DW_OP_xderef_size: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| printf ("DW_OP_xderef_size: %" PRIu64, 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: |
| /* FIXME: 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: <%#" PRIx64 ">", svalue + cu_offset); |
| break; |
| case DW_OP_call4: |
| /* FIXME: 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: <%#" PRIx64 ">", svalue + cu_offset); |
| break; |
| case DW_OP_call_ref: |
| /* FIXME: 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: <%#" PRIx64 ">", 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: "); |
| READ_ULEB (uvalue, data, end); |
| printf (_("size: %" PRIu64 " "), uvalue); |
| READ_ULEB (uvalue, data, end); |
| printf (_("offset: %" PRIu64 " "), uvalue); |
| 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"); |
| READ_ULEB (uvalue, data, end); |
| 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; |
| uint64_t 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_hex_ns (addr, pointer_size); |
| } |
| break; |
| case DW_OP_implicit_pointer: |
| case DW_OP_GNU_implicit_pointer: |
| /* FIXME: Strictly speaking for 64-bit DWARF3 files |
| this ought to be an 8-byte wide computation. */ |
| if (dwarf_version == -1) |
| { |
| printf (_("(%s in frame info)"), |
| (op == DW_OP_implicit_pointer |
| ? "DW_OP_implicit_pointer" |
| : "DW_OP_GNU_implicit_pointer")); |
| /* 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); |
| } |
| READ_SLEB (svalue, data, end); |
| printf ("%s: <%#" PRIx64 "> %" PRId64, |
| (op == DW_OP_implicit_pointer |
| ? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"), |
| uvalue, svalue); |
| break; |
| case DW_OP_entry_value: |
| case DW_OP_GNU_entry_value: |
| READ_ULEB (uvalue, data, end); |
| /* PR 17531: file: 0cc9cd00. */ |
| if (uvalue > (size_t) (end - data)) |
| uvalue = end - data; |
| printf ("%s: (", (op == DW_OP_entry_value ? "DW_OP_entry_value" |
| : "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; |
| break; |
| case DW_OP_const_type: |
| case DW_OP_GNU_const_type: |
| READ_ULEB (uvalue, data, end); |
| printf ("%s: <%#" PRIx64 "> ", |
| (op == DW_OP_const_type ? "DW_OP_const_type" |
| : "DW_OP_GNU_const_type"), |
| cu_offset + uvalue); |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| data = display_block (data, uvalue, end, ' '); |
| break; |
| case DW_OP_regval_type: |
| case DW_OP_GNU_regval_type: |
| READ_ULEB (uvalue, data, end); |
| printf ("%s: %" PRIu64 " (%s)", |
| (op == DW_OP_regval_type ? "DW_OP_regval_type" |
| : "DW_OP_GNU_regval_type"), |
| uvalue, regname (uvalue, 1)); |
| READ_ULEB (uvalue, data, end); |
| printf (" <%#" PRIx64 ">", cu_offset + uvalue); |
| break; |
| case DW_OP_deref_type: |
| case DW_OP_GNU_deref_type: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| printf ("%s: %" PRId64, |
| (op == DW_OP_deref_type ? "DW_OP_deref_type" |
| : "DW_OP_GNU_deref_type"), |
| uvalue); |
| READ_ULEB (uvalue, data, end); |
| printf (" <%#" PRIx64 ">", cu_offset + uvalue); |
| break; |
| case DW_OP_convert: |
| case DW_OP_GNU_convert: |
| READ_ULEB (uvalue, data, end); |
| printf ("%s <%#" PRIx64 ">", |
| (op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"), |
| uvalue ? cu_offset + uvalue : uvalue); |
| break; |
| case DW_OP_reinterpret: |
| case DW_OP_GNU_reinterpret: |
| READ_ULEB (uvalue, data, end); |
| printf ("%s <%#" PRIx64 ">", |
| (op == DW_OP_reinterpret ? "DW_OP_reinterpret" |
| : "DW_OP_GNU_reinterpret"), |
| uvalue ? cu_offset + uvalue : uvalue); |
| break; |
| case DW_OP_GNU_parameter_ref: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| printf ("DW_OP_GNU_parameter_ref: <%#" PRIx64 ">", |
| cu_offset + uvalue); |
| break; |
| case DW_OP_addrx: |
| READ_ULEB (uvalue, data, end); |
| printf ("DW_OP_addrx <%#" PRIx64 ">", uvalue); |
| break; |
| case DW_OP_GNU_addr_index: |
| READ_ULEB (uvalue, data, end); |
| printf ("DW_OP_GNU_addr_index <%#" PRIx64 ">", uvalue); |
| break; |
| case DW_OP_GNU_const_index: |
| READ_ULEB (uvalue, data, end); |
| printf ("DW_OP_GNU_const_index <%#" PRIx64 ">", uvalue); |
| break; |
| case DW_OP_GNU_variable_value: |
| /* FIXME: Strictly speaking for 64-bit DWARF3 files |
| this ought to be an 8-byte wide computation. */ |
| if (dwarf_version == -1) |
| { |
| printf (_("(DW_OP_GNU_variable_value 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_variable_value: <%#" PRIx64 ">", 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 %#x)"), op); |
| else |
| printf (_("(Unknown location op %#x)"), 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 (uint64_t 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; |
| } |
| |
| static const char * |
| fetch_alt_indirect_string (uint64_t offset) |
| { |
| separate_info * i; |
| |
| if (! do_follow_links) |
| return ""; |
| |
| if (first_separate_info == NULL) |
| return _("<no links available>"); |
| |
| for (i = first_separate_info; i != NULL; i = i->next) |
| { |
| struct dwarf_section * section; |
| const char * ret; |
| |
| if (! load_debug_section (separate_debug_str, i->handle)) |
| continue; |
| |
| section = &debug_displays [separate_debug_str].section; |
| |
| if (section->start == NULL) |
| continue; |
| |
| if (offset >= section->size) |
| continue; |
| |
| ret = (const char *) (section->start + offset); |
| /* Unfortunately we cannot rely upon the .debug_str section ending with a |
| NUL byte. Since our caller is expecting to receive a well formed C |
| string we test for the lack of a terminating byte here. */ |
| if (strnlen ((const char *) ret, section->size - offset) |
| == section->size - offset) |
| return _("<no NUL byte at end of alt .debug_str section>"); |
| |
| return ret; |
| } |
| |
| warn (_("DW_FORM_GNU_strp_alt offset (%#" PRIx64 ")" |
| " too big or no string sections available\n"), offset); |
| return _("<offset is too big>"); |
| } |
| |
| 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 void |
| add_dwo_info (const char * value, uint64_t cu_offset, dwo_type type) |
| { |
| dwo_info * dwinfo = xmalloc (sizeof * dwinfo); |
| |
| dwinfo->type = type; |
| dwinfo->value = value; |
| dwinfo->cu_offset = cu_offset; |
| dwinfo->next = first_dwo_info; |
| first_dwo_info = dwinfo; |
| } |
| |
| static void |
| add_dwo_name (const char * name, uint64_t cu_offset) |
| { |
| add_dwo_info (name, cu_offset, DWO_NAME); |
| } |
| |
| static void |
| add_dwo_dir (const char * dir, uint64_t cu_offset) |
| { |
| add_dwo_info (dir, cu_offset, DWO_DIR); |
| } |
| |
| static void |
| add_dwo_id (const char * id, uint64_t cu_offset) |
| { |
| add_dwo_info (id, cu_offset, DWO_ID); |
| } |
| |
| static void |
| free_dwo_info (void) |
| { |
| dwo_info * dwinfo; |
| dwo_info * next; |
| |
| for (dwinfo = first_dwo_info; dwinfo != NULL; dwinfo = next) |
| { |
| next = dwinfo->next; |
| free (dwinfo); |
| } |
| first_dwo_info = NULL; |
| } |
| |
| /* Ensure that START + UVALUE is less than END. |
| Return an adjusted UVALUE if necessary to ensure this relationship. */ |
| |
| static inline uint64_t |
| check_uvalue (const unsigned char *start, |
| uint64_t uvalue, |
| const unsigned char *end) |
| { |
| uint64_t max_uvalue = end - start; |
| |
| /* See PR 17512: file: 008-103549-0.001:0.1. |
| and PR 24829 for examples of where these tests are triggered. */ |
| if (uvalue > max_uvalue) |
| { |
| warn (_("Corrupt attribute block length: %#" PRIx64 "\n"), uvalue); |
| uvalue = max_uvalue; |
| } |
| |
| return uvalue; |
| } |
| |
| static unsigned char * |
| skip_attr_bytes (unsigned long form, |
| unsigned char *data, |
| unsigned char *end, |
| uint64_t pointer_size, |
| uint64_t offset_size, |
| int dwarf_version, |
| uint64_t *value_return) |
| { |
| int64_t svalue; |
| uint64_t uvalue = 0; |
| uint64_t inc = 0; |
| |
| * value_return = 0; |
| |
| switch (form) |
| { |
| case DW_FORM_ref_addr: |
| if (dwarf_version == 2) |
| SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| else if (dwarf_version > 2) |
| SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| else |
| return NULL; |
| break; |
| |
| case DW_FORM_addr: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| break; |
| |
| case DW_FORM_strp: |
| case DW_FORM_line_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: |
| case DW_FORM_strx1: |
| case DW_FORM_addrx1: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| break; |
| |
| case DW_FORM_strx3: |
| case DW_FORM_addrx3: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); |
| break; |
| |
| case DW_FORM_ref2: |
| case DW_FORM_data2: |
| case DW_FORM_strx2: |
| case DW_FORM_addrx2: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
| break; |
| |
| case DW_FORM_ref4: |
| case DW_FORM_data4: |
| case DW_FORM_strx4: |
| case DW_FORM_addrx4: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| break; |
| |
| case DW_FORM_sdata: |
| READ_SLEB (svalue, data, end); |
| uvalue = svalue; |
| break; |
| |
| case DW_FORM_ref_udata: |
| case DW_FORM_udata: |
| case DW_FORM_GNU_str_index: |
| case DW_FORM_strx: |
| case DW_FORM_GNU_addr_index: |
| case DW_FORM_addrx: |
| case DW_FORM_loclistx: |
| case DW_FORM_rnglistx: |
| READ_ULEB (uvalue, data, end); |
| break; |
| |
| case DW_FORM_ref8: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
| break; |
| |
| case DW_FORM_data8: |
| case DW_FORM_ref_sig8: |
| inc = 8; |
| break; |
| |
| case DW_FORM_data16: |
| inc = 16; |
| break; |
| |
| case DW_FORM_string: |
| inc = strnlen ((char *) data, end - data) + 1; |
| break; |
| |
| case DW_FORM_block: |
| case DW_FORM_exprloc: |
| READ_ULEB (uvalue, data, end); |
| inc = uvalue; |
| break; |
| |
| case DW_FORM_block1: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| inc = uvalue; |
| break; |
| |
| case DW_FORM_block2: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
| inc = uvalue; |
| break; |
| |
| case DW_FORM_block4: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| inc = uvalue; |
| break; |
| |
| case DW_FORM_indirect: |
| READ_ULEB (form, data, end); |
| if (form == DW_FORM_implicit_const) |
| SKIP_ULEB (data, end); |
| return skip_attr_bytes (form, data, end, pointer_size, offset_size, |
| dwarf_version, value_return); |
| |
| default: |
| return NULL; |
| } |
| |
| * value_return = uvalue; |
| if (inc <= (size_t) (end - data)) |
| data += inc; |
| else |
| data = end; |
| return data; |
| } |
| |
| /* Given form FORM with value UVALUE, locate and return the abbreviation |
| associated with it. */ |
| |
| static abbrev_entry * |
| get_type_abbrev_from_form (unsigned long form, |
| uint64_t uvalue, |
| uint64_t cu_offset, |
| unsigned char *cu_end, |
| const struct dwarf_section *section, |
| unsigned long *abbrev_num_return, |
| unsigned char **data_return, |
| abbrev_map **map_return) |
| { |
| switch (form) |
| { |
| case DW_FORM_GNU_ref_alt: |
| case DW_FORM_ref_sig8: |
| /* FIXME: We are unable to handle this form at the moment. */ |
| return NULL; |
| |
| case DW_FORM_ref_addr: |
| if (uvalue >= section->size) |
| { |
| warn (_("Unable to resolve ref_addr form: uvalue %" PRIx64 |
| " >= section size %" PRIx64 " (%s)\n"), |
| uvalue, section->size, section->name); |
| return NULL; |
| } |
| break; |
| |
| case DW_FORM_ref_sup4: |
| case DW_FORM_ref_sup8: |
| break; |
| |
| case DW_FORM_ref1: |
| case DW_FORM_ref2: |
| case DW_FORM_ref4: |
| case DW_FORM_ref8: |
| case DW_FORM_ref_udata: |
| if (uvalue + cu_offset < uvalue |
| || uvalue + cu_offset > (size_t) (cu_end - section->start)) |
| { |
| warn (_("Unable to resolve ref form: uvalue %" PRIx64 |
| " + cu_offset %" PRIx64 " > CU size %tx\n"), |
| uvalue, cu_offset, cu_end - section->start); |
| return NULL; |
| } |
| uvalue += cu_offset; |
| break; |
| |
| /* FIXME: Are there other DW_FORMs that can be used by types ? */ |
| |
| default: |
| warn (_("Unexpected form %lx encountered whilst finding abbreviation for type\n"), form); |
| return NULL; |
| } |
| |
| abbrev_map *map = find_abbrev_map_by_offset (uvalue); |
| |
| if (map == NULL) |
| { |
| warn (_("Unable to find abbreviations for CU offset %" PRIx64 "\n"), |
| uvalue); |
| return NULL; |
| } |
| if (map->list == NULL) |
| { |
| warn (_("Empty abbreviation list encountered for CU offset %" PRIx64 "\n"), |
| uvalue); |
| return NULL; |
| } |
| |
| if (map_return != NULL) |
| { |
| if (form == DW_FORM_ref_addr) |
| *map_return = map; |
| else |
| *map_return = NULL; |
| } |
| |
| unsigned char *data = section->start + uvalue; |
| if (form == DW_FORM_ref_addr) |
| cu_end = section->start + map->end; |
| |
| unsigned long abbrev_number; |
| READ_ULEB (abbrev_number, data, cu_end); |
| |
| if (abbrev_num_return != NULL) |
| *abbrev_num_return = abbrev_number; |
| |
| if (data_return != NULL) |
| *data_return = data; |
| |
| abbrev_entry *entry; |
| for (entry = map->list->first_abbrev; entry != NULL; entry = entry->next) |
| if (entry->number == abbrev_number) |
| break; |
| |
| if (entry == NULL) |
| warn (_("Unable to find entry for abbreviation %lu\n"), abbrev_number); |
| |
| return entry; |
| } |
| |
| /* Return IS_SIGNED set to TRUE if the type using abbreviation ENTRY |
| can be determined to be a signed type. The data for ENTRY can be |
| found starting at DATA. */ |
| |
| static void |
| get_type_signedness (abbrev_entry *entry, |
| const struct dwarf_section *section, |
| unsigned char *data, |
| unsigned char *end, |
| uint64_t cu_offset, |
| uint64_t pointer_size, |
| uint64_t offset_size, |
| int dwarf_version, |
| bool *is_signed, |
| unsigned int nesting) |
| { |
| abbrev_attr * attr; |
| |
| * is_signed = false; |
| |
| #define MAX_NESTING 20 |
| if (nesting > MAX_NESTING) |
| { |
| /* FIXME: Warn - or is this expected ? |
| NB/ We need to avoid infinite recursion. */ |
| return; |
| } |
| |
| for (attr = entry->first_attr; |
| attr != NULL && attr->attribute; |
| attr = attr->next) |
| { |
| unsigned char * orig_data = data; |
| uint64_t uvalue = 0; |
| |
| data = skip_attr_bytes (attr->form, data, end, pointer_size, |
| offset_size, dwarf_version, & uvalue); |
| if (data == NULL) |
| return; |
| |
| switch (attr->attribute) |
| { |
| case DW_AT_linkage_name: |
| case DW_AT_name: |
| if (do_wide) |
| { |
| if (attr->form == DW_FORM_strp) |
| printf (", %s", fetch_indirect_string (uvalue)); |
| else if (attr->form == DW_FORM_string) |
| printf (", %.*s", (int) (end - orig_data), orig_data); |
| } |
| break; |
| |
| case DW_AT_type: |
| /* Recurse. */ |
| { |
| abbrev_entry *type_abbrev; |
| unsigned char *type_data; |
| abbrev_map *map; |
| |
| type_abbrev = get_type_abbrev_from_form (attr->form, |
| uvalue, |
| cu_offset, |
| end, |
| section, |
| NULL /* abbrev num return */, |
| &type_data, |
| &map); |
| if (type_abbrev == NULL) |
| break; |
| |
| get_type_signedness (type_abbrev, section, type_data, |
| map ? section->start + map->end : end, |
| map ? map->start : cu_offset, |
| pointer_size, offset_size, dwarf_version, |
| is_signed, nesting + 1); |
| } |
| break; |
| |
| case DW_AT_encoding: |
| /* Determine signness. */ |
| switch (uvalue) |
| { |
| case DW_ATE_address: |
| /* FIXME - some architectures have signed addresses. */ |
| case DW_ATE_boolean: |
| case DW_ATE_unsigned: |
| case DW_ATE_unsigned_char: |
| case DW_ATE_unsigned_fixed: |
| * is_signed = false; |
| break; |
| |
| default: |
| case DW_ATE_complex_float: |
| case DW_ATE_float: |
| case DW_ATE_signed: |
| case DW_ATE_signed_char: |
| case DW_ATE_imaginary_float: |
| case DW_ATE_decimal_float: |
| case DW_ATE_signed_fixed: |
| * is_signed = true; |
| break; |
| } |
| break; |
| } |
| } |
| } |
| |
| static void |
| read_and_print_leb128 (unsigned char *data, |
| unsigned int *bytes_read, |
| unsigned const char *end, |
| bool is_signed) |
| { |
| int status; |
| uint64_t val = read_leb128 (data, end, is_signed, bytes_read, &status); |
| if (status != 0) |
| report_leb_status (status); |
| else if (is_signed) |
| printf ("%" PRId64, val); |
| else |
| printf ("%" PRIu64, val); |
| } |
| |
| static void |
| display_discr_list (unsigned long form, |
| uint64_t uvalue, |
| unsigned char *data, |
| int level) |
| { |
| unsigned char *end = data; |
| |
| if (uvalue == 0) |
| { |
| printf ("[default]"); |
| return; |
| } |
| |
| switch (form) |
| { |
| case DW_FORM_block: |
| case DW_FORM_block1: |
| case DW_FORM_block2: |
| case DW_FORM_block4: |
| /* Move data pointer back to the start of the byte array. */ |
| data -= uvalue; |
| break; |
| default: |
| printf ("<corrupt>\n"); |
| warn (_("corrupt discr_list - not using a block form\n")); |
| return; |
| } |
| |
| if (uvalue < 2) |
| { |
| printf ("<corrupt>\n"); |
| warn (_("corrupt discr_list - block not long enough\n")); |
| return; |
| } |
| |
| bool is_signed = (level > 0 && level <= MAX_CU_NESTING |
| ? level_type_signed [level - 1] : false); |
| |
| printf ("("); |
| while (data < end) |
| { |
| unsigned char discriminant; |
| unsigned int bytes_read; |
| |
| SAFE_BYTE_GET_AND_INC (discriminant, data, 1, end); |
| |
| switch (discriminant) |
| { |
| case DW_DSC_label: |
| printf ("label "); |
| read_and_print_leb128 (data, & bytes_read, end, is_signed); |
| data += bytes_read; |
| break; |
| |
| case DW_DSC_range: |
| printf ("range "); |
| read_and_print_leb128 (data, & bytes_read, end, is_signed); |
| data += bytes_read; |
| |
| printf (".."); |
| read_and_print_leb128 (data, & bytes_read, end, is_signed); |
| data += bytes_read; |
| break; |
| |
| default: |
| printf ("<corrupt>\n"); |
| warn (_("corrupt discr_list - unrecognized discriminant byte %#x\n"), |
| discriminant); |
| return; |
| } |
| |
| if (data < end) |
| printf (", "); |
| } |
| |
| if (is_signed) |
| printf (")(signed)"); |
| else |
| printf (")(unsigned)"); |
| } |
| |
| static void |
| display_lang (uint64_t uvalue) |
| { |
| 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_OpenCL: printf ("OpenCL"); break; |
| case DW_LANG_Go: printf ("Go"); break; |
| case DW_LANG_Modula3: printf ("Modula 3"); break; |
| case DW_LANG_Haskell: printf ("Haskell"); break; |
| case DW_LANG_C_plus_plus_03: printf ("C++03"); break; |
| case DW_LANG_C_plus_plus_11: printf ("C++11"); break; |
| case DW_LANG_OCaml: printf ("OCaml"); break; |
| case DW_LANG_Rust: printf ("Rust"); break; |
| case DW_LANG_C11: printf ("C11"); break; |
| case DW_LANG_Swift: printf ("Swift"); break; |
| case DW_LANG_Julia: printf ("Julia"); break; |
| case DW_LANG_Dylan: printf ("Dylan"); 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; |
| case DW_LANG_RenderScript: printf ("RenderScript"); 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: %#" PRIx64 ""), uvalue); |
| else |
| printf (_("unknown: %#" PRIx64 ""), uvalue); |
| break; |
| } |
| } |
| |
| static unsigned char * |
| read_and_display_attr_value (unsigned long attribute, |
| unsigned long form, |
| int64_t implicit_const, |
| unsigned char *start, |
| unsigned char *data, |
| unsigned char *end, |
| uint64_t cu_offset, |
| uint64_t pointer_size, |
| uint64_t offset_size, |
| int dwarf_version, |
| debug_info *debug_info_p, |
| int do_loc, |
| struct dwarf_section *section, |
| struct cu_tu_set *this_set, |
| char delimiter, |
| int level) |
| { |
| int64_t svalue; |
| uint64_t uvalue = 0; |
| uint64_t uvalue_hi = 0; |
| unsigned char *block_start = NULL; |
| unsigned char *orig_data = data; |
| |
| if (data > end || (data == end && form != DW_FORM_flag_present)) |
| { |
| warn (_("Corrupt attribute\n")); |
| return data; |
| } |
| |
| if (do_wide && ! do_loc) |
| { |
| /* PR 26847: Display the name of the form. */ |
| const char * name = get_FORM_name (form); |
| |
| /* For convenience we skip the DW_FORM_ prefix to the name. */ |
| if (name[0] == 'D') |
| name += 8; /* strlen ("DW_FORM_") */ |
| printf ("%c(%s)", delimiter, name); |
| } |
| |
| switch (form) |
| { |
| case DW_FORM_ref_addr: |
| if (dwarf_version == 2) |
| SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| else if (dwarf_version > 2) |
| SAFE_BYTE_GET_AND_INC (uvalue, data, offset_size, end); |
| else |
| error (_("Internal error: DW_FORM_ref_addr is not supported in DWARF version 1.\n")); |
| break; |
| |
| case DW_FORM_addr: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, pointer_size, end); |
| break; |
| |
| case DW_FORM_strp_sup: |
| case DW_FORM_strp: |
| case DW_FORM_line_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: |
| case DW_FORM_strx1: |
| case DW_FORM_addrx1: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| break; |
| |
| case DW_FORM_ref2: |
| case DW_FORM_data2: |
| case DW_FORM_strx2: |
| case DW_FORM_addrx2: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
| break; |
| |
| case DW_FORM_strx3: |
| case DW_FORM_addrx3: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 3, end); |
| break; |
| |
| case DW_FORM_ref_sup4: |
| case DW_FORM_ref4: |
| case DW_FORM_data4: |
| case DW_FORM_strx4: |
| case DW_FORM_addrx4: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| break; |
| |
| case DW_FORM_ref_sup8: |
| case DW_FORM_ref8: |
| case DW_FORM_data8: |
| case DW_FORM_ref_sig8: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
| break; |
| |
| case DW_FORM_data16: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 8, end); |
| SAFE_BYTE_GET_AND_INC (uvalue_hi, data, 8, end); |
| if (byte_get != byte_get_little_endian) |
| { |
| uint64_t utmp = uvalue; |
| uvalue = uvalue_hi; |
| uvalue_hi = utmp; |
| } |
| break; |
| |
| case DW_FORM_sdata: |
| READ_SLEB (svalue, data, end); |
| uvalue = svalue; |
| break; |
| |
| case DW_FORM_GNU_str_index: |
| case DW_FORM_strx: |
| case DW_FORM_ref_udata: |
| case DW_FORM_udata: |
| case DW_FORM_GNU_addr_index: |
| case DW_FORM_addrx: |
| case DW_FORM_loclistx: |
| case DW_FORM_rnglistx: |
| READ_ULEB (uvalue, data, end); |
| break; |
| |
| case DW_FORM_indirect: |
| READ_ULEB (form, data, end); |
| if (!do_loc) |
| printf ("%c%s", delimiter, get_FORM_name (form)); |
| if (form == DW_FORM_implicit_const) |
| READ_SLEB (implicit_const, data, end); |
| return read_and_display_attr_value (attribute, form, implicit_const, |
| start, data, end, |
| cu_offset, pointer_size, |
| offset_size, dwarf_version, |
| debug_info_p, do_loc, |
| section, this_set, delimiter, level); |
| |
| case DW_FORM_implicit_const: |
| uvalue = implicit_const; |
| break; |
| |
| default: |
| break; |
| } |
| |
| switch (form) |
| { |
| case DW_FORM_ref_addr: |
| if (!do_loc) |
| printf ("%c<%#" PRIx64 ">", delimiter, uvalue); |
| break; |
| |
| case DW_FORM_GNU_ref_alt: |
| if (!do_loc) |
| { |
| if (do_wide) |
| /* We have already printed the form name. */ |
| printf ("%c<%#" PRIx64 ">", delimiter, uvalue); |
| else |
| printf ("%c<alt %#" PRIx64 ">", delimiter, uvalue); |
| } |
| /* FIXME: Follow the reference... */ |
| break; |
| |
| case DW_FORM_ref1: |
| case DW_FORM_ref2: |
| case DW_FORM_ref4: |
| case DW_FORM_ref_sup4: |
| case DW_FORM_ref_udata: |
| if (!do_loc) |
| printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset); |
| break; |
| |
| case DW_FORM_data4: |
| case DW_FORM_addr: |
| case DW_FORM_sec_offset: |
| if (!do_loc) |
| printf ("%c%#" PRIx64, delimiter, uvalue); |
| break; |
| |
| case DW_FORM_flag_present: |
| case DW_FORM_flag: |
| case DW_FORM_data1: |
| case DW_FORM_data2: |
| case DW_FORM_sdata: |
| if (!do_loc) |
| printf ("%c%" PRId64, delimiter, uvalue); |
| break; |
| |
| case DW_FORM_udata: |
| if (!do_loc) |
| printf ("%c%" PRIu64, delimiter, uvalue); |
| break; |
| |
| case DW_FORM_implicit_const: |
| if (!do_loc) |
| printf ("%c%" PRId64, delimiter, implicit_const); |
| break; |
| |
| case DW_FORM_ref_sup8: |
| case DW_FORM_ref8: |
| case DW_FORM_data8: |
| if (!do_loc) |
| { |
| uint64_t utmp = uvalue; |
| if (form == DW_FORM_ref8) |
| utmp += cu_offset; |
| printf ("%c%#" PRIx64, delimiter, utmp); |
| } |
| break; |
| |
| case DW_FORM_data16: |
| if (!do_loc) |
| { |
| if (uvalue_hi == 0) |
| printf (" %#" PRIx64, uvalue); |
| else |
| printf (" %#" PRIx64 "%016" PRIx64, uvalue_hi, uvalue); |
| } |
| break; |
| |
| case DW_FORM_string: |
| if (!do_loc) |
| printf ("%c%.*s", delimiter, (int) (end - data), data); |
| data += strnlen ((char *) data, end - data); |
| if (data < end) |
| data++; |
| break; |
| |
| case DW_FORM_block: |
| case DW_FORM_exprloc: |
| READ_ULEB (uvalue, data, end); |
| do_block: |
| block_start = data; |
| if (block_start >= end) |
| { |
| warn (_("Block ends prematurely\n")); |
| uvalue = 0; |
| block_start = end; |
| } |
| |
| uvalue = check_uvalue (block_start, uvalue, end); |
| |
| data = block_start + uvalue; |
| if (!do_loc) |
| { |
| unsigned char op; |
| |
| SAFE_BYTE_GET (op, block_start, sizeof (op), end); |
| if (op != DW_OP_addrx) |
| data = display_block (block_start, uvalue, end, delimiter); |
| } |
| break; |
| |
| case DW_FORM_block1: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end); |
| goto do_block; |
| |
| case DW_FORM_block2: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 2, end); |
| goto do_block; |
| |
| case DW_FORM_block4: |
| SAFE_BYTE_GET_AND_INC (uvalue, data, 4, end); |
| goto do_block; |
| |
| case DW_FORM_strp: |
| if (!do_loc) |
| { |
| if (do_wide) |
| /* We have already displayed the form name. */ |
| printf (_("%c(offset: %#" PRIx64 "): %s"), |
| delimiter, uvalue, fetch_indirect_string (uvalue)); |
| else |
| printf (_("%c(indirect string, offset: %#" PRIx64 "): %s"), |
| delimiter, uvalue, fetch_indirect_string (uvalue)); |
| } |
| break; |
| |
| case DW_FORM_line_strp: |
| if (!do_loc) |
| { |
| if (do_wide) |
| /* We have already displayed the form name. */ |
| printf (_("%c(offset: %#" PRIx64 "): %s"), |
| delimiter, uvalue, fetch_indirect_line_string (uvalue)); |
| else |
| printf (_("%c(indirect line string, offset: %#" PRIx64 "): %s"), |
| delimiter, uvalue, fetch_indirect_line_string (uvalue)); |
| } |
| break; |
| |
| case DW_FORM_GNU_str_index: |
| case DW_FORM_strx: |
| case DW_FORM_strx1: |
| case DW_FORM_strx2: |
| case DW_FORM_strx3: |
| case DW_FORM_strx4: |
| if (!do_loc) |
| { |
| const char *suffix = section ? strrchr (section->name, '.') : NULL; |
| bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
| const char *strng; |
| |
| strng = fetch_indexed_string (uvalue, this_set, offset_size, dwo, |
| debug_info_p ? debug_info_p->str_offsets_base : 0); |
| if (do_wide) |
| /* We have already displayed the form name. */ |
| printf (_("%c(offset: %#" PRIx64 "): %s"), |
| delimiter, uvalue, strng); |
| else |
| printf (_("%c(indexed string: %#" PRIx64 "): %s"), |
| delimiter, uvalue, strng); |
| } |
| break; |
| |
| case DW_FORM_GNU_strp_alt: |
| if (!do_loc) |
| { |
| if (do_wide) |
| /* We have already displayed the form name. */ |
| printf (_("%c(offset: %#" PRIx64 ") %s"), |
| delimiter, uvalue, fetch_alt_indirect_string (uvalue)); |
| else |
| printf (_("%c(alt indirect string, offset: %#" PRIx64 ") %s"), |
| delimiter, uvalue, fetch_alt_indirect_string (uvalue)); |
| } |
| break; |
| |
| case DW_FORM_indirect: |
| /* Handled above. */ |
| break; |
| |
| case DW_FORM_ref_sig8: |
| if (!do_loc) |
| printf ("%c%s: %#" PRIx64, delimiter, do_wide ? "" : "signature", |
| uvalue); |
| break; |
| |
| case DW_FORM_GNU_addr_index: |
| case DW_FORM_addrx: |
| case DW_FORM_addrx1: |
| case DW_FORM_addrx2: |
| case DW_FORM_addrx3: |
| case DW_FORM_addrx4: |
| case DW_FORM_loclistx: |
| case DW_FORM_rnglistx: |
| if (!do_loc) |
| { |
| uint64_t base, idx; |
| const char *suffix = strrchr (section->name, '.'); |
| bool dwo = suffix && strcmp (suffix, ".dwo") == 0; |
| |
| if (form == DW_FORM_loclistx) |
| { |
| if (debug_info_p == NULL) |
| idx = -1; |
| else if (dwo) |
| { |
| idx = fetch_indexed_offset (uvalue, loclists_dwo, |
| debug_info_p->loclists_base, |
| debug_info_p->offset_size); |
| if (idx != (uint64_t) -1) |
| idx += (offset_size == 8) ? 20 : 12; |
| } |
| else if (dwarf_version > 4) |
| { |
| idx = fetch_indexed_offset (uvalue, loclists, |
| debug_info_p->loclists_base, |
| debug_info_p->offset_size); |
| } |
| else |
| { |
| /* We want to compute: |
| idx = fetch_indexed_value (uvalue, loclists, |
| debug_info_p->loclists_base); |
| idx += debug_info_p->loclists_base; |
| Fortunately we already have that sum cached in the |
| loc_offsets array. */ |
| if (uvalue < debug_info_p->num_loc_offsets) |
| idx = debug_info_p->loc_offsets [uvalue]; |
| else |
| { |
| warn (_("loc_offset %" PRIu64 " too big\n"), uvalue); |
| idx = -1; |
| } |
| } |
| } |
| else if (form == DW_FORM_rnglistx) |
| { |
| if (debug_info_p == NULL) |
| idx = -1; |
| else |
| idx = fetch_indexed_offset (uvalue, |
| dwo ? rnglists_dwo : rnglists, |
| debug_info_p->rnglists_base, |
| debug_info_p->offset_size); |
| } |
| else |
| { |
| if (debug_info_p == NULL) |
| base = 0; |
| else if (debug_info_p->addr_base == DEBUG_INFO_UNAVAILABLE) |
| base = 0; |
| else |
| base = debug_info_p->addr_base; |
| |
| base += uvalue * pointer_size; |
| idx = fetch_indexed_addr (base, pointer_size); |
| } |
| |
| /* We have already displayed the form name. */ |
| if (idx != (uint64_t) -1) |
| printf (_("%c(index: %#" PRIx64 "): %#" PRIx64), |
| delimiter, uvalue, idx); |
| } |
| break; |
| |
| case DW_FORM_strp_sup: |
| if (!do_loc) |
| printf ("%c<%#" PRIx64 ">", delimiter, uvalue + cu_offset); |
| break; |
| |
| default: |
| warn (_("Unrecognized form: %#lx\n"), form); |
| /* What to do? Consume a byte maybe? */ |
| ++data; |
| break; |
| } |
| |
| if ((do_loc || do_debug_loc || do_debug_ranges || do_debug_info) |
| && num_debug_info_entries == 0 |
| && debug_info_p != NULL) |
| { |
| switch (attribute) |
| { |
| case DW_AT_loclists_base: |
| if (debug_info_p->loclists_base) |
| warn (_("CU @ %#" PRIx64 " has multiple loclists_base values " |
| "(%#" PRIx64 " and %#" PRIx64 ")\n"), |
| debug_info_p->cu_offset, |
| debug_info_p->loclists_base, uvalue); |
| svalue = uvalue; |
| if (svalue < 0) |
| { |
| warn (_("CU @ %#" PRIx64 " has has a negative loclists_base " |
| "value of %#" PRIx64 " - treating as zero\n"), |
| debug_info_p->cu_offset, svalue); |
| uvalue = 0; |
| } |
| debug_info_p->loclists_base = uvalue; |
| break; |
| |
| case DW_AT_rnglists_base: |
| /* Assignment to debug_info_p->rnglists_base is now elsewhere. */ |
| break; |
| |
| case DW_AT_str_offsets_base: |
| if (debug_info_p->str_offsets_base) |
| warn (_("CU @ %#" PRIx64 " has multiple str_offsets_base values " |
| "%#" PRIx64 " and %#" PRIx64 ")\n"), |
| debug_info_p->cu_offset, |
| debug_info_p->str_offsets_base, uvalue); |
| svalue = uvalue; |
| if (svalue < 0) |
| { |
| warn (_("CU @ %#" PRIx64 " has has a negative stroffsets_base " |
| "value of %#" PRIx64 " - treating as zero\n"), |
| debug_info_p->cu_offset, svalue); |
| uvalue = 0; |
| } |
| debug_info_p->str_offsets_base = uvalue; |
| break; |
| |
| case DW_AT_frame_base: |
| /* This is crude; the have_frame_base is reset on the next |
| subprogram, not at the end of the current topmost one. */ |
| have_frame_base = 1; |
| frame_base_level = level; |
| /* Fall through. */ |
| case DW_AT_location: |
| case DW_AT_GNU_locviews: |
| 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_call_value: |
| case DW_AT_GNU_call_site_value: |
| case DW_AT_call_data_value: |
| case DW_AT_GNU_call_site_data_value: |
| case DW_AT_call_target: |
| case DW_AT_GNU_call_site_target: |
| case DW_AT_call_target_clobbered: |
| 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 |
| || form == DW_FORM_loclistx) |
| { |
| /* 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 = (uint64_t *) |
| xcrealloc (debug_info_p->loc_offsets, |
| lmax, sizeof (*debug_info_p->loc_offsets)); |
| debug_info_p->loc_views = (uint64_t *) |
| xcrealloc (debug_info_p->loc_views, |
| lmax, sizeof (*debug_info_p->loc_views)); |
| 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 (form == DW_FORM_loclistx) |
| uvalue = fetch_indexed_offset (num, loclists, |
| debug_info_p->loclists_base, |
| debug_info_p->offset_size); |
| else if (this_set != NULL) |
| uvalue += this_set->section_offsets [DW_SECT_LOC]; |
| |
| debug_info_p->have_frame_base [num] = have_frame_base; |
| if (attribute != DW_AT_GNU_locviews) |
| { |
| /* Corrupt DWARF info can produce more offsets than views. |
| See PR 23062 for an example. */ |
| if (debug_info_p->num_loc_offsets |
| > debug_info_p->num_loc_views) |
| warn (_("More location offset attributes than DW_AT_GNU_locview attributes\n")); |
| else |
| { |
| debug_info_p->loc_offsets [num] = uvalue; |
| debug_info_p->num_loc_offsets++; |
| } |
| } |
| else |
| { |
| if (debug_info_p->num_loc_views > num) |
| { |
| warn (_("The number of views (%u) is greater than the number of locations (%u)\n"), |
| debug_info_p->num_loc_views, num); |
| debug_info_p->num_loc_views = num; |
| } |
| else |
| num = debug_info_p->num_loc_views; |
| if (num > debug_info_p->num_loc_offsets) |
| warn (_("More DW_AT_GNU_locview attributes than location offset attributes\n")); |
| else |
| { |
| debug_info_p->loc_views [num] = uvalue; |
| debug_info_p->num_loc_views++; |
| } |
| } |
| } |
| break; |
| |
| case DW_AT_low_pc: |
| if (need_base_address) |
| { |
| if (form == DW_FORM_addrx) |
| uvalue = fetch_indexed_addr (debug_info_p->addr_base |
| + uvalue * pointer_size, |
| pointer_size); |
| |
| debug_info_p->base_address = uvalue; |
| } |
| break; |
| |
| case DW_AT_GNU_addr_base: |
| case DW_AT_addr_base: |
| debug_info_p->addr_base = uvalue; |
| /* Retrieved elsewhere so that it is in |
| place by the time we read low_pc. */ |
| 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 |
| || form == DW_FORM_rnglistx) |
| { |
| /* 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 = (uint64_t *) |
| xcrealloc (debug_info_p->range_lists, |
| lmax, sizeof (*debug_info_p->range_lists)); |
| debug_info_p->max_range_lists = lmax; |
| } |
| |
| if (form == DW_FORM_rnglistx) |
| uvalue = fetch_indexed_offset (uvalue, rnglists, |
| debug_info_p->rnglists_base, |
| debug_info_p->offset_size); |
| |
| debug_info_p->range_lists [num] = uvalue; |
| debug_info_p->num_range_lists++; |
| } |
| break; |
| |
| case DW_AT_GNU_dwo_name: |
| case DW_AT_dwo_name: |
| if (need_dwo_info) |
| switch (form) |
| { |
| case DW_FORM_strp: |
| add_dwo_name ((const char *) fetch_indirect_string (uvalue), |
| cu_offset); |
| break; |
| case DW_FORM_GNU_strp_alt: |
| add_dwo_name ((const char *) fetch_alt_indirect_string (uvalue), cu_offset); |
| break; |
| case DW_FORM_GNU_str_index: |
| case DW_FORM_strx: |
| case DW_FORM_strx1: |
| case DW_FORM_strx2: |
| case DW_FORM_strx3: |
| case DW_FORM_strx4: |
| add_dwo_name (fetch_indexed_string (uvalue, this_set, |
| offset_size, false, |
| debug_info_p->str_offsets_base), |
| cu_offset); |
| break; |
| case DW_FORM_string: |
| add_dwo_name ((const char *) orig_data, cu_offset); |
| break; |
| default: |
| warn (_("Unsupported form (%s) for attribute %s\n"), |
| get_FORM_name (form), get_AT_name (attribute)); |
| break; |
| } |
| break; |
| |
| case DW_AT_comp_dir: |
| /* FIXME: Also extract a build-id in a CU/TU. */ |
| if (need_dwo_info) |
| switch (form) |
| { |
| case DW_FORM_strp: |
| add_dwo_dir ((const char *) fetch_indirect_string (uvalue), cu_offset); |
| break; |
| case DW_FORM_GNU_strp_alt: |
| add_dwo_dir (fetch_alt_indirect_string (uvalue), cu_offset); |
| break; |
| case DW_FORM_line_strp: |
| add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue), cu_offset); |
| break; |
| case DW_FORM_GNU_str_index: |
| case DW_FORM_strx: |
| case DW_FORM_strx1: |
| case DW_FORM_strx2: |
| case DW_FORM_strx3: |
| case DW_FORM_strx4: |
| add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, false, |
| debug_info_p->str_offsets_base), |
| cu_offset); |
| break; |
| case DW_FORM_string: |
| add_dwo_dir ((const char *) orig_data, cu_offset); |
| break; |
| default: |
| warn (_("Unsupported form (%s) for attribute %s\n"), |
| get_FORM_name (form), get_AT_name (attribute)); |
| break; |
| } |
| break; |
| |
| case DW_AT_GNU_dwo_id: |
| if (need_dwo_info) |
| switch (form) |
| { |
| case DW_FORM_data8: |
| /* FIXME: Record the length of the ID as well ? */ |
| add_dwo_id ((const char *) (data - 8), cu_offset); |
| break; |
| default: |
| warn (_("Unsupported form (%s) for attribute %s\n"), |
| get_FORM_name (form), get_AT_name (attribute)); |
| break; |
| } |
| break; |
| |
| default: |
| break; |
| } |
| } |
| |
| if (do_loc || attribute == 0) |
| return data; |
| |
| /* For some attributes we can display further information. */ |
| switch (attribute) |
| { |
| case DW_AT_type: |
| if (level >= 0 && level < MAX_CU_NESTING |
| && uvalue < (size_t) (end - start)) |
| { |
| bool is_signed = false; |
| abbrev_entry *type_abbrev; |
| unsigned char *type_data; |
| abbrev_map *map; |
| |
| type_abbrev = get_type_abbrev_from_form (form, uvalue, |
| cu_offset, end, |
| section, NULL, |
| &type_data, &map); |
| if (type_abbrev != NULL) |
| { |
| get_type_signedness (type_abbrev, section, type_data, |
| map ? section->start + map->end : end, |
| |