blob: 06ef1f7285e55c120fd21736c97b46d004067613 [file] [log] [blame]
/* dwarf.c -- display DWARF contents of a BFD binary file
Copyright (C) 2005-2019 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"
#include "filenames.h"
#include "safe-ctype.h"
#include <assert.h>
#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 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;
struct dwo_info * next;
} dwo_info;
static dwo_info * first_dwo_info = NULL;
static bfd_boolean 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_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;
int dwarf_cutoff_level = -1;
unsigned long dwarf_start_die;
int dwarf_check = 0;
/* Convenient constant, to avoid having to cast -1 to dwarf_vma when
testing whether e.g. a locview list is present. */
static const dwarf_vma vm1 = -1;
/* 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;
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 bfd_boolean 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 bfd_boolean 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 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];
if (fmtch)
sprintf (fmt, "%%%s%s", DWARF_VMA_FMT, fmtch);
else
sprintf (fmt, "%%%s", DWARF_VMA_FMT);
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));
}
/* Print a view number in hexadecimal value, with the same width
print_dwarf_vma would have printed it with the same num_bytes.
Print blanks for zero view, unless force is nonzero. */
static void
print_dwarf_view (dwarf_vma value, unsigned num_bytes, int force)
{
int len;
if (!num_bytes)
len = 4;
else
len = num_bytes * 2;
assert (value == (unsigned long) value);
if (value || force)
printf ("v%0*lx ", len - 1, (unsigned long) value);
else
printf ("%*s", len + 1, "");
}
/* 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 SKIP_ULEB() read_uleb128 (start, & length_return, end); start += length_return
#define SKIP_SLEB() read_sleb128 (start, & length_return, end); start += length_return
#define READ_ULEB(var) \
do \
{ \
dwarf_vma _val; \
\
(var) = _val = read_uleb128 (start, &length_return, end); \
if ((var) != _val) \
error (_("Internal error: %s:%d: LEB value (%s) " \
"too large for containing variable\n"), \
__FILE__, __LINE__, dwarf_vmatoa ("u", _val)); \
start += length_return; \
} \
while (0)
#define READ_SLEB(var) \
do \
{ \
dwarf_signed_vma _val; \
\
(var) = _val = read_sleb128 (start, &length_return, end); \
if ((var) != _val) \
error (_("Internal error: %s:%d: LEB value (%s) " \
"too large for containing variable\n"), \
__FILE__, __LINE__, dwarf_vmatoa ("d", _val)); \
start += length_return; \
} \
while (0)
/* Read AMOUNT bytes from PTR and store them in VAL as an unsigned value.
Checks to make sure that the read will not reach or pass END
and that VAL is big enough to hold AMOUNT bytes. */
#define SAFE_BYTE_GET(VAL, PTR, AMOUNT, END) \
do \
{ \
unsigned int 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), \
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)
/* Like SAFE_BYTE_GET, but also increments PTR by AMOUNT. */
#define SAFE_BYTE_GET_AND_INC(VAL, PTR, AMOUNT, END) \
do \
{ \
SAFE_BYTE_GET (VAL, PTR, AMOUNT, END); \
PTR += AMOUNT; \
} \
while (0)
/* Like SAFE_BYTE_GET, but reads a signed value. */
#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)
/* Like SAFE_SIGNED_BYTE_GET, but also increments PTR by AMOUNT. */
#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 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 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.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 += len + 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", (int) l, 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;
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: %s\n"),
dwarf_vmatoa ("x", 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 (dwarf_vma 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: %s\n"),
dwarf_vmatoa ("x", 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 (dwarf_vma idx, struct cu_tu_set *this_set,
dwarf_vma offset_size, bfd_boolean 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;
const char * ret;
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>");
}
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)
ret = (const char *) _("<no NUL byte at end of section>");
return ret;
}
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;
bfd_signed_vma implicit_const;
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,
bfd_signed_vma implicit_const)
{
abbrev_attr *attr;
attr = (abbrev_attr *) malloc (sizeof (*attr));
if (attr == NULL)
/* ugg */
return;
attr->attribute = attribute;
attr->form = form;
attr->implicit_const = implicit_const;
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;
/* Initialize it due to a false compiler warning. */
bfd_signed_vma implicit_const = -1;
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;
if (form == DW_FORM_implicit_const)
{
implicit_const = read_sleb128 (start, & bytes_read, end);
start += bytes_read;
if (start == end)
break;
}
add_abbrev_attr (attribute, form, implicit_const);
}
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];
if (tag >= DW_TAG_lo_user && tag <= DW_TAG_hi_user)
snprintf (buffer, sizeof (buffer), _("User TAG value: %#lx"), tag);
else
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 const char *
get_IDX_name (unsigned long idx)
{
const char *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,
dwarf_vma length,
const unsigned char * const end, char delimiter)
{
dwarf_vma maxlen;
printf (_("%c%s byte block: "), delimiter, 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:
/* 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: <0x%s>",
dwarf_vmatoa ("x", 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: <0x%s>",
dwarf_vmatoa ("x", 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: <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_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);
}
printf ("%s: <0x%s> %s",
(op == DW_OP_implicit_pointer
? "DW_OP_implicit_pointer" : "DW_OP_GNU_implicit_pointer"),
dwarf_vmatoa ("x", uvalue),
dwarf_vmatoa ("d", read_sleb128 (data,
&bytes_read, end)));
data += bytes_read;
break;
case DW_OP_entry_value:
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 ("%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;
if (data > end)
data = end;
break;
case DW_OP_const_type:
case DW_OP_GNU_const_type:
uvalue = read_uleb128 (data, &bytes_read, end);
data += bytes_read;
printf ("%s: <0x%s> ",
(op == DW_OP_const_type ? "DW_OP_const_type"
: "DW_OP_GNU_const_type"),
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_regval_type:
case DW_OP_GNU_regval_type:
uvalue = read_uleb128 (data, &bytes_read, end);
data += bytes_read;
printf ("%s: %s (%s)",
(op == DW_OP_regval_type ? "DW_OP_regval_type"
: "DW_OP_GNU_regval_type"),
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_deref_type:
case DW_OP_GNU_deref_type:
SAFE_BYTE_GET_AND_INC (uvalue, data, 1, end);
printf ("%s: %ld",
(op == DW_OP_deref_type ? "DW_OP_deref_type"
: "DW_OP_GNU_deref_type"),
(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_convert:
case DW_OP_GNU_convert:
uvalue = read_uleb128 (data, &bytes_read, end);
data += bytes_read;
printf ("%s <0x%s>",
(op == DW_OP_convert ? "DW_OP_convert" : "DW_OP_GNU_convert"),
dwarf_vmatoa ("x", uvalue ? cu_offset + uvalue : 0));
break;
case DW_OP_reinterpret:
case DW_OP_GNU_reinterpret:
uvalue = read_uleb128 (data, &bytes_read, end);
data += bytes_read;
printf ("%s <0x%s>",
(op == DW_OP_reinterpret ? "DW_OP_reinterpret"
: "DW_OP_GNU_reinterpret"),
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;
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: <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 0x%x)"), op);
else
printf (_("(Unknown location op 0x%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 (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 const char *
fetch_alt_indirect_string (dwarf_vma 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 (%s) too big or no string sections available\n"),
dwarf_vmatoa ("x", 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 * field, dwo_type type)
{
dwo_info * dwinfo = xmalloc (sizeof * dwinfo);
dwinfo->type = type;
dwinfo->value = field;
dwinfo->next = first_dwo_info;
first_dwo_info = dwinfo;
}
static void
add_dwo_name (const char * name)
{
add_dwo_info (name, DWO_NAME);
}
static void
add_dwo_dir (const char * dir)
{
add_dwo_info (dir, DWO_DIR);
}
static void
add_dwo_id (const char * id)
{
add_dwo_info (id, 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 dwarf_vma
check_uvalue (const unsigned char * start,
dwarf_vma uvalue,
const unsigned char * end)
{
dwarf_vma 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: %lx\n"), (long) uvalue);
uvalue = max_uvalue;
}
return uvalue;
}
static unsigned char *
skip_attr_bytes (unsigned long form,
unsigned char * data,
unsigned const char * end,
dwarf_vma pointer_size,
dwarf_vma offset_size,
int dwarf_version,
dwarf_vma * value_return)
{
unsigned int bytes_read;
dwarf_vma uvalue = 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 == 3 || dwarf_version == 4)
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:
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_ref_udata:
case DW_FORM_udata:
case DW_FORM_GNU_str_index:
case DW_FORM_GNU_addr_index:
uvalue = read_uleb128 (data, & bytes_read, end);
data += bytes_read;
break;
case DW_FORM_ref8:
case DW_FORM_data8:
data += 8;
break;
case DW_FORM_data16:
data += 16;
break;
case DW_FORM_string:
data += strnlen ((char *) data, end - data) + 1;
break;
case DW_FORM_block:
case DW_FORM_exprloc:
uvalue = read_uleb128 (data, & bytes_read, end);
data += bytes_read + uvalue;
break;
case DW_FORM_block1:
SAFE_BYTE_GET (uvalue, data, 1, end);
data += 1 + uvalue;
break;
case DW_FORM_block2:
SAFE_BYTE_GET (uvalue, data, 2, end);
data += 2 + uvalue;
break;
case DW_FORM_block4:
SAFE_BYTE_GET (uvalue, data, 4, end);
data += 4 + uvalue;
break;
case DW_FORM_ref_sig8:
data += 8;
break;
case DW_FORM_indirect:
/* FIXME: Handle this form. */
default:
return NULL;
}
* value_return = uvalue;
if (data > end)
data = (unsigned char *) end;
return data;
}
/* Return IS_SIGNED set to TRUE if the type at
DATA can be determined to be a signed type. */
static void
get_type_signedness (unsigned char * start,
unsigned char * data,
unsigned const char * end,
dwarf_vma pointer_size,
dwarf_vma offset_size,
int dwarf_version,
bfd_boolean * is_signed,
bfd_boolean is_nested)
{
unsigned long abbrev_number;
unsigned int bytes_read;
abbrev_entry * entry;
abbrev_attr * attr;
* is_signed = FALSE;
abbrev_number = read_uleb128 (data, & bytes_read, end);
data += bytes_read;
for (entry = first_abbrev;
entry != NULL && entry->entry != abbrev_number;
entry = entry->next)
continue;
if (entry == NULL)
/* FIXME: Issue a warning ? */
return;
for (attr = entry->first_attr;
attr != NULL && attr->attribute;
attr = attr->next)
{
dwarf_vma uvalue = 0;
data = skip_attr_bytes (attr->form, data, end, pointer_size,
offset_size, dwarf_version, & uvalue);
if (data == NULL)
return;
switch (attr->attribute)
{
#if 0 /* FIXME: It would be nice to print the name of the type,
but this would mean updating a lot of binutils tests. */
case DW_AT_name:
if (attr->form == DW_FORM_strp)
printf ("%s", fetch_indirect_string (uvalue));
break;
#endif
case DW_AT_type:
/* Recurse. */
if (is_nested)
{
/* FIXME: Warn - or is this expected ?
NB/ We need to avoid infinite recursion. */
return;
}
if (uvalue >= (size_t) (end - start))
return;
get_type_signedness (start, start + uvalue, end, pointer_size,
offset_size, dwarf_version, is_signed, TRUE);
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,
bfd_boolean is_signed)
{
if (is_signed)
{
dwarf_signed_vma sval = read_sleb128 (data, bytes_read, end);
printf ("%ld", (long) sval);
}
else
{
dwarf_vma uval = read_uleb128 (data, bytes_read, end);
printf ("%lu", (unsigned long) uval);
}
}
static void
display_discr_list (unsigned long form,
dwarf_vma uvalue,
unsigned char * data,
unsigned const char * end,
int level)
{
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;
}
bfd_boolean is_signed =
(level > 0 && level <= MAX_CU_NESTING)
? level_type_signed [level - 1] : FALSE;
printf ("(");
while (uvalue)
{
unsigned char discriminant;
unsigned int bytes_read;
SAFE_BYTE_GET (discriminant, data, 1, end);
-- uvalue;
data ++;
assert (uvalue > 0);
switch (discriminant)
{
case DW_DSC_label:
printf ("label ");
read_and_print_leb128 (data, & bytes_read, end, is_signed);
assert (bytes_read <= uvalue && bytes_read > 0);
uvalue -= bytes_read;
data += bytes_read;
break;
case DW_DSC_range:
printf ("range ");
read_and_print_leb128 (data, & bytes_read, end, is_signed);
assert (bytes_read <= uvalue && bytes_read > 0);
uvalue -= bytes_read;
data += bytes_read;
printf ("..");
read_and_print_leb128 (data, & bytes_read, end, is_signed);
assert (bytes_read <= uvalue && bytes_read > 0);
uvalue -= bytes_read;
data += bytes_read;
break;
default:
printf ("<corrupt>\n");
warn (_("corrupt discr_list - unrecognised discriminant byte %#x\n"),
discriminant);
return;
}
if (uvalue)
printf (", ");
}
if (is_signed)
printf (")(signed)");
else
printf (")(unsigned)");
}
static unsigned char *
read_and_display_attr_value (unsigned long attribute,
unsigned long form,
dwarf_signed_vma implicit_const,
unsigned char * start,
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,
char delimiter,
int level)
{
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_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:
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 ("%c%s", delimiter, get_FORM_name (form));
if (form == DW_FORM_implicit_const)
{
implicit_const = read_sleb128 (data, & bytes_read, end);
data += bytes_read;
}
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_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 ("%c<0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
break;
case DW_FORM_GNU_ref_alt:
if (!do_loc)
printf ("%c<alt 0x%s>", delimiter, dwarf_vmatoa ("x",uvalue));
/* FIXME: Follow the reference... */
break;
case DW_FORM_ref1:
case DW_FORM_ref2:
case DW_FORM_ref4:
case DW_FORM_ref_udata:
if (!do_loc)
printf ("%c<0x%s>", delimiter, dwarf_vmatoa ("x", uvalue + cu_offset));
break;
case DW_FORM_data4:
case DW_FORM_addr:
case DW_FORM_sec_offset:
if (!do_loc)
printf ("%c0x%s", delimiter, 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 ("%c%s", delimiter, dwarf_vmatoa ("d", uvalue));
break;
case DW_FORM_implicit_const:
if (!do_loc)
printf ("%c%s", delimiter, dwarf_vmatoa ("d", implicit_const));
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 ("%c0x%s", delimiter,
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_data16:
if (!do_loc)
{
dwarf_vma left_high_bits, left_low_bits;
dwarf_vma right_high_bits, right_low_bits;
SAFE_BYTE_GET64 (data, &left_high_bits, &left_low_bits, end);
SAFE_BYTE_GET64 (data + 8, &right_high_bits, &right_low_bits, end);
if (byte_get == byte_get_little_endian)
{
/* Swap them. */
left_high_bits ^= right_high_bits;
right_high_bits ^= left_high_bits;
left_high_bits ^= right_high_bits;
left_low_bits ^= right_low_bits;
right_low_bits ^= left_low_bits;
left_low_bits ^= right_low_bits;
}
printf (" 0x%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x"
"%08" DWARF_VMA_FMT "x%08" DWARF_VMA_FMT "x",
left_high_bits, left_low_bits, right_high_bits,
right_low_bits);
}
data += 16;
break;
case DW_FORM_string:
if (!do_loc)
printf ("%c%.*s", delimiter, (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;
}
uvalue = check_uvalue (block_start, uvalue, end);
if (do_loc)
data = block_start + uvalue;
else
data = display_block (block_start, uvalue, end, delimiter);
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;
}
uvalue = check_uvalue (block_start, uvalue, end);
if (do_loc)
data = block_start + uvalue;
else
data = display_block (block_start, uvalue, end, delimiter);
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;
}
uvalue = check_uvalue (block_start, uvalue, end);
if (do_loc)
data = block_start + uvalue;
else
data = display_block (block_start, uvalue, end, delimiter);
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;
}
uvalue = check_uvalue (block_start, uvalue, end);
if (do_loc)
data = block_start + uvalue;
else
data = display_block (block_start, uvalue, end, delimiter);
break;
case DW_FORM_strp:
if (!do_loc)
printf (_("%c(indirect string, offset: 0x%s): %s"), delimiter,
dwarf_vmatoa ("x", uvalue),
fetch_indirect_string (uvalue));
break;
case DW_FORM_line_strp:
if (!do_loc)
printf (_("%c(indirect line string, offset: 0x%s): %s"), delimiter,
dwarf_vmatoa ("x", uvalue),
fetch_indirect_line_string (uvalue));
break;
case DW_FORM_GNU_str_index:
if (!do_loc)
{
const char * suffix = strrchr (section->name, '.');
bfd_boolean dwo = (suffix && strcmp (suffix, ".dwo") == 0) ? TRUE : FALSE;
printf (_("%c(indexed string: 0x%s): %s"), delimiter,
dwarf_vmatoa ("x", uvalue),
fetch_indexed_string (uvalue, this_set, offset_size, dwo));
}
break;
case DW_FORM_GNU_strp_alt:
if (!do_loc)
{
printf (_("%c(alt indirect string, offset: 0x%s) %s"), delimiter,
dwarf_vmatoa ("x", uvalue),
fetch_alt_indirect_string (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 ("%csignature: 0x%s", delimiter,
dwarf_vmatoa64 (high_bits, uvalue, buf, sizeof (buf)));
}
data += 8;
break;
case DW_FORM_GNU_addr_index:
if (!do_loc)
printf (_("%c(addr_index: 0x%s): %s"), delimiter,
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_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)
{
/* 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->loc_views = (dwarf_vma *)
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 (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
{
assert (debug_info_p->num_loc_views <= num);
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)
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;
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));
break;
case DW_FORM_GNU_str_index:
add_dwo_name (fetch_indexed_string (uvalue, this_set, offset_size, FALSE));
break;
case DW_FORM_string:
add_dwo_name ((const char *) orig_data);
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));
break;
case DW_FORM_line_strp:
add_dwo_dir ((const char *) fetch_indirect_line_string (uvalue));
break;
case DW_FORM_GNU_str_index:
add_dwo_dir (fetch_indexed_string (uvalue, this_set, offset_size, FALSE));
break;
case DW_FORM_string:
add_dwo_dir ((const char *) orig_data);
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));
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))
{
bfd_boolean is_signed = FALSE;
get_type_signedness (start, start + uvalue, end, pointer_size,
offset_size, dwarf_version, & is_signed, FALSE);
level_type_signed[level] = is_signed;
}
break;
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_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: %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;
/* DWARF 4 values: */
case DW_ATE_UTF: printf ("(unicode string)"); break;
/* DWARF 5 values: */
case DW_ATE_UCS: printf ("(UCS)"); break;
case DW_ATE_ASCII: printf ("(ASCII)"); 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;
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_endianity:
printf ("\t");
switch (uvalue)
{
case DW_END_default: printf ("(default)"); break;
case DW_END_big: printf ("(big)"); break;
case DW_END_little: printf ("(little)"); break;
default:
if (uvalue >= DW_END_lo_user && uvalue <= DW_END_hi_user)
printf (_("(user specified)"));
else
printf (_("(unknown endianity)"));
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;
case DW_CC_pass_by_reference: printf ("(pass by ref)"); break;
case DW_CC_pass_by_value: printf ("(pass by value)"); break;
case DW_CC_GNU_renesas_sh: printf ("(Rensas SH)"); break;
case DW_CC_GNU_borland_fastcall_i386: printf ("(Borland fastcall i386)"); 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 255:
case -1: printf (_("(undefined)")); break;
case 0: printf ("(row major)"); break;
case 1: printf ("(column major)"); break;
}
break;
case DW_AT_decimal_sign:
printf ("\t");
switch (uvalue)
{
case DW_DS_unsigned: printf (_("(unsigned)")); break;
case DW_DS_leading_overpunch: printf (_("(leading overpunch)")); break;
case DW_DS_trailing_overpunch: printf (_("(trailing overpunch)")); break;
case DW_DS_leading_separate: printf (_("(leading separate)")); break;
case DW_DS_trailing_separate: printf (_("(trailing separate)")); break;
default: printf (_("(unrecognised)")); break;
}
break;
case DW_AT_defaulted:
printf ("\t");
switch (uvalue)
{
case DW_DEFAULTED_no: printf (_("(no)")); break;
case DW_DEFAULTED_in_class: printf (_("(in class)")); break;
case DW_DEFAULTED_out_of_class: printf (_("(out of class)")); break;
default: printf (_("(unrecognised)")); break;
}
break;
case DW_AT_discr_list:
printf ("\t");
display_discr_list (form, uvalue, data, end, level);
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_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)
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_data_bit_offset:
case DW_AT_byte_size:
case DW_AT_bit_size:
case DW_AT_string_length_byte_size:
case DW_AT_string_length_bit_size:
case DW_AT_bit_stride:
if (form == DW_FORM_exprloc)
{
printf ("\t(");
(void) decode_location_expression (block_start, pointer_size,
offset_size, dwarf_version,
uvalue, cu_offset, section);
printf (")");
}
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 unsigned char *
read_and_display_attr (unsigned long attribute,
unsigned long form,
dwarf_signed_vma implicit_const,
unsigned char * start,
unsigned char * data,
unsigned char * end,
dwarf_vma cu_offset,
dwarf_vma pointer_size,